Commit Graph

75 Commits

Author SHA1 Message Date
Johannes Zellner 918c2f8587 Move to @cloudron/safetydance 2026-04-01 09:49:34 +02:00
Girish Ramakrishnan f12b4faf34 lint 2026-03-12 23:23:23 +05:30
Girish Ramakrishnan 01d0c738bc replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever
we want by flipping a flag and restarting box
2026-03-12 23:08:35 +05:30
Girish Ramakrishnan e9f96593c3 reorder functions for no-use-before-define 2026-02-14 16:34:34 +01:00
Girish Ramakrishnan 36aa641cb9 migrate to "export default"
also, set no-use-before-define in linter
2026-02-14 15:43:24 +01:00
Girish Ramakrishnan 96dc79cfe6 Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
  (dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
  declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
  loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing

Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 15:11:45 +01:00
Girish Ramakrishnan 162e51a0af restore: fix crash when trying to mount fs volumes 2025-12-04 00:14:37 +01:00
Girish Ramakrishnan 43e426ab9f Revert "Add no-use-before-define linter rule"
This reverts commit fdcc5d68a2.

Unfortunately, this requires us to move exports to the bottom.
This in turn causes circular dep issues and also access of
exports.GLOBAL_VAR in the global context
2025-10-08 21:17:52 +02:00
Girish Ramakrishnan b790d085bb volumes: remove usage of secret placeholder 2025-10-08 18:05:30 +02:00
Girish Ramakrishnan 5dd5a20fc1 code -> sqlCode 2025-09-29 12:18:26 +02:00
Girish Ramakrishnan f92cdf36f5 system: return the mounted and unmounted block devices (as long as xfs or ext4) 2025-09-23 18:51:23 +02:00
Johannes Zellner f779957145 Pass only hostPath as string to mounts.remount() 2025-08-18 14:19:55 +02:00
Girish Ramakrishnan 12e073e8cf use node: prefix for requires
mostly because code is being autogenerated by all the AI stuff using
this prefix. it's also used in the stack trace.
2025-08-14 12:55:35 +05:30
Johannes Zellner 0ff760fe4a Ensure we pass mount object also from volumes code 2025-08-04 14:40:35 +02:00
Girish Ramakrishnan 9dfe6242b9 mounts: rename name to description
this makes it clear that the field is not important
2025-08-01 15:48:11 +02:00
Girish Ramakrishnan cbc73f5c9a remove uuid module
built into node.js now
2025-07-28 12:54:09 +02:00
Johannes Zellner a7bba61b6a Better error message if hostPath is already used in a volume 2025-07-14 16:15:01 +02:00
Johannes Zellner d86045c64e Try to consolidate volumes eventlogs 2025-07-02 18:25:14 +02:00
Girish Ramakrishnan 88b9eed559 mount: use enums for mount types 2025-01-12 17:43:55 +01:00
Girish Ramakrishnan 1e2ca7b835 volumes: test host path validation 2025-01-02 11:46:11 +01:00
Girish Ramakrishnan f7ea847336 do not modify hostPath variable 2025-01-02 11:22:09 +01:00
Girish Ramakrishnan 9d890e1c21 security: fix issue where '/' symlink allows admins to get ssh access
* create a volume
* create symlink to /
* now, create another volume with that symlink as host directory
2025-01-02 11:18:39 +01:00
Girish Ramakrishnan 21705a0e96 volumes: /mnt/volumes is reserved 2024-08-08 14:45:50 +02:00
Girish Ramakrishnan 2f3fba346f volumes: throw error for unsupported update 2023-10-09 10:31:31 +05:30
Girish Ramakrishnan 64381e2a04 backups: remove validation mount point after testing it
this also moves out the attempt validation logic from mounts code
into volumes. mounts.tryAddMount is also used in backup code
2023-09-29 08:01:58 +05:30
Johannes Zellner 328c61b67f Show volume edit options for network mounts 2023-09-20 20:24:19 +02:00
Johannes Zellner 981d76ef7f Add rest api to update volume mount options 2023-09-20 16:28:47 +02:00
Girish Ramakrishnan 03a77ddf01 Fix validation of hostPath
When adding a volume, this comes in mountOptions. The hostPath in the
database is the computed host path.
2023-02-25 23:41:11 +01:00
Girish Ramakrishnan 3caffdb4e1 Rework app stats
Previously, the du plugin was collecting data every 20 seconds but
carbon was configured to only keep data every 12 hours causing much
confusion.

In the process of reworking this, it was determined:

* No need to collect disk usage info over time. Not sure how that is useful
* Instead, collect CPU/Network/Block info over time. We get this now from docker stats
* We also collect info about the services (addon containers)
* No need to reconfigure collectd for each app change anymore since there is no per
app collectd configuration anymore.
2022-10-10 21:13:26 +02:00
Girish Ramakrishnan a3e097d541 add missing awaits for eventlog.add 2022-02-24 20:04:46 -08:00
Girish Ramakrishnan 964c1a5f5a remove field from errors
we have standardized on indexOf in error.message by now
2022-02-07 13:44:29 -08:00
Girish Ramakrishnan 8b9d821905 isMountProvider -> isManagedProvider 2022-01-26 12:40:28 -08:00
Girish Ramakrishnan ca252e80d6 Fix usage of await 2021-10-11 10:29:46 -07:00
Johannes Zellner 9eed3af8b6 add volume remount 2021-10-11 16:22:56 +02:00
Girish Ramakrishnan 3bcd32c56d restore: mount all volumes before restoring apps
fixes #786
2021-09-28 11:51:01 -07:00
Girish Ramakrishnan d90beb18d4 eventlog: add service rebuild/restart/configure events 2021-09-24 10:22:45 -07:00
Girish Ramakrishnan c5794b5ecd get rid of all the NOOP_CALLBACKs 2021-09-17 09:40:26 -07:00
Girish Ramakrishnan 167eae5b81 Use safe instead of try/catch 2021-09-01 15:37:04 -07:00
Girish Ramakrishnan 411cc7daa1 merge settingsdb into settings code 2021-08-19 17:45:40 -07:00
Girish Ramakrishnan bad6e39d59 volume: add filesystem type for shared folders
rename noop to mountpoint
2021-06-25 10:12:28 -07:00
Girish Ramakrishnan 1ce4875db1 volumes: set hostPath based on volume id
this is required for the file browser to work which does operations
based on the id

fixes #789
2021-06-24 17:32:41 -07:00
Girish Ramakrishnan 097a7d6b60 sftp: rework appdata and volume mounting logic
this tries to solve two issues:

* the current approach mounts the data directories of apps/volumes individually.
this causes a problem with volume mounts that mount after the container is started i.e not
network time/delay but systemd ordering. With CIFS, the mount is a hostname. This requires
unbound to be running but unbound can only start after docker because it wants to bind to
the docker network. one way to fix is to not start sftp automatically and only start sftp
container in the box code. This results in the sftp container attaching itself of the
directory before mounting and it appears empty. (on the host, the directory will appear
to have mount data!)

* every time apptask runs we keep rebuilding this sftp container. this results in much race.

the fix is: mount the parent directory of apps and volumes. in addition, then any specialized appdata
paths and volume paths are mounted individually. this greatly minimized rebuilding and also since we don't rely
on binding to the mount point itself. the child directories can mount in leisure. this limits the race
issue to only no-op volume mounts.

part of #789
2021-06-24 16:51:58 -07:00
Girish Ramakrishnan 3ba2f96d51 volume: remove private fields 2021-06-21 16:35:08 -07:00
Girish Ramakrishnan 6ace8d1ac5 volumes: fix various mount related issues
Various notes on mounting:

* The permissions come from the mounted file system and not the mount point.
This means that if we change the perms before mounting, it is overridden by
whatever is in the actual file system.

* uid/gid only works for permission-less file systems

SFTP container notes:

* Assumes that nothing changed if the host path hasn't changed. This means that
if a user changes the disk uuid, reload doesn't work.

* Not sure how/why, but even after unmounting the container can still access the old
mount files (!). With ext4 on disk change or nfs after root path change, the file manager
continues to be able to access the old mounts (despite umount succeeding).

All this led to following changes:

* Remove editing of volumes. Just allow editing username/password.
* edit UI then just also provides a way to re-mount.
* Change mode of mountpoint to be 777 post mounting for ease of use. Otherwise, we have to
make the user do this by ssh. this can always become options later.
2021-06-21 16:11:48 -07:00
Girish Ramakrishnan f433146484 volumes: reload sftp on update
when diskPath changes, docker is busy holding on to the previous mount!
I guess this is because this is all somehow inode based.
2021-06-21 11:53:27 -07:00
Girish Ramakrishnan c23b935cea volumes: hostPath -> mount point 2021-06-18 23:31:11 -07:00
Girish Ramakrishnan 0a5a24ba2e add tryAddMount
we try to add a mount. if it fails, it will revert to the previous mount config.

there was a plan to make this work based on systemd-mount but we hit this bug - https://bugzilla.redhat.com/show_bug.cgi?id=1708996
2021-05-21 22:32:51 -07:00
Girish Ramakrishnan 59db625ad9 volumes: wait for mount during add/update
this is a better feedback mechanism for the user
2021-05-19 11:08:33 -07:00
Girish Ramakrishnan c7474511aa fix volume test 2021-05-17 16:23:37 -07:00
Girish Ramakrishnan aae40f506b backups: add mounting config 2021-05-14 15:27:07 -07:00