Пример #1
0
/**
 * w3e_createInfo()
 *
 * @param mixed $params
 * @param mixed $vmid
 * @param mixed $template
 * @param mixed $foruser
 * @return
 */
function w3e_createInfo($params, $vmid, $template, $foruser)
{
    $user = $params['serverusername'];
    $pass = $params['serverpassword'];
    $host = $params['serverip'];
    $vmware = new VMware();
    $vmware->setServerConfig($host, $user, $pass);
    //SHOW ONLY POWER STATE
    $stateSettings = false;
    if ($foruser == 'client') {
        $stateSettings = w3e_getSettings('only_show_power_state_to_client');
    } else {
        $stateSettings = w3e_getSettings('only_show_power_state_to_admin');
    }
    if ($stateSettings) {
        $info = $vmware->getState($vmid);
        $info = str_replace(' ', '', $info);
        $state = 'white';
        $stateText = 'UnKnown';
        if ($info == 'poweredon') {
            $state = 'green';
            $stateText = 'Power On';
        } elseif ($info == 'poweredoff') {
            $state = 'red';
            $stateText = 'Power Off';
        } elseif ($info == 'suspended') {
            $state = 'blue';
            $stateText = 'Suspended';
        }
        $template = preg_replace('@({W3EELSE_STATUS}.*?{/W3EELSE_STATUS})@is', '', $template);
        $search = array('{W3E_IMG_PATH}', '{W3E_POWER_STATE_TEXT}', '{W3E_POWER_STATE_COLOR}', '{W3EIF_STATUS}', '{/W3EIF_STATUS}', '{W3E_NOW}');
        $replace = array(W3E_IMGDIR, $stateText, $state, '', '', strftime('%Y-%m-%d %H:%M:%S'));
        return str_replace($search, $replace, $template);
    }
    //SHOW FULL INFO
    $hard_details = w3e_getSettings('show_hard_details');
    $info = $vmware->getImportantInfo($vmid, $hard_details);
    $state = 'white';
    $stateText = 'UnKnown';
    if ($info['powerState'] == 'poweredon') {
        $state = 'green';
        $stateText = 'Powered On';
    } elseif ($info['powerState'] == 'poweredoff') {
        $state = 'red';
        $stateText = 'Powered Off';
    } elseif ($info['powerState'] == 'suspended') {
        $state = 'blue';
        $stateText = 'Suspended';
    }
    $os = $params['configoption1'];
    if ($os == 'Other') {
        $os = $params['configoption2'];
    }
    $upt = $info['uptime'];
    $h = round($upt / 3600, 0);
    $upt %= 3600;
    $m = round($upt / 60, 0);
    $upt %= 60;
    $s = $upt;
    $uptime = "{$h}H {$m}Min {$s}Sec";
    $ramUsagePercent = 0;
    if ($info['memoryUsage'] != 0) {
        $ramUsagePercent = round($info['memoryUsage'] * 100 / $info['memorySize'], 2);
    }
    $hardUsagePercent = 0;
    if ($info['hd']) {
        $hardUsagePercent = round($info['hardUsage'] * 100 / $info['hd'], 2);
    }
    $cpuUsagePercent = 0;
    if ($info['cpuMax']) {
        $cpuUsagePercent = round($info['cpuUsage'] * 100 / $info['cpuMax'], 2);
    }
    if ($hard_details) {
        $template = preg_replace('@({W3EELSE_HARD_DETAILS}.*?{/W3EELSE_HARD_DETAILS})@is', '', $template);
    } else {
        $template = preg_replace('@({W3EIF_HARD_DETAILS}.*?{/W3EIF_HARD_DETAILS})@is', '', $template);
    }
    $search = array('{W3E_IMG_PATH}', '{W3E_POWER_STATE_TEXT}', '{W3E_POWER_STATE_COLOR}', '{W3E_IP}', '{W3E_HOST}', '{W3E_OS}', '{W3E_ONVMWARE_OS}', '{W3E_ONVMWARE_FULLNAME_OS}', '{W3E_BOOT_TIME}', '{W3E_UPTIME}', '{W3E_CPU}', '{W3E_CPU_USAGE}', '{W3E_CPU_USAGE_PERCENT}', '{W3E_RAM}', '{W3E_RAM_USAGE}', '{W3E_RAM_USAGE_PERCENT}', '{W3E_SPACE}', '{W3E_FREE_SPACE}', '{W3E_SPACE_USAGE}', '{W3E_SPACE_USAGE_PERCENT}', '{W3E_VMID}', '{W3E_HARD_NUMS}', '{W3EIF_HARD_DETAILS}', '{/W3EIF_HARD_DETAILS}', '{W3EELSE_HARD_DETAILS}', '{/W3EELSE_HARD_DETAILS}', '{W3EIF_STATUS}', '{/W3EIF_STATUS}', '{W3EELSE_STATUS}', '{/W3EELSE_STATUS}', '{W3E_NOW}');
    $replace = array(W3E_IMGDIR, $stateText, $state, $info['ip'], $info['hostname'], $os, $info['os'], $info['osFullName'], $info['bootTime'], $uptime, $info['cpuMax'], $info['cpuUsage'], $cpuUsagePercent, $info['memorySize'], $info['memoryUsage'], $ramUsagePercent, $info['hd'], $info['hardFree'], $info['hardUsage'], $hardUsagePercent, $vmid, $info['hardNums'], '', '', '', '', '', '', '', '', strftime('%Y-%m-%d %H:%M:%S'));
    return str_replace($search, $replace, $template);
}
Пример #2
0
    private function renderAllVmTable()
    {
        /*
                $_SESSION['W3EALLVM'] = array();
                $_SESSION['W3EALLVM']['query']
                $_SESSION['W3EALLVM']['pagination_query']
                $_SESSION['W3EALLVM']['items']
        */
        $html = null;
        if (!isset($_SESSION['W3EALLVM'])) {
            $this->setErrors('Filter form is not filled.', 'ERROR');
            header('Location: ' . W3E_MOD_LINK . '&view=allvm');
            exit;
        }
        $offset = 0;
        $limit = $_SESSION['W3EALLVM']['items'];
        if (isset($_REQUEST['page'])) {
            $page = intval($_REQUEST['page']);
            if ($page > 0) {
                $offset = ($page - 1) * $limit;
            }
        }
        $query = $_SESSION['W3EALLVM']['query'];
        $query .= " LIMIT {$limit} OFFSET {$offset} ";
        $result = @mysql_query($query);
        if (!$result) {
            $this->setErrors('Cannot get items from DB: ' . mysql_error(), 'ERROR');
            header('Location: ' . W3E_MOD_LINK . '&view=allvm');
            exit;
        }
        if (!mysql_num_rows($result)) {
            $this->setErrors('There is no item to see.', 'WARNING');
            header('Location: ' . W3E_MOD_LINK . '&view=allvm');
            exit;
        } else {
            $page = 1;
            if (isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0) {
                $page = intval($_REQUEST['page']);
            }
            $html .= '       <div id="W3E_allvmtable">
            <script type="text/javascript">
                w3e_select = true;
                function w3e_de_select(){
                    var w3e_checkbox = document.querySelectorAll("#w3eCheckbox");
                    for(i = 0; i < w3e_checkbox.length; i++){
                         w3e_checkbox[i].checked = w3e_select;
                    }
                    if(w3e_select){
                        w3e_select = false;
                    }else{
                        w3e_select = true;
                    }
                }

            </script>
            ';
            $html .= '
        	<h3 style="color: #FFAA00">AllVM</h3>
            <form action="' . W3E_MOD_LINK . '&view=allvm&filter=1&action=save&page=' . $page . '" method="POST">
                <table id="w3e_allvm_table"">
                	<thead>
                        <tr>
                            <th style="width:3%" onclick="w3e_de_select()">*</th>
                            <th style="width:3%">#</th>
        					<th style="width:16%">Client</th>
                            <th style="width:16%">Server</th>
        					<th style="width:16%">Product</th>
                            <th style="width:6%">VMID</th>

                            <th style="width:12%">CPU</th>
                            <th style="width:12%">RAM</th>
                            <th style="width:12%">Space</th>
                            <th style="width:12%">UpTime</th>
                            <th style="width:9%">Status</th>



                        </tr>
                </thead>
                <tbody>
            ';
            $counter = $offset + 1;
            $vmware = new VMware();
            while ($row = mysql_fetch_assoc($result)) {
                //Connect to vmware server
                $host = $row['ipaddress'];
                $user = $row['username'];
                $pass = decrypt($row['password']);
                $vmware->setServerConfig($host, $user, $pass);
                $hard_details = $this->getSettings('show_hard_details');
                $info = $vmware->getImportantInfo($row['vmid'], $hard_details);
                if (!$info) {
                    $this->setErrors("Cannot get info of vmid: {$row['vmid']}", 'ERROR');
                    continue;
                }
                $state = 'white';
                if ($info['powerState'] == 'poweredon') {
                    $state = 'green';
                    $stateText = 'Powered On';
                } elseif ($info['powerState'] == 'poweredoff') {
                    $state = 'red';
                    $stateText = 'Powered Off';
                } elseif ($info['powerState'] == 'suspended') {
                    $state = 'blue';
                    $stateText = 'Suspended';
                } else {
                    $stateText = $info['powerState'];
                }
                $hard = $info['hd'] . ' GB';
                if ($hard_details) {
                    $hard = '<span title="Free Space: ' . $info['hardFree'] . ' GB / ' . $info['hardNums'] . '" alt="Free Space: ' . $info['hardFree'] . ' GB / ' . $info['hardNums'] . '">' . $info['hardUsage'] . '/' . $info['hd'] . ' GB</span>';
                }
                //WHMCS LINKS
                $clientLink = "clientssummary.php?userid={$row['clientid']}";
                $productLink = "configproducts.php?action=edit&id={$row['pid']}";
                $serverLink = "configservers.php?action=manage&id={$row['serverid']}";
                $serviceLink = "clientshosting.php?userid={$row['clientid']}&id={$row['serviceid']}";
                $pOS = $row['os'];
                if ($pOS == 'Other') {
                    $pOS = $row['otheros'];
                }
                $upt = $info['uptime'];
                $h = round($upt / 3600, 0);
                $upt %= 3600;
                $m = round($upt / 60, 0);
                $upt %= 60;
                $s = $upt;
                $uptime = "{$h}H {$m}Min {$s}Sec";
                $html .= '
                <tr>
                    <td><input id="w3eCheckbox" type="checkbox" value="' . $row['serviceid'] . '" name="W3EServices[]" /></td>
                    <td>' . $counter . '</td>
                    <td><a href="' . $clientLink . '" alt="' . $row['firstname'] . ' - ' . $row['lastname'] . '" title="' . $row['firstname'] . ' - ' . $row['lastname'] . '">' . $row['lastname'] . '</a></td>
                    <td><a href="' . $serverLink . '" alt="' . $row['ipaddress'] . '" title="' . $row['ipaddress'] . '">' . $row['servername'] . '</a></td>
                    <td><a href="' . $productLink . '" alt="' . $pOS . '" title="' . $pOS . '">' . $row['productname'] . '</a></td>
                    <td><a href="' . $serviceLink . '" alt="' . $row['dedicatedip'] . '" title="' . $row['dedicatedip'] . '">' . $row['vmid'] . '</a></td>
                    <td>' . $info['cpuUsage'] . '/' . $info['cpuMax'] . ' MHZ</td>
                    <td>' . $info['memoryUsage'] . '/' . $info['memorySize'] . ' MB</td>
                    <td>' . $hard . '</td>
                    <td><span title="Boot Time: ' . $info['bootTime'] . '" alt="Boot Time: ' . $info['bootTime'] . '">' . $uptime . '</span></td>
                    <td><img src="' . W3E_IMGDIR . 'circle_' . $state . '.png" alt="' . $stateText . '" title="' . $stateText . '" style="width:25px; height:25px;" /></td>
                </tr>';
                $counter++;
            }
            $html .= '
                </tbody>
           </table>
         <div id="w3e_command">
                         Action:
              <select name="W3E_ACTION" id="w3e_action_menu">

              <option value="poweron">Power ON</option>
              <option value="poweroff">Power OFF</option>
              <option value="reset">Reset</option>
              <option value="rebootos">Reboot OS</option>
              <option value="shutdownos">Shutdown OS</option>
              <option value="suspend">Suspend</option>
              <option value="unsuspend">Unsuspend</option>
                    </select>
              <select id="w3e_allvm_back_manu" name="back" >
              	<option value="1" selected="selected">Back to this page</option>
                <option value="0">Back to allvm page</option>
              </select>

              <input type="hidden" name="filter" value="1" />
               <input type="hidden" name="page" value="1" />
                <input type="hidden" name="view" value="allvm" />
                 <input type="hidden" name="action" value="command" />
              <input id="w3e_allvm_submit" type="submit" value="Go" />

              </div>
		</form>
      </div>    ';
        }
        return $html;
    }