From ce2095d7f8802b161acae1f9cb289ca9c0209d7f Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 16 Jun 2019 17:34:43 -0500 Subject: [PATCH] + added hit count stat - removed bypass_tor_check as defunct config option * actually fixed connect stat in cli for real this time * improved ui stats more --- docs/http-api.md | 3 +++ onionr/api.py | 6 ++++++ onionr/netcontroller.py | 1 - onionr/onionrcommands/onionrstatistics.py | 2 +- .../default-plugins/pluginmanager/main.py | 2 -- .../static-data/default-plugins/pms/main.py | 5 +++-- onionr/static-data/default_config.json | 21 +++++++++---------- onionr/static-data/www/private/index.html | 13 +++++++----- onionr/static-data/www/shared/main/stats.js | 5 ++++- onionr/static-data/www/shared/main/style.css | 2 +- 10 files changed, 36 insertions(+), 24 deletions(-) diff --git a/docs/http-api.md b/docs/http-api.md index 241320ae..74745e1a 100755 --- a/docs/http-api.md +++ b/docs/http-api.md @@ -37,6 +37,9 @@ Please note: endpoints that simply provide static web app files are not document * /getblockheader/hash - Methods: GET - Returns the header (metadata section) of a block. +* /hitcount + - Methods: GET + - Return the amount of requests the public api server has received this session * /lastconnect - Methods: GET - Returns the epoch timestamp of when the last incoming connection to the public API server was logged diff --git a/onionr/api.py b/onionr/api.py index 854711f0..ab1eeb59 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -76,6 +76,7 @@ class PublicAPI: self.i2pAdder = clientAPI._core.i2pAddress self.bindPort = config.get('client.public.port') self.lastRequest = 0 + self.hitCount = 0 # total rec requests to public api since server started logger.info('Running public api on %s:%s' % (self.host, self.bindPort)) @app.before_request @@ -90,6 +91,7 @@ class PublicAPI: if request.host not in (self.i2pAdder, self.torAdder): # Disallow connection if wrong HTTP hostname, in order to prevent DNS rebinding attacks abort(403) + self.hitCount += 1 # raise hit count for valid requests @app.after_request def sendHeaders(resp): @@ -295,6 +297,10 @@ class API: abort(403) return send_from_directory(config.get('www.private.path', 'static-data/www/private/'), path) + @app.route('/hitcount') + def get_hit_count(): + return Response(str(self.publicAPI.hitCount)) + @app.route('/queueResponseAdd/', methods=['post']) def queueResponseAdd(name): # Responses from the daemon. TODO: change to direct var access instead of http endpoint diff --git a/onionr/netcontroller.py b/onionr/netcontroller.py index 79f77692..74087500 100755 --- a/onionr/netcontroller.py +++ b/onionr/netcontroller.py @@ -72,7 +72,6 @@ class NetController: hsVer = '# v2 onions' if config.get('tor.v3onions'): hsVer = 'HiddenServiceVersion 3' - logger.debug('Using v3 onions') if os.path.exists(self.torConfigLocation): os.remove(self.torConfigLocation) diff --git a/onionr/onionrcommands/onionrstatistics.py b/onionr/onionrcommands/onionrstatistics.py index 88643b0c..918d8445 100755 --- a/onionr/onionrcommands/onionrstatistics.py +++ b/onionr/onionrcommands/onionrstatistics.py @@ -39,7 +39,7 @@ def show_stats(o_inst): # count stats 'div2' : True, - 'Known Peers' : str(len(o_inst.onionrCore.listPeers())), + 'Known Peers' : str(max(len(o_inst.onionrCore.listPeers()) - 1, 0)), 'Enabled Plugins' : str(len(o_inst.onionrCore.config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(o_inst.dataDir + 'plugins/'))), 'Stored Blocks' : str(totalBlocks), 'Percent Blocks Signed' : str(round(100 * signedBlocks / max(totalBlocks, 1), 2)) + '%' diff --git a/onionr/static-data/default-plugins/pluginmanager/main.py b/onionr/static-data/default-plugins/pluginmanager/main.py index aa5c2887..979b1133 100755 --- a/onionr/static-data/default-plugins/pluginmanager/main.py +++ b/onionr/static-data/default-plugins/pluginmanager/main.py @@ -389,8 +389,6 @@ def commandInstallPlugin(): pkobh = distributor except Exception as e: logger.warn('Failed to lookup plugin in repositories.', timestamp = False) - logger.error('asdf', error = e, timestamp = False) - return True if pkobh is None: diff --git a/onionr/static-data/default-plugins/pms/main.py b/onionr/static-data/default-plugins/pms/main.py index ce58c58e..9acb99f2 100755 --- a/onionr/static-data/default-plugins/pms/main.py +++ b/onionr/static-data/default-plugins/pms/main.py @@ -303,9 +303,10 @@ def add_deleted(keyStore, bHash): keyStore.put('deleted_mail', existing.append(bHash)) def on_insertblock(api, data={}): - sentboxTools = sentboxdb.SentBox(api.get_core()) meta = json.loads(data['meta']) - sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject']) + if meta['type'] == 'pm': + sentboxTools = sentboxdb.SentBox(api.get_core()) + sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject']) def on_init(api, data = None): ''' diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 65cad2f5..cd68ede8 100755 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -2,17 +2,16 @@ "general" : { "dev_mode" : true, "display_header" : false, - "minimum_block_pow": 4, - "minimum_send_pow": 4, - "use_subprocess_pow_if_possible": true, - "socket_servers": false, - "security_level": 0, - "hide_created_blocks": true, - "insert_deniable_blocks": true, - "max_block_age": 2678400, - "bypass_tor_check": false, - "public_key": "", - "random_bind_ip": false + "minimum_block_pow" : 4, + "minimum_send_pow" : 4, + "use_subprocess_pow_if_possible" : true, + "socket_servers" : false, + "security_level" : 0, + "hide_created_blocks" : true, + "insert_deniable_blocks" : true, + "max_block_age" : 2678400, + "public_key" : "", + "random_bind_ip" : false }, "www" : { diff --git a/onionr/static-data/www/private/index.html b/onionr/static-data/www/private/index.html index 633bda94..07247011 100755 --- a/onionr/static-data/www/private/index.html +++ b/onionr/static-data/www/private/index.html @@ -23,7 +23,7 @@


-

Onionr Services

+

Onionr Services




Mail - Friend Manager - Boards - @@ -38,13 +38,16 @@
-

Stats

+

Statistics

🕰️ Uptime:

-

🖇️ Last Received Connection: None since start

-

💾 Stored Blocks:

-

📨 Blocks in queue:

+

Connections

+

🖇️ Last Received Request: None since start

+

⬇️ Total Requests Received: None since start

🔗 Outgoing Connections:


+            

Blocks

+

💾 Stored Blocks:

+

📨 Blocks in queue:

diff --git a/onionr/static-data/www/shared/main/stats.js b/onionr/static-data/www/shared/main/stats.js index 3c8d2af6..86b7f451 100755 --- a/onionr/static-data/www/shared/main/stats.js +++ b/onionr/static-data/www/shared/main/stats.js @@ -21,6 +21,7 @@ connectedDisplay = document.getElementById('connectedNodes') storedBlockDisplay = document.getElementById('storedBlocks') queuedBlockDisplay = document.getElementById('blockQueue') lastIncoming = document.getElementById('lastIncoming') +totalRec = document.getElementById('totalRec') function getStats(){ stats = JSON.parse(httpGet('getstats', webpass)) @@ -28,11 +29,13 @@ function getStats(){ connectedDisplay.innerText = stats['connectedNodes'] storedBlockDisplay.innerText = stats['blockCount'] queuedBlockDisplay.innerText = stats['blockQueueCount'] + totalRec.innerText = httpGet('/hitcount') var lastConnect = httpGet('/lastconnect') if (lastConnect > 0){ var humanDate = new Date(0) humanDate.setUTCSeconds(httpGet('/lastconnect')) - lastConnect = humanDate.toString() + humanDate = humanDate.toString() + lastConnect = humanDate.substring(0, humanDate.indexOf('(')); } else{ lastConnect = 'None since start' diff --git a/onionr/static-data/www/shared/main/style.css b/onionr/static-data/www/shared/main/style.css index c895696b..18388845 100755 --- a/onionr/static-data/www/shared/main/style.css +++ b/onionr/static-data/www/shared/main/style.css @@ -46,7 +46,7 @@ body{ margin-left: 1%; } - .logoText, h1, h2{ + .logoText, h1, h2, h3{ font-family: Verdana, Geneva, Tahoma, sans-serif; }