threadr.lostcave.ddnss.de/strassenkind.php

71 lines
2.1 KiB
PHP
Raw Normal View History

2020-02-12 04:24:26 +01:00
<!DOCTYPE html>
<!--
<?php
function get_command_list($command_file_name){
echo "Getting commands from file $command_file_name...";
$command_file = fopen($command_file_name, "r") or die("Could not read file $command_file_name. Aborting.");
$commands = explode(PHP_EOL, fread($command_file, filesize($command_file_name)));
fclose($command_file);
echo "Done.";
return $commands;
}
$status_commands = get_command_list("commands_status.conf");
$ondemand_commands = get_command_list("commands_ondemand.conf");
$git_commands = get_command_list("commands_git.conf");
2020-02-12 04:24:26 +01:00
?>
2020-02-12 04:45:55 +01:00
-->
<html>
<head>
2020-02-12 05:26:21 +01:00
<title> Strassenkind Server Status Page </title>
2020-03-04 21:49:18 +01:00
<link rel="stylesheet" type="text/css" href="style.css" />
2020-02-12 05:26:21 +01:00
<?php
if (!isset($_POST['ondemand'])) {
echo "<meta http-equiv=\"refresh\" content=\"20\" />";
}
?>
2020-02-12 04:45:55 +01:00
</head>
2020-02-12 05:26:21 +01:00
<body class="status_page">
<h1> Strassenkind Server Status </h1>
<hr />
2020-02-12 06:21:22 +01:00
<?php
function add_button($button_text, $button_action){
if (!isset($_POST[$button_action])) {
echo "<form action=\"\" method=\"post\"><input type=\"submit\" value=\"$button_text\" name=\"$button_action\" /></form>";
} else {
echo "<a href=\"\"><button> Return to regular status commands </button></a>";
}
2020-02-12 06:21:22 +01:00
}
add_button("Run ondemand commands", "ondemand");
add_button("Force ThreadR update", "git");
?>
<hr />
<?php
2020-03-05 03:35:16 +01:00
function execute_command_list($commands){
foreach ($commands as $command) {
2020-03-05 03:07:56 +01:00
if ($command != ""){
// === is here on purpose.
if (strpos($command, '>') === false) {
$command = $command . " 2>&1";
}
2020-03-05 03:07:56 +01:00
$output = shell_exec($command);
echo "<pre class=\"commandLine\"> $command </pre>\n<pre class=\"commandLine\"> $output </pre>\n<hr />";
}
2020-02-12 05:26:21 +01:00
}
2020-03-05 03:35:16 +01:00
}
// run ondemand command list if demanded
if (isset($_POST['ondemand'])) {
execute_command_list($ondemand_commands);
} elseif (isset($_POST['git'])) {
execute_command_list($git_commands);
2020-03-05 03:35:16 +01:00
} else {
//run status command list otherwise
execute_command_list($status_commands);
2020-02-12 05:26:21 +01:00
}
?>
2020-02-12 04:45:55 +01:00
</body>
2020-03-04 21:49:18 +01:00
</html>