avm99963 | 1b63761 | 2018-12-28 01:03:44 +0100 | [diff] [blame] | 1 | <?php |
| 2 | require_once("config.php"); |
| 3 | |
| 4 | class write { |
| 5 | public static function output($json) { |
| 6 | print_r(json_encode($json)); |
| 7 | exit(); |
| 8 | } |
| 9 | |
| 10 | public static function error($n, $msg) { |
Adrià Vilanova Martínez | 1082a13 | 2021-07-08 16:54:10 +0200 | [diff] [blame^] | 11 | http_response_code(400); |
avm99963 | 1b63761 | 2018-12-28 01:03:44 +0100 | [diff] [blame] | 12 | self::output(["error" => $n, "msg" => $msg]); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | function get_graph() { |
| 17 | global $conf; |
| 18 | return json_decode(file_get_contents($conf["apiurl"]), true); |
| 19 | } |
| 20 | |
| 21 | if (!isset($_GET["action"])) { |
| 22 | write::error(1, "No action provided"); |
| 23 | } |
| 24 | |
| 25 | switch ($_GET["action"]) { |
| 26 | case "getgraf": |
Adrià Vilanova Martínez | 1082a13 | 2021-07-08 16:54:10 +0200 | [diff] [blame^] | 27 | $ch = curl_init($conf["apiurl"]); |
| 28 | |
| 29 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 30 | curl_setopt($ch, CURLOPT_FAILONERROR, true); |
| 31 | |
| 32 | $graf = curl_exec($ch); |
| 33 | $error = curl_errno($ch); |
| 34 | if ($error) |
| 35 | $errorMsg = curl_error($ch); |
| 36 | |
| 37 | curl_close($ch); |
| 38 | |
| 39 | if ($error) |
| 40 | write::error(3, "Error while retrieving Graf from dirbaio's website: ".$errorMsg); |
| 41 | |
| 42 | echo $graf; |
| 43 | break; |
avm99963 | 1b63761 | 2018-12-28 01:03:44 +0100 | [diff] [blame] | 44 | |
| 45 | default: |
Adrià Vilanova Martínez | 1082a13 | 2021-07-08 16:54:10 +0200 | [diff] [blame^] | 46 | write::error(2, "Unknown action"); |
avm99963 | 1b63761 | 2018-12-28 01:03:44 +0100 | [diff] [blame] | 47 | } |
| 48 | ?> |