The secrets module will now look for "moonraker.secrets"
in the data folder. If the file does not exist the deprecated
"secrets_path" option will be used as a fallback.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Deprecate the "database_path" option. If the database
does not exist, however the "database_path" does, it
will be used as a fallback.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
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>
Prepare to move away from configurable paths. This will
resolve potential security vulnerabilities in the event that
a user's access is compromised.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Klipper now has the ability to report the current layer on
properly configured slicers. Prefer this value if available,
otherwise fall back to layer detection.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Users may specify a dedicated ambient sensor in the
[simplyprint] configuration. If the specified sensor is
invalid or no sensor is specified ambient detection
will fall back to an estimate using the extruder.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Its possible for the websocket client to disconnect before
read_message() returns None. Await all calls to write_message()
to handle websocket closed exceptions.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Moonraker requires that the configuration be parsed in 'strict' mode,
ie: duplicate sections are not allowed within the same file and duplicate
options are not allowed within the same section.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Query the detected url and make sure it redirects to the
expected url. This closes a security vulnerability
where a remote could be changed to an arbitrary repo's url.
The `moved_origin` option is no longer necessary, however it
is currently used as an additional check. In the future it will be
deprecated.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Close a security hole where an attacker could overwrite an existing repo
with any remote and run malicious code through an update.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If the supplied python executable is a symbolic link attempt
to read the location at which it points. If this is a virtualenv
this should give us the correct pip location.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This adds initial support for connecting Moonraker to the SimplyPrint
service. Currently the connection defaults to SimplyPrint's dev/test
endpoint, this will be changed prior to official release.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Its possible for any component to request a configuration
option from another component. Don't overwrite the
inital value stored.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Process included files in the order they are added. This changes how
duplicate sections throughout included files are merged, options in
the last section to be parsed will take precedent.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The webcam module allows users to enter webcam configuration through
moonraker.conf while keeping compatibility with frontends that
store webcam data in the database.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
In the future, an `Access-Control-Request-Private-Network` header will be sent with
these requests, and servers must respond with `Access-Control-Allow-Private-Network`.
This will start with the next Chrome version (104), and Mozilla has marked the
standard as "worth prototyping", which often leads to final implementation.
Signed-off-by: Franklyn Tackitt <git@frank.af>
Check for updates every 7 days rather than every 28 days. This
is in preparation of an upcoming beta release.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Python 3.10 deprecates "get_event_loop()", so it is necessary to
create a new loop and set it as active at startup. Previously
Moonraker only did this after a soft restart.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
For legacy purposes its possible that "initialize()" may be an
awaitable. Ignore the type as it consues mypy.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Remote devices, such as the tplink smartplug and http
based devices, may not be immediately available when
Moonraker starts. Previously this would result in an error.
Remote switches that requiring polling for state will now
reattempt initialization indefinitely. This behavior brings
them in line with devices that are updated asynchronously.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Override the paho-mqtt client "reconnect()" method with
a method capable of taking a connected socket. This allows
Moonraker to connect the socket asynchronously, then finish
establishing the connection.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't allow exceptions to propagate beyond a call to
_process_event(). Make sure the future is not marked
as done prior to setting the result.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
For the "Percent" preset the intensity controls the amount of the bar lit up 0-100
Work around issue when preset is re-enabled if sending intensity or speed while no preset is active
Removed control endpoint
Added missed toggle endpoint
Transition time to 0 for control changes
Signed-off-by: Richard Mitchell <richardjm+moonraker@gmail.com>
To accommodate access to multiple protocols Moonraker will always
require that the "params" field contain a dictionary, so reject any
other type as invalid. There is no need to expand keyword arguments,
simply pass the params dict to the callback.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add basic support "agents", ie: unmanaged extensions. Connected
agents are granted a limited ability to emit websocket notifications
and process rpc requests from Moonraker.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
HTTP 404 and JSON-RPC -32601 are equivalent, so translate
where necessary. Any other JRPC code received outside of the
HTTP error range should be assigned a 500.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Handle exceptions should the attempt to fetch peer
credentials on the unix socket fail. This isn't a hard
requirement for connection and should not cause
the connection to abort.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This prevents a scenario where a request handler mutates
the arguments of a WebRequest, which could result in
changing the default "request_arguments" in
"InternalTransport.call_method()".
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This is a reimplementation of commit d61540cad5,
however this attempt provides a fallback for legacy configurations
that still have configuration in the server section.
This will change how `/server/config` reports configuration. Options
will always be reported in their respective component's field, even if
they are currently configured in the `[server]` section.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This isn't necessary as we don't add new sections to the
original config object when parsing supplemental data.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
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>
This isn't necessary as we don't add new sections to the
original config object when parsing supplemental data.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Most core components have default options that allow them to
load without a section specified in moonraker.conf. This resulted
in those options showing up in the [server] section in the
"/server/config" response. These changes will make sure that those
values show up in the correct section.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Use git for-each-ref to retreive tags and their associated commit
hashes. This allows us to limit the amount of tags to 10 and
simplifies the code as the returned objects are already dereferenced.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't require the `app_params` argument, instead dynamically
generate the configuration from a dict. This simiplifies AppDeploy
initialization as the internally generated configurations can be
read in the same way as those supplied in moonraker.conf.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
While use of "unofficial" klippy extras an moonraker components
is not officially supported, there is no harm in facilitating
updates for these extensions in the update manager. This adds
configuration which will restart either moonraker or klipper
after an extension is updated.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If "None" is specified as a separator for getdict and the getlist
variants then strings will split along any whitespace character.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't require a config object to instantiate and don't attempt
to wrap database namespace. These changes allow instantation
after the server has started.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
While the curl based client is better in most respects, it requires
that libcurl be against with an asynchronous DNS resolver, such
as c-ares, in order to prevent blocking. As of now it Debian does
not ship with a version of curl with ares enabled. Fall back to the
simple client until this can be resolved.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Its possible for users to have an unstable internet connection. Log
connection errors rather than warn.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The parsed feeds are stored in the DB, so there is no
need to cache the result when 304 is returned.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This adds support for announcements retreived via RSS feed from
the "moonlight" GitHub repo. Announcements may also be procedurally
generated internally.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When using tempfile.TemporaryDirectory it is possible that
exiting the context will block when attempting to delete
the temporary directory. Don't use the context manager,
instead create and cleanup the temp dir using the default
threadpoolexecutor.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This abstracts the tornado http client from the rest of Moonraker,
allowing all components to access the client's most used functionality
without importing tornado modules.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Provide a remote method by which clients may identify their
name, version, and type.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
fix
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
By retreiving and storing the hostname in the websocket
header, it is possible to determine a fully qualified domain
used to reach the instance.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Refactor the PowerDevice initialize() method so that it acquires the
request lock. Always register the "klippy_started" event if the
"restart_klipper" option is set, and always check if Klipper is is
the ready state before performing the restart. Remove stale
PowerDevice methods no longer used.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
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>
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>
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>
This option was intended for Moonraker developers to live test
changes to write protected namespaces. This can be accomplished
locally with other methods, thus this option has been removed to
prevent users from compromising sections of the database.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This component will be a bridge between moonraker and https://github.com/caronc/apprise. This way users can easily add all kind of notification services to their printer.
Signed-off-by: Pieter Willekens <me@pataar.nl>
Moonraker depends on "future" annotations and uses fstrings, so
versions of Python older than 3.7 will fail to load and never make
it to the version check.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Start tracking the Remote API version separately from the application
version. This allows the API to stick to semantic versioning while
and track the application version separately. This is necessary as
we prepare to release a beta.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
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>
The "wait_connected" method would block indefinitely until a klippy
connection is established. This isn't the behavior we want, we only
want to wait "if" a connection has been established until Klippy
reports that its startup sequence is complete.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This makes the order in which they are reported consistent,
as the namespaces are stored in a set.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible to reduce to a value that is not a dict in "insert_item()"
and "update_item()". Raise a ServerError with a clear description of
what went wrong in these situations.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible that Moonraker can be instantiated while the eventloop
is running during tests. To avoid errors allow synchronous calls until
the server starts.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since the User DB is not going to be large cache the users
in local memory and sync with the DB when changes are
made to the local user store.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Now that all transactions run in a thread it is possible for them to
interleave. The record based operations allow for batch operations
within a single transaction.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Wrap command implementations in with a _run_command() method. All
database commands now return a Future object. If the command was
run before the eventloop starts its possible to immediately query
the Future's result.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Similar to the update method, however sync will remove any
keys in the database not in the new value.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than creating two wrappers, use a single wrapper whose methods
always return a future or awaitable. If the operation occurs during
the __init__() method of a component it will be syncrhonous, and the
result from the future can be immediately queried.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than reading out the entire database, attempt to pop off
empty keys in each database. This should should speed up
init on platforms with slow disk I/O and prevents reading
large namespaces in memory.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It isn't necessary to read out the entire namespace, just attempt
to fetch the record and reduce the key list.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since transactions are now threaded we need updating
and clearing a namespace needs to be performed within
one transaction.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Database transactions can perform disk I/O tasks, which at times will
block the eventloop. Run all transactions in threads to prevent this
from occuring.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The read() method will return an empty list if the file specified
does not exist or if the read failed in some fashion.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Moonraker requires that some Klipper objects be configured
and loaded. This check has always been performed and logged,
now track and report missing requirements.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move the KlippyConnection class into its own module. Refactor
init to use loops rather than callbacks, this reduces complexity
of tracking and cancelling callback handles.
All Klippy state previously tracked by the Server is now in the
KlippyConnection. This improves testing and makes the code
less ambiguous, ie: the `server.make_request()` method is not
as clear as `klippy.request()`.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move the version check to the top of the module. An older version
of python is unlikely to make it beyond the initial import statements,
so print a message to stdout and stderr.
Move argument parsing out of the main method. This makes it possible
to invoke main without parsing command line arguments, which is useful
for tests.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than instantiate a new version of the event loop wrapper
we can simply reset the internal event loop.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>