2007-03-24 08:27:00 +01:00
|
|
|
<?php
|
2007-09-30 17:53:54 +02:00
|
|
|
/**
|
|
|
|
* Postfix Admin
|
|
|
|
*
|
|
|
|
* LICENSE
|
|
|
|
* This source file is subject to the GPL license that is bundled with
|
|
|
|
* this package in the file LICENSE.TXT.
|
|
|
|
*
|
2013-11-10 16:57:32 +01:00
|
|
|
* Further details on the project are available at http://postfixadmin.sf.net
|
2007-09-30 17:53:54 +02:00
|
|
|
*
|
|
|
|
* @version $Id$
|
|
|
|
* @license GNU GPL v2 or later.
|
|
|
|
*
|
|
|
|
* File: edit-alias.php
|
|
|
|
* Users can use this to set forwards etc for their mailbox.
|
|
|
|
*
|
2009-12-24 15:58:01 +01:00
|
|
|
* Template File: users_edit-alias.tpl
|
2007-09-30 17:53:54 +02:00
|
|
|
*
|
|
|
|
*/
|
2007-03-24 08:27:00 +01:00
|
|
|
|
2012-05-28 20:01:31 +02:00
|
|
|
$rel_path = '../';
|
2007-09-22 12:54:00 +02:00
|
|
|
require_once('../common.php');
|
2009-11-05 15:55:39 +01:00
|
|
|
$smarty->assign ('smarty_template', 'users_edit-alias');
|
2007-09-22 12:54:00 +02:00
|
|
|
|
2017-04-17 17:27:23 +02:00
|
|
|
authentication_require_role('user');
|
|
|
|
$USERID_USERNAME = authentication_get_username();
|
|
|
|
|
2017-02-14 20:18:25 +01:00
|
|
|
// is edit-alias support enabled in $CONF ?
|
2017-04-17 17:27:23 +02:00
|
|
|
if (! Config::bool('edit_alias')) {
|
|
|
|
header ("Location: main.php");
|
2017-02-14 20:18:25 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2011-12-26 21:54:40 +01:00
|
|
|
$ah = new AliasHandler();
|
|
|
|
$ah->init($USERID_USERNAME);
|
|
|
|
|
2009-11-05 15:55:39 +01:00
|
|
|
$smarty->assign ('USERID_USERNAME', $USERID_USERNAME);
|
|
|
|
|
|
|
|
|
2012-04-09 03:06:52 +02:00
|
|
|
if ( ! $ah->view() ) die("Can't get alias details. Invalid alias?"); # this can only happen if a admin deleted the user since the user logged in
|
|
|
|
$result = $ah->result();
|
|
|
|
$tGotoArray = $result['goto'];
|
|
|
|
$tStoreAndForward = $result['goto_mailbox'];
|
2009-03-13 21:48:24 +01:00
|
|
|
|
2007-03-24 08:27:00 +01:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "GET")
|
|
|
|
{
|
2011-07-30 23:24:24 +02:00
|
|
|
if ($tStoreAndForward) {
|
|
|
|
$smarty->assign ('forward_and_store', ' checked="checked"');
|
|
|
|
$smarty->assign ('forward_only', '');
|
|
|
|
} else {
|
|
|
|
$smarty->assign ('forward_and_store', '');
|
|
|
|
$smarty->assign ('forward_only', ' checked="checked"');
|
|
|
|
}
|
2009-11-05 15:55:39 +01:00
|
|
|
|
2010-12-26 01:00:24 +01:00
|
|
|
$smarty->assign ('tGotoArray', $tGotoArray);
|
|
|
|
$smarty->display ('index.tpl');
|
2007-03-24 08:27:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "POST")
|
|
|
|
{
|
2016-05-20 22:42:04 +02:00
|
|
|
if (safepost('token') != $_SESSION['PFA_token']) die('Invalid token!');
|
|
|
|
|
2007-09-22 12:54:00 +02:00
|
|
|
// user clicked on cancel button
|
|
|
|
if(isset($_POST['fCancel'])) {
|
|
|
|
header("Location: main.php");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2012-04-09 03:48:04 +02:00
|
|
|
$fGoto = trim(safepost('fGoto'));
|
|
|
|
$fForward_and_store = safepost('fForward_and_store');
|
|
|
|
|
|
|
|
# TODO: use edit.php (or create a edit_user.php)
|
|
|
|
# TODO: this will obsolete lots of the code below (parsing $goto and the error checks)
|
2009-03-25 16:26:23 +01:00
|
|
|
|
2007-09-22 12:54:00 +02:00
|
|
|
$goto = strtolower ($fGoto);
|
|
|
|
$goto = preg_replace ('/\\\r\\\n/', ',', $goto);
|
|
|
|
$goto = preg_replace ('/\r\n/', ',', $goto);
|
2010-12-26 01:00:24 +01:00
|
|
|
$goto = preg_replace ('/,[\s]+/i', ',', $goto);
|
|
|
|
$goto = preg_replace ('/[\s]+,/i', ',', $goto);
|
2007-09-22 12:54:00 +02:00
|
|
|
$goto = preg_replace ('/\,*$/', '', $goto);
|
2009-03-13 21:48:24 +01:00
|
|
|
|
2007-09-22 12:54:00 +02:00
|
|
|
$goto = explode(",",$goto);
|
|
|
|
|
2010-09-27 01:14:42 +02:00
|
|
|
$error = 0;
|
2009-03-13 21:48:24 +01:00
|
|
|
$goto = array_merge(array_unique($goto));
|
|
|
|
$good_goto = array();
|
2010-09-27 01:14:42 +02:00
|
|
|
|
2012-04-09 03:48:04 +02:00
|
|
|
if($fForward_and_store != 1 && sizeof($goto) == 1 && $goto[0] == '') {
|
2011-07-19 00:36:38 +02:00
|
|
|
flash_error($PALANG['pEdit_alias_goto_text_error1']);
|
2009-03-25 16:26:23 +01:00
|
|
|
$error += 1;
|
|
|
|
}
|
|
|
|
if($error === 0) {
|
|
|
|
foreach($goto as $address) {
|
2010-09-27 01:14:42 +02:00
|
|
|
if ($address != "") { # $goto[] may contain a "" element
|
|
|
|
# TODO - from https://sourceforge.net/tracker/?func=detail&aid=3027375&group_id=191583&atid=937964
|
|
|
|
# The not-so-good news is that some internals of edit-alias aren't too nice
|
|
|
|
# - for example, $goto[] can contain an element with empty string. I added a
|
|
|
|
# check for that in the 2.3 branch, but we should use a better solution
|
|
|
|
# (avoid empty elements in $goto) in trunk ;-)
|
2013-04-01 23:22:30 +02:00
|
|
|
$email_check = check_email($address);
|
|
|
|
if($email_check != '') {
|
2009-03-25 16:26:23 +01:00
|
|
|
$error += 1;
|
2013-04-01 23:22:30 +02:00
|
|
|
flash_error("$address: $email_check");
|
2009-03-25 16:26:23 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$good_goto[] = $address;
|
|
|
|
}
|
2010-09-27 01:14:42 +02:00
|
|
|
}
|
2007-09-22 12:54:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 21:48:24 +01:00
|
|
|
if ($error == 0) {
|
2012-04-09 03:48:04 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'goto' => $good_goto,
|
|
|
|
'goto_mailbox' => $fForward_and_store,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$ah->set($values)) {
|
|
|
|
$errormsg = $ah->errormsg;
|
|
|
|
flash_error($errormsg[0]);
|
2007-09-22 12:54:00 +02:00
|
|
|
}
|
2012-04-09 03:48:04 +02:00
|
|
|
|
|
|
|
$updated = $ah->store();
|
|
|
|
|
2009-03-13 21:48:24 +01:00
|
|
|
if($updated) {
|
2007-09-22 12:54:00 +02:00
|
|
|
header ("Location: main.php");
|
|
|
|
exit;
|
|
|
|
}
|
2011-07-19 00:36:38 +02:00
|
|
|
flash_error($PALANG['pEdit_alias_result_error']);
|
2012-04-09 03:48:04 +02:00
|
|
|
|
2007-09-22 12:54:00 +02:00
|
|
|
}
|
2009-03-25 16:26:23 +01:00
|
|
|
else {
|
|
|
|
$tGotoArray = $goto;
|
|
|
|
}
|
2010-12-26 01:00:24 +01:00
|
|
|
$smarty->assign ('tGotoArray', $tGotoArray);
|
2012-04-09 03:48:04 +02:00
|
|
|
if ($fForward_and_store == 1) {
|
2010-12-26 20:37:27 +01:00
|
|
|
$smarty->assign ('forward_and_store', ' checked="checked"');
|
2011-07-30 23:24:24 +02:00
|
|
|
$smarty->assign ('forward_only', '');
|
2010-12-26 20:37:27 +01:00
|
|
|
} else {
|
2011-07-30 23:24:24 +02:00
|
|
|
$smarty->assign ('forward_and_store', '');
|
2010-12-26 20:37:27 +01:00
|
|
|
$smarty->assign ('forward_only', ' checked="checked"');
|
|
|
|
}
|
2009-12-24 15:58:01 +01:00
|
|
|
$smarty->display ('index.tpl');
|
2007-03-24 08:27:00 +01:00
|
|
|
}
|
2009-02-15 16:02:26 +01:00
|
|
|
|
|
|
|
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|
2017-04-17 17:27:23 +02:00
|
|
|
?>
|