/
index1.php
163 lines (143 loc) · 5.56 KB
/
index1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
require_once 'Gdata_OAuth_Helper.php';
require_once 'siteUtils.php';
require_once 'siteConfig.php';
require_once 'dbFuncs.php';
session_start();
require_once 'openIdAuth.php';
$APP_URL = getAppUrl();
$openId = new Gamut_OpenId();
$consumer = new Gdata_OAuth_Helper($CONSUMER_KEY, $CONSUMER_SEC);
$dbFuncsObj = new dbFuncs(false);
$dbFuncsObj->doConnect();
/**
* This switch statement performs selective processing
* based on the supplied 'action'.
**/
switch (@$_REQUEST['action'])
{
case 'request_token':
$_SESSION['ACCESS_TOKEN'] = $dbFuncsObj->getAccessToken('mail2naresh@gmail.com');
if (isset($_SESSION['ACCESS_TOKEN']))
{
$accessToken = unserialize($_SESSION['ACCESS_TOKEN']);
//print $accessToken;
$httpClient = $accessToken->getHttpClient($consumer->getOauthOptions());
$emailService = new Zend_Gdata_EMail($httpClient);
$emailId = $emailService->getEMailFeed();
print $emailId;
renderHTML('User logged-in with access token: <br> <a href="'. getRedirectUrl().'" >Logout </a>' , false);
}
else
{
$_SESSION['REQUEST_TOKEN'] = serialize(
$consumer->fetchRequestToken(
implode(' ', $SCOPES), $APP_URL . '?action='.getActionString('access')));
$consumer->authorizeRequestToken();
}
break;
case 'access_token':
if (!isset($_SESSION['ACCESS_TOKEN']))
{
$_SESSION['ACCESS_TOKEN'] = serialize($consumer->fetchAccessTokenFromOpenId($_SESSION['REQUEST_TOKEN']));
$dbFuncsObj->setAccessToken($_SESSION['OPENID_EMAIL'], $_SESSION['ACCESS_TOKEN'], true);
}
if ($dbFuncsObj->validateAccessToken($_SESSION['OPENID_EMAIL'], $_SESSION['ACCESS_TOKEN']) == false)
{
header('Location: ' . getRedirectUrl());
}
else
{
global $PYTHON_PATH;
global $BACKEND_DIR;
global $BACKEND_BIN;
//Trigger the backend to download emails.
/*$command = $PYTHON_PATH.' '.$BACKEND_DIR.$BACKEND_BIN.' '.$_SESSION['OPENID_EMAIL'].'&';
//$command = 'rm -rf /home/naresh/LifeParser/Data/GMail_DataStore/mail2naresh@gmail.com';
exec($command, $output, $retVal);
print_r ($output);
$command = 'rm -rf /home/naresh/LifeParser/Analysis/mail2naresh@gmail.com*';
$command = 'rm -rf /home/naresh/LifeParser/Data/GMail_DataStore/mail2naresh@gmail.com';
exec($command, $output, $retVal);*/
header('Location: ' . constructPageUrl('graphDisplay.php'));
}
break;
case 'logout':
session_destroy();
header('Location: ' . $APP_URL);
exit;
case 'openid_auth':
$authorizedToken = $openId->getRequestToken();
$_SESSION['REQUEST_TOKEN'] = $authorizedToken;
$_SESSION['OPENID_EMAIL'] = $openId->getEMailId();
$_SESSION['OPENID_FIRSTNAME'] = $openId->getFirstName();
$_SESSION['OPENID_LASTNAME'] = $openId->getLastName();
header('Location: ' . getRedirectUrl('access'));
break;
case 'gadget_login':
global $openId;
$redirUrl = constructPageUrl() . '?action=' . getActionString('openid_auth');
header('Location: '. $openId->getUrl($redirUrl));
break;
case 'login':
default:
if (!isset($_SESSION['ACCESS_TOKEN']))
{
renderHTML('Click here to sign-in', true);
}
else
{
renderHTML('User: ' . $_SESSION['OPENID_FIRSTNAME'] . ' ' . $_SESSION['OPENID_LASTNAME'] . '<br/> EMail: <b>' . $_SESSION['OPENID_EMAIL'] . '</b> logged-in with access token: <br> <a href="'. getRedirectUrl().'" >Logout </a>' , false);
}
break;
}
$dbFuncsObj->doDisconnect();
function renderHTML ($displayMessage, $isLink)
{
?>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="default.css" rel="stylesheet" type="text/css">
<title>Life Parser</title>
</head>
<body>
<table align="center" border="0" height="80%" width="80%"
bgcolor="#FFFFFF">
<tbody>
<tr><td class="siteTitle">Life Parser</td></tr>
<tr rowspan="2"><td colspan="2"></td></tr>
<tr>
<td>
<table width=100% height=100% align="center" border="0">
<tbody>
<tr height=100%>
<td width=50%>Gmail account is required to use this site.<br>
</td>
<td width=50%>
<?php
if ($isLink == true)
{
?>
<a href="<?php global $openId; $redirUrl = constructPageUrl() . '?action=' . getActionString('openid_auth');
echo $openId->getUrl($redirUrl); ?>"><?php echo $displayMessage; ?></a>
<?php
}
else
{
echo $displayMessage;
}
?>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tbody>
</table>
</body>
</html>
<?php
}
?>