API-DirectAdmin

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

API-DirectAdmin
=======================

INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

DEPENDENCIES

This module requires these other modules and libraries:
  Modern::Perl

lib/API/DirectAdmin.pm  view on Meta::CPAN

    my $request = HTTP::Request->new( $method, $url );
    
    if ( $method eq 'GET' ) {
	my $response = $ua->request( $request );
	$content = $response->content;
    }
    else { # Temporary URL for making request
	my $temp_uri = URI->new('http:');
	$temp_uri->query_form( $params );
	$request->content( $temp_uri->query );
	$request->content_type('application/x-www-form-urlencoded');
	my $response = $ua->request($request);
	$content = $response->content;
    }
    
    warn "Answer: " . $content if $self->{debug};
    
    return $content if $params->{noparse};
    return $self->parse_answer($content);
}

lib/API/DirectAdmin.pm  view on Meta::CPAN

=item dumpzone

Return zone structure for domain

Example:

    $da->dns->dumpzone( {domain => 'domain.com'} );

=item add_record

Add zone record to dns for domain. Available types of records: A, AAAA, NS, MX, TXT, PTR, CNAME, SRV

Example:

    my $result = $da->dns->add_record({
        domain => 'domain.com', 
        type   => 'A',
        name   => 'subdomain', # will be "subdomain.domain.com." in record
        value  => '127.127.127.127',
    });

Example with MX record:

    my $result = $da->dns->add_record( { 
        domain  => 'domain.com',
        type    => 'MX',
        name    => 'mx1',
        value   => 10,
    } );

=item remove_record

Remove record from domain zone

Example:

    my $result = $da->dns->remove_record({
        domain => 'domain.com',
        type   => 'A',
        name   => 'subdomain',
        value  => '127.127.127.127',
    });

Example with MX record:

    my $result = $da->dns->remove_record({
        domain => 'domain.com',
        type   => 'mx',
        name   => 'mx1',
        value  => 10,
    });

=back

=head1 INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

=head1 DEPENDENCIES

This module requires these other modules and libraries:
  Modern::Perl

lib/API/DirectAdmin/DNS.pm  view on Meta::CPAN

        params         => \%params,
        command        => 'CMD_API_DNS_CONTROL',
        allowed_fields => 'domain noparse',
    );

    return _parse_zone($zone, $params->{domain}. '.', '') unless ref $zone eq 'HASH';
    return $zone;
}

# Add records A, MX, CNAME, NS, PTR, TXT, AAAA
# params: domain, type, name, value
sub add_record {
    my ($self, $params ) = @_;

    my %add_params = (
	action => 'add',
    );
    
    my %params = (%$params, %add_params);

    return $self->directadmin->query(
        params         => \%params,
        command        => 'CMD_API_DNS_CONTROL',
	method	       => 'POST',
        allowed_fields => "type name action value domain",
    );
}

# Remove records A, MX, CNAME, NS, PTR, TXT, AAAA, SRV
# params: domain, type, name, value
sub remove_record {
    my ($self, $params ) = @_;
    
    my %add_params = (
	action => 'select',
	lc $params->{type} . 'recs0' => "name=$params->{name}&value=$params->{value}",
    );
    
    delete $params->{type};
    
    my %params = (%$params, %add_params);

    return $self->directadmin->query(
        params         => \%params,
        command        => 'CMD_API_DNS_CONTROL',
	method	       => 'POST',
	allowed_fields => 'domain 
			   action 
			   name 

lib/API/DirectAdmin/DNS.pm  view on Meta::CPAN

    my %zone;

    my $zentry = qr/^
	    (\S+)\s+ # name
	    (
		    (?: (?: IN | CH | HS ) \s+ \d+ \s+ ) |
		    (?: \d+ \s+ (?: IN | CH | HS ) \s+ ) |
		    (?: (?: IN | CH | HS ) \s+ ) |
		    (?: \d+ \s+ ) |
	    )? # <ttl> <class> or <class> <ttl>
	    (\S+)\s+ # type
	    (.*) # rdata
    $/ix;

    foreach ( split /\n+/, $zonetext ) {

	    chomp;
	    s/;.*$//;
	    next if /^\s*$/;
	    s/\s+/ /g;
	    

lib/API/DirectAdmin/DNS.pm  view on Meta::CPAN

		    $mrow.=$_;
		    next;
	    }

	    if(/^ /) {
		    s/^/$prev/;
	    }

	    $origin = $1, next if(/^\$ORIGIN ([\w\-\.]+)\s*$/i);

	    my($name,$ttlclass,$type,$rdata) = /$zentry/;

	    my($ttl, $class);
	    if(defined $ttlclass) {
		    ($ttl) = $ttlclass=~/(\d+)/o;
		    ($class) = $ttlclass=~/(CH|IN|HS)/io;

		    $ttlclass=~s/\d+//;
		    $ttlclass=~s/(?:CH|IN|HS)//;
		    $ttlclass=~s/\s//g;
		    if($ttlclass) {
			    next;
		    }
	    }

	    $ttl = defined $ttl ? $ttl : 14400;

	    next if (!$name || !$type || !$rdata);

	    $prev=$name;
	    $name.=".$origin" if $name ne $origin && $name !~ /\.$/;

	    if($type =~ /^(?:cname|afsdb|mx|ns)$/i and 
	       $rdata ne $origin and $rdata !~ /\.$/) {
		    $rdata.=".$origin";
	    }

	    push(@{$zone{lc $name}{lc $type}{rdata}}, $rdata);
	    push(@{$zone{lc $name}{lc $type}{ttl}}, $ttl);
	    push(@{$zone{lc $name}{lc $type}{class}}, $class);
    }

    return \%zone;
}

1;



( run in 1.182 second using v1.01-cache-2.11-cpan-df04353d9ac )