Commit a04cd42c authored by lang's avatar lang

refs #2675 - fix google authorization. Should now be more robust, and is set...

refs #2675 - fix google authorization. Should now be more robust, and is set per user. Will require re-authorizaton on reboot for now until dbtables get figured out.
parent 353ea12d
......@@ -6,7 +6,7 @@ error_reporting(-1);
function initAuth($mediadbADO, $dbADO, $output){
$client_id="252010262386-d8djlkh01ag0v0r514jf1lgcflpodb1c.apps.googleusercontent.com";
$client_id="252010262386-d8djlkh01ag0v0r514jf1lgcflpodb1c.apps.googleusercontent.com";
$client_secret="ibgv0ECx-N5bK_Abj4cXR1rj";
$driveScope="https://www.googleapis.com/auth/drive%20https://www.googleapis.com/auth/drive.metadata";
$photosScope="%20https://picasaweb.google.com/data/";
......
......@@ -23,50 +23,22 @@ if (! isset($_GET['code'])) {
//header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
$deviceTemplate=2316;
$deviceQuery = 'SELECT
DeviceData.Description AS dd_Description,
Device_DeviceData.FK_DeviceData,
Device.PK_Device,
ParameterType.Description AS typeParam,
Device_DeviceData.IK_DeviceData
FROM DeviceData
INNER JOIN ParameterType ON FK_ParameterType = PK_ParameterType
INNER JOIN Device_DeviceData ON Device_DeviceData.FK_DeviceData=PK_DeviceData
INNER JOIN Device ON FK_Device=PK_Device
LEFT JOIN DeviceTemplate_DeviceData ON DeviceTemplate_DeviceData.FK_DeviceData=Device_DeviceData.FK_DeviceData AND DeviceTemplate_DeviceData.FK_DeviceTemplate=Device.FK_DeviceTemplate
WHERE Device.FK_DeviceTemplate=2316 AND Device_DeviceData.FK_DeviceData=59 ';
$res = $dbADO->Execute($deviceQuery);
$ddForDevice = $res->FetchRow();
file_put_contents('/tmp/user'.$_SESSION['userID'].'.json', $_SESSION['access_token']);
$out="";
$out.="<br>";
$out.="Device:".$ddForDevice['PK_Device'];
$oldData= json_decode($ddForDevice['IK_DeviceData']);
$newDataString= array( $_SESSION['userID']=>$_SESSION['access_token'] );
$accessData = json_decode($_SESSION['access_token']);
$parsedOldData= $oldData;
$parsedOldData[$_SESSION['userID']] = $accessData;
$newDataString = json_encode($parsedOldData);
$updateQuery="UPDATE Device_DeviceData SET IK_DeviceData= ' ".$newDataString." ' where FK_DEVICE=".$ddForDevice['PK_Device']." AND FK_DeviceData=59";
$dbADO->Execute($updateQuery);
$out='Completed google authorization for '.$_SESSION['hh_username'].'.<br>';
$jsonArr = json_decode($_SESSION['access_token'], true );
/*
$out='Completed google authorization for '.$_SESSION['hh_username'].'.<br>';
$jsonArr = json_decode($_SESSION['access_token'], true );
$out.="Access Token:".$jsonArr['access_token']."<br>";
$out.="Token Type:".$jsonArr['token_type']."<br>";
$out.="Expires:".$jsonArr['expires_in']."<br>";
$out.="created:".$jsonArr['created']."<br>";
$out.="Refresh Token:".$jsonArr['refresh_token']."<br>";
$out.="ID Token: Not Shown<br><br>";
*
*/
$out.="Writing to file.<br>";
print_r($newDataString);
$out.="Writing to device data.<br>";
//$output -> setScriptInHead($scriptInHead);
$output -> setReloadLeftFrame(false);
......
......@@ -7,7 +7,7 @@ require_once 'Google/Client.php';
require_once 'Google/autoload.php';
$client = new Google_Client();
$client->setAuthConfigFile('/tmp/client_secret.json');
$client->setAuthConfigFile('/var/www/lmce-admin/operations/cloudServices/includes/client_secret.json');
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/lmce-admin/operations/cloudServices/googleOauthCallback.php');
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
......
......@@ -22,8 +22,13 @@ function refreshToken($token){
}
function getClient($auth){
$latestToken=json_decode( file_get_contents(CREDENTIALS_PATH) , true);
if(empty($latestToken)){
}
$secret = file_get_contents(CLIENT_SECRET_PATH);
if(empty( $latestToken ) && !empty($auth)){
$latestToken=$auth;
......
......@@ -2,31 +2,20 @@
function init_services($mediadbADO, $dbADO, $output){
$googleCheck=' SELECT
DeviceData.Description AS dd_Description,
Device_DeviceData.FK_DeviceData,
Device.PK_Device,
ParameterType.Description AS typeParam,
Device_DeviceData.IK_DeviceData
FROM DeviceData
INNER JOIN ParameterType ON FK_ParameterType = PK_ParameterType
INNER JOIN Device_DeviceData ON Device_DeviceData.FK_DeviceData=PK_DeviceData
INNER JOIN Device ON FK_Device=PK_Device
LEFT JOIN DeviceTemplate_DeviceData ON DeviceTemplate_DeviceData.FK_DeviceData=Device_DeviceData.FK_DeviceData AND DeviceTemplate_DeviceData.FK_DeviceTemplate=Device.FK_DeviceTemplate
WHERE Device.FK_DeviceTemplate=2316 AND Device_DeviceData.FK_DeviceData=59 ';
$gmailBox='<th class="tg-031e"> <a href="index.php?section=cloudServices&service=gmail&action=auth" ><img src="operations/cloudServices/images/gmail.gif" alt="gmail" ></a></th>';
$res = $dbADO->Execute($googleCheck);
$ddForDevice = $res->FetchRow();
$authfile = '/tmp/user'.$_SESSION['userID'].'.json';
$check = file_exists($authfile);
$gmailBox='<th class="tg-031e"> <a href="index.php?section=cloudServices&service=gmail&action=auth" >
<img src="operations/cloudServices/images/gmail.gif" alt="gmail" >
<br> Google Services are not enabled for '.$_SESSION['hh_username'].'. <br> Click to Authorize <br></a>
</th>';
$confData=json_decode($ddForDevice['IK_DeviceData'], true);
$userDataArray = $confData[$_SESSION['userID']];
if( !empty($userDataArray)){
if( $check){
$gmailBox='<th class="tg-031e">
<img src="operations/cloudServices/images/gmail.gif" alt="gmail" >
<br> Google Services are enabled. <a href="index.php?section=googleFiles">View Files.</a> <br>
</th>';
} else {
}
$out='<style type="text/css">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment