Приглашаем посетить
Дельвиг (delvig.lit-info.ru)

ICheck

#!/usr/bin/perl
# ICheck v.1.0 written by Dave Palmer <dave@upstatepress.com>
# http://upstatepress.com/dave/perl.shtml
###############################################################
# ICheck allows you to "protect" a directory, without editing
# your .htaccess file. Of course this isn't as secure as editing
# your .htaccess file, but for those who don't want just want
# a bit of security, or just want people to register themselves
# before gaining access to a site, this is the script for that 
# job! You can also choose to leave out the "register as a new
# user" on the form if you do not want to allow just anyone to
# register. Its up to you!!
###############################################################

# Location of your data.txt file. This file stores your registered
# users. This should be chmod to 777 Same with the directory: icheck
$datafile = "/u3/home/upstate/public_html/icheck/data.txt";

# Once the user is registered, this is the location of the "secured"
# site.
$location = "http://www.upstatepress.com/icheck/secure.html";

################################################################

read(STDIN, $input, $ENV{'CONTENT_LENGTH'});

	@pairs = split(/&/, $input);
	foreach $pair (@pairs) {
	($name, $value) = split(/=/, $pair);
	
	$name =~ tr/+/ /;
	$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	$value =~ tr/+/ /;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

   $FORM{$name} = $value;
		}
$usrname = $FORM{'usrname'};
$email = $FORM{'email'};
$action = $FORM{'action'};

if($action eq "register") {
	®ister;
		}

	else {
	  &admit;
    		}

sub admit {
open(FILE, "$datafile") || die "I can't\n";	

	while(<FILE>) {
	chop;		
	@all = split(/\n/);

	foreach $line (@all) {
	($loginname, $loginemail) = split(/&&/, $line);

	if($loginname eq "$usrname" && $loginemail eq "$email") {
		$match = 1;
		&relocate;
			   }
		}
	
      }
	
close(FILE);

		if (! $match) {
		&error;
	        	}

	}

sub register {
open(FILE, ">>$datafile") || die "Nope\n";
print FILE "$usrname&&$email\n";
close(FILE);

print "Content-type: text/html\n\n";
print "<html><head><title>Thanks! $usrname!</title></head>\n";
print "<body>\n";
print "<p><h1>Thanks $usrname</p></h1>\n";
print "You have been registered. You may now go back and enter <b>$usrname\n";
print "</b> and <b>$email</b> to gain access to this site\n";
print "</body></html>\n";
	}

sub relocate {
print "Location: $location\n\n";
	}

sub error {
print "Content-type: text/html\n\n";
print "<html><head><title>Error</title></head>\n";
print "<body>\n";
print "<p><h1>Error</p></h1>\n";
print "You do not have access to this site\n";
print "</body></html>\n";
exit;
		}