This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.php
332 lines (274 loc) · 10.3 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<?php
// ****************************************************************************
//
// ZZJ Audit Tool v1.5
// Copyright (C) 2010 ZigZagJoe ([email protected]) and
// Copyright (C) 2012 Equto ([email protected])
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License,or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc.,59 Temple Place,Suite 330,Boston,MA 02111-1307 USA
//
// ****************************************************************************
ini_set("zlib.output_compression", "On");
ini_set("zlib.output_compression", 4096);
if( isset( $_SERVER['HTTPS'] ) ) {
define("URL_SCHEME", "https" );
}
else {
define("URL_SCHEME", "http" );
}
define("SELF_URL", URL_SCHEME."://" . $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?");
define("AUDIT_PHP", true);
$cookielogin = false;
$charSelect=true;
$infoBarFunctions=array();
$footerFunctions=array();
require_once("eve.php");
require_once("audit.funcs.php");
require_once("audit.views.php");
if(isset($_GET['code']) && defined("SSO_URL")){
require_once ("ccpOAuth.php");
$sso = new ccpOAuth(SSO_URL, SSO_CLIENTID, SSO_SECRET, SSO_CALLBACK, $curl, false);
$token = $sso->getToken($_GET['code']);
redirect("?accessToken=$token");
}
if(defined("allow_login")&&allow_login==true) {
require_once("login.php");
}
if(!isset($_SESSION)){
session_start();
}
$_SESSION['redirect']="index.php";
if (isset($_GET['newapi']))
clear_api_cookie();
// load variables n such - defined here temporary before being set to constants later on
if (isset($_GET['usid']))
$userid = trim($_GET['usid']);
if (isset($_GET['apik']))
$apikey = trim($_GET['apik']);
if (isset($_GET['chid']))
$chid = trim($_GET['chid']);
if (isset($_GET['accessToken'])) {
$userid = trim($_GET['accessToken']);
$apikey = "";
define("SSO_MODE",true);
}
if(!defined("SSO_MODE")){
define("SSO_MODE",false);
}
if (isset($_GET['key']))
$short_api_key = trim($_GET['key']);
if (!login_load_creds($Db, (isset($userid) && isset($apikey) || isset($short_api_key)))) {
// handle cookie stuff
if (isset($_COOKIE["api"]) && ($_COOKIE["api"] != "") && !isset($userid) && !isset($short_api_key)) { // if a cookie was present, and we were not passed args via get, try to use what is in the cookie
$login = explode(',',$_COOKIE["api"]);
$cookielogin = true;
if ($login[0] == "api") {
$userid = trim($login[1]);
$apikey = trim($login[2]);
if (count($login) > 3)
$chid = trim($login[3]);
} else
$short_api_key = trim($login[1]);
$_GET['save'] = "1";
}
} else
$_GET['save'] = "1";
if (isset($short_api_key)) { // get stored apikey
$charSelect=false;
$ret = retrieve_api_key($Db, $short_api_key);
if ($ret != null) {
$chid = $ret["chid"];
$userid = $ret["usid"];
$apikey = $ret["apik"];
} else {
unset($short_api_key); // invalid key
$cookielogin = false;
}
}
if(!isset($chid)&&isset($_GET['chid'])){
$chid = trim($_GET['chid']);
$charSelect=true;
}
define("COOKIE_LOGIN", $cookielogin);
if ((!isset($apikey) || !isset($userid)) && !isset($short_api_key)) {
$info = "";
if (isset($_GET['fittingid'])) {
$result=$Db->selectWhere(FITTINGS_TABLE,["keyv"=>$_GET['fittingid']]);
if ($result != false && $result->rows) {
// yay! got a cached value
$row = $result->results[0];
$info = "Your ability to use the fitting '$row[name]' ($row[ship]) will be shown after you log in.";
}
$Db->close();
}
api_input($info); // die
}
if(!isset($_SESSION['redFlagText']))
$_SESSION['redFlagText']="";
if(!isset($_SESSION['redFlagIds']))
$_SESSION['redFlagIds']=array();
define("USER_ID", $userid);
define("API_KEY",$apikey);
$multiplechars = false;
if(SSO_MODE)
$keyInfo = cache_api_retrieve($Db,"/account/APIKeyInfo.xml.aspx", array("accessToken"=>USER_ID),5*60)->value;
else
$keyInfo = cache_api_retrieve($Db,"/account/APIKeyInfo.xml.aspx", array("keyID"=>USER_ID, "vCode" => API_KEY),5*60)->value;
if (!is_object($keyInfo)||$keyInfo->error)
fatal_error("Unable to load API. Verify the key is correct and not expired.");
define("KEY_MASK",(float)$keyInfo->result->key["accessMask"]);
$multiplechars = count($keyInfo->result->key->rowset->row) > 1;
if (!$multiplechars)
$chid = (string)$keyInfo->result->key->rowset->row[0]["characterID"];
if (isset($chid)) {
$char = $keyInfo->api->xpath("//row[@characterID='$chid']");
if (count($char) == 0)
fatal_error("The character ID was not found on this account.");
define("CHAR_NAME",(string)$char[0]["characterName"]);
}
define("KEY_TYPE",(string)$keyInfo->result->key["type"]);
if (KEY_TYPE == "Corporation") {
define("CORP_MODE",true);
define("CORP_ID",(string)$keyInfo->result->key->rowset->row[0]["corporationID"]);
define("CORP_NAME",(string)$keyInfo->result->key->rowset->row[0]["corporationName"]);
$multiplechars = false;
} else
define("CORP_MODE",false);
if (isset($short_api_key)&&$charSelect)
$urlAuthInfo = "key=$short_api_key&chid=$chid";
elseif (isset($short_api_key)&&!$charSelect)
$urlAuthInfo = "key=$short_api_key";
elseif (SSO_MODE)
$urlAuthInfo = "accessToken=".USER_ID;
else
$urlAuthInfo = (isset($chid) ? "chid=$chid&" :"") . "usid=" . USER_ID . "&apik=" . API_KEY ;
define("FULL_URL", /*SELF_URL .*/ "?" . $urlAuthInfo . ((isset($_GET['save']) && $_GET['save'] == "1") ? "&save=1":""));
/* . ((!isset($_GET['view']) && isset($_GET['fittingid'])) ? "&fittingid=$_GET[fittingid]" : "")*/
if ($multiplechars && !isset($chid)) { // must resolve a character id
if (!isset($chars))
$chars = $Db->fetchApiChars(USER_ID, API_KEY);
character_select($Db, $chars);
}
define("CHAR_ID",$chid);
define("USER_NAME",CORP_MODE ? CORP_NAME: CHAR_NAME); // set to corp name or char name depending on key type
if (!CORP_MODE && isset($_GET['save']) && $_GET['save'] == "1") { // save api key into a cookie if present
if (isset($short_api_key)) {
$auth="key,$short_api_key";
} else
$auth="api," . USER_ID . "," . API_KEY . "," .CHAR_ID;
setcookie("api",$auth,time()+60*60*24*30);
}
// load pages into registered_pages (all pages),eligible_pages (supported by key type),enabled_pages
require_once("audit.pages.php");
if (isset($_GET['makeshorturl'])) {
$key = make_short_key($Db,USER_ID,API_KEY,CHAR_NAME,CHAR_ID);
if ($key) {
header("Location: ".SELF_URL."key=$key" . (isset($_GET['view']) ? "&view=".$_GET['view'] : ""));
die("<html><body><a href=\"" .SELF_URL."key=$key" . (isset($_GET['view']) ? "&view=".$_GET['view'] : "") . "\">Click here to continue.</a><body></html>");
} else
fatal_error("Unable to create key.","Please try again later.",true);
}
$infobar = "<span id='infobar' class=\"infobar\">< ";
$getpage = "none";
if (isset($_GET['view'])) {
$getpage = trim($_GET['view']);
if (!isset($eligible_pages[$getpage]))
$getpage = "none";
}
foreach ($eligible_pages as $name=>$page) {
if (isset($enabled_pages[$name])) {
if ($getpage == "none")
$getpage = $name;
if ($name != $getpage) {
$infobar .= "<a href=\"" . FULL_URL . "&view=$name\">$name</a>";
} else
$infobar .= "<span class=\"current_page\">$name</span>";
} else {
$infobar .= "<span class=\"disabled_page\">$name</span>";
}
$infobar .= " ";
}
if ($getpage == "none")
fatal_error("This API has no pages that the Jackknife can display.");
define("PAGE_VIEW", $getpage);
$infobar .= "| ";
$infobar .= "<a href=\"".SELF_URL."newapi\">new api</a> ";
if ($multiplechars&&$charSelect)
if(isset($short_api_key))
$infobar .= "<a href=\"".SELF_URL."key=$short_api_key\">char select</a> ";
else
$infobar .= "<a href=\"".SELF_URL."usid=". USER_ID."&apik=".API_KEY. ((isset($_GET['save']) && $_GET['save'] == "1") ? "&save=1":"")."\">char select</a> ";
if (!isset($short_api_key)) {
$infobar .= "<a href=\"".FULL_URL."&makeshorturl&view=".PAGE_VIEW."\">short url</a> ";
}
$infobar .= "|<a id='redFlag' href=\"#redflag\">Set Red Flags</a> ";
foreach($infoBarFunctions as $function){
$infobar.="| ".$function();
}
$infobar .= "> <b>" . strtoupper(KEY_TYPE);
$infobar.="</b></span>";
//////// FINAL OUTPUT
if (PAGE_VIEW == "onepage") {
insert_header("Ataglance for " . USER_NAME);
echo $infobar . "<br>";
$next = 1;
$time_start2 = microtime_float();
foreach($enabled_pages as $name => $page) {
if ($page == "onepage")
continue;
$error = !$page->GetOutput($Db);
if ($error) {
//fatal_error("API: " . $page->Output);
} else {
echo "<br>";
echo "<a name=\"s".($next-1)."\"></a>";
echo "<span style=\"font-size: 70%\"><a href=\"#s$next\">skip to next section</a></span><br>";
$next++;
echo "<h2>" . ucfirst($name) . "</h2>";
if ($page->Header != "")
echo $page->Header . "<br>";
echo $page->Output . "<hr>";
}
}
echo "<a name=\"s".($next-1)."\"></a>";
$time_end2 = microtime_float();
$time_exec = $time_end2 - $time_start2;
echo "<br><span style=\"font-size:80%;\"><a href=\"#top\">top</a></span><br>\n";
echo "<span style=\"font-size:80%;\">";
echo "\n".$Db->getCount()." queries<br>";
echo "exec time: $time_exec s<br>";
echo "</span>";
echo "</body></html>";
} else {
$page = $eligible_pages[PAGE_VIEW];
$error = !$page->GetOutput($Db);
echo $infobar . "<br>";
if ($error) {
fatal_error("API: " . $page->Output,"",true);
} else {
$page->SetHeaders();
insert_header($page->Title);
if ($page->Updated)
echo "<span class=\"updated_text\">" . $page->Updated . "</span><br>";
if ($page->Header != "") {
echo $page->Header . "<br>";
} else
echo "<span style=\"font-size:450%\">". USER_NAME . "</span><br>";
echo $page->Output . "<br>";
echo $page->Times . "<br>";
echo "</body></html>";
}
}
?>