Skip to content

Commit 79cadeb

Browse files
Improved alterstandardtime in view of security
1 parent ba3deb7 commit 79cadeb

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

alterstandardtime.php

+7-18
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,13 @@
1818

1919
require_login();
2020
require_sesskey();
21-
if (!is_siteadmin()) {
22-
header('HTTP/1.0 403 Forbidden');
23-
echo '403 Forbidden';
24-
return;
25-
}
26-
$starttime = optional_param('starttime', 'NULL', PARAM_INT);
27-
$endtime = optional_param('endtime', 'NULL', PARAM_INT);
28-
$cat = required_param('category', PARAM_INT);
21+
require_capability('moodle/site:config', context_system::instance());
2922

30-
if (!preg_match('/^[[0-9]*|NULL]$/', strval($starttime))) {
31-
exit("securtity violation1");
32-
}
33-
if (!preg_match('/^[[0-9]*|NULL]$/', strval($endtime))) {
34-
exit("security violaion2");
35-
}
23+
$starttime = optional_param('starttime', null, PARAM_INT);
24+
$endtime = optional_param('endtime', null, PARAM_INT);
25+
$cat = required_param('category', PARAM_INT);
3626

37-
// Not safe against SQL-injection. But site admin has access to Database anyway, right?
3827
global $DB;
39-
$sql = "UPDATE {block_evasys_sync_categories} SET standard_time_start = $starttime, standard_time_end = $endtime " .
40-
"WHERE id = ?";
41-
$DB->execute($sql, array($cat));
28+
$sql = 'UPDATE {block_evasys_sync_categories} SET standard_time_start = ?, standard_time_end = ? ' .
29+
'WHERE id = ?';
30+
$DB->execute($sql, array($starttime, $endtime, $cat));

0 commit comments

Comments
 (0)