PHP_Debug
[ class tree: PHP_Debug ] [ index: PHP_Debug ] [ all elements ]

Source for file PHP_Debug_ShowSource.php

Documentation is available at PHP_Debug_ShowSource.php

  1. <?php
  2.  
  3. /**
  4.  * This an exemple of showsource file
  5.  * 
  6.  * It uses the Pear package TEXT_Highlighter
  7.  * 
  8.  * /!\ Don't forget to securise this script /!\
  9.  *   - By Ip
  10.  *   - By allowed path (as the isAllowedPath() function below)
  11.  * 
  12.  * @package PHP_Debug
  13.  * @since V2.0.0 - 26 apr 2006
  14.  * @filesource
  15.  */
  16.  
  17.  
  18. // View source configuration (to modify with your settings)
  19. $view_source_options = array(
  20.     'PEAR_ROOT' => 'W:/var/www/php/PEAR',
  21.     'CSS_ROOT' => 'css',
  22.     'ALLOWED_PATH' => array(
  23.         'W:\var\www\html\phpdebug\\',
  24.         'W:\var\www\html\phpdebugweb\\',
  25.         'E:\Works\Projets-DEV\phpdebug\\',
  26.         '/home.10.3/autonet/www/phpdebug/web/',
  27.         '/home/phpdebug/',
  28.     )
  29. );
  30.  
  31. // Files that are allowed to be viewed
  32. $pathPattern '/^{$path}(.*)(.php)$/';
  33.  
  34. // Additional include path for Pear (to adapt to your configuration )
  35. //set_include_path($options['PEAR_ROOT'] . PATH_SEPARATOR. get_include_path());
  36. // End //
  37.  
  38. //Include Pear 
  39. require_once 'PEAR.php';
  40.  
  41. //Include Debug_Renderer_HTML_Table_Config to get the configuration
  42. require_once 'PHP/Debug.php';
  43. require_once 'PHP/Debug/Renderer/HTML/TableConfig.php';
  44. $options PHP_Debug_Renderer_HTML_TableConfig::singleton()->getConfig();
  45.  
  46. //Include the class definition of highlighter
  47. require_once 'Text/Highlighter.php';
  48. require_once 'Text/Highlighter/Renderer/Html.php';
  49.  
  50. /**
  51.  * Security test
  52.  */
  53. function isPathAllowed($file{
  54.  
  55.     global $view_source_options$pathPattern;
  56.     $allowed = false;
  57.  
  58.     foreach ($view_source_options['ALLOWED_PATH'as $path{
  59.         $pattern str_replace(
  60.             '{$path}'
  61.             regPath(preg_quote($path))
  62.             $pathPattern
  63.         );
  64.         if (preg_match($pattern$file)) {
  65.             $allowed = true;
  66.         }
  67.     }
  68.     return $allowed;
  69. }
  70.  
  71. // Add your ip restriction here
  72. function isIpAllowed({
  73.     return true;
  74. }
  75.  
  76. // Transform path for regex
  77. function regPath($path{
  78.     return str_replace(
  79.         array(
  80.             '/',
  81.             '-',
  82.         ),
  83.         array(
  84.             '\/',
  85.             '\-',
  86.         ),
  87.         $path
  88.     );
  89. }
  90.  
  91. // Build the array options for the HTML renderer to get the nice file numbering
  92. $rendOptions = array
  93.     'numbers' => $options['HTML_TABLE_view_source_numbers'],
  94.     'tabsize' => $options['HTML_TABLE_view_source_tabsize'],
  95. );
  96.  
  97.  
  98. // Finish parser object creation 
  99. $renderer = new Text_Highlighter_Renderer_Html($rendOptions);
  100. $phpHighlighter = Text_Highlighter::factory('PHP');
  101. $phpHighlighter->setRenderer($renderer);
  102.  
  103. // Now start output, header
  104. $header str_replace(
  105.     '<title>PEAR::PHP_Debug</title>'
  106.     '<title>PEAR::PHP_Debug::View_Source::'$_GET['file']'</title>'
  107.     $options['HTML_TABLE_simple_header']);
  108. echo $header;
  109. echo '
  110.     <link rel="stylesheet" type="text/css" media="screen" href="'$view_source_options['CSS_ROOT'.'/view_source.css" />
  111.   </head>
  112.   <body>
  113. ';
  114.  
  115. // Security check
  116. if (isPathAllowed($_GET['file']&& isIpAllowed()) {
  117.     if(file_exists($_GET['file'])) 
  118.         echo
  119.         '<div>
  120.             <span class="hl-title">'.
  121.                 $_GET['file'].'
  122.             </span>
  123.         </div>';
  124.         echo $phpHighlighter->highlight(file_get_contents($_GET['file']));
  125.     else {
  126.         echo '<h2>File does not exists</h2>';
  127.     }
  128. else {
  129.     echo '<h1>Sorry, your are not allowed to access this path</h1>';
  130. }
  131.  
  132. // Footer
  133. echo $options['HTML_TABLE_simple_footer'];

Documentation generated on Mon, 11 Mar 2019 15:14:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.