mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
mediawiki: Serve hidden service over http for .onion domains
[sunil: rename the form field variable] [sunil: rename the parater to get/set_server_url functions] [sunil: remove unused PrependWidget, can be added back later] [sunil: update functional tests] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
b3d5d68448
commit
1dcfa06dd8
@ -157,7 +157,11 @@ def get_server_url():
|
|||||||
return urlparse(server_url).netloc
|
return urlparse(server_url).netloc
|
||||||
|
|
||||||
|
|
||||||
def set_server_url(server_url):
|
def set_server_url(domain):
|
||||||
"""Set the value of $wgServer."""
|
"""Set the value of $wgServer."""
|
||||||
|
protocol = 'https'
|
||||||
|
if domain.endswith('.onion'):
|
||||||
|
protocol = 'http'
|
||||||
|
|
||||||
actions.superuser_run('mediawiki',
|
actions.superuser_run('mediawiki',
|
||||||
['set-server-url', f'https://{server_url}'])
|
['set-server-url', f'{protocol}://{domain}'])
|
||||||
|
|||||||
@ -6,8 +6,6 @@ FreedomBox app for configuring MediaWiki.
|
|||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms import Widget
|
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
@ -21,31 +19,6 @@ def get_skins():
|
|||||||
if skin.is_dir()]
|
if skin.is_dir()]
|
||||||
|
|
||||||
|
|
||||||
class PrependWidget(Widget):
|
|
||||||
"""Widget to create input-groups with prepended text."""
|
|
||||||
|
|
||||||
def __init__(self, base_widget, data, *args, **kwargs):
|
|
||||||
"""Initialize widget and get base instance"""
|
|
||||||
super(PrependWidget, self).__init__(*args, **kwargs)
|
|
||||||
self.base_widget = base_widget(*args, **kwargs)
|
|
||||||
self.data = data
|
|
||||||
|
|
||||||
def render(self, name, value, attrs=None, renderer=None):
|
|
||||||
"""Render base widget and add bootstrap spans."""
|
|
||||||
attrs['class'] = 'form-control'
|
|
||||||
field = self.base_widget.render(name, value, attrs, renderer)
|
|
||||||
widget_html = '''
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-prepend">
|
|
||||||
<span class="input-group-text">
|
|
||||||
%(data)s
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
%(field)s
|
|
||||||
</div>'''
|
|
||||||
return mark_safe((widget_html) % {'field': field, 'data': self.data})
|
|
||||||
|
|
||||||
|
|
||||||
class MediaWikiForm(forms.Form): # pylint: disable=W0232
|
class MediaWikiForm(forms.Form): # pylint: disable=W0232
|
||||||
"""MediaWiki configuration form."""
|
"""MediaWiki configuration form."""
|
||||||
password = forms.CharField(
|
password = forms.CharField(
|
||||||
@ -56,11 +29,11 @@ class MediaWikiForm(forms.Form): # pylint: disable=W0232
|
|||||||
'Leave this field blank to keep the current password.'),
|
'Leave this field blank to keep the current password.'),
|
||||||
required=False, widget=forms.PasswordInput, min_length=10)
|
required=False, widget=forms.PasswordInput, min_length=10)
|
||||||
|
|
||||||
server_url = forms.CharField(
|
domain = forms.CharField(
|
||||||
label=_('Server URL'), required=False, help_text=_(
|
label=_('Domain'), required=False, help_text=_(
|
||||||
'Used by MediaWiki to generate URLs that point to the wiki '
|
'Used by MediaWiki to generate URLs that point to the wiki '
|
||||||
'such as in footer, feeds and emails.'),
|
'such as in footer, feeds and emails. Examples: '
|
||||||
widget=PrependWidget(base_widget=forms.TextInput, data='https://'))
|
'"myfreedombox.example.org" or "example.onion".'))
|
||||||
|
|
||||||
enable_public_registrations = forms.BooleanField(
|
enable_public_registrations = forms.BooleanField(
|
||||||
label=_('Enable public registrations'), required=False,
|
label=_('Enable public registrations'), required=False,
|
||||||
|
|||||||
@ -6,8 +6,9 @@ Functional, browser based tests for mediawiki app.
|
|||||||
import pathlib
|
import pathlib
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import requests
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import requests
|
||||||
|
|
||||||
from plinth.tests import functional
|
from plinth.tests import functional
|
||||||
from plinth.tests.functional import config
|
from plinth.tests.functional import config
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ class TestMediawikiApp(functional.BaseAppTests):
|
|||||||
"""Setup the app."""
|
"""Setup the app."""
|
||||||
functional.login(session_browser)
|
functional.login(session_browser)
|
||||||
functional.install(session_browser, 'mediawiki')
|
functional.install(session_browser, 'mediawiki')
|
||||||
_set_server_url(session_browser)
|
_set_domain(session_browser)
|
||||||
|
|
||||||
def test_public_registrations(self, session_browser):
|
def test_public_registrations(self, session_browser):
|
||||||
"""Test enabling public registrations."""
|
"""Test enabling public registrations."""
|
||||||
@ -241,9 +242,9 @@ def __has_main_page(browser):
|
|||||||
return 'This page has been deleted.' not in content.text
|
return 'This page has been deleted.' not in content.text
|
||||||
|
|
||||||
|
|
||||||
def _set_server_url(browser):
|
def _set_domain(browser):
|
||||||
"""Set the value of server url to the value in the given env_var."""
|
"""Set the value of domain to the value in the given env_var."""
|
||||||
functional.nav_to_module(browser, 'mediawiki')
|
functional.nav_to_module(browser, 'mediawiki')
|
||||||
server_url = urlparse(config['DEFAULT']['url']).netloc
|
domain = urlparse(config['DEFAULT']['url']).netloc
|
||||||
browser.find_by_id('id_server_url').fill(server_url)
|
browser.find_by_id('id_domain').fill(domain)
|
||||||
functional.submit(browser, form_class='form-configuration')
|
functional.submit(browser, form_class='form-configuration')
|
||||||
|
|||||||
@ -63,6 +63,6 @@ def test_default_skin():
|
|||||||
def test_server_url():
|
def test_server_url():
|
||||||
"""Test getting and setting $wgServer."""
|
"""Test getting and setting $wgServer."""
|
||||||
assert mediawiki.get_server_url() == 'freedombox.local'
|
assert mediawiki.get_server_url() == 'freedombox.local'
|
||||||
new_server_url = 'mydomain.freedombox.rocks'
|
new_domain = 'mydomain.freedombox.rocks'
|
||||||
mediawiki.set_server_url(new_server_url)
|
mediawiki.set_server_url(new_domain)
|
||||||
assert mediawiki.get_server_url() == new_server_url
|
assert mediawiki.get_server_url() == new_domain
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class MediaWikiAppView(views.AppView):
|
|||||||
'enable_public_registrations': is_public_registration_enabled(),
|
'enable_public_registrations': is_public_registration_enabled(),
|
||||||
'enable_private_mode': is_private_mode_enabled(),
|
'enable_private_mode': is_private_mode_enabled(),
|
||||||
'default_skin': get_default_skin(),
|
'default_skin': get_default_skin(),
|
||||||
'server_url': get_server_url()
|
'domain': get_server_url()
|
||||||
})
|
})
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
@ -93,8 +93,8 @@ class MediaWikiAppView(views.AppView):
|
|||||||
mediawiki.set_default_skin(new_config['default_skin'])
|
mediawiki.set_default_skin(new_config['default_skin'])
|
||||||
messages.success(self.request, _('Default skin changed'))
|
messages.success(self.request, _('Default skin changed'))
|
||||||
|
|
||||||
if is_changed('server_url'):
|
if is_changed('domain'):
|
||||||
mediawiki.set_server_url(new_config['server_url'])
|
mediawiki.set_server_url(new_config['domain'])
|
||||||
messages.success(self.request, _('Server URL updated'))
|
messages.success(self.request, _('Domain name updated'))
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user