Skip to content

Commit 06c7b42

Browse files
committed
edit user package
1 parent 9a1fde8 commit 06c7b42

File tree

7 files changed

+364
-17
lines changed

7 files changed

+364
-17
lines changed

bin/v_change_user_package

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: change user package
3-
# options: user package
3+
# options: user package [force]
44
#
55
# The function changes user's hosting package.
66

@@ -12,6 +12,7 @@
1212
# Argument defenition
1313
user=$1
1414
package=$2
15+
force=$3
1516

1617
# Includes
1718
source $VESTA/conf/vesta.conf
@@ -54,7 +55,8 @@ change_user_package() {
5455
usr_data=$(cat $USER_DATA/user.conf)
5556
eval $usr_data
5657

57-
pkg_data=$(cat $VESTA/data/packages/$package.pkg)
58+
pkg_data=$(cat $VESTA/data/packages/$package.pkg |grep -v TIME |\
59+
grep -v DATE)
5860
eval $pkg_data
5961

6062
echo "FNAME='$FNAME'
@@ -114,11 +116,13 @@ DATE='$DATE'" > $USER_DATA/user.conf
114116
# Verifications #
115117
#----------------------------------------------------------#
116118

117-
check_args '2' "$#" 'user package'
119+
check_args '2' "$#" 'user package [force]'
118120
validate_format 'user' 'package'
119121
is_object_valid 'user' 'USER' "$user"
120122
is_package_valid
121-
is_package_avalable
123+
if [ "$force" != 'yes' ];then
124+
is_package_avalable
125+
fi
122126

123127

124128
#----------------------------------------------------------#

bin/v_update_user_package

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# info: update user package
3+
# options: pacakge
4+
#
5+
# The function propogates package to connected users.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
package=$1
14+
15+
# Includes
16+
source $VESTA/conf/vesta.conf
17+
source $VESTA/func/main.sh
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'package'
25+
validate_format 'package'
26+
is_package_valid
27+
28+
29+
#----------------------------------------------------------#
30+
# Action #
31+
#----------------------------------------------------------#
32+
33+
for user in $(ls $VESTA/data/users); do
34+
check_package=$(grep "PACKAGE='$package'" $USER_DATA/$user/user.conf)
35+
if [ ! -z "$check_package" ]; then
36+
$BIN/v_change_user_package $user $package 'yes'
37+
fi
38+
done
39+
40+
#----------------------------------------------------------#
41+
# Vesta #
42+
#----------------------------------------------------------#
43+
44+
# Logging
45+
log_event "$OK" "$EVENT"
46+
47+
exit

web/add/package/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
}
115115

116116
// Remove tmpdir
117-
exec ('rm -rf '.$tmdir, $output, $return_var);
117+
exec ('rm -rf '.$tmpdir, $output, $return_var);
118118
unset($output);
119119

120120
// Check output

web/edit/package/index.php

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
7+
$TAB = 'PACKAGE';
8+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
9+
10+
// Header
11+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
12+
13+
// Panel
14+
top_panel($user,$TAB);
15+
16+
// Are you admin?
17+
if ($_SESSION['user'] == 'admin') {
18+
19+
// Check user argument?
20+
if (empty($_GET['package'])) {
21+
header("Location: /list/package/");
22+
exit;
23+
}
24+
25+
$v_package = escapeshellarg($_GET['package']);
26+
exec (VESTA_CMD."v_list_user_package ".$v_package." 'json'", $output, $return_var);
27+
if ($return_var != 0) {
28+
$error = implode('<br>', $output);
29+
if (empty($error)) $error = 'Error: vesta did not return any output.';
30+
$_SESSION['error_msg'] = $error;
31+
} else {
32+
$data = json_decode(implode('', $output), true);
33+
unset($output);
34+
35+
$v_package = $_GET['package'];
36+
$v_template = $data[$v_package]['TEMPLATE'];
37+
$v_web_domains = $data[$v_package]['WEB_DOMAINS'];
38+
$v_web_aliases = $data[$v_package]['WEB_ALIASES'];
39+
$v_dns_domains = $data[$v_package]['DNS_DOMAINS'];
40+
$v_dns_records = $data[$v_package]['DNS_RECORDS'];
41+
$v_mail_domains = $data[$v_package]['MAIL_DOMAINS'];
42+
$v_mail_accounts = $data[$v_package]['MAIL_ACCOUNTS'];
43+
$v_databases = $data[$v_package]['DATABASES'];
44+
$v_cron_jobs = $data[$v_package]['CRON_JOBS'];
45+
$v_disk_quota = $data[$v_package]['DISK_QUOTA'];
46+
$v_bandwidth = $data[$v_package]['BANDWIDTH'];
47+
$v_shell = $data[$v_package]['SHELL'];
48+
$v_ns = $data[$v_package]['NS'];
49+
$nameservers = explode(", ", $v_ns);
50+
$v_ns1 = $nameservers[0];
51+
$v_ns2 = $nameservers[1];
52+
$v_ns3 = $nameservers[2];
53+
$v_ns4 = $nameservers[3];
54+
$v_backups = $data[$v_package]['BACKUPS'];
55+
$v_date = $data[$v_package]['DATE'];
56+
$v_time = $data[$v_package]['TIME'];
57+
$v_status = 'active';
58+
59+
60+
exec (VESTA_CMD."v_list_web_templates json", $output, $return_var);
61+
check_error($return_var);
62+
$templates = json_decode(implode('', $output), true);
63+
unset($output);
64+
65+
exec (VESTA_CMD."v_list_sys_shells json", $output, $return_var);
66+
check_error($return_var);
67+
$shells = json_decode(implode('', $output), true);
68+
unset($output);
69+
70+
// Action
71+
if (!empty($_POST['save'])) {
72+
// Check input
73+
if (empty($_POST['v_package'])) $errors[] = 'package';
74+
if (empty($_POST['v_template'])) $errors[] = 'template';
75+
if (empty($_POST['v_shell'])) $errrors[] = 'shell';
76+
if (!isset($_POST['v_web_domains'])) $errors[] = 'web domains';
77+
if (!isset($_POST['v_web_aliases'])) $errors[] = 'web aliases';
78+
if (!isset($_POST['v_dns_domains'])) $errors[] = 'dns domains';
79+
if (!isset($_POST['v_dns_records'])) $errors[] = 'dns records';
80+
if (!isset($_POST['v_mail_domains'])) $errors[] = 'mail domains';
81+
if (!isset($_POST['v_mail_accounts'])) $errors[] = 'mail accounts';
82+
if (!isset($_POST['v_databases'])) $errors[] = 'databases';
83+
if (!isset($_POST['v_cron_jobs'])) $errors[] = 'cron jobs';
84+
if (!isset($_POST['v_backups'])) $errors[] = 'backups';
85+
if (!isset($_POST['v_disk_quota'])) $errors[] = 'quota';
86+
if (!isset($_POST['v_bandwidth'])) $errors[] = 'bandwidth';
87+
if (empty($_POST['v_ns1'])) $errors[] = 'ns1';
88+
if (empty($_POST['v_ns2'])) $errors[] = 'ns2';
89+
90+
// Protect input
91+
$v_package = escapeshellarg($_POST['v_package']);
92+
$v_template = escapeshellarg($_POST['v_template']);
93+
$v_shell = escapeshellarg($_POST['v_shell']);
94+
$v_web_domains = escapeshellarg($_POST['v_web_domains']);
95+
$v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
96+
$v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
97+
$v_dns_records = escapeshellarg($_POST['v_dns_records']);
98+
$v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
99+
$v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
100+
$v_databases = escapeshellarg($_POST['v_databases']);
101+
$v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
102+
$v_backups = escapeshellarg($_POST['v_backups']);
103+
$v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
104+
$v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
105+
$v_ns1 = trim($_POST['v_ns1'], '.');
106+
$v_ns2 = trim($_POST['v_ns2'], '.');
107+
$v_ns3 = trim($_POST['v_ns3'], '.');
108+
$v_ns4 = trim($_POST['v_ns4'], '.');
109+
$v_ns = $v_ns1.",".$v_ns2;
110+
if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
111+
if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
112+
$v_ns = escapeshellarg($v_ns);
113+
$v_time = escapeshellarg(date('H:i:s'));
114+
$v_date = escapeshellarg(date('Y-m-d'));
115+
116+
// Check for errors
117+
if (!empty($errors[0])) {
118+
foreach ($errors as $i => $error) {
119+
if ( $i == 0 ) {
120+
$error_msg = $error;
121+
} else {
122+
$error_msg = $error_msg.", ".$error;
123+
}
124+
}
125+
$_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
126+
} else {
127+
exec ('mktemp -d', $output, $return_var);
128+
$tmpdir = $output[0];
129+
unset($output);
130+
131+
// Create package
132+
$pkg = "TEMPLATE=".$v_template."\n";
133+
$pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
134+
$pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
135+
$pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
136+
$pkg .= "DNS_RECORDS=".$v_dns_records."\n";
137+
$pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
138+
$pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
139+
$pkg .= "DATABASES=".$v_databases."\n";
140+
$pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
141+
$pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
142+
$pkg .= "BANDWIDTH=".$v_bandwidth."\n";
143+
$pkg .= "NS=".$v_ns."\n";
144+
$pkg .= "SHELL=".$v_shell."\n";
145+
$pkg .= "BACKUPS=".$v_backups."\n";
146+
$pkg .= "TIME=".$v_time."\n";
147+
$pkg .= "DATE=".$v_date."\n";
148+
149+
// Write package
150+
$fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
151+
fwrite($fp, $pkg);
152+
fclose($fp);
153+
154+
// Rewrite package
155+
if (empty($_SESSION['error_msg'])) {
156+
exec (VESTA_CMD."v_add_user_package ".$tmpdir." ".$v_package." 'yes'", $output, $return_var);
157+
if ($return_var != 0) {
158+
$error = implode('<br>', $output);
159+
if (empty($error)) $error = 'Error: vesta did not return any output.';
160+
$_SESSION['error_msg'] = $error;
161+
}
162+
unset($output);
163+
}
164+
165+
// Remove tmpdir
166+
exec ('rm -rf '.$tmpdir, $output, $return_var);
167+
unset($output);
168+
169+
// Propogate new package
170+
exec (VESTA_CMD."v_update_user_package ".$v_package." 'json'", $output, $return_var);
171+
if ($return_var != 0) {
172+
$error = implode('<br>', $output);
173+
if (empty($error)) $error = 'Error: vesta did not return any output.';
174+
$_SESSION['error_msg'] = $error;
175+
}
176+
177+
if (empty($_SESSION['error_msg'])) {
178+
$_SESSION['ok_msg'] = "OK: changes has been saved.";
179+
}
180+
}
181+
}
182+
}
183+
184+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_package.html');
185+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_package.html');
186+
unset($_SESSION['error_msg']);
187+
unset($_SESSION['ok_msg']);
188+
}
189+
190+
// Footer
191+
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

web/templates/admin/add_package.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<?php
2020
foreach ($templates as $key => $value) {
2121
echo "\t\t\t\t<option value=\"".$value."\"";
22+
if ((!empty($v_template)) && ( $value == $v_template)){
23+
echo 'selected' ;
24+
}
2225
if ((!empty($v_template)) && ( $value == $_POST['v_template'])){
2326
echo 'selected' ;
2427
}
@@ -43,27 +46,27 @@
4346
</select></td></tr>
4447

4548
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Web Domains</td></tr>
46-
<tr><td><input type="text" size="20" class="add-input" name="v_web_domains" <?php if (!empty($v_web_domains)) echo "value=".$v_web_domains; ?>></tr>
49+
<tr><td><input type="text" size="20" class="add-input" name="v_web_domains" <?php if (isset($v_web_domains)) echo "value=".$v_web_domains; ?>></tr>
4750
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Web Aliases <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(per domain)</span></td></tr>
48-
<tr><td><input type="text" size="20" class="add-input" name="v_web_aliases" <?php if (!empty($v_web_aliases)) echo "value=".$v_web_aliases; ?>></tr>
51+
<tr><td><input type="text" size="20" class="add-input" name="v_web_aliases" <?php if (isset($v_web_aliases)) echo "value=".$v_web_aliases; ?>></tr>
4952
<tr><td class="add-text" style="padding: 10px 0 0 2px;">DNS Domains</td></tr>
50-
<tr><td><input type="text" size="20" class="add-input" name="v_dns_domains" <?php if (!empty($v_dns_domains)) echo "value=".$v_dns_domains; ?>></tr>
53+
<tr><td><input type="text" size="20" class="add-input" name="v_dns_domains" <?php if (isset($v_dns_domains)) echo "value=".$v_dns_domains; ?>></tr>
5154
<tr><td class="add-text" style="padding: 10px 0 0 2px;">DNS Records <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(per domain)</span></td></tr>
52-
<tr><td><input type="text" size="20" class="add-input" name="v_dns_records" <?php if (!empty($v_dns_records)) echo "value=".$v_dns_records; ?>></tr>
55+
<tr><td><input type="text" size="20" class="add-input" name="v_dns_records" <?php if (isset($v_dns_records)) echo "value=".$v_dns_records; ?>></tr>
5356
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Mail Domains</td></tr>
54-
<tr><td><input type="text" size="20" class="add-input" name="v_mail_domains" <?php if (!empty($v_mail_domains)) echo "value=".$v_mail_domains; ?>></tr>
57+
<tr><td><input type="text" size="20" class="add-input" name="v_mail_domains" <?php if (isset($v_mail_domains)) echo "value=".$v_mail_domains; ?>></tr>
5558
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Mail Accounts <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(per domain)</span></td></tr>
56-
<tr><td><input type="text" size="20" class="add-input" name="v_mail_accounts" <?php if (!empty($v_mail_accounts)) echo "value=".$v_mail_accounts; ?>></tr>
59+
<tr><td><input type="text" size="20" class="add-input" name="v_mail_accounts" <?php if (isset($v_mail_accounts)) echo "value=".$v_mail_accounts; ?>></tr>
5760
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Databases</td></tr>
58-
<tr><td><input type="text" size="20" class="add-input" name="v_databases" <?php if (!empty($v_databases)) echo "value=".$v_databases; ?>></tr>
61+
<tr><td><input type="text" size="20" class="add-input" name="v_databases" <?php if (isset($v_databases)) echo "value=".$v_databases; ?>></tr>
5962
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Cron Jobs</td></tr>
60-
<tr><td><input type="text" size="20" class="add-input" name="v_cron_jobs" <?php if (!empty($v_cron_jobs)) echo "value=".$v_cron_jobs; ?>></tr>
63+
<tr><td><input type="text" size="20" class="add-input" name="v_cron_jobs" <?php if (isset($v_cron_jobs)) echo "value=".$v_cron_jobs; ?>></tr>
6164
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Backups</td></tr>
62-
<tr><td><input type="text" size="20" class="add-input" name="v_backups" <?php if (!empty($v_backups)) echo "value=".$v_backups; ?>></tr>
65+
<tr><td><input type="text" size="20" class="add-input" name="v_backups" <?php if (isset($v_backups)) echo "value=".$v_backups; ?>></tr>
6366
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Disk Quota <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(in Mb)</span></td></tr>
64-
<tr><td><input type="text" size="20" class="add-input" name="v_disk_quota" <?php if (!empty($v_disk_quota)) echo "value=".$v_disk_quota; ?>></tr>
67+
<tr><td><input type="text" size="20" class="add-input" name="v_disk_quota" <?php if (isset($v_disk_quota)) echo "value=".$v_disk_quota; ?>></tr>
6568
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Bandwidth <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(in Mb)</span></td></tr>
66-
<tr><td><input type="text" size="20" class="add-input" name="v_bandwidth" <?php if (!empty($v_bandwidth)) echo "value=".$v_bandwidth; ?>></tr>
69+
<tr><td><input type="text" size="20" class="add-input" name="v_bandwidth" <?php if (isset($v_bandwidth)) echo "value=".$v_bandwidth; ?>></tr>
6770
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Name Servers</td></tr>
6871
<tr><td><input type="text" size="20" class="add-input" name="v_ns1" <?php if (!empty($v_ns1)) echo "value=".$v_ns1; ?>></tr>
6972
<tr><td><input type="text" size="20" class="add-input" name="v_ns2" <?php if (!empty($v_ns2)) echo "value=".$v_ns2; ?>></tr>
@@ -74,7 +77,7 @@
7477
<tr><td style="padding: 24px 0 0 0;">
7578
<input type="submit" name="ok" value="OK" class="add-button">
7679
</form>
77-
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/user/'">
80+
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/package/'">
7881
</td></tr>
7982
</table>
8083
</td>

0 commit comments

Comments
 (0)