Merge branch 'master' of github.com:serghey-rodin/vesta

This commit is contained in:
Serghey Rodin 2014-12-12 01:49:06 +02:00
commit a719b6d4d4
5 changed files with 50 additions and 7 deletions

41
bin/v-generate-api-key Normal file
View file

@ -0,0 +1,41 @@
#!/bin/bash
# info: generate api key
# options: none
#
# The function creates a key file in /usr/local/vesta/data/keys/
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
keygen()
{
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
}
KEYS='/usr/local/vesta/data/keys/'
HASH=$(keygen)
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ ! -d ${KEYS} ]; then
mkdir ${KEYS}
fi
if [[ -e ${KEYS}${HASH} ]] ; then
while [[ -e ${KEYS}${HASH} ]] ; do
HASH=$(keygen)
done
fi
touch ${KEYS}${HASH}
echo ${HASH}
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

View file

@ -13,3 +13,4 @@ PROTOCOL='TCP' PORT='5432'
PROTOCOL='TCP' PORT='8080'
PROTOCOL='TCP' PORT='8443'
PROTOCOL='TCP' PORT='8083'
PROTOCOL='TCP' PORT='12000:12100'

View file

@ -13,3 +13,4 @@ PROTOCOL='TCP' PORT='5432'
PROTOCOL='TCP' PORT='8080'
PROTOCOL='TCP' PORT='8443'
PROTOCOL='TCP' PORT='8083'
PROTOCOL='TCP' PORT='12000:12100'

View file

@ -13,3 +13,4 @@ PROTOCOL='TCP' PORT='5432'
PROTOCOL='TCP' PORT='8080'
PROTOCOL='TCP' PORT='8443'
PROTOCOL='TCP' PORT='8083'
PROTOCOL='TCP' PORT='12000:12100'

View file

@ -6,6 +6,12 @@ if (isset($_POST['user']) || isset($_POST['hash'])) {
// Authentication
$auth_code = 1;
if (empty($_POST['hash'])) {
// Check user permission to use API
if ($_POST['user'] != 'admin') {
echo 'Error: only admin is allowed to use API';
exit;
}
$v_user = escapeshellarg($_POST['user']);
$v_password = escapeshellarg($_POST['password']);
exec(VESTA_CMD ."v-check-user-password ".$v_user." ".$v_password." '".$_SERVER["REMOTE_ADDR"]."'", $output, $auth_code);
@ -21,13 +27,6 @@ if (isset($_POST['user']) || isset($_POST['hash'])) {
exit;
}
// Check user permission to use API
if ($_POST['user'] != 'admin') {
echo 'Error: only admin is allowed to use API';
exit;
}
// Prepare arguments
if (isset($_POST['cmd'])) $cmd = escapeshellarg($_POST['cmd']);
if (isset($_POST['arg1'])) $arg1 = escapeshellarg($_POST['arg1']);