$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', ynh_setting_get('service_enabled')); set('wifi_device_id', $wifi_device_id); set('wifi_ssid', $wifi_ssid); set('wifi_ssid_list', $wifi_ssid_list); set('opt_maxspace', ynh_setting_get('opt_maxspace')); set('opt_renaming', ynh_setting_get('opt_renaming')); set('opt_deleting', ynh_setting_get('opt_deleting')); set('opt_chat', ynh_setting_get('opt_chat')); set('opt_name', ynh_setting_get('opt_name')); set('opt_domain', ynh_setting_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') . ').');
} function ipv6_compressed($ip) { exec('ipv6_compressed ' . escapeshellarg($ip), $output); return $output[0]; } dispatch('/', function () { $ip6_net = ynh_setting_get('ip6_net'); $ip6_net = $ip6_net == 'none' ? '' : $ip6_net; $raw_openvpn = file_get_contents('/etc/openvpn/client.conf.tpl'); set('service_enabled', ynh_setting_get('service_enabled')); set('server_name', ynh_setting_get('server_name')); set('server_port', ynh_setting_get('server_port')); set('server_proto', ynh_setting_get('server_proto')); set('login_user', ynh_setting_get('login_user')); set('login_passphrase', ynh_setting_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';
$wifi_passphrase = getArray(ynh_setting_get('wifi_passphrase')); $ip6_net = getArray(ynh_setting_get('ip6_net')); $ip6_firewall = getArray(ynh_setting_get('ip6_firewall')); $ip6_dns0 = getArray(ynh_setting_get('ip6_dns0')); $ip6_dns1 = getArray(ynh_setting_get('ip6_dns1')); $ip4_nat_prefix = getArray(ynh_setting_get('ip4_nat_prefix')); $ip4_dns0 = getArray(ynh_setting_get('ip4_dns0')); $ip4_dns1 = getArray(ynh_setting_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_firewall' => noneValue($ip6_firewall[$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 = ynh_setting_get('ip6_net'); $ip6_net = $ip6_net == 'none' ? '' : getArray($ip6_net); $ip4_nat_prefix = getArray(ynh_setting_get('ip4_nat_prefix')); set('service_enabled', ynh_setting_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();
$raw_openvpn = file_get_contents('/etc/openvpn/client.conf.tpl'); set('service_enabled', ynh_setting_get('service_enabled')); set('server_name', noneValue(ynh_setting_get('server_name'))); set('server_port', ynh_setting_get('server_port')); set('server_proto', ynh_setting_get('server_proto')); set('login_user', ynh_setting_get('login_user')); set('login_passphrase', ynh_setting_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_client_ta_exists', file_exists('/etc/openvpn/keys/user_ta.key')); set('crt_server_ca_exists', file_exists('/etc/openvpn/keys/ca-server.crt')); set('faststatus', service_faststatus() == 0); set('raw_openvpn', $raw_openvpn); set('dns0', ynh_setting_get('dns0')); set('dns1', ynh_setting_get('dns1')); return render('settings.html.php'); }); dispatch_put('/settings', function () { $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; if ($service_enabled == 1) { $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'); $config = $_POST; $autoconf = false; try { if ($_FILES['cubefile']['error'] == UPLOAD_ERR_OK) { $config = readAutoConf($_FILES['cubefile']['tmp_name']); if (is_null($config)) { throw new Exception(_('Json Syntax Error, please check your dot cube file'));