PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
6.4 KiB

  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at :
  10. * http://www.postfixadmin.com or http://postfixadmin.sf.net
  11. *
  12. * @version $Id$
  13. * @license GNU GPL v2 or later.
  14. *
  15. * File: edit-vacation.php
  16. * Responsible for allowing users to update their vacation status.
  17. *
  18. * Template File: edit-vacation.php
  19. *
  20. * Template Variables:
  21. *
  22. * tUseremail
  23. * tMessage
  24. * tSubject
  25. * tBody
  26. *
  27. * Form POST \ GET Variables:
  28. *
  29. * fUsername
  30. * fDomain
  31. * fCanceltarget
  32. * fChange
  33. * fBack
  34. * fQuota
  35. * fActive
  36. */
  37. require_once('common.php');
  38. if($CONF['vacation'] == 'NO') {
  39. header("Location: " . $CONF['postfix_admin_url'] . "/list-virtual.php");
  40. exit(0);
  41. }
  42. $SESSID_USERNAME = authentication_get_username();
  43. $tmp = preg_split ('/@/', $SESSID_USERNAME);
  44. $USERID_DOMAIN = $tmp[1];
  45. // only allow admins to change someone else's 'stuff'
  46. if(authentication_has_role('admin')) {
  47. if (isset($_GET['username'])) $fUsername = escape_string ($_GET['username']);
  48. if (isset($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
  49. }
  50. else {
  51. $fUsername = $SESSID_USERNAME;
  52. $fDomain = $USERID_DOMAIN;
  53. }
  54. $vacation_domain = $CONF['vacation_domain'];
  55. $vacation_goto = preg_replace('/@/', '#', $fUsername);
  56. $vacation_goto = $vacation_goto . '@' . $vacation_domain;
  57. $fCanceltarget = $CONF['postfix_admin_url'] . "/list-virtual.php?domain=$fDomain";
  58. if ($_SERVER['REQUEST_METHOD'] == "GET")
  59. {
  60. $result = db_query("SELECT * FROM $table_vacation WHERE email='$fUsername'");
  61. if ($result['rows'] == 1)
  62. {
  63. $row = db_array($result['result']);
  64. $tMessage = '';
  65. $tSubject = $row['subject'];
  66. $tBody = $row['body'];
  67. }
  68. $tUseremail = $fUsername;
  69. $tDomain = $fDomain;
  70. if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); }
  71. if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
  72. }
  73. if ($_SERVER['REQUEST_METHOD'] == "POST")
  74. {
  75. $tSubject = safepost('fSubject');
  76. $fSubject = escape_string ($tSubject);
  77. $tBody = safepost('fBody');
  78. $fBody = escape_string ($tBody);
  79. $fChange = escape_string (safepost('fChange'));
  80. $fBack = escape_string (safepost('fBack'));
  81. if(authentication_has_role('admin') && isset($_GET['domain'])) {
  82. $fDomain = escape_string ($_GET['domain']);
  83. }
  84. else {
  85. $fDomain = $USERID_DOMAIN;
  86. }
  87. if(authentication_has_role('admin') && isset ($_GET['username'])) {
  88. $fUsername = escape_string($_GET['username']);
  89. }
  90. else {
  91. $fUsername = authentication_get_username();
  92. }
  93. $tUseremail = $fUsername;
  94. if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); }
  95. if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
  96. //if change, remove old one, then perhaps set new one
  97. if (!empty ($fBack) || !empty ($fChange))
  98. {
  99. //if we find an existing vacation entry, disable it
  100. $result = db_query("SELECT * FROM $table_vacation WHERE email='$fUsername'");
  101. if ($result['rows'] == 1)
  102. {
  103. $db_false = db_get_boolean(false);
  104. // retain vacation message if possible - i.e disable vacation away-ness.
  105. $result = db_query ("UPDATE $table_vacation SET active = $db_false WHERE email='$fUsername'");
  106. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
  107. if ($result['rows'] == 1)
  108. {
  109. $row = db_array ($result['result']);
  110. $goto = $row['goto'];
  111. //only one of these will do something, first handles address at beginning and middle, second at end
  112. $goto= preg_replace ( "/$vacation_goto,/", '', $goto);
  113. $goto= preg_replace ( "/,$vacation_goto/", '', $goto);
  114. $goto= preg_replace ( "/$vacation_goto/", '', $goto);
  115. if($goto == '') {
  116. $sql = "DELETE FROM $table_alias WHERE address = '$fUsername'";
  117. }
  118. else {
  119. $sql = "UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'";
  120. }
  121. $result = db_query($sql);
  122. if ($result['rows'] != 1)
  123. {
  124. $error = 1;
  125. }
  126. }
  127. }
  128. }
  129. //Set the vacation data for $fUsername
  130. if (!empty ($fChange))
  131. {
  132. $goto = '';
  133. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
  134. if ($result['rows'] == 1)
  135. {
  136. $row = db_array ($result['result']);
  137. $goto = $row['goto'];
  138. }
  139. $Active = db_get_boolean(True);
  140. $notActive = db_get_boolean(False);
  141. // I don't think we need to care if the vacation entry is inactive or active.. as long as we don't try and
  142. // insert a duplicate
  143. $result = db_query("SELECT * FROM $table_vacation WHERE email = '$fUsername'");
  144. if($result['rows'] == 1) {
  145. $result = db_query("UPDATE $table_vacation SET active = $Active, subject = '$fSubject', body = '$fBody', created = NOW() WHERE email = '$fUsername'");
  146. }
  147. else {
  148. $result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active) VALUES ('$fUsername','$fSubject','$fBody','$fDomain',NOW(),$Active)");
  149. }
  150. if ($result['rows'] != 1)
  151. {
  152. $error = 1;
  153. }
  154. if($goto == '') {
  155. $goto = $vacation_goto;
  156. $sql = "INSERT INTO $table_alias (goto, address, domain, modified) VALUES ('$goto', '$fUsername', '$fDomain', NOW())";
  157. }
  158. else {
  159. $goto = $goto . "," . $vacation_goto;
  160. $sql = "UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'";
  161. }
  162. $result = db_query ($sql);
  163. if ($result['rows'] != 1)
  164. {
  165. $error = 1;
  166. }
  167. }
  168. }
  169. if($error == 0) {
  170. if(!empty ($fBack)) {
  171. $tMessage = $PALANG['pVacation_result_removed'];
  172. }
  173. if(!empty($fChange)) {
  174. $tMessage= $PALANG['pVacation_result_added'];
  175. }
  176. }
  177. else {
  178. $tMessage = $PALANG['pVacation_result_error'];
  179. }
  180. include ("templates/header.php");
  181. include ("templates/menu.php");
  182. include ("templates/edit-vacation.php");
  183. include ("templates/footer.php");
  184. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  185. ?>