PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ravencore/server/httpdocs/mail.php

https://github.com/cormander/ravencore
PHP | 223 lines | 149 code | 44 blank | 30 comment | 62 complexity | 3a70242ed85124b03a4de04a925712ed MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /*
  3. RavenCore Hosting Control Panel
  4. Copyright (C) 2005 Corey Henderson
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. include "auth.php";
  18. if ($action) {
  19. $ret = $db->run("push_mail", Array(
  20. action => $action,
  21. did => $did,
  22. mid => $mid,
  23. mail => $_POST[mail],
  24. catchall => $_POST[catchall],
  25. catchall_addr => $_POST[catchall_addr],
  26. relay_host => $_POST[relay_host],
  27. bounce_message => $_POST[bounce_message],
  28. alias_addr => $_POST[alias_addr],
  29. ));
  30. if (1 == $ret) send_to_url("mail.php?did=$did");
  31. }
  32. if ($did) {
  33. // we include the nav_top inside the if statement, because if we're a user and try to view the page
  34. // we'll go to the else statement and the req_admin will print out a nav_top
  35. nav_top();
  36. $domain = $db->run("get_domain_by_id", Array(id => $did));
  37. if (!is_array($domain)) print __("Domain does not exist");
  38. else {
  39. print '<form method=post name=main>' . __('Mail for') . ' <a href="domains.php?did=' . $domain[id] . '" onmouseover="show_help(\'' . __('Goto') . ' ' . $domain[name] . '\');" onmouseout="help_rst();">' . $domain[name] . '</a> ' . __('is') . ' ';
  40. if ($domain[mail] != "on") print __('OFF') . ' <a href="javascript:document.main.submit();" onmouseover="show_help(\'' . __('Turn ON mail for') . ' ' . $domain[name] . '\');" onmouseout="help_rst();">*</a>
  41. <input type=hidden name=did value="' . $did . '">
  42. <input type=hidden name=action value="toggle">
  43. <input type=hidden name=mail value="on">
  44. ';
  45. else {
  46. print __('ON') . ' <a href="javascript:document.main.submit();" onmouseover="show_help(\'' . __('Turn OFF mail for') . ' ' . $domain[name] . '\');" onmouseout="help_rst();" onclick="return confirm(\'' . __('Are you sure you wish to disable mail for this domain?') . '\');">*</a>
  47. <input type=hidden name=did value="' . $did . '">
  48. <input type=hidden name=action value="toggle">
  49. <input type=hidden name=mail value="off">
  50. </form>
  51. <p>';
  52. print '<form method=POST>
  53. ' . __('Mail sent to email accounts not set up for this domain ( catchall address )') . ':
  54. <br>
  55. <input type=radio name=catchall value=send_to';
  56. if ($domain[catchall] == "send_to") print ' checked';
  57. print '> ' . __('Send to') . ': <input type=text name=catchall_addr value="' . $domain[catchall_addr] . '"> ';
  58. print '<br> <input type=radio name=catchall value=bounce';
  59. if ($domain[catchall] == "bounce") print ' checked';
  60. print '> ' . __('Bounce with') . ': <input type=text name=bounce_message value="' . $domain[bounce_message] . '"> <br>
  61. <input type=radio name=catchall value=relay';
  62. if ($domain[catchall] == "relay") print ' checked';
  63. print '> ' . __('Relay to') . ': <input type=text name=relay_host value="' . $domain[relay_host] . '"> <br> ';
  64. print '<input type=radio name="catchall" value="delete_it"';
  65. if ($domain[catchall] == "delete_it") print ' checked';
  66. print '> ' . __('Delete it') . ' <br>';
  67. $domains = $db->run("get_domains_by_user_id", Array(uid => $uid));
  68. // remove this $did and all ones with 'mail = no'
  69. for ($i = 0; $i < count($domains); $i++) {
  70. if ($did == $domains[$i][id] or "on" != $domains[$i][mail]) {
  71. array_splice($domains, $i, 1);
  72. $i--;
  73. }
  74. }
  75. // for domains with no user
  76. if (0 == count($domains)) {
  77. print '<input type=radio name=catchall value=alias_to';
  78. if ($domain[catchall] == "alias_to") print ' checked';
  79. print '> ' . __('Forward to that user') . ' @ <input type=text name=alias_addr value="' . $domain[alias_addr] . '">';
  80. // for users with more then one domain setup
  81. }
  82. else if (count($domains) > 0) {
  83. print '<input type=radio name=catchall value=alias_to';
  84. if ($domain[catchall] == "alias_to") print ' checked';
  85. print '> ' . __('Forward to that user') . ' @ <select name=alias_addr>';
  86. // all other domains for this user ( with mail turned on )
  87. foreach ($domains as $dom) {
  88. print '<option value="' . $dom[name] . '"';
  89. if ($domain[alias_addr] == $dom[name]) print ' selected';
  90. print '>' . $dom[name] . '</option>';
  91. }
  92. print '</select>';
  93. } else print '<input type=radio disabled> ' . __('You need at least one other domain in the account with mail turned on to be able to alias mail');
  94. print '<p>';
  95. print '
  96. <input type=submit value="' . __('Update') . '"> <input type=hidden name=did value="' . $domain[id] . '"> <input type=hidden name=action value=update>
  97. </form>
  98. <p>';
  99. $mails = $db->run("get_mail_users_by_domain_id", Array(did => $domain[id]));
  100. if (0 == count($mails)) print __('No mail for this domain.') . '<p>';
  101. else print '<table class="listpad"><tr><th class="listpad" colspan="100%">' . __('Mail for this domain') . ':</th></tr>';
  102. foreach ($mails as $mail) {
  103. print '<tr>
  104. <td class="listpad"><a href="edit_mail.php?did=' .
  105. $mail[did] . '&mid=' . $mail[id] .
  106. '" onmouseover="show_help(\'' . __('Edit') . ' ' .
  107. $mail[mail_name] . '@' . $domain[name] .
  108. '\');" onmouseout="help_rst();">' . __('edit') . '</a></td>
  109. <td class="listpad">' . $mail[mail_name] . '@' . $domain[name] .
  110. '</td><td class="listpad">';
  111. print '&nbsp;</td>
  112. <td class="listpad"><a href=mail.php?did=' .
  113. $domain[id] . '&mid=' . $mail[id] .
  114. '&action=delete onmouseover="show_help(\'' . __('Delete') . ' ' .
  115. $mail[mail_name] . '@' . $domain[name] .
  116. '\');" onmouseout="help_rst();" onclick="';
  117. if (!user_can_add($uid, "email") and !is_admin()) print 'return confirm(\'' . __('If you delete this email, you may not be able to add it again.\rAre you sure you wish to do this?') . '\');';
  118. else print 'return confirm(\'' . __('Are you sure you wish to delete this email?') . '\');';
  119. print '">' . __('delete') . '</a></td></tr>';
  120. }
  121. if (0 != count($mails)) print '</table>';
  122. if (user_can_add($uid, "email") or is_admin()) {
  123. print ' <a href="edit_mail.php?did=' . $domain[id] . '"';
  124. if (!user_can_add($uid, "email") and is_admin()) print ' onclick="return confirm(\'' . __('This user is only allowed to create ' . user_have_permission($uid, "email") . ' email accounts. Are you sure you want to add another?') . '\');"';
  125. print ' onmouseover="show_help(\'' . __('Add an email account') . '\');" onmouseout="help_rst();">' . __('Add Mail') . '</a>';
  126. }
  127. }
  128. }
  129. } else {
  130. // req_admin();
  131. nav_top();
  132. // check to see if we have any domains setup at all. If not, die with this error
  133. if ($uid) $domains = $db->run("get_domains_by_user_id", Array(uid => $uid));
  134. else $domains = $db->run("get_domains");
  135. if (0 == count($domains)) {
  136. print __('You have no domains setup.');
  137. // give an "add a domain" link if the user has permission to add one more
  138. if (is_admin() or user_have_permission($uid, "domain")) print ' <a href="edit_domain.php">' . __('Add a Domain') . '</a>';
  139. nav_bottom();
  140. exit;
  141. }
  142. if(user_can_add($uid, "email") or is_admin()) print '<a href="edit_mail.php" onmouseover="show_help(\'' . __('Create a new email account') . '\');" onmouseout="help_rst();">' . __('Add an email address') . '</a>';
  143. print '<p>
  144. <form method="GET" name=search>
  145. ' . __('Search') . ': <input type=text name=search value="' . $_GET[search] . '">
  146. <input type=submit value="' . __('Go') . '" onclick="if(!document.search.search.value) { alert(\'' . __('Please enter in a search value!') . '\'); return false; }">';
  147. if ($_GET[search]) print ' <input type=button value="' . __('Show All') . '" onclick="self.location=\'mail.php\'">';
  148. print '</form><p>';
  149. $mails = Array();
  150. foreach ($domains as $domain) {
  151. foreach ($db->run("get_mail_users_by_domain_id", Array(did => $domain[id])) as $mail) {
  152. array_push($mails, $mail);
  153. }
  154. }
  155. if (0 == count($mails) and !$_GET[search]) print __("There are no mail users setup");
  156. else if ($_GET[search]) print __('Your search returned') . ' <i><b>' . $num . '</b></i> ' . __('results') . '<p>';
  157. if (0 != count($mails)) print '<table class="listpad" width="45%"><tr><th class="listpad" colspan="100%">' . __('Email Addresses') . '</th></tr>';
  158. foreach ($mails as $mail) {
  159. print '<tr><td class="listpad"><a href="edit_mail.php?did=' . $mail[did] . '&mid=' . $mail[mid] . '" onmouseover="show_help(\'' . __('Edit') . ' ' . $mail[mail_name] . '@' . $mail[name] . '\');" onmouseout="help_rst();">' . $mail[mail_name] . '@' . $mail[name] . '</td><td class="listpad">';
  160. if ( $mail[mailbox] == "true" ) {
  161. //if (@fsockopen("127.0.0.1", 143)) print '<a href="webmail.php?mid=' . $mail[mid] . '&did=' . $mail[did] . '" target="_blank">' . __('Webmail') . '</a>';
  162. //else print '<a href="#" onclick="alert(\'' . __('Webmail is currently offline') . '\')" onmouseover="show_help(\'' . __('Webmail is currently offline') . '\');" onmouseout="help_rst();">' . __('Webmail') . ' ( ' . __('offline') . ' )</a>';
  163. } else {
  164. print '&nbsp;';
  165. }
  166. print '</td>
  167. <td class="listpad"><a href=mail.php?did=' . $mail[did] . '&mid=' . $mail[mid] . '&action=delete onmouseover="show_help(\'' . __('Delete') . ' ' . $mail[mail_name] . '@' . $mail[name] . '\');" onmouseout="help_rst();" onclick="';
  168. if (!user_can_add($uid, "email") and !is_admin()) print 'return confirm(\'' . __('If you delete this email, you may not be able to add it again.\rAre you sure you wish to do this?') . '\');';
  169. else print 'return confirm(\'' . __('Are you sure you wish to delete this email?') . '\');';
  170. print '">' . __('delete') . '</a></td></tr>';
  171. }
  172. }
  173. if (0 != count($mails)) print '</table>';
  174. nav_bottom();
  175. ?>