cvs: phpweb / source.php
| From: | Gabor Hojtsy | Date: | Sun, 03 Aug 2003 15:51:25 +0000 |
| Subject: | cvs: phpweb / source.php | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-19784@lists.php.net to get a copy of this message | ||
goba Sun Aug 3 11:51:25 2003 EDT
Modified files:
/phpweb source.php
Log:
Update the source display code to use the new include
methods, to have a page base name. Also update the url
check code to use _GET, and better check for file names
Index: phpweb/source.php
diff -u phpweb/source.php:1.16 phpweb/source.php:1.17
--- phpweb/source.php:1.16 Tue Jun 10 06:21:52 2003
+++ phpweb/source.php Sun Aug 3 11:51:25 2003
@@ -1,66 +1,81 @@
<?php
-require_once 'prepend.inc';
+// $Id: source.php,v 1.17 2003/08/03 15:51:25 goba Exp $
+$_SERVER['BASE_PAGE'] = 'source.php';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
$SIDEBAR_DATA = '
<p>
-The syntax highlighted source is automatically generated by PHP from
-the plaintext script.<br /><br />
+ The syntax highlighted source is automatically generated by PHP from
+ the plaintext script.
+</p>
-If you\'re interested in what\'s behind the several functions we
-used, you can always take a look at the source of the<br />
- ' . make_link("/source.php?url=/include/prepend.inc",
"prepend.inc") . ',<br />
- ' . make_link("/source.php?url=/include/site.inc", "site.inc")
. ',<br />
- ' . make_link("/source.php?url=/include/layout.inc",
"layout.inc") . ',<br />
- ' . make_link("/source.php?url=/include/shared-manual.inc",
"shared-manual.inc") . ' and<br />
- ' . make_link("/source.php?url=/include/manual-lookup.inc",
"manual-lookup.inc") . '<br />
-files.<br /><br />
-
-Of course, if you want to see the source of this page, have a look ' .
-make_link("/source.php?url=/source.php", "here") . '.
-You can also browse the cvs repository for this website ' .
-make_link("http://cvs.php.net/cvs.php/phpweb/",
"here") . '.
+<p>
+ If you\'re interested in what\'s behind the several functions we
+ used, you can always take a look at the source of the
+ <ul>
+ <li><a
href="/source.php?url=/include/prepend.inc">prepend.inc</a></li>
+ <li><a
href="/source.php?url=/include/site.inc">site.inc</a></li>
+ <li><a
href="/source.php?url=/include/mirrors.inc">mirrors.inc</a></li>
+ <li><a
href="/source.php?url=/include/countries.inc">countries.inc</a></li>
+ <li><a
href="/source.php?url=/include/languages.inc">languages.inc</a></li>
+ <li><a
href="/source.php?url=/include/langchooser.inc">langchooser.inc</a></li>
+ <li><a
href="/source.php?url=/include/ip-to-country.inc">ip-to-country.inc</a></li>
+ <li><a
href="/source.php?url=/include/layout.inc">layout.inc</a></li>
+ <li><a
href="/source.php?url=/include/last_updated.inc">last_updated.inc</a></li>
+ <li><a
href="/source.php?url=/include/shared-manual.inc">shared-manual.inc</a></li>
+ <li><a
href="/source.php?url=/include/manual-lookup.inc">manual-lookup.inc</a></li>
+ </ul>
+ files.
+</p>
+
+<p>
+ Of course, if you want to see the source of this page, have a look
+ <a href="/source.php?url=/source.php">here</a>.
+ You can also browse the cvs repository for this website on
+ <a href="http://cvs.php.net/cvs.php/phpweb/">cvs.php.net</a>.
</p>
';
commonHeader("Show Source");
-if (!isset($url)) {
- echo "No page URL specified.";
+// No file param specified
+if (!isset($_GET['url'])) {
+ echo "<h1>No page URL specified</h1>";
commonFooter();
exit;
}
-echo "<h1>Source of: ", htmlentities($url), "</h1>", hdelim();
+echo "<h1>Source of: ", htmlentities($_GET['url']),
"</h1>", hdelim();
-$legal_dirs = array(
- "/manual" => 1,
- "/include" => 1,
- "/stats" => 1,
- "/error" => 1
-);
-
-$dir = $url ? dirname($url) : "";
-
-// The separate manual language dirs are legal dirs
-if (preg_match("!^/manual/(en|pt_BR|cs|nl|fr|de|hu|it|ja|kr|es)$!", $dir) ||
isset($legal_dirs[$dir])) {
- $legal_dir = TRUE;
-} else { $legal_dir = FALSE; }
-
-// If this is a legal dir, then it is under the docroot, else use basename
-if ($dir && $legal_dir) {
- $page_name = $DOCUMENT_ROOT . $url;
+// Get dirname of the specified URL part
+$dir = dirname($_GET['url']);
+
+// Some dir was present in the filename
+if (!empty($dir) && !preg_match("!^(\\.|/)$!", $dir)) {
+
+ // Check if the specified dir is valid
+ $legal_dirs = array(
+ "/manual" => 1,
+ "/include" => 1,
+ "/stats" => 1,
+ "/error" => 1,
+ "/license" => 1
+ );
+ if (preg_match("!^/manual/$!", $dir) || isset($legal_dirs[$dir])) {
+ $page_name = $_SERVER['DOCUMENT_ROOT'] . $_GET['url'];
+ } else { $page_name = FALSE; }
} else {
- $page_name = basename($url);
+ $page_name = $_SERVER['DOCUMENT_ROOT'] . '/' .
basename($_GET['url']);
}
echo "<!-- ", htmlentities($page_name), " -->\n";
-if (file_exists($page_name) && !is_dir($page_name)) {
- show_source($page_name);
-} else if (@is_dir($page_name)) {
- echo "<p>No file specified. Can't show source for a
directory.</p>\n";
-}
-else {
+// Provide some feedback based on the file found
+if (!$page_name || @is_dir($page_name)) {
+ echo "<p>Invalid file or folder specified</p>\n";
+} elseif (file_exists($page_name)) {
+ highlight_php(join("", file($page_name)));
+} else {
echo "<p>This file does not exist.</p>\n";
}