forked from whinis/eve-jacknife
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.func.php
193 lines (178 loc) · 5.38 KB
/
manage.func.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
<?php
function save_api_view(){
$apik="";
$vcode="";
if(isset($_GET['apik']))
$apik=$_GET['apik'];
if(isset($_GET['vcode']))
$vcode=$_GET['vcode'];
$addKey=<<<EOD
<h3> Please Name Your Key</h3>
<form id="api" action="manage.php?saveKey" method="post">
<table>
<tr><td>Key Name:</td><td><input type="textbox" name="keyName" id="keyName" size="30"></td></tr>
<tr><td>Api Key:</td><td><input type="textbox" name="apik" id="keyName" size="16" value="$apik"></td></tr>
<tr><td>vCode:</td><td><input type="textbox" name="vcode" id="keyName" size="80" value="$vcode"></td></tr>
<tr><td>Notes:</td><td><textarea name='notes' Cols='28' id='notes' style='resize:none;' onKeyDown="limitText(this,3000)"></textarea> </td></tr>
</table>
<input type="hidden" value='save' name='save'>
<input type="submit" value="Save Api">
</form>
EOD;
return $addKey;
}
function management_view($db){
// Table for management
$table=<<<EOD
<table id='keysTable' class="fancy" style="font-size:83%;" border=1>
<tr>
<th>
<a href="">Name</a>
</th>
<th>
<a href="">Type</a>
</th>
<th>
<a href="">Characters</a>
</th>
<th>
<a href="">Notes</a>
</th>
</tr>
EOD;
$apiResults=retrieve_api_keys($db);
if($apiResults){
$alt_b = false;
foreach($apiResults as $row){
$alt_b = !$alt_b;
$rand=rand();
$name=$row['keyName'];
$type=$row['type'];
$Characters=$row['characters'];
$key=$row['apiKey'];
$notes=$row['notes'];
if(!$notes)
$trunNotes="no notes";
elseif(strlen($notes)>140)
$trunNotes=substr($notes,0,130)." . . . ";
else
$trunNotes=$notes;
$id=$row['id'];
$class=($alt_b?"main":"alt");
$table.=<<<EOD
<tr keyID={$id} class="{$class}">
<td style="color: #FFA500"><a href="index.php?key={$key}" class="keyName">{$name}</a></td>
<td>{$type}</td>
<td>{$Characters}</td>
<td class="keyNotes">{$trunNotes}</td>
<td><a keyID={$id} class="editKey" href="manage.php?editNotes&id={$id}">Edit Key</a></td>
<td><a keyID={$id} class="removeKey" href="manage.php?removeKey&id={$id}">Remove Key</a></td>
</tr>
EOD;
}
$table.='<div class="fadeDiv"> </div><div id="keyInfoBox" class="floating_login_div" style="display: none;">';
$table.='<div class="exitbutton"><a href="#">[X]</a></div>';
$table.=edit_key_form();
$table.='</div>';
}else
$table.="<tr><td colspan=4> No Keys Found </td></tr>";
$table.="</table>";
$table.="
</body></html>
";
return $table;
}
function retrieve_api_keys(){
global $Db;
$uid=$_SESSION['uid'];
$result = $Db->selectWhere("keyInformation",array('userID'=>$uid));
if ($result != false&&$result->rows>0) {
return $result->results;
}
return false;
}
// checks if a short key is already assigned to an account
function check_saved_key($key,$uid) {
global $Db;
$result = $Db->selectWhere("keyInformation",array('apiKey'=>$key,'userID'=>$uid),null,1);
if ($result != false&&$result->rows>0) {
return $result->results[0]['id'];
}
return false;
}
// removed api key's from the table
function remove_api_key($Db,$id){
global $Db;
$uid=$_SESSION['uid'];
$result = $Db->selectWhere("keyInformation",array('id'=>$id),['apiKey'],1);
if ($result != false&&$result->rows>0) {
if(!check_saved_key($result->results[0]['apiKey'],$uid)){
return ["result"=>"failure","id"=>$id,"response"=>"Api key already removed"];
}
}else{
return ["result"=>"failure","id"=>$id,"response"=>"Api key already removed"];
}
$result=$Db->delete("keyInformation",['id'=>$id,'userID'=>$uid]);
if (!$result) {
if(DEBUG) {
exit;
}
Return false;
}else{
return true;
}
}
// add api key to account
function add_api_key($Db,$uid,$keyID,$vCode,$name,$notes=""){
$apikey=make_short_key($Db,$keyID,$vCode,$uid);
$ID=check_saved_key($apikey,$uid);
if($ID){
return ["result"=>"failure","id"=>$ID,"response"=>"Api Code Already added"];
}
if(!$name) $name="No Name Set";
$keyInfo = cache_api_retrieve($Db,"/account/APIKeyInfo.xml.aspx", array("keyID"=>$keyID, "vCode" => $vCode),5*60)->value;
echo $keyInfo->error;
if ($keyInfo->error){
if ($keyInfo->error==222) {
return ["result"=>"failure","response"=>"Api Key expired"];
}else if ($keyInfo->error==203) {
return ["result"=>"failure","response"=>"Api vCode or Id Incorrect"];
}else {
return ["result"=>"failure","response"=>"Unable to load API. Verify the key is correct and not expired."];
}
return false;
}
$type=(string)$keyInfo->result->key["type"];
foreach ($keyInfo->result->key->rowset->row as $char) {
if(isset($char["characterName"])){
if(isset($characters)){
$characters.="<br/>".$char["characterName"].",".$char["characterId"];
}else{
$characters=$char["characterName"].",".$char["characterId"];
}
}
}
$result=$Db->insert("keyInformation",['apiKey'=>$apikey,'userID'=>$uid,'keyName'=>$name,'characters'=>$characters,'type'=>$type,'notes'=>$notes]);
if (!$result) {
return false;
}else{
return ["id"=>$Db->lastid,"response"=>"Api Key successfully added"];
}
}
function edit_api_key($Db,$keyID,$name="",$notes=""){
$uid=$_SESSION['uid'];
$updateArray=array();
if($name!="false"){
$updateArray['keyName']=$name;
}
if($notes!="false"){
$updateArray['notes']=$notes;
}
$result=$Db->update("keyInformation",['id'=>$keyID,'userID'=>$uid],$updateArray);
if (!$result) {
Return false;
}else{
return true;
}
}
?>