Spaces:
Running
Running
import time | |
import random | |
import hashlib | |
from .. import helpers | |
def signatureGen(request): | |
endtime = round(time.time())+3600 | |
uK = helpers.getFromRequest(request, "key") | |
if uK == None: return {"status": "error", "details": {"error_code": -1, "error_details": "No key to generate signature"}} | |
userKey = hashlib.md5(uK.encode()).hexdigest() | |
text = f"--START SIGNATURE-- {userKey}{endtime} --END SIGNATURE--" | |
salt = hashlib.md5("funapi-salt".encode()).hexdigest()[0:16] | |
creatorKey = hashlib.md5(f"HOST-IP:{request.remote_addr};USERKEY={userKey};DATE={time.strftime('%Y-%m-%d')};".encode()).hexdigest() | |
key = hashlib.blake2b(text.encode(), key=userKey.encode(), salt=salt.encode()).hexdigest().upper() | |
config = helpers.configFile() | |
db = helpers.EazySQLite3(config['signatures-db']) | |
query = db.query(f"INSERT INTO `table` (`key`, `endtime`, `creatorKey`) VALUES (\"{key}\", \"{endtime}\", \"{creatorKey}\")") | |
if query['status']: | |
return {"status": "ok", "result": key, "endtime": endtime} | |
else: | |
return {"status": "error", "details": {"error_code": -1, "error_details": "This key already got signature"}} | |