Introduction
I recently discovered that the bittorrent application µtorrent
contained a Web interface. I eventually got it up and running and thought it was pretty neat. I wanted to customize it and make it my own. So, I searched the Web and came across a set of C# classes that hooked into the official µtorrent
Web UI. The original posting is located here. In that same posting, there was also a post about an ASP.NET interface using the C# classes. I tested it out, and thought I could build my own and overcome some of the quirks it had. I also thought it would be a test of what was possible with AJAX.
Background
Getting it up and running should be fairly straightforward. What is needed is IIS, .NET 3.5, and a recent version of µtorrent
with the Web UI enabled. If you have trouble running the site, you may also need the AJAX Control Toolkit. There is also a Windows service that gathers stats for each of the torrents.
Screenshots
Figure 1. The Settings page that is displayed when the Settings link is clicked, on first run, or when there is an error within the configuration.
Figure 2. The primary page that is displayed. It contains the list of torrent types in a listbox, the torrents in a GridView, a tab control with a formview for general information and a GridView listing the files. On this page is a DropDownList to change the site theme, a link to the settings, and a link to view the logs. Also on this page is a section to start new torrents from either a URL or from a file.
Figure 3. After clicking the Details link from the torrent GridView, the general tab will list the information about a torrent.
Figure 4. After clicking the Details link from the torrent GridView, the files tab will list the files and their status of a torrent.
Figure 5. The log viewer will list all of the information about the logs. The GridView features a DropDownList for each field that can be used to filter the logs.
Figure 6. The Stats tab contains a dynamically updated graph of the stats of the current torrent. The X and Y axis are selected by the two ListBoxes above the graph. A third-party graphing utility,
SasqChart, was used for the graphs.
Using the Code
To get started, copy the files to your server's directory. Make sure that the directory is configured as an application. Open your Web browser and point it towards the URL of the directory you created. The first time the application runs, it will detect that the settings are invalid and will prompt you to enter them. Once completed, click the Save button to commit the changes. If you wish to encrypt the information within the web.config, you can click the Link Button on the Settings page to do that. If you click it and go through the confirmation, the appSettings
section of the web.config will be encrypted.
I decided to use the HTTP Compression features of this project in the hopes of speeding things up a bit.
I also added in an extremely simple HttpModule
to handle the security since I did not want to mess with or rely on the IIS security. In a shared hosting environment, you also might not have easy access to that. The web.config contains an accesslist
setting that is a comma delimited string
of the IP addresses that can access the site. If this is not needed, then all you have to do is remove the SecurityHttpModule
entry in the web.config or leave the entry on the Settings page blank.
I have updated this article to include a Windows service that will gather stats for each of the torrents. The installation of the service is very simple. The application can run as either a console application or as a Windows service. I came up with the idea from this Code Project article. To run it as a console application, run the application without any arguments. To run the application as a service, run it with a –service
argument. To remove the service from the system, run the application with a –removeservice
argument.
To install, extract the compiled binaries and the application configuration file to a directory. Set up the application configuration file as needed. Install the application as a service (run once with a –service
argument) or setup a Task Scheduler task to execute the application without any arguments.
One last option to consider. The performance of the site can be greatly improved by setting the debug setting in the web.config to false
. This is mainly due to the AJAX Control Toolkit and the difference in the scripts it sends to the client.
There are still some quirks, but overall, it gets the job done; whatever that may be!
Features
Here is a list of some of the features of this project:
- Uses AJAX to display the data from
µtorrent
, providing a simple Web interface that is accessible by most browsers. - The page is updated with
UpdatePanels
by an AJAX Timer control. - The
GridView
s support paging and sorting from within the Update Panel. - New torrents can be added via new files or via URLs.
- An Update Progress Control is used to display a Loading... animation in the top left corner. It can be configured with stylesheets or themes.
- I have imported all of the auto-format themes from Visual Studio into *.theme files to support Website theming.
- The
logviewer
features a GridView
with a neat feature - filtering. The distinct values of each column are displayed in a DropDownList
in the column header that can be used to filter the data in the GridView
. - A logging utility was created to facilitate the logging. Logs can be in either a tab delimited text file or an XML file. I have included an XSLT file to transform the XML log file from being element based to attribute based; some controls (
GridView
, etc.) prefer attribute based, others (TreeView
) prefer element based. This would be needed if you want to bind the log data to other control types.
- A very simple security utility was created that will filter requests by IP Address.
- A method of getting distinct values from a column in a datatable was created.
- A historical stats history of each torrent. You can choose the X and Y axis on demand.
Points of Interest
None really yet. Comments and criticisms are welcome.