Location: PHPKode > projects > Open SoCks > 404.php3
<?
// Copyright (C) 2000-2002 C├ędric Raguenaud (hide@address.com) for Napier University

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// If you modify this file, please send me a copy.

/* Author: Cedric Raguenaud */
/* Version: 0.0.4 040202 */
/* 040202: added search in aliases first */

include_once("core.php3");

$dcs = "http://www.dcs.napier.ac.uk";
$soc = "http://www.soc.napier.ac.uk";
$napier = "http://www.napier.ac.uk";
$google = "http://www.google.com";
$localsearch = "http://www.soc.napier.ac.uk/cgi-bin/htsearch?words=";
$nothing = 0;
$good = "";
$bad = "";
$uri = $REQUEST_URI;
if ($request != "") {
	$uri = rawurldecode($request);
}

$db2 = new myDB($config["sqlserver"], $config["sqluser"], $config["sqlpassword"], $config["sqldatabase"]);
if ($db2) {
	$db2->setQuery("select redirection from aliases where name = '".addslashes(str_replace("/", "", $uri))."'");
	$r2 = $db2->executequery();
	if ($r2 >0) {
		if ($db2->hasMoreElements()) {
			$row2 = $db2->nextElement();
			header("Location: ".stripslashes($row2["redirection"]));
			die();
		}
	}
	$db2->close();
}

printTop();
print(manageLinks("<H1>Welcome to the 404 Wizard</H1>\n"));
print("<table>");
print("<tr><td><img src=\"".$config["httproot"]."getbinary.php3?src=wizard.jpg\"></td>");
print("<td>");
print(manageLinks("Hello, my name is <i>404</i>. The page you have requested has not been found on this server. Due to recent renovations, some pages that once were are not. And new pages that never were... are!<br><br>"));
$fp = fopen($localsearch.rawurlencode(str_replace("%20", "+", $uri)), 'r');
if(!$fp) {
	$bad .= " The local SoC search engine doesn't reply, there is something wrong, I can't help you there.";
	$bad .= "<br><br>\n";
} else {
	$line = "";
	$page = "";
	$visit = "";
	while (!feof($fp)) {
		$line = fgets($fp, 4096);
		$page .= $line."\n";
		if ($visit == "") {
			if (substr($line, 0, strlen("<dl><dt><strong>")) == "<dl><dt><strong>") {
				$visit = substr($line, 25, strpos($line, "\"", 26)-25);
			}
		}
	}
	fclose($fp);
	if ((eregi("No matches", $page)) || ($visit == "")) {
		$bad .= " I couldn't find anything relevant on this server for you.";
		$bad .= "<br><br>\n";
		$nothing++;
	} else {
		$good .= " On the <a href=\"".$soc."\">SoC</a> server, I found the following URL that you might find interesting: <a href=\"".$visit."\">".$visit."</a>.";
		$good .= "<br><br>\n";
	}
}
if (eregi("op/", $uri) || eregi("op=", $uri)) {
	$fp = fopen($dcs.$uri, 'r');
	if(!$fp) {
		$bad .= "I had a look at one possible location for your page: <a href=\"$dcs$uri\">$dcs$uri</a>.";
		$bad .= " By the look of it I don't think this URL could be over there.";
		$bad .= " When I tried it for you, I got another of my collegues telling me that that page is not there, so this is a dead end.";
		$bad .= "<br><br>\n";
		$nothing++;
	} else {
		$good .= "I had a look at one possible location for your page: <a href=\"$dcs$uri\">$dcs$uri</a>.";
		$good .= " By the look of it I don't think this URL could be over there.";
		$good .= " However, when I tried it for you, I got a positive reply, so you might want to have a look.";
		$good .= "<br><br>\n";
		fclose($fp);
	}
} else {
	$fp = fopen($dcs.$uri, 'r');
	if(!$fp) {
		$bad .= "I had a look at one possible location for your page: <a href=\"$dcs$uri\">$dcs$uri</a>.";
		$bad .= " When I tried it for you, I got another of my collegues telling me that that page is not there, so this is a dead end.";
		$bad .= "<br><br>\n";
		$nothing++;
	} else {
		$good .= "I had a look at one possible location for your page: <a href=\"$dcs$uri\">$dcs$uri</a>.";
		$good .= " When I tried it for you, I got a positive reply, so you might want to have a look.";
		$good .= "<br><br>\n";
		fclose($fp);
	}
}
if (eregi("/exchange", $uri)) {
	$good .= " My best guess would be to try this one: <a href=\"http://owa.napier.ac.uk/exchange\">http://owa.napier.ac.uk/exchange</a>.";
	$good .= "<br><br>\n";
	$nothing--;
}
$fp = fopen($dcs."/~".substr($uri, 1), 'r');
if(!$fp) {
	$bad .= "A possible location of what you're looking for would be: <a href=\"$dcs/~".substr($uri, 1)."\">$dcs/~".substr($uri, 1)."</a>.";
	$bad .= " But when I tried it for you, I got nowhere.";
	$bad .= "<br><br>\n";
	$nothing++;
} else {
	$good .= "A possible location of what you're looking for would be: <a href=\"$dcs/~".substr($uri, 1)."\">$dcs/~".substr($uri, 1)."</a>.";
	$good .= " That page seems to exist, you might want to have a look.";
	$good .= "<br><br>\n";
	fclose($fp);
}
$fp = fopen($napier.$uri, 'r');
if(!$fp) {
	$bad .= "On the main <a href=\"$napier\">Napier</a> server, ";
	$bad .= " I met one of my collegues when I tried <a href=\"$napier$uri\">$napier$uri</a> for you.";
	$bad .= "<br><br>\n";
	$nothing++;
} else {
	$good .= " <a href=\"$napier$uri\">$napier$uri</a> exists and might be what you are looking for.";
	$good .= "<br><br>\n";
	fclose($fp);
}
$fp = fopen($google."/search?lr=&safe=on&q=".rawurlencode(str_replace("%20", "+", $uri))."+Napier+University", 'r');
if(!$fp) {
	$bad .= " My friend <a href=\"$google\">Google</a> does not reply, there might be something wrong with my network connection.";
	$bad .= "<br><br>\n";
} else {
	$line = "";
	$page = "";
	$visit = "";
	while (!feof($fp)) {
		$line = fgets($fp, 4096);
		$page .= $line."\n";
		if ($visit == "") {
			if (substr($line, 0, strlen("<p><a href")) == "<p><a href") {
				$start = 11;
				$end = strpos($line, ">", 11)-$start;
				$visit = substr($line, $start, $end);
				if (substr($visit, 0, 1) == "/") {
					$visit = $google.$visit;
				}
			}
		}
	}
	fclose($fp);
	if ((eregi("did not match any documents", $page)) || ($visit == "")) {
		$bad .= " My friend <a href=\"$google\">Google</a> tells me that there is nothing relating to the university matching your search. Sorry, another dead end.";
		$bad .= "<br><br>\n";
		$nothing++;
	} else {
		$good .= " My friend <a href=\"$google\">Google</a> suggests that you visit <a href=\"".$visit."\">".$visit."</a>.";
		$good .= "<br><br>\n";
	}
}
if ($nothing == 5) {
	$bad .= "I have to say that you are particularly unlucky, I couldn't find anything for you.";
	$bad .= "<br><br>\n";
}
print("I tried to find it. Really, I tried hard. ");
if ($good != "") {
	print(manageLinks("I searched on many servers here and elsewhere, and here are the results of my search:<br><br>".$good));
} else {
	print(manageLinks("I'm sorry, I searched the page you are looking for on many serveurs, but couldn't find anything interesting. Even <a href=\"http://www.google.com\">Google</a> and the <a href=\"show.php3?op=show&page=Search\">local search</a> engine failed to produce results.<br><br>"));

}
/*
if ($bad != "") {
	print(manageLinks("<b>The bad news</b>:<br>".$bad));
}
*/
print(manageLinks("<b>What you might want to do next</b>:<br>"));
print(manageLinks("Plan B might be to search for the resource on your own on this server: <a href=\"show.php3?op=show&page=Search\">search</a>.<br><br>\n"));
print(manageLinks("If you're really, <b>really</b>, <b>REALLY</b> desperate and ready to cry, and if you're not afraid of disturbing God who's really busy right now, you might want to <a href=\"mailto:hide@address.com\">email the webmaster</a>.<br>\n"));
print("</td></tr>");
print("</table>");
printBottom();

?>
Return current item: Open SoCks