apache.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. $gapsIni = realpath(dirname(__FILE__) . "/../../GAPS.ini");
  3. $config = parse_ini_file($gapsIni);
  4. $gapsApacheConf = $config['PORTAL']. "/Tasks/config/GAPS.Apache.conf";
  5. $apache = realpath($config['PHP'] . "/../httpd/conf/");
  6. function convertGapsConf () {
  7. global $config;
  8. global $apache;
  9. global $gapsApacheConf;
  10. if (!$apache) return "Apache-Verzeichnis nicht gefunden.";
  11. if (!file_exists($apache . "/GAPS.conf")) return "GAPS.conf nicht gefunden.";
  12. $httpdConf = file_get_contents($apache . "/httpd.conf");
  13. $match = array();
  14. if (!preg_match('/\r\nListen (\d+)/im', $httpdConf, $match)) return "Apache-Port nicht gefunden.";
  15. $httpdConf = preg_replace('/\r\nListen \d+/im', "", $httpdConf);
  16. $port = $match[1];
  17. $httpdConf = str_replace('GCPS.conf', 'php5.module.conf', $httpdConf);
  18. $httpdConf .= "\r\n" . 'include "' . str_replace("\\", "/", $config['PORTAL']) . '/Tasks/config/GAPS.Apache.conf"';
  19. if (!rename($apache . "/GAPS.conf", $gapsApacheConf)) return "GAPS.conf laesst sich nicht verschieben.";
  20. if (!file_put_contents($apache . "/httpd.conf", $httpdConf)) {
  21. file_put_contents($config['PORTAL']. "/Tasks/httpd.conf", $httpdConf);
  22. return "httpd.conf laesst sich nicht ueberschreiben. Bitte manuell austauschen.";
  23. }
  24. unlink($apache. "/GCPS.conf");
  25. $gapsConf = file_get_contents($gapsApacheConf);
  26. $gapsConf = "Listen " . $port . "\r\n\r\n" . $gapsConf;
  27. file_put_contents($gapsApacheConf, $gapsConf);
  28. return "";
  29. }
  30. function addGapsUrl () {
  31. global $config;
  32. global $gapsIni;
  33. global $gapsApacheConf;
  34. $gapsConf = file_get_contents($gapsApacheConf);
  35. if (!preg_match('/\nAlias "\/(.*)" "(.*)"\r\n/im', $gapsConf, $match)) return "Alias unbekannt";
  36. $subdir = $match[1];
  37. if (preg_match('/Listen (\d+)/im', $gapsConf, $match)) {
  38. $port = $match[1];
  39. } else {
  40. $port = "80";
  41. }
  42. $output = array();
  43. exec("systeminfo", $output);
  44. $output = implode("\r\n", $output);
  45. if (!preg_match('/(LAN-Verbindung|Ethernet0|Local Area)[^[]*\[01\]:\s([\d\.]+)/im', $output, $match)) return "IP-Adresse unbekannt.";
  46. $host = $match[2];
  47. $config['GAPS_URL'] = "http://{$host}:{$port}/{$subdir}";
  48. file_put_contents($gapsIni, "\r\nGAPS_URL=\"{$config['GAPS_URL']}\"" , FILE_APPEND);
  49. return "";
  50. }
  51. function addRemoteTasks() {
  52. global $gapsApacheConf;
  53. $gapsConf = file_get_contents($gapsApacheConf);
  54. if (!preg_match('/\nAlias "\/Remote\/" "(.*)"\r\n/im', $gapsConf, $match)) {
  55. $alias = 'Alias "/Remote/" "' . str_replace("\\", "/", realpath(dirname(__FILE__)."/../Remote")) . '/"' . "\r\n\r\n";
  56. $gapsConf = str_replace("\r\n<Dir", $alias . "\r\n<Dir", $gapsConf);
  57. file_put_contents($gapsApacheConf, $gapsConf);
  58. }
  59. return "";
  60. }
  61. if (!file_exists($gapsApacheConf)) {
  62. echo convertGapsConf();
  63. }
  64. if (!isset($config['GAPS_URL'])) {
  65. echo addGapsUrl();
  66. }
  67. if (file_exists($gapsApacheConf)) {
  68. echo addRemoteTasks();
  69. }
  70. echo "Apache-Umstellung erfolgreich.";