From 7c7e5de09198fb0309b822fad22e20873334b061 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 5 Feb 2020 20:31:38 -0600 Subject: [PATCH] do not allow restart on windows --- src/etc/onionrvalues.py | 3 ++- src/httpapi/miscclientapi/endpoints.py | 5 +++++ src/onionrcommands/restartonionr.py | 7 ++++-- src/runtests/__init__.py | 4 +++- src/runtests/osver.py | 8 +++++++ static-data/www/onboarding/index.html | 5 ----- static-data/www/private/index.html | 4 +++- static-data/www/private/js/windows.js | 26 ++++++++++++++++++++++ static-data/www/shared/getos.js | 30 ++++++++++++++++++++++++++ tests/runtime-result.txt | 2 +- 10 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 src/runtests/osver.py create mode 100644 static-data/www/private/js/windows.js create mode 100644 static-data/www/shared/getos.js diff --git a/src/etc/onionrvalues.py b/src/etc/onionrvalues.py index 6a878202..49515836 100755 --- a/src/etc/onionrvalues.py +++ b/src/etc/onionrvalues.py @@ -23,7 +23,8 @@ import filepaths DENIABLE_PEER_ADDRESS = "OVPCZLOXD6DC5JHX4EQ3PSOGAZ3T24F75HQLIUZSDSMYPEOXCPFA" PASSWORD_LENGTH = 25 ONIONR_TAGLINE = 'Private P2P Communication - GPLv3 - https://Onionr.net' -ONIONR_VERSION = '1.1.0' +ONIONR_VERSION = '2.0.0' +ONIONR_VERSION_CODENAME = 'Genesis' ONIONR_VERSION_TUPLE = tuple(ONIONR_VERSION.split('.')) # (MAJOR, MINOR, VERSION) API_VERSION = '0' # increments of 1; only change when something fundamental about how the API works changes. This way other nodes know how to communicate without learning too much information about you. MIN_PY_VERSION = 7 # min version of 7 so we can take advantage of non-cyclic type hints diff --git a/src/httpapi/miscclientapi/endpoints.py b/src/httpapi/miscclientapi/endpoints.py index 2f0581b8..186dfcae 100644 --- a/src/httpapi/miscclientapi/endpoints.py +++ b/src/httpapi/miscclientapi/endpoints.py @@ -4,6 +4,7 @@ Misc client API endpoints too small to need their own file and that need access """ import os import subprocess +import platform from flask import Response, Blueprint, request, send_from_directory, abort from gevent import spawn @@ -130,4 +131,8 @@ class PrivateEndpoints: @private_endpoints_bp.route('/setonboarding', methods=['POST']) def set_onboarding(): return Response(config.onboarding.set_config_from_onboarding(request.get_json())) + + @private_endpoints_bp.route('/os') + def get_os_system(): + return Response(platform.system().lower()) diff --git a/src/onionrcommands/restartonionr.py b/src/onionrcommands/restartonionr.py index 2785d193..e006a758 100644 --- a/src/onionrcommands/restartonionr.py +++ b/src/onionrcommands/restartonionr.py @@ -36,6 +36,10 @@ SCRIPT_NAME = os.path.dirname(os.path.realpath( def restart(): """Tell the Onionr daemon to restart.""" + if platform.system() == 'Windows': + logger.warn('Cannot restart Onionr on Windows. Run stop and manually restart.', terminal=True) + return + logger.info('Restarting Onionr', terminal=True) # On platforms where we can, fork out to prevent locking @@ -44,8 +48,7 @@ def restart(): if pid != 0: return except (AttributeError, OSError): - if platform.platform() != 'Windows': - logger.warn('Could not fork on restart') + logger.warn('Could not fork on restart') daemonlaunch.kill_daemon() while localcommand.local_command('ping', maxWait=8) == 'pong!': diff --git a/src/runtests/__init__.py b/src/runtests/__init__.py index 2dbfa931..9da68437 100644 --- a/src/runtests/__init__.py +++ b/src/runtests/__init__.py @@ -10,6 +10,7 @@ from onionrutils import epoch from . import uicheck, inserttest, stresstest from . import ownnode from .webpasstest import webpass_test +from .osver import test_os_ver_endpoint """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -30,7 +31,8 @@ RUN_TESTS = [uicheck.check_ui, ownnode.test_tor_adder, ownnode.test_own_node, stresstest.stress_test_block_insert, - webpass_test + webpass_test, + test_os_ver_endpoint ] SUCCESS_FILE = os.path.dirname(os.path.realpath(__file__)) + '/../../tests/runtime-result.txt' diff --git a/src/runtests/osver.py b/src/runtests/osver.py new file mode 100644 index 00000000..98ba46f4 --- /dev/null +++ b/src/runtests/osver.py @@ -0,0 +1,8 @@ +import platform + +from onionrutils import localcommand + + +def test_os_ver_endpoint(test_manager): + if localcommand.local_command('os') != platform.system().lower(): + raise ValueError('could not get proper os platform from endpoint /os') diff --git a/static-data/www/onboarding/index.html b/static-data/www/onboarding/index.html index 276b0cb0..0488d77c 100644 --- a/static-data/www/onboarding/index.html +++ b/static-data/www/onboarding/index.html @@ -51,11 +51,6 @@ Shutdown

-

- - Restart - -

diff --git a/static-data/www/private/index.html b/static-data/www/private/index.html index ead38f61..60752756 100755 --- a/static-data/www/private/index.html +++ b/static-data/www/private/index.html @@ -17,6 +17,7 @@ + @@ -25,7 +26,8 @@ - + + diff --git a/static-data/www/private/js/windows.js b/static-data/www/private/js/windows.js new file mode 100644 index 00000000..5a6dabf2 --- /dev/null +++ b/static-data/www/private/js/windows.js @@ -0,0 +1,26 @@ +/* + Onionr - Private P2P Communication + + Hide restart button if node OS is windows + since restart is broken on windows + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +var hideRestartIfWindows = function(){ + if (onionrNodeOS === 'windows'){ + document.getElementById('restartNode').style.display = 'none' + } +} + +setTimeout(function(){hideRestartIfWindows()}, 500) diff --git a/static-data/www/shared/getos.js b/static-data/www/shared/getos.js new file mode 100644 index 00000000..888fe04d --- /dev/null +++ b/static-data/www/shared/getos.js @@ -0,0 +1,30 @@ +/* + Onionr - Private P2P Communication + + Get node OS version (not browser) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +onionrNodeOS = "" + +fetch('/os', { + method: 'GET', + headers: { + "token": webpass + }}) +.then((resp) => resp.text()) // Transform the data into text +.then(function(os) { + onionrNodeOS = os + }) diff --git a/tests/runtime-result.txt b/tests/runtime-result.txt index b2e7f967..804d12b3 100644 --- a/tests/runtime-result.txt +++ b/tests/runtime-result.txt @@ -1 +1 @@ -1580888911 \ No newline at end of file +1580971981 \ No newline at end of file