// -*- c++ -*-
//
// This file will show a given source (.cc, .h., etc) file in MTL
// webness format. That is, given the argument $file to the URL, it
// will include() that file here with all the standard MTL web page
// stuff.
//
// An error will be displayed if:
//
// - $file is not specified
// - $file begins with / or . (don't want to grab arbitrary files)
//
// This file will determine if the file is being browsed from the main
// OSL web tree or from elsewhere. If the file is being browsed from
// the main OSL web tree, no prefix will be preprended to $file
// (because subdirectories like devel/examples and devel/test are
// directly in the current directory [as "examples" and "test" --
// "devel" is not there]).
//
// If the file is being browsed from elsewhere, the prefix "../devel/"
// is prepended on to the $file so that developers can browse "in
// place" properly -- i.e., developers can have a different directory
// structure than the online web pages.
//
// This has been the topic of much debate for the last several months
// in the OSL -- trust us, it's the best way. There is really no way
// to reconcile having two different directory structures (in a
// developer's checked out CVS copy, and in the online web pages);
// having a smart browsing page that automagically remaps things is
// really the Best Way.
include('./defs.php3');
$dir_prefix = "";
// $dir_prefix = "../devel/"; seems wrong
$badness_title = "Oops!";
$badness = false;
$file = $_GET['file'];
if ($file == "") {
$badness = true;
$title = $badness_title;
} else if ($file[0] == "/") {
// Don't let malicious people steal /etc/passwd and the like
$badness = true;
$title = $badness_title;
} else {
// Check if .. is in the file anywhere
if (ereg("\.\.", $file)) {
$title = $badness_title;
$badness = true;
}
if (!$badness) {
// Determine if we're in the online OSL web pages tree, or if we're
// elsewhere.
$lsc_top = "/research/mtl/";
if (substr($_SERVER['REQUEST_URI'], 0, strlen($lsc_top)) != $lsc_top)
$file = $dir_prefix . $file;
// Ensure that the file exists.
if (file_exists($file)) {
$title = "Source code for " . basename($file) . "";
} else {
$badness = true;
$foo = basename($file);
$title = "$foo not found";
}
}
}
// If we're not showing the HTML, ensure that we're MIME type text/plain
if ($no_html)
header("Content-Type: text/plain");
// Start the document
if ($badness || !$no_html) {
head("The Matrix Template Library", urlencode($title));
begin_document();
left_column();
begin_main_column();
begin_section($title);
}
// Display the body
if ($badness) {
?>
Bummer! Something seems to be wrong here -- we didn't
get the filename to show you. Sorry...
// Stupid emacs mode: '
} else {
// Alles gut. Show the document.
if ($no_html) {
include($file);
} else {
print("Show this file without HTML\n");
print("
\n");
include($file);
print("\n");
}
}
// End the document
if ($badness || !isset($no_html)) {
end_subsection();
end_main_column();
end_document();
}