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.

222 lines
7.6 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.tpl
  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. $tActiveFrom = $row['activefrom'];
  68. $tActiveUntil = $row['activeuntil'];
  69. }
  70. $tUseremail = $fUsername;
  71. $tDomain = $fDomain;
  72. if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); }
  73. if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
  74. }
  75. if ($_SERVER['REQUEST_METHOD'] == "POST")
  76. {
  77. $tSubject = safepost('fSubject');
  78. $fSubject = escape_string ($tSubject);
  79. $tBody = safepost('fBody');
  80. // $tActiveFrom = safepost('activefrom').' 00:00:01';
  81. // $tActiveUntil = safepost('activeuntil').' 23:59:59';
  82. $tActiveFrom = date ("Y-m-d 00:00:00", strtotime (safepost('activefrom')));
  83. $tActiveUntil = date ("Y-m-d 23:59:59", strtotime (safepost('activeuntil')));
  84. $fBody = escape_string ($tBody);
  85. $fChange = escape_string (safepost('fChange'));
  86. $fBack = escape_string (safepost('fBack'));
  87. if(authentication_has_role('admin') && isset($_GET['domain'])) {
  88. $fDomain = escape_string ($_GET['domain']);
  89. }
  90. else {
  91. $fDomain = $USERID_DOMAIN;
  92. }
  93. if(authentication_has_role('admin') && isset ($_GET['username'])) {
  94. $fUsername = escape_string($_GET['username']);
  95. }
  96. else {
  97. $fUsername = authentication_get_username();
  98. }
  99. $tUseremail = $fUsername;
  100. if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); }
  101. if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
  102. //if change, remove old one, then perhaps set new one
  103. if (!empty ($fBack) || !empty ($fChange))
  104. {
  105. //if we find an existing vacation entry, disable it
  106. $result = db_query("SELECT * FROM $table_vacation WHERE email='$fUsername'");
  107. if ($result['rows'] == 1)
  108. {
  109. $db_false = db_get_boolean(false);
  110. // retain vacation message if possible - i.e disable vacation away-ness.
  111. $result = db_query ("UPDATE $table_vacation SET active = '$db_false' WHERE email='$fUsername'");
  112. $result = db_query("DELETE FROM $table_vacation_notification WHERE on_vacation='$fUsername'");
  113. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
  114. if ($result['rows'] == 1)
  115. {
  116. $row = db_array ($result['result']);
  117. $goto = $row['goto'];
  118. //only one of these will do something, first handles address at beginning and middle, second at end
  119. $goto= preg_replace ( "/$vacation_goto,/", '', $goto);
  120. $goto= preg_replace ( "/,$vacation_goto/", '', $goto);
  121. $goto= preg_replace ( "/$vacation_goto/", '', $goto);
  122. if($goto == '') {
  123. $sql = "DELETE FROM $table_alias WHERE address = '$fUsername'";
  124. }
  125. else {
  126. $sql = "UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'";
  127. }
  128. $result = db_query($sql);
  129. if ($result['rows'] != 1)
  130. {
  131. $error = 1;
  132. }
  133. }
  134. }
  135. }
  136. //Set the vacation data for $fUsername
  137. if (!empty ($fChange))
  138. {
  139. $goto = '';
  140. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
  141. if ($result['rows'] == 1)
  142. {
  143. $row = db_array ($result['result']);
  144. $goto = $row['goto'];
  145. }
  146. $Active = db_get_boolean(True);
  147. $notActive = db_get_boolean(False);
  148. // I don't think we need to care if the vacation entry is inactive or active.. as long as we don't try and
  149. // insert a duplicate
  150. $result = db_query("SELECT * FROM $table_vacation WHERE email = '$fUsername'");
  151. if($result['rows'] == 1) {
  152. $result = db_query("UPDATE $table_vacation SET active = '$Active', subject = '$fSubject', body = '$fBody', created = NOW(), activefrom = '$tActiveFrom', activeuntil = '$tActiveUntil' WHERE email = '$fUsername'");
  153. }
  154. else {
  155. $result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active, activefrom, activeuntil) VALUES ('$fUsername','$fSubject','$fBody','$fDomain',NOW(),$Active, '$tActiveFrom', '$tActiveUntil')");
  156. }
  157. if ($result['rows'] != 1)
  158. {
  159. $error = 1;
  160. }
  161. if($goto == '') {
  162. $goto = $vacation_goto;
  163. $sql = "INSERT INTO $table_alias (goto, address, domain, modified, activefrom, activeuntil) VALUES ('$goto', '$fUsername', '$fDomain', NOW(), '$tActiveFrom', '$tActiveUntil')";
  164. }
  165. else {
  166. $goto = $goto . "," . $vacation_goto;
  167. $sql = "UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'";
  168. }
  169. $result = db_query ($sql);
  170. if ($result['rows'] != 1)
  171. {
  172. $error = 1;
  173. }
  174. }
  175. }
  176. if($error == 0) {
  177. if(!empty ($fBack)) {
  178. $tMessage = $PALANG['pVacation_result_removed'];
  179. }
  180. if(!empty($fChange)) {
  181. $tMessage= $PALANG['pVacation_result_added'];
  182. }
  183. }
  184. else {
  185. $tMessage = $PALANG['pVacation_result_error'];
  186. }
  187. if (empty ($tActiveFrom))
  188. $tActiveFrom = date ("Y-m-d");
  189. if (empty ($tActiveUntil))
  190. $tActiveUntil = date ("Y-m-d");
  191. $smarty->assign ('tUseremail', $tUseremail);
  192. $smarty->assign ('tSubject', $tSubject);
  193. $smarty->assign ('tBody', $tBody ,false);
  194. $smarty->assign ('tMessage', $tMessage, false);
  195. $smarty->assign ('tActiveFrom', date ("d.m.Y", strtotime ($tActiveFrom)));
  196. $smarty->assign ('tActiveUntil', date ("d.m.Y", strtotime ($tActiveUntil)));
  197. $smarty->assign ('fCanceltarget', $fCanceltarget);
  198. $smarty->assign ('smarty_template', 'edit-vacation');
  199. $smarty->display ('index.tpl');
  200. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  201. ?>