blob: 3fdcf7b7f328b4fbd7b3e4da06f073022e0c05cc [file] [log] [blame]
avm999631b637612018-12-28 01:03:44 +01001<?php
2require_once("config.php");
3
4class 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ínez1082a132021-07-08 16:54:10 +020011 http_response_code(400);
avm999631b637612018-12-28 01:03:44 +010012 self::output(["error" => $n, "msg" => $msg]);
13 }
14}
15
16function get_graph() {
17 global $conf;
18 return json_decode(file_get_contents($conf["apiurl"]), true);
19}
20
21if (!isset($_GET["action"])) {
22 write::error(1, "No action provided");
23}
24
25switch ($_GET["action"]) {
26 case "getgraf":
Adrià Vilanova Martínez1082a132021-07-08 16:54:10 +020027 $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;
avm999631b637612018-12-28 01:03:44 +010044
45 default:
Adrià Vilanova Martínez1082a132021-07-08 16:54:10 +020046 write::error(2, "Unknown action");
avm999631b637612018-12-28 01:03:44 +010047}
48?>