mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Added a new network connection type to handle PPPoE connections
* Added a new choice to main selectbox for adding Network Connections (network.py) * Added a new form which asks for name, interface, firewall zone, username and password (forms.py, urls.py) * Added new helper functions to create PPPoE based connection object (network.py)
This commit is contained in:
1 parent
2879c9cedb
commit
286caf8917
4 files changed
+131
-4
No files matched your search
+61
-2
@@ -32,6 +32,7 @@ logger = logging.getLogger(__name__)
|
||||
CONNECTION_TYPE_NAMES = {
|
||||
'802-3-ethernet': 'Ethernet',
|
||||
'802-11-wireless': 'Wi-Fi',
|
||||
'pppoe': 'PPPoE',
|
||||
}
|
||||
|
||||
|
||||
@@ -127,8 +128,8 @@ def get_active_connection(connection_uuid):
|
||||
raise ConnectionNotFound(connection_uuid)
|
||||
|
||||
|
||||
def _update_common_settings(connection, connection_uuid, name, type_, interface,
|
||||
zone, ipv4_method, ipv4_address):
|
||||
def _update_common_settings(connection, connection_uuid, name, type_,
|
||||
interface, zone, ipv4_method, ipv4_address):
|
||||
"""Create/edit basic settings for network manager connections."""
|
||||
if not connection:
|
||||
connection = nm.SimpleConnection.new()
|
||||
@@ -184,6 +185,59 @@ def _update_ethernet_settings(connection, connection_uuid, name, interface,
|
||||
return connection
|
||||
|
||||
|
||||
def _update_pppoe_settings(connection, connection_uuid, name, interface, zone,
|
||||
username, password):
|
||||
"""Create/edit ethernet settings for network manager connections."""
|
||||
type_ = 'pppoe'
|
||||
|
||||
connection = _update_common_settings(connection, connection_uuid, name,
|
||||
type_, interface, zone, 'auto',
|
||||
'0.0.0.0')
|
||||
|
||||
#pppoe
|
||||
settings = connection.get_setting_pppoe()
|
||||
if not settings:
|
||||
settings = nm.SettingPppoe.new()
|
||||
|
||||
settings.set_property(nm.SETTING_PPPOE_USERNAME, username)
|
||||
settings.set_property(nm.SETTING_PPPOE_PASSWORD, password)
|
||||
connection.add_setting(settings)
|
||||
|
||||
settings = connection.get_setting_ppp()
|
||||
if not settings:
|
||||
settings = nm.SettingPpp.new()
|
||||
|
||||
#ToDo: make this configurable?
|
||||
#ToDo: apt-get install ppp pppoe
|
||||
settings.set_property(nm.SETTING_PPP_LCP_ECHO_FAILURE, 5)
|
||||
settings.set_property(nm.SETTING_PPP_LCP_ECHO_INTERVAL, 30)
|
||||
|
||||
connection.add_setting(settings)
|
||||
return connection
|
||||
|
||||
|
||||
def add_pppoe_connection(name, interface, zone, username, password):
|
||||
"""Add an automatic pppoe connection in network manager.
|
||||
|
||||
Return the UUID for the connection.
|
||||
"""
|
||||
connection_uuid = str(uuid.uuid4())
|
||||
connection = _update_pppoe_settings(
|
||||
None, connection_uuid, name, interface, zone, username, password)
|
||||
client = nm.Client.new(None)
|
||||
client.add_connection_async(connection, True, None, _callback, None)
|
||||
return connection_uuid
|
||||
|
||||
|
||||
def edit_pppoe_connection(connection, name, interface, zone, username,
|
||||
password):
|
||||
"""Edit an existing pppoe connection in network manager."""
|
||||
_update_pppoe_settings(
|
||||
connection, connection.get_uuid(), name, interface, zone, username,
|
||||
password)
|
||||
connection.commit_changes(True)
|
||||
|
||||
|
||||
def add_ethernet_connection(name, interface, zone, ipv4_method, ipv4_address):
|
||||
"""Add an automatic ethernet connection in network manager.
|
||||
|
||||
@@ -272,6 +326,11 @@ def activate_connection(connection_uuid):
|
||||
# Find the connection
|
||||
connection = get_connection(connection_uuid)
|
||||
|
||||
# ToDo: is the following code still needed? Because the connections
|
||||
# are bound to an interface and for this reason, the device name should
|
||||
# be available within connection object. So simply use:
|
||||
# connection.get_interface_name() ??
|
||||
|
||||
# Find a suitable device
|
||||
client = nm.Client.new(None)
|
||||
connection_type = connection.get_connection_type()
|
||||
|
||||
Reference in new issue
Block a user