mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
searx: Changes from code review
- Use 32-bit key for HMAC-256 - Use secrets library instead of os.urandom - uwsgi enable/disable along with webserver enable/disable - Text changes Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
823c2968f0
commit
67274e1566
@ -22,6 +22,8 @@ Configuration helper for searx.
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import secrets
|
||||||
|
import shutil
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth.utils import YAMLFile, gunzip
|
from plinth.utils import YAMLFile, gunzip
|
||||||
@ -42,14 +44,17 @@ def parse_arguments():
|
|||||||
|
|
||||||
|
|
||||||
def _copy_uwsgi_configuration():
|
def _copy_uwsgi_configuration():
|
||||||
"""Copy the example uwsgi configuration shipped with Searx to the
|
"""Copy example uwsgi configuration
|
||||||
appropriate uwsgi directory."""
|
|
||||||
|
Copy the example uwsgi configuration shipped with Searx documentation to
|
||||||
|
the appropriate uwsgi directory.
|
||||||
|
"""
|
||||||
example_config = ('/usr/share/doc/searx/examples/'
|
example_config = ('/usr/share/doc/searx/examples/'
|
||||||
'uwsgi/apps-available/searx.ini')
|
'uwsgi/apps-available/searx.ini')
|
||||||
destination = '/etc/uwsgi/apps-enabled/searx.ini'
|
destination = '/etc/uwsgi/apps-available/'
|
||||||
|
|
||||||
if not os.path.exists(destination):
|
if not os.path.exists(destination):
|
||||||
os.symlink(example_config, destination)
|
shutil.copy(example_config, destination)
|
||||||
action_utils.webserver_enable('uwsgi', kind='module')
|
action_utils.webserver_enable('uwsgi', kind='module')
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +69,7 @@ def _generate_secret_key():
|
|||||||
|
|
||||||
# Generate and set a secret key
|
# Generate and set a secret key
|
||||||
with YAMLFile(settings_file) as settings:
|
with YAMLFile(settings_file) as settings:
|
||||||
secret_key = os.urandom(16).hex()
|
secret_key = secrets.token_hex(32)
|
||||||
settings['server']['secret_key'] = secret_key
|
settings['server']['secret_key'] = secret_key
|
||||||
|
|
||||||
action_utils.service_restart('uwsgi')
|
action_utils.service_restart('uwsgi')
|
||||||
@ -78,12 +83,16 @@ def subcommand_setup(_):
|
|||||||
|
|
||||||
def subcommand_enable(_):
|
def subcommand_enable(_):
|
||||||
"""Enable web configuration and reload."""
|
"""Enable web configuration and reload."""
|
||||||
action_utils.webserver_enable('searx-plinth')
|
# TODO Write action_utils functions for enable/disable uwsgi
|
||||||
|
os.symlink('/etc/uwsgi/apps-available/searx.ini',
|
||||||
|
'/etc/uwsgi/apps-enabled/')
|
||||||
|
action_utils.webserver_enable('searx-freedombox')
|
||||||
|
|
||||||
|
|
||||||
def subcommand_disable(_):
|
def subcommand_disable(_):
|
||||||
"""Disable web configuration and reload."""
|
"""Disable web configuration and reload."""
|
||||||
action_utils.webserver_disable('searx-plinth')
|
action_utils.webserver_disable('searx-freedombox')
|
||||||
|
os.unlink('/etc/uwsgi/apps-enabled/searx.ini')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# This file is part of Plinth.
|
# This file is part of FreedomBox.
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
@ -15,9 +15,11 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
"""
|
"""
|
||||||
Plinth module to configure Searx
|
FreedomBox module to configure Searx
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from plinth import service as service_module
|
from plinth import service as service_module
|
||||||
@ -33,7 +35,7 @@ version = 1
|
|||||||
managed_services = ['searx']
|
managed_services = ['searx']
|
||||||
|
|
||||||
managed_packages = [
|
managed_packages = [
|
||||||
'searx', 'uwsgi', 'uwsgi-plugin-python3', 'libapache2-mod-uwsgi'
|
'searx', 'uwsgi', 'uwsgi-plugin-python3', 'libapache2-mod-proxy-uwsgi'
|
||||||
]
|
]
|
||||||
|
|
||||||
name = _('Searx')
|
name = _('Searx')
|
||||||
@ -44,10 +46,7 @@ description = [
|
|||||||
_('Searx is a privacy-respecting internet metasearch engine. '
|
_('Searx is a privacy-respecting internet metasearch engine. '
|
||||||
'It aggregrates and displays results from multiple search engines.'),
|
'It aggregrates and displays results from multiple search engines.'),
|
||||||
_('Searx can be used to avoid tracking and profiling by search engines. '
|
_('Searx can be used to avoid tracking and profiling by search engines. '
|
||||||
'It stores no cookies by default. Additionally, Searx can be used over '
|
'It stores no cookies by default.')
|
||||||
'Tor for online anonymity.'),
|
|
||||||
_('When enabled, Searx\'s web interface will be available from '
|
|
||||||
'<a href="/searx">/searx</a>.'),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
service = None
|
service = None
|
||||||
@ -74,7 +73,7 @@ def init():
|
|||||||
def setup(helper, old_version=None):
|
def setup(helper, old_version=None):
|
||||||
"""Install and configure the module."""
|
"""Install and configure the module."""
|
||||||
helper.install(managed_packages)
|
helper.install(managed_packages)
|
||||||
helper.call('setup', actions.superuser_run, 'searx', ['setup'])
|
helper.call('post', actions.superuser_run, 'searx', ['setup'])
|
||||||
helper.call('post', actions.superuser_run, 'searx', ['enable'])
|
helper.call('post', actions.superuser_run, 'searx', ['enable'])
|
||||||
global service
|
global service
|
||||||
if service is None:
|
if service is None:
|
||||||
@ -93,7 +92,8 @@ def add_shortcut():
|
|||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.webserver_is_enabled('searx-plinth')
|
return (action_utils.webserver_is_enabled('searx-freedombox')
|
||||||
|
and os.path.exists('/etc/uwsgi/apps-enabled/searx.ini'))
|
||||||
|
|
||||||
|
|
||||||
def enable():
|
def enable():
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# This file is part of Plinth.
|
# This file is part of FreedomBox.
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# This file is part of Plinth.
|
# This file is part of FreedomBox.
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
|||||||
@ -150,8 +150,8 @@ def gunzip(gzip_file, output_file):
|
|||||||
if not os.path.exists(output_dir):
|
if not os.path.exists(output_dir):
|
||||||
os.makedirs(output_dir, mode=0o755)
|
os.makedirs(output_dir, mode=0o755)
|
||||||
|
|
||||||
with gzip.open(gzip_file, 'rb') as f:
|
with gzip.open(gzip_file, 'rb') as file_handle:
|
||||||
contents = f.read()
|
contents = file_handle.read()
|
||||||
with open(output_file, 'wb') as f:
|
with open(output_file, 'wb') as file_handle:
|
||||||
f.write(contents)
|
file_handle.write(contents)
|
||||||
os.chmod(output_file, 0o644)
|
os.chmod(output_file, 0o644)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user