Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ src/Http/routes.php the route contract (relative to the module group; `
src/Http/Controllers/ thin: request -> one service call -> JSON. Base Controller: respond()/fail()/ok()/presentRun()
src/Services/ Actor, Mounts, Rules, Files, Runs, Syncer, Transfer, Delivery, Serve, ServerConfig, AmountException
src/Queue/ Dispatcher, SystemQueue (CMS task queue), STaskQueue (sTask)
src/Console/ SyncHandler (task handler), TickCommand, ServerCommand, DriversCommand, DemoCommand
src/Console/ SyncHandler, DriverInstallHandler (task handlers), TickCommand, ServerCommand, DriversCommand, DemoCommand
src/Workers/SyncWorker sTask worker (file guarded: only loads when sTask exists)
src/Listeners/ NotFound (OnPageNotFound), Cleanup (OnManagerDeleteUser)
src/Drivers/ one class per Flysystem adapter; Drivers::all()
Expand All @@ -41,6 +41,15 @@ ci/ .github/ builds a full CMS with the plugin inside (Docker),
first, and only then asks whether the path exists.
- **A stranger's personal mount is "not found", never "forbidden"** (and not even an administrator opens it);
`Mounts::find()` enforces it, controllers must always go through it.
- **Storage drivers are optional packages**: `require` holds only `league/flysystem` and
`league/flysystem-local`; every other driver's package is in `suggest`, with its minimum version
in `conflict` (SFTP `<3.36` would break host-key pinning). Builds (tests, demo, zip, images)
add `PLUGIN_EXTRAS` from `ci/plugin.env`, so tests may use the S3/SFTP/WebDAV classes; code may
not assume them outside their driver (`Driver::available()`). `PackagesTest` keeps this in sync.
- **Installing a driver** (DESIGN rule 11): `amount:drivers --install=<ids>` from a shell; from the page, only an
administrator, through the CMS task queue (`DriverInstaller` queues `amount.driver_install` via the core's
`createTaskFromStoreRequest()`, `DriverInstallHandler` delegates to `ConsoleInstallFlowService`). Never run Composer
in a request, and never take a package name from a request: packages come from `Driver::packages()`.
- **Where a mount connects** (DESIGN rule 10): `Driver::filesystem()` is fail-closed - without
`_trusted` (set by `Mount::filesystem()` from `Mount::trusted()`) local/zip refuse and every
`destinations()` entry must resolve public. A driver gaining a host/URL field must list it in
Expand Down Expand Up @@ -90,8 +99,8 @@ ci/ .github/ builds a full CMS with the plugin inside (Docker),

`{ok:true, ...}` or `{ok:false, error, message[, errors, candidates]}` with the refusal's HTTP status
(403 forbidden, 404 not found, 409 ambiguous/refused, 422 invalid with `errors` field => message, 502 store failure).
`GET /bootstrap` returns `drivers, mounts, foreign_mounts, rules, presets, runs, queue, server (administrators only, else
null), flags{may_manage,is_admin,use_udperms,serve_enabled}, user_id, groups (administrators only), limits, csrf_token`.
`GET /bootstrap` returns `drivers, driver_installs (unfinished installs by driver id, administrators only), mounts, foreign_mounts, rules, presets, runs, queue, server (administrators only, else
null), flags{may_manage,is_admin,may_install_drivers,use_udperms,serve_enabled}, user_id, groups (administrators only), limits, csrf_token`.
Runs are presented by `Controller::presentRun()`.

## Tests
Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,25 @@ php artisan package:installrequire elcreator/amount "*"
php artisan migrate
```

The module appears in the manager menu as **aMount**. Run `php artisan amount:drivers` to see which drivers are
installed; install a missing one with the command it prints. `php artisan amount:demo --run` seeds a demo on a local
The module appears in the manager menu as **aMount**. Only the local folder driver comes with it; every storage
driver is an optional package, so a site carries just the ones it uses (the AWS SDK alone is about 77 MB). Run
`php artisan amount:drivers` to see which drivers are installed, and install missing ones by id, e.g. S3, SFTP and
WebDAV (each package goes through the CMS's `package:installrequire`, which undoes a failed install):

```sh
php artisan amount:drivers --install=s3,sftp,webdav
```

Administrators can also click **Install** next to a missing driver in the manager. The page doesn't run Composer
itself: it queues a task for the CMS task worker (the same queue the Extras module installs through) and shows its
progress. That needs a running `system:task-worker` (the CMS cron line starts it) and a `core/vendor` directory the
worker can write to. Other managers see the command to pass on.

> **Upgrading from a version that required S3, SFTP and WebDAV:** `composer update` removes those packages if nothing
> else needs them, and mounts using them then report the install command instead of connecting. Install the drivers
> you use as above before or after updating.

The ready-made zip and Docker images include the S3, SFTP and WebDAV drivers. `php artisan amount:demo --run` seeds a demo on a local
disk (no account needed).

## Permissions
Expand Down Expand Up @@ -148,6 +165,8 @@ access, and **this site's code**.
S3 endpoint, FTP/SFTP host or computer gateway only when it resolves to public addresses; the address that was checked
is the one connected to, and WebDAV redirects are not followed. This is checked when the mount is saved or tested and
again on every connection, for whoever last changed its connection settings. Mounts from configuration are trusted.
- **Only an administrator can install a driver from the manager**, since that changes the site's code. Composer runs in
the CMS task worker, never in a web request, and only for the packages the chosen driver lists.
- **SFTP needs a pinned host key** (`ssh-keyscan HOST | ssh-keygen -lf -` prints it as `SHA256:...`); a connection to
a server presenting another key is refused. Several keys may be pinned, so a key can be rotated without downtime.
- **Downloads back are cautious.** The destination must be a folder the user can write to; nothing is overwritten unless
Expand Down
8 changes: 6 additions & 2 deletions ci/compose-evo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ step "core/custom/composer.json"
# CMS plus this one plugin; a package that happened to be installed in the
# core this was built from has no business travelling into a published image.
custom="$target/core/custom/composer.json"
PLUGIN_PACKAGE="$PLUGIN_PACKAGE" PLUGIN_SLUG="$PLUGIN_SLUG" php "$here/lib/write-custom-composer.php" "$custom"
PLUGIN_PACKAGE="$PLUGIN_PACKAGE" PLUGIN_SLUG="$PLUGIN_SLUG" PLUGIN_EXTRAS="${PLUGIN_EXTRAS:-}" \
php "$here/lib/write-custom-composer.php" "$custom"
cat "$custom"

step "composer update $PLUGIN_PACKAGE (partial)"
Expand All @@ -200,7 +201,10 @@ step "composer update $PLUGIN_PACKAGE (partial)"
# being maintained and wrong for a build that has to be reproducible.
lock_before=$(mktemp)
cp "$target/core/composer.lock" "$lock_before"
( cd "$target/core" && composer update "${composer_args[@]}" --with-dependencies "$PLUGIN_PACKAGE" )
# The optional packages from plugin.env (PLUGIN_EXTRAS) are named too, so they
# may be installed; word splitting is intended.
# shellcheck disable=SC2086
( cd "$target/core" && composer update "${composer_args[@]}" --with-dependencies "$PLUGIN_PACKAGE" ${PLUGIN_EXTRAS:-} )

step "What the plugin changed in core/composer.lock"
php "$here/lib/lock-delta.php" "$lock_before" "$target/core/composer.lock"
Expand Down
8 changes: 6 additions & 2 deletions ci/lib/write-custom-composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
* else they had installed there is exactly what must not travel into a
* published zip or image.
*
* Usage: PLUGIN_PACKAGE=... PLUGIN_SLUG=... php write-custom-composer.php <path>
* PLUGIN_EXTRAS (optional, space-separated package names) are required at
* any version: the plugin's own "conflict" section sets their minimums.
*
* Usage: PLUGIN_PACKAGE=... PLUGIN_SLUG=... [PLUGIN_EXTRAS=...] php write-custom-composer.php <path>
*/

$custom = $argv[1] ?? '';
$package = getenv('PLUGIN_PACKAGE') ?: '';
$slug = getenv('PLUGIN_SLUG') ?: '';
$extras = preg_split('/\s+/', trim((string) getenv('PLUGIN_EXTRAS')), -1, PREG_SPLIT_NO_EMPTY) ?: [];

if ($custom === '' || $package === '' || $slug === '') {
fwrite(STDERR, "usage: PLUGIN_PACKAGE=... PLUGIN_SLUG=... php write-custom-composer.php <path>\n");
Expand All @@ -44,7 +48,7 @@
'options' => ['symlink' => false],
],
],
'require' => [$package => '@dev'],
'require' => [$package => '@dev'] + array_fill_keys($extras, '*'),
'autoload' => ['psr-4' => ['EvolutionCMS\\Custom\\' => 'src/']],
];

Expand Down
7 changes: 7 additions & 0 deletions ci/plugin.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ PLUGIN_PROVIDER='Elcreator\aMount\aMountServiceProvider'
# Directory name under core/custom/packages/, and the local docker image name.
PLUGIN_SLUG='amount'

# Optional (composer "suggest") packages the builds install next to the plugin,
# space-separated, at any version the plugin's "conflict" allows. The unit
# suite, the demo and the published zip/images then carry these drivers, while
# a site installing the plugin from packagist adds only the ones it uses.
# PLUGIN_EXTRAS= (set but empty) builds the bare plugin.
PLUGIN_EXTRAS="${PLUGIN_EXTRAS-league/flysystem-aws-s3-v3 league/flysystem-sftp-v3 league/flysystem-webdav}"

# The CMS this plugin is built into.
EVO_REPO="${EVO_REPO:-https://github.com/evolution-cms/evolution}"
EVO_REF="${EVO_REF:-3.5.x}"
Expand Down
8 changes: 8 additions & 0 deletions ci/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ fail() { echo "smoke.sh: $*" >&2; exit 1; }
step "Package is installed"
[ -d "$evo_dir/core/vendor/$PLUGIN_PACKAGE" ] || fail "$PLUGIN_PACKAGE missing from core/vendor"

if [ -n "${PLUGIN_EXTRAS:-}" ]; then
step "Optional packages are installed"
for extra in $PLUGIN_EXTRAS; do
[ -d "$evo_dir/core/vendor/$extra" ] || fail "$extra (PLUGIN_EXTRAS) missing from core/vendor"
echo "ok $extra"
done
fi

step "Service provider is discovered"
# `artisan package:discover` runs on every composer dump-autoload and drops one
# file per discovered provider into core/custom/config/app/providers/. That
Expand Down
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"php": "^8.3",
"evolution-cms/evolution": "^3.5.2",
"league/flysystem": "^3.10",
"league/flysystem-aws-s3-v3": "^3.10",
"league/flysystem-sftp-v3": "^3.36",
"league/flysystem-webdav": "^3.6"
"league/flysystem-local": "^3.10"
},
"require-dev": {
"pestphp/pest": "^4.0"
},
"suggest": {
"league/flysystem-aws-s3-v3": "Amazon S3 and S3-compatible driver (MinIO, Cloudflare R2, Backblaze B2, Wasabi, DigitalOcean Spaces ...)",
"league/flysystem-sftp-v3": "SFTP / SSH driver",
"league/flysystem-webdav": "WebDAV driver (Nextcloud, ownCloud, Synology ...)",
"league/flysystem-ftp": "FTP/FTPS driver (needs ext-ftp, which many PHP builds omit, so it is not a hard requirement)",
"league/flysystem-async-aws-s3": "AsyncAws S3 driver (lighter alternative to the AWS SDK)",
"league/flysystem-google-cloud-storage": "Google Cloud Storage driver",
Expand All @@ -31,6 +32,11 @@
"overtrue/flysystem-qiniu": "Qiniu Kodo driver",
"seiger/stask": "Alternative queue manager: aMount runs its uploads as an sTask worker when it is installed"
},
"conflict": {
"league/flysystem-aws-s3-v3": "<3.10",
"league/flysystem-sftp-v3": "<3.36",
"league/flysystem-webdav": "<3.6"
},
"autoload": {
"psr-4": {
"Elcreator\\aMount\\": "src/"
Expand Down
7 changes: 6 additions & 1 deletion docs/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ is gone); **private** ones are downloadable only by managers who may see the ori
(else owner, else creator) being an administrator *now*. Untrusted connections use the checked address
(`_pinned`: cURL `RESOLVE` for WebDAV/S3, the address itself for FTP/SFTP) and WebDAV follows no redirect.
SFTP refuses to connect without a pinned host key (`host_fingerprint`, several allowed for rotation).
11. Composer never runs in a web request. A missing driver is installed from the manager only by an administrator,
as an `amount.driver_install` system task (`Services\DriverInstaller`, `Console\DriverInstallHandler`): exclusive,
`system_tasks.manage_packages` + super administrator, queued through the core's
`SystemTaskService::createTaskFromStoreRequest()` (its lock and scheduler checks) and run by `system:task-worker`
with the core's `ConsoleInstallFlowService`. Requests name a driver; the packages always come from the driver.

## Already written (do not rewrite; extend only if a contract below says so)

Expand Down Expand Up @@ -207,7 +212,7 @@ heartbeat for too long is healed to `error`, the page polls).
Private files (backups) are never served by the web server; they are denied by the existing rules and downloaded through the
authenticated manager endpoint.
- `Console\ServerCommand` (`amount:server {server?} {--write} {--probe}`), `Console\DriversCommand` (`amount:drivers`: table of
drivers, installed or not, with install command), `Console\DemoCommand` (`amount:demo`: seeds a local-driver demo mount "Demo cloud",
drivers, installed or not, with install command; `--install=<ids>` runs `package:installrequire` once per missing package), `Console\DemoCommand` (`amount:demo`: seeds a local-driver demo mount "Demo cloud",
sample files under `assets/amount-demo/`, one public rule, one backup-like private rule, optionally runs them synchronously
for demo purposes — must be idempotent).
- `Listeners\Cleanup` — remove a deleted user's personal mounts/rules/index rows; remove a deleted user group from
Expand Down
11 changes: 11 additions & 0 deletions lang/az/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
'error_ambiguous_mount' => 'Bir neçə qoşulma uyğun gəlir: :names. Hansını nəzərdə tutursunuz?',
'error_driver_unknown' => 'Bu saxlama növü tanınmır.',
'error_driver_unavailable' => ':driver əlavə paket tələb edir. Onu bu əmrlə quraşdırın: :command',
'error_driver_installed' => ':driver artıq quraşdırılıb.',
'error_driver_not_installable' => ':driver paketlərinə malikdir, lakin yenə də işə düşə bilmir; çox güman ki, PHP genişlənməsi tələb edir. Serveri idarə edən şəxsə müraciət edin.',
'error_driver_install_unavailable' => 'Bu Evolution CMS menecerdən paket quraşdıra bilmir. Onu bu əmrlə quraşdırın: :command',
'error_driver_install_refused' => 'CMS quraşdırmanı növbəyə qoymadı: :reason',
'error_driver_admin_only' => ':driver bu serverin öz diskinə çıxış əldə edir, ona görə də onu yalnız administrator qura bilər.',
'error_destination_private' => ':host bu serverdə və ya daxili şəbəkədədir. Ora qoşulmanı yalnız administrator yarada bilər.',
'error_destination_unresolved' => ':host tapılmadı. Ünvanı yoxlayın.',
Expand Down Expand Up @@ -292,6 +296,13 @@
'ui_driver_choose' => 'Seç: :name',
'ui_driver_choose_short' => 'Seç',
'ui_driver_missing' => 'Əlavə paket tələb edir (:packages). Onu bu əmrlə quraşdırın:',
'ui_driver_install' => 'Quraşdır',
'ui_driver_install_aria' => 'Quraşdır: :name',
'ui_driver_install_help' => 'CMS tapşırıq işçisi onu arxa planda Composer ilə quraşdırır və uğursuz olarsa, hər şeyi geri qaytarır.',
'ui_driver_install_queued' => 'CMS tapşırıq işçisi gözlənilir...',
'ui_driver_installing' => 'Quraşdırılır (:progress%): :message',
'ui_driver_installed' => ':name quraşdırıldı.',
'ui_driver_install_failed' => 'Quraşdırma uğursuz oldu: :message',
'ui_group_object' => 'Obyekt saxlama yerləri',
'ui_group_cloud' => 'Bulud diskləri',
'ui_group_server' => 'Serverlər',
Expand Down
11 changes: 11 additions & 0 deletions lang/be/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
'error_ambiguous_mount' => 'Адпавядае некалькі падключэнняў: :names. Якое вы маеце на ўвазе?',
'error_driver_unknown' => 'Гэты тып сховішча невядомы.',
'error_driver_unavailable' => ':driver патрабуе дадатковы пакет. Усталюйце яго камандай: :command',
'error_driver_installed' => ':driver ужо ўсталяваны.',
'error_driver_not_installable' => 'У :driver ёсць пакеты, але ён усё роўна не можа запусціцца; верагодна, яму патрэбна пашырэнне PHP. Звярніцеся да таго, хто абслугоўвае сервер.',
'error_driver_install_unavailable' => 'Гэты Evolution CMS не можа ўсталёўваць пакеты з менеджара. Усталюйце яго камандай: :command',
'error_driver_install_refused' => 'CMS не паставіла ўсталяванне ў чаргу: :reason',
'error_driver_admin_only' => ':driver звяртаецца да ўласнага дыска гэтага сервера, таму наладзіць яго можа толькі адміністратар.',
'error_destination_private' => ':host знаходзіцца на гэтым серверы або ва ўнутранай сетцы. Падключэнне туды можа стварыць толькі адміністратар.',
'error_destination_unresolved' => 'Не ўдалося знайсці :host. Праверце адрас.',
Expand Down Expand Up @@ -292,6 +296,13 @@
'ui_driver_choose' => 'Выбраць: :name',
'ui_driver_choose_short' => 'Выбраць',
'ui_driver_missing' => 'Патрабуе дадатковы пакет (:packages). Усталюйце яго камандай:',
'ui_driver_install' => 'Усталяваць',
'ui_driver_install_aria' => 'Усталяваць: :name',
'ui_driver_install_help' => 'Выканаўца задач CMS усталёўвае яго праз Composer у фоне і адмяняе ўсе змены, калі нешта пойдзе не так.',
'ui_driver_install_queued' => 'Чакае выканаўцу задач CMS...',
'ui_driver_installing' => 'Усталяванне (:progress%): :message',
'ui_driver_installed' => ':name усталяваны.',
'ui_driver_install_failed' => 'Усталяванне не ўдалося: :message',
'ui_group_object' => 'Аб’ектныя сховішчы',
'ui_group_cloud' => 'Воблачныя дыскі',
'ui_group_server' => 'Серверы',
Expand Down
Loading
Loading