start api implementation

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-02-15 07:47:35 +01:00
parent 5c30961d3c
commit dd371c72a2
9 changed files with 339 additions and 13 deletions

View File

@@ -25,7 +25,7 @@
* @author Florian Lippert <flo@syscp.org>
* @author Ron Brand <ron.brand@web.de>
*/
function standard_error($errors = '', $replacer = '') {
function standard_error($errors = '', $replacer = '', $throw_exception = false) {
global $userinfo, $s, $header, $footer, $lng, $theme;
@@ -60,6 +60,9 @@ function standard_error($errors = '', $replacer = '') {
}
}
if ($throw_exception) {
throw new Exception($error);
}
eval("echo \"" . getTemplate('misc/error', '1') . "\";");
exit;
}

View File

@@ -31,7 +31,7 @@
*
*/
function validate($str, $fieldname, $pattern = '', $lng = '', $emptydefault = array()) {
function validate($str, $fieldname, $pattern = '', $lng = '', $emptydefault = array(), $throw_exception = false) {
global $log, $theme;
@@ -74,6 +74,6 @@ function validate($str, $fieldname, $pattern = '', $lng = '', $emptydefault = ar
$lng = 'stringformaterror';
}
standard_error($lng, $fieldname);
standard_error($lng, $fieldname, $throw_exception);
exit;
}

View File

@@ -23,7 +23,7 @@
* @return mixed ip address on success, standard_error on failure
* @deprecated use validate_ip2
*/
function validate_ip($ip, $return_bool = false, $lng = 'invalidip') {
function validate_ip($ip, $return_bool = false, $lng = 'invalidip', $throw_exception = false) {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false
&& filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false
@@ -32,7 +32,7 @@ function validate_ip($ip, $return_bool = false, $lng = 'invalidip') {
if ($return_bool) {
return false;
} else {
standard_error($lng, $ip);
standard_error($lng, $ip, $throw_exception);
exit();
}
} else {
@@ -53,7 +53,7 @@ function validate_ip($ip, $return_bool = false, $lng = 'invalidip') {
*
* @return string|bool ip address on success, false on failure
*/
function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_localhost = false, $allow_priv = false, $allow_cidr = false) {
function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_localhost = false, $allow_priv = false, $allow_cidr = false, $throw_exception = false) {
$cidr = "";
if ($allow_cidr) {
@@ -69,7 +69,7 @@ function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_loca
if ($return_bool) {
return false;
} else {
standard_error($lng, $ip);
standard_error($lng, $ip, $throw_exception);
exit();
}
}
@@ -91,7 +91,7 @@ function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_loca
if ($return_bool) {
return false;
} else {
standard_error($lng, $ip);
standard_error($lng, $ip, $throw_exception);
exit();
}
}