From bdda9770e7749533ef1c0e2f5ced25b0afdd9318 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 15 Sep 2011 16:14:01 +0530 Subject: [PATCH 1/7] added cgi-bin/getfile.cgi for bc --- cgi-bin/README.md | 1 + cgi-bin/getfile.cgi | 83 +++++++++++++++++++++++++++++++++++++++++++++ index.cgi | 1 - 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 cgi-bin/README.md create mode 100644 cgi-bin/getfile.cgi diff --git a/cgi-bin/README.md b/cgi-bin/README.md new file mode 100644 index 0000000000..0ea0779468 --- /dev/null +++ b/cgi-bin/README.md @@ -0,0 +1 @@ +## Deprecated \ No newline at end of file diff --git a/cgi-bin/getfile.cgi b/cgi-bin/getfile.cgi new file mode 100644 index 0000000000..6b113057dc --- /dev/null +++ b/cgi-bin/getfile.cgi @@ -0,0 +1,83 @@ +#!/usr/bin/python + +try: + + import sys, os + + sys.path.append('../lib/py') + sys.path.append('../erpnext') + + def getTraceback(): + import sys, traceback, string + type, value, tb = sys.exc_info() + body = "Traceback (innermost last):\n" + list = traceback.format_tb(tb, None) \ + + traceback.format_exception_only(type, value) + body = body + "%-20s %s" % (string.join(list[:-1], ""), list[-1]) + return body + + import cgi + import webnotes + import webnotes.auth + import webnotes.utils + import webnotes.utils.file_manager + import webnotes.db + import webnotes.defs + + sys.path.append(webnotes.defs.modules_path) + + form = cgi.FieldStorage() + webnotes.form_dict = {} + + for each in form.keys(): + webnotes.form_dict[each] = form.getvalue(each) + + n = form.getvalue('name') + + # authenticate + webnotes.auth.HTTPRequest() + + # get file + res = webnotes.utils.file_manager.get_file(n) + + fname = res[0] + if hasattr(res[1], 'tostring'): + fcontent = res[1].tostring() + else: + fcontent = res[1] + + if form.getvalue('thumbnail'): + tn = webnotes.utils.cint(form.getvalue('thumbnail')) + try: + from PIL import Image + import cStringIO + + fobj = cStringIO.StringIO(fcontent) + image = Image.open(fobj) + image.thumbnail((tn,tn*2), Image.ANTIALIAS) + outfile = cStringIO.StringIO() + + if image.mode != "RGB": + image = image.convert("RGB") + + image.save(outfile, 'JPEG') + outfile.seek(0) + fcontent = outfile.read() + except: + pass + + import mimetypes + print "Content-Type: %s" % (mimetypes.guess_type(fname)[0] or 'application/unknown') + print "Content-Disposition: filename="+fname.replace(' ', '_') + print "Cache-Control: max-age=3600" + print + print fcontent + +except Exception, e: + print "Content-Type: text/html" + try: + out = {'message':'', 'exc':getTraceback().replace('\n','
')} + except: + out = {'exc': e} + print + print str(out) diff --git a/index.cgi b/index.cgi index da52ef1186..3d61c56052 100755 --- a/index.cgi +++ b/index.cgi @@ -9,7 +9,6 @@ sys.path.append('lib/py') sys.path.append('erpnext') import webnotes -import webnotes.defs webnotes.form = cgi.FieldStorage() From 61c7a4ca815b5dbf6f51f90eba75dd3d0cca3dad Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 15 Sep 2011 16:17:03 +0530 Subject: [PATCH 2/7] perms of cgi-bin/getfile.cgi --- cgi-bin/getfile.cgi | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 cgi-bin/getfile.cgi diff --git a/cgi-bin/getfile.cgi b/cgi-bin/getfile.cgi old mode 100644 new mode 100755 From df08f45391e8350be66bf8b87bc16baf2c21989f Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 15 Sep 2011 17:10:25 +0530 Subject: [PATCH 3/7] version fix --- index.html | 2 +- versions-master.db | Bin 461824 -> 461824 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 5d45b5f795..c33d163ceb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ ERPNext -