2019-12-19 10:34:19 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
2019-03-02 06:22:59 +00:00
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
Open the web interface properly into a web browser
|
|
|
|
"""
|
|
|
|
import webbrowser
|
2020-02-12 01:49:44 +00:00
|
|
|
from time import sleep
|
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
import logger
|
|
|
|
from onionrutils import getclientapiserver
|
|
|
|
import config
|
2020-02-12 01:49:44 +00:00
|
|
|
from onionrutils.localcommand import local_command
|
2021-01-16 02:08:36 +00:00
|
|
|
|
|
|
|
from .daemonlaunch import geturl
|
2019-12-19 10:34:19 +00:00
|
|
|
"""
|
2019-03-02 06:22:59 +00:00
|
|
|
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 <https://www.gnu.org/licenses/>.
|
2019-12-19 10:34:19 +00:00
|
|
|
"""
|
|
|
|
|
2019-09-30 03:03:55 +00:00
|
|
|
|
2020-02-12 01:49:44 +00:00
|
|
|
def _tell_if_ui_not_ready():
|
|
|
|
if local_command('/torready') != 'true':
|
|
|
|
logger.warn('The UI is not ready yet, waiting on Tor to start.', terminal=True)
|
|
|
|
|
|
|
|
|
|
|
|
def _wait_for_ui_to_be_ready():
|
|
|
|
if config.get('general.offline_mode', False) or \
|
|
|
|
not config.get('transports.tor', True) or \
|
|
|
|
config.get('tor.use_existing_tor'):
|
|
|
|
return
|
|
|
|
_tell_if_ui_not_ready()
|
|
|
|
while local_command('/torready') != 'true':
|
|
|
|
sleep(0.5)
|
|
|
|
logger.info("Tor is ready, opening UI", terminal=True)
|
|
|
|
|
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
def get_url() -> str:
|
|
|
|
"""Build UI URL string and return it."""
|
2021-01-16 02:08:36 +00:00
|
|
|
geturl.get_url(config)
|
2019-09-30 03:03:55 +00:00
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
|
|
|
|
get_url.onionr_help = "Shows the Onionr " # type: ignore
|
|
|
|
get_url.onionr_help += "web interface URL with API key" # type: ignore
|
|
|
|
|
2019-09-30 03:03:55 +00:00
|
|
|
|
2019-08-05 04:08:56 +00:00
|
|
|
def open_home():
|
2019-12-19 10:34:19 +00:00
|
|
|
"""Command to open web interface URL in default browser."""
|
2019-06-12 20:12:56 +00:00
|
|
|
try:
|
2019-07-19 04:59:44 +00:00
|
|
|
url = getclientapiserver.get_client_API_server()
|
2019-06-12 20:12:56 +00:00
|
|
|
except FileNotFoundError:
|
2019-12-19 10:34:19 +00:00
|
|
|
logger.error(
|
|
|
|
'Onionr seems to not be running (could not get api host)',
|
|
|
|
terminal=True)
|
2019-06-12 20:12:56 +00:00
|
|
|
else:
|
2020-02-17 12:13:57 +00:00
|
|
|
_wait_for_ui_to_be_ready() # wait for Tor/transports to start
|
|
|
|
sleep(3) # Sleep a little longer to wait for web UI to init some vars it needs
|
2020-02-12 01:49:44 +00:00
|
|
|
url = get_url()
|
2019-12-19 10:34:19 +00:00
|
|
|
logger.info(
|
|
|
|
'If Onionr does not open automatically, use this URL: ' + url,
|
|
|
|
terminal=True)
|
2019-09-21 05:06:49 +00:00
|
|
|
webbrowser.open_new_tab(url)
|
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
|
|
|
|
open_home.onionr_help = "Opens the Onionr UI in the default " # type: ignore
|
|
|
|
open_home.onionr_help += "browser. Node must be running." # type: ignore
|