From bb83fe83e4ae03d09cabaaad92e73e48525319b6 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Fri, 28 Jan 2011 15:55:26 +0000 Subject: [PATCH] =?UTF-8?q?Nouvelle=20gestion=20des=20DNS,=20compl=C3=A9te?= =?UTF-8?q?ment=20repens=C3=A9e=20Nouvelle=20g=C3=A9n=C3=A9ration=20des=20?= =?UTF-8?q?formulaires=20Nouvelle=20gestions=20des=20HOST=20disponible=20(?= =?UTF-8?q?dynamique)=20Nouveau=20update=5Fdomains.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ToDo : - finir de tester/mettre au propre les DNS - intégrer la nouvelle gestion VHOST au reste On y crois, on se bat ! --- .gitattributes | 1 + bureau/admin/adm_domstype.php | 12 +- bureau/admin/adm_domstypedoedit.php | 2 +- bureau/admin/adm_domstypeedit.php | 21 +- bureau/admin/dom_edit.inc.php | 99 +++++ bureau/admin/dom_edit.php | 78 +--- bureau/admin/dom_subdel.php | 2 + bureau/admin/dom_subdodel.php | 3 +- bureau/admin/dom_subdoedit.php | 47 +-- bureau/admin/dom_subedit.php | 139 +------ bureau/class/m_dom.php | 301 +++++++------- debian/alternc.dirs | 1 + debian/alternc.postinst | 1 + etc/alternc/apache.conf | 1 + etc/alternc/apache2.conf | 1 + .../templates/bind/templates/named.template | 2 +- install/mysql.sql | 23 - install/upgrades/1.0.sql | 48 ++- src/dns.sh | 53 ++- src/functions.sh | 393 ++---------------- src/hosting_functions_v2.sh | 14 +- src/update_domains.sh | 323 ++++---------- 22 files changed, 518 insertions(+), 1047 deletions(-) create mode 100644 bureau/admin/dom_edit.inc.php mode change 100644 => 100755 src/functions.sh mode change 100755 => 100644 src/update_domains.sh diff --git a/.gitattributes b/.gitattributes index a66f9580..8d92b127 100644 --- a/.gitattributes +++ b/.gitattributes @@ -91,6 +91,7 @@ bureau/admin/direct.php -text bureau/admin/dom_add.php -text bureau/admin/dom_doadd.php -text bureau/admin/dom_dodel.php -text +bureau/admin/dom_edit.inc.php -text bureau/admin/dom_edit.php -text bureau/admin/dom_editdns.php -text bureau/admin/dom_subdel.php -text diff --git a/bureau/admin/adm_domstype.php b/bureau/admin/adm_domstype.php index 441f68d3..75310480 100644 --- a/bureau/admin/adm_domstype.php +++ b/bureau/admin/adm_domstype.php @@ -45,10 +45,6 @@ include_once("head.php"); echo "

$error

"; } -$dom = new m_dom(); -$r=$dom->domains_type_lst; -// die(print_r($dom->domains_type_lst())); - ?>

@@ -56,10 +52,9 @@ $r=$dom->domains_type_lst;

- - + @@ -70,13 +65,12 @@ foreach($dom->domains_type_lst() as $d) { ++$pair; ?> - - + - + diff --git a/bureau/admin/adm_domstypedoedit.php b/bureau/admin/adm_domstypedoedit.php index 91c78a66..a8ebc2a6 100644 --- a/bureau/admin/adm_domstypedoedit.php +++ b/bureau/admin/adm_domstypedoedit.php @@ -6,7 +6,7 @@ if (!$admin->enabled) { } -if ( ! $dom->domains_type_update($id, $name, $description, $ask_dest, $entry, $compatibility) ) { +if ( ! $dom->domains_type_update($name, $description, $target, $entry, $compatibility) ) { die($err->errstr()); } else { include("adm_domstype.php"); diff --git a/bureau/admin/adm_domstypeedit.php b/bureau/admin/adm_domstypeedit.php index 37c70d46..70e5a839 100644 --- a/bureau/admin/adm_domstypeedit.php +++ b/bureau/admin/adm_domstypeedit.php @@ -36,17 +36,16 @@ if (!$admin->enabled) { include_once("head.php"); $fields = array ( - "id" => array ("request", "integer", ""), "name" => array ("request", "string", ""), "description" => array ("request", "string", ""), - "ask_dest" => array ("request", "boolean", ""), + "target" => array ("request", "string", ""), "entry" => array ("request", "string", ""), "compatibility" => array ("request", "string", ""), ); getFields($fields); -if (! $d=$dom->domains_type_get($id)) { +if (! $d=$dom->domains_type_get($name)) { $error=$err->errstr(); echo $error; } else { @@ -63,19 +62,21 @@ if ($error_edit) { } ?> - +
- - - - - - + + diff --git a/bureau/admin/dom_edit.inc.php b/bureau/admin/dom_edit.inc.php new file mode 100644 index 00000000..81f1637a --- /dev/null +++ b/bureau/admin/dom_edit.inc.php @@ -0,0 +1,99 @@ +lock(); +if (!$r=$dom->get_domain_all($domain)) { + $error=$err->errstr(); +} +/* +if (! empty($sub)) { + if (!$sd=$dom->get_sub_domain_all($domain,$sub,$type,$value)) { + $error=$err->errstr(); + } +} +*/ +$sd=$dom->get_sub_domain_all($domain,$sub,$type,$value); + +$dom->unlock(); +?> + + +
/> + +
+ + + + domains_type_lst() as $dt) { + if (! $dt['enable']) continue; + if ( (! $r['dns'] ) and ($dt['need_dns']) ) continue; + $targval=(strtoupper($type)==strtoupper($dt['name']))?$sd['dest']:''; + ?> + + + + + + + + + + + + +
+ + + + + + +.
+ /> + + + + + + + + + + + + +
" />
+ + + + diff --git a/bureau/admin/dom_edit.php b/bureau/admin/dom_edit.php index 7b829a5a..b5cd9962 100644 --- a/bureau/admin/dom_edit.php +++ b/bureau/admin/dom_edit.php @@ -33,13 +33,6 @@ include_once("head.php"); $fields = array ( "domain" => array ("request", "string", ""), "sub" => array ("request", "string", ""), - "type" => array ("request", "integer", $dom->type_local), - "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); @@ -90,10 +83,10 @@ for($i=0;$i<$r["nsub"];$i++) { ?> -
&sub=&type="><?php __(" />
+
&sub=&type=&value="><?php __(" />
-
&sub=&type="><?php __(" />
+
&sub=&type=&value="><?php __(" />
" target="_blank"> '.htmlspecialchars($r["sub"][$i]["dest"]).'' : htmlspecialchars($r["sub"][$i]["dest"]); ?>  @@ -102,70 +95,11 @@ for($i=0;$i<$r["nsub"];$i++) {

+
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- " /> - - -.
type_local); ?> onclick="document.main.sub_local.focus();" /> - - -
type_url); ?> onclick="document.main.sub_url.focus();" /> -
type_webmail); ?>/> -  
type_ip); ?> onclick="document.main.sub_ip.focus();" /> -
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();" /> -
" />
-
show_help("edit_domain"); ?>

 

 

diff --git a/bureau/admin/dom_subdel.php b/bureau/admin/dom_subdel.php index efb99268..6449b6f7 100644 --- a/bureau/admin/dom_subdel.php +++ b/bureau/admin/dom_subdel.php @@ -34,6 +34,7 @@ $fields = array ( "domain" => array ("request", "string", ""), "sub" => array ("request", "string", ""), "type" => array ("request", "string", ""), + "value" => array ("request", "string", ""), ); getFields($fields); @@ -62,6 +63,7 @@ $dom->unlock(); + :

diff --git a/bureau/admin/dom_subdodel.php b/bureau/admin/dom_subdodel.php index 7a12f819..b6b80185 100644 --- a/bureau/admin/dom_subdodel.php +++ b/bureau/admin/dom_subdodel.php @@ -34,12 +34,13 @@ $fields = array ( "domain" => array ("request", "string", ""), "sub" => array ("request", "string", ""), "type" => array ("request", "string", ""), + "value" => array ("request", "string", ""), ); getFields($fields); $dom->lock(); -if (!$dom->del_sub_domain($domain,$sub,$type)) { +if (!$dom->del_sub_domain($domain,$sub,$type,$value)) { $error=$err->errstr(); } diff --git a/bureau/admin/dom_subdoedit.php b/bureau/admin/dom_subdoedit.php index 94eb226d..35326992 100644 --- a/bureau/admin/dom_subdoedit.php +++ b/bureau/admin/dom_subdoedit.php @@ -32,43 +32,26 @@ 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"), + "sub_old" => array ("request", "string", ""), + "type" => array ("request", "string", $dom->type_local), + "type_old" => array ("request", "string", ""), + "value_old" => array ("request", "string", ""), ); getFields($fields); +// here we get a dynamic-named value +$dynamicvar="t_$type"; +$fields = array ( + "$dynamicvar" => array ("request", "string", ""), +); +getFields($fields); +$value=$$dynamicvar; +// The dynamic value is now in $value + $dom->lock(); -switch ($type) { - case $dom->type_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, $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, $type_old); - break; - case $dom->type_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,"", $type_old); - break; -} +$r=$dom->set_sub_domain($domain,$sub,$type,$value, $type_old, $sub_old, $value_old); + $dom->unlock(); if (!$r) { diff --git a/bureau/admin/dom_subedit.php b/bureau/admin/dom_subedit.php index 202d7b0e..f7c4c9e6 100644 --- a/bureau/admin/dom_subedit.php +++ b/bureau/admin/dom_subedit.php @@ -30,136 +30,39 @@ require_once("../class/config.php"); include_once("head.php"); + $fields = array ( "domain" => array ("request", "string", ""), "sub" => array ("request", "string", ""), - "type" => array ("request", "integer", $dom->type_local), - "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", ""), - "action" => array ("request", "string", "add"), + "type" => array ("request", "string", $dom->type_local), + "value" => array ("request", "string", ""), ); getFields($fields); $dom->lock(); +$domroot=$dom->get_domain_all($domain); if (!$noread) { - if (!$r=$dom->get_sub_domain_all($domain,$sub,$type)) { + if (!$r=$dom->get_sub_domain_all($domain,$sub,$type,$value)) { $error=$err->errstr(); - ?> -

http://

-"; +__("Editing subdomain"); +echo " http://"; ecif($sub,$sub."."); echo $domain.""; +if ($error) { echo "

$error

"; - include_once("foot.php"); - exit(); - } - -$sub=$r["name"]; -$type=$r["type"]; -switch ($type) { - case $dom->type_local: - $sub_local=$r["dest"]; - break; - 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; - case $dom->type_ip: - $sub_ip=$r["dest"]; - break; - case $dom->type_webmail: - break; - } - } - + include_once("foot.php"); + exit(); +} $dom->unlock(); +?> -?> -

http://

-$error

"; - } -?>

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - +type_local; ?>" type_local); ?> onclick="document.main.sub_local.focus();" /> - - -
type_url); ?> onclick="document.main.sub_url.focus();" /> -
type_ip); ?> onclick="document.main.sub_ip.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();" /> -
- " /> - " onclick="document.location='dom_edit.php?domain='" /> -
- -
- +include_once("foot.php"); +?> diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index cbe9d90a..318d3412 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -66,13 +66,13 @@ class m_dom { */ var $islocked=false; - var $type_local = "0"; - var $type_url = "1"; - var $type_ip = "2"; - var $type_webmail = "3"; - var $type_ipv6 = "4"; - var $type_cname = "5"; - var $type_txt = "6"; + var $type_local = "LOCAL"; + var $type_url = "URL"; + var $type_ip = "IP"; + var $type_webmail = "WEBMAIL"; + var $type_ipv6 = "IPV6"; + var $type_cname = "CNAME"; + var $type_txt = "TXT"; var $action_insert = "0"; var $action_update= "1"; @@ -102,7 +102,7 @@ class m_dom { function domains_type_lst() { global $db,$err,$cuid; $err->log("dom","domains_type_lst"); - $db->query("select * from domaines_type order by id;"); + $db->query("select * from domaines_type order by name;"); $this->domains_type_lst=false; while ($db->next_record()) { $this->domains_type_lst[] = $db->Record; @@ -110,18 +110,38 @@ class m_dom { return $this->domains_type_lst; } - function domains_type_get($id) { + function domains_type_target_values($type=null) { + global $db,$err,$cuid; + $err->log("dom","domains_type_target_values"); + if (is_null($type)) { + $db->query("desc domaines_type;"); + $r = array(); + while ($db->next_record()) { + if ($db->f('Field') == 'target') { + $tab = explode(",", substr($db->f('Type'), 5, -1)); + foreach($tab as $t) { $r[]=substr($t,1,-1); } + } + } + return $r; + } else { + $db->query("select target from domaines_type where name='$type';"); + if (! $db->next_record()) return false; + return $db->f('target'); + } + } + + function domains_type_get($name) { global $db,$err,$cuid; - $id=intval($id); - $db->query("select * from domaines_type where id = $id ;"); + $name=mysql_real_escape_string($name); + $db->query("select * from domaines_type where name='$name' ;"); $db->next_record(); return $db->Record; } - function domains_type_del($id) { + function domains_type_del($name) { global $db,$err,$cuid; - $id=intval($id); - $db->query("delete domaines_type where id=$id;"); + $name=mysql_real_escape_string($name); + $db->query("delete domaines_type where name='$name';"); return true; } @@ -139,15 +159,15 @@ class m_dom { return true; } - function domains_type_update($id, $name, $description, $ask_dest, $entry, $compatibility) { + function domains_type_update($name, $description, $target, $entry, $compatibility) { global $err,$cuid,$db; $id=intval($id); $name=mysql_real_escape_string($name); $description=mysql_real_escape_string($description); - $ask_dest=intval($ask_dest); + $target=mysql_real_escape_string($target); $entry=mysql_real_escape_string($entry); $compatibility=mysql_real_escape_string($compatibility); - $db->query("UPDATE domaines_type SET name='$name', description='$description', ask_dest='$ask_dest', entry='$entry', compatibility='$compatibility' where id='$id';"); + $db->query("UPDATE domaines_type SET description='$description', target='$target', entry='$entry', compatibility='$compatibility' where name='$name';"); return true; } @@ -199,21 +219,20 @@ class m_dom { $err->raise("dom",2,$dom); return false; } - $db->query("INSERT INTO domaines_standby (compte,domaine,mx,gesdns,gesmx,action) SELECT compte,domaine,mx,gesdns,gesmx,2 FROM domaines WHERE domaine='$dom'"); // DELETE - $db->query("DELETE FROM domaines WHERE domaine='$dom';"); - $db->query("DELETE FROM sub_domaines WHERE domaine='$dom';"); + $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE domaine='$dom';"); + $db->query("UPDATE domaines SET dns_action='DELETE' WHERE domaine='$dom';"); // DEPENDANCE : // Lancement de del_dom sur les classes domain_sensitive : // Declenchons les autres classes. foreach($classes as $c) { if (method_exists($GLOBALS[$c],"alternc_del_domain")) { - $GLOBALS[$c]->alternc_del_domain($dom); + $GLOBALS[$c]->alternc_del_domain($dom); } } foreach($classes as $c) { if (method_exists($GLOBALS[$c],"alternc_del_mx_domain")) { - $GLOBALS[$c]->alternc_del_mx_domain($dom); + $GLOBALS[$c]->alternc_del_mx_domain($dom); } } return true; @@ -276,11 +295,6 @@ class m_dom { $err->raise("dom",8); return false; } - $db->query("select compte from domaines_standby where domaine='$domain';"); - if ($db->num_rows()!=0) { - $err->raise("dom",9); - return false; - } $this->dns=$this->whois($domain); if (!$force) { $v=checkhostallow($domain,$this->dns); @@ -316,8 +330,7 @@ class m_dom { return false; } if ($noerase) $noerase="1"; else $noerase="0"; - $db->query("insert into domaines (compte,domaine,mx,gesdns,gesmx,noerase) values ('$cuid','$domain','$L_MX','$dns','$mx','$noerase');"); - $db->query("insert into domaines_standby (compte,domaine,mx,gesdns,gesmx,action) values ('$cuid','$domain','$L_MX','$dns','$mx',0);"); // INSERT + $db->query("insert into domaines (compte,domaine,mx,gesdns,gesmx,noerase,dns_action) values ('$cuid','$domain','$L_MX','$dns','$mx','$noerase','UPDATE');"); if ($isslave) { $isslave=true; @@ -328,9 +341,9 @@ class m_dom { $isslave=false; } // Point to the master domain : - $this->set_sub_domain($domain, '', $this->type_url,'add', 'http://www.'.$slavedom); - $this->set_sub_domain($domain, 'www', $this->type_url,'add', 'http://www.'.$slavedom); - $this->set_sub_domain($domain, 'mail', $this->type_url,'add', 'http://mail.'.$slavedom); + $this->set_sub_domain($domain, '', $this->type_url, 'http://www.'.$slavedom); + $this->set_sub_domain($domain, 'www', $this->type_url, 'http://www.'.$slavedom); + $this->set_sub_domain($domain, 'mail', $this->type_url, 'http://mail.'.$slavedom); } if (!$isslave) { // Creation du repertoire dans www @@ -342,9 +355,9 @@ class m_dom { } // Creation des 3 sous-domaines par défaut : Vide, www et mail - $this->set_sub_domain($domain, '', $this->type_url, 'add', 'http://www.'.$domain); - $this->set_sub_domain($domain, 'www', $this->type_local, 'add', '/'. $domshort); - $this->set_sub_domain($domain, 'mail', $this->type_webmail, 'add', ''); + $this->set_sub_domain($domain, '', $this->type_url, 'http://www.'.$domain); + $this->set_sub_domain($domain, 'www', $this->type_local, '/'. $domshort); + $this->set_sub_domain($domain, 'mail', $this->type_webmail, ''); } // DEPENDANCE : // Lancement de add_dom sur les classes domain_sensitive : @@ -571,9 +584,6 @@ class m_dom { /** * retourne TOUTES les infos d'un domaine * - * Note : si le domaine est en attente (présent dans - * domaines_standby), une erreur est retournée - * * @param string $dom Domaine dont on souhaite les informations * @return array Retourne toutes les infos du domaine sous la forme d'un * tableau associatif comme suit :
@@ -604,11 +614,6 @@ class m_dom {
       return false;
     }
     $r["name"]=$dom;
-    $db->query("select * from domaines_standby where compte='$cuid' and domaine='$dom'");
-    if ($db->num_rows()>0) {
-      $err->raise("dom",13);
-      return false;
-    }
     $db->query("select * from domaines where compte='$cuid' and domaine='$dom'");
     if ($db->num_rows()==0) {
       $err->raise("dom",1,$dom);
@@ -633,10 +638,12 @@ class m_dom {
       $r["sub"][$i]["name"]=$db->Record["sub"];
       $r["sub"][$i]["dest"]=$db->Record["valeur"];
       $r["sub"][$i]["type"]=$db->Record["type"];
+/*
       if ($db->Record["type"]==3) { // Webmail
 	$this->webmail=1;
 	$r["sub"][$i]["dest"]=_("Webmail access");
       }
+*/
     }
     $db->free();
     return $r;
@@ -657,7 +664,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, $type = "") {
+  function get_sub_domain_all($dom,$sub, $type="", $value='') {
     global $db,$err,$cuid;
     $err->log("dom","get_sub_domain_all",$dom."/".$sub);
     // Locked ?
@@ -670,10 +677,15 @@ class m_dom {
       $err->raise("dom",3+$t);
       return false;
     }
-    if ( ! empty($type)) {
-        $type = " and type='".intval($type)."'";
+/*
+    if ( ! empty($value)) {
+        $type = " and valeur=\"".mysql_real_escape_string($value)."\"";
     }
-    $db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub' $type");
+    if ( ! empty($type)) {
+        $type = " and type=\"".mysql_real_escape_string($type)."\"";
+    }
+*/
+    $db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub' and ( length('$type')=0 or type='$type') and (length('$value')=0 or '$value'=valeur);");
     if ($db->num_rows()==0) {
       $err->raise("dom",14);
       return false;
@@ -688,7 +700,66 @@ class m_dom {
   } // get_sub_domain_all
 
 
-  /* ----------------------------------------------------------------- */
+  function check_type_value($type, $value) {
+    // check the type we can have in domaines_type.target
+
+    switch ($this->domains_type_target_values($type)) {
+      case 'NONE':
+        if (empty($value) or is_null($value)) {return true;}
+        break;
+      case 'URL': 
+        if ( $value == strval($value)) {return true;}
+        break;
+      case 'DIRECTORY': 
+        if (substr($value,0,1)!="/") {
+          $value="/".$value;
+        }
+        if (!checkuserpath($value)) {
+          $err->raise("dom",21);
+        return false;
+        }
+        break;
+      case 'IP': 
+        if (checkip($value)) {return true;}
+        break;
+      case 'IPV6': 
+        if (checkipv6($value)) {return true;}
+        break;
+      case 'DOMAIN': 
+        if (checkcname($value)) {return true;}
+        break;
+      case 'TXT':
+        if ( $value == strval($value)) {return true;}
+        break;
+      default:
+        return false;
+        break;
+    }
+    return false;
+  } //check_type_value
+
+
+  function can_create_subdomain($dom,$sub,$type) {
+    global $db,$err,$cuid;
+    $err->log("dom","can_create_subdomain",$dom."/".$sub);
+
+    # Get the compatibility list for this domain type
+    $db->query("select upper(compatibility) as compatibility from domaines_type where upper(name)=upper('$type');");
+    if (!$db->next_record()) return false;
+    $compatibility_lst = explode(",",$db->f('compatibility'));
+
+    # Get the list of type of subdomains already here who have the same name
+    $db->query("select distinct type from sub_domaines where sub='$sub' and domaine='$dom';");
+    while ($db->next_record()) {
+      # And if there is a domain with a incompatible type, return false
+      if (! in_array(strtoupper($db->f('type')),$compatibility_lst)) return false;
+    }
+    
+    # All is right, go ! Create ur domain !
+    return true;
+  }
+
+  //  /* ----------------------------------------------------------------- */
   /**
    * Modifier les information du sous-domaine demandé.
    *
@@ -704,8 +775,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, $type_old=null) {
-    if (is_null($type_old)) $type_old=$type;
+   // TODO : j'ai viré le type action, valider que plus personne ne l'utilise (quatrieme argument)
+  function set_sub_domain($dom,$sub,$type,$dest, $type_old=null,$sub_old=null,$value_old=null) {
     global $db,$err,$cuid;
     $err->log("dom","set_sub_domain",$dom."/".$sub);
     // Locked ?
@@ -725,108 +796,38 @@ class m_dom {
       $err->raise("dom",24);
       return false;
     }
-    if ($type==2) { // IP
-      if (!checkip($dest)) {
-	    $err->raise("dom",19);
-	    return false;
-      }
-    }
-    if ($type==4) { // IPv6
-      if (!checkipv6($dest)) {
-	    $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;
-      }
-    }
-    if ($type==0) { // LOCAL
-      if (substr($dest,0,1)!="/") {
-	    $dest="/".$dest;
-      }
-      if (!checkuserpath($dest)) {
-	    $err->raise("dom",21);
-    	return false;
-      }
+
+    if (! $this->check_type_value($type,$dest)) {
+      # TODO have a real err code
+      $err->raise("dom",667);
+      return false;
     }
+
     // On a épuré $dir des problèmes eventuels ... On est en DESSOUS du dossier de l'utilisateur.
-    $t=checkfqdn($dom);
-    if ($t) {
+    if ($t=checkfqdn($dom)) {
       $err->raise("dom",3+$t);
       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 {
-        $err->raise("dom",16);
-        return false;
+    if (! $this->can_create_subdomain($dom,$sub,$type)) {
+      # TODO have a real error code
+      $err->raise("dom", 654);
+      return false;
     }
+
+    if (! is_null($type_old )) { // It's not a creation, it's an edit. Delete the old one
+      $db->query("delete from sub_domaines where domaine='$dom' and sub='$sub' and upper(type)=upper('$type_old') and valeur='$value_old';");
+    }
+
+    // Re-create the one we want
+    $db->query("insert into sub_domaines (compte,domaine,sub,valeur,type,web_action) values ('$cuid','$dom','$sub','$dest','$type','UPDATE');");
+    // Tell to update the DNS file
+    $db->query("update domaines set dns_action='UPDATE' where domaine='$dom';");
+
     return true;
   } // set_sub_domain
 
+
   /* ----------------------------------------------------------------- */
   /**
    *  Supprime le sous-domaine demandé
@@ -836,7 +837,7 @@ die(" XXXX type = $type ---- type_old = $type_old XXXX ");
    * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
    *
    */
-  function del_sub_domain($dom,$sub,$type) {
+  function del_sub_domain($dom,$sub,$type,$value='') {
     global $db,$err,$cuid;
     $err->log("dom","del_sub_domain",$dom."/".$sub);
     // Locked ?
@@ -855,9 +856,8 @@ die(" XXXX type = $type ---- type_old = $type_old XXXX ");
       return false;
     } else {
       // OK, on valide :
-      $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
+      $db->query("delete from sub_domaines where domaine='$dom' and sub='$sub' and type='$type' and ( length('$value')=0 or valeur='$value') ");
+      $db->query("update domaines set dns_action='UPDATE' where domaine='$dom';");
     }
     return true;
   } // del_sub_domain
@@ -959,13 +959,8 @@ die(" XXXX type = $type ---- type_old = $type_old XXXX ");
     }
     
     $db->query("UPDATE domaines SET gesdns='$dns', mx='$mx', gesmx='$gesmx' WHERE domaine='$dom'");
-    $db->query("INSERT INTO domaines_standby (compte,domaine,mx,gesdns,gesmx,action) VALUES ('$cuid','$dom','$mx','$dns','$gesmx',1);"); 
-    // If we go from NODNS to YESDNS, we HAVE TO recreate all the subdomains of this domain in the bind zone file
-    // This code will fix Ticket 517
-    if ($dns==1 && $r["dns"]==0) {
-      $db->query("INSERT INTO sub_domaines_standby SELECT compte,domaine,sub,valeur,type,1 FROM sub_domaines WHERE domaine='$dom';");
-    }
-    
+    $db->query("UPDATE domaines set dns_action='UPDATE' where domaine='$dom';");
+
     return true;
   } // edit_domain
   
diff --git a/debian/alternc.dirs b/debian/alternc.dirs
index 8a0fc309..4b0104cd 100644
--- a/debian/alternc.dirs
+++ b/debian/alternc.dirs
@@ -15,6 +15,7 @@ usr/sbin
 usr/share/alternc/install
 usr/share/locale/fr/LC_MESSAGES
 usr/share/lintian/overrides/
+var/alternc/apache-vhost
 var/alternc/apacheconf
 var/alternc/apacheconf/_
 var/alternc/apacheconf/0
diff --git a/debian/alternc.postinst b/debian/alternc.postinst
index f449220a..fe080700 100644
--- a/debian/alternc.postinst
+++ b/debian/alternc.postinst
@@ -227,6 +227,7 @@ EOF
     /usr/lib/alternc/slave_dns
     # Apache will not start without this file
     touch /var/alternc/apacheconf/override_php.conf
+    touch /var/alternc/apache-vhost/vhosts_all.conf
 
     # Update l18n files
     /usr/share/alternc/install/dopo.sh
diff --git a/etc/alternc/apache.conf b/etc/alternc/apache.conf
index 61b32111..6734ece7 100644
--- a/etc/alternc/apache.conf
+++ b/etc/alternc/apache.conf
@@ -39,3 +39,4 @@ ScriptAlias /cgi-bin/ /var/alternc/cgi-bin/
 
 
 Include /etc/alternc/bureau.conf
+Include /var/alternc/apache-vhost/vhosts_all.conf
diff --git a/etc/alternc/apache2.conf b/etc/alternc/apache2.conf
index 577b4698..661be7bb 100644
--- a/etc/alternc/apache2.conf
+++ b/etc/alternc/apache2.conf
@@ -46,3 +46,4 @@ ScriptAlias /cgi-bin/ /var/alternc/cgi-bin/
 
 
 Include /etc/alternc/bureau.conf
+Include /var/alternc/apache-vhost/vhosts_all.conf
diff --git a/etc/alternc/templates/bind/templates/named.template b/etc/alternc/templates/bind/templates/named.template
index 14ec981b..9c7f7cff 100644
--- a/etc/alternc/templates/bind/templates/named.template
+++ b/etc/alternc/templates/bind/templates/named.template
@@ -1 +1 @@
-zone "@@DOMAINE@@" { type master; file "/var/alternc/bind/zones/@@DOMAINE@@"; allow-query { any; }; };
+zone "@@DOMAINE@@" { type master; file "@@ZONE_FILE@@"; allow-query { any; }; };
diff --git a/install/mysql.sql b/install/mysql.sql
index 0d0aa452..78d56b1a 100644
--- a/install/mysql.sql
+++ b/install/mysql.sql
@@ -504,26 +504,3 @@ VALUES (
 'subadmin_restriction', '', 
 'This variable set the way the account list works for accounts other than "admin" (2000). 0 (default) = admin other than admin/2000 can see their own account, but not the other one 1 = admin other than admin/2000 can see any account by clicking the ''show all accounts'' link. '
 );
-
-CREATE TABLE IF NOT EXISTS `domaines_type` (
-    `id` INTEGER NOT NULL ,
-    `name` VARCHAR (255) NOT NULL,
-    `description` TEXT,
-    `ask_dest` BOOLEAN DEFAULT FALSE,
-    `entry` VARCHAR (255) DEFAULT '',
-    `compatibility` VARCHAR (255) DEFAULT '',
-    `enable` BOOLEAN DEFAULT TRUE,
-PRIMARY KEY ( `id` )
-) COMMENT = 'Type of domains allowed';
-
-INSERT IGNORE INTO `domaines_type` (id, name, description, ask_dest, entry, compatibility) values
-(0, 'local','local redirection', false, '%SUB% IN A @@PUBLIC_IP@@', '6'),
-(1, 'url','url redirection', false, '%SUB% IN A @@PUBLIC_IP@@','6'),
-(2, 'ip','ip address', true, '%SUB% IN A %TARGET%','2,4,6'),
-(3, 'webmail', 'webmail', false, '%SUB% IN A @@PUBLIC_IP@@', '6'),
-(4, 'ipv6','ipv6 address', true, '%SUB% IN AAAA %TARGET%','2,4,6'),
-(5, 'cname', 'cname entry', true, '%SUB% CNAME %TARGET%', '6'),
-(6, 'txt', 'txt entry', true, '%SUB% IN TXT "%TARGET%"','0,1,2,3,4,5,6'),
-(7, 'mx', 'mx entry', true, '%SUB% IN MX %TARGET%', '0,1,2,3,4,5,6')
-;
-
diff --git a/install/upgrades/1.0.sql b/install/upgrades/1.0.sql
index 33008c7e..40cec9c8 100644
--- a/install/upgrades/1.0.sql
+++ b/install/upgrades/1.0.sql
@@ -1,10 +1,48 @@
--- 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);
+ALTER TABLE sub_domaines ADD CONSTRAINT pk_SubDomaines PRIMARY KEY (compte,domaine,sub,type,valeur);
 
 -- Alter table mail_domain to add support of temporary mail
 ALTER TABLE mail_domain ADD expiration_date datetime DEFAULT null;
+
+-- Domains type
+CREATE TABLE IF NOT EXISTS `domaines_type` (
+    `name` VARCHAR (255) NOT NULL, -- Uniq name
+    `description` TEXT, -- Human description
+    `target` enum ('NONE', 'URL', 'DIRECTORY', 'IP', 'IPV6', 'DOMAIN', 'TXT') NOT NULL DEFAULT 'NONE', -- Target type
+    `entry` VARCHAR (255) DEFAULT '', -- BIND entry
+    `compatibility` VARCHAR (255) DEFAULT '', -- Which type can be on the same subdomains
+    `enable` BOOLEAN DEFAULT TRUE, -- Show this options to the users ?
+    `only_dns` BOOLEAN DEFAULT FALSE, -- Update_domains modify just the dns, no web configuration
+    `need_dns` BOOLEAN DEFAULT TRUE, -- The server need to be the DNS to allow this service
+PRIMARY KEY ( `name` )
+) COMMENT = 'Type of domains allowed';
+
+INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, only_dns, need_dns) values
+('local','Locally managed', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'txt', false, false),
+('url','URL redirection', 'URL', '%SUB% IN A @@PUBLIC_IP@@','txt', true, true),
+('ip','IP redirection', 'IP', '%SUB% IN A %TARGET%','url,ip,ipv6,txt', true, true),
+('webmail', 'Webmail access', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'txt', false, false),
+('ipv6','ipv6 address', 'IPV6', '%SUB% IN AAAA %TARGET%','ip,ipv6,webmail,txt',true, true),
+('cname', 'cname entry', 'DOMAIN', '%SUB% CNAME %TARGET%', 'txt',true, true),
+('txt', 'txt entry', 'TXT', '%SUB% IN TXT "%TARGET%"','local,url,ip,webmail,ipv6,cname,txt',true, true),
+('mx', 'mx entry', 'IP', '%SUB% IN MX %TARGET%', 'local,url,ip,webmail,ipv6,cname,txt',true, false)
+;
+
+-- Changing stanby use
+-- TODO modify mysql.sh to add this changes
+alter table domaines add column dns_action enum ('OK','UPDATE','DELETE') NOT NULL default 'UPDATE';
+alter table domaines add column dns_result varchar(255) not null default '';
+alter table sub_domaines add column web_action enum ('OK','UPDATE','DELETE') NOT NULL default 'UPDATE';
+alter table sub add column dns_result varchar(255) not null default '';
+drop table sub_domaines_standby;
+drop table domaines_standby;
+
+update sub_domaines set type='LOCAL' where type='0';
+update sub_domaines set type='URL' where type='1';
+update sub_domaines set type='IP' where type='2';
+update sub_domaines set type='WEBMAIL' where type='3';
+update sub_domaines set type='IPV6' where type='4';
+update sub_domaines set type='CNAME' where type='5';
+update sub_domaines set type='TXT' where type='6';
+
diff --git a/src/dns.sh b/src/dns.sh
index 936fd11e..4fb38da0 100755
--- a/src/dns.sh
+++ b/src/dns.sh
@@ -1,13 +1,14 @@
 #!/bin/bash
 # dns.sh next-gen by Fufroma
 
-# Init some vars
+# Init some vars
 . /etc/alternc/local.sh
+. /usr/lib/alternc/functions.sh
 
 # Init some other vars
-MYSQL_DO="mysql --defaults-file=/etc/alternc/my.cnf -Bs -e "
 ZONE_TEMPLATE="/etc/alternc/templates/bind/templates/zone.template"
-NAMED_TEMPLATE="/etc/bind/templates/named.template"
+NAMED_TEMPLATE="/etc/alternc/templates/bind/templates/named.template"
+NAMED_CONF="/var/alternc/bind/automatic.conf"
 
 dns_zone_file() {
     echo "$ALTERNC_LOC/bind/zones/$1"
@@ -15,7 +16,10 @@ dns_zone_file() {
 
 dns_is_locked() {
     local domain=$1
-    grep "LOCKED:YES" "$(dns_zone_file $domain)" &> /dev/null 
+    if [ ! -r "$(dns_zone_file $domain)" ] ; then
+      return 1
+    fi
+    grep "LOCKED:YES" "$(dns_zone_file $domain)"
     return $?
 }
 
@@ -37,13 +41,43 @@ dns_chmod() {
     return 0
 }
 
+dns_named_conf() {
+  local domain=$1
+
+  if [ ! -f "$(dns_zone_file $domain)" ] ; then
+    echo Error : no file $(dns_zone_file $domain)
+    return 1
+  fi
+
+  grep -q "$domain" "$NAMED_CONF"
+  if [ $? -ne 0 ] ; then
+    local tempo=$(cat "$NAMED_TEMPLATE")
+    tempo=${tempo/@@DOMAINE@@/$domain}
+    tempo=${tempo/@@ZONE_FILE@@/$(dns_zone_file $domain)}
+    echo $tempo >> "$NAMED_CONF"
+  fi
+}
+
+dns_delete() {
+  local domain=$1
+
+  # Delete the zone file
+  if [ -w $(dns_zone_file $domain) ] ; then
+    rm -f $(dns_zone_file $domain)
+  fi
+
+  # Remove from the named conf
+  local file=$(cat "$NAMED_CONF")
+  echo -e "$file" |grep -v "\"$domain\"" > "$NAMED_CONF"
+}
+
 # DNS regenerate
 dns_regenerate() {
     local domain=$1
     local manual_tag=";;; END ALTERNC AUTOGENERATE CONFIGURATION"
     local zone_file=$(dns_zone_file $domain)
 
-    # Check if locked
+    # Check if locked
     dns_is_locked "$domain"
     if [ $? -eq 0 ]; then
         echo "DNS $domain LOCKED" 
@@ -59,11 +93,11 @@ dns_regenerate() {
     # Add the entry
     file=$(
         echo -e "$file"
-        $MYSQL_DO "select replace(replace(dt.entry,'%TARGET%',sd.valeur), '%SUB%', sd.sub) from sub_domaines sd,domaines_type dt where sd.type=dt.id and sd.domaine='$domain';"|sort
+        $MYSQL_DO "select replace(replace(dt.entry,'%TARGET%',sd.valeur), '%SUB%', if(length(sd.sub)>0,sd.sub,'@')) from sub_domaines sd,domaines_type dt where sd.type=dt.name and sd.domaine='$domain';"|sort
     )
 
 
-    # Get some usefull vars
+    # Get some usefull vars
     local mx=$( $MYSQL_DO "select mx from domaines where domaine='$domain';")
 
     # Replace the vars by their values
@@ -87,8 +121,11 @@ dns_regenerate() {
         file=$(echo -e "$file"; echo "$manual_tag")
     fi
 
-    # Init the file
+    # Init the file
     echo -e "$file" > "$zone_file"
+
     # And set his rights
     dns_chmod $domain
+    # Add it to named conf
+    dns_named_conf $domain
 }
diff --git a/src/functions.sh b/src/functions.sh
old mode 100644
new mode 100755
index e100bc77..19541d72
--- a/src/functions.sh
+++ b/src/functions.sh
@@ -1,5 +1,14 @@
-# some miscellaneous shell functions
+#!/bin/bash
+# functions.sh next-gen by Fufroma
 
+# Init some vars
+. /etc/alternc/local.sh
+
+# Init some other vars
+MYSQL_DO="mysql --defaults-file=/etc/alternc/my.cnf -Bs -e "
+DOMAIN_LOG_FILE="/var/log/alternc/update_domains.log"
+
+# Some usefull miscellaneous shell functions
 print_domain_letter() {
     local domain="$1"
 
@@ -12,379 +21,27 @@ print_domain_letter() {
 
 print_user_letter() {
     local user="$1"
-
     echo "$user" | awk '{print substr($1, 1, 1)}'
 }
 
-add_to_php_override() {
-    local fqdn="$1"
-
-    /usr/lib/alternc/basedir_prot.sh "$fqdn" >> "$DOMAIN_LOG_FILE"
-}
-
-remove_php_override() {
-    local fqdn="$1"
-    local letter=`print_domain_letter $fqdn`
-
-    sed -i "/$fqdn/d" $APACHECONF_DIR/override_php.conf
-    rm -f $APACHECONF_DIR/$letter/$fqdn
-}
-
-add_to_named_reload() {
-    local domain="$1"
-    local escaped_domain=`echo "$domain" | sed -e 's/\./\\\./g'`
-
-    if [ "domain" = "all" ] || grep -q "^all$" "$RELOAD_ZONES_TMP_FILE"; then
-        echo "all" > "$RELOAD_ZONES_TMP_FILE"
-    else
-        if ! grep -q "^${escaped_domain}$" "$RELOAD_ZONES_TMP_FILE"; then
-            echo "$domain" >> "$RELOAD_ZONES_TMP_FILE"
-        fi
-    fi
-}
-
-# we assume that the serial line contains the "serial string", eg.:
-#                 2005012703      ; serial
-#
-# returns 1 if file isn't readable
-# returns 2 if we can't find the serial number
-# returns 3 if a tempfile can't be created
-increment_serial() {
-    local domain="$1"
-    local zone_file="$ZONES_DIR/$domain"
-    local current_serial
-    local new_serial
-    local date
-    local revision
-    local today
-
-    if [ ! -f "$zone_file" ]; then
-        return 1
-    fi
-
-    # the assumption is here
-    current_serial=`awk '/^..*serial/ {print $1}' < "$zone_file"` || return 2
-    if [ -z "$current_serial" ]; then
-        return 2
-    fi
-
-    date=`echo $current_serial | cut -c1-8`
-    revision=`echo $current_serial | sed s/"${date}0\?"/""/g`
-    today=`date +%Y%m%d`
-    # increment the serial number only if the date hasn't changed
-    if [ "$date" = "$today" ] ; then
-        revision=$(($revision + 1))
-    else
-        revision=1
-        date=$today
-    fi
-    new_serial="$date`printf '%.2d' $revision`"
-
-    # replace serial number
-    cp -a -f "$zone_file" "$zone_file.$$"
-    awk -v "NEW_SERIAL=$new_serial" \
-        '{if ($3 == "serial")
-             print "		"NEW_SERIAL "	; serial"
-          else
-             print $0}' < "$zone_file" > "$zone_file.$$"
-    mv -f "$zone_file.$$" "$zone_file"
-
-    add_to_named_reload "$domain"
-
-    return 0
-}
-
-change_host_ip() {
-    local domain="$1"
-    local zone_file="$ZONES_DIR/$domain"
-    local ip="$2"
-    local host="$3"
-    local pattern
-    local a_line
-
-    if [ -z "$host" ]; then
-        host="@"
-    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
-    fi
-    if grep -q "$pattern" "$zone_file"; then
-        cp -a -f "$zone_file" "$zone_file.$$"
-        sed "s/$pattern/$a_line/" < "$zone_file" > "$zone_file.$$"
-        mv "$zone_file.$$" "$zone_file"
-    else
-        echo "$a_line" >> "$zone_file"
-    fi
-    add_to_named_reload "$domain"
-}
-
-add_host() {
-    local domain="$1"
-    local host_type="$2"
-    local host="$3"
-    local value="$4"
-    local user="$5"
-    local domain_letter=`print_domain_letter "$domain"`
-    local user_letter=`print_user_letter "$user"`
-    local ip
-    local fqdn
-    local vhost_directory
-
-    delete_host "$domain" "$host" "$host_type"
-
-    if [ "$host" = "@" -o -z "$host" ]; then
-        FQDN="$domain"
-    else
-        FQDN="$host.$domain"
-    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"
-    else
-        change_host_ip "$domain" "$ip" "$host" || true
-        fqdn="${host}.${domain}"
-    fi
-
-    vhost_directory="${HTTP_DNS}/${domain_letter}/${fqdn}"
-    htaccess_directory="${HTTP_DNS}/redir/${domain_letter}/${fqdn}"
-
-    case "$host_type" in
-      $TYPE_LOCAL)
-		host_create_vhost $user $fqdn ${value}
-        ;;
-
-      $TYPE_WEBMAIL)
-		host_create_webmail $user $fqdn
-        ;;
-
-      $TYPE_URL)
-        mkdir -p "$htaccess_directory"
-        # normalize the url provided to make sure the hostname part is
-        # followed by at least /
-        value=`echo $value | sed -e 's#\([^/:]*://\)\?\([^/]*\)/*\(.*\)#\1\2/\3#'`
-
-		host_create_redirect $user $fqdn $value
-        ;;
-
-      $TYPE_IP)
-        rm -f "$vhost_directory"
-        rm -rf "$htaccess_directory/.htaccess"
-        ;;
-
-      *)
-        echo "Unknow type code: $type" >> "$DOMAIN_LOG_FILE"
-        ;;
-    esac
- 	host_enable_host $user $fqdn
-}
-
-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"
-        escaped_host=""
-    else
-        fqdn="$host.$domain"
-        escaped_host=`echo "$host" | sed 's/\([\*|\.]\)/\\\\\1/g'`
-    fi
-
-    if [ -f "$ZONES_DIR/$domain" ] ; then
-        cp -a -f "$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"
-    fi
-
-    rm -f "$APACHECONF_DIR/$domain_letter/$fqdn"
-
-    escaped_fqdn=`echo "$fqdn" | sed 's/\([\*|\.]\)/\\\\\1/g'`
-
-    cp -a -f "$OVERRIDE_PHP_FILE" "$OVERRIDE_PHP_FILE.$$"
-    sed -e "/\/${escaped_fqdn}\$/d" \
-        < "$OVERRIDE_PHP_FILE" > "$OVERRIDE_PHP_FILE.$$"
-    mv "$OVERRIDE_PHP_FILE.$$" "$OVERRIDE_PHP_FILE"
-
-    rm -f "$HTTP_DNS/$domain_letter/$fqdn"
-    rm -rf "$HTTP_DNS/redir/$domain_letter/$fqdn"
-	host_disable_host $fqdn
-}
-
-
-init_zone() {
-    local domain="$1"
-    local escaped_domain=`echo "$domain" | sed -e 's/\./\\\./g'`
-    local zone_file="$ZONES_DIR/$domain"
-    local serial
-
-    if [ ! -f "$zone_file" ]; then
-        serial=`date +%Y%m%d`00
-        sed -e "s/@@DOMAINE@@/$domain/g;s/@@SERIAL@@/$serial/g" \
-            < "$ZONE_TEMPLATE" > "$zone_file"
-        chgrp bind "$zone_file"
-        chmod 640  "$zone_file"
-    fi
-    if ! grep -q "\"$escaped_domain\"" "$NAMED_CONF_FILE"; then
-        cp -a -f "$NAMED_CONF_FILE" "$NAMED_CONF_FILE".prec
-        sed -e "s/@@DOMAINE@@/$domain/g" \
-                < "$NAMED_TEMPLATE" >> "$NAMED_CONF_FILE"
-        add_to_named_reload "all"
-    fi
-}
-
-remove_zone() {
-    local domain="$1"
-    local escaped_domain=`echo "$domain" | sed -e 's/\./\\\./g'`
-    local zone_file="$ZONES_DIR/$domain"
-
-    if [ -f "$zone_file" ]; then
-        rm -f "$zone_file"
-    fi
-
-    if grep -q "\"$escaped_domain\"" "$NAMED_CONF_FILE"; then
-        cp -a -f "$NAMED_CONF_FILE" "$NAMED_CONF_FILE.prec"
-        cp -a -f "$NAMED_CONF_FILE" "$NAMED_CONF_FILE.$$"
-        # That's for multi-line template
-        #sed -e "/^zone \"$escaped_domain\"/,/^};/d" \
-        # That's for one-line template
-        grep -v "^zone \"$escaped_domain\"" \
-            < "$NAMED_CONF_FILE" > "$NAMED_CONF_FILE.$$" || true
-        mv -f "$NAMED_CONF_FILE.$$" "$NAMED_CONF_FILE"
-        add_to_named_reload "all"
-    fi
-}
-
-change_mx() {
-    local domain="$1"
-    local mx="$2"
-    local zone_file="$ZONES_DIR/$domain"
-    local pattern="^@*[[:space:]]*IN[[:space:]]*MX[[:space:]]*[[:digit:]]*[[:space:]].*\$"
-    local mx_line="@ 	IN 	MX 	5 	$mx."
-
-    # aller chercher le numéro de la ligne MX
-    # XXX: comportement inconnu si plusieurs matchs ou MX commenté
-    if grep -q "$pattern" "$zone_file"; then
-        cp -a -f "$zone_file" "$zone_file.$$"
-        sed -e "s/$pattern/$mx_line/" < "$zone_file" > "$zone_file.$$"
-        mv "$zone_file.$$" "$zone_file"
-    else
-        echo "$mx_line" >> "$zone_file"
-    fi
-
-    increment_serial "$domain"
-    add_to_named_reload "$domain"
-}
-
-
-
 # imprime le nom d'usager associé au domaine
 get_account_by_domain() {
-	# les admintools ne sont peut-être pas là
-	if [ -x "/usr/bin/get_account_by_domain" ]
-	then
-		# only first field, only first line
-		/usr/bin/get_account_by_domain "$1" | cut -d\  -f1 | cut -d'
-' -f 1
-	else
-		# implantons localement ce que nous avons besoin, puisque admintools
-		# n'est pas là
-  		mysql --defaults-file=/etc/alternc/my.cnf -B -N -e \
-  		'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
-  		CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
-	fi
+    # les admintools ne sont peut-être pas là
+    if [ -x "/usr/bin/get_account_by_domain" ]
+    then
+        # only first field, only first line
+        /usr/bin/get_account_by_domain "$1"|head -1|awk '{ print $1;}'
+    else
+        # implantons localement ce que nous avons besoin, puisque admintools
+        # n'est pas là
+        $MYSQL_DO 'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
+        CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
+    fi
 }
 
-# add the standard input to a given file, only if not already present
-append_no_dupe() {
-	realfile="$1"
-	tmpfile=`mktemp`
-	trap "rm -f $tmpfile; exit 1" 1 2 15
-	cat > $tmpfile
-	if [ -r "$realfile" ] &&
-		(diff -q "$tmpfile" "$realfile" > /dev/null || \
-			diff -u "$tmpfile" "$realfile"  | grep '^ ' | sed 's/^ //' | diff -q - "$tmpfile" > /dev/null)
-	then
-		ret=0
-	else
-		ret=1
-		cat "$tmpfile" >> "$realfile"
-	fi
-	rm -f "$tmpfile"
-	return "$ret"
+log_error() {
+  local error=$1
+  echo "`date` $0 : $1" | tee -a "$DOMAIN_LOG_FILE" >&2
+  exit 1
 }
 
-add_dom_entry() {
-	# protect ourselves from interrupts
-	trap "rm -f ${override_f}.new; exit 1" 1 2 15
-	# ajouter une entrée, seulement s'il n'y en pas déjà, pour ce domaine
-	(echo "$1"; [ -r $override_f ] && cat $override_f) | \
-	sort -u > ${override_f}.new && \
-	cp ${override_f}.new ${override_f} && \
-	rm ${override_f}.new
-}
diff --git a/src/hosting_functions_v2.sh b/src/hosting_functions_v2.sh
index 5d415ecf..d374d0bd 100644
--- a/src/hosting_functions_v2.sh
+++ b/src/hosting_functions_v2.sh
@@ -1,12 +1,14 @@
+#!/bin/bash
+
+. /usr/lib/alternc/functions.sh
+
 TEMPLATE_DIR="/etc/alternc/templates/apache2"
 HOSTING_DIR="/usr/lib/alternc/hosting_functions"
 
-DATA_ROOT="/var/alternc"
-HTML_HOME="$DATA_ROOT/html"
-VHOST_DIR="$DATA_ROOT/apache-vhost"
+HTML_HOME="$ALTERNC_LOC/html"
+VHOST_DIR="$ALTERNC_LOC/apache-vhost"
 VHOST_FILE="$VHOST_DIR/vhosts_all.conf"
 
-. /usr/lib/alternc/functions.sh
 
 host_create() {
     # Function to create a vhost for a website
@@ -79,7 +81,7 @@ host_create() {
     # Check if all is right in the conf file
     # If not, put a debug message
     local ISNOTGOOD=$(grep "%%" "$TMP_FILE") 
-    [ "$ISNOTGOOD" ] && (echo "# There was a probleme in the generation : $ISNOTGOOD" > "$TMP_FILE"
+    [ "$ISNOTGOOD" ] && (echo "# There was a probleme in the generation : $ISNOTGOOD" > "$TMP_FILE" )
 
     # Put the conf file in prod
     mkdir -p "$(dirname "$FILE_TARGET")"
@@ -87,7 +89,7 @@ host_create() {
 
     # Execute post-install if there is some for this VTYPE
     [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] && "$HOSTING_DIR/hosting_$VTYPE.sh" "postint" $@
- 
+
 }
 
 host_disable() {
diff --git a/src/update_domains.sh b/src/update_domains.sh
old mode 100755
new mode 100644
index 39462b2f..6af029b6
--- a/src/update_domains.sh
+++ b/src/update_domains.sh
@@ -1,92 +1,31 @@
-#!/bin/sh
-#
-# $Id: update_domaines.sh,v 1.31 2005/08/29 19:21:31 anarcat Exp $
-# ----------------------------------------------------------------------
-# AlternC - Web Hosting System
-# Copyright (C) 2002 by the AlternC Development Team.
-# http://alternc.org/
-# ----------------------------------------------------------------------
-# Based on:
-# Valentin Lacambre's web hosting softwares: http://altern.org/
-# ----------------------------------------------------------------------
-# LICENSE
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License (GPL)
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# To read the license please visit http://www.gnu.org/copyleft/gpl.html
-# ----------------------------------------------------------------------
-# Original Author of file: Jerome Moinet for l'Autre Net - 14/12/2000
-# Purpose of file: system level domain management
-# ----------------------------------------------------------------------
-#
+#!/bin/bash
+# Update domain next-gen by fufrom
 
-PATH=/sbin:/bin:/usr/sbin:/usr/bin
-
-set -e
+for CONFIG_FILE in \
+      /etc/alternc/local.sh \
+      /usr/lib/alternc/functions.sh \
+      /usr/lib/alternc/hosting_functions_v2.sh \
+      /usr/lib/alternc/dns.sh
+  do
+    if [ ! -r "$CONFIG_FILE" ]; then
+        echo "Can't access $CONFIG_FILE."
+        exit 1
+    fi
+    . "$CONFIG_FILE"
+done
 
+# Some vars
 umask 022
+LOCK_FILE="$ALTERNC_LOC/bureau/cron.lock"
 
-########################################################################
-# Constants & Preliminary checks
-#
-
-CONFIG_FILE="/etc/alternc/local.sh"
-
-DOMAIN_LOG_FILE="/var/log/alternc/update_domains.log"
-DATA_ROOT="/var/alternc"
-
-NAMED_TEMPLATE="/etc/bind/templates/named.template"
-ZONE_TEMPLATE="/etc/bind/templates/zone.template"
-
-ACTION_INSERT=0
-ACTION_UPDATE=1
-ACTION_DELETE=2
-TYPE_LOCAL=0
-TYPE_URL=1
-TYPE_IP=2
-TYPE_WEBMAIL=3
-TYPE_IPV6=4
-TYPE_CNAME=5
-TYPE_TXT=6
-YES=1
 
+# Somes check before start operations
 if [ `id -u` -ne 0 ]; then
-    echo "update_domains.sh must be launched as root"
-    exit 1
-fi
-
-if [ ! -x "/usr/bin/get_account_by_domain" ]; then
-    echo "Your AlternC installation is incorrect ! If you are using pre 0.9.4, "
-    echo "you have to install alternc-admintools: "
-    echo "    apt-get update ; apt-get install alternc-admintools"
-    exit 1
-fi
-
-if [ ! -r "$CONFIG_FILE" ]; then
-    echo "Can't access $CONFIG_FILE."
-    exit 1
-fi
-
-. "$CONFIG_FILE"
-
-if [ -z "$DEFAULT_MX" -o -z "$PUBLIC_IP" ]; then
-    echo "Bad configuration. Please use:"
-    echo "   dpkg-reconfigure alternc"
-    exit 1
-fi
-
-if [ -f "$LOCK_FILE" ]; then
-    echo "`date` $0: last cron unfinished or stale lock file." |
-        tee -a "$DOMAIN_LOG_FILE" >&2
-    exit 1
+    log_error "must be launched as root"
+elif [ -z "$DEFAULT_MX" -o -z "$PUBLIC_IP" ]; then
+    log_error "Bad configuration. Please use: dpkg-reconfigure alternc"
+elif [ -f "$LOCK_FILE" ]; then
+    log_error "last cron unfinished or stale lock file ($LOCK_FILE)."
 fi
 
 # backward compatibility: single-server setup
@@ -94,167 +33,71 @@ if [ -z "$ALTERNC_SLAVES" ] ; then
     ALTERNC_SLAVES="localhost"
 fi
 
-NAMED_CONF_FILE="$DATA_ROOT/bind/automatic.conf"
-ZONES_DIR="$DATA_ROOT/bind/zones"
-APACHECONF_DIR="$DATA_ROOT/apacheconf"
-OVERRIDE_PHP_FILE="$APACHECONF_DIR/override_php.conf"
-WEBMAIL_DIR="$DATA_ROOT/bureau/admin/webmail"
-LOCK_FILE="$DATA_ROOT/bureau/cron.lock"
-HTTP_DNS="$DATA_ROOT/dns"
-HTML_HOME="$DATA_ROOT/html"
-
-MYSQL_SELECT="mysql --defaults-file=/etc/alternc/my.cnf -Bs "
-MYSQL_DELETE="mysql --defaults-file=/etc/alternc/my.cnf "
-
-########################################################################
-# Functions
-#
-. /usr/lib/alternc/hosting_functions.sh
-
-########################################################################
-# Main
-#
-
-# Init
-
+# We lock the application
 touch "$LOCK_FILE"
-DOMAINS_TMP_FILE=`mktemp -t alternc.update_domains.XXXXXX`
-HOSTS_TMP_FILE=`mktemp -t alternc.update_domains.XXXXXX`
-RELOAD_ZONES_TMP_FILE=`mktemp -t alternc.update_domains.XXXXXX`
 
-cleanup() {
-    rm -f "$LOCK_FILE" "$DOMAINS_TMP_FILE" "$HOSTS_TMP_FILE"
-    rm -f "$RELOAD_ZONES_TMP_FILE"
-    exit 0
-}
+# For domains we want to delete completely, make sure all the tags are all right
+# set sub_domaines.web_action = delete where domaines.dns_action = DELETE
+$MYSQL_DO "update sub_domaines sd, domaines d set sd.web_action = 'DELETE' where sd.domaine = d.domaine and sd.compte=d.compte and d.dns_action = 'DELETE';"
 
-trap cleanup 0 1 2 15
-
-# Query database
-
-$MYSQL_SELECT < "$DOMAINS_TMP_FILE"
-SELECT membres.login,
-       domaines_standby.domaine,
-       if (domaines_standby.mx = '', '@', domaines_standby.mx),
-       domaines_standby.gesdns,
-       domaines_standby.gesmx,
-       domaines_standby.action
-  FROM domaines_standby
-       LEFT JOIN membres membres
-               ON membres.uid = domaines_standby.compte
- ORDER BY domaines_standby.action
-EOF
-
-$MYSQL_SELECT < "$HOSTS_TMP_FILE"
-SELECT membres.login,
-       sub_domaines_standby.domaine,
-       if (sub_domaines_standby.sub = '', '@', sub_domaines_standby.sub),
-       if (sub_domaines_standby.valeur = '', 'NULL',
-                                             sub_domaines_standby.valeur),
-       sub_domaines_standby.type,
-       sub_domaines_standby.action
-  FROM sub_domaines_standby
-       LEFT JOIN membres membres
-               ON membres.uid = sub_domaines_standby.compte
- ORDER BY sub_domaines_standby.action desc
-EOF
-
-# Handle domain updates
-
-if [ "`wc -l < $DOMAINS_TMP_FILE`" -gt 0 ]; then
-    echo `date` >> $DOMAIN_LOG_FILE
-    cat "$DOMAINS_TMP_FILE" >> $DOMAIN_LOG_FILE
-fi
-
-# We need to tweak the IFS as $MYSQL_SELECT use tabs to separate fields
-OLD_IFS="$IFS"
-IFS="	"
-while read user domain mx are_we_dns are_we_mx action ; do
-    IFS="$OLD_IFS" 
-
-    DOMAIN_LETTER=`print_domain_letter "$domain"`
-    USER_LETTER=`print_user_letter "$user"`
-
-    case "$action" in
-      $ACTION_INSERT)
-        if [ "$are_we_dns" = "$YES" ] ; then
-            init_zone "$domain"
-        fi
-        ;;
-
-      $ACTION_UPDATE)
-        if [ "$are_we_dns" = "$YES" ] ; then
-            init_zone "$domain"
-            change_mx "$domain" "$mx"
-        else
-            remove_zone "$domain"
-        fi
-        ;;
-
-      $ACTION_DELETE)
-        remove_zone "$domain"
-
-        # remove symlinks
-        rm -f "${HTTP_DNS}/${DOMAIN_LETTER}/"*".$domain"
-        rm -f "${HTTP_DNS}/${DOMAIN_LETTER}/$domain"
-        rm -rf "${HTTP_DNS}/redir/${DOMAIN_LETTER}/"*".$domain"
-        rm -rf "${HTTP_DNS}/redir/${DOMAIN_LETTER}/$domain"
-        ;;
-
-      *)
-        echo "Unknown action code: $action" >> "$DOMAIN_LOG_FILE"
-        ;;
-    esac
-
-    IFS="	"
-done < "$DOMAINS_TMP_FILE"
-IFS="$OLD_IFS"
-
-# Handle hosts update
-
-if [ "`wc -l < $HOSTS_TMP_FILE`" -gt 0 ] ; then
-    echo `date` >> $DOMAIN_LOG_FILE
-    cat "$HOSTS_TMP_FILE" >> $DOMAIN_LOG_FILE
-fi
-
-OLD_IFS="$IFS"
-IFS="	"
-while read user domain host value type action; do
-    IFS="$OLD_IFS"
-
-    case "$action" in
-      $ACTION_UPDATE | $ACTION_INSERT)
-        add_host "$domain" "$type" "$host" "$value" "$user"
-        ;;
-
-      $ACTION_DELETE)
-        delete_host "$domain" "$host" "$type"
-        ;;
-
-      *)
-        echo "Unknown action code: $action" >> "$DOMAIN_LOG_FILE"
-        ;;
-    esac
-
-    IFS="	"
-done < "$HOSTS_TMP_FILE"
-IFS="$OLD_IFS"
-
-# Reload configuration for named and apache
-
-RELOAD_ZONES=`cat "$RELOAD_ZONES_TMP_FILE"`
-
-# we assume we run apache and bind on the master
-alternc_reload $RELOAD_ZONES || true
-for slave in $ALTERNC_SLAVES; do
-    if [ "$slave" != "localhost" ]; then
-        ssh alternc@$slave alternc_reload "$RELOAD_ZONES" || true
-    fi
+# Sub_domaines we want to delete
+# sub_domaines.web_action = delete
+for sub in $( $MYSQL_DO "select if (length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) from sub_domaines sd where web_action ='DELETE';") ; do
+    echo $sub
+    # TODO Do the conf
+    # TODO Update the entry in the DB with the result and the action
 done
 
-# Cleanup
+# Sub domaines we want to update
+# sub_domaines.web_action = update and sub_domains.only_dns = false
+# TODO do the conf
+# TODO Update the entry in the DB with the result and the action
+
+# Domains we do not want to be the DNS serveur anymore :
+# domaines.dns_action = UPDATE and domaines.gesdns = 0
+for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'UPDATE' and gesdns = 0;") ; do
+    dns_delete $dom
+    $MYSQL_DO "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'"
+done
+
+# Domains we have to update the dns :
+# domaines.dns_action = UPDATE
+for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'UPDATE';") ; do
+    dns_regenerate $dom
+    $MYSQL_DO "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'"
+done
+
+# Domains we want to delete completely, now we do it
+# domaines.dns_action = DELETE
+for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'DELETE';") ; do
+    dns_delete $dom
+    # Web configurations have already bean cleaned previously
+    $MYSQL_DO "delete sub_domaines where domaine='$dom'; delete domaines where domaine='$dom';"
+done
+
+
+echo Exitbefore reload everything, we are testing, FUCK
+rm "$LOCK_FILE"
+exit 1
+# Concat the apaches files
+local tempo=$(mktemp /tmp/alternc-vhost.XXXXX)
+find "$VHOST_DIR" -type f -iname "*.conf" -exec cat '{}' >> "$tempo" \;
+if [ $? -ne 0 ] ; then
+  log_error " web file concatenation failed"
+fi
+if [ ! -w "$VHOST_FILE" ] ; then
+  log_error "cannot write on $VHOST_FILE"
+fi
+
+mv "$tempo" "$VHOST_FILE"
+
+# Reload web and dns
+alternc_reload all
+
+# TODO reload slaves
+
+rm "$LOCK_FILE"
+
+exit 0
 
-echo "DELETE FROM domaines_standby" | $MYSQL_DELETE 
-echo "DELETE FROM sub_domaines_standby" | $MYSQL_DELETE 
 
-# vim: et sw=4