summaryrefslogtreecommitdiffstats
path: root/modules-available/dozmod
diff options
context:
space:
mode:
authorUdo Walter2017-11-21 17:52:04 +0100
committerUdo Walter2017-11-21 17:52:04 +0100
commit653851f35d0eea172c2302e9f1b6f0d03c70096c (patch)
tree42f267c360104b98d2e3199273adba62a1e2023b /modules-available/dozmod
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)
downloadslx-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')
-rw-r--r--modules-available/dozmod/api.inc.php94
-rw-r--r--modules-available/dozmod/lang/de/template-tags.json1
-rw-r--r--modules-available/dozmod/lang/en/template-tags.json1
-rw-r--r--modules-available/dozmod/page.inc.php1
-rw-r--r--modules-available/dozmod/style.css1
-rw-r--r--modules-available/dozmod/templates/runtimeconfig.html38
6 files changed, 56 insertions, 80 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');
diff --git a/modules-available/dozmod/lang/de/template-tags.json b/modules-available/dozmod/lang/de/template-tags.json
index 0c7d8348..4b49579a 100644
--- a/modules-available/dozmod/lang/de/template-tags.json
+++ b/modules-available/dozmod/lang/de/template-tags.json
@@ -45,6 +45,7 @@
"lang_mailTemplates": "E-Mail Templates",
"lang_maxImageValidity": "G\u00fcltigkeitsdauer neuer VM-Versionen (Tage)",
"lang_maxLectureVisibility": "Sp\u00e4testes Enddatum einer Veranstaltung (Tage in der Zukunft)",
+ "lang_maxLocationsPerLecture": "Max. explizite Orte pro Veranstaltung",
"lang_maxTransfers": "Maximale Zahl gleichzeitiger Up-\/Downloads pro Benutzer",
"lang_miscOptions": "Verschiedene Einstellungen",
"lang_modified": "Modifiziert",
diff --git a/modules-available/dozmod/lang/en/template-tags.json b/modules-available/dozmod/lang/en/template-tags.json
index 95edfe49..ed8f3465 100644
--- a/modules-available/dozmod/lang/en/template-tags.json
+++ b/modules-available/dozmod/lang/en/template-tags.json
@@ -45,6 +45,7 @@
"lang_mailTemplates": "E-Mail Templates",
"lang_maxImageValidity": "New VM validity (days)",
"lang_maxLectureVisibility": "Max time lecture end date may lie in the future (days)",
+ "lang_maxLocationsPerLecture": "Max. explicit locations per lecture",
"lang_maxTransfers": "Max concurrent transfers per user",
"lang_miscOptions": "Misc options",
"lang_modified": "modified",
diff --git a/modules-available/dozmod/page.inc.php b/modules-available/dozmod/page.inc.php
index 19c05555..ffb38663 100644
--- a/modules-available/dozmod/page.inc.php
+++ b/modules-available/dozmod/page.inc.php
@@ -353,6 +353,7 @@ class Page_DozMod extends Page
'int' => [
'maxImageValidityDays' => array('min' => 7, 'max' => 999),
'maxLectureValidityDays' => array('min' => 7, 'max' => 999),
+ 'maxLocationsPerLecture' => array('min' => 0, 'max' => 999),
'maxTransfers' => array('min' => 1, 'max' => 10),
],
'bool' => [
diff --git a/modules-available/dozmod/style.css b/modules-available/dozmod/style.css
index 07853324..23dd121e 100644
--- a/modules-available/dozmod/style.css
+++ b/modules-available/dozmod/style.css
@@ -30,6 +30,7 @@
.table-input-group tr.input-group input.form-control {
width: auto;
+ min-width: 95px;
}
.table-input-group tr.input-group td:last-child input {
diff --git a/modules-available/dozmod/templates/runtimeconfig.html b/modules-available/dozmod/templates/runtimeconfig.html
index 8d27a14e..cff61441 100644
--- a/modules-available/dozmod/templates/runtimeconfig.html
+++ b/modules-available/dozmod/templates/runtimeconfig.html
@@ -41,26 +41,26 @@
<input type="hidden" name="defaultImagePermissions[link]" value="0"/>
<div class="checkbox">
- <input type="checkbox" name="defaultImagePermissions[admin]" value="1" {{defaultImagePermissions.admin}} id ="image_admin" class="form-control">
- <label class="" for="image_admin">
+ <input type="checkbox" name="defaultImagePermissions[admin]" value="1" {{defaultImagePermissions.admin}} id="image_admin" class="form-control">
+ <label for="image_admin">
{{lang_defaultImagePermissionAdmin}}
</label>
</div>
<div class="checkbox">
- <input type="checkbox" name="defaultImagePermissions[edit]" value="1" {{defaultImagePermissions.edit}} id ="image_edit" class="form-control">
- <label>
+ <input type="checkbox" name="defaultImagePermissions[edit]" value="1" {{defaultImagePermissions.edit}} id="image_edit" class="form-control">
+ <label for="image_edit">
{{lang_defaultImagePermissionEdit}}
</label>
</div>
<div class="checkbox">
- <input type="checkbox" name="defaultImagePermissions[download]" value="1" {{defaultImagePermissions.download}} id ="image_download" class="form-control">
- <label>
+ <input type="checkbox" name="defaultImagePermissions[download]" value="1" {{defaultImagePermissions.download}} id="image_download" class="form-control">
+ <label for="image_download">
{{lang_defaultImagePermissionDownload}}
</label>
</div>
<div class="checkbox">
- <input type="checkbox" name="defaultImagePermissions[link]" value="1" {{defaultImagePermissions.link}} id ="image_link" class="form-control">
- <label>
+ <input type="checkbox" name="defaultImagePermissions[link]" value="1" {{defaultImagePermissions.link}} id="image_link" class="form-control">
+ <label for="image_link">
{{lang_defaultImagePermissionLink}}
</label>
</div>
@@ -71,21 +71,27 @@
<p><i>{{lang_descriptionRuntimeLimits}}</i></p>
<table class="table-input-group">
<tr class="input-group">
- <td class="input-group-addon" for="max_image_validity">{{lang_maxImageValidity}}</td>
+ <td class="input-group-addon">{{lang_maxImageValidity}}</td>
+ <td>
+ <input name="maxImageValidityDays" class="form-control" type="number" value="{{maxImageValidityDays}}" min="7" max="999" pattern="^\d+$">
+ </td>
+ </tr>
+ <tr class="input-group">
+ <td class="input-group-addon">{{lang_maxLectureVisibility}}</td>
<td>
- <input name="maxImageValidityDays" id="max_image_validity" class="form-control" type="number" value="{{maxImageValidityDays}}" min="7" max="999" pattern="^\d+$">
+ <input name="maxLectureValidityDays" class="form-control" type="number" value="{{maxLectureValidityDays}}" min="1" max="999" pattern="^\d+$">
</td>
</tr>
<tr class="input-group">
- <td class="input-group-addon" for="max_lecture_validity">{{lang_maxLectureVisibility}}</td>
+ <td class="input-group-addon">{{lang_maxLocationsPerLecture}}</td>
<td>
- <input name="maxLectureValidityDays" id="max_lecture_validity" class="form-control" type="number" value="{{maxLectureValidityDays}}" min="1" max="999" pattern="^\d+$">
+ <input name="maxLocationsPerLecture" class="form-control" type="number" value="{{maxLocationsPerLecture}}" min="0" max="999" pattern="^\d+$">
</td>
</tr>
<tr class="input-group">
- <td class="input-group-addon" for="max_transfers">{{lang_maxTransfers}}</td>
+ <td class="input-group-addon">{{lang_maxTransfers}}</td>
<td>
- <input name="maxTransfers" id="max_transfers" class="form-control" type="number" value="{{maxTransfers}}" min="1" max="10" pattern="^\d+$">
+ <input name="maxTransfers" class="form-control" type="number" value="{{maxTransfers}}" min="1" max="10" pattern="^\d+$">
</td>
</tr>
</table>
@@ -95,8 +101,8 @@
<legend>{{lang_miscOptions}}</legend>
<div class="checkbox">
<input type="hidden" name="allowLoginByDefault" value="0">
- <input type="checkbox" name="allowLoginByDefault" value="1" {{allowLoginByDefault}} id ="allowLoginByDefault" class="form-control">
- <label>
+ <input type="checkbox" name="allowLoginByDefault" value="1" {{allowLoginByDefault}} id="allowLoginByDefault" class="form-control">
+ <label for="allowLoginByDefault">
{{lang_allowLoginByDefault}}
</label>
<p><i>{{lang_allowLoginDescription}}</i></p>