From 8e01063f94146ff1e1c93b297692109156099cdf Mon Sep 17 00:00:00 2001 From: Arinerron Date: Mon, 30 Jul 2018 21:52:48 -0700 Subject: [PATCH] Move to www --- onionr/api.py | 48 +++++++++++++++--- onionr/static-data/default_config.json | 16 ++++-- onionr/static-data/{ => www}/ui/README.md | 0 .../{ => www}/ui/common/footer.html | 0 .../{ => www}/ui/common/header.html | 0 .../ui/common/onionr-timeline-post.html | 0 onionr/static-data/{ => www}/ui/compile.py | 0 onionr/static-data/{ => www}/ui/config.json | 0 .../{ => www}/ui/dist/css/main.css | 0 .../{ => www}/ui/dist/css/themes/dark.css | 0 .../{ => www}/ui/dist/img/default.png | Bin .../static-data/{ => www}/ui/dist/index.html | 0 .../static-data/{ => www}/ui/dist/js/main.js | 0 .../{ => www}/ui/dist/js/timeline.js | 0 onionr/static-data/{ => www}/ui/lang.json | 0 .../static-data/{ => www}/ui/src/css/main.css | 0 .../{ => www}/ui/src/css/themes/dark.css | 0 .../{ => www}/ui/src/img/default.png | Bin .../static-data/{ => www}/ui/src/index.html | 0 .../static-data/{ => www}/ui/src/js/main.js | 0 .../{ => www}/ui/src/js/timeline.js | 0 21 files changed, 54 insertions(+), 10 deletions(-) rename onionr/static-data/{ => www}/ui/README.md (100%) rename onionr/static-data/{ => www}/ui/common/footer.html (100%) rename onionr/static-data/{ => www}/ui/common/header.html (100%) rename onionr/static-data/{ => www}/ui/common/onionr-timeline-post.html (100%) rename onionr/static-data/{ => www}/ui/compile.py (100%) rename onionr/static-data/{ => www}/ui/config.json (100%) rename onionr/static-data/{ => www}/ui/dist/css/main.css (100%) rename onionr/static-data/{ => www}/ui/dist/css/themes/dark.css (100%) rename onionr/static-data/{ => www}/ui/dist/img/default.png (100%) rename onionr/static-data/{ => www}/ui/dist/index.html (100%) rename onionr/static-data/{ => www}/ui/dist/js/main.js (100%) rename onionr/static-data/{ => www}/ui/dist/js/timeline.js (100%) rename onionr/static-data/{ => www}/ui/lang.json (100%) rename onionr/static-data/{ => www}/ui/src/css/main.css (100%) rename onionr/static-data/{ => www}/ui/src/css/themes/dark.css (100%) rename onionr/static-data/{ => www}/ui/src/img/default.png (100%) rename onionr/static-data/{ => www}/ui/src/index.html (100%) rename onionr/static-data/{ => www}/ui/src/js/main.js (100%) rename onionr/static-data/{ => www}/ui/src/js/timeline.js (100%) diff --git a/onionr/api.py b/onionr/api.py index e9ecd475..4da9364c 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -117,8 +117,8 @@ class API: return resp - @app.route('/client/ui/') - def webUI(path): + @app.route('/www/private/') + def www_private(path): startTime = math.floor(time.time()) if request.args.get('timingToken') is None: @@ -126,10 +126,10 @@ class API: else: timingToken = request.args.get('timingToken') - if not config.get("onionr_ui.run", True): + if not config.get("www.private.run", True): abort(403) - if config.get("onionr_ui.private_only", True): - self.validateHost('private') + + self.validateHost('private') endTime = math.floor(time.time()) elapsed = endTime - startTime @@ -138,7 +138,42 @@ class API: if elapsed < self._privateDelayTime: time.sleep(self._privateDelayTime - elapsed) - return send_from_directory('static-data/ui/dist/', path) + return send_from_directory('static-data/www/private/', path) + + @app.route('/www/public/') + def www_public(path): + if not config.get("www.public.run", True): + abort(403) + + self.validateHost('public') + + return send_from_directory('static-data/www/public/', path) + + @app.route('/www/ui/') + def ui_private(path): + startTime = math.floor(time.time()) + + if request.args.get('timingToken') is None: + timingToken = '' + else: + timingToken = request.args.get('timingToken') + + if not config.get("www.ui.run", True): + abort(403) + + if config.get("www.ui.private", True): + self.validateHost('private') + else: + self.validateHost('public') + + endTime = math.floor(time.time()) + elapsed = endTime - startTime + + if not hmac.compare_digest(timingToken, self.timeBypassToken): + if elapsed < self._privateDelayTime: + time.sleep(self._privateDelayTime - elapsed) + + return send_from_directory('static-data/www/ui/dist/', path) @app.route('/client/') def private_handler(): @@ -270,7 +305,6 @@ class API: except: data = '' - events.event('webapi_public', onionr = None, data = {'action' : action, 'data' : data, 'requestingPeer' : requestingPeer, 'request' : request}) if action == 'firstConnect': diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 663bd732..04c00835 100644 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -9,9 +9,19 @@ } }, - "onionr_ui" : { - "run" : true, - "private_only" : true + "www" : { + "public" : { + "run" : true + }, + + "private" : { + "run" : true + }, + + "ui" : { + "run" : true, + "private" : true + } }, "client" : { diff --git a/onionr/static-data/ui/README.md b/onionr/static-data/www/ui/README.md similarity index 100% rename from onionr/static-data/ui/README.md rename to onionr/static-data/www/ui/README.md diff --git a/onionr/static-data/ui/common/footer.html b/onionr/static-data/www/ui/common/footer.html similarity index 100% rename from onionr/static-data/ui/common/footer.html rename to onionr/static-data/www/ui/common/footer.html diff --git a/onionr/static-data/ui/common/header.html b/onionr/static-data/www/ui/common/header.html similarity index 100% rename from onionr/static-data/ui/common/header.html rename to onionr/static-data/www/ui/common/header.html diff --git a/onionr/static-data/ui/common/onionr-timeline-post.html b/onionr/static-data/www/ui/common/onionr-timeline-post.html similarity index 100% rename from onionr/static-data/ui/common/onionr-timeline-post.html rename to onionr/static-data/www/ui/common/onionr-timeline-post.html diff --git a/onionr/static-data/ui/compile.py b/onionr/static-data/www/ui/compile.py similarity index 100% rename from onionr/static-data/ui/compile.py rename to onionr/static-data/www/ui/compile.py diff --git a/onionr/static-data/ui/config.json b/onionr/static-data/www/ui/config.json similarity index 100% rename from onionr/static-data/ui/config.json rename to onionr/static-data/www/ui/config.json diff --git a/onionr/static-data/ui/dist/css/main.css b/onionr/static-data/www/ui/dist/css/main.css similarity index 100% rename from onionr/static-data/ui/dist/css/main.css rename to onionr/static-data/www/ui/dist/css/main.css diff --git a/onionr/static-data/ui/dist/css/themes/dark.css b/onionr/static-data/www/ui/dist/css/themes/dark.css similarity index 100% rename from onionr/static-data/ui/dist/css/themes/dark.css rename to onionr/static-data/www/ui/dist/css/themes/dark.css diff --git a/onionr/static-data/ui/dist/img/default.png b/onionr/static-data/www/ui/dist/img/default.png similarity index 100% rename from onionr/static-data/ui/dist/img/default.png rename to onionr/static-data/www/ui/dist/img/default.png diff --git a/onionr/static-data/ui/dist/index.html b/onionr/static-data/www/ui/dist/index.html similarity index 100% rename from onionr/static-data/ui/dist/index.html rename to onionr/static-data/www/ui/dist/index.html diff --git a/onionr/static-data/ui/dist/js/main.js b/onionr/static-data/www/ui/dist/js/main.js similarity index 100% rename from onionr/static-data/ui/dist/js/main.js rename to onionr/static-data/www/ui/dist/js/main.js diff --git a/onionr/static-data/ui/dist/js/timeline.js b/onionr/static-data/www/ui/dist/js/timeline.js similarity index 100% rename from onionr/static-data/ui/dist/js/timeline.js rename to onionr/static-data/www/ui/dist/js/timeline.js diff --git a/onionr/static-data/ui/lang.json b/onionr/static-data/www/ui/lang.json similarity index 100% rename from onionr/static-data/ui/lang.json rename to onionr/static-data/www/ui/lang.json diff --git a/onionr/static-data/ui/src/css/main.css b/onionr/static-data/www/ui/src/css/main.css similarity index 100% rename from onionr/static-data/ui/src/css/main.css rename to onionr/static-data/www/ui/src/css/main.css diff --git a/onionr/static-data/ui/src/css/themes/dark.css b/onionr/static-data/www/ui/src/css/themes/dark.css similarity index 100% rename from onionr/static-data/ui/src/css/themes/dark.css rename to onionr/static-data/www/ui/src/css/themes/dark.css diff --git a/onionr/static-data/ui/src/img/default.png b/onionr/static-data/www/ui/src/img/default.png similarity index 100% rename from onionr/static-data/ui/src/img/default.png rename to onionr/static-data/www/ui/src/img/default.png diff --git a/onionr/static-data/ui/src/index.html b/onionr/static-data/www/ui/src/index.html similarity index 100% rename from onionr/static-data/ui/src/index.html rename to onionr/static-data/www/ui/src/index.html diff --git a/onionr/static-data/ui/src/js/main.js b/onionr/static-data/www/ui/src/js/main.js similarity index 100% rename from onionr/static-data/ui/src/js/main.js rename to onionr/static-data/www/ui/src/js/main.js diff --git a/onionr/static-data/ui/src/js/timeline.js b/onionr/static-data/www/ui/src/js/timeline.js similarity index 100% rename from onionr/static-data/ui/src/js/timeline.js rename to onionr/static-data/www/ui/src/js/timeline.js