Blob


1 <?php
2 //
3 // Postfix Admin
4 // by Mischa Peters <mischa at high5 dot net>
5 // Copyright (c) 2002 - 2005 High5!
6 // License Info: http://www.postfixadmin.com/?file=LICENSE.TXT
7 //
8 // File: edit-alias.php
9 //
10 // Template File: edit-alias.tpl
11 //
12 // Template Variables:
13 //
14 // tMessage
15 // tGoto
16 //
17 // Form POST \ GET Variables:
18 //
19 // fAddress
20 // fDomain
21 // fGoto
22 //
23 require ("./variables.inc.php");
24 require ("./config.inc.php");
25 require ("./functions.inc.php");
26 include ("./languages/" . check_language () . ".lang");
28 $SESSID_USERNAME = check_session ();
30 if ($_SERVER['REQUEST_METHOD'] == "GET")
31 {
32 $fAddress = escape_string ($_GET['address']);
33 $fDomain = escape_string ($_GET['domain']);
35 if (check_owner ($SESSID_USERNAME, $fDomain))
36 {
37 $result = db_query ("SELECT * FROM alias WHERE address='$fAddress' AND domain='$fDomain'");
38 if ($result['rows'] == 1)
39 {
40 $row = db_array ($result['result']);
41 $tGoto = $row['goto'];
42 }
43 }
44 else
45 {
46 $tMessage = $PALANG['pEdit_alias_address_error'];
47 }
49 include ("./templates/header.tpl");
50 include ("./templates/menu.tpl");
51 include ("./templates/edit-alias.tpl");
52 include ("./templates/footer.tpl");
53 }
55 if ($_SERVER['REQUEST_METHOD'] == "POST")
56 {
57 $pEdit_alias_goto = $PALANG['pEdit_alias_goto'];
59 $fAddress = escape_string ($_GET['address']);
60 $fAddress = strtolower ($fAddress);
61 $fDomain = escape_string ($_GET['domain']);
62 $fGoto = escape_string ($_POST['fGoto']);
63 $fGoto = strtolower ($fGoto);
65 if (!check_owner ($SESSID_USERNAME, $fDomain))
66 {
67 $error = 1;
68 $tGoto = $fGoto;
69 $tMessage = $PALANG['pEdit_alias_domain_error'] . "$fDomain</font>";
70 }
72 if (empty ($fGoto))
73 {
74 $error = 1;
75 $tGoto = $fGoto;
76 $tMessage = $PALANG['pEdit_alias_goto_text_error1'];
77 }
79 $goto = preg_replace ('/\\\r\\\n/', ',', $fGoto);
80 $goto = preg_replace ('/\r\n/', ',', $fGoto);
81 $goto = preg_replace ('/[\s]+/i', '', $goto);
82 $goto = preg_replace ('/\,*$/', '', $goto);
83 $array = preg_split ('/,/', $goto);
85 if (!empty ($array)) { $array_count = count ($array); }
87 for ($i = 0; $i < $array_count; $i++) {
88 if (in_array ("$array[$i]", $CONF['default_aliases'])) continue;
89 if (empty ($array[$i])) continue;
90 if (!check_email ($array[$i]))
91 {
92 $error = 1;
93 $tGoto = $goto;
94 $tMessage = $PALANG['pEdit_alias_goto_text_error2'] . "$array[$i]</div>";
95 }
96 }
98 if ($error != 1)
99 {
100 $result = db_query ("UPDATE alias SET goto='$goto',modified=NOW() WHERE address='$fAddress' AND domain='$fDomain'");
101 if ($result['rows'] != 1)
103 $tMessage = $PALANG['pEdit_alias_result_error'];
105 else
107 db_log ($SESSID_USERNAME, $fDomain, "edit alias", "$fAddress -> $goto");
109 header ("Location: overview.php?domain=$fDomain");
110 exit;
114 include ("./templates/header.tpl");
115 include ("./templates/menu.tpl");
116 include ("./templates/edit-alias.tpl");
117 include ("./templates/footer.tpl");
119 ?>