/** * parsing the output of pciconf command * * @return Array */ public static function pciconf() { $arrResults = array(); $intS = 0; if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) { $arrTemp = array(); $arrLines = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY); foreach ($arrLines as $strLine) { if (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) { if (trim($arrParts[1]) == "vendor") { $arrTemp[$intS] = trim($arrParts[2]); } elseif (trim($arrParts[1]) == "device") { $arrTemp[$intS] .= " - " . trim($arrParts[2]); $intS++; } } } foreach ($arrTemp as $name) { $dev = new HWDevice(); $dev->setName($name); $arrResults[] = $dev; } } return $arrResults; }
/** * compare a given device with the internal one * * @param HWDevice $dev device that should be compared * * @return boolean */ public function equals($dev) { if ($dev->getName() === $this->_name && $dev->getCapacity() === $this->_capacity) { return true; } else { return false; } }
/** * parsing the output of lspci command * * @return Array */ public static function lspci($debug = PSI_DEBUG) { $arrResults = array(); if (CommonFunctions::executeProgram("lspci", "", $strBuf, $debug)) { $arrLines = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY); foreach ($arrLines as $strLine) { $arrParams = preg_split('/ /', trim($strLine), 2); if (count($arrParams) == 2) { $strName = $arrParams[1]; } else { $strName = "unknown"; } $strName = preg_replace('/\\(.*\\)/', '', $strName); $dev = new HWDevice(); $dev->setName($strName); $arrResults[] = $dev; } } return $arrResults; }
/** * USB devices * * @return array */ private function _usb() { $devnum = -1; if (!CommonFunctions::executeProgram('lsusb', '', $bufr, PSI_DEBUG)) { if (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) { $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); foreach ($bufe as $buf) { if (preg_match('/^T/', $buf)) { $devnum += 1; $results[$devnum] = ""; } elseif (preg_match('/^S:/', $buf)) { list($key, $value) = preg_split('/: /', $buf, 2); list($key, $value2) = preg_split('/=/', $value, 2); if (trim($key) != "SerialNumber") { $results[$devnum] .= " " . trim($value2); } } } foreach ($results as $var) { $dev = new HWDevice(); $dev->setName($var); $this->sys->setUsbDevices($dev); } } } else { $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); foreach ($bufe as $buf) { $device = preg_split("/ /", $buf, 7); if (isset($device[6]) && trim($device[6]) != "") { $dev = new HWDevice(); $dev->setName(trim($device[6])); $this->sys->setUsbDevices($dev); } } } }
/** * get the ide device information out of ioreg * * @return void */ protected function ide() { $s = $this->_grabioreg('IOATABlockStorageDevice'); $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); foreach ($lines as $line) { $ar_buf = preg_split("/\\/\\//", $line, 19); if (isset($ar_buf[1]) && $ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) { $dev = new HWDevice(); $dev->setName($ar_buf[0]); $this->sys->setIdeDevices($dev); } } }
/** * PCI devices * get the pci device information out of dmesg * * @return void */ protected function _pci() { if (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) { $arrLines = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY); foreach ($arrLines as $strLine) { $arrParams = preg_split('/\\s+/', trim($strLine), 4); if (count($arrParams) == 4) { $strName = $arrParams[3]; } else { $strName = "unknown"; } $strName = preg_replace('/\\(.*\\)/', '', $strName); $dev = new HWDevice(); $dev->setName($strName); $arrResults[] = $dev; } foreach ($arrResults as $dev) { $this->sys->setPciDevices($dev); } } if (!is_array($arrResults) && is_array($results = Parser::lspci())) { /* if access error: chmod 4755 /usr/bin/lspci */ foreach ($results as $dev) { $this->sys->setPciDevices($dev); } } }
/** * generate the hardware information * * @return void */ private function _buildHardware() { $dev = new HWDevice(); $hardware = $this->_xml->addChild('Hardware'); $pci = $hardware->addChild('PCI'); foreach (System::removeDupsAndCount($this->_sys->getPciDevices()) as $dev) { $tmp = $pci->addChild('Device'); $tmp->addAttribute('Name', $dev->getName()); $tmp->addAttribute('Count', $dev->getCount()); } $usb = $hardware->addChild('USB'); foreach (System::removeDupsAndCount($this->_sys->getUsbDevices()) as $dev) { $tmp = $usb->addChild('Device'); $tmp->addAttribute('Name', $dev->getName()); $tmp->addAttribute('Count', $dev->getCount()); } $ide = $hardware->addChild('IDE'); foreach (System::removeDupsAndCount($this->_sys->getIdeDevices()) as $dev) { $tmp = $ide->addChild('Device'); $tmp->addAttribute('Name', $dev->getName()); $tmp->addAttribute('Count', $dev->getCount()); if ($dev->getCapacity() !== null) { $tmp->addAttribute('Capacity', $dev->getCapacity()); } } $scsi = $hardware->addChild('SCSI'); foreach (System::removeDupsAndCount($this->_sys->getScsiDevices()) as $dev) { $tmp = $scsi->addChild('Device'); $tmp->addAttribute('Name', $dev->getName()); $tmp->addAttribute('Count', $dev->getCount()); if ($dev->getCapacity() !== null) { $tmp->addAttribute('Capacity', $dev->getCapacity()); } } $cpu = $hardware->addChild('CPU'); foreach ($this->_sys->getCpus() as $oneCpu) { $tmp = $cpu->addChild('CpuCore'); $tmp->addAttribute('Model', $oneCpu->getModel()); if ($oneCpu->getCpuSpeed() !== 0) { $tmp->addAttribute('CpuSpeed', $oneCpu->getCpuSpeed()); } if ($oneCpu->getCpuSpeedMax() !== 0) { $tmp->addAttribute('CpuSpeedMax', $oneCpu->getCpuSpeedMax()); } if ($oneCpu->getCpuSpeedMin() !== 0) { $tmp->addAttribute('CpuSpeedMin', $oneCpu->getCpuSpeedMin()); } if ($oneCpu->getTemp() !== null) { $tmp->addAttribute('CpuTemp', $oneCpu->getTemp()); } if ($oneCpu->getBusSpeed() !== null) { $tmp->addAttribute('BusSpeed', $oneCpu->getBusSpeed()); } if ($oneCpu->getCache() !== null) { $tmp->addAttribute('Cache', $oneCpu->getCache()); } if ($oneCpu->getVirt() !== null) { $tmp->addAttribute('Virt', $oneCpu->getVirt()); } if ($oneCpu->getBogomips() !== null) { $tmp->addAttribute('Bogomips', $oneCpu->getBogomips()); } if ($oneCpu->getLoad() !== null) { $tmp->addAttribute('Load', $oneCpu->getLoad()); } } }
/** * Hardwaredevices * * @return void */ private function _hardware() { foreach ($this->_devicelist('PCI') as $pciDev) { $dev = new HWDevice(); $dev->setName($pciDev); $this->sys->setPciDevices($dev); } foreach ($this->_devicelist('IDE') as $ideDev) { $dev = new HWDevice(); $dev->setName($ideDev); $this->sys->setIdeDevices($dev); } foreach ($this->_devicelist('SCSI') as $scsiDev) { $dev = new HWDevice(); $dev->setName($scsiDev); $this->sys->setScsiDevices($dev); } foreach ($this->_devicelist('USB') as $usbDev) { $dev = new HWDevice(); $dev->setName($usbDev); $this->sys->setUsbDevices($dev); } }
/** * USB devices * get the ide device information out of dmesg * * @return void */ protected function usb() { foreach ($this->readdmesg() as $line) { // if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) { // $dev->setName($ar_buf[1].": ".$ar_buf[2]); if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) { $dev = new HWDevice(); $dev->setName($ar_buf[2]); $this->sys->setUSBDevices($dev); } } }
/** * USB devices * @return void */ private function _usb() { foreach ($this->readaixdata() as $line) { if (preg_match("/^[\\*\\+]\\s\\S+\\s+\\S+\\s+(.*USB.*)/", $line, $ar_buf)) { $dev = new HWDevice(); $dev->setName(trim($ar_buf[1])); $this->sys->setUsbDevices($dev); } } }
/** * get the ide information * * @return array */ protected function ide() { foreach ($this->readdmesg() as $line) { if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]\\-(.*)) (.*)/', $line, $ar_buf)) { $dev = new HWDevice(); $dev->setName($ar_buf[1]); if (!preg_match("/^acd[0-9](.*)/", $ar_buf[1])) { $dev->setCapacity($ar_buf[2] * 1024); } $this->sys->setIdeDevices($dev); } } }
/** * get the thunderbolt device information out of ioreg * * @return void */ protected function _tb() { $s = $this->_grabioreg('IOThunderboltPort'); $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); foreach ($lines as $line) { $dev = new HWDevice(); if (!preg_match('/"Description" = "([^"]*)"/', $line, $ar_buf)) { $ar_buf = preg_split("/[\\s@]+/", $line, 19); } $dev->setName(trim($ar_buf[1])); $this->sys->setTbDevices($dev); } }
/** * USB devices * * @return array */ private function _usb() { if (CommonFunctions::executeProgram('lsusb', '', $bufr, false)) { $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); foreach ($bufe as $buf) { $device = preg_split("/ /", $buf, 6); if (isset($device[5]) && trim($device[5]) != "") { $dev = new HWDevice(); $dev->setName(trim($device[5])); $this->sys->setUsbDevices($dev); } } } }
/** * IDE devices * get the ide device information out of dmesg * * @return void */ protected function ide() { foreach ($this->readdmesg() as $line) { if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) { $dev = new HWDevice(); $dev->setName($ar_buf[1]); $dev->setCapacity($ar_buf[2] * 1024); $this->sys->setIdeDevices($dev); } elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) { $dev = new HWDevice(); $dev->setName($ar_buf[1]); $this->sys->setIdeDevices($dev); } } }
/** * USB devices * get the usb device information * * @return void */ protected function _usb() { if (CommonFunctions::executeProgram('listusb', '', $bufr, PSI_DEBUG)) { $devices = preg_split("/\n/", $bufr); foreach ($devices as $device) { if (preg_match("/^\\S+\\s+\\S+\\s+\"(.*)\"\\s+\"(.*)\"/", $device, $ar_buf)) { $dev = new HWDevice(); $dev->setName(trim($ar_buf[1] . " " . $ar_buf[2])); $this->sys->setUSBDevices($dev); } } } }
/** * get the scsi device information out of ioreg * * @return void */ protected function scsi() { $s = $this->_grabioreg('IOBlockStorageServices'); $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); foreach ($lines as $line) { $dev = new HWDevice(); if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf)) { $ar_buf = preg_split("/[\\s]+/", $line, 19); } $dev->setName(trim($ar_buf[1])); $this->sys->setScsiDevices($dev); } }
/** * I2C devices * * @return void */ protected function _i2c() { $i2cdevices = glob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT); if (($total = count($i2cdevices)) > 0) { $buf = ""; for ($i = 0; $i < $total; $i++) { if (CommonFunctions::rfts($i2cdevices[$i], $buf, 1, 4096, false) && trim($buf) != "") { $dev = new HWDevice(); $dev->setName(trim($buf)); $this->sys->setI2cDevices($dev); } } } }
/** * IDE information * * @return void */ protected function ide() { foreach ($this->readdmesg() as $line) { if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9] (.*): <(.*)>/', $line, $ar_buf)) { $dev = new HWDevice(); $dev->setName($ar_buf[1]); // now loop again and find the capacity foreach ($this->readdmesg() as $line2) { if (preg_match("/^(" . $ar_buf[1] . "): (.*), (.*), (.*)MB, .*\$/", $line2, $ar_buf_n)) { $dev->setCapacity($ar_buf_n[4] * 2048 * 1.049); } elseif (preg_match("/^(" . $ar_buf[1] . "): (.*) MB, (.*), (.*), .*\$/", $line2, $ar_buf_n)) { $dev->setCapacity($ar_buf_n[2] * 2048); } } $this->sys->setIdeDevices($dev); } } }
/** * USB devices * @return void */ private function _usb() { // FIXME CommonFunctions::executeProgram('cat', '/tmp/webprtconf.txt |grep USB', $bufr); $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); foreach ($lines as $line) { $dev = new HWDevice(); $dev->setName($line); $this->sys->setUsbDevices($dev); } }