1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<?php
class SubPage
{
public static function doPreprocess()
{
/* execute actions */
$action = Request::post('action', false, 'string');
if ($action === 'runtime') {
User::assertPermission("runtimeconfig.save");
self::runtimeHandler();
}
}
private static function runtimeHandler()
{
// Check action
$do = Request::post('button');
if ($do === 'save') {
$data = [];
$data['defaultLecturePermissions'] = Request::post('defaultLecturePermissions', NULL, "array");
$data['defaultImagePermissions'] = Request::post('defaultImagePermissions', NULL, "array");
$params = [
'int' => [
'maxImageValidityDays' => array('min' => 7, 'max' => 9999),
'maxLectureValidityDays' => array('min' => 7, 'max' => 9999),
'maxLocationsPerLecture' => array('min' => 0, 'max' => 999),
'maxTransfers' => array('min' => 1, 'max' => 10),
],
'bool' => [
'allowLoginByDefault' => array('default' => false),
'allowStudentDownload' => array('default' => false),
],
];
foreach ($params as $type => $list) {
foreach ($list as $field => $limits) {
$default = $limits['default'] ?? false;
$value = Request::post($field, $default, $type);
if (isset($limits['min']) && $value < $limits['min']) {
$value = $limits['min'];
}
if (isset($limits['max']) && $value > $limits['max']) {
$value = $limits['max'];
}
$data[$field] = $value;
}
}
// ServerSide Copy
$data['serverSideCopy'] = Request::post('serverSideCopy', 'OFF', 'string');
if (!in_array($data['serverSideCopy'], ['OFF', 'ON', 'AUTO', 'USER'])) {
$data['serverSideCopy'] = 'OFF';
}
// VM size limit
$data['vmSizeLimit'] = ceil(max(0, Request::post('vmSizeLimit', '0', 'float') * 1024 * 1024 * 1024));
/* ensure types */
settype($data['defaultLecturePermissions']['edit'], 'boolean');
settype($data['defaultLecturePermissions']['admin'], 'boolean');
settype($data['defaultImagePermissions']['edit'], 'boolean');
settype($data['defaultImagePermissions']['admin'], 'boolean');
settype($data['defaultImagePermissions']['link'], 'boolean');
settype($data['defaultImagePermissions']['download'], 'boolean');
// Write to DB - java server app wil reload this periodically
$data = json_encode($data);
Database::exec('INSERT INTO sat.configuration (parameter, value)'
. ' VALUES (:param, :value)'
. ' ON DUPLICATE KEY UPDATE value = VALUES(value)', array(
'param' => 'runtimelimits',
'value' => $data
));
Message::addSuccess('runtimelimits-config-saved');
}
Util::redirect('?do=DozMod§ion=runtimeconfig');
}
public static function doRender()
{
// Runtime config
$runtimeConf = Database::queryFirst('SELECT value FROM sat.configuration WHERE parameter = :param', array('param' => 'runtimelimits'));
if ($runtimeConf !== false) {
$runtimeConf = json_decode($runtimeConf['value'], true);
/* convert some value to corresponding "selected" texts */
if ($runtimeConf['defaultLecturePermissions']['edit'] ?? false) {
$runtimeConf['defaultLecturePermissions']['edit'] = 'checked';
}
if ($runtimeConf['defaultLecturePermissions']['admin'] ?? false) {
$runtimeConf['defaultLecturePermissions']['admin'] = 'checked';
}
if ($runtimeConf['defaultImagePermissions']['edit'] ?? false) {
$runtimeConf['defaultImagePermissions']['edit'] = 'checked';
}
if ($runtimeConf['defaultImagePermissions']['admin'] ?? false) {
$runtimeConf['defaultImagePermissions']['admin'] = 'checked';
}
if ($runtimeConf['defaultImagePermissions']['link'] ?? false) {
$runtimeConf['defaultImagePermissions']['link'] = 'checked';
}
if ($runtimeConf['defaultImagePermissions']['download'] ?? false) {
$runtimeConf['defaultImagePermissions']['download'] = 'checked';
}
if ($runtimeConf['allowLoginByDefault'] ?? false) {
$runtimeConf['allowLoginByDefault'] = 'checked';
}
if ($runtimeConf['allowStudentDownload'] ?? false) {
$runtimeConf['allowStudentDownload'] = 'checked';
}
if (isset($runtimeConf['serverSideCopy'])) {
$runtimeConf[$runtimeConf['serverSideCopy'] . '_selected'] = 'selected';
}
$runtimeConf['vmSizeLimit'] = ceil(($runtimeConf['vmSizeLimit'] ?? 0) / (1024 * 1024 * 1024));
}
$runtimeConf['allowedSave'] = User::hasPermission("runtimeconfig.save");
Render::addTemplate('runtimeconfig', $runtimeConf);
}
public static function doAjax()
{
}
}
|