diff --git a/assets/mail_templates/default.html b/assets/mail_templates/default.html
index c6f302b..217eff7 100644
--- a/assets/mail_templates/default.html
+++ b/assets/mail_templates/default.html
@@ -81,7 +81,10 @@
.container .masthead {
padding: 18px 0;
background: #71bc37;
- color: white; }
+ color: white;
+ margin-top: 40px;
+ display: block;
+ }
.container .masthead h1 {
margin: 0 auto !important;
max-width: 90%; }
@@ -124,7 +127,6 @@
-
{FOOTER}
@@ -135,7 +137,7 @@
diff --git a/inc/func.php b/inc/func.php
index 490c686..6463774 100644
--- a/inc/func.php
+++ b/inc/func.php
@@ -274,36 +274,6 @@ function getOS() {
}
- /**
- * Отправка уведомления на почту администратору с использованием шаблонов
- */
-function adminSendMailWithTemplate($template, $subject, $message, $file = false){
- $mail = new CMail;
- $mail->from('iot@'.$_SERVER['SERVER_NAME'], 'Система оповещений IoT Core');
- $mail->to(ADMIN_EMAIL, 'Администратор панели');
- $mail->subject = $subject;
- $mail->assignTemplateVars(
- array(
- 'HEADER' => 'IoT Core',
- 'MESSAGE' => 'test0',
- 'TITLE' => 'test title',
- 'LINK' => 'https://it-stories.ru/',
- 'LINKNAME' => 'Go to site',
- 'FOOTER' => 'Thanks!',
- 'SERVERNAME' => 'it-stories.ru'
- )
- );
-
-
-
- // прикрепляем лог, если он есть
- if(isset($file) and !empty($file) and file_exists($file)){
- $mail->addFile($file);
- }
- $mail->sendUsingTemplate($template);
-
- return;
- }
/**
* Отправка уведомления пользователю
*
@@ -332,7 +302,7 @@ function adminSendMailWithTemplate($template, $subject, $message, $file = false)
if(isset($file) and !empty($file) and file_exists($file)){
$mail->addFile($file);
}
- $mail->send();
+ $mail->sendDefault();
return;
}
diff --git a/inc/header.php b/inc/header.php
index e0eddb7..1bc3223 100644
--- a/inc/header.php
+++ b/inc/header.php
@@ -162,7 +162,7 @@ if(!CUser::is_user() and $_SERVER['REQUEST_URI'] !== '/login.php') {
- Почтовые рассылки
+ Почтовые рассылки
diff --git a/inc/lib/CMail.class.php b/inc/lib/CMail.class.php
index d817457..a79c095 100644
--- a/inc/lib/CMail.class.php
+++ b/inc/lib/CMail.class.php
@@ -1,346 +1,8 @@
'margin: 0 0 0 0; padding: 10px 10px 10px 10px; background: #ffffff; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
- 'a' => 'color: #003399; text-decoration: underline; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
- 'p' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
- 'ul' => 'margin: 0 0 20px 20px; padding: 0 0 0 0; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
- 'ol' => 'margin: 0 0 20px 20px; padding: 0 0 0 0; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
- 'table' => 'margin: 0 0 20px 0; border: 1px solid #dddddd; border-collapse: collapse;',
- 'th' => 'padding: 10px; border: 1px solid #dddddd; vertical-align: middle; background-color: #eeeeee; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
- 'td' => 'padding: 10px; border: 1px solid #dddddd; vertical-align: middle; background-color: #ffffff; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
- 'h1' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 22px; font-family: Arial, Helvetica, sans-serif; line-height: 26px; font-weight: bold;',
- 'h2' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 20px; font-family: Arial, Helvetica, sans-serif; line-height: 24px; font-weight: bold;',
- 'h3' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 18px; font-family: Arial, Helvetica, sans-serif; line-height: 22px; font-weight: bold;',
- 'h4' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 16px; font-family: Arial, Helvetica, sans-serif; line-height: 20px; font-weight: bold;',
- 'hr' => 'height: 1px; border: none; color: #dddddd; background: #dddddd; margin: 0 0 20px 0;'
- );
-
- /**
- * Проверка существования файла
- * Если директория не существует - пытается её создать.
- * Если файл существует - к концу файла приписывает префикс.
- */
- private function safeFile($filename)
- {
- $dir = dirname($filename);
- if (!is_dir($dir)) {
- mkdir($dir, 0777, true);
- }
-
- $info = pathinfo($filename);
- $name = $dir . '/' . $info['filename'];
- $ext = (empty($info['extension'])) ? '' : '.' . $info['extension'];
- $prefix = '';
-
- if (is_file($name . $ext)) {
- $i = 1;
- $prefix = '_' . $i;
-
- while (is_file($name . $prefix . $ext)) {
- $prefix = '_' . ++$i;
- }
- }
-
- return $name . $prefix . $ext;
- }
-
- /**
- * От кого
- */
- public function from($email, $name = null)
- {
- $this->fromEmail = $email;
- $this->fromName = $name;
- }
-
- /**
- * Кому
- */
- public function to($email, $name = null)
- {
- $this->toEmail = $email;
- $this->toName = $name;
- }
-
- public function assignTemplateVars($arrVars) {
- $this->arrTemplate = $arrVars;
- }
-
- /**
- * Добавление файла к письму
- */
- public function addFile($filename)
- {
- if (is_file($filename)) {
- $name = basename($filename);
- $fp = fopen($filename, 'rb');
- $file = fread($fp, filesize($filename));
- fclose($fp);
- $this->_files[] = array(
- 'Content-Type: application/octet-stream; name="' . $name . '"',
- 'Content-Transfer-Encoding: base64',
- 'Content-Disposition: attachment; filename="' . $name . '"',
- '',
- chunk_split(base64_encode($file)),
- );
- }
- }
-
- /**
- * Добавление к тегам стили
- */
- public function addHtmlStyle($html)
- {
- foreach ($this->_styles as $tag => $style) {
- preg_match_all('/<' . $tag . '([\s].*?)?>/i', $html, $matchs, PREG_SET_ORDER);
- foreach ($matchs as $match) {
- $attrs = array();
- if (!empty($match[1])) {
- preg_match_all('/[ ]?(.*?)=[\"|\'](.*?)[\"|\'][ ]?/', $match[1], $chanks);
- if (!empty($chanks[1]) && !empty($chanks[2])) {
- $attrs = array_combine($chanks[1], $chanks[2]);
- }
- }
-
- if (empty($attrs['style'])) {
- $attrs['style'] = $style;
- } else {
- $attrs['style'] = rtrim($attrs['style'], '; ') . '; ' . $style;
- }
-
- $compile = array();
- foreach ($attrs as $name => $value) {
- $compile[] = $name . '="' . $value . '"';
- }
-
- $html = str_replace($match[0], '<' . $tag . ' ' . implode(' ', $compile) . '>', $html);
- }
- }
-
- return $html;
- }
-
- /**
- * Отправка
- */
- public function send()
- {
- if (empty($this->toEmail)) {
- return false;
- }
-
- // От кого
- $from = (empty($this->fromName)) ? $this->fromEmail : '=?UTF-8?B?' . base64_encode($this->fromName) . '?= <' . $this->fromEmail . '>';
-
- // Кому
- $array_to = array();
- foreach (explode(',', $this->toEmail) as $row) {
- $row = trim($row);
- if (!empty($row)) {
- $array_to[] = (empty($this->toName)) ? $row : '=?UTF-8?B?' . base64_encode($this->toName) . '?= <' . $row . '>';
- }
- }
-
- // Тема письма
- $subject = (empty($this->subject)) ? 'No subject' : $this->subject;
-
- // Текст письма
- $body = '
-
-
-
-
-
- ' . $this->body . '
-
- ';
-
- // Добавление стилей к тегам
- $body = $this->addHtmlStyle($body);
-
- $boundary = md5(uniqid(time()));
-
- // Заголовок письма
- $headers = array(
- 'Content-Type: multipart/mixed; boundary="' . $boundary . '"',
- 'Content-Transfer-Encoding: 7bit',
- 'MIME-Version: 1.0',
- 'From: ' . $from,
- 'Date: ' . date('r')
- );
-
- // Тело письма
- $message = array(
- '--' . $boundary,
- 'Content-Type: text/html; charset=UTF-8',
- 'Content-Transfer-Encoding: base64',
- '',
- chunk_split(base64_encode($body))
- );
-
- if (!empty($this->_files)) {
- foreach ($this->_files as $row) {
- $message = array_merge($message, array('', '--' . $boundary), $row);
- }
- }
-
- $message[] = '';
- $message[] = '--' . $boundary . '--';
- $res = array();
-
- foreach ($array_to as $to) {
- // Дамп письма в файл
- if ($this->dump == true) {
- if (empty($this->dumpPath)) {
- $this->dumpPath = dirname(__FILE__) . '/uploads';
- }
-
- $dump = array_merge($headers, array('To: ' . $to, 'Subject: ' . $subject, ''), $message);
- $file = $this->safeFile($this->dumpPath . '/' . date('Y-m-d_H-i-s') . '.eml');
- file_put_contents($file, implode("\r\n", $dump));
- }
- $res[] = mb_send_mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
- }
-
- return $res;
- }
-
- public function sendUsingTemplate($template = 'default') {
- if (empty($this->toEmail)) {
- return false;
- }
-
- // От кого
- $from = (empty($this->fromName)) ? $this->fromEmail : '=?UTF-8?B?' . base64_encode($this->fromName) . '?= <' . $this->fromEmail . '>';
-
- // Кому
- $array_to = array();
- foreach (explode(',', $this->toEmail) as $row) {
- $row = trim($row);
- if (!empty($row)) {
- $array_to[] = (empty($this->toName)) ? $row : '=?UTF-8?B?' . base64_encode($this->toName) . '?= <' . $row . '>';
- }
- }
-
- // Тема письма
- $subject = (empty($this->subject)) ? 'No subject' : $this->subject;
-
- $body = file_get_contents(__DIR__.'/../../assets/mail_templates/'.$template.'.html');
- foreach($this->arrTemplate as $templateKey => $templateValue){
- $body = str_replace('{'.$templateKey.'}', $templateValue, $body);
- }
-
-
- $boundary = md5(uniqid(time()));
-
- // Заголовок письма
- $headers = array(
- 'Content-Type: multipart/mixed; boundary="' . $boundary . '"',
- 'Content-Transfer-Encoding: 7bit',
- 'MIME-Version: 1.0',
- 'From: ' . $from,
- 'Date: ' . date('r')
- );
-
- // Тело письма
- $message = array(
- '--' . $boundary,
- 'Content-Type: text/html; charset=UTF-8',
- 'Content-Transfer-Encoding: base64',
- '',
- chunk_split(base64_encode($body))
- );
-
- if (!empty($this->_files)) {
- foreach ($this->_files as $row) {
- $message = array_merge($message, array('', '--' . $boundary), $row);
- }
- }
-
- $message[] = '';
- $message[] = '--' . $boundary . '--';
- $res = array();
-
- foreach ($array_to as $to) {
- // Дамп письма в файл
- if ($this->dump == true) {
- if (empty($this->dumpPath)) {
- $this->dumpPath = dirname(__FILE__) . '/uploads';
- }
-
- $dump = array_merge($headers, array('To: ' . $to, 'Subject: ' . $subject, ''), $message);
- $file = $this->safeFile($this->dumpPath . '/' . date('Y-m-d_H-i-s') . '.eml');
- file_put_contents($file, implode("\r\n", $dump));
- }
- $res[] = mb_send_mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
- }
-
- return $res;
- }
-}
-
-
-
/**
* Класс для отправки E-Mail с использованием почтовых шаблонов
*/
-class CMail2 {
+class CMail {
/**
* Шаблон письма
*/
@@ -480,7 +142,7 @@ class CMail2 {
}
/**
- * Отправка
+ * Отправка с использованием шаблонов
*/
public function send() {
if (empty($this->toEmail)) {
@@ -556,4 +218,89 @@ class CMail2 {
return $res;
}
+
+ /**
+ * Отправка с использованием встроенных стилей
+ */
+ public function sendDefault()
+ {
+ if (empty($this->toEmail)) {
+ return false;
+ }
+
+ // От кого
+ $from = (empty($this->fromName)) ? $this->fromEmail : '=?UTF-8?B?' . base64_encode($this->fromName) . '?= <' . $this->fromEmail . '>';
+
+ // Кому
+ $array_to = array();
+ foreach (explode(',', $this->toEmail) as $row) {
+ $row = trim($row);
+ if (!empty($row)) {
+ $array_to[] = (empty($this->toName)) ? $row : '=?UTF-8?B?' . base64_encode($this->toName) . '?= <' . $row . '>';
+ }
+ }
+
+ // Тема письма
+ $subject = (empty($this->subject)) ? 'No subject' : $this->subject;
+
+ // Текст письма
+ $body = '
+
+
+
+
+
+ ' . $this->body . '
+
+ ';
+
+ // Добавление стилей к тегам
+ $body = $this->addHtmlStyle($body);
+
+ $boundary = md5(uniqid(time()));
+
+ // Заголовок письма
+ $headers = array(
+ 'Content-Type: multipart/mixed; boundary="' . $boundary . '"',
+ 'Content-Transfer-Encoding: 7bit',
+ 'MIME-Version: 1.0',
+ 'From: ' . $from,
+ 'Date: ' . date('r')
+ );
+
+ // Тело письма
+ $message = array(
+ '--' . $boundary,
+ 'Content-Type: text/html; charset=UTF-8',
+ 'Content-Transfer-Encoding: base64',
+ '',
+ chunk_split(base64_encode($body))
+ );
+
+ if (!empty($this->_files)) {
+ foreach ($this->_files as $row) {
+ $message = array_merge($message, array('', '--' . $boundary), $row);
+ }
+ }
+
+ $message[] = '';
+ $message[] = '--' . $boundary . '--';
+ $res = array();
+
+ foreach ($array_to as $to) {
+ // Дамп письма в файл
+ if ($this->dump == true) {
+ if (empty($this->dumpPath)) {
+ $this->dumpPath = dirname(__FILE__) . '/uploads';
+ }
+
+ $dump = array_merge($headers, array('To: ' . $to, 'Subject: ' . $subject, ''), $message);
+ $file = $this->safeFile($this->dumpPath . '/' . date('Y-m-d_H-i-s') . '.eml');
+ file_put_contents($file, implode("\r\n", $dump));
+ }
+ $res[] = mb_send_mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
+ }
+
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/login.php b/login.php
index 5777508..300b41a 100644
--- a/login.php
+++ b/login.php
@@ -22,10 +22,10 @@ if(CUser::is_user()) {
/**
* В случае неудачной попытки входа информируем администратора о данной ситуации
*/
- $debugFile = $_SERVER['DOCUMENT_ROOT'].'/cache/auth_'.md5($_REQUEST['login'].$_REQUEST['pass']).'_time_'.time().'.txt';
+ /*$debugFile = $_SERVER['DOCUMENT_ROOT'].'/cache/auth_'.md5($_REQUEST['login'].$_REQUEST['pass']).'_time_'.time().'.txt';
file_put_contents($debugFile, print_r($_SERVER, true)."\n\n".print_r($_REQUEST, true)."".print_r(getClientInfo(), true));
adminSendMail('Попытка вторжения', 'Неудачная попытка авториации в системе (IP: '.getIp().', '.$_REQUEST['login'].', '.$_REQUEST['pass'].', OS: '.getOS().')', $debugFile);
- unlink($debugFile);
+ unlink($debugFile);*/
}
} else {
diff --git a/mailings.php b/mailings.php
index 3891aa1..ca53cb5 100644
--- a/mailings.php
+++ b/mailings.php
@@ -7,6 +7,81 @@ require_once __DIR__ . '/inc/header.php';
if(isset($_REQUEST['save']) and $_REQUEST['save'] == 'Y'):
//TODO: делаем рассылку
+
+ /*
+ Array (
+ [save] => Y
+ [template] => default
+ [subject] => Почтовая рассылка IoT Core Board
+ [header] => Заголовок
+ [message] => ТЕкст123
+ 1234567
+ [admin] => on
+ [user] => on
+ )
+ */
+ $userEmails = [];
+
+ if(isset($_REQUEST['admin']) and $_REQUEST['admin'] == 'on') {
+ $arUsers = $DB->query('SELECT id, email FROM users WHERE access_level="admin"');
+ foreach($arUsers as $mailingUser) {
+ $userEmails[] = $mailingUser['email'];
+ }
+ }
+
+ if(isset($_REQUEST['user']) and $_REQUEST['user'] == 'on') {
+ $arUsers = $DB->query('SELECT id, email FROM users WHERE access_level="user"');
+ foreach($arUsers as $mailingUser) {
+ $userEmails[] = $mailingUser['email'];
+ }
+ }
+
+ if(isset($_REQUEST['demo']) and $_REQUEST['demo'] == 'on') {
+ $arUsers = $DB->query('SELECT id, email FROM users WHERE access_level="demo"');
+ foreach($arUsers as $mailingUser) {
+ $userEmails[] = $mailingUser['email'];
+ }
+ }
+
+ if(isset($_REQUEST['use_html_message']) and $_REQUEST['use_html_message'] == 'on') {
+ $message = $_REQUEST['message'];
+ } else {
+ $message = nl2br($_REQUEST['message']);
+ }
+
+ $mail = new CMail;
+ $mail->dump = true;
+ $mail->dumpPath = $_SERVER['DOCUMENT_ROOT'].'/uploads/emails';
+ $mail->from('iot@'.$_SERVER['SERVER_NAME'], 'IoT Core Board v.'.VERSION);
+ $mail->to(implode(',', $userEmails));
+ $mail->subject = $_REQUEST['subject'];
+ $mail->assignTemplateVars(
+ array(
+ 'HEADER' => $_REQUEST['subject'],
+ 'MESSAGE' => $message,
+ 'TITLE' => $_REQUEST['title'],
+ 'LINK' => 'https://it-stories.ru/',
+ 'LINKNAME' => 'Перейти в панель',
+ 'SERVERNAME' => 'it-stories.ru'
+ )
+ );
+
+ $mail->template = 'default';
+ $mail->templateDir = $_SERVER['DOCUMENT_ROOT'].'/assets/mail_templates';
+
+ /*
+ // прикрепляем лог, если он есть
+ if(isset($file) and !empty($file) and file_exists($file)){
+ $mail->addFile($file);
+ }*/
+ $mail->send();
+ ?>
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test2.php b/test2.php
index fb2b60b..db836bb 100644
--- a/test2.php
+++ b/test2.php
@@ -12,7 +12,7 @@ $retval=null;
exec('uptime', $output, $retval);
- $mail = new CMail2;
+ $mail = new CMail;
$mail->dump = true;
$mail->dumpPath = $_SERVER['DOCUMENT_ROOT'].'/uploads/emails';
$mail->from('iot@'.$_SERVER['SERVER_NAME'], 'Система оповещений IoT Core');