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

/oiclient/lib/hardware/windowsOppClass.php

http://openirudi.googlecode.com/
PHP | 157 lines | 119 code | 27 blank | 11 comment | 25 complexity | e0fabd7c670e89ef3eec6fecbe067bd7 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. class windowsOppClass extends ntfsOppClass {
  3. // function __construct($disk,$partitionNumber,$partitionName,$partitionTypeId) {
  4. // parent::__construct($disk,$partitionNumber,$partitionName,$partitionTypeId);
  5. // $this->__set('os', 'windows');
  6. // $this->__set('bootable', true);
  7. // }
  8. public function getWinDriver($hw) {
  9. $returnPci = $this->scanPciDriver($hw->lspci);
  10. $PciErrors = $returnPci[0];
  11. $PciSuccesses = $returnPci[1];
  12. $returnUsb = $this->scanUsbDriver($hw->lsusb);
  13. $UsbErrors = $returnUsb[0];
  14. $UsbSuccesses = $returnUsb[1];
  15. return array($PciErrors, $PciSuccesses, $UsbErrors, $UsbSuccesses);
  16. }
  17. function scanPciDriver( $lspci ) {
  18. if(!$mountPoint=$this->isMounted()) {
  19. $mountedAlready=false;
  20. $mountPoint=$this->mount();
  21. }else {
  22. $mountedAlready=true;
  23. }
  24. $DriverServer=ImageServerOppClass::address();
  25. $serverPathPattern = sfConfig::get('app_driver_driverUrl');
  26. $sysprepWinPath = sfConfig::get('app_driver_sysprepwinpath');
  27. $defaultWinPath = sfConfig::get('app_driver_defaultwinpath');
  28. $vars = array('$server','$type','$vendor','$device','$subsys','$rev');
  29. $i = 1;
  30. $error = array();
  31. $success = array();
  32. foreach ( $lspci as $dev) {
  33. $values = array($DriverServer, 'pci', $dev['vendor'], $dev['device'], $dev['subsys'], $dev['rev']);
  34. $vid = $dev['vendor'];
  35. $pid = $dev['device'];
  36. if ($dev['subsys'] != '00000000') $subsys = $dev['subsys'];
  37. if ($dev['rev'] != '00') $rev = $dev['rev'];
  38. $url = str_replace($vars,$values,$serverPathPattern);
  39. exceptionHandlerClass::saveError("url:: $url");
  40. try {
  41. $zipped_driver = '';
  42. if ($zipped_driver = @fopen($url, 'r')) {
  43. // imprimir toda la pagina comenzando en la posicion 10
  44. $content = stream_get_contents($zipped_driver);
  45. if (strlen($content) != 0) {
  46. $zipFile = '/tmp/'.$i.'.zip';
  47. file_put_contents($zipFile, $content);
  48. if (is_dir($mountPoint.'/'.$sysprepWinPath)) {
  49. $cmd = sfConfig::get('app_driver_unzip');
  50. $cmd = str_replace('$winpath',$mountPoint.'/'.$sysprepWinPath,$cmd);
  51. $cmd = str_replace('$zipfile',$zipFile,$cmd);
  52. $re = executeClass::execute($cmd);
  53. exceptionHandlerClass::saveMessage("Driver saved from: $url to ". $sysprepWinPath );
  54. if (isset($subsys) && isset($rev))
  55. $success[] = strtoupper('pci\ven_'.$vid.'&dev_'.$pid.'&subsys_'.$subsys.'&rev_'.$rev);
  56. elseif (isset($subsys))
  57. $success[] = strtoupper('pci\ven_'.$vid.'&dev_'.$pid.'&subsys_'.$subsys);
  58. else
  59. $success[] = strtoupper('pci\ven_'.$vid.'&dev_'.$pid);
  60. } else {
  61. if (!is_dir($mountPoint.'/'.$defaultWinPath)) {
  62. if (@mkdir($mountPoint.'/'.$defaultWinPath) === false) {
  63. $error[] = __(sprintf("Permission denied for create %s folder", $mountPoint.$defaultWinPath));
  64. }
  65. }
  66. if (is_dir($mountPoint.'/'.$defaultWinPath)) {
  67. $cmd = sfConfig::get('app_driver_unzip');
  68. $cmd = str_replace('$winpath',$mountPoint.'/'.$defaultWinPath,$cmd);
  69. $cmd = str_replace('$zipfile',$zipFile,$cmd);
  70. $re = executeClass::execute($cmd);
  71. //exceptionHandlerClass::saveMessage("Driver saved from: $url to ".$defaultWinPath );
  72. if (isset($subsys) && isset($rev))
  73. $success[] = strtoupper('pci\ven_'.$vid.'&dev_'.$pid.'&subsys_'.$subsys.'&rev_'.$rev);
  74. elseif (isset($subsys))
  75. $success[] = strtoupper('pci\ven_'.$vid.'&dev_'.$pid.'&subsys_'.$subsys);
  76. else
  77. $success[] = strtoupper('pci\ven_'.$vid.'&dev_'.$pid);
  78. } else {
  79. //exceptionHandlerClass::saveError($sysprepWinPath." does not exists, and could not create " .$defaultWinPath." path");
  80. $error[] = __(sprintf("%s does not exists, and could not create %s path", $sysprepWinPath, $defaultWinPath));
  81. break;
  82. }
  83. }
  84. }
  85. fclose($zipped_driver);
  86. $i++;
  87. } else {
  88. //exceptionHandlerClass::saveError("I am sorry we have not drivers for this device $url" );
  89. $error[] = 'No drivers found for '.$url;
  90. }
  91. } catch (Exception $ex) {
  92. //exceptionHandlerClass::saveError("I am sorry we have not drivers for this device $url" );
  93. $error[] = 'No drivers found for '.$url;
  94. }
  95. unset($vid, $pid);
  96. if (isset($subsys)) unset($subsys);
  97. if (isset($rev)) unset($rev);
  98. }
  99. if(!$mountedAlready) {
  100. $this->umount();
  101. }
  102. return array($error, $success);
  103. }
  104. function scanUsbDriver($lsusb ) {
  105. if(!$mountPoint=$this->isMounted()) {
  106. $mountedAlready=false;
  107. $mountPoint=$this->mount();
  108. }else {
  109. $mountedAlready=true;
  110. }
  111. $error = array();
  112. $success = array();
  113. // TODO
  114. return array($error, $success);
  115. if(!$mountedAlready) {
  116. $this->umount();
  117. }
  118. }
  119. function changeUUID($uuid){
  120. $this->umount();
  121. exceptionHandlerClass::saveError("-----CHANGE uuid: $uuid");
  122. $f = fopen('/dev/'.$this->partitionName, "c+b");
  123. fseek($f,72,SEEK_CUR );
  124. foreach(array_reverse(str_split(trim($x),2)) as $h){
  125. fwrite($f,chr(hexdec($h)));
  126. }
  127. fclose($f);
  128. }
  129. }
  130. ?>