From dacbd14cf9386d2153e6d70b72d828f336700b16 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Sat, 29 Jan 2011 17:58:19 +0000 Subject: [PATCH] Update domains, l'aventure continue --- bureau/admin/dom_edit.php | 31 ++++++++++++++++++++++++++++++- bureau/class/m_dom.php | 19 +++++++++++++------ install/upgrades/1.0.sql | 5 +++-- src/dns.sh | 3 +-- src/hosting_functions_v2.sh | 1 + src/update_domains.sh | 22 ++++++++++------------ 6 files changed, 58 insertions(+), 23 deletions(-) diff --git a/bureau/admin/dom_edit.php b/bureau/admin/dom_edit.php index d1446759..ab388053 100644 --- a/bureau/admin/dom_edit.php +++ b/bureau/admin/dom_edit.php @@ -94,7 +94,7 @@ if ($r['dns_action']=='UPDATE') {?> gestion des sous-domaines --> - +" target="_blank"> + + +
'.htmlspecialchars($r["sub"][$i]["dest"]).'' : htmlspecialchars($r["sub"][$i]["dest"]); ?> 
diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 7ee68048..9371e57a 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -646,7 +646,7 @@ class m_dom { $db->next_record(); $r["nsub"]=$db->Record["cnt"]; $db->free(); - $db->query("select sd.*, dt.description as type_desc from sub_domaines sd, domaines_type dt where compte='$cuid' and domaine='$dom' and upper(dt.name)=upper(sd.type)"); + $db->query("select sd.*, dt.description as type_desc, dt.only_dns from sub_domaines sd, domaines_type dt where compte='$cuid' and domaine='$dom' and upper(dt.name)=upper(sd.type)"); // Pas de webmail, on le cochera si on le trouve. $this->webmail=0; for($i=0;$i<$r["nsub"];$i++) { @@ -655,7 +655,10 @@ class m_dom { $r["sub"][$i]["name"]=$db->Record["sub"]; $r["sub"][$i]["dest"]=$db->Record["valeur"]; $r["sub"][$i]["type"]=$db->Record["type"]; + $r["sub"][$i]["enable"]=$db->Record["enable"]; $r["sub"][$i]["type_desc"]=$db->Record["type_desc"]; + $r["sub"][$i]["only_dns"]=$db->Record["only_dns"]; + $r["sub"][$i]["web_action"]=$db->Record["web_action"]; /* if ($db->Record["type"]==3) { // Webmail $this->webmail=1; @@ -703,7 +706,7 @@ class m_dom { $type = " and type=\"".mysql_real_escape_string($type)."\""; } */ - $db->query("select sd.*, dt.description as type_desc from sub_domaines sd, domaines_type dt where compte='$cuid' and domaine='$dom' and sub='$sub' and ( length('$type')=0 or type='$type') and (length('$value')=0 or '$value'=valeur) and upper(dt.name)=upper(sd.type);"); + $db->query("select sd.*, dt.description as type_desc, dt.only_dns from sub_domaines sd, domaines_type dt where compte='$cuid' and domaine='$dom' and sub='$sub' and ( length('$type')=0 or type='$type') and (length('$value')=0 or '$value'=valeur) and upper(dt.name)=upper(sd.type);"); if ($db->num_rows()==0) { $err->raise("dom",14); return false; @@ -712,8 +715,10 @@ class m_dom { $r=array(); $r["name"]=$db->Record["sub"]; $r["dest"]=$db->Record["valeur"]; - $r["type"]=$db->Record["type"]; + $r["enable"]=$db->Record["enable"]; $r["type_desc"]=$db->Record["type_desc"]; + $r["only_dns"]=$db->Record["only_dns"]; + $r["web_action"]=$db->Record["web_action"]; $db->free(); return $r; } // get_sub_domain_all @@ -737,6 +742,7 @@ class m_dom { $err->raise("dom",21); return false; } + return true; break; case 'IP': if (checkip($value)) {return true;} @@ -758,7 +764,7 @@ class m_dom { } //check_type_value - function can_create_subdomain($dom,$sub,$type) { + function can_create_subdomain($dom,$sub,$type,$value_old='') { global $db,$err,$cuid; $err->log("dom","can_create_subdomain",$dom."/".$sub); @@ -768,7 +774,8 @@ class m_dom { $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';"); + $db->query("select * from sub_domaines where sub='$sub' and domaine='$dom' and not (type='$type' and valeur='$value_old')"); + #$db->query("select * 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; @@ -828,7 +835,7 @@ class m_dom { return false; } - if (! $this->can_create_subdomain($dom,$sub,$type)) { + if (! $this->can_create_subdomain($dom,$sub,$type,$value_old)) { # TODO have a real error code $err->raise("dom", 654); return false; diff --git a/install/upgrades/1.0.sql b/install/upgrades/1.0.sql index 28f05582..e35fd70f 100644 --- a/install/upgrades/1.0.sql +++ b/install/upgrades/1.0.sql @@ -34,8 +34,9 @@ INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibil -- 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','ENABLE','DISABLE','DELETE') NOT NULL default 'UPDATE'; -alter table sub 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_domaines add column dns_result varchar(255) not null default ''; +alter table sub_domaines add column enable enum ('ENABLED', 'ENABLE', 'DISABLED', 'DISABLE') NOT NULL DEFAULT 'ENABLED'; drop table sub_domaines_standby; drop table domaines_standby; diff --git a/src/dns.sh b/src/dns.sh index 6774b0b5..b27467ea 100755 --- a/src/dns.sh +++ b/src/dns.sh @@ -93,10 +93,9 @@ dns_regenerate() { # Add the entry file=$( echo -e "$file" - $MYSQL_DO "select distinct replace(replace(dt.entry,'%TARGET%',sd.valeur), '%SUB%', if(length(sd.sub)>0,sd.sub,'@')) as entry from sub_domaines sd,domaines_type dt where sd.type=dt.name and sd.domaine='$domain' order by entry ;" + $MYSQL_DO "select distinct replace(replace(dt.entry,'%TARGET%',sd.valeur), '%SUB%', if(length(sd.sub)>0,sd.sub,'@')) as entry from sub_domaines sd,domaines_type dt where sd.type=dt.name and sd.domaine='$domain' and sd.enable in ('ENABLE', 'ENABLED') order by entry ;" ) - # Get some usefull vars local mx=$( $MYSQL_DO "select mx from domaines where domaine='$domain' limit 1;") diff --git a/src/hosting_functions_v2.sh b/src/hosting_functions_v2.sh index 51121a92..3dab574c 100644 --- a/src/hosting_functions_v2.sh +++ b/src/hosting_functions_v2.sh @@ -113,6 +113,7 @@ host_change_enable() { fi local FQDN=$2 + local TYPE=$3 # no use here, but one day, maybe... So here he is local USER=$(get_account_by_domain $FQDN) local user_letter=`print_user_letter "$USER"` local FENABLED="$VHOST_DIR/${user_letter}/$USER/$FQDN.conf" diff --git a/src/update_domains.sh b/src/update_domains.sh index e1275896..86653fa5 100644 --- a/src/update_domains.sh +++ b/src/update_domains.sh @@ -42,8 +42,8 @@ $MYSQL_DO "update sub_domaines sd, domaines d set sd.web_action = 'DELETE' where # 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 - host_delete $sub +for sub in $( $MYSQL_DO "select concat_ws('|µ',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),sd.type) from sub_domaines sd where web_action ='DELETE';") ; do + host_delete $(echo $sub|tr '|µ' ' ') # TODO Update the entry in the DB with the result and the action done @@ -51,26 +51,24 @@ done # sub_domaines.web_action = update and sub_domains.only_dns = false params=$( $MYSQL_DO " select concat_ws('|µ',lower(sd.type), if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine), valeur) - from sub_domaines sd, domaines_type dt + from sub_domaines sd where sd.web_action ='UPDATE' - and lower(sd.type) = lower(dt.name) - and dt.only_dns = false ;") for sub in $params;do host_create $(echo $sub|tr '|µ' ' ') - # TODO Update the entry in the DB with the result and the action + $MYSQL_DO "update sub_domaines sd set web_action='OK',web_result='$?' where concat_ws('|µ',lower(sd.type),if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),valeur)='$sub'" done # Domaine to enable -for sub in $( $MYSQL_DO "select if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) from sub_domaines sd where sd.web_action ='ENABLE' ;");do - host_enable $sub - # TODO Update the entry in the DB with the result and the action +for sub in $( $MYSQL_DO "select concat_ws('|µ',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) from sub_domaines sd where sd.enable ='ENABLE' ;");do + host_enable $(echo $sub|tr '|µ' ' ') + $MYSQL_DO "update sub_domaines sd set enable='ENABLED' where concat_ws('|µ',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) = '$sub';" done # Domains to disable -for sub in $( $MYSQL_DO "select if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) from sub_domaines sd where sd.web_action ='DISABLE' ;");do - host_disable $sub - # TODO Update the entry in the DB with the result and the action +for sub in $( $MYSQL_DO "select concat_ws('|µ',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) from sub_domaines sd where sd.enable ='DISABLE' ;");do + host_disable $(echo $sub|tr '|µ' ' ') + $MYSQL_DO "update sub_domaines sd set enable='DISABLED' where concat_ws('|µ',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) = '$sub';" done # Domains we do not want to be the DNS serveur anymore :