Mini Shell

Direktori : /usr/share/l.v.e-manager/ispmanager/liblve1.1/addon/lvemanager/
Upload File :
Current File : //usr/share/l.v.e-manager/ispmanager/liblve1.1/addon/lvemanager/output.class.php

<?php

/**
 * Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */
    
class ISPOutput {
    
    private $XMLBody = '';
    public $Error = '';
    
    // Set XMLBody
    private function SetXML($val,$rewrite = 0) {
        if (0 == $rewrite)
            $this->XMLBody .= $val;
        else 
            $this->XMLBody = $val;
    }
    
    // Get XMLBody
    private function GetXML() {
        return $this->XMLBody;
    }
    
    // Return Success result data
    private function PrintResult() {
        if (!self::IfError()) {
            $return = '<?xml version="1.0" encoding="UTF-8"?>';
            $return .= '<doc><error code="1">'.PHP_EOL.PHP_EOL.$this->Error.'</error></doc>';
            return $return;
        } else {
            $return = '<?xml version="1.0" encoding="UTF-8"?>';
            $return .= '<doc>'.self::GetXML().'</doc>';
            return $return;
        }
    }
    
    // Return Error Data
    private function PrintError() {
        
    }
    
    public function IfError() {
        if ($this->Error == '') {
            return true;
        } else {
            return false;
        }
    }
    
    public function SetError($error) {
        if (self::IfError())
            $this->Error=$error;
    }
    
    // Format Body Xml for Home tab
    public function HomeResult($data = array()) {
        if (0 != count($data)) {
            self::SetXML('',1); // Set XMLBody blank
            
            foreach ($data as $row) {
                self::SetXML('<elem>');
                foreach ($row as $key => $val) {
                    if (5 == $key) {
                        $val = round(($val/1024),2).' MB';
                    }
                    self::SetXML("<item{$key}>{$val}</item{$key}>");
                }
                self::SetXML('</elem>');
            }
        }
        return self::PrintResult();
    }
    
    public function HomeResultAuto($data = array()) {
        if (0 != count($data)) {
            self::SetXML('',1); // Set XMLBody blank
            
            foreach ($data as $row) {
                self::SetXML('<elem>');
                foreach ($row as $key => $val) {
                    if (5 == $key) {
                        $val = round(($val/1024),2).' MB';
                    }
                    self::SetXML("<item{$key}>{$val}</item{$key}>");
                }
                self::SetXML('</elem>');
            }
        }
        return self::PrintResult();
    }
    
    // Format Body Xml for accounts tab
    public function AccountResult($data = array()) {
        if (0 != count($data)) {
            self::SetXML('',1); // Set XMLBody blank
            
            foreach ($data as $row) {
                self::SetXML('<elem>');
                self::SetXML("<acc0>{$row['UserName']}</acc0>");
                self::SetXML("<acc1>{$row['Domains']}</acc1>");
                self::SetXML("<acc2>{$row['LveID']}</acc2>");
                self::SetXML("<acc3>{$row['SPEED']}</acc3>");
                self::SetXML("<acc4>{$row['NCPU']}</acc4>");
                self::SetXML("<acc5>{$row['VMEM']}</acc5>");
                self::SetXML("<acc5-1>{$row['PMEM']}</acc5-1>");
                self::SetXML("<acc6>{$row['EP']}</acc6>");
                self::SetXML("<acc6-1>{$row['NPROC']}</acc6-1>");
                self::SetXML("<acc6-2>{$row['IO']}</acc6-2>");
                self::SetXML("<acc7>{$row['PACKAGE']}</acc7>");
                self::SetXML('</elem>');
            }
        }
        return self::PrintResult();
    }
    
    // Return Memory select
    public function ShowMemList($default) {
        $return = '';
        $default = str_replace(' MB',' ',$default);
        $default = str_replace('*',' ',$default);
        $default = str_replace('M',' ',$default);
        $return .= '<msg key="'.$default.'M">'.$default.' MB</msg>';
        $return .= '<msg key="0">Disabled</msg>';
        for ($i = 128; $i <= 16256; $i+=128) {
            if ($i != $default)
                $return .= '<msg key="'.$i.'M">'.$i.' MB</msg>';
        }
        return $return;
    }
    
    // Show Defaul Settings Form
    public function DefaultShow($default) {
        if (0 != count($default)) {
            self::SetXML('',1); // Set XMLBody blank
            self::SetXML('<elid>Edit</elid>');
            self::SetXML("<cpu>{$default['SPEED']}</cpu>");
            self::SetXML("<ncpu>{$default['NCPU']}</ncpu>");
            self::SetXML("<nproc>{$default['NPROC']}</nproc>");
            self::SetXML("<io>{$default['IO']}</io>");
            self::SetXML("<maxEntryProcs>{$default['maxentryprocs']}</maxEntryProcs>");
            self::SetXML('<slist name="mem">'.self::ShowMemList($default['MEM']).'</slist>');
            self::SetXML('<slist name="pmem">'.self::ShowMemList($default['PMEM']).'</slist>');
        }
        return self::PrintResult();
    }
    
    // Show User Settings
    public function UserShow($data) {
         if (0 != count($data)) {
            self::SetXML('',1); // Set XMLBody blank
            self::SetXML("<elid>{$data['UserName']}</elid>");
            self::SetXML("<uid>{$data['UserID']}</uid>");
            self::SetXML("<cpu>{$data['SPEED']}</cpu>");
            self::SetXML("<ncpu>{$data['NCPU']}</ncpu>");
            self::SetXML("<nproc>{$data['NPROC']}</nproc>");
            self::SetXML("<io>{$data['IO']}</io>");
            self::SetXML("<maxEntryProcs>{$data['EP']}</maxEntryProcs>");
            self::SetXML('<slist name="mem">'.self::ShowMemList($data['VMEM']).'</slist>');
            self::SetXML('<slist name="pmem">'.self::ShowMemList($data['PMEM']).'</slist>');
        }
        return self::PrintResult();
    }
    
    // Return Form OK
    public function FormOK($param = 0) {
        self::SetXML('',1); // Set XMLBody blank
        switch ($param) {
            case 1: self::SetXML('<redirect>location=\'ispmgr?func=lvemanager.confirmation\'</redirect>');  break;
            case 2: self::SetXML('<elid>OK</elid>'); break;
            default: self::SetXML('<ok/>'); break;
        }
        return self::PrintResult();
    }
    
    // Return detail info
    public function GetDetailInfo($data) {
        self::SetXML('',1); // Set XMLBody blank
                
        foreach ($data as $item) {
            self::SetXML('<elem>');
                self::SetXML("<time>{$item['time']}</time>");
                self::SetXML("<User>{$item['User']}</User>");
                self::SetXML("<aCPU>{$item['aCPU']}</aCPU>");
                self::SetXML("<mCPU>{$item['mCPU']}</mCPU>");
                self::SetXML("<lCPU>{$item['lCPU']}</lCPU>");
                self::SetXML("<avMEM>".round(($item['aMem']/1024/1024),2)." MB</avMEM>");
                self::SetXML("<mvMEM>".round(($item['mMem']/1024/1024),2)." MB</mvMEM>");
                self::SetXML("<lvMEM>".round(($item['lMem']/1024/1024),2)." MB</lvMEM>");
                self::SetXML("<apMEM>".round(($item['apMem']/1024/1024),2)." MB</apMEM>");
                self::SetXML("<mpMEM>".round(($item['mpMem']/1024/1024),2)." MB</mpMEM>");
                self::SetXML("<lpMEM>".round(($item['lpMem']/1024/1024),2)." MB</lpMEM>");
                self::SetXML("<aEP>".$item['aEP']."</aEP>");
                self::SetXML("<mEP>".$item['mEP']."</mEP>");
                self::SetXML("<lEP>".$item['lEP']."</lEP>");
                self::SetXML("<aNPROC>".$item['aNproc']."</aNPROC>");
                self::SetXML("<mNPROC>".$item['mNproc']."</mNPROC>");
                self::SetXML("<lNPROC>".$item['lNproc']."</lNPROC>");
                self::SetXML("<vMemF>".$item['vMemF']."</vMemF>");
                self::SetXML("<pMemF>".$item['pMemF']."</pMemF>");
                self::SetXML("<epF>".$item['EPf']."</epF>");
                self::SetXML("<NprocF>".$item['NprocF']."</NprocF>");
            self::SetXML('</elem>');
        }
        return self::PrintResult();
    }
    
    // Return Chart Data
    public function GetChart($data, $onlyLimits = 0) {
        self::SetXML('',1); // Set XMLBody blank
        $MepFaults = 0;
        $MemFaults = 0;
        $PMemFaults = 0;
        $NprocFaults = 0;
        $CpuLimit = 0;
        foreach ($data as $item) {
            if ($onlyLimits == 0) {
                self::SetXML('<elem>');
                    self::SetXML('<time>'.$item['time'].'</time>');
                    self::SetXML('<aCPU>'.$item['aCPU'].'</aCPU>');
                    self::SetXML('<mCPU>'.$item['mCPU'].'</mCPU>');
                    self::SetXML('<lCPU>'.$item['lCPU'].'</lCPU>');
                    self::SetXML('<aEP>'.$item['aEP'].'</aEP>');
                    self::SetXML('<mEP>'.$item['mEP'].'</mEP>');
                    self::SetXML('<lEP>'.$item['lEP'].'</lEP>');
                    self::SetXML('<avMEM>'.round(($item['aMem']/1024/1024),2).'</avMEM>');
                    self::SetXML('<mvMEM>'.round(($item['mMem']/1024/1024),2).'</mvMEM>');
                    self::SetXML('<lvMEM>'.round(($item['lMem']/1024/1024),2).'</lvMEM>');
                    self::SetXML('<apMEM>'.round(($item['apMem']/1024/1024),2).'</apMEM>');
                    self::SetXML('<mpMEM>'.round(($item['mpMem']/1024/1024),2).'</mpMEM>');
                    self::SetXML('<lpMEM>'.round(($item['lpMem']/1024/1024),2).'</lpMEM>');
                    self::SetXML('<aNPROC>'.$item['aNproc'].'</aNPROC>');
                    self::SetXML('<lNPROC>'.$item['lNproc'].'</lNPROC>');
                    self::SetXML('<mNPROC>'.$item['mNproc'].'</mNPROC>');
                    self::SetXML('<vMemF>'.$item['vMemF'].'</vMemF>');
                    self::SetXML('<pMemF>'.$item['pMemF'].'</pMemF>');
                    self::SetXML('<epF>'.$item['EPf'].'</epF>');
                    self::SetXML('<NprocF>'.$item['NprocF'].'</NprocF>');
                self::SetXML('</elem>');
// <![CDATA[<script>alert("data");</script>                top.mn_cancel_form();
            } else {
                $MepFaults += $item['MepF'];
                $MemFaults += $item['MemF'];
                $PMemFaults += $item['pMemF'];
                $NprocFaults += $item['NprocF'];
                
                if ($item['mCPU'] >= $item['lCPU'])
                    $CpuLimit = 1;
            }
        }
        if ($onlyLimits != 0) {
            $msg = '<Limits><![CDATA[';
            self::SetXML('<elem>');
                if  ($MepFaults != 0 || $MemFaults != 0 || $CpuLimit != 0) {
                    $msg .= 'Your site has been limited within the past 24 hours'.PHP_EOL;
                    
                    if ($MepFaults != 0)
                        $msg .= 'You have reached entry processes (number of simultaneously running php and cgi scripts, as well as cron jobs and shell sessions) limit '.$MepFaults.' times'.PHP_EOL;
                        
                    if ($MemFaults != 0)
                        $msg .= 'Virtual Memory resources were limited for your site'.PHP_EOL;
                    
                    if ($PMemFaults != 0)
                        $msg .= 'Physical Memory resources were limited for your site'.PHP_EOL;
                    
                    if ($NprocFaults != 0)
                        $msg .= 'Processes were limited for your site'.PHP_EOL;
                         
                                
                    if ($CpuLimit != 0)
                        $msg .= 'CPU resources were limited for your site'.PHP_EOL;
                        
                } else {
                    $msg .= 'Your site had no issues in the past 24 hours'.PHP_EOL;
                    
                    if ( (( !$CpuLimit ) && ( $item['mCPU'] > 90 )) || 
                         (( $MemFaults == 0 ) && ( round(($item['lMem']/1024/1024),2) > 0 ) && ( round(($item['mMem']/1024/1024),2) > round(($item['lMem']/1024/1024),2) * 0.9 )) || 
                         (( $MepFaults == 0 ) && ( $item['lEP'] > 0 )  && ($item['mEP'] > $item['lEP'] * 0.9 ))
                       ) 
                    {
                        $msg .= 'Your site might hit resource limits soon'.PHP_EOL;

                    	if ( ( !$CpuLimit ) && ( $item['mCPU'] > 90 ) ) {
                    		$msg .= 'Your CPU usage was at '.$item['mCPU'].'% out of 100%'.PHP_EOL;
                    	}
                    	
                    	if ( ( $MemFaults == 0 ) && ( round(($item['lMem']/1024/1024),2) > 0 ) && ( round(($item['mMem']/1024/1024),2) > round(($item['lMem']/1024/1024),2) * 0.9 ) ) 
                    	{
                    		$msg .= 'Your Memory usage was at '.round(($item['mMem']/1024/1024),2).'MB out of '.round(($item['lMem']/1024/1024),2).'MB'.PHP_EOL;
                    	}
                    
                    	if ( ( $MepFaults == 0 ) && ( $item['lEP'] > 0 ) && ( $item['mEP'] > $item['lEP'] * 0.9 ) ) 
                    	{
                    		$msg .= 'You had '.$item['mEP'].' entry processes (number of simultaneously running php and cgi scripts, as well as cron jobs and shell sessions) out of '.$item['lEP'].' max entry processes allowed'.PHP_EOL;
                    	}
                    }


                }
            $msg .= ']]></Limits>';
            self::SetXML($msg);
            self::SetXML('</elem>');
        }
        return self::PrintResult();
    }
    
    // Set Up time period for Chart
    public function ChartSetup($type = null) {
        self::SetXML('',1); // Set XMLBody blank
        self::SetXML('<elid>Select time</elid>');
        self::SetXML('<slist name="time">
            <msg key="10m">Last 10 minutes</msg>
            <msg key="30m">Last 30 minutes</msg>
            <msg key="1h">Last hour</msg>
            <msg key="4h">Last 4 hours</msg>
            <msg key="today">Today</msg>
            <msg key="yesterday">Yesterday</msg>
            <msg key="7d">Last 7 days</msg>
            <msg key="30d">Last 30 days</msg>
        </slist>');
        return self::PrintResult();
    }
    
    // Redirect to chart view after setup time
    public function ChartRedirect($chart,$time) {
        self::SetXML('',1); // Set XMLBody blank
        $time = explode('&',$time);
        $time = $time[0];
        $time = explode('=',$time);
        $time = $time[1];
        self::SetXML('<ok>top<![CDATA[
        <script>
           top.mn_cancel_form();
           top.mn_load_loc ( "binary", "?func=lvemanager.chart.show'.$chart.'&time='.$time.'&clickstat=yes", "list" );
        </script>
        ]]></ok>');
        return self::PrintResult();
    }
    
    // Statictic Blank Show
    public function StatBlankShow() {
        self::SetXML('',1); // Set XMLBody blank
        self::SetXML('<elem>');
        self::SetXML("<LVE_id><![CDATA[<script>top.mn_load_loc ( 'binary', '?func=lvemanager.statistic.setup', 'form' );</script>]]></LVE_id>");
        self::SetXML('</elem>');
        return self::PrintResult();
    }
    
    // Statistic show
    public function StatShow($data,$RequestString) {
        $temp = explode('period=',$RequestString);
        $temp = explode('&',$temp[1]);
        self::SetXML('',1); // Set XMLBody blank
        if (0 == count($data)) {
            self::SetXML('<elem>');
            self::SetXML('</elem>');
        } else {
            foreach ($data as $elem) {
                self::SetXML('<elem>');
                self::SetXML("<LVE_id>{$elem[0]}</LVE_id>");
                if (!isset($_SESSION['user']))
                    $_SESSION['user'] = $elem[1];
                self::SetXML('<User>'.$elem[1].'</User>');
                self::SetXML("<aCPU>{$elem[2]}</aCPU>");
                self::SetXML("<mCpu>{$elem[3]}</mCpu>");
                self::SetXML("<lCpu>{$elem[4]}</lCpu>");
                self::SetXML("<aEP>{$elem[5]}</aEP>");
                self::SetXML("<mEP>{$elem[6]}</mEP>");
                self::SetXML("<lEP>{$elem[7]}</lEP>");
                self::SetXML("<avMEM>{$elem[8]}</avMEM>");
                self::SetXML("<mvMEM>{$elem[9]}</mvMEM>");
                self::SetXML("<lvMEM>{$elem[10]}</lvMEM>");
                self::SetXML("<vMemF>{$elem[11]}</vMemF>");
                self::SetXML("<epF>{$elem[12]}</epF>");
                self::SetXML("<apMEM>{$elem[13]}</apMEM>");
                self::SetXML("<mpMEM>{$elem[14]}</mpMEM>");
                self::SetXML("<lpMEM>{$elem[15]}</lpMEM>");
                self::SetXML("<aNPROC>{$elem[16]}</aNPROC>");
                self::SetXML("<mNPROC>{$elem[17]}</mNPROC>");
                self::SetXML("<lNPROC>{$elem[18]}</lNPROC>");
                self::SetXML("<pMemF>{$elem[19]}</pMemF>");
                self::SetXML("<NprocF>{$elem[20]}</NprocF>");
                self::SetXML('</elem>');
            }
            $file = fopen(getcwd().'/addon/lvemanager/detail_root',"w");
            fwrite($file,'<?php'.PHP_EOL);
            fwrite($file,'$_SESSION[\'period\']=\''.$temp[0].'\';'.PHP_EOL);
            fwrite($file,'$_SESSION[\'user\']=\''.$_SESSION['user'].'\';'.PHP_EOL);
            fclose($file);
        }
            
        return self::PrintResult();
    }
    
    public function StatFilterApply($redirect) {
        self::SetXML('',1); // Set XMLBody blank
        self::SetXML('<elid>Setup</elid>');
        self::SetXML('<slist name="Timeframe">
            <msg key="10m">Last 10 minutes</msg>
            <msg key="30m">Last 30 minutes</msg>
            <msg key="1h">Last hour</msg>
            <msg key="4h">Last 4 hours</msg>
            <msg key="today">Today</msg>
            <msg key="yesterday">Yesterday</msg>
            <msg key="7d">Last 7 days</msg>
            <msg key="30d">Last 30 days</msg>
        </slist>');
        self::SetXML('<order-by>
            <![CDATA[
                <br />
                Show &nbsp;&nbsp; <input type="radio" name="filter_type" value="order-by" checked />
                <br /><br />
                Show TOP LVEs By 
                <select name="order-by" size="1">
                    <option value="cpu_max">Max CPU</option>
                    <option value="cpu_avg">Average CPU</option>
                    <option value="mep_max">Max EP</option>
                    <option value="mep_avg">Average EP</option>
                    <option value="mem_max">Max MEM</option>
                    <option value="mem_avg">Average MEM</option> 
                    <option value="pmem_max">Max pMEM</option>
                    <option value="pmem_avg">Average pMEM</option>
                    <option value="total_mem_faults">Memory Faults</option>
                    <option value="total_mep_faults">Entry Procs Faults</option>
                </select>
                <br /><br />
                Limit:
                <select name="limit" size="1">
                    <option>10</option>
                    <option>25</option>
                    <option>50</option>
                    <option>100</option>
                </select>
                <br />
            ]]>
        </order-by>');
        self::SetXML('<by-usage>
            <![CDATA[
                <br />
                Show &nbsp;&nbsp; <input type="radio" name="filter_type" value="by-usage" />
                <br /><br />
                Show LVEs Approaching Limit
                <select name="by-usage" size="1">
                    <option value="cpu_max">Max CPU</option>
                    <option value="cpu_avg">Average CPU</option>
                    <option value="mep_max">Max EP</option>
                    <option value="mep_avg">Average EP</option>
                    <option value="mem_max">Max MEM</option>
                    <option value="mem_avg">Average MEM</option>
                    <option value="pmem_max">Max pMEM</option>
                    <option value="pmem_avg">Average pMEM</option>
                </select>
                <br /><br />
                Using:
                <select name="percentage" size="1">
                    <option>50</option>
                    <option>75</option>
                    <option>90</option>
                    <option>95</option>
                </select>
                <br />
            ]]>
        </by-usage>');
        self::SetXML('<by-fault>
            <![CDATA[
                <br />
                Show &nbsp;&nbsp; <input type="radio" name="filter_type" value="by-usage" />
                <br /><br />
                By Fault
                <select name="by-fault" size="1">
                    <option value="mep">Max Entry Processes</option>
                    <option value="mem">Max Memory Limit</option>
                </select>
                <br /><br />
                Treshold:
                <select name="threshold" size="1">
                    <option>1</option>
                    <option>10</option>
                    <option>50</option>
                    <option>75</option>
                    <option>1000</option>
                </select>
                <br />
                <script>
                    '.$redirect.';
                </script>
            ]]>
        </by-fault>');
        return self::PrintResult();
    }
    
    // Statictic Setup
    public function StatSetupShow() {
        self::SetXML('',1); // Set XMLBody blank
        self::SetXML('<elid>Setup</elid>');
        self::SetXML('<slist name="Timeframe">
            <msg key="10m">Last 10 minutes</msg>
            <msg key="30m">Last 30 minutes</msg>
            <msg key="1h">Last hour</msg>
            <msg key="4h">Last 4 hours</msg>
            <msg key="today">Today</msg>
            <msg key="yesterday">Yesterday</msg>
            <msg key="7d">Last 7 days</msg>
            <msg key="30d">Last 30 days</msg>
        </slist>');
        self::SetXML('<order-by>
            <![CDATA[
                <br />
                Show &nbsp;&nbsp; <input type="radio" name="filter_type" value="order-by" checked />
                <br /><br />
                Show TOP LVEs By 
                <select name="order-by" size="1">
                    <option value="cpu_max">Max CPU</option>
                    <option value="cpu_avg">Average CPU</option>
                    <option value="mep_max">Max EP</option>
                    <option value="mep_avg">Average EP</option>
                    <option value="mem_max">Max MEM</option>
                    <option value="mem_avg">Average MEM</option> 
                    <option value="pmem_max">Max pMEM</option>
                    <option value="pmem_avg">Average pMEM</option>
                    <option value="total_mem_faults">Memory Faults</option>
                    <option value="total_mep_faults">Entry Procs Faults</option>
                </select>
                <br /><br />
                Limit:
                <select name="limit" size="1">
                    <option>10</option>
                    <option>25</option>
                    <option>50</option>
                    <option>100</option>
                </select>
                <br />
            ]]>
        </order-by>');
        self::SetXML('<by-usage>
            <![CDATA[
                <br />
                Show &nbsp;&nbsp; <input type="radio" name="filter_type" value="by-usage" />
                <br /><br />
                Show LVEs Approaching Limit
                <select name="by-usage" size="1">
                    <option value="cpu_max">Max CPU</option>
                    <option value="cpu_avg">Average CPU</option>
                    <option value="mep_max">Max EP</option>
                    <option value="mep_avg">Average EP</option>
                    <option value="mem_max">Max MEM</option>
                    <option value="mem_avg">Average MEM</option>
                    <option value="pmem_max">Max pMEM</option>
                    <option value="pmem_avg">Average pMEM</option>
                </select>
                <br /><br />
                Using:
                <select name="percentage" size="1">
                    <option>50</option>
                    <option>75</option>
                    <option>90</option>
                    <option>95</option>
                </select>
                <br />
            ]]>
        </by-usage>');
        self::SetXML('<by-fault>
            <![CDATA[
                <br />
                Show &nbsp;&nbsp; <input type="radio" name="filter_type" value="by-usage" />
                <br /><br />
                By Fault
                <select name="by-fault" size="1">
                    <option value="mep">Max Entry Processes</option>
                    <option value="mem">Max Memory Limit</option>
                </select>
                <br /><br />
                Treshold:
                <select name="threshold" size="1">
                    <option>1</option>
                    <option>10</option>
                    <option>50</option>
                    <option>75</option>
                    <option>1000</option>
                </select>
                <br />
            ]]>
        </by-fault>');
        return self::PrintResult();
    }
}

Zerion Mini Shell 1.0