searx: Add option to allow public access to the application

[jvalleroy] Resolved merge conflict to use shortcut component.

Fixes #1590

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati authored and James Valleroy committed 2019-06-09 10:37:16 -04:00
1 parent 6a9133c305
commit 2d85b61199
10 files changed
+138 -22

No files matched your search

+20 -4
View File
@@ -30,7 +30,7 @@ from .manifest import backup, clients
clients = clients
version = 2
version = 3
managed_services = ['searx']
@@ -68,10 +68,17 @@ class SearxApp(app_module.App):
shortcut = frontpage.Shortcut(
'shortcut-searx', name, short_description=short_description,
icon='searx', url='/searx/', clients=clients, login_required=True,
icon='searx', url='/searx/', clients=clients,
login_required=(not is_public_access_enabled()),
allowed_groups=[group[0]])
self.add(shortcut)
def set_shortcut_login_required(self, login_required):
"""Change the login_required property of shortcut."""
shortcut = self.remove('shortcut-searx')
shortcut.login_required = login_required
self.add(shortcut)
def init():
"""Intialize the module."""
@@ -95,8 +102,12 @@ def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'searx', ['setup'])
if not old_version:
if not old_version or old_version < 3:
helper.call('post', actions.superuser_run, 'searx', ['enable'])
helper.call('post', actions.superuser_run, 'searx',
['disable-public-access'])
app.set_shortcut_login_required(True)
app.enable()
global service
if service is None:
@@ -108,11 +119,16 @@ def setup(helper, old_version=None):
def get_safe_search_setting():
"""Get the current value of the safe search setting for Seax."""
"""Get the current value of the safe search setting for Searx."""
value = actions.superuser_run('searx', ['get-safe-search'])
return int(value.strip())
def is_public_access_enabled():
"""Check whether public access is enabled for Searx."""
return not action_utils.webserver_is_enabled('searx-freedombox-auth')
def is_enabled():
"""Return whether the module is enabled."""
return (action_utils.webserver_is_enabled('searx-freedombox')
@@ -0,0 +1,9 @@
<Location /searx/>
Include includes/freedombox-single-sign-on.conf
<IfModule mod_auth_pubtkt.c>
TKTAuthToken "web-search" "admin"
</IfModule>
ProxyPass unix:/run/uwsgi/app/searx/socket|uwsgi://uwsgi-uds-searx/
</Location>
@@ -9,12 +9,6 @@
<Location /searx/>
Include includes/freedombox-single-sign-on.conf
<IfModule mod_auth_pubtkt.c>
TKTAuthToken "web-search" "admin"
</IfModule>
ProxyPass unix:/run/uwsgi/app/searx/socket|uwsgi://uwsgi-uds-searx/
</Location>
+8 -5
View File
@@ -26,8 +26,11 @@ from plinth.forms import ServiceForm
class SearxForm(ServiceForm):
"""Searx configuration form."""
safe_search = forms.ChoiceField(label=_('Safe Search'), help_text=_(
'Select the default family filter to apply to your search results.'),
choices=((0, _('None')),
(1, _('Moderate')),
(2, _('Strict'))))
safe_search = forms.ChoiceField(
label=_('Safe Search'), help_text=_(
'Select the default family filter to apply to your search results.'
), choices=((0, _('None')), (1, _('Moderate')), (2, _('Strict'))))
public_access = forms.BooleanField(
label=_('Public Access'), help_text=_(
'Allow this application to be used by anyone who can reach it.'),
required=False)
+16 -2
View File
@@ -23,8 +23,9 @@ from django.utils.translation import ugettext as _
from plinth import actions, views
from plinth.errors import ActionError
from plinth.modules.searx import (clients, description,
get_safe_search_setting, manual_page)
from plinth.modules.searx import (add_shortcut, clients, description,
get_safe_search_setting,
is_public_access_enabled, manual_page)
from .forms import SearxForm
@@ -43,6 +44,7 @@ class SearxServiceView(views.ServiceView):
"""Return the status of the service to fill in the form."""
initial = super().get_initial()
initial['safe_search'] = get_safe_search_setting()
initial['public_access'] = is_public_access_enabled()
return initial
def form_valid(self, form):
@@ -59,4 +61,16 @@ class SearxServiceView(views.ServiceView):
messages.error(self.request,
_('An error occurred during configuration.'))
if old_data['public_access'] != form_data['public_access']:
try:
if form_data['public_access']:
actions.superuser_run('searx', ['enable-public-access'])
else:
actions.superuser_run('searx', ['disable-public-access'])
add_shortcut()
messages.success(self.request, _('Configuration updated.'))
except ActionError as e:
messages.error(self.request,
_('An error occurred during configuration.'))
return super().form_valid(form)