prepare removal edit-alias for users

This commit is contained in:
mischa 2022-09-04 17:45:17 +00:00
parent 6322a7e713
commit d9a0010d04
3 changed files with 78 additions and 74 deletions

View File

@ -2,12 +2,11 @@
<form name="edit_alias" method="post"> <form name="edit_alias" method="post">
<table> <table>
<tr> <tr>
<td colspan="3"><h3><?php echo $LANG['Edit_alias_welcome']; ?></h3></td> <td colspan="2"><h3><?php echo $LANG['Edit_alias_welcome']; ?></h3></td>
</tr> </tr>
<tr> <tr>
<td><?php echo $LANG['Edit_alias_address'] . ":"; ?></td> <td><?php echo $LANG['Edit_alias_address'] . ":"; ?></td>
<td><?php echo $address; ?></td> <td><?php echo $address; ?></td>
<td>&nbsp;</td>
</tr> </tr>
<tr> <tr>
<td><?php echo $LANG['Edit_alias_goto'] . ":"; ?></td> <td><?php echo $LANG['Edit_alias_goto'] . ":"; ?></td>
@ -20,13 +19,12 @@ foreach ($goto as $row) {
?> ?>
</textarea> </textarea>
</td> </td>
<td>&nbsp;</td>
</tr> </tr>
<tr> <tr>
<td colspan="3" class="hlp_center"><input class="button" type="submit" name="submit" value="<?php echo $LANG['Edit_alias_button']; ?>" /></td> <td colspan="2" class="hlp_center"><input class="button" type="submit" name="submit" value="<?php echo $LANG['Edit_alias_button']; ?>" /></td>
</tr> </tr>
<tr> <tr>
<td colspan="3" class="standout"><?php echo $message ?? '&nbsp;'; ?></td> <td colspan="2" class="standout"><?php echo $message ?? '&nbsp;'; ?></td>
</tr> </tr>
</table> </table>
</form> </form>

View File

@ -2,34 +2,29 @@
<form name="edit_alias" method="post"> <form name="edit_alias" method="post">
<table> <table>
<tr> <tr>
<td colspan="3"><h3><?php echo $LANG['Edit_alias_welcome']; ?></h3></td> <td colspan="2"><h3><?php echo $LANG['Edit_alias_welcome']; ?></h3></td>
</tr> </tr>
<tr> <tr>
<td><?php echo $LANG['Edit_alias_address'] . ":"; ?></td> <td><?php echo $LANG['Edit_alias_address'] . ":"; ?></td>
<td><?php echo $USERID_USERNAME; ?></td> <td><?php echo $SESSID_USERNAME; ?></td>
<td>&nbsp;</td>
</tr> </tr>
<tr> <tr>
<td><?php echo $LANG['Edit_alias_goto'] . ":"; ?></td> <td><?php echo $LANG['Edit_alias_goto'] . ":"; ?></td>
<td><textarea class="flat" rows="4" cols="30" name="fGoto"> <td>
<textarea class="flat" rows="4" cols="60" name="goto">
<?php <?php
$array = preg_split('/,/', $tGoto); foreach ($goto as $row) {
echo "$row\n";
for ($i = 0 ; $i < count($array) ; $i++) {
if (empty($array[$i])) continue;
if ($array[$i] == $USERID_USERNAME) continue;
echo "$array[$i]\n";
} }
?> ?>
</textarea> </textarea>
</td> </td>
<td>&nbsp;</td>
</tr> </tr>
<tr> <tr>
<td colspan="3" class="hlp_center"><input class="button" type="submit" name="submit" value="<?php echo $LANG['Edit_alias_button']; ?>"></td> <td colspan="2" class="hlp_center"><input class="button" type="submit" name="submit" value="<?php echo $LANG['Edit_alias_button']; ?>"></td>
</tr> </tr>
<tr> <tr>
<td colspan="3" class="standout"><?php echo $tMessage; ?></td> <td colspan="2" class="standout"><?php echo $message ?? '&nbsp;'; ?></td>
</tr> </tr>
</table> </table>
</form> </form>

View File

@ -7,77 +7,88 @@
// //
// File: edit-alias.php // File: edit-alias.php
// //
// Template File: users_edit-alias.tpl // Template File: edit-alias.tpl
// //
// Template Variables: // Template Variables:
// //
// tMessage // message
// tGoto // goto
// //
// Form POST \ GET Variables: // Form POST \ GET Variables:
// //
// fAddress // address
// fDomain // domain
// fGoto // goto
// //
require("../functions.inc.php"); require_once './functions.inc.php';
include("../languages/" . check_language() . ".lang"); include './languages/' . check_language() . '.lang';
$USERID_USERNAME = check_session('userid'); $SESSID_USERNAME = check_session();
$USERID_DOMAIN = substr(strrchr($USERID_USERNAME, "@"), 1); $list_domains = list_domains($SESSID_USERNAME);
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
if ($_SERVER['REQUEST_METHOD'] == "GET") { if ($_SERVER['REQUEST_METHOD'] == "GET") {
$result = db_query("SELECT * FROM alias WHERE address='$USERID_USERNAME'"); $address = filter_input(INPUT_GET, 'address', FILTER_VALIDATE_EMAIL);
if ($result['rows'] == 1) { $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
$row = db_array($result['result']); $domain_key = array_search($domain, array_column($list_domains, 'domain'));
$tGoto = preg_replace('/vmail/', '', $row['goto']); $domain_exist = in_array($domain, array_column($list_domains, 'domain'));
#$tGoto = $row['goto'];
} else { if ($domain_exist) {
$tMessage = $LANG['Edit_alias_address_error']; try {
$dbh = connect_db();
$sth = $dbh->prepare("SELECT goto FROM alias WHERE address=? AND domain=?");
$sth->bindParam(1, $address, PDO::PARAM_STR);
$sth->bindParam(2, $domain, PDO::PARAM_STR);
$sth->execute();
$goto = $sth->fetch(PDO::FETCH_COLUMN);
$goto = explode(',', $goto);
} catch(PDOException $e) {
$message = $LANG['Edit_alias_address_error'];
}
} }
} }
if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($_SERVER['REQUEST_METHOD'] == "POST") {
$pEdit_alias_goto = $LANG['Edit_alias_goto']; $address = strtolower(filter_input(INPUT_GET, 'address', FILTER_VALIDATE_EMAIL));
$domain = strtolower(filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN));
$goto = strtolower(filter_input(INPUT_POST, 'goto', FILTER_DEFAULT));
$domain_key = array_search($domain, array_column($list_domains, 'domain'));
$domain_exist = in_array($domain, array_column($list_domains, 'domain'));
if (isset($_POST['fGoto'])) $fGoto = escape_string($_POST['fGoto']); if (empty($goto)) {
$fGoto = strtolower($fGoto); $goto = array();
$message = $LANG['Edit_alias_goto_text_error1'];
$goto = preg_replace('/\\\r\\\n/', ',', $fGoto); } else {
$goto = preg_replace('/\r\n/', ',', $fGoto); $goto = preg_replace('/\\\r\\\n/', ',', $goto);
$goto = preg_replace('/\r\n/', ',', $goto);
$goto = preg_replace('/[\s]+/i', '', $goto); $goto = preg_replace('/[\s]+/i', '', $goto);
$goto = preg_replace('/\,*$/', '', $goto); $goto = preg_replace('/\,*$/', '', $goto);
$array = preg_split('/,/', $goto); $validate_goto = explode(',', $goto);
for ($i = 0; $i < count($array); $i++) { foreach ($validate_goto as $row) {
if (in_array("$array[$i]", $CONF['default_aliases'])) continue; if (!filter_var($row, FILTER_VALIDATE_EMAIL)) {
if (empty($array[$i])) continue; $goto = explode(',', $goto);
if (!check_email($array[$i])) { $message = $LANG['Edit_alias_goto_text_error2'] . "$row</div>";
$error = 1; }
$tGoto = $goto;
$tMessage = $LANG['Edit_alias_goto_text_error2'] . "$array[$i]</font>";
} }
} }
if ($error != 1) { if ($domain_exist && empty($message)) {
if (empty($goto)) { try {
$goto = "vmail"; $dbh = connect_db();
} else { $sth = $dbh->prepare("UPDATE alias SET goto=?,modified=NOW() WHERE address=? AND domain=?");
$goto = "vmail," . $goto; $sth->bindParam(1, $goto, PDO::PARAM_STR);
} $sth->bindParam(2, $address, PDO::PARAM_STR);
$sth->bindParam(3, $domain, PDO::PARAM_STR);
$result = db_query("UPDATE alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'"); $sth->execute();
if ($result['rows'] != 1) { logging($admin, $domain, $LANG['Logging_alias_edit'], "$address -> $goto");
$tMessage = $LANG['Edit_alias_result_error']; header("Location: list-virtual.php?domain=$domain");
} else { } catch(PDOException $e) {
db_log($USERID_USERNAME, $USERID_DOMAIN, "edit alias", "$USERID_USERNAME -> $goto"); $message = $LANG['Edit_alias_result_error'];
header("Location: main.php");
exit;
} }
} }
} }
include("../templates/header.tpl"); include './templates/header.tpl';
include("../templates/users_menu.tpl"); include './templates/admin_menu.tpl';
include("../templates/users_edit-alias.tpl"); include './templates/edit-alias.tpl';
include("../templates/footer.tpl"); include './templates/footer.tpl';
?> ?>