From de50457bb9037d630be0d21e1422290a00a438ac Mon Sep 17 00:00:00 2001 From: Apkawa Date: Sat, 27 Sep 2008 21:15:22 +0400 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D1=8E?= =?utf8?q?=20=D1=87=D0=B5=D1=80=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=B2?= =?utf8?q?=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D0=BA=D0=BE=D0=BD=D1=81?= =?utf8?q?=D0=BE=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D1=83=D1=82=D0=B8=D0=BB?= =?utf8?q?=D0=B8=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=B7=D0=B0=D0=BB?= =?utf8?q?=D0=B8=D0=B2=D0=BA=D0=B8=20=D0=BD=D0=B0=20rghost.ru?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Apkawa/rghost.ru.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Apkawa/rghost.ru.py diff --git a/Apkawa/rghost.ru.py b/Apkawa/rghost.ru.py new file mode 100644 index 0000000..2fa88c0 --- /dev/null +++ b/Apkawa/rghost.ru.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +import httplib, mimetypes, sys +USER_AGENT = 'Mozilla/5.0 (X11; U; Linux i686; ru-RU; rv:1.9.0.2pre) Gecko/2008072703 Firefox/3.0.2pre (Swiftfox)' + +def get_file_contents(file_name): + f = open(file_name); + data = f.read() + f.close() + return data + +def get_content_type(file_name): + cont_type=mimetypes.guess_type(file_name)[0] or 'application/octet-stream' + return cont_type + +def encode_multipart_formdata(filename): + BOUNDARY = '----------' + CRLF = '\r\n' + L = [] + # add additional form fields + form_vaule = {'authenticity_token':'13619ba0aed720f2c822937f14409450d658b50c'} + + L.append('--' + BOUNDARY) + L.append('Content-Disposition: form-data; name="authenticity_token"') + L.append('') + L.append('13619ba0aed720f2c822937f14409450d658b50c') + L.append('--' + BOUNDARY) + L.append('Content-Disposition: form-data; name="file"; filename="%s"' \ + % (filename)) + L.append('Content-Type: %s' % get_content_type(filename)) + L.append('') + L.append(get_file_contents(filename)) + L.append('--' + BOUNDARY + '--') + L.append('') + body = CRLF.join(L) + content_type = 'multipart/form-data; boundary=%s' % BOUNDARY + + return content_type, body + +def upload_file(filename): + cookie = '_rghost_session=BAh7CDoMY3NyZl9pZCIlMjYzMjY4MzBiNGUwNzE0NWI3ODBlODhmNmNmYTk1ZTgiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA6CWxhbmciCnJ1LVJV--bd4e9c60b4a8ccb5a6b9f797bdc07a4265150872' + content_type, body = encode_multipart_formdata(filename) + header = httplib.HTTPConnection('phonon.rghost.ru') + header.putrequest('POST', '/files') + header.putheader('User-Agent', USER_AGENT) + header.putheader('Cookie',cookie) + header.putheader('Content-Type', content_type) + header.putheader('Content-Length', str(len(body))) + header.endheaders() + header.send(body) + #header.set_debuglevel(1) + return header.getresponse() + +if __name__ == '__main__': + filename = sys.argv[1] + print upload_file(filename).getheader('location') + + -- 2.11.4.GIT