[enh] allow different path for system_bind
This commit is contained in:
parent
396fe6743c
commit
9c4c68b6eb
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
|
|
||||||
class system_bind {
|
class system_bind {
|
||||||
var $ZONE_TEMPLATE ="/etc/alternc/templates/bind/templates/zone.template";
|
var $ZONE_TEMPLATE = "/etc/alternc/templates/bind/templates/zone.template";
|
||||||
var $NAMED_TEMPLATE ="/etc/alternc/templates/bind/templates/named.template";
|
var $NAMED_TEMPLATE = "/etc/alternc/templates/bind/templates/named.template";
|
||||||
var $NAMED_CONF ="/var/lib/alternc/bind/automatic.conf";
|
var $NAMED_CONF = "/var/lib/alternc/bind/automatic.conf";
|
||||||
var $RNDC ="/usr/sbin/rndc";
|
var $RNDC = "/usr/sbin/rndc";
|
||||||
|
|
||||||
var $dkim_trusted_host_file = "/etc/opendkim/TrustedHosts";
|
var $dkim_trusted_host_file = "/etc/opendkim/TrustedHosts";
|
||||||
var $dkim_keytable_file = "/etc/opendkim/KeyTable";
|
var $dkim_keytable_file = "/etc/opendkim/KeyTable";
|
||||||
|
@ -19,10 +19,37 @@ class system_bind {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @param array $options optional parameters
|
||||||
*/
|
*/
|
||||||
function system_bind() {
|
public function __construct($options = null) {
|
||||||
// Constructeur
|
|
||||||
|
if (isset($options["ZONE_TEMPLATE"])) {
|
||||||
|
$this->ZONE_TEMPLATE = $options["ZONE_TEMPLATE"];
|
||||||
}
|
}
|
||||||
|
if (isset($options["NAMED_TEMPLATE"])) {
|
||||||
|
$this->NAMED_TEMPLATE = $options["NAMED_TEMPLATE"];
|
||||||
|
}
|
||||||
|
if (isset($options["NAMED_CONF"])) {
|
||||||
|
$this->NAMED_CONF = $options["NAMED_CONF"];
|
||||||
|
}
|
||||||
|
if (isset($options["RNDC"])) {
|
||||||
|
$this->RNDC = $options["RNDC"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options["dkim_trusted_host_file"])) {
|
||||||
|
$this->dkim_trusted_host_file = $options["dkim_trusted_host_file"];
|
||||||
|
}
|
||||||
|
if (isset($options["dkim_keytable_file"])) {
|
||||||
|
$this->dkim_keytable_file = $options["dkim_keytable_file"];
|
||||||
|
}
|
||||||
|
if (isset($options["dkim_signingtable_file"])) {
|
||||||
|
$this->dkim_signingtable_file = $options["dkim_signingtable_file"];
|
||||||
|
}
|
||||||
|
if (isset($options["zone_file_directory"])) {
|
||||||
|
$this->zone_file_directory = $options["zone_file_directory"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the part of the conf we got from the database
|
* Return the part of the conf we got from the database
|
||||||
|
@ -43,10 +70,10 @@ class system_bind {
|
||||||
sub_domaines sd,
|
sub_domaines sd,
|
||||||
domaines_type dt
|
domaines_type dt
|
||||||
where
|
where
|
||||||
sd.type=dt.name
|
sd.type = dt.name
|
||||||
and sd.enable in ('ENABLE', 'ENABLED')
|
and sd.enable in ('ENABLE', 'ENABLED')
|
||||||
order by entry ;");
|
order by entry ;");
|
||||||
$t=array();
|
$t = array();
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$t[$db->f('domaine')][] = $db->f('entry');
|
$t[$db->f('domaine')][] = $db->f('entry');
|
||||||
}
|
}
|
||||||
|
@ -102,7 +129,7 @@ class system_bind {
|
||||||
$calc = date('Ymd').'00'."\n";
|
$calc = date('Ymd').'00'."\n";
|
||||||
|
|
||||||
// Old one :
|
// Old one :
|
||||||
$old=$calc; // default value
|
$old = $calc; // default value
|
||||||
$file = $this->get_zone_file($domain);
|
$file = $this->get_zone_file($domain);
|
||||||
preg_match_all("/\s*(\d{10})\s+\;\sserial\s?/", $file, $output_array);
|
preg_match_all("/\s*(\d{10})\s+\;\sserial\s?/", $file, $output_array);
|
||||||
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
||||||
|
@ -190,7 +217,7 @@ class system_bind {
|
||||||
if (! is_dir($target_dir)) mkdir($target_dir); // create dir
|
if (! is_dir($target_dir)) mkdir($target_dir); // create dir
|
||||||
|
|
||||||
// Generate the key
|
// Generate the key
|
||||||
$old_dir=getcwd();
|
$old_dir = getcwd();
|
||||||
chdir($target_dir);
|
chdir($target_dir);
|
||||||
exec('opendkim-genkey -r -d "'.escapeshellarg($domain).'" -s "alternc" ');
|
exec('opendkim-genkey -r -d "'.escapeshellarg($domain).'" -s "alternc" ');
|
||||||
chdir($old_dir);
|
chdir($old_dir);
|
||||||
|
@ -220,31 +247,31 @@ class system_bind {
|
||||||
if (! file_exists("/etc/opendkim/keys/$domain/alternc.txt")) continue;
|
if (! file_exists("/etc/opendkim/keys/$domain/alternc.txt")) continue;
|
||||||
|
|
||||||
// Modif the files.
|
// Modif the files.
|
||||||
$trusted_host_new.="$domain\n";
|
$trusted_host_new .= "$domain\n";
|
||||||
$keytable_new .="alternc._domainkey.$domain $domain:alternc:/etc/opendkim/keys/$domain/alternc.private\n";
|
$keytable_new .= "alternc._domainkey.$domain $domain:alternc:/etc/opendkim/keys/$domain/alternc.private\n";
|
||||||
$signingtable_new.="$domain alternc._domainkey.$domain\n";
|
$signingtable_new .= "$domain alternc._domainkey.$domain\n";
|
||||||
}
|
}
|
||||||
$trusted_host_new.="# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
|
$trusted_host_new .= "# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
|
||||||
$keytable_new .="# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
|
$keytable_new .= "# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
|
||||||
$signingtable_new.="# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
|
$signingtable_new .= "# END AUTOMATIC FILE. ADD YOUR CHANGES AFTER THIS LINE\n";
|
||||||
|
|
||||||
# Get old files
|
# Get old files
|
||||||
$trusted_host_old=@file_get_contents($this->dkim_trusted_host_file);
|
$trusted_host_old = @file_get_contents($this->dkim_trusted_host_file);
|
||||||
$keytable_old =@file_get_contents($this->dkim_keytable_file);
|
$keytable_old = @file_get_contents($this->dkim_keytable_file);
|
||||||
$signingtable_old=@file_get_contents($this->dkim_signingtable_file);
|
$signingtable_old = @file_get_contents($this->dkim_signingtable_file);
|
||||||
|
|
||||||
# Keep manuel entry
|
# Keep manuel entry
|
||||||
preg_match_all('/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $trusted_host_old, $output_array);
|
preg_match_all('/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $trusted_host_old, $output_array);
|
||||||
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
||||||
$trusted_host_new.=$output_array[1][0];
|
$trusted_host_new .= $output_array[1][0];
|
||||||
}
|
}
|
||||||
preg_match_all('/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $keytable_old, $output_array);
|
preg_match_all('/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $keytable_old, $output_array);
|
||||||
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
||||||
$keytable_new.=$output_array[1][0];
|
$keytable_new .= $output_array[1][0];
|
||||||
}
|
}
|
||||||
preg_match_all('/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $signingtable_old, $output_array);
|
preg_match_all('/\#\s*END\ AUTOMATIC\ FILE\.\ ADD\ YOUR\ CHANGES\ AFTER\ THIS\ LINE(.*)/s', $signingtable_old, $output_array);
|
||||||
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
||||||
$signingtable_new.=$output_array[1][0];
|
$signingtable_new .= $output_array[1][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save if there are some diff
|
// Save if there are some diff
|
||||||
|
@ -265,7 +292,7 @@ class system_bind {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function dkim_entry($domain) {
|
function dkim_entry($domain) {
|
||||||
$keyfile="/etc/opendkim/keys/$domain/alternc.txt";
|
$keyfile = "/etc/opendkim/keys/$domain/alternc.txt";
|
||||||
$domainInfo = $this->get_domain_summary($domain);
|
$domainInfo = $this->get_domain_summary($domain);
|
||||||
if (! file_exists($keyfile) && $domainInfo['gesmx'] ) {
|
if (! file_exists($keyfile) && $domainInfo['gesmx'] ) {
|
||||||
$this->dkim_generate_key($domain);
|
$this->dkim_generate_key($domain);
|
||||||
|
@ -281,9 +308,9 @@ class system_bind {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function mail_autoconfig_entry($domain) {
|
function mail_autoconfig_entry($domain) {
|
||||||
$zone= implode("\n",$this->conf_from_db($domain))."\n".$this->get_persistent($domain);
|
$zone = implode("\n",$this->conf_from_db($domain))."\n".$this->get_persistent($domain);
|
||||||
|
|
||||||
$entry='';
|
$entry = '';
|
||||||
$domainInfo = $this->get_domain_summary($domain);
|
$domainInfo = $this->get_domain_summary($domain);
|
||||||
if ( $domainInfo['gesmx'] ) {
|
if ( $domainInfo['gesmx'] ) {
|
||||||
// If we manage the mail
|
// If we manage the mail
|
||||||
|
@ -291,10 +318,10 @@ class system_bind {
|
||||||
// Check if there is no the same entry (defined or manual)
|
// Check if there is no the same entry (defined or manual)
|
||||||
// can be toto IN A or toto.fqdn.tld. IN A
|
// can be toto IN A or toto.fqdn.tld. IN A
|
||||||
if (! preg_match("/autoconfig(\s|\.".str_replace('.','\.',$domain)."\.)/", $zone )) {
|
if (! preg_match("/autoconfig(\s|\.".str_replace('.','\.',$domain)."\.)/", $zone )) {
|
||||||
$entry.="autoconfig IN CNAME %%fqdn%%.\n";
|
$entry .= "autoconfig IN CNAME %%fqdn%%.\n";
|
||||||
}
|
}
|
||||||
if (! preg_match("/autodiscover(\s|\.".str_replace('.','\.',$domain)."\.)/", $zone )) {
|
if (! preg_match("/autodiscover(\s|\.".str_replace('.','\.',$domain)."\.)/", $zone )) {
|
||||||
$entry.="autodiscover IN CNAME %%fqdn%%.\n";
|
$entry .= "autodiscover IN CNAME %%fqdn%%.\n";
|
||||||
}
|
}
|
||||||
} // if gesmx
|
} // if gesmx
|
||||||
return $entry;
|
return $entry;
|
||||||
|
@ -317,15 +344,15 @@ class system_bind {
|
||||||
function get_zone($domain) {
|
function get_zone($domain) {
|
||||||
global $L_FQDN, $L_NS1_HOSTNAME, $L_NS2_HOSTNAME, $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX, $L_PUBLIC_IP;
|
global $L_FQDN, $L_NS1_HOSTNAME, $L_NS2_HOSTNAME, $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX, $L_PUBLIC_IP;
|
||||||
|
|
||||||
$zone =$this->get_zone_header();
|
$zone = $this->get_zone_header();
|
||||||
$zone.=implode("\n",$this->conf_from_db($domain));
|
$zone .= implode("\n",$this->conf_from_db($domain));
|
||||||
$zone.="\n;;;HOOKED ENTRY\n";
|
$zone .= "\n;;;HOOKED ENTRY\n";
|
||||||
|
|
||||||
$zone.= $this->dkim_entry($domain);
|
$zone .= $this->dkim_entry($domain);
|
||||||
$zone.= $this->mail_autoconfig_entry($domain);
|
$zone .= $this->mail_autoconfig_entry($domain);
|
||||||
|
|
||||||
$zone.="\n;;;END ALTERNC AUTOGENERATE CONFIGURATION\n";
|
$zone .= "\n;;;END ALTERNC AUTOGENERATE CONFIGURATION\n";
|
||||||
$zone.=$this->get_persistent($domain);
|
$zone .= $this->get_persistent($domain);
|
||||||
$domainInfo = $this->get_domain_summary($domain);
|
$domainInfo = $this->get_domain_summary($domain);
|
||||||
|
|
||||||
// FIXME check those vars
|
// FIXME check those vars
|
||||||
|
@ -392,7 +419,7 @@ class system_bind {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save file, and apply chmod/chown
|
// Save file, and apply chmod/chown
|
||||||
$file=$this->get_zone_file_uri($domain);
|
$file = $this->get_zone_file_uri($domain);
|
||||||
file_put_contents($file, $this->get_zone($domain));
|
file_put_contents($file, $this->get_zone($domain));
|
||||||
chown($file, 'bind');
|
chown($file, 'bind');
|
||||||
chmod($file, 0640);
|
chmod($file, 0640);
|
||||||
|
@ -408,7 +435,7 @@ class system_bind {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function delete_zone($domain) {
|
function delete_zone($domain) {
|
||||||
$file=$this->get_zone_file_uri($domain);
|
$file = $this->get_zone_file_uri($domain);
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
|
@ -424,11 +451,11 @@ class system_bind {
|
||||||
function reload_named() {
|
function reload_named() {
|
||||||
global $hooks;
|
global $hooks;
|
||||||
// Generate the new conf file
|
// Generate the new conf file
|
||||||
$new_named_conf="// DO NOT EDIT\n// This file is generated by Alternc.\n// Every changes you'll make will be overwrited.\n";
|
$new_named_conf = "// DO NOT EDIT\n// This file is generated by Alternc.\n// Every changes you'll make will be overwrited.\n";
|
||||||
$tpl=file_get_contents($this->NAMED_TEMPLATE);
|
$tpl = file_get_contents($this->NAMED_TEMPLATE);
|
||||||
foreach ($this->get_domain_summary() as $domain => $ds ) {
|
foreach ($this->get_domain_summary() as $domain => $ds ) {
|
||||||
if ( ! $ds['gesdns'] || strtoupper($ds['dns_action']) == 'DELETE' ) continue;
|
if ( ! $ds['gesdns'] || strtoupper($ds['dns_action']) == 'DELETE' ) continue;
|
||||||
$new_named_conf.=strtr($tpl, array("@@DOMAINE@@"=>$domain, "@@ZONE_FILE@@"=>$this->get_zone_file_uri($domain)));
|
$new_named_conf .= strtr($tpl, array("@@DOMAINE@@"=>$domain, "@@ZONE_FILE@@"=>$this->get_zone_file_uri($domain)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the actual conf file
|
// Get the actual conf file
|
||||||
|
|
Loading…
Reference in New Issue