mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
Enable Single Sign On for transmission
- Disabled login using username and password. Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
5e2b4b1c9e
commit
5ff459387e
@ -8,6 +8,10 @@
|
||||
##
|
||||
<Location /transmission>
|
||||
ProxyPass http://localhost:9091/transmission
|
||||
Include includes/freedombox-single-sign-on.conf
|
||||
<IfModule mod_auth_pubtkt.c>
|
||||
TKTAuthToken "admin" "bit-torrent"
|
||||
</IfModule>
|
||||
## Send the scheme from user's request to enable Transmission to
|
||||
## redirect URLs, set cookies, set absolute URLs (if any)
|
||||
## properly.
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Plinth module to configure Transmission server
|
||||
"""
|
||||
@ -28,7 +27,7 @@ from plinth import frontpage
|
||||
from plinth import service as service_module
|
||||
from plinth.menu import main_menu
|
||||
from plinth.client import web_client
|
||||
|
||||
from plinth.modules.users import add_group
|
||||
|
||||
version = 1
|
||||
|
||||
@ -47,7 +46,7 @@ description = [
|
||||
_('Access the web interface at <a href="/transmission">/transmission</a>.')
|
||||
]
|
||||
|
||||
web_clients = [web_client(name='Transmission',url='/transmission')]
|
||||
web_clients = [web_client(name='Transmission', url='/transmission')]
|
||||
|
||||
reserved_usernames = ['debian-transmission']
|
||||
|
||||
@ -57,15 +56,20 @@ service = None
|
||||
def init():
|
||||
"""Intialize the Transmission module."""
|
||||
menu = main_menu.get('apps')
|
||||
menu.add_urlname(name, 'glyphicon-save', 'transmission:index', short_description)
|
||||
menu.add_urlname(name, 'glyphicon-save', 'transmission:index',
|
||||
short_description)
|
||||
|
||||
global service
|
||||
setup_helper = globals()['setup_helper']
|
||||
if setup_helper.get_state() != 'needs-setup':
|
||||
service = service_module.Service(
|
||||
managed_services[0], name, ports=['http', 'https'],
|
||||
is_external=True, is_enabled=is_enabled,
|
||||
enable=enable, disable=disable)
|
||||
managed_services[0],
|
||||
name,
|
||||
ports=['http', 'https'],
|
||||
is_external=True,
|
||||
is_enabled=is_enabled,
|
||||
enable=enable,
|
||||
disable=disable)
|
||||
|
||||
if is_enabled():
|
||||
add_shortcut()
|
||||
@ -75,32 +79,45 @@ def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
helper.install(managed_packages)
|
||||
|
||||
new_configuration = {'rpc-whitelist-enabled': False}
|
||||
helper.call('post', actions.superuser_run, 'transmission',
|
||||
['merge-configuration'],
|
||||
input=json.dumps(new_configuration).encode())
|
||||
new_configuration = {
|
||||
'rpc-whitelist-enabled': False,
|
||||
'rpc-authentication-required': False
|
||||
}
|
||||
helper.call(
|
||||
'post',
|
||||
actions.superuser_run,
|
||||
'transmission', ['merge-configuration'],
|
||||
input=json.dumps(new_configuration).encode())
|
||||
|
||||
helper.call('post', actions.superuser_run, 'transmission', ['enable'])
|
||||
global service
|
||||
if service is None:
|
||||
service = service_module.Service(
|
||||
managed_services[0], name, ports=['http', 'https'],
|
||||
is_external=True, is_enabled=is_enabled,
|
||||
enable=enable, disable=disable)
|
||||
managed_services[0],
|
||||
name,
|
||||
ports=['http', 'https'],
|
||||
is_external=True,
|
||||
is_enabled=is_enabled,
|
||||
enable=enable,
|
||||
disable=disable)
|
||||
helper.call('post', service.notify_enabled, None, True)
|
||||
helper.call('post', add_shortcut)
|
||||
add_group('bit-torrent')
|
||||
|
||||
|
||||
def add_shortcut():
|
||||
frontpage.add_shortcut(
|
||||
'transmission', name, short_description=short_description, url='/transmission',
|
||||
login_required=True)
|
||||
'transmission',
|
||||
name,
|
||||
short_description=short_description,
|
||||
url='/transmission',
|
||||
login_required=True)
|
||||
|
||||
|
||||
def is_enabled():
|
||||
"""Return whether the module is enabled."""
|
||||
return (action_utils.service_is_enabled('transmission-daemon') and
|
||||
action_utils.webserver_is_enabled('transmission-plinth'))
|
||||
return (action_utils.service_is_enabled('transmission-daemon')
|
||||
and action_utils.webserver_is_enabled('transmission-plinth'))
|
||||
|
||||
|
||||
def enable():
|
||||
@ -121,7 +138,8 @@ def diagnose():
|
||||
|
||||
results.append(action_utils.diagnose_port_listening(9091, 'tcp4'))
|
||||
results.append(action_utils.diagnose_port_listening(9091, 'tcp6'))
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/transmission', check_certificate=False))
|
||||
results.extend(
|
||||
action_utils.diagnose_url_on_all(
|
||||
'https://{host}/transmission', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Plinth module for configuring Transmission.
|
||||
"""
|
||||
@ -32,13 +31,3 @@ class TransmissionForm(ServiceForm): # pylint: disable=W0232
|
||||
help_text=_('Directory where downloads are saved. If you change the '
|
||||
'default directory, ensure that the new directory exists '
|
||||
'and is writable by "debian-transmission" user.'))
|
||||
|
||||
rpc_username = forms.CharField(
|
||||
label=_('Username'),
|
||||
help_text=_('Username to login to the web interface.'))
|
||||
|
||||
rpc_password = forms.CharField(
|
||||
label=_('Password'),
|
||||
help_text=_('Password to login to the web interface. Current '
|
||||
'password is shown in a hashed format. To set a new '
|
||||
'password, enter the password in plain text.'))
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Plinth module for configuring Transmission Server
|
||||
"""
|
||||
@ -42,11 +41,15 @@ class TransmissionServiceView(views.ServiceView):
|
||||
|
||||
def get_initial(self):
|
||||
"""Get the current settings from Transmission server."""
|
||||
configuration = actions.superuser_run(
|
||||
'transmission', ['get-configuration'])
|
||||
configuration = actions.superuser_run('transmission',
|
||||
['get-configuration'])
|
||||
status = json.loads(configuration)
|
||||
status = {key.translate(str.maketrans({'-': '_'})): value
|
||||
for key, value in status.items()}
|
||||
status = {
|
||||
key.translate(str.maketrans({
|
||||
'-': '_'
|
||||
})): value
|
||||
for key, value in status.items()
|
||||
}
|
||||
status['is_enabled'] = self.service.is_enabled()
|
||||
status['is_running'] = self.service.is_running()
|
||||
status['hostname'] = socket.gethostname()
|
||||
@ -58,17 +61,14 @@ class TransmissionServiceView(views.ServiceView):
|
||||
old_status = form.initial
|
||||
new_status = form.cleaned_data
|
||||
|
||||
if old_status['download_dir'] != new_status['download_dir'] or \
|
||||
old_status['rpc_username'] != new_status['rpc_username'] or \
|
||||
old_status['rpc_password'] != new_status['rpc_password']:
|
||||
if old_status['download_dir'] != new_status['download_dir']:
|
||||
new_configuration = {
|
||||
'download-dir': new_status['download_dir'],
|
||||
'rpc-username': new_status['rpc_username'],
|
||||
'rpc-password': new_status['rpc_password'],
|
||||
}
|
||||
|
||||
actions.superuser_run('transmission', ['merge-configuration'],
|
||||
input=json.dumps(new_configuration).encode())
|
||||
actions.superuser_run(
|
||||
'transmission', ['merge-configuration'],
|
||||
input=json.dumps(new_configuration).encode())
|
||||
messages.success(self.request, _('Configuration updated'))
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user