From a2a40014ab878993ba265334758971e3f8f1d76a Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Sat, 4 May 2024 12:10:34 +0200 Subject: [PATCH] Handle multiple accounts. --- account.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++ auth.sh | 2 +- gdrive_proxy.conf | 22 ++++++++++++++------- gdrive_proxy.sh | 4 +++- 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100755 account.sh diff --git a/account.sh b/account.sh new file mode 100755 index 0000000..190fc75 --- /dev/null +++ b/account.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. + +. /etc/environment + +format_accounts() { + echo ${gdrive_accounts} \ + | xargs --replace={} \ + --delimiter=" " echo "" +} + +PAGE=" + + + + GdriveProxy + + + + +
+
+ Account + + +
+
+ +" + +echo "HTTP/1.1 200 OK" +echo "Content-type: text/html" +echo "${PAGE}" | sed 's/^[ \t]*//g' diff --git a/auth.sh b/auth.sh index bf27382..023406a 100755 --- a/auth.sh +++ b/auth.sh @@ -12,7 +12,7 @@ with_hyperlink() { python3 -u -m gdrive_knife auth \ --credentials ${gdrive_credentials} \ - --token ${gdrive_auth_token} \ + --token ${AUTH_TOKEN} \ --on_success https://drive.${private_domain} \ --on_token https://drive.${private_domain}/auth \ --port 3030 \ diff --git a/gdrive_proxy.conf b/gdrive_proxy.conf index aea72dd..dedb4e5 100644 --- a/gdrive_proxy.conf +++ b/gdrive_proxy.conf @@ -25,6 +25,20 @@ server { proxy_pass http://localhost:3030; } + location ~ ^/list(.*) { + include fastcgi_params; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + + fastcgi_keep_conn on; + fastcgi_read_timeout 3s; + + fastcgi_buffering off; + fastcgi_param NO_BUFFERING ""; + + fastcgi_param ACCOUNT ${dollar}arg_account; + fastcgi_param SCRIPT_FILENAME ${dollar}document_root/gdrive_proxy.sh; + } + location = /delete { include fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap.socket; @@ -90,13 +104,7 @@ server { include fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap.socket; - fastcgi_keep_conn on; - fastcgi_read_timeout 3s; - - fastcgi_buffering off; - fastcgi_param NO_BUFFERING ""; - - fastcgi_param SCRIPT_FILENAME ${dollar}document_root/gdrive_proxy.sh; + fastcgi_param SCRIPT_FILENAME ${dollar}document_root/account.sh; } } diff --git a/gdrive_proxy.sh b/gdrive_proxy.sh index 230c64a..22d6c2a 100755 --- a/gdrive_proxy.sh +++ b/gdrive_proxy.sh @@ -7,9 +7,11 @@ # Kill authentication server if already present. [ ! -z $(pgrep --full ".*gdrive_knife.*") ] && pkill --full ".*gdrive_knife.*" +AUTH_TOKEN="${prod_dir}/${gdrive_proxy}/${ACCOUNT}.json" + . ./auth.sh || exit 0 -FILES=$(python3 -u -m gdrive_knife 2>&1 list --token ${gdrive_auth_token}) +FILES=$(python3 -u -m gdrive_knife 2>&1 list --token ${AUTH_TOKEN}) format_files() { echo ${FILES} | xargs --replace={} --delimiter=" " echo "${1}" -- 2.39.5