Apache-DnsZone

 view release on metacpan or  search on metacpan

lib/Apache/DnsZone.pm  view on Meta::CPAN

package Apache::DnsZone;

# $Id: DnsZone.pm,v 1.41 2001/06/26 19:58:04 thomas Exp $

use strict;
use Exporter;
use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS @ISA);

@ISA = qw(Exporter);
@EXPORT = qw();
@EXPORT_OK = qw(Debug);
%EXPORT_TAGS = ();
$VERSION = '0.2';

use Apache ();
use Apache::Constants qw(:common REDIRECT);
use Apache::Request ();
use Apache::DnsZone::Config;
use Apache::DnsZone::Resolver;
use Apache::DnsZone::DB;
use Apache::DnsZone::Language;
use Apache::DnsZone::AuthCookie;
use Net::DNS;
use Net::IP qw(:PROC);
use HTML::Entities;
use Email::Valid;
use CGI::FastTemplate;
use Data::Dumper;

my %lang = ();
my $cfg;
my $res;
my $dbh;
my $apr;
my $DebugLevel = 1;

sub init {
    my $r = shift || Apache->request();
    $cfg = Apache::DnsZone::Config->new($r);
    $res = Apache::DnsZone::Resolver->new();
    $dbh = Apache::DnsZone::DB->new($cfg);
    $apr = Apache::Request->instance($r, DISABLE_UPLOADS => 1, POST_MAX => 1024);
    my $status = $apr->parse;
    if ($status) {
	my $errmsg = $apr->notes("error-notes");
	Debug(1, qq{Apache::Request error: $errmsg});
	return $status;
    }
}

sub Debug {
    my $level = shift;
    if ($level <= $Apache::DnsZone::DebugLevel) {
	if ($_[-1] !~ /\n$/) {
	    warn("[DnsZone]: ", @_, "\n");
	} else {
	    warn("[DnsZone]: ", @_);
	}
    }
}

sub lang {
    my $lang = shift;
    return Apache::DnsZone::Language->fetch($cfg, $lang);
}

sub apr {
    return $apr;
}

sub cfg {
    return $cfg->{'cfg'};
}

###############################################
# check_ip(ip)                                #
# Checks ip for a valid ip address for a host #
# returns 0 on anything else than valid ip    #
###############################################

# might be swithced out with some of Net::IP's functions
sub check_ip ($) {
    my $ip = shift;
    Debug(5, qq{check_ip($ip)});
    if ($ip =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) {
        return 0 unless ($1 >= 1 && $1 <= 254 && $2 >= 0 && $2 <= 255 && $3 >= 0 && $3 <= 255 && $4 >= 1 && $4 <= 254);
        # By using int on the values we make sure that the user can't enter data that will corrupt the database. 
        # IP addresses like 001.001.001.001 are avoided and will only show 1.1.1.1



( run in 1.744 second using v1.01-cache-2.11-cpan-98e64b0badf )