Просмотр исходного кода

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

Serghey Rodin 11 лет назад
Родитель
Сommit
a719b6d4d4

+ 41 - 0
bin/v-generate-api-key

@@ -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

+ 1 - 0
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'

+ 1 - 0
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'

+ 1 - 0
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'

+ 6 - 7
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']);