-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.php
executable file
·259 lines (179 loc) · 7.17 KB
/
index.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
require 'config.php';
require '/var/www/classes/Session.class.php';
require '/var/www/classes/System.class.php';
//$session = new Session();
$loadFacebook = FALSE;
$loadTwitter = FALSE;
$remembered = FALSE;
require '/var/www/classes/Facebook.class.php';
if(isset($_COOKIE['PHPSESSID'])){
$session = new Session();
}
if(!isset($_SESSION['id'])){
if(isset($_GET['nologin'])){
$_SESSION = NULL;
session_destroy();
header("Location:index");
exit();
}
if($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['code']) || isset($_SESSION['FBLOGIN'])){
$fbServerURL = 'http://hackerexperience.com/';
if(isset($_SERVER['HTTP_HOST'])){
if($_SERVER['HTTP_HOST'] == 'br.hackerexperience.com'){
$fbServerURL = 'http://br.hackerexperience.com/';
} elseif($_SERVER['HTTP_HOST'] == 'en.hackerexperience.com'){
$fbServerURL = 'http://en.hackerexperience.com/';
}
}
// 2019: Update the links, the appId and the appSecret below in order to enable FB login
switch($fbServerURL){
case 'http://hackerexperience.com/':
$appID = 0;
$appSecret = 'REDACTED';
break;
case 'http://br.hackerexperience.com/':
$appID = 0;
$appSecret = 'REDACTED';
break;
case 'http://en.hackerexperience.com/':
$appID = 0;
$appSecret = 'REDACTED';
break;
}
$facebook = new Facebook(array(
'appId' => $appID,
'secret' => $appSecret,
'cookie' => true
));
$user = $facebook->getUser();
if($user){
try {
$userInfo = $facebook->api('/me');
} catch (FacebookApiException $e) {
echo $e;
error_log($e);
$user = NULL;
}
}
$pdo = PDO_DB::factory();
if($user){
$sql = 'SELECT COUNT(*) AS total, users.login
FROM users_facebook
LEFT JOIN users
ON users.id = users_facebook.gameID
WHERE userID = '.$user;
$fbInfo = $pdo->query($sql)->fetch(PDO::FETCH_OBJ);
if($fbInfo->total == 0){
//first login. need to determine one username and then use the usercreate function
$loadFacebook = TRUE;
$_SESSION['SPECIAL_ID'] = 'fb';
} else {
require '/var/www/classes/Database.class.php';
$database = new LRSys();
$database->login($fbInfo->login, '0', 'facebook');
header("Location:index");
}
}
} elseif((isset($_GET['oauth_verifier']) && !isset($_SESSION['twitter_data'])) || isset($_SESSION['TTLOGIN'])){
if(!isset($_SESSION['TTLOGIN'])){
$error = FALSE;
if(!isset($_SESSION['oauth_token']) || !isset($_SESSION['oauth_token_secret'])){
$error = TRUE;
$msg = 'Invalid authentication token. Please, try again.';
}
if($error){
$_SESSION = NULL;
session_destroy();
session_start();
$_SESSION['MSG'] = $msg;
$_SESSION['MSG_TYPE'] = 'error';
$_SESSION['TYP'] = 'home';
header("Location:index");
exit();
}
require 'twitter/twitteroauth.php';
// Modify `REDACTED` to enable twitter login
$twitteroauth = new TwitterOAuth('REDACTED', 'REDACTED', $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$twitteroauth->host = "https://api.twitter.com/1.1/";
$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']);
$_SESSION['access_token'] = $access_token;
$user_info = $twitteroauth->get('account/verify_credentials');
if(array_key_exists('errors', $user_info)){
$_SESSION = NULL;
session_destroy();
session_start();
$_SESSION['MSG'] = $user_info->errors[0]->message;
$_SESSION['MSG_TYPE'] = 'error';
$_SESSION['TYP'] = 'home';
header("Location:index");
exit();
}
$_SESSION['twitter_data'] = $user_info;
} else {
$user_info = $_SESSION['twitter_data'];
unset($_SESSION['twitter_data']);
}
$pdo = PDO_DB::factory();
$_SESSION['QUERY_COUNT'] += 1;
$sql = 'SELECT COUNT(*) AS total, users.login
FROM users_twitter
LEFT JOIN users
ON users.id = users_twitter.gameID
WHERE userID = '.$user_info->id;
$ttInfo = $pdo->query($sql)->fetch(PDO::FETCH_OBJ);
if($ttInfo->total == 0){
//first login. need to determine one username and then use the usercreate function
$loadTwitter = TRUE;
$_SESSION['SPECIAL_ID'] = 'tt';
} else {
require '/var/www/classes/Database.class.php';
$database = new LRSys();
$database->login($ttInfo->login, '0', 'twitter');
header("Location:index");
}
} elseif(isset($_SESSION['twitter_data'])){
$loadTwitter = TRUE;
} else {
// 2019: User is not doing any type of social login, so I'll check if it's logged in the database (remember me feature)
//não está fazendo nenhum tipo de social login, vou verificar se está logado no banco (remember me)
require '/var/www/classes/RememberMe.class.php';
$key = pack("H*", 'REDACTED');
$remember = new RememberMe($key, PDO_DB::factory());
$remember->rememberlogin();
$remembered = TRUE;
}
}
if($loadFacebook){
require 'template/fbtpl.php';
} elseif($loadTwitter){
require 'template/tttpl.php';
} elseif (isset($_SESSION['id'])) {
$session = new Session();
if(!$remembered) require_once '/var/www/classes/Player.class.php';
$player = new Player($_SESSION['id']);
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST)){
$player->handlePost();
}
require 'template/contentStart.php';
if($session->issetMsg()){
$session->returnMsg();
}
if($_SESSION['ROUND_STATUS'] == 1){
$player->showIndex();
} else {
$player->showGameOver();
}
require 'template/contentEnd.php';
} else {
if(isset($_SESSION)) unset($_SESSION['GOING_ON']);
if(isset($_SESSION['SPECIAL_ID'])){
if($_SESSION['SPECIAL_ID'] == 'fb'){
require 'template/fbtpl.php';
} else {
require 'template/tttpl.php';
}
} else {
require 'template/default.php';
}
}