forked from openlp/openlp
Bye Bye SSL
This commit is contained in:
parent
41d3ea59a0
commit
a5f460dc76
@ -213,7 +213,9 @@ class Settings(QtCore.QSettings):
|
||||
('media/players', 'media/players_temp', [(media_players_conv, None)]), # Convert phonon to system
|
||||
('media/players_temp', 'media/players', []), # Move temp setting from above to correct setting
|
||||
('advanced/default color', 'core/logo background color', []), # Default image renamed + moved to general > 2.4.
|
||||
('advanced/default image', '/core/logo file', []) # Default image renamed + moved to general after 2.4.
|
||||
('advanced/default image', '/core/logo file', []), # Default image renamed + moved to general after 2.4.
|
||||
('remotes/https enabled', '', []),
|
||||
('remotes/https port', '', [])
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
|
@ -20,22 +20,8 @@
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
|
||||
import os
|
||||
from openlp.core.common import AppLocation
|
||||
|
||||
|
||||
def get_cert_file(file_type):
|
||||
"""
|
||||
Helper method to get certificate files
|
||||
:param file_type: file suffix key, cert or pem
|
||||
:return: full path to file
|
||||
"""
|
||||
local_data = AppLocation.get_directory(AppLocation.DataDir)
|
||||
return os.path.join(local_data, 'remotes', 'openlp.{type}'.format(type=file_type))
|
||||
|
||||
|
||||
from .poll import OpenLPPoll
|
||||
from .wsserver import OpenWSServer
|
||||
from .remotecontroller import RemoteController
|
||||
|
||||
__all__ = ['OpenLPPoll', 'RemoteController', 'get_cert_file']
|
||||
__all__ = ['OpenLPPoll', 'RemoteController']
|
||||
|
@ -19,9 +19,13 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
import logging
|
||||
|
||||
from openlp.core.common import OpenLPMixin, Registry, RegistryMixin, RegistryProperties
|
||||
from openlp.core.lib.remote import OpenWSServer, OpenLPPoll
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RemoteController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
"""
|
||||
|
@ -29,12 +29,10 @@ import asyncio
|
||||
import websockets
|
||||
import logging
|
||||
import time
|
||||
import ssl
|
||||
|
||||
from PyQt5 import QtCore
|
||||
|
||||
from openlp.core.common import Settings, RegistryProperties, OpenLPMixin, Registry
|
||||
from openlp.core.lib.remote import get_cert_file
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -100,15 +98,9 @@ class OpenWSServer(RegistryProperties, OpenLPMixin):
|
||||
:param port: The run port
|
||||
"""
|
||||
loop = 1
|
||||
is_secure = Settings().value(self.settings_section + '/https enabled')
|
||||
while loop < 4:
|
||||
try:
|
||||
if is_secure:
|
||||
context = ssl.create_default_context()
|
||||
context.load_cert_chain(certfile=get_cert_file('crt'), keyfile=get_cert_file('key'))
|
||||
self.ws_server = websockets.serve(self.handle_websocket, address, port, ssl=context)
|
||||
else:
|
||||
self.ws_server = websockets.serve(self.handle_websocket, address, port)
|
||||
self.ws_server = websockets.serve(self.handle_websocket, address, port)
|
||||
log.debug("Web Socket Server started for class {address} {port}".format(address=address, port=port))
|
||||
break
|
||||
except Exception as e:
|
||||
|
@ -35,9 +35,8 @@ from PyQt5 import QtCore
|
||||
from openlp.core.common import Settings, RegistryProperties, OpenLPMixin
|
||||
|
||||
from openlp.plugins.remotes.lib import HttpRouter
|
||||
from openlp.core.lib.remote import get_cert_file
|
||||
|
||||
from socketserver import BaseServer, ThreadingMixIn
|
||||
from socketserver import ThreadingMixIn
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -110,18 +109,9 @@ class OpenLPServer(RegistryProperties, OpenLPMixin):
|
||||
Start the correct server and save the handler
|
||||
"""
|
||||
address = Settings().value(self.settings_section + '/ip address')
|
||||
is_secure = Settings().value(self.settings_section + '/https enabled')
|
||||
# Try to start secure server but not enabled.
|
||||
if self.secure and not is_secure:
|
||||
return
|
||||
if self.secure:
|
||||
port = Settings().value(self.settings_section + '/https port')
|
||||
else:
|
||||
port = Settings().value(self.settings_section + '/port')
|
||||
if self.secure:
|
||||
self.start_server_instance(address, port, HTTPSServer)
|
||||
else:
|
||||
self.start_server_instance(address, port, ThreadingHTTPServer)
|
||||
port = Settings().value(self.settings_section + '/port')
|
||||
self.start_server_instance(address, port, ThreadingHTTPServer)
|
||||
# If HTTP server start listening
|
||||
if hasattr(self, 'httpd') and self.httpd:
|
||||
self.httpd.serve_forever()
|
||||
@ -162,18 +152,3 @@ class OpenLPServer(RegistryProperties, OpenLPMixin):
|
||||
self.http_thread.stop()
|
||||
self.httpd = None
|
||||
log.debug('Stopped the server.')
|
||||
|
||||
|
||||
class HTTPSServer(HTTPServer):
|
||||
def __init__(self, address, handler):
|
||||
"""
|
||||
Initialise the secure handlers for the SSL server if required.s
|
||||
"""
|
||||
BaseServer.__init__(self, address, handler)
|
||||
self.socket = ssl.SSLSocket(
|
||||
sock=socket.socket(self.address_family, self.socket_type),
|
||||
certfile=get_cert_file('crt'),
|
||||
keyfile=get_cert_file('key'),
|
||||
server_side=True)
|
||||
self.server_bind()
|
||||
self.server_activate()
|
||||
|
@ -88,42 +88,6 @@ class RemoteTab(SettingsTab):
|
||||
self.live_url.setOpenExternalLinks(True)
|
||||
self.http_setting_layout.addRow(self.live_url_label, self.live_url)
|
||||
self.left_layout.addWidget(self.http_settings_group_box)
|
||||
self.https_settings_group_box = QtWidgets.QGroupBox(self.left_column)
|
||||
self.https_settings_group_box.setCheckable(True)
|
||||
self.https_settings_group_box.setChecked(False)
|
||||
self.https_settings_group_box.setObjectName('https_settings_group_box')
|
||||
self.https_settings_layout = QtWidgets.QFormLayout(self.https_settings_group_box)
|
||||
self.https_settings_layout.setObjectName('https_settings_layout')
|
||||
self.https_error_label = QtWidgets.QLabel(self.https_settings_group_box)
|
||||
self.https_error_label.setVisible(False)
|
||||
self.https_error_label.setWordWrap(True)
|
||||
self.https_error_label.setObjectName('https_error_label')
|
||||
self.https_settings_layout.addRow(self.https_error_label)
|
||||
self.https_port_label = QtWidgets.QLabel(self.https_settings_group_box)
|
||||
self.https_port_label.setObjectName('https_port_label')
|
||||
self.https_port_spin_box = QtWidgets.QSpinBox(self.https_settings_group_box)
|
||||
self.https_port_spin_box.setMaximum(32767)
|
||||
self.https_port_spin_box.setObjectName('https_port_spin_box')
|
||||
self.https_settings_layout.addRow(self.https_port_label, self.https_port_spin_box)
|
||||
self.remote_https_url = QtWidgets.QLabel(self.https_settings_group_box)
|
||||
self.remote_https_url.setObjectName('remote_http_url')
|
||||
self.remote_https_url.setOpenExternalLinks(True)
|
||||
self.remote_https_url_label = QtWidgets.QLabel(self.https_settings_group_box)
|
||||
self.remote_https_url_label.setObjectName('remote_http_url_label')
|
||||
self.https_settings_layout.addRow(self.remote_https_url_label, self.remote_https_url)
|
||||
self.stage_https_url_label = QtWidgets.QLabel(self.http_settings_group_box)
|
||||
self.stage_https_url_label.setObjectName('stage_https_url_label')
|
||||
self.stage_https_url = QtWidgets.QLabel(self.https_settings_group_box)
|
||||
self.stage_https_url.setObjectName('stage_https_url')
|
||||
self.stage_https_url.setOpenExternalLinks(True)
|
||||
self.https_settings_layout.addRow(self.stage_https_url_label, self.stage_https_url)
|
||||
self.live_https_url_label = QtWidgets.QLabel(self.https_settings_group_box)
|
||||
self.live_https_url_label.setObjectName('live_url_label')
|
||||
self.live_https_url = QtWidgets.QLabel(self.https_settings_group_box)
|
||||
self.live_https_url.setObjectName('live_https_url')
|
||||
self.live_https_url.setOpenExternalLinks(True)
|
||||
self.https_settings_layout.addRow(self.live_https_url_label, self.live_https_url)
|
||||
self.left_layout.addWidget(self.https_settings_group_box)
|
||||
self.user_login_group_box = QtWidgets.QGroupBox(self.left_column)
|
||||
self.user_login_group_box.setCheckable(True)
|
||||
self.user_login_group_box.setChecked(False)
|
||||
@ -177,8 +141,6 @@ class RemoteTab(SettingsTab):
|
||||
self.thumbnails_check_box.stateChanged.connect(self.on_thumbnails_check_box_changed)
|
||||
self.address_edit.textChanged.connect(self.set_urls)
|
||||
self.port_spin_box.valueChanged.connect(self.set_urls)
|
||||
self.https_port_spin_box.valueChanged.connect(self.set_urls)
|
||||
self.https_settings_group_box.clicked.connect(self.https_changed)
|
||||
|
||||
def retranslateUi(self):
|
||||
self.server_settings_group_box.setTitle(translate('RemotePlugin.RemoteTab', 'Server Settings'))
|
||||
@ -200,14 +162,6 @@ class RemoteTab(SettingsTab):
|
||||
translate('RemotePlugin.RemoteTab',
|
||||
'Scan the QR code or click <a href="{qr}">download</a> to install the iOS app from the App '
|
||||
'Store.').format(qr='https://itunes.apple.com/app/id1096218725'))
|
||||
self.https_settings_group_box.setTitle(translate('RemotePlugin.RemoteTab', 'HTTPS Server'))
|
||||
self.https_error_label.setText(
|
||||
translate('RemotePlugin.RemoteTab', 'Could not find an SSL certificate. The HTTPS server will not be '
|
||||
'available unless an SSL certificate is found. Please see the manual for more information.'))
|
||||
self.https_port_label.setText(self.port_label.text())
|
||||
self.remote_https_url_label.setText(self.remote_url_label.text())
|
||||
self.stage_https_url_label.setText(self.stage_url_label.text())
|
||||
self.live_https_url_label.setText(self.live_url_label.text())
|
||||
self.user_login_group_box.setTitle(translate('RemotePlugin.RemoteTab', 'User Authentication'))
|
||||
self.user_id_label.setText(translate('RemotePlugin.RemoteTab', 'User id:'))
|
||||
self.password_label.setText(translate('RemotePlugin.RemoteTab', 'Password:'))
|
||||
@ -218,17 +172,11 @@ class RemoteTab(SettingsTab):
|
||||
"""
|
||||
ip_address = self.get_ip_address(self.address_edit.text())
|
||||
http_url = 'http://{url}:{text}/'.format(url=ip_address, text=self.port_spin_box.value())
|
||||
https_url = 'https://{url}:{text}/'.format(url=ip_address, text=self.https_port_spin_box.value())
|
||||
self.remote_url.setText('<a href="{url}">{url}</a>'.format(url=http_url))
|
||||
self.remote_https_url.setText('<a href="{url}">{url}</a>'.format(url=https_url))
|
||||
http_url_temp = http_url + 'stage'
|
||||
https_url_temp = https_url + 'stage'
|
||||
self.stage_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))
|
||||
self.stage_https_url.setText('<a href="{url}">{url}</a>'.format(url=https_url_temp))
|
||||
http_url_temp = http_url + 'main'
|
||||
https_url_temp = https_url + 'main'
|
||||
self.live_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))
|
||||
self.live_https_url.setText('<a href="{url}">{url}</a>'.format(url=https_url_temp))
|
||||
|
||||
def get_ip_address(self, ip_address):
|
||||
"""
|
||||
@ -254,43 +202,25 @@ class RemoteTab(SettingsTab):
|
||||
"""
|
||||
Load the configuration and update the server configuration if necessary
|
||||
"""
|
||||
self.is_secure = Settings().value(self.settings_section + '/https enabled')
|
||||
self.port_spin_box.setValue(Settings().value(self.settings_section + '/port'))
|
||||
self.https_port_spin_box.setValue(Settings().value(self.settings_section + '/https port'))
|
||||
self.address_edit.setText(Settings().value(self.settings_section + '/ip address'))
|
||||
self.twelve_hour = Settings().value(self.settings_section + '/twelve hour')
|
||||
self.twelve_hour_check_box.setChecked(self.twelve_hour)
|
||||
self.thumbnails = Settings().value(self.settings_section + '/thumbnails')
|
||||
self.thumbnails_check_box.setChecked(self.thumbnails)
|
||||
local_data = AppLocation.get_directory(AppLocation.DataDir)
|
||||
if not os.path.exists(os.path.join(local_data, 'remotes', 'openlp.crt')) or \
|
||||
not os.path.exists(os.path.join(local_data, 'remotes', 'openlp.key')):
|
||||
self.https_settings_group_box.setChecked(False)
|
||||
self.https_settings_group_box.setEnabled(False)
|
||||
self.https_error_label.setVisible(True)
|
||||
else:
|
||||
self.https_settings_group_box.setChecked(Settings().value(self.settings_section + '/https enabled'))
|
||||
self.https_settings_group_box.setEnabled(True)
|
||||
self.https_error_label.setVisible(False)
|
||||
self.user_login_group_box.setChecked(Settings().value(self.settings_section + '/authentication enabled'))
|
||||
self.user_id.setText(Settings().value(self.settings_section + '/user id'))
|
||||
self.password.setText(Settings().value(self.settings_section + '/password'))
|
||||
self.set_urls()
|
||||
self.https_changed()
|
||||
|
||||
def save(self):
|
||||
"""
|
||||
Save the configuration and update the server configuration if necessary
|
||||
"""
|
||||
if Settings().value(self.settings_section + '/ip address') != self.address_edit.text() or \
|
||||
Settings().value(self.settings_section + '/port') != self.port_spin_box.value() or \
|
||||
Settings().value(self.settings_section + '/https port') != self.https_port_spin_box.value() or \
|
||||
Settings().value(self.settings_section + '/https enabled') != \
|
||||
self.https_settings_group_box.isChecked():
|
||||
Settings().value(self.settings_section + '/port') != self.port_spin_box.value():
|
||||
self.settings_form.register_post_process('remotes_config_updated')
|
||||
Settings().setValue(self.settings_section + '/port', self.port_spin_box.value())
|
||||
Settings().setValue(self.settings_section + '/https port', self.https_port_spin_box.value())
|
||||
Settings().setValue(self.settings_section + '/https enabled', self.https_settings_group_box.isChecked())
|
||||
Settings().setValue(self.settings_section + '/ip address', self.address_edit.text())
|
||||
Settings().setValue(self.settings_section + '/twelve hour', self.twelve_hour)
|
||||
Settings().setValue(self.settings_section + '/thumbnails', self.thumbnails)
|
||||
@ -317,12 +247,6 @@ class RemoteTab(SettingsTab):
|
||||
if check_state == QtCore.Qt.Checked:
|
||||
self.thumbnails = True
|
||||
|
||||
def https_changed(self):
|
||||
"""
|
||||
Invert the HTTP group box based on Https group settings
|
||||
"""
|
||||
self.http_settings_group_box.setEnabled(not self.https_settings_group_box.isChecked())
|
||||
|
||||
def generate_icon(self):
|
||||
"""
|
||||
Generate icon for main window
|
||||
@ -330,12 +254,6 @@ class RemoteTab(SettingsTab):
|
||||
self.remote_server_icon.hide()
|
||||
icon = QtGui.QImage(':/remote/network_server.png')
|
||||
icon = icon.scaled(80, 80, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
||||
if self.is_secure:
|
||||
overlay = QtGui.QImage(':/remote/network_ssl.png')
|
||||
overlay = overlay.scaled(60, 60, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
||||
painter = QtGui.QPainter(icon)
|
||||
painter.drawImage(0, 0, overlay)
|
||||
painter.end()
|
||||
if Settings().value(self.settings_section + '/authentication enabled'):
|
||||
overlay = QtGui.QImage(':/remote/network_auth.png')
|
||||
overlay = overlay.scaled(60, 60, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
||||
|
@ -33,9 +33,7 @@ log = logging.getLogger(__name__)
|
||||
__default_settings__ = {
|
||||
'remotes/twelve hour': True,
|
||||
'remotes/port': 4316,
|
||||
'remotes/https port': 4317,
|
||||
'remotes/websocket port': 4318,
|
||||
'remotes/https enabled': False,
|
||||
'remotes/user id': 'openlp',
|
||||
'remotes/password': 'password',
|
||||
'remotes/authentication enabled': False,
|
||||
@ -63,7 +61,6 @@ class RemotesPlugin(Plugin, OpenLPMixin):
|
||||
"""
|
||||
super(RemotesPlugin, self).initialise()
|
||||
self.server = OpenLPServer()
|
||||
self.server_secure = OpenLPServer(secure=True)
|
||||
if not hasattr(self, 'remote_server_icon'):
|
||||
self.remote_server_icon = QtWidgets.QLabel(self.main_window.status_bar)
|
||||
size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
|
||||
@ -88,9 +85,6 @@ class RemotesPlugin(Plugin, OpenLPMixin):
|
||||
if self.server:
|
||||
self.server.stop_server()
|
||||
self.server = None
|
||||
if self.server_secure:
|
||||
self.server_secure.stop_server()
|
||||
self.server_secure = None
|
||||
|
||||
@staticmethod
|
||||
def about():
|
||||
|
Loading…
Reference in New Issue
Block a user