/** * filesystem information * * @return void */ private function _filesystems() { $typearray = array('Unknown', 'No Root Directory', 'Removable Disk', 'Local Disk', 'Network Drive', 'Compact Disc', 'RAM Disk'); $floppyarray = array('Unknown', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', 'Other', 'HD', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '8 in.'); $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_LogicalDisk', array('Name', 'Size', 'FreeSpace', 'FileSystem', 'DriveType', 'MediaType')); foreach ($buffer as $filesystem) { $dev = new DiskDevice(); $dev->setMountPoint($filesystem['Name']); $dev->setFsType($filesystem['FileSystem']); if ($filesystem['Size'] > 0) { $dev->setTotal($filesystem['Size']); $dev->setFree($filesystem['FreeSpace']); $dev->setUsed($filesystem['Size'] - $filesystem['FreeSpace']); } if ($filesystem['MediaType'] != "" && $filesystem['DriveType'] == 2) { $dev->setName($typearray[$filesystem['DriveType']] . " (" . $floppyarray[$filesystem['MediaType']] . ")"); } else { $dev->setName($typearray[$filesystem['DriveType']]); } $this->sys->setDiskDevices($dev); } if (!$buffer && $this->sys->getDistribution() == "ReactOS") { // test for command 'free' on current disk if (CommonFunctions::executeProgram("cmd", "/c free 2>nul", $out_value, true)) { for ($letter = 'A'; $letter != 'AA'; $letter++) { if (CommonFunctions::executeProgram("cmd", "/c free " . $letter . ": 2>nul", $out_value, false)) { if (preg_match('/\\n\\s*([\\d\\.\\,]+).*\\n\\s*([\\d\\.\\,]+).*\\n\\s*([\\d\\.\\,]+).*$/', $out_value, $out_dig)) { $size = preg_replace('/(\\.)|(\\,)/', '', $out_dig[1]); $used = preg_replace('/(\\.)|(\\,)/', '', $out_dig[2]); $free = preg_replace('/(\\.)|(\\,)/', '', $out_dig[3]); if ($used + $free == $size) { $dev = new DiskDevice(); $dev->setMountPoint($letter . ":"); $dev->setFsType('Unknown'); $dev->setTotal($size); $dev->setFree($free); $dev->setUsed($used); $this->sys->setDiskDevices($dev); } } } } } } }
/** * get memory and swap information * * @return void */ protected function memory() { $s = $this->grabkey('hw.memsize'); if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) { // calculate free memory from page sizes (each page = 4096) if (preg_match('/^Pages free:\\s+(\\S+)/m', $pstat, $free_buf)) { if (preg_match('/^Anonymous pages:\\s+(\\S+)/m', $pstat, $anon_buf) && preg_match('/^Pages wired down:\\s+(\\S+)/m', $pstat, $wire_buf) && preg_match('/^File-backed pages:\\s+(\\S+)/m', $pstat, $fileb_buf)) { // OS X 10.9 or never $this->sys->setMemFree($free_buf[1] * 4 * 1024); $this->sys->setMemApplication(($anon_buf[1] + $wire_buf[1]) * 4 * 1024); $this->sys->setMemCache($fileb_buf[1] * 4 * 1024); if (preg_match('/^Pages occupied by compressor:\\s+(\\S+)/m', $pstat, $compr_buf)) { $this->sys->setMemBuffer($compr_buf[1] * 4 * 1024); } } else { if (preg_match('/^Pages speculative:\\s+(\\S+)/m', $pstat, $spec_buf)) { $this->sys->setMemFree(($free_buf[1] + $spec_buf[1]) * 4 * 1024); } else { $this->sys->setMemFree($free_buf[1] * 4 * 1024); } $appMemory = 0; if (preg_match('/^Pages wired down:\\s+(\\S+)/m', $pstat, $wire_buf)) { $appMemory += $wire_buf[1] * 4 * 1024; } if (preg_match('/^Pages active:\\s+(\\S+)/m', $pstat, $active_buf)) { $appMemory += $active_buf[1] * 4 * 1024; } $this->sys->setMemApplication($appMemory); if (preg_match('/^Pages inactive:\\s+(\\S+)/m', $pstat, $inactive_buf)) { $this->sys->setMemCache($inactive_buf[1] * 4 * 1024); } } } else { $lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY); $ar_buf = preg_split("/\\s+/", $lines[1], 19); $this->sys->setMemFree($ar_buf[2] * 4 * 1024); } $this->sys->setMemTotal($s); $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree()); if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) { $swap1 = preg_split('/M/', $swapBuff); $swap2 = preg_split('/=/', $swap1[1]); $swap3 = preg_split('/=/', $swap1[2]); $dev = new DiskDevice(); $dev->setName('SWAP'); $dev->setMountPoint('SWAP'); $dev->setFsType('swap'); $dev->setTotal($swap1[0] * 1024 * 1024); $dev->setUsed($swap2[1] * 1024 * 1024); $dev->setFree($swap3[1] * 1024 * 1024); $this->sys->setSwapDevices($dev); } } }
/** * filesystem information * * @return void */ private function _filesystems() { if (CommonFunctions::executeProgram('df', '-k', $df, PSI_DEBUG)) { $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); foreach ($mounts as $mount) { $ar_buf = preg_split('/\\s+/', $mount, 6); $dev = new DiskDevice(); $dev->setName($ar_buf[0]); $dev->setTotal($ar_buf[1] * 1024); $dev->setUsed($ar_buf[2] * 1024); $dev->setFree($ar_buf[3] * 1024); $dev->setMountPoint($ar_buf[5]); if (CommonFunctions::executeProgram('df', '-n', $dftypes, PSI_DEBUG)) { $mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY); foreach ($mounttypes as $type) { $ty_buf = preg_split('/:/', $type, 2); if ($ty_buf == $dev->getName()) { $dev->setFsType($ty_buf[1]); break; } } } $this->sys->setDiskDevices($dev); } } }
/** * Physical memory information and Swap Space information * * @return void */ private function _memory() { if (CommonFunctions::rfts('/proc/meminfo', $bufr)) { $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); foreach ($bufe as $buf) { if (preg_match('/^MemTotal:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) { $this->sys->setMemTotal($ar_buf[1] * 1024); } elseif (preg_match('/^MemFree:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) { $this->sys->setMemFree($ar_buf[1] * 1024); } elseif (preg_match('/^Cached:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) { $this->sys->setMemCache($ar_buf[1] * 1024); } elseif (preg_match('/^Buffers:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) { $this->sys->setMemBuffer($ar_buf[1] * 1024); } } $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree()); // values for splitting memory usage if ($this->sys->getMemCache() !== null && $this->sys->getMemBuffer() !== null) { $this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer()); } if (CommonFunctions::rfts('/proc/swaps', $bufr)) { $swaps = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); unset($swaps[0]); foreach ($swaps as $swap) { $ar_buf = preg_split('/\\s+/', $swap, 5); $dev = new DiskDevice(); $dev->setMountPoint($ar_buf[0]); $dev->setName("SWAP"); $dev->setTotal($ar_buf[2] * 1024); $dev->setUsed($ar_buf[3] * 1024); $dev->setFree($dev->getTotal() - $dev->getUsed()); $this->sys->setSwapDevices($dev); } } } }
/** * Physical memory information and Swap Space information * * @return void */ protected function memory() { if (PHP_OS == 'FreeBSD' || PHP_OS == 'OpenBSD') { // vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize // I should probably add some version checking here, but for now // we only support fbsd 4.4 $pagesize = 1024; } else { $pagesize = $this->grabkey('hw.pagesize'); } if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) { $lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY); $ar_buf = preg_split("/\\s+/", trim($lines[2]), 19); if (PHP_OS == 'NetBSD' || PHP_OS == 'DragonFly') { $this->sys->setMemFree($ar_buf[4] * 1024); } else { $this->sys->setMemFree($ar_buf[4] * $pagesize); } $this->sys->setMemTotal($this->grabkey('hw.physmem')); $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree()); if ((PHP_OS == 'OpenBSD' || PHP_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) { $lines = preg_split("/\n/", $swapstat, -1, PREG_SPLIT_NO_EMPTY); foreach ($lines as $line) { $ar_buf = preg_split("/\\s+/", $line, 6); if ($ar_buf[0] != 'Total') { $dev = new DiskDevice(); $dev->setMountPoint($ar_buf[0]); $dev->setName("SWAP"); $dev->setFsType('swap'); $dev->setTotal($ar_buf[1] * 1024); $dev->setUsed($ar_buf[2] * 1024); $dev->setFree($dev->getTotal() - $dev->getUsed()); $this->sys->setSwapDevices($dev); } } } } }
/** * parsing the output of df command * * @param string $df_param additional parameter for df command * * @return array */ public static function df($df_param = "", $get_inodes = true) { $arrResult = array(); if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) { $mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY); foreach ($mount as $mount_line) { if (preg_match("/(\\S+) on ([\\S ]+) type (.*) \\((.*)\\)/", $mount_line, $mount_buf)) { $parm = array(); $parm['mountpoint'] = trim($mount_buf[2]); $parm['fstype'] = $mount_buf[3]; $parm['name'] = $mount_buf[1]; if (PSI_SHOW_MOUNT_OPTION) { $parm['options'] = $mount_buf[4]; } $mount_parm[] = $parm; } elseif (preg_match("/(\\S+) is (.*) mounted on (\\S+) \\(type (.*)\\)/", $mount_line, $mount_buf)) { $parm = array(); $parm['mountpoint'] = trim($mount_buf[3]); $parm['fstype'] = $mount_buf[4]; $parm['name'] = $mount_buf[1]; if (PSI_SHOW_MOUNT_OPTION) { $parm['options'] = $mount_buf[2]; } $mount_parm[] = $parm; } elseif (preg_match("/(\\S+) (.*) on (\\S+) \\((.*)\\)/", $mount_line, $mount_buf)) { $parm = array(); $parm['mountpoint'] = trim($mount_buf[3]); $parm['fstype'] = $mount_buf[2]; $parm['name'] = $mount_buf[1]; if (PSI_SHOW_MOUNT_OPTION) { $parm['options'] = $mount_buf[4]; } $mount_parm[] = $parm; } elseif (preg_match("/(\\S+) on ([\\S ]+) \\((\\S+)(,\\s(.*))?\\)/", $mount_line, $mount_buf)) { $parm = array(); $parm['mountpoint'] = trim($mount_buf[2]); $parm['fstype'] = $mount_buf[3]; $parm['name'] = $mount_buf[1]; if (PSI_SHOW_MOUNT_OPTION) { $parm['options'] = isset($mount_buf[5]) ? $mount_buf[5] : ''; } $mount_parm[] = $parm; } } } elseif (CommonFunctions::rfts("/etc/mtab", $mount)) { $mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY); foreach ($mount as $mount_line) { if (preg_match("/(\\S+) (\\S+) (\\S+) (\\S+) ([0-9]+) ([0-9]+)/", $mount_line, $mount_buf)) { $parm = array(); $mount_point = preg_replace("/\\\\040/i", ' ', $mount_buf[2]); //space as \040 $parm['mountpoint'] = $mount_point; $parm['fstype'] = $mount_buf[3]; $parm['name'] = $mount_buf[1]; if (PSI_SHOW_MOUNT_OPTION) { $parm['options'] = $mount_buf[4]; } $mount_parm[] = $parm; } } } if (CommonFunctions::executeProgram('df', '-k ' . $df_param, $df, PSI_DEBUG) && $df !== "") { $df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); if ($get_inodes && PSI_SHOW_INODES) { if (CommonFunctions::executeProgram('df', '-i ' . $df_param, $df2, PSI_DEBUG)) { $df2 = preg_split("/\n/", $df2, -1, PREG_SPLIT_NO_EMPTY); // Store inode use% in an associative array (df_inodes) for later use foreach ($df2 as $df2_line) { if (preg_match("/^(\\S+).*\\s([0-9]+)%/", $df2_line, $inode_buf)) { $df_inodes[$inode_buf[1]] = $inode_buf[2]; } } } } foreach ($df as $df_line) { $df_buf1 = preg_split("/(\\%\\s)/", $df_line, 3); if (count($df_buf1) < 2) { continue; } if (preg_match("/(.*)(\\s+)(([0-9]+)(\\s+)([0-9]+)(\\s+)([\\-0-9]+)(\\s+)([0-9]+)\$)/", $df_buf1[0], $df_buf2)) { if (count($df_buf1) == 3) { $df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[2]); } else { $df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[1]); } if (count($df_buf) == 6) { $df_buf[5] = trim($df_buf[5]); $dev = new DiskDevice(); $dev->setName(trim($df_buf[0])); if ($df_buf[2] < 0) { $dev->setTotal($df_buf[3] * 1024); $dev->setUsed($df_buf[3] * 1024); } else { $dev->setTotal($df_buf[1] * 1024); $dev->setUsed($df_buf[2] * 1024); if ($df_buf[3] > 0) { $dev->setFree($df_buf[3] * 1024); } } if (PSI_SHOW_MOUNT_POINT) { $dev->setMountPoint($df_buf[5]); } $notwas = true; if (isset($mount_parm)) { foreach ($mount_parm as $mount_param) { //name and mountpoint find if ($mount_param['name'] === trim($df_buf[0]) && $mount_param['mountpoint'] === $df_buf[5]) { $dev->setFsType($mount_param['fstype']); if (PSI_SHOW_MOUNT_OPTION) { if (PSI_SHOW_MOUNT_CREDENTIALS) { $dev->setOptions($mount_param['options']); } else { $mpo = $mount_param['options']; $mpo = preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo); $mpo = preg_replace('/,guest,/i', ',', $mpo); $mpo = preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,user=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,username=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,password=[^,]*,/i', ',', $mpo); $dev->setOptions($mpo); } } $notwas = false; break; } } if ($notwas) { foreach ($mount_parm as $mount_param) { //mountpoint find if ($mount_param['mountpoint'] === $df_buf[5]) { $dev->setFsType($mount_param['fstype']); if (PSI_SHOW_MOUNT_OPTION) { if (PSI_SHOW_MOUNT_CREDENTIALS) { $dev->setOptions($mount_param['options']); } else { $mpo = $mount_param['options']; $mpo = preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo); $mpo = preg_replace('/,guest,/i', ',', $mpo); $mpo = preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,user=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,username=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,password=[^,]*,/i', ',', $mpo); $dev->setOptions($mpo); } } $notwas = false; break; } } } } if ($notwas) { $dev->setFsType('unknown'); } if ($get_inodes && PSI_SHOW_INODES && isset($df_inodes[trim($df_buf[0])])) { $dev->setPercentInodesUsed($df_inodes[trim($df_buf[0])]); } $arrResult[] = $dev; } } } } else { if (isset($mount_parm)) { foreach ($mount_parm as $mount_param) { $total = disk_total_space($mount_param['mountpoint']); if ($mount_param['fstype'] != 'none' && $total > 0) { $dev = new DiskDevice(); $dev->setName($mount_param['name']); $dev->setFsType($mount_param['fstype']); if (PSI_SHOW_MOUNT_POINT) { $dev->setMountPoint($mount_param['mountpoint']); } $dev->setTotal($total); $free = disk_free_space($mount_param['mountpoint']); if ($free > 0) { $dev->setFree($free); } else { $free = 0; } if ($total > $free) { $dev->setUsed($total - $free); } if (PSI_SHOW_MOUNT_OPTION) { if (PSI_SHOW_MOUNT_CREDENTIALS) { $dev->setOptions($mount_param['options']); } else { $mpo = $mount_param['options']; $mpo = preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo); $mpo = preg_replace('/,guest,/i', ',', $mpo); $mpo = preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,user=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,username=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,password=[^,]*,/i', ',', $mpo); $dev->setOptions($mpo); } } $arrResult[] = $dev; } } } } return $arrResult; }
/** * get memory and swap information * * @return void */ protected function memory() { $s = $this->grabkey('hw.memsize'); if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) { $lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY); $ar_buf = preg_split("/\\s+/", $lines[1], 19); // calculate free memory from page sizes (each page = 4MB) $this->sys->setMemTotal($s); $this->sys->setMemFree($ar_buf[2] * 4 * 1024); $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree()); if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) { $swap1 = preg_split('/M/', $swapBuff); $swap2 = preg_split('/=/', $swap1[1]); $swap3 = preg_split('/=/', $swap1[2]); $dev = new DiskDevice(); $dev->setName('SWAP'); $dev->setMountPoint('SWAP'); $dev->setFsType('swap'); $dev->setTotal($swap1[0] * 1024 * 1024); $dev->setUsed($swap2[1] * 1024 * 1024); $dev->setFree($swap3[1] * 1024 * 1024); $this->sys->setSwapDevices($dev); } } }
/** * filesystem information * * @return void */ private function _filesystems() { if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) { $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) { $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); while (list(, $line) = each($lines)) { $a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY); $fsdev[$a[0]] = $a[4]; } } foreach ($mounts as $mount) { $ar_buf = preg_split("/\\s+/", $mount, 6); $dev = new DiskDevice(); $dev->setName($ar_buf[0]); $dev->setTotal($ar_buf[1] * 1024); $dev->setUsed($ar_buf[2] * 1024); $dev->setFree($ar_buf[3] * 1024); $dev->setMountPoint($ar_buf[5]); if (isset($fsdev[$ar_buf[0]])) { $dev->setFsType($fsdev[$ar_buf[0]]); } $this->sys->setDiskDevices($dev); } } }
/** * fill a xml element with atrributes from a disk device * * @param SimpleXmlExtended $mount Xml-Element * @param DiskDevice $dev DiskDevice * @param Integer $i counter * * @return Void */ private function _fillDevice(SimpleXMLExtended $mount, DiskDevice $dev, $i) { $mount->addAttribute('MountPointID', $i); $mount->addAttribute('FSType', $dev->getFsType()); $mount->addAttribute('Name', $dev->getName()); $mount->addAttribute('Free', sprintf("%.0f", $dev->getFree())); $mount->addAttribute('Used', sprintf("%.0f", $dev->getUsed())); $mount->addAttribute('Total', sprintf("%.0f", $dev->getTotal())); $mount->addAttribute('Percent', $dev->getPercentUsed()); if (PSI_SHOW_MOUNT_OPTION === true) { if ($dev->getOptions() !== null) { $mount->addAttribute('MountOptions', preg_replace("/,/", ", ", $dev->getOptions())); } } if ($dev->getPercentInodesUsed() !== null) { $mount->addAttribute('Inodes', $dev->getPercentInodesUsed()); } if (PSI_SHOW_MOUNT_POINT === true) { $mount->addAttribute('MountPoint', $dev->getMountPoint()); } }
/** * parsing the output of df command * * @param string $df_param additional parameter for df command * * @return array */ public static function df($df_param = "") { $arrResult = array(); if (CommonFunctions::executeProgram('df', '-k ' . $df_param, $df, PSI_DEBUG)) { $df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); if (PSI_SHOW_INODES) { if (CommonFunctions::executeProgram('df', '-i ' . $df_param, $df2, PSI_DEBUG)) { $df2 = preg_split("/\n/", $df2, -1, PREG_SPLIT_NO_EMPTY); // Store inode use% in an associative array (df_inodes) for later use foreach ($df2 as $df2_line) { if (preg_match("/^(\\S+).*\\s([0-9]+)%/", $df2_line, $inode_buf)) { $df_inodes[$inode_buf[1]] = $inode_buf[2]; } } } } if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) { $mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY); foreach ($mount as $mount_line) { if (preg_match("/\\S+ on (\\S+) type (.*) \\((.*)\\)/", $mount_line, $mount_buf)) { $mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2]; $mount_parm[$mount_buf[1]]['options'] = $mount_buf[3]; } elseif (preg_match("/\\S+ (.*) on (\\S+) \\((.*)\\)/", $mount_line, $mount_buf)) { $mount_parm[$mount_buf[2]]['fstype'] = $mount_buf[1]; $mount_parm[$mount_buf[2]]['options'] = $mount_buf[3]; } elseif (preg_match("/\\S+ on (\\S+) \\((\\S+)(,\\s(.*))?\\)/", $mount_line, $mount_buf)) { $mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2]; $mount_parm[$mount_buf[1]]['options'] = isset($mount_buf[4]) ? $mount_buf[4] : ''; } } foreach ($df as $df_line) { $df_buf1 = preg_split("/(\\%\\s)/", $df_line, 2); if (count($df_buf1) != 2) { continue; } preg_match("/(.*)(\\s+)(([0-9]+)(\\s+)([0-9]+)(\\s+)([0-9]+)(\\s+)([0-9]+)\$)/", $df_buf1[0], $df_buf2); $df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[1]); if (count($df_buf) == 6) { $df_buf[5] = trim($df_buf[5]); $dev = new DiskDevice(); $dev->setName(trim($df_buf[0])); if ($df_buf[2] < 0) { $dev->setTotal($df_buf[3] * 1024); $dev->setUsed($df_buf[3] * 1024); } else { $dev->setTotal($df_buf[1] * 1024); $dev->setUsed($df_buf[2] * 1024); $dev->setFree($df_buf[3] * 1024); } $dev->setMountPoint($df_buf[5]); $dev->setFsType($mount_parm[$df_buf[5]]['fstype']); $dev->setOptions($mount_parm[$df_buf[5]]['options']); if (PSI_SHOW_INODES && isset($df_inodes[trim($df_buf[0])])) { $dev->setPercentInodesUsed($df_inodes[trim($df_buf[0])]); } $arrResult[] = $dev; } } } } return $arrResult; }
/** * filesystem information * * @return void */ private function _filesystems() { $arrResult = array(); if (CommonFunctions::executeProgram('df', '-b', $df, PSI_DEBUG)) { $df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); foreach ($df as $df_line) { $ar_buf = preg_split("/\\s+/", $df_line); if (substr($df_line, 0, 1) == "/" && count($ar_buf) == 6) { $dev = new DiskDevice(); $dev->setMountPoint($ar_buf[0]); $dev->setName($ar_buf[5]); $dev->setFsType($ar_buf[1]); $dev->setOptions($ar_buf[4]); $dev->setTotal($ar_buf[2] * 1024); $dev->setFree($ar_buf[3] * 1024); $dev->setUsed($dev->getTotal() - $dev->getFree()); $this->sys->setDiskDevices($dev); } } } }
/** * filesystem information * * @return void */ private function _filesystems() { if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG)) { $df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) { $mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY); foreach ($mount as $mount_line) { $mount_buf = preg_split('/\\s+/', $mount_line); if (count($mount_buf) == 6) { $mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2]; if (PSI_SHOW_MOUNT_OPTION) { $mount_parm[$mount_buf[1]]['options'] = $mount_buf[3]; } $mount_parm[$mount_buf[1]]['mountdev'] = $mount_buf[0]; } } foreach ($df as $df_line) { if ((preg_match("/^(\\/\\S+)(\\s+)(([0-9\\.]+)([KMGT])(\\s+)([0-9\\.]+)([KMGT])(\\s+)([0-9\\.]+)([KMGT])(\\s+))/", $df_line, $df_buf) || preg_match("/^(\\/[^\\s\\:]+)\\:(\\s+)(([0-9\\.]+)([KMGT])(\\s+total\\,\\s+)([0-9\\.]+)([KMGT])(\\s+used\\,\\s+)([0-9\\.]+)([KMGT])(\\s+available))/", $df_line, $df_buf)) && !preg_match('/^\\/mnt\\/asec\\/com\\./', $df_buf[1])) { $dev = new DiskDevice(); if (PSI_SHOW_MOUNT_POINT) { $dev->setMountPoint($df_buf[1]); } if ($df_buf[5] == 'K') { $dev->setTotal($df_buf[4] * 1024); } elseif ($df_buf[5] == 'M') { $dev->setTotal($df_buf[4] * 1024 * 1024); } elseif ($df_buf[5] == 'G') { $dev->setTotal($df_buf[4] * 1024 * 1024 * 1024); } elseif ($df_buf[5] == 'T') { $dev->setTotal($df_buf[4] * 1024 * 1024 * 1024 * 1024); } if ($df_buf[8] == 'K') { $dev->setUsed($df_buf[7] * 1024); } elseif ($df_buf[8] == 'M') { $dev->setUsed($df_buf[7] * 1024 * 1024); } elseif ($df_buf[8] == 'G') { $dev->setUsed($df_buf[7] * 1024 * 1024 * 1024); } elseif ($df_buf[8] == 'T') { $dev->setUsed($df_buf[7] * 1024 * 1024 * 1024 * 1024); } if ($df_buf[11] == 'K') { $dev->setFree($df_buf[10] * 1024); } elseif ($df_buf[11] == 'M') { $dev->setFree($df_buf[10] * 1024 * 1024); } elseif ($df_buf[11] == 'G') { $dev->setFree($df_buf[10] * 1024 * 1024 * 1024); } elseif ($df_buf[11] == 'T') { $dev->setFree($df_buf[10] * 1024 * 1024 * 1024 * 1024); } if (isset($mount_parm[$df_buf[1]])) { $dev->setFsType($mount_parm[$df_buf[1]]['fstype']); $dev->setName($mount_parm[$df_buf[1]]['mountdev']); if (PSI_SHOW_MOUNT_OPTION) { if (PSI_SHOW_MOUNT_CREDENTIALS) { $dev->setOptions($mount_parm[$df_buf[1]]['options']); } else { $mpo = $mount_parm[$df_buf[1]]['options']; $mpo = preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo); $mpo = preg_replace('/,guest,/i', ',', $mpo); $mpo = preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,user=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,username=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,password=[^,]*,/i', ',', $mpo); $dev->setOptions($mpo); } } } $this->sys->setDiskDevices($dev); } } } } }
/** * filesystem information * * @return void */ private function _filesystems() { $typearray = array('Unknown', 'No Root Directory', 'Removable Disk', 'Local Disk', 'Network Drive', 'Compact Disc', 'RAM Disk'); $floppyarray = array('Unknown', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', 'Other', 'HD', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '8 in.'); $buffer = $this->_getWMI('Win32_LogicalDisk', array('Name', 'Size', 'FreeSpace', 'FileSystem', 'DriveType', 'MediaType')); foreach ($buffer as $filesystem) { $dev = new DiskDevice(); $dev->setMountPoint($filesystem['Name']); $dev->setFsType($filesystem['FileSystem']); if ($filesystem['Size'] > 0) { $dev->setTotal($filesystem['Size']); $dev->setFree($filesystem['FreeSpace']); $dev->setUsed($filesystem['Size'] - $filesystem['FreeSpace']); } if ($filesystem['MediaType'] != "" && $filesystem['DriveType'] == 2) { $dev->setName($typearray[$filesystem['DriveType']] . " (" . $floppyarray[$filesystem['MediaType']] . ")"); } else { $dev->setName($typearray[$filesystem['DriveType']]); } $this->sys->setDiskDevices($dev); } }
/** * fill a xml element with atrributes from a disk device * * @param SimpleXmlExtended $mount Xml-Element * @param DiskDevice $dev DiskDevice * @param Integer $i counter * * @return Void */ private function _fillDevice($mount, $dev, $i) { $mount->addAttribute('MountPointID', $i); $mount->addAttribute('FSType', $dev->getFsType()); $mount->addAttribute('Name', $dev->getName()); $mount->addAttribute('Free', $dev->getFree()); $mount->addAttribute('Used', $dev->getUsed()); $mount->addAttribute('Total', $dev->getTotal()); $mount->addAttribute('Percent', $dev->getPercentUsed()); if ($dev->getOptions() !== null) { $mount->addAttribute('MountOptions', $dev->getOptions()); } if ($dev->getPercentInodesUsed() !== null) { $mount->addAttribute('Inodes', $dev->getPercentInodesUsed()); } if (PSI_SHOW_MOUNT_POINT === true) { $mount->addAttribute('MountPoint', $dev->getMountPoint()); } }
/** * parsing the output of df command * * @param string $df_param additional parameter for df command * * @return array */ public static function df($df_param = "") { $arrResult = array(); if (CommonFunctions::executeProgram('df', '-k ' . $df_param, $df, PSI_DEBUG)) { $df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); if (PSI_SHOW_INODES) { if (CommonFunctions::executeProgram('df', '-i ' . $df_param, $df2, PSI_DEBUG)) { $df2 = preg_split("/\n/", $df2, -1, PREG_SPLIT_NO_EMPTY); // Store inode use% in an associative array (df_inodes) for later use foreach ($df2 as $df2_line) { if (preg_match("/^(\\S+).*\\s([0-9]+)%/", $df2_line, $inode_buf)) { $df_inodes[$inode_buf[1]] = $inode_buf[2]; } } } } if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) { $mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY); foreach ($mount as $mount_line) { if (preg_match("/\\S+ on (\\S+) type (.*) \\((.*)\\)/", $mount_line, $mount_buf)) { $mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2]; if (PSI_SHOW_MOUNT_OPTION) { $mount_parm[$mount_buf[1]]['options'] = $mount_buf[3]; } } elseif (preg_match("/\\S+ is (.*) mounted on (\\S+) \\(type (.*)\\)/", $mount_line, $mount_buf)) { $mount_parm[$mount_buf[2]]['fstype'] = $mount_buf[3]; if (PSI_SHOW_MOUNT_OPTION) { $mount_parm[$mount_buf[2]]['options'] = $mount_buf[1]; } } elseif (preg_match("/\\S+ (.*) on (\\S+) \\((.*)\\)/", $mount_line, $mount_buf)) { $mount_parm[$mount_buf[2]]['fstype'] = $mount_buf[1]; if (PSI_SHOW_MOUNT_OPTION) { $mount_parm[$mount_buf[2]]['options'] = $mount_buf[3]; } } elseif (preg_match("/\\S+ on ([\\S ]+) \\((\\S+)(,\\s(.*))?\\)/", $mount_line, $mount_buf)) { $mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2]; if (PSI_SHOW_MOUNT_OPTION) { $mount_parm[$mount_buf[1]]['options'] = isset($mount_buf[4]) ? $mount_buf[4] : ''; } } } foreach ($df as $df_line) { $df_buf1 = preg_split("/(\\%\\s)/", $df_line, 3); if (count($df_buf1) < 2) { continue; } if (preg_match("/(.*)(\\s+)(([0-9]+)(\\s+)([0-9]+)(\\s+)([\\-0-9]+)(\\s+)([0-9]+)\$)/", $df_buf1[0], $df_buf2)) { if (count($df_buf1) == 3) { $df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[2]); } else { $df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[1]); } if (count($df_buf) == 6) { $df_buf[5] = trim($df_buf[5]); $dev = new DiskDevice(); $dev->setName(trim($df_buf[0])); if ($df_buf[2] < 0) { $dev->setTotal($df_buf[3] * 1024); $dev->setUsed($df_buf[3] * 1024); } else { $dev->setTotal($df_buf[1] * 1024); $dev->setUsed($df_buf[2] * 1024); if ($df_buf[3] > 0) { $dev->setFree($df_buf[3] * 1024); } } if (PSI_SHOW_MOUNT_POINT) { $dev->setMountPoint($df_buf[5]); } if (isset($mount_parm[$df_buf[5]])) { $dev->setFsType($mount_parm[$df_buf[5]]['fstype']); if (PSI_SHOW_MOUNT_OPTION) { if (PSI_SHOW_MOUNT_CREDENTIALS) { $dev->setOptions($mount_parm[$df_buf[5]]['options']); } else { $mpo = $mount_parm[$df_buf[5]]['options']; $mpo = preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo); $mpo = preg_replace('/,guest,/i', ',', $mpo); $mpo = preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,user=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,username=[^,]*,/i', ',', $mpo); $mpo = preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo); $mpo = preg_replace('/,password=[^,]*,/i', ',', $mpo); $dev->setOptions($mpo); } } } if (PSI_SHOW_INODES && isset($df_inodes[trim($df_buf[0])])) { $dev->setPercentInodesUsed($df_inodes[trim($df_buf[0])]); } $arrResult[] = $dev; } } } } } return $arrResult; }
/** * fill a xml element with atrributes from a disk device * * @param DiskDevice $dev DiskDevice * @param Integer $i counter * * @return Void */ private function _fillDevice(DiskDevice $dev, $i) { $mount = array('MountPointID' => $i, 'FSType' => $dev->getFsType(), 'Name' => $dev->getName(), 'Free' => sprintf("%.0f", $dev->getFree()), 'Used' => sprintf("%.0f", $dev->getUsed()), 'Total' => sprintf("%.0f", $dev->getTotal()), 'Percent' => $dev->getPercentUsed()); if (PSI_SHOW_MOUNT_OPTION === true && $dev->getOptions() !== null) { $mount['MountOptions'] = preg_replace("/,/", ", ", $dev->getOptions()); } if ($dev->getPercentInodesUsed() !== null) { $mount['Inodes'] = $dev->getPercentInodesUsed(); } if (PSI_SHOW_MOUNT_POINT === true) { $mount['MountPoint'] = $dev->getMountPoint(); } return $mount; }