-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathauthorisation.php
More file actions
334 lines (307 loc) · 8.58 KB
/
Copy pathauthorisation.php
File metadata and controls
334 lines (307 loc) · 8.58 KB
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
333
334
<?php
require_once('defines.php');
// function redirect($loc)
// {
// echo "<script language=\"JavaScript\" type=\"text/javascript\">";
// echo "<!--\n";
// echo "window.location.href=\"$loc\";";
// echo "//-->\n";
// echo "</script>\n";
// }
// Function to substitute deprecated mysql_result, sure have to look for better solution
function mysqli_result($res,$row=0,$col=0){
$numrows = mysqli_num_rows($res);
if ($numrows && $row <= ($numrows-1) && $row >=0){
mysqli_data_seek($res,$row);
$resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
if (isset($resrow[$col])){
return $resrow[$col];
}
}
return false;
}
//
function redirect($url, $permanent = false) {
if($permanent) {
header('HTTP/1.1 301 Moved Permanently');
}
header('Location: '.$url);
exit();
}
function db_connect()
{
$link = mysqli_connect(MYSQLHOST, MYSQLUSER, MYSQLPASSWORD, DATABASE);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
return $link;
}
function is_admin($what,$usePk,$comPk)
{
$link = db_connect();
$query = "select useLevel from tblCompAuth where usePk=$usePk and comPk in ($comPk,-1)";
$result = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' Admin Check failed: ' . mysqli_connect_error());
while ($row = mysqli_fetch_assoc($result))
{
$level = $row['useLevel'];
if ($what == $level)
{
return 1;
}
}
return 0;
}
function check_admin($what,$usePk,$comPk)
{
if (is_admin($what,$usePk,$comPk))
{
return 1;
}
echo "You are unauthorised to perform that action ($what $usePk $comPk).<br>";
//redirect('unauthorised.php');
return 0;
}
function check_auth($region)
{
$link = db_connect();
// FIX: check time/region/IP stuff too ...
// but for no just validate the session
if (!array_key_exists('XCauth', $_COOKIE))
{
return 0;
}
$magic = addslashes($_COOKIE['XCauth']);
$query = "select usePk from tblUserSession where useSession='$magic'";
$result = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' Query failed: ' . mysqli_connect_error());
$usePk = 0;
if (mysqli_num_rows($result) > 0)
{
$usePk = mysqli_result($result,0,0);
}
mysqli_close($link);
if (!$usePk)
{
return 0;
}
return $usePk;
}
function auth($region)
{
$usePk = 0;
$browser = addslashes($_SERVER['HTTP_USER_AGENT']);
if ((strpos($browser, "MSIE 6.0; Windows") || strpos($browser, "MSIE 7.0; Windows")) && strpos($browser, "Opera") == FALSE)
{
redirect("better_browsers.php");
exit;
}
$usePk = check_auth($region);
if ($usePk == 0)
{
// auth fails - redirect to login.
echo "<b><i>Authorisation Failed</i></b>";
redirect("login.php?message=Authorisation%20Failed:$magic");
exit;
}
return $usePk;
}
function menubar($comPk)
{
if ($comPk != 0)
{
$link = db_connect();
$query = "select comName,comType from tblCompetition where comPk=$comPk";
$result = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' Query failed: ' . mysqli_connect_error());
if (mysqli_num_rows($result) > 0)
{
$comName = mysqli_result($result,0,0);
$comType = mysqli_result($result,0,1);
}
else
{
$comName = 'Unknown Competition';
$comType = 'OLC';
}
mysqli_close($link);
echo "<div id=\"vhead\"><h1>$comName</h1></div>";
}
else
{
echo "<div id=\"vhead\"><h1>Skyhigh Cup</h1></div>";
$comPk = 5;
}
echo "<div id=\"menu\">";
echo "<ul>";
if (check_auth("system"))
{
if ($comPk > 0)
{
echo "<li><a href=\"competition_admin.php?comPk=$comPk\">Admin</a></li>";
}
else
{
echo "<li><a href=\"comp_admin.php\">Admin</a></li>";
}
}
if ($comType == 'OLC')
{
echo "<li><a href=\"index.php\">Home</a></li>";
echo "<li><a href=\"top_scores.php?comPk=$comPk\">Top Scores</a></li>";
echo "<li><a href=\"top.php?comPk=$comPk\">Top Tracks</a></li>";
echo "<li><a href=\"recent.php?comPk=$comPk\">Recent Tracks</a></li>";
}
else
{
echo "<li><a href=\"compview.php?comPk=$comPk\">Home</a></li>";
echo "<li><a href=\"comp_result.php?comPk=$comPk\">Scores</a></li>";
echo "<li><a href=\"recent.php?comPk=$comPk\">Recent Tracks</a></li>";
}
echo "<li><a href=\"submit_track.php?comPk=$comPk\">Submit Track</a></li>";
echo "</ul>";
echo "</div>\n";
}
function adminbar($comPk)
{
echo "<div id=\"container-eyecatcher\">";
echo "<div id=\"menu\">";
echo "<ul id=\"navigation\">";
if (check_auth("system"))
{
echo "<li><a href=\"login.php?logout=1\">Logout</a></li>";
}
else
{
echo "<li><a href=\"login.php\">Login</a></li>";
}
echo "<li><a href=\"comp_admin.php\">Competition</a></li>";
if ($comPk > 0)
{
$link = db_connect();
$query = "select comName,comType,comEntryRestrict from tblCompetition where comPk=$comPk";
$result = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' Query failed: ' . mysqli_connect_error());
if (mysqli_num_rows($result) > 0)
{
$comName = mysqli_result($result,0,0);
$comType = mysqli_result($result,0,1);
$comEntryRestrict = mysqli_result($result,0,2);
}
else
{
$comName = 'Unknown Competition';
$comType = 'OLC';
}
mysqli_close($link);
echo "<li><a href=\"comp_result.php?comPk=$comPk\">Scores</a></li>";
echo "<li><a href=\"track_admin.php?comPk=$comPk\">Track</a></li>";
echo "<li><a href=\"team_admin.php?comPk=$comPk\">Teams</a></li>";
echo "<li><a href=\"pilot_admin.php?comPk=$comPk\">Pilots</a></li>";
if ($comEntryRestrict == 'registered')
{
echo "<li><a href=\"registration.php?comPk=$comPk\">Registration</a></li>";
}
}
else
{
echo "<li><a href=\"track_admin.php\">Track</a></li>";
echo "<li><a href=\"pilot_admin.php\">Pilots</a></li>";
}
echo "<li><a href=\"region_admin.php\">Waypoints</a></li>";
echo "<li><a href=\"airspace_admin.php\">Airspace</a></li>";
echo "</ul>";
echo "</div>";
echo "</div>";
}
function output_select($name,$selected,$options)
{
echo "<select name=\"$name\">";
foreach ($options as $key => $value)
{
if (is_int($key))
{
$key = $value;
}
if ($selected == $value)
{
echo "<option value=\"$value\" selected>$key</option>\n";
}
else
{
echo "<option value=\"$value\">$key</option>\n";
}
}
echo "</select>\n";
}
function waypoint_select($link,$tasPk,$name,$selected)
{
$query="select distinct RW.* from tblTask T, tblRegion R, tblRegionWaypoint RW where T.tasPk=$tasPk and RW.regPk=R.regPk and R.regPk=T.regPk order by RW.rwpName";
$result = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' Waypoint select failed: ' . mysqli_connect_error());
$waypoints = [];
while ($row = mysqli_fetch_assoc($result))
{
$rwpPk = $row['rwpPk'];
$rname = $row['rwpName'];
$waypoints[$rname] = $rwpPk;
}
//ksort($waypoints);
output_select($name,$selected,$waypoints);
}
function cmdlinecheck()
{
if (!$_REQUEST)
{
if (!isset($_SERVER["HTTP_HOST"]))
{
global $argv;
parse_str($argv[1], $_REQUEST);
//parse_str($argv[1], $_POST);
}
}
}
function reqexists($key)
{
cmdlinecheck();
if (array_key_exists($key, $_REQUEST))
{
return 1;
}
return 0;
}
function reqival($key)
{
cmdlinecheck();
if (array_key_exists($key, $_REQUEST))
{
return intval($_REQUEST[$key]);
}
else
{
return 0;
}
}
function reqfval($key)
{
cmdlinecheck();
if (array_key_exists($key, $_REQUEST))
{
return floatval($_REQUEST[$key]);
}
else
{
return 0;
}
}
function reqsval($key)
{
cmdlinecheck();
if (array_key_exists($key, $_REQUEST))
{
return addslashes($_REQUEST[$key]);
}
else
{
return '';
}
}
?>