Wipe branch
This commit is contained in:
		
							
								
								
									
										76
									
								
								license.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								license.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,76 @@ | ||||
| from threading import Thread | ||||
| from time import sleep, time | ||||
| from macros import * | ||||
| from Crypto.Cipher import AES | ||||
| from Crypto.Random import get_random_bytes | ||||
| from hashlib import sha256 | ||||
| from base64 import b64decode | ||||
| from datetime import datetime | ||||
| from urllib import request | ||||
| import os, json, requests | ||||
|  | ||||
|  | ||||
| class LThread(Thread): | ||||
| 	_FIRST = True | ||||
|  | ||||
|  | ||||
| 	def __init__(self, event): | ||||
| 		super(LThread, self).__init__() | ||||
| 		self.event = event | ||||
|  | ||||
|  | ||||
| 	def check(self): | ||||
| 		url = 'https://license.bitheaven.ru/api/v1/license.check' | ||||
| 		post = { | ||||
| 			'key': CONF.get('license'), | ||||
| 			'loc': CONF.get('location'), | ||||
| 			'time': int(time()), | ||||
| 			'data': get_random_bytes(16) | ||||
| 		} | ||||
| 		curtime = post['time'] | ||||
|  | ||||
| 		try: | ||||
| 			req = requests.post(url, data=post).json() | ||||
| 		except requests.exceptions.RequestException as e: | ||||
| 			return False | ||||
|  | ||||
| 		if req['error']: | ||||
| 			ERR(f"Server error! {req['msg']}") | ||||
| 			return True | ||||
|  | ||||
| 		key = sha256(post['loc'].encode('utf-8')).hexdigest()[0:32].encode("utf-8") | ||||
| 		iv = post['data'] | ||||
| 		aes = AES.new(key, AES.MODE_OFB, iv=iv) | ||||
| 		msg = aes.decrypt(b64decode(req['data'])).decode('unicode_escape').strip() | ||||
|  | ||||
| 		until = datetime.fromtimestamp(req['until']).strftime('%d.%m.%Y') | ||||
|  | ||||
| 		if self._FIRST: | ||||
| 			INFO(f'License paid until: {until}') | ||||
| 			self._FIRST = False | ||||
|  | ||||
| 		return f"{CONF.get('license')}{curtime}" == msg | ||||
|  | ||||
|  | ||||
| 	def run(self): | ||||
| 		try: | ||||
| 			while 1: | ||||
| 				if self.event.is_set(): | ||||
| 					break | ||||
|  | ||||
| 				cur = self.check() | ||||
|  | ||||
| 				if not cur: | ||||
| 					try: | ||||
| 						request.urlopen('http://1.1.1.1', timeout=2) | ||||
| 						CRIT("License wrong or expired!") | ||||
| 						WARN("Get it on https://bhev.ru/glfbam") | ||||
| 						sleep(60) | ||||
| 					except: | ||||
| 						ERR("No access to network!") | ||||
| #					os._exit(1) | ||||
|  | ||||
| 				sleep(5) | ||||
| 		except Exception as e: | ||||
| 			CRIT(str(e)) | ||||
| 			os._exit(1) | ||||
		Reference in New Issue
	
	Block a user