Current File : //root/panel/modules/hardware_info/code/controller.ext.php
<?php
/**
 * @copyright 2014-2015 Sentora Project (http://www.sentora.org/) 
 * Sentora is a GPL fork of the ZPanel Project whose original header follows:
 *
 * ZPanel - A Cross-Platform Open-Source Web Hosting Control panel.
 *
 * @package ZPanel
 * @version $Id$
 * @author Bobby Allen - ballen@bobbyallen.me
 * @copyright (c) 2008-2014 ZPanel Group - http://www.zpanelcp.com/
 * @license http://opensource.org/licenses/gpl-3.0.html GNU Public License v3
 *
 * This program (ZPanel) 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */
class module_controller extends ctrl_module
{

    static function getinit()
{
     return '<script type="text/javascript" src="modules/hardware_info/assets/loader.js"></script>
             <script src="modules/hardware_info/assets/pie.js"></script>';
}

  static function gethelpicon()
    {
        global $zdbh;
        global $controller;
        $temp=$controller->GetControllerRequest('URL','module') ;
        $val = '/assets/one.txt';
        $val1 = '/modules/';
        $name=file_get_contents("modules/$temp/assets/helpicon.txt");
        return $name;
    }

static function getchart()
{
$html_data="<div style=\"width:100%;min-height:100px;\" >";
$html_data.="<table>";
$html_data.="<tr>";
$html_data.="<td><div  id=\"donut_single\" style=\"min-width: 300px;float:left;font-size:12px;\" ></div></td>";
$html_data.="<td><div  id=\"donut_single_1\" style=\"min-width:300px;float:left;font-size:12px;\" ></div></td>";
$html_data.="</tr>";
$html_data.="</table>";
$html_data.="</div>";
return  $html_data;
}
static function getchart_2()
{

$html_data="<div style=\"width:100%;min-height:100px;\" >";
$html_data.="<table>";
$html_data.="<tr>";
$html_data.="<td><div  id=\"donut_single_2\" style=\"min-width: 300px;float:left;font-size:12px;\" ></div></td>";
$html_data.="<td><div  id=\"donut_single_3\" style=\"min-width: 300px;float:left;font-size:12px;\" ></div></td>";
$html_data.="</tr>";
$html_data.="</table>";
$html_data.="</div>";
return  $html_data;
}
    static function gethardwareinfo()
    {
		$cmd='lshw -html';
		$line="";	 
		//$line="<pre>";
		$line.=shell_exec($cmd);
		//$line.="</pre>";
		return $line;
	}
	static function getsysteminfo()
	{
		$cmd='uname -a';
		$line="<div class='hardware_node'>";	 
		$line.=shell_exec($cmd);
		$line.='</div>';
		return $line;
	}
	static function getcpuinfo()
	{
		$cmd='cat /proc/cpuinfo';
		$line="<div class='hardware_node'><pre>";	 
		$line.=shell_exec($cmd);
		$line.='</pre></div>';
		return $line;	
	}

        static function dopiesup()
	{
		$cmd="free | awk 'FNR == 2 {print $3/($2)*100}'";	 
	echo $line=shell_exec($cmd);
    exit;	    
       
	}
    static function dovirtmem()
	{
		$cmd="swapon -s | awk 'FNR == 2 {print $4/($3)*100}'";	 
	echo $line=shell_exec($cmd);
    exit;	    
    }
    static function docpuload()
	{
		$cmd="mpstat | awk 'FNR ==4{print $4+$5+$6}'";	 
	echo $line=shell_exec($cmd);
    exit;	    
    }
    
   /*  static function docpuload()
	{
	             
                $service_port = 4444 ;
                $address = gethostbyname('localhost');
                $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
                if ($socket === false) {
                // echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
                self::$tryagain=true;
                return false;
                } 


                //  echo "Attempting to connect to '$address' on port '$service_port'...";
                $result = socket_connect($socket, $address, $service_port);
                if ($result === false) {
                //            echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
                self::$tryagain=true;
                return false;

                }
                socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
				$in="command cpuloads";
                 $out = '';
                socket_write($socket, $in, strlen($in));
                $output = "" ;
               
                 while(true)
                {
                sleep(5);
                $out = socket_read($socket, 2048);
                $output .= $out ;
                // echo "Output=".$out."\n\n" ;
                if ($out)
                break ;
                } 
                socket_close($socket);
                exit;
                

	 self::$Ok=true;
	 return true ;  

	}
      /* static function dolocaldiskspace()
	{
    echo $cmd="df | awk 'FNR == 2 {print $3/($2)*100}'";	 
	 $line=shell_exec($cmd);
    echo $line;
    exit;	    
       
	}*/
     static function dolocaldiskspacefn()
    {
               
                $service_port = 4444 ;
                $address = gethostbyname('localhost');
                $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
                if ($socket === false) {
                // echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
                self::$tryagain=true;
                return false;
                } 


                //  echo "Attempting to connect to '$address' on port '$service_port'...";
                $result = socket_connect($socket, $address, $service_port);
                if ($result === false) {
                //            echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
                self::$tryagain=true;
                return false;

                }
                socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
				$in="command localdiskspace";
                 $out = '';
                socket_write($socket, $in, strlen($in));
                $output = "" ;
               
                 while(true)
                {
                sleep(5);
                $out = socket_read($socket, 2048);
                $output .= $out ;
                // echo "Output=".$out."\n\n" ;
                if ($out)
                break ;
                } 
                echo str_replace("%","",$output); 
	            socket_close($socket);
                exit;
                

	 self::$Ok=true;
	 return true ;  


    }
    static function getloadinfo()
	{
		$cmd='w';
		$line="<div class='hardware_node'><pre>";	 
		$line.=shell_exec($cmd);
		$line.='</pre></div>';
		return $line;	
	}
	static function getramusageinfo()
	{
		$cmd='df -h';
		$line="<div class='hardware_node'><pre>";	 
		$line.=shell_exec($cmd);
		$line.='</pre></div>';
		return $line;
	}
	static function gethardwreusageinfo()
	{
		$cmd='free -m';
		$line="<div class='hardware_node'><pre>";	 
		$line.=shell_exec($cmd);
		$line.='</pre></div>';
		return $line;
	}

	static function gettotalnumproc()
	{
		$cmd="nproc";
		$line=shell_exec($cmd);
		return $line;
	}
}