PageRenderTime 37ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/control/test.php

https://github.com/agnesrambaud/yacs
PHP | 298 lines | 158 code | 50 blank | 90 comment | 52 complexity | 43ee4d53b0950fb4ac020f4ed1bda7e9 MD5 | raw file
  1. <?php
  2. /**
  3. * display system information
  4. *
  5. * This script is aiming to troubleshoot particular situations.
  6. *
  7. * First of all, several options are offered to call it, including a bar GET, a more complex GET
  8. * with parameters, and also a POST.
  9. *
  10. * After that, several blocks of information are displayed:
  11. *
  12. * [*] Data sent by the user agent -- the content of [code]$_REQUEST[/code]
  13. *
  14. * [*] Arguments passed in the URL -- YACS decodes the query string and puts everything into [code]$context['arguments'][/code]
  15. *
  16. * [*] Cookies -- the content of [code]$_COOKIE[/code]
  17. *
  18. * [*] Session data -- the content of [code]$_SESSION[/code]
  19. *
  20. * [*] Session storage test -- a counter incremented at each page visit
  21. *
  22. * [*] Some YACS global variables -- including [code]$context['host_name'][/code],
  23. * [code]$context['url_to_home'][/code], [code]$context['url_to_root'][/code],
  24. * [code]$context['script_url'][/code], [code]$context['path_to_root'][/code],
  25. * and [code]$context['charset'][/code].
  26. *
  27. * [*] YACS version -- the content of [code]footprints.php[/code]
  28. *
  29. * [*] Run-time information (to associates only) -- the result of [code]getcwd()[/code],
  30. * of [code]php_sapi_name()[/code]
  31. *
  32. * [*] Server attributes -- the content of [code]$_SERVER[/code]; some attributes are masked to non-associates,
  33. * for example: [code]$_SERVER['COMSPEC'][/code], [code]$_SERVER['DOCUMENT_ROOT'][/code],
  34. * [code]$_SERVER['PATH'][/code], [code]$_SERVER['SCRIPT_FILENAME'][/code],
  35. * [code]$_SERVER['SystemRoot'][/code], [code]$_SERVER['WINDIR'][/code].
  36. *
  37. * [*] Time offset, as expressed by the browser, if any -- based on Javascript, and by the server -- based on PHP
  38. *
  39. * @link http://www.olate.com/articles/254 Use PHP and JavaScript to Display Local Time
  40. *
  41. * If the file [code]parameters/demo.flag[/code] exists, the script assumes that this instance
  42. * of YACS runs in demonstration mode, and does not provide the content
  43. * of [code]$_SERVER[/code].
  44. *
  45. * @author Bernard Paques
  46. * @author GnapZ
  47. * @tester Geoffroy Raimbault
  48. * @tester Christian Loubechine
  49. * @reference
  50. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  51. */
  52. // include global declarations
  53. include_once '../shared/global.php';
  54. // if it was a HEAD request, stop here
  55. if(isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'HEAD'))
  56. return;
  57. // load localized strings
  58. i18n::bind('control');
  59. // stop crawlers
  60. if(Surfer::is_crawler()) {
  61. Safe::header('Status: 401 Forbidden', TRUE, 401);
  62. return i18n::s('You are not allowed to perform this operation.');
  63. }
  64. // no skin for this page
  65. if(!defined('BR'))
  66. define('BR', '<br>');
  67. // add language information, if known
  68. if(isset($context['page_language']))
  69. $language = ' xml:lang="'.$context['page_language'].'" ';
  70. else
  71. $language = '';
  72. // start the page
  73. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n"
  74. .'<html '.$language.' xmlns="http://www.w3.org/1999/xhtml">'."\n"
  75. .'<head>'."\n"
  76. ."\t".'<meta http-equiv="Content-Type" content="'.$context['content_type'].'; charset='.$context['charset'].'" />'."\n"
  77. ."\t".'<title>'.i18n::s('The test page').'</title>'."\n"
  78. .'</head><body>'."\n";
  79. // the path to this page
  80. echo '<p><a href="'.$context['url_to_root'].'control/">'.i18n::s('Control Panel')."</a></p>\n";
  81. // the title of the page
  82. echo '<h1>'.i18n::s('The test page')."</h1>\n";
  83. // stop crawlers here
  84. if(Surfer::is_crawler())
  85. return;
  86. // native calls for this script
  87. echo '<p>'.i18n::s('A more complex GET test').' <a href="'.$context['url_to_root'].'control/test.php/123/456/789?a=B">test.php/123/456/789?a=B</a></p>'."\n";
  88. echo '<form action="'.$context['url_to_root'].'control/test.php/123/456/789?a=B" method="post"><div>'
  89. .'<button type="submit"><span>'.i18n::s('A complex POST test').'</span></button>'
  90. .'<input type="hidden" name="hello" value="world">'
  91. .'</div></form>'."\n";
  92. // rewritten call for this script
  93. echo '<form action="'.$context['script_url'].'" method="post"><div>'
  94. .'<button type="submit"><span>'.i18n::s('A self-referencing POST test').'</span></button>'
  95. .'<input type="hidden" name="hello" value="world">'
  96. .'</div></form>'."\n";
  97. // session test
  98. if(isset($_SESSION['test_hits']))
  99. $_SESSION['test_hits'] += 1;
  100. else
  101. $_SESSION['test_hits'] = 1;
  102. echo '<p>'.sprintf(i18n::s('Session variables are stored correctly if the counter increments on page reload: %s'), $_SESSION['test_hits']).'</p>'."\n";
  103. // reflect data sent by the user agent
  104. if(@count($_REQUEST)) {
  105. echo '<p>'.i18n::s('Submitted request:').BR."\n";
  106. foreach($_REQUEST as $name => $value)
  107. echo '$_REQUEST[\''.strip_tags($name).'\']='.strip_tags($value).BR."\n";
  108. echo "</p>\n";
  109. }
  110. // args passed in the URL
  111. if(@count($context['arguments'])) {
  112. echo '<p>'.i18n::s('Script args:').BR."\n";
  113. for($index = 0; $index < count($context['arguments']); $index++)
  114. echo '$context[\'arguments\']['.$index.']='.strip_tags($context['arguments'][$index]).BR."\n";
  115. echo "</p>\n";
  116. }
  117. // cookies
  118. if(@count($_COOKIE)) {
  119. echo '<p>'.i18n::s('Cookies sent by the browser:').BR."\n";
  120. foreach($_COOKIE as $name => $value)
  121. echo '$_COOKIE[\''.strip_tags($name).'\']='.strip_tags($value).BR."\n";
  122. echo "</p>\n";
  123. }
  124. // session data -- this is safe, we are only reflecting data for this surfer
  125. if(@count($_SESSION)) {
  126. echo '<p>'.i18n::s('Session data:').BR."\n";
  127. foreach($_SESSION as $name => $value) {
  128. if(!is_array($value))
  129. echo '$_SESSION[\''.$name.'\']='.$value.BR."\n";
  130. }
  131. echo "</p>\n";
  132. }
  133. // yacs version
  134. if(!isset($generation['version']))
  135. Safe::load('footprints.php'); // initial archive
  136. if(isset($generation['version'])) {
  137. echo '<p>'.sprintf(i18n::s('YACS version %s'), $generation['version'].', '.$generation['date'].', '.$generation['server'])."</p>\n";
  138. } else {
  139. echo '<p>'.sprintf(i18n::s('YACS version %s'), '< 6.3')."</p>\n";
  140. }
  141. // YACS variables
  142. echo '<p>'.i18n::s('Global YACS variables:').BR."\n";
  143. if($context['country'])
  144. echo '$context[\'country\']='.$context['country'].BR."\n";
  145. if($context['country_code'])
  146. echo '$context[\'country_code\']='.$context['country_code'].BR."\n";
  147. echo '$context[\'language\']='.$context['language'].BR."\n"
  148. .'$context[\'host_name\']='.$context['host_name'].BR."\n"
  149. .'$context[\'url_to_home\']='.$context['url_to_home'].BR."\n"
  150. .'$context[\'url_to_root\']='.$context['url_to_root'].BR."\n"
  151. .'$context[\'script_url\']='.$context['script_url'].BR."\n"
  152. .'$context[\'self_url\']='.$context['self_url'].BR."\n"
  153. .'$context[\'self_script\']='.$context['self_script'].BR."\n";
  154. if(Surfer::is_associate()) {
  155. echo '$context[\'path_to_root\']='.$context['path_to_root'].BR."\n";
  156. echo '$context[\'directory_mask\']='.sprintf('0%o', $context['directory_mask']).BR."\n";
  157. echo '$context[\'file_mask\']='.sprintf('0%o', $context['file_mask']).BR."\n";
  158. echo '$context[\'skin\']='.$context['skin'].BR."\n";
  159. }
  160. echo '$context[\'charset\']='.$context['charset'].BR."\n";
  161. // server attributes -- not in demonstration mode
  162. if(@count($_SERVER) && !file_exists($context['path_to_root'].'parameters/demo.flag')) {
  163. echo '<p>'.i18n::s('Server attributes:').BR."\n";
  164. foreach($_SERVER as $name => $value) {
  165. // protect key attributes
  166. if(!Surfer::is_associate() && !preg_match('/^(HTTP_|PATH_INFO|QUERY_STRING|REMOTE_|REQUEST_|SERVER_|STATUS)/', $name))
  167. continue;
  168. echo '$_SERVER[\''.$name.'\']='.$value.BR."\n";
  169. }
  170. echo "</p>\n";
  171. }
  172. // display workstation time offset
  173. echo JS_PREFIX
  174. .'now = new Date();'."\n"
  175. .'offset = (-now.getTimezoneOffset() / 60);'."\n"
  176. .'document.write("<p>'.i18n::s('Browser GMT offset:').' UTC " + ((offset > 0) ? "+" : "") + offset + " '.i18n::s('hour(s)').'</p>");'."\n"
  177. .JS_SUFFIX;
  178. // display server time offset
  179. $offset = intval((strtotime(date('M d Y H:i:s')) - strtotime(gmdate('M d Y H:i:s'))) / 3600);
  180. echo '<p>'.i18n::s('Server GMT offset:').' UTC '.(($offset > 0) ? "+" : "").$offset.' '.i18n::s('hour(s)').' ('.date('Y-M-d H:i:s').")</p>\n";
  181. // run-time information
  182. if(Surfer::is_associate()) {
  183. echo '<p>';
  184. // current directory
  185. if(is_callable('getcwd'))
  186. echo 'getcwd()='.getcwd().BR."\n";
  187. // PHP SAPI name
  188. if(is_callable('php_sapi_name'))
  189. echo 'php_sapi_name()='.php_sapi_name().BR."\n";
  190. echo "</p>\n";
  191. }
  192. // do not reveal names of accounts used on server side
  193. if(Surfer::is_associate() && !file_exists($context['path_to_root'].'parameters/demo.flag')) {
  194. // user/group of this script
  195. if(is_callable('getmyuid') && (($uid = getmyuid()) !== FALSE) && is_callable('getmygid') && (($gid = getmygid()) !== FALSE)) {
  196. // describe user
  197. $ulabel = $uid;
  198. if(is_callable('posix_getpwuid') && (($uinfo = posix_getpwuid($uid)) !== FALSE)) {
  199. if(isset($uinfo['name']))
  200. $ulabel = $uinfo['name'].'['.$uid.']';
  201. }
  202. // describe group and members
  203. $glabel = $gid;
  204. if(is_callable('posix_getgrgid') && (($ginfo = posix_getgrgid($gid)) !== FALSE)) {
  205. // group name
  206. if(isset($ginfo['name']))
  207. $glabel = $ginfo['name'].'['.$gid.']';
  208. // group members
  209. if(isset($ginfo['members']) && is_array($ginfo['members'])) {
  210. $gmembers = array();
  211. foreach($ginfo['members'] as $index => $label)
  212. $gmembers[] = $label;
  213. if(count($gmembers))
  214. $glabel .= ' ('.implode(', ', $gmembers).')';
  215. }
  216. }
  217. // display gathered information
  218. echo '<p>'.i18n::s('user/group of this script:').' '.$ulabel.'/'.$glabel."</p>\n";
  219. } else
  220. echo '<p>'.i18n::s('Impossible to retrieve user/group of this script.')."</p>\n";
  221. // user/group of this process
  222. if(is_callable('posix_geteuid') && (($uid = posix_geteuid()) !== FALSE) && is_callable('posix_getgroups') && (($gids = posix_getgroups()) !== FALSE)) {
  223. // describe user
  224. $ulabel = $uid;
  225. if(is_callable('posix_getpwuid') && (($uinfo = posix_getpwuid($uid)) !== FALSE)) {
  226. if(isset($uinfo['name']))
  227. $ulabel = $uinfo['name'].'['.$uid.']';
  228. }
  229. // describe groups
  230. $glabel = '';
  231. foreach($gids as $gid) {
  232. // group name
  233. if(is_callable('posix_getgrgid') && (($ginfo = posix_getgrgid($gid)) !== FALSE) && isset($ginfo['name']))
  234. $glabel .= $ginfo['name'].'['.$gid.']';
  235. else
  236. $glabel .= $gid;
  237. // next one
  238. $glabel .= ' ';
  239. }
  240. // display gathered information
  241. echo '<p>'.i18n::s('user/group of this process:').' '.$ulabel.'/'.$glabel."</p>\n";
  242. } else
  243. echo '<p>'.i18n::s('Impossible to retrieve user/group of this process.')."</p>\n";
  244. }
  245. // end of the page
  246. echo '</body>'."\n"
  247. .'</html>';
  248. ?>