setApplicationName('Login to GPS LogisticMaps'); $gClient->setClientId($google_client_id); $gClient->setClientSecret($google_client_secret); $gClient->setRedirectUri($google_redirect_url); $gClient->setDeveloperKey($google_developer_key); $google_oauthV2 = new Google_Oauth2Service($gClient); if ($gClient->getAccessToken()) { $user = $google_oauthV2->userinfo->get(); $user_id = $user['id']; $_GET['auth'] = $user_id; $user_name = filter_var($user['name'], FILTER_SANITIZE_SPECIAL_CHARS); $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL); $profile_url = filter_var($user['link'], FILTER_VALIDATE_URL); $profile_image_url = filter_var($user['picture'], FILTER_VALIDATE_URL); $personMarkup = "$email
"; $_SESSION['token'] = $gClient->getAccessToken(); $authID = $user_id; } if (isset($_REQUEST['reset'])){ unset($_SESSION['token']); $gClient->revokeToken(); mysql_query("DELETE FROM users_google WHERE google_id = '".$_GET['reset']."' AND user = '".$_SESSION['login']."'"); header('Location: /options/integration/'); return; } if (isset($_GET['code'])){ $gClient->authenticate($_GET['code']); $_SESSION['token'] = $gClient->getAccessToken(); #header('Location: ' . filter_var($google_redirect_url, FILTER_SANITIZE_URL)); header('Location: /options/integration/'); return; } if (isset($_GET['auth']) || isset($authID)){ $authID = $_GET['auth']; if ($authID == ''){ if ($gClient->getAccessToken()) { $user = $google_oauthV2->userinfo->get(); $user_id = $user['id']; $_GET['auth'] = $user_id; $user_name = filter_var($user['name'], FILTER_SANITIZE_SPECIAL_CHARS); $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL); $profile_url = filter_var($user['link'], FILTER_VALIDATE_URL); $profile_image_url = filter_var($user['picture'], FILTER_VALIDATE_URL); $personMarkup = "$email
"; $_SESSION['token'] = $gClient->getAccessToken(); } else { $authUrl = $gClient->createAuthUrl(); header('Location: '.$authUrl); return; } } foreach($_SESSION['servers'] as $server => $ip){ $sdb_name = $ip; $user_name = "traccar"; $user_password = "1bv050bv"; $db_name = "traccar"; $GLOBALS['link'] = mysql_connect($sdb_name, $user_name, $user_password); mysql_select_db($db_name, $GLOBALS['link']); mysql_query('SET NAMES utf8'); $users = mysql_query("SELECT user, google_email FROM users_google WHERE google_id = '".mysql_real_escape_string($authID)."'"); if ($user = mysql_fetch_array($users)){ $logins = mysql_query("SELECT login, status, email, phone, username, usersurname, regdate, map, status, invoice, invoiceStatus FROM users WHERE login = '".$user['user']."'"); if ($login = mysql_fetch_array($logins)){ $_SESSION['login'] = $login['login']; $_SESSION['username'] = $login['username'].' '.$login['usersurname']; $_SESSION['email'] = $login['email']; $_SESSION['phone'] = $login['phone']; $_SESSION['regdate'] = $login['regdate']; $_MAP = array('0' => 'ROADMAP', '1' => 'HYBRID', '2' => 'SATELLITE', '3' => 'TERRAIN'); $_SESSION['map'] = $_MAP[substr($login['map'],0,1)]; $_SESSION['status'] = $login['status']; $_SESSION['invoice'] = $login['invoice']; $_SESSION['invoiceStatus'] = $login['invoiceStatus']; $devices = mysql_query("SELECT * FROM devices WHERE accountID = '".$_SESSION['login']."' OR subuserID LIKE '%|".$_SESSION['login']."|%'"); $_SESSION['devices'] = array(); $_SESSION['devices']['id'] = array(); $_SESSION['devices']['imei'] = array(); $_SESSION['devices']['spz'] = array(); $_SESSION['devices']['nic'] = array(); $_SESSION['devices']['odo'] = array(); $_SESSION['devices']['name'] = array(); $_SESSION['devices']['modules'] = array(); while ($device = mysql_fetch_array($devices)){ if ($device['spz_pr'] == '') $device['spz_pr'] = ' '; array_push($_SESSION['devices']['id'], $device['id']); array_push($_SESSION['devices']['imei'], $device['uniqueId']); array_push($_SESSION['devices']['spz'], $device['spz']); array_push($_SESSION['devices']['nic'], $device['spz_pr']); array_push($_SESSION['devices']['name'], $device['name']); array_push($_SESSION['devices']['modules'], $device['modules']); array_push($_SESSION['devices']['odo'], $device['odo'] + $device['odometerOffsetKM']); } } header('Location: /dash/'); return; } } } header('Location: ' . filter_var('https://gps.Lokace.eu', FILTER_SANITIZE_URL)); //header('Location: /options/integration/'); ?>