Browse Source

utils/morty.sh: set morty key to avoid service abuse

- https://github.com/asciimoo/searx/issues/1871#issuecomment-592459798

    make install all

generates random MORTY_KEY, install service with that key and sets option in the
searx settingy.yml file.

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Markus Heiser 5 years ago
parent
commit
ea3255835a
3 changed files with 7 additions and 4 deletions
  1. 4 1
      utils/morty.sh
  2. 2 2
      utils/searx.sh
  3. 1 1
      utils/templates/lib/systemd/system/morty.service

+ 4 - 1
utils/morty.sh

@@ -208,6 +208,9 @@ main() {
 }
 }
 
 
 install_all() {
 install_all() {
+
+    MORTY_KEY="$(head -c 32 /dev/urandom | base64)"
+
     rst_title "Install $SERVICE_NAME (service)"
     rst_title "Install $SERVICE_NAME (service)"
     assert_user
     assert_user
     wait_key
     wait_key
@@ -233,7 +236,7 @@ install_all() {
     fi
     fi
     info_searx
     info_searx
     if ask_yn "Add image and result proxy to searx settings.yml?" Yn; then
     if ask_yn "Add image and result proxy to searx settings.yml?" Yn; then
-        "${REPO_ROOT}/utils/searx.sh" option result-proxy "${PUBLIC_URL_MORTY}"
+        "${REPO_ROOT}/utils/searx.sh" option result-proxy "${PUBLIC_URL_MORTY}" "${MORTY_KEY}"
         "${REPO_ROOT}/utils/searx.sh" option image-proxy-on
         "${REPO_ROOT}/utils/searx.sh" option image-proxy-on
     fi
     fi
 
 

+ 2 - 2
utils/searx.sh

@@ -584,7 +584,7 @@ set_result_proxy() {
 
 
     # usage: set_result_proxy <URL> [<key>]
     # usage: set_result_proxy <URL> [<key>]
 
 
-    info_msg "try to set result proxy: $1"
+    info_msg "try to set result proxy: '$1' ($2)"
     cp "${SEARX_SETTINGS_PATH}" "${SEARX_SETTINGS_PATH}.bak"
     cp "${SEARX_SETTINGS_PATH}" "${SEARX_SETTINGS_PATH}.bak"
     _set_result_proxy "$1" "$2" > "${SEARX_SETTINGS_PATH}"
     _set_result_proxy "$1" "$2" > "${SEARX_SETTINGS_PATH}"
 }
 }
@@ -593,7 +593,7 @@ _set_result_proxy() {
     local line
     local line
     local stage=0
     local stage=0
     local url="    url: $1"
     local url="    url: $1"
-    local key="    key: $2"
+    local key="    key: !!binary \"$2\""
     if [[ -z $2 ]]; then
     if [[ -z $2 ]]; then
        key=
        key=
     fi
     fi

+ 1 - 1
utils/templates/lib/systemd/system/morty.service

@@ -10,7 +10,7 @@ Type=simple
 User=${SERVICE_USER}
 User=${SERVICE_USER}
 Group=${SERVICE_GROUP}
 Group=${SERVICE_GROUP}
 WorkingDirectory=${SERVICE_HOME}
 WorkingDirectory=${SERVICE_HOME}
-ExecStart=${SERVICE_HOME}/go-apps/bin/morty -key '' -listen '${MORTY_LISTEN}' -timeout ${MORTY_TIMEOUT}
+ExecStart=${SERVICE_HOME}/go-apps/bin/morty -key '${MORTY_KEY}' -listen '${MORTY_LISTEN}' -timeout ${MORTY_TIMEOUT}
 
 
 Restart=always
 Restart=always
 Environment=USER=${SERVICE_USER} HOME=${SERVICE_HOME} DEBUG=${SERVICE_ENV_DEBUG}
 Environment=USER=${SERVICE_USER} HOME=${SERVICE_HOME} DEBUG=${SERVICE_ENV_DEBUG}