summaryrefslogtreecommitdiffstats
path: root/modules-available/dozmod/api.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-07-27 12:25:18 +0200
committerSimon Rettberg2016-07-27 12:25:18 +0200
commite86bb73f3188e2f13d7a25aef92baaecffbb0e68 (patch)
tree56164b39470303a15cc09566cf74491332fe0519 /modules-available/dozmod/api.inc.php
parentdozmod runtimeconfig. (diff)
downloadslx-admin-e86bb73f3188e2f13d7a25aef92baaecffbb0e68.tar.gz
slx-admin-e86bb73f3188e2f13d7a25aef92baaecffbb0e68.tar.xz
slx-admin-e86bb73f3188e2f13d7a25aef92baaecffbb0e68.zip
[dozmod] API: Implement netrules and runscript fetching for lectures
Diffstat (limited to 'modules-available/dozmod/api.inc.php')
-rw-r--r--modules-available/dozmod/api.inc.php51
1 files changed, 48 insertions, 3 deletions
diff --git a/modules-available/dozmod/api.inc.php b/modules-available/dozmod/api.inc.php
index 17ead3c1..dc9788fc 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'];
+$availableRessources = ['list', 'vmx', 'test', 'netrules', 'runscript'];
/* BEGIN: A simple caching mechanism ---------------------------- */
@@ -148,9 +148,12 @@ function outputLectureXmlForLocation($locationIds)
return getListForLocations($locationIds, true);
}
-function _getVMX($lecture_uuid)
+function _getVmData($lecture_uuid, $subResource = false)
{
$url = VMX_URL . '/' . $lecture_uuid;
+ if ($subResource !== false) {
+ $url .= '/' . $subResource;
+ }
$response = Download::asString($url, 60, $code);
return $response;
}
@@ -162,7 +165,35 @@ function outputVMX($lecture_uuid)
if (cache_has($key)) {
cache_get_passthru($key);
} else {
- $value = _getVMX($lecture_uuid);
+ $value = _getVmData($lecture_uuid);
+ if ($value === false)
+ return false;
+ cache_put($key, $value);
+ die($value);
+ }
+}
+
+function outputNetrules($lecture_uuid)
+{
+ $key = 'netrules_' . $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 = 'netrules_' . $lecture_uuid;
+ if (cache_has($key)) {
+ cache_get_passthru($key);
+ } else {
+ $value = _getVmData($lecture_uuid, 'runscript');
if ($value === false)
return false;
cache_put($key, $value);
@@ -226,6 +257,20 @@ if ($resource === 'vmx') {
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...