Clean PHP exceptions
This commit is contained in:
@@ -55,49 +55,42 @@ dispatch_put('/settings', function() {
|
||||
$ip6_net = empty($_POST['ip6_net']) ? 'none' : $_POST['ip6_net'];
|
||||
$ip6_addr = 'none';
|
||||
|
||||
try {
|
||||
if(empty($_POST['server_name']) || empty($_POST['server_port']) || empty($_POST['server_proto'])) {
|
||||
flash('error', T_('The Server Address, the Server Port and the Protocol cannot be empty.'));
|
||||
goto redirect;
|
||||
throw new Exception(T_('The Server Address, the Server Port and the Protocol cannot be empty'));
|
||||
}
|
||||
|
||||
if(!preg_match('/^\d+$/', $_POST['server_port'])) {
|
||||
flash('error', T_('The Server Port must be only composed of digits.'));
|
||||
goto redirect;
|
||||
throw new Exception(T_('The Server Port must be only composed of digits'));
|
||||
}
|
||||
|
||||
if($_POST['server_proto'] != 'udp' && $_POST['server_proto'] != 'tcp') {
|
||||
flash('error', T_('The Protocol must be "udp" or "tcp".'));
|
||||
goto redirect;
|
||||
throw new Exception(T_('The Protocol must be "udp" or "tcp"'));
|
||||
}
|
||||
|
||||
if(($_FILES['crt_client']['error'] == UPLOAD_ERR_OK && $_FILES['crt_client_key']['error'] != UPLOAD_ERR_OK && (!$crt_client_key_exists || $_POST['crt_client_key_delete'] == 1))
|
||||
|| ($_FILES['crt_client_key']['error'] == UPLOAD_ERR_OK && $_FILES['crt_client']['error'] != UPLOAD_ERR_OK && (!$crt_client_exists || $_POST['crt_client_delete'] == 1))) {
|
||||
|
||||
flash('error', T_('A Client Certificate is needed when you suggest a Key (or vice versa).'));
|
||||
goto redirect;
|
||||
throw new Exception(T_('A Client Certificate is needed when you suggest a Key, or vice versa'));
|
||||
}
|
||||
|
||||
if(empty($_POST['login_user']) xor empty($_POST['login_passphrase'])) {
|
||||
flash('error', T_('A Password is needed when you suggest a Username (or vice versa).'));
|
||||
goto redirect;
|
||||
throw new Exception(T_('A Password is needed when you suggest a Username, or vice versa'));
|
||||
}
|
||||
|
||||
if($_FILES['crt_server_ca']['error'] != UPLOAD_ERR_OK && !$crt_server_ca_exists) {
|
||||
flash('error', T_('You need a Server CA.'));
|
||||
goto redirect;
|
||||
throw new Exception(T_('You need a Server CA.'));
|
||||
}
|
||||
|
||||
if(($_FILES['crt_client_key']['error'] != UPLOAD_ERR_OK && (!$crt_client_key_exists || $_POST['crt_client_key_delete'] == 1)) && empty($_POST['login_user'])) {
|
||||
flash('error', T_('You need either a Client Certificate, either a Username (or both).'));
|
||||
goto redirect;
|
||||
throw new Exception(T_('You need either a Client Certificate, either a Username, or both'));
|
||||
}
|
||||
|
||||
if($ip6_net != 'none') {
|
||||
$ip6_net = ipv6_expanded($ip6_net);
|
||||
|
||||
if(empty($ip6_net)) {
|
||||
flash('error', T_('The IPv6 Delegated Prefix format looks bad.'));
|
||||
goto redirect;
|
||||
throw new Exception(T_('The IPv6 Delegated Prefix format looks bad'));
|
||||
}
|
||||
|
||||
$ip6_blocs = explode(':', $ip6_net);
|
||||
@@ -107,6 +100,11 @@ dispatch_put('/settings', function() {
|
||||
$ip6_addr = ipv6_compressed($ip6_addr);
|
||||
}
|
||||
|
||||
} catch(Exception $e) {
|
||||
flash('error', $e->getMessage().T_(' (configuration not updated).'));
|
||||
goto redirect;
|
||||
}
|
||||
|
||||
stop_service();
|
||||
|
||||
moulinette_set('server_name', $_POST['server_name']);
|
||||
|
Reference in New Issue
Block a user