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.

broadcast-message.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 http://postfixadmin.sf.net
  10. *
  11. * @version $Id$
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: broadcast-message.php
  15. * Used to send a message to _ALL_ users with mailboxes on this server.
  16. *
  17. * Template File: broadcast-message.tpl
  18. *
  19. * Template Variables: -none-
  20. *
  21. * Form POST \ GET Variables:
  22. *
  23. * name
  24. * subject
  25. * message
  26. */
  27. require_once('common.php');
  28. if (Config::bool('sendmail_all_admins')) {
  29. authentication_require_role('admin');
  30. } else {
  31. authentication_require_role('global-admin');
  32. }
  33. if ($CONF['sendmail'] != 'YES') {
  34. header("Location: main.php");
  35. exit;
  36. }
  37. $error = 0;
  38. $smtp_from_email = smtp_get_admin_email();
  39. $allowed_domains = list_domains_for_admin(authentication_get_username());
  40. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  41. if (safepost('token') != $_SESSION['PFA_token']) {
  42. die('Invalid token!');
  43. }
  44. if (empty($_POST['subject']) || empty($_POST['message']) || empty($_POST['name'])) {
  45. $error = 1;
  46. flash_error($PALANG['pBroadcast_error_empty']);
  47. } else {
  48. $wanted_domains = array_intersect($allowed_domains, $_POST['domains']);
  49. $table_mailbox = table_by_key('mailbox');
  50. $table_alias = table_by_key('alias');
  51. $recipients = array();
  52. $q = "SELECT username from $table_mailbox WHERE active='" . db_get_boolean(true) . "' AND ".db_in_clause("domain", $wanted_domains);
  53. if (intval(safepost('mailboxes_only')) == 0) {
  54. $q .= " UNION SELECT goto FROM $table_alias WHERE active='" . db_get_boolean(true) . "' AND ".db_in_clause("domain", $wanted_domains)."AND goto NOT IN ($q)";
  55. }
  56. $result = db_query($q);
  57. if ($result['rows'] > 0) {
  58. while ($row = db_assoc($result['result'])) {
  59. $recipients[] = $row['username'];
  60. }
  61. }
  62. $recipients = array_unique($recipients);
  63. if (count($recipients)>0) {
  64. mb_internal_encoding("UTF-8");
  65. $b_name = mb_encode_mimeheader($_POST['name'], 'UTF-8', 'Q');
  66. $b_subject = mb_encode_mimeheader($_POST['subject'], 'UTF-8', 'Q');
  67. $b_message = chunk_split(base64_encode($_POST['message']));
  68. $serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : php_uname('n'); // ??
  69. $i = 0;
  70. foreach ($recipients as $rcpt) {
  71. $fTo = $rcpt;
  72. $fHeaders = 'To: ' . $fTo . "\n";
  73. $fHeaders .= 'From: ' . $b_name . ' <' . $smtp_from_email . ">\n";
  74. $fHeaders .= 'Subject: ' . $b_subject . "\n";
  75. $fHeaders .= 'MIME-Version: 1.0' . "\n";
  76. $fHeaders .= 'Content-Type: text/plain; charset=UTF-8' . "\n";
  77. $fHeaders .= 'Content-Transfer-Encoding: base64' . "\n";
  78. $fHeaders .= 'Date: ' . date('r', time()) . "\n";
  79. $fHeaders .= 'Message-ID: <' . microtime(true) . '-' . md5($smtp_from_email . $fTo) . "@{$serverName}>\n\n";
  80. $fHeaders .= $b_message;
  81. if (!smtp_mail($fTo, $smtp_from_email, $fHeaders)) {
  82. flash_error(Config::lang_f('pSendmail_result_error', $fTo));
  83. } else {
  84. flash_info(Config::lang_f('pSendmail_result_success', $fTo));
  85. }
  86. }
  87. }
  88. flash_info($PALANG['pBroadcast_success']);
  89. $smarty->assign('smarty_template', 'message');
  90. $smarty->display('index.tpl');
  91. // echo '<p>'.$PALANG['pBroadcast_success'].'</p>';
  92. }
  93. }
  94. if ($_SERVER['REQUEST_METHOD'] == "GET" || $error == 1) {
  95. $smarty->assign('allowed_domains', $allowed_domains);
  96. $smarty->assign('smtp_from_email', $smtp_from_email);
  97. $smarty->assign('error', $error);
  98. $smarty->assign('smarty_template', 'broadcast-message');
  99. $smarty->display('index.tpl');
  100. // include ("templates/broadcast-message.tpl");
  101. }
  102. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */