#!/usr/bin/perl
# #############################################################
# Script PERL de configuration du Firewall Apache
# Projet Internet 98
# par Maxime Legas et Lionel Dousse
# #############################################################
# Ce script permet d'editer de maniere interactive le fichier de 
# configuration du firewall.
# Format du fichier : URL NB_MAX_ACCESS MAX_TIME_INTERVAL
# il est toujours possible d'editer le fichier soi meme bien sur !
# ce script utilise firewall_update.cgi pour mettre a jour les infos

use CGI;
$q = new CGI;

# ou se trouve le fichier de conf
# change this line !
# don't forget to change same line in firewall_update.cgi !
$ficconf="../conf/urls";

print $q->header;
print $q->start_html(-title=>'Firewall Configuration');

open(IN,$ficconf);

print "<h1>Firewall configuration</h1><HR>\n";
print "This script is a way to edit configuration file through the web, but you can still edit it by yourself !<br>\n";
print "Check <a href=\"/Firewall\">Firewall Status (handler)</a> to see if it is done.<br>";
print "Configuration file is : $ficconf<br>\n";
print "File format is : url max_number_access time_interval<br>\n";

print "<P>Here are the URL which are protected : <br>\n";
print "<form method=\"POST\" action=\"firewall_update.cgi\"><OL>\n";
$i=0;
while ($ligne=<IN>)
{
    $ligne =~ m/(.*) (.*) (.*)/;
    print "<LI><input type=\"text\" size=30 name=\"url$i\" value=\"$1\">";
    print " <input type=\"text\" size=4 name=\"nbmax$i\" value=\"$2\">";
    print " <input type=\"text\" size=4 name=\"maxtime$i\" value=\"$3\">";
    print " <input type=\"checkbox\" name=\"check$i\" checked=\"true\">";
    print " unckeck it to delete !\n";
    print "<BR>";
    $i++;
}
close IN;
print "<P>Here you can add some : <br>\n";
$k=$i;
foreach($i..($i+3))
{
    print "<LI><input type=\"text\" size=30 name=\"url$k\" value=\"\">";
    print " <input type=\"text\" size=4 name=\"nbmax$k\" value=\"\">";
    print " <input type=\"text\" size=4 name=\"maxtime$k\" value=\"\">";
    print " <input type=\"checkbox\" name=\"check$k\" checked=\"true\">";
    print "<BR>";  
    $k++;
}
print "</OL><P><input type=\"submit\" value=\"Update the file and restart Apache\">";
print " <input type=\"reset\" value=\"Reset to file values\">";
print "<br> <strong> When you update you will get a <i>document contains no data !</i></strong> which is normal because of server restart.\n";
print "<HR> Firewall Configuration comes with module mod_firewall.c <br>by Maxime Legas and Lionel Dousse, see <a href=\"mod_firewall.html\">help file</a> for more information";
print "</body></html>";




