%PDF- %PDF-
| Direktori : /usr/share/l.v.e-manager/interworx/lvemanager/Ctrl/Nodeworx/ |
| Current File : //usr/share/l.v.e-manager/interworx/lvemanager/Ctrl/Nodeworx/LVE.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 LVE {
private $ProcLVEVersion;
private $PanelUsers;
private $PanelPackages;
public function __construct() {
$result = self::CommandExecute('/usr/bin/sudo /usr/sbin/lvectl lve-version');
$result = explode(PHP_EOL,$result);
$this->ProcLVEVersion = $result[0];
self::GetPanelUsers();
unset($result);
}
// Execute Shell Command
private function CommandExecute($command,$result = true) {
if ($result) {
ob_start();
passthru($command);
$return = ob_get_contents();
ob_end_clean();
return $return;
// return explode(PHP_EOL,$return);
} else {
passthru($command);
return true;
}
}
// Simply Get Users from control panel
private function GetPanelUsers() {
$result = self::CommandExecute('/usr/bin/sudo /usr/sbin/lvectl limits all --no-iops');
if ($this->ProcLVEVersion >= 6) {
$counter = 7;
} else {
$counter = 5;
}
while (strpos($result,' ') !== false) {
$result = str_replace(' ',' ',$result);
}
$tmp = explode(' ',trim($result));
for ($i=0; $i<=$counter; $i++) {
$blank[$i] = trim($tmp[$i]);
}
foreach ($tmp as $key => $value) {
if (($key % ($counter+1)) == 0)
$uid = $tmp[$key];
if ($uid != 'ID')
$data[$uid][$blank[($key%($counter+1))]] = str_replace(PHP_EOL,'',$value);
}
foreach ($data as $key => $value) {
$data[$key]['IOPRIO'] = $data[$key]['IO'];
}
// echo '<pre>';
// print_r($data);
// echo '</pre>';
$result = self::CommandExecute('/usr/local/interworx/bin/listaccounts.pex');
$Accounts = array();
$result = explode(chr(10), $result);
foreach ($result as $k)
{
$listAccountsArTmp = explode(chr(9), $k);
if (strlen(trim($listAccountsArTmp[0])) > 0) {
$Accounts[trim($listAccountsArTmp[0])] = trim($listAccountsArTmp[1]);
}
}
// echo '<pre>';
// print_r($Accounts);
// echo '</pre>';
$result = array();
$result['DEFAULT'] = $data['default'];
$result['DEFAULT']['Username'] = '-';
$result['DEFAULT']['Domain'] = '-';
$result['DEFAULT']['ID'] = 'DEFAULT';
$result['DEFAULT']['SPEED'] = $result['DEFAULT']['SPEED'].'%';
foreach ($Accounts as $UserName => $Domain) {
$UserID = str_replace(PHP_EOL,'',self::CommandExecute('getent passwd '.trim($UserName).' | cut -f 3 -d ":"'));
if (key_exists($UserID,$data)) {
$result[$UserID] = $data[$UserID];
$result[$UserID]['Username'] = $UserName;
$result[$UserID]['Domain'] = $Domain;
$result[$UserID]['ID'] = $UserID;
} else {
$result[$UserID] = $data['default'];
$result[$UserID]['Username'] = $UserName;
$result[$UserID]['Domain'] = $Domain;
$result[$UserID]['ID'] = $UserID;
}
$result[$UserID]['SPEED'] = $result[$UserID]['SPEED'].'%';
if ($result[$UserID]['SPEED'] != $result['DEFAULT']['SPEED']) {
$result[$UserID]['SPEED'] = '<span style="color:#EE0000">'.$result[$UserID]['SPEED'].'</span>';
}
if ($result[$UserID]['NCPU'] != $result['DEFAULT']['NCPU']) {
$result[$UserID]['NCPU'] = '<span style="color:#EE0000">'.$result[$UserID]['NCPU'].'</span>';
}
if ($result[$UserID]['VMEM'] != $result['DEFAULT']['VMEM']) {
if ((str_replace('K','',$result[$UserID]['VMEM']) == '0') or (str_replace('M','',$result[$UserID]['VMEM']) == '0')){
$result[$UserID]['VMEM'] = '<center><span style="color:#EE0000">-</span></center>';
} else {
$result[$UserID]['VMEM'] = '<span style="color:#EE0000; float:right;">'.str_replace('M','',$result[$UserID]['VMEM']).'</span>';
}
} else {
if ((str_replace('K','',$result[$UserID]['VMEM']) == '0') or (str_replace('M','',$result[$UserID]['VMEM']) == '0')) {
$result[$UserID]['VMEM'] = '<center>-</center>';
} else {
$result[$UserID]['VMEM'] = '<span style="float:right;">'.str_replace('M','',$result[$UserID]['VMEM']).'</span>';
}
}
if ($this->ProcLVEVersion >= 6) {
if ($result[$UserID]['PMEM'] != $result['DEFAULT']['PMEM']) {
if ((str_replace('K','',$result[$UserID]['PMEM']) == '0') or (str_replace('M','',$result[$UserID]['PMEM']) == '0')){
$result[$UserID]['PMEM'] = '<center><span style="color:#EE0000">-</span></center>';
} else {
$result[$UserID]['PMEM'] = '<span style="color:#EE0000; float:right;">'.str_replace('M','',$result[$UserID]['PMEM']).'</span>';
}
} else {
if ((str_replace('K','',$result[$UserID]['PMEM']) == '0') or (str_replace('M','',$result[$UserID]['PMEM']) == '0')){
$result[$UserID]['PMEM'] = '<center>-</center>';
} else {
$result[$UserID]['PMEM'] = '<span style="float:right;">'.str_replace('M','',$result[$UserID]['PMEM']).'</span>';
}
}
}
if ($result[$UserID]['EP'] != $result['DEFAULT']['EP']) {
$result[$UserID]['EP'] = '<span style="color:#EE0000">'.$result[$UserID]['EP'].'</span>';
}
if ($this->ProcLVEVersion >= 6) {
if ($result[$UserID]['NPROC'] != $result['DEFAULT']['NPROC']) {
if ($result[$UserID]['NPROC'] == '0') {
$result[$UserID]['NPROC'] = '<center><span style="color:#EE0000">-</span></center>';
} else {
$result[$UserID]['NPROC'] = '<span style="color:#EE0000; float:right;">'.$result[$UserID]['NPROC'].'</span>';
}
} else {
if ($result[$UserID]['NPROC'] == '0') {
$result[$UserID]['NPROC'] = '<center>-</center>';
} else {
$result[$UserID]['NPROC'] = '<span style="float:right;">'.$result[$UserID]['NPROC'].'</span>';
}
}
}
if ($result[$UserID]['IOPRIO'] != $result['DEFAULT']['IOPRIO']) {
if ($result[$UserID]['IOPRIO'] == '0') {
$result[$UserID]['IOPRIO'] = '<center><span style="color:#EE0000">-</span></center>';
} else {
$result[$UserID]['IOPRIO'] = '<span style="color:#EE0000; float:right;">'.$result[$UserID]['IOPRIO'].'</span>';
}
} else {
if ($result[$UserID]['IOPRIO'] == '0') {
$result[$UserID]['IOPRIO'] = '<center>-</center>';
} else {
$result[$UserID]['IOPRIO'] = '<span style="float:right;">'.$result[$UserID]['IOPRIO'].'</span>';
}
}
}
$result['DEFAULT']['VMEM'] = '<span style="float:right;">'.str_replace('M','',$result['DEFAULT']['VMEM']).'</span>';
$result['DEFAULT']['PMEM'] = '<span style="float:right;">'.str_replace('M','',$result['DEFAULT']['PMEM']).'</span>';
$result['DEFAULT']['NPROC'] = '<span style="float:right;">'.$result['DEFAULT']['NPROC'].'</span>';
$result['DEFAULT']['IOPRIO'] = '<span style="float:right;">'.$result['DEFAULT']['IOPRIO'].'</span>';
// echo '<pre>';
// print_r($result);
// echo '</pre>';
$this->PanelUsers = $result;
// unset($data,$tmp,$counter,$uid,$blank,$result,$Accounts);
}
public function GetEditData($UID) {
$result = self::CommandExecute('/usr/bin/sudo /usr/sbin/lvectl limits all --no-iops');
if ($this->ProcLVEVersion >= 6) {
$counter = 7;
} else {
$counter = 5;
}
while (strpos($result,' ') !== false) {
$result = str_replace(' ',' ',$result);
}
$tmp = explode(' ',trim($result));
for ($i=0; $i<=$counter; $i++) {
$blank[$i] = trim($tmp[$i]);
}
foreach ($tmp as $key => $value) {
if (($key % ($counter+1)) == 0)
$uid = $tmp[$key];
if ($uid != 'ID')
$data[$uid][$blank[($key%($counter+1))]] = str_replace(PHP_EOL,'',$value);
}
foreach ($data as $key => $value) {
$data[$key]['IOPRIO'] = $data[$key]['IO'];
}
$result = self::CommandExecute('/usr/local/interworx/bin/listaccounts.pex');
$Accounts = array();
$result = explode(chr(10), $result);
foreach ($result as $k)
{
$listAccountsArTmp = explode(chr(9), $k);
if (strlen(trim($listAccountsArTmp[0])) > 0) {
$Accounts[trim($listAccountsArTmp[0])] = trim($listAccountsArTmp[1]);
}
}
$result = array();
$result['DEFAULT'] = $data['default'];
$result['DEFAULT']['Username'] = '-';
$result['DEFAULT']['Domain'] = '-';
$result['DEFAULT']['ID'] = 'DEFAULT';
foreach ($Accounts as $UserName => $Domain) {
$UserID = str_replace(PHP_EOL,'',self::CommandExecute('getent passwd '.trim($UserName).' | cut -f 3 -d ":"'));
if (key_exists($UserID,$data)) {
$result[$UserID] = $data[$UserID];
$result[$UserID]['Username'] = $UserName;
$result[$UserID]['Domain'] = $Domain;
$result[$UserID]['ID'] = $UserID;
} else {
$result[$UserID] = $data['default'];
$result[$UserID]['Username'] = $UserName;
$result[$UserID]['Domain'] = $Domain;
$result[$UserID]['ID'] = $UserID;
}
}
$result[$UID]['VMEM'] = str_replace('M','',$result[$UID]['VMEM']);
$result[$UID]['PMEM'] = str_replace('M','',$result[$UID]['PMEM']);
return $result[$UID];
}
// return ProcLVE version
public function ReturnProcLVEVerion() {
return $this->ProcLVEVersion;
}
// return panel users and limits
public function ReturnPanelUsers() {
return $this->PanelUsers;
}
// delete user settings
public function SetUserToDefault($UID) {
self::CommandExecute('/usr/bin/sudo /usr/sbin/lvectl delete '.$UID,false);
}
// Setup LVE for user
public function SetupLVE($UID,$params) {
self::CommandExecute('/usr/bin/sudo /usr/sbin/lvectl set '.$UID.$params,false);
}
public function GetStatData($params) {
$result = self::CommandExecute('/usr/bin/sudo /usr/sbin/lveinfo '.$params);
$result = explode(PHP_EOL,$result);
$tmp = $result[0];
unset($result[0]);
unset($result[count($result)]);
$tmp = explode(',',$tmp);
$i = 0;
$keys = array();
foreach ($tmp as $value) {
$keys[$i] = $value;
$i++;
}
$return = array();
$j = 0;
foreach ($result as $item) {
$tmp = explode(',',$item);
$i = 0;
foreach ($tmp as $value) {
$return[$j][$keys[$i]] = $value;
$i++;
}
$j++;
}
return $return;
}
}
$LVE = new LVE();