Skip to content

Commit

Permalink
Remove tor and add cert in config
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomtibo committed Jan 9, 2021
1 parent 23429bf commit ea57bba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
7 changes: 1 addition & 6 deletions cn-cli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import json
import sys
from libcn.libcn import CypherNode
def main(conf):
cn = CypherNode(cnid=conf.cnid[0], key=conf.key[0], url=conf.url[0], tor=conf.tor, unsecure=conf.unsecure, verbose=conf.verbose, configfile=conf.configfile, cert=conf.cert)
cn = CypherNode(cnid=conf.cnid[0], key=conf.key[0], url=conf.url[0], unsecure=conf.unsecure, verbose=conf.verbose, configfile=conf.configfile, cert=conf.cert)
resp = None
if conf.info == True:
if conf.command:
Expand All @@ -15,9 +15,6 @@ def main(conf):
data = cn.get_token()
print(data)
else:
if conf.showip:
data = cn.show_ip()
print(data['ip'])
if conf.arguments:
resp = eval('cn.{}{}'.format(conf.command, tuple(conf.arguments)))
elif not conf.arguments:
Expand All @@ -41,8 +38,6 @@ if __name__=='__main__':
conf.add_argument('-c', '--configfile', nargs=1, type=str, default="{}/.cn/cn.conf".format(os.path.expanduser('~')), help='Define the configuration file path')
conf.add_argument('-i', '--info', action="store_true", default=False, help='Get command informations')
conf.add_argument('--token', action="store_true", default=None, help='Generate and return autorisation token')
conf.add_argument('--showip', action="store_true", default=None, help='Show IP addresse used for the request. Used with --tor')
conf.add_argument('-t', '--tor', nargs=1, type=str, default=False, help='Use local tor daemon for request. Need HTTPTunnelPort enabled in \'/etc/tor/torrc\'')
conf.add_argument('-u', '--unsecure', action="store_true", default=None, help='Ignore ssl certificate error')
conf.add_argument('-j', '--json', action="store_true", default=None, help='Use json indentation formating')
conf.add_argument('-v', '--verbose', action="store_true", help='Use verbose mode')
Expand Down
23 changes: 8 additions & 15 deletions libcn/libcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def __init__(self, \
url=None, \
cert=None, \
configfile="{}/.cn/cn.conf".format(os.path.expanduser('~')), \
tor=False, \
unsecure=False, \
showip=False, \
verbose=False):
"""Cyphernode object reprensenting a cyphernode server"""
stats_cmd = ['getblockchaininfo', 'getblockhash', \
Expand Down Expand Up @@ -51,6 +49,7 @@ def __init__(self, \
self.cnid = cnid
self.key = key
self.url = url
self.cert = cert
try:
if configfile: # If no explicit config provided, search for configfile in ~/.cn/cn.conf
config = configparser.ConfigParser()
Expand All @@ -59,6 +58,7 @@ def __init__(self, \
self.cnid = "{}".format(config.get(k, 'cnid')).replace('"', '')
self.key = "{}".format(config.get(k, 'key')).replace('"', '')
self.url = "{}".format(config.get(k, 'url')).replace('"', '')
self.cert = "{}".format(config.get(k, 'cert')).replace('"', '')
self.auth = []
if self.cnid == '003':
for itm in stats_cmd, watcher_cmd, spender_cmd, admin_cmd:
Expand All @@ -79,17 +79,13 @@ def __init__(self, \
print('Authentification failed !')
return None
self.req = ['endpoint', 'headers=headers']
if tor:
print("Tor Activated!")
self.req.append('proxies={"https": "127.0.0.1:{}"}'.format(tor))
if unsecure:
urllib3.disable_warnings()
self.req.append('verify=False')
elif self.cert:
self.req.append('verify="{}"'.format(self.cert))
else:
if cert:
self.req.append('verify="{}"'.format(cert[0]))
else:
self.req.append('verify=True')
print('Error! Invalid ssl certificate, use --cert with a valid cert, or bypass cert validation with the -u, --unsecure option')
if verbose:
self.verbose()
def inform(self, command):
Expand Down Expand Up @@ -133,18 +129,13 @@ def get_headers(self):
headers["Authorization"] = "Bearer {}".format(self.get_token())
headers["Connection"] = "close"
return headers
def show_ip(self):
endpoint = "https://api.myip.com"
headers = {"accept": "applicaition/json", "Connection":"close"}
request = "self.requests.get{}.json()".format(tuple(self.req)).replace('\'', '')
response = eval(request)
return response
def get_data(self, call, endpoint):
"""Get data request"""
if call in self.auth:
headers = self.get_headers()
if headers and endpoint:
request = "self.requests.get{}.json()".format(tuple(self.req)).replace('\'', '')
#print(request)
response = eval(request)
return response
else:
Expand All @@ -158,6 +149,7 @@ def post_data(self, call, endpoint, payload):
if headers and endpoint and payload:
self.req.append('data=payload')
request = "self.requests.post{}.json()".format(tuple(self.req)).replace('\'', '')
#print(request)
response = eval(request)
return response
else:
Expand Down Expand Up @@ -585,6 +577,7 @@ def ots_backoffice(self):#########
#endpoint = "{}/{}".format(self.url, call)
#response = self.get_data(call, endpoint)
#return response

class CallbackServer:
"""CallbackServer is a socket server used in a child class to
listen incoming callbacks request"""
Expand Down

0 comments on commit ea57bba

Please sign in to comment.