From ab7170ddd3592283d5920e7a8a36e2e1d7fd48b9 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 23 Jan 2024 17:52:12 -0800 Subject: [PATCH 1/8] Update README.md --- README.md | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1fe234ec..d43f7cd7 100644 --- a/README.md +++ b/README.md @@ -417,31 +417,52 @@ For more discussion on managed and paid hosting options see here: [!TIP] +> Whether in Docker or not, ArchiveBox commands all work the same way, and can be used in tandem to access the same data directory. +> For example, you can run the web server in Docker Compose, and run one-off commands on the host at the same time with `pip`-installed ArchiveBox. + +```bash +# e.g. archivebox add --depth=1 'https://news.ycombinator.com' +# or docker compose run archivebox --depth=1 'https://news.ycombinator.com' +# or docker run -it -v $PWD:/data archivebox/archivebox add --depth=1 'https://news.ycombinator.com' +``` + +#### Bare Metal Usage (`pip`/`apt`/`brew`/etc.) +```bash +archivebox init --setup # safe to run init multiple times (also how you update versions) +archivebox version # get archivebox version info and more +archivebox add --depth=1 'https://news.ycombinator.com' +``` + +##### Docker Compose Usage +```bash +# make sure you have `docker-compose.yml` from the Quickstart instructions first +docker compose run archivebox init --setup +docker compose run archivebox version +docker compose run archivebox add --depth=1 'https://news.ycombinator.com' +``` + +#### Docker Usage +```bash +docker run -v $PWD:/data -it archivebox/archivebox init --setup +docker run -v $PWD:/data -it archivebox/archivebox version +``` + +#### Next Steps + - `archivebox help/version` to see the list of available subcommands and currently installed version info - `archivebox setup/init/config/status/manage` to administer your collection - `archivebox add/schedule/remove/update/list/shell/oneshot` to manage Snapshots in the archive - `archivebox schedule` to pull in fresh URLs regularly from [bookmarks/history/Pocket/Pinboard/RSS/etc.](#input-formats) -*Docker hint:* Because ArchiveBox commands all work the same way, you can run the UI server -in Docker Compose, but run one-off commands on the host without needing Docker (just `cd data/; pip install archivebox; archivebox status`). #### 🖥  Web UI Usage +##### Start the Web Server ```bash +# Bare metal (pip/apt/brew/etc): archivebox server 0.0.0.0:8000 # open http://127.0.0.1:8000 to view it -# Optional: -archivebox manage createsuperuser # create new admin username & pass -archivebox config --set PUBLIC_ADD_VIEW=False # True = allow anyone to submit URLs -archivebox config --set PUBLIC_SNAPSHOTS=False # True = allow anyone to see snapshot content -archivebox config --set PUBLIC_INDEX=False # True = allow anyone to see list of all snapshots +# Docker Compose: +docker compose up +# Docker: +docker run -v $PWD:/data -it -p 8000:8000 archivebox/archivebox ``` + +##### Allow Public Access or Create an Admin User +```bash +archivebox manage createsuperuser # create a new admin username & pass +# OR # OR +archivebox config --set PUBLIC_ADD_VIEW=True # allow guests to submit URLs +archivebox config --set PUBLIC_SNAPSHOTS=True # allow guests to see snapshot content +archivebox config --set PUBLIC_INDEX=True # allow guests to see list of all snapshots + +# restart the server to apply any config changes +``` + *Docker hint:* Set the [`ADMIN_USERNAME` & `ADMIN_PASSWORD`)](https://github.com/ArchiveBox/ArchiveBox/wiki/Configuration#admin_username--admin_password) env variables to auto-create an admin user on first-run. #### 🗄  SQL/Python/Filesystem Usage From 4146c1d673a7003498e585bd5f079a6182fec08f Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 23 Jan 2024 18:22:36 -0800 Subject: [PATCH 3/8] Update README.md --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bd097c2d..aa7a92b8 100644 --- a/README.md +++ b/README.md @@ -426,16 +426,6 @@ cd ~/archivebox/data # IMPORTANT: cd into the directory # archivebox [subcommand] [--args] ``` -> [!TIP] -> Whether in Docker or not, ArchiveBox commands all work the same way, and can be used in tandem to access the same data directory. -> For example, you can run the web server in Docker Compose, and run one-off commands on the host at the same time with `pip`-installed ArchiveBox. - -```bash -# e.g. archivebox add --depth=1 'https://news.ycombinator.com' -# or docker compose run archivebox --depth=1 'https://news.ycombinator.com' -# or docker run -it -v $PWD:/data archivebox/archivebox add --depth=1 'https://news.ycombinator.com' -``` - #### Bare Metal Usage (`pip`/`apt`/`brew`/etc.) ```bash archivebox init --setup # safe to run init multiple times (also how you update versions) @@ -464,6 +454,18 @@ docker run -v $PWD:/data -it archivebox/archivebox version - `archivebox add/schedule/remove/update/list/shell/oneshot` to manage Snapshots in the archive - `archivebox schedule` to pull in fresh URLs regularly from [bookmarks/history/Pocket/Pinboard/RSS/etc.](#input-formats) +> [!TIP] +> Whether in Docker or not, ArchiveBox commands all work the same way, and can be used in tandem to access the same data directory. +> For example, you can run the Web UI in Docker Compose, and run one-off commands on host with `pip`-installed ArchiveBox or in Docker interchangeably. + +```bash +docker compose up -d # start the Web UI server in the background +docker compose run archivebox add 'https://example.com' # add a test URL to snapshot w/ Docker Compose + +archivebox list 'https://example.com' # fetch it with pip-installed archivebox on the host +docker compose run archivebox list 'https://example.com' # or w/ Docker Compose +docker run -it -v $PWD:/data archivebox/archivebox list 'https://example.com' # or w/ Docker, all equivalent +``` #### 🖥  Web UI Usage From 2cddb61877ff74dba93fb6234352adc57952eb1a Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 23 Jan 2024 18:27:48 -0800 Subject: [PATCH 4/8] Update README.md --- README.md | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index aa7a92b8..881ffa1a 100644 --- a/README.md +++ b/README.md @@ -426,26 +426,48 @@ cd ~/archivebox/data # IMPORTANT: cd into the directory # archivebox [subcommand] [--args] ``` -#### Bare Metal Usage (`pip`/`apt`/`brew`/etc.) -```bash +##### Bare Metal Usage (`pip`/`apt`/`brew`/etc.) + +
+
+Click to expand... +
+ +

 archivebox init --setup      # safe to run init multiple times (also how you update versions)
 archivebox version           # get archivebox version info and more
 archivebox add --depth=1 'https://news.ycombinator.com'
-```
+
+
+
##### Docker Compose Usage -```bash + +
+Click to expand... +
+ +

 # make sure you have `docker-compose.yml` from the Quickstart instructions first
 docker compose run archivebox init --setup
 docker compose run archivebox version
 docker compose run archivebox add --depth=1 'https://news.ycombinator.com'
-```
+
-#### Docker Usage -```bash +
+ +##### Docker Usage + +
+Click to expand... +
+ +

 docker run -v $PWD:/data -it archivebox/archivebox init --setup
 docker run -v $PWD:/data -it archivebox/archivebox version
-```
+
+ +
#### Next Steps @@ -458,14 +480,21 @@ docker run -v $PWD:/data -it archivebox/archivebox version > Whether in Docker or not, ArchiveBox commands all work the same way, and can be used in tandem to access the same data directory. > For example, you can run the Web UI in Docker Compose, and run one-off commands on host with `pip`-installed ArchiveBox or in Docker interchangeably. -```bash +
+
+Expand to show example... +
+ +

 docker compose up -d                                      # start the Web UI server in the background
 docker compose run archivebox add 'https://example.com'   # add a test URL to snapshot w/ Docker Compose
 
 archivebox list 'https://example.com'                     # fetch it with pip-installed archivebox on the host
 docker compose run archivebox list 'https://example.com'                       # or w/ Docker Compose
 docker run -it -v $PWD:/data archivebox/archivebox list 'https://example.com'  # or w/ Docker, all equivalent
-```
+
+ +
#### 🖥  Web UI Usage From e193e48afff19361e85bdcf28bbb2bb883485108 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 23 Jan 2024 18:29:41 -0800 Subject: [PATCH 5/8] Update README.md --- README.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 881ffa1a..78c1de1e 100644 --- a/README.md +++ b/README.md @@ -437,12 +437,13 @@ cd ~/archivebox/data # IMPORTANT: cd into the directory archivebox init --setup # safe to run init multiple times (also how you update versions) archivebox version # get archivebox version info and more archivebox add --depth=1 'https://news.ycombinator.com' - + ##### Docker Compose Usage +
Click to expand...
@@ -458,6 +459,7 @@ docker compose run archivebox add --depth=1 'https://news.ycombinator.com' ##### Docker Usage +
Click to expand...
@@ -479,22 +481,14 @@ docker run -v $PWD:/data -it archivebox/archivebox version > [!TIP] > Whether in Docker or not, ArchiveBox commands all work the same way, and can be used in tandem to access the same data directory. > For example, you can run the Web UI in Docker Compose, and run one-off commands on host with `pip`-installed ArchiveBox or in Docker interchangeably. - -
-
-Expand to show example... -
- -

+> 
Expand to show example...

 docker compose up -d                                      # start the Web UI server in the background
 docker compose run archivebox add 'https://example.com'   # add a test URL to snapshot w/ Docker Compose
 
 archivebox list 'https://example.com'                     # fetch it with pip-installed archivebox on the host
 docker compose run archivebox list 'https://example.com'                       # or w/ Docker Compose
 docker run -it -v $PWD:/data archivebox/archivebox list 'https://example.com'  # or w/ Docker, all equivalent
-
- -
+
#### 🖥  Web UI Usage From bddea22dac705b429bae6d4cfb375169231d4a57 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 23 Jan 2024 18:31:44 -0800 Subject: [PATCH 6/8] Update README.md --- README.md | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 78c1de1e..625ca8d5 100644 --- a/README.md +++ b/README.md @@ -426,6 +426,25 @@ cd ~/archivebox/data # IMPORTANT: cd into the directory # archivebox [subcommand] [--args] ``` +> [!TIP] +> Whether in Docker or not, ArchiveBox commands all work the same way, and can be used in tandem to access the same data directory. +> For example, you can run the Web UI in Docker Compose, and run one-off commands on host with `pip`-installed ArchiveBox or in Docker interchangeably. + +
+Expand to show examples...
+ +

+docker compose up -d                                      # start the Web UI server in the background
+docker compose run archivebox add 'https://example.com'   # add a test URL to snapshot w/ Docker Compose
+
+archivebox list 'https://example.com'                     # fetch it with pip-installed archivebox on the host
+docker compose run archivebox list 'https://example.com'                       # or w/ Docker Compose
+docker run -it -v $PWD:/data archivebox/archivebox list 'https://example.com'  # or w/ Docker, all equivalent
+
+ +
+
+ ##### Bare Metal Usage (`pip`/`apt`/`brew`/etc.)
@@ -440,6 +459,7 @@ archivebox add --depth=1 'https://news.ycombinator.com'
+
##### Docker Compose Usage @@ -456,6 +476,7 @@ docker compose run archivebox add --depth=1 'https://news.ycombinator.com'
+
##### Docker Usage @@ -470,6 +491,7 @@ docker run -v $PWD:/data -it archivebox/archivebox version +
#### Next Steps @@ -478,17 +500,6 @@ docker run -v $PWD:/data -it archivebox/archivebox version - `archivebox add/schedule/remove/update/list/shell/oneshot` to manage Snapshots in the archive - `archivebox schedule` to pull in fresh URLs regularly from [bookmarks/history/Pocket/Pinboard/RSS/etc.](#input-formats) -> [!TIP] -> Whether in Docker or not, ArchiveBox commands all work the same way, and can be used in tandem to access the same data directory. -> For example, you can run the Web UI in Docker Compose, and run one-off commands on host with `pip`-installed ArchiveBox or in Docker interchangeably. ->
Expand to show example...

-docker compose up -d                                      # start the Web UI server in the background
-docker compose run archivebox add 'https://example.com'   # add a test URL to snapshot w/ Docker Compose
-
-archivebox list 'https://example.com'                     # fetch it with pip-installed archivebox on the host
-docker compose run archivebox list 'https://example.com'                       # or w/ Docker Compose
-docker run -it -v $PWD:/data archivebox/archivebox list 'https://example.com'  # or w/ Docker, all equivalent
-
#### 🖥  Web UI Usage From 95580ee743b53c1e6770e6b6cce5dfddc81d71b9 Mon Sep 17 00:00:00 2001 From: Vladimir D Date: Wed, 24 Jan 2024 22:18:02 +0400 Subject: [PATCH 7/8] populate is_staff and is_superuser flags at LDAP authentication --- archivebox/config.py | 1 + archivebox/core/__init__.py | 2 ++ archivebox/core/apps.py | 5 +++++ archivebox/core/auth.py | 13 +++++++++++++ archivebox/core/auth_ldap.py | 11 +++++++++++ 5 files changed, 32 insertions(+) create mode 100644 archivebox/core/auth.py create mode 100644 archivebox/core/auth_ldap.py diff --git a/archivebox/config.py b/archivebox/config.py index c4a3aef6..4c7bed0c 100644 --- a/archivebox/config.py +++ b/archivebox/config.py @@ -112,6 +112,7 @@ CONFIG_SCHEMA: Dict[str, ConfigDefaultDict] = { 'LDAP_FIRSTNAME_ATTR': {'type': str, 'default': None}, 'LDAP_LASTNAME_ATTR': {'type': str, 'default': None}, 'LDAP_EMAIL_ATTR': {'type': str, 'default': None}, + 'LDAP_CREATE_SUPERUSER': {'type': bool, 'default': False}, }, 'ARCHIVE_METHOD_TOGGLES': { diff --git a/archivebox/core/__init__.py b/archivebox/core/__init__.py index 3e1d607a..9cd0ce16 100644 --- a/archivebox/core/__init__.py +++ b/archivebox/core/__init__.py @@ -1 +1,3 @@ __package__ = 'archivebox.core' + +default_app_config = 'archivebox.core.apps.CoreConfig' diff --git a/archivebox/core/apps.py b/archivebox/core/apps.py index b1150eb9..32088de4 100644 --- a/archivebox/core/apps.py +++ b/archivebox/core/apps.py @@ -5,3 +5,8 @@ class CoreConfig(AppConfig): name = 'core' # WIP: broken by Django 3.1.2 -> 4.0 migration default_auto_field = 'django.db.models.UUIDField' + + def ready(self): + from .auth import register_signals + + register_signals() diff --git a/archivebox/core/auth.py b/archivebox/core/auth.py new file mode 100644 index 00000000..fb15d5a8 --- /dev/null +++ b/archivebox/core/auth.py @@ -0,0 +1,13 @@ +import os +from django.conf import settings +from ..config import ( + LDAP +) + +def register_signals(): + + if LDAP: + import django_auth_ldap.backend + from .auth_ldap import create_user + + django_auth_ldap.backend.populate_user.connect(create_user) diff --git a/archivebox/core/auth_ldap.py b/archivebox/core/auth_ldap.py new file mode 100644 index 00000000..bd35d25e --- /dev/null +++ b/archivebox/core/auth_ldap.py @@ -0,0 +1,11 @@ +from django.conf import settings +from ..config import ( + LDAP_CREATE_SUPERUSER +) + +def create_user(sender, user=None, ldap_user=None, **kwargs): + + if not user.id and LDAP_CREATE_SUPERUSER: + user.is_superuser = True + + user.is_staff = True From e8772513ca502f0c57059967f60a944ab45c6ab7 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Wed, 24 Jan 2024 11:00:42 -0800 Subject: [PATCH 8/8] Update archivebox/core/auth_ldap.py add log line --- archivebox/core/auth_ldap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archivebox/core/auth_ldap.py b/archivebox/core/auth_ldap.py index bd35d25e..9057683c 100644 --- a/archivebox/core/auth_ldap.py +++ b/archivebox/core/auth_ldap.py @@ -9,3 +9,4 @@ def create_user(sender, user=None, ldap_user=None, **kwargs): user.is_superuser = True user.is_staff = True + print(f'[!] WARNING: Creating new user {user} based on LDAP user {ldap_user} (is_staff={user.is_staff}, is_superuser={user.is_superuser})')