53 if (empty($this->cache_conf_db)) {
57 replace(replace(dt.entry,'%TARGET%',sd.valeur), '%SUB%', if(length(sd.sub)>0,sd.sub,'@')) as entry 63 and sd.enable in ('ENABLE', 'ENABLED') 66 while ($db->next_record()) {
67 $t[$db->f(
'domaine')][] = $db->f(
'entry');
69 $this->cache_conf_db =
$t;
72 if (isset($this->cache_conf_db[
$domain])) {
73 return $this->cache_conf_db[
$domain];
89 return $this->zone_file_directory.$domain;
100 if (!isset($this->cache_zone_file[
$domain]) ) {
104 $this->cache_zone_file[
$domain] =
false;
107 return $this->cache_zone_file[
$domain] ;
121 $calc = date(
'Ymd').
'00'.
"\n";
126 preg_match_all(
"/\s*(\d{10})\s+\;\sserial\s?/", $file, $output_array);
127 if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
128 $old = $output_array[1][0];
132 return max(array($calc,$old)) + 1 ;
143 if ( ! isset($this->cache_get_persistent[
$domain] )) {
144 preg_match_all(
'/\;\s*END\sALTERNC\sAUTOGENERATE\sCONFIGURATION(.*)/s', $this->
get_zone_file($domain), $output_array);
145 if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
146 $this->cache_get_persistent[
$domain] = $output_array[1][0];
148 $this->cache_get_persistent[
$domain] =
false;
151 return $this->cache_get_persistent[
$domain];
160 return file_get_contents($this->ZONE_TEMPLATE);
174 if (empty($this->cache_domain_summary)) {
175 $this->cache_domain_summary = $dom->get_domain_all_summary();
189 $target_dir =
"/etc/opendkim/keys/$domain";
190 if (file_exists($target_dir)) {
191 @unlink(
"$target_dir/alternc_private");
192 @unlink(
"$target_dir/alternc.txt");
208 if ( ! $domainInfo[
'gesmx'] )
return;
210 $target_dir =
"/etc/opendkim/keys/$domain";
212 if (file_exists($target_dir.
'/alternc.txt'))
return;
214 if (! is_dir($target_dir)) mkdir($target_dir);
219 exec(
'opendkim-genkey -r -d '.escapeshellarg(
$domain).
' -s "alternc" ');
223 chown(
"$target_dir/alternc.private",
'opendkim');
224 chgrp(
"$target_dir/alternc.private",
'opendkim');
235 $trusted_host_new =
"# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n";
236 $keytable_new =
"# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n";
237 $signingtable_new =
"# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n";
239 # Generate automatic entry 242 if ( ! $ds[
'gesdns'] || ! $ds[
'gesmx'] || strtoupper($ds[
'dns_action']) ==
'DELETE' )
continue;
245 if (! file_exists(
"/etc/opendkim/keys/$domain/alternc.txt"))
continue;
248 $trusted_host_new.=
"$domain\n";
249 $keytable_new .=
"alternc._domainkey.$domain $domain:alternc:/etc/opendkim/keys/$domain/alternc.private\n";
250 $signingtable_new.=
"$domain alternc._domainkey.$domain\n";
252 $trusted_host_new.=
"# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
253 $keytable_new .=
"# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
254 $signingtable_new.=
"# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
257 $trusted_host_old=@file_get_contents($this->dkim_trusted_host_file);
258 $keytable_old =@file_get_contents($this->dkim_keytable_file);
259 $signingtable_old=@file_get_contents($this->dkim_signingtable_file);
262 preg_match_all(
'/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $trusted_host_old, $output_array);
263 if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
264 $trusted_host_new.=$output_array[1][0];
266 preg_match_all(
'/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $keytable_old, $output_array);
267 if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
268 $keytable_new.=$output_array[1][0];
270 preg_match_all(
'/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $signingtable_old, $output_array);
271 if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
272 $signingtable_new.=$output_array[1][0];
276 if ( $trusted_host_new != $trusted_host_old ) {
277 file_put_contents($this->dkim_trusted_host_file, $trusted_host_new);
279 if ( $keytable_new != $keytable_old ) {
280 file_put_contents($this->dkim_keytable_file, $keytable_new);
282 if ( $signingtable_new != $signingtable_old ) {
283 file_put_contents($this->dkim_signingtable_file, $signingtable_new);
295 $keyfile=
"/etc/opendkim/keys/$domain/alternc.txt";
297 if (! file_exists($keyfile) && $domainInfo[
'gesmx'] ) {
300 return @file_get_contents($keyfile);
316 if ( $domainInfo[
'gesmx'] ) {
321 if (! preg_match(
"/autoconfig(\s|\.".str_replace(
'.',
'\.',
$domain).
"\.)/", $zone )) {
322 $entry.=
"autoconfig IN CNAME %%fqdn%%.\n";
324 if (! preg_match(
"/autodiscover(\s|\.".str_replace(
'.',
'\.',
$domain).
"\.)/", $zone )) {
325 $entry.=
"autodiscover IN CNAME %%fqdn%%.\n";
346 global $L_FQDN, $L_NS1_HOSTNAME, $L_NS2_HOSTNAME, $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX, $L_PUBLIC_IP;
350 $zone.=
"\n;;;HOOKED ENTRY\n";
355 $zone.=
"\n;;; END ALTERNC AUTOGENERATE CONFIGURATION\n";
360 $zone = strtr($zone, array(
361 "%%fqdn%%"=>
"$L_FQDN",
362 "%%ns1%%"=>
"$L_NS1_HOSTNAME",
363 "%%ns2%%"=>
"$L_NS2_HOSTNAME",
364 "%%DEFAULT_MX%%"=>
"$L_DEFAULT_MX",
365 "%%DEFAULT_SECONDARY_MX%%"=>
"$L_DEFAULT_SECONDARY_MX",
366 "@@fqdn@@"=>
"$L_FQDN",
367 "@@ns1@@"=>
"$L_NS1_HOSTNAME",
368 "@@ns2@@"=>
"$L_NS2_HOSTNAME",
369 "@@DEFAULT_MX@@"=>
"$L_DEFAULT_MX",
370 "@@DEFAULT_SECONDARY_MX@@"=>
"$L_DEFAULT_SECONDARY_MX",
371 "@@DOMAINE@@"=>
"$domain",
373 "@@PUBLIC_IP@@"=>
"$L_PUBLIC_IP",
374 "@@ZONETTL@@"=> $domainInfo[
'zonettl'],
386 exec($this->RNDC.
" reload ".escapeshellarg(
$domain), $output, $return_value);
387 if ($return_value != 0 ) {
388 echo
"ERROR: Reload zone failed for zone $domain\n";
401 if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
420 $dom->set_dns_result(
$domain,
"The zone file of this domain is locked. Contact your administrator.");
421 $dom->set_dns_action(
$domain,
'OK');
428 chown($file,
'bind');
431 $dom->set_dns_action(
$domain,
'OK');
444 if (file_exists($file)) {
460 $new_named_conf=
"// DO NOT EDIT\n// This file is generated by Alternc.\n// Every changes you'll make will be overwrited.\n";
461 $tpl=file_get_contents($this->NAMED_TEMPLATE);
463 if ( ! $ds[
'gesdns'] || strtoupper($ds[
'dns_action']) ==
'DELETE' )
continue;
468 $old_named_conf = @file_get_contents($this->NAMED_CONF);
471 if ($old_named_conf != $new_named_conf ) {
472 file_put_contents($this->NAMED_CONF,$new_named_conf);
473 chown($this->NAMED_CONF,
'bind');
474 chmod($this->NAMED_CONF, 0640);
475 exec($this->RNDC.
" reconfig");
476 $hooks->invoke_scripts(
"/usr/lib/alternc/reload.d", array(
'dns_reconfig') );
494 if ( ! $ds[
'gesdns'] && strtoupper($ds[
'dns_action']) ==
'OK' )
continue;
496 if ( (strtoupper($ds[
'dns_action']) ==
'DELETE' ) ||
497 (strtoupper($ds[
'dns_action']) ==
'UPDATE' && $ds[
'gesdns']==
false )
503 if ( ( $all || strtoupper($ds[
'dns_action']) ==
'UPDATE' ) && $ds[
'gesdns'] ) {
506 $hooks->invoke_scripts(
"/usr/lib/alternc/reload.d", array(
'dns_reload_zone',
$domain) );
520 _(
"The zone file of this domain is locked. Contact your administrator.");
dkim_generate_key($domain)
Generate the domain DKIM key.
get_domain_summary($domain=false)
delete_zone($domain)
Delete the zone configuration file.
get_zone_file_uri($domain)
Return full path of the zone configuration file.
foreach($domaines_user as $domaine) $t
mail_autoconfig_entry($domain)
Conditionnal generation autoconfig entry for outlook / thunderbird If entry with the same name allrea...
bind9 file management class
is_locked($domain)
return true if zone is locked
get_persistent($domain)
Return lines that are after ;;; END ALTERNC AUTOGENERATE CONFIGURATION.
conf_from_db($domain=false)
Return the part of the conf we got from the database.
dkim_refresh_list()
Refresh DKIM configuration: be sure to list the domain having a private key (and only them) ...
regenerate_conf($all=false)
Regenerate bind configuration and load it.
get_zone($domain)
Return a fully generated zone.