<?php $start_time=microtime(true);?>

<?php
$pinfo_ver="v0.04";
/* Author: G Bentley, 2017 Contact: gbentley@uk2.net */
/* Prerequisites: RPi, httpd, php and sysstat */

/* SET USER VARIABLES BELOW */

/* Title bar date format - See http://php.net/manual/en/function.date.php */ 
$date_format="l d F, Y";

/* Your network interfaces? '#ifconfig -a' or '#ip link show' or '#ls /sys/class/net' */
$net_if0="eth0";
$net_if1="lo";
$net_if2="example";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base target="_blank"/>
<title>Pinfo <?php echo $pinfo_ver;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="https://www.raspberrypi.org/app/themes/mind-control/images/favicon.png" />

<style type="text/css">
body {font-family:verdana;font-size:12px;background:#BEBAB3;background:linear-gradient(#696358,#BEBAB3) fixed no-repeat;}
pre {font-family:monospace;font-size:12px;line-height:12px;color:#000;}
a {text-decoration:none;color:#BC0331;}
.info {cursor: help;color:#fff;}
.pilogo {background-image:url("https://upload.wikimedia.org/wikipedia/en/thumb/c/cb/Raspberry_Pi_Logo.svg/95px-Raspberry_Pi_Logo.svg.png");background-repeat:no-repeat;background-position:right 20px top 4px;} 
.mono {font-family:monospace;font-size:12px;line-height:12px;}
.layout {width: 830px;margin: 0 auto;}
.about {text-align:justify;font-family:verdana;font-size:12px;}
.title {padding:4px;border:1px solid #37352F;text-align:center;background:#BC1142;color:#fff;font-weight:bold;margin-top:20px;}
.infobox {padding:0px; border: 1px solid #37352F; margin:10px 0px 0px 0px;text-align:left;}
.infobox-title {padding: 4px; text-align: left;background:#75A928;color:#fff;font-weight: bold;}
.infobox-content {padding: 4px; text-align: left;border-top: 1px solid #37352F;background:#fff;}
.infobox-df {float:left;width:386px;margin-right:10px}
.infobox-net {float:right;width:434px;}
.infobox-pidstat {float:left;width:600px;margin-right:10px}
.infobox-meminfo {float:right;width:220px}
.infobox-about {float:right;width:220px;}
#clearfix::after{content:"";clear: both;display: table;}
.footer {padding:4px;border:1px solid #37352F;text-align:center;background:#BC1142;color:#fff;font-weight:bold;margin:10px 0px 20px 0px;}
</style>
</head>

 <body>
  <div class="layout">
      
       <div class="title" style="text-shadow:1px 1px 1px #660B24">Pinfo <?php echo $pinfo_ver;?> :: System Information for RasPi Web Servers :: <?php print(date($date_format));?></div>
 
       <div class="infobox">
          <div class="infobox-title">
             <a href="http://man7.org/linux/man-pages/man1/lscpu.1.html" title="man lscpu" class="info">&#9432;</a> System Vitals
          </div>
          <div class="infobox-content">
	   <div class="pilogo">

<pre><?php system("lscpu");?>
Kernel:              <?php system("cat /proc/version | grep -Po '.+P'");?>
<?php Board();?> 
<?php ChipType();?> 
CPU Temp:	     <?php CpuTemp();?></pre>
           </div>
	  </div>
       </div>
 
       <div class="infobox">
          <div class="infobox-title">
          <a href="http://man7.org/linux/man-pages/man1/uptime.1.html" title="man uptime" class="info">&#9432;</a> Uptime
          </div>
          <div class="infobox-content">
          <pre><?php system("uptime");?></pre>
          </div>
       </div>
       
       <div class="infobox">
          <div class="infobox-title">
          <a href="http://man7.org/linux/man-pages/man1/mpstat.1.html" title="man mpstat" class="info">&#9432;</a> Processor Stats
          </div>
          <div class="infobox-content">
          <pre><?php system("mpstat");?></pre>
          </div>
       </div>
       
       <div class="infobox">
          <div class="infobox-title">
          <a href="http://man7.org/linux/man-pages/man8/lsusb.8.html" title="man lsusb" class="info">&#9432;</a> USB Information
          </div>
          <div class="infobox-content">
          <pre><?php system("lsusb");?></pre>
          </div>
       </div>
       
       <div class="infobox-df">
        <div class="infobox">
          <div class="infobox-title">
          <a href="http://man7.org/linux/man-pages/man1/df.1.html" title="man df" class="info">&#9432;</a> Disk Usage
          </div>
          <div class="infobox-content">
          <pre><?php system("df -h");?></pre>
          </div>
        </div>
       </div>

       <div class="infobox-net">
        <div class="infobox">
          <div class="infobox-title">
          <a href="https://en.wikipedia.org/wiki/Sysfs" title="sysfs info" class="info">&#9432;</a> Network Usage
          </div>
          <div class="infobox-content">

	    <div class="mono">	
	    <p>
	    Ethernet &#171; RX Bytes (KiB): <?php system("cat /sys/class/net/".$net_if0."/statistics/rx_bytes");?> &#166; RX Packets: <?php system("cat /sys/class/net/".$net_if0."/statistics/rx_packets");?><br/>
	    Ethernet &#187; TX Bytes (KiB): <?php system("cat /sys/class/net/".$net_if0."/statistics/tx_bytes");?> &#166; TX Packets: <?php system("cat /sys/class/net/".$net_if0."/statistics/tx_packets");?><br/>
	    Ethernet &#171; Receive Errors: <?php system("cat /sys/class/net/".$net_if0."/statistics/rx_errors");?> &#166; Packets Dropped: <?php system("cat /sys/class/net/".$net_if0."/statistics/rx_dropped");?></p>
	    <p>	
	    Loopback &#171; RX Bytes (KiB): <?php system("cat /sys/class/net/".$net_if1."/statistics/rx_bytes");?> &#166; RX Packets: <?php system("cat /sys/class/net/".$net_if1."/statistics/rx_packets");?><br/>
	    Loopback &#187; TX Bytes (KiB): <?php system("cat /sys/class/net/".$net_if1."/statistics/tx_bytes");?> &#166; TX Packets: <?php system("cat /sys/class/net/".$net_if1."/statistics/tx_packets");?><br/>
	    Loopback &#171; Receive Errors: <?php system("cat /sys/class/net/".$net_if1."/statistics/rx_errors");?> &#166; Packets Dropped: <?php system("cat /sys/class/net/".$net_if1."/statistics/rx_dropped");?></p>
	    <p>
	    Total Bytes (<abbr title='1 Kibibyte=1024 bytes - https://en.wikipedia.org/wiki/Kibibyte' style='cursor: help'>KiB</abbr>): <?php echo TotalBytes($net_if0,$net_if1);?> &#166; Total Packets: <?php echo TotalPacks($net_if0,$net_if1);?></p>
	  </div>
         </div>
        </div>
       </div>

       <div class="infobox-pidstat">
         <div class="infobox">
          <div class="infobox-title">
           <a href="http://man7.org/linux/man-pages/man1/pidstat.1.html" title="man pidstat" class="info">&#9432;</a> PID Statistics
           </div>
          <div class="infobox-content">
          <pre><?php system("pidstat");?></pre>
          </div> 
         </div> 
       </div>
       
       <div class="infobox-meminfo">
         <div class="infobox">
          <div class="infobox-title">
           <a href="https://www.kernel.org/doc/Documentation/filesystems/proc.txt" title="procfs info" class="info">&#9432;</a> Memory Info
           </div>
          <div class="infobox-content">
          <pre><?php system("cat /proc/meminfo");?></pre>
          </div> 
         </div> 
       </div>

	<div class="infobox-about">
	 <div class="infobox">
          <div class="infobox-title">
          About Pinfo
          </div>
          <div class="infobox-content">
	   <div class="about">
            Pinfo is a PHP script that displays the hardware &amp; system statistics of your <a href="https://www.raspberrypi.org">
            Raspberry Pi&trade;</a> powered Web Server - by G Bentley, 2017 Pinfo is free software published under the terms of 
            <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a><br/> See also:- 
            <a href="http://linfo.sourceforge.net">Linfo</a> and <a href="http://phpsysinfo.github.io/phpsysinfo">phpSysInfo</a>
	   </div>
          </div>
         </div>
       </div>
	
      <div id="clearfix"></div>

     <div class="footer" style="text-shadow:1px 1px 1px #660B24">
     Pinfo <?php echo $pinfo_ver;?> &#187; Served by <?php echo GetServer();?> and PHP <?php echo phpversion();?> &#187; Page generated in <?php echo(number_format(microtime(true) - $start_time, 2));?> seconds
  </div>

</div>
</body>
</html>

<?php function Board(){
		      $getboard=exec("cat /proc/device-tree/model");
		      $board=preg_replace('/[^A-Za-z0-9 _\-\+\.]/','',$getboard);
		      echo "Board:               $board";}
?>

<?php function ChipType(){
			 $chiptype=exec("cat /proc/cpuinfo | grep -m 1 \"Hardware\" | cut -f2- -d':'");
			 $revision=exec("cat /proc/cpuinfo | grep -m 1 \"Revision\" | cut -f2- -d':'");
			 echo "Chiptype:           $chiptype Rev:$revision";}
?>

<?php function CpuTemp(){		
			$temp0=exec("cat /sys/class/thermal/thermal_zone0/temp");
			$temp1=(intval($temp0/1000));
			$temp2=(($temp0/100));
			$tempM=(($temp2 % $temp1));
			echo "$temp1.$tempM&deg;C";
			}
?>

<?php function TotalBytes($net_if0,$net_if1){
                            $net1=exec("cat /sys/class/net/$net_if0/statistics/rx_bytes");
                            $net2=exec("cat /sys/class/net/$net_if0/statistics/tx_bytes");
                            $net3=exec("cat /sys/class/net/$net_if1/statistics/rx_bytes");
                            $net4=exec("cat /sys/class/net/$net_if1/statistics/tx_bytes"); 
                            $totbytes=($net1 + $net2 + $net3 + $net4);
                            return $totbytes;}
?>
                        
<?php function TotalPacks($net_if0,$net_if1){                              
                            $net5=exec("cat /sys/class/net/$net_if0/statistics/rx_packets");
                            $net6=exec("cat /sys/class/net/$net_if0/statistics/tx_packets");
                            $net7=exec("cat /sys/class/net/$net_if1/statistics/rx_packets");
                            $net8=exec("cat /sys/class/net/$net_if1/statistics/tx_packets");
                            $totpacks=($net5 + $net6 + $net7 + $net8);
                            return $totpacks;}
?>                       

<?php function GetServer(){
                          if(isset($_SERVER['SERVER_SOFTWARE'])){
                          return $_SERVER['SERVER_SOFTWARE'];}}
?>
