From 4f89cf9757bff745a9b1101a5e67c27431fdd936 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Wed, 8 Jun 2016 14:51:29 +0200 Subject: first version of the dozmod proxy (without caching). --- modules-available/dozmod/api.inc.php | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 modules-available/dozmod/api.inc.php (limited to 'modules-available/dozmod/api.inc.php') diff --git a/modules-available/dozmod/api.inc.php b/modules-available/dozmod/api.inc.php new file mode 100644 index 00000000..f5525ef8 --- /dev/null +++ b/modules-available/dozmod/api.inc.php @@ -0,0 +1,79 @@ +eintrag as $e) { + $uuids[] = strval($e->uuid['param'][0]); + } + return $uuids; +} + +function getVMX($lecture_uuid) { + $url = VMX_URL . '/' . $lecture_uuid; + $response = Download::asString($url, 60, $code); + return $response; +} + + +// -----------------------------------------------------------------------------// +$ip = $_SERVER['REMOTE_ADDR']; +if (substr($ip, 0, 7) === '::ffff:') { + $ip = substr($ip, 7); +} + +/* request data, don't trust */ +$request = [ 'ressource' => filter_var(strtolower(trim($_REQUEST['ressource'])), FILTER_SANITIZE_STRING), + 'lecture' => filter_var(strtolower(trim($_REQUEST['lecture'])), FILTER_SANITIZE_STRING), + 'ip' => $ip ]; + + +/* lookup location id(s) */ +$location_ids = Location::getFromIP($request['ip']); + +/* lookup lecture uuids */ +$lectures = getLecturesForLocations(array($location_ids)); + + +/* validate request -------------------------------------------- */ +/* check ressources */ +if (!in_array($request['ressource'], $availableRessources)) { + Util::traceError("unknown ressource: {$request['ressource']}"); +} + +/* check that the user requests a lecture that he is allowed to have */ +if (!in_array($request['lecture'], $lectures)) { + Util::traceError("client is not allowed to access this lecture: ${request['lecture']}"); +} + +if ($request['ressource'] === 'vmx') { + echo getVMX($request['lecture']); +} else if ($request['ressource'] === 'test') { + echo "Here's your special test data!"; +} else { + echo "I don't know how to give you that ressource"; +} -- cgit v1.2.3-55-g7522