mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Save the slug when using a persistent private key
This commit is contained in:
parent
448f6af796
commit
3e7d4c64ff
@ -23,7 +23,7 @@ import os, sys, time, argparse, threading
|
|||||||
from . import strings, common, web
|
from . import strings, common, web
|
||||||
from .onion import *
|
from .onion import *
|
||||||
from .onionshare import OnionShare
|
from .onionshare import OnionShare
|
||||||
|
from .settings import Settings
|
||||||
|
|
||||||
def main(cwd=None):
|
def main(cwd=None):
|
||||||
"""
|
"""
|
||||||
@ -77,6 +77,10 @@ def main(cwd=None):
|
|||||||
if not valid:
|
if not valid:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
settings = Settings(config)
|
||||||
|
settings.load()
|
||||||
|
|
||||||
# Start the Onion object
|
# Start the Onion object
|
||||||
onion = Onion()
|
onion = Onion()
|
||||||
try:
|
try:
|
||||||
@ -108,7 +112,7 @@ def main(cwd=None):
|
|||||||
print('')
|
print('')
|
||||||
|
|
||||||
# Start OnionShare http service in new thread
|
# Start OnionShare http service in new thread
|
||||||
t = threading.Thread(target=web.start, args=(app.port, app.stay_open))
|
t = threading.Thread(target=web.start, args=(app.port, app.stay_open, settings.get('slug')))
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
@ -120,6 +124,12 @@ def main(cwd=None):
|
|||||||
if app.shutdown_timeout > 0:
|
if app.shutdown_timeout > 0:
|
||||||
app.shutdown_timer.start()
|
app.shutdown_timer.start()
|
||||||
|
|
||||||
|
# Save the web slug if we are using a persistent private key
|
||||||
|
if settings.get('save_private_key'):
|
||||||
|
if not settings.get('slug'):
|
||||||
|
settings.set('slug', web.slug)
|
||||||
|
settings.save()
|
||||||
|
|
||||||
if(stealth):
|
if(stealth):
|
||||||
print(strings._("give_this_url_stealth"))
|
print(strings._("give_this_url_stealth"))
|
||||||
print('http://{0:s}/{1:s}'.format(app.onion_host, web.slug))
|
print('http://{0:s}/{1:s}'.format(app.onion_host, web.slug))
|
||||||
|
@ -63,6 +63,7 @@ class Settings(object):
|
|||||||
'autoupdate_timestamp': None,
|
'autoupdate_timestamp': None,
|
||||||
'save_private_key': False,
|
'save_private_key': False,
|
||||||
'private_key': '',
|
'private_key': '',
|
||||||
|
'slug': '',
|
||||||
'hidservauth_string': ''
|
'hidservauth_string': ''
|
||||||
}
|
}
|
||||||
self._settings = {}
|
self._settings = {}
|
||||||
|
@ -128,9 +128,12 @@ def add_request(request_type, path, data=None):
|
|||||||
slug = None
|
slug = None
|
||||||
|
|
||||||
|
|
||||||
def generate_slug():
|
def generate_slug(persistent_slug=''):
|
||||||
global slug
|
global slug
|
||||||
slug = common.build_slug()
|
if persistent_slug:
|
||||||
|
slug = persistent_slug
|
||||||
|
else:
|
||||||
|
slug = common.build_slug()
|
||||||
|
|
||||||
download_count = 0
|
download_count = 0
|
||||||
error404_count = 0
|
error404_count = 0
|
||||||
@ -383,11 +386,11 @@ def force_shutdown():
|
|||||||
func()
|
func()
|
||||||
|
|
||||||
|
|
||||||
def start(port, stay_open=False):
|
def start(port, stay_open=False, persistent_slug=''):
|
||||||
"""
|
"""
|
||||||
Start the flask web server.
|
Start the flask web server.
|
||||||
"""
|
"""
|
||||||
generate_slug()
|
generate_slug(persistent_slug)
|
||||||
|
|
||||||
set_stay_open(stay_open)
|
set_stay_open(stay_open)
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
self.file_selection.file_list.add_file(filename)
|
self.file_selection.file_list.add_file(filename)
|
||||||
|
|
||||||
# Server status
|
# Server status
|
||||||
self.server_status = ServerStatus(self.qtapp, self.app, web, self.file_selection)
|
self.server_status = ServerStatus(self.qtapp, self.app, web, self.file_selection, self.settings)
|
||||||
self.server_status.server_started.connect(self.file_selection.server_started)
|
self.server_status.server_started.connect(self.file_selection.server_started)
|
||||||
self.server_status.server_started.connect(self.start_server)
|
self.server_status.server_started.connect(self.start_server)
|
||||||
self.server_status.server_stopped.connect(self.file_selection.server_stopped)
|
self.server_status.server_stopped.connect(self.file_selection.server_stopped)
|
||||||
@ -278,7 +278,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
self.app.stay_open = not self.settings.get('close_after_first_download')
|
self.app.stay_open = not self.settings.get('close_after_first_download')
|
||||||
|
|
||||||
# start onionshare http service in new thread
|
# start onionshare http service in new thread
|
||||||
t = threading.Thread(target=web.start, args=(self.app.port, self.app.stay_open))
|
t = threading.Thread(target=web.start, args=(self.app.port, self.app.stay_open, self.settings.get('slug')))
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
# wait for modules in thread to load, preventing a thread-related cx_Freeze crash
|
# wait for modules in thread to load, preventing a thread-related cx_Freeze crash
|
||||||
|
@ -21,7 +21,7 @@ import platform
|
|||||||
from .alert import Alert
|
from .alert import Alert
|
||||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
from onionshare import strings, common
|
from onionshare import strings, common, settings
|
||||||
|
|
||||||
class ServerStatus(QtWidgets.QVBoxLayout):
|
class ServerStatus(QtWidgets.QVBoxLayout):
|
||||||
"""
|
"""
|
||||||
@ -36,7 +36,7 @@ class ServerStatus(QtWidgets.QVBoxLayout):
|
|||||||
STATUS_WORKING = 1
|
STATUS_WORKING = 1
|
||||||
STATUS_STARTED = 2
|
STATUS_STARTED = 2
|
||||||
|
|
||||||
def __init__(self, qtapp, app, web, file_selection):
|
def __init__(self, qtapp, app, web, file_selection, settings):
|
||||||
super(ServerStatus, self).__init__()
|
super(ServerStatus, self).__init__()
|
||||||
self.status = self.STATUS_STOPPED
|
self.status = self.STATUS_STOPPED
|
||||||
|
|
||||||
@ -45,6 +45,8 @@ class ServerStatus(QtWidgets.QVBoxLayout):
|
|||||||
self.web = web
|
self.web = web
|
||||||
self.file_selection = file_selection
|
self.file_selection = file_selection
|
||||||
|
|
||||||
|
self.settings = settings
|
||||||
|
|
||||||
# Helper boolean as this is used in a few places
|
# Helper boolean as this is used in a few places
|
||||||
self.timer_enabled = False
|
self.timer_enabled = False
|
||||||
# Shutdown timeout layout
|
# Shutdown timeout layout
|
||||||
@ -141,6 +143,11 @@ class ServerStatus(QtWidgets.QVBoxLayout):
|
|||||||
self.url_label.show()
|
self.url_label.show()
|
||||||
self.copy_url_button.show()
|
self.copy_url_button.show()
|
||||||
|
|
||||||
|
if self.settings.get('save_private_key'):
|
||||||
|
if not self.settings.get('slug'):
|
||||||
|
self.settings.set('slug', self.web.slug)
|
||||||
|
self.settings.save()
|
||||||
|
|
||||||
if self.app.stealth:
|
if self.app.stealth:
|
||||||
self.copy_hidservauth_button.show()
|
self.copy_hidservauth_button.show()
|
||||||
else:
|
else:
|
||||||
|
@ -570,10 +570,12 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
if self.save_private_key_checkbox.isChecked():
|
if self.save_private_key_checkbox.isChecked():
|
||||||
settings.set('save_private_key', True)
|
settings.set('save_private_key', True)
|
||||||
settings.set('private_key', self.old_settings.get('private_key'))
|
settings.set('private_key', self.old_settings.get('private_key'))
|
||||||
|
settings.set('slug', self.old_settings.get('slug'))
|
||||||
settings.set('hidservauth_string', self.old_settings.get('hidservauth_string'))
|
settings.set('hidservauth_string', self.old_settings.get('hidservauth_string'))
|
||||||
else:
|
else:
|
||||||
settings.set('save_private_key', False)
|
settings.set('save_private_key', False)
|
||||||
settings.set('private_key', '')
|
settings.set('private_key', '')
|
||||||
|
settings.set('slug', '')
|
||||||
# Also unset the HidServAuth if we are removing our reusable private key
|
# Also unset the HidServAuth if we are removing our reusable private key
|
||||||
settings.set('hidservauth_string', '')
|
settings.set('hidservauth_string', '')
|
||||||
settings.set('use_stealth', self.stealth_checkbox.isChecked())
|
settings.set('use_stealth', self.stealth_checkbox.isChecked())
|
||||||
|
@ -60,6 +60,7 @@ class TestSettings:
|
|||||||
'autoupdate_timestamp': None,
|
'autoupdate_timestamp': None,
|
||||||
'save_private_key': False,
|
'save_private_key': False,
|
||||||
'private_key': '',
|
'private_key': '',
|
||||||
|
'slug': '',
|
||||||
'hidservauth_string': ''
|
'hidservauth_string': ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user