Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. cdserver.py
  2.  
  3. import os, sys, json, subprocess
  4. from flask import Flask, render_template, flash
  5. from flask_cors import cross_origin, CORS
  6.  
  7. app = Flask(__name__)
  8. app.config['SECRET_KEY'] ="abcdef"
  9. cors = CORS(app, resources={r"/checkkey/*/*": {"origins": "*"}})
  10.  
  11. #checkKey takes in a cdkey, and a uuid number. If the cd key is present in our list of valid cdkeys, it checks whether the UUID being passed is the one registered, if so , return a value of 100(Valid)
  12. #if not the UUID registered, return type 200(Invalid UUID). If the cdkey isn't a valid key, return type 300 - Invalid Key.
  13.  
  14. # First time customer :  
  15. # Admin mode > passwd set> enter cdkey > check if key valid and uuid unset> set cdkey value as uuid> return good status
  16.  
  17. #Customer needs to replace computer, trys to install software, it already has a UUID associated with it, so a message appears stating so, and a contact numer. We would just unset the UUID, and let
  18. # them reinstall.
  19.  
  20. #This is the cdkey checker upon admin>cdkey enter  
  21. @app.route("/checkkey/<cdkey>/<uuidNum>", methods=['POST', "GET"])
  22. @cross_origin()
  23. def checkKey(cdkey, uuidNum):
  24.     #REMEMBER TO CHANGE BEFORE UPLOADING TO SERVER
  25.     cd_key_file = os.getcwd() + "\\static\\keys.json"
  26.     with open(cd_key_file, 'r+') as keyfile:
  27.         keydata = json.load(keyfile)
  28.         #Check each cd key available, and test against given information (cdkey/ uuid)
  29.         if cdkey in keydata['certificates']['keys'].keys():
  30.             if keydata['certificates']['keys'][cdkey] == "unset":
  31.                 with open(cd_key_file, 'w') as writekeyfile:
  32.                     keydata['certificates']['keys'][cdkey] = uuidNum
  33.                     json.dump(keydata, writekeyfile)
  34.                 print('100 - Valid - Key Registered')
  35.                 return str('100 - Valid - Key Registered')
  36.  
  37.             elif keydata['certificates']['keys'][cdkey] == uuidNum:
  38.                 print('100 - Valid')
  39.                 return str('100 - Valid')
  40.             else:
  41.                 print('200 - Cd key already in use')
  42.                 return str('200 - Cd key already in use on another computer. Please purchase another license key.')
  43.         else:
  44.             print('300 - Invalid Key')
  45.             return str('300 - Invalid Key')
  46.  
  47.  
  48. if __name__ == "__main__":
  49.     app.run(host="127.0.0.1", port="80")
  50.  
  51.  
  52. ------------------------------
  53. cdserver.yaml
  54.  
  55. runtime: python37
  56. handlers:
  57. - url: /*
  58.   http_headers:
  59.     Access-Control-Allow-Origin: *
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement