73 Commits

Author SHA1 Message Date
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
Eric Callahan
500e8f3b68
machine: disable file write access when validation fails
Prevent users from uploading files before validation is complete, as
this can populate one of the subfolders resulting in a failure when
attempting to symlink the original path.

When validating the config symlink the database first.  This should
allow Moonraker to correctly move the database should an error
be encountered when validating the other config options.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-10-15 06:01:36 -04:00
Eric Callahan
86fc1057f7 server: deprecate debug logging option
Add a debug option to the command line to enable
debug features.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-10-14 15:15:41 -04:00
Eric Callahan
41ea45a486 moonraker: remove alias option
Differentiate instances based on the data path provided.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-10-14 15:15:41 -04:00
Eric Callahan
7217b36f9b file_manager: handle overlapped inotify watches
Handle exceptions raised when adding a new watch.  Warn
the user and skip adding the node to the watched tree.

Signed-off-by: Eric Callahan <arksine.code@gmail.com>
2022-10-14 15:15:41 -04:00
Eric Callahan
069a655df8 file_manager: update reserved path handling
Allow components to register reserved paths, then perform reserved
path validation it upon request.  Reserved paths may be registered as
read-only or no access.  Any request to modify an file/folder that is
either reserved or a child of a reserved path is rejected.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-10-14 15:15:41 -04:00
Eric Callahan
480ebfac8e file_manager: add support for new "data_path"
The config and logs paths are no longer configurable,
they all exist as folders or symbolic links within the primary
data folder.  The gcode path no longer relies on Klipper to
specify the location, instead Klipper's virtual_sdcard path
shold be configured to the location of the "gcodes" folder
in the data path.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-10-14 15:15:41 -04:00
Eric Callahan
18169f279e
file_manager: add get_directory method
This replaces the previous "get_sd_directory()" method, allowing
consumers to get any registered root path.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-04-04 17:18:03 -04:00
Eric Callahan
fd8bde7185
file_manager: implement access check method
This method can be used by other components to check if Moonraker has
access to a particular file or folder.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-02-26 10:48:51 -05:00
Eric Callahan
a32bf4a47a
file_manager: allow server to start with invalid paths
Don't raise an exeption if the config or log paths are invalid,
add warnings instead.  This allows the user to see what is wrong
and resolve this issue.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-02-26 10:48:50 -05:00
Eric Callahan
3a384e62dd
file_manager: add registered directory validation
Make sure that paths registered with full access do not overlap one
another, nor that they overlap sensitive folders such as the database,
Moonraker's source, or Klipper's source.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-02-26 10:48:48 -05:00
Eric Callahan
7ab1dda772 power: change behavior of "on when queued"
Rename the "on_when_upload_queued" option to "on_when_job_queued",
deprecate the former.  This option now applies to any queued job while
the device is off.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-02-22 14:36:46 -05:00
Eric Callahan
9e57db0611 file_manager: add method to retreive the metadata storage object
This allows other components to synchronously access and update
metadata if necessary.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-02-17 11:19:57 -05:00
Eric Callahan
0dd10ce116 file_manager: update for changes in the database
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-02-17 11:19:57 -05:00
Eric Callahan
0f7af929f1 file_manager: suppress "root_update" notifications during init
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-02-05 06:56:29 -05:00
Eric Callahan
e2fb1cc931 octoprint_compat: add support for "print on start"
Cura's Octoprint plugin does not set the 'start' flag on uploads
when UFP is enabled.  Instead it waits for the upload to
finish then issues Octoprint's "file command" request.  Add
limited support for this API, mimicing how uploads are normally
handled.

Singed-off-by:  Eric Callahan <arksine.code@gmail.com>
2021-12-22 05:41:00 -05:00
Eric Callahan
b369173f94 app: refactor upload handler registration
Move upload handler registration out of the file manager.
Register the primary hander in the app module, and the
Octoprint Comptaiblity handler in octoprint_compat.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2021-12-21 16:53:33 -05:00
Eric Callahan
f5f87bf08c file_manager: metadata move fix
If the destination exits in the metadata database it is necessary
to either overwrite it with the source metadata or delete it
so that the new metadata can be rescanned.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2021-12-08 15:26:45 -05:00