-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.php
More file actions
49 lines (44 loc) · 1.43 KB
/
launch.php
File metadata and controls
49 lines (44 loc) · 1.43 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
<?php
/*
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
*/
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
$old_path = getcwd();
chdir("/var/www/golang/bin/");
$output = "{}";
$outputJSON = isset($_GET['json']);
if (isset($_GET['cookie'])) {
$cookie = $_GET['cookie'];
$cookie = str_replace("!", "\!", $cookie);
$output = shell_exec("./peterplanner --cookie \"".$cookie."\"".($outputJSON ? " --json" : ""));
} else if (isset($_GET['uid'])) {
$uid = $_GET['uid'];
$output = shell_exec("./peterplanner --uid \"".$uid."\" --json");
} else if (isset($_GET['studentID'])) {
$studentID = $_GET['studentID'];
$output = shell_exec("./peterplanner --studentID \"".$studentID."\"".($outputJSON ? " --json" : ""));
}
chdir($old_path);
if (strpos($output, "No flags were specified.") !== false) {
header("Location: /saveme");
die();
} else if (isset($_GET['cookie'])) {
$result = json_decode($output, true);
$uid = $result["uid"];
$days = 30 * 4;
setcookie("uid", $uid, time() + ($days * 24 * 60 * 60));
header("Location: /app");
die();
} else {
// TODO: Determine if output contains some error about cookies, and alert the user.
if ($outputJSON || isset($_GET['uid'])) {
header("Content-Type: application/json");
} else {
header("Content-Type: text/plain");
}
echo $output;
}
?>