From 2baf794ae76d1f9e2f34dc836cf0684f9baaa38b Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 27 Dec 2017 19:18:00 -0500 Subject: [PATCH] made server multi threaded & config bugfix --- api.py | 8 ++++++-- onionr.py | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/api.py b/api.py index 90cf774c..0edeabab 100755 --- a/api.py +++ b/api.py @@ -15,7 +15,7 @@ ''' import flask from flask import request, Response -import configparser, sys, random +import configparser, sys, random, threading ''' Main API ''' @@ -34,6 +34,10 @@ class API: else: self.host = '127.0.0.1' + @app.before_request + def beforeReq(): + return + @app.after_request def afterReq(resp): resp.headers['Access-Control-Allow-Origin'] = '*' @@ -58,7 +62,7 @@ class API: print('Starting client on ' + self.host + ':' + str(bindPort)) print('Client token:', clientToken) - app.run(host=self.host, port=bindPort, debug=True) + app.run(host=self.host, port=bindPort, debug=True, threaded=True) def validateHost(self): if self.debug: diff --git a/onionr.py b/onionr.py index d8fb6dcd..fcffe4b5 100755 --- a/onionr.py +++ b/onionr.py @@ -20,10 +20,14 @@ class Onionr: def __init__(self): # Get configuration and Handle commands - + self.debug = True # Whole application debugging os.chdir(sys.path[0]) + + if not os.path.exists('data'): + os.mkdir('data') + # Get configuration self.config = configparser.ConfigParser() if os.path.exists('data/config.ini'): @@ -31,7 +35,7 @@ class Onionr: else: # Generate default config # Hostname should only be set if different from 127.x.x.x. Important for DNS rebinding attack prevention. - if debug: + if self.debug: randomPort = 8080 else: randomPort = random.randint(1024, 65535) @@ -65,4 +69,4 @@ class Onionr: def showHelp(self): return -Onionr() \ No newline at end of file +Onionr()