Last active
August 24, 2021 08:06
-
-
Save WangYihang/d87fb9d46e0da0a13c86967e18a242be to your computer and use it in GitHub Desktop.
TimeSnapper License Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding:utf-8 | |
import time | |
import string | |
import random | |
from flask import Flask | |
from flask import Response | |
app = Flask(__name__) | |
class Licence(): | |
@classmethod | |
def random_string(self, length, charset): | |
return "".join([random.choice(charset) for i in range(length)]) | |
@classmethod | |
def generate_key(cls): | |
return "{} {} {} {}".format( | |
cls.random_string(4, string.ascii_uppercase), | |
cls.random_string(4, "123456789"), | |
cls.random_string(4, string.ascii_uppercase), | |
cls.random_string(4, "123456789"), | |
) | |
def __bytes__(self): | |
def encode_key(data): | |
return str(__import__("base64").b64encode((__import__("hashlib").md5(data.encode("utf-16le")).digest())), encoding="utf-8") | |
# thanks to wxk (https://pullp.github.io/) to fix hostname bug. | |
hostname = __import__("os").environ['COMPUTERNAME'] | |
print("Using licence: {}".format(key)) | |
valid_from = time.strftime("%Y%m%d", time.localtime()) | |
valid_until = valid_from | |
product_version = "2.0.0.0" | |
product_id = "557" | |
secret = "m,0f9r90813u4fokjnm93tuynvkjvneririvnkljvnqwil" | |
key_plain = "_".join([ | |
"TimeSnapper", | |
key, | |
hostname, | |
product_version, | |
product_id, | |
valid_from, | |
valid_until, | |
product_id, | |
secret, | |
]) | |
print("Generated key: {}".format(key_plain)) | |
key_encoded = encode_key(key_plain) | |
print("Encoded key: {}".format(key_encoded)) | |
content = '''<?xml version="1.0" encoding="utf-8"?> | |
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soap:Body> | |
<ValidateResponse xmlns="http://TimeSnapper.com/LicenseValidator/Validator"> | |
<ValidateResult>{}</ValidateResult> | |
<_ValidFrom>{}</_ValidFrom> | |
<_ValidUntil>{}</_ValidUntil> | |
</ValidateResponse> | |
</soap:Body> | |
</soap:Envelope>'''.format( | |
key_encoded, | |
valid_from, | |
valid_until, | |
).replace("\n", "\r\n") | |
return bytes(content, encoding="utf-8") | |
@app.route("/<path:path>", methods=['POST']) | |
def keygen(path): | |
return Response(Licence().__bytes__(), mimetype='text/xml') | |
def usage(): | |
print("Usage: ") | |
steps = [ | |
"Start TimeSnapper, click `Help->Acticate Licence`", | |
"Click `Proxy Settings`, a window named `TimeSnapper Options` will be opened, then navigate to `Proxy` tab", | |
"Choose `use the following proxy`, set Host to `{}`, set Port to `{}`, click `OK`".format(server_addr[0], server_addr[1]), | |
"Please `{}` in the TimeSnapper activate window as `Your Unique Code`".format(key), | |
"Click `Activate`", | |
"Restore TimeSnapper Proxy Setting", | |
] | |
for i, step in enumerate(steps): | |
print(" Step [{}/{}]: {}".format(i + 1, len(steps), step)) | |
server_addr = ("127.0.0.1", 13337) | |
key = Licence.generate_key() | |
def main(): | |
usage() | |
app.run(*server_addr) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment