Skip to content

Commit f2b42fa

Browse files
committed
Merge pull request hestiacp#2 from serghey-rodin/master
update with master
2 parents e00ed17 + 5ba751b commit f2b42fa

File tree

113 files changed

+4025
-2773
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+4025
-2773
lines changed

bin/v-add-cron-job

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
5555
# Adding to crontab
5656
echo "$str" >> $VESTA/data/users/$user/cron.conf
5757

58-
# Chaning permissions
58+
# Changing permissions
5959
chmod 660 $VESTA/data/users/$user/cron.conf
6060

6161
# Sort jobs by id number

bin/v-copy-fs-file

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# File copier
3+
4+
user=$1
5+
file_src=$2
6+
file_dst=$3
7+
8+
# Checking arguments
9+
if [ -z "$file_dst" ]; then
10+
echo "Usage: USER SRC_FILE DST_FILE"
11+
exit 1
12+
fi
13+
14+
# Checking users
15+
if [ ! -e "$VESTA/data/users/$user" ]; then
16+
exit 1
17+
fi
18+
19+
# Checking homedir
20+
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
21+
if [ -z $homedir ]; then
22+
exit 1
23+
fi
24+
25+
# Checking source file
26+
if [ ! -e "$file_src" ]; then
27+
exit 1
28+
fi
29+
30+
# Checking source path
31+
rpath=$(readlink -f "$file_src")
32+
if [ -z "$(echo $rpath |grep ^/tmp)" ]; then
33+
exit 1
34+
fi
35+
36+
# Checking destination path
37+
rpath=$(readlink -f "$file_dst")
38+
if [ -z "$(echo $rpath |grep ^$homedir)" ]; then
39+
exit 1
40+
fi
41+
42+
# Checking dst file permission
43+
if [ -e "$file_dst" ]; then
44+
perms=$(stat --format '%a' $file_dst)
45+
fi
46+
47+
# Copying file
48+
cp $file_src $file_dst
49+
50+
# Changing ownership
51+
chown $user:$user $file_dst
52+
53+
# Changin permissions
54+
if [ ! -z "$perms" ]; then
55+
chmod $perms $file_dst
56+
fi
57+
58+
exit

bin/v-list-fs-directory

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# File list wrapper
3+
4+
user=$1
5+
path=$2
6+
7+
# Checking arguments
8+
if [ -z "$user" ]; then
9+
echo "Usage: USER [PATH]"
10+
exit 1
11+
fi
12+
13+
# Checking users
14+
if [ ! -e "$VESTA/data/users/$user" ]; then
15+
exit 1
16+
fi
17+
18+
# Checking homedir
19+
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
20+
if [ -z $homedir ]; then
21+
exit 1
22+
fi
23+
24+
# Checking path
25+
if [ ! -z "$path" ]; then
26+
# Validating absolute path
27+
rpath=$(readlink -f "$path")
28+
if [ -z "$(echo $rpath |grep $homedir)" ]; then
29+
exit 1
30+
fi
31+
else
32+
path=$homedir
33+
fi
34+
35+
# Listing files
36+
find "$path" -maxdepth 1 -printf "%y/%m/%TY-%Tm-%Td/%TH:%TM:%TS/%u/%g/%s/%P\n"
37+
38+
39+
exit

bin/v-list-user-ns

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ json_list_ns() {
2121
ns=$(grep "^NS='" $USER_DATA/user.conf |cut -f 2 -d \')
2222
echo '['
2323
i=1
24-
nslistc=$(echo -e "${ns//,/\n}"|wc -l)
24+
nslistc=$(echo -e "${ns//,/\\n}"|wc -l)
2525
for nameserver in ${ns//,/ };do
2626
if [ "$i" -ne "$nslistc" ]; then
2727
echo -e "\t\"$nameserver\","

bin/v-open-fs-file

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
# File reader
3+
4+
user=$1
5+
path=$2
6+
7+
# Checking arguments
8+
if [ -z "$path" ]; then
9+
echo "Usage: USER PATH"
10+
exit 1
11+
fi
12+
13+
# Checking users
14+
if [ ! -e "$VESTA/data/users/$user" ]; then
15+
exit 1
16+
fi
17+
18+
# Checking homedir
19+
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
20+
if [ -z $homedir ]; then
21+
exit 1
22+
fi
23+
24+
# Checking path
25+
if [ ! -z "$path" ]; then
26+
# Validating absolute path
27+
rpath=$(readlink -f "$path")
28+
if [ -z "$(echo $rpath |grep $homedir)" ]; then
29+
exit 1
30+
fi
31+
fi
32+
33+
cat "$path"
34+
35+
exit
36+

func/db.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,20 +337,20 @@ dump_mysql_database() {
337337
fi
338338

339339
query='SELECT VERSION()'
340-
mysql -h $HOST -u $USER -p$PASSWORD -e "$query" > /dev/null 2>&1
340+
mysql -h $HOST -u $USER -p$PASSWORD -e "$query" >/dev/null 2>/tmp/e.mysql
341341
if [ '0' -ne "$?" ]; then
342342
rm -rf $tmpdir
343-
echo "Can't connect to mysql server $HOST" |\
343+
echo -e "Can't connect to $HOST\n$(cat /tmp/e.mysql)" |\
344344
$send_mail -s "$subj" $email
345345
echo "Error: Connection failed"
346346
log_event "$E_CONNECT $EVENT"
347347
exit $E_CONNECT
348348
fi
349349

350-
mysqldump -h $HOST -u $USER -p$PASSWORD -r $dump $database
350+
mysqldump -h $HOST -u $USER -p$PASSWORD -r $dump $database 2>/tmp/e.mysql
351351
if [ '0' -ne "$?" ]; then
352352
rm -rf $tmpdir
353-
echo "Can't dump mysql database $database" |\
353+
echo -e "Can't dump database $database\n$(cat /tmp/e.mysql)" |\
354354
$send_mail -s "$subj" $email
355355
echo "Error: dump $database failed"
356356
log_event "$E_DB $EVENT"

web/add/cron/index.php

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,19 @@
44
ob_start();
55
session_start();
66
$TAB = 'CRON';
7-
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
87

9-
// Header
10-
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
11-
12-
// Panel
13-
top_panel($user,$TAB);
8+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
149

10+
// Check POST request
1511
if (!empty($_POST['ok'])) {
16-
// Check input
12+
13+
// Check empty fields
1714
if ((!isset($_POST['v_min'])) || ($_POST['v_min'] == '')) $errors[] = __('minute');
1815
if ((!isset($_POST['v_hour'])) || ($_POST['v_hour'] == '')) $errors[] = __('hour');
1916
if ((!isset($_POST['v_day'])) || ($_POST['v_day'] == '')) $errors[] = __('day');
2017
if ((!isset($_POST['v_month'])) || ($_POST['v_month'] == '')) $errors[] = __('month');
2118
if ((!isset($_POST['v_wday'])) || ($_POST['v_wday'] == '')) $errors[] = __('day of week');
2219
if ((!isset($_POST['v_cmd'])) || ($_POST['v_cmd'] == '')) $errors[] = __('cmd');
23-
24-
// Protect input
25-
$v_min = escapeshellarg($_POST['v_min']);
26-
$v_hour = escapeshellarg($_POST['v_hour']);
27-
$v_day = escapeshellarg($_POST['v_day']);
28-
$v_month = escapeshellarg($_POST['v_month']);
29-
$v_wday = escapeshellarg($_POST['v_wday']);
30-
$v_cmd = escapeshellarg($_POST['v_cmd']);
31-
32-
// Check for errors
3320
if (!empty($errors[0])) {
3421
foreach ($errors as $i => $error) {
3522
if ( $i == 0 ) {
@@ -39,32 +26,46 @@
3926
}
4027
}
4128
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
42-
} else {
43-
// Add Cron Job
29+
}
30+
31+
// Protect input
32+
$v_min = escapeshellarg($_POST['v_min']);
33+
$v_hour = escapeshellarg($_POST['v_hour']);
34+
$v_day = escapeshellarg($_POST['v_day']);
35+
$v_month = escapeshellarg($_POST['v_month']);
36+
$v_wday = escapeshellarg($_POST['v_wday']);
37+
$v_cmd = escapeshellarg($_POST['v_cmd']);
38+
39+
// Add cron job
40+
if (empty($_SESSION['error_msg'])) {
4441
exec (VESTA_CMD."v-add-cron-job ".$user." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
45-
$v_type = $_POST['v_type'];
46-
$v_charset = $_POST['v_charset'];
4742
check_return_code($return_var,$output);
48-
unset($v_password);
4943
unset($output);
50-
if (empty($_SESSION['error_msg'])) {
51-
$_SESSION['ok_msg'] = __('CRON_CREATED_OK');
52-
unset($v_min);
53-
unset($v_hour);
54-
unset($v_day);
55-
unset($v_month);
56-
unset($v_wday);
57-
unset($v_cmd);
58-
unset($output);
59-
}
44+
}
45+
46+
// Flush field values on success
47+
if (empty($_SESSION['error_msg'])) {
48+
$_SESSION['ok_msg'] = __('CRON_CREATED_OK');
49+
unset($v_min);
50+
unset($v_hour);
51+
unset($v_day);
52+
unset($v_month);
53+
unset($v_wday);
54+
unset($v_cmd);
55+
unset($output);
6056
}
6157
}
6258

63-
exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
64-
$db_types = json_decode(implode('', $output), true);
65-
unset($output);
59+
// Header
60+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
6661

62+
// Panel
63+
top_panel($user,$TAB);
64+
65+
// Display body
6766
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_cron.html');
67+
68+
// Flush session messages
6869
unset($_SESSION['error_msg']);
6970
unset($_SESSION['ok_msg']);
7071

0 commit comments

Comments
 (0)