| Server IP : 138.197.176.125 / Your IP : 216.73.217.122 Web Server : Apache/2.4.41 (Ubuntu) System : Linux SuiteCRM-8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/vt84/ |
Upload File : |
<?php
/*******************************************************************************
* The content of this file is subject to the CRMTiger Pro license.
* ("License"); You may not use this file except in compliance with the License
* The Initial Developer of the Original Code is https://crmtiger.com/
* Portions created by CRMTiger.com are Copyright(C) CRMTiger.com
* All Rights Reserved.
******************************************************************************/
header("Content-Type:application/json");
require_once "vendor/autoload.php";
include_once 'include/Webservices/Relation.php';
include_once 'vtlib/Vtiger/Module.php';
include_once 'includes/main/WebUI.php';
require_once('include/utils/utils.php');
global $adb,$current_user;
$jsonStr = file_get_contents("php://input"); //read the HTTP body.
$jsonDecodeData = json_decode($jsonStr, true);
$tokenDetails = json_decode($jsonDecodeData['token'],true);
$currentUserId = $jsonDecodeData['userId'];
$outgoingId = $jsonDecodeData['outgoingId'];
$accessToken = $tokenDetails['access_token'];
$refreshToken = $tokenDetails['refresh_token'];
$expiresIn = $tokenDetails['expires_in'];
$currentTime = date('Y-m-d H:i:s');
$token = "'".$accessToken."'";
$refreshTokenData = "'".$refreshToken."'";
$expiresToken = "'".$expiresIn."'";
$date = "'".$currentTime."'";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://graph.microsoft.com/v1.0/me",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer ".$accessToken
),
));
$response = curl_exec($curl);
$jsonDecodeData = json_decode($response, true);
$emailId = $jsonDecodeData['userPrincipalName'];
$displayName = $jsonDecodeData['displayName'];
$usersEmailId = "'".$emailId."'";
$userName = "'".$displayName."'";
$err = curl_error($curl);
$query2 = $adb->pquery("INSERT INTO `ctoffice_outgoingserver_token`(`user_id`, `token`,`refresh_token`,`token_generated_time`,`token_expires_in`,`users_emailid`, `display_name`) VALUES ($currentUserId, $token, $refreshTokenData, $date, $expiresToken, $usersEmailId, $userName)",array());
if ($outgoingId) {
$outgoingId = (int)$outgoingId;
$result = $adb->pquery("SELECT server FROM vtiger_systems WHERE id = ?", array($outgoingId));
if ($adb->num_rows($result) > 0) {
$currentServer = $adb->query_result($result, 0, 'server');
if ($currentServer !== 'smtp.auth.outlook.com') {
$adb->pquery("DELETE FROM vtiger_systems WHERE id = ?", array($outgoingId));
$newId = $adb->getUniqueId("vtiger_systems");
$adb->pquery(
"INSERT INTO vtiger_systems (id, server, server_type) VALUES (?, ?, ?)",
array($newId, 'smtp.auth.outlook.com', 'email')
);
}
} else {
$newId = $adb->getUniqueId("vtiger_systems");
$adb->pquery(
"INSERT INTO vtiger_systems (id, server, server_type) VALUES (?, ?, ?)",
array($newId, 'smtp.auth.outlook.com', 'email')
);
}
} else {
$newId = $adb->getUniqueId("vtiger_systems");
$adb->pquery(
"INSERT INTO vtiger_systems (id, server, server_type) VALUES (?, ?, ?)",
array($newId, 'smtp.auth.outlook.com', 'email')
);
}
echo json_encode(array('status' => 'success'));
?>