Skip to content

Commit dd249d8

Browse files
committed
edit mail account page
1 parent fb8f65c commit dd249d8

13 files changed

+254
-33
lines changed

bin/v_add_mail_account_autoreply

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
# info: add mail account alias aka nickname
3-
# options: user domain account alias
2+
# info: add mail account autoreply message
3+
# options: user domain account message
44
#
55
# The function add new email account.
66

@@ -27,7 +27,7 @@ source $VESTA/func/domain.sh
2727
# Verifications #
2828
#----------------------------------------------------------#
2929

30-
check_args '4' "$#" 'user domain account autoreply'
30+
check_args '4' "$#" 'user domain account message'
3131
validate_format 'user' 'domain' 'account' 'autoreply'
3232
is_system_enabled "$MAIL_SYSTEM"
3333
is_object_valid 'user' 'USER' "$user"

bin/v_list_mail_account

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ json_list_account() {
3131
echo -e "\t\"$value\": {"
3232
else
3333
if [ "$fileds_count" -eq "$i" ]; then
34-
echo -e "\t\t\"${field//$/}\": \"$value\","
35-
else
3634
echo -e "\t\t\"${field//$/}\": \"$value\""
35+
else
36+
echo -e "\t\t\"${field//$/}\": \"$value\","
3737
fi
3838
fi
3939
(( ++i))

bin/v_list_mail_account_autoreply

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ json_list_msg() {
2323
i='1' # iterator
2424
echo '{'
2525
echo -e "\t\"$account\": {"
26-
echo " \"MSG\": \"$msg\""
26+
echo " \"MSG\": \"$msg\""
2727
echo -e "\t}\n}"
2828
}
2929

web/edit/dns/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
if (empty($error)) $error = 'Error: vesta did not return any output.';
189189
$_SESSION['error_msg'] = $error;
190190
}
191+
$v_val = $_POST['v_val'];
191192
$restart_dns = 'yes';
192193
unset($output);
193194
}

web/edit/mail/index.php

Lines changed: 160 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,11 @@
171171
unset($_SESSION['error_msg']);
172172
unset($_SESSION['ok_msg']);
173173
} else {
174+
175+
$v_username = $user;
174176
$v_domain = escapeshellarg($_GET['domain']);
175-
$v_record_id = escapeshellarg($_GET['record_id']);
176-
exec (VESTA_CMD."v_list_dns_domain_records ".$user." ".$v_domain." 'json'", $output, $return_var);
177+
$v_account = escapeshellarg($_GET['account']);
178+
exec (VESTA_CMD."v_list_mail_account ".$user." ".$v_domain." ".$v_account." 'json'", $output, $return_var);
177179
if ($return_var != 0) {
178180
$error = implode('<br>', $output);
179181
if (empty($error)) $error = 'Error: vesta did not return any output.';
@@ -183,46 +185,185 @@
183185
unset($output);
184186
$v_username = $user;
185187
$v_domain = $_GET['domain'];
186-
$v_d = $_GET['record_id'];
187-
$v_rec = $data[$v_record_id]['RECORD'];
188-
$v_type = $data[$v_record_id]['TYPE'];
189-
$v_val = $data[$v_record_id]['VALUE'];
190-
$v_priority = $data[$v_record_id]['PRIORITY'];
191-
$v_suspended = $data[$v_record_id]['SUSPENDED'];
188+
$v_account = $_GET['account'];
189+
$v_password = "••••••••";
190+
$v_aliases = str_replace(',', "\n", $data[$v_account]['ALIAS']);
191+
$valiases = explode(",", $data[$v_account]['ALIAS']);
192+
$v_fwd = str_replace(',', "\n", $data[$v_account]['FWD']);
193+
$vfwd = explode(",", $data[$v_account]['FWD']);
194+
$v_quota = $data[$v_account]['QUOTA'];
195+
$v_autoreply = $data[$v_account]['AUTOREPLY'];
196+
if ( $v_autoreply == 'yes' ) {
197+
exec (VESTA_CMD."v_list_mail_account_autoreply ".$user." '".$v_domain."' '".$v_account."' json", $output, $return_var);
198+
$autoreply_str = json_decode(implode('', $output), true);
199+
unset($output);
200+
$v_autoreply_message = $autoreply_str[$v_account]['MSG'];
201+
}
202+
$v_suspended = $data[$v_account]['SUSPENDED'];
192203
if ( $v_suspended == 'yes' ) {
193204
$v_status = 'suspended';
194205
} else {
195206
$v_status = 'active';
196207
}
197-
$v_date = $data[$v_record_id]['DATE'];
198-
$v_time = $data[$v_record_id]['TIME'];
208+
$v_date = $data[$v_account]['DATE'];
209+
$v_time = $data[$v_account]['TIME'];
199210
}
200211

201212
// Action
202213
if (!empty($_POST['save'])) {
203214
$v_domain = escapeshellarg($_POST['v_domain']);
204-
$v_record_id = escapeshellarg($_POST['v_record_id']);
215+
$v_account = escapeshellarg($_POST['v_account']);
216+
217+
// Password
218+
if (($v_password != $_POST['v_password']) && (empty($_SESSION['error_msg']))) {
219+
$v_password = escapeshellarg($_POST['v_password']);
220+
exec (VESTA_CMD."v_change_mail_account_password ".$v_username." ".$v_domain." ".$v_account." ".$v_password, $output, $return_var);
221+
if ($return_var != 0) {
222+
$error = implode('<br>', $output);
223+
if (empty($error)) $error = 'Error: vesta did not return any output.';
224+
$_SESSION['error_msg'] = $error;
225+
}
226+
$v_password = "••••••••";
227+
unset($output);
228+
}
205229

206-
if (($v_val != $_POST['v_val']) || ($v_priority != $_POST['v_priority']) && (empty($_SESSION['error_msg']))) {
207-
$v_val = escapeshellarg($_POST['v_val']);
208-
$v_priority = escapeshellarg($_POST['v_priority']);
209-
exec (VESTA_CMD."v_change_dns_domain_record ".$v_username." ".$v_domain." ".$v_record_id." ".$v_val." ".$v_priority, $output, $return_var);
230+
// Quota
231+
if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
232+
if (empty($_POST['v_quota'])) {
233+
$v_quota = 0;
234+
} else {
235+
$v_quota = escapeshellarg($_POST['v_quota']);
236+
}
237+
exec (VESTA_CMD."v_change_mail_account_quota ".$v_username." ".$v_domain." ".$v_account." ".$v_quota, $output, $return_var);
210238
if ($return_var != 0) {
211239
$error = implode('<br>', $output);
212240
if (empty($error)) $error = 'Error: vesta did not return any output.';
213241
$_SESSION['error_msg'] = $error;
214242
}
215-
$restart_dns = 'yes';
216243
unset($output);
217244
}
218-
245+
246+
247+
// Aliases
248+
if (empty($_SESSION['error_msg'])) {
249+
$waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
250+
$waliases = preg_replace("/,/", " ", $waliases);
251+
$waliases = preg_replace('/\s+/', ' ',$waliases);
252+
$waliases = trim($waliases);
253+
$aliases = explode(" ", $waliases);
254+
$v_aliases = str_replace(' ', "\n", $waliases);
255+
$result = array_diff($valiases, $aliases);
256+
foreach ($result as $alias) {
257+
if (empty($_SESSION['error_msg'])) {
258+
exec (VESTA_CMD."v_delete_mail_account_alias ".$v_username." ".$v_domain." ".$v_account." '".$alias, $output, $return_var);
259+
if ($return_var != 0) {
260+
$error = implode('<br>', $output);
261+
if (empty($error)) $error = 'Error: vesta did not return any output.';
262+
$_SESSION['error_msg'] = $error;
263+
}
264+
unset($output);
265+
}
266+
}
267+
$result = array_diff($aliases, $valiases);
268+
foreach ($result as $alias) {
269+
if (empty($_SESSION['error_msg'])) {
270+
exec (VESTA_CMD."v_add_mail_account_alias ".$v_username." ".$v_domain." ".$v_account." '".$alias, $output, $return_var);
271+
if ($return_var != 0) {
272+
$error = implode('<br>', $output);
273+
if (empty($error)) $error = 'Error: vesta did not return any output.';
274+
$_SESSION['error_msg'] = $error;
275+
}
276+
unset($output);
277+
}
278+
}
279+
}
280+
281+
// Forwarders
282+
if (empty($_SESSION['error_msg'])) {
283+
$wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
284+
$wfwd = preg_replace("/,/", " ", $wfwd);
285+
$wfwd = preg_replace('/\s+/', ' ',$wfwd);
286+
$wfwd = trim($wfwd);
287+
$fwd = explode(" ", $wfwd);
288+
$v_fwd = str_replace(' ', "\n", $wfwd);
289+
$result = array_diff($vfwd, $fwd);
290+
foreach ($result as $forward) {
291+
if (empty($_SESSION['error_msg'])) {
292+
exec (VESTA_CMD."v_delete_mail_account_forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
293+
if ($return_var != 0) {
294+
$error = implode('<br>', $output);
295+
if (empty($error)) $error = 'Error: vesta did not return any output.';
296+
$_SESSION['error_msg'] = $error;
297+
}
298+
unset($output);
299+
}
300+
}
301+
$result = array_diff($fwd, $vfwd);
302+
foreach ($result as $forward) {
303+
if (empty($_SESSION['error_msg'])) {
304+
exec (VESTA_CMD."v_add_mail_account_forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
305+
if ($return_var != 0) {
306+
$error = implode('<br>', $output);
307+
if (empty($error)) $error = 'Error: vesta did not return any output.';
308+
$_SESSION['error_msg'] = $error;
309+
}
310+
unset($output);
311+
}
312+
}
313+
}
314+
315+
// Autoreply
316+
if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
317+
exec (VESTA_CMD."v_delete_mail_account_autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
318+
if ($return_var != 0) {
319+
$error = implode('<br>', $output);
320+
if (empty($error)) $error = 'Error: vesta did not return any output.';
321+
$_SESSION['error_msg'] = $error;
322+
}
323+
unset($output);
324+
$v_autoreply = 'no';
325+
$v_autoreply_message = '';
326+
}
327+
if (($v_autoreply == 'yes') && (!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
328+
if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
329+
$v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
330+
$v_autoreply_message = escapeshellarg($v_autoreply_message);
331+
exec (VESTA_CMD."v_add_mail_account_autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
332+
if ($return_var != 0) {
333+
$error = implode('<br>', $output);
334+
if (empty($error)) $error = 'Error: vesta did not return any output.';
335+
$_SESSION['error_msg'] = $error;
336+
}
337+
unset($output);
338+
$v_autoreply_message = $_POST['v_autoreply_message'];
339+
}
340+
}
341+
342+
if (($v_autoreply == 'no') && (!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
343+
if (empty($_POST['v_autoreply_message'])) $_SESSION['error_msg'] = "Error: field atoreply message can not be blank.";
344+
if (empty($_SESSION['error_msg'])) {
345+
$v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
346+
$v_autoreply_message = escapeshellarg($v_autoreply_message);
347+
exec (VESTA_CMD."v_add_mail_account_autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
348+
if ($return_var != 0) {
349+
$error = implode('<br>', $output);
350+
if (empty($error)) $error = 'Error: vesta did not return any output.';
351+
$_SESSION['error_msg'] = $error;
352+
}
353+
unset($output);
354+
$v_autoreply = 'yes';
355+
$v_autoreply_message = $_POST['v_autoreply_message'];
356+
}
357+
}
358+
359+
219360
if (empty($_SESSION['error_msg'])) {
220361
$_SESSION['ok_msg'] = "OK: changes has been saved.";
221362
}
222363

223364
}
224-
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_dns_rec.html');
225-
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_dns_rec.html');
365+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_mail_acc.html');
366+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail_acc.html');
226367
unset($_SESSION['error_msg']);
227368
unset($_SESSION['ok_msg']);
228369
}

web/templates/admin/add_dns_rec.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<option value="PTR" <?php if ($v_type == 'PTR') echo selected; ?>>PTR</option>
4444
<option value="SPF" <?php if ($v_type == 'SPF') echo selected; ?>>SPF</option>
4545
</select></td></tr>
46-
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Value</td></tr>
46+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">IP or Value</td></tr>
4747
<tr><td><input type="text" size="20" class="add-input" name="v_val" <?php if (!empty($v_val)) echo "value=".$v_val; ?>></tr>
4848
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Priority <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(optional)</span></td></tr>
4949
<tr><td><input type="text" size="20" class="add-input" name="v_priority" <?php if (!empty($v_priority)) echo "value=".$v_priority; ?>></tr>

web/templates/admin/add_mail_acc.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Account</td></tr>
4040
<tr><td><input type="text" size="20" class="add-input" name="v_account" <?php if (!empty($v_account)) echo "value=".$v_account; ?>></tr>
4141
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Password <a href="javascript:randomString();" class="genpass">generate</a></td></tr>
42-
<tr><td><input type="text" size="20" class="add-input" name="v_password"</tr>
42+
<tr><td><input type="text" size="20" class="add-input" name="v_password"></tr>
4343
<tr><td class="add-text" style="padding: 10px 0 0 2px;"><a href="javascript:elementHideShow('advtable');" class="add-advanced">Advanced Options ⇢</a></td></tr>
4444
<tr><td class="add-text" style="padding: 9px 0 0 0px;">
4545
<table style="display:<?php if (empty($v_adv)) echo 'none';?> ;" id="advtable">
4646
<tr><td class="add-text" style="padding: 0 0 0 2px;">Quota <span style="padding: 0pt 0pt 0pt 6px; font-size: 10pt; color: rgb(85, 85, 85);">(in megabytes)</span></td></tr>
4747
<tr><td><input type="text" size="20" class="add-input" name="v_quota" <?php if (!empty($v_quota)) echo "value=".$v_quota; ?>></tr>
48-
<tr><td class="add-text" style="padding: 10 0 0 2px;">Aliases <span style="padding: 0pt 0pt 0pt 6px; font-size: 10pt; color: rgb(85, 85, 85);">(local part only)</span></td></tr>
48+
<tr><td class="add-text" style="padding: 10 0 0 2px;">Aliases <span style="padding: 0pt 0pt 0pt 6px; font-size: 10pt; color: rgb(85, 85, 85);">(use local-part)</span></td></tr>
4949
<tr><td><textarea size="20" class="add-textinput" name="v_aliases"><?php if (!empty($v_aliases)) echo $v_aliases; ?></textarea></td></tr>
5050
<tr><td class="add-text" style="padding: 10 0 0 2px;">Forward to <span style="padding: 0pt 0pt 0pt 6px; font-size: 10pt; color: rgb(85, 85, 85);">(email address or addresses)</span></td></tr>
5151
<tr><td><textarea size="20" class="add-textinput" name="v_fwd"><?php if (!empty($v_fwd)) echo $v_fwd; ?></textarea></td></tr>

web/templates/admin/edit_dns_rec.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<tr><td><input type="text" size="20" class="add-input" name="v_rec" <?php if (!empty($v_rec)) echo "value=".$v_rec; ?> disabled> <input type="hidden" name="v_record_id" <?php if (!empty($v_record_id)) echo "value=".$v_record_id; ?> ></tr>
2020
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Type</td></tr>
2121
<tr><td><input type="text" size="20" class="add-input" name="v_type" <?php if (!empty($v_rec)) echo "value=".$v_type; ?> disabled></tr>
22-
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Value</td></tr>
23-
<tr><td><input type="text" size="20" class="add-input" name="v_val" <?php if (!empty($v_val)) echo "value=".$v_val; ?>></tr>
22+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">IP or Value</td></tr>
23+
<tr><td><input type="text" size="20" class="add-input" name="v_val" <?php if (!empty($v_val)) echo "value='".$v_val."'"; ?>></tr>
2424
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Priority <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(optional)</span></td></tr>
2525
<tr><td><input type="text" size="20" class="add-input" name="v_priority" <?php if (!empty($v_priority)) echo "value=".$v_priority; ?>></tr>
2626

0 commit comments

Comments
 (0)