#!/usr/bin/perl

use CGI;
use DBI;
use strict;
unshift(@INC, '.');
use ipac_cfg;

my $q = new CGI;
my $path="https://" . $q->server_name();
my $cgi=$path . "/cgi-bin";             
my $ip = "0";
my $net_id = "0";
my $dbh;
my $sth;
my $user = $ENV{REMOTE_USER};

if ($ENV{HTTPS} ne "on" || $user ne "admin") {
    print $q->header(-type=>"text/html;", -status=>'403 Forbidden'),
	    $q->start_html('Forbidden'),
	    $q->h1('You dont have permission to access this script'),
	    $q->end_html;
    exit;
}

if (($q->param('ip') ne "") && ($q->param('net') ne "")) {
	$ip = $q->param('ip');
	$net_id = $q->param('net');
} else {
	exit;
}

my $dbh = DBI->connect("dbi:Pg:dbname=$ipac_cfg::pg_dbname",
                        $ipac_cfg::pg_login, $ipac_cfg::pg_pwd,
                             { RaiseError => 1, AutoCommit => 0 });
			     
$dbh->do(q{delete from nets where ip_net=? and net_id=?}, undef, 
				$ip, $net_id) or die $dbh->errstr;
$dbh->commit();
$dbh->disconnect  or warn $dbh->errstr;

reconfig();

print $q->header(-Refresh=>"1; URL=$cgi/br_net?net=$net_id") ;
print $q->end_html;
