2014-09-02 20:30:01 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-09-02 15:10:42 -04:00
|
|
|
"""
|
|
|
|
OnionShare | https://onionshare.org/
|
|
|
|
|
2018-04-24 13:07:59 -04:00
|
|
|
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
2014-09-02 15:10:42 -04: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 <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2014-08-27 22:07:15 -04:00
|
|
|
import platform
|
2018-08-21 05:31:02 -04:00
|
|
|
import textwrap
|
2016-02-12 18:12:27 -05:00
|
|
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
2014-08-27 19:11:43 -04:00
|
|
|
|
2018-03-08 13:18:31 -05:00
|
|
|
from onionshare import strings
|
2014-08-27 19:11:43 -04:00
|
|
|
|
2018-04-25 12:46:49 -04:00
|
|
|
from .widgets import Alert
|
2018-04-24 20:26:54 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2018-02-06 19:01:59 -05:00
|
|
|
class ServerStatus(QtWidgets.QWidget):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
The server status chunk of the GUI.
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
server_started = QtCore.pyqtSignal()
|
2018-05-04 18:53:34 -04:00
|
|
|
server_started_finished = QtCore.pyqtSignal()
|
2014-08-27 20:24:44 -04:00
|
|
|
server_stopped = QtCore.pyqtSignal()
|
2018-02-25 01:44:27 -05:00
|
|
|
server_canceled = QtCore.pyqtSignal()
|
2018-02-11 01:32:45 -05:00
|
|
|
button_clicked = QtCore.pyqtSignal()
|
2014-08-29 18:43:07 -04:00
|
|
|
url_copied = QtCore.pyqtSignal()
|
2016-12-22 20:47:05 -05:00
|
|
|
hidservauth_copied = QtCore.pyqtSignal()
|
2014-08-27 20:24:44 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
MODE_SHARE = "share"
|
|
|
|
MODE_RECEIVE = "receive"
|
|
|
|
MODE_WEBSITE = "website"
|
2018-04-28 02:02:04 -04:00
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
STATUS_STOPPED = 0
|
|
|
|
STATUS_WORKING = 1
|
|
|
|
STATUS_STARTED = 2
|
|
|
|
|
2018-09-27 01:43:59 -04:00
|
|
|
def __init__(self, common, qtapp, app, file_selection=None, local_only=False):
|
2014-08-27 19:11:43 -04:00
|
|
|
super(ServerStatus, self).__init__()
|
2018-03-08 13:18:31 -05:00
|
|
|
|
|
|
|
self.common = common
|
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
self.status = self.STATUS_STOPPED
|
2019-10-13 00:01:25 -04:00
|
|
|
self.mode = None # Gets set in self.set_mode
|
2014-08-27 19:11:43 -04:00
|
|
|
|
2014-08-27 22:07:15 -04:00
|
|
|
self.qtapp = qtapp
|
|
|
|
self.app = app
|
2018-04-26 12:30:53 -04:00
|
|
|
|
|
|
|
self.web = None
|
2019-03-25 00:28:31 -04:00
|
|
|
self.autostart_timer_datetime = None
|
2018-09-27 01:43:59 -04:00
|
|
|
self.local_only = local_only
|
2018-04-25 12:46:49 -04:00
|
|
|
|
2018-08-27 19:33:49 -04:00
|
|
|
self.resizeEvent(None)
|
|
|
|
|
2019-03-25 00:28:31 -04:00
|
|
|
# Auto-start timer layout
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostart_timer_label = QtWidgets.QLabel(
|
|
|
|
strings._("gui_settings_autostart_timer")
|
|
|
|
)
|
2019-03-25 00:28:31 -04:00
|
|
|
self.autostart_timer_widget = QtWidgets.QDateTimeEdit()
|
|
|
|
self.autostart_timer_widget.setDisplayFormat("hh:mm A MMM d, yy")
|
2019-03-04 18:28:27 -05:00
|
|
|
if self.local_only:
|
|
|
|
# For testing
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostart_timer_widget.setDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(15)
|
|
|
|
)
|
|
|
|
self.autostart_timer_widget.setMinimumDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime()
|
|
|
|
)
|
2019-03-04 18:28:27 -05:00
|
|
|
else:
|
|
|
|
# Set proposed timer to be 5 minutes into the future
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostart_timer_widget.setDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(300)
|
|
|
|
)
|
2019-03-04 18:28:27 -05:00
|
|
|
# Onion services can take a little while to start, so reduce the risk of it expiring too soon by setting the minimum to 60s from now
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostart_timer_widget.setMinimumDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(60)
|
|
|
|
)
|
|
|
|
self.autostart_timer_widget.setCurrentSection(
|
|
|
|
QtWidgets.QDateTimeEdit.MinuteSection
|
|
|
|
)
|
2019-03-25 00:28:31 -04:00
|
|
|
autostart_timer_layout = QtWidgets.QHBoxLayout()
|
|
|
|
autostart_timer_layout.addWidget(self.autostart_timer_label)
|
|
|
|
autostart_timer_layout.addWidget(self.autostart_timer_widget)
|
|
|
|
|
|
|
|
# Auto-start timer container, so it can all be hidden and shown as a group
|
|
|
|
autostart_timer_container_layout = QtWidgets.QVBoxLayout()
|
|
|
|
autostart_timer_container_layout.addLayout(autostart_timer_layout)
|
|
|
|
self.autostart_timer_container = QtWidgets.QWidget()
|
|
|
|
self.autostart_timer_container.setLayout(autostart_timer_container_layout)
|
|
|
|
self.autostart_timer_container.hide()
|
2019-03-04 18:28:27 -05:00
|
|
|
|
2019-03-25 00:05:54 -04:00
|
|
|
# Auto-stop timer layout
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostop_timer_label = QtWidgets.QLabel(
|
|
|
|
strings._("gui_settings_autostop_timer")
|
|
|
|
)
|
2019-03-25 00:05:54 -04:00
|
|
|
self.autostop_timer_widget = QtWidgets.QDateTimeEdit()
|
|
|
|
self.autostop_timer_widget.setDisplayFormat("hh:mm A MMM d, yy")
|
2018-09-27 01:43:59 -04:00
|
|
|
if self.local_only:
|
|
|
|
# For testing
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostop_timer_widget.setDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(15)
|
|
|
|
)
|
|
|
|
self.autostop_timer_widget.setMinimumDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime()
|
|
|
|
)
|
2018-09-27 01:43:59 -04:00
|
|
|
else:
|
2019-03-25 00:05:54 -04:00
|
|
|
# Set proposed timer to be 5 minutes into the future
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostop_timer_widget.setDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(300)
|
|
|
|
)
|
2018-09-27 01:43:59 -04:00
|
|
|
# Onion services can take a little while to start, so reduce the risk of it expiring too soon by setting the minimum to 60s from now
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostop_timer_widget.setMinimumDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(60)
|
|
|
|
)
|
|
|
|
self.autostop_timer_widget.setCurrentSection(
|
|
|
|
QtWidgets.QDateTimeEdit.MinuteSection
|
|
|
|
)
|
2019-03-25 00:05:54 -04:00
|
|
|
autostop_timer_layout = QtWidgets.QHBoxLayout()
|
|
|
|
autostop_timer_layout.addWidget(self.autostop_timer_label)
|
|
|
|
autostop_timer_layout.addWidget(self.autostop_timer_widget)
|
|
|
|
|
|
|
|
# Auto-stop timer container, so it can all be hidden and shown as a group
|
|
|
|
autostop_timer_container_layout = QtWidgets.QVBoxLayout()
|
|
|
|
autostop_timer_container_layout.addLayout(autostop_timer_layout)
|
|
|
|
self.autostop_timer_container = QtWidgets.QWidget()
|
|
|
|
self.autostop_timer_container.setLayout(autostop_timer_container_layout)
|
|
|
|
self.autostop_timer_container.hide()
|
2018-02-23 23:38:45 -05:00
|
|
|
|
2018-02-05 12:29:28 -05:00
|
|
|
# Server layout
|
2016-02-12 18:12:27 -05:00
|
|
|
self.server_button = QtWidgets.QPushButton()
|
2014-09-17 20:37:19 -04:00
|
|
|
self.server_button.clicked.connect(self.server_button_clicked)
|
2014-08-27 19:11:43 -04:00
|
|
|
|
2018-02-05 12:29:28 -05:00
|
|
|
# URL layout
|
2018-10-09 23:51:10 -04:00
|
|
|
url_font = QtGui.QFontDatabase.systemFont(QtGui.QFontDatabase.FixedFont)
|
2018-04-28 02:02:04 -04:00
|
|
|
self.url_description = QtWidgets.QLabel()
|
2018-02-06 23:59:13 -05:00
|
|
|
self.url_description.setWordWrap(True)
|
|
|
|
self.url_description.setMinimumHeight(50)
|
2018-02-06 19:01:59 -05:00
|
|
|
self.url = QtWidgets.QLabel()
|
|
|
|
self.url.setFont(url_font)
|
2018-02-06 23:59:13 -05:00
|
|
|
self.url.setWordWrap(True)
|
2018-02-11 01:16:52 -05:00
|
|
|
self.url.setMinimumSize(self.url.sizeHint())
|
2019-10-13 00:01:25 -04:00
|
|
|
self.url.setStyleSheet(self.common.css["server_status_url"])
|
2018-02-06 19:01:59 -05:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
self.copy_url_button = QtWidgets.QPushButton(strings._("gui_copy_url"))
|
2018-02-06 19:01:59 -05:00
|
|
|
self.copy_url_button.setFlat(True)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.copy_url_button.setStyleSheet(self.common.css["server_status_url_buttons"])
|
2018-10-09 23:51:10 -04:00
|
|
|
self.copy_url_button.setMinimumHeight(65)
|
2014-08-27 19:11:43 -04:00
|
|
|
self.copy_url_button.clicked.connect(self.copy_url)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.copy_hidservauth_button = QtWidgets.QPushButton(
|
|
|
|
strings._("gui_copy_hidservauth")
|
|
|
|
)
|
2018-02-06 19:01:59 -05:00
|
|
|
self.copy_hidservauth_button.setFlat(True)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.copy_hidservauth_button.setStyleSheet(
|
|
|
|
self.common.css["server_status_url_buttons"]
|
|
|
|
)
|
2016-12-22 20:47:05 -05:00
|
|
|
self.copy_hidservauth_button.clicked.connect(self.copy_hidservauth)
|
2018-02-06 19:01:59 -05:00
|
|
|
url_buttons_layout = QtWidgets.QHBoxLayout()
|
|
|
|
url_buttons_layout.addWidget(self.copy_url_button)
|
|
|
|
url_buttons_layout.addWidget(self.copy_hidservauth_button)
|
|
|
|
url_buttons_layout.addStretch()
|
|
|
|
|
|
|
|
url_layout = QtWidgets.QVBoxLayout()
|
|
|
|
url_layout.addWidget(self.url_description)
|
|
|
|
url_layout.addWidget(self.url)
|
|
|
|
url_layout.addLayout(url_buttons_layout)
|
2014-08-27 19:11:43 -04:00
|
|
|
|
2018-02-05 12:29:28 -05:00
|
|
|
# Add the widgets
|
2018-02-06 19:01:59 -05:00
|
|
|
layout = QtWidgets.QVBoxLayout()
|
2018-02-06 22:31:02 -05:00
|
|
|
layout.addWidget(self.server_button)
|
2018-02-06 19:01:59 -05:00
|
|
|
layout.addLayout(url_layout)
|
2019-03-25 00:28:31 -04:00
|
|
|
layout.addWidget(self.autostart_timer_container)
|
2019-03-25 00:05:54 -04:00
|
|
|
layout.addWidget(self.autostop_timer_container)
|
2018-02-06 19:01:59 -05:00
|
|
|
self.setLayout(layout)
|
2018-05-04 18:53:34 -04:00
|
|
|
|
2018-04-28 02:02:04 -04:00
|
|
|
def set_mode(self, share_mode, file_selection=None):
|
2018-04-26 01:59:26 -04:00
|
|
|
"""
|
|
|
|
The server status is in share mode.
|
|
|
|
"""
|
2018-04-28 02:02:04 -04:00
|
|
|
self.mode = share_mode
|
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
if (self.mode == ServerStatus.MODE_SHARE) or (
|
|
|
|
self.mode == ServerStatus.MODE_WEBSITE
|
|
|
|
):
|
2018-04-28 02:02:04 -04:00
|
|
|
self.file_selection = file_selection
|
|
|
|
|
2018-04-26 12:30:53 -04:00
|
|
|
self.update()
|
2014-08-27 20:24:44 -04:00
|
|
|
|
2018-08-27 19:33:49 -04:00
|
|
|
def resizeEvent(self, event):
|
|
|
|
"""
|
|
|
|
When the widget is resized, try and adjust the display of a v3 onion URL.
|
|
|
|
"""
|
|
|
|
try:
|
2018-10-10 21:16:08 -04:00
|
|
|
# Wrap the URL label
|
2019-10-13 00:01:25 -04:00
|
|
|
url_length = len(self.get_url())
|
2018-08-27 19:33:49 -04:00
|
|
|
if url_length > 60:
|
|
|
|
width = self.frameGeometry().width()
|
|
|
|
if width < 530:
|
2018-10-10 21:16:08 -04:00
|
|
|
wrapped_onion_url = textwrap.fill(self.get_url(), 46)
|
2018-08-27 19:33:49 -04:00
|
|
|
self.url.setText(wrapped_onion_url)
|
|
|
|
else:
|
|
|
|
self.url.setText(self.get_url())
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2019-03-25 00:28:31 -04:00
|
|
|
def autostart_timer_reset(self):
|
2019-03-04 18:28:27 -05:00
|
|
|
"""
|
2019-03-25 00:28:31 -04:00
|
|
|
Reset the auto-start timer in the UI after stopping a share
|
2019-03-04 18:28:27 -05:00
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostart_timer_widget.setDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(300)
|
|
|
|
)
|
2019-03-04 18:28:27 -05:00
|
|
|
if not self.local_only:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostart_timer_widget.setMinimumDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(60)
|
|
|
|
)
|
2018-08-27 19:33:49 -04:00
|
|
|
|
2019-03-25 00:05:54 -04:00
|
|
|
def autostop_timer_reset(self):
|
2017-11-09 01:26:32 -05:00
|
|
|
"""
|
2019-03-25 00:05:54 -04:00
|
|
|
Reset the auto-stop timer in the UI after stopping a share
|
2017-11-09 01:26:32 -05:00
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostop_timer_widget.setDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(300)
|
|
|
|
)
|
2018-09-27 01:43:59 -04:00
|
|
|
if not self.local_only:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostop_timer_widget.setMinimumDateTime(
|
|
|
|
QtCore.QDateTime.currentDateTime().addSecs(60)
|
|
|
|
)
|
2017-11-09 01:26:32 -05:00
|
|
|
|
2019-03-04 18:28:27 -05:00
|
|
|
def show_url(self):
|
|
|
|
"""
|
|
|
|
Show the URL in the UI.
|
|
|
|
"""
|
2019-03-24 01:48:56 -04:00
|
|
|
self.url_description.show()
|
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
info_image = self.common.get_resource_path("images/info.png")
|
2019-03-24 01:48:56 -04:00
|
|
|
|
|
|
|
if self.mode == ServerStatus.MODE_SHARE:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.url_description.setText(
|
|
|
|
strings._("gui_share_url_description").format(info_image)
|
|
|
|
)
|
2019-04-19 10:52:43 -04:00
|
|
|
elif self.mode == ServerStatus.MODE_WEBSITE:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.url_description.setText(
|
|
|
|
strings._("gui_website_url_description").format(info_image)
|
|
|
|
)
|
2019-03-24 01:48:56 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.url_description.setText(
|
|
|
|
strings._("gui_receive_url_description").format(info_image)
|
|
|
|
)
|
2019-03-24 01:48:56 -04:00
|
|
|
|
|
|
|
# Show a Tool Tip explaining the lifecycle of this URL
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.settings.get("save_private_key"):
|
|
|
|
if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get(
|
|
|
|
"close_after_first_download"
|
|
|
|
):
|
|
|
|
self.url_description.setToolTip(
|
|
|
|
strings._("gui_url_label_onetime_and_persistent")
|
|
|
|
)
|
2019-03-24 01:48:56 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.url_description.setToolTip(strings._("gui_url_label_persistent"))
|
2019-03-24 01:48:56 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get(
|
|
|
|
"close_after_first_download"
|
|
|
|
):
|
|
|
|
self.url_description.setToolTip(strings._("gui_url_label_onetime"))
|
2019-03-24 01:48:56 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.url_description.setToolTip(strings._("gui_url_label_stay_open"))
|
2019-03-24 01:48:56 -04:00
|
|
|
|
2019-03-04 18:28:27 -05:00
|
|
|
self.url.setText(self.get_url())
|
|
|
|
self.url.show()
|
|
|
|
self.copy_url_button.show()
|
|
|
|
|
2019-03-11 00:55:17 -04:00
|
|
|
if self.app.stealth:
|
|
|
|
self.copy_hidservauth_button.show()
|
|
|
|
else:
|
|
|
|
self.copy_hidservauth_button.hide()
|
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
def update(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Update the GUI elements based on the current state.
|
|
|
|
"""
|
2018-02-05 12:44:17 -05:00
|
|
|
# Set the URL fields
|
2014-08-27 22:07:15 -04:00
|
|
|
if self.status == self.STATUS_STARTED:
|
2019-09-16 00:51:16 -04:00
|
|
|
# The backend Onion may have saved new settings, such as the private key.
|
|
|
|
# Reload the settings before saving new ones.
|
|
|
|
self.common.settings.load()
|
2019-03-04 18:28:27 -05:00
|
|
|
self.show_url()
|
2015-05-18 14:05:33 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.settings.get("save_private_key"):
|
|
|
|
if not self.common.settings.get("password"):
|
|
|
|
self.common.settings.set("password", self.web.password)
|
2018-03-13 06:28:47 -04:00
|
|
|
self.common.settings.save()
|
2018-01-14 18:01:34 -05:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.settings.get("autostart_timer"):
|
2019-03-25 00:28:31 -04:00
|
|
|
self.autostart_timer_container.hide()
|
2019-03-04 18:28:27 -05:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.settings.get("autostop_timer"):
|
2019-03-25 00:05:54 -04:00
|
|
|
self.autostop_timer_container.hide()
|
2014-08-27 22:07:15 -04:00
|
|
|
else:
|
2018-02-06 19:01:59 -05:00
|
|
|
self.url_description.hide()
|
|
|
|
self.url.hide()
|
2014-08-27 22:07:15 -04:00
|
|
|
self.copy_url_button.hide()
|
2016-12-22 20:47:05 -05:00
|
|
|
self.copy_hidservauth_button.hide()
|
2014-08-27 22:07:15 -04:00
|
|
|
|
2018-02-05 12:44:17 -05:00
|
|
|
# Button
|
2019-10-13 00:01:25 -04:00
|
|
|
if (
|
|
|
|
self.mode == ServerStatus.MODE_SHARE
|
|
|
|
and self.file_selection.get_num_files() == 0
|
|
|
|
):
|
2018-02-05 12:44:17 -05:00
|
|
|
self.server_button.hide()
|
2019-10-13 00:01:25 -04:00
|
|
|
elif (
|
|
|
|
self.mode == ServerStatus.MODE_WEBSITE
|
|
|
|
and self.file_selection.get_num_files() == 0
|
|
|
|
):
|
2019-04-19 10:52:43 -04:00
|
|
|
self.server_button.hide()
|
2014-08-27 20:24:44 -04:00
|
|
|
else:
|
2018-02-05 12:44:17 -05:00
|
|
|
self.server_button.show()
|
2018-02-05 21:20:09 -05:00
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
if self.status == self.STATUS_STOPPED:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setStyleSheet(
|
|
|
|
self.common.css["server_status_button_stopped"]
|
|
|
|
)
|
2014-09-17 20:37:19 -04:00
|
|
|
self.server_button.setEnabled(True)
|
2018-04-28 02:02:04 -04:00
|
|
|
if self.mode == ServerStatus.MODE_SHARE:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setText(strings._("gui_share_start_server"))
|
2019-04-19 10:52:43 -04:00
|
|
|
elif self.mode == ServerStatus.MODE_WEBSITE:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setText(strings._("gui_share_start_server"))
|
2018-04-25 23:14:27 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setText(strings._("gui_receive_start_server"))
|
|
|
|
self.server_button.setToolTip("")
|
|
|
|
if self.common.settings.get("autostart_timer"):
|
2019-03-25 00:28:31 -04:00
|
|
|
self.autostart_timer_container.show()
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.settings.get("autostop_timer"):
|
2019-03-25 00:05:54 -04:00
|
|
|
self.autostop_timer_container.show()
|
2014-08-29 18:50:19 -04:00
|
|
|
elif self.status == self.STATUS_STARTED:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setStyleSheet(
|
|
|
|
self.common.css["server_status_button_started"]
|
|
|
|
)
|
2014-09-17 20:37:19 -04:00
|
|
|
self.server_button.setEnabled(True)
|
2018-04-28 02:02:04 -04:00
|
|
|
if self.mode == ServerStatus.MODE_SHARE:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setText(strings._("gui_share_stop_server"))
|
2019-05-20 22:14:04 -04:00
|
|
|
elif self.mode == ServerStatus.MODE_WEBSITE:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setText(strings._("gui_share_stop_server"))
|
2018-04-25 23:14:27 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setText(strings._("gui_receive_stop_server"))
|
|
|
|
if self.common.settings.get("autostart_timer"):
|
2019-03-25 00:28:31 -04:00
|
|
|
self.autostart_timer_container.hide()
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.settings.get("autostop_timer"):
|
2019-03-25 00:05:54 -04:00
|
|
|
self.autostop_timer_container.hide()
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setToolTip(
|
|
|
|
strings._("gui_stop_server_autostop_timer_tooltip").format(
|
|
|
|
self.autostop_timer_widget.dateTime().toString(
|
|
|
|
"h:mm AP, MMMM dd, yyyy"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-11-08 19:46:26 -05:00
|
|
|
elif self.status == self.STATUS_WORKING:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setStyleSheet(
|
|
|
|
self.common.css["server_status_button_working"]
|
|
|
|
)
|
2018-02-25 01:44:27 -05:00
|
|
|
self.server_button.setEnabled(True)
|
2019-03-25 00:28:31 -04:00
|
|
|
if self.autostart_timer_datetime:
|
|
|
|
self.autostart_timer_container.hide()
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setToolTip(
|
|
|
|
strings._("gui_start_server_autostart_timer_tooltip").format(
|
|
|
|
self.autostart_timer_widget.dateTime().toString(
|
|
|
|
"h:mm AP, MMMM dd, yyyy"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2019-03-04 18:28:27 -05:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setText(strings._("gui_please_wait"))
|
|
|
|
if self.common.settings.get("autostop_timer"):
|
2019-03-25 00:05:54 -04:00
|
|
|
self.autostop_timer_container.hide()
|
2014-08-29 18:50:19 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setStyleSheet(
|
|
|
|
self.common.css["server_status_button_working"]
|
|
|
|
)
|
2014-09-17 20:37:19 -04:00
|
|
|
self.server_button.setEnabled(False)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setText(strings._("gui_please_wait"))
|
|
|
|
if self.common.settings.get("autostart_timer"):
|
2019-03-25 00:28:31 -04:00
|
|
|
self.autostart_timer_container.hide()
|
2019-10-13 00:01:25 -04:00
|
|
|
self.server_button.setToolTip(
|
|
|
|
strings._("gui_start_server_autostart_timer_tooltip").format(
|
|
|
|
self.autostart_timer_widget.dateTime().toString(
|
|
|
|
"h:mm AP, MMMM dd, yyyy"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if self.common.settings.get("autostop_timer"):
|
2019-03-25 00:05:54 -04:00
|
|
|
self.autostop_timer_container.hide()
|
2014-09-17 20:37:19 -04:00
|
|
|
|
|
|
|
def server_button_clicked(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Toggle starting or stopping the server.
|
|
|
|
"""
|
2014-09-17 20:37:19 -04:00
|
|
|
if self.status == self.STATUS_STOPPED:
|
2019-03-06 00:49:32 -05:00
|
|
|
can_start = True
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.settings.get("autostart_timer"):
|
2019-03-04 18:28:27 -05:00
|
|
|
if self.local_only:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostart_timer_datetime = (
|
|
|
|
self.autostart_timer_widget.dateTime().toPyDateTime()
|
|
|
|
)
|
2019-03-04 18:28:27 -05:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostart_timer_datetime = (
|
|
|
|
self.autostart_timer_widget.dateTime()
|
|
|
|
.toPyDateTime()
|
|
|
|
.replace(second=0, microsecond=0)
|
|
|
|
)
|
2019-03-06 00:49:32 -05:00
|
|
|
# If the timer has actually passed already before the user hit Start, refuse to start the server.
|
2019-10-13 00:01:25 -04:00
|
|
|
if (
|
|
|
|
QtCore.QDateTime.currentDateTime().toPyDateTime()
|
|
|
|
> self.autostart_timer_datetime
|
|
|
|
):
|
2019-03-06 00:49:32 -05:00
|
|
|
can_start = False
|
2019-10-13 00:01:25 -04:00
|
|
|
Alert(
|
|
|
|
self.common,
|
|
|
|
strings._("gui_server_autostart_timer_expired"),
|
|
|
|
QtWidgets.QMessageBox.Warning,
|
|
|
|
)
|
|
|
|
if self.common.settings.get("autostop_timer"):
|
2018-09-27 01:43:59 -04:00
|
|
|
if self.local_only:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostop_timer_datetime = (
|
|
|
|
self.autostop_timer_widget.dateTime().toPyDateTime()
|
|
|
|
)
|
2018-09-27 01:43:59 -04:00
|
|
|
else:
|
2019-03-25 00:05:54 -04:00
|
|
|
# Get the timer chosen, stripped of its seconds. This prevents confusion if the share stops at (say) 37 seconds past the minute chosen
|
2019-10-13 00:01:25 -04:00
|
|
|
self.autostop_timer_datetime = (
|
|
|
|
self.autostop_timer_widget.dateTime()
|
|
|
|
.toPyDateTime()
|
|
|
|
.replace(second=0, microsecond=0)
|
|
|
|
)
|
2019-03-25 00:05:54 -04:00
|
|
|
# If the timer has actually passed already before the user hit Start, refuse to start the server.
|
2019-10-13 00:01:25 -04:00
|
|
|
if (
|
|
|
|
QtCore.QDateTime.currentDateTime().toPyDateTime()
|
|
|
|
> self.autostop_timer_datetime
|
|
|
|
):
|
2019-03-06 00:49:32 -05:00
|
|
|
can_start = False
|
2019-10-13 00:01:25 -04:00
|
|
|
Alert(
|
|
|
|
self.common,
|
|
|
|
strings._("gui_server_autostop_timer_expired"),
|
|
|
|
QtWidgets.QMessageBox.Warning,
|
|
|
|
)
|
|
|
|
if self.common.settings.get("autostart_timer"):
|
2019-03-25 00:28:31 -04:00
|
|
|
if self.autostop_timer_datetime <= self.autostart_timer_datetime:
|
2019-10-13 00:01:25 -04:00
|
|
|
Alert(
|
|
|
|
self.common,
|
|
|
|
strings._(
|
|
|
|
"gui_autostop_timer_cant_be_earlier_than_autostart_timer"
|
|
|
|
),
|
|
|
|
QtWidgets.QMessageBox.Warning,
|
|
|
|
)
|
2019-03-11 00:55:17 -04:00
|
|
|
can_start = False
|
2019-03-06 00:49:32 -05:00
|
|
|
if can_start:
|
2017-11-09 01:26:32 -05:00
|
|
|
self.start_server()
|
2014-09-17 20:37:19 -04:00
|
|
|
elif self.status == self.STATUS_STARTED:
|
|
|
|
self.stop_server()
|
2018-02-25 01:44:27 -05:00
|
|
|
elif self.status == self.STATUS_WORKING:
|
|
|
|
self.cancel_server()
|
2018-02-11 01:32:45 -05:00
|
|
|
self.button_clicked.emit()
|
2014-08-27 20:24:44 -04:00
|
|
|
|
2014-08-27 19:11:43 -04:00
|
|
|
def start_server(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Start the server.
|
|
|
|
"""
|
2014-08-27 20:24:44 -04:00
|
|
|
self.status = self.STATUS_WORKING
|
|
|
|
self.update()
|
|
|
|
self.server_started.emit()
|
2014-08-27 19:11:43 -04:00
|
|
|
|
2014-08-27 22:07:15 -04:00
|
|
|
def start_server_finished(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
The server has finished starting.
|
|
|
|
"""
|
2014-08-27 22:07:15 -04:00
|
|
|
self.status = self.STATUS_STARTED
|
2014-08-28 02:52:56 -04:00
|
|
|
self.copy_url()
|
2014-08-27 22:07:15 -04:00
|
|
|
self.update()
|
2018-05-04 18:53:34 -04:00
|
|
|
self.server_started_finished.emit()
|
2014-08-27 22:07:15 -04:00
|
|
|
|
2014-08-27 19:11:43 -04:00
|
|
|
def stop_server(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Stop the server.
|
|
|
|
"""
|
2014-08-27 22:07:15 -04:00
|
|
|
self.status = self.STATUS_WORKING
|
2019-03-25 00:28:31 -04:00
|
|
|
self.autostart_timer_reset()
|
2019-03-25 00:05:54 -04:00
|
|
|
self.autostop_timer_reset()
|
2014-08-27 20:24:44 -04:00
|
|
|
self.update()
|
|
|
|
self.server_stopped.emit()
|
2014-08-27 19:11:43 -04:00
|
|
|
|
2018-02-25 01:44:27 -05:00
|
|
|
def cancel_server(self):
|
|
|
|
"""
|
|
|
|
Cancel the server.
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
self.common.log(
|
|
|
|
"ServerStatus", "cancel_server", "Canceling the server mid-startup"
|
|
|
|
)
|
2018-02-25 01:44:27 -05:00
|
|
|
self.status = self.STATUS_WORKING
|
2019-03-25 00:28:31 -04:00
|
|
|
self.autostart_timer_reset()
|
2019-03-25 00:05:54 -04:00
|
|
|
self.autostop_timer_reset()
|
2018-02-25 01:44:27 -05:00
|
|
|
self.update()
|
|
|
|
self.server_canceled.emit()
|
|
|
|
|
2014-08-27 22:07:15 -04:00
|
|
|
def stop_server_finished(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
The server has finished stopping.
|
|
|
|
"""
|
2014-08-27 22:07:15 -04:00
|
|
|
self.status = self.STATUS_STOPPED
|
|
|
|
self.update()
|
|
|
|
|
2014-08-27 19:11:43 -04:00
|
|
|
def copy_url(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Copy the onionshare URL to the clipboard.
|
|
|
|
"""
|
2016-02-15 16:06:12 -05:00
|
|
|
clipboard = self.qtapp.clipboard()
|
2018-04-29 19:33:48 -04:00
|
|
|
clipboard.setText(self.get_url())
|
2014-08-27 22:07:15 -04:00
|
|
|
|
2014-08-29 18:43:07 -04:00
|
|
|
self.url_copied.emit()
|
2016-12-22 20:47:05 -05:00
|
|
|
|
|
|
|
def copy_hidservauth(self):
|
|
|
|
"""
|
|
|
|
Copy the HidServAuth line to the clipboard.
|
|
|
|
"""
|
|
|
|
clipboard = self.qtapp.clipboard()
|
|
|
|
clipboard.setText(self.app.auth_string)
|
|
|
|
|
|
|
|
self.hidservauth_copied.emit()
|
2018-05-04 18:53:34 -04:00
|
|
|
|
2018-04-29 19:33:48 -04:00
|
|
|
def get_url(self):
|
|
|
|
"""
|
|
|
|
Returns the OnionShare URL.
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.settings.get("public_mode"):
|
|
|
|
url = "http://{0:s}".format(self.app.onion_host)
|
2018-04-29 19:33:48 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
url = "http://onionshare:{0:s}@{1:s}".format(
|
|
|
|
self.web.password, self.app.onion_host
|
|
|
|
)
|
2018-04-29 19:33:48 -04:00
|
|
|
return url
|