PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/1.0RC4/www/testenvironment.php

http://scalr.googlecode.com/
PHP | 148 lines | 106 code | 23 blank | 19 comment | 36 complexity | d7c5f3252e4eabf6c00e8bd4858ef520 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, GPL-3.0
  1. <?
  2. $sapi_type = php_sapi_name();
  3. if (substr($sapi_type, 0, 3) == 'cli')
  4. $CLI = true;
  5. // Check POSIX
  6. if (!function_exists('posix_getpid'))
  7. $err[] = "Cannot find posix_getpid function. Make sure that POSIX Functions enabled.";
  8. // Check PCNTL
  9. if ($CLI && !function_exists('pcntl_fork'))
  10. $err[] = "Cannot find pcntl_fork function. Make sure that PCNTL Functions enabled.";
  11. // Check DOM
  12. if (!class_exists('DOMDocument'))
  13. $err[] = "Cannot find DOM functions. Make sure that DOM Functions enabled.";
  14. // Check SimpleXML
  15. if (!function_exists('simplexml_load_string'))
  16. $err[] = "Cannot find simplexml_load_string function. Make sure that SimpleXML Functions enabled.";
  17. // Check MySQLi
  18. if (!function_exists('mysqli_connect'))
  19. $err[] = "Cannot find mysqli_connect function. Make sure that MYSQLi Functions enabled.";
  20. // Check GetText
  21. if (!function_exists('gettext'))
  22. $err[] = "Cannot find gettext function. Make sure that GetText Functions enabled.";
  23. // Check MCrypt
  24. if (!function_exists('mcrypt_encrypt'))
  25. $err[] = "Cannot find mcrypt_encrypt function. Make sure that mCrypt Functions enabled.";
  26. // Check MHash
  27. if (!function_exists('mhash'))
  28. $err[] = "Cannot find mhash function. Make sure that mHASH Functions enabled.";
  29. // Check OpenSSL
  30. if (!function_exists('openssl_verify'))
  31. $err[] = "Cannot find OpenSSL functions. Make sure that OpenSSL Functions enabled.";
  32. // Check SOAP
  33. if (!class_exists('SoapClient'))
  34. $err[] = "Cannot find SoapClient class. Make sure that SoapClient Extension enabled.";
  35. // Check SSH
  36. if (!function_exists('ssh2_connect'))
  37. $err[] = "Cannot find SSH2 functions. Make sure that SSH2 Functions enabled.";
  38. // Check SNMP
  39. if (!function_exists('snmpget'))
  40. $err[] = "Cannot find SNMP functions. Make sure that SNMP Functions enabled.";
  41. //
  42. // Check php sessings
  43. //
  44. if (ini_get('safe_mode') == 1)
  45. $err[] = "PHP safe mode enabled. Please disable it.";
  46. if (ini_get('register_gloabls') == 1)
  47. $err[] = "PHP register globals enabled. Please disable it.";
  48. if (str_replace(".", "", PHP_VERSION) < 525)
  49. $err[] = "PHP version must be 5.2.5 or greater.";
  50. // If all extensions installed
  51. if (count($err) == 0)
  52. {
  53. // Check files & folders permissions
  54. $files = array(
  55. realpath(dirname(__FILE__)."/../etc/.passwd"),
  56. realpath(dirname(__FILE__)."/../cache"),
  57. realpath(dirname(__FILE__)."/../cache/smarty_bin")
  58. );
  59. foreach ($files as $file)
  60. {
  61. if (!is_writable($file))
  62. $err[] = "Insuficient permissions on file {$file}. Please chmod 0777";
  63. }
  64. // Parse config.ini and test database connection
  65. $cfg = @parse_ini_file(dirname(__FILE__)."/../etc/config.ini", true);
  66. if ($cfg)
  67. {
  68. $c = @mysqli_connect($cfg['db']['host'], $cfg['db']['user'], $cfg['db']['pass'], $cfg['db']['name']);
  69. if (!$c)
  70. $err[] = "Cannot connect to database using settings from etc/config.ini file";
  71. }
  72. else
  73. $err[] = "Cannot parse etc/config.ini file.";
  74. require_once (dirname(__FILE__).'/../src/prepend.inc.php');
  75. $keys = glob(dirname(__FILE__).'/../etc/pk-*.pem');
  76. if (count($keys) == 0)
  77. $err[] = "Cannot find your AWS keys. Please configure Scalr as described in <a href='http://code.google.com/p/scalr/wiki/Installation'>wiki</a>.";
  78. else
  79. {
  80. foreach ($keys as $key)
  81. {
  82. $key = realpath($key);
  83. try
  84. {
  85. $AmazonEC2 = AmazonEC2::GetInstance(AWSRegions::GetAPIURL($_SESSION['aws_region']));
  86. $AmazonEC2->SetAuthKeys(
  87. $keys[0],
  88. str_replace("pk-", "cert-", $key),
  89. true
  90. );
  91. $AmazonEC2->DescribeInstances();
  92. }
  93. catch(Exception $e)
  94. {
  95. $err[] = "Cannot use {$key} key: {$e->getMessage()}";
  96. }
  97. }
  98. }
  99. // Check path to SNMP Trap
  100. if (!file_exists(CONFIG::$SNMPTRAP_PATH) || !is_executable(CONFIG::$SNMPTRAP_PATH))
  101. $err[] = CONFIG::$SNMPTRAP_PATH." not exists or not executable. Please check path to snmpinformer on Settings > Core Settings page.";
  102. }
  103. if (!$CLI)
  104. {
  105. if (count($err) == 0)
  106. print "<span style='color:green'>Congratulations, your environment settings match Scalr requirements!</span>";
  107. else
  108. {
  109. print "<span style='color:red'>Errors:</span><br>";
  110. foreach ($err as $e)
  111. print "<span style='color:red'>&bull; {$e}</span><br>";
  112. }
  113. }
  114. else
  115. {
  116. if (count($err) == 0)
  117. print "\033[32mCongratulations, your environment settings match Scalr requirements!\033[0m\n";
  118. else
  119. {
  120. print "\033[31mErrors:\033[0m\n";
  121. foreach ($err as $e)
  122. print "\033[31m- {$e}\033[0m\n";
  123. }
  124. }
  125. ?>