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

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