68 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
eaa3a59791
*: pylint: Drop unnecessary 'pass' statements
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-04 19:46:31 -04:00
Jim Gregory
66e19ff56e
network: Fix showing wifi connection
Viewing a wifi connection will cause a 500 error.  To reproduce this
issue, go to plinth/sys/networks/.  If no wifi connections exist,
add one use the "Add Connection" button.  Then, click on the name of
the wifi connection to view it.  A 500 error is returned.

This commit fixes this error so the normal "show connection" is
returned.  It also fixes a bytestring conversion error
for the SSID and a blank value for "mode" on the page.

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2022-03-28 15:19:48 -07: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
Fioddor Superconcentrado
ce87de1dfb
networks: Hide deactivate/remove buttons for primary connections
Helps: #1962.

Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-01-25 15:40:51 -08:00
Fioddor Superconcentrado
6cc13bea65
network: Minor refactoring, new is_primary() function
Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
[sunil: Made the method private to reduce the exposed API of the module]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-01-25 15:40:38 -08:00
Fioddor Superconcentrado
ff9d0ace31
networks: i18n: Mark various strings for translation
Helps: #1938.

- Translate various states passed in by Network Manager:
  - Device state
  - Device state reason
  - Device type
  - Firewall zone
  - IPv4/IPv6 connection method
  - Wireless mode
- forms.py: Move zones list to network.py, reuse in views.py.

Testing:
- Yapf applied.
- Flake8 without errors or warnings for changed files.
- (Unit) tests run without errors.
- Screnshots attached to #1938.

Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
[sunil: Add strings for many more states]
[sunil: Don't allow None to be selected as firewall zone]
[sunil: Drop forced_literals.py as it reduces modularity of the code]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-10-20 11:57:12 -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
6e1b0a3642
wireguard: Handle client connections through network manager
- Any changes done directly using 'wg' command need to be redone after a reboot
  and disable/enable sequence. Let that duty be handled by network manager.

- Handle (none) values for keys and 0 values for latest handshake from 'wg'
  dump command output.

- Don't store public/private keys for wireguard in /var/lib. Let Network Manager
  deal with the storage of secrets.

- Create client connections in the 'external' zone.

- Show allowed IPs for each client in the main page.

- Show server connection public key only for clients. We use different key pairs
  when connecting to each of the servers.

- Separate out configuration information and status information in the show
  page.

- Allocate IP addresses to each of the clients.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-18 13:53:35 -05:00
Sunil Mohan Adapa
71c7ab4a9d
wireguard: Only use network manager for connections to servers
- Don't create network link. This don't persist across reboots and it is the job
  of Network Manager.

- Move NM settings code to regular plinth process instead of superuser.
  Permission for managing NM connections from the service daemon is granted by
  PolKit.

- Use interface name to identify the connection as it seems to be simply to do
  so than the public key. Public key is not easy to retrieve from NM connection.

- Merge code for adding and editing the connection to avoid repetition.

- Add icon to the edit button.

- Throw 404 error when incorrect client is specified.

- Fix issue with storing preshared key.

- Show formatting date in case of last connected time.

- Show formatted sizes for data transmitted.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-18 13:53:31 -05:00
Sunil Mohan Adapa
39fade1095
wireguard: Accept all IPs on server in a client setup
- Without this, all IPs on the server will be rejected and communication will
  not be possible.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-18 13:53:26 -05:00
James Valleroy
0bef87579f
wireguard: Replace nmcli use with libnm
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-01-18 13:53:15 -05:00
James Valleroy
b0855dad91
wireguard: Use network API to handle connections
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Use the new method for creating network manager client instance]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-01-18 13:53:10 -05:00
Sunil Mohan Adapa
f444fba6ea
network: Add method to re-activate connections after an update
- When a connection is updated with newer settings, the changes don't reflect
  unless the connection is deactivated and reactivated. Add a convenience method
  to achieve this.

- Don't perform any operation if the connection is not active.

- Wait until connection is deactivated before reactivating

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-18 13:52:32 -05:00
Sunil Mohan Adapa
42569d75ec
network: Allow setting the auto-connect property on a connection
Also don't require updating all the common properties of a connection when
updating only some properties such as 'autoconnect'.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-18 13:52:30 -05:00
Sunil Mohan Adapa
68e5684d10
network: Fix activating connections that don't have real devices
When a WireGuard connection is activated, it create the wireguard interface.
Looking for matching devices before activating a connection will then fail. Use
get_all_devices() API to get the list of all devices that are real and those
that will be created due to connection activation.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-18 13:52:26 -05:00
Sunil Mohan Adapa
4ad3a9ee8f
networks: Fix crashing when accessing network manager D-Bus API
Network Manager client fetches the basic information from Network Manager,
caches it and updates the cache whenever it receives the signal. So, create only
a single instance of it and reuse it. Reusing from different threads is
apparently fine because the underlying DBusConnection is a singleton[1] that is
meant to be used from multiple threads.

The glib main loop context that is related to the client must run even after the
network manager client object goes away[2]. So, create the network manager
client instance from a thread that continues to run the glib main thread.

This fixes an infrequent crash when accessing network manager page. The problem
was reproducible from very early version of Network Manager and FreedomBox.
However, in more recent versions of NetworkManager 1.20 with recent DBus changes
in FreedomBox, the problem is more prominent. The problem reduces to a simple
warning in NetworkManager 1.22.

Closes: #1724
Closes: #382

Tests:

- Reproduce the problem by accessing the networks app index page repeatedly.

- Create a simple test case file to reproduce the problem and ensure that the
  fix works there.

- On Network Manager 1.20 repeatedly access the networks app index page and
  create/delete/activate/deactivate/show connections.

- On Network Manager 1.22 repeatedly access the networks app index page and
  create/delete/activate/deactivate/show connections.

Links:

1) https://developer.gnome.org/gio/unstable/GDBusConnection.html#g-bus-get-sync

2) https://developer.gnome.org/libnm/stable/NMClient.html#nm-client-get-main-context

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-13 17:22:39 -05:00
Sunil Mohan Adapa
7695047606
networks: Remove unused method
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-13 17:22:36 -05:00
Sunil Mohan Adapa
b5ae03239c
networks: Refactor creating a network manager client
This allows better control on how to create and maintain the network manager
client.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-01-13 17:22:32 -05:00
Alice Kile
eb83e00011
fix formatting issues
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-12-07 13:08:35 -05:00
Michael Pimmer
db5a66c1d0
Remove unused imports and variables
Signed-off-by: Michael Pimmer <info@fonfon.at>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-06-18 19:27:40 -04:00
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
Sunil Mohan Adapa
dce51fd6d7
networks: Support configuring IPv6 networks
- Very similar to configuration of IPv4 networks.

- Supports 'auto', 'dhcp', 'manual' and 'ignored' modes as supported by
  network manager.  'shared' mode is not yet implemented by network
  manager.
2016-10-01 07:09:03 -04:00
Sunil Mohan Adapa
fee14b1764
networks: Remove the IP address hack fully 2016-08-11 17:11:23 -04:00
nikhil rayaprolu
43e070972a
networks: Remove hack for fetching IP address 2016-08-11 17:11:17 -04:00
Sunil Mohan Adapa
28a9933fd9
networks: Configure wireless BSSID, band, channel
Select the frequency band (2.4 GHz vs. 5 GHz) is a prerequisite for
selecting the channel.  Channel selection is useful primarily as follow:

- Restrict to a particular access point when multiple access points use
  the same SSID (AP name) but are available on different frequencies.

- Configure for a particular ad-hoc mesh network.

- Setup multiple access points from a single FreedomBox on multiple
  channels to maximize the throughput and number of simultaneous
  clients.

Ability to specify a particular BSSID will help associate with a
particular access point when multiple access points use the same
SSID (AP name).  This is also makes it slightly harder to trick clients
into connection to a malicious device.  Also configuring BATMAN-adv
seems to require setting a particular BSSID.
2016-07-21 19:23:31 -04:00
Sunil Mohan Adapa
04babacafa
networks: Ability to configure generic interfaces
After batman-adv kernel driver takes over the Wi-Fi network interface
and provides a bat0 interface, this interface shows up as device type
'batadv'.  This type is not recognized by network manager is dealt with
as a generic device.  Configuring this device for IPv4/IPv6 in
auto/shared mode etc. works fine.  So, add the ability to configure
generic interfaces.
2016-07-21 19:23:20 -04:00
Sunil Mohan Adapa
4865a64d2b
networks: Allow shared connections to have IPs
Setting IP address on a shared connection can be usefull.  This tells
Network Manager to pick the provided network range (inferred from
IP/netmask) instead of something in 10.42.x.x.  This can be used to give
predicatable IPs, static IPs and to make large static
reservations (instead of the default 8).
2016-06-07 08:12:18 -04:00
Sunil Mohan Adapa
3b7b7881b1
networks: Fix issue when looking up AP details
As reported by Jan Costermans, it is possible that for an access point
scanned by a Wi-Fi device, get_ssid() returns None.  The reported as
follows:

  if access_point.get_ssid().get_data() == ssid:

  AttributeError: 'NoneType' object has no attribute 'get_data'
2016-03-05 16:00:27 -05:00
Sunil Mohan Adapa
db7ed51e53
networks: Minor update to primary connection fix
To make sure 'primary' key is always available in status.
2016-01-08 14:30:14 +05:30
Daniel Steglich
8e4abf282f
networks: fix for primary connection Closes: #334
Check if there is any primary connection available before accessing this
connections parameter.  Otherwise Plinth will raise an exception because
of non existing object.
2016-01-08 14:29:35 +05:30
Sunil Mohan Adapa
42d0198a2e networks: Refactor for simplicity and brevity
- Make connection adding/editing forms inherit from base.

- Make the forms responsible for extracting cleaned data.

- Use dictionaries for passing around settings values while
  adding/editing connections.
2015-12-09 17:56:11 +05:30
Sunil Mohan Adapa
8438bd3f31 networks: Fix issue with setting default netmask
- Minor refactoring of DNS server setting code.
2015-12-09 17:56:11 +05:30
Sunil Mohan Adapa
ba5c7a772d networks: Refactor & fix extracting netmask
- Use host byte ordering instead of big-endian.
2015-12-09 17:55:03 +05:30
Sunil Mohan Adapa
da99a7cb9d networks: Minor indentation fixes 2015-12-09 12:21:38 +05:30
Daniel Steglich
1a1faa8a1b Github issue 314: static IP configuration enhancement
* fixed IP configuration
  * set up a new ipv4settings object to avoid the need of reseting all the values
* extended Static IP configuration:
  * allow configuration of netmask (optional)
  * allow configuration of Gateway (optional)
  * allow configuartion of two DNS Servers (optional)
* extend DHCP configuration:
  * allow configuration of user specific DNS Server
  * DHCP provided DNS Servers will be ignored in that case
2015-12-09 10:28:53 +05:30
Daniel Steglich
ff412c2af1 network: Fix changing addressing method (GH #307)
When changing the addressing method from manual to automatic, the IP
addresses where removed from connection object without removing the
Gateway property.  This causes a networkmanager error.

Create new SettingIP4Config object to avoid the need to reset all
propertys when changing methods
2015-12-06 18:01:49 +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
Nik Nyby
608897b9ec Test on python 3.3 and 3.4 with travis
Python 3.2.x is deprecated, so I thought it would be
good to get tests running on some newer pythons. I've
switched from the python3-gi package to using 'pgi' from
pypi, because the apt-installed python3-gi was having trouble
importing.

pgi required python 3.3+ (see: https://pypi.python.org/pypi/pgi),
so I've removed python 3.2 from the test matrix. Let me know if
we're using python 3.2 anywhere, but as far as I know plinth is
run on python 3.4.3 with debian sid on the freedombox image.
2015-11-16 08:44:01 +05:30
Sunil Mohan Adapa
3df1a88824 Switch to Django i18n for code strings
Django i18n layer is on top of gettext and provide may crucial features
such as per-request locales, lazy translations etc.
2015-11-13 22:08:43 +05:30
Sunil Mohan Adapa
11bf585025 networks: Show network diagram
- As discussed in the first boot redesign proposal.

- Images are taken from Tango icon set, GNOME icons or created.

- Responsive, works for very small widths also.

- First cut, special cases of network connectivity are not handled.
2015-10-28 20:02:56 -04:00
Sunil Mohan Adapa
96b98fae9f networks: Handle unavailability of device 2015-10-28 20:02:56 -04:00
Sunil Mohan Adapa
2ef22ec1b4 Require library version for GObject introspection
Specify the version of a library before importing it using GObject
introspection.  Mainly to avoid warnings with recent version of
pygobject.  Closes #247.
2015-10-17 21:13:35 -04:00
Sunil Mohan Adapa
fc19b0fd3d networks: Refactor code for showing connection
- Fix showing configured IP address in edit form.

- Combine the retrival functions and organize them according to where
  the information is being retrived from connection/device/active
  connection/access point.

- Add more fields to show such as ether speed, default ipv4/ipv6
  connection, wifi mode, etc.

- Re-format the page.  Separate ipv4/ipv6 sections. Separate device
  information and connection information sections.

- Take the action buttons to the top.

- Make the activate/deactivate button work with new POST only CSRF
  requirement.

- Update Firewall zone description messages.

- Show all IP addresses of the device.
2015-10-11 16:28:55 +05:30
Sunil Mohan Adapa
682e5d7c2d networks: Prefill proper Wi-Fi device in add form
Add access points found on a particular Wi-Fi device only to that device
as it is not gauranteed that other Wi-Fi devices will be able to find
them.  For example, an access point operating in 5 GHz frequency will
only be found and used by Wi-Fi devices capable for 5 GHz communication.
2015-10-11 16:28:55 +05:30
Daniel Steglich
408aa8910a wi-fi network connection: Fixed error message when entering the form
- When selecting an existing WiFi on the "scan" page, the user will be redirected to the "WiFi add" form.
  This form did not contain a WiFi capable Interface as default selection, for this reason the user get a
  invalid form message when entering the form.
2015-10-11 16:28:55 +05:30
Daniel Steglich
3c47dfb6ef Minor coding styleguide fix
- fixed a pep8 error (line too long)
2015-10-11 16:28:55 +05:30
Daniel Steglich
c3e5753b52 Network Status pages: added status pages
- implemented network status page which supports:
 * show IP address and netmask
 * show MAC address
 * show device name
 * show firewall zone name
 * show DNS server information
 * show default gateway
 * show wifi information
 * shows if connection is shared or not and if connection is the default connection

- when clicking on a cennection on the overview page go to the status page, not to the
  editing page

- ToDo: if connection is disabled and re-enabled again, no information are visible anymore (Bug)
2015-10-11 16:28:55 +05:30
Sunil Mohan Adapa
ef156dab91 networks: Minor styling and comments update
- Add comment about PPP peers possibly not responding to echo requests.
2015-08-22 21:14:21 +05:30
Sunil Mohan Adapa
2c23b0ecb4 networks: During activation raise device not found
When an interface assigned to a connection is not available in list of
devices, raise a proper error that device is not found.
2015-08-22 21:13:36 +05:30
Sunil Mohan Adapa
e7214b7586 networks: Refactor common settings updation
Since IPv4 address settings are not relavent for PPPoE and the command
settings take them, split the common setting updation into basic
settings and IPv4 settings.
2015-08-22 21:11:13 +05:30