2006-04-26 12:28:53 +00:00
< ? php
/*
$Id : m_dom . php , v 1.27 2006 / 02 / 17 18 : 34 : 30 olivier Exp $
----------------------------------------------------------------------
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 : Benjamin Sonntag
Purpose of file : PHP Class that manage domain names installed on the server
----------------------------------------------------------------------
*/
define ( 'SLAVE_FLAG' , " /var/run/alternc/refresh_slave " );
/**
* Classe de gestion des domaines de l ' h<EFBFBD> berg<EFBFBD> .
*
* Cette classe permet de g<EFBFBD> rer les domaines / sous - domaines , redirections
* dns et mx des domaines d ' un membre h<EFBFBD> berg<EFBFBD> .< br />
* Copyleft { @ link http :// alternc . net / AlternC Team }
*
* @ copyright AlternC - Team 2002 - 11 - 01 http :// alternc . net /
*
*/
class m_dom {
/** $domains : Cache des domaines du membre
* @ access private
*/
var $domains ;
/** $dns : Liste des dns trouv<EFBFBD> s par la fonction whois
* @ access private
*/
var $dns ;
/** Flag : a - t - on trouv<EFBFBD> un sous - domaine Webmail pour ce domaine ?
* @ access private
*/
var $webmail ;
/**
* Syst<EFBFBD> me de verrouillage du cron
* Ce fichier permet de verrouiller le cron en attendant la validation
* du domaine par update_domains . sh
* @ access private
*/
var $fic_lock_cron = " /var/run/alternc/cron.lock " ;
/**
* Le cron a - t - il <EFBFBD> t<EFBFBD> bloqu<EFBFBD> ?
* Il faut appeler les fonctions priv<EFBFBD> es lock et unlock entre les
* appels aux domaines .
* @ access private
*/
var $islocked = false ;
var $type_local = " 0 " ;
var $type_url = " 1 " ;
var $type_ip = " 2 " ;
var $type_webmail = " 3 " ;
2010-11-14 16:54:27 +00:00
var $type_ipv6 = " 4 " ;
2010-11-16 17:11:06 +00:00
var $type_cname = " 5 " ;
var $type_txt = " 6 " ;
2006-04-26 12:28:53 +00:00
var $action_insert = " 0 " ;
var $action_update = " 1 " ;
var $action_delete = " 2 " ;
/* ----------------------------------------------------------------- */
/**
* Constructeur
*/
function m_dom () {
}
/* ----------------------------------------------------------------- */
/**
* Quota name
*/
function alternc_quota_names () {
return " dom " ;
}
/* ----------------------------------------------------------------- */
/**
* Retourne un tableau contenant les domaines d ' un membre .
*
* @ return array retourne un tableau index<EFBFBD> contenant la liste des
* domaines h<EFBFBD> berg<EFBFBD> s sur le compte courant . Retourne FALSE si une
* erreur s ' est produite .
*/
function enum_domains () {
global $db , $err , $cuid ;
$err -> log ( " dom " , " enum_domains " );
2009-02-06 14:49:50 +00:00
$db -> query ( " select * from domaines where compte=' $cuid ' order by domaine asc; " );
2006-04-26 12:28:53 +00:00
$this -> domains = array ();
if ( $db -> num_rows () > 0 ) {
while ( $db -> next_record ()) {
$this -> domains [] = $db -> f ( " domaine " );
}
}
return $this -> domains ;
}
/* ----------------------------------------------------------------- */
/**
* Efface un domaine du membre courant , et tous ses sous - domaines
*
* Cette fonction efface un domaine et tous ses sous - domaines , ainsi que
* les autres services attach<EFBFBD> s <EFBFBD> celui - ci . Elle appelle donc les autres
* classe . Chaque classe peut d<EFBFBD> clarer une fonction del_dom qui sera
* appell<EFBFBD> e lors de la destruction d ' un domaine .
*
* @ param string $dom nom de domaine <EFBFBD> effacer
* @ return boolean Retourne FALSE si une erreur s ' est produite , TRUE sinon .
*/
function del_domain ( $dom ) {
global $db , $err , $classes , $cuid ;
$err -> log ( " dom " , " del_domain " , $dom );
$dom = strtolower ( $dom );
$db -> query ( " SELECT * FROM domaines WHERE domaine=' $dom '; " );
if ( $db -> num_rows () == 0 ) {
$err -> raise ( " dom " , 1 , $dom );
return false ;
}
$db -> next_record ();
if ( $db -> f ( " compte " ) != $cuid ) {
$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 '; " );
// 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 );
}
}
foreach ( $classes as $c ) {
if ( method_exists ( $GLOBALS [ $c ], " alternc_del_mx_domain " )) {
$GLOBALS [ $c ] -> alternc_del_mx_domain ( $dom );
}
}
return true ;
}
/* ----------------------------------------------------------------- */
/**
* Installe un domaine sur le compte courant .
*
* < p > Si le domaine existe d<EFBFBD> j<EFBFBD> ou est interdit , ou est celui du serveur ,
* l 'installation est refus<75> e. Si l' h<EFBFBD> bergement DNS est demand<EFBFBD> , la fonction
* checkhostallow v<EFBFBD> rifiera que le domaine peut <EFBFBD> tre install<EFBFBD> conform<EFBFBD> ment
* aux demandes des super - admin .
* Si le dns n 'est pas demand<6E> , le domaine peut <20> tre install<6C> s' il est en
* seconde main d ' un tld ( exemple : test . eu . org ou test . com , mais pas
* toto . test . org ou test . test . asso . fr ) </ p >
* < p > Chaque classe peut d<EFBFBD> finir une fonction add_dom ( $dom ) qui sera
* appell<EFBFBD> e lors de l 'installation d' un nouveau domaine .</ p >
*
* @ param string $dom nom fqdn du domaine <EFBFBD> installer
* @ param integer $dns 1 ou 0 pour h<EFBFBD> berger le DNS du domaine ou pas .
* @ param integer $noerase 1 ou 0 pour rendre le domaine inamovible ou non
* @ param integer $force 1 ou 0 , si 1 , n ' effectue pas les tests de DNS .
* force ne devrait <EFBFBD> tre utilis<EFBFBD> que par le super - admin .
$ @ return boolean Retourne FALSE si une erreur s ' est produite , TRUE sinon .
*/
2010-06-02 21:39:26 +00:00
function add_domain ( $domain , $dns , $noerase = 0 , $force = 0 , $isslave = 0 , $slavedom = " " ) {
2010-03-04 15:10:05 +00:00
global $db , $err , $quota , $classes , $L_MX , $L_FQDN , $tld , $cuid , $bro ;
2006-04-26 12:28:53 +00:00
$err -> log ( " dom " , " add_domain " , $domain );
$mx = " 1 " ;
// Locked ?
if ( ! $this -> islocked ) {
$err -> raise ( " dom " , 3 );
return false ;
}
// Verifie que le domaine est rfc-compliant
$domain = strtolower ( $domain );
$t = checkfqdn ( $domain );
if ( $t ) {
$err -> raise ( " dom " , 3 + $t );
return false ;
}
// Interdit les domaines cl<63> s (table forbidden_domains) sauf en cas FORCE
$db -> query ( " select domain from forbidden_domains where domain=' $domain ' " );
if ( $db -> num_rows () && ! $force ) {
$err -> raise ( " dom " , 22 );
return false ;
}
if ( $domain == $L_FQDN || $domain == " www. $L_FQDN " ) {
$err -> raise ( " dom " , 18 );
return false ;
}
$db -> query ( " SELECT compte FROM domaines WHERE domaine=' $domain '; " );
if ( $db -> num_rows ()) {
$err -> raise ( " dom " , 8 );
return false ;
}
$db -> query ( " SELECT compte FROM `sub_domaines` WHERE sub != \" \" AND concat( sub, \" . \" , domaine )=' $domain ' OR domaine=' $domain '; " );
if ( $db -> num_rows ()) {
$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 );
if ( $v ==- 1 ) {
$err -> raise ( " dom " , 7 ); // TLD interdit
return false ;
}
if ( $dns && $v ==- 2 ) {
$err -> raise ( " dom " , 12 ); // Domaine non trouv<75> dans le whois
return false ;
}
if ( $dns && $v ==- 3 ) {
$err -> raise ( " dom " , 23 ); // Domaine non trouv<75> dans le whois
return false ;
}
if ( $dns ) $dns = " 1 " ; else $dns = " 0 " ;
// mode 5 : force DNS to NO.
if ( $tld [ $v ] == 5 ) $dns = 0 ;
// It must be a real domain (no subdomain)
if ( ! $dns ) {
$v = checkhostallow_nodns ( $domain );
if ( $v ) {
$err -> raise ( " dom " , 22 );
return false ;
}
}
}
// Check the quota :
if ( ! $quota -> cancreate ( " dom " )) {
$err -> raise ( " dom " , 10 );
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
2009-01-28 22:12:01 +00:00
2010-03-04 16:16:13 +00:00
if ( $isslave ) {
$isslave = true ;
$db -> query ( " SELECT domaine FROM domaines WHERE compte=' $cuid ' AND domaine=' $slavedom '; " );
$db -> next_record ();
if ( ! $db -> Record [ " domaine " ]) {
$err -> raise ( " dom " , 1 , $slavedom );
$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 );
}
if ( ! $isslave ) {
// Creation du repertoire dans www
$dest_root = $bro -> get_userid_root ( $cuid );
$domshort = str_replace ( " - " , " " , str_replace ( " . " , " " , $domain ));
if ( ! is_dir ( $dest_root . " / " . $domshort )) {
mkdir ( $dest_root . " / " . $domshort );
}
// 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' , '' );
2009-01-28 22:12:01 +00:00
}
2006-04-26 12:28:53 +00:00
// DEPENDANCE :
// Lancement de add_dom sur les classes domain_sensitive :
2010-03-04 16:16:13 +00:00
// Declenchons les autres classes.
2006-04-26 12:28:53 +00:00
foreach ( $classes as $c ) {
if ( method_exists ( $GLOBALS [ $c ], " alternc_add_domain " )) {
$GLOBALS [ $c ] -> alternc_add_domain ( $domain );
}
}
foreach ( $classes as $c ) {
if ( method_exists ( $GLOBALS [ $c ], " alternc_add_mx_domain " )) {
$GLOBALS [ $c ] -> alternc_add_mx_domain ( $domain );
}
}
2010-03-04 16:16:13 +00:00
if ( $isslave ) {
foreach ( $classes as $c ) {
if ( method_exists ( $GLOBALS [ $c ], " alternc_add_slave_domain " )) {
$GLOBALS [ $c ] -> alternc_add_slave_domain ( $domain , $slavedom );
}
}
}
return true ;
2006-04-26 12:28:53 +00:00
}
/* ----------------------------------------------------------------- */
/**
* Retourne les entr<EFBFBD> es DNS du domaine $domain issues du WHOIS .
*
* Cette fonction effectue un appel WHOIS ( $domain ) sur Internet ,
* et extrait du whois les serveurs DNS du domaine demand<EFBFBD> . En fonction
* du TLD , on sait ( ou pas ) faire le whois correspondant .
* Actuellement , les tld suivants sont support<EFBFBD> s :
* . com . net . org . be . info . ca . cx . fr . biz . name
*
* @ param string $domain Domaine fqdn dont on souhaite les serveurs DNS
* @ return array Retourne un tableau index<EFBFBD> avec les NOMS fqdn des dns
* du domaine demand<EFBFBD> . Retourne FALSE si une erreur s ' est produite .
*
*/
function whois ( $domain ) {
global $db , $err ;
$err -> log ( " dom " , " whois " , $domain );
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
// echo "whois : $domain<br />";
ereg ( " .* \ .([^ \ .]*) " , $domain , $out );
$ext = $out [ 1 ];
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
// echo "ext: $ext<br />";
$egal = " " ;
switch ( $ext ) {
case " com " :
case " net " :
2008-09-03 15:31:18 +00:00
$serveur = " whois.crsnic.net " ;
2006-04-26 12:28:53 +00:00
$egal = " = " ;
break ;
case " org " :
$serveur = " whois.pir.org " ;
break ;
case " be " :
$serveur = " whois.dns.be " ;
break ;
case " eu " :
2008-10-21 19:37:25 +00:00
# source: http://www.iana.org/domains/root/db/eu.html
$serveur = " whois.eu " ;
2006-04-26 12:28:53 +00:00
break ;
case " info " :
$serveur = " whois.afilias.net " ;
break ;
case " ca " :
$serveur = " whois.cira.ca " ;
break ;
2009-01-26 21:07:41 +00:00
case " cc " :
$serveur = " ccwhois.verisign-grs.com " ;
break ;
2006-04-26 12:28:53 +00:00
case " cx " :
$serveur = " whois.nic.cx " ;
break ;
2009-09-25 16:12:05 +00:00
case " im " :
$serveur = " whois.nic.im " ;
break ;
2006-04-26 12:28:53 +00:00
case " it " :
$serveur = " whois.nic.it " ;
break ;
case " fr " :
$serveur = " whois.nic.fr " ;
break ;
case " biz " :
$serveur = " whois.nic.biz " ;
break ;
case " name " :
$serveur = " whois.nic.name " ;
2007-08-22 22:57:03 +00:00
$egal = " domain = " ;
2006-04-26 12:28:53 +00:00
break ;
case " ws " :
$serveur = " whois.samoanic.ws " ;
break ;
2009-01-26 21:07:41 +00:00
case " re " :
$serveur = " whois.nic.re " ;
break ;
2010-08-30 20:16:01 +00:00
case " coop " :
$serveur = " whois.nic.coop " ;
break ;
2006-04-26 12:28:53 +00:00
default :
$err -> raise ( " dom " , 7 );
return false ;
break ;
}
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
// echo "serveur : $serveur <br />";
2010-04-06 20:29:08 +00:00
if (( $fp =@ fsockopen ( $serveur , 43 )) > 0 ) {
2006-04-26 12:28:53 +00:00
fputs ( $fp , " $egal $domain\r\n " );
$found = false ;
$state = 0 ;
while ( ! feof ( $fp )) {
$ligne = fgets ( $fp , 128 );
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
// echo "| $ligne<br />";
switch ( $ext ) {
case " org " :
case " com " :
case " net " :
case " info " :
case " biz " :
case " name " :
2009-01-26 21:07:41 +00:00
case " cc " :
2006-04-26 12:28:53 +00:00
if ( ereg ( " Name Server: " , $ligne )) {
$found = true ;
$tmp = strtolower ( ereg_replace ( chr ( 10 ), " " , ereg_replace ( chr ( 13 ), " " , ereg_replace ( " " , " " , ereg_replace ( " Name Server: " , " " , $ligne )))));
if ( $tmp )
$server [] = $tmp ;
}
break ;
case " cx " :
$ligne = ereg_replace ( chr ( 10 ), " " , ereg_replace ( chr ( 13 ), " " , ereg_replace ( " " , " " , $ligne )));
if ( $ligne == " " && $state == 1 )
$state = 2 ;
if ( $state == 1 )
$server [] = strtolower ( $ligne );
if ( $ligne == " Nameservers: " && $state == 0 ) {
$state = 1 ;
$found = true ;
}
break ;
case " eu " :
case " be " :
2007-08-22 22:57:03 +00:00
$ligne = preg_replace ( " /^ *([^ ]*) \ (.* \ ) $ / " , " \\ 1 " , trim ( $ligne ));
2006-04-26 12:28:53 +00:00
if ( $found )
$tmp = trim ( $ligne );
if ( $tmp )
$server [] = $tmp ;
if ( $ligne == " Nameservers: " ) {
$state = 1 ;
$found = true ;
}
break ;
2009-09-25 16:12:05 +00:00
case " im " :
if ( preg_match ( '/Name Server:/' , $ligne )) {
$found = true ;
// weird regexp (trailing garbage after name server), but I could not make it work otherwise
$tmp = strtolower ( preg_replace ( '/Name Server: ([^ ]+)\..$/' , " \\ 1 " , $ligne ));
$tmp = preg_replace ( '/[^-_a-z0-9\.]/' , '' , $tmp );
if ( $tmp )
$server [] = $tmp ;
}
break ;
case " it " :
2006-04-26 12:28:53 +00:00
if ( ereg ( " nserver: " , $ligne )) {
$found = true ;
$tmp = strtolower ( preg_replace ( " /nserver: \ s*[^ ]* \ s*([^ \ s]*) $ / " , " \\ 1 " , $ligne ));
if ( $tmp )
$server [] = $tmp ;
}
break ;
case " fr " :
2009-01-26 21:07:41 +00:00
case " re " :
2006-04-26 12:28:53 +00:00
if ( ereg ( " nserver: " , $ligne )) {
$found = true ;
$tmp = strtolower ( preg_replace ( " /nserver: \ s*([^ \ s]*) \ s*.* $ / " , " \\ 1 " , $ligne ));
if ( $tmp )
$server [] = $tmp ;
}
break ;
2008-06-18 23:48:04 +00:00
case " ca " :
2006-04-26 12:28:53 +00:00
case " ws " ;
if ( ereg ( '^[[:space:]]*Name servers:[[:space:]]*$' , $ligne )) {
// found the server
$state = 1 ;
} elseif ( $state ) {
2008-06-18 23:48:04 +00:00
if ( ereg ( '^[^%]' , $ligne ) && $ligne = ereg_replace ( '[[:space:]]' , " " , $ligne )) {
2006-04-26 12:28:53 +00:00
// first non-whitespace line is considered to be the nameservers themselves
$found = true ;
$server [] = $ligne ;
}
}
break ;
2010-08-30 20:16:01 +00:00
case " coop " :
if ( preg_match ( '/Host Name:\s*([^\s]+)/' , $ligne , $matches )) {
$found = true ;
$server [] = $matches [ 1 ];
}
2006-04-26 12:28:53 +00:00
} // switch
} // while
fclose ( $fp );
} else {
$err -> raise ( " dom " , 11 );
return false ;
}
if ( $found ) {
return $server ;
} else {
$err -> raise ( " dom " , 12 );
return false ;
}
} // whois
2006-07-04 09:22:55 +00:00
/* ----------------------------------------------------------------- */
/**
* v<EFBFBD> rifie la presence d ' un champs mx valide sur un serveur DNS
*
*/
function checkmx ( $domaine , $mx ) {
//initialise variables
$mxhosts = array ();
//r<> cup<75> re les champs mx
if ( ! getmxrr ( $domaine , $mxhosts )) {
//aucune h<> te mx sp<73> cifi<66>
return 1 ;
}
else {
//v<> rifie qu'un des h<> tes est bien sur alternc
$bolmx = 0 ;
//d<> compose les diff<66> rents champ MX cot<6F> alternc
2006-07-07 10:08:08 +00:00
$arrlocalmx = split ( " , " , $mx );
2006-07-04 09:22:55 +00:00
//parcours les diff<66> rents champ MX retourn<72> s
foreach ( $mxhosts as $mxhost ) {
2006-07-07 10:10:08 +00:00
foreach ( $arrlocalmx as $localmx ) {
2006-07-04 09:22:55 +00:00
if ( $mxhost == $localmx ) {
$bolmx = 1 ;
}
}
}
//d<> finition de l'erreur selon reponse du parcours de mxhosts
if ( $bolmx == 0 ) {
//aucun des champs MX ne correspond au serveur
return 2 ;
}
else {
//un champ mx correct a <20> t<EFBFBD> trouv<75>
return 0 ;
}
}
} //checkmx
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* retourne TOUTES les infos d ' un domaine
*
* < b > Note </ b > : si le domaine est en attente ( pr<EFBFBD> sent dans
* domaines_standby ), une erreur est retourn<EFBFBD> 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 :< br />< pre >
* $r [ " name " ] = Nom fqdn
* $r [ " dns " ] = Gestion du dns ou pas ?
* $r [ " mx " ] = Valeur du champs MX si " dns " = true
* $r [ " mail " ] = Heberge - t - on le mail ou pas ? ( si " dns " = false )
* $r [ " nsub " ] = Nombre de sous - domaines
* $r [ " sub " ] = tableau associatif des sous - domaines
* $r [ " sub " ][ 0 - ( nsub - 1 )][ " name " ] = nom du sous - domaine ( NON - complet )
* $r [ " sub " ][ 0 - ( nsub - 1 )][ " dest " ] = Destination ( url , ip , local ... )
* $r [ " sub " ][ 0 - ( nsub - 1 )][ " type " ] = Type ( 0 - n ) de la redirection .
* </ pre >
* Retourne FALSE si une erreur s ' est produite .
*
*/
function get_domain_all ( $dom ) {
global $db , $err , $cuid ;
$err -> log ( " dom " , " get_domain_all " , $dom );
// Locked ?
if ( ! $this -> islocked ) {
$err -> raise ( " dom " , 3 );
return false ;
}
$t = checkfqdn ( $dom );
if ( $t ) {
$err -> raise ( " dom " , 3 + $t );
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 );
return false ;
}
$db -> next_record ();
$r [ " dns " ] = $db -> Record [ " gesdns " ];
$r [ " mail " ] = $db -> Record [ " gesmx " ];
$r [ " mx " ] = $db -> Record [ " mx " ];
$r [ noerase ] = $db -> Record [ noerase ];
$db -> free ();
$db -> query ( " select count(*) as cnt from sub_domaines where compte=' $cuid ' and domaine=' $dom ' " );
$db -> next_record ();
$r [ " nsub " ] = $db -> Record [ " cnt " ];
$db -> free ();
$db -> query ( " select * from sub_domaines where compte=' $cuid ' and domaine=' $dom ' " );
// Pas de webmail, on le cochera si on le trouve.
$this -> webmail = 0 ;
for ( $i = 0 ; $i < $r [ " nsub " ]; $i ++ ) {
$db -> next_record ();
$r [ " sub " ][ $i ] = array ();
$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 ;
} // get_domain_all
2007-08-27 06:51:09 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* Retourne TOUTES les infos d ' un sous domaine du compte courant .
*
* @ param string $dom Domaine fqdn concern<EFBFBD>
* @ param string $sub Sous - domaine dont on souhaite les informations
* @ return arrray Retourne un tableau associatif contenant les
* informations du sous - domaine demand<EFBFBD> .< pre >
* $r [ " name " ] = nom du sous - domaine ( NON - complet )
* $r [ " dest " ] = Destination ( url , ip , local ... )
* </ pre >
* $r [ " type " ] = Type ( 0 - n ) de la redirection .
* Retourne FALSE si une erreur s ' est produite .
*/
2010-11-16 17:11:06 +00:00
function get_sub_domain_all ( $dom , $sub , $type = " " ) {
2006-04-26 12:28:53 +00:00
global $db , $err , $cuid ;
$err -> log ( " dom " , " get_sub_domain_all " , $dom . " / " . $sub );
// Locked ?
if ( ! $this -> islocked ) {
$err -> raise ( " dom " , 3 );
return false ;
}
$t = checkfqdn ( $dom );
if ( $t ) {
$err -> raise ( " dom " , 3 + $t );
return false ;
}
2010-11-16 17:11:06 +00:00
if ( ! empty ( $type )) {
$type = " and type=' " . intval ( $type ) . " ' " ;
}
$db -> query ( " select * from sub_domaines where compte=' $cuid ' and domaine=' $dom ' and sub=' $sub ' $type " );
2006-04-26 12:28:53 +00:00
if ( $db -> num_rows () == 0 ) {
$err -> raise ( " dom " , 14 );
return false ;
}
$db -> next_record ();
$r = array ();
$r [ " name " ] = $db -> Record [ " sub " ];
$r [ " dest " ] = $db -> Record [ " valeur " ];
$r [ " type " ] = $db -> Record [ " type " ];
$db -> free ();
return $r ;
} // get_sub_domain_all
2007-08-27 06:51:09 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* Modifier les information du sous - domaine demand<EFBFBD> .
*
* < b > Note </ b > : si le sous - domaine $sub . $dom n ' existe pas , il est cr<EFBFBD> <EFBFBD> .< br />
* < b > Note : TODO </ b > : v<EFBFBD> rification de concordance de $dest < br />
*
* @ param string $dom Domaine dont on souhaite modifier / ajouter un sous domaine
* @ param string $subk Sous domaine <EFBFBD> modifier / cr<EFBFBD> er
* @ param integer $type Type de sous - domaine ( local , ip , url ... )
* @ param string $action Action : vaut " add " ou " edit " selon que l ' on
* Cr<EFBFBD> e ( add ) ou Modifie ( edit ) le sous - domaine
* @ param string $dest Destination du sous - domaine , d<EFBFBD> pend de la valeur
* de $type ( url , ip , dossier ... )
* @ return boolean Retourne FALSE si une erreur s ' est produite , TRUE sinon .
*/
2010-11-16 17:11:06 +00:00
function set_sub_domain ( $dom , $sub , $type , $action , $dest , $type_old = null ) {
if ( is_null ( $type_old )) $type_old = $type ;
2006-04-26 12:28:53 +00:00
global $db , $err , $cuid ;
$err -> log ( " dom " , " set_sub_domain " , $dom . " / " . $sub );
// Locked ?
if ( ! $this -> islocked ) {
$err -> raise ( " dom " , 3 );
return false ;
}
$dest = trim ( $dest );
2007-08-27 07:19:10 +00:00
$sub = trim ( trim ( $sub ), " . " );
2006-04-26 12:28:53 +00:00
$dom = strtolower ( $dom );
$sub = strtolower ( $sub );
2006-11-09 20:11:16 +00:00
2007-08-27 06:55:03 +00:00
// if (!(($sub == '*') || ($sub=="") || (preg_match('/([a-z0-9][\.\-a-z0-9]*)?[a-z0-9]/', $sub)))) {
2007-08-27 07:19:10 +00:00
$fqdn = checkfqdn ( $sub );
2007-09-25 15:13:57 +00:00
// Special cases : * (all subdomains at once) and '' empty subdomain are allowed.
if (( $sub != '*' && $sub != '' ) && ! ( $fqdn == 0 || $fqdn == 4 )) {
2006-04-26 12:28:53 +00:00
$err -> raise ( " dom " , 24 );
return false ;
}
if ( $type == 2 ) { // IP
if ( ! checkip ( $dest )) {
2010-11-16 17:11:06 +00:00
$err -> raise ( " dom " , 19 );
return false ;
2006-04-26 12:28:53 +00:00
}
}
2010-11-14 16:54:27 +00:00
if ( $type == 4 ) { // IPv6
if ( ! checkipv6 ( $dest )) {
2010-11-16 17:11:06 +00:00
$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 ;
2010-11-14 16:54:27 +00:00
}
}
2006-04-26 12:28:53 +00:00
if ( $type == 1 ) { // URL
if ( ! checkurl ( $dest )) {
2010-11-16 17:11:06 +00:00
$err -> raise ( " dom " , 20 );
return false ;
2006-04-26 12:28:53 +00:00
}
}
if ( $type == 0 ) { // LOCAL
if ( substr ( $dest , 0 , 1 ) != " / " ) {
2010-11-16 17:11:06 +00:00
$dest = " / " . $dest ;
2006-04-26 12:28:53 +00:00
}
if ( ! checkuserpath ( $dest )) {
2010-11-16 17:11:06 +00:00
$err -> raise ( " dom " , 21 );
return false ;
2006-04-26 12:28:53 +00:00
}
}
// On a <20> pur<75> $dir des probl<62> mes eventuels ... On est en DESSOUS du dossier de l'utilisateur.
$t = checkfqdn ( $dom );
if ( $t ) {
$err -> raise ( " dom " , 3 + $t );
return false ;
}
2010-11-16 17:11:06 +00:00
// Si l'action demand<6E> est une cr<63> ation
if ( $action == " add " ) {
$do_create = false ;
// Tout d'abord on v<> rifie si il faut le cr<63> 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 <20> tre en doublon
foreach ( $r as $rr ) { $rtype [] = $rr [ 'type' ];} // Tableau pour v<> rifier les compatibilit<69> 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<63> 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 <20> t<EFBFBD> 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
}
2006-04-26 12:28:53 +00:00
} else {
2010-11-16 17:11:06 +00:00
$err -> raise ( " dom " , 16 );
return false ;
2006-04-26 12:28:53 +00:00
}
return true ;
} // set_sub_domain
/* ----------------------------------------------------------------- */
/**
* Supprime le sous - domaine demand<EFBFBD>
*
* @ param string $dom Domaine dont on souhaite supprimer un sous - domaine
* @ param string $sub Sous - domaine que l ' on souhaite supprimer
* @ return boolean Retourne FALSE si une erreur s ' est produite , TRUE sinon .
*
*/
2010-11-16 17:11:06 +00:00
function del_sub_domain ( $dom , $sub , $type ) {
2006-04-26 12:28:53 +00:00
global $db , $err , $cuid ;
$err -> log ( " dom " , " del_sub_domain " , $dom . " / " . $sub );
// Locked ?
if ( ! $this -> islocked ) {
$err -> raise ( " dom " , 3 );
return false ;
}
$t = checkfqdn ( $dom );
if ( $t ) {
$err -> raise ( " dom " , 3 + $t );
return false ;
}
2010-11-16 17:11:06 +00:00
if ( ! $r = $this -> get_sub_domain_all ( $dom , $sub , $type )) {
2006-04-26 12:28:53 +00:00
// Le sous-domaine n'existe pas, erreur
$err -> raise ( " dom " , 14 );
return false ;
} else {
// OK, on valide :
2010-11-16 17:11:06 +00:00
$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 " );
2006-04-26 12:28:53 +00:00
$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 ;
} // del_sub_domain
/* ----------------------------------------------------------------- */
/**
* Modifie les information du domaine pr<EFBFBD> cis<EFBFBD> .
*
* @ param string $dom Domaine du compte courant que l ' on souhaite modifier
* @ param integer $dns Vaut 1 ou 0 pour h<EFBFBD> berger ou pas le DNS du domaine
* @ param integer $mx Nom fqdn du serveur mx , si le mx local est pr<EFBFBD> cis<EFBFBD> ,
* on h<EFBFBD> berge alors les mails du domaine .
2007-09-09 20:33:30 +00:00
* @ param boolean $force Faut - il passer les checks DNS ou MX ? ( admin only )
2006-04-26 12:28:53 +00:00
* @ return boolean appelle $mail -> add_dom ou $ma -> del_dom si besoin , en
* fonction du champs MX . Retourne FALSE si une erreur s ' est produite ,
* TRUE sinon .
*
*/
2007-09-11 22:11:22 +00:00
function edit_domain ( $dom , $dns , $mx , $force = 0 ) {
2006-04-26 12:28:53 +00:00
global $db , $err , $L_MX , $classes , $cuid ;
$err -> log ( " dom " , " edit_domain " , $dom );
// Locked ?
2007-09-09 20:33:30 +00:00
if ( ! $this -> islocked && ! $force ) {
2006-04-26 12:28:53 +00:00
$err -> raise ( " dom " , 3 );
return false ;
}
2007-09-09 20:33:30 +00:00
if ( $dns == 1 && ! $force ) {
2006-04-26 12:28:53 +00:00
$this -> dns = $this -> whois ( $dom );
$v = checkhostallow ( $dom , $this -> dns );
if ( $v ==- 1 ) {
$err -> raise ( " dom " , 7 ); // TLD interdit
return false ;
}
if ( $dns && $v ==- 2 ) {
$err -> raise ( " dom " , 12 ); // Domaine non trouv<75> dans le whois
return false ;
}
if ( $dns && $v ==- 3 ) {
$err -> raise ( " dom " , 23 ); // Domaine non trouv<75> dans le whois
return false ;
}
}
$t = checkfqdn ( $dom );
if ( $t ) {
$err -> raise ( " dom " , 3 + $t );
return false ;
}
if ( ! $r = $this -> get_domain_all ( $dom )) {
// Le domaine n'existe pas, Failure
$err -> raise ( " dom " , 4 , $dom );
return false ;
}
if ( $dns != " 1 " ) $dns = " 0 " ;
// On v<> rifie que des modifications ont bien eu lieu :)
if ( $r [ " dns " ] == $dns && $r [ " mx " ] == $mx ) {
$err -> raise ( " dom " , 15 );
return false ;
}
// MX ?
if ( $mx == $L_MX )
$gesmx = " 1 " ;
else
$gesmx = " 0 " ;
2006-07-04 09:22:55 +00:00
//si gestion mx uniquement, v<> rification du dns externe
2007-09-09 20:33:30 +00:00
if ( $dns == " 0 " && $gesmx == " 1 " && ! $force ) {
2007-02-09 12:58:33 +00:00
$vmx = $this -> checkmx ( $dom , $mx );
2006-07-04 09:22:55 +00:00
if ( $vmx == 1 ) {
2007-09-09 20:33:30 +00:00
// Aucun champ mx de sp<73> cifi<66> sur le dns
$err -> raise ( " dom " , 25 );
return false ;
2006-07-04 09:22:55 +00:00
}
if ( $vmx == 2 ) {
2007-09-09 20:33:30 +00:00
// Serveur non sp<73> cifi<66> parmi les champx mx
$err -> raise ( " dom " , 25 );
return false ;
2006-07-04 09:22:55 +00:00
}
}
2006-04-26 12:28:53 +00:00
// OK, des modifs ont <20> t<EFBFBD> faites, on valide :
// DEPENDANCE :
if ( $gesmx && ! $r [ " mail " ]) { // on a associ<63> le MX : on cree donc l'entree dans LDAP
// Lancement de add_dom sur les classes domain_sensitive :
foreach ( $classes as $c ) {
if ( method_exists ( $GLOBALS [ $c ], " alternc_add_mx_domain " )) {
$GLOBALS [ $c ] -> alternc_add_mx_domain ( $dom );
}
}
}
if ( ! $gesmx && $r [ " mail " ]) { // on a dissoci<63> le MX : on d<> truit donc l'entree dans LDAP
// Lancement de del_dom sur les classes domain_sensitive :
foreach ( $classes as $c ) {
if ( method_exists ( $GLOBALS [ $c ], " alternc_del_mx_domain " )) {
$GLOBALS [ $c ] -> alternc_del_mx_domain ( $dom );
}
}
}
2010-06-23 22:16:10 +00:00
$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 '; " );
}
2006-04-26 12:28:53 +00:00
return true ;
} // edit_domain
/****************************/
/* Slave dns ip managment */
/****************************/
/* ----------------------------------------------------------------- */
/**
* Return the list of ip addresses and classes that are allowed access to domain list
* through AXFR Transfers from the bind server .
*/
function enum_slave_ip () {
global $db , $err ;
$db -> query ( " SELECT * FROM slaveip; " );
if ( ! $db -> next_record ()) {
return false ;
}
do {
$res [] = $db -> Record ;
} while ( $db -> next_record ());
return $res ;
}
/* ----------------------------------------------------------------- */
/**
* Add an ip address ( or a ip class ) to the list of allowed slave ip access list .
*/
function add_slave_ip ( $ip , $class = " 32 " ) {
global $db , $err ;
if ( ! checkip ( $ip )) {
$err -> raise ( " dom " , 19 );
return false ;
}
$class = intval ( $class );
if ( $class < 8 || $class > 32 ) $class = 32 ;
$db -> query ( " SELECT * FROM slaveip WHERE ip=' $ip ' AND class=' $class '; " );
if ( $db -> next_record ()) {
$err -> raise ( " err " , 22 );
return false ;
}
$db -> query ( " INSERT INTO slaveip (ip,class) VALUES (' $ip ',' $class '); " );
$f = fopen ( SLAVE_FLAG , " w " );
fputs ( $f , " yopla " );
fclose ( $f );
return true ;
}
/* ----------------------------------------------------------------- */
/**
* Remove an ip address ( or a ip class ) from the list of allowed slave ip access list .
*/
function del_slave_ip ( $ip ) {
global $db , $err ;
if ( ! checkip ( $ip )) {
$err -> raise ( " dom " , 19 );
return false ;
}
$db -> query ( " DELETE FROM slaveip WHERE ip=' $ip ' " );
$f = fopen ( SLAVE_FLAG , " w " );
fputs ( $f , " yopla " );
fclose ( $f );
return true ;
}
/* ----------------------------------------------------------------- */
/**
* Check for a slave account
*/
function check_slave_account ( $login , $pass ) {
global $db , $err ;
$db -> query ( " SELECT * FROM slaveaccount WHERE login=' $login ' AND pass=' $pass '; " );
if ( $db -> next_record ()) {
return true ;
}
return false ;
}
/* ----------------------------------------------------------------- */
/**
* Out ( echo ) the complete hosted domain list :
*/
function echo_domain_list () {
global $db , $err ;
$db -> query ( " SELECT domaine FROM domaines WHERE gesdns=1 ORDER BY domaine " );
while ( $db -> next_record ()) {
echo $db -> f ( " domaine " ) . " \n " ;
}
return true ;
}
2010-03-04 16:16:13 +00:00
/* ----------------------------------------------------------------- */
/**
* Returns the complete hosted domain list :
*/
2010-05-24 11:40:39 +00:00
function get_domain_list ( $uid =- 1 ) {
2010-03-04 16:16:13 +00:00
global $db , $err ;
2010-05-24 11:40:39 +00:00
$uid = intval ( $uid );
2010-03-04 16:16:13 +00:00
$res = array ();
2010-05-24 11:40:39 +00:00
if ( $uid !=- 1 ) {
$sql = " AND compte=' $uid ' " ;
}
$db -> query ( " SELECT domaine FROM domaines WHERE gesdns=1 $sql ORDER BY domaine " );
2010-03-04 16:16:13 +00:00
while ( $db -> next_record ()) {
$res [] = $db -> f ( " domaine " );
}
return $res ;
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* Return the list of allowed slave accounts
*/
function enum_slave_account () {
global $db , $err ;
$db -> query ( " SELECT * FROM slaveaccount; " );
$res = array ();
while ( $db -> next_record ()) {
$res [] = $db -> Record ;
}
if ( ! count ( $res )) return false ;
return $res ;
}
/* ----------------------------------------------------------------- */
/**
* Add a slave account that will be allowed to access the domain list
*/
function add_slave_account ( $login , $pass ) {
global $db , $err ;
$db -> query ( " SELECT * FROM slaveaccount WHERE login=' $login ' " );
if ( $db -> next_record ()) {
$err -> raise ( " err " , 23 );
return false ;
}
$db -> query ( " INSERT INTO slaveaccount (login,pass) VALUES (' $login ',' $pass ') " );
return true ;
}
/* ----------------------------------------------------------------- */
/**
* Remove a slave account
*/
function del_slave_account ( $login ) {
global $db , $err ;
$db -> query ( " DELETE FROM slaveaccount WHERE login=' $login ' " );
return true ;
}
/*************/
/* Private */
/*************/
/* ----------------------------------------------------------------- */
/**
* Lock tente de verrouiller le fichier lock du cron . Si tout va bien ( toujours ? )
* retourne True , sinon retourne False
* NOTE : le systeme de lock est asym<EFBFBD> trique , si on a un fichier CRONLOCK , on
* attends ( que le cron ait fini son execution ) .
* @ access private
*/
function lock () {
global $db , $err ;
$err -> log ( " dom " , " lock " );
if ( $this -> islocked ) {
$err -> raise ( " dom " , 17 );
}
while ( file_exists ( $this -> fic_lock_cron )) {
sleep ( 2 );
}
$this -> islocked = true ;
return true ;
}
/* ----------------------------------------------------------------- */
/**
* unlock d<EFBFBD> verrouille le fichier lock du cron . Si tout va bien ( toujours ? )
* retourne True , sinon retourne False
* NOTE : actuellement , vu le syst<EFBFBD> me de lock asymetrique , on ne fait rien ;)
* @ access private
*/
function unlock () {
global $db , $err ;
$err -> log ( " dom " , " unlock " );
if ( ! $this -> islocked ) {
$err -> raise ( " dom " , 3 );
}
$this -> islocked = false ;
return true ;
}
/* ----------------------------------------------------------------- */
/**
* Efface un compte ( tous ses domaines )
*/
function alternc_del_member () {
global $err ;
$err -> log ( " dom " , " alternc_del_member " );
$li = $this -> enum_domains ();
foreach ( $li as $dom ) {
$this -> del_domain ( $dom );
}
return true ;
}
/* ----------------------------------------------------------------- */
/**
* Returns the used quota for the $name service for the current user .
* @ param $name string name of the quota
* @ return integer the number of service used or false if an error occured
* @ access private
*/
function alternc_get_quota ( $name ) {
global $db , $err , $cuid ;
if ( $name == " dom " ) {
$err -> log ( " dom " , " get_quota " );
$db -> query ( " SELECT COUNT(*) AS cnt FROM domaines WHERE compte=' $cuid ' " );
$db -> next_record ();
return $db -> f ( " cnt " );
} else return false ;
}
/* ----------------------------------------------------------------- */
/**
* Exporte toutes les informations domaine du compte .
* @ access private
* EXPERIMENTAL 'sid' function ;)
*/
function alternc_export () {
global $db , $err ;
$err -> log ( " dom " , " export " );
$this -> enum_domains ();
$str = " <dom> \n " ;
foreach ( $this -> domains as $d ) {
$str .= " <domain> \n <name> " . xml_entities ( $d ) . " </name> \n " ;
$s = $this -> get_domain_all ( $d );
$str .= " <hasdns> " . xml_entities ( $s [ dns ]) . " </hasdns> \n " ;
$str .= " <hasmx> " . xml_entities ( $s [ mx ]) . " </hasmx> \n " ;
$str .= " <mx> " . xml_entities ( $s [ mail ]) . " </mx> \n " ;
if ( is_array ( $s [ sub ])) {
foreach ( $s [ sub ] as $sub ) {
$str .= " <subdomain> " ;
$str .= " <name> " . xml_entities ( $sub [ name ]) . " </name> " ;
$str .= " <dest> " . xml_entities ( $sub [ dest ]) . " </dest> " ;
$str .= " <type> " . xml_entities ( $sub [ type ]) . " </type> " ;
$str .= " </subdomain> \n " ;
}
}
$str .= " </domain> \n " ;
}
$str .= " </dom> \n " ;
return $str ;
}
} /* Class m_domains */
?>