diff options
author | Udo Walter | 2017-11-21 17:52:04 +0100 |
---|---|---|
committer | Udo Walter | 2017-11-21 17:52:04 +0100 |
commit | 653851f35d0eea172c2302e9f1b6f0d03c70096c (patch) | |
tree | 42f267c360104b98d2e3199273adba62a1e2023b /modules-available/dozmod/api.inc.php | |
parent | [internetaccess] reworked permission system from "click and you get error" to... (diff) | |
parent | [statistics] Also adapt MAC-UUID fixing code to mltk changes (diff) | |
download | slx-admin-653851f35d0eea172c2302e9f1b6f0d03c70096c.tar.gz slx-admin-653851f35d0eea172c2302e9f1b6f0d03c70096c.tar.xz slx-admin-653851f35d0eea172c2302e9f1b6f0d03c70096c.zip |
Merge remote-tracking branch 'origin/master' into permission-manager
# Conflicts:
# modules-available/backup/templates/_page.html
# style/default.css
Diffstat (limited to 'modules-available/dozmod/api.inc.php')
-rw-r--r-- | modules-available/dozmod/api.inc.php | 94 |
1 files changed, 30 insertions, 64 deletions
diff --git a/modules-available/dozmod/api.inc.php b/modules-available/dozmod/api.inc.php index accfe813..74aaa003 100644 --- a/modules-available/dozmod/api.inc.php +++ b/modules-available/dozmod/api.inc.php @@ -17,7 +17,7 @@ if (!Module::isAvailable('locations')) { define('LIST_URL', CONFIG_DOZMOD_URL . '/vmchooser/list'); define('VMX_URL', CONFIG_DOZMOD_URL . '/vmchooser/lecture'); -$availableRessources = ['list', 'vmx', 'test', 'netrules', 'runscript']; +$availableRessources = ['list', 'vmx', 'test', 'netrules', 'runscript', 'netshares']; /* BEGIN: A simple caching mechanism ---------------------------- */ @@ -45,7 +45,8 @@ function cache_has($key) if ($mtime === false) { return false; // cache miss } - if (time() - $mtime > CONFIG_DOZMOD_EXPIRE) { + $now = time(); + if ($now < $mtime || $now - $mtime > CONFIG_DOZMOD_EXPIRE) { return false; } else { return true; @@ -94,7 +95,9 @@ function xmlToLectureIds($responseXML) $uuids = []; foreach ($xml->eintrag as $e) { - $uuids[] = strval($e->uuid['param'][0]); + if (isset($e->uuid) && isset($e->uuid['param']) && isset($e->uuid['param'][0])) { + $uuids[] = strval($e->uuid['param'][0]); + } } return $uuids; } @@ -149,11 +152,13 @@ function getListForLocations($locationIds, $raw) if (Module::isAvailable('exams')) { // If we have the exam mode module, we can enforce a server side check and make sure it agrees with the client $serverExamMode = Exams::isInExamMode($locationIds); - $clientServerMismatch = ($serverExamMode !== $examMode); + if ($raw) { + $clientServerMismatch = ($serverExamMode !== $examMode); + } $examMode = $serverExamMode; } // Only enforce exam mode validity check if the client requests the raw xml data - if ($raw && $clientServerMismatch) { + if ($clientServerMismatch) { sendExamModeMismatch(); // does not return } // Proceed normally from here on @@ -175,7 +180,7 @@ function getListForLocations($locationIds, $raw) $url .= '&exams'; } $value = Download::asString($url, 60, $code); - if ($value === false) + if ($value === false || $code < 200 || $code > 299) return false; cache_put($rawKey, $value); $list = xmlToLectureIds($value); @@ -203,67 +208,45 @@ function _getVmData($lecture_uuid, $subResource = false) $url .= '/' . $subResource; } $response = Download::asString($url, 60, $code); + if ($code < 200 || $code > 299) + return (int)$code; return $response; } -/** Caching wrapper around _getVMX() **/ -function outputVMX($lecture_uuid) -{ - $key = 'vmx_' . $lecture_uuid; - if (cache_has($key)) { - cache_get_passthru($key); - } else { - $value = _getVmData($lecture_uuid); - if ($value === false) - return false; - cache_put($key, $value); - die($value); - } -} - -function outputNetrules($lecture_uuid) +/** Caching wrapper around _getVmData() **/ +function outputResource($lecture_uuid, $resource) { - $key = 'netrules_' . $lecture_uuid; + $key = $resource . '_' . $lecture_uuid; if (cache_has($key)) { cache_get_passthru($key); } else { - $value = _getVmData($lecture_uuid, 'netrules'); - if ($value === false) - return false; - cache_put($key, $value); - die($value); - } -} - -function outputRunscript($lecture_uuid) -{ - $key = 'runscript_' . $lecture_uuid; - if (cache_has($key)) { - cache_get_passthru($key); - } else { - $value = _getVmData($lecture_uuid, 'runscript'); + $value = _getVmData($lecture_uuid, $resource); if ($value === false) return false; + if (is_int($value)) { + http_response_code($value); + exit; + } cache_put($key, $value); die($value); } + return false; } function fatalDozmodUnreachable() { Header('HTTP/1.1 504 Gateway Timeout'); - die('Resource not available'); + die('DMSD currently not available'); } -function readLectureParam() +function readLectureParam($locationIds) { - global $location_ids; $lecture = Request::get('lecture', false, 'string'); if ($lecture === false) { Header('HTTP/1.1 400 Bad Request'); die('Missing lecture UUID'); } - $lectures = getLectureUuidsForLocations($location_ids); + $lectures = getLectureUuidsForLocations($locationIds); if ($lectures === false) { fatalDozmodUnreachable(); } @@ -295,34 +278,17 @@ if (substr($ip, 0, 7) === '::ffff:') { /* lookup location id(s) */ -$location_ids = Location::getFromIp($ip); +$location_ids = Location::getFromIp($ip, true); $location_ids = Location::getLocationRootChain($location_ids); -if ($resource === 'vmx') { - $lecture = readLectureParam(); - outputVMX($lecture); - // outputVMX does not return on success - fatalDozmodUnreachable(); -} - -if ($resource === 'netrules') { - $lecture = readLectureParam(); - outputNetrules($lecture); - // no return on success - fatalDozmodUnreachable(); -} - -if ($resource === 'runscript') { - $lecture = readLectureParam(); - outputRunscript($lecture); - // no return on success - fatalDozmodUnreachable(); -} - if ($resource === 'list') { outputLectureXmlForLocation($location_ids); // Won't return on success... fatalDozmodUnreachable(); +} else { + $lecture = readLectureParam($location_ids); + outputResource($lecture, $resource); + fatalDozmodUnreachable(); } Header('HTTP/1.1 400 Bad Request'); |