head     1.1;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @# @;


1.1
date     95.03.07.14.17.29;  author yonah;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@#!/usr/athena/bin/perl

print("Content-Type: text/html\n\n");

$query = $ENV{'QUERY_STRING'};
&do_coolthing($query);

sub do_coolthing {
	local($request) = @@_;

	print($request,"\n");
	if($ENV{'REMOTE_ADDR'} !~/^18\./){
		print("Sorry, you are only allowed to add to this list from MIT\n");
		print `cat /var/local/www/root/cool/cool-list.html`;
		return;
   	 }


	$request =~ y/\+/ /;
#	print("Yech, request is<p>\"$request\"\n");
	$request =~ /url\=([^\&]+)\&title\=([^\&]+)\&desc\=([^\&]+)/;
	$url = $1;
	$title = $2;
	$desc = $3;
	$url =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; # remove % escapes
	$title =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; # remove % escapes
	$desc =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; # remove % escapes

	if($url =~ /http:\/\/([^\/]+)\//i){
		$site = $1;
		$tail = $';
		if($1 !~/www\.mit\.edu:8001/i){
			print("<h1>Refused</h1>\n");
			print("Please only point to urls via www.mit.edu:8001\n");
			print("<p>If you would like <em>$site</em> added to the <a href=\"other-servers.html\">list of servers at MIT</a>, please <a href=\"comment\">mail webmaster@@mit.edu</a>\n") if $site=~/mit.edu/i;
			return;
		}
		else{
			$url = $tail;
		}
	}

	if($url eq ''){
		print("<h1>Refused</h1>\n");
		print("No blank URLs!\n");
		return;
	}

	if(!-e "/var/local/www/root/$url"){
		print("<h1>Refused</h1>\n");
		print("That doesn't exist!\n");
		return;
	}
	

	if($url=~ /<img/i || $title =~ /<img/i || $desc =~/<img/i){
		print("<h1>Refused</h1>\n");
		print("Please do not put inlined images in listings\n");
	return;
	}

	$file='';
	open(FILE, "/var/local/www/root/cool/cool-list.html");
	while(<FILE>){$file.=$_;}
	unlink("/var/local/www/root/cool/cool-list.html");

	open(FILE, ">>/var/local/www/root/cool/cool-list.html") || print("Can't create cool list\n");
	chop($date = `date`);
	print(FILE "<hr><em>$date</em><p><dl>\n");
	print(FILE "<dt><a href=\"$url\">$title</a>\n<dd>\n$desc</dl>");
	print(FILE $file);
	close(FILE);
	
	print("<hr><dl>\n");
	print("<dt><a href=\"$url\">$title</a>\n<dd>$desc</dl>");
	print("<hr>\n");

	print("<h1>Added!</h1>\n");
	print("<a href=\"cool-list.html\">The list so far</a>\n");
}

1;
@
