webbzr – php to browse a bzr repository from a web page
– You can see webbzr in action here
Latest changes
- Version 1.4 (Jun 30, 2010)Fixed a vulnerability where webbzr could be used to list content outside of the webbzr root.
- Version 1.3 (Jan 24, 2010) Branches and directories within branches can now be download as a tgz or tbz2 package straight from the bzr repository.
- Version 1.2 (Jan 21, 2010) Security fix (thanks to Andrew Bradley)
- Version 1.1 (Oct. 6 2009) Fix for repository that are not at the root of a url, for instance: http://www.site.com/~user/bzr/ (thanks to Dr. Rich Wareham)
- Version 1.0 (Aug. 5 2009) Initial version
Motivation
Bazaar (bzr) can push and pull branches on a remote server without having to install anything on the server side. This is useful in cases where you have access to a web server without admin privileges (i.e. you could not install WebDAV or setup a svn site). With bzr, you simply upload (sftp) your branch to a directory visible from your web page, and then people download (branch) using http.
Next step, I wanted to allow browsing of the branch from the web. This feature is “free” with svn through WebDAV, and there have been extra tools to browse svn and cvs (e.g. ViewVC). For bzr however, all I could find was LoggerHead which works as an actual web server. It has to start a daemon and open ports – pretty much defeating my initial motivation for using bzr.
I figured I’d just hack something quick.
webbzr
Features
webbzr is a php script that will:
- List the content of a directory and show normal and versioned files
- Allow browsing into the repository
- Allow viewing or downloading of files in the repository
- Allow downloading of branches or directories as a tgz/tbz2 package
- Allow browsing of revisions (going back in time)
- Display information about the last modifications
Files, not just directories, can be browsed by version. For example:
- http://bazaar.enseed.com/app/webbzr/.webbzr/webbzr.php
grabs you the latest release of the file - http://bazaar.enseed.com/app/webbzr/.webbzr/webbzr.php?rev=1
would get you revision 1 of the file.
Hiding the Parameters from the URL
Using mod_rewrite, browsing is transparent (you can browse using the actual path in the url). For example, the link to http://bazaar.enseed.com/app/webbzr/ brings you straight into a branch. This is more convenient than using the equivalent url: http://bazaar.enseed.com/.webbzr/webbzr.php?path=app/webbzr/.
To make this possible without configuring the web server directly, we use a .htaccess file that redirects requests to the script:
1 2 3 | RewriteEngine on RewriteCond %{REQUEST_URI} !^/\..*$ RewriteRule ^(.*)$ /.webbzr/webbzr.php?path=$1 [L,QSA] |
This reads: given that the request uri does not start with a “.” (the script in stored in .webbzr/ to avoid recursive redirection), whatever the request was, pass it as an argument named path to webbzr.php.
Formatting the Output
The webbzr.php script actually outputs xml, not html. The xml is transformed on the client side with an xslt (webbzr.xsl) and styled with css (webbzr.css). That means you can change the look if without having to touch the php code at all.
Installing
1. Download
To download:
1 | bzr branch http://bazaar.enseed.com/app/webbzr/ |
2. Configure
Move to webbzr/.webbzr:
1 | cd webbzr/.webbzr/ |
In the config.php file you will have to edit the following variables:
- $BZRURL: this should be the url to the root of your web site (i.e. from where the script will run)
- $BZRBINARY: how to invoke bzr. This may simply be “bzr” if it’s in your path.
- $XSLABSOLUTEURL: absolute url to the webbzr.xsl file.
- $CSSABSOLUTEURL: absolute url to the webbzr.css file.
Move back to the webbzr directory (cd ..) and edit the .htaccess file. Next to the RewriteRule, make sure the url to the webbzr.php is fine. By default, it expects to be in /.webbzr/webbzr.php
3. Install
Copy the .htaccess file to the root of your browsing directory. Next to it, copy the .webbzr/ directory with the webbzr.php, config.php, webbzr.css, webbzr.xsl and the img/ directory.
4. Try it
And let me know if it works…

Hey,
I’m searching for a way to offer a webinterface to bazaar on my website. Unfortunately my website is running on a shared host which makes it impossible to install additional software. But as my webspace supports python and ruby on rails scripts, I just wanted to ask if your website is running on a shared host, too, or if you own a dedicated server.
If your site is running on a shared host, too, can you please tell me how you managed the bazaar setup on the server?
Thanks for any help and the cool php script
.
Ben
Hello Ben,
This site and http://bazaar.enseed.com/ are on a shared server. The only requirement is that you install bzr. I have posted instructions to do that as a user (for when you cannot sudo) here: http://thoughts.enseed.com/installing-bazaar-bzr-locally-on-a-web-host/
You will end up with a bzr binary in your ~/bin which will be used by webbzr. Let me know if you’re having troubles.
Hi,
I want to use bzr on my university project. I’ve installed bzr on school shared server and tried to install webbzr. I faild. Don’t know where.
I’m getting internal server error 500. When I rename .htaccess file this error gones.
I have Apache 2.0 and php 5.1.4, here is my php info http://www.ee.pw.edu.pl/~gargaso/phpinfo.php if it may help.
I don’t fully understand how to modyfy .htaccess. I’ve done it this way:
RewriteRule ^(.*)$ /home/ee/stud/gargaso/WWW/.webbzr/webbzr.php?path=$1 [L,QSA]
where /home/ee/stud/gargaso/WWW/ is my full path to the public html folder.
Thanks for any support.
Oskar
PS Please contact me on my mail if you can. Thanks.
Hi. Webbzr is great, it’s replaced my loggerhead install and uses less resources. Unfortunately, I can’t seem to use the “bzr branch” feature for branching code that webbzr has. i.e. If you goto tim.purewhite.id.au/code/handbrake-cluster/ you can see all the code in webbzr no problem. However using ‘bzr branch http://tim.purewhite.id.au/code/handbrake-cluster/‘ fails with a connection closed error message.
On the server I see an OPTIONS request, and then a POST request to /code/handbrake-cluster/.bzr/smart which when accessed via the web interface gives me a blank page. the .bzr part works, it’s the /smart part that doesn’t. Am I missing something with the install? This is running on a Nginx frontend proxying to php-fpm.
Thanks
Tim