domain validation
This commit is contained in:
parent
ba3ced4b8d
commit
435e7aae38
|
@ -45,7 +45,7 @@ rpcs = {
|
|||
}
|
||||
|
||||
DB = {
|
||||
'host': 'localhost',
|
||||
'host': '127.0.0.1',
|
||||
'port': 3306,
|
||||
'user': 'root',
|
||||
'pass': 'xegh3kAJyDLaRu'
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15
functions.py
15
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
|
||||
return False
|
35
main.py
35
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)
|
Loading…
Reference in New Issue