File tree Expand file tree Collapse file tree 2 files changed +47
-7
lines changed
Expand file tree Collapse file tree 2 files changed +47
-7
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # info: generate api key
3+ # options: none
4+ #
5+ # The function creates a key file in /usr/local/vesta/data/keys/
6+
7+
8+ # ----------------------------------------------------------#
9+ # Variable&Function #
10+ # ----------------------------------------------------------#
11+
12+ keygen ()
13+ {
14+ cat /dev/urandom | tr -dc ' a-zA-Z0-9' | fold -w ${1:- 32} | head -n 1
15+ }
16+ KEYS=' /usr/local/vesta/data/keys/'
17+ HASH=$( keygen)
18+
19+
20+ # ----------------------------------------------------------#
21+ # Action #
22+ # ----------------------------------------------------------#
23+
24+ if [ ! -d ${KEYS} ]; then
25+ mkdir ${KEYS}
26+ fi
27+
28+ if [[ -e ${KEYS}${HASH} ]] ; then
29+ while [[ -e ${KEYS}${HASH} ]] ; do
30+ HASH=$( keygen)
31+ done
32+ fi
33+
34+ touch ${KEYS}${HASH}
35+ echo ${HASH}
36+
37+ # ----------------------------------------------------------#
38+ # Vesta #
39+ # ----------------------------------------------------------#
40+
41+ exit
Original file line number Diff line number Diff line change 66 // Authentication
77 $ auth_code = 1 ;
88 if (empty ($ _POST ['hash ' ])) {
9+ // Check user permission to use API
10+ if ($ _POST ['user ' ] != 'admin ' ) {
11+ echo 'Error: only admin is allowed to use API ' ;
12+ exit ;
13+ }
14+
915 $ v_user = escapeshellarg ($ _POST ['user ' ]);
1016 $ v_password = escapeshellarg ($ _POST ['password ' ]);
1117 exec (VESTA_CMD ."v-check-user-password " .$ v_user ." " .$ v_password ." ' " .$ _SERVER ["REMOTE_ADDR " ]."' " , $ output , $ auth_code );
2026 echo 'Error: authentication failed ' ;
2127 exit ;
2228 }
23-
24- // Check user permission to use API
25- if ($ _POST ['user ' ] != 'admin ' ) {
26- echo 'Error: only admin is allowed to use API ' ;
27- exit ;
28- }
29-
3029
3130 // Prepare arguments
3231 if (isset ($ _POST ['cmd ' ])) $ cmd = escapeshellarg ($ _POST ['cmd ' ]);
You can’t perform that action at this time.
0 commit comments