[fix] misc bugs in update_domaines.php,

This commit is contained in:
Benjamin Sonntag 2018-07-17 16:59:54 +02:00
parent dbfc59097b
commit cdf07913da
6 changed files with 29 additions and 28 deletions

View File

@ -39,7 +39,7 @@ if (!defined("ALTERNC_PANEL")) exit(); // must be included ;)
if (file_exists("styles/style-custom.css") ) { if (file_exists("styles/style-custom.css") ) {
echo '<link rel="stylesheet" href="styles/style-custom.css" type="text/css" />'; echo '<link rel="stylesheet" href="styles/style-custom.css" type="text/css" />';
} }
if (count($addhead['css'])) { if (isset($addhead) && count($addhead['css'])) {
foreach($addhead['css'] as $css) echo $css."\n"; foreach($addhead['css'] as $css) echo $css."\n";
} }
$favicon = variable_get('favicon', 'favicon.ico' ,'You can specify a favicon, for example /images/my_logo.ico', array('desc'=>'URL','type'=>'string')); $favicon = variable_get('favicon', 'favicon.ico' ,'You can specify a favicon, for example /images/my_logo.ico', array('desc'=>'URL','type'=>'string'));
@ -53,7 +53,7 @@ $favicon = variable_get('favicon', 'favicon.ico' ,'You can specify a favicon, fo
<script src="/javascript/jquery-ui/jquery-ui.min.js" type="text/javascript"></script> <script src="/javascript/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="/javascript/jquery-tablesorter/jquery.tablesorter.min.js" type="text/javascript"></script> <script src="/javascript/jquery-tablesorter/jquery.tablesorter.min.js" type="text/javascript"></script>
<?php <?php
if (count($addhead['js'])) { if (isset($addhead) && count($addhead['js'])) {
foreach($addhead['js'] as $js) echo $js."\n"; foreach($addhead['js'] as $js) echo $js."\n";
} }
?> ?>

View File

@ -44,7 +44,7 @@ class m_apache {
// launched for each FQDN for which we want a new vhost template // launched for each FQDN for which we want a new vhost template
function hook_updatedomains_web_add($subdomid) { function hook_updatedomains_web_add($subdomid) {
global $msg,$db; global $msg,$db,$ssl,$L_FQDN;
$db->query("SELECT sd.*, dt.only_dns, dt.has_https_option, m.login FROM domaines_type dt, sub_domaines sd LEFT JOIN membres m ON m.uid=sd.compte WHERE dt.name=sd.type AND sd.web_action!='OK' AND id=?;",array($subdomid)); $db->query("SELECT sd.*, dt.only_dns, dt.has_https_option, m.login FROM domaines_type dt, sub_domaines sd LEFT JOIN membres m ON m.uid=sd.compte WHERE dt.name=sd.type AND sd.web_action!='OK' AND id=?;",array($subdomid));
$db->next_record(); $db->next_record();
@ -85,7 +85,7 @@ class m_apache {
"%%redirect%%" => $subdom['valeur'], "%%redirect%%" => $subdom['valeur'],
"%%UID%%" => $subdom['compte'], "%%UID%%" => $subdom['compte'],
"%%GID%%" => $subdom['compte'], "%%GID%%" => $subdom['compte'],
"%%mail_account%%" => $subdom['mail'], "%%mail_account%%" => $subdom['login']."@".$L_FQDN,
"%%user%%" => "FIXME", "%%user%%" => "FIXME",
"%%CRT%%" => $cert["cert"], "%%CRT%%" => $cert["cert"],
"%%KEY%%" => $cert["key"], "%%KEY%%" => $cert["key"],
@ -94,7 +94,7 @@ class m_apache {
// and write the template // and write the template
$confdir = $this->vhostroot."/".substr($subdom["compte"],-1)."/".$subdom["compte"]; $confdir = $this->vhostroot."/".substr($subdom["compte"],-1)."/".$subdom["compte"];
@mkdir($confdir,0755,true); @mkdir($confdir,0755,true);
file_put_contents($confdir."/".$subdom["fqdn"].".conf"); file_put_contents($confdir."/".$subdom["fqdn"].".conf",$tpl);
$this->shouldreload=true; $this->shouldreload=true;
return 0; // shell meaning => OK ;) return 0; // shell meaning => OK ;)

View File

@ -107,7 +107,7 @@ class m_bind {
trim(strtr( trim(strtr(
file_get_contents($this->NAMED_TEMPLATE), file_get_contents($this->NAMED_TEMPLATE),
array( array(
"@@DOMAIN@@" => $DOMAIN, "@@DOMAIN@@" => $domain,
"@@ZONE_FILE@@" => $this->zone_file_directory."/".$domain "@@ZONE_FILE@@" => $this->zone_file_directory."/".$domain
) )
))) )))
@ -225,7 +225,7 @@ class m_bind {
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="";
while ($db->next_record()) { while ($db->next_record()) {
$t.= $db->f('entry')."\n"; $t.= $db->f('entry')."\n";
} }

View File

@ -635,35 +635,35 @@ class m_dom {
* @param string $dom nom de domaine é effacer * @param string $dom nom de domaine é effacer
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
*/ */
function del_domain($dom) { function del_domain($domain) {
global $db, $msg, $hooks; global $db, $msg, $hooks;
$msg->log("dom", "del_domain", $dom); $msg->log("dom", "del_domain", $domain);
$dom = strtolower($dom); $domain = strtolower($domain);
$this->lock(); $this->lock();
if (!$r = $this->get_domain_all($dom)) { if (!$r = $this->get_domain_all($domain)) {
return false; return false;
} }
$this->unlock(); $this->unlock();
// Call Hooks to delete the domain and the MX management: // Call Hooks to delete the domain and the MX management:
// TODO : the 2 calls below are using an OLD hook call, FIXME: remove them when unused // TODO : the 2 calls below are using an OLD hook call, FIXME: remove them when unused
$hooks->invoke("alternc_del_domain", array($dom)); $hooks->invoke("alternc_del_domain", array($domain));
$hooks->invoke("alternc_del_mx_domain", array($dom)); $hooks->invoke("alternc_del_mx_domain", array($domain));
// New hook calls: // New hook calls:
$hooks->invoke("hook_dom_del_domain", array($r["id"])); $hooks->invoke("hook_dom_del_domain", array($r["id"]));
$hooks->invoke("hook_dom_del_mx_domain", array($r["id"])); $hooks->invoke("hook_dom_del_mx_domain", array($r["id"]));
// Now mark the domain for deletion: // Now mark the domain for deletion:
$db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE domaine= ?;", array($dom)); $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE domaine= ?;", array($domain));
$this->set_dns_action($dom, 'DELETE'); $this->set_dns_action($domain, 'DELETE');
return true; return true;
} }
function domshort($dom, $sub = "") { function domshort($domain, $sub = "") {
return str_replace("-", "", str_replace(".", "", empty($sub) ? "" : "$sub.") . $dom); return str_replace("-", "", str_replace(".", "", empty($sub) ? "" : "$sub.") . $domain);
} }
@ -1302,9 +1302,10 @@ class m_dom {
* de $type (url, ip, dossier...) * de $type (url, ip, dossier...)
* @param string $https the HTTPS behavior : HTTP(redirect https to http), * @param string $https the HTTPS behavior : HTTP(redirect https to http),
* HTTPS(redirect http to https) or BOTH (both hosted at the same place) * HTTPS(redirect http to https) or BOTH (both hosted at the same place)
* or nothing "" when not applicable for this domain type.
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
*/ */
function set_sub_domain($dom, $sub, $type, $dest, $sub_domain_id = 0, $https) { function set_sub_domain($dom, $sub, $type, $dest, $sub_domain_id = 0, $https="") {
global $db, $msg, $cuid, $bro, $domislocked; global $db, $msg, $cuid, $bro, $domislocked;
$msg->log("dom", "set_sub_domain", $dom . "/" . $sub . "/" . $type . "/" . $dest); $msg->log("dom", "set_sub_domain", $dom . "/" . $sub . "/" . $type . "/" . $dest);
// Locked ? // Locked ?
@ -1931,7 +1932,7 @@ class m_dom {
} else { } else {
// we keep the highest result returned by hooks... // we keep the highest result returned by hooks...
rsort($ret,SORT_NUMERIC); $returncode=$ret[0]; rsort($ret,SORT_NUMERIC); $returncode=$ret[0];
$db->query("UPDATE domaines SET dns_result=?, dns_action='OK' WHERE domaine=?;",array($returncode,$onedom)); $db->query("UPDATE domaines SET dns_result=?, dns_action='OK' WHERE domaine=?;",array($returncode,$onedom["domaine"]));
} }
} }
$hooks->invoke("hook_updatedomains_dns_post"); $hooks->invoke("hook_updatedomains_dns_post");

View File

@ -1099,21 +1099,21 @@ ORDER BY
global $db; global $db;
// for each domain where we don't have the MX or the DNS, remove the DKIM setup // for each domain where we don't have the MX or the DNS, remove the DKIM setup
$this->shouldreloaddkim=false; $this->shouldreloaddkim=false;
$db->query("SELECT domaine,gesdns,gesmx FROM domaines WHERE dns_action!='OK';"); $db->query("SELECT domaine,compte,gesdns,gesmx FROM domaines WHERE dns_action!='OK';");
$add=array(); $add=array();
$del=array(); $del=array();
while ($db->next_record()) { while ($db->next_record()) {
if ($db->Record["gesdns"]==0 || $db->Record["gesmx"]==0) { if ($db->Record["gesdns"]==0 || $db->Record["gesmx"]==0) {
$del[]=$db->Record["domaine"]; $del[]=$db->Record;
} else { } else {
$add[]=$db->Record["domaine"]; $add[]=$db->Record;
} }
} }
foreach($add as $domain) { foreach($add as $domain) {
$this->dkim_add($domain); $this->dkim_add($domain["domaine"],$domain["compte"]);
} }
foreach($del as $domain) { foreach($del as $domain) {
$this->dkim_del($domain); $this->dkim_del($domain["domaine"],$domain["compte"]);
} }
} }
@ -1134,7 +1134,7 @@ ORDER BY
/** /**
* Add a domain into OpenDKIM configuration * Add a domain into OpenDKIM configuration
*/ */
function dkim_add($domain) { function dkim_add($domain,$uid) {
global $db; global $db;
$target_dir = "/etc/opendkim/keys/$domain"; $target_dir = "/etc/opendkim/keys/$domain";
if (file_exists($target_dir.'/alternc.txt')) return; // Do not generate if exist if (file_exists($target_dir.'/alternc.txt')) return; // Do not generate if exist
@ -1154,7 +1154,7 @@ ORDER BY
add_line_to_file("/etc/opendkim/SigningTable",$domain." alternc._domainkey.".$domain); add_line_to_file("/etc/opendkim/SigningTable",$domain." alternc._domainkey.".$domain);
// Add subdomaine entry // Add subdomaine entry
$dkim_key=$this->dkim_get_entry($domain); $dkim_key=$this->dkim_get_entry($domain);
$db->query("INSERT INTO sub_domaines SET domaine=?, compte=?, sub='', type='dkim', valeur=?;",array($uid,$domain,$dkim_key)); $db->query("INSERT INTO sub_domaines SET domaine=?, compte=?, sub='', type='dkim', valeur=?;",array($domain,$uid,$dkim_key));
// no need to do DNS_ACTION="UPDATE" => we are in the middle of a HOOK, so dns WILL BE reloaded for this domain // no need to do DNS_ACTION="UPDATE" => we are in the middle of a HOOK, so dns WILL BE reloaded for this domain
} }
@ -1163,7 +1163,7 @@ ORDER BY
/** /**
* Delete a domain from OpenDKIM configuration * Delete a domain from OpenDKIM configuration
*/ */
function dkim_del($domain) { function dkim_del($domain,$uid) {
$target_dir = "/etc/opendkim/keys/$domain"; $target_dir = "/etc/opendkim/keys/$domain";
if (file_exists($target_dir)) { if (file_exists($target_dir)) {
$this->shouldreloaddkim=true; $this->shouldreloaddkim=true;

View File

@ -667,7 +667,7 @@ SELECT ?,?,?, FROM_UNIXTIME(?), FROM_UNIXTIME(?), ?, ?, sslcsr FROM certificate
} }
$subdom["fqdn"]=$subdom["sub"].(($subdom["sub"])?".":"").$subdom["domaine"]; $subdom["fqdn"]=$subdom["sub"].(($subdom["sub"])?".":"").$subdom["domaine"];
list($cert) = $this->get_valid_certs($fqdn, $subdom["provider"]); list($cert) = $this->get_valid_certs($subdom["fqdn"], $subdom["provider"]);
// Edit certif_hosts: // Edit certif_hosts:
$db->query("UPDATE sub_domaines SET certificate_id=? WHERE id=?;",array($cert["id"], $subdom["id"])); $db->query("UPDATE sub_domaines SET certificate_id=? WHERE id=?;",array($cert["id"], $subdom["id"]));
} }