diff --git a/config.py b/config.py index ab0738e..eb3bf92 100755 --- a/config.py +++ b/config.py @@ -45,7 +45,7 @@ rpcs = { } DB = { - 'host': 'localhost', + 'host': '127.0.0.1', 'port': 3306, 'user': 'root', 'pass': 'xegh3kAJyDLaRu' diff --git a/dependencies/__pycache__/bchconvert.cpython-310.pyc b/dependencies/__pycache__/bchconvert.cpython-310.pyc deleted file mode 100644 index 6568ee9..0000000 Binary files a/dependencies/__pycache__/bchconvert.cpython-310.pyc and /dev/null differ diff --git a/dependencies/__pycache__/bchconvert.cpython-38.pyc b/dependencies/__pycache__/bchconvert.cpython-38.pyc deleted file mode 100755 index 9f58402..0000000 Binary files a/dependencies/__pycache__/bchconvert.cpython-38.pyc and /dev/null differ diff --git a/dependencies/__pycache__/bchconvert.cpython-39.pyc b/dependencies/__pycache__/bchconvert.cpython-39.pyc deleted file mode 100644 index 25a280f..0000000 Binary files a/dependencies/__pycache__/bchconvert.cpython-39.pyc and /dev/null differ diff --git a/dependencies/__pycache__/crypto.cpython-310.pyc b/dependencies/__pycache__/crypto.cpython-310.pyc deleted file mode 100644 index 457da7a..0000000 Binary files a/dependencies/__pycache__/crypto.cpython-310.pyc and /dev/null differ diff --git a/dependencies/__pycache__/crypto.cpython-38.pyc b/dependencies/__pycache__/crypto.cpython-38.pyc deleted file mode 100755 index 8dfee76..0000000 Binary files a/dependencies/__pycache__/crypto.cpython-38.pyc and /dev/null differ diff --git a/dependencies/__pycache__/crypto.cpython-39.pyc b/dependencies/__pycache__/crypto.cpython-39.pyc deleted file mode 100644 index 3f6babb..0000000 Binary files a/dependencies/__pycache__/crypto.cpython-39.pyc and /dev/null differ diff --git a/dependencies/__pycache__/moneropy.cpython-310.pyc b/dependencies/__pycache__/moneropy.cpython-310.pyc deleted file mode 100644 index b487422..0000000 Binary files a/dependencies/__pycache__/moneropy.cpython-310.pyc and /dev/null differ diff --git a/dependencies/__pycache__/moneropy.cpython-38.pyc b/dependencies/__pycache__/moneropy.cpython-38.pyc deleted file mode 100755 index 476f93e..0000000 Binary files a/dependencies/__pycache__/moneropy.cpython-38.pyc and /dev/null differ diff --git a/dependencies/__pycache__/moneropy.cpython-39.pyc b/dependencies/__pycache__/moneropy.cpython-39.pyc deleted file mode 100644 index c3f328b..0000000 Binary files a/dependencies/__pycache__/moneropy.cpython-39.pyc and /dev/null differ diff --git a/dependencies/__pycache__/segwit_addr.cpython-310.pyc b/dependencies/__pycache__/segwit_addr.cpython-310.pyc deleted file mode 100644 index 6cd864f..0000000 Binary files a/dependencies/__pycache__/segwit_addr.cpython-310.pyc and /dev/null differ diff --git a/dependencies/__pycache__/segwit_addr.cpython-38.pyc b/dependencies/__pycache__/segwit_addr.cpython-38.pyc deleted file mode 100755 index b568bb3..0000000 Binary files a/dependencies/__pycache__/segwit_addr.cpython-38.pyc and /dev/null differ diff --git a/dependencies/__pycache__/segwit_addr.cpython-39.pyc b/dependencies/__pycache__/segwit_addr.cpython-39.pyc deleted file mode 100644 index bf3e190..0000000 Binary files a/dependencies/__pycache__/segwit_addr.cpython-39.pyc and /dev/null differ diff --git a/functions.py b/functions.py index dc75481..f6fe18b 100755 --- a/functions.py +++ b/functions.py @@ -34,6 +34,8 @@ def checksumCheck(method, address): match method.lower(): case 'btc': return decodeBase58(address) if address[0] == '1' or address[0] == '3' else True if address[0:3] == 'bc1' and segwit_addr.decode("bc", address)[0] != None else False + case 'btct': + return decodeBase58(address) if address[0] == '1' or address[0] == '3' else True if address[0:3] == 'tb1' and segwit_addr.decode("tb", address)[0] != None else False case 'ltc': return decodeBase58(address) if address[0] == '3' or address[0] == 'M' or address[0] == 'L' else True if address[0:4] == 'ltc1' and segwit_addr.decode("ltc", address)[0] != None else False case 'bch': @@ -44,15 +46,4 @@ def checksumCheck(method, address): #needs new function to check if address is valid, a decoder maybe return decodeMonero(address) case _: - return False - -def validDns(d): - try: - a = socket.gethostbyname(d) - except: - return False - # ip validation - if a.split('.')[0] in ['127', '0'] or '.'.join([a.split('.')[0], a.split('.')[1]]) == '192.168' or a in ['1.1.1.1','2.2.2.2', '3.3.3.3']: - return False - else: - return True \ No newline at end of file + return False \ No newline at end of file diff --git a/main.py b/main.py index 3d4427f..fa1bf63 100755 --- a/main.py +++ b/main.py @@ -1,20 +1,21 @@ +import time, socket, uvicorn + from typing import Optional, Union -from urllib.parse import urlparse from fastapi import FastAPI, Request from fastapi.responses import JSONResponse -import time, socket from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.pool import QueuePool -import uvicorn #local from rpcs import RPCHost, RPCXMR from models import Return from meta import Queue -from functions import checksumCheck, validDns +from functions import checksumCheck import config +from dependencies.validate_url import UrlValidator + class ErrorException(Exception): def __init__(self, code: str, status: str, status_message: str): self.status = status @@ -46,24 +47,16 @@ def receive(method: str, address: str, callback: Union[str, None] = None): if method.lower() not in ['btc', 'btct', 'ltc', 'doge', 'zec', 'bch', 'xmr']: raise ErrorException(code=422,status="error",status_message='Invalid method used') if checksumCheck(method.lower(), address) == False: - raise ErrorException(code=422,status="error",status_message='Invalid Destination Address') + raise ErrorException(code=422,status="error",status_message='Invalid destination address') if callback: - try: - data = urlparse(callback) - #scheme validation - if data.scheme == 'http' or data.scheme == 'https': - #domain validation - if validDns(data.netloc) != True: - raise ErrorException(code=422,status="error",status_message='Invalid callback: domain name does not resolve') - else: - raise ErrorException(code=422,status="error",status_message='Invalid callback: wrong url scheme, we accept http or https only') - except: - callback = 'None' - callback_req_n = 0 + if UrlValidator.validate(callback) != True: + raise ErrorException(code=422,status="error",status_message='Invalid callback') + callback_req_n = 1 else: callback = 'None' - callback_req_n = 1 + callback_req_n = 0 + ## RPC connection to Demons match method.upper(): @@ -114,13 +107,13 @@ def receive(method: str, address: str, callback: Union[str, None] = None): if wallet: try: - q = Queue(txhash = 'None', time = int(time.time()), account = method.upper(), fee = config.fee['REGULAR'][method.upper()], ready = 0, confirmations =0, callbackurl = callback, generated_address = wallet, destination = address, balance_received = '0.00000000', callback_req = callback_req_n, ip = socket.gethostbyname(socket.gethostname()) , hostname = socket.gethostname(), merchantId = 'None', dateTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + q = Queue(txhash = 'None', time = int(time.time()), account = method.upper(), fee = config.fee['REGULAR'][method.upper()], ready = 0, confirmations =0, callbackurl = callback, generated_address = wallet, destination = address, balance_received = '0.00000000', callback_req = callback_req_n, ip = '', hostname = '', merchantId = 'None', dateTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) session.add(q) session.commit() session.close() except Exception as error: ## notify admin about the error - raise ErrorException(code=422,status="error",status_message='Invalid response from dbServer') + raise ErrorException(code=422,status="error",status_message='Invalid response from dbServer:'+str(error)) else: ## notify admin about the error raise ErrorException(code=422,status="error",status_message='Invalid response from rpcServer') @@ -135,5 +128,5 @@ def receive(method: str, address: str, callback: Union[str, None] = None): # Run if __name__ == '__main__': - uvicorn.run('main:app', host='0.0.0.0') + uvicorn.run('main:app', host='0.0.0.0', reload=True, debug=True) #workers=4 (doesn't work with reload) \ No newline at end of file diff --git a/test.file b/test.file deleted file mode 100644 index e69de29..0000000