There is probably some way to read arbitrary files from the container via some kind of crafted path, but it's their own container so meh. Minimal due diligence has been done to sanitize the path a bit at least. Slightly rearranged the start page as well to make it more logical
84 lines
1.9 KiB
PHP
84 lines
1.9 KiB
PHP
<?php
|
|
|
|
$user = explode('@', $_SERVER['REMOTE_USER'])[0];
|
|
|
|
$group = 'none';
|
|
foreach(file('../groups.list') as $line) {
|
|
$line = preg_split("/[\t ]+/", trim($line));
|
|
if($line[0] == $user) {
|
|
$group = $line[1];
|
|
}
|
|
}
|
|
|
|
if($group == 'none') {
|
|
print("You don't seem to belong to a group.");
|
|
exit(0);
|
|
}
|
|
|
|
if(!isset($_GET['a'])) {
|
|
print("Action required.");
|
|
exit(1);
|
|
}
|
|
|
|
function reset_container($group) {
|
|
$result = shell_exec("sudo pvt-manage reset $group");
|
|
error_log(<<<EOF
|
|
$group was reset with the following result:
|
|
|
|
$result
|
|
|
|
EOF
|
|
);
|
|
return "$group has been reset";
|
|
}
|
|
|
|
function get_log($group, $filename) {
|
|
$safe_filename = basename($filename);
|
|
$command = "cat /usr/local/tomcat/logs/$safe_filename";
|
|
$output = array();
|
|
$result = 0;
|
|
exec("sudo pvt-manage connect $group $command", $output, $result);
|
|
if($result === 0) {
|
|
return implode("\n", $output);
|
|
} else {
|
|
return "Something went wrong. "
|
|
."You probably tried to access a nonexistent file.";
|
|
}
|
|
}
|
|
|
|
function get_logs($group, $date) {
|
|
$command = "cat /usr/local/tomcat/logs/catalina.$date.log";
|
|
$output = array();
|
|
$result = 0;
|
|
exec("sudo pvt-manage connect $group $command", $output, $result);
|
|
if($result === 0) {
|
|
return implode("\n", $output);
|
|
} else {
|
|
return "Something went wrong. "
|
|
."Either there are no logs for the given date ($date) "
|
|
."or the date is invalid.";
|
|
}
|
|
}
|
|
|
|
$action = $_GET['a'];
|
|
switch($action) {
|
|
case 'reset':
|
|
print(reset_container($group));
|
|
break;
|
|
case 'log':
|
|
header('Content-type: text/plain');
|
|
$file = $_GET['file'];
|
|
print(get_log($group, $file));
|
|
break;
|
|
case 'logs':
|
|
header('Content-type: text/plain');
|
|
$date = date('Y-m-d');
|
|
print(get_logs($group, $date));
|
|
break;
|
|
default:
|
|
print("Unknown action $action");
|
|
exit(1);
|
|
}
|
|
|
|
?>
|