39 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
770974c8ce
sso: Switch to django-axes >= 5.0
- Add explicit dependency on django-ipware >=3. django-axes >= 6 adds
only and optional dependency on django-ipware. Adding explicit dependency make
the behavior safer.

- Depend on django-axes >= 5 where the authentication backend and other features
are available. The new code won't work with older versions. The new approach
uses and authentication backend to deny access to the login form on lockout and
a middleware to redirect user to locked out form when limit of attempts have
been reached.

- Drop old code used for compatibility with django-axes 3.x.

- Suppress verbose and debug messages as django-axes is too chatty.

- Re-implment the CAPTCHA form entirely. In the old style, we have a login form
with CAPTCHA field. That would not work with the new django-axes authentication
middle. On submission of the form, auth.authenticate() will be called. This
call invokes various authentication backends include django-axes authentication
backend. This backend's behavior is to reject all authentication attempts when
the IP is listed in locked table. The new approach is to provide a simple
CAPTCHA form with just the CAPTCHA field. If the form is successfully
validated (correct CAPTCHA is provided), then the lock on the IP address is
reset. The user is then free to perform 3 more attempts to login.

- Update firstboot form to send the request parameter when using
auth.authenticate() method. This needed by Django axes' authentication method
which will be triggered.

Tests:

- Run tests on Debian Bookworm and Debian testing.

- Axes verbose messages and debug messages are not printed on the console when
running FreedomBox in debug mode.

- Only three invalid attempts are allowed at the login page. After the final
incorrect attempt, user is redirected to CAPTCHA page. Visiting the login page
using the URL works but entering the correct credentials still takes the user to
CAPTCHA page.

- CAPTCHA form appears as expected. Clicking the CAPTCHA images downloads the
audio file corresponding to the image. Incorrect CAPTCHA shows an error. Correct
CAPTCHA takes the user to login form where they are able to login with correct
credentials. Entering incorrect credentials 3 times will take the user again to
CAPTCHA page.

- Creating user account during firstboot works.

- Blocked IP address the IP of the client such as 10.42.0.1 and not the local IP
address 127.0.0.1 according the django-axes log messages. While one client IP
address is blocked, another IP is able to login to the same user account that
was attempted by the blocked client.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-08-23 21:47:39 -04:00
James Valleroy
4920e33160
version: Compare Debian package version numbers
Provides a Version class wrapper around apt_pkg.version_compare.

Replaces distutils.version which is deprecated.

Closes: #2261.

Tests:

- Install ejabberd.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Add two more version comparison tests]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2022-09-08 21:38:58 -07:00
Sunil Mohan Adapa
bfa11beb73
*: pylint: Don't inherit from 'object'
- This was required in Python 2 but useless in Python 3.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-04 19:46:15 -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
Joseph Nuthalapati
af53064660
utils: Fix ruamel.yaml deprecation warnings
Fixes #2143

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Convert the class property to instance property for added safety]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-10-29 14:34:53 -07:00
Fioddor Superconcentrado
337e8c28dd
config: Add user websites as choices for homepage config.
Closes: #1981
Closes also most of threads in !1952.

Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-12-13 08:20:26 -05:00
Joseph Nuthalapati
377010b078
openvpn: Deny access to users not in group "vpn"
A new function called `user_group_view` has been added to
restrict access to only users in the groups "vpn" and "admin".

Some changes are made in AdminRequiredMiddleware to handle this.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-11-25 13:15:22 -05:00
Veiko Aasa
dfaf009d3c
users: Require admin credentials when creating or editing a user
This change prevents the plinth user to become a superuser without
knowing an admin password.

Users module and action script:
- User credentials are now required for the subcommands: create-user,
  set-user-password, add-user-to-group (if the group is admin),
  remove-user-from-group (if the group is admin), set-user-status,
  remove-user (if the removed user is the last admin user.
  Note: the web UI doesn't allow to delete last admin user).
- subcommand remove-users requires authentication if the user is last
  admin user. Password must be provided through standard input.
- subcommand remove-group: do not allow to remove group 'admin'
- User credentials must be provided using the argument
  --auth-user and a passsword must be provided through standard input.
- If there are no users in the admin group, no admin password is
  required and if the --auth-user argument is required, it can be an
  empty string.

Users web UI:
- An admin needs to enter current password to create and edit a user
  and to change user's password.
- Show more detailed error text on exceptions when submitting forms.
- Show page title on the edit and create user pages.

Users unit and functional tests:
- Added a configuration parameters to the pytest configuration file
  to set current admin user/password.
- Added a configuration parameter 'ssh_port' to the functional tests.
  You can overwrite this with the FREEDOMBOX_SSH_PORT environment
  variable. Modified HACKING.md accordingly.
- Added an unit test:
     - test changing the password as a non-admin user.
     - test invalid admin password input.
     - test that removing the admin group fails.
- Capture stdout and stderr in the unit tests when calling an action
  script to be able to see more info on exceptions.
- Added functional tests for setting ssh keys and changing passwords
  for admin and non-admin users.
- Added a functional test for setting a user as active/inactive.

Changes during review [sunil]:
- Move uncommon functional step definitions to users module from global. This is
  keep the common functional step definitions to minimal level and promote when
  needed.
- Minor styling changes, flake8 fixes.
- Don't require pampy module when running non-admin tests. This allows tests to
  be run from outside the container on the host machine without python3-pam
  installed.
- Call the confirm password field 'Authorization Password'. This avoid confusion
  with a very common field 'Confirm Password' which essentially means retype
  your password to ensure you didn't get it wrong. Add label explaining why the
  field exists.
- Don't hard-code /tmp path in test_actions.py. Use tmp_path_factory fixture
  provided by pytest.
- Remove unused _get_password_hash() from actions/users.
- Undo splitting ldapgid output before parsing. It does not seem correct and
  could introduce problems when field values contain spaces.

Tests performed:
- No failed unit tests (run with and without sudo).
- All 'users' functional tests pass.
- Creating an admin user during the first boot wizard succeeds.
- Creating a user using the web UI with an empty or wrong admin
  password fails and with the correct admin password succeeds.
- Editing a user using the web UI with an empty or wrong admin
  password fails and with the correct admin password succeeds.
- Changing user's password using the web UI with an empty or wrong
  admin password fails and with the correct admin password succeeds.
- Above mentioned user action script commands can't be run without
  correct credentials.
- Adding the daemon user to the freedombox-share group succeeds when
  installing certain apps (deluge, mldonkey, syncthing, transmission).

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Move uncommon functional step definitions to users module from global]
[sunil: Minor styling changes, flake8 fixes]
[sunil: Don't require pampy module when running non-admin tests]
[sunil: Call the confirm password field 'Authorization Password']
[sunil: Don't hard-code /tmp path in test_actions.py]
[sunil: Remove unused _get_password_hash() from actions/users]
[sunil: Undo splitting ldapgid output before parsing]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-10-05 00:05:44 -07:00
Veiko Aasa
6b61ca2f18
ssh: action script: Require user credentials when editing ssh keys
This change prevents the plinth user to set the ssh-keys without
knowing the user password.

- Debian: added new dependency python3-pampy to authenticate users.
- Added additional required parameter --auth-user to the
  'actions/ssh set-keys' command. A password should be
  provided through STDIN.

Tests performed:
- running 'actions/ssh set-keys' with empty or wrong admin credentials
  fails.
- running 'actions/ssh set-keys' with correct admin credentials
  succeeds.
- running 'actions/ssh set-keys' with correct non-admin credentials
  succeeds if the --username is the same user.
- running 'actions/ssh set-keys' with correct non-admin credentials
  fails if the --username is a different user.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-10-05 00:05:41 -07:00
James Valleroy
f46b7ae2a6
utils: Handle removal of axes.get_version()
This was removed from django-axes 5.0.13 with introduction of
setuptools-scm.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-05-26 17:47:30 -07:00
Sunil Mohan Adapa
1ba55e793f
networks: Fix i18n for wizard forms
- Using Markup on format_lazy objects seems to convert negate their lazy
behavior.

- Extend the format_lazy() utility method to handle markup.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-02-24 12:36:41 -05: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
Alice Kile
8e3bbdb089
clients: implement launch button feature
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2019-11-18 19:41:14 +05:30
Sunil Mohan Adapa
b684b07d11
names: Make all apps use new api to retrieve domain names
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-08-11 18:39:54 -04:00
Nikolas Nyby
d2e987ef3c
Fix a handful of typos in docs and comments
Found with [codespell](https://github.com/codespell-project/codespell/)

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-07-24 12:39:11 -07:00
Sunil Mohan Adapa
0f807bcd48
sso: Use new features of axes, log axes messages
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-07-21 09:05:58 -04:00
Joseph Nuthalapati
d451b54286
backups: Add test for adding ssh remotes
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-07-03 12:42:02 +05:30
Sunil Mohan Adapa
ebca76b236
utils: Introduce abstraction over distutils comparison of versions
In future, if the semantics need to better align with Debian's version
comparison, we can implement that easily.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-03-01 23:50:37 -05:00
Sunil Mohan Adapa
d3bdaf0729
utils: Handle exceptions in context management for YAMLFile
When an exception is raised within the context, the YAML file should not
written.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-18 21:51:20 -05:00
Joseph Nuthalapati
753881b80f
utils: Simplify YAMLFile by removing the post_exit argument
Whatever function is passed in post_exit can simply be called by the caller
itself as the next statement.

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-02-14 16:39:05 -08:00
Joseph Nuthalapati
3a579e2d72
openvpn: is-setup checks for non-empty dh.pem file
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-11-19 07:46:31 -05:00
Sunil Mohan Adapa
89f31db71f
utils: Remove unused method
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-07-29 15:57:16 -04:00
Joseph Nuthalapati
8451c0b2dc
apps: Fix app names and short descriptions not being translated
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-04-08 10:57:19 -04:00
Sunil Mohan Adapa
0e9d10bff5
searx: Set file permissions while creating file
To avoid race conditions.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2018-02-26 18:56:53 +05:30
Joseph Nuthalapati
67274e1566
searx: Changes from code review
- Use 32-bit key for HMAC-256
- Use secrets library instead of os.urandom
- uwsgi enable/disable along with webserver enable/disable
- Text changes

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2018-02-26 18:53:59 +05:30
Joseph Nuthalapati
823c2968f0
searx: New app for Searx metasearch engine
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2018-02-26 18:53:46 +05:30
Sunil Mohan Adapa
dea4af17fb
Rename Plinth to FreedomBox in license headers
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-02-16 20:10:09 -05:00
Joseph Nuthalpati
37138ee83b
mediawiki: Add wiki application
Installs and configures MediaWiki. SSO integration is not included yet.

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-01-01 13:20:37 -05:00
Joseph Nuthalapati
202d0bf5c7
snapshots: Minor refactoring
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2017-12-18 12:23:58 +05:30
Sunil Mohan Adapa
acd248e506
clients: Cleanup framework
- Move all utilities to a separate clients.py module. Tests too.

- Use fewer custom template tags. Actually only one tag is really required.
  Keeping custom tags minimal is a goal.

- Merge the methods to generate app store URLs.

- Implement a validator for validating client information and use that instead
  of enums.

- Internationalize the text on template page.

- Add missing RPM package case.

- Cleanup CSS. Remove unused styles, minimize the styles set.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2017-12-13 18:56:30 -05:00
Joseph Nuthalapati
4c69935e7a
Remove unnecessary attributes in manifest files
- Other minor refactoring
- Fix ejabberd and jsxc Client Apps listing

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2017-12-04 12:15:54 -05:00
Joseph Nuthalpati
f330d09ec9
sso: Add captcha validation on 3 failed attempts
- clearing ip address correctly is not implemented yet
- currently clearing all ip addresses

Signed-off-by: Joseph Nuthalpati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2017-10-17 22:07:57 -04:00
Joseph Nuthalpati
5ad180fcc9
Add Tahoe-LAFS module
- Created basic plinth app which starts an introducer and a storage
  node on the FreedomBox.
- Prompt user to set a domain name before creating Tahoe-LAFS nodes.
- Support adding and removing of introducers to the storage node.
- Serve Tahoe-LAFS from a different port.
- Start all nodes and introducers at system startup.
- Add utility class YAMLFile with test cases.
2017-06-10 09:38:57 -04:00
Soumya97
6a53dd015e
context_processor: Cache whether user is admin (Closes: #781) 2017-04-18 16:01:48 +05:30
Rahul De
ad0b235dd7
users: Restrict groups and active user control to admins
- Only admins can now edit the groups of any user

- Only admins can mark any user as active or not

- Refactored all occurrences of admin checks to its own utility function
2017-02-15 21:07:54 +05:30
Sunil Mohan Adapa
dd5ab7612e
Minor refactoring and lint fixes
- Rename AdminMiddleware to AdminRequiredMiddleware to be consistent
  with stronghold/Django terminology

- Simplify .gitignore pattern

- Format single line docstrings as per PEP8.

- Add missing docstrings.

- Restrict lines to 79 characters.
2017-02-15 21:07:27 +05:30
lispyclouds
3b23f78bdc
Implement middleware for admin views
- Add AdminMiddleware to deny non admin users
- Add decorator to mark views as "non admin"
2017-02-15 20:57:52 +05:30
Sunil Mohan Adapa
8ccffcf02c
Add utility method to lazy format lazy string
This method is useful to format strings that are lazy (such as those in
Forms).
2016-01-24 00:22:59 +05:30
Sunil Mohan Adapa
cc858bbd6a Use pgi only when gi is not available
- Write a convenience utility to handle the import process.
2015-11-16 09:55:20 +05:30