Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
34413fc61b
8 files changed
+513
-24
No files matched your search
Vendored
+147
@@ -0,0 +1,147 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width"/>
|
||||
<style type="text/css">
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-size: 100%;
|
||||
font-family: 'Avenir Next', "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
|
||||
line-height: 1.65; }
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
margin: 0 auto;
|
||||
display: block; }
|
||||
|
||||
body,
|
||||
.body-wrap {
|
||||
width: 100% !important;
|
||||
height: 100%;
|
||||
background: #efefef;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-text-size-adjust: none; }
|
||||
|
||||
a {
|
||||
color: #71bc37;
|
||||
text-decoration: none; }
|
||||
|
||||
.text-center {
|
||||
text-align: center; }
|
||||
|
||||
.text-right {
|
||||
text-align: right; }
|
||||
|
||||
.text-left {
|
||||
text-align: left; }
|
||||
|
||||
.button {
|
||||
display: inline-block;
|
||||
color: white;
|
||||
background: #71bc37;
|
||||
border: solid #71bc37;
|
||||
border-width: 10px 20px 8px;
|
||||
font-weight: bold;
|
||||
border-radius: 4px; }
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
margin-bottom: 20px;
|
||||
line-height: 1.25; }
|
||||
|
||||
h1 {
|
||||
font-size: 32px; }
|
||||
|
||||
h2 {
|
||||
font-size: 28px; }
|
||||
|
||||
h3 {
|
||||
font-size: 24px; }
|
||||
|
||||
h4 {
|
||||
font-size: 20px; }
|
||||
|
||||
h5 {
|
||||
font-size: 16px; }
|
||||
|
||||
p, ul, ol {
|
||||
font-size: 16px;
|
||||
font-weight: normal;
|
||||
margin-bottom: 20px; }
|
||||
|
||||
.container {
|
||||
display: block !important;
|
||||
clear: both !important;
|
||||
margin: 0 auto !important;
|
||||
max-width: 580px !important; }
|
||||
.container table {
|
||||
width: 100% !important;
|
||||
border-collapse: collapse; }
|
||||
.container .masthead {
|
||||
padding: 18px 0;
|
||||
background: #71bc37;
|
||||
color: white; }
|
||||
.container .masthead h1 {
|
||||
margin: 0 auto !important;
|
||||
max-width: 90%; }
|
||||
.container .content {
|
||||
background: white;
|
||||
padding: 30px 35px; }
|
||||
.container .content.footer {
|
||||
background: none; }
|
||||
.container .content.footer p {
|
||||
margin-bottom: 0;
|
||||
color: #888;
|
||||
text-align: center;
|
||||
font-size: 14px; }
|
||||
.container .content.footer a {
|
||||
color: #888;
|
||||
text-decoration: none;
|
||||
font-weight: bold; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class="body-wrap">
|
||||
<tr>
|
||||
<td class="container">
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" class="masthead">
|
||||
<h1>{HEADER}</h1>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="content">
|
||||
<h2>{TITLE}</h2>
|
||||
<p>{MESSAGE}</p>
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<p>
|
||||
<a href="{LINK}" class="button">{LINKNAME}</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>{FOOTER}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="container">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="content footer" align="center">
|
||||
<p>Сообщение сгенерировано системой <a href="{HOME}">IoT Core Board</a>, {SERVERNAME}</p>
|
||||
<p><a href="mailto:rsgrinko@gmail.com">E-Mail: rsgrinko@gmail.com</a> | <a href="https://telegram.me/rsgrinko">Telegram @rsgrinko</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
Vendored
-13
@@ -1,13 +0,0 @@
|
||||
<application>
|
||||
<component name="XDebuggerSettings">
|
||||
<data-views />
|
||||
<general />
|
||||
<debuggers>
|
||||
<debugger id="javascript">
|
||||
<configuration>
|
||||
<custom-object-presentation />
|
||||
</configuration>
|
||||
</debugger>
|
||||
</debuggers>
|
||||
</component>
|
||||
</application>
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
<application>
|
||||
<component name="GithubAccounts">
|
||||
<account name="El-matador45" id="b49a76bf-73d2-497e-99d5-990ddf3f4005">
|
||||
<server host="github.com" />
|
||||
</account>
|
||||
</component>
|
||||
</application>
|
||||
@@ -273,6 +273,37 @@ function getOS() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Отправка уведомления на почту администратору с использованием шаблонов
|
||||
*/
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Отправка уведомления пользователю
|
||||
*
|
||||
|
||||
@@ -173,7 +173,7 @@ class CCache
|
||||
* @return int Размер кэша в байтах или false
|
||||
*/
|
||||
public static function getCacheSize():int
|
||||
{
|
||||
{ // Получить размер кэша
|
||||
$return_size = 0;
|
||||
foreach (scandir(self::$cache_dir) as $file) {
|
||||
if ($file == '.' or $file == '..') continue;
|
||||
|
||||
+291
-1
@@ -31,6 +31,11 @@ class CMail
|
||||
* Текст
|
||||
*/
|
||||
public $body = '';
|
||||
|
||||
/**
|
||||
* Массив с данными для подстановки в шаблон
|
||||
*/
|
||||
public $arrTemplate = [];
|
||||
|
||||
/**
|
||||
* Массив заголовков файлов
|
||||
@@ -112,6 +117,10 @@ class CMail
|
||||
$this->toEmail = $email;
|
||||
$this->toName = $name;
|
||||
}
|
||||
|
||||
public function assignTemplateVars($arrVars) {
|
||||
$this->arrTemplate = $arrVars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление файла к письму
|
||||
@@ -239,7 +248,288 @@ class CMail
|
||||
// Дамп письма в файл
|
||||
if ($this->dump == true) {
|
||||
if (empty($this->dumpPath)) {
|
||||
$this->dumpPath = dirname(__FILE__) . '/sendmail';
|
||||
$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 {
|
||||
/**
|
||||
* Шаблон письма
|
||||
*/
|
||||
public $template = 'default';
|
||||
|
||||
/**
|
||||
* Дирректория с шаблонами писем
|
||||
*/
|
||||
public $templateDir = '/assets/mail_templates/';
|
||||
|
||||
/**
|
||||
* От кого
|
||||
*/
|
||||
public $fromEmail = '';
|
||||
public $fromName = '';
|
||||
|
||||
/**
|
||||
* Кому
|
||||
*/
|
||||
public $toEmail = '';
|
||||
public $toName = '';
|
||||
|
||||
/**
|
||||
* Тема
|
||||
*/
|
||||
public $subject = '';
|
||||
|
||||
/**
|
||||
* Массив с данными для подстановки в шаблон
|
||||
*/
|
||||
public $arrTemplate = [];
|
||||
|
||||
/**
|
||||
* Массив заголовков файлов
|
||||
*/
|
||||
private $_files = array();
|
||||
|
||||
/**
|
||||
* Создавать письмо в файл при отправке
|
||||
*/
|
||||
public $dump = false;
|
||||
|
||||
/**
|
||||
* Директория сохранения писем
|
||||
*/
|
||||
public $dumpPath = '';
|
||||
|
||||
|
||||
/**
|
||||
* От кого
|
||||
*/
|
||||
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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка существования файла
|
||||
* Если директория не существует - пытается её создать.
|
||||
* Если файл существует - к концу файла приписывает префикс.
|
||||
*/
|
||||
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 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 = file_get_contents($this->templateDir.'/'.$this->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);
|
||||
|
||||
@@ -6,6 +6,6 @@ require_once __DIR__.'/inc/bootstrap.php';
|
||||
if(!CUser::is_admin()) {
|
||||
die('403 - Access denied');
|
||||
}
|
||||
userSendMail(1, 'Test userMail', 'Hello!!!',false);
|
||||
//adminSendMail('Тестовое уведомление', 'Запушен тестовый скрипт для проверки функционала почтовых уведомлений.<br>Если Вы видите данное сообщение - значит система работает.');
|
||||
//userSendMail(1, 'Test userMail', 'Hello!!!',false);
|
||||
adminSendMailWithTemplate('default', 'Тестовое уведомление', 'Запушен тестовый скрипт для проверки функционала почтовых уведомлений.<br>Если Вы видите данное сообщение - значит система работает.');
|
||||
echo 'ok';
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Файл для тестирования и отладки нового функционала
|
||||
*/
|
||||
require_once __DIR__.'/inc/bootstrap.php';
|
||||
if(!CUser::is_admin()) {
|
||||
die('403 - Access denied');
|
||||
}
|
||||
|
||||
$output=null;
|
||||
$retval=null;
|
||||
exec('uptime', $output, $retval);
|
||||
|
||||
|
||||
$mail = new CMail2;
|
||||
$mail->dump = true;
|
||||
$mail->dumpPath = $_SERVER['DOCUMENT_ROOT'].'/uploads/emails';
|
||||
$mail->from('iot@'.$_SERVER['SERVER_NAME'], 'Система оповещений IoT Core');
|
||||
$mail->to(ADMIN_EMAIL, 'Администратор панели');
|
||||
$mail->subject = 'Проверка почтовой подсистемы';
|
||||
$mail->assignTemplateVars(
|
||||
array(
|
||||
'HEADER' => 'IoT Core Board',
|
||||
'MESSAGE' => '<pre>'.print_r($output, true).'</pre>',
|
||||
'TITLE' => 'Код: '.$retval,
|
||||
'LINK' => 'https://it-stories.ru/',
|
||||
'LINKNAME' => 'Перейти в панель',
|
||||
'FOOTER' => 'Сообщение сгенерировано автоматически',
|
||||
'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();
|
||||
Reference in new issue
Block a user