Jump to content

.NET library for Utorrent WebUI


Jipy

Recommended Posts

Posted

I'm developing a .NET library for the UTorrent WebUI, you'll find it on a svn :

http://88.191.26.230/UTorrentLib

Login : utorrent / utorrent

It comes with a very simple Gui, to show how to use the lib with windows forms.

Simple gui example :

dd.png

Edit2: For IE only online Gui launcher : Here

P.S: if you have some time feel free to help :P

P.S 2 : Not really documented yet.

  • 5 weeks later...
  • 4 weeks later...
Posted

Hi Jippy..

I have downloaded and started to use your code in a attempt enclose the webiu within an ASP.NET 2.0 webapplication (this to higher the security level, i my case let IIS, windows server & security policies handle brute force attack etc.).

Doing this I have used your nice code.

However I have changed som of your code (e.g refactored the 'UpdateLists' method and added a mtheod called 'StartNewTorrent' within the TorrentSession class.)

If you are intressted in the changes / additions (or want a look at the ASP.NET project in progress please let me know)

Best regards!

smithimage

Posted

Hi smithimage, i try make web app on uTorrent Web UI with multiuser, forum, statistics and other features. I tryed Jippy's library, but I had some problems.

I´m interested in your project and I can help you with developing. Could you tell me something about your idea and show me your project?

Thanks, Lukas.

Posted

Ok I've been busy lately, I've just moved in Montreal.

I'll resume my work on the lib starting tomorrow. I'm interrested in your changes, can you contact me by msn or mail (jipy666(at)hotmail(dot)com)

Posted

Hi there Jipy and taxik.

I have now published my work and the changes I made at this address :

http://www.smithimage.com/home/development.aspx

My basic idea was / is just to make it "safely", publicly (but restricted) publishable on a windows server (i.e. asp.NET). This since the security implemented in the webui as is don't implement any brute force security checks (as far as I could figure out anyhow). My idea is just to use the C# UTorrentlib and wire a simple (ajax enabled) asp.net UI around the UTorrentlib and let IIS-folder security and security policies (or any other security solution usable within the asp.net) handle multiple faulty login tries (with lookout rules).

This by publicly publish this restricted asp.net application on my webserver (on port 80) having the UTorrent WebUI running behind the firewall on a port not publicly visable from outside the firewall.

Please have in mind this is a work in progress just started, but don't hesitate to make any remark in regard to the idea or problem solution..

Best regards!

smithimage

  • 4 weeks later...
Posted

Hi smithimage, good job...

I like your WebUI. Do you have a new realease? Because I must start on my multiuser WebUI. I have extern app, that can start torrents to directory of every user, but I need UI with better loggin and with session of every user.

Taxik.

  • 2 months later...
  • 1 month later...
Posted

hi everyone

I have downloaded this .net code. I get hazy when i debug it and check for UTorrentStatus field in torrent object. I found its 233/201. it means more than 1 state is set in that long variable. why is it like this? 233 means start,pause states are set. but the torrent is in pause mode. i can find out by ANDing it but the problem is when both are set in 233 case what should i take?

one more thing. start,stop,pause actions do not update internal data structures about modified torrents. The code given here calls updateLists() periodically and updates internal structures which reflect new values. I dont want to call updateList() periodically in my project. to overcome this problem what i did is , i called updateLists() method whenever i do any action(like start,stop,pause) on any torrent.

somebody pls help me out

Posted

hello

When we add a torrent file from webUI it makes a HTTP POST request and sends the torrent file right. I have done multipart/form-data post but the result is error.Torrent logger shows "?action=add-file" in its log, but that doesn't mean success or failure. I did not find this piece of code in the .NET library i downloaded here. pls find the c# code here and correct me where i'm wrong.

c# code

==============================================================

HttpWebRequest ts = (HttpWebRequest)HttpWebRequest.Create("http://" + this.m_strHostname + ":" + this.m_iPort.ToString() + "/gui/" + request);

ts.KeepAlive = false;

ts.Headers.Add("Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(this.m_strUsername + ":" + this.m_strPassword)));

string postdata = "";

string boundary = "------------------------BoundaryLine";

postdata += "\r\n"+"--" + boundary + "\r\n";

postdata += "Content-Disposition: form-data; name=\"file\" filename=\""+new FileInfo(torrentFilePath).Name+"\""+"\r\n";

postdata += "Content-Type: application/x-bittorrent" + "\r\n";//+ getContentType(@torrentFilePath) + "\r\n";

postdata += "" + "\r\n";

char[] chartowrite1 = postdata.ToCharArray();

byte[] w1 = Encoding.ASCII.GetBytes(postdata);

postdata = "\r\n" + "--" + boundary + "--\r\n";

char[] chartowrite2 = postdata.ToCharArray();

byte[] w2 = Encoding.ASCII.GetBytes(postdata);

//fileBytes contains the torrenfile contents . its type is byte[]

byte[] bytesToWrite = new byte[w1.Length + w2.Length + fileBytes.Length];

int index = 0;

for (int i = 0; i < w1.Length; i++)

{

bytesToWrite[index + i] = (byte)w1;

}

index += w1.Length;

for(int i=0; i<fileBytes.Length;i++)

{

bytesToWrite[index+i]=fileBytes;

}

index += fileBytes.Length;

for (int i = 0; i < w2.Length; i++)

{

bytesToWrite[index + i] = (byte)w2;

}

ts.Method = "POST";

ts.ContentType = "multipart/form-data; boundary=" + boundary;

ts.ContentLength = bytesToWrite.Length;

Stream writeStream = ts.GetRequestStream();

writeStream.Write(bytesToWrite, 0, bytesToWrite.Length);

writeStream.Close();

resp = (HttpWebResponse)ts.GetResponse();

StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);

String response = responseReader.ReadToEnd();

Object GuiResp = JavaScriptConvert.DeserializeObject(response);

=========================================================

data posted looks like this.

--------------------------BoundaryLine

Content-Disposition: form-data; name="file" filename="TorrentSession.cs.torrent"

Content-Type: application/x-bittorrent

d10:created by13:uTorrent/177013:creation datei1213169314e8:encoding5:UTF-84:inf

od6:lengthi12615e4:name17:TorrentSession.cs12:piece lengthi65536e6:pieces20:?6?"

·]û¬ºù♫↓?↔µ↓Y▲►ee

--------------------------BoundaryLine--

=============================================================

in the content-disposition i tried name="torrent_file" also but of no use.

GuiResp at the end of code shows error as the response.

some one pls help me out adding torrent

Posted

Hi,

This looks great but i am getting an error when testing your sample. IT also happens when i call the code in my version.

here is the error

"The given key was not present in the dictionary."

this is the line throwing the exeption

JavaScriptArray mjsTorrents = (JavaScriptArray)GuiResp["torrentp"]; // More code below

here is the code sample generating the error:

 public void UpdateLists()
{

//Sending request and retrieving response.
JavaScriptObject GuiResp = GetResponseFromUi("?list=1&cid=" + this.m_strLastCache);
this.m_strLastCache = (String)GuiResp["torrentc"];
//Creating a List of the modified torrents.
List<JavaScriptArray> mTorrents = new List<JavaScriptArray>();
JavaScriptArray mjsTorrents = (JavaScriptArray)GuiResp["torrentp"];
for (int i = 0; i < mjsTorrents.Count; i++)
{
mTorrents.Add((JavaScriptArray)mjsTorrents[i]);
}

and full exeption detail

System.Collections.Generic.KeyNotFoundException was unhandled

Message="The given key was not present in the dictionary."

Source="mscorlib"

StackTrace:

at System.ThrowHelper.ThrowKeyNotFoundException()

at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

at UTorrentLib.TorrentSession.UpdateLists() in C:\Users\Tyron\Desktop\New Folder\UTorrentLib\TorrentSession.cs:line 122

at UtorrentApp.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Tyron\Documents\Visual Studio 2008\Projects\Utorrent\Utorrent\Form1.cs:line 28

at System.Windows.Forms.Form.OnLoad(EventArgs e)

at System.Windows.Forms.Form.OnCreateControl()

at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

at System.Windows.Forms.Control.CreateControl()

at System.Windows.Forms.Control.WmShowWindow(Message& m)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

at System.Windows.Forms.ContainerControl.WndProc(Message& m)

at System.Windows.Forms.Form.WmShowWindow(Message& m)

at System.Windows.Forms.Form.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)

at System.Windows.Forms.Control.SetVisibleCore(Boolean value)

at System.Windows.Forms.Form.SetVisibleCore(Boolean value)

at System.Windows.Forms.Control.set_Visible(Boolean value)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.Run(Form mainForm)

at UtorrentApp.Program.Main() in C:\Users\Tyron\Documents\Visual Studio 2008\Projects\Utorrent\Utorrent\Program.cs:line 19

at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

InnerException:

Posted

Hi

I have a reason why you are getting KeyNotFoundException. If the response from utorrent client doesn't contain records for "torrentp", you will get this exception. Because without checking whether there is any record with key "torrentp" you are trying to get results for it. The code which you have is outdated. There is a new code for updateList() where there is check for the key something like below

JavaScriptObject GuiResp = GetResponseFromUi("?list=1&cid=" + this.m_strLastCache);

this.m_strLastCache = (String)GuiResp["torrentc"];

//Creating a List of the modified torrents.

List<JavaScriptArray> mTorrents = new List<JavaScriptArray>();

if(GuiResp.ContainsKey("torrentp")

{

JavaScriptArray mjsTorrents = (JavaScriptArray)GuiResp["torrentp"];

for (int i = 0; i < mjsTorrents.Count; i++)

{

mTorrents.Add((JavaScriptArray)mjsTorrents);

}

}

If any of you have code to POST torrent file pls share with me. I need it immediately

Posted

I haven't done .Net programing in a while, but I can offer you the way to do it in Javascript

should be simple enough to change around to either C# or whatever language you use in your .Net

well, lets just say your also missing a semicolon after your file="torrent_file"

but otherwise I can't really see much of an error in your coding...

and IDK about this, wouldn't it be easier to create a binaryWriter than to convert it using that method. Also just for pretifying code, wouldn't it be easier to create a function to write your bytes for you, i mean you are essentially calling the same code 3 times. Bleh, nvm me I'm not the one to talk about making code efficient :). Anyways... I think thats your problem though, i haven't really tested it... But thats what I think you are missing the semicolon.

BTW >>> code is from the uTorrent firefox extension, and isn't written by me

var multipartBoundary = "=*=*=*=*=*=";

function writeBinary(ostream, string)
{
for(i=0; i != string.length; ++i)
{
ostream.write8(string.charAt(i));
}
}


function addTorrent(uri, torrentData)
{
var body = Components.classes["@mozilla.org/storagestream;1"]
.createInstance(Components.interfaces.nsIStorageStream);
body.init(1024, 1024*1024, null);
var bodyOutput = body.getOutputStream(0);
var bodyBinary = Components.classes["@mozilla.org/binaryoutputstream;1"]
.createInstance(Components.interfaces.nsIBinaryOutputStream);
bodyBinary.setOutputStream(bodyOutput);

var filename = getFilenameFromUri(uri);

writeBinary(bodyBinary,
"--" + multipartBoundary + "\r\n" +
"Content-Disposition: form-data; name=\"torrent_file\"; filename=\"" + filename + "\"\r\n" +
"Content-Type: application/x-bittorrent\r\n" +
"\r\n");
writeBinary(bodyBinary, torrentData);
writeBinary(bodyBinary, "\r\n--" + multipartBoundary + "--\r\n");
bodyOutput.close();

var request = new XMLHttpRequest();
request.open("POST", gUTorrentPrefs.getConnectionType() + "://" + gUTorrentPrefs.serverAddress() + ":" + gUTorrentPrefs.serverPort() +
"/gui/?action=add-file", true, gUTorrentPrefs.adminUsername(), gUTorrentPrefs.adminPassword());
request.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + multipartBoundary);
request.onreadystatechange = function(event)
{
if (request.readyState == 4)
{
if (request.status == 200)
{
var response = request.responseText.parseJSON();
var message = response.error;
if (message != null)
displayError("uTorrent responded with an error for torrent \"" + uri.spec + "\". The error was: " + message);
}
else
{
displayError("Error uploading torrent file \"" + uri.spec +
"\" to uTorrent. Error code was " + request.status + ".");
}
}
};

var bodyInput = bodyOutput.newInputStream(0);
request.send(bodyInput);
}

  • 4 months later...
Posted

Hi everyone,

What ever became of this library?

I am looking for a way to hook into uTorrent, which I found has to be the webUI. I then found references to this wrapper, which I would like to check out. However I am not able to get contact to the SVN and checkout the source using TortoiseSVN.

Can anyone confirm if this project is dead or still in development?

Thanks,

Bo

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...