Update app.py
1. Format codes 2. GenerateLicense takes int rather than LicenseType typepull/15/head
parent
d1f202b785
commit
bcd98e8143
55
app.py
55
app.py
|
@ -1,16 +1,19 @@
|
|||
#/usr/bin/env python3
|
||||
|
||||
import os, sys, zipfile
|
||||
from flask import Flask, request, send_file
|
||||
import os
|
||||
import os.path
|
||||
import zipfile
|
||||
|
||||
from flask import Flask, request, send_file
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
VariantBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
||||
VariantBase64Dict = { i : VariantBase64Table[i] for i in range(len(VariantBase64Table)) }
|
||||
VariantBase64ReverseDict = { VariantBase64Table[i] : i for i in range(len(VariantBase64Table)) }
|
||||
VariantBase64Dict = {i: VariantBase64Table[i] for i in range(len(VariantBase64Table))}
|
||||
VariantBase64ReverseDict = {VariantBase64Table[i]: i for i in range(len(VariantBase64Table))}
|
||||
|
||||
def VariantBase64Encode(bs : bytes):
|
||||
|
||||
def VariantBase64Encode(bs: bytes):
|
||||
result = b''
|
||||
blocks_count, left_bytes = divmod(len(bs), 3)
|
||||
|
||||
|
@ -38,7 +41,8 @@ def VariantBase64Encode(bs : bytes):
|
|||
result += block.encode()
|
||||
return result
|
||||
|
||||
def VariantBase64Decode(s : str):
|
||||
|
||||
def VariantBase64Decode(s: str):
|
||||
result = b''
|
||||
blocks_count, left_bytes = divmod(len(s), 4)
|
||||
|
||||
|
@ -65,38 +69,44 @@ def VariantBase64Decode(s : str):
|
|||
else:
|
||||
raise ValueError('Invalid encoding.')
|
||||
|
||||
def EncryptBytes(key : int, bs : bytes):
|
||||
|
||||
def EncryptBytes(key: int, bs: bytes):
|
||||
result = bytearray()
|
||||
for i in range(len(bs)):
|
||||
result.append(bs[i] ^ ((key >> 8) & 0xff))
|
||||
key = result[-1] & key | 0x482D
|
||||
return bytes(result)
|
||||
|
||||
def DecryptBytes(key : int, bs : bytes):
|
||||
|
||||
def DecryptBytes(key: int, bs: bytes):
|
||||
result = bytearray()
|
||||
for i in range(len(bs)):
|
||||
result.append(bs[i] ^ ((key >> 8) & 0xff))
|
||||
key = bs[i] & key | 0x482D
|
||||
return bytes(result)
|
||||
|
||||
|
||||
class LicenseType:
|
||||
Professional = 1
|
||||
Educational = 3
|
||||
Personal = 4
|
||||
|
||||
def GenerateLicense(Type : LicenseType, Count : int, UserName : str, MajorVersion : int, MinorVersion):
|
||||
assert(Count >= 0)
|
||||
LicenseString = '%d#%s|%d%d#%d#%d3%d6%d#%d#%d#%d#' % (Type,
|
||||
UserName, MajorVersion, MinorVersion,
|
||||
Count,
|
||||
MajorVersion, MinorVersion, MinorVersion,
|
||||
0, # Unknown
|
||||
0, # No Games flag. 0 means "NoGames = false". But it does not work.
|
||||
0) # No Plugins flag. 0 means "NoPlugins = false". But it does not work.
|
||||
|
||||
def GenerateLicense(Type: int, Count: int, UserName: str, MajorVersion: int, MinorVersion):
|
||||
assert (Count >= 0)
|
||||
LicenseString = '%d#%s|%d%d#%d#%d3%d6%d#%d#%d#%d#' % (
|
||||
Type,
|
||||
UserName, MajorVersion, MinorVersion,
|
||||
Count,
|
||||
MajorVersion, MinorVersion, MinorVersion,
|
||||
0, # Unknown
|
||||
0, # No Games flag. 0 means "NoGames = false". But it does not work.
|
||||
0 # No Plugins flag. 0 means "NoPlugins = false". But it does not work.
|
||||
)
|
||||
EncodedLicenseString = VariantBase64Encode(EncryptBytes(0x787, LicenseString.encode())).decode()
|
||||
FileName = EncodedLicenseString.replace('/','').replace('\\','')
|
||||
FileName = EncodedLicenseString.replace('/', '').replace('\\', '')
|
||||
with zipfile.ZipFile(FileName, 'w') as f:
|
||||
f.writestr('Pro.key', data = EncodedLicenseString)
|
||||
f.writestr('Pro.key', data=EncodedLicenseString)
|
||||
return FileName
|
||||
|
||||
|
||||
|
@ -119,8 +129,8 @@ def get_lc():
|
|||
def download_lc(lc):
|
||||
if lc and len(lc) > 5 and os.path.exists('./' + lc):
|
||||
return send_file(lc,
|
||||
as_attachment=True,
|
||||
attachment_filename='Custom.mxtpro')
|
||||
as_attachment=True,
|
||||
attachment_filename='Custom.mxtpro')
|
||||
else:
|
||||
return "请检查用户名版本号是否正确!"
|
||||
|
||||
|
@ -136,8 +146,5 @@ def index():
|
|||
return send_file('index.html')
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000, debug=False)
|
||||
|
||||
|
|
Loading…
Reference in New Issue