/upload/p_c.php

https://bitbucket.org/niidees/madserve · PHP · 167 lines · 133 code · 15 blank · 19 comment · 30 complexity · 87d23b173ab58a4ffd9b5f6aa04d838d MD5 · raw file

  1. <?php
  2. require_once 'mem_f.php';
  3. function MAD_CheckIfSystemInstalled()
  4. {
  5. $path = @dirname(__FILE__);
  6. if (!@empty($path)) {
  7. if (@file_exists($path . '/conf/INSTALLED')) {
  8. return false;
  9. } else {
  10. return true;
  11. }
  12. }
  13. return false;
  14. }
  15. function MAD_checkSystemInitialRequirements(&$aErrors){
  16. $isSystemOK = true;
  17. $return = true;
  18. $aRequiredFunctions = array(
  19. 'dirname',
  20. 'empty',
  21. 'file_exists',
  22. 'ini_set',
  23. 'parse_ini_file',
  24. 'version_compare'
  25. );
  26. // Prepare error strings, in the simplest possible way
  27. $errorString1 = 'The built in PHP function "';
  28. $errorString2 = '" is in the "disable_functions" list in your "php.ini" file.';
  29. // Need "function_exists" to be able to test for functions required
  30. // for testing what is in the "disabled_functions" list
  31. if (!function_exists('function_exists')) {
  32. $aErrors[] = $errorString1 . 'function_exists' . $errorString2;
  33. // Cannot detect any more errors, as function_exists is
  34. // needed to detect the required functions!
  35. return -1;
  36. }
  37. // Test for existence of "parse_url" and "strpos", which are
  38. // special cases required for the display of the error message
  39. // in the event of anything failing in this test!
  40. if (!function_exists('parse_url')) {
  41. $aErrors[] = $errorString1 . 'parse_url' . $errorString2;
  42. $isSystemOK = false;
  43. if ($return === true) {
  44. $return = -2;
  45. }
  46. }
  47. if (!function_exists('strpos')) {
  48. $aErrors[] = $errorString1 . 'strpos' . $errorString2;
  49. $isSystemOK = false;
  50. if ($return === true) {
  51. $return = -2;
  52. }
  53. }
  54. // Test for existence of "array_intersect", "explode", "ini_get"
  55. // and "trim", which are all required as part of the code to test
  56. // which functions are in the "disabled_functions" list below...
  57. if (!function_exists('array_intersect')) {
  58. $aErrors[] = $errorString1 . 'array_intersect' . $errorString2;
  59. $isSystemOK = false;
  60. if ($return === true) {
  61. $return = -3;
  62. }
  63. }
  64. if (!function_exists('explode')) {
  65. $aErrors[] = $errorString1 . 'explode' . $errorString2;
  66. $isSystemOK = false;
  67. if ($return === true) {
  68. $return = -3;
  69. }
  70. }
  71. if (!function_exists('ini_get')) {
  72. $aErrors[] = $errorString1 . 'ini_get' . $errorString2;
  73. $isSystemOK = false;
  74. if ($return === true) {
  75. $return = -3;
  76. }
  77. }
  78. if (!function_exists('trim')) {
  79. $aErrors[] = $errorString1 . 'trim' . $errorString2;
  80. $isSystemOK = false;
  81. if ($return === true) {
  82. $return = -3;
  83. }
  84. }
  85. // Test the disabled functons list with required functions list
  86. // defined above in $aRequiredFunctions
  87. $aDisabledFunctions = explode(',', ini_get('disable_functions'));
  88. foreach ($aDisabledFunctions as $key => $value) {
  89. $aDisabledFunctions[$key] = trim($value);
  90. }
  91. $aNeededFunctions = array_intersect($aDisabledFunctions, $aRequiredFunctions);
  92. if (count($aNeededFunctions) > 0) {
  93. $isSystemOK = false;
  94. foreach ($aNeededFunctions as $functionName) {
  95. $aErrors[] = $errorString1 . $functionName . $errorString2;
  96. }
  97. }
  98. // Check PHP version, as use of PHP < 5.1.4 will result in parse errors
  99. $errorMessage = "PHP version 5.1.4, or greater, was not detected.";
  100. if (function_exists('version_compare')) {
  101. $result = version_compare(phpversion(), '5.1.4', '<');
  102. if ($result) {
  103. $aErrors[] = $errorMessage;
  104. $isSystemOK = false;
  105. if ($return === true) {
  106. $return = -3;
  107. }
  108. }
  109. }
  110. // Check minimum memory requirements are okay (24MB)
  111. $minimumRequiredMemory = MAD_getMinimumRequiredMemory();
  112. $phpMemoryLimit = MAD_getMemoryLimitSizeInBytes();
  113. if ($phpMemoryLimit > 0 && $phpMemoryLimit < $minimumRequiredMemory) {
  114. // The memory limit is too low, but can it be increased?
  115. $memoryCanBeSet = MAD_checkMemoryCanBeSet();
  116. if (!$memoryCanBeSet) {
  117. $minimumRequiredMemoryInMB = $minimumRequiredMemory / 1048576;
  118. $errorMessage = 'The PHP "memory_limit" value is set to less than the required minimum of ' .
  119. $minimumRequiredMemoryInMB . 'MB, but because the built in PHP function "ini_set" ' .
  120. 'has been disabled, the memory limit cannot be automatically increased.';
  121. $aErrors[] = $errorMessage;
  122. $isSystemOK = false;
  123. if ($return === true) {
  124. $return = -4;
  125. }
  126. }
  127. }
  128. // Check magic_quotes_runtime and try to unset it
  129. $GLOBALS['original_get_magic_quotes_runtime'] = MAD_getMagicQuotesRuntime();
  130. if ($GLOBALS['original_get_magic_quotes_runtime']) {
  131. ini_set('magic_quotes_runtime', 0);
  132. if (MAD_getMagicQuotesRuntime()) {
  133. // try deprecated set_magic_quotes_runtime
  134. if (function_exists('set_magic_quotes_runtime')) {
  135. @set_magic_quotes_runtime(0);
  136. }
  137. }
  138. // check magic_quotes_runtime again, stop if still is set
  139. if (MAD_getMagicQuotesRuntime()) {
  140. $aErrors[] = 'The PHP magic_quotes_runtime option is ON, and cannot be automatically turned off.';
  141. $isSystemOK = false;
  142. if ($return === true) {
  143. $return = -5;
  144. }
  145. }
  146. }
  147. if (!$isSystemOK) {
  148. return $return;
  149. }
  150. return true;
  151. }
  152. ?>