From d8382e5c66e4ad3151b50eef29175e33cf7dc3dc Mon Sep 17 00:00:00 2001 From: anton-reutov Date: Sat, 6 Dec 2014 14:57:29 +0300 Subject: [PATCH 1/6] Update ports.conf --- install/debian/firewall/ports.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/install/debian/firewall/ports.conf b/install/debian/firewall/ports.conf index 8b371f2e5..e970f91de 100644 --- a/install/debian/firewall/ports.conf +++ b/install/debian/firewall/ports.conf @@ -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' From 7ab09233c0771fc2c21e9f7f06ddca1b2ddefbc8 Mon Sep 17 00:00:00 2001 From: anton-reutov Date: Sat, 6 Dec 2014 14:59:03 +0300 Subject: [PATCH 2/6] Update ports.conf --- install/rhel/firewall/ports.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/install/rhel/firewall/ports.conf b/install/rhel/firewall/ports.conf index 8b371f2e5..e970f91de 100644 --- a/install/rhel/firewall/ports.conf +++ b/install/rhel/firewall/ports.conf @@ -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' From 6c73c2078b57d9849e37fc09cd727b937a0188f5 Mon Sep 17 00:00:00 2001 From: anton-reutov Date: Sat, 6 Dec 2014 15:00:11 +0300 Subject: [PATCH 3/6] Update ports.conf --- install/ubuntu/firewall/ports.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/install/ubuntu/firewall/ports.conf b/install/ubuntu/firewall/ports.conf index 8b371f2e5..e970f91de 100644 --- a/install/ubuntu/firewall/ports.conf +++ b/install/ubuntu/firewall/ports.conf @@ -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' From 608b9d740ae988de809ff40c13d0743f38600b3c Mon Sep 17 00:00:00 2001 From: Stuart H Jimenez Date: Tue, 9 Dec 2014 13:45:34 -0600 Subject: [PATCH 4/6] If you use an api key you wont have to set a user name, if you don't use a key you will have to login as admin. --- web/api/index.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/web/api/index.php b/web/api/index.php index 80354da07..c0b420dbe 100644 --- a/web/api/index.php +++ b/web/api/index.php @@ -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); @@ -20,13 +26,6 @@ if (isset($_POST['user']) || isset($_POST['hash'])) { echo 'Error: authentication failed'; 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']); From 95b77d8bffecff227249b9befe70566a41f88f39 Mon Sep 17 00:00:00 2001 From: Stuart H Jimenez Date: Tue, 9 Dec 2014 16:11:42 -0600 Subject: [PATCH 5/6] Simple api key generator --- bin/v-generate-api-key | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 bin/v-generate-api-key diff --git a/bin/v-generate-api-key b/bin/v-generate-api-key new file mode 100644 index 000000000..a6f044a1c --- /dev/null +++ b/bin/v-generate-api-key @@ -0,0 +1,37 @@ +#!/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 [[ -e ${KEYS}${HASH} ]] ; then + while [[ -e ${KEYS}${HASH} ]] ; do + HASH=$(keygen) + done +fi + +touch ${KEYS}${HASH} +echo ${HASH} + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit From 00a393f4ac3e96b476dfe190ac645d2b767bc4d9 Mon Sep 17 00:00:00 2001 From: Stuart H Jimenez Date: Tue, 9 Dec 2014 16:23:08 -0600 Subject: [PATCH 6/6] If the keys dir does not exists create it. --- bin/v-generate-api-key | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/v-generate-api-key b/bin/v-generate-api-key index a6f044a1c..5fe2cc81b 100644 --- a/bin/v-generate-api-key +++ b/bin/v-generate-api-key @@ -21,6 +21,10 @@ HASH=$(keygen) # Action # #----------------------------------------------------------# +if [ ! -d ${KEYS} ]; then + mkdir ${KEYS} +fi + if [[ -e ${KEYS}${HASH} ]] ; then while [[ -e ${KEYS}${HASH} ]] ; do HASH=$(keygen)