]> git.ekhem.eu.org Git - gdrive_proxy.git/commitdiff
Handle multiple accounts.
authorJakub Czajka <jczajka@google.com>
Sat, 4 May 2024 10:10:34 +0000 (12:10 +0200)
committerJakub Czajka <jczajka@google.com>
Sat, 4 May 2024 10:10:34 +0000 (12:10 +0200)
account.sh [new file with mode: 0755]
auth.sh
gdrive_proxy.conf
gdrive_proxy.sh

diff --git a/account.sh b/account.sh
new file mode 100755 (executable)
index 0000000..190fc75
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Copyright (c) 2024 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+. /etc/environment
+
+format_accounts() {
+  echo ${gdrive_accounts} \
+    | xargs --replace={} \
+            --delimiter=" " echo "<option value='{}'>{}</option>"
+}
+
+PAGE="
+<!DOCTYPE html>
+<html>
+<head>
+  <title>GdriveProxy</title>
+  <meta name='viewport' content='width=device-width'>
+  <style>
+    body {
+      background-color: #7fa99b;
+    }
+    form {
+      width: min(400px, 100%);
+    }
+    fieldset {
+      background-color: #f1d18a;
+      display: flex;
+      flex-direction: column;
+      row-gap: 10px;
+    }
+  </style>
+</head>
+<body>
+  <form action='/list'>
+    <fieldset>
+      <legend>Account</legend>
+      <select id='account' name='account'>
+        $(format_accounts)
+      </select>
+      <button type='submit'>Select</button>
+    </fieldset>
+  </form>
+</body>
+</html>"
+
+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 bf273829bd059e156d40bdb058c1b259e7d44bb9..023406aa8872779139250ec283b2578a086728e2 100755 (executable)
--- 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 \
index aea72ddb0ceea45a449aac46b7566444409fbc7b..dedb4e57619b743677b6999c2365aecb0382fba3 100644 (file)
@@ -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;
     }
 }
 
index 230c64a04914c5cfc4cbcc7c77af3948b4f8aac4..22d6c2a1851a5a0f44ccf0e3fe943e72d772652e 100755 (executable)
@@ -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}"