63 lines
1.3 KiB
PHP
63 lines
1.3 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 resetsoft $group");
|
|
error_log(<<<EOF
|
|
$group was reset with the following result:
|
|
|
|
$result
|
|
|
|
EOF
|
|
);
|
|
return "$group has been reset";
|
|
}
|
|
|
|
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 'logs':
|
|
header('Content-type: text/plain');
|
|
$date = date('Y-m-d');
|
|
print(get_logs($group, $date));
|
|
break;
|
|
default:
|
|
print("Unknown action $action");
|
|
exit(1);
|
|
}
|
|
|
|
?>
|