Home | History | Annotate | Download | only in android
      1 <?php
      2 # Copyright (C) 2010 The Android Open Source Project
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 # http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 
     16 ###############################################################################
     17 
     18 # Show the source of the test.
     19 #
     20 # Usage:
     21 #   view_source.php?src=PATH
     22 #   where
     23 #     PATH - relative path in the LayoutTests dir
     24 
     25   # Global variables
     26   # The server document root is LayoutTests/http/tests. See run_apache2.py.
     27   $rootDir = realpath($_SERVER['DOCUMENT_ROOT'] . '..' . DIRECTORY_SEPARATOR . '..');
     28 
     29   function getAbsolutePath($relPath) {
     30     global $rootDir;
     31     return $rootDir . DIRECTORY_SEPARATOR . $relPath;
     32   }
     33 
     34   function main() {
     35     global $rootDir;
     36 
     37     # Very primitive check if path tries to go above DOCUMENT_ROOT or is absolute
     38     if (strpos($_GET['src'], "..") !== False ||
     39         substr($_GET['src'], 0, 1) == DIRECTORY_SEPARATOR) {
     40       return;
     41     }
     42 
     43     # If we don't want realpath to append any prefixes we need to pass it an absolute path
     44     $src = realpath(getAbsolutePath($_GET['src']));
     45 
     46     echo "<html><body>";
     47     # TODO: Add link following and syntax highlighting for html and js.
     48     highlight_string(file_get_contents($src));
     49     echo "</body></html>";
     50   }
     51 
     52   main();
     53 ?>
     54