diff --git a/html/user/server_status.php b/html/user/server_status.php index e6b6f520f5..f390a3dc38 100644 --- a/html/user/server_status.php +++ b/html/user/server_status.php @@ -1,25 +1,36 @@ - $host - $function - "; - } else { - echo "$function$host"; - } + global $xml,$xmlout,$xmloutfile; + $xmlstring = " \n $host\n $function\n"; + $htmlstring = "$function$host"; if ($running == 1) { - if ($xml) { - echo " running\n"; - } else { - echo "Running\n"; + $xmlstring .= " running\n"; + $htmlstring .= "Running\n"; } - } elseif ($running == 0) { - if ($xml) { - echo " not running\n"; - } else { - echo "Not Running\n"; + elseif ($running == 0) { + $xmlstring .= " not running\n"; + $htmlstring .= "Not Running\n"; } - } else { - if ($xml) { - echo " disabled\n"; - } else { - echo "Disabled\n"; + else { + $xmlstring .= " disabled\n"; + $htmlstring .= "Disabled\n"; } - } - if ($xml) { - echo " \n"; - } else { - echo ""; - } + $xmlstring .= " \n"; + $htmlstring .= "\n"; + if ($xml) { echo $xmlstring; return 0; } + if ($xmlout) { fwrite($xmloutfile,$xmlstring); } + echo $htmlstring; + return 0; } function show_daemon_status($host, $pidname, $progname, $disabled) { @@ -113,13 +119,13 @@ function show_daemon_status($host, $pidname, $progname, $disabled) { } function show_counts($key, $xmlkey, $value) { - global $xml; + global $xml,$xmlout,$xmloutfile; $formattedvalue = number_format($value); - if ($xml) { - echo " <$xmlkey>$value\n"; - } else { - echo "$key$formattedvalue"; - } + $xmlstring = " <$xmlkey>$value\n"; + if ($xml) { echo $xmlstring; return 0; } + if ($xmlout) { fwrite($xmloutfile,$xmlstring); } + echo "$key$formattedvalue"; + return 0; } function get_mysql_count ($query) { @@ -148,12 +154,14 @@ $ps_exe = parse_element($config_vars,""); if ($ps_exe == "") { $ps_exe = "/bin/ps"; } +$xmlstring = "\n " . time() . "\n \n"; if ($xml) { xml_header(); - echo "\n"; - echo " " . time() . "\n"; - echo " \n"; + echo $xmlstring; } else { + if ($xmlout) { + fwrite($xmloutfile,$xmlstring); + } page_head("Server status page"); echo "

[As of ", time_str(time()), "] @@ -205,9 +213,10 @@ while ($thisxml = trim(parse_next_element($config_xml,"",&$cursor))) { show_daemon_status($host,$nlog,$ncmd,$disabled); } -if ($xml) { - echo " \n \n"; -} else { +$xmlstring = " \n \n"; +if ($xml) { echo $xmlstring; } +else { + if ($xmlout) { fwrite($xmloutfile,$xmlstring); } echo " Running: Program is operating normally @@ -235,6 +244,13 @@ if ($retval) { "; } + // If you are reading these values from a file rather than + // making live queries to the database, do something like this: + // + // $sendfile = "/home/boincadm/server_status_data/count_results_unsent.out"; + // $n = `/bin/tail -1 $sendfile`; + // show_counts("Results ready to send","results_ready_to_send",$n); + show_counts("Results ready to send","results_ready_to_send",get_mysql_count("result where server_state = 2")); show_counts("Results in progress","results_in_progress",get_mysql_count("result where server_state = 4")); show_counts("Workunits waiting for validation","workunits_waiting_for_validation",get_mysql_count("workunit where need_validate=1")); @@ -253,10 +269,10 @@ if ($retval) { } } -if ($xml) { - echo " \n"; - echo "\n"; -} else { +$xmlstring = " \n\n"; +if ($xml) { echo $xmlstring; } +else { + if ($xmlout) { fwrite($xmloutfile,$xmlstring); } echo "