diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..5311f0fa2 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# someone from the docker-maintainers team will be requested for review +# whenever the trigger_docker workflow is changed in a Pull Request +.github/workflows/trigger_docker.yml @OctoPrint/docker-maintainers diff --git a/.github/issue-validation.yml b/.github/issue-validation.yml new file mode 100644 index 000000000..763ca73a2 --- /dev/null +++ b/.github/issue-validation.yml @@ -0,0 +1,62 @@ +approve_label: approved +problem_label: incomplete +ignored_labels: + - approved + - bug + - request + - improvement + - brainstorming + - task + - rc feedback + - awaiting information + - not octoprint + - done +ignored_authors: + - "@OctoPrint" + - "sentry-io" + - "FormerLurker" + - "bzed" + +validation_comment: > + Hi @@@AUTHOR@@, + + + it looks like there is some **information missing** from your bug report that will + be needed in order to solve the problem. Read the [Contribution Guidelines](https://github.com/OctoPrint/OctoPrint/blob/master/CONTRIBUTING.md) + which will provide you with a template to *fully fill out* here so that your bug report + is ready to be investigated (I promise I'll go away then too!). + + + If you did not intend to report a bug but wanted to **request a feature or brain + storm** about some kind of development, please take special note of the title format + to use as described in the [Contribution Guidelines](https://github.com/OctoPrint/OctoPrint/blob/master/CONTRIBUTING.md). + + + **Please do not abuse the bug tracker as a support forum** - that can be found at + [community.octoprint.org](https://community.octoprint.org). Go there for any kind + of issues with network connectivity, webcam functionality, printer detection or + any other kind of such support requests or general questions. + + + Also **make sure you are at the right place** - this is the bug tracker of the official + version of OctoPrint, not the Raspberry Pi image OctoPi nor any unbundled third + party OctoPrint plugins or unofficial versions. Make sure too that you have **read + through the [Frequently Asked Questions](http://faq.octoprint.org)** and searched + the [**existing tickets**](https://github.com/OctoPrint/OctoPrint/issues) + for your problem - try multiple search terms please. + + + I'm marking this one now as needing some more information. Please understand that + if you do not provide that information within the next two weeks + I'll close this ticket so it doesn't clutter the bug tracker. This is nothing + personal, it's needed to keep this project manageable. Please just be considerate + and help the maintainers solve this problem + quickly by following the guidelines linked above. Remember, the less time the devs + have to spend running after information on tickets, the more time they have to actually + solve problems and add awesome new features. Thank you! + + + *I'm just a bot ๐Ÿค–, not a human being, so don't expect any replies + from me :) Your ticket is read by humans too, I'm just not one of them.* + +keyphrase: I have read the FAQ diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000..ed3f1c77a --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,25 @@ +docs: + - "docs/*" + - "docs/**/*" + - "README.md" + +meta: + - "CODE_OF_CONDUCT.md" + - "CONTRIBUTING.md" + - "SECURITY.md" + - ".github/CODEOWNERS" + - ".github/FUNDING.yml" + - ".github/ISSUE_TEMPLATE/*" + - ".github/PULL_REQUEST_TEMPLATE.md" + +ci/cd: + - ".github/fixtures/**/*" + - ".github/workflows/*" + - ".github/labeler.yml" + +docker: + - ".github/workflows/trigger_docker.yml" + +tests: + - "tests/*" + - "tests/**/*" diff --git a/.github/pr-validation.yml b/.github/pr-validation.yml new file mode 100644 index 000000000..b6644f25c --- /dev/null +++ b/.github/pr-validation.yml @@ -0,0 +1,14 @@ +approve_label: "approved" +problem_label: "needs some work" + +allowed_targets: ["maintenance", "devel", "staging/maintenance", "staging/devel"] +forbidden_sources: + ["master", "maintenance", "devel", "staging/maintenance", "staging/devel"] + +labels: + docs: + additional_allowed_targets: ["master"] + meta: + additional_allowed_targets: ["master"] + ci/cd: + additional_allowed_targets: ["master"] diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml new file mode 100644 index 000000000..80ff4f957 --- /dev/null +++ b/.github/workflows/cleanup.yml @@ -0,0 +1,37 @@ +name: "Cleanup issues & PRs" + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + lock: + name: ๐Ÿ”’ Lock issues & PRs closed over a year + runs-on: ubuntu-latest + steps: + - uses: dessant/lock-threads@v2 + with: + github-token: ${{ github.token }} + issue-lock-comment: "" + pr-lock-comment: "" + + cleanup: + name: ๐Ÿงน Close issues marked as incomplete & older than 14 days + runs-on: ubuntu-latest + steps: + - id: date + run: | + echo "::set-output name=CUTOFF::`date --date='14 days ago' +'%Y-%m-%d'`" + - uses: OctoPrint/actions/close-by-query@main + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + query: "is:issue is:open label:incomplete created:<${{ steps.date.outputs.CUTOFF }}" + comment: > + Since apparently some of the required information is still missing, this will be + closed now, sorry. Feel free to request a reopen of this or create a new issue + once you can provide **all** + [required information](https://github.com/OctoPrint/OctoPrint/blob/master/CONTRIBUTING.md#how-to-file-a-bug-report). + + + This is nothing personal. Thank you for your collaboration. diff --git a/.github/workflows/issue_labeler.yml b/.github/workflows/issue_automation.yml similarity index 87% rename from .github/workflows/issue_labeler.yml rename to .github/workflows/issue_automation.yml index 5b6e026e7..0ba8b6f44 100644 --- a/.github/workflows/issue_labeler.yml +++ b/.github/workflows/issue_automation.yml @@ -1,10 +1,10 @@ -name: "Issue Labeler" +name: "Issue Automation" on: issues: types: [opened, edited, closed, reopened] jobs: - label-opened-and-edited: + issue-automation: runs-on: ubuntu-latest steps: - uses: actions/github-script@v2 @@ -62,3 +62,8 @@ jobs: labels: labels }) } + + - uses: OctoPrint/actions/issue-validation@main + if: github.event_name == 'issues' && (github.event.action == 'opened' || github.event.action == 'edited') + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml deleted file mode 100644 index b753d3fc0..000000000 --- a/.github/workflows/lock.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: "Lock outdated issues & PRs" - -on: - schedule: - - cron: "0 0 * * *" - -jobs: - lock: - runs-on: ubuntu-latest - steps: - - name: ๐Ÿ”’ Lock issues & PRs closed over a year - uses: dessant/lock-threads@v2 - with: - github-token: ${{ github.token }} - issue-lock-comment: "" - pr-lock-comment: "" diff --git a/.github/workflows/pr_automation.yml b/.github/workflows/pr_automation.yml new file mode 100644 index 000000000..659733438 --- /dev/null +++ b/.github/workflows/pr_automation.yml @@ -0,0 +1,16 @@ +name: "Pull Request Automation" +on: + pull_request_target: + types: ["opened", "synchronize", "reopened", "edited", "labeled", "unlabeled"] + +jobs: + pr-automation: + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v3 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + + - uses: OctoPrint/actions/pr-validation@main + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/trigger_docker.yml b/.github/workflows/trigger_docker.yml index edf7a4c1d..1a86bb0c6 100644 --- a/.github/workflows/trigger_docker.yml +++ b/.github/workflows/trigger_docker.yml @@ -4,16 +4,44 @@ on: types: - released - prereleased + push: + branches: + - maintenance + - devel jobs: - trigger: + dispatch_releases: runs-on: ubuntu-latest - if: github.repository == 'OctoPrint/OctoPrint' + if: github.repository == 'OctoPrint/OctoPrint' && github.event_name != 'push' steps: - name: ๐Ÿš€ Repository Dispatch uses: peter-evans/repository-dispatch@v1 with: token: ${{ secrets.DOCKER_ACCESS_TOKEN }} repository: ${{ github.repository_owner }}/octoprint-docker - event-type: "release" + event-type: ${{ github.event.action }} client-payload: '{"tag_name": "${{ github.event.release.tag_name }}"}' + + dispatch_canary: + runs-on: ubuntu-latest + if: github.repository == 'OctoPrint/OctoPrint' && github.event_name == 'push' && github.ref == 'refs/heads/maintenance' + steps: + - name: ๐Ÿš€ Repository Dispatch + uses: peter-evans/repository-dispatch@v1 + with: + token: ${{ secrets.DOCKER_ACCESS_TOKEN }} + repository: ${{ github.repository_owner }}/octoprint-docker + event-type: "canary" + client-payload: '{"tag_name": "maintenance"}' + + dispatch_bleeding: + runs-on: ubuntu-latest + if: github.repository == 'OctoPrint/OctoPrint' && github.event_name == 'push' && github.ref == 'refs/heads/devel' + steps: + - name: ๐Ÿš€ Repository Dispatch + uses: peter-evans/repository-dispatch@v1 + with: + token: ${{ secrets.DOCKER_ACCESS_TOKEN }} + repository: ${{ github.repository_owner }}/octoprint-docker + event-type: "bleeding" + client-payload: '{"tag_name": "devel"}' diff --git a/.versioneer-lookup b/.versioneer-lookup index dea2ee3c3..6f5e25bb4 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -24,8 +24,10 @@ maintenance 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev fix/.* 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev improve/.* 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev -# staging/hotfix is the branch for preparation of the 1.5.1 hotfix release -staging/hotfix 1.5.1 f67c15a9a47794a68be9aed4f2d5a12a87e70179 pep440-dev +# staging/bugfix is the branch for preparation of the 1.5.3 hotfix release +# so are any bug/... branches +staging/bugfix 1.5.3 e46e8fa17a1553cd0c228a4fa4cfd93e2a9bce7b pep440-dev +bug/.* 1.5.3 e46e8fa17a1553cd0c228a4fa4cfd93e2a9bce7b pep440-dev # staging/maintenance is currently the branch for preparation of 1.5.0rc4 # so is regressionfix/... diff --git a/AUTHORS.md b/AUTHORS.md index c200bf191..4e56a653e 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -130,6 +130,11 @@ date of first contribution): * [Sophist](https://github.com/Sophist-UK) * [Manuel McLure](https://github.com/ManuelMcLure) * ["j7126"](https://github.com/j7126) + * ["coliss86"](https://github.com/coliss86) + * ["MichaIng"](https://github.com/MichaIng) + * ["jasonbcox"](https://github.com/jasonbcox) + * ["shadycuz"](https://github.com/shadycuz) + * [David Rifkind](https://github.com/drifkind) * [Nils Hofmann](https://github.com/Master92) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by diff --git a/SUPPORTERS.md b/SUPPORTERS.md index c7d1ab3fd..46d0e9a1d 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -6,18 +6,22 @@ thanks to everyone who contributed! ## Patrons & Sponsors + * 3DPrinterOS * Andrew Moorby * Arnljot Arntsen * Ash King * BigTreeTech * Boris Hussein * Brad Jackson + * BRANDON ROBERTSON * BuildBee * Christian Petropolis * Christian Wolf + * Creality3D * D Brian Kimmel * DeltaMaker 3D Printers * Dennis Breining + * Diana C Rodriguez * Eric Betts * Ernesto Martinez * Franziska Kunsmann @@ -25,12 +29,10 @@ thanks to everyone who contributed! * Greg Holloway * Hog Duske * Hopewell Medical Acupuncture Center - * Hugh Blemings * jean-claude migneault * Jefferson Hunt * Jeremy Cole * Joe Pasqua - * John Gregory Robinson * Joshua Wills * Justin Kaufman * Kaile Riser @@ -51,13 +53,14 @@ thanks to everyone who contributed! * Mosaic Manufacturing * Neil R. Goldberg * Patrick Glyrรฉ - * Patrick McGinnis + * Pete Barnwell * Prof Yuh Wen Chen * Raise3D * Randy C. Will * Ranjib Dey * Richard McGuire * Richard Michaud + * Richard Stocks * Rigid3D * Robert Gusek * Ronald Griehsler @@ -68,4 +71,4 @@ thanks to everyone who contributed! * Sven Mueller * Ulrich Kempken -and 2116 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [Github Sponsors](https://github.com/users/foosel/sponsorship)! +and 2225 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [Github Sponsors](https://github.com/users/foosel/sponsorship)! diff --git a/docs/api/job.rst b/docs/api/job.rst index e8250c172..e95729459 100644 --- a/docs/api/job.rst +++ b/docs/api/job.rst @@ -205,8 +205,10 @@ Retrieve information about the current job }, "estimatedPrintTime": 8811, "filament": { - "length": 810, - "volume": 5.36 + "tool0": { + "length": 810, + "volume": 5.36 + } } }, "progress": { diff --git a/docs/bundledplugins/action_command_notification.rst b/docs/bundledplugins/action_command_notification.rst index fb3b50277..d2b5a005c 100644 --- a/docs/bundledplugins/action_command_notification.rst +++ b/docs/bundledplugins/action_command_notification.rst @@ -10,7 +10,7 @@ The OctoPrint Action Command Notification Support Plugin comes bundled with Octo It allows firmware to trigger notifications users with the ``PLUGIN_ACTION_COMMAND_NOTIFICATION_SHOW`` permission using :ref:`action commands ` about relevant events. These notifications will be shown in the sidebar and if configured also as popup messages. The notifications in the sidebar panel can also be cleared -by users with the ``PLUGIN_ACTION_COMMAND_NOTIFICATION_CLEAR` permission. +by users with the ``PLUGIN_ACTION_COMMAND_NOTIFICATION_CLEAR`` permission. .. _fig-bundledplugins-action_command_notification-example: .. figure:: ../images/bundledplugins-action_command_notification-example.png diff --git a/docs/bundledplugins/backup.rst b/docs/bundledplugins/backup.rst index e11c149c4..24be587e1 100644 --- a/docs/bundledplugins/backup.rst +++ b/docs/bundledplugins/backup.rst @@ -177,6 +177,30 @@ octoprint.plugin.backup.additional_excludes :return: A list of paths to exclude, relative to your plugin's data folder :rtype: list +Helpers +------- + +.. _sec-bundledplugins-backup-helpers: + +The Backup plugin exports two helpers that can be used by other plugins or internal methods +from within OctoPrint, without going via the API. + +.. _sec-bundledplugins-backup-helpers-create_backup: + +create_backup ++++++++++++++ + +.. autofunction:: octoprint.plugins.backup.BackupPlugin.create_backup_helper + + +.. _sec-bundledplugins-backup-helpers-delete_backup: + +delete_backup ++++++++++++++ + +.. autofunction:: octoprint.plugins.backup.BackupPlugin.delete_backup_helper + + .. _sec-bundledplugins-backup-sourcecode: Source code diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 7b8a949eb..56a0a5fce 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -30,7 +30,7 @@ Use the following settings to enable access control: userManager: octoprint.access.users.FilebasedUserManager # The YAML user file to use. If left out defaults to users.yaml in the default configuration folder. - userFile: /path/to/users.yaml + userfile: /path/to/users.yaml # If set to true, will automatically log on clients originating from any of the networks defined in # "localNetworks" as the user defined in "autologinAs". Defaults to false. diff --git a/docs/development/branches.rst b/docs/development/branches.rst index d2fef6255..57ec18158 100644 --- a/docs/development/branches.rst +++ b/docs/development/branches.rst @@ -30,8 +30,8 @@ There are three main branches in OctoPrint: There are couple more RC and staging branches that see regular use: -``staging/hotfix`` - Any preparation for potential hotfix releases takes place here. +``staging/bugfix`` + Any preparation for potential bugfix releases takes place here. Version number follows the scheme ``..`` (e.g. ``1.5.1``) for a current release of ``..``. ``rc/maintenance`` @@ -56,8 +56,8 @@ There are couple more RC and staging branches that see regular use: Additionally, from time to time you might see other branches pop up in the repository. Those usually have one of the following prefixes: -``hotfix/...`` - Hotfixes under development that are to be merged into the ``staging/hotfix`` +``bug/...`` + Fixes under development that are to be merged into the ``staging/bugfix`` and later the ``master`` branch. ``fix/...`` Fixes under development that are to be merged into the ``maintenance`` diff --git a/docs/development/virtual_printer.rst b/docs/development/virtual_printer.rst index 2ff4f2323..5e7a31e4d 100644 --- a/docs/development/virtual_printer.rst +++ b/docs/development/virtual_printer.rst @@ -200,6 +200,31 @@ There many configuration options via ``config.yaml`` for the virtual printer tha # Simulated ambient temperature in ยฐC ambientTemperature: 21.3 + + # Response to M105 when there is a target + # Placeholders: + # - heater: The heater id (eg. T0, T1, B) + # - actual: The actual temperature of the heater + # - target: The target temperature of heater + m105TargetFormatString: {heater}:{actual:.2f}/ {target:.2f} + + # Response to M105 when there is no target + # Placeholders: + # - heater: The heater id (eg. T0, T1, B) + # - actual: The actual temperature of the heater + m105NoTargetFormatString: {heater}:{actual:.2f} + + # Enable virtual EEPROM + # If enabled, a file `eeprom.json` will be created in the plugin data folder + # to enable settings persistence across connections. Enables M500/1/2/4 commmands + # And a selection of other settings commands. Responses modeled on Marlin 2.0 + enable_eeprom: true + + # Support M503 + support_m503: true + + # Resend ratio to simulate noise on the line + resend_ratio: 0 .. _sec-development-virtual-printer-log: diff --git a/docs/events/index.rst b/docs/events/index.rst index 7fa5e733e..71a55d68e 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -539,6 +539,34 @@ PrintResumed .. versionchanged:: 1.4.0 +GcodeScript${ScriptName}Running + A custom :ref:`GCODE script ` has started running. + + Payload: + + * ``name``: the file's name + * ``path``: the file's path within its storage location + * ``origin``: the origin storage location of the file, either ``local`` or ``sdcard`` + * ``size``: the file's size in bytes (if available) + * ``owner``: the user who started the print job (if available) + * ``time``: the time needed for the print, in seconds (float) + + .. versionadded:: 1.6.0 + +GcodeScript${ScriptName}Finished + A custom :ref:`GCODE script ` has finished running. + + Payload: + + * ``name``: the file's name + * ``path``: the file's path within its storage location + * ``origin``: the origin storage location of the file, either ``local`` or ``sdcard`` + * ``size``: the file's size in bytes (if available) + * ``owner``: the user who started the print job (if available) + * ``time``: the time needed for the print, in seconds (float) + + .. versionadded:: 1.6.0 + .. _sec-events-available_events-gcode_processing: GCODE processing diff --git a/docs/features/accesscontrol.rst b/docs/features/accesscontrol.rst index ca035d699..23bf90b75 100644 --- a/docs/features/accesscontrol.rst +++ b/docs/features/accesscontrol.rst @@ -3,7 +3,7 @@ Access Control ============== -.. versionchanged:: 1.4.0 +.. versionchanged:: 1.5.0 OctoPrint's bundled access control feature allows granular permission control over which users or user groups are allowed to access which parts of OctoPrint. @@ -17,8 +17,17 @@ users out of the box. thus also cannot limit access to it. If an anonymous user correctly guesses the webcam URL, they will thus be able to see it. -If read-only access for anonymous users is enabled, anonymous users will have -read-only access to the following parts of the UI: +Upon first start a configuration wizard is provided which allows configuration +of the first administrator account to be used for OctoPrint. After initial setup, +you can then create more users and groups under Settings > Access Control for +customisation of the granular permission system. + +The predefined "Guests" group can be used to configure default permissions of anonymous +users, that is those who have not logged in. By default, no permissions are granted to +these users. + +A predefined "Read-only Access" group with no users is configured which by default grants +read-only access to the following parts of the UI to any users assigned to this group: * printer state * available gcode files and stats (upload is disabled) @@ -30,29 +39,195 @@ read-only access to the following parts of the UI: * any components provided through plugins which are enabled for anonymous users -Logged in users without admin flag will be allowed to access everything besides the -Settings and System Commands, which are admin-only. +Another predefined "Operator" group is the default group for newly created users and +by default gives access to all aspects of OctoPrint that involve regular printer +operation. It matches the old "user" role from OctoPrint prior to 1.4.0. -If Access Control is disabled, everything is directly accessible. **That also -includes all administrative functionality as well as full control over the -printer**, and without the need for an :ref:`API key `! - -Upon first start a configuration wizard is provided which allows configuration -of the first administrator account or alternatively disabling Access Control -(which is **NOT** recommended for systems that are directly accessible via the -internet or other untrusted networks!). +Finally, the predefined "Admins" group gives full admin access to the platform. You should +be careful of who you put into that. It matches the old "admin" role from OctoPrint prior +to 1.4.0. .. hint:: If you plan to have your OctoPrint instance accessible over the internet, - **always enable Access Control** and ideally **don't make it accessible to + **please use additional security measures** and ideally **don't make it accessible to everyone over the internet but instead use a VPN** or at the very least - HTTP basic authentication on a layer above OctoPrint. + HTTP basic authentication on a layer above OctoPrint. Unless you are using a VPN + **please do not** enable any permissions for the Guest group or the auto-login feature + described below. A physical device that includes heaters and stepper motors really should not be publicly reachable by everyone with an internet connection, even with access control enabled. +.. _sec-features-access_control-autologin: + +Autologin +--------- + +While access control cannot be disabled as of OctoPrint 1.5+, the Autologin feature can +be used to bypass authentication for hosts on the network(s) that you trust. + +Starting with OctoPrint 1.5.0, OctoPrint makes enabled access control mandatory. This +might be an inconvience for some who run OctoPrint in an isolated setup where a login is +not required to ensure security, at a benefit for a huge number of users out there who +continue to underestimate or simply ignore the risk of keeping their OctoPrint instance +unsecured and then happily exposing it on the public internet. + +That being said, even as far back as OctoPrint 1.0.0 (released in 2013) there has existed +a way to have OctoPrint automatically log you in, if you connect from a trusted local +network address. This functionality has not been exposed on the UI, and for now also won't +be (to make it a bit harder to once again create an insecure setup for those who simply +won't listen to common sense), but it's easy to set up with a bit of configuration +editing. + +When set up properly, it will make sure to automatically log you in as a configured user +whenever you connect from a device on your local network. To get back pretty much the same +behaviour as with disabled access control, you'll only need to create a single (admin) +account and then set up autologin for it. + + +.. warning:: + + **Do not do this if you cannot trust EVERYONE on your local network.** And that really + means mean everyone. If you ignore this and then someone takes over your OctoPrint + instance, installs malware on it and makes your printer print an endless stream of + benchies, that's on you. + +.. _sec-features-access_control-autologin-gather_config_info: + +Gather configuration information +................................ + +You can configure Autologin via a plugin (the easy way), or manually (the hard way), but +in either case you will need to specify which user should be automatically logged in, and +which hosts are permitted access this way. + +**Improperly setting this subnet option can lead to the compromise of your system, or even +your entire network. Proceed with extreme caution.** + +The subnet to use is usually the IP address range of your LAN, which sounds scary but +actually isn't. Just `figure out your PC's IP address and subnet mask `_ +and then combine both with a / in between. + +On OctoPi (or another Linux distribution) you can use the follwing command: + +.. code-block:: + + ip route | grep -P 'eth0|wlan0' | awk '{print $1}' + +Or, for IPv6, use this: + +.. code-block:: + + ip -6 route | grep -P 'eth0|wlan0' | awk '{print $1}' + +This will be what you set as the subnet in the plugin, or where it says +```` below on the manual configuration instructions. + +Example: Your PC has an IP address of ``192.168.23.42`` and a subnet mask of +``255.255.255.0``. Your address range is ``192.168.23.42/255.255.255.0``. + +.. _sec-features-access_control-autologin-plugin: + +The easy way: Using the OctoPrint-AutoLoginConfig plugin +........................................................ + +The easist way to configure AutoLogin is to install the +`OctoPrint-AutoLoginConfig plugin `_ +via the plugin manager. + +Open its settings and follow the instructions on the screen. + +.. _sec-features-access_control-autologin-manual: + +The hard way: Manual editing of config.yaml +........................................... + +Preparation +*********** + +First of all, read :ref:`the YAML primer `. You +will have to edit OctoPrint's main configuration file, and thus should make sure +you understand at least roughly how things work and that you should keep your +hands off the Tab key. If you don't, you might break your config file, and +while the steps include making a backup, this still can be easily avoided by +learning about the DOs and DONTs first. + +Then, take a look at :ref:`the docs on config.yaml ` +on where to find that central configuration file of OctoPrint. + +Configuration +************* + +Ready? Let's do some editing then. I'll outline what to do and where first, and then +further down there's also a dedicated list of steps for OctoPi specifically. + +1. Shutdown OctoPrint +2. Make a backup of your config.yaml +3. Open it in a text editor (e.g. nano). Right at the very top it'll say something like + this: + + .. code-block:: yaml + + accessControl: + salt: aabbccddee1234523452345 + + Edit this, adding lines so it looks like this (making absolutely sure not to touch the + salt line): + + .. code-block:: yaml + accessControl: + salt: aabbccddee1234523452345 + autologinLocal: true + autologinAs: "" + localNetworks: + - "127.0.0.0/8" + - "" + +4. Restart OctoPrint, check that everything works. + +This will automatically log you in as the user you specified whenver you connect to +OctoPrint from an address in the address range (e.g. a device on your local network). + +OctoPi specific steps +********************* + +If you are running OctoPi you will have to SSH into your Raspberry Pi. Then issue +the following commands: + +1. ``sudo service octoprint stop`` +2. ``cp ~/.octoprint/config.yaml ~/.octoprint/config.yaml.back`` +3. ``nano ~/.octoprint/config.yaml, make the edits as described above`` +4. ``sudo service octoprint start`` + +If something went wrong, you can restore the config backup with + +.. code-block:: + + cp ~/.octoprint/config.yaml.back ~/.octoprint/config.yaml + + +If you are using a VPN and your setup ABSOLUTELY REQUIRES disabling internal OctoPrint access controls +...................................................................................................... + +.. warning:: + + You probably shouldn't do this, EVER. There are usually other options. Don't even + THINK about it, unless you have a VPN layer for security. Only consider proceeding + with this configuration after exhausting ALL other possibilities, and even then, you + should think long and hard about whether this is a good idea. You almost certainly + don't need or want to do this. + +While access controls can no longer be disabled in OctoPrint 1.5+, this can be +approximated by an Autologin configuration that automatically logs in all users, that is +by using subnets that match all possible IP addresses. By specifying the ``0.0.0.0/0`` +subnet (for IPv4) and ``::/0`` for IPv6 in the AutoLogin configuration, you can achieve +this. This configuration is permitted, but highly, highly discouraged. + +Please don't do this. You will almost certainly regret it. You alone are responsible for +your actions. + .. _sec-features-access_control-hooks: Available Extension Hooks @@ -71,42 +246,7 @@ See :ref:`here `. .. _sec-features-access_control-hooks-loginui: -octoprint.plugin.loginui.theming -................................ +octoprint.theming.login +....................... -See :ref:`here `. - -.. _sec-features-access_control-rerunning_wizard: - -Rerunning the wizard --------------------- - -In case Access Control was disabled in the configuration wizard, it is -possible to re-run it by editing ``config.yaml`` [#f1]_ and setting ``firstRun`` -in the ``server`` section and ``enabled`` in the ``accessControl`` section to -``true``: - -.. code-block-ext:: yaml - - accessControl: - enabled: true - # ... - server: - firstRun: true - -Then restart the server and connect to the web interface - the wizard should -be shown again. - -.. note:: - - If user accounts were created prior to disabling Access Control and those - user accounts are not to be used any more, remove ``.octoprint/users.yaml``. - If you don't remove this file, the above changes won't lead to the - configuration being shown again, instead Access Control will just be - enabled using the already existing login data. This is to prevent you from - resetting access control by accident. - -.. rubric:: Footnotes - -.. [#f1] For Linux that will be ``~/.octoprint/config.yaml``, for Windows it will be ``%APPDATA%/OctoPrint/config.yaml`` and for - Mac ``~/Library/Application Support/OctoPrint/config.yaml`` +See :ref:`here `. diff --git a/docs/features/gcode_scripts.rst b/docs/features/gcode_scripts.rst index dbd84ef0d..d836d3fad 100644 --- a/docs/features/gcode_scripts.rst +++ b/docs/features/gcode_scripts.rst @@ -43,6 +43,15 @@ The following GCODE scripts are sent by OctoPrint automatically: Plugins may extend these scripts through :ref:`a hook `. +.. _sec-features-gcode_scripts-events: + +Events +------ + +Every GCODE script that is executed will emit two events. The event name will start with 'GcodeScript' followed by the capitalized name +of the script. When ``afterPrintDone`` has started the event will be ``GcodeScriptAfterPrintDoneRunning`` and once it has completed the last event +will be ``GcodeScriptAfterPrintDoneFinished``. You can find more details in the :ref:`Events ` documentation. + .. _sec-features-gcode_scripts-snippets: Snippets diff --git a/docs/plugins/distributing.rst b/docs/plugins/distributing.rst index f01bbf79b..35325d38f 100644 --- a/docs/plugins/distributing.rst +++ b/docs/plugins/distributing.rst @@ -60,3 +60,22 @@ that in the `Plugin Repository's help pages `_ when creating your plugin, you can find a prepared registration entry ``.md`` file in the ``extras`` folder of your plugin. + +Version management after the official plugin repository release +--------------------------------------------------------------- + +Once your plugin is available in the official plugin repository, you probably want to create and distribute new versions. +For "beta" users you can use the manual file distribution method, or a more elegant release channels (see below). +After you finalized a new plugin version, don't forget to actually update the version in the ``setup.py``, +and `submit a new release on github `_. + +After you published the new release, you can verify it on your installed octoprint, +with force checking the updates under the advanced options (in the software updates menu in the settings). +The new versions will appear to the plugin users in the next 24 hours (it depends on their cache refreshes). + +The `Software Update Plugin `_ has options to define multiple release channels, +and you can let the users decide if they want to test your pre-releases or not. +This can be achieved with defining ``stable_branch`` and ``prerelease_branches`` in the ``get_update_information`` function, +and creating github releases to the newly configured branches too. +For more information you can check the `Software Update Plugin documentation `_ +or read a more step-by-step writeup `here `_. diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index 5863c034b..eb52fbec4 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -1173,15 +1173,6 @@ octoprint.plugin.backup.additional_excludes See :ref:`here `. -.. _sec-plugins-hook-plugin-loginui-theming: - -octoprint.plugin.loginui.theming -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. versionadded:: 1.4.0 - -See :ref:`here `. - .. _sec-plugins-hook-plugin-pluginmanager-reconnect: octoprint.plugin.pluginmanager.reconnect_hooks diff --git a/docs/plugins/viewmodels.rst b/docs/plugins/viewmodels.rst index dc8d9cace..91759647f 100644 --- a/docs/plugins/viewmodels.rst +++ b/docs/plugins/viewmodels.rst @@ -259,6 +259,10 @@ onUserSettingsShown() onUserSettingsHidden() Called when the user settings dialog is hidden. +onUserSettingsBeforeSave() + Called just before the user settings view model is sent to the server. This is useful, for example, if your plugin + needs to compute persisted settings from a custom view model. + onWizardDetails(response) Called with the response from the wizard detail API call initiated before opening the wizard dialog. Will contain the data from all :class:`~octoprint.plugin.WizardPlugin` implementations returned by their :meth:`~octoprint.plugin.WizardPlugin.get_wizard_details` diff --git a/scripts/octoprint.service b/scripts/octoprint.service index 14f5d7f4b..ae5405c34 100644 --- a/scripts/octoprint.service +++ b/scripts/octoprint.service @@ -6,7 +6,7 @@ Wants=network-online.target [Service] Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" -Type=simple +Type=exec User=pi ExecStart=/home/pi/OctoPrint/venv/bin/octoprint diff --git a/setup.py b/setup.py index 31efb1135..33c12b9b9 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ INSTALL_REQUIRES = [ "PyYAML>=5.3.1,<6", "pyserial>=3.4,<4", "netaddr>=0.7.19,<1", - "watchdog>=0.10.2,<1", + "watchdog==0.10.4", # watchdog dropped Py>3.6 on 0.10.5 point release... "sarge==0.1.5post0", "netifaces>=0.10.9,<1", "pylru>=1.2,<2", @@ -62,6 +62,7 @@ INSTALL_REQUIRES = [ "frozendict>=1.2,<2", "sentry-sdk>=0.15.1,<1", "filetype>=1.0.7,<2", + "zipstream-new>=1.1.8,<1.2", # vendor bundled dependencies "unidecode>=0.04.14,<0.05", # dependency of awesome-slugify "blinker>=1.4,<2", # dependency of flask_principal diff --git a/src/octoprint/cli/config.py b/src/octoprint/cli/config.py index 9468992ee..c45e56394 100644 --- a/src/octoprint/cli/config.py +++ b/src/octoprint/cli/config.py @@ -40,7 +40,7 @@ def _set_helper(settings, path, value, data_type=None): if name is not None: method = getattr(settings, name) - method(path, value) + method(path, value, force=True) settings.save() diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index 6012549b9..c724b9c35 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -792,7 +792,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): list: A list of paths to additional files whose modification to track for (in)validating the cache. Ignored if ``None`` is returned. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -807,7 +807,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): list: A list of paths representing the only files whose modification to track for (in)validating the cache. Ignored if ``None`` is returned. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -820,7 +820,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: str: An alternatively calculated ETag value. Ignored if ``None`` is returned (default). - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -838,7 +838,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: (list): A list of additional fields for the ETag generation, or None - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return default_additional @@ -851,7 +851,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: int: An alternatively calculated LastModified value. Ignored if ``None`` is returned (default). - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -877,7 +877,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: dict: Additional data to persist in the preemptive cache configuration. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -895,7 +895,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): dict: Additional request data to persist in the preemptive cache configuration and to use for request environment construction. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -911,7 +911,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: bool: Whether to suppress a record (True) or not (False, default) - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return False @@ -933,7 +933,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): and returning ``True`` to keep it and ``False`` to filter it out. If ``None`` is returned, no filtering will take place. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return default_template_filter @@ -953,7 +953,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): (list) A list of permissions which to check the current user session against. May be empty to indicate that no permission checks should be made by OctoPrint. - ..versionadded: 1.5.0 + .. versionadded: 1.5.0 """ from octoprint.access.permissions import Permissions @@ -1381,7 +1381,7 @@ class BlueprintPlugin(OctoPrintPlugin, RestartNeedingPlugin): and `the documentation for flask.Flask.errorhandler `_ for more information. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ from collections import defaultdict @@ -1580,7 +1580,7 @@ class SettingsPlugin(OctoPrintPlugin): from flask_login import current_user - from octoprint.access.permissions import Permissions + from octoprint.access.permissions import OctoPrintPermission, Permissions data = copy.deepcopy(self._settings.get_all_data(merged=True)) if self.config_version_key in data: @@ -1632,9 +1632,15 @@ class SettingsPlugin(OctoPrintPlugin): "never": lambda: False, } - for level, condition in conditions.items(): - paths_for_level = restricted_paths.get(level, []) - for path in paths_for_level: + for level, paths in restricted_paths.items(): + if isinstance(level, OctoPrintPermission): + condition = lambda: ( + current_user is not None and current_user.has_permission(level) + ) + else: + condition = conditions.get(level, lambda: False) + + for path in paths: restrict_path_unless(data, path, condition) return data @@ -1708,12 +1714,15 @@ class SettingsPlugin(OctoPrintPlugin): Retrieves the list of paths in the plugin's settings which be restricted on the REST API. Override this in your plugin's implementation to restrict whether a path should only be returned to users with - the SETTINGS permission, any logged in users, or never on the REST API. + certain permissions, or never on the REST API. - Return a ``dict`` with the keys ``admin``, ``user``, ``never`` mapping to a list of paths (as tuples or lists of - the path elements) for which to restrict access via the REST API accordingly. Paths returned for the ``admin`` - key will only be available on the REST API when access with admin rights, ``user`` will only be available when accessed - as a logged in user. ``never`` will never be returned on the API. + Return a ``dict`` with one of the following keys, mapping to a list of paths (as tuples or lists of + the path elements) for which to restrict access via the REST API accordingly. + + * An :py:class:`~octoprint.access.permissions.OctoPrintPermission` instance: Paths will only be available on the REST API for users with the permission + * ``admin``: Paths will only be available on the REST API for users with admin rights (any user with the SETTINGS permission) + * ``user``: Paths will only be available on the REST API when accessed as a logged in user + * ``never``: Paths will never be returned on the API Example: @@ -1724,12 +1733,15 @@ class SettingsPlugin(OctoPrintPlugin): user_only=dict(path="path", bar="bar")), another=dict(admin_only=dict(path="path"), field="field"), - path=dict(to=dict(never=dict(return="return")))) + path=dict(to=dict(never=dict(return="return"))), + the=dict(webcam=dict(data="webcam"))) def get_settings_restricted_paths(self): - return dict(admin=[["some", "admin_only", "path"], ["another", "admin_only", "path"],], - user=[["some", "user_only", "path"],], - never=[["path", "to", "never", "return"],]) + from octoprint.access.permissions import Permissions + return {'admin':[["some", "admin_only", "path"], ["another", "admin_only", "path"],], + 'user':[["some", "user_only", "path"],], + 'never':[["path", "to", "never", "return"],], + Permissions.WEBCAM:[["the", "webcam", "data"],]} # this will make the plugin return settings on the REST API like this for an anonymous user # @@ -1737,15 +1749,26 @@ class SettingsPlugin(OctoPrintPlugin): # user_only=dict(path=None, bar="bar")), # another=dict(admin_only=dict(path=None), # field="field"), - # path=dict(to=dict(never=dict(return=None)))) + # path=dict(to=dict(never=dict(return=None))), + # the=dict(webcam=dict(data=None))) # - # like this for a logged in user + # like this for a logged in user without the webcam permission # # dict(some=dict(admin_only=dict(path=None, foo="foo"), # user_only=dict(path="path", bar="bar")), # another=dict(admin_only=dict(path=None), # field="field"), - # path=dict(to=dict(never=dict(return=None)))) + # path=dict(to=dict(never=dict(return=None))), + # the=dict(webcam=dict(data=None))) + # + # like this for a logged in user with the webcam permission + # + # dict(some=dict(admin_only=dict(path=None, foo="foo"), + # user_only=dict(path="path", bar="bar")), + # another=dict(admin_only=dict(path=None), + # field="field"), + # path=dict(to=dict(never=dict(return=None))), + # the=dict(webcam=dict(data="webcam"))) # # and like this for an admin user # @@ -1753,9 +1776,10 @@ class SettingsPlugin(OctoPrintPlugin): # user_only=dict(path="path", bar="bar")), # another=dict(admin_only=dict(path="path"), # field="field"), - # path=dict(to=dict(never=dict(return=None)))) + # path=dict(to=dict(never=dict(return=None))), + # the=dict(webcam=dict(data="webcam"))) - ..versionadded:: 1.2.17 + .. versionadded:: 1.2.17 """ return {} @@ -1793,7 +1817,7 @@ class SettingsPlugin(OctoPrintPlugin): Returns: (dict, dict): A tuple consisting of two dictionaries, the first being the plugin's preprocessors for - getters, the second the preprocessors for setters + getters, the second the preprocessors for setters """ return {}, {} @@ -1807,8 +1831,8 @@ class SettingsPlugin(OctoPrintPlugin): Returns: int or None: an int signifying the current settings format, should be incremented by plugins whenever there - are backwards incompatible changes. Returning None here disables the version tracking for the - plugin's configuration. + are backwards incompatible changes. Returning None here disables the version tracking for the + plugin's configuration. """ return None @@ -1844,7 +1868,7 @@ class SettingsPlugin(OctoPrintPlugin): the differences to the defaults (in case the current data was persisted with an older version of OctoPrint that still duplicated default data). - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ import octoprint.util from octoprint.settings import NoSuchSettingsPath @@ -1987,7 +2011,7 @@ class SlicerPlugin(OctoPrintPlugin): Returns: (dict) a dictionary containing a valid extension subtree. - ..versionadded:: 1.3.11 + .. versionadded:: 1.3.11 """ from octoprint.filemanager import ContentTypeMapping @@ -2004,7 +2028,7 @@ class SlicerPlugin(OctoPrintPlugin): Arguments: profile_path (str): The base folder where OctoPrint stores this slicer plugin's profiles - ..versionadded:: 1.3.7 + .. versionadded:: 1.3.7 """ try: @@ -2029,7 +2053,7 @@ class SlicerPlugin(OctoPrintPlugin): # noinspection PyMethodMayBeStatic def get_slicer_profiles_lastmodified(self, profile_path): """ - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ import os diff --git a/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 b/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 index 0a9d041e5..c9f903f73 100644 --- a/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 +++ b/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 @@ -1,3 +1,3 @@ diff --git a/src/octoprint/plugins/announcements/static/js/announcements.js b/src/octoprint/plugins/announcements/static/js/announcements.js index 2e015853f..75720f39a 100644 --- a/src/octoprint/plugins/announcements/static/js/announcements.js +++ b/src/octoprint/plugins/announcements/static/js/announcements.js @@ -31,7 +31,7 @@ $(function () { 5 ); - self.unread = ko.observable(); + self.unread = ko.observable(false); self.hiddenChannels = []; self.channelNotifications = {}; diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index c9d85d444..366e03883 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -168,65 +168,14 @@ class BackupPlugin( @no_firstrun_access @Permissions.PLUGIN_BACKUP_ACCESS.require(403) def create_backup(self): - backup_file = self._build_backup_filename(settings=self._settings) data = flask.request.json exclude = data.get("exclude", []) + filename = self._build_backup_filename(settings=self._settings) - def on_backup_start(name, temporary_path, exclude): - self._logger.info( - "Creating backup zip at {} (excluded: {})...".format( - temporary_path, ",".join(exclude) if len(exclude) else "-" - ) - ) + self._start_backup(exclude, filename) - with self._in_progress_lock: - self._in_progress.append(name) - self._send_client_message("backup_started", payload={"name": name}) - - def on_backup_done(name, final_path, exclude): - with self._in_progress_lock: - self._in_progress.remove(name) - self._send_client_message("backup_done", payload={"name": name}) - - self._logger.info("... done creating backup zip.") - - self._event_bus.fire( - Events.PLUGIN_BACKUP_BACKUP_CREATED, - {"name": name, "path": final_path, "excludes": exclude}, - ) - - def on_backup_error(name, exc_info): - with self._in_progress_lock: - try: - self._in_progress.remove(name) - except ValueError: - # we'll ignore that - pass - - self._send_client_message( - "backup_error", payload={"name": name, "error": "{}".format(exc_info[1])} - ) - self._logger.error("Error while creating backup zip", exc_info=exc_info) - - thread = threading.Thread( - target=self._create_backup, - args=(backup_file,), - kwargs={ - "exclude": exclude, - "settings": self._settings, - "plugin_manager": self._plugin_manager, - "logger": self._logger, - "datafolder": self.get_plugin_data_folder(), - "on_backup_start": on_backup_start, - "on_backup_done": on_backup_done, - "on_backup_error": on_backup_error, - }, - ) - thread.daemon = True - thread.start() - - response = flask.jsonify(started=True, name=backup_file) + response = flask.jsonify(started=True, name=filename) response.status_code = 201 return response @@ -234,18 +183,8 @@ class BackupPlugin( @no_firstrun_access @Permissions.PLUGIN_BACKUP_ACCESS.require(403) def delete_backup(self, filename): - backup_folder = self.get_plugin_data_folder() - full_path = os.path.realpath(os.path.join(backup_folder, filename)) - if ( - full_path.startswith(backup_folder) - and os.path.exists(full_path) - and not is_hidden_path(full_path) - ): - try: - os.remove(full_path) - except Exception: - self._logger.exception("Could not delete {}".format(filename)) - raise + self._delete_backup(filename) + return NO_CONTENT @octoprint.plugin.BlueprintPlugin.route("/restore", methods=["POST"]) @@ -454,6 +393,76 @@ class BackupPlugin( # max upload size of 1GB for the restore endpoint return [("POST", r"/restore", 1024 * 1024 * 1024)] + # Exported plugin helpers + def create_backup_helper(self, exclude=None, filename=None): + """ + .. versionadded:: 1.6.0 + + Create a backup from a plugin or other internal call + + This helper is exported as ``create_backup`` and can be used from the plugin + manager's ``get_helpers`` method. + + **Example** + + The following code snippet can be used from within a plugin, and will create a backup + excluding two folders (``timelapse`` and ``uploads``) + + .. code-block:: python + + helpers = self._plugin_manager.get_helpers("backup", "create_backup") + + if helpers and "create_backup" in helpers: + helpers["create_backup"](exclude=["timelapse", "uploads"]) + + By using the ``if helpers [...]`` clause, plugins can fall back to other methods + when they are running under versions where these helpers did not exist. + + + :param list exclude: Names of data folders to exclude, defaults to None + :param str filename: Name of backup to be created, if None (default) the backup + name will be auto-generated. This should use a ``.zip`` extension. + """ + if exclude is None: + exclude = [] + if not isinstance(exclude, list): + exclude = list(exclude) + + self._start_backup(exclude, filename=filename) + + def delete_backup_helper(self, filename): + """ + .. versionadded:: 1.6.0 + + Delete the specified backup from a plugin or other internal call + + This helper is exported as ``delete_backup`` and can be used through the plugin + manager's ``get_helpers`` method. + + **Example** + The following code snippet can be used from within a plugin, and will attempt to + delete the backup named ``ExampleBackup.zip``. + + .. code-block:: python + + helpers = self._plugin_manager.get_helpers("backup", "delete_backup") + + if helpers and "delete_backup" in helpers: + helpers["delete_backup"]("ExampleBackup.zip") + + By using the ``if helpers [...]`` clause, plugins can fall back to other methods + when they are running under versions where these helpers did not exist. + + .. warning:: + + This method will fail silently if the backup does not exist, and so + it is recommended that you make sure the name comes from a verified source, + for example the name from the events or other helpers. + + :param str filename: The name of the backup to delete + """ + self._delete_backup(filename) + ##~~ CLI hook def cli_commands_hook(self, cli_group, pass_octoprint_ctx, *args, **kwargs): @@ -482,26 +491,24 @@ class BackupPlugin( ) if path is not None: - datafolder, backup_file = os.path.split(os.path.abspath(path)) + datafolder, filename = os.path.split(os.path.abspath(path)) else: - backup_file = self._build_backup_filename(settings=settings) + filename = self._build_backup_filename(settings=settings) datafolder = os.path.join(settings.getBaseFolder("data"), "backup") if not os.path.isdir(datafolder): os.makedirs(datafolder) - click.echo("Creating backup at {}, please wait...".format(backup_file)) + click.echo("Creating backup at {}, please wait...".format(filename)) self._create_backup( - backup_file, + filename, exclude=exclude, settings=settings, plugin_manager=cli_group.plugin_manager, datafolder=datafolder, ) click.echo("Done.") - click.echo( - "Backup located at {}".format(os.path.join(datafolder, backup_file)) - ) + click.echo("Backup located at {}".format(os.path.join(datafolder, filename))) @click.command("restore") @click.argument("path") @@ -638,6 +645,82 @@ class BackupPlugin( ##~~ helpers + def _start_backup(self, exclude, filename=None): + if filename is None: + filename = self._build_backup_filename(settings=self._settings) + + def on_backup_start(name, temporary_path, exclude): + self._logger.info( + "Creating backup zip at {} (excluded: {})...".format( + temporary_path, ",".join(exclude) if len(exclude) else "-" + ) + ) + + with self._in_progress_lock: + self._in_progress.append(name) + self._send_client_message("backup_started", payload={"name": name}) + + def on_backup_done(name, final_path, exclude): + with self._in_progress_lock: + self._in_progress.remove(name) + self._send_client_message("backup_done", payload={"name": name}) + + self._logger.info("... done creating backup zip.") + + self._event_bus.fire( + Events.PLUGIN_BACKUP_BACKUP_CREATED, + {"name": name, "path": final_path, "excludes": exclude}, + ) + + def on_backup_error(name, exc_info): + with self._in_progress_lock: + try: + self._in_progress.remove(name) + except ValueError: + # we'll ignore that + pass + + self._send_client_message( + "backup_error", payload={"name": name, "error": "{}".format(exc_info[1])} + ) + self._logger.error("Error while creating backup zip", exc_info=exc_info) + + thread = threading.Thread( + target=self._create_backup, + args=(filename,), + kwargs={ + "exclude": exclude, + "settings": self._settings, + "plugin_manager": self._plugin_manager, + "logger": self._logger, + "datafolder": self.get_plugin_data_folder(), + "on_backup_start": on_backup_start, + "on_backup_done": on_backup_done, + "on_backup_error": on_backup_error, + }, + ) + thread.daemon = True + thread.start() + + def _delete_backup(self, filename): + """ + Delete the backup specified + Args: + filename (str): Name of backup to delete + """ + backup_folder = self.get_plugin_data_folder() + full_path = os.path.realpath(os.path.join(backup_folder, filename)) + if ( + full_path.startswith(backup_folder) + and os.path.exists(full_path) + and not is_hidden_path(full_path) + ): + try: + os.remove(full_path) + except Exception: + self._logger.exception("Could not delete {}".format(filename)) + raise + def _get_backups(self): backups = [] for entry in scandir(self.get_plugin_data_folder()): @@ -1331,3 +1414,7 @@ __plugin_hooks__ = { "octoprint.events.register_custom_events": _register_custom_events, "octoprint.server.sockjs.emit": __plugin_implementation__.socket_emit_hook, } +__plugin_helpers__ = { + "create_backup": __plugin_implementation__.create_backup_helper, + "delete_backup": __plugin_implementation__.delete_backup_helper, +} diff --git a/src/octoprint/plugins/corewizard/templates/corewizard_onlinecheck_wizard.jinja2 b/src/octoprint/plugins/corewizard/templates/corewizard_onlinecheck_wizard.jinja2 index 6d8a71898..d8715540e 100644 --- a/src/octoprint/plugins/corewizard/templates/corewizard_onlinecheck_wizard.jinja2 +++ b/src/octoprint/plugins/corewizard/templates/corewizard_onlinecheck_wizard.jinja2 @@ -11,7 +11,7 @@ OctoPrint comes preconfigured to perform the connectivity check every 15 minutes. You may change the value here. {% endtrans %}

-
+ {% include "snippets/settings/server/serverOnlineCheckInterval.jinja2" %}
@@ -21,7 +21,7 @@ trust and that has a high availability. {% endtrans %}

-
+ {% include "snippets/settings/server/serverOnlineCheckHost.jinja2" %} {% include "snippets/settings/server/serverOnlineCheckPort.jinja2" %} {% include "snippets/settings/server/serverOnlineCheckTestConnectivity.jinja2" %} @@ -34,7 +34,7 @@ side with the general connectivity check, leave the field empty. {% endtrans %}

- +
{% include "snippets/settings/server/serverOnlineCheckName.jinja2" %} {% include "snippets/settings/server/serverOnlineCheckTestResolution.jinja2" %} @@ -47,8 +47,12 @@ {% endtrans %}