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:
Paula Quispe
2020-02-03 13:58:16 +00:00
committed by Julio Cesar Laura Avendaño
37 changed files with 2841 additions and 361 deletions

View File

@@ -51,6 +51,8 @@
"php-imap/php-imap": "^3.0",
"nikic/php-parser": "3.1.5",
"laravel/tinker": "^1.0",
"league/oauth2-client": "^2.4",
"league/oauth2-google": "^3.0",
"tecnickcom/tcpdf": "6.3.*"
},
"require-dev": {

126
composer.lock generated
View File

@@ -1393,6 +1393,124 @@
],
"time": "2020-01-04T16:30:31+00:00"
},
{
"name": "league/oauth2-client",
"version": "2.4.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/oauth2-client.git",
"reference": "cc114abc622a53af969e8664722e84ca36257530"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/cc114abc622a53af969e8664722e84ca36257530",
"reference": "cc114abc622a53af969e8664722e84ca36257530",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^6.0",
"paragonie/random_compat": "^1|^2|^9.99",
"php": "^5.6|^7.0"
},
"require-dev": {
"eloquent/liberator": "^2.0",
"eloquent/phony-phpunit": "^1.0|^3.0",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"phpunit/phpunit": "^5.7|^6.0",
"squizlabs/php_codesniffer": "^2.3|^3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-2.x": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"League\\OAuth2\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alex Bilbie",
"email": "hello@alexbilbie.com",
"homepage": "http://www.alexbilbie.com",
"role": "Developer"
},
{
"name": "Woody Gilk",
"homepage": "https://github.com/shadowhand",
"role": "Contributor"
}
],
"description": "OAuth 2.0 Client Library",
"keywords": [
"Authentication",
"SSO",
"authorization",
"identity",
"idp",
"oauth",
"oauth2",
"single sign on"
],
"time": "2018-11-22 18:33:57"
},
{
"name": "league/oauth2-google",
"version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/oauth2-google.git",
"reference": "3290273029f7cc2a468aae68bad184479a23b9d2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/oauth2-google/zipball/3290273029f7cc2a468aae68bad184479a23b9d2",
"reference": "3290273029f7cc2a468aae68bad184479a23b9d2",
"shasum": ""
},
"require": {
"league/oauth2-client": "^2.0"
},
"require-dev": {
"eloquent/phony-phpunit": "^2.0",
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^6.0",
"squizlabs/php_codesniffer": "^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"League\\OAuth2\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Woody Gilk",
"email": "woody.gilk@gmail.com",
"homepage": "http://shadowhand.me"
}
],
"description": "Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
"keywords": [
"Authentication",
"authorization",
"client",
"google",
"oauth",
"oauth2"
],
"time": "2018-12-28 16:18:33"
},
{
"name": "libchart/libchart",
"version": "1.4.0",
@@ -5727,8 +5845,8 @@
"authors": [
{
"name": "Sebastian Bergmann",
"role": "lead",
"email": "sb@sebastian-bergmann.de"
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
@@ -5995,8 +6113,8 @@
"authors": [
{
"name": "Sebastian Bergmann",
"role": "lead",
"email": "sebastian@phpunit.de"
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "The PHP Unit Testing framework.",

View File

@@ -0,0 +1,37 @@
<?php
use Faker\Generator as Faker;
$factory->define(\ProcessMaker\Model\AppMessage::class, function(Faker $faker) {
return [
'APP_MSG_UID' => G::generateUniqueID(),
'MSG_UID' => '',
'APP_UID' => function() {
return factory(\ProcessMaker\Model\Application::class)->create()->APP_UID;
},
'DEL_INDEX' => 1,
'APP_MSG_TYPE' => 'ROUTING',
'APP_MSG_TYPE_ID' => 0,
'APP_MSG_SUBJECT' => $faker->title,
'APP_MSG_FROM' => $faker->email,
'APP_MSG_TO' => $faker->email,
'APP_MSG_BODY' => $faker->text,
'APP_MSG_DATE' => $faker->dateTime(),
'APP_MSG_CC' => '',
'APP_MSG_BCC' => '',
'APP_MSG_TEMPLATE' => '',
'APP_MSG_STATUS' => 'pending',
'APP_MSG_STATUS_ID' => 1,
'APP_MSG_ATTACH' => '',
'APP_MSG_SEND_DATE' => $faker->dateTime(),
'APP_MSG_SHOW_MESSAGE' => 1,
'APP_MSG_ERROR' => '',
'PRO_ID' => function() {
return factory(\ProcessMaker\Model\Process::class)->create()->PRO_ID;
},
'TAS_ID' => function() {
return factory(\ProcessMaker\Model\Task::class)->create()->TAS_ID;
},
'APP_NUMBER' => 1
];
});

View File

@@ -5,7 +5,7 @@ use Faker\Generator as Faker;
$factory->define(\ProcessMaker\Model\EmailServerModel::class, function(Faker $faker) {
return [
'MESS_UID' => G::generateUniqueID(),
'MESS_ENGINE' => '',
'MESS_ENGINE' => 'MAIL',
'MESS_SERVER' => '',
'MESS_PORT' => 0,
'MESS_INCOMING_SERVER' => '',
@@ -19,5 +19,96 @@ $factory->define(\ProcessMaker\Model\EmailServerModel::class, function(Faker $fa
'MESS_TRY_SEND_INMEDIATLY' => 0,
'MAIL_TO' => '',
'MESS_DEFAULT' => 0,
'OAUTH_CLIENT_ID' => '',
'OAUTH_CLIENT_SECRET' => '',
'OAUTH_REFRESH_TOKEN' => ''
];
});
$factory->state(\ProcessMaker\Model\EmailServerModel::class, 'PHPMAILER', function ($faker) {
return [
'MESS_UID' => G::generateUniqueID(),
'MESS_ENGINE' => 'PHPMAILER',
'MESS_PORT' => $faker->numberBetween(400, 500),
'MESS_INCOMING_SERVER' => '',
'MESS_INCOMING_PORT' => 0,
'MESS_RAUTH' => 1,
'MESS_ACCOUNT' => $faker->email,
'MESS_PASSWORD' => $faker->password,
'MESS_FROM_MAIL' => $faker->email,
'MESS_FROM_NAME' => $faker->name,
'SMTPSECURE' => 'ssl',
'MESS_TRY_SEND_INMEDIATLY' => 0,
'MAIL_TO' => $faker->email,
'MESS_DEFAULT' => 0,
'OAUTH_CLIENT_ID' => '',
'OAUTH_CLIENT_SECRET' => '',
'OAUTH_REFRESH_TOKEN' => ''
];
});
$factory->state(\ProcessMaker\Model\EmailServerModel::class, 'IMAP', function ($faker) {
return [
'MESS_UID' => G::generateUniqueID(),
'MESS_ENGINE' => 'IMAP',
'MESS_PORT' => $faker->numberBetween(400, 500),
'MESS_INCOMING_SERVER' => 'imap.' . $faker->domainName,
'MESS_INCOMING_PORT' => $faker->numberBetween(400, 500),
'MESS_RAUTH' => 1,
'MESS_ACCOUNT' => $faker->email,
'MESS_PASSWORD' => $faker->password,
'MESS_FROM_MAIL' => $faker->email,
'MESS_FROM_NAME' => $faker->name,
'SMTPSECURE' => 'ssl',
'MESS_TRY_SEND_INMEDIATLY' => 0,
'MAIL_TO' => $faker->email,
'MESS_DEFAULT' => 0,
'OAUTH_CLIENT_ID' => '',
'OAUTH_CLIENT_SECRET' => '',
'OAUTH_REFRESH_TOKEN' => ''
];
});
$factory->state(\ProcessMaker\Model\EmailServerModel::class, 'GMAILAPI', function ($faker) {
return [
'MESS_UID' => G::generateUniqueID(),
'MESS_ENGINE' => 'GMAILAPI',
'MESS_PORT' => 0,
'MESS_INCOMING_SERVER' => '',
'MESS_INCOMING_PORT' => 0,
'MESS_RAUTH' => 1,
'MESS_ACCOUNT' => $faker->email,
'MESS_PASSWORD' => '',
'MESS_FROM_MAIL' => $faker->email,
'MESS_FROM_NAME' => $faker->name,
'SMTPSECURE' => 'No',
'MESS_TRY_SEND_INMEDIATLY' => 0,
'MAIL_TO' => $faker->email,
'MESS_DEFAULT' => 0,
'OAUTH_CLIENT_ID' => $faker->regexify("/[0-9]{12}-[a-z]{32}\.apps\.googleusercontent\.com/"),
'OAUTH_CLIENT_SECRET' => $faker->regexify("/[a-z]{24}/"),
'OAUTH_REFRESH_TOKEN' => $faker->regexify("/[a-z]{7}[a-zA-Z0-9]{355}==/")
];
});
$factory->state(\ProcessMaker\Model\EmailServerModel::class, 'OPENMAIL', function ($faker) {
return [
'MESS_UID' => G::generateUniqueID(),
'MESS_ENGINE' => 'OPENMAIL',
'MESS_PORT' => 0,
'MESS_INCOMING_SERVER' => '',
'MESS_INCOMING_PORT' => 0,
'MESS_RAUTH' => 1,
'MESS_ACCOUNT' => $faker->email,
'MESS_PASSWORD' => $faker->password,
'MESS_FROM_MAIL' => $faker->email,
'MESS_FROM_NAME' => $faker->name,
'SMTPSECURE' => 'ssl',
'MESS_TRY_SEND_INMEDIATLY' => 0,
'MAIL_TO' => $faker->email,
'MESS_DEFAULT' => 0,
'OAUTH_CLIENT_ID' => '',
'OAUTH_CLIENT_SECRET' => '',
'OAUTH_REFRESH_TOKEN' => ''
];
});

View File

@@ -633,7 +633,7 @@ class G
try {
$file = G::ExpandPath('skinEngine') . 'skinEngine.php';
include $file;
include_once $file;
$skinEngine = new SkinEngine($G_TEMPLATE, $G_SKIN, $G_CONTENT);
$skinEngine->setLayout($layout);
$skinEngine->dispatch();

View File

@@ -1,46 +1,7 @@
<?php
/**
* class.rbac.php
*
* @package gulliver.system
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
use ProcessMaker\Exception\RBACException;
/**
* File: $Id$
*
* RBAC class definition
*
* @package gulliver.system
*/
/**
* Clase Wrapper
*
* @package gulliver.system
*/
class RBAC
{
const ADMIN_USER_UID = '00000000000000000000000000000001';
@@ -180,7 +141,11 @@ class RBAC
'UPD' => ['PM_SETUP'],
'DEL' => ['PM_SETUP'],
'LST' => ['PM_SETUP'],
'TEST' => ['PM_SETUP']
'TEST' => ['PM_SETUP'],
'createAuthUrl' => ['PM_SETUP']
],
'emailServerGmailOAuth.php' => [
'code' => ['PM_SETUP']
],
'processes_GetFile.php' => [
'mailTemplates' => ['PM_FACTORY'],

View File

@@ -31,6 +31,7 @@
<directory suffix=".php">./gulliver</directory>
<directory suffix=".php">./workflow/engine/classes</directory>
<directory suffix=".php">./workflow/engine/src</directory>
<directory suffix=".php">./workflow/engine/methods/emailServer/</directory>
</whitelist>
<exclude>
<directory>./workflow/engine/classes/model/map</directory>

View File

@@ -0,0 +1,31 @@
<?php
namespace Tests\unit\gulliver\system;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use G;
use RBAC;
use Tests\TestCase;
class rbacTest extends TestCase
{
use DatabaseTransactions;
/**
* This tests the initialization of values.
* @test
* @covers \RBAC::__construct()
*/
public function it_should_initialize_properties_for_gmail_oauth()
{
$rbac = new RBAC();
$authorizedActions = $rbac->authorizedActions;
$this->assertArrayHasKey("emailServerGmailOAuth.php", $authorizedActions);
$subset = [
'code' => ['PM_SETUP']
];
$this->assertContains($subset, $authorizedActions);
}
}

View File

@@ -1,10 +1,14 @@
<?php
use Faker\Factory;
use Illuminate\Http\UploadedFile;
use ProcessMaker\Model\AppMessage;
use ProcessMaker\Model\EmailServerModel;
use Tests\TestCase;
class SpoolRunTest extends TestCase
{
/**
* Constructor of the class.
*/
@@ -16,7 +20,7 @@ class SpoolRunTest extends TestCase
/**
* Check if "envelope_cc" and "envelope_bcc" was set correctly in consecutive calls
*
* @covers SpoolRun::setData()
* @covers \SpoolRun::setData()
*
* @test
*/
@@ -30,14 +34,14 @@ class SpoolRunTest extends TestCase
// Set a first set of data
$spoolRun->setData(
G::generateUniqueID(),
$faker->words(3, true),
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
G::generateUniqueID(),
$faker->words(3, true),
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
// Build the "to", "cc" an "bcc" values
@@ -45,14 +49,14 @@ class SpoolRunTest extends TestCase
// Set a second set of data
$spoolRun->setData(
G::generateUniqueID(),
$faker->words(3, true),
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
G::generateUniqueID(),
$faker->words(3, true),
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
// Build the "to", "cc" an "bcc" values
@@ -66,4 +70,302 @@ class SpoolRunTest extends TestCase
$this->assertCount(1, $fileData['envelope_cc']);
$this->assertCount(1, $fileData['envelope_bcc']);
}
/**
* This test uses the GMAILAPI option in a simple way.
* @test
* @covers \SpoolRun::__construct()
* @covers \SpoolRun::setData()
* @covers \SpoolRun::setConfig()
* @covers \SpoolRun::sendMail()
* @covers \SpoolRun::handleMail()
*/
public function it_should_handle_gmail_oauth_option()
{
$appMsgUid = G::generateUniqueID();
factory(AppMessage::class)->create([
'APP_MSG_UID' => $appMsgUid
]);
$emailServer = factory(EmailServerModel::class)->states('GMAILAPI')->make();
$config = $emailServer->toArray();
$config['SMTPSecure'] = 'ssl';
$faker = Factory::create();
$spoolRun = new SpoolRun();
$spoolRun->setData(
$appMsgUid,
$faker->title,
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
$spoolRun->setConfig($config);
$expected = $spoolRun->sendMail();
$this->assertTrue($expected);
}
/**
* This test uses the MAIL option in a simple way.
* @test
* @covers \SpoolRun::__construct()
* @covers \SpoolRun::setData()
* @covers \SpoolRun::setConfig()
* @covers \SpoolRun::sendMail()
* @covers \SpoolRun::handleMail()
*/
public function it_should_handle_mail_option()
{
$appMsgUid = G::generateUniqueID();
factory(AppMessage::class)->create([
'APP_MSG_UID' => $appMsgUid
]);
$emailServer = factory(EmailServerModel::class)->create();
$config = $emailServer->toArray();
$faker = Factory::create();
$spoolRun = new SpoolRun();
$spoolRun->setData(
$appMsgUid,
$faker->title,
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
$spoolRun->setConfig($config);
$expected = $spoolRun->sendMail();
$this->assertTrue($expected);
}
/**
* This test uses the PHPMAILER option in a simple way.
* @test
* @covers \SpoolRun::__construct()
* @covers \SpoolRun::setData()
* @covers \SpoolRun::setConfig()
* @covers \SpoolRun::sendMail()
* @covers \SpoolRun::handleMail()
*/
public function it_should_handle_php_mailer_option()
{
$appMsgUid = G::generateUniqueID();
factory(AppMessage::class)->create([
'APP_MSG_UID' => $appMsgUid
]);
$emailServer = factory(EmailServerModel::class)->states('PHPMAILER')->make();
$config = $emailServer->toArray();
$config['SMTPSecure'] = 'ssl';
$faker = Factory::create();
$spoolRun = new SpoolRun();
$spoolRun->setData(
$appMsgUid,
$faker->title,
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
$spoolRun->setConfig($config);
$expected = $spoolRun->sendMail();
$this->assertTrue($expected);
}
/**
* This test uses the OPENMAIL option in a simple way.
* @test
* @covers \SpoolRun::__construct()
* @covers \SpoolRun::setData()
* @covers \SpoolRun::setConfig()
* @covers \SpoolRun::sendMail()
* @covers \SpoolRun::handleMail()
*/
public function it_should_handle_open_mail_option()
{
$this->markTestIncomplete("The OPENMAIL depends on the package class but this is not found in the environment.");
$appMsgUid = G::generateUniqueID();
factory(AppMessage::class)->create([
'APP_MSG_UID' => $appMsgUid
]);
$emailServer = factory(EmailServerModel::class)->states('OPENMAIL')->make();
$config = $emailServer->toArray();
$faker = Factory::create();
$spoolRun = new SpoolRun();
$spoolRun->setData(
$appMsgUid,
$faker->title,
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
$spoolRun->setConfig($config);
$expected = $spoolRun->sendMail();
$this->assertTrue($expected);
}
/**
* This test ensures that characters that are not utf8 are converted properly,
* for subject and body fields.
* @test
* @covers \SpoolRun::__construct()
* @covers \SpoolRun::setData()
* @covers \SpoolRun::setConfig()
* @covers \SpoolRun::sendMail()
* @covers \SpoolRun::handleMail()
*/
public function it_should_handle_utf8_characters()
{
$appMsgUid = G::generateUniqueID();
factory(AppMessage::class)->create([
'APP_MSG_UID' => $appMsgUid
]);
$emailServer = factory(EmailServerModel::class)->states('PHPMAILER')->make();
$config = $emailServer->toArray();
$config['SMTPSecure'] = 'ssl';
$faker = Factory::create();
$subject = "\xf8foo";
$body = "\xf8foo\xf8foo";
$spoolRun = new SpoolRun();
$spoolRun->setData(
$appMsgUid,
$subject,
$faker->companyEmail,
$faker->freeEmail,
$body,
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
$spoolRun->setConfig($config);
$expected = $spoolRun->sendMail();
$this->assertTrue($expected);
}
/**
* This test verifies the sending of attachments to the email.
* @test
* @covers \SpoolRun::__construct()
* @covers \SpoolRun::setData()
* @covers \SpoolRun::setConfig()
* @covers \SpoolRun::sendMail()
* @covers \SpoolRun::handleMail()
*/
public function it_should_handle_attachment_files()
{
$appMsgUid = G::generateUniqueID();
factory(AppMessage::class)->create([
'APP_MSG_UID' => $appMsgUid
]);
$emailServer = factory(EmailServerModel::class)->states('PHPMAILER')->make();
$config = $emailServer->toArray();
$config['SMTPSecure'] = 'ssl';
$faker = Factory::create();
$file1 = UploadedFile::fake()->image('avatar.jpg', 400, 300);
$file2 = UploadedFile::fake()->create('document.pdf', 200);
$files = [
$file1->path(),
$file2->path()
];
$spoolRun = new SpoolRun();
$spoolRun->setData(
$appMsgUid,
$faker->title,
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail,
'',
$files
);
$spoolRun->setConfig($config);
$expected = $spoolRun->sendMail();
$this->assertTrue($expected);
}
/**
* This test ensures that the EnvelopeTo field process is working.
* @test
* @covers \SpoolRun::__construct()
* @covers \SpoolRun::setData()
* @covers \SpoolRun::runHandleEnvelopeTo()
* @covers \SpoolRun::handleEnvelopeTo()
* @covers \SpoolRun::setConfig()
* @covers \SpoolRun::sendMail()
* @covers \SpoolRun::handleMail()
*/
public function it_should_handle_envelope_to()
{
$appMsgUid = G::generateUniqueID();
factory(AppMessage::class)->create([
'APP_MSG_UID' => $appMsgUid
]);
$emailServer = factory(EmailServerModel::class)->states('PHPMAILER')->make();
$config = $emailServer->toArray();
$config['SMTPSecure'] = 'ssl';
$faker = Factory::create();
$spoolRun = new SpoolRun();
$spoolRun->setData(
$appMsgUid,
$faker->title,
$faker->name . "<" . $faker->companyEmail . "," . $faker->companyEmail . ">",
$faker->name . "<" . $faker->freeEmail . "," . $faker->freeEmail . ">",
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->name . "<" . $faker->companyEmail . "," . $faker->companyEmail . ">",
$faker->name . "<" . $faker->freeEmail . "," . $faker->freeEmail . ">"
);
$spoolRun->runHandleEnvelopeTo();
$spoolRun->setConfig($config);
$expected = $spoolRun->sendMail();
$this->assertTrue($expected);
}
}

View File

@@ -10,6 +10,7 @@ use ProcessMaker\Model\EmailServerModel;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
use ProcessMaker\Util\WsMessageResponse;
use Tests\TestCase;
class WsBaseTest extends TestCase
@@ -484,48 +485,48 @@ class WsBaseTest extends TestCase
//Create the application factory
$application1 = factory(Application::class)->create(
[
'APP_STATUS' => 'TO_DO',
'APP_TITLE' => 'Title1'
]
[
'APP_STATUS' => 'TO_DO',
'APP_TITLE' => 'Title1'
]
);
$application2 = factory(Application::class)->create(
[
'APP_STATUS' => 'DRAFT',
'APP_TITLE' => 'Title2'
]
[
'APP_STATUS' => 'DRAFT',
'APP_TITLE' => 'Title2'
]
);
//Create the delegation factory
$delegation1 = factory(Delegation::class)->create(
[
'USR_UID' => $user->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application1->APP_NUMBER
]
[
'USR_UID' => $user->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application1->APP_NUMBER
]
);
$delegation2 = factory(Delegation::class)->create(
[
'USR_UID' => $user->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application2->APP_NUMBER
]
[
'USR_UID' => $user->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application2->APP_NUMBER
]
);
//Create app thread factory
factory(AppThread::class)->create(
[
'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation1->APP_UID
]
[
'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation1->APP_UID
]
);
factory(AppThread::class)->create(
[
'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation2->APP_UID
]
[
'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation2->APP_UID
]
);
//Instance the object
@@ -559,48 +560,48 @@ class WsBaseTest extends TestCase
//Create the application factory
$application1 = factory(Application::class)->create(
[
'APP_STATUS' => 'TO_DO',
'APP_TITLE' => 'Title1'
]
[
'APP_STATUS' => 'TO_DO',
'APP_TITLE' => 'Title1'
]
);
$application2 = factory(Application::class)->create(
[
'APP_STATUS' => 'DRAFT',
'APP_TITLE' => 'Title2'
]
[
'APP_STATUS' => 'DRAFT',
'APP_TITLE' => 'Title2'
]
);
//Create the delegation factory
$delegation1 = factory(Delegation::class)->create(
[
'USR_UID' => $user1->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application1->APP_NUMBER
]
[
'USR_UID' => $user1->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application1->APP_NUMBER
]
);
$delegation2 = factory(Delegation::class)->create(
[
'USR_UID' => $user1->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application2->APP_NUMBER
]
[
'USR_UID' => $user1->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application2->APP_NUMBER
]
);
//Create app thread factory
factory(AppThread::class)->create(
[
'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation1->APP_UID
]
[
'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation1->APP_UID
]
);
factory(AppThread::class)->create(
[
'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation2->APP_UID
]
[
'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation2->APP_UID
]
);
//Instance the object
@@ -612,4 +613,36 @@ class WsBaseTest extends TestCase
//Assert the result his empty
$this->assertEmpty($res);
}
/**
* This test ensures obtaining the email configuration with all fields.
* @test
* @covers \WsBase::sendMessage()
*/
public function it_should_get_email_configuration()
{
$faker = Factory::create();
//data
$case = $this->createNewCase();
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$from = $faker->email;
$to = "";
$cc = "";
$bcc = "";
$subject = $faker->title;
$templateName = basename($template->PRF_PATH);
$appFields = [
'var1' => $faker->numberBetween(1, 100)
];
$wsBase = new WsBase();
$result = $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields);
//assertions
$this->assertInstanceOf(WsMessageResponse::class, $result);
}
}

View File

@@ -0,0 +1,208 @@
<?php
namespace Tests\unit\workflow\engine\methods\emailServer;
use Faker\Factory;
use ProcessMaker\Model\EmailServerModel;
use ProcessMaker\Model\User;
use RBAC;
use Tests\TestCase;
class EmailServerAjaxTest extends TestCase
{
/**
* This set initial parameters for each test.
*/
public function setUp()
{
parent::setUp();
$this->settingUserLogged();
}
/**
* This starts a valid user in session with the appropriate permissions.
* @global object $RBAC
*/
private function settingUserLogged()
{
global $RBAC;
$user = User::where('USR_ID', '=', 1)
->get()
->first();
$_SESSION['USER_LOGGED'] = $user['USR_UID'];
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
$RBAC->initRBAC();
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
}
/**
* This allows multiple calls to the require_once statement, use the original
* content by creating several documents in the temporary folder.
* @global object $RBAC
* @return string
*/
private function requireOnceForEmailServerAjax(): string
{
$fileName = PATH_METHODS . 'emailServer/emailServerAjax.php';
$tempFile = tempnam(sys_get_temp_dir(), basename($fileName, '.php'));
if ($tempFile !== false) {
file_put_contents($tempFile, file_get_contents($fileName));
global $RBAC;
$RBAC->authorizedActions[basename($tempFile)] = [
'INS' => ['PM_SETUP'],
'UPD' => ['PM_SETUP'],
'DEL' => ['PM_SETUP'],
'LST' => ['PM_SETUP'],
'TEST' => ['PM_SETUP'],
'createAuthUrl' => ['PM_SETUP']
];
ob_start();
require_once $tempFile;
return ob_get_clean();
}
return "";
}
/**
* This tests the createAuthUrl option at the endpoint emailServerAjax.php.
* @test
*/
public function it_should_verify_the_option_create_auth_url()
{
$faker = Factory::create();
$post = [
'option' => 'createAuthUrl',
'clientID' => $faker->regexify('[0-9]{12}\-[a-zA-Z]{20}'),
'clientSecret' => $faker->regexify('[a-zA-Z]{10}'),
'emailEngine' => 'GMAILAPI',
'fromAccount' => $faker->email,
'senderEmail' => $faker->email,
'senderName' => $faker->name,
'sendTestMail' => 1,
'mailTo' => $faker->email,
'setDefaultConfiguration' => 1
];
$_POST = array_merge($_POST, $post);
$content = $this->requireOnceForEmailServerAjax();
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
$this->assertContains(200, $data);
}
/**
* This tests the INS option at the endpoint emailServerAjax.php.
* @test
*/
public function it_should_verify_the_option_ins()
{
$faker = Factory::create();
$post = [
'option' => 'INS',
'cboEmailEngine' => 'PHPMAILER',
'server' => 'smtp.gmail.com',
'port' => '465',
'incomingServer' => '',
'incomingPort' => '',
'reqAuthentication' => 1,
'accountFrom' => $faker->email,
'password' => $faker->password,
'fromMail' => $faker->email,
'fromName' => $faker->name,
'smtpSecure' => 'ssl',
'sendTestMail' => 1,
'mailTo' => $faker->email,
'emailServerDefault' => 1,
];
$_POST = array_merge($_POST, $post);
$content = $this->requireOnceForEmailServerAjax();
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
$this->assertContains("OK", $data);
}
/**
* This tests the UPD option at the endpoint emailServerAjax.php.
* @test
*/
public function it_should_verify_the_option_upd()
{
$faker = Factory::create();
$emailServer = factory(EmailServerModel::class)->create([
'MESS_ENGINE' => 'PHPMAILER',
]);
$post = [
'option' => 'UPD',
'emailServerUid' => $emailServer->MESS_UID,
'cboEmailEngine' => 'PHPMAILER',
'server' => 'smtp.gmail.com',
'port' => '465',
'incomingServer' => '',
'incomingPort' => '',
'reqAuthentication' => 1,
'accountFrom' => $faker->email,
'password' => $faker->password,
'fromMail' => $faker->email,
'fromName' => $faker->name,
'smtpSecure' => 'ssl',
'sendTestMail' => 1,
'mailTo' => $faker->email,
'emailServerDefault' => 1,
];
$_POST = array_merge($_POST, $post);
$content = $this->requireOnceForEmailServerAjax();
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
$this->assertContains("OK", $data);
}
/**
* This tests the DEL option at the endpoint emailServerAjax.php.
* @test
*/
public function it_should_verify_the_option_del()
{
$emailServer = factory(EmailServerModel::class)->create([
'MESS_ENGINE' => 'PHPMAILER',
]);
$post = [
'option' => 'DEL',
'emailServerUid' => $emailServer->MESS_UID
];
$_POST = array_merge($_POST, $post);
$content = $this->requireOnceForEmailServerAjax();
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
$this->assertContains("OK", $data);
}
/**
* This tests the LST option at the endpoint emailServerAjax.php.
* @test
*/
public function it_should_verify_the_option_lst()
{
$post = [
'option' => 'LST',
'pageSize' => 25,
'search' => ''
];
$_POST = array_merge($_POST, $post);
$content = $this->requireOnceForEmailServerAjax();
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
$this->assertContains("OK", $data);
$this->assertTrue(isset($data["resultRoot"]));
$this->assertTrue(is_array($data["resultRoot"]));
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Tests\unit\workflow\engine\methods\emailServer;
use Faker\Factory;
use Google_Auth_Exception;
use Illuminate\Support\Facades\Cache;
use ProcessMaker\GmailOAuth\GmailOAuth;
use ProcessMaker\Model\User;
use RBAC;
use Tests\TestCase;
class EmailServerGmailOAuthTest extends TestCase
{
/**
* This test expects an error message stored in the cache.
* The Google client requires valid codes to obtain the clientId from a request,
* otherwise it will throw an exception.
* @test
*/
public function it_should_try_to_authenticate_on_google_oauth_with_a_fake_code()
{
$faker = Factory::create();
global $RBAC;
$user = User::where('USR_ID', '=', 1)
->get()
->first();
$_SESSION['USER_LOGGED'] = $user['USR_UID'];
$_POST['USR_UID'] = $user['USR_UID'];
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
$RBAC->initRBAC();
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
$_SESSION['gmailOAuth'] = new GmailOAuth();
/**
* This gets a fake code, according to the nomenclature.
*/
$_GET['code'] = $faker->regexify("/[1-9]\/[a-zA-Z]{25}-[a-zA-Z]{16}_[a-zA-Z]{19}-[a-zA-Z]{24}/");
require_once PATH_METHODS . 'emailServer/emailServerGmailOAuth.php';
$this->assertTrue(Cache::has('errorMessageIfNotAuthenticate'));
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Tests\unit\workflow\engine\methods\emailServer;
use ProcessMaker\Model\User;
use RBAC;
use Tests\TestCase;
class EmailServerTest extends TestCase
{
/**
* This test ensures that the script output generates the javascript variable
* EMAILSERVER_LICENSED.
* @test
*/
public function it_should_verify_the_script_output_contains_javascript_variable()
{
global $RBAC;
$user = User::where('USR_ID', '=', 1)
->get()
->first();
$_SESSION['USER_LOGGED'] = $user['USR_UID'];
$_POST['USR_UID'] = $user['USR_UID'];
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
$RBAC->initRBAC();
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
ob_start();
require_once PATH_METHODS . 'emailServer/emailServer.php';
$content = ob_get_clean();
$this->assertContains("EMAILSERVER_LICENSED", $content);
}
}

View File

@@ -0,0 +1,253 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel;
use Exception;
use Faker\Factory;
use G;
use ProcessMaker\BusinessModel\EmailServer;
use ProcessMaker\Model\EmailServerModel;
use Tests\TestCase;
class EmailServerTest extends TestCase
{
private $emailServer;
private $faker;
/**
* set up function.
*/
public function setUp()
{
parent::setUp();
$this->emailServer = new EmailServer();
$this->faker = Factory::create();
}
/**
* Get structure for registry the EMAIL_SERVER.
* @return array
*/
private function getDataForEmailServerRegistry(): array
{
$faker = $this->faker;
return [
'MESS_ENGINE' => 'PHPMAILER',
'MESS_SERVER' => 'smtp.' . $faker->domainName,
'MESS_PORT' => $faker->numberBetween(400, 500),
'MESS_INCOMING_SERVER' => '',
'MESS_INCOMING_PORT' => $faker->numberBetween(400, 500),
'MESS_RAUTH' => 1,
'MESS_ACCOUNT' => $faker->email,
'MESS_PASSWORD' => $faker->password,
'MESS_FROM_MAIL' => $faker->email,
'MESS_FROM_NAME' => $faker->name,
'SMTPSECURE' => 'ssl',
'MESS_TRY_SEND_INMEDIATLY' => 1,
'MAIL_TO' => $faker->email,
'MESS_DEFAULT' => 1,
'OAUTH_CLIENT_ID' => '',
'OAUTH_CLIENT_SECRET' => '',
'OAUTH_REFRESH_TOKEN' => '',
];
}
/**
* This creates a record in the EMAIL_SERVER table.
* @test
* @covers \ProcessMaker\BusinessModel\EmailServer::create()
*/
public function it_should_create()
{
$faker = $this->faker;
$expected = $this->getDataForEmailServerRegistry();
$this->emailServer->setContextLog([
'workspace' => 'workflow'
]);
$actual = $this->emailServer->create($expected);
$this->assertTrue(isset($actual['MESS_UID']));
$this->assertTrue(is_string($actual['MESS_UID']));
$this->assertEquals($expected['MESS_ENGINE'], $actual['MESS_ENGINE']);
$this->assertEquals($expected['MESS_ACCOUNT'], $actual['MESS_ACCOUNT']);
$expected['MESS_PASSWORD'] = G::encrypt('hash:' . $faker->password, 'EMAILENCRYPT');
$actual = $this->emailServer->create($expected);
$expected['MESS_PASSWORD'] = G::encrypt('hash:' . $faker->password . 'hash:', 'EMAILENCRYPT');
$actual = $this->emailServer->create($expected);
$this->expectException(Exception::class);
$this->emailServer->create([]);
}
/**
* This updates a record in the EMAIL_SERVER table.
* @test
* @covers \ProcessMaker\BusinessModel\EmailServer::update()
*/
public function it_should_update()
{
$faker = $this->faker;
$emailServer = factory(EmailServerModel::class)->create($this->getDataForEmailServerRegistry());
$data = $emailServer->toArray();
$this->emailServer->setContextLog([
'workspace' => 'workflow'
]);
$expected = [
'MESS_ENGINE' => 'PHPMAILER',
'MESS_SERVER' => 'smtp.' . $faker->domainName,
'MESS_PORT' => $faker->numberBetween(400, 500),
'MESS_INCOMING_SERVER' => '',
'MESS_INCOMING_PORT' => $faker->numberBetween(400, 500),
'MESS_RAUTH' => 1,
'MESS_ACCOUNT' => $faker->email,
'MESS_PASSWORD' => $faker->password,
'MESS_FROM_MAIL' => $faker->email,
'MESS_FROM_NAME' => $faker->name,
'SMTPSECURE' => 'ssl',
'MESS_TRY_SEND_INMEDIATLY' => 1,
'MAIL_TO' => $faker->email,
'MESS_DEFAULT' => 1,
];
$actual = $this->emailServer->update($data['MESS_UID'], $expected);
$this->assertEquals($expected['MESS_ENGINE'], $actual['MESS_ENGINE']);
$this->assertEquals($expected['MESS_ACCOUNT'], $actual['MESS_ACCOUNT']);
$expected['MESS_PASSWORD'] = G::encrypt('hash:' . $faker->password, 'EMAILENCRYPT');
$actual = $this->emailServer->update($data['MESS_UID'], $expected);
$expected['MESS_PASSWORD'] = G::encrypt('hash:' . $faker->password . 'hash:', 'EMAILENCRYPT');
$actual = $this->emailServer->update($data['MESS_UID'], $expected);
$this->emailServer->setFormatFieldNameInUppercase(false);
$this->expectException(Exception::class);
$actual = $this->emailServer->update($data['MESS_UID'], $expected);
}
/**
* Get data of a from a record EMAIL_SERVER.
* @test
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServerDataFromRecord()
*/
public function it_should_get_email_server_data_from_record()
{
$faker = $this->faker;
$this->emailServer->setContextLog([
'workspace' => 'workflow'
]);
$expected = $this->getDataForEmailServerRegistry();
$expected['MESS_UID'] = $faker->regexify("/[a-zA-Z]{32}/");
$actual = $this->emailServer->getEmailServerDataFromRecord($expected);
$this->assertEquals($expected['MESS_ENGINE'], $actual['MESS_ENGINE']);
$this->assertEquals($expected['MESS_ACCOUNT'], $actual['MESS_ACCOUNT']);
unset($expected['MESS_ENGINE']);
$this->expectException(Exception::class);
$actual = $this->emailServer->getEmailServerDataFromRecord($expected);
}
/**
* This test obtains the configuration record that is marked by default.
* @test
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServerDefault()
*/
public function it_should_get_email_server_default()
{
$this->emailServer->setContextLog([
'workspace' => 'workflow'
]);
$actual = $this->emailServer->getEmailServerDefault();
$this->assertNotEmpty($actual);
}
/**
* This test gets the records from the "EMAIL_SERVER" table.
* @test
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServers()
*/
public function it_should_get_email_servers()
{
$this->emailServer->setContextLog([
'workspace' => 'workflow'
]);
$actual = $this->emailServer->getEmailServers();
$this->assertNotEmpty($actual);
}
/**
* This test gets the records from the "EMAIL_SERVER" table with parameters.
* @test
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServers()
*/
public function it_should_get_email_servers_with_parameters()
{
$this->emailServer->setContextLog([
'workspace' => 'workflow'
]);
$actual = $this->emailServer->getEmailServers(null, null, null, null, 0);
$this->assertEmpty($actual);
$faker = $this->faker;
$actual = $this->emailServer->getEmailServers(['filter' => $faker->text]);
$this->assertNotEmpty($actual);
$actual = $this->emailServer->getEmailServers(null, $faker->text);
$this->assertNotEmpty($actual);
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER");
$this->assertNotEmpty($actual);
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER", "DESC");
$this->assertNotEmpty($actual);
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER", "DESC", 0);
$this->assertNotEmpty($actual);
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER", "DESC", 0, 10);
$this->assertNotEmpty($actual);
$this->expectException(Exception::class);
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER", "DESC", -1, -10);
}
/**
* This test gets a record of the EMAIL_SERVER table.
* @test
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServer()
*/
public function it_should_get_email_server()
{
$this->emailServer->setContextLog([
'workspace' => 'workflow'
]);
$emailServer = factory(EmailServerModel::class)->create($this->getDataForEmailServerRegistry());
$emailServerUid = $emailServer->MESS_UID;
$actual = $this->emailServer->getEmailServer($emailServerUid);
$this->assertNotEmpty($actual);
}
/**
* This test should throw an exception when a record is not found.
* @test
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServer()
*/
public function it_should_get_email_server_when_not_exist_registry()
{
$faker = $this->faker;
$this->emailServer->setContextLog([
'workspace' => 'workflow'
]);
$emailServer = factory(EmailServerModel::class)->create($this->getDataForEmailServerRegistry());
$emailServerUid = $faker->regexify("/[a-zA-Z]{32}/");
$this->expectException(Exception::class);
$actual = $this->emailServer->getEmailServer($emailServerUid);
}
}

View File

@@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Core;
use G;
use Faker\Factory;
use ProcessMaker\Core\System;
use ProcessMaker\Model\EmailServerModel;
use Tests\TestCase;
class SystemTest extends TestCase
@@ -19,9 +20,9 @@ class SystemTest extends TestCase
}
/**
* It tests the initLaravel method
*
* It tests the initLaravel method.
* @test
* @covers \ProcessMaker\Core\System::initLaravel()
*/
public function it_should_init_laravel_configurations()
{
@@ -37,6 +38,32 @@ class SystemTest extends TestCase
$this->assertEquals(DB_PASS, config('database.connections.workflow.password'));
}
/**
* This gets the settings for sending email.
* @test
* @covers \ProcessMaker\Core\System::getEmailConfiguration()
*/
public function it_should_get_email_configuration()
{
$system = new System();
//default values
EmailServerModel::truncate();
$actual = $system->getEmailConfiguration();
$this->assertEmpty($actual);
//new instance
$emailServer = factory(EmailServerModel::class)->create([
'MESS_DEFAULT' => 1
]);
$actual = $system->getEmailConfiguration();
$this->assertNotEmpty($actual);
$this->assertArrayHasKey('MESS_ENGINE', $actual);
$this->assertArrayHasKey('OAUTH_CLIENT_ID', $actual);
$this->assertArrayHasKey('OAUTH_CLIENT_SECRET', $actual);
$this->assertArrayHasKey('OAUTH_REFRESH_TOKEN', $actual);
}
/**
* It should return default system configuration parameters.
* @test

View File

@@ -0,0 +1,333 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\GmailOAuth;
use Exception;
use Faker\Factory;
use Google_Client;
use Google_Service_Gmail_Message;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPMailerOAuth;
use ProcessMaker\GmailOAuth\GmailOAuth;
use RBAC;
use Tests\TestCase;
class GmailOAuthTest extends TestCase
{
use DatabaseTransactions;
private $faker;
/**
* Init properties
*/
public function setUp()
{
parent::setUp();
$this->faker = Factory::create();
global $RBAC;
$RBAC = RBAC::getSingleton();
$RBAC->initRBAC();
}
/**
* This ensures that the properties of the GmailOAuth object have consistency.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setEmailServerUid()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setEmailEngine()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setClientID()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setClientSecret()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setRedirectURI()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setEmailEngine()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setFromAccount()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setSenderEmail()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setSenderName()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setSendTestMail()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setMailTo()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setSetDefaultConfiguration()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setRefreshToken()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getEmailServerUid()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getClientID()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getClientSecret()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getRedirectURI()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getEmailEngine()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getFromAccount()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getSenderEmail()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getSenderName()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getSendTestMail()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getMailTo()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getSetDefaultConfiguration()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getRefreshToken()
*/
public function it_should_set_and_get_properties()
{
$faker = $this->faker;
$expected = $faker->word;
$digit = $faker->randomDigitNotNull;
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setEmailServerUid($expected);
$actual = $gmailOAuth->getEmailServerUid();
$this->assertEquals($expected, $actual);
$gmailOAuth->setClientID($expected);
$actual = $gmailOAuth->getClientID();
$this->assertEquals($expected, $actual);
$gmailOAuth->setClientSecret($expected);
$actual = $gmailOAuth->getClientSecret();
$this->assertEquals($expected, $actual);
$gmailOAuth->setRedirectURI($expected);
$actual = $gmailOAuth->getRedirectURI();
$this->assertEquals($expected, $actual);
$gmailOAuth->setEmailEngine($expected);
$actual = $gmailOAuth->getEmailEngine();
$this->assertEquals($expected, $actual);
$gmailOAuth->setFromAccount($expected);
$actual = $gmailOAuth->getFromAccount();
$this->assertEquals($expected, $actual);
$gmailOAuth->setSenderEmail($expected);
$actual = $gmailOAuth->getSenderEmail();
$this->assertEquals($expected, $actual);
$gmailOAuth->setSenderName($expected);
$actual = $gmailOAuth->getSenderName();
$this->assertEquals($expected, $actual);
$gmailOAuth->setSendTestMail($expected);
$actual = $gmailOAuth->getSendTestMail();
$this->assertEquals($expected, $actual);
$gmailOAuth->setMailTo($expected);
$actual = $gmailOAuth->getMailTo();
$this->assertEquals($expected, $actual);
$gmailOAuth->setSetDefaultConfiguration($expected);
$actual = $gmailOAuth->getSetDefaultConfiguration();
$this->assertEquals($expected, $actual);
$gmailOAuth->setRefreshToken($expected);
$actual = $gmailOAuth->getRefreshToken();
$this->assertEquals($expected, $actual);
}
/**
* Obtenga una instancia de Google_Client.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getGoogleClient()
*/
public function it_should_()
{
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setClientID("");
$gmailOAuth->setClientSecret("");
$gmailOAuth->setRedirectURI("");
$googleClient = $gmailOAuth->getGoogleClient();
$this->assertTrue($googleClient instanceof Google_Client);
}
/**
* Create Email Server data.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::saveEmailServer()
*/
public function it_should_create_email_server()
{
$this->markTestIncomplete("It required valid workspace");
$faker = $this->faker;
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setEmailEngine("GMAILAPI");
$gmailOAuth->setClientID($faker->uuid);
$gmailOAuth->setClientSecret($faker->uuid);
$gmailOAuth->setRefreshToken($faker->uuid);
$gmailOAuth->setFromAccount($faker->email);
$gmailOAuth->setSenderEmail(1);
$gmailOAuth->setSenderName($faker->word);
$gmailOAuth->setSendTestMail(1);
$gmailOAuth->setMailTo($faker->email);
$gmailOAuth->setSetDefaultConfiguration(0);
$this->expectException(Exception::class);
$result = $gmailOAuth->saveEmailServer();
}
/**
* Update Email Server data.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::saveEmailServer()
*/
public function it_should_udpate_email_server()
{
$this->markTestIncomplete("It required valid workspace");
$faker = $this->faker;
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setEmailServerUid($faker->uuid);
$gmailOAuth->setEmailEngine("GMAILAPI");
$gmailOAuth->setClientID($faker->uuid);
$gmailOAuth->setClientSecret($faker->uuid);
$gmailOAuth->setRefreshToken($faker->uuid);
$gmailOAuth->setFromAccount($faker->email);
$gmailOAuth->setSenderEmail(1);
$gmailOAuth->setSenderName($faker->word);
$gmailOAuth->setSendTestMail(1);
$gmailOAuth->setMailTo($faker->email);
$gmailOAuth->setSetDefaultConfiguration(0);
$this->expectException(Exception::class);
$result = $gmailOAuth->saveEmailServer();
}
/**
* This ensures proof of email delivery with Google_Service_Gmail.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::sendTestEmailWithGoogleServiceGmail()
*/
public function it_should_send_an_email_test_with_google_service_gmail()
{
$faker = $this->faker;
$gmailOauth = new GmailOAuth();
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
$this->assertTrue($result instanceof Google_Service_Gmail_Message);
$gmailOauth->setFromAccount($faker->email);
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
$this->assertTrue($result instanceof Google_Service_Gmail_Message);
$gmailOauth->setSenderEmail($faker->email);
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
$this->assertTrue($result instanceof Google_Service_Gmail_Message);
$gmailOauth->setMailTo($faker->email);
$gmailOauth->setSendTestMail(0);
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
$this->assertTrue($result instanceof Google_Service_Gmail_Message);
$this->expectException(Exception::class);
$gmailOauth->setSendTestMail(1);
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
}
/**
* This test ensures that the message body for the email test.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getRawMessage()
*/
public function it_should_get_raw_message_for_test_email()
{
$gmailOAuth = new GmailOAuth();
$result = $gmailOAuth->getRawMessage();
$this->assertTrue(is_string($result));
}
/**
* This ensures proof of email delivery with PHPMailerOAuth.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::sendTestMailWithPHPMailerOAuth()
*/
public function it_should_send_an_email_test_with_PHPMailerOAuth()
{
$faker = $this->faker;
$gmailOauth = new GmailOAuth();
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
$gmailOauth->setFromAccount($faker->email);
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
$gmailOauth->setSenderEmail($faker->email);
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
$gmailOauth->setMailTo($faker->email);
$gmailOauth->setSendTestMail(0);
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
$this->expectException(Exception::class);
$gmailOauth->setSenderEmail("");
$gmailOauth->setMailTo($faker->email);
$gmailOauth->setSendTestMail(1);
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
}
/**
* This ensures proof of get message body.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getMessageBody()
*/
public function it_should_get_message_body()
{
$gmailOauth = new GmailOAuth();
$result = $gmailOauth->getMessageBody();
$this->assertTrue(is_string($result));
}
/**
* This ensures that it is saved in the APP_MESSAGE table.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::saveIntoAppMessage()
*/
public function it_should_save_into_app_message_table()
{
$faker = $this->faker;
$gmailOauth = new GmailOAuth();
$gmailOauth->setFromAccount($faker->email);
$gmailOauth->setSenderEmail($faker->email);
$gmailOauth->setMailTo($faker->email);
try {
$gmailOauth->saveIntoAppMessage("pending");
} catch (Exception $e) {
$this->fail($e->getMessage());
}
$this->assertTrue(true);
try {
$gmailOauth->saveIntoAppMessage("sent");
} catch (Exception $e) {
$this->fail($e->getMessage());
}
$this->assertTrue(true);
}
/**
* This ensures that it is saved in the Standard Log table.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::saveIntoStandardLogs()
*/
public function it_should_save_into_standard_log()
{
$faker = $this->faker;
$gmailOauth = new GmailOAuth();
$gmailOauth->setFromAccount($faker->email);
$gmailOauth->setSenderEmail($faker->email);
$gmailOauth->setMailTo($faker->email);
try {
$gmailOauth->saveIntoStandardLogs("pending");
} catch (Exception $e) {
$this->fail($e->getMessage());
}
$this->assertTrue(true);
try {
$gmailOauth->saveIntoStandardLogs("sent");
} catch (Exception $e) {
$this->fail($e->getMessage());
}
$this->assertTrue(true);
}
}

View File

@@ -510,6 +510,7 @@ class SpoolRun
case 'MAIL':
case 'PHPMAILER':
case 'IMAP':
case 'GMAILAPI':
switch ($this->config['MESS_ENGINE']) {
case 'MAIL':
$phpMailer = new PHPMailer();
@@ -520,6 +521,11 @@ class SpoolRun
$phpMailer = new PHPMailer(true);
$phpMailer->Mailer = 'smtp';
break;
case 'GMAILAPI':
$phpMailer = new PHPMailerOAuth();
$phpMailer->AuthType = 'XOAUTH2';
$phpMailer->isSMTP();
break;
}
$phpMailer->SMTPAuth = (isset($this->config['SMTPAuth']) ? $this->config['SMTPAuth'] : '');
@@ -529,6 +535,7 @@ class SpoolRun
break;
case 'IMAP':
case 'PHPMAILER':
case 'GMAILAPI':
//Posible Options for SMTPSecure are: "", "ssl" or "tls"
if (isset($this->config['SMTPSecure']) && preg_match('/^(ssl|tls)$/', $this->config['SMTPSecure'])) {
$phpMailer->SMTPSecure = $this->config['SMTPSecure'];
@@ -543,8 +550,15 @@ class SpoolRun
$phpMailer->Encoding = "8bit";
$phpMailer->Host = $this->config['MESS_SERVER'];
$phpMailer->Port = $this->config['MESS_PORT'];
$phpMailer->Username = $this->config['MESS_ACCOUNT'];
$phpMailer->Password = $this->config['MESS_PASSWORD'];
if ($this->config['MESS_ENGINE'] !== 'GMAILAPI') {
$phpMailer->Username = $this->config['MESS_ACCOUNT'];
$phpMailer->Password = $this->config['MESS_PASSWORD'];
} else {
$phpMailer->oauthUserEmail = $this->config['MESS_ACCOUNT'];
$phpMailer->oauthClientId = $this->config['OAUTH_CLIENT_ID'];
$phpMailer->oauthClientSecret = $this->config['OAUTH_CLIENT_SECRET'];
$phpMailer->oauthRefreshToken = $this->config['OAUTH_REFRESH_TOKEN'];
}
//From
$phpMailer->SetFrom($this->fileData['from_email'], utf8_decode($this->fileData['from_name']));

View File

@@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Facades\Crypt;
use ProcessMaker\BusinessModel\EmailServer;
/*----------------------------------********---------------------------------*/
use ProcessMaker\ChangeLog\ChangeLog;
@@ -930,6 +931,12 @@ class WsBase
$row = $rsCriteria->getRow();
$arrayConfigAux = $row;
$arrayConfigAux["SMTPSecure"] = $row["SMTPSECURE"];
$arrayConfigAux["OAUTH_CLIENT_ID"] = !empty($row["OAUTH_CLIENT_ID"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_ID"]) : '';
$arrayConfigAux["OAUTH_CLIENT_SECRET"] = !empty($row["OAUTH_CLIENT_SECRET"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_SECRET"]) : '';
$arrayConfigAux["OAUTH_REFRESH_TOKEN"] = !empty($row["OAUTH_REFRESH_TOKEN"]) ?
Crypt::decryptString($row["OAUTH_REFRESH_TOKEN"]) : '';
}
}
}

View File

@@ -931,7 +931,9 @@ function getEmailConfiguration ()
* @param array | $attachments = [] | Attachment | An Optional arrray. An array of files (full paths) to be attached to the email.
* @param boolean | $showMessage = true | Show message | Optional parameter. Set to TRUE to show the message in the case's message history.
* @param int | $delIndex = 0 | Delegation index of the case | Optional parameter. The delegation index of the current task in the case.
* @param array | $config = [] | Email server configuration | An optional array: An array of parameters to be used in the Email sent (MESS_ENGINE, MESS_SERVER, MESS_PORT, MESS_FROM_MAIL, MESS_RAUTH, MESS_ACCOUNT, MESS_PASSWORD, and SMTPSecure) Or String: UID of Email server .
* @param array | $config = [] | Email server configuration | An optional array: An array of parameters to be used in the Email sent (MESS_ENGINE,
* MESS_SERVER, MESS_PORT, MESS_FROM_MAIL, MESS_RAUTH, MESS_ACCOUNT, MESS_PASSWORD, SMTPSecure, OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET and OAUTH_REFRESH_TOKEN)
* Or String: UID of Email server .
* @return int | | result | Result of sending email
*
* @see class.pmFunctions::PMFSendMessageToGroup()

View File

@@ -95,6 +95,12 @@ class EmailServerMapBuilder
$tMap->addColumn('MESS_DEFAULT', 'MessDefault', 'int', CreoleTypes::INTEGER, true, null);
$tMap->addColumn('OAUTH_CLIENT_ID', 'OauthClientId', 'string', CreoleTypes::VARCHAR, true, 512);
$tMap->addColumn('OAUTH_CLIENT_SECRET', 'OauthClientSecret', 'string', CreoleTypes::VARCHAR, true, 512);
$tMap->addColumn('OAUTH_REFRESH_TOKEN', 'OauthRefreshToken', 'string', CreoleTypes::VARCHAR, true, 512);
} // doBuild()
} // EmailServerMapBuilder

View File

@@ -117,6 +117,24 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
*/
protected $mess_default = 0;
/**
* The value for the oauth_client_id field.
* @var string
*/
protected $oauth_client_id = '';
/**
* The value for the oauth_client_secret field.
* @var string
*/
protected $oauth_client_secret = '';
/**
* The value for the oauth_refresh_token field.
* @var string
*/
protected $oauth_refresh_token = '';
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
@@ -296,6 +314,39 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
return $this->mess_default;
}
/**
* Get the [oauth_client_id] column value.
*
* @return string
*/
public function getOauthClientId()
{
return $this->oauth_client_id;
}
/**
* Get the [oauth_client_secret] column value.
*
* @return string
*/
public function getOauthClientSecret()
{
return $this->oauth_client_secret;
}
/**
* Get the [oauth_refresh_token] column value.
*
* @return string
*/
public function getOauthRefreshToken()
{
return $this->oauth_refresh_token;
}
/**
* Set the value of [mess_uid] column.
*
@@ -626,6 +677,72 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
} // setMessDefault()
/**
* Set the value of [oauth_client_id] column.
*
* @param string $v new value
* @return void
*/
public function setOauthClientId($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->oauth_client_id !== $v || $v === '') {
$this->oauth_client_id = $v;
$this->modifiedColumns[] = EmailServerPeer::OAUTH_CLIENT_ID;
}
} // setOauthClientId()
/**
* Set the value of [oauth_client_secret] column.
*
* @param string $v new value
* @return void
*/
public function setOauthClientSecret($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->oauth_client_secret !== $v || $v === '') {
$this->oauth_client_secret = $v;
$this->modifiedColumns[] = EmailServerPeer::OAUTH_CLIENT_SECRET;
}
} // setOauthClientSecret()
/**
* Set the value of [oauth_refresh_token] column.
*
* @param string $v new value
* @return void
*/
public function setOauthRefreshToken($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->oauth_refresh_token !== $v || $v === '') {
$this->oauth_refresh_token = $v;
$this->modifiedColumns[] = EmailServerPeer::OAUTH_REFRESH_TOKEN;
}
} // setOauthRefreshToken()
/**
* Hydrates (populates) the object variables with values from the database resultset.
*
@@ -673,12 +790,18 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$this->mess_default = $rs->getInt($startcol + 14);
$this->oauth_client_id = $rs->getString($startcol + 15);
$this->oauth_client_secret = $rs->getString($startcol + 16);
$this->oauth_refresh_token = $rs->getString($startcol + 17);
$this->resetModified();
$this->setNew(false);
// FIXME - using NUM_COLUMNS may be clearer.
return $startcol + 15; // 15 = EmailServerPeer::NUM_COLUMNS - EmailServerPeer::NUM_LAZY_LOAD_COLUMNS).
return $startcol + 18; // 18 = EmailServerPeer::NUM_COLUMNS - EmailServerPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating EmailServer object", $e);
@@ -927,6 +1050,15 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
case 14:
return $this->getMessDefault();
break;
case 15:
return $this->getOauthClientId();
break;
case 16:
return $this->getOauthClientSecret();
break;
case 17:
return $this->getOauthRefreshToken();
break;
default:
return null;
break;
@@ -962,6 +1094,9 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$keys[12] => $this->getMessTrySendInmediatly(),
$keys[13] => $this->getMailTo(),
$keys[14] => $this->getMessDefault(),
$keys[15] => $this->getOauthClientId(),
$keys[16] => $this->getOauthClientSecret(),
$keys[17] => $this->getOauthRefreshToken(),
);
return $result;
}
@@ -1038,6 +1173,15 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
case 14:
$this->setMessDefault($value);
break;
case 15:
$this->setOauthClientId($value);
break;
case 16:
$this->setOauthClientSecret($value);
break;
case 17:
$this->setOauthRefreshToken($value);
break;
} // switch()
}
@@ -1121,6 +1265,18 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$this->setMessDefault($arr[$keys[14]]);
}
if (array_key_exists($keys[15], $arr)) {
$this->setOauthClientId($arr[$keys[15]]);
}
if (array_key_exists($keys[16], $arr)) {
$this->setOauthClientSecret($arr[$keys[16]]);
}
if (array_key_exists($keys[17], $arr)) {
$this->setOauthRefreshToken($arr[$keys[17]]);
}
}
/**
@@ -1192,6 +1348,18 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$criteria->add(EmailServerPeer::MESS_DEFAULT, $this->mess_default);
}
if ($this->isColumnModified(EmailServerPeer::OAUTH_CLIENT_ID)) {
$criteria->add(EmailServerPeer::OAUTH_CLIENT_ID, $this->oauth_client_id);
}
if ($this->isColumnModified(EmailServerPeer::OAUTH_CLIENT_SECRET)) {
$criteria->add(EmailServerPeer::OAUTH_CLIENT_SECRET, $this->oauth_client_secret);
}
if ($this->isColumnModified(EmailServerPeer::OAUTH_REFRESH_TOKEN)) {
$criteria->add(EmailServerPeer::OAUTH_REFRESH_TOKEN, $this->oauth_refresh_token);
}
return $criteria;
}
@@ -1274,6 +1442,12 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$copyObj->setMessDefault($this->mess_default);
$copyObj->setOauthClientId($this->oauth_client_id);
$copyObj->setOauthClientSecret($this->oauth_client_secret);
$copyObj->setOauthRefreshToken($this->oauth_refresh_token);
$copyObj->setNew(true);

View File

@@ -25,7 +25,7 @@ abstract class BaseEmailServerPeer
const CLASS_DEFAULT = 'classes.model.EmailServer';
/** The total number of columns. */
const NUM_COLUMNS = 15;
const NUM_COLUMNS = 18;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
@@ -76,6 +76,15 @@ abstract class BaseEmailServerPeer
/** the column name for the MESS_DEFAULT field */
const MESS_DEFAULT = 'EMAIL_SERVER.MESS_DEFAULT';
/** the column name for the OAUTH_CLIENT_ID field */
const OAUTH_CLIENT_ID = 'EMAIL_SERVER.OAUTH_CLIENT_ID';
/** the column name for the OAUTH_CLIENT_SECRET field */
const OAUTH_CLIENT_SECRET = 'EMAIL_SERVER.OAUTH_CLIENT_SECRET';
/** the column name for the OAUTH_REFRESH_TOKEN field */
const OAUTH_REFRESH_TOKEN = 'EMAIL_SERVER.OAUTH_REFRESH_TOKEN';
/** The PHP to DB Name Mapping */
private static $phpNameMap = null;
@@ -87,10 +96,10 @@ abstract class BaseEmailServerPeer
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('MessUid', 'MessEngine', 'MessServer', 'MessPort', 'MessIncomingServer', 'MessIncomingPort', 'MessRauth', 'MessAccount', 'MessPassword', 'MessFromMail', 'MessFromName', 'Smtpsecure', 'MessTrySendInmediatly', 'MailTo', 'MessDefault', ),
BasePeer::TYPE_COLNAME => array (EmailServerPeer::MESS_UID, EmailServerPeer::MESS_ENGINE, EmailServerPeer::MESS_SERVER, EmailServerPeer::MESS_PORT, EmailServerPeer::MESS_INCOMING_SERVER, EmailServerPeer::MESS_INCOMING_PORT, EmailServerPeer::MESS_RAUTH, EmailServerPeer::MESS_ACCOUNT, EmailServerPeer::MESS_PASSWORD, EmailServerPeer::MESS_FROM_MAIL, EmailServerPeer::MESS_FROM_NAME, EmailServerPeer::SMTPSECURE, EmailServerPeer::MESS_TRY_SEND_INMEDIATLY, EmailServerPeer::MAIL_TO, EmailServerPeer::MESS_DEFAULT, ),
BasePeer::TYPE_FIELDNAME => array ('MESS_UID', 'MESS_ENGINE', 'MESS_SERVER', 'MESS_PORT', 'MESS_INCOMING_SERVER', 'MESS_INCOMING_PORT', 'MESS_RAUTH', 'MESS_ACCOUNT', 'MESS_PASSWORD', 'MESS_FROM_MAIL', 'MESS_FROM_NAME', 'SMTPSECURE', 'MESS_TRY_SEND_INMEDIATLY', 'MAIL_TO', 'MESS_DEFAULT', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
BasePeer::TYPE_PHPNAME => array ('MessUid', 'MessEngine', 'MessServer', 'MessPort', 'MessIncomingServer', 'MessIncomingPort', 'MessRauth', 'MessAccount', 'MessPassword', 'MessFromMail', 'MessFromName', 'Smtpsecure', 'MessTrySendInmediatly', 'MailTo', 'MessDefault', 'OauthClientId', 'OauthClientSecret', 'OauthRefreshToken', ),
BasePeer::TYPE_COLNAME => array (EmailServerPeer::MESS_UID, EmailServerPeer::MESS_ENGINE, EmailServerPeer::MESS_SERVER, EmailServerPeer::MESS_PORT, EmailServerPeer::MESS_INCOMING_SERVER, EmailServerPeer::MESS_INCOMING_PORT, EmailServerPeer::MESS_RAUTH, EmailServerPeer::MESS_ACCOUNT, EmailServerPeer::MESS_PASSWORD, EmailServerPeer::MESS_FROM_MAIL, EmailServerPeer::MESS_FROM_NAME, EmailServerPeer::SMTPSECURE, EmailServerPeer::MESS_TRY_SEND_INMEDIATLY, EmailServerPeer::MAIL_TO, EmailServerPeer::MESS_DEFAULT, EmailServerPeer::OAUTH_CLIENT_ID, EmailServerPeer::OAUTH_CLIENT_SECRET, EmailServerPeer::OAUTH_REFRESH_TOKEN, ),
BasePeer::TYPE_FIELDNAME => array ('MESS_UID', 'MESS_ENGINE', 'MESS_SERVER', 'MESS_PORT', 'MESS_INCOMING_SERVER', 'MESS_INCOMING_PORT', 'MESS_RAUTH', 'MESS_ACCOUNT', 'MESS_PASSWORD', 'MESS_FROM_MAIL', 'MESS_FROM_NAME', 'SMTPSECURE', 'MESS_TRY_SEND_INMEDIATLY', 'MAIL_TO', 'MESS_DEFAULT', 'OAUTH_CLIENT_ID', 'OAUTH_CLIENT_SECRET', 'OAUTH_REFRESH_TOKEN', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, )
);
/**
@@ -100,10 +109,10 @@ abstract class BaseEmailServerPeer
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('MessUid' => 0, 'MessEngine' => 1, 'MessServer' => 2, 'MessPort' => 3, 'MessIncomingServer' => 4, 'MessIncomingPort' => 5, 'MessRauth' => 6, 'MessAccount' => 7, 'MessPassword' => 8, 'MessFromMail' => 9, 'MessFromName' => 10, 'Smtpsecure' => 11, 'MessTrySendInmediatly' => 12, 'MailTo' => 13, 'MessDefault' => 14, ),
BasePeer::TYPE_COLNAME => array (EmailServerPeer::MESS_UID => 0, EmailServerPeer::MESS_ENGINE => 1, EmailServerPeer::MESS_SERVER => 2, EmailServerPeer::MESS_PORT => 3, EmailServerPeer::MESS_INCOMING_SERVER => 4, EmailServerPeer::MESS_INCOMING_PORT => 5, EmailServerPeer::MESS_RAUTH => 6, EmailServerPeer::MESS_ACCOUNT => 7, EmailServerPeer::MESS_PASSWORD => 8, EmailServerPeer::MESS_FROM_MAIL => 9, EmailServerPeer::MESS_FROM_NAME => 10, EmailServerPeer::SMTPSECURE => 11, EmailServerPeer::MESS_TRY_SEND_INMEDIATLY => 12, EmailServerPeer::MAIL_TO => 13, EmailServerPeer::MESS_DEFAULT => 14, ),
BasePeer::TYPE_FIELDNAME => array ('MESS_UID' => 0, 'MESS_ENGINE' => 1, 'MESS_SERVER' => 2, 'MESS_PORT' => 3, 'MESS_INCOMING_SERVER' => 4, 'MESS_INCOMING_PORT' => 5, 'MESS_RAUTH' => 6, 'MESS_ACCOUNT' => 7, 'MESS_PASSWORD' => 8, 'MESS_FROM_MAIL' => 9, 'MESS_FROM_NAME' => 10, 'SMTPSECURE' => 11, 'MESS_TRY_SEND_INMEDIATLY' => 12, 'MAIL_TO' => 13, 'MESS_DEFAULT' => 14, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
BasePeer::TYPE_PHPNAME => array ('MessUid' => 0, 'MessEngine' => 1, 'MessServer' => 2, 'MessPort' => 3, 'MessIncomingServer' => 4, 'MessIncomingPort' => 5, 'MessRauth' => 6, 'MessAccount' => 7, 'MessPassword' => 8, 'MessFromMail' => 9, 'MessFromName' => 10, 'Smtpsecure' => 11, 'MessTrySendInmediatly' => 12, 'MailTo' => 13, 'MessDefault' => 14, 'OauthClientId' => 15, 'OauthClientSecret' => 16, 'OauthRefreshToken' => 17, ),
BasePeer::TYPE_COLNAME => array (EmailServerPeer::MESS_UID => 0, EmailServerPeer::MESS_ENGINE => 1, EmailServerPeer::MESS_SERVER => 2, EmailServerPeer::MESS_PORT => 3, EmailServerPeer::MESS_INCOMING_SERVER => 4, EmailServerPeer::MESS_INCOMING_PORT => 5, EmailServerPeer::MESS_RAUTH => 6, EmailServerPeer::MESS_ACCOUNT => 7, EmailServerPeer::MESS_PASSWORD => 8, EmailServerPeer::MESS_FROM_MAIL => 9, EmailServerPeer::MESS_FROM_NAME => 10, EmailServerPeer::SMTPSECURE => 11, EmailServerPeer::MESS_TRY_SEND_INMEDIATLY => 12, EmailServerPeer::MAIL_TO => 13, EmailServerPeer::MESS_DEFAULT => 14, EmailServerPeer::OAUTH_CLIENT_ID => 15, EmailServerPeer::OAUTH_CLIENT_SECRET => 16, EmailServerPeer::OAUTH_REFRESH_TOKEN => 17, ),
BasePeer::TYPE_FIELDNAME => array ('MESS_UID' => 0, 'MESS_ENGINE' => 1, 'MESS_SERVER' => 2, 'MESS_PORT' => 3, 'MESS_INCOMING_SERVER' => 4, 'MESS_INCOMING_PORT' => 5, 'MESS_RAUTH' => 6, 'MESS_ACCOUNT' => 7, 'MESS_PASSWORD' => 8, 'MESS_FROM_MAIL' => 9, 'MESS_FROM_NAME' => 10, 'SMTPSECURE' => 11, 'MESS_TRY_SEND_INMEDIATLY' => 12, 'MAIL_TO' => 13, 'MESS_DEFAULT' => 14, 'OAUTH_CLIENT_ID' => 15, 'OAUTH_CLIENT_SECRET' => 16, 'OAUTH_REFRESH_TOKEN' => 17, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, )
);
/**
@@ -234,6 +243,12 @@ abstract class BaseEmailServerPeer
$criteria->addSelectColumn(EmailServerPeer::MESS_DEFAULT);
$criteria->addSelectColumn(EmailServerPeer::OAUTH_CLIENT_ID);
$criteria->addSelectColumn(EmailServerPeer::OAUTH_CLIENT_SECRET);
$criteria->addSelectColumn(EmailServerPeer::OAUTH_REFRESH_TOKEN);
}
const COUNT = 'COUNT(EMAIL_SERVER.MESS_UID)';
@@ -564,6 +579,9 @@ abstract class BaseEmailServerPeer
}
} else {
if ($obj->isNew() || $obj->isColumnModified(EmailServerPeer::MESS_ENGINE))
$columns[EmailServerPeer::MESS_ENGINE] = $obj->getMessEngine();
}
return BasePeer::doValidate(EmailServerPeer::DATABASE_NAME, EmailServerPeer::TABLE_NAME, $columns);

View File

@@ -5013,6 +5013,9 @@
<column name="MESS_TRY_SEND_INMEDIATLY" type="INTEGER" required="true" default="0"/>
<column name="MAIL_TO" type="VARCHAR" size="256" required="false" default=""/>
<column name="MESS_DEFAULT" type="INTEGER" required="true" default="0"/>
<column name="OAUTH_CLIENT_ID" type="VARCHAR" size="512" required="true" default=""/>
<column name="OAUTH_CLIENT_SECRET" type="VARCHAR" size="512" required="true" default=""/>
<column name="OAUTH_REFRESH_TOKEN" type="VARCHAR" size="512" required="true" default=""/>
</table>
<table name="WEB_ENTRY_EVENT">

View File

@@ -4331,6 +4331,18 @@ msgstr "Click the lock to make changes."
msgid "Click the lock to prevent further changes."
msgstr "Click the lock to prevent further changes."
# TRANSLATION
# LABEL/ID_CLIENT_ID
#: LABEL/ID_CLIENT_ID
msgid "Client ID"
msgstr "Client ID"
# TRANSLATION
# LABEL/ID_CLIENT_SECRET
#: LABEL/ID_CLIENT_SECRET
msgid "Client Secret"
msgstr "Client Secret"
# TRANSLATION
# LABEL/ID_CLOSE
#: LABEL/ID_CLOSE
@@ -7064,8 +7076,8 @@ msgstr "The email was resend to"
# TRANSLATION
# LABEL/ID_EMAIL_SERVER_ACCOUNT_FROM
#: LABEL/ID_EMAIL_SERVER_ACCOUNT_FROM
msgid "Sender Account"
msgstr "Sender Account"
msgid "From Account"
msgstr "From Account"
# TRANSLATION
# LABEL/ID_EMAIL_SERVER_CONFIRM_DELETE
@@ -18701,6 +18713,12 @@ msgstr "SMTP (PHPMailer)"
msgid "SMTP (OpenMail)"
msgstr "SMTP (OpenMail)"
# TRANSLATION
# LABEL/ID_MESS_ENGINE_TYPE_4
#: LABEL/ID_MESS_ENGINE_TYPE_4
msgid "OAUTH (GMail OAuth)"
msgstr "OAUTH (GMail OAuth)"
# TRANSLATION
# LABEL/ID_MESS_SEND_MAX_REQUIRED
#: LABEL/ID_MESS_SEND_MAX_REQUIRED

View File

@@ -57530,6 +57530,8 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_CLEAR_LOG','en','Clear Log','2014-01-15') ,
( 'LABEL','ID_CLICK_LOCK','en','Click the lock to make changes.','2014-01-15') ,
( 'LABEL','ID_CLICK_UNLOCK','en','Click the lock to prevent further changes.','2014-01-15') ,
( 'LABEL','ID_CLIENT_ID','en','Client ID','2019-11-14') ,
( 'LABEL','ID_CLIENT_SECRET','en','Client Secret','2019-11-14') ,
( 'LABEL','ID_CLOSE','en','Close','2014-01-15') ,
( 'LABEL','ID_CLOSE_EDITOR','en','Close Editor','2014-01-15') ,
( 'LABEL','ID_CODE','en','Code','2014-01-15') ,
@@ -57997,7 +57999,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_EMAIL_MORE_USER','en','This email is assigned to more than one user. Please contact your administrator.','2015-10-02') ,
( 'LABEL','ID_EMAIL_NOT_CORRESPONDS_TOKEN','en','The email does not corresponds to the token gmail user.','2015-10-02') ,
( 'LABEL','ID_EMAIL_RESENT_TO','en','The email was resend to','2016-04-08') ,
( 'LABEL','ID_EMAIL_SERVER_ACCOUNT_FROM','en','Sender Account','2017-02-21') ,
( 'LABEL','ID_EMAIL_SERVER_ACCOUNT_FROM','en','From Account','2017-02-21') ,
( 'LABEL','ID_EMAIL_SERVER_CONFIRM_DELETE','en','Do you want to delete the Email Server?','2014-12-24') ,
( 'LABEL','ID_EMAIL_SERVER_DEFAULT','en','Default','2014-12-24') ,
( 'LABEL','ID_EMAIL_SERVER_DELETE_DATA','en','Delete data...','2014-12-24') ,
@@ -59980,6 +59982,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_MESS_ENGINE_TYPE_1','en','Mail (PHP)','2014-01-15') ,
( 'LABEL','ID_MESS_ENGINE_TYPE_2','en','SMTP (PHPMailer)','2014-01-15') ,
( 'LABEL','ID_MESS_ENGINE_TYPE_3','en','SMTP (OpenMail)','2014-01-15') ,
( 'LABEL','ID_MESS_ENGINE_TYPE_4','en','OAUTH (GMail OAuth)','2019-11-15') ,
( 'LABEL','ID_MESS_SEND_MAX_REQUIRED','en','The maximum number of attempts to send mail is a required field.','2014-01-15') ,
( 'LABEL','ID_MESS_TEST_BODY','en','ProcessMaker Test Email','2014-01-15') ,
( 'LABEL','ID_MESS_TEST_MESSAGE_ERROR_PHP_MAIL','en','Test message send failed, error:','2014-01-15') ,

View File

@@ -2784,6 +2784,9 @@ CREATE TABLE `EMAIL_SERVER`
`MESS_TRY_SEND_INMEDIATLY` INTEGER default 0 NOT NULL,
`MAIL_TO` VARCHAR(256) default '',
`MESS_DEFAULT` INTEGER default 0 NOT NULL,
`OAUTH_CLIENT_ID` VARCHAR(512) default '' NOT NULL,
`OAUTH_CLIENT_SECRET` VARCHAR(512) default '' NOT NULL,
`OAUTH_REFRESH_TOKEN` VARCHAR(512) default '' NOT NULL,
PRIMARY KEY (`MESS_UID`)
)ENGINE=InnoDB DEFAULT CHARSET='utf8';
#-----------------------------------------------------------------------------

View File

@@ -817,7 +817,10 @@ switch (($_POST['action']) ? $_POST['action'] : $_REQUEST['action']) {
'MESS_ACCOUNT' => $aSetup['MESS_ACCOUNT'],
'MESS_PASSWORD' => $aSetup['MESS_PASSWORD'],
'SMTPSecure' => $aSetup['SMTPSecure'],
'SMTPAuth' => $aSetup['MESS_RAUTH']
'SMTPAuth' => $aSetup['MESS_RAUTH'],
'OAUTH_CLIENT_ID' => $aSetup['OAUTH_CLIENT_ID'],
'OAUTH_CLIENT_SECRET' => $aSetup['OAUTH_CLIENT_SECRET'],
'OAUTH_REFRESH_TOKEN' => $aSetup['OAUTH_REFRESH_TOKEN']
)
);
$oSpool->create(array('msg_uid' => $data['MSG_UID'], 'app_uid' => $data['APP_UID'], 'del_index' => $data['DEL_INDEX'], 'app_msg_type' => $data['APP_MSG_TYPE'], 'app_msg_subject' => $data['APP_MSG_SUBJECT'], 'app_msg_from' => $data['APP_MSG_FROM'], 'app_msg_to' => $data['APP_MSG_TO'], 'app_msg_body' => $data['APP_MSG_BODY'], 'app_msg_cc' => $data['APP_MSG_CC'], 'app_msg_bcc' => $data['APP_MSG_BCC'], 'app_msg_attach' => $data['APP_MSG_ATTACH'], 'app_msg_template' => $data['APP_MSG_TEMPLATE'], 'app_msg_status' => 'pending'

View File

@@ -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");

View File

@@ -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);

View File

@@ -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;

View File

@@ -5,6 +5,7 @@ use AppMessage;
use Bootstrap;
use Exception;
use G;
use Illuminate\Support\Facades\Crypt;
use ProcessMaker\Core\System;
use SpoolRun;
use TemplatePower;
@@ -14,7 +15,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"), "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"),
@@ -809,6 +810,13 @@ class EmailServer
$arrayData["MESS_PASSWORD"] = G::encrypt($arrayData["MESS_PASSWORD"], "EMAILENCRYPT");
}
$arrayData["OAUTH_CLIENT_ID"] = !empty($arrayData["OAUTH_CLIENT_ID"]) ?
Crypt::encryptString($arrayData["OAUTH_CLIENT_ID"]) : "";
$arrayData["OAUTH_CLIENT_SECRET"] = !empty($arrayData["OAUTH_CLIENT_SECRET"]) ?
Crypt::encryptString($arrayData["OAUTH_CLIENT_SECRET"]) : "";
$arrayData["OAUTH_REFRESH_TOKEN"] = !empty($arrayData["OAUTH_REFRESH_TOKEN"]) ?
Crypt::encryptString($arrayData["OAUTH_REFRESH_TOKEN"]) : "";
$emailServer->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$emailServerUid = \ProcessMaker\Util\Common::generateUID();
@@ -981,6 +989,13 @@ class EmailServer
}
}
$arrayData["OAUTH_CLIENT_ID"] = !empty($arrayData["OAUTH_CLIENT_ID"]) ?
Crypt::encryptString($arrayData["OAUTH_CLIENT_ID"]) : "";
$arrayData["OAUTH_CLIENT_SECRET"] = !empty($arrayData["OAUTH_CLIENT_SECRET"]) ?
Crypt::encryptString($arrayData["OAUTH_CLIENT_SECRET"]) : "";
$arrayData["OAUTH_REFRESH_TOKEN"] = !empty($arrayData["OAUTH_REFRESH_TOKEN"]) ?
Crypt::encryptString($arrayData["OAUTH_REFRESH_TOKEN"]) : "";
$emailServer->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
if ($emailServer->validate()) {
@@ -1106,6 +1121,9 @@ class EmailServer
$criteria->addSelectColumn(\EmailServerPeer::MESS_TRY_SEND_INMEDIATLY);
$criteria->addSelectColumn(\EmailServerPeer::MAIL_TO);
$criteria->addSelectColumn(\EmailServerPeer::MESS_DEFAULT);
$criteria->addSelectColumn(\EmailServerPeer::OAUTH_CLIENT_ID);
$criteria->addSelectColumn(\EmailServerPeer::OAUTH_CLIENT_SECRET);
$criteria->addSelectColumn(\EmailServerPeer::OAUTH_REFRESH_TOKEN);
return $criteria;
} catch (Exception $e) {
@@ -1124,7 +1142,7 @@ class EmailServer
public function getEmailServerDataFromRecord(array $record)
{
try {
return array(
return [
$this->getFieldNameByFormatFieldName("MESS_UID") => $record["MESS_UID"],
$this->getFieldNameByFormatFieldName("MESS_ENGINE") => $record["MESS_ENGINE"],
$this->getFieldNameByFormatFieldName("MESS_SERVER") => $record["MESS_SERVER"],
@@ -1143,8 +1161,11 @@ class EmailServer
$this->getFieldNameByFormatFieldName("MESS_BACKGROUND") => '',
$this->getFieldNameByFormatFieldName("MESS_PASSWORD_HIDDEN") => '',
$this->getFieldNameByFormatFieldName("MESS_EXECUTE_EVERY") => '',
$this->getFieldNameByFormatFieldName("MESS_SEND_MAX") => ''
);
$this->getFieldNameByFormatFieldName("MESS_SEND_MAX") => '',
$this->getFieldNameByFormatFieldName("OAUTH_CLIENT_ID") => $record["OAUTH_CLIENT_ID"],
$this->getFieldNameByFormatFieldName("OAUTH_CLIENT_SECRET") => $record["OAUTH_CLIENT_SECRET"],
$this->getFieldNameByFormatFieldName("OAUTH_REFRESH_TOKEN") => $record["OAUTH_REFRESH_TOKEN"]
];
} catch (Exception $e) {
throw $e;
}
@@ -1191,6 +1212,12 @@ class EmailServer
$arrayData["MESS_PASSWORD_HIDDEN"] = '';
$arrayData["MESS_EXECUTE_EVERY"] = '';
$arrayData["MESS_SEND_MAX"] = '';
$arrayData["OAUTH_CLIENT_ID"] = !empty($row["OAUTH_CLIENT_ID"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_ID"]) : '';
$arrayData["OAUTH_CLIENT_SECRET"] = !empty($row["OAUTH_CLIENT_SECRET"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_SECRET"]) : '';
$arrayData["OAUTH_REFRESH_TOKEN"] = !empty($row["OAUTH_REFRESH_TOKEN"]) ?
Crypt::decryptString($row["OAUTH_REFRESH_TOKEN"]) : '';
}
//Return
@@ -1287,6 +1314,9 @@ class EmailServer
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$row['OAUTH_CLIENT_ID'] = !empty($row['OAUTH_CLIENT_ID']) ? Crypt::decryptString($row['OAUTH_CLIENT_ID']) : '';
$row['OAUTH_CLIENT_SECRET'] = !empty($row['OAUTH_CLIENT_SECRET']) ? Crypt::decryptString($row['OAUTH_CLIENT_SECRET']) : '';
$row['OAUTH_REFRESH_TOKEN'] = !empty($row['OAUTH_REFRESH_TOKEN']) ? Crypt::decryptString($row['OAUTH_REFRESH_TOKEN']) : '';
$arrayEmailServer[] = $this->getEmailServerDataFromRecord($row);
}
@@ -1340,6 +1370,9 @@ class EmailServer
$row["MESS_PASSWORD_HIDDEN"] = '';
$row["MESS_EXECUTE_EVERY"] = '';
$row["MESS_SEND_MAX"] = '';
$row["OAUTH_CLIENT_ID"] = !empty($row["OAUTH_CLIENT_ID"]) ? Crypt::decryptString($row["OAUTH_CLIENT_ID"]) : '';
$row["OAUTH_CLIENT_SECRET"] = !empty($row["OAUTH_CLIENT_SECRET"]) ? Crypt::decryptString($row["OAUTH_CLIENT_SECRET"]) : '';
$row["OAUTH_REFRESH_TOKEN"] = !empty($row["OAUTH_REFRESH_TOKEN"]) ? Crypt::decryptString($row["OAUTH_REFRESH_TOKEN"]) : '';
//Return
return (!$flagGetRecord)? $this->getEmailServerDataFromRecord($row) : $row;

View File

@@ -1016,7 +1016,10 @@ class System
"MESS_BACKGROUND" => "",
"MESS_PASSWORD_HIDDEN" => "",
"MESS_EXECUTE_EVERY" => "",
"MESS_SEND_MAX" => ""
"MESS_SEND_MAX" => "",
"OAUTH_CLIENT_ID" => $arrayEmailServerDefault["OAUTH_CLIENT_ID"],
"OAUTH_CLIENT_SECRET" => $arrayEmailServerDefault["OAUTH_CLIENT_SECRET"],
"OAUTH_REFRESH_TOKEN" => $arrayEmailServerDefault["OAUTH_REFRESH_TOKEN"]
);
//Return

View File

@@ -0,0 +1,482 @@
<?php
namespace ProcessMaker\GmailOAuth;
use AppMessage;
use Bootstrap;
use G;
use Google_Client;
use Google_Service_Gmail;
use Google_Service_Gmail_Message;
use PHPMailerOAuth;
use ProcessMaker\BusinessModel\EmailServer;
use ProcessMaker\Core\System;
use TemplatePower;
use WsBase;
class GmailOAuth
{
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 $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 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;
}
/**
* Get a Google_Client object, this may vary depending on the service provider.
* @return Google_Client
*/
public function getGoogleClient(): Google_Client
{
$googleClient = new Google_Client();
$googleClient->setClientId($this->clientID);
$googleClient->setClientSecret($this->clientSecret);
$googleClient->setRedirectUri($this->redirectURI);
$googleClient->setAccessType('offline');
$googleClient->setApprovalPrompt('force');
$googleClient->addScope(Google_Service_Gmail::MAIL_GOOGLE_COM);
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.
* @return Google_Service_Gmail_Message
*/
public function sendTestEmailWithGoogleServiceGmail(): Google_Service_Gmail_Message
{
$googleServiceGmailMessage = new Google_Service_Gmail_Message();
if (!filter_var($this->fromAccount, FILTER_VALIDATE_EMAIL)) {
return $googleServiceGmailMessage;
}
if (!filter_var($this->mailTo, FILTER_VALIDATE_EMAIL)) {
return $googleServiceGmailMessage;
}
if ($this->sendTestMail === 0) {
return $googleServiceGmailMessage;
}
$googleClient = $this->getGoogleClient();
$googleClient->refreshToken($this->getRefreshToken());
if ($googleClient->isAccessTokenExpired()) {
$newAccessToken = $googleClient->getAccessToken();
$googleClient->setAccessToken($newAccessToken);
}
$raw = $this->getRawMessage();
$googleServiceGmailMessage->setRaw($raw);
$service = new Google_Service_Gmail($googleClient);
$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::getServerHostname());
$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 = "")
{
$channel = "Test Email Servers Configuration";
$severity = 200; //INFO
$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
];
$workspace = config("system.workspace");
Bootstrap::registerMonolog($channel, $severity, $message, $context, $workspace);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class AppMessage extends Model
{
protected $table = 'APP_MESSAGE';
public $timestamps = false;
}

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Crypt;
class EmailServerModel extends Model
{
@@ -31,13 +32,25 @@ class EmailServerModel extends Model
'EMAIL_SERVER.SMTPSECURE',
'EMAIL_SERVER.MESS_TRY_SEND_INMEDIATLY',
'EMAIL_SERVER.MAIL_TO',
'EMAIL_SERVER.MESS_DEFAULT'
'EMAIL_SERVER.MESS_DEFAULT',
'EMAIL_SERVER.OAUTH_CLIENT_ID',
'EMAIL_SERVER.OAUTH_CLIENT_SECRET',
'EMAIL_SERVER.OAUTH_REFRESH_TOKEN'
];
$query = EmailServerModel::query()->select($selectedColumns);
$query->where('EMAIL_SERVER.MESS_UID', '=', $messUid);
$res = $query->get()->values()->toArray();
$firstElement = head($res);
if (!empty($firstElement)) {
$firstElement['OAUTH_CLIENT_ID'] = !empty($firstElement['OAUTH_CLIENT_ID']) ?
Crypt::decryptString($firstElement['OAUTH_CLIENT_ID']) : '';
$firstElement['OAUTH_CLIENT_SECRET'] = !empty($firstElement['OAUTH_CLIENT_SECRET']) ?
Crypt::decryptString($firstElement['OAUTH_CLIENT_SECRET']) : '';
$firstElement['OAUTH_REFRESH_TOKEN'] = !empty($firstElement['OAUTH_REFRESH_TOKEN']) ?
Crypt::decryptString($firstElement['OAUTH_REFRESH_TOKEN']) : '';
}
return $firstElement;
}
@@ -64,7 +77,10 @@ class EmailServerModel extends Model
'EMAIL_SERVER.SMTPSECURE',
'EMAIL_SERVER.MESS_TRY_SEND_INMEDIATLY',
'EMAIL_SERVER.MAIL_TO',
'EMAIL_SERVER.MESS_DEFAULT'
'EMAIL_SERVER.MESS_DEFAULT',
'EMAIL_SERVER.OAUTH_CLIENT_ID',
'EMAIL_SERVER.OAUTH_CLIENT_SECRET',
'EMAIL_SERVER.OAUTH_REFRESH_TOKEN'
];
$query = EmailServerModel::query()->select($selectedColumns)
->where('MESS_DEFAULT', '=', 1);
@@ -77,6 +93,12 @@ class EmailServerModel extends Model
$firstElement['MESS_PASSWORD_HIDDEN'] = '';
$firstElement['MESS_EXECUTE_EVERY'] = '';
$firstElement['MESS_SEND_MAX'] = '';
$firstElement['OAUTH_CLIENT_ID'] = !empty($firstElement['OAUTH_CLIENT_ID']) ?
Crypt::decryptString($firstElement['OAUTH_CLIENT_ID']) : '';
$firstElement['OAUTH_CLIENT_SECRET'] = !empty($firstElement['OAUTH_CLIENT_SECRET']) ?
Crypt::decryptString($firstElement['OAUTH_CLIENT_SECRET']) : '';
$firstElement['OAUTH_REFRESH_TOKEN'] = !empty($firstElement['OAUTH_REFRESH_TOKEN']) ?
Crypt::decryptString($firstElement['OAUTH_REFRESH_TOKEN']) : '';
}
return $firstElement;

View File

@@ -25,8 +25,6 @@ emailServer.application = {
case "DEL":
msg = _("ID_EMAIL_SERVER_DELETE_DATA");
break;
//case "LST":
// break;
case "TEST":
msg = _("ID_EMAIL_SERVER_TEST_DATA");
break;
@@ -40,9 +38,9 @@ emailServer.application = {
/*----------------------------------********---------------------------------*/
if (Ext.getCmp("chkEmailServerDefault").checked) {
/*----------------------------------********---------------------------------*/
/*----------------------------------********---------------------------------*/
var emailDefault = 1;
/*----------------------------------********---------------------------------*/
/*----------------------------------********---------------------------------*/
} else {
var emailDefault = 0;
}
@@ -102,7 +100,7 @@ emailServer.application = {
cboEmailEngine: typeEmailEngine,
fromMail: Ext.getCmp("txtFromMail").getValue(),
fromName: Ext.getCmp("txtFromName").getValue(),
sendTestMail: (Ext.getCmp("chkSendTestMail").checked)? 1 : 0,
sendTestMail: (Ext.getCmp("chkSendTestMail").checked) ? 1 : 0,
mailTo: Ext.getCmp("txtMailTo").getValue(),
emailServerDefault: emailDefault
};
@@ -156,9 +154,6 @@ emailServer.application = {
}
}
break;
//case "LST":
// break;
case "TEST":
showTestConnection(typeEmailEngine, dataResponse.data);
@@ -213,6 +208,8 @@ emailServer.application = {
emailServerSetMailTo(Ext.getCmp("chkSendTestMail").checked);
Ext.getCmp("txtMailTo").setValue("");
Ext.getCmp("textClientId").setValue("");
Ext.getCmp("textClientSecret").setValue("");
/*----------------------------------********---------------------------------*/
Ext.getCmp("chkEmailServerDefault").setValue(false);
@@ -229,19 +226,19 @@ emailServer.application = {
case "UPD":
var record = grdpnlMain.getSelectionModel().getSelected();
if (typeof(record) != "undefined") {
if (typeof (record) != "undefined") {
Ext.getCmp("emailServerUid").setValue(record.get("MESS_UID"));
Ext.getCmp("cboEmailEngine").setValue(record.get("MESS_ENGINE"));
emailServerSetEmailEngine(record.get("MESS_ENGINE"));
Ext.getCmp("txtServer").setValue(record.get("MESS_SERVER"));
Ext.getCmp("txtPort").setValue((record.get("MESS_PORT") != 0)? record.get("MESS_PORT") : "");
Ext.getCmp("txtPort").setValue((record.get("MESS_PORT") != 0) ? record.get("MESS_PORT") : "");
Ext.getCmp("txtIncomingServer").setValue(record.get("MESS_INCOMING_SERVER"));
Ext.getCmp("txtIncomingPort").setValue((record.get("MESS_INCOMING_PORT") !== 0)? record.get("MESS_INCOMING_PORT") : "");
Ext.getCmp("txtIncomingPort").setValue((record.get("MESS_INCOMING_PORT") !== 0) ? record.get("MESS_INCOMING_PORT") : "");
Ext.getCmp("chkReqAuthentication").setValue((parseInt(record.get("MESS_RAUTH")) == 1)? true : false);
Ext.getCmp("chkReqAuthentication").setValue((parseInt(record.get("MESS_RAUTH")) == 1) ? true : false);
emailServerSetPassword(Ext.getCmp("chkReqAuthentication").checked);
@@ -250,17 +247,19 @@ emailServer.application = {
Ext.getCmp("txtFromMail").setValue(record.get("MESS_FROM_MAIL"));
Ext.getCmp("txtFromName").setValue(record.get("MESS_FROM_NAME"));
Ext.getCmp("rdoGrpSmtpSecure").setValue((record.get("SMTPSECURE") != "")? record.get("SMTPSECURE") : "No");
Ext.getCmp("chkSendTestMail").setValue((parseInt(record.get("MESS_TRY_SEND_INMEDIATLY")) == 1)? true : false);
Ext.getCmp("rdoGrpSmtpSecure").setValue((record.get("SMTPSECURE") != "") ? record.get("SMTPSECURE") : "No");
Ext.getCmp("chkSendTestMail").setValue((parseInt(record.get("MESS_TRY_SEND_INMEDIATLY")) == 1) ? true : false);
emailServerSetMailTo(Ext.getCmp("chkSendTestMail").checked);
Ext.getCmp("txtMailTo").setValue(record.get("MAIL_TO"));
Ext.getCmp("textClientId").setValue(record.get("OAUTH_CLIENT_ID"));
Ext.getCmp("textClientSecret").setValue(record.get("OAUTH_CLIENT_SECRET"));
/*----------------------------------********---------------------------------*/
if (parseInt(record.get("MESS_DEFAULT")) == 1) {
/*----------------------------------********---------------------------------*/
/*----------------------------------********---------------------------------*/
Ext.getCmp("chkEmailServerDefault").setValue(true);
/*----------------------------------********---------------------------------*/
/*----------------------------------********---------------------------------*/
} else {
Ext.getCmp("chkEmailServerDefault").setValue(false);
}
@@ -278,6 +277,12 @@ emailServer.application = {
{
Ext.getCmp("frmEmailServer").getForm().clearInvalid();
Ext.getCmp("textClientId").setVisible(false);
Ext.getCmp("textClientSecret").setVisible(false);
Ext.getCmp("buttonContinue").setVisible(false);
Ext.getCmp("btnTest").setVisible(true);
Ext.getCmp("btnSave").setVisible(true);
if (cboEmailEngine === "PHPMAILER") {
Ext.getCmp("txtServer").setVisible(true);
Ext.getCmp("txtPort").setVisible(true);
@@ -334,6 +339,29 @@ emailServer.application = {
Ext.getCmp("txtIncomingPort").allowBlank = false;
Ext.getCmp("txtAccountFrom").allowBlank = false;
/*----------------------------------********---------------------------------*/
} else if (cboEmailEngine === "GMAILAPI") {
Ext.getCmp("txtServer").setVisible(false);
Ext.getCmp("txtPort").setVisible(false);
Ext.getCmp("txtIncomingServer").setVisible(false);
Ext.getCmp("txtIncomingPort").setVisible(false);
Ext.getCmp("chkReqAuthentication").setVisible(false);
Ext.getCmp("rdoGrpSmtpSecure").setVisible(false);
Ext.getCmp("btnTest").setVisible(false);
Ext.getCmp("btnSave").setVisible(false);
Ext.getCmp("txtAccountFrom").setVisible(true);
Ext.getCmp("textClientId").setVisible(true);
Ext.getCmp("textClientSecret").setVisible(true);
Ext.getCmp("buttonContinue").setVisible(true);
emailServerSetPassword(false);
Ext.getCmp("txtServer").allowBlank = true;
Ext.getCmp("txtPort").allowBlank = true;
Ext.getCmp("txtIncomingServer").allowBlank = true;
Ext.getCmp("txtIncomingPort").allowBlank = true;
Ext.getCmp("txtAccountFrom").allowBlank = false;
Ext.getCmp("txtPassword").allowBlank = true;
} else {
//MAIL
Ext.getCmp("txtServer").setVisible(false);
@@ -360,7 +388,7 @@ emailServer.application = {
function emailServerSetPassword(flagPassChecked)
{
if (flagPassChecked) {
if (flagPassChecked && Ext.getCmp("cboEmailEngine").getValue() !== 'GMAILAPI') {
Ext.getCmp("txtPassword").setVisible(true);
Ext.getCmp("txtPassword").allowBlank = false;
} else {
@@ -387,67 +415,67 @@ emailServer.application = {
FLAGTEST = 1;
if (option === "PHPMAILER" || option === "IMAP") {
if (typeof(testData.resolving_name) != "undefined") {
if (typeof (testData.resolving_name) != "undefined") {
if (testData.resolving_name.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.resolving_name.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.resolving_name.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.resolving_name.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.resolving_name.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.resolving_name.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.resolving_name.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.check_port) != "undefined") {
if (typeof (testData.check_port) != "undefined") {
if (testData.check_port.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.check_port.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.check_port.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.check_port.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.check_port.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.check_port.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.check_port.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.establishing_connection_host) != "undefined") {
if (typeof (testData.establishing_connection_host) != "undefined") {
if (testData.establishing_connection_host.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.establishing_connection_host.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.establishing_connection_host.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.establishing_connection_host.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.establishing_connection_host.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.establishing_connection_host.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.establishing_connection_host.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.login) != "undefined") {
if (typeof (testData.login) != "undefined") {
if (testData.login.result != "") {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.login.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.login.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.login.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.login.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.login.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.login.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.sending_email) != "undefined") {
if (typeof (testData.sending_email) != "undefined") {
if (testData.sending_email.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.sending_email.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.sending_email.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.sending_email.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.sending_email.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.sending_email.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.sending_email.message + "</span><br />";
FLAGTEST = 0;
}
}
} else {
//MAIL
if (typeof(testData.verifying_mail) != "undefined") {
if (typeof (testData.verifying_mail) != "undefined") {
if (testData.verifying_mail.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em;\" />" + testData.verifying_mail.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em;\" />" + testData.verifying_mail.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.verifying_mail.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.verifying_mail.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.verifying_mail.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.verifying_mail.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.sending_email) != "undefined") {
if (typeof (testData.sending_email) != "undefined") {
if (testData.sending_email.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.sending_email.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.sending_email.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.sending_email.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.sending_email.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.sending_email.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.sending_email.message + "</span><br />";
FLAGTEST = 0;
}
}
@@ -504,7 +532,9 @@ emailServer.application = {
{name: "SMTPSECURE", type: "string"},
{name: "MESS_TRY_SEND_INMEDIATLY", type: "int"},
{name: "MAIL_TO", type: "string"},
{name: "MESS_DEFAULT", type: "int"}
{name: "MESS_DEFAULT", type: "int"},
{name: "OAUTH_CLIENT_ID", type: "string"},
{name: "OAUTH_CLIENT_SECRET", type: "string"}
]
}),
@@ -540,7 +570,7 @@ emailServer.application = {
var emailUrlValidationText = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))|((([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$/i;
Ext.apply(Ext.form.VTypes, {
emailUrlValidation: function(val, field)
emailUrlValidation: function (val, field)
{
return emailUrlValidationText.test(val);
}
@@ -555,7 +585,8 @@ emailServer.application = {
/*----------------------------------********---------------------------------*/
["IMAP", "SMTP - IMAP (PHPMailer)"],
/*----------------------------------********---------------------------------*/
["MAIL", "Mail (PHP)"]
["MAIL", "Mail (PHP)"],
["GMAILAPI", "GMAIL API (PHPMailer)"]
]
});
@@ -579,7 +610,7 @@ emailServer.application = {
forceSelection: true,
listeners: {
select: function(combo, value)
select: function (combo, value)
{
emailServerSetEmailEngine(Ext.getCmp("cboEmailEngine").getValue());
}
@@ -597,7 +628,7 @@ emailServer.application = {
id: "txtPort",
name: "txtPort",
fieldLabel: _("PORT_DEFAULT"), //Port (default 25)
fieldLabel: _("PORT_DEFAULT"), //Port (default 25)
anchor: "36%",
maxLength: 3,
@@ -615,7 +646,7 @@ emailServer.application = {
id: "txtIncomingPort",
name: "txtIncomingPort",
fieldLabel: _("INCOMING_PORT_DEFAULT"), //Port (default 993)
fieldLabel: _("INCOMING_PORT_DEFAULT"), //Port (default 993)
anchor: "36%",
maxLength: 3,
@@ -628,7 +659,7 @@ emailServer.application = {
boxLabel: _("REQUIRE_AUTHENTICATION"), //Require authentication
handler: function()
handler: function ()
{
emailServerSetPassword(this.checked);
}
@@ -680,7 +711,7 @@ emailServer.application = {
vertical: true,
items: [
{boxLabel: "No", inputValue: "No", name: "rdoGrpSmtpSecure", checked: true},
{boxLabel: "No", inputValue: "No", name: "rdoGrpSmtpSecure", checked: true},
{boxLabel: "TLS", inputValue: "tls", name: "rdoGrpSmtpSecure"},
{boxLabel: "SSL", inputValue: "ssl", name: "rdoGrpSmtpSecure"}
]
@@ -692,7 +723,7 @@ emailServer.application = {
boxLabel: _("SEND_TEST_MAIL"), //Send a test mail
handler: function()
handler: function ()
{
emailServerSetMailTo(this.checked);
}
@@ -756,66 +787,140 @@ emailServer.application = {
var btnCancel = new Ext.Action({
id: "btnCancel",
text: _("ID_CANCEL"),
width: 85,
disabled: false,
handler: function ()
{
handler: function () {
Ext.getCmp("frmEmailServer").setVisible(true);
winData.hide();
}
});
var textClientId = new Ext.form.TextField({
id: "textClientId",
name: "textClientId",
fieldLabel: _("ID_CLIENT_ID")
});
var textClientSecret = new Ext.form.TextField({
id: "textClientSecret",
name: "textClientSecret",
fieldLabel: _("ID_CLIENT_SECRET")
});
var buttonContinue = new Ext.Action({
id: 'buttonContinue',
text: _("ID_CONTINUE"),
width: 85,
handler: function () {
var frmEmailServer, parameters;
frmEmailServer = Ext.getCmp("frmEmailServer");
if (frmEmailServer.getForm().isValid()) {
winData.setDisabled(true);
parameters = {
option: 'createAuthUrl',
emailEngine: Ext.getCmp("cboEmailEngine").getValue(),
clientID: Ext.getCmp("textClientId").getValue(),
clientSecret: Ext.getCmp("textClientSecret").getValue(),
fromAccount: Ext.getCmp("txtAccountFrom").getValue(),
senderEmail: Ext.getCmp("txtFromMail").getValue(),
senderName: Ext.getCmp("txtFromName").getValue(),
sendTestMail: (Ext.getCmp("chkSendTestMail").checked) ? 1 : 0,
mailTo: Ext.getCmp("txtMailTo").getValue(),
setDefaultConfiguration: Ext.getCmp("chkEmailServerDefault").checked ? 1 : 0
};
if (EMAILSERVEROPTION === "UPD") {
parameters.emailServerUid = Ext.getCmp("emailServerUid").getValue();
}
Ext.Ajax.request({
url: "emailServerAjax",
method: "POST",
params: parameters,
success: function (response) {
winData.setDisabled(false);
var dataResponse = Ext.util.JSON.decode(response.responseText);
if (dataResponse.status === 200) {
if (window.parent.parent) {
window.parent.parent.location = dataResponse.data;
} else if (window.parent) {
window.parent.location = dataResponse.data;
} else {
window.location = dataResponse.data;
}
} else {
Ext.MessageBox.show({
title: _("ID_ERROR"),
icon: Ext.MessageBox.ERROR,
msg: dataResponse.message,
buttons: {ok: _("ID_ACCEPT")}
});
}
},
failure: function () {
winData.setDisabled(false);
Ext.MessageBox.show({
title: _("ID_ERROR"),
icon: Ext.MessageBox.ERROR,
msg: "",
buttons: {ok: _("ID_ACCEPT")}
});
}
});
} else {
Ext.MessageBox.alert(_("ID_INVALID_DATA"), _("ID_CHECK_FIELDS_MARK_RED"));
}
}
});
var frmEmailServer = new Ext.FormPanel({
id: "frmEmailServer",
frame: true,
labelAlign: "right",
labelWidth: 150,
autoWidth: true,
autoScroll: false,
defaults: {width: 325},
items: [
{
xtype: "hidden",
id: "emailServerUid",
name: "emailServerUid"
},
cboEmailEngine,
txtServer,
txtPort,
txtIncomingServer,
txtIncomingPort,
chkReqAuthentication,
textClientId,
textClientSecret,
txtAccountFrom,
txtPassword,
txtFromMail,
txtFromName,
rdoGrpSmtpSecure,
chkSendTestMail,
txtMailTo
/*----------------------------------********---------------------------------*/
, chkEmailServerDefault
/*----------------------------------********---------------------------------*/
]
});
//Components
var winData = new Ext.Window({
layout: "fit",
width: 550,
height: 450,
//title: "",
modal: true,
resizable: false,
closeAction: "hide",
items: [
new Ext.FormPanel({
id: "frmEmailServer",
frame: true,
labelAlign: "right",
labelWidth: 150,
autoWidth: true,
autoScroll: false,
defaults: {width: 325},
items: [
{
xtype: "hidden",
id: "emailServerUid",
name: "emailServerUid"
},
cboEmailEngine,
txtServer,
txtPort,
txtIncomingServer,
txtIncomingPort,
chkReqAuthentication,
txtAccountFrom,
txtPassword,
txtFromMail,
txtFromName,
rdoGrpSmtpSecure,
chkSendTestMail,
txtMailTo
/*----------------------------------********---------------------------------*/
, chkEmailServerDefault
/*----------------------------------********---------------------------------*/
]
})
],
buttons: [btnTest, btnSave, btnCancel]
items: [frmEmailServer],
buttons: [buttonContinue, btnTest, btnSave, btnCancel]
});
winData.show();
winData.hide();
var winTestConnection = new Ext.Window({
layout: "fit",
@@ -906,7 +1011,7 @@ emailServer.application = {
{
var record = grdpnlMain.getSelectionModel().getSelected();
if (typeof(record) != "undefined") {
if (typeof (record) != "undefined") {
Ext.getCmp("btnSave").disable();
EMAILSERVEROPTION = "UPD";
@@ -927,18 +1032,18 @@ emailServer.application = {
{
var record = grdpnlMain.getSelectionModel().getSelected();
if (typeof(record) != "undefined") {
if (typeof (record) != "undefined") {
Ext.MessageBox.confirm(
_("ID_CONFIRM"),
_("ID_EMAIL_SERVER_DELETE_WARNING_MESSAGE"),
function (btn)
{
if (btn == "yes") {
EMAILSERVEROPTION = "DEL";
emailServerProcessAjax(EMAILSERVEROPTION, record.get("MESS_UID"));
_("ID_CONFIRM"),
_("ID_EMAIL_SERVER_DELETE_WARNING_MESSAGE"),
function (btn) {
if (btn == "yes") {
EMAILSERVEROPTION = "DEL";
Ext.getCmp("cboEmailEngine").setValue(record.get("MESS_ENGINE"));
Ext.getCmp("rdoGrpSmtpSecure").setValue((record.get("SMTPSECURE") != "") ? record.get("SMTPSECURE") : "No");
emailServerProcessAjax(EMAILSERVEROPTION, record.get("MESS_UID"));
}
}
}
);
}
}
@@ -1016,32 +1121,32 @@ emailServer.application = {
var rendererMessServer = function (value)
{
return (value != "")? value : "-";
return (value != "") ? value : "-";
};
var rendererMessPort = function (value)
{
return (value != 0)? value : "-";
return (value != 0) ? value : "-";
};
var rendererMessIncomingServer = function (value)
{
return (value !== "")? value : "-";
return (value !== "") ? value : "-";
};
var rendererMessIncomingPort = function (value)
{
return (value !== 0)? value : "-";
return (value !== 0) ? value : "-";
};
var rendererMessSmtpSecure = function (value)
{
return (value != "")? value : "-";
return (value != "") ? value : "-";
};
var rendererMessDefault = function (value)
{
return (value == 1)? "<img src = \"/images/ext/default/saved.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em;\" />" : "";
return (value == 1) ? "<img src = \"/images/ext/default/saved.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em;\" />" : "";
};
var cmodel = new Ext.grid.ColumnModel({
@@ -1050,20 +1155,20 @@ emailServer.application = {
},
columns: [
{id: "MESS_UID", dataIndex: "MESS_UID", hidden: true, header: "uid_emailServer", width: 0, hideable: false, align: "left"},
{id: "MESS_UID", dataIndex: "MESS_UID", hidden: true, header: "uid_emailServer", width: 0, hideable: false, align: "left"},
{id: "MESS_ENGINE", dataIndex: "MESS_ENGINE", hidden: false, header: _("EMAIL_ENGINE"), width: 80, hideable: true, align: "left"},
{id: "MESS_SERVER", dataIndex: "MESS_SERVER", hidden: false, header: _("ID_SERVER"), width: 150, hideable: true, align: "center", renderer: rendererMessServer},
{id: "MESS_PORT", dataIndex: "MESS_PORT", hidden: false, header: _("ID_EMAIL_SERVER_PORT"), width: 50, hideable: true, align: "center", renderer: rendererMessPort},
{id: "MESS_PORT", dataIndex: "MESS_PORT", hidden: false, header: _("ID_EMAIL_SERVER_PORT"), width: 50, hideable: true, align: "center", renderer: rendererMessPort},
{id: "MESS_INCOMING_SERVER", dataIndex: "MESS_INCOMING_SERVER", hidden: true, header: _("ID_INCOMING_SERVER"), width: 150, hideable: true, align: "center", renderer: rendererMessIncomingServer},
{id: "MESS_INCOMING_PORT", dataIndex: "MESS_INCOMING_PORT", hidden: true, header: _("ID_EMAIL_SERVER_PORT"), width: 50, hideable: true, align: "center", renderer: rendererMessIncomingPort},
{id: "MESS_RAUTH", dataIndex: "MESS_RAUTH", hidden: true, header: _("REQUIRE_AUTHENTICATION"), width: 50, hideable: false, align: "left"},
{id: "MESS_ACCOUNT", dataIndex: "MESS_ACCOUNT", hidden: false, header: _("ID_EMAIL_SERVER_ACCOUNT_FROM"), width: 130, hideable: true, align: "left"},
{id: "MESS_PASSWORD", dataIndex: "MESS_PASSWORD", hidden: true, header: _("ID_PASSWORD"), width: 130, hideable: false, align: "left"},
{id: "MESS_INCOMING_PORT", dataIndex: "MESS_INCOMING_PORT", hidden: true, header: _("ID_EMAIL_SERVER_PORT"), width: 50, hideable: true, align: "center", renderer: rendererMessIncomingPort},
{id: "MESS_RAUTH", dataIndex: "MESS_RAUTH", hidden: true, header: _("REQUIRE_AUTHENTICATION"), width: 50, hideable: false, align: "left"},
{id: "MESS_ACCOUNT", dataIndex: "MESS_ACCOUNT", hidden: false, header: _("ID_EMAIL_SERVER_ACCOUNT_FROM"), width: 130, hideable: true, align: "left"},
{id: "MESS_PASSWORD", dataIndex: "MESS_PASSWORD", hidden: true, header: _("ID_PASSWORD"), width: 130, hideable: false, align: "left"},
{id: "MESS_FROM_MAIL", dataIndex: "MESS_FROM_MAIL", hidden: false, header: _("ID_FROM_EMAIL"), width: 130, hideable: true, align: "left"},
{id: "MESS_FROM_NAME", dataIndex: "MESS_FROM_NAME", hidden: false, header: _("ID_FROM_NAME"), width: 150, hideable: true, align: "left"},
{id: "SMTPSECURE", dataIndex: "SMTPSECURE", hidden: false, header: _("USE_SECURE_CONNECTION"), width: 140, hideable: true, align: "center", renderer: rendererMessSmtpSecure},
{id: "MESS_TRY_SEND_INMEDIATLY", dataIndex: "MESS_TRY_SEND_INMEDIATLY", hidden: true, header: _("SEND_TEST_MAIL"), width: 50, hideable: false, align: "left"},
{id: "MAIL_TO", dataIndex: "MAIL_TO", hidden: false, header: _("MAIL_TO"), width: 150, hideable: true, align: "left"},
{id: "MESS_TRY_SEND_INMEDIATLY", dataIndex: "MESS_TRY_SEND_INMEDIATLY", hidden: true, header: _("SEND_TEST_MAIL"), width: 50, hideable: false, align: "left"},
{id: "MAIL_TO", dataIndex: "MAIL_TO", hidden: false, header: _("MAIL_TO"), width: 150, hideable: true, align: "left"},
{id: "MESS_DEFAULT", dataIndex: "MESS_DEFAULT", hidden: false, header: _("ID_EMAIL_SERVER_DEFAULT"), width: 50, hideable: true, align: "center", renderer: rendererMessDefault}
]
});
@@ -1129,7 +1234,7 @@ emailServer.application = {
{
var record = grdpnlMain.getSelectionModel().getSelected();
if (typeof(record) != "undefined") {
if (typeof (record) != "undefined") {
Ext.getCmp("btnSave").disable();
EMAILSERVEROPTION = "UPD";
@@ -1157,14 +1262,14 @@ emailServer.application = {
//Initialize events
grdpnlMain.on(
"rowcontextmenu",
function (grid, rowIndex, evt)
{
var sm = grid.getSelectionModel();
sm.selectRow(rowIndex, sm.isSelected(rowIndex));
},
this
);
"rowcontextmenu",
function (grid, rowIndex, evt)
{
var sm = grid.getSelectionModel();
sm.selectRow(rowIndex, sm.isSelected(rowIndex));
},
this
);
grdpnlMain.addListener("rowcontextmenu", onMnuContext, this);
@@ -1178,6 +1283,10 @@ emailServer.application = {
autoScroll: false,
items: [grdpnlMain]
});
if (errorMessageIfNotAuthenticate && errorMessageIfNotAuthenticate !== "") {
Ext.MessageBox.alert(_("ID_INVALID_DATA"), errorMessageIfNotAuthenticate);
}
}
}