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.2 2008/09/24 12:34:44 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.         'E:\Works\Projets-DEV\phpdebug\\',
  25.         '/var/www-protected/php-debug.com/www/',
  26.     )
  27. );
  28.  
  29. // Files that are allowed to be viewed
  30. $pathPattern '/^{$path}(.*)(.php)$/';
  31.  
  32. // Additional include path for Pear (to adapt to your configuration )
  33. //set_include_path($options['PEAR_ROOT'] . PATH_SEPARATOR. get_include_path());
  34. // End //
  35.  
  36. //Include Pear 
  37. require_once 'PEAR.php';
  38.  
  39. //Include Debug_Renderer_HTML_Table_Config to get the configuration
  40. require_once 'PHP/Debug.php';
  41. require_once 'PHP/Debug/Renderer/HTML/TableConfig.php';
  42. $options PHP_Debug_Renderer_HTML_TableConfig::singleton()->getConfig();
  43.  
  44. //Include the class definition of highlighter
  45. require_once 'Text/Highlighter.php';
  46. require_once 'Text/Highlighter/Renderer/Html.php';
  47.  
  48. /**
  49.  * Security test
  50.  */
  51. function isPathAllowed($file{
  52.  
  53.     global $view_source_options$pathPattern;
  54.     $allowed = false;
  55.  
  56.     $file get_magic_quotes_gpc(stripslashes($file$file;
  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_magic_quotes_gpc(stripslashes($_GET['file']$_GET['file']).'
  122.             </span>
  123.         </div>';
  124.         echo $phpHighlighter->highlight(file_get_contents((get_magic_quotes_gpc(stripslashes($_GET['file']$_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:28:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.