<?
////////////////////////////////////////////////////////////////////////
/*SMI - SHOUTcast Management Interface
A web based shoutcast server management program
Founding Author: Scott D. Harvanek <scotth@sourcemirrors.org>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.*/
////////////////////////////////////////////////////////////////////////
//
// Data Collection - FIXME
//
////////////////////////////////////////////////////////////////////////

$host = php_uname("n");

// This section is not useful if we are running on Windows
// TODO: Find more useful info for Windows :)

if (!iswin()) {
  $up = shell_exec("/usr/bin/uptime | grep -E 'min|days' | awk '{print $3 $4}' | sed 's/,//g' | sed 's/days/ days/g'");
  $load = shell_exec("/usr/bin/uptime | awk -F'average:' '{ print $2}' | sed 's/,//g'");
  $uram = shell_exec("/usr/bin/free -mto | grep Mem: | awk '{ print $3 \" MB\" }'");
  $fram = shell_exec("/usr/bin/free -mto | grep Mem: | awk '{ print $4 \" MB\" }'");
  $tram = shell_exec("/usr/bin/free -mto | grep Mem: | awk '{ print $2 \" MB\" }'");
  $o = "100";
  // Prevent division by zero
  if ($tram > 0) {
    $usage = $uram / $tram * $o;
  }
  $used = substr($usage, 0, -13);
  $free = $o - $used;
}
?>
<table border="0" width="400px">
        <tr>
                <td align="left">
                <b>System Vitals</b><br>
                </td>
	</tr>
</table>
<table border="0" class="vitals" width="400px"> 
	<tr>
		<td align="right">
		Hostname:
		</td>
		<td>
		<?echo $host;?>
		</td>
	</tr>
<? if (!iswin()) { ?>
	<tr>
		<td align="right">
		System Uptime:
		</td>
		<td>
		<?echo $up;?>
		</td>	
	</tr>
	<tr>
		<td align="right">
		System Load:
		</td>
		<td>	
		<?echo $load;?>
		</td>
	</tr>
	<tr>
                <td align="right">
                Total RAM:
                </td>
                <td>
                <?echo $tram;?>
                </td>
        </tr>
	<tr>
		<td align="right">
		Used RAM:
		</td>
		<td>
		<?echo $uram;?>
		</td>
	</tr>
	<tr>
                <td align="right">
                Free RAM:
                </td>
                <td>
                <?echo $fram;?>
                </td>
        </tr>
	<tr>
		<td align="right">
		Running Processes:
		</td>
		<td>
		<?system("/bin/ps axue | grep -vE '^USER|grep|ps' | wc -l");?>
		</td>
	</tr>
	<tr>
		<td align="right">
		Disk Usage:
		</td>
		<td>
		<?system("/bin/df -hT | grep -vE \"^Filesystem|shm\"   | awk 'BEGIN{print \"<table class='disks'>\"}{w=sprintf(\"%d\",$6);print \"<tr><td>\" $7 \"</td><td>\" $6 \"&nbsp;&nbsp;&nbsp;&nbsp;\" $4\"/\"$3 \"</td></tr>\"}END{print \"</table>\"}'");?>
		</td>
	</tr>
<? } ?>
</table>

