]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Dns/PowerdnsPlugin.pm
1 package PVE
:: Network
:: SDN
:: Dns
:: PowerdnsPlugin
;
12 use base
( 'PVE::Network::SDN::Dns::Plugin' );
35 url
=> { optional
=> 0 },
36 key
=> { optional
=> 0 },
37 ttl
=> { optional
=> 1 },
38 reversemaskv6
=> { optional
=> 1 , description
=> "force a different netmask for the ipv6 reverse zone name." },
43 # Plugin implementation
46 my ( $class, $plugin_config, $zone, $hostname, $ip ) = @_ ;
48 my $url = $plugin_config ->{ url
};
49 my $key = $plugin_config ->{ key
};
50 my $ttl = $plugin_config ->{ ttl
} ?
$plugin_config ->{ ttl
} : 14400 ;
51 my $headers = [ 'Content-Type' => 'application/json; charset=UTF-8' , 'X-API-Key' => $key ];
53 my $type = Net
:: IP
:: ip_is_ipv6
( $ip ) ?
"AAAA" : "A" ;
54 my $fqdn = $hostname . "." . $zone . "." ;
57 my $record = { content
=> $ip,
58 disabled
=> JSON
:: false
,
63 my $rrset = { name
=> $fqdn,
66 changetype
=> "REPLACE" ,
67 records
=> [ $record ] };
70 my $params = { rrsets
=> [ $rrset ] };
73 PVE
:: Network
:: SDN
:: Dns
:: Plugin
:: api_request
( "PATCH" , " $url/zones/$zone " , $headers, $params );
77 die "error add $fqdn to zone $zone : $@ " ;
82 my ( $class, $plugin_config, $zone, $hostname, $ip ) = @_ ;
84 my $url = $plugin_config ->{ url
};
85 my $key = $plugin_config ->{ key
};
86 my $ttl = $plugin_config ->{ ttl
} ?
$plugin_config ->{ ttl
} : 14400 ;
87 my $headers = [ 'Content-Type' => 'application/json; charset=UTF-8' , 'X-API-Key' => $key ];
90 my $reverseip = Net
:: IP-
> new ( $ip )-> reverse_ip ();
94 my $record = { content
=> $hostname,
95 disabled
=> JSON
:: false
,
100 my $rrset = { name
=> $reverseip,
103 changetype
=> "REPLACE" ,
104 records
=> [ $record ] };
107 my $params = { rrsets
=> [ $rrset ] };
110 PVE
:: Network
:: SDN
:: Dns
:: Plugin
:: api_request
( "PATCH" , " $url/zones/$zone " , $headers, $params );
114 die "error add $reverseip to zone $zone : $@ " ;
119 my ( $class, $plugin_config, $zone, $hostname, $ip ) = @_ ;
121 my $url = $plugin_config ->{ url
};
122 my $key = $plugin_config ->{ key
};
123 my $headers = [ 'Content-Type' => 'application/json; charset=UTF-8' , 'X-API-Key' => $key ];
124 my $fqdn = $hostname . "." . $zone . "." ;
125 my $type = Net
:: IP
:: ip_is_ipv6
( $ip ) ?
"AAAA" : "A" ;
127 my $rrset = { name
=> $fqdn,
129 changetype
=> "DELETE" ,
132 my $params = { rrsets
=> [ $rrset ] };
135 PVE
:: Network
:: SDN
:: Dns
:: Plugin
:: api_request
( "PATCH" , " $url/zones/$zone " , $headers, $params );
139 die "error delete $fqdn from zone $zone : $@ " ;
144 my ( $class, $plugin_config, $zone, $ip ) = @_ ;
146 my $url = $plugin_config ->{ url
};
147 my $key = $plugin_config ->{ key
};
148 my $headers = [ 'Content-Type' => 'application/json; charset=UTF-8' , 'X-API-Key' => $key ];
150 my $reverseip = Net
:: IP-
> new ( $ip )-> reverse_ip ();
154 my $rrset = { name
=> $reverseip,
156 changetype
=> "DELETE" ,
159 my $params = { rrsets
=> [ $rrset ] };
162 PVE
:: Network
:: SDN
:: Dns
:: Plugin
:: api_request
( "PATCH" , " $url/zones/$zone " , $headers, $params );
166 die "error delete $reverseip from zone $zone : $@ " ;
171 my ( $class, $plugin_config, $zone ) = @_ ;
173 #verify that api is working
175 my $url = $plugin_config ->{ url
};
176 my $key = $plugin_config ->{ key
};
177 my $headers = [ 'Content-Type' => 'application/json; charset=UTF-8' , 'X-API-Key' => $key ];
180 PVE
:: Network
:: SDN
:: Dns
:: Plugin
:: api_request
( "GET" , " $url/zones/$zone " , $headers );
184 die "can't read zone $zone : $@ " ;
188 sub get_reversedns_zone
{
189 my ( $class, $plugin_config, $subnetid, $ip ) = @_ ;
191 my ( $network, $mask ) = split ( /-/ , $subnetid );
193 my $cidr = " $ip/$mask " ;
196 if ( Net
:: IP
:: ip_is_ipv4
( $ip )) {
197 my ( $ipblock1, $ipblock2, $ipblock3, $ipblock4 ) = split ( /\./ , $ip );
199 my $ipv4 = new NetAddr
:: IP
( $cidr );
200 #private addresse #powerdns built-in private zone : serve-rfc1918
201 if ( $ipv4 -> is_rfc1918 ()) {
202 if ( $ipblock1 == 192 ) {
203 $zone = "168.192.in-addr.arpa." ;
204 } elsif ( $ipblock1 == 172 ) {
205 $zone = "16-31.172.in-addr.arpa." ;
206 } elsif ( $ipblock1 == 10 ) {
207 $zone = "10.in-addr.arpa." ;
211 #public ipv4 : RIPE,ARIN,AFRNIC
212 #. Delegations can be managed in IPv4 on bit boundaries (/8, /16 or /24s), and IPv6 networks can be managed on nibble boundaries (every 4 bits of the IPv6 address)
213 #One or more /24 type zones need to be created if your address space has a prefix length between /17 and /24.
214 # If your prefix length is between /16 and /9 you will have to request one or more delegations for /16 type zones.
217 $zone = " $ipblock3 . $ipblock2 . $ipblock1 .in-addr.arpa." ;
218 } elsif ( $mask <= 16 ) {
219 $zone = " $ipblock2 . $ipblock1 .in-addr.arpa." ;
220 } elsif ( $mask <= 8 ) {
221 $zone = " $ipblock1 .in-addr.arpa." ;
225 $mask = $plugin_config ->{ reversemaskv6
} if $plugin_config ->{ reversemaskv6
};
226 die "reverse dns zone mask need to be a multiple of 4" if ( $mask % 4 );
227 my $networkv6 = NetAddr
:: IP-
> new ( $cidr )-> network ();
228 $zone = Net
:: IP-
> new ( $networkv6 )-> reverse_ip ();
236 my ( $class, $plugin_config ) = @_ ;
238 #verify that api is working
240 my $url = $plugin_config ->{ url
};
241 my $key = $plugin_config ->{ key
};
242 my $headers = [ 'Content-Type' => 'application/json; charset=UTF-8' , 'X-API-Key' => $key ];
245 PVE
:: Network
:: SDN
:: Dns
:: Plugin
:: api_request
( "GET" , " $url " , $headers );
249 die "dns api error: $@ " ;