def Search_item(): try: if request.form.get("key", "") and request.form.get("keyword", ""): keyword = base64.b64encode( request.form["keyword"].encode()).decode() key: str = request.form['key'] KeyMode_Str: str = { "0": "Address", "1": "Account", "2": "Password", "3": "Text"}.get(key, "Error") if KeyMode_Str == "Error": return "400 Bad Request3", 400 if key == "3": keyword = request.form["keyword"] log.warning("Search Word { %s } Class { %s }" % (keyword, KeyMode_Str,)) sql = manage_sql() result: list = sql.Search_Item( KeyMode_Str, keyword) + [[time.strftime("%Y-%m-%d-%H-%M-%S")]] del sql return json.dumps(result), 200 else: return json.dumps({"code": "500", "message": "argv error"}), 500 except IOError: return "400 Bad Request 2", 400
def Save_Result_to_sql(): try: if request.form['password'] and request.form["AccountStr"]: try: if request.form["AddressStr"]: AddressStr: str = base64.b64encode( request.form["AddressStr"].encode()).decode() else: AddressStr: str = "Tm9BZGRyZXNz" # NoAddress except: AddressStr: str = "Tm9BZGRyZXNz" # NoAddress try: Text: str = request.form["Text"] except: Text: str = "NoValue" # NoValue AccountStr, Password = base64.b64encode(request.form['AccountStr'].encode( )).decode(), base64.b64encode(request.form['password'].encode()).decode() log.warning("Address { %s } Account { %s } Text { %s }" % ( request.form["AddressStr"], request.form["AccountStr"], request.form["Text"],)) sql = manage_sql() sql.Save_Result_to_sql(AddressStr, AccountStr, Password, Text) del sql return "Succ", 200 except IOError: print(IOError) return "400 Bad Request", 400
def Delete(Date): try: if Date: Date = base64.b64encode(Date.encode()).decode() sql = pjsql.manage_sql() sql.Delete_Item(Date) del sql return "Succ", 200 except: return "400 Bad Request", 400
def Delete(Date: str): try: if Date: Date = base64.b64encode(Date.encode()).decode() sql = manage_sql() log.warning(sql.Delete_Item(Date)) del sql return time.strftime("%Y-%m-%d--%H-%M-%S"), 200 except: return "400 Bad Request", 400
def Backup(): sql = pjsql.manage_sql() return Response(sql.Backup_Database(), mimetype="application/octet-stream", headers={ "Content-Type": "application/octet-stream", "Content-disposition": "attachment; filename=" + str(time.strftime(r"%Y-%m-%d--%H-%M-%S") + ".db") })
def Update_Text(): try: if request.form['DateStr'] and request.form["TextStr"]: DateStr, TextStr = base64.b64encode( request.form["DateStr"].encode()).decode(), base64.b64encode( request.form["TextStr"].encode()).decode() sql = pjsql.manage_sql() sql.Update_Text(DateStr, TextStr) del sql return "Succ", 200 except: return "400 Bad Request", 400
def Update_Text(): try: if request.form['DateStr'] and request.form["TextStr"]: DateStr, TextStr = base64.b64encode(request.form["DateStr"].encode()).decode( ), request.form["TextStr"] log.warning("Date { %s } TextStr { %s } " % ( request.form['DateStr'], request.form["TextStr"],)) sql = manage_sql() sql.Update_Text(DateStr, TextStr) del sql return time.strftime("%Y-%m-%d--%H-%M-%S"), 200 except: return "400 Bad Request", 400
def Search_item(): try: if request.form['key'] and request.form["keyword"]: keyword = base64.b64encode( request.form["keyword"].encode()).decode() key = request.form['key'] if key == "0": KeyMode_Str = 'Address' elif key == "1": KeyMode_Str = 'Account' elif key == "2": KeyMode_Str = 'Password' else: return "400 Bad Request", 400 sql = pjsql.manage_sql() result = sql.Search_Item(KeyMode_Str, keyword) del sql return result, 200 except: return "400 Bad Request", 400
def Save_Result_to_sql(): try: if request.form['password'] and request.form["AccountStr"]: try: AddressStr = base64.b64encode( request.form["AddressStr"].encode()).decode() except: AddressStr = "Tm9BZGRyZXNz" #NoAddress try: Text = base64.b64encode(request.form["Text"].decode()).decode() except: Text = "Tm9WYWx1ZQ==" # NoValue AccountStr, Password = base64.b64encode( request.form['password'].encode()).decode(), base64.b64encode( request.form['password'].encode()).decode() sql = pjsql.manage_sql() sql.Save_Result_to_sql(AddressStr, AccountStr, Password, Text) del sql return "Succ", 200 except: return "400 Bad Request", 400
def Backup(): log.critical("Backup is Downloaded! Downloader's ip { %s } " % ( request.remote_addr,)) sql = manage_sql() return Response(sql.Backup_Database(), mimetype="application/octet-stream", headers={"Content-Type": "application/octet-stream", "Content-disposition": "attachment; filename="+str(time.strftime(r"%Y-%m-%d--%H-%M-%S")+".db")})