UpdateController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. class UpdateController
  3. {
  4. public static function Run ($argv)
  5. {
  6. if (!class_exists("ZipArchive")) {
  7. exit(25);
  8. }
  9. $beta = (count($argv) > 1);
  10. $updateCtrl = new UpdateController($beta);
  11. $version = $updateCtrl->newVersionAvailable();
  12. if ($version) {
  13. echo "Neue Version gefunden: " . $version . "\r\nUpdate ";
  14. echo ($updateCtrl->upgrade()) ? "erfolgreich" : "fehlgeschlagen";
  15. echo "\r\n";
  16. } else {
  17. echo "Kein Update erforderlich.\r\n";
  18. }
  19. $updateCtrl->pcvisit();
  20. $updateCtrl->symlink();
  21. }
  22. private $url = "http://dev.global-cube.com/";
  23. private $path;
  24. public function __construct($beta = false)
  25. {
  26. $this->path = ($beta) ? "tasks-beta/" : "tasks/";
  27. }
  28. public function upgrade()
  29. {
  30. $remoteZipFile = $this->url . $this->path . "scripts.zip";
  31. $scriptsDir = realpath(".");
  32. $localZipFile = $scriptsDir . "/scripts.zip";
  33. $zipFile = file_get_contents($remoteZipFile);
  34. if (!$zipFile || !class_exists("ZipArchive")) {
  35. return false;
  36. }
  37. file_put_contents($localZipFile, $zipFile);
  38. $zip = new ZipArchive();
  39. if (!$zip->open($localZipFile)) {
  40. return false;
  41. }
  42. exec("del /Q /S \"{$scriptsDir}\" ");
  43. $zip->extractTo($scriptsDir);
  44. $zip->close();
  45. unlink($localZipFile);
  46. return true;
  47. }
  48. public function newVersionAvailable ()
  49. {
  50. $serverVersion = @file_get_contents($this->url . $this->path . "version.txt");
  51. if (!$serverVersion) {
  52. return false;
  53. }
  54. $localVersionFile = "version.txt";
  55. if (file_exists($localVersionFile)) {
  56. if (file_get_contents($localVersionFile) >= $serverVersion) {
  57. return false;
  58. }
  59. }
  60. return $serverVersion;
  61. }
  62. private function pcvisit ()
  63. {
  64. require_once(dirname(__FILE__) . '/../pcvisit.php');
  65. }
  66. private function symlink ()
  67. {
  68. $config = parse_ini_file(dirname(__FILE__) . "/../../../GAPS.ini");
  69. $filename = "%USERPROFILE%\\Desktop\\GAPS Tasks " . $config['KUNDE'] . ".lnk";
  70. // if (file_exists($filename)) return;
  71. if (!isset($config['GAPS_URL'])) {
  72. require_once(dirname(__FILE__) . '/../apache.php');
  73. }
  74. $split = explode("/", $config['GAPS_URL']);
  75. $remote = "http://" . $split[2] . "/Remote/";
  76. file_put_contents(dirname(__FILE__) . "/../link.bat",
  77. 'start /MIN explorer.exe /e, "' . $config['PORTAL'] . '\Tasks"' . "\r\n" .
  78. 'start /MIN iexplore.exe -nosessionmerging "' . $config['GAPS_URL'] . 'index.php5?&rc=MISModel&rm=getModel"' . "\r\n" .
  79. 'start /MIN iexplore.exe -nosessionmerging "' . $remote . '"' . "\r\n" .
  80. 'start %WINDIR%\system32\cmd.exe /T:1f /K "' . $config['PORTAL'] . '\Tasks\scripts\config.bat"' . "\r\n");
  81. $shell = new COM('WScript.Shell');
  82. $shortcut = $shell->CreateShortcut(dirname(__FILE__) . "/../link.lnk");
  83. $shortcut->TargetPath = $config['PORTAL'] . '\Tasks\scripts\Tools\link.bat';
  84. $shortcut->IconLocation = "%WINDIR%\\system32\\shell32.dll, 165";
  85. $shortcut->Save();
  86. exec('copy /Y "Tools\link.lnk" "' . $filename . '"');
  87. }
  88. }