summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2021-05-26 19:43:27 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2021-05-28 08:32:52 +0200
commit6ed4616da99b25703489e7431d84d8749a7a167c (patch)
treeb05c82a900f25c384f3cf26898314225ba5d1fc3 /searx/webapp.py
parente1f244b2d5698480f93169fce4bdc1782fc75bda (diff)
downloadsearxng-6ed4616da99b25703489e7431d84d8749a7a167c.tar.gz
searxng-6ed4616da99b25703489e7431d84d8749a7a167c.zip
[enh] add settings option to enable/disable search formats
Access to formats can be denied by settings configuration:: search: formats: [html, csv, json, rss] Closes: https://github.com/searxng/searxng/issues/95 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-xsearx/webapp.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index ad6ed368b..47f77acc7 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -31,6 +31,8 @@ from pygments.formatters import HtmlFormatter # pylint: disable=no-name-in-modu
from werkzeug.middleware.proxy_fix import ProxyFix
from werkzeug.serving import WSGIRequestHandler
+import flask
+
from flask import (
Flask,
request,
@@ -86,6 +88,7 @@ from searx.utils import (
gen_useragent,
dict_subset,
match_language,
+ get_value,
)
from searx.version import VERSION_STRING
from searx.query import RawTextQuery
@@ -161,6 +164,8 @@ for indice, theme in enumerate(themes):
for (dirpath, dirnames, filenames) in os.walk(theme_img_path):
global_favicons[indice].extend(filenames)
+OUTPUT_FORMATS = ['html', 'csv', 'json', 'rss']
+
STATS_SORT_PARAMETERS = {
'name': (False, 'name', ''),
'score': (True, 'score', 0),
@@ -511,6 +516,11 @@ def render(template_name, override_theme=None, **kwargs):
kwargs['preferences'] = request.preferences
+ kwargs['search_formats'] = [
+ x for x in get_value(
+ settings, 'search', 'formats', default=OUTPUT_FORMATS)
+ if x != 'html']
+
kwargs['brand'] = brand
kwargs['translations'] = json.dumps(get_translations(), separators=(',', ':'))
@@ -683,9 +693,12 @@ def search():
# output_format
output_format = request.form.get('format', 'html')
- if output_format not in ['html', 'csv', 'json', 'rss']:
+ if output_format not in OUTPUT_FORMATS:
output_format = 'html'
+ if output_format not in get_value(settings, 'search', 'formats', default=OUTPUT_FORMATS):
+ flask.abort(403)
+
# check if there is query (not None and not an empty string)
if not request.form.get('q'):
if output_format == 'html':