Advertisement
Guest User

Untitled

a guest
Apr 26th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. function getEnvironmentValue($key, $default)
  5. {
  6.     $env = getenv($key);
  7.     if ($env === false)
  8.     {
  9.         $env = $default;
  10.     }
  11.     if (is_string($env))
  12.     {
  13.         return "'" . addslashes($env) . "'";
  14.     }
  15.     else if (is_numeric($env))
  16.     {
  17.         return $env;
  18.     }
  19.     else
  20.     {
  21.         echo "Invalid type for environment variable '$key'\n";
  22.         return "''";
  23.     }
  24. }
  25.  
  26. $mysqlUsername = getEnvironmentValue('MYSQL_USERNAME', 'root');
  27. $mysqlPassword = getEnvironmentValue('MYSQL_PASSWORD', '');
  28. $mysqlHost = getEnvironmentValue('MYSQL_HOST', '127.0.0.1');
  29. $mysqlPort = getEnvironmentValue('MYSQL_PORT', 3306);
  30. $mysqlDbname = getEnvironmentValue('MYSQL_DBNAME', 'xenforo');
  31.  
  32. $superAdmins = getEnvironmentValue('SUPER_ADMINS', '1');
  33. $mpqFilesPath = getEnvironmentValue('MPQ_FILES_PATH', '/usr/share/mpq');
  34. $debug = getEnvironmentValue('DEBUG', 0);
  35.  
  36. $cacheHost = getEnvironmentValue('MEMCACHED_HOST', '127.0.0.1');
  37. $cachePort = getEnvironmentValue('MEMCACHED_PORT', 11211);
  38. $cacheCompression = getEnvironmentValue('CACHE_COMPRESSION', 1);
  39.  
  40. $importLogTable = getEnvironmentValue('IMPORT_LOG_TABLE', 'xf_import_log');
  41. $xenGalleryImportLogTable = getEnvironmentValue('XENGALLERY_IMPORT_LOG_TABLE', 'xf_import_log');
  42.  
  43. // E.g. HTTP_X_FORWARDED_FOR
  44. $proxyIpCode = '';
  45. if (getenv('PROXY_IP_HEADER'))
  46. {
  47.     $proxyIpHeader = getEnvironmentValue('PROXY_IP_HEADER', '');
  48.     $proxyIpCode = "if (isset(\$_SERVER[$proxyIpHeader]))
  49. {
  50.     \$_SERVER['REMOTE_ADDR'] = \$_SERVER[$proxyIpHeader];
  51. }
  52. ";
  53. }
  54.  
  55. $config = "<?php
  56.  
  57. \$config['db']['host'] = $mysqlHost;
  58. \$config['db']['port'] = $mysqlPort;
  59. \$config['db']['username'] = $mysqlUsername;
  60. \$config['db']['password'] = $mysqlPassword;
  61. \$config['db']['dbname'] = $mysqlDbname;
  62.  
  63. \$config['mpqFilesPath'] = $mpqFilesPath;
  64.  
  65. \$config['superAdmins'] = $superAdmins;
  66.  
  67. \$config['debug'] = $debug;
  68.  
  69. \$config['cache']['backend'] = 'Memcached';
  70. \$config['cache']['backendOptions'] = array(
  71.     'compression' => $cacheCompression,
  72.     'servers' => array(
  73.         array(
  74.             'host' => $cacheHost,
  75.             'port' => $cachePort,
  76.         )
  77.     )
  78. );
  79.  
  80. $proxyIpCode
  81. ";
  82.  
  83. $importConfig = "
  84. <?php
  85.  
  86. define('IMPORT_LOG_TABLE', $importLogTable);
  87. define('XENGALLERY_IMPORT_LOG_TABLE', $xenGalleryImportLogTable);
  88. define('INCLUDE_PAGE_LINKS', true);
  89.  
  90. \$fileDir = dirname(__FILE__) . '/..';
  91.  
  92. ";
  93.  
  94. $result1 = file_put_contents('/var/www/html/library/config.php', $config) !== false;
  95.  
  96. $result2 = file_put_contents('/var/www/html/forums/301config.php', $importConfig) !== false;
  97.  
  98. exit(($result1 && $result2) ? 0 : 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement