Merged in feature/PMC-1332 (pull request #7136)
PMC-1332 PMCORE-1018 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com> Approved-by: Paula Quispe <paula.quispe@processmaker.com>
This commit is contained in:
@@ -1,27 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
global $RBAC;
|
||||
|
||||
$resultRbac = $RBAC->requirePermissions('PM_SETUP_EMAIL');
|
||||
$resultRbac = $RBAC->requirePermissions('PM_SETUP_EMAIL');
|
||||
if (!$resultRbac) {
|
||||
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
|
||||
G::header('location: ../login/login');
|
||||
die();
|
||||
}
|
||||
|
||||
$messageSent = "";
|
||||
if (Cache::has('errorMessageIfNotAuthenticate')) {
|
||||
$messageSent = Cache::get('errorMessageIfNotAuthenticate');
|
||||
}
|
||||
Cache::forget('errorMessageIfNotAuthenticate');
|
||||
|
||||
//Data
|
||||
$configuration = new Configurations();
|
||||
$arrayConfigPage = $configuration->getConfiguration("emailServerList", "pageSize", null, $_SESSION["USER_LOGGED"]);
|
||||
|
||||
$arrayConfig = array();
|
||||
$arrayConfig["pageSize"] = (isset($arrayConfigPage["pageSize"]))? $arrayConfigPage["pageSize"] : 20;
|
||||
$arrayConfig["pageSize"] = (isset($arrayConfigPage["pageSize"])) ? $arrayConfigPage["pageSize"] : 20;
|
||||
|
||||
$headPublisher = headPublisher::getSingleton();
|
||||
$headPublisher->addContent("emailServer/emailServer"); //Adding a HTML file
|
||||
$headPublisher->addExtJsScript("emailServer/emailServer", false); //Adding a JavaScript file
|
||||
$headPublisher->assign("CONFIG", $arrayConfig);
|
||||
$headPublisher->assign("errorMessageIfNotAuthenticate", $messageSent);
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$headPublisher->assign("EMAILSERVER_LICENSED", (PMLicensedFeatures::getSingleton()->verifyfeature("zIKRGpDM3pjcHFsWGplNDN0dTl5bGN3UTNiOWdQU0E5Q05QTksrU1ladWQ0VT0="))? 1 : 0);
|
||||
$headPublisher->assign("EMAILSERVER_LICENSED", (PMLicensedFeatures::getSingleton()->verifyfeature("zIKRGpDM3pjcHFsWGplNDN0dTl5bGN3UTNiOWdQU0E5Q05QTksrU1ladWQ0VT0=")) ? 1 : 0);
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
G::RenderPage("publish", "extJs");
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
<?php
|
||||
$option = (isset($_POST["option"]))? $_POST["option"] : "";
|
||||
$response = array();
|
||||
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\GmailOAuth\GmailOAuth;
|
||||
|
||||
$option = (isset($_POST["option"])) ? $_POST["option"] : "";
|
||||
$response = [];
|
||||
|
||||
$RBAC->allows(basename(__FILE__), $option);
|
||||
switch ($option) {
|
||||
case "INS":
|
||||
$arrayData = array();
|
||||
$arrayData = [];
|
||||
|
||||
$server = "";
|
||||
$port = "";
|
||||
@@ -16,45 +20,45 @@ switch ($option) {
|
||||
$smtpSecure = "";
|
||||
|
||||
$cboEmailEngine = $_POST["cboEmailEngine"];
|
||||
$accountFrom = (isset($_POST["accountFrom"]))? $_POST["accountFrom"] : "";
|
||||
$accountFrom = (isset($_POST["accountFrom"])) ? $_POST["accountFrom"] : "";
|
||||
$fromName = $_POST["fromName"];
|
||||
$fromMail = $_POST["fromMail"];
|
||||
$sendTestMail = (int)($_POST["sendTestMail"]);
|
||||
$mailTo = ($sendTestMail == 1)? $_POST["mailTo"] : "";
|
||||
$emailServerDefault = (int)($_POST["emailServerDefault"]);
|
||||
$sendTestMail = (int) ($_POST["sendTestMail"]);
|
||||
$mailTo = ($sendTestMail == 1) ? $_POST["mailTo"] : "";
|
||||
$emailServerDefault = (int) ($_POST["emailServerDefault"]);
|
||||
|
||||
if ($cboEmailEngine == "PHPMAILER") {
|
||||
$server = $_POST["server"];
|
||||
$port = (int)($_POST["port"]);
|
||||
$reqAuthentication = (int)($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
|
||||
$port = (int) ($_POST["port"]);
|
||||
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
|
||||
$smtpSecure = $_POST["smtpSecure"];
|
||||
} elseif ($cboEmailEngine == "IMAP") {
|
||||
$server = $_POST["server"];
|
||||
$port = (int)($_POST["port"]);
|
||||
$port = (int) ($_POST["port"]);
|
||||
$incomingServer = $_POST["incomingServer"];
|
||||
$incomingPort = (int)($_POST["incomingPort"]);
|
||||
$reqAuthentication = (int)($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
|
||||
$incomingPort = (int) ($_POST["incomingPort"]);
|
||||
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
|
||||
$smtpSecure = $_POST["smtpSecure"];
|
||||
}
|
||||
|
||||
try {
|
||||
$arrayData = array(
|
||||
"MESS_ENGINE" => $cboEmailEngine,
|
||||
"MESS_SERVER" => $server,
|
||||
"MESS_PORT" => $port,
|
||||
"MESS_INCOMING_SERVER" => $incomingServer,
|
||||
"MESS_INCOMING_PORT" => $incomingPort,
|
||||
"MESS_RAUTH" => $reqAuthentication,
|
||||
"MESS_ACCOUNT" => $accountFrom,
|
||||
"MESS_PASSWORD" => $password,
|
||||
"MESS_FROM_MAIL" => $fromMail,
|
||||
"MESS_FROM_NAME" => $fromName,
|
||||
"SMTPSECURE" => $smtpSecure,
|
||||
"MESS_ENGINE" => $cboEmailEngine,
|
||||
"MESS_SERVER" => $server,
|
||||
"MESS_PORT" => $port,
|
||||
"MESS_INCOMING_SERVER" => $incomingServer,
|
||||
"MESS_INCOMING_PORT" => $incomingPort,
|
||||
"MESS_RAUTH" => $reqAuthentication,
|
||||
"MESS_ACCOUNT" => $accountFrom,
|
||||
"MESS_PASSWORD" => $password,
|
||||
"MESS_FROM_MAIL" => $fromMail,
|
||||
"MESS_FROM_NAME" => $fromName,
|
||||
"SMTPSECURE" => $smtpSecure,
|
||||
"MESS_TRY_SEND_INMEDIATLY" => $sendTestMail,
|
||||
"MAIL_TO" => $mailTo,
|
||||
"MESS_DEFAULT" => $emailServerDefault
|
||||
"MAIL_TO" => $mailTo,
|
||||
"MESS_DEFAULT" => $emailServerDefault
|
||||
);
|
||||
|
||||
$emailSever = new \ProcessMaker\BusinessModel\EmailServer();
|
||||
@@ -62,14 +66,14 @@ switch ($option) {
|
||||
$arrayEmailServerData = $emailSever->create($arrayData);
|
||||
|
||||
$response["status"] = "OK";
|
||||
$response["data"] = $arrayEmailServerData;
|
||||
$response["data"] = $arrayEmailServerData;
|
||||
} catch (Exception $e) {
|
||||
$response["status"] = "ERROR";
|
||||
$response["status"] = "ERROR";
|
||||
$response["message"] = $e->getMessage();
|
||||
}
|
||||
break;
|
||||
case "UPD":
|
||||
$arrayData = array();
|
||||
$arrayData = [];
|
||||
|
||||
$emailServerUid = $_POST["emailServerUid"];
|
||||
|
||||
@@ -82,45 +86,45 @@ switch ($option) {
|
||||
$smtpSecure = "";
|
||||
|
||||
$cboEmailEngine = $_POST["cboEmailEngine"];
|
||||
$accountFrom = (isset($_POST["accountFrom"]))? $_POST["accountFrom"] : "";
|
||||
$accountFrom = (isset($_POST["accountFrom"])) ? $_POST["accountFrom"] : "";
|
||||
$fromName = $_POST["fromName"];
|
||||
$fromMail = $_POST["fromMail"];
|
||||
$sendTestMail = (int)($_POST["sendTestMail"]);
|
||||
$mailTo = ($sendTestMail == 1)? $_POST["mailTo"] : "";
|
||||
$emailServerDefault = (int)($_POST["emailServerDefault"]);
|
||||
$sendTestMail = (int) ($_POST["sendTestMail"]);
|
||||
$mailTo = ($sendTestMail == 1) ? $_POST["mailTo"] : "";
|
||||
$emailServerDefault = (int) ($_POST["emailServerDefault"]);
|
||||
|
||||
if ($cboEmailEngine == "PHPMAILER") {
|
||||
$server = $_POST["server"];
|
||||
$port = (int)($_POST["port"]);
|
||||
$reqAuthentication = (int)($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
|
||||
$port = (int) ($_POST["port"]);
|
||||
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
|
||||
$smtpSecure = $_POST["smtpSecure"];
|
||||
} elseif ($cboEmailEngine == "IMAP") {
|
||||
$server = $_POST["server"];
|
||||
$port = (int)($_POST["port"]);
|
||||
$port = (int) ($_POST["port"]);
|
||||
$incomingServer = $_POST["incomingServer"];
|
||||
$incomingPort = (int)($_POST["incomingPort"]);
|
||||
$reqAuthentication = (int)($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
|
||||
$incomingPort = (int) ($_POST["incomingPort"]);
|
||||
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
|
||||
$smtpSecure = $_POST["smtpSecure"];
|
||||
}
|
||||
|
||||
try {
|
||||
$arrayData = array(
|
||||
"MESS_ENGINE" => $cboEmailEngine,
|
||||
"MESS_SERVER" => $server,
|
||||
"MESS_PORT" => $port,
|
||||
"MESS_INCOMING_SERVER" => $incomingServer,
|
||||
"MESS_INCOMING_PORT" => $incomingPort,
|
||||
"MESS_RAUTH" => $reqAuthentication,
|
||||
"MESS_ACCOUNT" => $accountFrom,
|
||||
"MESS_PASSWORD" => $password,
|
||||
"MESS_FROM_MAIL" => $fromMail,
|
||||
"MESS_FROM_NAME" => $fromName,
|
||||
"SMTPSECURE" => $smtpSecure,
|
||||
"MESS_ENGINE" => $cboEmailEngine,
|
||||
"MESS_SERVER" => $server,
|
||||
"MESS_PORT" => $port,
|
||||
"MESS_INCOMING_SERVER" => $incomingServer,
|
||||
"MESS_INCOMING_PORT" => $incomingPort,
|
||||
"MESS_RAUTH" => $reqAuthentication,
|
||||
"MESS_ACCOUNT" => $accountFrom,
|
||||
"MESS_PASSWORD" => $password,
|
||||
"MESS_FROM_MAIL" => $fromMail,
|
||||
"MESS_FROM_NAME" => $fromName,
|
||||
"SMTPSECURE" => $smtpSecure,
|
||||
"MESS_TRY_SEND_INMEDIATLY" => $sendTestMail,
|
||||
"MAIL_TO" => $mailTo,
|
||||
"MESS_DEFAULT" => $emailServerDefault
|
||||
"MAIL_TO" => $mailTo,
|
||||
"MESS_DEFAULT" => $emailServerDefault
|
||||
);
|
||||
|
||||
$emailSever = new \ProcessMaker\BusinessModel\EmailServer();
|
||||
@@ -128,9 +132,9 @@ switch ($option) {
|
||||
$arrayEmailServerData = $emailSever->update($emailServerUid, $arrayData);
|
||||
|
||||
$response["status"] = "OK";
|
||||
$response["data"] = $arrayEmailServerData;
|
||||
$response["data"] = $arrayEmailServerData;
|
||||
} catch (Exception $e) {
|
||||
$response["status"] = "ERROR";
|
||||
$response["status"] = "ERROR";
|
||||
$response["message"] = $e->getMessage();
|
||||
}
|
||||
|
||||
@@ -145,7 +149,7 @@ switch ($option) {
|
||||
|
||||
$response["status"] = "OK";
|
||||
} catch (Exception $e) {
|
||||
$response["status"] = "ERROR";
|
||||
$response["status"] = "ERROR";
|
||||
$response["message"] = $e->getMessage();
|
||||
}
|
||||
break;
|
||||
@@ -153,27 +157,27 @@ switch ($option) {
|
||||
$pageSize = $_POST["pageSize"];
|
||||
$search = $_POST["search"];
|
||||
|
||||
$sortField = (isset($_POST["sort"]))? $_POST["sort"]: "";
|
||||
$sortDir = (isset($_POST["dir"]))? $_POST["dir"]: "";
|
||||
$start = (isset($_POST["start"]))? $_POST["start"]: 0;
|
||||
$limit = (isset($_POST["limit"]))? $_POST["limit"]: $pageSize;
|
||||
$sortField = (isset($_POST["sort"])) ? $_POST["sort"] : "";
|
||||
$sortDir = (isset($_POST["dir"])) ? $_POST["dir"] : "";
|
||||
$start = (isset($_POST["start"])) ? $_POST["start"] : 0;
|
||||
$limit = (isset($_POST["limit"])) ? $_POST["limit"] : $pageSize;
|
||||
|
||||
try {
|
||||
$emailSever = new \ProcessMaker\BusinessModel\EmailServer();
|
||||
|
||||
$result = $emailSever->getEmailServers(array("filter" => $search), $sortField, $sortDir, $start, $limit);
|
||||
|
||||
$response["status"] = "OK";
|
||||
$response["status"] = "OK";
|
||||
$response["success"] = true;
|
||||
$response["resultTotal"] = $result["total"];
|
||||
$response["resultRoot"] = $result["data"];
|
||||
$response["resultRoot"] = $result["data"];
|
||||
} catch (Exception $e) {
|
||||
$response["status"] = "ERROR";
|
||||
$response["status"] = "ERROR";
|
||||
$response["message"] = $e->getMessage();
|
||||
}
|
||||
break;
|
||||
case "TEST":
|
||||
$arrayData = array();
|
||||
$arrayData = [];
|
||||
|
||||
$server = "";
|
||||
$port = "";
|
||||
@@ -184,48 +188,76 @@ switch ($option) {
|
||||
$smtpSecure = "";
|
||||
|
||||
$cboEmailEngine = $_POST["cboEmailEngine"];
|
||||
$accountFrom = (isset($_POST["accountFrom"]))? $_POST["accountFrom"] : "";
|
||||
$accountFrom = (isset($_POST["accountFrom"])) ? $_POST["accountFrom"] : "";
|
||||
$fromName = $_POST["fromName"];
|
||||
$fromMail = $_POST["fromMail"];
|
||||
$sendTestMail = (int)($_POST["sendTestMail"]);
|
||||
$mailTo = ($sendTestMail == 1)? $_POST["mailTo"] : "";
|
||||
$emailServerDefault = (int)($_POST["emailServerDefault"]);
|
||||
$sendTestMail = (int) ($_POST["sendTestMail"]);
|
||||
$mailTo = ($sendTestMail == 1) ? $_POST["mailTo"] : "";
|
||||
$emailServerDefault = (int) ($_POST["emailServerDefault"]);
|
||||
|
||||
if ($cboEmailEngine == "PHPMAILER" || $cboEmailEngine == "IMAP") {
|
||||
$server = $_POST["server"];
|
||||
$port = (int)($_POST["port"]);
|
||||
$reqAuthentication = (int)($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
|
||||
$port = (int) ($_POST["port"]);
|
||||
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
|
||||
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
|
||||
$smtpSecure = $_POST["smtpSecure"];
|
||||
}
|
||||
|
||||
try {
|
||||
$arrayData = array(
|
||||
"MESS_ENGINE" => $cboEmailEngine,
|
||||
"MESS_SERVER" => $server,
|
||||
"MESS_PORT" => $port,
|
||||
"MESS_RAUTH" => $reqAuthentication,
|
||||
"MESS_ACCOUNT" => $accountFrom,
|
||||
"MESS_PASSWORD" => $password,
|
||||
"MESS_FROM_MAIL" => $fromMail,
|
||||
"MESS_FROM_NAME" => $fromName,
|
||||
"SMTPSECURE" => $smtpSecure,
|
||||
"MESS_ENGINE" => $cboEmailEngine,
|
||||
"MESS_SERVER" => $server,
|
||||
"MESS_PORT" => $port,
|
||||
"MESS_RAUTH" => $reqAuthentication,
|
||||
"MESS_ACCOUNT" => $accountFrom,
|
||||
"MESS_PASSWORD" => $password,
|
||||
"MESS_FROM_MAIL" => $fromMail,
|
||||
"MESS_FROM_NAME" => $fromName,
|
||||
"SMTPSECURE" => $smtpSecure,
|
||||
"MESS_TRY_SEND_INMEDIATLY" => $sendTestMail,
|
||||
"MAIL_TO" => $mailTo,
|
||||
"MESS_DEFAULT" => $emailServerDefault
|
||||
"MAIL_TO" => $mailTo,
|
||||
"MESS_DEFAULT" => $emailServerDefault
|
||||
);
|
||||
|
||||
$emailSever = new \ProcessMaker\BusinessModel\EmailServer();
|
||||
|
||||
$arrayEmailServerData = $emailSever->testConnection($arrayData);
|
||||
|
||||
$response["data"] = $arrayEmailServerData;
|
||||
$response["data"] = $arrayEmailServerData;
|
||||
} catch (Exception $e) {
|
||||
$response["status"] = "ERROR";
|
||||
$response["status"] = "ERROR";
|
||||
$response["message"] = $e->getMessage();
|
||||
}
|
||||
break;
|
||||
case "createAuthUrl":
|
||||
try {
|
||||
$gmailOAuth = new GmailOAuth();
|
||||
$gmailOAuth->setClientID($_POST['clientID']);
|
||||
$gmailOAuth->setClientSecret($_POST['clientSecret']);
|
||||
$gmailOAuth->setRedirectURI(System::getServerMainPath() . "/emailServer/emailServerGmailOAuth");
|
||||
$gmailOAuth->setEmailEngine($_POST['emailEngine']);
|
||||
$gmailOAuth->setFromAccount($_POST['fromAccount']);
|
||||
$gmailOAuth->setSenderEmail($_POST['senderEmail']);
|
||||
$gmailOAuth->setSenderName($_POST['senderName']);
|
||||
$gmailOAuth->setSendTestMail((int) $_POST['sendTestMail']);
|
||||
$gmailOAuth->setMailTo($_POST['mailTo']);
|
||||
$gmailOAuth->setSetDefaultConfiguration((int) $_POST['setDefaultConfiguration']);
|
||||
if (!empty($_POST['emailServerUid'])) {
|
||||
$gmailOAuth->setEmailServerUid($_POST['emailServerUid']);
|
||||
}
|
||||
$client = $gmailOAuth->getGoogleClient();
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"data" => $client->createAuthUrl()
|
||||
];
|
||||
$_SESSION['gmailOAuth'] = $gmailOAuth;
|
||||
} catch (Exception $e) {
|
||||
$response = [
|
||||
"status" => 500,
|
||||
"message" => $e->getMessage()
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
echo G::json_encode($response);
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\GmailOAuth\GmailOAuth;
|
||||
|
||||
Cache::forget('errorMessageIfNotAuthenticate');
|
||||
try {
|
||||
$header = "location:" . System::getServerMainPath() . "/setup/main?s=EMAIL_SERVER";
|
||||
|
||||
$validInput = empty($_GET['code']) || empty($_SESSION['gmailOAuth']) || !is_object($_SESSION['gmailOAuth']);
|
||||
if ($validInput) {
|
||||
G::header($header);
|
||||
return;
|
||||
}
|
||||
|
||||
$RBAC->allows(basename(__FILE__), "code");
|
||||
$gmailOAuth = $_SESSION['gmailOAuth'];
|
||||
|
||||
$googleClient = $gmailOAuth->getGoogleClient();
|
||||
$result = $googleClient->authenticate($_GET['code']);
|
||||
if (isset($result["error"])) {
|
||||
Cache::put('errorMessageIfNotAuthenticate', G::json_decode($result["error"]), 2);
|
||||
G::header($header);
|
||||
return;
|
||||
}
|
||||
|
||||
$gmailOAuth->setRefreshToken($googleClient->getRefreshToken());
|
||||
$gmailOAuth->saveEmailServer();
|
||||
$gmailOAuth->sendTestMailWithPHPMailerOAuth();
|
||||
} catch (Exception $e) {
|
||||
/**
|
||||
* The laravel cache is volatile in each session, you can specify the duration
|
||||
* value in minutes for each session. We use 2 minutes, enough time to retrieve
|
||||
* the error message if there is one.
|
||||
*/
|
||||
Cache::put('errorMessageIfNotAuthenticate', $e->getMessage(), 2);
|
||||
}
|
||||
|
||||
G::header($header);
|
||||
return;
|
||||
Reference in New Issue
Block a user