Some slicers create a temporary file during export, then rename the file with gcode extension after completion. If file metadata does not exist during an attempt to move metadata, scan the file.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Shutdown the websocket and http server before doing final component cleanup. This prevents clients from making a request after components have been closed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This removes the cryptography dependency in favor of libsodium. Also removed is python-jose, as we must generate our own JWTs for use with EdDSA.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
use libnacl instead of pynacl
Systemd units are case sensitive, do not convert the "name" argument for service requests to lower case.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Home Assistant returns an empty response when switching a switch
on or off. Will now requery the switch status and return it's result
Signed-off-by: Alan Harper <alan@aussiegeek.net>
Clients can use this in situations where a browser may
prompt the user to take action prior to sending the
request. After the user accepts, Moonraker will redirect the user to the url provided in the request.
SIgned-off-by: Eric Callahan <arksine.code@gmail.com>
The addition of inotify can introduce scenarios where file transfers complete abruptly, resulting in a corrupt/incomplete file.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The logic used to sync requests to modify contents in hidden directories is no longer necessary, thus removed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The metadata won't always depict an actual change to the content of a file. Compare a hash of the file content rather than retrieve modified times to determine if it is necessary to install dependencies.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Re-entrant calls to "run" and "run_with_response" would poison the process state resulting in unexpected behavior. Use a lock to prevent this.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Reset the command tracking data before each retry. If the command is cancelled by the user immediately break.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Attempt to recover from "loose object" error in git status and git fetch commands. It is no longer necessary to run git fsck on every refresh attempt, only run it after a recovery attempt.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When no callback is set for stderr, the outputfrom stderr is piped to stdout. This makes setting the callback redundant.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Image files (.png) are still granted unauthorized access, however all other files require that the request be authorized.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
While inotify watches are not applied to hidden directories it is still valid to use Moonraker's endpoints to perform operations on them. When performing an operation on an item within a hidden directory, or on a hidden directory itself, do not sync the request with inotify.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows clients to display a list of warnings that Moonraker detects. Previously this info was only logged.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Clients may pass a json web token via the query string's "access_token" argument to authorize requests that do not allow modified headers.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When "force_logins" is enabled a user login is required if at least one user is registered, overriding the "trusted_clients" configuration.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Replace non-ASCII characters with "?" and add escaped unicode version of the file name to the "Content-Disposition" header to fix problems with thumbnails and downloading for the gcode file with non-ASCII characters in filename.
Signed-off-by: Uladzimir Palekh <visor.rti@gmail.com>
This root may be used to store log files for Klipper, Moonraker, and other applications as necessary.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
USER CHANGE: The deprecated "client_repo" and "client_path" options have been removed in this commit. Use [update_manger client client_name] to configure clients.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This includes a refactoring of the PowerDevice base class so that it defines some abstract methods that its children must implement.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Annotate function definitions, class attributes, and local variables as necessary for type hinting. This is useful for IDEs with linters that support type hints and also can be used by GitHub Actions to detect erroneous code.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add a SentinelClass singleton. This can be used to generate Sentinels by
modules that need to use the Sentinel pattern for default values. This
allows for more robust type checking, as the Sentinel type should not be
included as a return value.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
On slower platforms it is possible for this to take time and block the event loop. Run shutil.rmtree in another thread to prevent this from occuring.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If an inotify event is generated as the result of an API request, the notifications are synchronized so that they occur after the request returns. Use a mutex to prevent multiple "write" requests processing concurrently.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If a file is moved from one location to another in the "gcodes" root it isn't necessary to rescan the file metadata as the underlying file information does not change. Add the ability to change the metadata's key and move associated thumbnails when a file is moved.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since filelist_changed notifications are now delayed until after metadata is processed there is no need to send an additional metadata notification.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than tracking watch paths directly, wrap each watch in a node. This makes makes it a bit easier to handle move and delete changes, as we don't have to manage several different dicts to store the information we need.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When a directory is created, attempt to suppress notifications generated as its children are created.
Wait until all items are copied before notifying clients and scanning metadata.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The copy methods are blocking and will block the asyncio event loop. Run them in a ThreadPoolExecutor to keep the event loop free.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When a directory is deleted this attempts to suppress delete events for all children. Clients only need to be notified of the parent node, as its deletion implies all children have been deleted.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This guarantees that .ufps will not be unzipped in parallel and offloads a potential blocking operation to another process.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This removes all calls to "notify_filelist_changed" in the FileManager class. This also simplfies the previous `_convert_path()` method, as it is no longer necessary to return the path relative to the root.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Generally speaking static files do not require authorization, so there should be little harm in bypassing auth checks. This allows clients to retrieve assets without XHRs or requesting tokens.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
On some devices gpiod does not report the correct state. Since Moonraker maintains exclusive control over GPIO lines, its unnecessary to query the line itself for state, as we can maintain it ourselves.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This should allow git's internal timeout mechanisms to trigger at the expense of potentially delaying response time if a fetch or pull hangs.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is now possible for any authorized request to delete a user, however a logged in user cannot delete its own account.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
A single endpoint that can be used to both toggle and retrieve device state is useful for interoperability with home automation software. The previous endpoints will remain as they are still useful for batch operations.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Make sure that the current device state is correct in the event that a device is toggled by an external source.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Always run git fsck when initializing a repo. If a loose object error is detected when running git pull or git fetch, attempt to remove loose objects and retry.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't continuously log a change in throttled state, only log when a new throttled flag is detected.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Log the current user for each request. Dont' log requests that return with 200, 204, 206, or 304 in release mode.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
A Moonraker component may now register a namespace as "forbidden". API requests have no read/write access to forbidden namespaces and this cannot be overridden by the database debug option.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
CONFIG CHANGE: This deprecates the "enabled" option in the [authorization] section. Authorization will be enabled if the section is included in moonraker.conf, otherwise it will be disabled.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Force an update to cached file hashes should the modified time change. Re-enable the "should_return_304" check so clients can re-implement caching.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Some static files, such as logs, can change size during a request. This results in a content length mismatch and error. Cap the amount read based on the original content length.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add a timer parameter to shelly and tasmota integration.
Use case: 3D printer mains power is connected to one of these devices. Just turning off the smart switch will just kill power to the RaspberryPI. Adding a timer will allow the PI to shutdown cleanly before killing the power
Signed-off-by: Dominik Weis fsironman@gmail.com
This allows protected namespaces to be modified externally. This is for dev use only, modifying protected namespaces can potentially corrupt the database.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This fixes a bug where it is protected namespace can be modified in an optional component if that component is disabled.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
add a check and handle consequently in case tasmota device is only one relay and would return a power value when asked a power1 value
Signed-off-by: Arnaud Schaer <arnaud.schaer@wanadoo.fr>
The Klipper repo always initializes last. Send a notification at this time, so if any clients are connected they can receive the full update status after init.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
During normal updates dependencies will always been updated when necessary. It is possible to force a dependency updating using the new "/machine/update/recover" endpoint.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Gives callers flexibility as to which signal is used to cancel a command first. By default shell_command will start with SIGTERM, then proceed to SIGKILL.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than attempt to automate recovery, provide an endpoint for clients
to initiate. Clients can choose between a "hard" recovery, which removes
a corrupt repo and restores from a backup, or a "soft" recover which attempts
a git clean followed by a git reset.
Backups are now only taken when a valid repo is detected.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Note that this does not replace references to "Cura" or "Octoprint" plugins, which are also included in this module.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It isn't necessary for each updater to have their own init lock. Combine them all into a single Event that is set after the "initialize_updaters" method completes.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Give more time for a standard command to complete. This may help prevent a git command from being terminated prematurely.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Git repos can occasionally become corrupted when attempting to deploy updates thought automated means. Use rysnc to create a backup of each git repo, allowing the repo to be restored in the event of a corrupted repo.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since "run_with_response" now raises an exception there is no need to inspect the response for a None type. Instead the exception can be handled by the caller directly.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This error contains the return code and anything received from stdout and stderr when "run_with_response" encounters an error. This allows the caller to receive the output and easily distinguish between a successfully run command and an erronous command.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Sometimes git will erroneously leave the lock file in place when a command fails. Check for locked git repo before initialization, waiting up to 60 seconds before forcefully removing the lock. Also check for a locked repo after a failed fetch or pull, removing it if it exists.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Git clients may specify a branch other than "master" as the primary to pass the validation checks.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This field does not persist in the database as it is subject change if a file is moved or deleted when Moonraker is not running.
Also add thumbnail information to the metadata sans the base64 image data for each entry.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Other modules may look up this plugin to determine if a particular file exists at the specified root.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Moonraker now checks the modified time of both the install script and requirements file for git repos. If either is out of date their associated dependencies will be installed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This ensures that jobs in the database will be stored in the order they were started. Doing so also eliminates the need for the `history_auto_inc_id", as we can initialize the next id from the database keys.
This also caches history keys in memory so we do not need to read them from the database on each access.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add an additional checks to determine if a job needs to be cancelled when we receive a new "printing" state. A file name mismatch or a decrease in total_duration indicates a virtual sdcard reset.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add GET and DELETE `/server/history/job` APIs and remvoe the `DELETE /server/history/delete` API. When returning a list of jobs, return it as an array rather than as a object. The `/server/history/list` API no longer accepts a job id.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows the repo init sequence to distinguish between a broken git repo and an invalid git repo.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If a trusted IP address is passed as the origin then it is safe to assume that CORS access to this origin should be granted, but only if CORS is enabled by specifying at least one cors domain.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
A user may unintentionally allow access to dangerous domains if they place a wildcard in the top level domain portion of an entry. Raise a config error when this condition is detected.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move git command functionality to its own class outside of the Updater class. This class is responsible for tracking repo state and executing commands on the repo. Fetch and Pull no longer use built in command timeouts, instead a callback is scheduled to see if the command returned progress. Only when no progress is returned will a fetch or pull be terminated after a timeout.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This class handles running shell commands and sending http API requests. Each updater class shares an instance of the command helper rather than the UpdateManager instance.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
In the "run()" method verbosity should still be allowed if log_stderr is True, even
if both callbacks are not set.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>