5 var
$ZONE_TEMPLATE =
"/etc/alternc/templates/bind/templates/zone.template";
8 var
$RNDC =
"/usr/sbin/rndc";
28 if (empty($this->cache_conf_db)) {
32 replace(replace(dt.entry,'%TARGET%',sd.valeur), '%SUB%', if(length(sd.sub)>0,sd.sub,'@')) as entry
38 and sd.enable in ('ENABLE', 'ENABLED')
40 while ($db->next_record()) {
41 $t[$db->f(
'domaine')][] = $db->f(
'entry');
43 $this->cache_conf_db =
$t;
47 return $this->cache_conf_db[
$domain];
57 return $this->zone_file_directory.$domain;
66 $this->cache_zone_file[
$domain] =
false;
69 return $this->cache_zone_file[
$domain] ;
77 $calc = date(
'Ymd').
'00'.
"\n";
82 preg_match_all(
"/\s*(\d{10})\s+\;\sserial\s?/", $file, $output_array);
83 if (
isset($output_array[1][0]) && !empty($output_array[1][0])) {
84 $old = $output_array[1][0];
88 return max(array($calc,$old)) + 1 ;
94 preg_match_all(
'/\;\s*END\sALTERNC\sAUTOGENERATE\sCONFIGURATION(.*)/s', $this->
get_zone_file($domain), $output_array);
95 if (
isset($output_array[1][0]) && !empty($output_array[1][0])) {
96 $this->cache_get_persistent[
$domain] = $output_array[1][0];
98 $this->cache_get_persistent[
$domain] =
false;
101 return $this->cache_get_persistent[
$domain];
105 return file_get_contents($this->ZONE_TEMPLATE);
112 if (empty($this->cache_domain_summary)) {
113 $this->cache_domain_summary = $dom->get_domain_all_summary();
121 $target_dir =
"/etc/opendkim/keys/$domain";
122 if (file_exists($target_dir)) {
123 @unlink(
"$target_dir/alternc_private");
124 @unlink(
"$target_dir/alternc.txt");
135 $target_dir =
"/etc/opendkim/keys/$domain";
137 if (file_exists($target_dir.
'/alternc.txt'))
return;
139 if (! is_dir($target_dir)) mkdir($target_dir);
144 exec(
'opendkim-genkey -r -d "'.escapeshellarg(
$domain).
'" -s "alternc" ');
148 chown(
"$target_dir/alternc.private",
'opendkim');
149 chgrp(
"$target_dir/alternc.private",
'opendkim');
156 $trusted_host_new =
"# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n";
157 $keytable_new =
"# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n";
158 $signingtable_new =
"# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n";
160 # Generate automatic entry
163 if ( ! $ds[
'gesdns'] || ! $ds[
'gesmx'] || strtoupper($ds[
'dns_action']) ==
'DELETE' )
continue;
166 if (! file_exists(
"/etc/opendkim/keys/$domain/alternc.txt"))
continue;
169 $trusted_host_new.=
"$domain\n";
170 $keytable_new .=
"alternc._domainkey.$domain $domain:alternc:/etc/opendkim/keys/$domain/alternc.private\n";
171 $signingtable_new.=
"$domain alternc._domainkey.$domain\n";
173 $trusted_host_new.=
"# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE";
174 $keytable_new .=
"# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE";
175 $signingtable_new.=
"# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE";
178 $trusted_host_old=@file_get_contents($this->dkim_trusted_host_file);
179 $keytable_old =@file_get_contents($this->dkim_keytable_file);
180 $signingtable_old=@file_get_contents($this->dkim_signingtable_file);
183 preg_match_all(
'/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $trusted_host_old, $output_array);
184 if (
isset($output_array[1][0]) && !empty($output_array[1][0])) {
185 $trusted_host_new.=$output_array[1][0];
187 preg_match_all(
'/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $keytable_old, $output_array);
188 if (
isset($output_array[1][0]) && !empty($output_array[1][0])) {
189 $keytable_new.=$output_array[1][0];
191 preg_match_all(
'/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $signingtable_old, $output_array);
192 if (
isset($output_array[1][0]) && !empty($output_array[1][0])) {
193 $signingtable_new.=$output_array[1][0];
197 if ( $trusted_host_new != $trusted_host_old ) {
198 file_put_contents($this->dkim_trusted_host_file, $trusted_host_new);
200 if ( $keytable_new != $keytable_old ) {
201 file_put_contents($this->dkim_keytable_file, $keytable_new);
203 if ( $signingtable_new != $signingtable_old ) {
204 file_put_contents($this->dkim_signingtable_file, $signingtable_new);
210 $keyfile=
"/etc/opendkim/keys/$domain/alternc.txt";
214 return @file_get_contents($keyfile);
228 if (! preg_match(
"/autoconfig(\s|\.".str_replace(
'.',
'\.',
$domain).
"\.)/", $zone )) {
229 $entry.=
"autoconfig IN CNAME %%fqdn%%.\n";
231 if (! preg_match(
"/autodiscover(\s|\.".str_replace(
'.',
'\.',
$domain).
"\.)/", $zone )) {
232 $entry.=
"autodiscover IN CNAME %%fqdn%%.\n";
240 global $L_FQDN, $L_NS1_HOSTNAME, $L_NS2_HOSTNAME, $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX, $L_PUBLIC_IP;
244 $zone.=
"\n;;;HOOKED ENTRY\n";
249 $zone.=
"\n;;;END ALTERNC AUTOGENERATE CONFIGURATION";
253 $zone = strtr($zone, array(
254 "%%fqdn%%"=>
"$L_FQDN",
255 "%%ns1%%"=>
"$L_NS1_HOSTNAME",
256 "%%ns2%%"=>
"$L_NS2_HOSTNAME",
257 "%%DEFAULT_MX%%"=>
"$L_DEFAULT_MX",
258 "%%DEFAULT_SECONDARY_MX%%"=>
"$L_DEFAULT_SECONDARY_MX",
259 "@@fqdn@@"=>
"$L_FQDN",
260 "@@ns1@@"=>
"$L_NS1_HOSTNAME",
261 "@@ns2@@"=>
"$L_NS2_HOSTNAME",
262 "@@DEFAULT_MX@@"=>
"$L_DEFAULT_MX",
263 "@@DEFAULT_SECONDARY_MX@@"=>
"$L_DEFAULT_SECONDARY_MX",
264 "@@DOMAINE@@"=>
"$domain",
266 "@@PUBLIC_IP@@"=>
"$L_PUBLIC_IP",
274 exec($this->RNDC.
" reload ".escapeshellarg(
$domain), $output, $return_value);
275 if ($return_value != 0 ) {
276 echo
"ERROR: Reload zone failed for zone $domain\n";
283 if (
isset($output_array[1][0]) && !empty($output_array[1][0])) {
294 $dom->set_dns_result(
$domain,
"The zone file of this domain is locked. Contact your administrator.");
295 $dom->set_dns_action(
$domain,
'OK');
302 chown($file,
'bind');
305 $dom->set_dns_action(
$domain,
'OK');
312 if (file_exists($file)) {
322 $new_named_conf=
"// DO NOT EDIT\n// This file is generated by Alternc.\n// Every changes you'll make will be overwrited.\n";
323 $tpl=file_get_contents($this->NAMED_TEMPLATE);
325 if ( ! $ds[
'gesdns'] || strtoupper($ds[
'dns_action']) ==
'DELETE' )
continue;
330 $old_named_conf = @file_get_contents($this->NAMED_CONF);
333 if ($old_named_conf != $new_named_conf ) {
334 file_put_contents($this->NAMED_CONF,$new_named_conf);
335 chown($this->NAMED_CONF,
'bind');
336 chmod($this->NAMED_CONF, 0640);
337 exec($this->RNDC.
" reconfig");
338 $hooks->invoke_scripts(
"/usr/lib/alternc/reload.d", array(
'dns_reconfig') );
349 if ( ! $ds[
'gesdns'] && strtoupper($ds[
'dns_action']) ==
'OK' )
continue;
351 if ( (strtoupper($ds[
'dns_action']) ==
'DELETE' ) ||
352 (strtoupper($ds[
'dns_action']) ==
'UPDATE' && $ds[
'gesdns']==
false )
358 if ( ( $all || strtoupper($ds[
'dns_action']) ==
'UPDATE' ) && $ds[
'gesdns'] ) {
361 $hooks->invoke_scripts(
"/usr/lib/alternc/reload.d", array(
'dns_reload_zone',
$domain) );
372 _(
"The zone file of this domain is locked. Contact your administrator.");