mirror of https://github.com/MISP/MISP
new: [emailing] add custom templates to override existing ones
- currently implemented for event publish alerts and user enrollment (password_reset.ctp, alert.ctp) - simply place the new templates in MISP/app/View/Emails/[text|html]/Custompull/8063/merge
parent
f81bb700c4
commit
3e706867e9
|
@ -107,3 +107,8 @@ vagrant/.vagrant/
|
||||||
vagrant/*.log
|
vagrant/*.log
|
||||||
/app/Lib/Dashboard/Custom/*
|
/app/Lib/Dashboard/Custom/*
|
||||||
!/app/Lib/Dashboard/Custom/empty
|
!/app/Lib/Dashboard/Custom/empty
|
||||||
|
/app/View/Emails/html/Custom/*
|
||||||
|
!/app/View/Emails/html/Custom/empty
|
||||||
|
/app/View/Emails/text/Custom/*
|
||||||
|
!/app/View/Emails/text/Custom/empty
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
http://download.geonames.org/export/dump/countryInfo.txt
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
class SupportShell extends AppShell {
|
class SupportShell extends AppShell {
|
||||||
|
|
||||||
|
|
|
@ -71,14 +71,26 @@ class SendEmailTemplate
|
||||||
|
|
||||||
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'html';
|
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'html';
|
||||||
try {
|
try {
|
||||||
$html = $View->render($this->viewName);
|
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'html' . DS . 'Custom';
|
||||||
|
$html = $View->render($this->viewName); // Attempt to load a custom template if it exists
|
||||||
} catch (MissingViewException $e) {
|
} catch (MissingViewException $e) {
|
||||||
$html = null; // HTMl template is optional
|
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'html';
|
||||||
|
try {
|
||||||
|
$html = $View->render($this->viewName);
|
||||||
|
} catch (MissingViewException $e) {
|
||||||
|
$html = null; // HTMl template is optional
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'text';
|
|
||||||
$View->hasRendered = false;
|
$View->hasRendered = false;
|
||||||
$text = $View->render($this->viewName);
|
try {
|
||||||
|
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'text' . DS . 'Custom';
|
||||||
|
$text = $View->render($this->viewName); // Attempt to load a custom template if it exists
|
||||||
|
} catch (MissingViewException $e) {
|
||||||
|
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'text';
|
||||||
|
$text = $View->render($this->viewName);
|
||||||
|
}
|
||||||
|
|
||||||
// Template can change default subject.
|
// Template can change default subject.
|
||||||
if ($View->get('subject')) {
|
if ($View->get('subject')) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ App::uses('AuthComponent', 'Controller/Component');
|
||||||
App::uses('RandomTool', 'Tools');
|
App::uses('RandomTool', 'Tools');
|
||||||
App::uses('GpgTool', 'Tools');
|
App::uses('GpgTool', 'Tools');
|
||||||
App::uses('SendEmail', 'Tools');
|
App::uses('SendEmail', 'Tools');
|
||||||
|
App::uses('SendEmailTemplate', 'Tools');
|
||||||
App::uses('BlowfishConstantPasswordHasher', 'Controller/Component/Auth');
|
App::uses('BlowfishConstantPasswordHasher', 'Controller/Component/Auth');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -832,6 +833,7 @@ class User extends AppModel
|
||||||
|
|
||||||
$gpg = $this->initializeGpg();
|
$gpg = $this->initializeGpg();
|
||||||
$sendEmail = new SendEmail($gpg);
|
$sendEmail = new SendEmail($gpg);
|
||||||
|
$result = $sendEmail->sendToUser($user, $subject, $body, $bodyNoEnc,$replyToUser ?: []);
|
||||||
try {
|
try {
|
||||||
$result = $sendEmail->sendToUser($user, $subject, $body, $bodyNoEnc,$replyToUser ?: []);
|
$result = $sendEmail->sendToUser($user, $subject, $body, $bodyNoEnc,$replyToUser ?: []);
|
||||||
|
|
||||||
|
@ -867,16 +869,6 @@ class User extends AppModel
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function adminMessageResolve($message)
|
|
||||||
{
|
|
||||||
$resolveVars = array('$contact' => 'MISP.contact', '$org' => 'MISP.org', '$misp' => 'MISP.baseurl');
|
|
||||||
foreach ($resolveVars as $k => $v) {
|
|
||||||
$v = Configure::read($v);
|
|
||||||
$message = str_replace($k, $v, $message);
|
|
||||||
}
|
|
||||||
return $message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $email
|
* @param string $email
|
||||||
* @return array
|
* @return array
|
||||||
|
@ -955,24 +947,15 @@ class User extends AppModel
|
||||||
public function initiatePasswordReset($user, $firstTime = false, $simpleReturn = false, $fixedPassword = false)
|
public function initiatePasswordReset($user, $firstTime = false, $simpleReturn = false, $fixedPassword = false)
|
||||||
{
|
{
|
||||||
$org = Configure::read('MISP.org');
|
$org = Configure::read('MISP.org');
|
||||||
$options = array('newUserText', 'passwordResetText');
|
|
||||||
$subjects = array('[' . $org . ' MISP] New user registration', '[' . $org . ' MISP] Password reset');
|
$subjects = array('[' . $org . ' MISP] New user registration', '[' . $org . ' MISP] Password reset');
|
||||||
$textToFetch = $options[($firstTime ? 0 : 1)];
|
|
||||||
$subject = $subjects[($firstTime ? 0 : 1)];
|
$subject = $subjects[($firstTime ? 0 : 1)];
|
||||||
$this->Server = ClassRegistry::init('Server');
|
$this->Server = ClassRegistry::init('Server');
|
||||||
$body = Configure::read('MISP.' . $textToFetch);
|
|
||||||
if (!$body) {
|
|
||||||
$body = $this->Server->serverSettings['MISP'][$textToFetch]['value'];
|
|
||||||
}
|
|
||||||
$body = $this->adminMessageResolve($body);
|
|
||||||
if ($fixedPassword) {
|
if ($fixedPassword) {
|
||||||
$password = $fixedPassword;
|
$password = $fixedPassword;
|
||||||
} else {
|
} else {
|
||||||
$password = $this->generateRandomPassword();
|
$password = $this->generateRandomPassword();
|
||||||
}
|
}
|
||||||
$body = str_replace('$password', $password, $body);
|
$body = $this->preparePasswordResetEmail($user, $password, $firstTime, $subject);
|
||||||
$body = str_replace('$username', $user['User']['email'], $body);
|
|
||||||
$body = str_replace('\n', PHP_EOL, $body);
|
|
||||||
$result = $this->sendEmail($user, $body, false, $subject);
|
$result = $this->sendEmail($user, $body, false, $subject);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$this->id = $user['User']['id'];
|
$this->id = $user['User']['id'];
|
||||||
|
@ -991,6 +974,22 @@ class User extends AppModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function preparePasswordResetEmail($user, $password, $firstTime, $subject)
|
||||||
|
{
|
||||||
|
$textToFetch = $firstTime ? 'newUserText': 'passwordResetText';
|
||||||
|
$this->Server = ClassRegistry::init('Server');
|
||||||
|
$bodyTemplate = Configure::read('MISP.' . $textToFetch);
|
||||||
|
if (!$bodyTemplate) {
|
||||||
|
$bodyTemplate = $this->Server->serverSettings['MISP'][$textToFetch]['value'];
|
||||||
|
}
|
||||||
|
$template = new SendEmailTemplate('password_reset');
|
||||||
|
$template->set('body', $bodyTemplate);
|
||||||
|
$template->set('user', $user);
|
||||||
|
$template->set('password', $password);
|
||||||
|
$template->subject($subject);
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
public function getOrgAdminsForOrg($org_id, $excludeUserId = false)
|
public function getOrgAdminsForOrg($org_id, $excludeUserId = false)
|
||||||
{
|
{
|
||||||
$adminRoles = $this->Role->find('column', array(
|
$adminRoles = $this->Role->find('column', array(
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
$body = str_replace('$password', $password, $body);
|
||||||
|
$body = str_replace('$username', $user['User']['email'], $body);
|
||||||
|
$body = str_replace('\n', PHP_EOL, $body);
|
||||||
|
$resolveVars = [
|
||||||
|
'$contact' => 'MISP.contact',
|
||||||
|
'$org' => 'MISP.org',
|
||||||
|
'$misp' => 'MISP.baseurl'
|
||||||
|
];
|
||||||
|
foreach ($resolveVars as $k => $v) {
|
||||||
|
$v = Configure::read($v);
|
||||||
|
$body= str_replace($k, $v, $body);
|
||||||
|
}
|
||||||
|
echo $body;
|
Loading…
Reference in New Issue