Uma vez executado, ele pede para que crie um login e uma senha, estes dados que somente você saberá serão encriptados e salvos em um arquivo de texto.
Eis o script:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
$pwd = "password.txt"; # Arquivo onde o Login e a Senha serão salvos
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@conteudo = split(/&/, $buffer);
foreach $par (@conteudo) {
($campo, $valor) = split(/=/, $par);
$valor =~ tr/+/ /;
$valor =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$CAMPO{$campo} = $valor;
}
sub conteudo {print qq~
<!-- AQUI VOCÊ COLOCA O CONTEUDO PROTEGIDO //-->
<!-- AQUI VOCÊ COLOCA O CONTEUDO PROTEGIDO //-->
~;}
$qs = "$ENV{QUERY_STRING}";
if ($qs eq "") {if (-e $pwd){&login;}else{&cadastro;}}
if ($qs eq "cadastra"){&cadastrar;}
if ($qs eq "login") {&logar;}
sub cadastrar{
$senha = substr(crypt($CAMPO{senha},substr($CAMPO{senha},0,2)),2);
open (PWD,">$pwd");
print PWD "$CAMPO{login}\n$senha";
close(PWD);
print qq|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Secure Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.texto {font-family:Sans-serif; font-size:8pt;}
.bold {font-weight:bold; font-family:Sans-serif; font-size:8pt}
INPUT {font-weight:bold; font-family:Verdana; font-size:9pt}
.tabela {background-repeat:no-repeat; padding:10pt; }
TEXTAREA {font-weight:bold; font-family:Verdana; font-size:9pt; overflow:auto;}
A {font-family:Sans-serif; font-size:8pt; color:555555; text-decoration:none}
A:hover {font-family:Sans-serif; font-size:8pt; color:99999; text-decoration:none}
</style>
</head>
<body leftmargin="3" topmargin="3" marginwidth="3" marginheight="3">
<table width="80%" align="center" cellspacing="2" class="texto">
<tr>
<td width="100%" bgcolor="#006600"><div align="center" class="bold"><font color="#FFFFFF">True
Login </font></div></td>
</tr>
<tr>
<td class="tabela">Parabéns <font class="bold">$CAMPO{login}</font>,
o password foi setado corretamente.<a href="?">Clique aqui para voltar
à tela de login.</a></td>
</tr>
</table>
</body>
</html>
|;}
sub cadastro{
print qq|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Secure Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.texto {font-family:Sans-serif; font-size:8pt;}
.bold {font-weight:bold; font-family:Sans-serif; font-size:8pt}
INPUT {font-weight:bold; font-family:Verdana; font-size:9pt}
.tabela {background-repeat:no-repeat; padding:10pt; }
TEXTAREA {font-weight:bold; font-family:Verdana; font-size:9pt; overflow:auto;}
A {font-family:Sans-serif; font-size:8pt; color:555555; text-decoration:none}
A:hover {font-family:Sans-serif; font-size:8pt; color:99999; text-decoration:none}
</style>
</head>
<body leftmargin="3" topmargin="3" marginwidth="3" marginheight="3">
<table width="80%" align="center" cellspacing="2" class="texto">
<tr>
<td width="100%" bgcolor="#006600"><div align="center" class="bold"><font color="#FFFFFF">Secure Admin </font></div></td>
</tr>
<tr>
<td class="tabela">
Atenção! Só se cadastre caso você for o administrador do site.<br>
<form name="form1" method="post" action="?cadastra">
<table width="100%" class="bold">
<tr>
<td width="51%"><div align="right">Login:</div></td>
<td width="49%"><input name="login" type="text" id="login"></td>
</tr>
<tr>
<td><div align="right">Senha:</div></td>
<td><input name="senha" type="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td width="50%"> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Cadastrar">
</div></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
|;}
sub logar{
open(PWD,"$pwd");
@pwd = <PWD>;
close(PWD);
$senha = substr(crypt($CAMPO{senha},substr($CAMPO{senha},0,2)),2);
foreach (@pwd){chomp;}
if($CAMPO{login} eq "$pwd[0]"){
if ($senha eq "$pwd[1]"){
&conteudo;
}else{
print qq|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Secure Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.texto {font-family:Sans-serif; font-size:8pt;}
.bold {font-weight:bold; font-family:Sans-serif; font-size:8pt}
INPUT {font-weight:bold; font-family:Verdana; font-size:9pt}
.tabela {background-repeat:no-repeat; padding:10pt; }
TEXTAREA {font-weight:bold; font-family:Verdana; font-size:9pt; overflow:auto;}
A {font-family:Sans-serif; font-size:8pt; color:555555; text-decoration:none}
A:hover {font-family:Sans-serif; font-size:8pt; color:99999; text-decoration:none}
</style>
</head>
<body leftmargin="3" topmargin="3" marginwidth="3" marginheight="3">
<table width="80%" align="center" cellspacing="2" class="texto">
<tr>
<td width="100%" bgcolor="#006600"><div align="center" class="bold"><font color="#FFFFFF">Secure Admin </font></div></td>
</tr>
<tr>
<td class="tabela"> Desculpe <font class="bold">$CAMPO{login}</font>, mas
esta não é a senha correta. <br>
Volte e tente novamente. <br>
<br>
<input type="button" name="Button" value="Voltar" onClick="self.location.href('java script:history.go(-1)')"> </td>
</tr>
</table>
</body>
</html>
|;}
}else{
print qq|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Secure Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.texto {font-family:Sans-serif; font-size:8pt;}
.bold {font-weight:bold; font-family:Sans-serif; font-size:8pt}
INPUT {font-weight:bold; font-family:Verdana; font-size:9pt}
.tabela {background-repeat:no-repeat; padding:10pt; }
TEXTAREA {font-weight:bold; font-family:Verdana; font-size:9pt; overflow:auto;}
A {font-family:Sans-serif; font-size:8pt; color:555555; text-decoration:none}
A:hover {font-family:Sans-serif; font-size:8pt; color:99999; text-decoration:none}
</style>
</head>
<body leftmargin="3" topmargin="3" marginwidth="3" marginheight="3">
<table width="80%" align="center" cellspacing="2" class="texto">
<tr>
<td width="100%" bgcolor="#006600"><div align="center" class="bold"><font color="#FFFFFF">Secure Admin </font></div></td>
</tr>
<tr>
<td class="tabela">
Desculpe <font class="bold">$CAMPO{login}</font>, mas este não é o login correto.
<br>Volte e tente novamente. <br>
<br>
<input type="button" name="Button" value="Voltar" onClick="self.location.href('java script:history.go(-1)')"> </td>
</tr>
</table>
</body>
</html>
|;}
}
sub login{
print qq|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Secure Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.texto {font-family:Sans-serif; font-size:8pt;}
.bold {font-weight:bold; font-family:Sans-serif; font-size:8pt}
INPUT {font-weight:bold; font-family:Verdana; font-size:9pt}
.tabela {background-repeat:no-repeat; padding:10pt; }
TEXTAREA {font-weight:bold; font-family:Verdana; font-size:9pt; overflow:auto;}
A {font-family:Sans-serif; font-size:8pt; color:555555; text-decoration:none}
A:hover {font-family:Sans-serif; font-size:8pt; color:99999; text-decoration:none}
</style>
</head>
<body leftmargin="3" topmargin="3" marginwidth="3" marginheight="3">
<font class="texto">Você acessou uma área restrita. Faça o login para prosseguir.</font>
<table width="80%" align="center" cellspacing="2" class="texto">
<tr>
<td width="100%" bgcolor="#006600"><div align="center" class="bold"><font color="#FFFFFF">Secure Admin </font></div></td>
</tr>
<tr>
<td class="tabela"><form name="form1" method="post" action="?login">
<br>
<table width="100%" class="bold">
<tr>
<td width="51%"><div align="right">Login:</div></td>
<td width="49%"><input name="login" type="text" id="login"></td>
</tr>
<tr>
<td><div align="right">Senha:</div></td>
<td><input name="senha" type="password" id="senha"></td>
</tr>
<tr>
<td> </td>
<td width="50%"> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Login">
</div></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
|;
}