def get(self): islock, site_notify = lock_site_notify() sessionkey = self.input_default('k') if (sessionkey): fileinfo = userpay.getPaySession(self, sessionkey) if not fileinfo: fileindex = '999999' filetype = '4' actiontype = '0' filename = '未知文件' else: fileindex = int(fileinfo['i']) filetype = fileinfo['t'] actiontype = fileinfo['a'] filename = fileinfo['name'] else: fileindex = self.input_default('i') filetype = self.input_default('t') actiontype = self.input_default('a') filename = self.input_default('name') user = self.get_current_user() message = self.input_default('m', None) if filetype: filetypename = getfiletypename(int(filetype)) self.render('fileview_' + filetype + '.html', username=user.nickname, filetype=filetype, filetypename=filetypename, fileindex=fileindex, actiontype=actiontype, filename=filename, message=message, site_notify=site_notify, siteinfo=siteinfo)
def get(self): islock, site_notify = lock_site_notify() user = self.get_current_user() if user: self.render('index.html', username=user.nickname, site_notify=site_notify, siteinfo=siteinfo) else: data = wechatapi self.render('login.html', data=data, site_notify=site_notify, siteinfo=siteinfo, returnurl=parse.quote(wechatapi['redirect_uri']))
def get(self, content): islock, site_notify = lock_site_notify() user = self.get_current_user() data = wechatapi if user: self.render(content, data=data, returnurl=parse.quote(wechatapi['redirect_uri']), username=user.nickname, site_notify=site_notify, siteinfo=siteinfo) else: self.render(content, data=data, returnurl=parse.quote(wechatapi['redirect_uri']), username=None, site_notify=site_notify, siteinfo=siteinfo)
def get(self): islock, site_notify = lock_site_notify() user = self.get_current_user() deep_number = self.get_deep_number(user) message = self.input_default('m', None) if (self.input_default('k') is None or not message is None): self.render('filedepth.html', username=user.nickname, deep_number=deep_number, message=message, site_notify=site_notify, siteinfo=siteinfo) return password = self.get_session('%s_%s' % (user.id, 'auth')) if (not password): self.render('filedepth.html', username=user.nickname, deep_number=deep_number, message=message, site_notify=site_notify, siteinfo=siteinfo) return self.clear_cookie('%s_%s' % (user.id, 'auth')) userdata = self.get_user_data(user, deep_number) ret = self.go_deep_path(user, deep_number, password, '2', userdata) if (ret['result'] == 'error'): message = ret['info'] self.render('filedepth.html', username=user.nickname, deep_number=deep_number, message=message, site_notify=site_notify, siteinfo=siteinfo) self.redirect('/filedepth') return
def get(self): islock, site_notify = lock_site_notify() user = self.get_current_user() filetype = self.input_default('t') filetypename = getfiletypename(int(filetype)) message = self.input_default('m', None) deep_number = self.get_deep_number(user) userdata = self.get_user_data(user, deep_number) userfilelist = userdata.filelist if(len(userfilelist)<=0): self.render('filelist.html', username=user.nickname, filetype=filetype, filetypename=filetypename, filelist=[], message=message,site_notify=site_notify, siteinfo=siteinfo) return data = [] alist = np.array(userfilelist) flist = alist[np.where(alist[:, 1] == str(filetype))] for item in flist: bsize = int(item[2]) if (bsize > 1024 * 1024): filesize = round(bsize / 1024 / 1024, 1) filesize = '%s%s' % (filesize, 'M') elif (bsize > 1024): filesize = round(bsize / 1024, 1) filesize = '%s%s' % (filesize, 'K') else: filesize = '%s%s' % (bsize, 'B') filetime = datetime.strptime(item[7], "%Y-%m-%d %H:%M:%S") try: filenameurl = parse.quote(item[0]) except Exception as err: print(err) filenameurl = item[0] finally: data.append([item[0], item[1], filesize, item[3], item[4], item[5], item[6], filetime, filenameurl]) self.render('filelist.html', username=user.nickname, filetype=filetype, filetypename=filetypename, filelist=data, message=message,site_notify=site_notify, siteinfo=siteinfo)
def post(self): user = self.get_current_user() fileindex = int(self.input_default('i')) filetype = self.input_default('t') actiontype = self.input_default('a') fileviewname = self.input_default('n') password = str(self.input_default('p', None)).strip() deep_number = self.get_deep_number(user) userdata = self.get_user_data(user, deep_number) userfilelist = userdata.filelist data = [] for item in userfilelist: if (item[1] == filetype): data.append([ item[0], item[1], item[2], item[3], item[4], item[5], item[6] ]) if (fileindex >= len(data)): ret = {'result': 'error'} ret['code'] = '1' ret['info'] = '参数异常,请重新打开网站后再试' self.write(json.dumps(ret)) return selectitem = data[fileindex] filename = selectitem[0] filehash = selectitem[3] passwordhash = selectitem[4] savename = selectitem[5] if fileviewname != filename: ret = {'result': 'error'} ret['code'] = '1' ret['info'] = '文件编号与文件名不一致,请重新打开网站后再试' self.write(json.dumps(ret)) return keyhash = crypto_helper.get_key(password, user.id, filehash, None, False) sessionkey = userpay.getSessionKey(user.id, fileindex, filetype, filename) if (int(filetype) > 3): if (userpay.checkPaySession(self, sessionkey, password) is False): islock, site_notify = lock_site_notify() if (islock is True): ret = {'result': 'error'} ret['code'] = '1' ret['info'] = site_notify self.write(ret) return trade_no = '%s%s' % (datetime.now().strftime('%Y%m%d%H%M%S'), uuid.uuid1()) trade_no = trade_no.replace('-', '') subject = '%s%s' % (filename, '权限校验') userpay.setPaySession(self, sessionkey, trade_no, user.id, fileindex, filetype, actiontype, filename, deep_number, password) amount = userpay.getPayAmount(filetype, password) if (len(filehash) <= 32): retcontent = {'filehash': filehash} else: retcontent = {'filehash': ''.join(list(filehash)[:32])} if (passwordhash == keyhash): retcontent['status'] = '1' else: retcontent['status'] = '0' retkey = crypto_helper.get_key( str(amount), trade_no, str(encryptkey, encoding='utf-8')) retkey = ''.join(list(retkey)[:32]) retkey = bytes(retkey, encoding='utf-8') retcontent = crypto_helper.aes_encrypt(json.dumps(retcontent), retkey) payurl = Alipay().getpaycheckurl(sessionkey, trade_no, subject, amount, retcontent) ret = {'result': 'pay'} ret['url'] = payurl self.write(json.dumps(ret)) return oss = Alioss() if (passwordhash != keyhash): self.clear_cookie(sessionkey) ret = {'result': 'error'} ret['code'] = '0' ret['info'] = '' self.write(json.dumps(ret)) return elif (actiontype == '1'): userdata.del_file(savename) if isuploadfileoss is True: encrpath = '%s/%s' % (alioss['userdatapath'], savename) oss.Bucket.delete_object(encrpath) else: encrpath = os.path.join(userdatapath, savename) os.unlink(encrpath) ret = {'result': 'delete'} self.write(json.dumps(ret)) return elif (actiontype == '0'): ret = self.getdownurl(user, password, filename, filehash, savename, fileindex, filetype, actiontype, oss) self.write(json.dumps(ret))
def post(self): islock, notify = lock_site_notify() if (islock is True): ret = {'result': 'error'} ret['info'] = notify self.write(ret) return keys = self.request.arguments.keys() if "file.path" not in keys and "userfile.path" not in keys: self.set_status(status_code=400, reason="file field not exist.") self.write("400") return files = list() if "file.path" in keys: file_path = self.request.arguments['file.path'] for index in range(len(file_path)): file = {} file['name'] = str(self.request.arguments['file.name'][index], encoding='utf-8') file['content_type'] = str( self.request.arguments['file.content_type'][index], encoding='utf-8') file['path'] = str(self.request.arguments['file.path'][index], encoding='utf-8') file['md5'] = str(self.request.arguments['file.md5'][index], encoding='utf-8') file['size'] = str(self.request.arguments['file.size'][index], encoding='utf-8') files.append(file) else: file_path = self.request.arguments['userfile.path'] for index in range(len(file_path)): file = {} file['name'] = str( self.request.arguments['userfile.name'][index], encoding='utf-8') file['content_type'] = str( self.request.arguments['userfile.content_type'][index], encoding='utf-8') file['path'] = str( self.request.arguments['userfile.path'][index], encoding='utf-8') file['md5'] = str( self.request.arguments['userfile.md5'][index], encoding='utf-8') file['size'] = str( self.request.arguments['userfile.size'][index], encoding='utf-8') files.append(file) filename = self.input_default('filename', None) filehash = self.input_default('filehash', None) filetype = self.input_default('t', None) filesize = int(self.input_default('s', '0')) password = self.input_default('p', None) if (filename == None or filehash == None or filetype == None or password == None): ret = {'result': 'error'} ret['info'] = '参数异常或缺失' self.write(json.dumps(ret)) return if (filesize == 0): ret = {'result': 'error'} ret['info'] = '参数异常或上传的文件为空文件' self.write(json.dumps(ret)) return password = str(password).strip() user = self.get_current_user() deep_number = self.get_deep_number(user) userdata = self.get_user_data(user, deep_number) userfilelist = userdata.filelist for item in userfilelist: if (item[0] == filename and item[1] == filetype and item[3] == filehash): ret = {'result': 'error'} ret['info'] = '同目录下已存在相同文件' self.write(json.dumps(ret)) return passhash = crypto_helper.get_key(password, user.id, filehash, None, False) finalname = userdata.add_file(filename, filetype, filesize, filehash, passhash) password = crypto_helper.get_key(password, user.id) encrpath = os.path.join(userdatapath, finalname) temp_file = files[0]['path'] now = datetime.now() nowdir = now.strftime('%Y%m%d') downpath = os.path.join(downloadpath, nowdir, filehash, filename) if (os.path.exists(downpath) is False): if (os.path.exists(os.path.join(downloadpath, nowdir, filehash)) is False): os.makedirs(os.path.join(downloadpath, nowdir, filehash)) shutil.move(temp_file, downpath) else: os.unlink(temp_file) if (os.path.exists(encrpath) is True): os.unlink(encrpath) crypto_helper.encrypt_file(bytes.fromhex(password), downpath, encrpath) if (not user.isexist): user.set_isexist(True) self.set_current_user(user.get_session()) ret = {'result': 'ok'} self.write(json.dumps(ret))
def post(self): islock, notify = lock_site_notify() if (islock is True): ret = {'result': 'error'} ret['info'] = notify self.write(ret) return filename = self.input_default('filename', None) filehash = self.input_default('filehash', None) filetype = self.input_default('t', None) filesize = int(self.input_default('s', '0')) password = self.input_default('p', None) if (filename == None or filehash == None or filetype == None or password == None): ret = {'result': 'error'} ret['info'] = '参数异常或缺失' self.write(json.dumps(ret)) return if (filesize == 0): ret = {'result': 'error'} ret['info'] = '参数异常或上传的文件为空文件' self.write(json.dumps(ret)) return password = str(password).strip() user = self.get_current_user() deep_number = self.get_deep_number(user) userdata = self.get_user_data(user, deep_number) userfilelist = userdata.filelist for item in userfilelist: if (item[0] == filename and item[1] == filetype and item[3] == filesize): ret = {'result': 'error'} ret['info'] = '同目录下已存在相同文件' self.write(json.dumps(ret)) return passhash = crypto_helper.get_key(password, user.id, filehash, None, False) finalname = userdata.add_file(filename, filetype, filesize, filehash, passhash) password = crypto_helper.get_key(password, user.id) oss = Alioss() now = datetime.now() nowdir = now.strftime('%Y%m%d') ossdownpath = '%s/%s/%s/%s' % (alioss['downloadpath'], nowdir, filehash, filename) localdownpath = os.path.join(downloadpath, nowdir, filehash, filename) ossencrpath = '%s/%s' % (alioss['userdatapath'], finalname) localencrpath = os.path.join(userdatapath, finalname) if (oss.exists(ossdownpath) is False): userdata.del_file(finalname) ret = {'result': 'error'} ret['info'] = '文件上传失败' self.write(json.dumps(ret)) return else: if (os.path.exists(os.path.join(downloadpath, nowdir, filehash)) is False): os.makedirs(os.path.join(downloadpath, nowdir, filehash)) if (os.path.exists(localdownpath) is False): oss.Bucket.get_object_to_file(ossdownpath, localdownpath) # 此处下载到本地进行解码的文件处理完后多长时间删除的逻辑处理需要更多的思考,目前采取48小时删除方式清理磁盘,systask定时任务每天定时执行 # 下载的逻辑处理与此处相同 crypto_helper.encrypt_file(bytes.fromhex(password), localdownpath, localencrpath) oss.Bucket.put_object_from_file(ossencrpath, localencrpath) if (os.path.exists(localencrpath) is True): os.unlink(localencrpath) if (user.isexist is False): user.set_isexist(True) self.set_current_user(user.get_session()) ret = {'result': 'ok'} self.write(json.dumps(ret))
def post(self): islock, notify = lock_site_notify() if (islock is True): ret = {'result': 'error'} ret['info'] = notify self.write(ret) return filename = self.input_default('filename', None) filehash = self.input_default('filehash', None) filetype = self.input_default('t', None) filesize = int(self.input_default('s', '0')) password = self.input_default('p', None) if (filename == None or filehash == None or filetype == None or password == None): ret = {'result': 'error'} ret['info'] = '参数异常或缺失' self.write(json.dumps(ret)) return if (filesize == 0): ret = {'result': 'error'} ret['info'] = '参数异常或上传的文件为空文件' self.write(json.dumps(ret)) return password = str(password).strip() user = self.get_current_user() deep_number = self.get_deep_number(user) userdata = self.get_user_data(user, deep_number) userfilelist = userdata.filelist for item in userfilelist: if (item[0] == filename and item[1] == filetype and item[3] == filesize): ret = {'result': 'error'} ret['info'] = '同目录下已存在相同文件' self.write(json.dumps(ret)) return passhash = crypto_helper.get_key(password, user.id, filehash, None, False) finalname = userdata.add_file(filename, filetype, filesize, filehash, passhash) password = crypto_helper.get_key(password, user.id) encrpath = os.path.join(userdatapath, finalname) now = datetime.now() nowdir = now.strftime('%Y%m%d') downpath = os.path.join(downloadpath, nowdir, filehash, filename) if (os.path.exists(os.path.join(downloadpath, nowdir, filehash)) is False): os.makedirs(os.path.join(downloadpath, nowdir, filehash)) file_metas = self.request.files.get('file', None) # 提取表单中‘name’为‘file’的文件元数据 if file_metas: temp_file = os.path.join(usertemppath, finalname) with open(temp_file, 'wb') as up: up.write(file_metas[0]['body']) temp_file = os.path.join(usertemppath, finalname) if (os.path.exists(downpath) is False): shutil.move(temp_file, downpath) else: os.unlink(temp_file) if (os.path.exists(encrpath) is True): os.unlink(encrpath) crypto_helper.encrypt_file(bytes.fromhex(password), downpath, encrpath) if (not user.isexist): user.set_isexist(True) self.set_current_user(user.get_session()) ret = {'result': 'ok'} self.write(json.dumps(ret))