} function ipv6_compressed($ip) { exec('ipv6_compressed ' . escapeshellarg($ip), $output); return $output[0]; } dispatch('/', function () { $ip6_net = moulinette_get('ip6_net'); $ip6_net = $ip6_net == 'none' ? '' : $ip6_net; $raw_openvpn = file_get_contents('/etc/openvpn/client.conf.tpl'); set('service_enabled', moulinette_get('service_enabled')); set('server_name', moulinette_get('server_name')); set('server_port', moulinette_get('server_port')); set('server_proto', moulinette_get('server_proto')); set('login_user', moulinette_get('login_user')); set('login_passphrase', moulinette_get('login_passphrase')); set('ip6_net', $ip6_net); set('crt_client_exists', file_exists('/etc/openvpn/keys/user.crt')); set('crt_client_key_exists', file_exists('/etc/openvpn/keys/user.key')); set('crt_server_ca_exists', file_exists('/etc/openvpn/keys/ca-server.crt')); set('faststatus', service_faststatus() == 0); set('raw_openvpn', $raw_openvpn); return render('settings.html.php'); }); dispatch_put('/settings', function () { $crt_client_exists = file_exists('/etc/openvpn/keys/user.crt'); $crt_client_key_exists = file_exists('/etc/openvpn/keys/user.key'); $crt_server_ca_exists = file_exists('/etc/openvpn/keys/ca-server.crt'); $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; $ip6_net = empty($_POST['ip6_net']) ? 'none' : $_POST['ip6_net']; $ip6_addr = 'none';
if ($i == $wifi_device_id) { $active = 'class="active"'; $wifi_ssid = htmlentities($ssids[$i]); } $wifi_ssid_list .= "<li {$active} data-device-id='{$i}'><a href='javascript:;'>" . htmlentities($ssids[$i]) . '</a></li>'; } set('faststatus', service_faststatus() == 0); set('service_enabled', moulinette_get('service_enabled')); set('wifi_device_id', $wifi_device_id); set('wifi_ssid', $wifi_ssid); set('wifi_ssid_list', $wifi_ssid_list); set('opt_renaming', moulinette_get('opt_renaming')); set('opt_deleting', moulinette_get('opt_deleting')); set('opt_chat', moulinette_get('opt_chat')); set('opt_name', moulinette_get('opt_name')); set('opt_domain', moulinette_get('opt_domain')); return render('settings.html.php'); }); dispatch_put('/settings', function () { $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; if ($service_enabled == 1) { try { $_POST['opt_name'] = htmlentities(str_replace('"', '', $_POST['opt_name'])); if (empty($_POST['opt_name'])) { throw new Exception(_('The name cannot be empty')); } if ($_POST['wifi_device_id'] == -1) { throw new Exception(_('You need to select an associated hotspot')); } } catch (Exception $e) { flash('error', _('PirateBox') . " {$id}: " . $e->getMessage() . ' (' . _('configuration not updated') . ').');
$wifi_secure = getArray(moulinette_get('wifi_secure')); $wifi_passphrase = getArray(moulinette_get('wifi_passphrase')); $ip6_net = getArray(moulinette_get('ip6_net')); $ip6_dns0 = getArray(moulinette_get('ip6_dns0')); $ip6_dns1 = getArray(moulinette_get('ip6_dns1')); $ip4_nat_prefix = getArray(moulinette_get('ip4_nat_prefix')); $ip4_dns0 = getArray(moulinette_get('ip4_dns0')); $ip4_dns1 = getArray(moulinette_get('ip4_dns1')); for ($i = 0; $i < $multissid; $i++) { $ssid = ['id' => $i, 'wifi_ssid' => noneValue($wifi_ssid[$i]), 'wifi_secure' => noneValue($wifi_secure[$i]), 'wifi_passphrase' => noneValue($wifi_passphrase[$i]), 'ip6_net' => noneValue($ip6_net[$i]), 'ip6_dns0' => noneValue($ip6_dns0[$i]), 'ip6_dns1' => noneValue($ip6_dns1[$i]), 'ip4_nat_prefix' => noneValue($ip4_nat_prefix[$i]), 'ip4_dns0' => noneValue($ip4_dns0[$i]), 'ip4_dns1' => noneValue($ip4_dns1[$i])]; array_push($ssids, $ssid); } $ip6_net = moulinette_get('ip6_net'); $ip6_net = $ip6_net == 'none' ? '' : getArray($ip6_net); $ip4_nat_prefix = getArray(moulinette_get('ip4_nat_prefix')); set('service_enabled', moulinette_get('service_enabled')); set('ssids', $ssids); set('wifi_device', $wifi_device); set('wifi_channel', $wifi_channel); set('wifi_device_list', $devs_list); set('faststatus', service_faststatus() == 0); set('is_connected_through_hotspot', is_connected_through_hotspot($ip6_net, $ip4_nat_prefix)); return render('settings.html.php'); }); dispatch_put('/settings', function () { exec('ip link show ' . escapeshellarg($_POST['wifi_device']), $output, $retcode); $wifi_device_exists = $retcode == 0; $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; $wifi_ssid_uniqueness = array(); $ip4_nat_prefix_uniqueness = array(); $ip6_net_uniqueness = array();