@@ -8,8 +8,6 @@ use Exception;
|
||||
use G;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Net;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Model\AbeConfiguration;
|
||||
use ProcessMaker\Model\EmailEvent;
|
||||
@@ -22,7 +20,7 @@ class EmailServer
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"MESS_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "emailServerUid"),
|
||||
"MESS_ENGINE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("PHPMAILER", "MAIL", "IMAP", "GMAILAPI", "OFFICE365API"), "fieldNameAux" => "emailServerEngine"),
|
||||
"MESS_ENGINE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("PHPMAILER", "MAIL", "IMAP", "GMAILAPI"), "fieldNameAux" => "emailServerEngine"),
|
||||
"MESS_SERVER" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerServer"),
|
||||
"MESS_PORT" => array("type" => "int", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerPort"),
|
||||
"MESS_INCOMING_SERVER" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerIncomingServer"),
|
||||
@@ -249,11 +247,12 @@ class EmailServer
|
||||
}
|
||||
|
||||
/**
|
||||
* Test connection by step.
|
||||
* Test connection by step
|
||||
*
|
||||
* @param array $arrayData
|
||||
* @param int $step
|
||||
* @return string
|
||||
* @param array $arrayData Data
|
||||
* @param int $step Step
|
||||
*
|
||||
* @return array, return array with result of test connection by step
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testConnectionByStep(array $arrayData, $step = 0)
|
||||
@@ -263,38 +262,40 @@ class EmailServer
|
||||
//MAIL
|
||||
if ($arrayData["MESS_ENGINE"] == "MAIL") {
|
||||
|
||||
$arrayDataMail = [];
|
||||
$arrayDataMail = array();
|
||||
|
||||
$eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3}$/";
|
||||
|
||||
$arrayDataMail["FROM_EMAIL"] = ($arrayData["MESS_FROM_MAIL"] != "" && preg_match($eregMail, $arrayData["MESS_FROM_MAIL"])) ? $arrayData["MESS_FROM_MAIL"] : "";
|
||||
$arrayDataMail["FROM_NAME"] = ($arrayData["MESS_FROM_NAME"] != "") ? $arrayData["MESS_FROM_NAME"] : G::LoadTranslation("ID_MESS_TEST_BODY");
|
||||
$arrayDataMail["MESS_ENGINE"] = "MAIL";
|
||||
$arrayDataMail["MESS_SERVER"] = "localhost";
|
||||
$arrayDataMail["MESS_PORT"] = 25;
|
||||
$arrayDataMail["MESS_ACCOUNT"] = $arrayData["MAIL_TO"];
|
||||
$arrayDataMail["FROM_EMAIL"] = ($arrayData["MESS_FROM_MAIL"] != "" && preg_match($eregMail, $arrayData["MESS_FROM_MAIL"]))? $arrayData["MESS_FROM_MAIL"] : "";
|
||||
$arrayDataMail["FROM_NAME"] = ($arrayData["MESS_FROM_NAME"] != "")? $arrayData["MESS_FROM_NAME"] : G::LoadTranslation("ID_MESS_TEST_BODY");
|
||||
$arrayDataMail["MESS_ENGINE"] = "MAIL";
|
||||
$arrayDataMail["MESS_SERVER"] = "localhost";
|
||||
$arrayDataMail["MESS_PORT"] = 25;
|
||||
$arrayDataMail["MESS_ACCOUNT"] = $arrayData["MAIL_TO"];
|
||||
$arrayDataMail["MESS_PASSWORD"] = "";
|
||||
$arrayDataMail["TO"] = $arrayData["MAIL_TO"];
|
||||
$arrayDataMail["MESS_RAUTH"] = true;
|
||||
$arrayDataMail["TO"] = $arrayData["MAIL_TO"];
|
||||
$arrayDataMail["MESS_RAUTH"] = true;
|
||||
|
||||
$arrayTestMailResult = [];
|
||||
$arrayTestMailResult = array();
|
||||
|
||||
try {
|
||||
$arrayTestMailResult = $this->sendTestMail($arrayDataMail);
|
||||
} catch (Exception $e) {
|
||||
$arrayTestMailResult["status"] = false;
|
||||
$arrayTestMailResult["message"] = $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
$arrayResult = [
|
||||
"result" => $arrayTestMailResult["status"],
|
||||
$arrayResult = array(
|
||||
"result" => $arrayTestMailResult["status"],
|
||||
"message" => ""
|
||||
];
|
||||
);
|
||||
|
||||
if ($arrayTestMailResult["status"] == false) {
|
||||
$arrayResult["message"] = G::LoadTranslation("ID_SENDMAIL_NOT_INSTALLED");
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayResult;
|
||||
}
|
||||
|
||||
@@ -310,7 +311,7 @@ class EmailServer
|
||||
$passwdHide = "";
|
||||
}
|
||||
|
||||
$passwdDec = G::decrypt($passwd, "EMAILENCRYPT");
|
||||
$passwdDec = G::decrypt($passwd,"EMAILENCRYPT");
|
||||
$auxPass = explode("hash:", $passwdDec);
|
||||
|
||||
if (count($auxPass) > 1) {
|
||||
@@ -324,24 +325,21 @@ class EmailServer
|
||||
|
||||
$arrayData["MESS_PASSWORD"] = $passwd;
|
||||
|
||||
$port = (int) ($arrayData["MESS_PORT"]);
|
||||
$auth_required = (int) ($arrayData["MESS_RAUTH"]);
|
||||
$port = (int)($arrayData["MESS_PORT"]);
|
||||
$auth_required = (int)($arrayData["MESS_RAUTH"]);
|
||||
$useSecureCon = $arrayData["SMTPSECURE"];
|
||||
$sendTestMail = (int) ($arrayData["MESS_TRY_SEND_INMEDIATLY"]);
|
||||
$sendTestMail = (int)($arrayData["MESS_TRY_SEND_INMEDIATLY"]);
|
||||
$mailTo = $arrayData["MAIL_TO"];
|
||||
$smtpSecure = $arrayData["SMTPSECURE"];
|
||||
|
||||
$serverNet = new Net($server);
|
||||
$smtp = new SMTP();
|
||||
$serverNet = new \Net($server);
|
||||
$smtp = new \SMTP();
|
||||
|
||||
$timeout = 10;
|
||||
$hostinfo = [];
|
||||
$hostinfo = array();
|
||||
$srv = $arrayData["MESS_SERVER"];
|
||||
|
||||
$arrayResult = [
|
||||
"result" => false,
|
||||
"message" => ""
|
||||
];
|
||||
$arrayResult = array();
|
||||
|
||||
switch ($step) {
|
||||
case 1:
|
||||
@@ -350,6 +348,7 @@ class EmailServer
|
||||
break;
|
||||
case 2:
|
||||
$serverNet->scannPort($port);
|
||||
|
||||
$arrayResult["result"] = $serverNet->getErrno() == 0;
|
||||
$arrayResult["message"] = $serverNet->error;
|
||||
break;
|
||||
@@ -358,10 +357,12 @@ class EmailServer
|
||||
if (preg_match("/^(.+):([0-9]+)$/", $srv, $hostinfo)) {
|
||||
$server = $hostinfo[1];
|
||||
$port = $hostinfo[2];
|
||||
} else {
|
||||
$host = $srv;
|
||||
}
|
||||
|
||||
$tls = strtolower($smtpSecure) === "tls";
|
||||
$ssl = strtolower($smtpSecure) === "ssl";
|
||||
$tls = (strtoupper($smtpSecure) == "tls");
|
||||
$ssl = (strtoupper($smtpSecure) == "ssl");
|
||||
|
||||
$arrayResult["result"] = $smtp->Connect(($ssl ? "ssl://" : "") . $server, $port, $timeout);
|
||||
$arrayResult["message"] = $serverNet->error;
|
||||
@@ -373,12 +374,27 @@ class EmailServer
|
||||
if (preg_match("/^(.+):([0-9]+)$/", $srv, $hostinfo)) {
|
||||
$server = $hostinfo[1];
|
||||
$port = $hostinfo[2];
|
||||
} else {
|
||||
$server = $srv;
|
||||
}
|
||||
if (strtoupper($useSecureCon)=="TLS") {
|
||||
$tls = "tls";
|
||||
}
|
||||
|
||||
$tls = strtolower($useSecureCon) === "tls";
|
||||
$ssl = strtolower($useSecureCon) === "ssl";
|
||||
if (strtoupper($useSecureCon)=="SSL") {
|
||||
$tls = "ssl";
|
||||
}
|
||||
|
||||
$resp = $smtp->Connect(($ssl ? "ssl://" : "") . $server, $port, $timeout);
|
||||
$tls = (strtoupper($useSecureCon) == "tls");
|
||||
$ssl = (strtoupper($useSecureCon) == "ssl");
|
||||
|
||||
$server = $arrayData["MESS_SERVER"];
|
||||
|
||||
if (strtoupper($useSecureCon) == "SSL") {
|
||||
$resp = $smtp->Connect(("ssl://") . $server, $port, $timeout);
|
||||
} else {
|
||||
$resp = $smtp->Connect($server, $port, $timeout);
|
||||
}
|
||||
|
||||
if ($resp) {
|
||||
$hello = $_SERVER["SERVER_NAME"];
|
||||
@@ -388,7 +404,7 @@ class EmailServer
|
||||
$smtp->Hello($hello);
|
||||
}
|
||||
|
||||
if ($smtp->Authenticate($user, $passwd)) {
|
||||
if ($smtp->Authenticate($user, $passwd) ) {
|
||||
$arrayResult["result"] = true;
|
||||
} else {
|
||||
if (strtoupper($useSecureCon) == "TLS") {
|
||||
@@ -416,18 +432,18 @@ class EmailServer
|
||||
case 5:
|
||||
if ($sendTestMail == 1) {
|
||||
try {
|
||||
$arrayDataPhpMailer = [];
|
||||
$arrayDataPhpMailer = array();
|
||||
|
||||
$eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3}$/";
|
||||
|
||||
$arrayDataPhpMailer["FROM_EMAIL"] = ($fromMail != "" && preg_match($eregMail, $fromMail)) ? $fromMail : "";
|
||||
$arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : G::LoadTranslation("ID_MESS_TEST_BODY");
|
||||
$arrayDataPhpMailer["MESS_ENGINE"] = "PHPMAILER";
|
||||
$arrayDataPhpMailer["MESS_SERVER"] = $server;
|
||||
$arrayDataPhpMailer["MESS_PORT"] = $port;
|
||||
$arrayDataPhpMailer["MESS_ACCOUNT"] = $user;
|
||||
$arrayDataPhpMailer["FROM_EMAIL"] = ($fromMail != "" && preg_match($eregMail, $fromMail))? $fromMail : "";
|
||||
$arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : G::LoadTranslation("ID_MESS_TEST_BODY");
|
||||
$arrayDataPhpMailer["MESS_ENGINE"] = "PHPMAILER";
|
||||
$arrayDataPhpMailer["MESS_SERVER"] = $server;
|
||||
$arrayDataPhpMailer["MESS_PORT"] = $port;
|
||||
$arrayDataPhpMailer["MESS_ACCOUNT"] = $user;
|
||||
$arrayDataPhpMailer["MESS_PASSWORD"] = $passwd;
|
||||
$arrayDataPhpMailer["TO"] = $mailTo;
|
||||
$arrayDataPhpMailer["TO"] = $mailTo;
|
||||
|
||||
if ($auth_required == 1) {
|
||||
$arrayDataPhpMailer["MESS_RAUTH"] = true;
|
||||
@@ -458,12 +474,19 @@ class EmailServer
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isset($arrayResult["message"])) {
|
||||
$arrayResult["message"] = "";
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayResult;
|
||||
} catch (Exception $e) {
|
||||
$arrayResult = [
|
||||
"result" => false,
|
||||
"message" => $e->getMessage()
|
||||
];
|
||||
$arrayResult = array();
|
||||
|
||||
$arrayResult["result"] = false;
|
||||
$arrayResult["message"] = $e->getMessage();
|
||||
|
||||
//Return
|
||||
return $arrayResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1253,6 +1253,7 @@ class System
|
||||
* @access public
|
||||
* @param string $globalIniFile
|
||||
* @return array of execute query Black list
|
||||
* @deprecated since version 3.6.4
|
||||
*/
|
||||
public static function getQueryBlackList($globalIniFile = '')
|
||||
{
|
||||
|
||||
@@ -1,480 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\EmailOAuth;
|
||||
|
||||
use AppMessage;
|
||||
use Bootstrap;
|
||||
use G;
|
||||
use Google_Client;
|
||||
use Google_Service_Gmail;
|
||||
use Google_Service_Gmail_Message;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use ProcessMaker\BusinessModel\EmailServer;
|
||||
use ProcessMaker\Core\System;
|
||||
use TemplatePower;
|
||||
use WsBase;
|
||||
|
||||
trait EmailBase
|
||||
{
|
||||
private $server;
|
||||
private $port;
|
||||
private $emailServerUid;
|
||||
private $emailEngine;
|
||||
private $clientID;
|
||||
private $clientSecret;
|
||||
private $fromAccount;
|
||||
private $senderEmail;
|
||||
private $senderName;
|
||||
private $sendTestMail;
|
||||
private $mailTo;
|
||||
private $setDefaultConfiguration;
|
||||
private $redirectURI;
|
||||
private $refreshToken;
|
||||
|
||||
/**
|
||||
* Set $server property.
|
||||
* @param string $server
|
||||
* @return void
|
||||
*/
|
||||
public function setServer($server): void
|
||||
{
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $port property.
|
||||
* @param string $port
|
||||
* @return void
|
||||
*/
|
||||
public function setPort($port): void
|
||||
{
|
||||
$this->port = $port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $emailServerUid property.
|
||||
* @param string $emailServerUid
|
||||
* @return void
|
||||
*/
|
||||
public function setEmailServerUid($emailServerUid): void
|
||||
{
|
||||
$this->emailServerUid = $emailServerUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $clientID property.
|
||||
* @param string $clientID
|
||||
* @return void
|
||||
*/
|
||||
public function setClientID($clientID): void
|
||||
{
|
||||
$this->clientID = $clientID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $clientSecret property.
|
||||
* @param string $clientSecret
|
||||
* @return void
|
||||
*/
|
||||
public function setClientSecret($clientSecret): void
|
||||
{
|
||||
$this->clientSecret = $clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $redirectURI property.
|
||||
* @param string $redirectURI
|
||||
* @return void
|
||||
*/
|
||||
public function setRedirectURI($redirectURI): void
|
||||
{
|
||||
$this->redirectURI = $redirectURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $emailEngine property.
|
||||
* @param string $emailEngine
|
||||
* @return void
|
||||
*/
|
||||
public function setEmailEngine($emailEngine): void
|
||||
{
|
||||
$this->emailEngine = $emailEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $fromAccount property.
|
||||
* @param string $fromAccount
|
||||
* @return void
|
||||
*/
|
||||
public function setFromAccount($fromAccount): void
|
||||
{
|
||||
$this->fromAccount = $fromAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $senderEmail property.
|
||||
* @param string $senderEmail
|
||||
* @return void
|
||||
*/
|
||||
public function setSenderEmail($senderEmail): void
|
||||
{
|
||||
$this->senderEmail = $senderEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $senderName property.
|
||||
* @param string $senderName
|
||||
* @return void
|
||||
*/
|
||||
public function setSenderName($senderName): void
|
||||
{
|
||||
$this->senderName = $senderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $sendTestMail property.
|
||||
* @param string $sendTestMail
|
||||
* @return void
|
||||
*/
|
||||
public function setSendTestMail($sendTestMail): void
|
||||
{
|
||||
$this->sendTestMail = $sendTestMail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $mailTo property.
|
||||
* @param string $mailTo
|
||||
* @return void
|
||||
*/
|
||||
public function setMailTo($mailTo): void
|
||||
{
|
||||
$this->mailTo = $mailTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $setDefaultConfiguration property.
|
||||
* @param int $setDefaultConfiguration
|
||||
* @return void
|
||||
*/
|
||||
public function setSetDefaultConfiguration($setDefaultConfiguration): void
|
||||
{
|
||||
$this->setDefaultConfiguration = $setDefaultConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $refreshToken property.
|
||||
* @param string $refreshToken
|
||||
* @return void
|
||||
*/
|
||||
public function setRefreshToken($refreshToken): void
|
||||
{
|
||||
$this->refreshToken = $refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $server property.
|
||||
* @return string
|
||||
*/
|
||||
public function getServer()
|
||||
{
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $port property.
|
||||
* @return string
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $emailServerUid property.
|
||||
* @return string
|
||||
*/
|
||||
public function getEmailServerUid()
|
||||
{
|
||||
return $this->emailServerUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $clientID property.
|
||||
* @return string
|
||||
*/
|
||||
public function getClientID()
|
||||
{
|
||||
return $this->clientID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $clientSecret property.
|
||||
* @return string
|
||||
*/
|
||||
public function getClientSecret()
|
||||
{
|
||||
return $this->clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $redirectURI property.
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirectURI()
|
||||
{
|
||||
return $this->redirectURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $emailEngine property.
|
||||
* @return string
|
||||
*/
|
||||
public function getEmailEngine()
|
||||
{
|
||||
return $this->emailEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $fromAccount property.
|
||||
* @return string
|
||||
*/
|
||||
public function getFromAccount()
|
||||
{
|
||||
return $this->fromAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $senderEmail property.
|
||||
* @return string
|
||||
*/
|
||||
public function getSenderEmail()
|
||||
{
|
||||
return $this->senderEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $senderName property.
|
||||
* @return string
|
||||
*/
|
||||
public function getSenderName()
|
||||
{
|
||||
return $this->senderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $sendTestMail property.
|
||||
* @return string
|
||||
*/
|
||||
public function getSendTestMail()
|
||||
{
|
||||
return $this->sendTestMail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $mailTo property.
|
||||
* @return string
|
||||
*/
|
||||
public function getMailTo()
|
||||
{
|
||||
return $this->mailTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $defaultConfiguration property.
|
||||
* @return int
|
||||
*/
|
||||
public function getSetDefaultConfiguration()
|
||||
{
|
||||
return $this->setDefaultConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $refreshToken property.
|
||||
* @return string
|
||||
*/
|
||||
public function getRefreshToken()
|
||||
{
|
||||
return $this->refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the data in the EmailServer table, and return the stored fields.
|
||||
* @return array
|
||||
*/
|
||||
public function saveEmailServer(): array
|
||||
{
|
||||
$result = [];
|
||||
$data = [
|
||||
"MESS_ENGINE" => $this->emailEngine,
|
||||
"OAUTH_CLIENT_ID" => $this->clientID,
|
||||
"OAUTH_CLIENT_SECRET" => $this->clientSecret,
|
||||
"OAUTH_REFRESH_TOKEN" => $this->refreshToken,
|
||||
"MESS_ACCOUNT" => $this->fromAccount,
|
||||
"MESS_FROM_MAIL" => $this->senderEmail,
|
||||
"MESS_FROM_NAME" => $this->senderName,
|
||||
"MESS_TRY_SEND_INMEDIATLY" => $this->sendTestMail,
|
||||
"MAIL_TO" => $this->mailTo,
|
||||
"MESS_DEFAULT" => $this->setDefaultConfiguration,
|
||||
"MESS_RAUTH" => 1,
|
||||
"SMTPSECURE" => "No",
|
||||
"MESS_PASSWORD" => "",
|
||||
"MESS_SERVER" => $this->server,
|
||||
"MESS_PORT" => $this->port,
|
||||
"MESS_PASSWORD" => "",
|
||||
"MESS_INCOMING_SERVER" => "",
|
||||
"MESS_INCOMING_PORT" => ""
|
||||
];
|
||||
$emailServer = new EmailServer();
|
||||
if (empty($this->emailServerUid)) {
|
||||
$result = $emailServer->create($data);
|
||||
} else {
|
||||
$result = $emailServer->update($this->emailServerUid, $data);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message body.
|
||||
* @return string
|
||||
*/
|
||||
public function getMessageBody(): string
|
||||
{
|
||||
$templateTower = new TemplatePower(PATH_TPL . "admin" . PATH_SEP . "email.tpl");
|
||||
$templateTower->prepare();
|
||||
$templateTower->assign("server", System::getServerProtocol() . System::getServerHost());
|
||||
$templateTower->assign("date", date("H:i:s"));
|
||||
$templateTower->assign("ver", System::getVersion());
|
||||
$templateTower->assign("engine", G::LoadTranslation("ID_MESS_ENGINE_TYPE_4"));
|
||||
$templateTower->assign("msg", G::LoadTranslation("ID_MESS_TEST_BODY"));
|
||||
$outputContent = $templateTower->getOutputContent();
|
||||
return $outputContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plain text of the test message.
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMessage(): string
|
||||
{
|
||||
$outputContent = $this->getMessageBody();
|
||||
|
||||
$strRawMessage = ""
|
||||
. "From: Email <{$this->fromAccount}> \r\n"
|
||||
. "To: <{$this->mailTo}>\r\n"
|
||||
. "Subject: =?utf-8?B?" . base64_encode(G::LoadTranslation("ID_MESS_TEST_SUBJECT")) . "?=\r\n"
|
||||
. "MIME-Version: 1.0\r\n"
|
||||
. "Content-Type: text/html; charset=utf-8\r\n"
|
||||
. "Content-Transfer-Encoding: quoted-printable\r\n\r\n"
|
||||
. "{$outputContent}\r\n";
|
||||
|
||||
$raw = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
|
||||
return $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sends a test email with PHPMailerOAuth object, as long
|
||||
* as the test flag is activated.
|
||||
* @param string $provider
|
||||
* @return PHPMailerOAuth
|
||||
*/
|
||||
public function sendTestMailWithPHPMailerOAuth($provider = 'League\OAuth2\Client\Provider\Google'): PHPMailerOAuth
|
||||
{
|
||||
$phpMailerOAuth = new PHPMailerOAuth([
|
||||
'provider' => new $provider([
|
||||
'clientId' => $this->clientID,
|
||||
'clientSecret' => $this->clientSecret,
|
||||
'redirectUri' => $this->refreshToken,
|
||||
'accessType' => 'offline'
|
||||
]),
|
||||
'clientId' => $this->clientID,
|
||||
'clientSecret' => $this->clientSecret,
|
||||
'refreshToken' => $this->refreshToken,
|
||||
'userName' => $this->fromAccount
|
||||
]);
|
||||
if (!filter_var($this->fromAccount, FILTER_VALIDATE_EMAIL)) {
|
||||
return $phpMailerOAuth;
|
||||
}
|
||||
if (!filter_var($this->mailTo, FILTER_VALIDATE_EMAIL)) {
|
||||
return $phpMailerOAuth;
|
||||
}
|
||||
if ($this->sendTestMail === 0) {
|
||||
return $phpMailerOAuth;
|
||||
}
|
||||
$senderEmail = $this->senderEmail;
|
||||
if (!filter_var($senderEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
$senderEmail = $this->fromAccount;
|
||||
}
|
||||
if (empty($this->senderName)) {
|
||||
$this->senderName = "";
|
||||
}
|
||||
|
||||
$phpMailerOAuth->isHTML(true);
|
||||
$phpMailerOAuth->isSMTP();
|
||||
$phpMailerOAuth->Host = $this->server;
|
||||
$phpMailerOAuth->Port = $this->port;
|
||||
$phpMailerOAuth->SMTPSecure = 'tls';
|
||||
$phpMailerOAuth->SMTPAuth = true;
|
||||
$phpMailerOAuth->AuthType = 'XOAUTH2';
|
||||
$phpMailerOAuth->SetFrom($senderEmail, $this->senderName);
|
||||
$phpMailerOAuth->Subject = G::LoadTranslation("ID_MESS_TEST_SUBJECT");
|
||||
$phpMailerOAuth->Body = utf8_encode($this->getMessageBody());
|
||||
$phpMailerOAuth->AddAddress($this->mailTo);
|
||||
$status = $phpMailerOAuth->Send();
|
||||
$this->saveIntoStandardLogs($status ? "sent" : "pending");
|
||||
$this->saveIntoAppMessage($status ? "sent" : "pending");
|
||||
return $phpMailerOAuth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register into APP_MESSAGE table.
|
||||
* @param string $status
|
||||
*/
|
||||
public function saveIntoAppMessage(string $status = "")
|
||||
{
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
$spool = new AppMessage();
|
||||
$spool->setAppMsgUid($appMsgUid);
|
||||
$spool->setMsgUid("");
|
||||
$spool->setAppUid("");
|
||||
$spool->setDelIndex(0);
|
||||
$spool->setAppMsgType(WsBase::MESSAGE_TYPE_TEST_EMAIL);
|
||||
$spool->setAppMsgTypeId(isset(AppMessage::$app_msg_type_values[WsBase::MESSAGE_TYPE_TEST_EMAIL]) ? AppMessage::$app_msg_type_values[WsBase::MESSAGE_TYPE_TEST_EMAIL] : 0);
|
||||
$spool->setAppMsgSubject(G::LoadTranslation("ID_MESS_TEST_SUBJECT"));
|
||||
$spool->setAppMsgFrom($this->fromAccount);
|
||||
$spool->setAppMsgTo($this->mailTo);
|
||||
$spool->setAppMsgBody(utf8_encode($this->getMessageBody()));
|
||||
$spool->setAppMsgDate(date('Y-m-d H:i:s'));
|
||||
$spool->setAppMsgCc("");
|
||||
$spool->setAppMsgBcc("");
|
||||
$spool->setappMsgAttach(serialize([""]));
|
||||
$spool->setAppMsgTemplate("");
|
||||
$spool->setAppMsgStatus($status);
|
||||
$spool->setAppMsgStatusId(AppMessage::$app_msg_status_values[$status] ? AppMessage::$app_msg_status_values[$status] : 0);
|
||||
$spool->setAppMsgSendDate(date('Y-m-d H:i:s'));
|
||||
$spool->setAppMsgShowMessage(1);
|
||||
$spool->setAppMsgError("");
|
||||
$spool->setAppNumber(0);
|
||||
$spool->setTasId(0);
|
||||
$spool->setProId(0);
|
||||
$spool->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register into standard logs.
|
||||
* @param string $status
|
||||
*/
|
||||
public function saveIntoStandardLogs(string $status = "")
|
||||
{
|
||||
$message = "Email Server test has been sent";
|
||||
$context = [
|
||||
"emailServerUid" => $this->emailServerUid,
|
||||
"emailEngine" => $this->emailEngine,
|
||||
"from" => $this->fromAccount,
|
||||
"senderAccount" => $this->mailTo,
|
||||
"senderEmail" => $this->senderEmail,
|
||||
"senderName" => $this->senderName,
|
||||
"status" => $status
|
||||
];
|
||||
Log::channel(':' . $this->emailEngine)->info($message, Bootstrap::context($context));
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\EmailOAuth;
|
||||
|
||||
use PHPMailer\PHPMailer\OAuth;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class PHPMailerOAuth extends PHPMailer
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor of the class.
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
$oauth = new OAuth($options);
|
||||
$this->setOAuth($oauth);
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,260 @@
|
||||
|
||||
namespace ProcessMaker\GmailOAuth;
|
||||
|
||||
use AppMessage;
|
||||
use Bootstrap;
|
||||
use G;
|
||||
use Google_Client;
|
||||
use Google_Service_Gmail;
|
||||
use Google_Service_Gmail_Message;
|
||||
use ProcessMaker\EmailOAuth\EmailBase;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use PHPMailerOAuth;
|
||||
use ProcessMaker\BusinessModel\EmailServer;
|
||||
use ProcessMaker\Core\System;
|
||||
use TemplatePower;
|
||||
use WsBase;
|
||||
|
||||
class GmailOAuth
|
||||
{
|
||||
|
||||
use EmailBase;
|
||||
private $emailServerUid;
|
||||
private $emailEngine;
|
||||
private $clientID;
|
||||
private $clientSecret;
|
||||
private $fromAccount;
|
||||
private $senderEmail;
|
||||
private $senderName;
|
||||
private $sendTestMail;
|
||||
private $mailTo;
|
||||
private $setDefaultConfiguration;
|
||||
private $redirectURI;
|
||||
private $refreshToken;
|
||||
|
||||
/**
|
||||
* Constructor of the class.
|
||||
* Set $emailServerUid property.
|
||||
* @param string $emailServerUid
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function setEmailServerUid($emailServerUid): void
|
||||
{
|
||||
$this->setServer("smtp.gmail.com");
|
||||
$this->setPort(587);
|
||||
$this->emailServerUid = $emailServerUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $clientID property.
|
||||
* @param string $clientID
|
||||
* @return void
|
||||
*/
|
||||
public function setClientID($clientID): void
|
||||
{
|
||||
$this->clientID = $clientID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $clientSecret property.
|
||||
* @param string $clientSecret
|
||||
* @return void
|
||||
*/
|
||||
public function setClientSecret($clientSecret): void
|
||||
{
|
||||
$this->clientSecret = $clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $redirectURI property.
|
||||
* @param string $redirectURI
|
||||
* @return void
|
||||
*/
|
||||
public function setRedirectURI($redirectURI): void
|
||||
{
|
||||
$this->redirectURI = $redirectURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $emailEngine property.
|
||||
* @param string $emailEngine
|
||||
* @return void
|
||||
*/
|
||||
public function setEmailEngine($emailEngine): void
|
||||
{
|
||||
$this->emailEngine = $emailEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $fromAccount property.
|
||||
* @param string $fromAccount
|
||||
* @return void
|
||||
*/
|
||||
public function setFromAccount($fromAccount): void
|
||||
{
|
||||
$this->fromAccount = $fromAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $senderEmail property.
|
||||
* @param string $senderEmail
|
||||
* @return void
|
||||
*/
|
||||
public function setSenderEmail($senderEmail): void
|
||||
{
|
||||
$this->senderEmail = $senderEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $senderName property.
|
||||
* @param string $senderName
|
||||
* @return void
|
||||
*/
|
||||
public function setSenderName($senderName): void
|
||||
{
|
||||
$this->senderName = $senderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $sendTestMail property.
|
||||
* @param string $sendTestMail
|
||||
* @return void
|
||||
*/
|
||||
public function setSendTestMail($sendTestMail): void
|
||||
{
|
||||
$this->sendTestMail = $sendTestMail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $mailTo property.
|
||||
* @param string $mailTo
|
||||
* @return void
|
||||
*/
|
||||
public function setMailTo($mailTo): void
|
||||
{
|
||||
$this->mailTo = $mailTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $setDefaultConfiguration property.
|
||||
* @param string $setDefaultConfiguration
|
||||
* @return void
|
||||
*/
|
||||
public function setSetDefaultConfiguration($setDefaultConfiguration): void
|
||||
{
|
||||
$this->setDefaultConfiguration = $setDefaultConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $refreshToken property.
|
||||
* @param string $refreshToken
|
||||
* @return void
|
||||
*/
|
||||
public function setRefreshToken($refreshToken): void
|
||||
{
|
||||
$this->refreshToken = $refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $emailServerUid property.
|
||||
* @return string
|
||||
*/
|
||||
public function getEmailServerUid()
|
||||
{
|
||||
return $this->emailServerUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $clientID property.
|
||||
* @return string
|
||||
*/
|
||||
public function getClientID()
|
||||
{
|
||||
return $this->clientID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $clientSecret property.
|
||||
* @return string
|
||||
*/
|
||||
public function getClientSecret()
|
||||
{
|
||||
return $this->clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $redirectURI property.
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirectURI()
|
||||
{
|
||||
return $this->redirectURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $emailEngine property.
|
||||
* @return string
|
||||
*/
|
||||
public function getEmailEngine()
|
||||
{
|
||||
return $this->emailEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $fromAccount property.
|
||||
* @return string
|
||||
*/
|
||||
public function getFromAccount()
|
||||
{
|
||||
return $this->fromAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $senderEmail property.
|
||||
* @return string
|
||||
*/
|
||||
public function getSenderEmail()
|
||||
{
|
||||
return $this->senderEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $senderName property.
|
||||
* @return string
|
||||
*/
|
||||
public function getSenderName()
|
||||
{
|
||||
return $this->senderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $sendTestMail property.
|
||||
* @return string
|
||||
*/
|
||||
public function getSendTestMail()
|
||||
{
|
||||
return $this->sendTestMail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $mailTo property.
|
||||
* @return string
|
||||
*/
|
||||
public function getMailTo()
|
||||
{
|
||||
return $this->mailTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $defaultConfiguration property.
|
||||
* @return string
|
||||
*/
|
||||
public function getSetDefaultConfiguration()
|
||||
{
|
||||
return $this->setDefaultConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $refreshToken property.
|
||||
* @return string
|
||||
*/
|
||||
public function getRefreshToken()
|
||||
{
|
||||
return $this->refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,6 +274,42 @@ class GmailOAuth
|
||||
return $googleClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the data in the EmailServer table, and return the stored fields.
|
||||
* @return array
|
||||
*/
|
||||
public function saveEmailServer(): array
|
||||
{
|
||||
$result = [];
|
||||
$data = [
|
||||
"MESS_ENGINE" => $this->emailEngine,
|
||||
"OAUTH_CLIENT_ID" => $this->clientID,
|
||||
"OAUTH_CLIENT_SECRET" => $this->clientSecret,
|
||||
"OAUTH_REFRESH_TOKEN" => $this->refreshToken,
|
||||
"MESS_ACCOUNT" => $this->fromAccount,
|
||||
"MESS_FROM_MAIL" => $this->senderEmail,
|
||||
"MESS_FROM_NAME" => $this->senderName,
|
||||
"MESS_TRY_SEND_INMEDIATLY" => $this->sendTestMail,
|
||||
"MAIL_TO" => $this->mailTo,
|
||||
"MESS_DEFAULT" => $this->setDefaultConfiguration,
|
||||
"MESS_RAUTH" => 1,
|
||||
"SMTPSECURE" => "No",
|
||||
"MESS_PASSWORD" => "",
|
||||
"MESS_SERVER" => "smtp.gmail.com",
|
||||
"MESS_PORT" => "",
|
||||
"MESS_PASSWORD" => "",
|
||||
"MESS_INCOMING_SERVER" => "",
|
||||
"MESS_INCOMING_PORT" => ""
|
||||
];
|
||||
$emailServer = new EmailServer();
|
||||
if (empty($this->emailServerUid)) {
|
||||
$result = $emailServer->create($data);
|
||||
} else {
|
||||
$result = $emailServer->update($this->emailServerUid, $data);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sends a test email with Google_Service_Gmail_Message object, as long
|
||||
* as the test flag is activated.
|
||||
@@ -69,4 +342,139 @@ class GmailOAuth
|
||||
$result = $service->users_messages->send("me", $googleServiceGmailMessage);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message body.
|
||||
* @return string
|
||||
*/
|
||||
public function getMessageBody(): string
|
||||
{
|
||||
$templateTower = new TemplatePower(PATH_TPL . "admin" . PATH_SEP . "email.tpl");
|
||||
$templateTower->prepare();
|
||||
$templateTower->assign("server", System::getServerProtocol() . System::getServerHost());
|
||||
$templateTower->assign("date", date("H:i:s"));
|
||||
$templateTower->assign("ver", System::getVersion());
|
||||
$templateTower->assign("engine", G::LoadTranslation("ID_MESS_ENGINE_TYPE_4"));
|
||||
$templateTower->assign("msg", G::LoadTranslation("ID_MESS_TEST_BODY"));
|
||||
$outputContent = $templateTower->getOutputContent();
|
||||
return $outputContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plain text of the test message.
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMessage(): string
|
||||
{
|
||||
$outputContent = $this->getMessageBody();
|
||||
|
||||
$strRawMessage = ""
|
||||
. "From: Email <{$this->fromAccount}> \r\n"
|
||||
. "To: <{$this->mailTo}>\r\n"
|
||||
. "Subject: =?utf-8?B?" . base64_encode(G::LoadTranslation("ID_MESS_TEST_SUBJECT")) . "?=\r\n"
|
||||
. "MIME-Version: 1.0\r\n"
|
||||
. "Content-Type: text/html; charset=utf-8\r\n"
|
||||
. "Content-Transfer-Encoding: quoted-printable\r\n\r\n"
|
||||
. "{$outputContent}\r\n";
|
||||
|
||||
$raw = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
|
||||
return $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sends a test email with PHPMailerOAuth object, as long
|
||||
* as the test flag is activated.
|
||||
* @return PHPMailerOAuth
|
||||
*/
|
||||
public function sendTestMailWithPHPMailerOAuth(): PHPMailerOAuth
|
||||
{
|
||||
$phpMailerOAuth = new PHPMailerOAuth();
|
||||
if (!filter_var($this->fromAccount, FILTER_VALIDATE_EMAIL)) {
|
||||
return $phpMailerOAuth;
|
||||
}
|
||||
if (!filter_var($this->mailTo, FILTER_VALIDATE_EMAIL)) {
|
||||
return $phpMailerOAuth;
|
||||
}
|
||||
if ($this->sendTestMail === 0) {
|
||||
return $phpMailerOAuth;
|
||||
}
|
||||
$senderEmail = $this->senderEmail;
|
||||
if (!filter_var($senderEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
$senderEmail = $this->fromAccount;
|
||||
}
|
||||
if (empty($this->senderName)) {
|
||||
$this->senderName = "";
|
||||
}
|
||||
|
||||
$phpMailerOAuth->isHTML(true);
|
||||
$phpMailerOAuth->isSMTP();
|
||||
$phpMailerOAuth->Host = 'smtp.gmail.com';
|
||||
$phpMailerOAuth->SMTPAuth = true;
|
||||
$phpMailerOAuth->AuthType = 'XOAUTH2';
|
||||
$phpMailerOAuth->oauthUserEmail = $this->fromAccount;
|
||||
$phpMailerOAuth->oauthClientId = $this->clientID;
|
||||
$phpMailerOAuth->oauthClientSecret = $this->clientSecret;
|
||||
$phpMailerOAuth->oauthRefreshToken = $this->refreshToken;
|
||||
$phpMailerOAuth->SetFrom($senderEmail, $this->senderName);
|
||||
$phpMailerOAuth->Subject = G::LoadTranslation("ID_MESS_TEST_SUBJECT");
|
||||
$phpMailerOAuth->Body = utf8_encode($this->getMessageBody());
|
||||
$phpMailerOAuth->AddAddress($this->mailTo);
|
||||
$status = $phpMailerOAuth->Send();
|
||||
$this->saveIntoStandardLogs($status ? "sent" : "pending");
|
||||
$this->saveIntoAppMessage($status ? "sent" : "pending");
|
||||
return $phpMailerOAuth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register into APP_MESSAGE table.
|
||||
* @param string $status
|
||||
*/
|
||||
public function saveIntoAppMessage(string $status = "")
|
||||
{
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
$spool = new AppMessage();
|
||||
$spool->setAppMsgUid($appMsgUid);
|
||||
$spool->setMsgUid("");
|
||||
$spool->setAppUid("");
|
||||
$spool->setDelIndex(0);
|
||||
$spool->setAppMsgType(WsBase::MESSAGE_TYPE_TEST_EMAIL);
|
||||
$spool->setAppMsgTypeId(isset(AppMessage::$app_msg_type_values[WsBase::MESSAGE_TYPE_TEST_EMAIL]) ? AppMessage::$app_msg_type_values[WsBase::MESSAGE_TYPE_TEST_EMAIL] : 0);
|
||||
$spool->setAppMsgSubject(G::LoadTranslation("ID_MESS_TEST_SUBJECT"));
|
||||
$spool->setAppMsgFrom($this->fromAccount);
|
||||
$spool->setAppMsgTo($this->mailTo);
|
||||
$spool->setAppMsgBody(utf8_encode($this->getMessageBody()));
|
||||
$spool->setAppMsgDate(date('Y-m-d H:i:s'));
|
||||
$spool->setAppMsgCc("");
|
||||
$spool->setAppMsgBcc("");
|
||||
$spool->setappMsgAttach(serialize([""]));
|
||||
$spool->setAppMsgTemplate("");
|
||||
$spool->setAppMsgStatus($status);
|
||||
$spool->setAppMsgStatusId(AppMessage::$app_msg_status_values[$status] ? AppMessage::$app_msg_status_values[$status] : 0);
|
||||
$spool->setAppMsgSendDate(date('Y-m-d H:i:s'));
|
||||
$spool->setAppMsgShowMessage(1);
|
||||
$spool->setAppMsgError("");
|
||||
$spool->setAppNumber(0);
|
||||
$spool->setTasId(0);
|
||||
$spool->setProId(0);
|
||||
$spool->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register into standard logs.
|
||||
* @param string $status
|
||||
*/
|
||||
public function saveIntoStandardLogs(string $status = "")
|
||||
{
|
||||
$message = "Email Server test has been sent";
|
||||
$context = [
|
||||
"emailServerUid" => $this->emailServerUid,
|
||||
"emailEngine" => $this->emailEngine,
|
||||
"from" => $this->fromAccount,
|
||||
"senderAccount" => $this->mailTo,
|
||||
"senderEmail" => $this->senderEmail,
|
||||
"senderName" => $this->senderName,
|
||||
"status" => $status
|
||||
];
|
||||
Log::channel(':GmailOAuth')->info($message, Bootstrap::context($context));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Office365OAuth;
|
||||
|
||||
use League\OAuth2\Client\Provider\GenericProvider;
|
||||
use ProcessMaker\EmailOAuth\EmailBase;
|
||||
use ProcessMaker\GmailOAuth\GmailOAuth;
|
||||
use Stevenmaguire\OAuth2\Client\Provider\Microsoft;
|
||||
|
||||
class Office365OAuth
|
||||
{
|
||||
|
||||
use EmailBase;
|
||||
private $options = [
|
||||
'scope' => [
|
||||
'wl.imap',
|
||||
'wl.offline_access'
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor of the class.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setServer("smtp.office365.com");
|
||||
$this->setPort(587);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $options property.
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Microsoft object, this may vary depending on the service provider.
|
||||
* @return Google_Client
|
||||
*/
|
||||
public function getOffice365Client()
|
||||
{
|
||||
$provider = new Microsoft([
|
||||
'clientId' => $this->getClientID(),
|
||||
'clientSecret' => $this->getClientSecret(),
|
||||
'redirectUri' => $this->getRedirectURI(),
|
||||
'accessType' => 'offline'
|
||||
]);
|
||||
return $provider;
|
||||
}
|
||||
}
|
||||
124
workflow/engine/src/ProcessMaker/Validation/SqlBlacklist.php
Normal file
124
workflow/engine/src/ProcessMaker/Validation/SqlBlacklist.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Validation;
|
||||
|
||||
use Exception;
|
||||
use G;
|
||||
use PhpMyAdmin\SqlParser\Parser;
|
||||
|
||||
class SqlBlacklist extends Parser
|
||||
{
|
||||
|
||||
/**
|
||||
* Define the statements to block, this is case sensitive.
|
||||
* @var array
|
||||
*/
|
||||
private $statementsToBeBlocked = [
|
||||
'SELECT',
|
||||
'EXECUTE',
|
||||
'EXEC',
|
||||
'SHOW',
|
||||
'DESCRIBE',
|
||||
'EXPLAIN',
|
||||
'BEGIN',
|
||||
'INSERT',
|
||||
'UPDATE',
|
||||
'DELETE',
|
||||
'REPLACE'
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor of class.
|
||||
* @param string $list
|
||||
* @param boolean $strict
|
||||
*/
|
||||
public function __construct($list = null, $strict = false)
|
||||
{
|
||||
parent::__construct($list, $strict);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about the statements permitted and tables that can be modified.
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigValues(): array
|
||||
{
|
||||
$tables = [];
|
||||
$statements = [];
|
||||
$pmtables = [];
|
||||
|
||||
$path = PATH_CONFIG . 'system-tables.ini';
|
||||
if (file_exists($path)) {
|
||||
$values = @parse_ini_file($path);
|
||||
|
||||
$string = isset($values['tables']) ? $values['tables'] : '';
|
||||
$tables = explode('|', $string);
|
||||
$tables = array_filter($tables, function ($v) {
|
||||
return !empty($v);
|
||||
});
|
||||
}
|
||||
|
||||
$path = PATH_CONFIG . 'execute-query-blacklist.ini';
|
||||
if (file_exists($path)) {
|
||||
$values = @parse_ini_file($path);
|
||||
|
||||
$string = isset($values['pmtables']) ? $values['pmtables'] : '';
|
||||
$pmtables = explode('|', $string);
|
||||
$pmtables = array_filter($pmtables, function ($v) {
|
||||
return !empty($v);
|
||||
});
|
||||
|
||||
$string = isset($values['queries']) ? $values['queries'] : '';
|
||||
$string = strtoupper($string);
|
||||
$statements = explode('|', $string);
|
||||
//get only statements allowed for lock
|
||||
$statements = array_filter($statements, function ($v) {
|
||||
$toUpper = strtoupper($v);
|
||||
return !empty($v) && in_array($toUpper, $this->statementsToBeBlocked);
|
||||
});
|
||||
}
|
||||
|
||||
return [
|
||||
'tables' => $tables,
|
||||
'statements' => $statements,
|
||||
'pmtables' => $pmtables
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a sql string and check the blacklist, an exception is thrown if it contains a restricted item.
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validate(): void
|
||||
{
|
||||
$config = $this->getConfigValues();
|
||||
|
||||
//verify statements
|
||||
foreach ($this->statements as $statement) {
|
||||
$signed = get_class($statement);
|
||||
foreach (Parser::$STATEMENT_PARSERS as $key => $value) {
|
||||
if ($signed === $value && in_array(strtoupper($key), $config['statements'])) {
|
||||
throw new Exception(G::loadTranslation('ID_INVALID_QUERY'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//verify tables
|
||||
//tokens are formed multidimensionally, it is necessary to recursively traverse the multidimensional object.
|
||||
$listTables = array_merge($config['tables'], $config['pmtables']);
|
||||
$fn = function ($object) use (&$fn, $listTables) {
|
||||
foreach ($object as $key => $value) {
|
||||
if (is_array($value) || is_object($value)) {
|
||||
$fn($value);
|
||||
}
|
||||
if ($key === 'table' && is_string($value)) {
|
||||
if (in_array($value, $listTables)) {
|
||||
throw new Exception(G::loadTranslation('ID_NOT_EXECUTE_QUERY', [$value]));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
$fn($this->statements);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user