From 3343aa803a6f63df21fea4ff727b119fff6e64da Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Tue, 16 Nov 2010 17:11:06 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20possibilit=C3=A9=20d'avoir=20?= =?UTF-8?q?des=20CNAME,=20TXT=20dans=20les=20DNS.=20Possibilit=C3=A9e=20d'?= =?UTF-8?q?avoir=20plusieurs=20entr=C3=A9e=20sur=20le=20m=C3=AAme=20sous-d?= =?UTF-8?q?omaine.=20ToDo=20:=20Merci=20aux=20experts=20Alternc=20de=20reg?= =?UTF-8?q?arder=20si=20j'ai=20mit=20les=20modifications=20de=20base=20dan?= =?UTF-8?q?s=20le=20bon=20fichier=20(install/upgrades/1.0.sql)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 1 + bureau/admin/dom_edit.php | 37 +++++++--- bureau/admin/dom_subdel.php | 4 +- bureau/admin/dom_subdodel.php | 3 +- bureau/admin/dom_subdoedit.php | 19 +++-- bureau/admin/dom_subedit.php | 38 ++++++++-- bureau/class/functions.php | 19 ++--- bureau/class/m_dom.php | 126 ++++++++++++++++++++++----------- install/upgrades/1.0.sql | 7 ++ src/functions.sh | 80 +++++++++++++++------ src/update_domains.sh | 4 +- 11 files changed, 245 insertions(+), 93 deletions(-) create mode 100644 install/upgrades/1.0.sql diff --git a/.gitattributes b/.gitattributes index 22094445..c40af3bd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -392,6 +392,7 @@ install/upgrades/0.9.5.sql -text install/upgrades/0.9.6.sql -text install/upgrades/0.9.7.sql -text install/upgrades/0.9.9.sql -text +install/upgrades/1.0.sql -text install/upgrades/README -text man/alternc-admintools.8 -text man/alternc-admintools.fr.8 -text diff --git a/bureau/admin/dom_edit.php b/bureau/admin/dom_edit.php index ec1a7a73..7b829a5a 100644 --- a/bureau/admin/dom_edit.php +++ b/bureau/admin/dom_edit.php @@ -37,6 +37,9 @@ $fields = array ( "sub_local" => array ("request", "string", "/"), "sub_url" => array ("request", "string", "http://"), "sub_ip" => array ("request", "string", ""), + "sub_ipv6" => array ("request", "string", ""), + "sub_cname" => array ("request", "string", ""), + "sub_txt" => array ("request", "string", ""), ); getFields($fields); @@ -87,10 +90,10 @@ for($i=0;$i<$r["nsub"];$i++) { ?> -
&sub="><?php __(" />
+
&sub=&type="><?php __(" />
-
&sub="><?php __(" />
+
&sub=&type="><?php __(" />
" target="_blank"> '.htmlspecialchars($r["sub"][$i]["dest"]).'' : htmlspecialchars($r["sub"][$i]["dest"]); ?>  @@ -125,6 +128,11 @@ for($i=0;$i<$r["nsub"];$i++) { + + type_webmail); ?>/> + +   + type_ip); ?> onclick="document.main.sub_ip.focus();" /> @@ -132,18 +140,27 @@ for($i=0;$i<$r["nsub"];$i++) { - - type_ipv6); ?> onclick="document.main.sub_ip.focus();" /> + Advanced options + + type_ipv6); ?> onclick="document.main.sub_ipv6.focus();" /> - + - - - type_webmail); ?>/> - -   + + type_cname); ?> onclick="document.main.sub_cname.focus();" /> + + + + + type_txt); ?> onclick="document.main.sub_txt.focus();" /> + + + + + + " /> diff --git a/bureau/admin/dom_subdel.php b/bureau/admin/dom_subdel.php index 1b4f8b2f..efb99268 100644 --- a/bureau/admin/dom_subdel.php +++ b/bureau/admin/dom_subdel.php @@ -33,11 +33,12 @@ include_once("head.php"); $fields = array ( "domain" => array ("request", "string", ""), "sub" => array ("request", "string", ""), + "type" => array ("request", "string", ""), ); getFields($fields); $dom->lock(); -if (!$r=$dom->get_sub_domain_all($domain,$sub)) { +if (!$r=$dom->get_sub_domain_all($domain,$sub,$type)) { $error=$err->errstr(); } $dom->unlock(); @@ -60,6 +61,7 @@ $dom->unlock();

+ :

diff --git a/bureau/admin/dom_subdodel.php b/bureau/admin/dom_subdodel.php index 5e740d8c..7a12f819 100644 --- a/bureau/admin/dom_subdodel.php +++ b/bureau/admin/dom_subdodel.php @@ -33,12 +33,13 @@ include_once("head.php"); $fields = array ( "domain" => array ("request", "string", ""), "sub" => array ("request", "string", ""), + "type" => array ("request", "string", ""), ); getFields($fields); $dom->lock(); -if (!$dom->del_sub_domain($domain,$sub)) { +if (!$dom->del_sub_domain($domain,$sub,$type)) { $error=$err->errstr(); } diff --git a/bureau/admin/dom_subdoedit.php b/bureau/admin/dom_subdoedit.php index 6841fa5d..94eb226d 100644 --- a/bureau/admin/dom_subdoedit.php +++ b/bureau/admin/dom_subdoedit.php @@ -32,10 +32,13 @@ require_once("../class/config.php"); $fields = array ( "domain" => array ("request", "string", ""), "sub" => array ("request", "string", ""), + "type_old" => array ("request", "integer",""), "type" => array ("request", "integer", $dom->type_local), "sub_local" => array ("request", "string", "/"), "sub_url" => array ("request", "string", "http://"), "sub_ip" => array ("request", "string", ""), + "sub_txt" => array ("request", "string", ""), + "sub_cname" => array ("request", "string", ""), "sub_ipv6" => array ("request", "string", ""), "action" => array ("request", "string", "add"), ); @@ -45,19 +48,25 @@ $dom->lock(); switch ($type) { case $dom->type_local: - $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_local); + $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_local, $type_old); break; case $dom->type_url: - $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_url); + $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_url, $type_old); + break; + case $dom->type_txt: + $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_txt, $type_old); + break; + case $dom->type_cname: + $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_cname, $type_old); break; case $dom->type_ip: - $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ip); + $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ip, $type_old); break; case $dom->type_ipv6: - $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ipv6); + $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ipv6, $type_old); break; case $dom->type_webmail: - $r=$dom->set_sub_domain($domain,$sub,$type,$action,""); + $r=$dom->set_sub_domain($domain,$sub,$type,$action,"", $type_old); break; } $dom->unlock(); diff --git a/bureau/admin/dom_subedit.php b/bureau/admin/dom_subedit.php index b8b2404a..202d7b0e 100644 --- a/bureau/admin/dom_subedit.php +++ b/bureau/admin/dom_subedit.php @@ -38,13 +38,15 @@ $fields = array ( "sub_url" => array ("request", "string", "http://"), "sub_ip" => array ("request", "string", ""), "sub_ipv6" => array ("request", "string", ""), + "sub_cname" => array ("request", "string", ""), + "sub_txt" => array ("request", "string", ""), "action" => array ("request", "string", "add"), ); getFields($fields); $dom->lock(); if (!$noread) { - if (!$r=$dom->get_sub_domain_all($domain,$sub)) { + if (!$r=$dom->get_sub_domain_all($domain,$sub,$type)) { $error=$err->errstr(); ?>

http://

@@ -63,6 +65,12 @@ switch ($type) { case $dom->type_url: $sub_url=$r["dest"]; break; + case $dom->type_cname: + $sub_cname=$r["dest"]; + break; + case $dom->type_txt: + $sub_txt=$r["dest"]; + break; case $dom->type_ipv6: $sub_ipv6=$r["dest"]; break; @@ -93,6 +101,7 @@ $dom->unlock(); + type_local); ?> onclick="document.main.sub_local.focus();" /> @@ -117,17 +126,32 @@ $dom->unlock(); - - type_ipv6); ?> onclick="document.main.sub_ipv6.focus();" /> - - - - type_webmail); ?> />   + + Advanced options + + type_ipv6); ?> onclick="document.main.sub_ipv6.focus();" /> + + + + + + type_cname); ?> onclick="document.main.sub_cname.focus();" /> + + + + + + type_txt); ?> onclick="document.main.sub_txt.focus();" /> + + + + + " /> diff --git a/bureau/class/functions.php b/bureau/class/functions.php index c8e7855a..f3ce2a7b 100644 --- a/bureau/class/functions.php +++ b/bureau/class/functions.php @@ -115,22 +115,25 @@ function checkurl($url) { return true; } +/* Check that TXT domain is correct */ +function checksubtxt($txt) { + return true; +} +/* Check that CNAME domain is correct */ +function checkcname($cname) { + return true; +} + /* Check that $ip is a correct 4 Dotted ip */ function checkip($ip) { // return true or false whether the ip is correctly formatted - if (!ereg("[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*",$ip)) return false; - $l=explode(".",$ip); - if ($l[0]>255 || $l[1]>255 || $l[2]>255 || $l[3]>255) return false; - return true; + return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } /* Check that $ip is a correct ipv6 ip */ function checkipv6($ip) { // return true or false whether the ip is correctly formatted - $pattern = -'/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/'; - - return preg_match( $pattern, $ip ) ? TRUE : FALSE; + return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); } /* Check a login mail */ diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 44606a2e..f378404c 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -71,6 +71,8 @@ class m_dom { var $type_ip = "2"; var $type_webmail = "3"; var $type_ipv6 = "4"; + var $type_cname = "5"; + var $type_txt = "6"; var $action_insert = "0"; var $action_update= "1"; @@ -631,7 +633,7 @@ class m_dom { * $r["type"]= Type (0-n) de la redirection. * Retourne FALSE si une erreur s'est produite. */ - function get_sub_domain_all($dom,$sub) { + function get_sub_domain_all($dom,$sub, $type = "") { global $db,$err,$cuid; $err->log("dom","get_sub_domain_all",$dom."/".$sub); // Locked ? @@ -644,7 +646,10 @@ class m_dom { $err->raise("dom",3+$t); return false; } - $db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub'"); + if ( ! empty($type)) { + $type = " and type='".intval($type)."'"; + } + $db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub' $type"); if ($db->num_rows()==0) { $err->raise("dom",14); return false; @@ -675,7 +680,8 @@ class m_dom { * de $type (url, ip, dossier...) * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. */ - function set_sub_domain($dom,$sub,$type,$action,$dest) { + function set_sub_domain($dom,$sub,$type,$action,$dest, $type_old=null) { + if (is_null($type_old)) $type_old=$type; global $db,$err,$cuid; $err->log("dom","set_sub_domain",$dom."/".$sub); // Locked ? @@ -697,29 +703,41 @@ class m_dom { } if ($type==2) { // IP if (!checkip($dest)) { - $err->raise("dom",19); - return false; + $err->raise("dom",19); + return false; } } if ($type==4) { // IPv6 if (!checkipv6($dest)) { - $err->raise("dom",19); - return false; + $err->raise("dom",19); + return false; + } + } + if ($type==5) { // Cname + if (!checkcname($dest)) { + $err->raise("dom",19); + return false; + } + } + if ($type==6) { // TXT + if (!checksubtxt($dest)) { + $err->raise("dom",19); + return false; } } if ($type==1) { // URL if (!checkurl($dest)) { - $err->raise("dom",20); - return false; + $err->raise("dom",20); + return false; } } if ($type==0) { // LOCAL if (substr($dest,0,1)!="/") { - $dest="/".$dest; + $dest="/".$dest; } if (!checkuserpath($dest)) { - $err->raise("dom",21); - return false; + $err->raise("dom",21); + return false; } } // On a épuré $dir des problèmes eventuels ... On est en DESSOUS du dossier de l'utilisateur. @@ -728,31 +746,59 @@ class m_dom { $err->raise("dom",3+$t); return false; } - if (!$r=$this->get_sub_domain_all($dom,$sub)) { - // Le sous-domaine n'existe pas, on le crée seulement si $action vaut add - if ($action=="add") { - $db->query("insert into sub_domaines (compte,domaine,sub,valeur,type) values ('$cuid','$dom','$sub','$dest',$type);"); - $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub';"); - $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',0);"); // INSERT - } else { - $err->raise("dom",14); - return false; - } + + + // Si l'action demandé est une création + if ($action=="add") { + $do_create=false; + // Tout d'abord on vérifie si il faut le créer + $r=$this->get_sub_domain_all($dom,$sub); + if ( !$r) { $do_create=true ;}; // If subdomains do not exist + if ($r and (!in_array($type, Array(0,1,3))) ) { // Les types URL, LOCAL et WEBMAIL ne peuvent pas être en doublon + foreach($r as $rr) { $rtype[] = $rr['type'];} // Tableau pour vérifier les compatibilitées de type + if ( + ( $type==$this->type_ipv6 and (in_array($this->type_cname, $rtype)) ) or + ( $type==$this->type_ipv4 and (in_array($this->type_cname, $rtype)) ) or + ( $type==$this->type_cname and (in_array($this->type_ipv4, $rtype)) ) or + ( $type==$this->type_cname and (in_array($this->type_ipv6, $rtype)) ) + ) { $do_create=false; } else {$do_create=true ;} + } + if ($do_create) { + // Tout est, je peux créer le sous-domaine + $db->query("insert into sub_domaines (compte,domaine,sub,valeur,type) values ('$cuid','$dom','$sub','$dest',$type);"); + $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub' and type=$type;"); + $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',0);"); // INSERT + } else { + $err->raise("dom",14); + return false; + } + }elseif ($action=="edit") { + // On vérifie que des modifications ont bien eu lieu :) + if ($r["type"]==$type && $r["dest"]==$dest) { + $err->raise("dom",15); + return false; + } + // OK, des modifs ont été faites, on valide : + //$db->query("update sub_domaines set type='$type', valeur='$dest' where domaine='$dom' and sub='$sub' and type='".$r["type"]."'"); + //$db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub' and type='".$r["type"]."'"); + //$db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',1);"); // UPDATE +/* +$type contient la valeur QUE LON VEUT DONNER au sous domaine +$type_old contient la valeur du subdomain QUE LON VEUX EDITER + +die(" XXXX type = $type ---- type_old = $type_old XXXX "); +*/ + if ($type != $type_old) { + $this->del_sub_domain($dom,$sub,$type_old); + $this->set_sub_domain($dom,$sub,$type,"add",$dest); + } else { + $db->query("update sub_domaines set type='$type', valeur='$dest' where domaine='$dom' and sub='$sub' and type='$type_old';"); + $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub' and type='$type_old';"); + $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',1);"); // UPDATE + } } else { - if ($action=="edit") { - // On vérifie que des modifications ont bien eu lieu :) - if ($r["type"]==$type && $r["dest"]==$dest) { - $err->raise("dom",15); - return false; - } - // OK, des modifs ont été faites, on valide : - $db->query("update sub_domaines set type='$type', valeur='$dest' where domaine='$dom' and sub='$sub'"); - $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub'"); - $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',1);"); // UPDATE - } else { - $err->raise("dom",16); - return false; - } + $err->raise("dom",16); + return false; } return true; } // set_sub_domain @@ -766,7 +812,7 @@ class m_dom { * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. * */ - function del_sub_domain($dom,$sub) { + function del_sub_domain($dom,$sub,$type) { global $db,$err,$cuid; $err->log("dom","del_sub_domain",$dom."/".$sub); // Locked ? @@ -779,14 +825,14 @@ class m_dom { $err->raise("dom",3+$t); return false; } - if (!$r=$this->get_sub_domain_all($dom,$sub)) { + if (!$r=$this->get_sub_domain_all($dom,$sub,$type)) { // Le sous-domaine n'existe pas, erreur $err->raise("dom",14); return false; } else { // OK, on valide : - $db->query("delete from sub_domaines where domaine='$dom' and sub='$sub'"); - $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub'"); + $db->query("delete from sub_domaines where domaine='$dom' and sub='$sub' and type='$type'"); + $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub' type='$type"); $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','".$r["dest"]."','".$r["type"]."',2);"); // DELETE } return true; diff --git a/install/upgrades/1.0.sql b/install/upgrades/1.0.sql new file mode 100644 index 00000000..e2907f5e --- /dev/null +++ b/install/upgrades/1.0.sql @@ -0,0 +1,7 @@ +-- Alter table to allow use of ipv6, cname and txt in dns record +ALTER TABLE sub_domaines_standby DROP PRIMARY KEY; +ALTER TABLE sub_domaines_standby ADD CONSTRAINT pk_SubDomainesStandby PRIMARY KEY (compte,domaine,sub,action,type); + +-- Alter table to allow use of ipv6, cname and txt in dns record +ALTER TABLE sub_domaines DROP PRIMARY KEY; +ALTER TABLE sub_domaines ADD CONSTRAINT pk_SubDomaines PRIMARY KEY (compte,domaine,sub,type); diff --git a/src/functions.sh b/src/functions.sh index 2bc14a14..e28f0356 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -105,13 +105,25 @@ change_host_ip() { if [ -z "$host" ]; then host="@" fi - if [ "$host_type" = "$TYPE_IPV6" ]; then - a_line="$host IN AAAA $ip" - pattern="^$host[[:space:]]*IN[[:space:]]*AAAA[[:space:]]*.*\$" - else - a_line="$host IN A $ip" - pattern="^$host[[:space:]]*IN[[:space:]]*A[[:space:]]*.*\$" - fi + + case "$host_type" in + "$TYPE_IPV6") + a_line="$host IN AAAA $ip" + pattern="^$host[[:space:]]*IN[[:space:]]*AAAA[[:space:]]+.+\$" + ;; + "$TYPE_CNAME") + a_line="$host IN CNAME $ip" + pattern="^$host[[:space:]]*IN[[:space:]]*CNAME[[:space:]]+.+\$" + ;; + "$TYPE_TXT") + a_line="$host IN TXT $ip" + pattern="^$host[[:space:]]*IN[[:space:]]*TXT[[:space:]]+.+\$" + ;; + *) + a_line="$host IN A $ip" + pattern="^$host[[:space:]]*IN[[:space:]]*A[[:space:]]+.+\$" + esac + if [ ! -f "$zone_file" ]; then echo "Should change $host.$domain, but can't find $zone_file." return 1 @@ -138,7 +150,7 @@ add_host() { local fqdn local vhost_directory - delete_host "$domain" "$host" + delete_host "$domain" "$host" "$host_type" if [ "$host" = "@" -o -z "$host" ]; then FQDN="$domain" @@ -146,16 +158,28 @@ add_host() { FQDN="$host.$domain" fi - if [ "$host_type" = "$TYPE_IP" ]; then - ip="$value" - elif [ "$host_type" = "$TYPE_IPV6" ]; then - ip="$value" - else - ip="$PUBLIC_IP" - if [ "$host_type" != "$TYPE_WEBMAIL" ]; then - add_to_php_override "$FQDN" - fi - fi + case "$host_type" in + "$TYPE_IP") + ip="$value" + ;; + "$TYPE_IPV6") + ip="$value" + ;; + "$TYPE_CNAME") + ip="$value" + ;; + "$TYPE_TXT") + ip="$value" + ;; + "$TYPE_WEBMAIL") + ip="$PUBLIC_IP" + add_to_php_override "$FQDN" + ;; + *) + ip="$PUBLIC_IP" + ;; + esac + if [ "$host" = "@" -o -z "$host" ]; then change_host_ip "$domain" "$ip" || true fqdn="$domain" @@ -203,10 +227,12 @@ add_host() { delete_host() { local domain="$1" local host="$2" + local host_type="$3" local domain_letter=`print_domain_letter "$domain"` local fqdn local escaped_host local escaped_fqdn + local pattern if [ "$host" = "@" -o -z "$host" ]; then fqdn="$domain" @@ -218,8 +244,22 @@ delete_host() { if [ -f "$ZONES_DIR/$domain" ] ; then cp -a -f "$ZONES_DIR/$domain" "$ZONES_DIR/$domain.$$" - sed -e "/^$escaped_host[[:space:]]*IN[[:space:]]*\(AAAA\|A\)[[:space:]]/d" \ - < "$ZONES_DIR/$domain" > "$ZONES_DIR/$domain.$$" + + case "$host_type" in + "$TYPE_IPV6") + pattern="/^$escaped_host[[:space:]]*IN[[:space:]]*AAAA[[:space:]]/d" + ;; + "$TYPE_CNAME") + pattern="/^$escaped_host[[:space:]]*IN[[:space:]]*CNAME[[:space:]]/d" + ;; + "$TYPE_TXT") + pattern="/^$escaped_host[[:space:]]*IN[[:space:]]*TXT[[:space:]]/d" + ;; + *) + pattern="/^$escaped_host[[:space:]]*IN[[:space:]]*A[[:space:]]/d" + esac + + sed -e "$pattern" < "$ZONES_DIR/$domain" > "$ZONES_DIR/$domain.$$" mv "$ZONES_DIR/$domain.$$" "$ZONES_DIR/$domain" increment_serial "$domain" add_to_named_reload "$domain" diff --git a/src/update_domains.sh b/src/update_domains.sh index c38b6423..4acad0e4 100755 --- a/src/update_domains.sh +++ b/src/update_domains.sh @@ -54,6 +54,8 @@ TYPE_URL=1 TYPE_IP=2 TYPE_WEBMAIL=3 TYPE_IPV6=4 +TYPE_CNAME=5 +TYPE_TXT=6 YES=1 if [ `id -u` -ne 0 ]; then @@ -226,7 +228,7 @@ while read user domain host value type action; do ;; $ACTION_DELETE) - delete_host "$domain" "$host" + delete_host "$domain" "$host" "$type" ;; *)