Mini Shell
<?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['MEM']}</acc5>");
self::SetXML("<acc6>{$row['maxentryprocs']}</acc6>");
self::SetXML("<acc7>{$row['default']}</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("<maxEntryProcs>{$default['maxentryprocs']}</maxEntryProcs>");
self::SetXML('<slist name="mem">'.self::ShowMemList($default['MEM']).'</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("<maxEntryProcs>{$data['maxentryprocs']}</maxEntryProcs>");
self::SetXML('<slist name="mem">'.self::ShowMemList($data['MEM']).'</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("<CpuLimit>{$item['lCPU']}</CpuLimit>");
self::SetXML("<Amem>".round(($item['aMem']/1024/1024),2)." MB</Amem>");
self::SetXML("<Mmem>".round(($item['mMem']/1024/1024),2)." MB</Mmem>");
self::SetXML("<MemLimit>".round(($item['lMem']/1024/1024),2)." MB</MemLimit>");
self::SetXML("<Amep>".$item['aEP']."</Amep>");
self::SetXML("<Mmep>".$item['mEP']."</Mmep>");
self::SetXML("<MepLimit>".$item['lEP']."</MepLimit>");
self::SetXML("<MepFaults>".$item['MepF']."</MepFaults>");
self::SetXML("<MemFaults>".$item['MemF']."</MemFaults>");
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;
$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('<CpuLimit>'.$item['lCPU'].'</CpuLimit>');
self::SetXML('<Amem>'.round(($item['aMem']/1024/1024),2).'</Amem>');
self::SetXML('<Mmem>'.round(($item['mMem']/1024/1024),2).'</Mmem>');
self::SetXML('<MemLimit>'.round(($item['lMem']/1024/1024),2).'</MemLimit>');
self::SetXML('<Amep>'.$item['aEP'].'</Amep>');
self::SetXML('<Mmep>'.$item['mEP'].'</Mmep>');
self::SetXML('<MepLimit>'.$item['lEP'].'</MepLimit>');
self::SetXML('<MepFaults>'.$item['MepF'].'</MepFaults>');
self::SetXML('<MemFaults>'.$item['MemF'].'</MemFaults>');
self::SetXML('</elem>');
// <![CDATA[<script>alert("data");</script> top.mn_cancel_form();
} else {
$MepFaults += $item['MepF'];
$MemFaults += $item['MemF'];
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 .= 'Memory resources 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("<aMEM>{$elem[8]}</aMEM>");
self::SetXML("<mMEM>{$elem[9]}</mMEM>");
self::SetXML("<lMEM>{$elem[10]}</lMEM>");
self::SetXML("<MemF>{$elem[11]}</MemF>");
self::SetXML("<MepF>{$elem[12]}</MepF>");
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 <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="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 <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>
</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 <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 <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="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 <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>
</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 <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