def insert_file(filepath, user, con=connect(), rkey='0', mkey=None): #print db_type if not mkey: key = rand_alpha_numeric(15) else: key = mkey date = time.asctime(time.gmtime()) con = connect() #try: cursor = con.cursor() query = (key, key, filepath, user, date, rkey) #print query if db_type == 'sqlite': cursor.execute( 'insert into files(fkey, name, path, user, time, rkey) values (?,?,?,?,?,?)', query) elif db_type == 'mysql': cursor.execute( 'insert into files(fkey, name, path, user, time, rkey) values (%s,%s,%s,%s,%s,%s)', query) con.commit() #except pymysql.err.InternalError, e: # print e[0]," ",e[1] # return None con.close() return key
def insert_file(filepath, user, con=connect(), rkey='0',mkey=None): #print db_type if not mkey: key=rand_alpha_numeric(15) else: key = mkey date=time.asctime(time.gmtime()) con = connect() #try: cursor = con.cursor() query = (key, key, filepath, user, date, rkey) #print query if db_type == 'sqlite': cursor.execute('insert into files(fkey, name, path, user, time, rkey) values (?,?,?,?,?,?)', query) elif db_type == 'mysql': cursor.execute('insert into files(fkey, name, path, user, time, rkey) values (%s,%s,%s,%s,%s,%s)', query) con.commit() #except pymysql.err.InternalError, e: # print e[0]," ",e[1] # return None con.close() return key
def index(self, batch=None): if not (cherrypy.session.get('login') == True) and not ( cherrypy.session.get('ip') == cherrypy.request.remote.ip): raise cherrypy.HTTPRedirect(["/login/"], 302) if cherrypy.request.scheme == 'https': raise cherrypy.HTTPRedirect( ["http://files.tech-keys.com:446/upload/"], 302) if batch: mkey = batch else: mkey = rand_alpha_numeric(15) return render( title="Upload", content=""" <div class="container"> <!-- The file upload form used as target for the file upload widget --> <form id="fileupload" action="http://""" + settings['hostname'] + ':' + str(settings['port']) + """/upload/do" method="post" enctype="multipart/form-data"> <div class="row" style="text-align:center;font-size:30px;padding-bottom:15px;line-height:33px;">Download entire batch (zip): <a href="http://""" + settings['hostname'] + ':' + str(settings['port']) + """/file/""" + mkey + """">http://""" + settings['hostname'] + ':' + str(settings['port']) + """/file/""" + mkey + """</a></div> <div class="row" style="text-align:center;font-size:20px;padding-bottom:20px;"><a href="javascript:delete_key('""" + mkey + """')">Delete the entire batch</a></div> <div class="row" style="text-align:center;font-size:20px;padding-bottom:20px;">Friendly name: <input id="batchname" type="text" class="textfield"></div> <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> <div class="row fileupload-buttonbar centered"> <div class="span7"> <!-- The fileinput-button span is used to style the file input field as button --> <span class="btn btn-success fileinput-button"> <i class="icon-plus icon-white"></i> <span>Add files...</span> <input type="file" name="myFile" multiple=""> </span> <span class="btn btn-success fileinput-button"> <i class="icon-plus icon-white"></i> <span>Add folder...</span> <input type="file" name="myFile" multiple="" webkitdirectory="true" directory="" title="Only works with Google Chrome 11+"> </span> <button type="submit" class="btn btn-primary start"> <i class="icon-upload icon-white"></i> <span>Start upload</span> </button> <button type="reset" class="btn btn-warning cancel"> <i class="icon-ban-circle icon-white"></i> <span>Cancel upload</span> </button> <button type="button" class="btn btn-danger delete" title="Delete from batch and server"> <i class="icon-trash icon-white"></i> <span>Delete</span> </button> <input type="checkbox" class="toggle" title="Select all"> <input type="hidden" id="key" name="key" value=\"""" + mkey + """\"> </div> </div> <br> <!-- The loading indicator is shown during image processing --> <div class="row" style="text-align:center;font-size:25px;padding-bottom:30px;color:grey;" title="Folders not yet supported by browers. IE not supported.">Drag and drop files below</div> <div class="row fileupload-buttonbar centered"> <div class="span5" style="width:100%; text-align:center; margin:0px;"> <!-- The global progress bar --> <div class="progress progress-success progress-striped active fade"> <div class="bar" style="width:0%;"></div> </div> </div> </div> <div class="fileupload-loading"></div> <br> <!-- The table listing the files available for upload/download --> <table class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table> </form> </div> <!-- modal-gallery is the modal dialog used for the image gallery --> <div id="modal-gallery" class="modal modal-gallery hide fade" data-filter=":odd"> <div class="modal-header"> <a class="close" data-dismiss="modal"></a> <h3 class="modal-title"></h3> </div> <div class="modal-body"><div class="modal-image"></div></div> <div class="modal-footer"> <a class="btn modal-download" target="_blank"> <i class="icon-download"></i> <span>Download</span> </a> <a class="btn btn-success modal-play modal-slideshow" data-slideshow="5000"> <i class="icon-play icon-white"></i> <span>Slideshow</span> </a> <a class="btn btn-info modal-prev"> <i class="icon-arrow-left icon-white"></i> <span>Previous</span> </a> <a class="btn btn-primary modal-next"> <span>Next</span> <i class="icon-arrow-right icon-white"></i> </a> </div> </div> <!-- The template to display files available for upload --> <script id="template-upload" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %} <tr class="template-upload fade"> <td class="preview"><span class="fade"></span></td> <td class="name"><span>{%=file.name%}</span></td> <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> {% if (file.error) { %} <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td> {% } else if (o.files.valid && !i) { %} <td> <div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div> </td> <td class="start">{% if (!o.options.autoUpload) { %} <button class="btn btn-primary"> <i class="icon-upload icon-white"></i> <span>{%=locale.fileupload.start%}</span> </button> {% } %}</td> {% } else { %} <td colspan="2"></td> {% } %} <td class="cancel">{% if (!i) { %} <button class="btn btn-warning"> <i class="icon-ban-circle icon-white"></i> <span>{%=locale.fileupload.cancel%}</span> </button> {% } %}</td> </tr> {% } %} </script> <!-- The template to display files available for download --> <script id="template-download" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %} <tr class="template-download fade"> {% if (file.error) { %} <td></td> <td class="name"><span>{%=file.name%}</span></td> <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td> {% } else { %} <td class="preview">{% if (file.thumbnail_url) { %} <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a> {% } %}</td> <td class="name"> <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a> </td> <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> <td colspan="2"></td> {% } %} <td class="delete"> <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"> <i class="icon-trash icon-white"></i> <span>{%=locale.fileupload.destroy%}</span> </button> <input type="checkbox" name="delete" value="1"> </td> </tr> {% } %} </script> <!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included --> <script src="/static/js/vendor/jquery.ui.widget.js"></script> <!-- The Templates plugin is included to render the upload/download listings --> <script src="/static/js/tmpl.min.js"></script> <!-- The Load Image plugin is included for the preview images and image resizing functionality --> <script src="/static/js/load-image.min.js"></script> <!-- The Canvas to Blob plugin is included for image resizing functionality --> <script src="/static/js/canvas-to-blob.min.js"></script> <!-- Bootstrap JS and Bootstrap Image Gallery are not required, but included for the demo --> <script src="/static/js/bootstrap.min.js"></script> <script src="/static/js/bootstrap-image-gallery.min.js"></script> <!-- The Iframe Transport is required for browsers without support for XHR file uploads --> <script src="/static/js/jquery.iframe-transport.js"></script> <!-- The basic File Upload plugin --> <script src="/static/js/jquery.fileupload.js"></script> <!-- The File Upload image processing plugin --> <script src="/static/js/jquery.fileupload-ip.js"></script> <!-- The File Upload user interface plugin --> <script src="/static/js/jquery.fileupload-ui.js"></script> <!-- The localization script --> <script src="/static/js/locale.js"></script> <!-- The main application script --> <script src="/static/js/main.js"></script> <!-- The XDomainRequest Transport is included for cross-domain file deletion for IE8+ --> <!--[if gte IE 8]><script src="/static/js/cors/jquery.xdr-transport.js"></script><![endif]--> """, login=True)
def create_unique_temp_dir(): if not (os.path.isdir(get_upload_path() + "temp")): os.mkdir(get_upload_path() + "temp") randdir = get_upload_path() + "temp" + os.path.sep + rand_alpha_numeric(10) os.mkdir(randdir) return randdir
def index(self, batch=None): if not (cherrypy.session.get('login') == True) and not (cherrypy.session.get('ip') == cherrypy.request.remote.ip): raise cherrypy.HTTPRedirect(["/login/"], 302) if cherrypy.request.scheme == 'https': raise cherrypy.HTTPRedirect(["http://files.tech-keys.com:446/upload/"], 302) if batch: mkey = batch else: mkey = rand_alpha_numeric(15) return render(title="Upload", content=""" <div class="container"> <!-- The file upload form used as target for the file upload widget --> <form id="fileupload" action="http://"""+settings['hostname']+':'+str(settings['port'])+"""/upload/do" method="post" enctype="multipart/form-data"> <div class="row" style="text-align:center;font-size:30px;padding-bottom:15px;line-height:33px;">Download entire batch (zip): <a href="http://"""+settings['hostname']+':'+str(settings['port'])+"""/file/"""+mkey+"""">http://"""+settings['hostname']+':'+str(settings['port'])+"""/file/"""+mkey+"""</a></div> <div class="row" style="text-align:center;font-size:20px;padding-bottom:20px;"><a href="javascript:delete_key('"""+mkey+"""')">Delete the entire batch</a></div> <div class="row" style="text-align:center;font-size:20px;padding-bottom:20px;">Friendly name: <input id="batchname" type="text" class="textfield"></div> <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> <div class="row fileupload-buttonbar centered"> <div class="span7"> <!-- The fileinput-button span is used to style the file input field as button --> <span class="btn btn-success fileinput-button"> <i class="icon-plus icon-white"></i> <span>Add files...</span> <input type="file" name="myFile" multiple=""> </span> <span class="btn btn-success fileinput-button"> <i class="icon-plus icon-white"></i> <span>Add folder...</span> <input type="file" name="myFile" multiple="" webkitdirectory="true" directory="" title="Only works with Google Chrome 11+"> </span> <button type="submit" class="btn btn-primary start"> <i class="icon-upload icon-white"></i> <span>Start upload</span> </button> <button type="reset" class="btn btn-warning cancel"> <i class="icon-ban-circle icon-white"></i> <span>Cancel upload</span> </button> <button type="button" class="btn btn-danger delete" title="Delete from batch and server"> <i class="icon-trash icon-white"></i> <span>Delete</span> </button> <input type="checkbox" class="toggle" title="Select all"> <input type="hidden" id="key" name="key" value=\""""+mkey+"""\"> </div> </div> <br> <!-- The loading indicator is shown during image processing --> <div class="row" style="text-align:center;font-size:25px;padding-bottom:30px;color:grey;" title="Folders not yet supported by browers. IE not supported.">Drag and drop files below</div> <div class="row fileupload-buttonbar centered"> <div class="span5" style="width:100%; text-align:center; margin:0px;"> <!-- The global progress bar --> <div class="progress progress-success progress-striped active fade"> <div class="bar" style="width:0%;"></div> </div> </div> </div> <div class="fileupload-loading"></div> <br> <!-- The table listing the files available for upload/download --> <table class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table> </form> </div> <!-- modal-gallery is the modal dialog used for the image gallery --> <div id="modal-gallery" class="modal modal-gallery hide fade" data-filter=":odd"> <div class="modal-header"> <a class="close" data-dismiss="modal"></a> <h3 class="modal-title"></h3> </div> <div class="modal-body"><div class="modal-image"></div></div> <div class="modal-footer"> <a class="btn modal-download" target="_blank"> <i class="icon-download"></i> <span>Download</span> </a> <a class="btn btn-success modal-play modal-slideshow" data-slideshow="5000"> <i class="icon-play icon-white"></i> <span>Slideshow</span> </a> <a class="btn btn-info modal-prev"> <i class="icon-arrow-left icon-white"></i> <span>Previous</span> </a> <a class="btn btn-primary modal-next"> <span>Next</span> <i class="icon-arrow-right icon-white"></i> </a> </div> </div> <!-- The template to display files available for upload --> <script id="template-upload" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %} <tr class="template-upload fade"> <td class="preview"><span class="fade"></span></td> <td class="name"><span>{%=file.name%}</span></td> <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> {% if (file.error) { %} <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td> {% } else if (o.files.valid && !i) { %} <td> <div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div> </td> <td class="start">{% if (!o.options.autoUpload) { %} <button class="btn btn-primary"> <i class="icon-upload icon-white"></i> <span>{%=locale.fileupload.start%}</span> </button> {% } %}</td> {% } else { %} <td colspan="2"></td> {% } %} <td class="cancel">{% if (!i) { %} <button class="btn btn-warning"> <i class="icon-ban-circle icon-white"></i> <span>{%=locale.fileupload.cancel%}</span> </button> {% } %}</td> </tr> {% } %} </script> <!-- The template to display files available for download --> <script id="template-download" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %} <tr class="template-download fade"> {% if (file.error) { %} <td></td> <td class="name"><span>{%=file.name%}</span></td> <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td> {% } else { %} <td class="preview">{% if (file.thumbnail_url) { %} <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a> {% } %}</td> <td class="name"> <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a> </td> <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> <td colspan="2"></td> {% } %} <td class="delete"> <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"> <i class="icon-trash icon-white"></i> <span>{%=locale.fileupload.destroy%}</span> </button> <input type="checkbox" name="delete" value="1"> </td> </tr> {% } %} </script> <!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included --> <script src="/static/js/vendor/jquery.ui.widget.js"></script> <!-- The Templates plugin is included to render the upload/download listings --> <script src="/static/js/tmpl.min.js"></script> <!-- The Load Image plugin is included for the preview images and image resizing functionality --> <script src="/static/js/load-image.min.js"></script> <!-- The Canvas to Blob plugin is included for image resizing functionality --> <script src="/static/js/canvas-to-blob.min.js"></script> <!-- Bootstrap JS and Bootstrap Image Gallery are not required, but included for the demo --> <script src="/static/js/bootstrap.min.js"></script> <script src="/static/js/bootstrap-image-gallery.min.js"></script> <!-- The Iframe Transport is required for browsers without support for XHR file uploads --> <script src="/static/js/jquery.iframe-transport.js"></script> <!-- The basic File Upload plugin --> <script src="/static/js/jquery.fileupload.js"></script> <!-- The File Upload image processing plugin --> <script src="/static/js/jquery.fileupload-ip.js"></script> <!-- The File Upload user interface plugin --> <script src="/static/js/jquery.fileupload-ui.js"></script> <!-- The localization script --> <script src="/static/js/locale.js"></script> <!-- The main application script --> <script src="/static/js/main.js"></script> <!-- The XDomainRequest Transport is included for cross-domain file deletion for IE8+ --> <!--[if gte IE 8]><script src="/static/js/cors/jquery.xdr-transport.js"></script><![endif]--> """, login=True)
def gen_session_key(): key = hashlib.sha256() key.update(rand_alpha_numeric(20)) return key.hexdigest()