5635 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
5d3c010b2e
main: List dependencies without writing to disk
- Don't run the second phase of web framework initialization. This avoids
writing to the DB file.

- Set log level to ERROR so that no messages get printed even to stderr while
listing dependencies.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:02:02 -04:00
Sunil Mohan Adapa
a145742ebc
log: Allow setting the default log level before log configuration
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:02:00 -04:00
Sunil Mohan Adapa
e5177289dc
web_framework: Don't create Django secret key when listing depends
This allows --list-dependencies to run without having to write to disk.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:57 -04:00
Sunil Mohan Adapa
28fe8c8c3e
web_framework: Split initialization into two parts
A simple Django configuration does not need to create the database whereas DB
migration requires creating the database.

In some operations such as listing dependencies, we can skip running the second
part and so writing to database will no longer be necessary during such
operations.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:55 -04:00
Sunil Mohan Adapa
91c4d6742e
cfg: In develop mode, use /var/lib for DB and sessions
- Only effects develop mode.

- To primarily avoid writing to the source code directory. Multiple containers
or VMs using the source folder won't fight with the database file (the overlay
file system plan is not working out well for containers #1873).

- In the earlier days, we used to allow running from source code directory
without even doing ./setup.py install. Currently it is not possible anyway. We
pretty much install freedombox package before running from source directory.

- If the build process itself learns not to write to source directory, then
containers/VMs won't have to write to source directory at all.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:53 -04:00
Sunil Mohan Adapa
a2281aaf07
cfg: Remove comments in test data
The file is not meant for human reading. The comments are already part of the
code.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:50 -04:00
Sunil Mohan Adapa
a33160d6a4
cfg: Remove redundant data in develop.config
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:47 -04:00
Sunil Mohan Adapa
3dfceda785
frontpage: Read from .d files too
Read from following paths:

/etc/freedombox/custom-shortcuts.json
/etc/freedombox/custom-shortcuts.json.d/*.json
/etc/plinth/custom-shortcuts.json
/etc/plinth/custom-shortcuts.json.d/*.json
/var/lib/freedombox/custom-shortcuts.json
/var/lib/freedombox/custom-shortcuts.json.d/*.json
/usr/share/freedombox/custom-shortcuts.json
/usr/share/freedombox/custom-shortcuts.json.d/*.json

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:45 -04:00
Sunil Mohan Adapa
4ea2e755db
frontpage: Load shortcuts from .d directories too
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:43 -04:00
Sunil Mohan Adapa
aaa306aef5
cfg: Read configuration from .d files and multiple locations
- Read configuration files from three different locations.
/usr/share/freedombox/freedombox.config, /etc/plinth/plinth.config and
/etc/freedombox/freedombox.conf. Later listed has higher priority.

- Provide backward compatibility for /etc/plinth/plinth.config files. With lower
priority than /etc/freedombox but higher priority than /usr/share/.

- Read sorted files from config.d directories with the same suffix as original
configuration file. Parse them by priority. This allows administrator/programs
to drop in configuration bits without worry about editing files.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:40 -04:00
Sunil Mohan Adapa
823735729b
d/tests/control: Rename Plinth to FreedomBox in a comment
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:38 -04:00
Sunil Mohan Adapa
6b1622bcec
cfg: Rename configuration file to freedombox.config
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:35 -04:00
Sunil Mohan Adapa
50ef5861d0
cfg: Move /plinth.config to plinth/develop.config
- Avoid a top level source code file.

- Makes it clear that the configuration file is only meant for development
purposes.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:33 -04:00
Sunil Mohan Adapa
62fc33e12c
cfg: Eliminate the need for 'root' directory in configuration
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:31 -04:00
Sunil Mohan Adapa
40663b7b5a
context_processor: tests: Use already available config fixture
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:28 -04:00
Sunil Mohan Adapa
8d2c33bf71
cfg: For develop mode, overlay on top of regular configuration
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:25 -04:00
Sunil Mohan Adapa
2a38e60d1c
cfg: Allow loading multiple configuration files
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:23 -04:00
Sunil Mohan Adapa
9def9750c0
frontpage: Drop empty custom shortcut files
Installing an empty file in /etc/ that is meant to be modified is an unnecessary
invitation to upgrade issues.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:20 -04:00
Sunil Mohan Adapa
5b579ff06d
frontpage: Read custom shortcuts from multiple locations
Read from /etc/plinth, /usr/share/plinth and /var/lib/plinth.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:17 -04:00
Sunil Mohan Adapa
4263f9e2c8
cfg: Drop the default configuration file
- The configuration module defaults to values in the production configuration
file.

- If the file is found, it is read and the read values overwrite the defaults.
If the file is not found, no error is raised. This allows us to not ship the
configuration file. User may create the configuration if they want to change the
defaults. This eases upgrades when configuration is edited. This also make
FreedomBox robust to deployments where /etc/ is not populated by default such as
OSTree. It is also a good practice for daemons as followed by the likes of
systemd.

- If the file partly populated only the values read override the defaults and
the remaining values don't change. This allows the user to write simpler
configuration file.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:15 -04:00
Sunil Mohan Adapa
64b1c21fe0
cfg: Don't fallback to develop config if main is not found
This was needed when our behavior for reading production vs. development
configuration depended on the presence of configuration files in expected
locations. The current behavior is based on whether --develop option is given or
not. This behavior is safer and more predictable.

So, remove the option to fallback to develop configuration if the production
configuration is not found.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:12 -04:00
Jens Molgaard
6230f8e6ce
Translated using Weblate (Danish)
Currently translated at 42.7% (547 of 1281 strings)
2020-06-28 21:30:31 +02:00
Sunil Mohan Adapa
6f30e12cd7
views: Drop use of private Django utility
We are currently using django.utils.http.is_safe_url which is a private method
and may break API anytime. Replace it with similar but limited implementation.

Tests:

- Unit tests.

- Dismiss a notification and the redirect to the same page happens properly.

- Logout, goto to home page or login page. Change the language and it will
redirect back to home page or login page appropriately.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-27 16:03:15 -04:00
Sunil Mohan Adapa
5a126e62a8
notifications: Fix issue with redirection on dismiss
The request variable is not available when a custom template is used to render a
notification. Fix this by passing the template rendering context additional
request variable.

Closes: #1887.

Tests:

- Reduce the version number in data for 'upgrades-new-release' notification
in the plinth_storednotification table in the DB. Start FreedomBox. New release
message will appear. Go to page other than home page. The dismiss button has
next= parameter filled properly with current URL. Dismiss the notification and
notice that page URL stays the same.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-27 16:03:12 -04: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
Sunil Mohan Adapa
64ff37e83f
storage: Don't log exception of disk space check fails
When running inside a container, it is not possible to retrieve information
about the disk that is mounted on '/'. Ignore errors in such cases.

Tests performed:

- Inside a container, start the service using freedombox-devel. Every 3 minutes
a check for disk space will be done in developer mode. If UDisks is being used
as source of information, the free space check will fail with an error logged.

- With the changes, the error is not shown.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Tested-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-27 11:00:46 -04:00
Veiko Aasa
29813696c6
functional-tests: Remove unnecessary wait when navigating to module
The fixture splinter_browser_load_condition already waits until a page
is loaded.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-06-26 08:32:56 -07:00
Éfrit
4c742d690e
Translated using Weblate (French)
Currently translated at 98.7% (1265 of 1281 strings)
2020-06-25 21:41:44 +02:00
James Valleroy
0f54fab067
apt: Run dpkg --configure -a before other actions
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-06-25 11:54:55 -07:00
James Valleroy
5424e1e23f
apt: Run apt-get -f install before other commands
Run `apt-get --fix-broken install` before installing package or manual
update. This will attempt to correct broken dependencies.

Tests:
- Install a package without its dependencies using `dpkg -i`.
- Both app install and manual update successfully recover from this
  situation.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-06-25 11:54:45 -07:00
Veiko Aasa
bf53fd8b17
functional-tests: Fix page not fully loaded errors when taking backups
- Use a submit() function to wait for a update when visiting app pages.
This prevents failures on pages which have custom javascript,
including the backup app. Those errors are more common if the server
hardware is slower.

- Remove unnecessary wait_for_page_update() as submit() already waits
for a page update.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-06-25 10:50:51 -07:00
Sunil Mohan Adapa
7f7f4cfb52
container: Remove sqlite3 file early enough
During --list-dependencies if an old sqlite3 file is present with gitweb
enabled, then a2enconf -c gitweb-freedombox-auth get executed. In this case,
setting up apache2 module fails because authpubtkt tokens are not yet generated
but they are being referred to in the configuration files.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-06-25 01:21:39 +03:00
Pavel Borecki
a988828f73
Translated using Weblate (Czech)
Currently translated at 79.0% (1012 of 1281 strings)
2020-06-24 13:41:46 +02:00
Michael Breidenbach
8892029268
Translated using Weblate (Swedish)
Currently translated at 100.0% (1281 of 1281 strings)
2020-06-24 13:41:46 +02:00
Sunil Mohan Adapa
cf9f086e6f
Translated using Weblate (Telugu)
Currently translated at 64.2% (823 of 1281 strings)
2020-06-24 13:41:46 +02:00
Fioddor Superconcentrado
7d0647319a
Translated using Weblate (Spanish)
Currently translated at 100.0% (1281 of 1281 strings)
2020-06-24 13:41:45 +02:00
Michael Breidenbach
b80bd00d5d
Translated using Weblate (German)
Currently translated at 100.0% (1281 of 1281 strings)
2020-06-24 13:41:44 +02:00
James Valleroy
2c1a868567
storage: Handle multi-line text in functional test
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:43 -04:00
Sunil Mohan Adapa
3fd0921e0f
backups: Remove an unnecessary print() statement
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:41 -04:00
Sunil Mohan Adapa
e59f9ac3fc
storage: Ignore eject failures if filesystems unmounted properly
Not all disks can be ejected. For example, SATA disks can't be ejected. However,
they can be removed as long as all filesystems are unmounted properly. Ignore
errors during ejecting of a disk.

Closes: #1597.

Tests performed:

- In VirtualBox, attach a SATA disk, format it with two partitions. See them
auto-mounted by FreedomBox. Eject one of the partitions, both partitions are
unmounted but operation does not fail despite SATA disks not being eject-able.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:39 -04:00
Sunil Mohan Adapa
d3b5143ed6
storage: Allow ejecting any device not in fstab or crypttab
Allow any disk including SATA disks to be ejected.

Helps: #1597.

Tests performed:

- Attach SATA disk to VirtualBox. Create two partitions and filesystem in it.
FreedomBox will auto-mount the filesystems. Eject button is shown on both the
partitions. Without the patch, this is not shown.

- Eject button is not shown against '/' as it is part of fstab.

- Add a device into /etc/fstab. Eject button will not be shown against the
device.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:37 -04:00
Sunil Mohan Adapa
426cef4c2c
storage: Don't auto-mount loopback devices except in develop mode
In the event containers are being used on the server with images, attempting to
auto-mounting loop devices could interfere with their operation. We currently
don't have a use case where a user would want to auto-mount loop devices.
Initially suggested in
https://salsa.debian.org/freedombox-team/freedombox/-/issues/1854

Tests performed:

- Add a loopback device as follows and observe that is automatically mounted.

  dd if=/dev/zero of=/tmp/test_disk bs=1M count=100
  mkfs.ext4 /tmp/test_disk
  losetup loop0 /tmp/test_disk
  umount /dev/loop0
  losetup -d /dev/loop0

- Add a loopback device as follows and observe that both partitions are mounted.

  dd if=/dev/zero of=/tmp/test_disk bs=1M count=100
  parted /tmp/test_disk
  mklabel gpt
  mkpart Part1 ext4 0% 50%
  mkpart Part2 ext4 50% 100%
  kpartx -avs /tmp/test_disk
  mkfs.ext4 /dev/mapper/loop0p1
  mkfs.ext4 /dev/mapper/loop0p2
  umount /dev/mapper/loop0p1
  umount /dev/mapper/loop0p2
  kpartx -dvs /tmp/test_disk

- When --develop is removed or when code is modified to negate the not
  condition, the partitions are not auto-mounted in the above cases.

Reported-by: James Valleroy <jvalleroy@mailbox.org>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:35 -04:00
Sunil Mohan Adapa
8c05fb0722
storage: Remove rule to not automount system disks with no paritions
This rule imported originally from udiskie's defaults seems somewhat arbitrary.
We attach a SATA drive with partitions, it mounts them. However, if the entire
drive is a file system, it does not auto-mount.

Tests performed:

- In VirtualBox, attach a SATA drive. Create two partitions and filesystems in
them. Both filesystems are auto-mounted.

- In VirtualBox, attach a SATA drive. Format the entire drive as a filesystem.
The filesystem is auto-mounted.

- Same behavior is observed with loop devices.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:33 -04:00
Sunil Mohan Adapa
d4ce843e22
storage: Don't show empty progress bar for disks not mounted
In future, we may consider showing disks that are not mounted and allow mounting
them manually or unlocking encrypted volumes manually. Prepare for that
scenario.

Tests performed:

- Edit get_disks() code to show not mounted disks. The progress bar or free
space information should not be shown.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:31 -04:00
Sunil Mohan Adapa
10b46f1968
storage: Use UDisks information as primary source
Rename get_disks() to get_mounts() and use it in for backups and samba shares.

Create a new get_disks() similar to get_mounts() but use df information only for
showing free space. This inverts the importance of 'df' and UDisks. Use UDisks
as primary source of information for showing list of disks and then use df to
fill in the free space information.

- Retrieve all the mount points of a device and return them as part of
get_disks() in an extra 'mount_points' property.

- For storage listing, this fixes showing up of /.snapshots as separate disk and
showing of vboxsf, network mounts etc. Only shows mounts that are related to
block devices.

- Update various uses of get_disks() within storage module to use
'mounts_points' instead of 'mount_point' to be accurate in cases where there are
multiple mounts for a given device. Use get_mounts() where appropriate instead.

- Display all the mount points against a devices in multiple lines.

- Also show devices that are not currently mounted.

Tests performed:

- Filling up a disk shows a disk space warning properly. Warning contains the
  free disk space correctly.

- Calling get_root_device(get_disks()) return the correct root device.

- In Deluge, the download directory contains a list of all samba current shares.
  If a disk with samba share is unmouted, it does not show up in the list.

- In the Samba app page, all disks are shown properly. Root disk is shown as
  'disk'. All other mount points such as .snapshots and /vagrant also show up.

- In the Samba app page, unavailable shares list shows up when a disk with a
  share is unmounted.

- Upload a backup, warning on the form shows available disk space properly.

- When adding a backup location. The list includes all mount points. Duplicated
  mount points are not shown. Root disk is not shown in the list. When all the
  disks are used up for backup location, a warning that no additional disks are
  available is shown.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:29 -04:00
Sunil Mohan Adapa
955dfea866
storage: Fix regression with showing error messages
In ed09028fcd2c850c3b87b65de66187b214190150, when eject was made to run as
superuser inside storage action, parsing of the error messages was not handled
properly. Fix it to show simple error messages about why the eject was not
successful.

Tests performed:

- In a terminal, switch to the directory where a disk is mounted to keep the
mount point busy. Attempt to eject the disk. A large stack trace is shown
without the patch and a clean error message is shown with it.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:27 -04:00
Sunil Mohan Adapa
225d86e344
storage: Use DBus directly for listing disks
Bring us closer to avoiding the use of two different methods to access UDisks
DBus API: UDisks2 client library and direct DBus access with GDBus.

Perform formatting of the bytes outside of udisks2 module to avoid depending on
Django.

Tests performed:

- Visit the storage page. Disks are listed properly.

- Sizes are formatted to be human readable.

- Filesystem type is show properly: ext4, btrfs

- Labels for disks are shown as set by tune2fs etc.

- Device paths are shown properly.

- Mount point is shown properly.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:24 -04:00
James Valleroy
34a28e35c9
upgrades: Append unattended-upgrades-dpkg.log for more detail
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-06-23 20:14:30 -07:00
Veiko Aasa
0c59dbb0e4
functional-tests: Skip tests if app is not available in distribution
Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-06-22 15:21:26 -07:00
Veiko Aasa
f97902615b
functional-tests: Handle connection error when web server restarts
Catch exeptions if web server restarts on form submit.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-06-22 15:20:21 -07:00