2015-11-09 11:01:11 -04:00
|
|
|
<?php
|
2018-03-23 09:41:40 -04:00
|
|
|
|
2015-12-18 09:57:40 -04:00
|
|
|
session_start();
|
2018-03-23 09:41:40 -04:00
|
|
|
require_once __DIR__ . '/../../../bootstrap/autoload.php';
|
2015-11-11 11:31:25 -04:00
|
|
|
require_once (dirname(__FILE__) . '/../../../gulliver/system/class.bootstrap.php');
|
2016-03-22 10:43:35 -04:00
|
|
|
require_once (dirname(__FILE__) . '/../../../gulliver/system/class.g.php');
|
2015-11-11 11:31:25 -04:00
|
|
|
|
|
|
|
|
$gmailToken = $_GET['gmailToken'];
|
|
|
|
|
$gmail = $_GET['gmail'];
|
|
|
|
|
$pmtoken = $_GET['pmtoken'];
|
|
|
|
|
$pmws = $_GET['pmws'];
|
|
|
|
|
$appUid = $_GET['appUid'];
|
|
|
|
|
$delIndex = $_GET['delIndex'];
|
|
|
|
|
$action = $_GET['action'];
|
|
|
|
|
$proUid = $_GET['proUid'];
|
|
|
|
|
$server = isset($_GET['server']) ? $_GET['server'] : '';
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2015-11-27 11:38:44 -04:00
|
|
|
//We do need the server to continue.
|
2018-03-23 09:41:40 -04:00
|
|
|
if (!isset($_GET['server']) || $server == "") {
|
|
|
|
|
throw new \Exception(Bootstrap::LoadTranslation('ID_GMAIL_NEED_SERVER'));
|
2015-11-27 11:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
//First check if the feature is enabled in the license.
|
2018-03-23 09:41:40 -04:00
|
|
|
$gCurl = curl_init('https://' . $server . '/api/1.0/' . $pmws . '/gmailIntegration/verifyGmailfeature/');
|
|
|
|
|
curl_setopt($gCurl, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $pmtoken));
|
|
|
|
|
curl_setopt($gCurl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
curl_setopt($gCurl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
curl_setopt($gCurl, CURLOPT_CONNECTTIMEOUT, 0);
|
2016-09-16 14:11:35 -04:00
|
|
|
curl_setopt($gCurl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
|
2018-03-23 09:41:40 -04:00
|
|
|
if (curl_exec($gCurl) === false) {
|
|
|
|
|
echo 'Curl error: ' . curl_error($gCurl);
|
2016-03-23 19:16:08 -04:00
|
|
|
error_log(Bootstrap::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR'));
|
2018-03-23 09:41:40 -04:00
|
|
|
die();
|
2016-09-16 14:11:35 -04:00
|
|
|
} else {
|
2018-03-23 09:41:40 -04:00
|
|
|
$gCurl_response = curl_exec($gCurl);
|
|
|
|
|
curl_close($gCurl);
|
|
|
|
|
$gResp = G::json_decode($gCurl_response);
|
2016-09-16 14:11:35 -04:00
|
|
|
if ($gResp === false) {
|
2018-03-23 09:41:40 -04:00
|
|
|
echo Bootstrap::LoadTranslation('ID_NO_LICENSE_FEATURE_ENABLED');
|
|
|
|
|
die();
|
2016-09-16 14:11:35 -04:00
|
|
|
}
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
set_time_limit(60);
|
|
|
|
|
|
2018-03-23 09:41:40 -04:00
|
|
|
$curl = curl_init('https://' . $server . '/api/1.0/' . $pmws . '/gmailIntegration/userexist/' . $gmail);
|
|
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $pmtoken));
|
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2018-03-23 09:41:40 -04:00
|
|
|
$curl_response = curl_exec($curl);
|
2015-11-09 11:01:11 -04:00
|
|
|
curl_close($curl);
|
2016-03-11 19:05:40 -04:00
|
|
|
$decodedResp = G::json_decode($curl_response);
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2018-03-23 09:41:40 -04:00
|
|
|
if (!is_object($decodedResp) || property_exists($decodedResp, 'error')) {
|
2017-10-13 07:57:22 -04:00
|
|
|
die($decodedResp->error->message);
|
2015-12-04 10:42:38 -04:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 11:38:44 -04:00
|
|
|
//getting the enviroment
|
|
|
|
|
$enviroment = $decodedResp->enviroment;
|
|
|
|
|
|
2018-03-23 09:41:40 -04:00
|
|
|
if (count($decodedResp->user) > 1) {
|
|
|
|
|
echo Bootstrap::LoadTranslation('ID_EMAIL_MORE_THAN_ONE_USER');
|
2017-10-13 07:57:22 -04:00
|
|
|
die;
|
2018-03-23 09:41:40 -04:00
|
|
|
} else if (count($decodedResp->user) < 1) {
|
|
|
|
|
echo Bootstrap::LoadTranslation('ID_USER_NOT_FOUND');
|
2017-10-13 07:57:22 -04:00
|
|
|
die;
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//validationg if there is an actual PM session
|
2018-03-23 09:41:40 -04:00
|
|
|
if (!isset($_SESSION['USER_LOGGED']) || $_SESSION['USER_LOGGED'] != $decodedResp->user['0']->USR_UID) {
|
|
|
|
|
$url = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' . $gmailToken;
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2017-10-13 07:57:22 -04:00
|
|
|
// init curl object
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
// define options
|
|
|
|
|
$optArray = array(
|
2018-03-23 09:41:40 -04:00
|
|
|
CURLOPT_URL => $url,
|
|
|
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
CURLOPT_SSL_VERIFYPEER => false,
|
|
|
|
|
CURLOPT_SSL_VERIFYHOST => false
|
2017-10-13 07:57:22 -04:00
|
|
|
);
|
|
|
|
|
// apply those options
|
|
|
|
|
curl_setopt_array($ch, $optArray);
|
|
|
|
|
// execute request and get response
|
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
|
$response = (G::json_decode($result));
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
|
|
//First validate if this user (mail) corresponds to a PM user
|
2018-03-23 09:41:40 -04:00
|
|
|
if (isset($response->email) && ($gmail == $response->email)) {
|
2017-10-13 07:57:22 -04:00
|
|
|
//If the email corresponds I get the username and with the gmail user_id the session is created.
|
2018-03-23 09:41:40 -04:00
|
|
|
if ($decodedResp->user['0']->USR_STATUS == "ACTIVE") {
|
2017-10-13 07:57:22 -04:00
|
|
|
//User Active! lets create the Session
|
|
|
|
|
@session_destroy();
|
|
|
|
|
session_start();
|
|
|
|
|
session_regenerate_id();
|
|
|
|
|
|
2021-11-24 21:00:16 +00:00
|
|
|
setcookie("workspaceSkin", $enviroment, time() + (24 * 60 * 60), "/sys" . $enviroment, null, G::is_https(), true);
|
2017-10-13 07:57:22 -04:00
|
|
|
|
|
|
|
|
$_SESSION = array();
|
|
|
|
|
$_SESSION['__EE_INSTALLATION__'] = 2;
|
|
|
|
|
$_SESSION['__EE_SW_PMLICENSEMANAGER__'] = 1;
|
|
|
|
|
$_SESSION['phpLastFileFound'] = '';
|
|
|
|
|
$_SESSION['USERNAME_PREVIOUS1'] = $decodedResp->user['0']->USR_USERNAME;
|
|
|
|
|
$_SESSION['USERNAME_PREVIOUS2'] = $decodedResp->user['0']->USR_USERNAME;
|
|
|
|
|
$_SESSION['WORKSPACE'] = $pmws;
|
2018-03-23 09:41:40 -04:00
|
|
|
$_SESSION['USR_FULLNAME'] = $decodedResp->user['0']->USR_FIRSTNAME . ' ' . $decodedResp->user['0']->USR_LASTNAME;
|
2017-10-13 07:57:22 -04:00
|
|
|
$_SESSION['__sw__'] = 1;
|
|
|
|
|
initUserSession(
|
2018-03-23 09:41:40 -04:00
|
|
|
$decodedResp->user['0']->USR_UID, $decodedResp->user['0']->USR_USERNAME
|
2017-10-13 07:57:22 -04:00
|
|
|
);
|
|
|
|
|
//session created
|
|
|
|
|
} else {
|
2018-03-23 09:41:40 -04:00
|
|
|
echo Bootstrap::LoadTranslation('ID_USER_NOT_ACTIVE');
|
2017-10-13 07:57:22 -04:00
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2018-03-23 09:41:40 -04:00
|
|
|
echo Bootstrap::LoadTranslation('ID_USER_DOES_NOT_CORRESPOND');
|
2017-10-13 07:57:22 -04:00
|
|
|
die;
|
|
|
|
|
}
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-23 09:41:40 -04:00
|
|
|
$_SESSION['server'] = 'https://' . $server . '/sys' . $pmws . '/en/' . $enviroment . '/';
|
|
|
|
|
$_SESSION['PMCase'] = 'cases/cases_Open?APP_UID=' . $appUid . '&DEL_INDEX=' . $delIndex . '&action=' . $action . '&gmail=1';
|
2015-11-11 11:31:25 -04:00
|
|
|
$_SESSION['PMProcessmap'] = 'designer?prj_uid=' . $proUid . '&prj_readonly=true&app_uid=' . $appUid;
|
|
|
|
|
$_SESSION['PMUploadedDocuments'] = 'cases/ajaxListener?action=uploadedDocuments';
|
|
|
|
|
$_SESSION['PMGeneratedDocuments'] = 'cases/casesGenerateDocumentPage_Ajax.php?actionAjax=casesGenerateDocumentPage';
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2018-03-23 09:41:40 -04:00
|
|
|
header('location:' . 'templateForm.php');
|
2015-11-09 11:01:11 -04:00
|
|
|
|