PageRenderTime 34ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/oiclient/lib/hardware/hardwareDetectOppClass.php

http://openirudi.googlecode.com/
PHP | 257 lines | 141 code | 26 blank | 90 comment | 16 complexity | 5d8e86c031a62508d6b32cd4d0801db7 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. class hardwareDetectOppClass {
  3. private $hardwareArray;
  4. private $hardDetail;
  5. private $lspci;
  6. private $lsusb;
  7. private $listDisks;
  8. private $motherBoard;
  9. private $cpuDescription;
  10. private $cpuFrecuency;
  11. private $ramType;
  12. private $ramSize;
  13. private $network;
  14. private $pcID;
  15. function __construct() {
  16. $sfUser = sfContext::getInstance()->getUser();
  17. $sfUser->setAttribute('partitionTypes', partitionOppClass::get_partitionTypes());
  18. $resync = executeClass::StrExecute(sfConfig::get('app_oipartition_reSyncDisk'));
  19. $this->hardwareArray = unserialize(str_replace(
  20. array('O:16:"SimpleXMLElement":0:{}', 'O:16:"SimpleXMLElement":'),
  21. array('s:0:"";', 'O:8:"stdClass":'),
  22. serialize($this->hardwareArray)));
  23. $this->set_listDisks();
  24. $this->set_lspci();
  25. $this->set_lsusb();
  26. //ImageServerOppClass::savePcConfig($this->registryArray());
  27. //exceptionHandlerClass::saveMessage("AAA: ".print_r($this->registryArray(),1) );
  28. }
  29. function __get($propertyName) {
  30. try {
  31. if (property_exists('hardwareDetectOppClass', $propertyName)) {
  32. if (empty($this->$propertyName)) {
  33. $this->__set($propertyName, '');
  34. }
  35. return $this->$propertyName;
  36. }
  37. throw new Exception("&&Invalid property value \"{$propertyName}\"");
  38. } catch (Exception $e) {
  39. exceptionHandlerClass::saveError($e->getMessage());
  40. }
  41. }
  42. function __set($propertyName, $value) {
  43. try {
  44. if (!property_exists('hardwareDetectOppClass', $propertyName)) {
  45. throw new Exception("Invalid property value \"{$propertyName}\" in hardwareDetectOppClass ");
  46. }
  47. if (method_exists($this, 'set_' . $propertyName)) {
  48. call_user_func(array($this, 'set_' . $propertyName), $value);
  49. } else {
  50. throw new Exception("*Invalid property value \"{$propertyName}\" in hardwareDetectOppClass ");
  51. }
  52. } catch (Exception $e) {
  53. exceptionHandlerClass::saveError($e->getMessage());
  54. }
  55. }
  56. function set_pcID(){
  57. $this->__get('listDisks');
  58. $this->__get('network');
  59. $d1=$this->listDisks->diskSerials();
  60. $d=array_shift($d1);
  61. $this->pcID = str_replace(' ','',"{$this->network->deviceHwInfo}{$d}");
  62. }
  63. function set_hardwareArray() {
  64. $hw_xml = executeClass::StrExecute(sfConfig::get('app_command_lshw'));
  65. $lshw = new lshwParseClass();
  66. $this->hardwareArray = $lshw->hardwareList($hw_xml);
  67. }
  68. function set_hardDetail() {
  69. $this->__get('hardwareArray');
  70. $strKendu = array('Array', '(', ')', '=>', "\n", ' ');
  71. $strBerri = array('', '', '', '=', '<br>', '&nbsp;');
  72. $this->hardDetail = str_replace($strKendu, $strBerri, print_r($this->hardwareArray, 1));
  73. }
  74. function set_listDisks() {
  75. $this->listDisks = new listDisksOppClass();
  76. foreach ($this->listDisks->disks as $disk) {
  77. $disk->sectorsMap();
  78. }
  79. }
  80. function set_network() {
  81. $this->network = new networkOppClass();
  82. }
  83. function set_cpuDescription() {
  84. $this->__get('hardwareArray');
  85. $cpu = array();
  86. $keys = array_keys($this->hardwareArray['core']);
  87. foreach ($keys as $k) {
  88. if (strpos($k, 'cpu') !== false && isset($this->hardwareArray['core'][$k]['product'])) {
  89. $cpu[] = $this->hardwareArray['core'][$k]['product'];
  90. }
  91. }
  92. $this->cpuDescription.=implode("<br>", $cpu);
  93. }
  94. function set_cpuFrecuency() {
  95. $this->__get('hardwareArray');
  96. $this->cpuFrecuency = unitsClass::sizeUnit($this->cpu = $this->hardwareArray['core']['cpu']['size']);
  97. }
  98. function set_motherBoard() {
  99. $this->__get('hardwareArray');
  100. if (isset($this->hardwareArray['core']['product'])) {
  101. $this->motherBoard = $this->hardwareArray['core']['product'];
  102. } elseif (isset($this->hardwareArray['product'])) {
  103. $this->motherBoard = $this->hardwareArray['product'];
  104. } else {
  105. $this->motherBoard = '';
  106. }
  107. }
  108. function set_ramSize() {
  109. $this->__get('hardwareArray');
  110. if(isset($this->hardwareArray['core']['memory:0']['capacity'])){
  111. $this->ramSize = unitsClass::sizeUnit($this->hardwareArray['core']['memory:0']['capacity']);
  112. }elseif(isset($this->hardwareArray['core']['memory']['capacity'])){
  113. $this->ramSize = unitsClass::sizeUnit($this->hardwareArray['core']['memory']['capacity']);
  114. }else{
  115. $this->ramSize ="";
  116. }
  117. }
  118. function set_ramType() {
  119. $this->__get('hardwareArray');
  120. if( isset($this->hardwareArray['core']['memory:0'])){
  121. $mem=$this->hardwareArray['core']['memory:0'];
  122. }elseif($this->hardwareArray['core']['memory']){
  123. $mem=$this->hardwareArray['core']['memory'];
  124. }else{
  125. $mem=array();
  126. }
  127. $r = '';
  128. foreach ($mem as $k => $v) {
  129. if (is_array($v) && strpos($k, 'bank:') !== false) {
  130. if (isset($v['size']) && !empty($v['size'])) {
  131. $b = unitsClass::sizeUnit($v['size']);
  132. $bb = "( " . $b['size'] . $b['unit'] . " )";
  133. } else {
  134. $bb = '';
  135. }
  136. $r.= "<br> slot (" . $v['slot'] . ") = " . $v['description'] . " $bb ";
  137. }
  138. }
  139. $this->ramType = $r;
  140. }
  141. function set_lspci() {
  142. $i = 0;
  143. foreach (glob("/sys/bus/pci/devices/*") as $bus) {
  144. $this->lspci[$i]['vendor'] = str_replace('0x', '', trim(file_get_contents($bus . '/vendor')));
  145. $this->lspci[$i]['device'] = str_replace('0x', '', trim(file_get_contents($bus . '/device')));
  146. $this->lspci[$i]['svendor'] = str_replace('0x', '', trim(file_get_contents($bus . '/subsystem_vendor')));
  147. $this->lspci[$i]['sdevice'] = str_replace('0x', '', trim(file_get_contents($bus . '/subsystem_device')));
  148. $a = parse_ini_file($bus . '/uevent');
  149. $this->lspci[$i]['subsys'] = str_replace(':', '', $a['PCI_SUBSYS_ID']);
  150. $this->lspci[$i]['pci_id'] = str_replace(':', '', $a['PCI_ID']);
  151. if (isset($a['DRIVER'])) {
  152. $this->lspci[$i]['driver'] = str_replace(':', '', $a['DRIVER']);
  153. }
  154. $this->lspci[$i]['rev'] = '00';
  155. $i++;
  156. }
  157. }
  158. function set_lsusb() {
  159. $i = 0;
  160. $this->lsusb = array();
  161. foreach (glob("/sys/bus/usb/devices/*") as $bus) {
  162. if (file_exists($bus . '/idVendor'))
  163. $this->lsusb[$i]['idVendor'] = trim(file_get_contents($bus . '/idVendor'));
  164. if (file_exists($bus . '/idProduct'))
  165. $this->lsusb[$i]['idProduct'] = trim(file_get_contents($bus . '/idProduct'));
  166. if (file_exists($bus . '/bcdDevice'))
  167. $this->lsusb[$i]['bcdDevice'] = trim(file_get_contents($bus . '/bcdDevice'));
  168. if (file_exists($bus . '/idVendor'))
  169. $this->lsusb[$i]['bDeviceClass'] = trim(file_get_contents($bus . '/bDeviceClass'));
  170. if (file_exists($bus . '/bDeviceSubClass'))
  171. $this->lsusb[$i]['bDeviceSubClass'] = trim(file_get_contents($bus . '/bDeviceSubClass'));
  172. if (file_exists($bus . '/bDeviceProtocol'))
  173. $this->lsusb[$i]['bDeviceProtocol'] = trim(file_get_contents($bus . '/bDeviceProtocol'));
  174. if (file_exists($bus . '/bInterfaceClass'))
  175. $this->lsusb[$i]['bInterfaceClass'] = trim(file_get_contents($bus . '/bInterfaceClass'));
  176. if (file_exists($bus . '/bInterfaceSubClass'))
  177. $this->lsusb[$i]['bInterfaceSubClass'] = trim(file_get_contents($bus . '/bInterfaceSubClass'));
  178. if (file_exists($bus . '/bInterfaceProtocol'))
  179. $this->lsusb[$i]['bInterfaceProtocol'] = trim(file_get_contents($bus . '/bInterfaceProtocol'));
  180. $i++;
  181. }
  182. }
  183. function registryArray() {
  184. $this->__get('network');
  185. $this->__get('pcID');
  186. $registryArray['mac'] = $this->network->deviceHwInfo;
  187. $registryArray['hddid'] = $this->pcID;
  188. $registryArray['name'] = $this->network->hostname;
  189. if (isset($this->network->ipAddress['main']['ip']) && !empty($this->network->ipAddress['main']['ip'])) {
  190. if ($this->network->ipAddress['main']['dhcp'] == 1) {
  191. $registryArray['ip'] = 'dhcp';
  192. } else {
  193. $registryArray['ip'] = $this->network->ipAddress['main']['ip'];
  194. $registryArray['netmask'] = $this->network->ipAddress['main']['netmask'];
  195. $registryArray['gateway'] = $this->network->route['default']['gateway'];
  196. }
  197. }
  198. $registryArray['dns'] = implode(',', $this->network->dns);
  199. $p = array();
  200. foreach ($this->listDisks->disks as $disk) {
  201. $serial = $disk->serialNumber;
  202. $i = 0;
  203. $p[$serial]['disks'][]=$disk->diskName;
  204. if(count($disk->partitions) > 0){
  205. foreach ($disk->partitions as $partition) {
  206. $p[$serial][$i]['partitionName'] = $partition->partitionName;
  207. $p[$serial][$i]['startSector'] = $partition->startSector;
  208. $p[$serial][$i]['sectors'] = $partition->sectors;
  209. $p[$serial][$i]['size'] = $partition->humanSize['size'] . $partition->humanSize['unit'];
  210. $p[$serial][$i]['partitionTypeId'] = $partition->partitionTypeId;
  211. $p[$serial][$i]['partitionTypeName'] = $partition->partitionTypeName;
  212. $p[$serial][$i]['fstype'] = $partition->fstype;
  213. $i++;
  214. }
  215. }
  216. }
  217. $registryArray['partitions'] = serialize($p);
  218. return $registryArray;
  219. }
  220. }
  221. ?>