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).
This commit is contained in:
Sunil Mohan Adapa 2016-06-02 16:49:11 +05:30 committed by James Valleroy
parent ccf217f2f7
commit 4865a64d2b
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
4 changed files with 34 additions and 69 deletions

View File

@ -94,7 +94,6 @@ available over this interfaces. Select Internal only for trusted networks.'),
return choices
def get_settings(self):
"""Return settings dict from cleaned data."""
settings = {}
@ -149,7 +148,6 @@ class PPPoEForm(EthernetForm):
show_password = forms.BooleanField(label=_('Show password'),
required=False)
def get_settings(self):
"""Return setting dict from cleaned data."""
settings = super().get_settings()

View File

@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "connections_edit.html" %}
{% comment %}
#
# This file is part of Plinth.
@ -37,48 +37,3 @@
</div>
{% endblock %}
{% block page_js %}
<script type="text/javascript">
(function($) {
if ($("#id_ipv4_method").prop("value") != "manual") {
$("#id_ipv4_address").prop("readOnly", true);
$("#id_ipv4_netmask").prop("readOnly", true);
$("#id_ipv4_gateway").prop("readOnly", true);
}
$("#id_name").focus();
$("#id_ipv4_method").change(function() {
if ($("#id_ipv4_method").prop("value") == "manual") {
$("#id_ipv4_address").prop("readOnly", false);
$("#id_ipv4_address").prop("required", true);
$("#id_ipv4_netmask").prop("readOnly", false);
$("#id_ipv4_gateway").prop("readOnly", false);
} else {
$("#id_ipv4_address").val("");
$("#id_ipv4_address").prop("readOnly", true);
$("#id_ipv4_address").prop("required", false);
$("#id_ipv4_netmask").val("");
$("#id_ipv4_netmask").prop("readOnly", true);
$("#id_ipv4_gateway").val("");
$("#id_ipv4_gateway").prop("readOnly", true);
}
});
$('#id_show_password').change(function() {
// Changing type attribute from password to text is prevented by
// most browsers. Making a new form field works.
new_type = 'password';
if ($('#id_show_password').prop('checked'))
new_type = 'text';
$('#id_password').replaceWith(
$('#id_password').clone().attr('type', new_type));
});
})(jQuery);
</script>
{% endblock %}

View File

@ -43,29 +43,40 @@
<script type="text/javascript">
(function($) {
if ($("#id_ipv4_method").prop("value") != "manual") {
$("#id_ipv4_address").prop("readOnly", true);
$("#id_ipv4_netmask").prop("readOnly", true);
$("#id_ipv4_gateway").prop("readOnly", true);
function ipv4_required(required, fields) {
for (var i = 0; i < fields.length; i++) {
$('#id_ipv4_' + fields[i]).prop("required", required);
}
}
function ipv4_readonly(readonly, fields) {
for (var i = 0; i < fields.length; i++) {
$('#id_ipv4_' + fields[i]).prop("readOnly", readonly);
if (readonly) {
$('#id_ipv4_' + fields[i]).val("");
$('#id_ipv4_' + fields[i]).prop("required", false);
}
}
}
function on_ipv4_method_change() {
if ($("#id_ipv4_method").prop("value") == "manual") {
ipv4_required(true, ['address']);
ipv4_readonly(false, ['address', 'netmask', 'gateway', 'dns',
'second_dns']);
} else if ($("#id_ipv4_method").prop("value") == "shared") {
ipv4_required(false, ['address']);
ipv4_readonly(false, ['address', 'netmask']);
ipv4_readonly(true, ['gateway', 'dns', 'second_dns']);
} else {
ipv4_readonly(true, ['address', 'netmask', 'gateway']);
ipv4_readonly(false, ['dns', 'second_dns']);
}
}
$("#id_name").focus();
$("#id_ipv4_method").change(function() {
if ($("#id_ipv4_method").prop("value") == "manual") {
$("#id_ipv4_address").prop("readOnly", false);
$("#id_ipv4_address").prop("required", true);
$("#id_ipv4_netmask").prop("readOnly", false);
$("#id_ipv4_gateway").prop("readOnly", false);
} else {
$("#id_ipv4_address").val("");
$("#id_ipv4_address").prop("readOnly", true);
$("#id_ipv4_address").prop("required", false);
$("#id_ipv4_netmask").val("");
$("#id_ipv4_netmask").prop("readOnly", true);
$("#id_ipv4_gateway").val("");
$("#id_ipv4_gateway").prop("readOnly", true);
}
});
$("#id_ipv4_method").change(on_ipv4_method_change).change();
$('#id_show_password').change(function() {
// Changing type attribute from password to text is prevented by

View File

@ -313,7 +313,8 @@ def _update_ipv4_settings(connection, ipv4):
connection.add_setting(settings)
settings.set_property(nm.SETTING_IP_CONFIG_METHOD, ipv4['method'])
if ipv4['method'] == nm.SETTING_IP4_CONFIG_METHOD_MANUAL and \
if (ipv4['method'] == nm.SETTING_IP4_CONFIG_METHOD_MANUAL or
ipv4['method'] == nm.SETTING_IP4_CONFIG_METHOD_SHARED) and \
ipv4['address']:
ipv4_address_int = ipv4_string_to_int(ipv4['address'])