90 Commits

Author SHA1 Message Date
Eric Callahan
0ff1d79b5b server: improve add_warning method
Add an exc_info parameter that optionally takes an
exception that is passed to the logging function. This
will log the traceback without an additional logging call.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-07-24 07:37:08 -04:00
Moggie
4d6037c3d3 module: file_manager
Allow default metadata parser timeout to be configurable

Signed-off-by: Paul Morgan moggieuk@hotmail.com
2024-06-23 05:31:18 -04:00
Eric Callahan
3f62bb6fb4 database: add backup, restore, and compact endpoints
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-21 06:18:46 -04:00
Eric Callahan
0b1fce8a6d file_manager: minor type checking fixes
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-21 06:18:46 -04:00
Eric Callahan
bb0266f5c4 app: replace dict with UserInfo throughout Moonraker
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-21 06:18:46 -04:00
Eric Callahan
531028ef4f history: report user in job history
When possible record the name of the user that requested the
job.  The klippy_api's component now takes an optional user
argument in its "start_print" method.  This user is broadcast
in an event after a print request successfully returns.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-04 08:16:37 -04:00
Eric Callahan
9447494bd5
file_manager: static type checking fixes 2024-04-19 11:28:01 -04:00
Eric Callahan
4b9973826e
file_manager: add "enable_config_write_access" option
Some installations, such as those in public areas, may wish disallow
changes to the configuration.

This option defaults to True, so no change in behavior is introduced.

Signed-off-by:  Eric  Callahan <arksine.code@gmail.com>
2024-01-28 05:55:29 -05:00
Eric Callahan
69f527b7c7
secrets: remove dependency on file_manager
It is desirable to use templates (and therefore secrets) in
the server's configuration options.  We need to defer loading
the "file_manager", remove its dependency from secrets.  When
the file_manager is loaded it will look up "secrets" and register
the file path as reserved.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-01-15 06:03:43 -05:00
Eric Callahan
ddd735feba
refactor: convert klippy_connection into a component
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-01-13 15:15:15 -05:00
Eric Callahan
b18e9cc222
all: Replace strings with RequestType flags
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:20 -05:00
Eric Callahan
3b53d9532d
file_manager: add option to opt out of klipper check
Some installations do not have Klipper's configuration
in the data path's "config" folder.  Provide a way to
opt out of this check.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 15:25:38 -05:00
Eric Callahan
6d8cb762ff
file_manager: relax registration requirements
Use EAFP techniques to test for directory read permission
during registration.  If access fails continue with registration.
This allows users to potentially fix an issue without restarting.
Inotify failures always require a restart to resolve.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-15 10:53:09 -05:00
Eric Callahan
6f6f535d6a
file_manager: fix linter errors
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-10-07 10:36:16 -04:00
Eric Callahan
f99e5b0bea
utils: add support for msgspec with stdlib json fallback
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
2023-10-06 18:20:28 -04:00
Eric Callahan
0c6b4e0dad
file_manager: fix reserved path handling during runtime
If the user creates or moves a folder that was is reserved
reserved correctly ignore or remove watches as appropriate.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-10-05 07:59:23 -04:00
Eric Callahan
c3c3170451
file_manager: log metadata response in real time
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-07-09 11:31:19 -04:00
Eric Callahan
d6231634db
history: add modified time check for file existence
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-06-01 05:50:31 -04:00
Eric Callahan
2d70511474
file_manager: use get_list WebRequest method
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-24 10:26:15 -05:00
Eric Callahan
6d73c60a38
moonraker: move common classes to common.py
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-24 07:08:41 -05:00
Eric Callahan
fce056e481
file_manager: fix notification sync on fast machines
Desktop class PCs may exit the request before the inotify observer
gains control of the loop.  When the observer does gain control
it will immediately notify as the sync mutex is no longer held,
this can result in sending  the websocket notification before
the response has returned.  Delay all notifications by 5ms to prevent
this.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-22 18:08:51 -05:00
Eric Callahan
79467e6484
utils: add source_info utility module
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-22 18:08:48 -05:00
Eric Callahan
0f8638fec7
components: correct imports
All imports must now be relative to work correctly with the
moonraker parent package.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-22 12:16:27 -05:00
Eric Callahan
dce3b9eaf5
file_manager: add metadata scan endpoint
Support manual scan requests for systems where inotify
does not function correctlly (network shares).  This endpoint
may also be used to force a rescan of files that have already
had an initial scan.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-21 12:10:56 -05:00
Eric Callahan
9178b3833c
file_manager: improve observer log message
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-21 07:33:45 -05:00
Eric Callahan
7845390dd1
file_manager: support uploading to symlinks
Previously Moonraker disabled writing to symbolic links, as
doing so would overwrite the link.  Moonraker now resolves
the link, overwrites the file, and manually emits a websocket
notification.

Signed-off-by: Eric Callahan <arksine.code@gmail.com>
2023-02-20 20:42:19 -05:00
Eric Callahan
0f7b781f57
file_manager: process metadata changes when no observer is configured
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-20 19:49:48 -05:00
Eric Callahan
347c9f4d2b
file_manager: improve duplicate notifcation detection
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-20 19:36:58 -05:00
Eric Callahan
2fd668bf0d
file_manager: implement configurable fs observer
Currently the choices are "none" and "inotify".

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-20 19:36:58 -05:00
Eric Callahan
1e97571aa8
file_manager: refactor attribute names
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-20 19:36:57 -05:00
Eric Callahan
7330c2c123
file_manager: add request notifcation fallback
Schedule fallback websocket notifications in the event that
inotify is unable to watch a file system.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-20 19:36:57 -05:00
Eric Callahan
51e307dbd6
file_manager: don't queue "create from move" events
Treat these events as if they were actual file write events.  They
will reset the node completion time and suppress the notifcation.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-20 19:36:56 -05:00
Eric Callahan
0a811b9e44
file_manager: cleanup coroutines on close
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-17 16:40:31 -05:00
Eric Callahan
7dac9c3961
file_manager: queue move event notifications
It is possible for a move event to occur shortly after a directory
is created.  These events are not bundled as part of an operation
like "copy", so they should not be suppressed, however the
notification should be emitted after the "create_dir" from its
parent is emitted.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-17 12:29:10 -05:00
Eric Callahan
d39792b84e
file_manager: allow concurrent inotify processing
All of the awaitable calls in the inotify loop only block to
postpone notifications.  Only gcode notifications require async
processing due to metadata analysis.  Queue these notifications
while allowing inotify events to be received concurrently.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>

fix
2023-02-17 08:24:55 -05:00
Eric Callahan
9f08aad6f6
file_manager: improve notification sync
Most requests do not require waiting for inotify to process the
file event before exiting.  Rework the NotifySyncLock to make this
optional.  Replace the write mutex with the sync lock itself,
a guarantee that the synchronization state is cleaned up when
a request is complete.

This implementation avoids potential deadlocks or long wait times
when inotify is not enabled on a file system.

Signed-off-by: Eric Callahan <arksine.code@gmail.com>
2023-02-16 19:37:34 -05:00
Eric Callahan
a40dae2bc8
file_manager: improve klipper config detection
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-13 15:33:04 -05:00
Eric Callahan
fb618a46fd
file_manager: fix thumbnails endpoint registration
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-01-31 14:00:33 -05:00
Eric Callahan
55e852cd87
file_manager: add thumbnail request endpoint
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-01-31 06:13:44 -05:00
Eric Callahan
a4b496d135
file_manager: fix internal access check
Include the reserved file check in the `can_access_path()` method.  This
fixes a potential vulnerability in the notifier where it may be possible
to attach a reserved file to a notification.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-01-08 13:50:08 -05:00
Eric Callahan
fe9a9899e3
file_manager: reserved path fix
Raise an exception if an attempt is made to access .git folders.

Signed-off-by:  Eric Callahan <arksine.cde@gmail.com>
2023-01-08 13:50:08 -05:00
Eric Callahan
6021b39234
file_manager: implement zip endpoint
Provides an API for front ends to archive a list of files and/or
folders into a single zipped file.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-01-08 13:49:32 -05:00
Eric Callahan
ecf7fb9267
klippy_connection: add is_printing() and is_ready() methods
Several components throughout Moonraker determine whether or not
Klipper is printing or is ready before taking action.  This centralizes
queries in one area.  The checks do not query Klipper directly but
rather rely on subscriptions to push state to Moonraker.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-01-06 12:20:52 -05:00
Eric Callahan
f3e13faf19
file_manager: validate Klipper config path
Warn when Klipper's configuration file is not located in
the "config" subfolder of the datapath.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-11-26 19:30:59 -05:00
Eric Callahan
a8018afd46
file_manager: always deny access to .git folders
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-11-06 10:51:32 -05:00
Eric Callahan
d490796da9
file_manager: fix permission reporting
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-11-06 10:51:32 -05:00
Eric Callahan
b291d94596
file_manager: implement additional reserved path filters
Do not add inotify watches for reserved paths that exclude
write acccess.  Do not return include reserved paths in
file list requests without read access.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-11-06 10:51:31 -05:00
Eric Callahan
e8dad1c8c0
file_manager: add list roots endpoint
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-11-06 10:51:30 -05:00
Misterke
130c2a48f0 file_manager: disallow drilling down protected folders
Signed-off-by:  Kurt Haenen <kurt.haenen@gmail.com>
2022-11-05 10:45:46 -04:00
Eric Callahan
a8cbfe6345
file_manager: improve gcode path warning
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
2022-10-18 07:23:25 -04:00