Skip to content

Commit bf41cf7

Browse files
Daniel AléxisDanielScIT-Raphaeljaapmarcus
authored
Small improvement to the API (hestiacp#1372)
This PR returns error codes via API when passing incorrect data or failed authentication. Co-authored-by: Daniel <alexis@pop-os.localdomain> Co-authored-by: Raphael Schneeberger <rs@scit.ch> Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 5e64915 commit bf41cf7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

web/api/index.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
}
1212

1313
$password = $_POST['password'];
14+
if (!isset($password)){
15+
echo 'Error: missing authentication';
16+
exit;
17+
}
1418
$v_ip = escapeshellarg($_SERVER['REMOTE_ADDR']);
1519
$output = '';
1620
exec (HESTIA_CMD."v-get-user-salt admin ".$v_ip." json" , $output, $return_var);
@@ -59,15 +63,11 @@
5963
exit;
6064
}
6165
} else {
62-
$return_var = 1;
66+
echo 'Error: authentication failed';
67+
exit;
6368
}
6469
}
6570

66-
if ( $return_var > 0 ) {
67-
echo 'Error: authentication failed';
68-
exit;
69-
}
70-
7171
// Prepare arguments
7272
if (isset($_POST['cmd'])) $cmd = escapeshellarg($_POST['cmd']);
7373
if (isset($_POST['arg1'])) $arg1 = escapeshellarg($_POST['arg1']);
@@ -122,4 +122,7 @@
122122
echo implode("\n",$output)."\n";
123123
}
124124
}
125+
} else {
126+
echo "Error: data received is null or invalid, check https://docs.hestiacp.com/admin_docs/rest_api.html";
127+
exit;
125128
}

0 commit comments

Comments
 (0)