|
@@ -87,7 +87,9 @@ dispatch('/', function() {
|
|
|
$ip6_net = ($ip6_net == 'none') ? '' : $ip6_net;
|
|
|
$ip4_nat_prefix = moulinette_get('ip4_nat_prefix');
|
|
|
|
|
|
+ set('service_enabled', moulinette_get('service_enabled'));
|
|
|
set('wifi_ssid', moulinette_get('wifi_ssid'));
|
|
|
+ set('wifi_secure', moulinette_get('wifi_secure'));
|
|
|
set('wifi_passphrase', moulinette_get('wifi_passphrase'));
|
|
|
set('wifi_channel', moulinette_get('wifi_channel'));
|
|
|
set('wifi_n', moulinette_get('wifi_n'));
|
|
@@ -111,95 +113,111 @@ dispatch_put('/settings', function() {
|
|
|
|
|
|
$ip6_net = empty($_POST['ip6_net']) ? 'none' : $_POST['ip6_net'];
|
|
|
$ip6_addr = 'none';
|
|
|
+ $service_enabled = isset($_POST['service_enabled']) ? 1 : 0;
|
|
|
+ $wifi_secure = isset($_POST['wifi_secure']) ? 1 : 0;
|
|
|
|
|
|
- try {
|
|
|
- if(empty($_POST['wifi_ssid']) || empty($_POST['wifi_passphrase']) || empty($_POST['wifi_channel'])) {
|
|
|
- throw new Exception(T_('Your Wifi Hotspot needs a name, a password and a channel'));
|
|
|
- }
|
|
|
-
|
|
|
- if(strlen($_POST['wifi_passphrase']) < 8 || strlen($_POST['wifi_passphrase']) > 63) {
|
|
|
- throw new Exception(T_('Your password must from 8 to 63 characters (WPA2 passphrase)'));
|
|
|
- }
|
|
|
-
|
|
|
- if(preg_match('/[^[:print:]]/', $_POST['wifi_passphrase'])) {
|
|
|
- throw new Exception(T_('Only printable ASCII characters are permitted in your password'));
|
|
|
- }
|
|
|
-
|
|
|
- if(!$wifi_device_exists) {
|
|
|
- throw new Exception(T_('The wifi antenna interface seems not exist on the system'));
|
|
|
- }
|
|
|
-
|
|
|
- if($ip6_net != 'none') {
|
|
|
- $ip6_net = ipv6_expanded($ip6_net);
|
|
|
+ if($service_enabled == 1) {
|
|
|
+ try {
|
|
|
+ if(empty($_POST['wifi_ssid']) || empty($_POST['wifi_passphrase']) || empty($_POST['wifi_channel'])) {
|
|
|
+ throw new Exception(T_('Your Wifi Hotspot needs a name, a password and a channel'));
|
|
|
+ }
|
|
|
|
|
|
- if(empty($ip6_net)) {
|
|
|
- throw new Exception(T_('The IPv6 Delegated Prefix format looks bad'));
|
|
|
+ if(strlen($_POST['wifi_passphrase']) < 8 || strlen($_POST['wifi_passphrase']) > 63) {
|
|
|
+ throw new Exception(T_('Your password must from 8 to 63 characters (WPA2 passphrase)'));
|
|
|
}
|
|
|
|
|
|
- $ip6_blocs = explode(':', $ip6_net);
|
|
|
- $ip6_addr = "${ip6_blocs[0]}:${ip6_blocs[1]}:${ip6_blocs[2]}:${ip6_blocs[3]}:${ip6_blocs[4]}:${ip6_blocs[5]}:${ip6_blocs[6]}:42";
|
|
|
+ if(preg_match('/[^[:print:]]/', $_POST['wifi_passphrase'])) {
|
|
|
+ throw new Exception(T_('Only printable ASCII characters are permitted in your password'));
|
|
|
+ }
|
|
|
|
|
|
- $ip6_net = ipv6_compressed($ip6_net);
|
|
|
- $ip6_addr = ipv6_compressed($ip6_addr);
|
|
|
- }
|
|
|
-
|
|
|
- $ip6_dns0 = ipv6_expanded($ip6_dns0);
|
|
|
-
|
|
|
- if(empty($_POST['ip6_dns0'])) {
|
|
|
- throw new Exception(T_('The format of the first IPv6 DNS Resolver looks bad'));
|
|
|
- }
|
|
|
-
|
|
|
- $ip6_dns0 = ipv6_compressed($ip6_dns0);
|
|
|
- $ip6_dns1 = ipv6_expanded($ip6_dns1);
|
|
|
-
|
|
|
- if(empty($_POST['ip6_dns1'])) {
|
|
|
- throw new Exception(T_('The format of the second IPv6 DNS Resolver looks bad'));
|
|
|
+ if(!$wifi_device_exists) {
|
|
|
+ throw new Exception(T_('The wifi antenna interface seems not exist on the system'));
|
|
|
+ }
|
|
|
+
|
|
|
+ if($ip6_net != 'none') {
|
|
|
+ $ip6_net = ipv6_expanded($ip6_net);
|
|
|
+
|
|
|
+ if(empty($ip6_net)) {
|
|
|
+ throw new Exception(T_('The IPv6 Delegated Prefix format looks bad'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $ip6_blocs = explode(':', $ip6_net);
|
|
|
+ $ip6_addr = "${ip6_blocs[0]}:${ip6_blocs[1]}:${ip6_blocs[2]}:${ip6_blocs[3]}:${ip6_blocs[4]}:${ip6_blocs[5]}:${ip6_blocs[6]}:42";
|
|
|
+
|
|
|
+ $ip6_net = ipv6_compressed($ip6_net);
|
|
|
+ $ip6_addr = ipv6_compressed($ip6_addr);
|
|
|
+ }
|
|
|
+
|
|
|
+ $ip6_dns0 = ipv6_expanded($ip6_dns0);
|
|
|
+
|
|
|
+ if(empty($_POST['ip6_dns0'])) {
|
|
|
+ throw new Exception(T_('The format of the first IPv6 DNS Resolver looks bad'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $ip6_dns0 = ipv6_compressed($ip6_dns0);
|
|
|
+ $ip6_dns1 = ipv6_expanded($ip6_dns1);
|
|
|
+
|
|
|
+ if(empty($_POST['ip6_dns1'])) {
|
|
|
+ throw new Exception(T_('The format of the second IPv6 DNS Resolver looks bad'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $ip6_dns1 = ipv6_compressed($ip6_dns1);
|
|
|
+
|
|
|
+ if(inet_pton($_POST['ip4_dns0']) === false) {
|
|
|
+ throw new Exception(T_('The format of the first IPv4 DNS Resolver looks bad'));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(inet_pton($_POST['ip4_dns1']) === false) {
|
|
|
+ throw new Exception(T_('The format of the second IPv4 DNS Resolver looks bad'));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(inet_pton("${_POST['ip4_nat_prefix']}.0") === false) {
|
|
|
+ throw new Exception(T_('The format of the IPv4 NAT Prefix (/24) looks bad : x.x.x expected)'));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(filter_var("${_POST['ip4_nat_prefix']}.0", FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) !== false) {
|
|
|
+ throw new Exception(T_('The IPv4 NAT Prefix must be from a private range'));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch(Exception $e) {
|
|
|
+ flash('error', $e->getMessage().' ('.T_('configuration not updated').').');
|
|
|
+ goto redirect;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- $ip6_dns1 = ipv6_compressed($ip6_dns1);
|
|
|
+ stop_service();
|
|
|
|
|
|
- if(inet_pton($_POST['ip4_dns0']) === false) {
|
|
|
- throw new Exception(T_('The format of the first IPv4 DNS Resolver looks bad'));
|
|
|
- }
|
|
|
+ moulinette_set('service_enabled', $service_enabled);
|
|
|
|
|
|
- if(inet_pton($_POST['ip4_dns1']) === false) {
|
|
|
- throw new Exception(T_('The format of the second IPv4 DNS Resolver looks bad'));
|
|
|
- }
|
|
|
+ if($service_enabled == 1) {
|
|
|
+ moulinette_set('wifi_ssid', $_POST['wifi_ssid']);
|
|
|
+ moulinette_set('wifi_secure', $wifi_secure);
|
|
|
|
|
|
- if(inet_pton("${_POST['ip4_nat_prefix']}.0") === false) {
|
|
|
- throw new Exception(T_('The format of the IPv4 NAT Prefix (/24) looks bad : x.x.x expected)'));
|
|
|
+ if($wifi_secure == 1) {
|
|
|
+ moulinette_set('wifi_passphrase', $_POST['wifi_passphrase']);
|
|
|
}
|
|
|
|
|
|
- if(filter_var("${_POST['ip4_nat_prefix']}.0", FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) !== false) {
|
|
|
- throw new Exception(T_('The IPv4 NAT Prefix must be from a private range'));
|
|
|
+ moulinette_set('wifi_channel', $_POST['wifi_channel']);
|
|
|
+ moulinette_set('wifi_n', isset($_POST['wifi_n']) ? 1 : 0);
|
|
|
+ moulinette_set('wifi_device', $_POST['wifi_device']);
|
|
|
+ moulinette_set('ip6_net', $ip6_net);
|
|
|
+ moulinette_set('ip6_addr', $ip6_addr);
|
|
|
+ moulinette_set('ip6_dns0', $_POST['ip6_dns0']);
|
|
|
+ moulinette_set('ip6_dns1', $_POST['ip6_dns1']);
|
|
|
+ moulinette_set('ip4_nat_prefix', $_POST['ip4_nat_prefix']);
|
|
|
+ moulinette_set('ip4_dns0', $_POST['ip4_dns0']);
|
|
|
+ moulinette_set('ip4_dns1', $_POST['ip4_dns1']);
|
|
|
+
|
|
|
+ $retcode = start_service();
|
|
|
+
|
|
|
+ if($retcode == 0) {
|
|
|
+ flash('success', T_('Configuration updated and service successfully reloaded'));
|
|
|
+ } else {
|
|
|
+ flash('error', T_('Configuration updated but service reload failed'));
|
|
|
}
|
|
|
|
|
|
- } catch(Exception $e) {
|
|
|
- flash('error', $e->getMessage().' ('.T_('configuration not updated').').');
|
|
|
- goto redirect;
|
|
|
- }
|
|
|
-
|
|
|
- stop_service();
|
|
|
-
|
|
|
- moulinette_set('wifi_ssid', $_POST['wifi_ssid']);
|
|
|
- moulinette_set('wifi_passphrase', $_POST['wifi_passphrase']);
|
|
|
- moulinette_set('wifi_channel', $_POST['wifi_channel']);
|
|
|
- moulinette_set('wifi_n', isset($_POST['wifi_n']) ? 1 : 0);
|
|
|
- moulinette_set('wifi_device', $_POST['wifi_device']);
|
|
|
- moulinette_set('ip6_net', $ip6_net);
|
|
|
- moulinette_set('ip6_addr', $ip6_addr);
|
|
|
- moulinette_set('ip6_dns0', $_POST['ip6_dns0']);
|
|
|
- moulinette_set('ip6_dns1', $_POST['ip6_dns1']);
|
|
|
- moulinette_set('ip4_nat_prefix', $_POST['ip4_nat_prefix']);
|
|
|
- moulinette_set('ip4_dns0', $_POST['ip4_dns0']);
|
|
|
- moulinette_set('ip4_dns1', $_POST['ip4_dns1']);
|
|
|
-
|
|
|
- $retcode = start_service();
|
|
|
-
|
|
|
- if($retcode == 0) {
|
|
|
- flash('success', T_('Configuration updated and service successfully reloaded'));
|
|
|
} else {
|
|
|
- flash('error', T_('Configuration updated but service reload failed'));
|
|
|
+ flash('success', T_('Service successfully disabled'));
|
|
|
}
|
|
|
|
|
|
redirect:
|