rewrote a significant portion of the code to make it more modular, added git commands

master
BodgeMaster 2020-03-05 04:17:53 +01:00
parent 91bc640df1
commit 9589a16566
1 changed files with 26 additions and 16 deletions

View File

@ -1,18 +1,18 @@
<!DOCTYPE html>
<!--
<?php
echo "Getting status commands...";
$status_file_name = "commands_status.conf";
$status_file = fopen($status_file_name, "r") or die("Could not read file $status_file_name. Aborting.");
$status_commands = explode(PHP_EOL, fread($status_file, filesize($status_file_name)));
fclose($status_file);
echo "Done.";
echo "Getting ondemand commands...";
$ondemand_file_name = "commands_ondemand.conf";
$ondemand_file = fopen($ondemand_file_name, "r") or die("Could not read file $ondemand_file_name. Aborting.");
$ondemand_commands = explode(PHP_EOL, fread($ondemand_file, filesize($ondemand_file_name)));
fclose($ondemand_file);
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");
?>
-->
<html>
@ -29,11 +29,19 @@ echo "Done.";
<h1> Strassenkind Server Status </h1>
<hr />
<?php
if (!isset($_POST['ondemand'])) {
echo "<form action=\"\" method=\"post\"><input type=\"submit\" value=\"Run ondemand commands\" name=\"ondemand\" /></form><hr />";
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><hr />";
echo "<a href=\"\"><button> Return to regular status commands </button></a>";
}
}
add_button("Run ondemand commands", "ondemand");
add_button("Force ThreadR update", "git");
?>
<hr />
<?php
function execute_command_list($commands){
foreach ($commands as $command) {
if ($command != ""){
@ -51,6 +59,8 @@ echo "Done.";
// run ondemand command list if demanded
if (isset($_POST['ondemand'])) {
execute_command_list($ondemand_commands);
} elseif (isset($_POST['git'])) {
execute_command_list($git_commands);
} else {
//run status command list otherwise
execute_command_list($status_commands);