aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2022-05-07 15:32:29 +0200
committercbdev <cb@cbcdn.com>2022-05-07 15:32:29 +0200
commit6d5ca0f46c55519aff239684639c5278d3bd2425 (patch)
tree2382a99fa4ab7ac8ab5c44c6593dbfd514a752a0
parent43c8e2d23a37153591fb34a69fe40caec4ac50b5 (diff)
downloadcargohold-6d5ca0f46c55519aff239684639c5278d3bd2425.tar.gz
cargohold-6d5ca0f46c55519aff239684639c5278d3bd2425.tar.bz2
cargohold-6d5ca0f46c55519aff239684639c5278d3bd2425.zip
Extend README, implement cargohold-cli
-rw-r--r--README.md36
-rw-r--r--TODO1
-rwxr-xr-xbackend/cargohold-cli71
3 files changed, 104 insertions, 4 deletions
diff --git a/README.md b/README.md
index 30588ac..7827385 100644
--- a/README.md
+++ b/README.md
@@ -6,22 +6,50 @@ that lets them download or view the files you want them to have.
## Installation
-* Install nginx and uwsgi
+Required dependencies
+
+* nginx
+* uwsgi
+* uwsgi-plugin-python3
+* sqlite3
+* python3
+
+Basic infrastructure
+
* Create a directory where cargohold will store the uploaded files
* Set the directory's owner to the user you want uwsgi to run the application under
* Edit `backend/config.py` to match your setup
* Edit `configs/nginx.config` to match your setup
* Note that the `client_max_body_size` directive will limit the maximum size of a single uploaded file
-* Install `configs/nginx.config` to `/etc/nginx/sites-enabled`
+* Install `configs/nginx.config` to `/etc/nginx/sites-enabled/`
* Edit `configs/uwsgi.ini` to match your setup
* Note that the `limit-post` option will limit the maximum size of a single uploaded file
-* Install `configs/uwsgi.ini` to `/etc/uwsgi/apps-enabled/cargohold.ini`
+* Install `configs/uwsgi.ini` to `/etc/uwsgi/apps-enabled/`
+
+Initial configuration
+
+* Create the cargohold database by running `sqlite3 cargohold.db3 < backend/cargohold.sql`
+* Update `backend/config.py` with the path to your database
TBD: Extend this.
## Usage
-TBD
+The database stores the the following data for each alias
+
+* *Alias*: The identifier to be appended to the base URL
+* *User*: The user the identifier belongs to, for administrative and storage accounting purposes
+* *Real path*: The on-disk directory name where, when prepended with both the `fileroot` and optionally, the `userdir`, the data is stored. Multiple aliases may point to the same real path.
+* *Access level*: The access level this alias permits to the real path. A string consisting of any of the characters *c* (*C*reate / Upload), *r* (*R*etrieve / Read), *u* (*U*pdate), *d* (*D*elete) in any order.
+* *Storage limit*: Per-alias storage limit (applied when uploading)
+* *Display mode*: Parameter
+
+The storage limit for each alias (applied when uploading files) is calculated as the minimum of the following parameters
+
+* Global disk size limit
+* `global_limit` in `backend/config.py`
+* The per-user limit
+* The per-alias limit
## Interface
diff --git a/TODO b/TODO
index 14cc4c1..9e35672 100644
--- a/TODO
+++ b/TODO
@@ -4,3 +4,4 @@ User-facing administration panel
Pluggable authentication
Automatic resizing for gallery mode
Link titles
+'Download all' button
diff --git a/backend/cargohold-cli b/backend/cargohold-cli
new file mode 100755
index 0000000..99c7caa
--- /dev/null
+++ b/backend/cargohold-cli
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+DATABASE=cargohold.db3
+
+usage(){
+ printf "This utility can be used to manage the cargohold database from the command line\n\n"
+ printf "Cargohold database used: %s\n\n" "$DATABASE"
+ printf "Usage:\n"
+ printf "\t%s adduser <name> [<limit>]\n" "$0"
+ printf "\tExample: %s adduser foo 10000\n" "$0"
+ printf "\tThis will add user 'foo' with a storage limit of 10K bytes\n\n"
+ printf "\t%s addalias <user> <directory> <access> [<alias>]\n" "$0"
+ printf "\tExample: %s addalias foo mydirectory c send-me-files\n" "$0"
+ printf "\tThis will make the directory 'mydirectory' under the fileroot (and optionally userdir) available for uploads ('c') under the alias 'send-me-files'\n\n"
+ printf "\t%s list\n" "$0"
+ printf "\tList all users and configured aliases\n"
+}
+
+# adduser <name> [<limit>]
+adduser(){
+ if [ -z "$1" ]; then
+ usage
+ exit 1
+ fi
+ limit=${2:-0}
+
+ printf "Adding user %s\n" "$1"
+ sqlite3 "$DATABASE" "PRAGMA foreign_keys = ON; INSERT INTO users (name, storage) VALUES ('$1', $limit);"
+}
+
+# addalias <user> <real> <access> [<alias>]
+addalias(){
+ if [ "$#" -lt 3 ]; then
+ usage
+ exit 1
+ fi
+ alias=${4:-$(xxd -g 0 -l 16 -p /dev/urandom)}
+
+ printf "Adding alias %s pointing to %s (ACL %s, User %s)\n" "$alias" "$2" "$3" "$1"
+ sqlite3 "$DATABASE" "PRAGMA foreign_keys = ON; INSERT INTO aliases (alias, user, real, access) VALUES ('$alias', '$1', '$2', '$3');"
+}
+
+list(){
+ printf "Listing all users\n"
+ sqlite3 -column -header "$DATABASE" "SELECT name, storage FROM users;"
+
+ printf "\nListing all aliases\n"
+ sqlite3 -column "$DATABASE" "SELECT user || ': ' || alias || ' (' || access || ') -> ' || real FROM aliases;"
+}
+
+if [ "$#" -lt 1 ]; then
+ usage
+ exit 0
+fi
+
+case "$1" in
+ "adduser")
+ shift
+ adduser $@
+ ;;
+ "addalias")
+ shift
+ addalias $@
+ ;;
+ "list")
+ list
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+esac