106 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
8f2520b327
backups: Allow selecting a single app from URL when creating backup
Take app_id in a URL fragment and fill that as the default selected app in
create backup form. This URL can be used in apps to create a backup link.

Tests:

- Visit /plinth/sys/backups/create/bepasty/. Only bepasty app will be selected.

- Visit /plinth/sys/backups/create/foo/. No apps are selected.

- Visit /plinth/sys/backups/create/. All apps are selected.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-02-12 13:29:54 -05:00
Sunil Mohan Adapa
9a4905e832
backups: Use privileged decorator for backup actions
Tests:

- DONE: Functional tests works
- DONE: Initial setup works
  - DONE: Borg repository is created at /var/lib/freedombox/borgbackup
- DONE: With regular and with encrypted repository
  - DONE: Creating a repository works
  - DONE: Getting information works. When adding a existing location, incorrect
    password leads to error in the add form.
  - DONE: Listing archives works
  - DONE: Creating/restoring an archive works
    - DONE: Backup manifest is created in /var/lib/plinth/backups-manifests/
    - DONE: Including an app that dumps/restores its settings works
  - DONE: Exporting an archive as tar works
    - DONE: Exporting a large archive yields reasonable download speeds. 31
      MB/s. 1GB file in about 30 seconds.
  - DONE: Restoring from an uploaded archive works
  - DONE: Listing the apps inside an archive works before restore
- DONE: Errors during operations are re-raises as simpler errors
  - DONE: Get info
  - DONE: List archives
  - DONE: Delete archive (not handled)
  - FAIL: Export tar
  - DONE: Init repo
  - DONE: Get archive apps (not handled)

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:53:57 -04:00
Sunil Mohan Adapa
2d3681605e
backups: Use generic form template for create and schedule views
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-09-03 17:28:59 -04:00
Sunil Mohan Adapa
2eca38299f
backups: Use AppView for the main app page
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-29 08:28:58 -04:00
Sunil Mohan Adapa
900c0d30b9
*: Drop module level app property
module.app property usage is greatly reduced because setup() and force_upgrade()
method are now part of App class instead of at the module level. Remove the
remaining minor cases of usage and drop the property altogether.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:29 -04:00
Sunil Mohan Adapa
3c7bc4a192
*: pylint: Explicitly specify encoding when open a file
This is recommended by PEP-0597: https://peps.python.org/pep-0597/

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-04 19:45:57 -04:00
Sunil Mohan Adapa
74214c18ae
*: Use Django gettext functions instead of ugettext
- ugettext functions will be removed in Django 4.0. Each use emits a warning
when running with Django 3.2. Since we have warnings enabled in developer mode,
we see quite a few messages because of this.

- ugettext is already a simple alias of gettext. So, no regressions are
expected.

Tests:

- Accessing an affected app in UI with Django 3.2 and Django 2.2 works fine.

- Using Django 3.2 there are no warnings related to removal of ugettext
functions.

- Ran regular unit tests.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-09-20 16:50:16 -04:00
Sunil Mohan Adapa
d4e9e7a965
backups: Add a notification to suggest users to enable schedules
Tests performed:

- Ensure that backups module is setup from version zero by deleting entry in DB.
Start FreedomBox. Observe the notification comes up.

- Dismiss button dismiss the notification.

- Go to button takes us to the backups module.

- Incrementing the version number of the backups app does not show the
notification again.

- Starting with old code, the notification show up when FreedomBox is run.
Incrementing the version number of the backups app after that does not show the
notification again.

- Enable a schedule and the notification should be dismissed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-01-21 20:56:05 -05:00
Sunil Mohan Adapa
eb526275c7
backups: Add UI to edit schedules
Closes: #1529.

Tests performed:

- Functional tests for backups app work.

- Functional tests for backup of several apps work.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-01-21 20:55:27 -05:00
Sunil Mohan Adapa
8c161431ba
backups: repository: Simplify handling of remote repo properties
- Simplify save() method such that a simple load(uuid).save() does not destroy
data. Currently, the verified parameter is lost.

- Drop unused store_credentials argument to save().

- Make verified a property of the SSH repository and instantiate with
it properly.

Tests performed:

- Adding a new remote repository works with SSH verification from unknown and
known hosts.

- Mounting and unmounting works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-01-21 20:47:06 -05:00
Sunil Mohan Adapa
fb1898befc
backups: Use the backup component in all apps
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2021-01-04 13:47:38 +02:00
Sunil Mohan Adapa
b1f64bb7bd
backups: i18n: Mark form success messages for translation
Helps: #1938.

Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
[sunil: Also mark restore success message]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-10-20 11:57:03 -07:00
Sunil Mohan Adapa
c3eac2c02e
storage: Use mount info instead of disk info for free space warning
Tests:

- In a container, fill up space. Start FreedomBox in develop mode wait 3 minutes
for storage warning to show.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-27 11:00:50 -04:00
Joseph Nuthalapati
f13ad07ecb
backups: Add optional field - Name
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Perform validation for name field]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-05-18 21:38:58 -07:00
Sunil Mohan Adapa
9368504da5
*.py: Use SPDX license identifier
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-02-19 14:38:55 +02:00
Sunil Mohan Adapa
b576a77c3d
app: Refactor all apps to use the Info component
- Remove the need to pass all the individual information elements to the AppView
  separately. This eliminates many issues with elements that were mistakenly not
  sent to AppView. Also reduces a lot of code duplication.

- Create App classes for power and sso for consistency.

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-02-16 18:22:01 -05:00
Alice Kile
88b8ff3d62
backups: fix title not appearing
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2019-11-21 20:07:40 +05:30
Sunil Mohan Adapa
d9d9c8167f
backups: Show error when there are no disks available to add repo
When there are no additional disks available, don't show an empty drop down
for disks and throw an error when submitting. Instead make it clear that no
additional disks are available and that is why repository can't be created.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:53:17 -04:00
Sunil Mohan Adapa
0465ce0efd
backups: Handle errors when adding disk repository
- Simplify repository initialization using inheritance.

- Share the code for saving repository for disk and remote repositories. Error
  messages are properly handled for disk repositories too.

- Move logic to create remote SSH directory to SSH repository class instead of
  views.

- Create a new error for handling borg repository already existing while
  initialization.

- Get information of repository after initializing so that password errors are
  caught early.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:53:03 -04:00
Sunil Mohan Adapa
063587f7ac
backups: Minor simplification when adding remote repository
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:53:00 -04:00
Sunil Mohan Adapa
7467fa4553
backups: Separate repository loading from instantiation
The constructor of the Repository object is being used for two distinct
purposes. One is to load the object from database and other to instantiate it
with parameter such that it can be saved to database. Separating the two usages
to different methods simplifies code and parameter passing for consumers.

Also turn some class specific constants from globals to class constants.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:49 -04:00
Sunil Mohan Adapa
5b01689a92
backups: Clarify two separate uses of name create_repository
It is being used to mean initialize the borg repository as well as creating an
instance of the repository class object. Use 'initialize' for former and
'get_instance' for latter.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:46 -04:00
Sunil Mohan Adapa
6c14e34875
backups: Implement hostname property on SSH repository
Use repository class instances instead of custom ad-hoc data structures such as
repo_data.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:44 -04:00
Sunil Mohan Adapa
0eb2db3f9a
backups: Use higher level method in views instead of store methods
Make store an internal implementation detail of the repository class and achieve
better abstraction.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:41 -04:00
Sunil Mohan Adapa
68fed450a9
backups: Rename remove_repository method to remove
Since the method is being called on Repository classes, _repository suffix is
redundant.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:30 -04:00
Sunil Mohan Adapa
e8b324eece
backups: Minor cosmetic fixes
- Remove some pylint warnings

- Add documentation strings.

- Yapf auto-formatting.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:22 -04:00
Sunil Mohan Adapa
0b0791d78f
backups: Introduce method for checking if a repository is usable
get_repositories method will return repositories instead of dictionaries for
view content. This will make it usable in more situations.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:20 -04:00
Sunil Mohan Adapa
0df07f5cf2
backups: Rename network_storage module to store
Same module is being used to store/retrieve local disk repositories also.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:17 -04:00
Sunil Mohan Adapa
5df34d1927
backups: Simplify listing repositories in index page
- Use sort_order property to decide which type of repositories should be listed
  first.

- Remove getting repositories of a given type and retrieve all of them at the
  same time.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:14 -04:00
Sunil Mohan Adapa
b5d7a910dd
backups: Simplify checking repository capabilities using flags
Also make storage_type an abstract property so that derived classes are forced
to override it.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:11 -04:00
Sunil Mohan Adapa
5136304212
backups: Fix removing local repository
- Remove incorrect instantiation of SSH repository for local disk repositories.

- Clarify the removal message to convey that backups are not removed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:52:08 -04:00
Joseph Nuthalpati
de4a019063
backups: Save new backup location to plinth database
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:51:58 -04:00
Joseph Nuthalpati
7c7ad6d56a
backups: Refactor class hierarchy in repository.py
- Reduce repetition between various kinds of BorgBackup repositories

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil@medhas.org Undo blank line removals]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:51:54 -04:00
Joseph Nuthalpati
8a93b5b90c
backups: Allow adding backup repositories on multiple disks
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil@medhas.org Fix showing form choices, undo blank line removals]
[sunil@medhas.org Fix typo in tooltip for add repo button]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-07 12:51:40 -04:00
Joseph Nuthalapati
caf1e4b0bd
flake8: Remove unused import
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-07-29 14:09:31 -07:00
Joseph Nuthalapati
c2cb187d91
backups: Make UI more consistent with other apps
- Replace subsubmenu with buttons
- Left align icons in table header (restore and delete)
- Replace the technical term "repository" with "location"
- Confirmation dialogs shouldn't have app name, description, manual etc.
- Confirmation dialogs don't need Cancel buttons

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
[sunil@medhas.org: Remove 'primary' for all but one button]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-07-29 14:09:12 -07:00
Joseph Nuthalapati
c952dc7a99
backups: Change "select all" to a pure JavaScript implementation
- Remove Python code to handle the extra item in the submitted form
- The select-all checkbox is never submitted in the form since it is missing the
  "name" attribute
- Replace selector ':checkbox' with the faster selector '[type=checkbox]'

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-07-13 06:37:43 -04:00
Joseph Nuthalapati
061c308e35
backups: Add option to select/deselect all apps for backup or restore
This is less tiresome for users and also improves the speed of functional tests.

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-07-13 06:37:39 -04:00
Sunil Mohan Adapa
6821d73025
backups: Minor cleanup
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:45:20 +05:30
Sunil Mohan Adapa
fa3e2ea86b
backups: Fix issue with verifying SSH host keys
Ensure that the fingerprint accepted is the one verified by user. If they
fingerprints and public keys are retrieved separately, there is chance that what
was verified by the user is not what is added to the known hosts file.

- Avoid creating a temporary file when fetching keys

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:44:43 +05:30
Sunil Mohan Adapa
463c620c65
backups: Remove known_hosts file from config file
- There is no compelling reason to make the file configurable. Simplifies
  configuration file if we make it relative to FreedomBox data directory.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:44:34 +05:30
Sunil Mohan Adapa
76efccce37
backups: Fix and refactor adding a new remote repository
- Fix encrypted repositories getting created without encryption.

- Set verified=False by during save operation for safety.

- Handle common error scenarios and show proper messages. Such as authentication
  failure.

- Use pathlib to simplify file handling code.

- Split nested code for readability and do better function splits.

- Expand ~ only if it is at the beginning of the path.

- Allow empty repository path as allowed by SSH.

- Don't internationalize log messages.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:44:18 +05:30
Sunil Mohan Adapa
661a00198e
backups: Minor styling changes
- Add docstrings.

- Add blank lines for extra readability.

- Use <span> instead of <i> tag for icon in template.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:43:49 +05:30
Sunil Mohan Adapa
984b7dca88
backups: Cleanup auto-mounting SSH repositories
Remove auto-mounting of repositories during instantiation entirely. It is better
to explicitly mount later.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:43:40 +05:30
Joseph Nuthalapati
bd1874d774
backups: Add regex validation for ssh_repository field
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:43:08 +05:30
Joseph Nuthalapati
2c97e1e02e
backups: Read file path of known_hosts directly from plinth.config
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:43:02 +05:30
Joseph Nuthalapati
795ed9d735
backups: Remove unnecessary context manager for paramiko SFTPClient
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:42:56 +05:30
Joseph Nuthalapati
3a6dcbe7a7
Verify SSH hostkey before mounting
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:42:41 +05:30
Joseph Nuthalapati
de7275d4a5
backups: ssh remotes: Refactoring
- Make url scheme consistent
- Add an FA icon to the drop-down button in VerifySshHostkeyView
- Refactoring to reduce code duplication

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:42:31 +05:30
Joseph Nuthalapati
0b43caf81d
Add SSH hostkey verification
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:42:25 +05:30