Ejemplo n.º 1
0
    def dosingle(self, myFile):
        if not (cherrypy.session.get('login') == True) and not (
                cherrypy.session.get('ip') == cherrypy.request.remote.ip):
            raise cherrypy.HTTPRedirect(["/login/"], 302)
        fpath = get_upload_path() + myFile.filename
        while os.path.exists(fpath):
            pathparts = fpath.split('.')
            pathparts[-2] += '_'
            fpath = ''
            for part in pathparts:
                fpath += part + '.'
            fpath = fpath[:-1]

        f = open(fpath, 'wb')
        size = 0
        while True:
            data = myFile.file.read(8192)
            if not data:
                break
            f.write(data)
            size += len(data)
        f.close()
        conn = sqlite3.connect(settings['db_name'])
        key = db.insert_file(fpath, cherrypy.session.get('user'), conn)

        hostaddr = cherrypy.request.local.ip
        hostport = cherrypy.request.local.port

        if hostaddr == '':
            hostaddr = 'localhost'
        print hostaddr
        if hostport != 80:
            absfilepath = '%s://%s:%s/file/%s/%s' % (cherrypy.request.scheme,
                                                     hostaddr, hostport, key,
                                                     myFile.filename)
        else:
            absfilepath = 'http://%s/file/%s/%s' % (hostaddr, key,
                                                    myFile.filename)

        return render(title="Upload complete",
                      content="""<h2>Upload Complete!</h2><br>
                                                        <div style="padding-left:15px;">The url for your file is:<br> %s</div>"""
                      % absfilepath)
Ejemplo n.º 2
0
    def dosingle(self, myFile):
        if not (cherrypy.session.get('login') == True) and not (cherrypy.session.get('ip') == cherrypy.request.remote.ip):
            raise cherrypy.HTTPRedirect(["/login/"], 302)
        fpath = get_upload_path()+myFile.filename
        while os.path.exists(fpath):
            pathparts = fpath.split('.')
            pathparts[-2]+='_'
            fpath = ''
            for part in pathparts:
                fpath += part + '.'
            fpath = fpath[:-1]
            
        f = open(fpath,'wb')
        size = 0
        while True:
            data = myFile.file.read(8192)
            if not data:
                break
            f.write(data)
            size += len(data)
        f.close()
        conn = sqlite3.connect(settings['db_name'])
        key = db.insert_file(fpath, cherrypy.session.get('user'), conn)   
             
        hostaddr = cherrypy.request.local.ip
        hostport = cherrypy.request.local.port

        if hostaddr == '': 
            hostaddr = 'localhost'
        print hostaddr 
        if hostport != 80:
            absfilepath = '%s://%s:%s/file/%s/%s' % (cherrypy.request.scheme, hostaddr, hostport, key, myFile.filename)
        else:
            absfilepath = 'http://%s/file/%s/%s' % (hostaddr, key, myFile.filename)
        
        return render(title="Upload complete",content="""<h2>Upload Complete!</h2><br>
                                                        <div style="padding-left:15px;">The url for your file is:<br> %s</div>""" % absfilepath)
Ejemplo n.º 3
0
    def do(self, myFile, key):
        if not (cherrypy.session.get('login') == True) and not (
                cherrypy.session.get('ip') == cherrypy.request.remote.ip):
            raise cherrypy.HTTPRedirect(["/login/"], 302)
        myFile.filename = myFile.filename.replace('"', '').replace("'", '')
        if ':' in myFile.filename:
            myFile.filename = myFile.filename.replace('/', os.path.sep).split(
                os.path.sep)[-1]
        #cherrypy.log.error("FileName: " + myFile.filename)
        relpath = key + os.path.sep + myFile.filename.replace('/', os.path.sep)
        #cherrypy.log.error("RELPATH:  " + relpath)
        fpath = get_upload_path() + relpath
        froot = '/#'
        if '\\' in relpath:
            froot = get_upload_path(
            ) + os.path.sep + key + os.path.sep + myFile.filename.split('/')[0]
            pathparts = relpath.split('\\')
            newpath = get_upload_path()
            #cherrypy.log.error("FROOT:  " + froot)
            for i in range(0, len(pathparts) - 1):
                #cherrypy.log.error("PRE MKDIR:  " + newpath + pathparts[i] + '\\')
                newpath = newpath + pathparts[i] + '\\'
                if not os.path.exists(newpath):
                    #cherrypy.log.error("MKDIR:  " + newpath)
                    os.mkdir(newpath)
        mkey = key

        if fpath[-1] == '.':
            conn = sqlite3.connect(settings['db_name'])
            rkey = db.query_filekey(mkey, conn)
            if not rkey:
                rkey = db.insert_file(froot, cherrypy.session.get('user'),
                                      conn, mkey, mkey)
            else:
                conn.close()
            conn = sqlite3.connect(settings['db_name'])
            key = db.insert_file(fpath[0:-2], cherrypy.session.get('user'),
                                 conn, rkey)
            #cherrypy.log.error("FOLDER:: KEY: "+key+"\r\n+MKEY: "+mkey+"\r\nRKEY: "+rkey)

            hostaddr = cherrypy.request.local.ip
            hostport = cherrypy.request.local.port

            if hostaddr == '':
                hostaddr = 'localhost'
            #print hostaddr
            if hostport != 80:
                absfilepath = '%s://%s:%s/file/%s/%s' % (
                    cherrypy.request.scheme, hostaddr, hostport, key,
                    myFile.filename)
                delurl = '%s://%s:%s/upload/delete?key=%s' % (
                    cherrypy.request.scheme, hostaddr, hostport, key)
            else:
                absfilepath = 'http://%s/file/%s/%s' % (hostaddr, key,
                                                        myFile.filename)
                delurl = 'http://%s/upload/delete?key=%s' % (hostaddr, key)
            rpath = 'http://%s/file/%s' % (hostaddr, mkey)

            jobj = [{
                'name': 'Folder: ' + myFile.filename[0:-1],
                'size': myFile.length,
                'url': absfilepath,
                'rpath': rpath,
                'delete_url': delurl,
                'delete_type': 'DELETE'
            }]
            #return render(title="Upload complete",content="""<h2>Upload Complete!</h2><br>
            #                                                <div style="padding-left:15px;">The url for your file is:<br> %s</div>""" % absfilepath)
            return json.dumps(jobj).decode()

        #cherrypy.log.error(fpath)
        while os.path.exists(fpath):
            pathparts = fpath.split('.')
            pathparts[-2] += '_'
            fpath = ''
            for part in pathparts:
                fpath += part + '.'
            fpath = fpath[:-1]
        f = open(fpath, 'wb')
        size = 0
        while True:
            data = myFile.file.read(4092)
            if not data:
                break
            f.write(data)
            size += len(data)
        f.close()

        froot = get_upload_path() + os.path.sep + key
        conn = sqlite3.connect(settings['db_name'])
        rkey = db.query_filekey(mkey, conn)
        if not rkey:
            rkey = db.insert_file(froot, cherrypy.session.get('user'), conn,
                                  mkey, mkey)
        else:
            conn.close()

        #cherrypy.log.error("FILE:: KEY: "+key+"\r\nMKEY: "+mkey+"\r\nRKEY: "+rkey)

        conn = sqlite3.connect(settings['db_name'])
        key = db.insert_file(fpath, cherrypy.session.get('user'), conn, mkey)

        hostaddr = cherrypy.request.local.ip
        hostport = cherrypy.request.local.port

        if hostaddr == '':
            hostaddr = hostaddr = settings['hostname']  #'localhost'
        #print hostaddr
        if hostport != 80:
            absfilepath = '%s://%s:%s/file/%s/%s' % (cherrypy.request.scheme,
                                                     hostaddr, hostport, key,
                                                     myFile.filename)
            delurl = '%s://%s:%s/upload/delete?key=%s' % (
                cherrypy.request.scheme, hostaddr, hostport, key)
        else:
            absfilepath = 'http://%s/file/%s/%s' % (hostaddr, key,
                                                    myFile.filename)
            delurl = 'http://%s/upload/delete?key=%s' % (hostaddr, key)
        rpath = 'http://%s/file/%s' % (hostaddr, mkey)
        jobj = [{
            'name': absfilepath,
            'size': myFile.length,
            'url': absfilepath,
            'rpath': rpath,
            'delete_url': delurl,
            'delete_type': 'DELETE'
        }]
        #return render(title="Upload complete",content="""<h2>Upload Complete!</h2><br>
        #                                                <div style="padding-left:15px;">The url for your file is:<br> %s</div>""" % absfilepath)
        return json.dumps(jobj).decode()
Ejemplo n.º 4
0
    def do(self, myFile, key):
        if not (cherrypy.session.get('login') == True) and not (cherrypy.session.get('ip') == cherrypy.request.remote.ip):
            raise cherrypy.HTTPRedirect(["/login/"], 302)
        myFile.filename = myFile.filename.replace('"', '').replace("'", '')
        if ':' in myFile.filename:
            myFile.filename = myFile.filename.replace('/',os.path.sep).split(os.path.sep)[-1]
        #cherrypy.log.error("FileName: " + myFile.filename)
        relpath = key + os.path.sep + myFile.filename.replace('/',os.path.sep)
        #cherrypy.log.error("RELPATH:  " + relpath)
        fpath = get_upload_path() + relpath
        froot = '/#'
        if '\\' in relpath:
            froot = get_upload_path() + os.path.sep + key + os.path.sep + myFile.filename.split('/')[0]
            pathparts = relpath.split('\\')
            newpath = get_upload_path()
            #cherrypy.log.error("FROOT:  " + froot)
            for i in range(0, len(pathparts)-1):
                #cherrypy.log.error("PRE MKDIR:  " + newpath + pathparts[i] + '\\')
                newpath = newpath + pathparts[i] +'\\'
                if  not os.path.exists(newpath):
                    #cherrypy.log.error("MKDIR:  " + newpath)
                    os.mkdir(newpath)
        mkey = key
        
        if fpath[-1] == '.':
            conn = sqlite3.connect(settings['db_name'])
            rkey = db.query_filekey(mkey, conn)
            if not rkey:
                rkey = db.insert_file(froot, cherrypy.session.get('user'), conn, mkey, mkey)
            else:
                conn.close()
            conn = sqlite3.connect(settings['db_name'])
            key = db.insert_file(fpath[0:-2], cherrypy.session.get('user'), conn, rkey)
            #cherrypy.log.error("FOLDER:: KEY: "+key+"\r\n+MKEY: "+mkey+"\r\nRKEY: "+rkey)
            
            hostaddr = cherrypy.request.local.ip
            hostport = cherrypy.request.local.port
        
            if hostaddr == '': 
                hostaddr = 'localhost'
            #print hostaddr 
            if hostport != 80:
                absfilepath = '%s://%s:%s/file/%s/%s' % (cherrypy.request.scheme, hostaddr, hostport, key, myFile.filename)
                delurl = '%s://%s:%s/upload/delete?key=%s' % (cherrypy.request.scheme, hostaddr, hostport, key)
            else:
                absfilepath = 'http://%s/file/%s/%s' % (hostaddr, key, myFile.filename)
                delurl = 'http://%s/upload/delete?key=%s' % (hostaddr, key)
            rpath = 'http://%s/file/%s' % (hostaddr, mkey)
        
            jobj = [{'name':'Folder: '+myFile.filename[0:-1],'size':myFile.length,'url':absfilepath,'rpath':rpath,'delete_url':delurl, 'delete_type':'DELETE'}]
            #return render(title="Upload complete",content="""<h2>Upload Complete!</h2><br>
            #                                                <div style="padding-left:15px;">The url for your file is:<br> %s</div>""" % absfilepath)
            return json.dumps(jobj).decode()
            
        #cherrypy.log.error(fpath)
        while os.path.exists(fpath):
            pathparts = fpath.split('.')
            pathparts[-2]+='_'
            fpath = ''
            for part in pathparts:
                fpath += part + '.'
            fpath = fpath[:-1]
        f = open(fpath,'wb')
        size = 0
        while True:
            data = myFile.file.read(4092)
            if not data:
                break
            f.write(data)
            size += len(data)
        f.close()
        

        froot = get_upload_path() + os.path.sep + key
        conn = sqlite3.connect(settings['db_name'])
        rkey = db.query_filekey(mkey, conn)
        if not rkey:
            rkey = db.insert_file(froot, cherrypy.session.get('user'), conn, mkey, mkey)
        else:
            conn.close()
            
        #cherrypy.log.error("FILE:: KEY: "+key+"\r\nMKEY: "+mkey+"\r\nRKEY: "+rkey)
            
        conn = sqlite3.connect(settings['db_name'])
        key = db.insert_file(fpath, cherrypy.session.get('user'), conn, mkey)   
             
        hostaddr = cherrypy.request.local.ip
        hostport = cherrypy.request.local.port
    
        if hostaddr == '': 
            hostaddr = hostaddr = settings['hostname']#'localhost'
        #print hostaddr 
        if hostport != 80:
            absfilepath = '%s://%s:%s/file/%s/%s' % (cherrypy.request.scheme, hostaddr, hostport, key, myFile.filename)
            delurl = '%s://%s:%s/upload/delete?key=%s' % (cherrypy.request.scheme, hostaddr, hostport, key)
        else:
            absfilepath = 'http://%s/file/%s/%s' % (hostaddr, key, myFile.filename)
            delurl = 'http://%s/upload/delete?key=%s' % (hostaddr, key)
        rpath = 'http://%s/file/%s' % (hostaddr, mkey)
        jobj = [{'name':absfilepath,'size':myFile.length,'url':absfilepath,'rpath':rpath, 'delete_url':delurl, 'delete_type':'DELETE'}]
        #return render(title="Upload complete",content="""<h2>Upload Complete!</h2><br>
        #                                                <div style="padding-left:15px;">The url for your file is:<br> %s</div>""" % absfilepath)
        return json.dumps(jobj).decode()