2006-04-26 12:28:53 +00:00
< ? php
2012-08-25 14:04:38 +00:00
/*
2006-04-26 12:28:53 +00:00
----------------------------------------------------------------------
2012-08-25 14:04:38 +00:00
AlternC - Web Hosting System
Copyright ( C ) 2000 - 2012 by the AlternC Development Team .
https :// alternc . org /
----------------------------------------------------------------------
2006-04-26 12:28:53 +00:00
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
----------------------------------------------------------------------
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 />
*/
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 ;
2011-03-06 18:06:27 +00:00
var $type_local = " VHOST " ;
2011-01-28 15:55:26 +00:00
var $type_url = " URL " ;
var $type_ip = " IP " ;
var $type_webmail = " WEBMAIL " ;
var $type_ipv6 = " IPV6 " ;
var $type_cname = " CNAME " ;
var $type_txt = " TXT " ;
2011-06-04 14:28:57 +00:00
var $type_defmx = " DEFMX " ;
var $type_defmx2 = " DEFMX2 " ;
2006-04-26 12:28:53 +00:00
var $action_insert = " 0 " ;
var $action_update = " 1 " ;
var $action_delete = " 2 " ;
/* ----------------------------------------------------------------- */
/**
* Constructeur
*/
function m_dom () {
}
2011-01-26 17:26:01 +00:00
/* ----------------------------------------------------------------- */
/**
* Retourne un tableau contenant les types de domaines
*
* @ return array retourne un tableau index<EFBFBD> contenant la liste types de domaines
* authoris<EFBFBD> . Retourne FALSE si une erreur s ' est produite .
*/
function domains_type_lst () {
global $db , $err , $cuid ;
$err -> log ( " dom " , " domains_type_lst " );
2011-03-27 13:29:44 +00:00
$db -> query ( " select * from domaines_type order by advanced; " );
2011-01-26 17:26:01 +00:00
$this -> domains_type_lst = false ;
while ( $db -> next_record ()) {
2011-06-04 14:28:57 +00:00
$this -> domains_type_lst [ strtolower ( $db -> Record [ " name " ])] = $db -> Record ;
2011-01-26 17:26:01 +00:00
}
return $this -> domains_type_lst ;
}
2011-03-06 15:03:51 +00:00
function domains_type_enable_values () {
global $db , $err , $cuid ;
$err -> log ( " dom " , " domains_type_target_values " );
$db -> query ( " desc domaines_type; " );
$r = array ();
while ( $db -> next_record ()) {
if ( $db -> f ( 'Field' ) == 'enable' ) {
$tab = explode ( " , " , substr ( $db -> f ( 'Type' ), 5 , - 1 ));
foreach ( $tab as $t ) { $r [] = substr ( $t , 1 , - 1 ); }
}
}
return $r ;
}
2011-01-28 15:55:26 +00:00
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' );
}
}
2011-01-30 13:18:14 +00:00
function domains_type_regenerate ( $name ) {
global $db , $err , $cuid ;
$name = mysql_real_escape_string ( $name );
$db -> query ( " update sub_domaines set web_action='UPDATE' where lower(type) = lower(' $name ') ; " );
$db -> query ( " update domaines d, sub_domaines sd set d.dns_action = 'UPDATE' where lower(sd.type)=lower(' $name '); " );
return true ;
}
2011-01-28 15:55:26 +00:00
function domains_type_get ( $name ) {
2011-01-26 17:26:01 +00:00
global $db , $err , $cuid ;
2011-01-28 15:55:26 +00:00
$name = mysql_real_escape_string ( $name );
$db -> query ( " select * from domaines_type where name=' $name ' ; " );
2011-01-26 17:26:01 +00:00
$db -> next_record ();
return $db -> Record ;
}
2011-01-28 15:55:26 +00:00
function domains_type_del ( $name ) {
2011-01-26 17:26:01 +00:00
global $db , $err , $cuid ;
2011-01-28 15:55:26 +00:00
$name = mysql_real_escape_string ( $name );
$db -> query ( " delete domaines_type where name=' $name '; " );
2011-01-26 17:26:01 +00:00
return true ;
}
2011-03-06 15:03:51 +00:00
function domains_type_update ( $name , $description , $target , $entry , $compatibility , $enable , $only_dns , $need_dns , $advanced ) {
2011-01-26 17:26:01 +00:00
global $err , $cuid , $db ;
2012-08-23 18:46:47 +00:00
$id = intval ( $id );
2011-10-18 19:09:44 +00:00
// The name MUST contain only letter and digits, it's an identifier after all ...
if ( ! preg_match ( " #^[a-z0-9]+ $ # " , $name )) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The name MUST contain only letter and digits. " ));
2011-10-18 19:09:44 +00:00
return false ;
}
2012-08-25 14:04:38 +00:00
$name = mysql_real_escape_string ( $name ); $description = mysql_real_escape_string ( $description ); $target = mysql_real_escape_string ( $target );
$entry = mysql_real_escape_string ( $entry ); $compatibility = mysql_real_escape_string ( $compatibility ); $enable = mysql_real_escape_string ( $enable );
$only_dns = intval ( $only_dns ); $need_dns = intval ( $need_dns ); $advanced = intval ( $advanced );
2011-03-06 15:03:51 +00:00
$db -> query ( " UPDATE domaines_type SET description=' $description ', target=' $target ', entry=' $entry ', compatibility=' $compatibility ', enable=' $enable ', need_dns= $need_dns , only_dns= $only_dns , advanced=' $advanced ' where name=' $name '; " );
2011-01-26 17:26:01 +00:00
return true ;
}
2011-01-29 18:26:32 +00:00
function sub_domain_change_status ( $domain , $sub , $type , $value , $status ) {
global $db , $err , $cuid ;
$err -> log ( " dom " , " sub_domain_change_status " );
$status = strtoupper ( $status );
if ( ! in_array ( $status , array ( 'ENABLE' , 'DISABLE' ))) return false ;
$db -> query ( " update sub_domaines set enable=' $status ' where domaine=' $domain ' and sub=' $sub ' and lower(type)=lower(' $type ') and valeur=' $value ' " );
return true ;
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* Retourne un tableau contenant les domaines d ' un membre .
2012-08-24 17:27:48 +00:00
* Par d<EFBFBD> faut le membre connect<EFBFBD>
2006-04-26 12:28:53 +00:00
*
* @ 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 .
*/
2012-08-24 17:27:48 +00:00
function enum_domains ( $uid =- 1 ) {
2006-04-26 12:28:53 +00:00
global $db , $err , $cuid ;
$err -> log ( " dom " , " enum_domains " );
2012-08-24 17:27:48 +00:00
if ( $uid == - 1 ) { $uid = $cuid ; }
$db -> query ( " SELECT * FROM domaines WHERE compte=' { $uid } ' ORDER BY domaine ASC; " );
2006-04-26 12:28:53 +00:00
$this -> domains = array ();
if ( $db -> num_rows () > 0 ) {
while ( $db -> next_record ()) {
2011-03-06 18:06:27 +00:00
$this -> domains [] = $db -> f ( " domaine " );
2006-04-26 12:28:53 +00:00
}
}
return $this -> domains ;
}
2011-01-29 10:35:12 +00:00
function del_domain_cancel ( $dom ) {
global $db , $err , $classes , $cuid ;
$err -> log ( " dom " , " del_domaini_canl " , $dom );
$dom = strtolower ( $dom );
$db -> query ( " UPDATE sub_domaines SET web_action='UPDATE' WHERE domaine=' $dom '; " );
$db -> query ( " UPDATE domaines SET dns_action='UPDATE' WHERE domaine=' $dom '; " );
2011-01-29 18:26:32 +00:00
# TODO : some work with domain sensitive classes
2011-01-29 10:35:12 +00:00
return true ;
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* 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 ) {
2012-08-25 14:04:38 +00:00
global $db , $err , $classes , $cuid , $hooks ;
2006-04-26 12:28:53 +00:00
$err -> log ( " dom " , " del_domain " , $dom );
$dom = strtolower ( $dom );
2012-08-25 14:04:38 +00:00
if ( ! $r = $this -> get_domain_all ( $dom )) {
2006-04-26 12:28:53 +00:00
return false ;
}
2012-08-25 14:04:38 +00:00
// Call Hooks to delete the domain and the MX management:
// TODO : the 2 calls below are using an OLD hook call, FIXME: remove them when unused
$hooks -> invoke ( " alternc_del_domain " , array ( $dom ));
$hooks -> invoke ( " alternc_del_mx_domain " , array ( $dom ));
// New hook calls:
$hooks -> invoke ( " hook_dom_del_domain " , array ( $r [ " id " ]));
$hooks -> invoke ( " hook_dom_del_mx_domain " , array ( $r [ " id " ]));
// Now mark the domain for deletion:
2011-01-28 15:55:26 +00:00
$db -> query ( " UPDATE sub_domaines SET web_action='DELETE' WHERE domaine=' $dom '; " );
$db -> query ( " UPDATE domaines SET dns_action='DELETE' WHERE domaine=' $dom '; " );
2006-04-26 12:28:53 +00:00
return true ;
}
2012-08-27 19:23:23 +00:00
function domshort ( $dom , $sub = " " ) {
return str_replace ( " - " , " " , str_replace ( " . " , " " , empty ( $sub ) ? " " : " $sub . " ) . $dom );
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* 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 = " " ) {
2012-08-25 14:04:38 +00:00
global $db , $err , $quota , $classes , $L_MX , $L_FQDN , $tld , $cuid , $bro , $hooks ;
2006-04-26 12:28:53 +00:00
$err -> log ( " dom " , " add_domain " , $domain );
2011-06-04 14:28:57 +00:00
2006-04-26 12:28:53 +00:00
// Locked ?
if ( ! $this -> islocked ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " --- Program error --- No lock on the domains! " ));
2006-04-26 12:28:53 +00:00
return false ;
}
// Verifie que le domaine est rfc-compliant
$domain = strtolower ( $domain );
$t = checkfqdn ( $domain );
if ( $t ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The domain name is syntaxically incorrect " ));
2006-04-26 12:28:53 +00:00
return false ;
}
// Interdit les domaines cl<63> s (table forbidden_domains) sauf en cas FORCE
2012-08-25 14:04:38 +00:00
$db -> query ( " SELECT domain FROM forbidden_domains WHERE domain=' $domain ' " );
2006-04-26 12:28:53 +00:00
if ( $db -> num_rows () && ! $force ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The requested domain is forbidden in this server, please contact the administrator " ));
2006-04-26 12:28:53 +00:00
return false ;
}
if ( $domain == $L_FQDN || $domain == " www. $L_FQDN " ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " This domain is the server's domain! You cannot host it on your account! " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db -> query ( " SELECT compte FROM domaines WHERE domaine=' $domain '; " );
if ( $db -> num_rows ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The domain already exist. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db -> query ( " SELECT compte FROM `sub_domaines` WHERE sub != \" \" AND concat( sub, \" . \" , domaine )=' $domain ' OR domaine=' $domain '; " );
if ( $db -> num_rows ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The domain already exist. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$this -> dns = $this -> whois ( $domain );
if ( ! $force ) {
$v = checkhostallow ( $domain , $this -> dns );
if ( $v ==- 1 ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The last member of the domain name is incorrect or cannot be hosted in that server. " ));
2011-03-28 12:28:37 +00:00
return false ;
2006-04-26 12:28:53 +00:00
}
if ( $dns && $v ==- 2 ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The domain cannot be found in the whois database. " ));
2011-03-28 12:28:37 +00:00
return false ;
2006-04-26 12:28:53 +00:00
}
if ( $dns && $v ==- 3 ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The domain cannot be found in the whois database. " ));
2011-03-28 12:28:37 +00:00
return false ;
2006-04-26 12:28:53 +00:00
}
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 ) {
2011-03-28 12:28:37 +00:00
$v = checkhostallow_nodns ( $domain );
if ( $v ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The requested domain is forbidden in this server, please contact the administrator " ));
2011-03-28 12:28:37 +00:00
return false ;
}
2006-04-26 12:28:53 +00:00
}
}
// Check the quota :
if ( ! $quota -> cancreate ( " dom " )) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " Your domain quota is over, you cannot create more domain names. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
if ( $noerase ) $noerase = " 1 " ; else $noerase = " 0 " ;
2012-08-25 14:04:38 +00:00
$db -> query ( " INSERT INTO domaines (compte,domaine,gesdns,gesmx,noerase,dns_action) VALUES (' $cuid ',' $domain ',' $dns ','1',' $noerase ','UPDATE'); " );
if ( ! ( $id = $db -> lastid ())) {
$err -> raise ( " dom " , _ ( " An unexpected error occured when creating the domain " ));
return false ;
}
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 " ]) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " Domain '%s' not found. " ), $slavedom );
2011-03-28 12:28:37 +00:00
$isslave = false ;
2010-03-04 16:16:13 +00:00
}
// Point to the master domain :
2012-08-27 19:23:23 +00:00
$this -> create_default_subdomains ( $domain , $slavedom );
2010-03-04 16:16:13 +00:00
}
if ( ! $isslave ) {
2012-08-27 19:23:23 +00:00
$this -> create_default_subdomains ( $domain );
2009-01-28 22:12:01 +00:00
}
2011-03-28 12:28:37 +00:00
2012-08-25 14:04:38 +00:00
// TODO: Old hooks, FIXME: when unused remove them
$hooks -> invoke ( " alternc_add_domain " , array ( $domain ));
$hooks -> invoke ( " alternc_add_mx_domain " , array ( $domain ));
if ( $isslave ) {
$hooks -> invoke ( " alternc_add_slave_domain " , array ( $domain ));
2006-04-26 12:28:53 +00:00
}
2012-08-25 14:04:38 +00:00
// New Hooks:
$hooks -> invoke ( " hook_dom_add_domain " , array ( $id ));
$hooks -> invoke ( " hook_dom_add_mx_domain " , array ( $id ));
2010-03-04 16:16:13 +00:00
if ( $isslave ) {
2012-08-25 14:04:38 +00:00
$hooks -> invoke ( " hook_dom_add_slave_domain " , array ( $id ));
2010-03-04 16:16:13 +00:00
}
return true ;
2006-04-26 12:28:53 +00:00
}
2012-08-27 19:23:23 +00:00
function create_default_subdomains ( $domain , $target_domain = " " ){
global $db ;
2012-08-31 10:05:39 +00:00
$err -> log ( " dom " , " create_default_subdomains " , $domain );
2012-08-27 19:23:23 +00:00
$query = " SELECT sub, domain_type, domain_type_parameter FROM default_subdomains WHERE concerned = 'SLAVE' or concerned = 'BOTH' and enabled=1; " ;
if ( empty ( $target_domain )) {
$query = " SELECT sub, domain_type, domain_type_parameter FROM default_subdomains WHERE concerned = 'MAIN' or concerned = 'BOTH' and enabled=1; " ;
}
$domaindir = $this -> domdefaultdir ( $domain );
$db -> query ( $query );
$jj = array ();
while ( $db -> next_record ()) {
$jj [] = Array ( " domain_type_parameter " => $db -> f ( 'domain_type_parameter' ), " sub " => $db -> f ( 'sub' ), " domain_type " => $db -> f ( 'domain_type' ));
}
$src_var = array ( " %%SUB%% " , " %%DOMAIN%% " , " %%DOMAINDIR%% " , " %%TARGETDOM%% " );
foreach ( $jj as $j ){
$trg_var = array ( $j [ 'sub' ], $domain , $domaindir , $target_domain );
$domain_type_parameter = str_ireplace ( $src_var , $trg_var , $j [ 'domain_type_parameter' ]);
$this -> set_sub_domain ( $domain , $j [ 'sub' ], strtolower ( $j [ 'domain_type' ]), $domain_type_parameter );
}
}
function domdefaultdir ( $domain ) {
global $bro , $cuid ;
$dest_root = $bro -> get_userid_root ( $cuid );
# return $dest_root."/www/".$this->domshort($domain);
return " /www/ " . $this -> domshort ( $domain );
}
2012-08-25 14:04:38 +00:00
2012-08-30 15:51:41 +00:00
function lst_default_subdomains (){
global $db , $err ;
2012-08-31 10:05:39 +00:00
$err -> log ( " dom " , " lst_default_subdomains " );
2012-08-30 15:51:41 +00:00
$c = array ();
$db -> query ( " select * from default_subdomains; " );
while ( $db -> next_record ()) {
$c [] = array ( 'id' => $db -> f ( 'id' ),
'sub' => $db -> f ( 'sub' ),
'domain_type' => $db -> f ( 'domain_type' ),
'domain_type_parameter' => $db -> f ( 'domain_type_parameter' ),
'concerned' => $db -> f ( 'concerned' ),
'enabled' => $db -> f ( 'enabled' )
) ;
}
return $c ;
}
function update_default_subdomains ( $arr ) {
2012-08-31 10:05:39 +00:00
global $err ;
$err -> log ( " dom " , " update_default_subdomains " );
2012-08-30 15:51:41 +00:00
$ok = true ;
foreach ( $arr as $a ) {
if ( ! isset ( $a [ 'id' ])) $a [ 'id' ] = null ;
if ( ! empty ( $a [ 'sub' ]) || ! empty ( $a [ 'domain_type_parameter' ])){
if ( ! isset ( $a [ 'enabled' ])) $a [ 'enabled' ] = 0 ;
if ( ! $this -> update_one_default ( $a [ 'domain_type' ], $a [ 'sub' ], $a [ 'domain_type_parameter' ], $a [ 'concerned' ], $a [ 'enabled' ], $a [ 'id' ]) ) {
$ok = false ;
}
}
}
return $ok ;
}
function update_one_default ( $domain_type , $sub , $domain_type_parameter , $concerned , $enabled , $id = null ){
global $db , $err ;
2012-08-31 10:05:39 +00:00
$err -> log ( " dom " , " update_one_default " );
2012-08-30 15:51:41 +00:00
if ( $id == null )
2012-08-31 10:05:39 +00:00
$db -> query ( " INSERT INTO default_subdomains values ('',' " . addslashes ( $sub ) . " ',' " . addslashes ( $domain_type ) . " ',' " . addslashes ( $domain_type_parameter ) . " ',' " . addslashes ( $concerned ) . " ',' " . addslashes ( $enabled ) . " '); " );
2012-08-30 15:51:41 +00:00
else
2012-08-31 10:05:39 +00:00
$db -> query ( " UPDATE default_subdomains set sub=' " . addslashes ( $sub ) . " ', domain_type=' " . addslashes ( $domain_type ) . " ',domain_type_parameter=' " . addslashes ( $domain_type_parameter ) . " ',concerned=' " . addslashes ( $concerned ) . " ',enabled=' " . addslashes ( $enabled ) . " ' where id= " . addslashes ( $id ) . " ; " );
2012-08-30 15:51:41 +00:00
return true ;
//update
2012-08-31 10:05:39 +00:00
}
function del_default_type ( $id ){
global $err , $db ;
$err -> log ( " dom " , " del_default_type " );
if ( ! $db -> query ( " delete from default_subdomains where id= $id ; " )){
$err -> raise ( " dom " , _ ( " Could not delete default type " ));
return false ;
}
return true ;
2012-08-30 15:51:41 +00:00
}
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.
2011-03-06 18:06:27 +00:00
// echo "whois : $domain<br />";
2011-06-17 10:32:21 +00:00
preg_match ( " #.* \ .([^ \ .]*)# " , $domain , $out );
2006-04-26 12:28:53 +00:00
$ext = $out [ 1 ];
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
2011-03-06 18:06:27 +00:00
// echo "ext: $ext<br />";
2010-12-20 21:05:48 +00:00
2012-08-21 07:48:24 +00:00
$serveur = " " ;
2010-12-20 21:05:48 +00:00
if (( $fp =@ fsockopen ( " whois.iana.org " , 43 )) > 0 ) {
fputs ( $fp , " $domain\r\n " );
$found = false ;
$state = 0 ;
while ( ! feof ( $fp )) {
$ligne = fgets ( $fp , 128 );
2011-06-17 10:32:21 +00:00
if ( preg_match ( '#^whois:#' , $ligne )) { $serveur = preg_replace ( '/whois:\ */' , '' , $ligne , 1 ); }
2010-12-20 21:05:48 +00:00
}
}
2012-08-21 07:48:24 +00:00
$serveur = str_replace ( array ( " " , " \n " ), " " , $serveur );
2010-12-20 21:05:48 +00:00
2006-04-26 12:28:53 +00:00
$egal = " " ;
switch ( $ext ) {
case " net " :
$egal = " = " ;
break ;
case " name " :
2007-08-22 22:57:03 +00:00
$egal = " domain = " ;
2006-04-26 12:28:53 +00:00
break ;
}
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
2011-03-06 18:06:27 +00:00
// 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 )) {
2011-03-06 18:06:27 +00:00
$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 " :
case " cc " :
2011-06-17 10:32:21 +00:00
if ( preg_match ( " #Name Server:# " , $ligne )) {
2011-03-06 18:06:27 +00:00
$found = true ;
2011-06-17 10:32:21 +00:00
$tmp = strtolower ( str_replace ( chr ( 10 ), " " , str_replace ( chr ( 13 ), " " , str_replace ( " " , " " , str_replace ( " Name Server: " , " " , $ligne )))));
2011-03-06 18:06:27 +00:00
if ( $tmp )
$server [] = $tmp ;
}
break ;
case " cx " :
2011-06-17 10:32:21 +00:00
$ligne = str_replace ( chr ( 10 ), " " , str_replace ( chr ( 13 ), " " , str_replace ( " " , " " , $ligne )));
2011-03-06 18:06:27 +00:00
if ( $ligne == " " && $state == 1 )
$state = 2 ;
if ( $state == 1 )
$server [] = strtolower ( $ligne );
if ( $ligne == " Nameservers: " && $state == 0 ) {
$state = 1 ;
$found = true ;
}
break ;
2006-04-26 12:28:53 +00:00
case " eu " :
2011-03-06 18:06:27 +00:00
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 " :
2011-06-17 10:32:21 +00:00
if ( preg_match ( " #nserver:# " , $ligne )) {
2006-04-26 12:28:53 +00:00
$found = true ;
$tmp = strtolower ( preg_replace ( " /nserver: \ s*[^ ]* \ s*([^ \ s]*) $ / " , " \\ 1 " , $ligne ));
if ( $tmp )
$server [] = $tmp ;
}
break ;
2011-03-06 18:06:27 +00:00
case " fr " :
case " re " :
2011-06-17 10:32:21 +00:00
if ( preg_match ( " #nserver:# " , $ligne )) {
2006-04-26 12:28:53 +00:00
$found = true ;
2011-06-17 10:32:21 +00:00
$tmp = strtolower ( preg_replace ( " #nserver: \ s*([^ \ s]*) \ s*.* $ # " , " \\ 1 " , $ligne ));
2006-04-26 12:28:53 +00:00
if ( $tmp )
$server [] = $tmp ;
}
break ;
2011-03-06 18:06:27 +00:00
case " ca " :
case " ws " ;
2011-06-17 10:32:21 +00:00
if ( preg_match ( '#Name servers#' , $ligne )) {
2011-03-06 18:06:27 +00:00
// found the server
$state = 1 ;
} elseif ( $state ) {
2011-06-17 10:32:21 +00:00
if ( preg_match ( '#^[^%]#' , $ligne ) && $ligne = preg_replace ( '#[[:space:]]#' , " " , $ligne )) {
2011-03-06 18:06:27 +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 " :
2011-06-17 10:32:21 +00:00
if ( preg_match ( '#Host Name:\s*([^\s]+)#' , $ligne , $matches )) {
2010-08-30 20:16:01 +00:00
$found = true ;
$server [] = $matches [ 1 ];
}
2011-03-06 18:06:27 +00:00
} // switch
2006-04-26 12:28:53 +00:00
} // while
fclose ( $fp );
} else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The Whois database is unavailable, please try again later. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
if ( $found ) {
return $server ;
} else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The domain cannot be found in the whois database. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
} // whois
2012-08-25 14:04:38 +00:00
2006-07-04 09:22:55 +00:00
/* ----------------------------------------------------------------- */
/**
* v<EFBFBD> rifie la presence d ' un champs mx valide sur un serveur DNS
*
2012-08-25 14:04:38 +00:00
*/
2006-07-04 09:22:55 +00:00
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
*
* @ 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 ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " --- Program error --- No lock on the domains! " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$t = checkfqdn ( $dom );
if ( $t ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " The domain name is syntaxically incorrect " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$r [ " name " ] = $dom ;
2012-08-25 21:06:27 +00:00
$db -> query ( " SELECT * FROM domaines WHERE compte=' $cuid ' AND domaine=' $dom ' " );
2006-04-26 12:28:53 +00:00
if ( $db -> num_rows () == 0 ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , 1 , _ ( " Domain '%s' not found. " ), $dom );
2006-04-26 12:28:53 +00:00
return false ;
}
$db -> next_record ();
2012-08-25 14:04:38 +00:00
$r [ " id " ] = $db -> Record [ " id " ];
2006-04-26 12:28:53 +00:00
$r [ " dns " ] = $db -> Record [ " gesdns " ];
2011-01-29 10:35:12 +00:00
$r [ " dns_action " ] = $db -> Record [ " dns_action " ];
$r [ " dns_result " ] = $db -> Record [ " dns_result " ];
2006-04-26 12:28:53 +00:00
$r [ " mail " ] = $db -> Record [ " gesmx " ];
2011-03-06 18:06:27 +00:00
$r [ 'noerase' ] = $db -> Record [ 'noerase' ];
2006-04-26 12:28:53 +00:00
$db -> free ();
2012-08-25 21:06:27 +00:00
$db -> query ( " SELECT COUNT(*) AS cnt FROM sub_domaines WHERE compte=' $cuid ' AND domaine=' $dom ' " );
2006-04-26 12:28:53 +00:00
$db -> next_record ();
$r [ " nsub " ] = $db -> Record [ " cnt " ];
$db -> free ();
2012-08-25 21:06:27 +00:00
$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) ORDER BY sd.sub,sd.type " );
2006-04-26 12:28:53 +00:00
// Pas de webmail, on le cochera si on le trouve.
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 " ];
2011-01-29 17:58:19 +00:00
$r [ " sub " ][ $i ][ " enable " ] = $db -> Record [ " enable " ];
2011-01-28 16:46:32 +00:00
$r [ " sub " ][ $i ][ " type_desc " ] = $db -> Record [ " type_desc " ];
2011-01-29 17:58:19 +00:00
$r [ " sub " ][ $i ][ " only_dns " ] = $db -> Record [ " only_dns " ];
$r [ " sub " ][ $i ][ " web_action " ] = $db -> Record [ " web_action " ];
2006-04-26 12:28:53 +00:00
}
$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 .
*/
2011-01-28 15:55:26 +00:00
function get_sub_domain_all ( $dom , $sub , $type = " " , $value = '' ) {
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 ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " --- Program error --- No lock on the domains! " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$t = checkfqdn ( $dom );
if ( $t ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The domain name is syntaxically incorrect " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2011-01-29 17:58:19 +00:00
$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); " );
2006-04-26 12:28:53 +00:00
if ( $db -> num_rows () == 0 ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The sub-domain does not exist. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db -> next_record ();
$r = array ();
$r [ " name " ] = $db -> Record [ " sub " ];
$r [ " dest " ] = $db -> Record [ " valeur " ];
2011-01-29 17:58:19 +00:00
$r [ " enable " ] = $db -> Record [ " enable " ];
2011-01-28 16:46:32 +00:00
$r [ " type_desc " ] = $db -> Record [ " type_desc " ];
2011-01-29 17:58:19 +00:00
$r [ " only_dns " ] = $db -> Record [ " only_dns " ];
$r [ " web_action " ] = $db -> Record [ " web_action " ];
2006-04-26 12:28:53 +00:00
$db -> free ();
return $r ;
} // get_sub_domain_all
2007-08-27 06:51:09 +00:00
2011-01-28 15:55:26 +00:00
function check_type_value ( $type , $value ) {
2011-03-06 18:06:27 +00:00
global $db , $err , $cuid ;
2011-01-28 15:55:26 +00:00
// 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 )) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The folder you entered is incorrect or does not exist. " ));
2012-08-27 19:23:23 +00:00
return false ;
2011-01-28 15:55:26 +00:00
}
2011-01-29 17:58:19 +00:00
return true ;
2011-01-28 15:55:26 +00:00
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
2011-10-18 19:09:44 +00:00
/* ----------------------------------------------------------------- */
/**
* Check the compatibility of the POSTed parameters with the chosen
* domain type
*
* @ param string $dom FQDN of the domain name
* @ param string $sub SUBdomain
* @ return boolean tell you if the subdomain can be installed there
*/
2011-02-01 14:14:26 +00:00
function can_create_subdomain ( $dom , $sub , $type , $type_old = '' , $value_old = '' ) {
2011-01-28 15:55:26 +00:00
global $db , $err , $cuid ;
$err -> log ( " dom " , " can_create_subdomain " , $dom . " / " . $sub );
2011-10-18 19:09:44 +00:00
// Get the compatibility list for this domain type
2011-01-28 15:55:26 +00:00
$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' ));
2011-10-18 19:09:44 +00:00
// Get the list of type of subdomains already here who have the same name
2011-02-01 14:14:26 +00:00
$db -> query ( " select * from sub_domaines where sub=' $sub ' and domaine=' $dom ' and not (type=' $type_old ' and valeur=' $value_old ') and web_action != 'DELETE' " );
2011-01-29 17:58:19 +00:00
#$db->query("select * from sub_domaines where sub='$sub' and domaine='$dom';");
2011-01-28 15:55:26 +00:00
while ( $db -> next_record ()) {
2011-10-18 19:09:44 +00:00
// And if there is a domain with a incompatible type, return false
2011-01-28 15:55:26 +00:00
if ( ! in_array ( strtoupper ( $db -> f ( 'type' )), $compatibility_lst )) return false ;
}
2011-10-18 19:09:44 +00:00
// All is right, go ! Create ur domain !
2011-01-28 15:55:26 +00:00
return true ;
}
2012-08-25 14:04:38 +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 .
*/
2011-01-28 15:55:26 +00:00
function set_sub_domain ( $dom , $sub , $type , $dest , $type_old = null , $sub_old = null , $value_old = null ) {
2012-08-27 19:23:23 +00:00
global $db , $err , $cuid , $bro ;
2011-06-04 14:28:57 +00:00
$err -> log ( " dom " , " set_sub_domain " , $dom . " / " . $sub . " / " . $type . " / " . $dest );
2006-04-26 12:28:53 +00:00
// Locked ?
if ( ! $this -> islocked ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " --- Program error --- No lock on the domains! " ));
2006-04-26 12:28:53 +00:00
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 )) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " There is some forbidden characters in the sub domain (only A-Z 0-9 and - are allowed). " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2011-01-28 15:55:26 +00:00
if ( ! $this -> check_type_value ( $type , $dest )) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " Invalid domain type selected, please check. " ));
2011-01-28 15:55:26 +00:00
return false ;
2006-04-26 12:28:53 +00:00
}
2011-01-28 15:55:26 +00:00
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.
2011-01-28 15:55:26 +00:00
if ( $t = checkfqdn ( $dom )) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The domain name is syntaxically incorrect " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2010-11-16 17:11:06 +00:00
2012-08-27 08:18:25 +00:00
if ( ! $this -> can_create_subdomain ( $dom , $sub , $type , $type_old , $value_old )) {
$err -> raise ( " dom " , _ ( " The parameters for this subdomain and domain type are invalid. Please check for subdomain entries incompatibility " ));
2011-01-28 15:55:26 +00:00
return false ;
}
2010-11-16 17:11:06 +00:00
2011-01-28 15:55:26 +00:00
if ( ! is_null ( $type_old )) { // It's not a creation, it's an edit. Delete the old one
2011-07-29 19:04:47 +00:00
$db -> query ( " update sub_domaines set web_action='DELETE' where domaine=' $dom ' and sub=' $sub_old ' and upper(type)=upper(' $type_old ') and valeur=' $value_old '; " );
2006-04-26 12:28:53 +00:00
}
2011-01-28 15:55:26 +00:00
// Re-create the one we want
2011-02-01 18:03:29 +00:00
if ( ! $db -> query ( " insert into sub_domaines (compte,domaine,sub,valeur,type,web_action) values (' $cuid ',' $dom ',' $sub ',' $dest ',' $type ','UPDATE'); " ) ) {
echo " query failed: " . $db -> Error ;
return false ;
}
2012-08-27 19:23:23 +00:00
// Create TMP dir and TARGET dir if needed by the domains_type
$dest_root = $bro -> get_userid_root ( $cuid );
$domshort = $this -> domshort ( $dom , $sub );
$db -> query ( " select create_tmpdir, create_targetdir from domaines_type where name = ' $type '; " );
$db -> next_record ();
if ( $db -> f ( 'create_tmpdir' )) {
if ( ! is_dir ( $dest_root . " /tmp " )) {
if ( ! mkdir ( $dest_root . " /tmp " )){
printvar ( " je viens de tenter de mkdir ++ $dest_root /tmp++ " ); // FIXME Bullshit. Safemode <20> la con ?
$err -> raise ( " dom " , _ ( " I can't write to the destination folder " ));
}
}
}
if ( $db -> f ( 'create_targetdir' )) {
$dirr = $dest_root . $dest ;
if ( ! is_dir ( $dirr )) {
if ( ! mkdir ( $dirr , null , 1 )){
printvar ( " je viens de tenter de mkdir ++ $dirr ++ " ); // FIXME Bullshit. Safemode <20> la con ?
$err -> raise ( " dom " , _ ( " I can't write to the destination folder " ));
}
}
}
2011-01-28 15:55:26 +00:00
// Tell to update the DNS file
$db -> query ( " update domaines set dns_action='UPDATE' where domaine=' $dom '; " );
2006-04-26 12:28:53 +00:00
return true ;
} // set_sub_domain
2011-01-28 15:55:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* 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 .
*
*/
2011-01-28 15:55:26 +00:00
function del_sub_domain ( $dom , $sub , $type , $value = '' ) {
2006-04-26 12:28:53 +00:00
global $db , $err , $cuid ;
$err -> log ( " dom " , " del_sub_domain " , $dom . " / " . $sub );
// Locked ?
if ( ! $this -> islocked ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " --- Program error --- No lock on the domains! " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$t = checkfqdn ( $dom );
if ( $t ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " ,( " The domain name is syntaxically incorrect " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2010-11-16 17:11:06 +00:00
if ( ! $r = $this -> get_sub_domain_all ( $dom , $sub , $type )) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The sub-domain does not exist. " ));
2006-04-26 12:28:53 +00:00
return false ;
} else {
2011-02-01 17:17:58 +00:00
$db -> query ( " update sub_domaines set web_action='DELETE' where domaine=' $dom ' and sub=' $sub ' and type=' $type ' and ( length(' $value ')=0 or valeur=' $value ') " );
2011-01-28 15:55:26 +00:00
$db -> query ( " update domaines set dns_action='UPDATE' where domaine=' $dom '; " );
2006-04-26 12:28:53 +00:00
}
return true ;
} // del_sub_domain
2012-08-25 14:04:38 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
* 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
2011-06-04 14:28:57 +00:00
* @ param integer $gesmx H<EFBFBD> berge - t - on le emails du domaines sur ce serveur ?
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 .
*
*/
2011-06-04 14:28:57 +00:00
function edit_domain ( $dom , $dns , $gesmx , $force = 0 ) {
2012-08-25 14:04:38 +00:00
global $db , $err , $L_MX , $classes , $cuid , $hooks ;
2011-06-17 10:32:21 +00:00
$err -> log ( " dom " , " edit_domain " , $dom . " / " . $dns . " / " . $gesmx );
2006-04-26 12:28:53 +00:00
// Locked ?
2007-09-09 20:33:30 +00:00
if ( ! $this -> islocked && ! $force ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " --- Program error --- No lock on the domains! " ));
2006-04-26 12:28:53 +00:00
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 ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The last member of the domain name is incorrect or cannot be hosted in that server. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
if ( $dns && $v ==- 2 ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The domain cannot be found in the whois database. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
if ( $dns && $v ==- 3 ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The DNS of this domain do not match the server's DNS. Please change your domain's DNS (you may need to wait 1 day) before you install it again. " ));
2006-04-26 12:28:53 +00:00
return false ;
}
}
$t = checkfqdn ( $dom );
if ( $t ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The domain name is syntaxically incorrect " ));
2006-04-26 12:28:53 +00:00
return false ;
}
if ( ! $r = $this -> get_domain_all ( $dom )) {
// Le domaine n'existe pas, Failure
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The domain name %s does not exist " ), $dom );
2006-04-26 12:28:53 +00:00
return false ;
}
if ( $dns != " 1 " ) $dns = " 0 " ;
// On v<> rifie que des modifications ont bien eu lieu :)
2011-06-04 14:28:57 +00:00
if ( $r [ " dns " ] == $dns && $r [ " mail " ] == $gesmx ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " No change has been requested... " ));
2006-04-26 12:28:53 +00:00
return false ;
}
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 ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " There is no MX record pointing to this server, and you are asking us to host the mail here. Please fix your MX DNS pointer. " ));
2011-06-04 14:28:57 +00:00
return false ;
2006-07-04 09:22:55 +00:00
}
2011-06-04 14:28:57 +00:00
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
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " There is no MX record pointing to this server, and you are asking us to host the mail here. Please fix your MX DNS pointer. " ));
2011-06-04 14:28:57 +00:00
return false ;
2006-07-04 09:22:55 +00:00
}
}
2012-08-25 14:04:38 +00:00
if ( $gesmx && ! $r [ " mail " ]) {
// TODO: old hooks, FIXME: remove when unused
$hooks -> invoke ( " alternc_add_mx_domain " , array ( $domain ));
// New Hooks:
$hooks -> invoke ( " hook_dom_add_mx_domain " , array ( $r [ " id " ]));
2006-04-26 12:28:53 +00:00
}
if ( ! $gesmx && $r [ " mail " ]) { // on a dissoci<63> le MX : on d<> truit donc l'entree dans LDAP
2012-08-25 14:04:38 +00:00
// TODO: old hooks, FIXME: remove when unused
$hooks -> invoke ( " alternc_del_mx_domain " , array ( $domain ));
// New Hooks:
$hooks -> invoke ( " hook_dom_del_mx_domain " , array ( $r [ " id " ]));
2006-04-26 12:28:53 +00:00
}
2011-06-17 10:32:21 +00:00
$db -> query ( " UPDATE domaines SET gesdns=' $dns ', gesmx=' $gesmx ' WHERE domaine=' $dom ' " );
2011-01-28 15:55:26 +00:00
$db -> query ( " UPDATE domaines set dns_action='UPDATE' where domaine=' $dom '; " );
2011-06-04 14:28:57 +00:00
2006-04-26 12:28:53 +00:00
return true ;
} // edit_domain
/****************************/
/* Slave dns ip managment */
/****************************/
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Return the list of ip addresses and classes that are allowed access to domain list
2006-04-26 12:28:53 +00:00
* through AXFR Transfers from the bind server .
*/
function enum_slave_ip () {
2011-03-06 18:06:27 +00:00
global $db , $err ;
$db -> query ( " SELECT * FROM slaveip; " );
if ( ! $db -> next_record ()) {
return false ;
}
do {
$res [] = $db -> Record ;
} while ( $db -> next_record ());
return $res ;
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Add an ip address ( or a ip class ) to the list of allowed slave ip access list .
2006-04-26 12:28:53 +00:00
*/
function add_slave_ip ( $ip , $class = " 32 " ) {
2011-03-06 18:06:27 +00:00
global $db , $err ;
2012-08-27 08:18:25 +00:00
if ( ! checkip ( $ip )) { // FIXME: replace by filter_var (same for checkfqdn ?
$err -> raise ( " dom " , _ ( " The IP address you entered is incorrect. " ));
2011-03-06 18:06:27 +00:00
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 ()) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " err " , _ ( " The requested domain is forbidden in this server, please contact the administrator " ));
2011-03-06 18:06:27 +00:00
return false ;
}
$db -> query ( " INSERT INTO slaveip (ip,class) VALUES (' $ip ',' $class '); " );
$f = fopen ( SLAVE_FLAG , " w " );
fputs ( $f , " yopla " );
fclose ( $f );
return true ;
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Remove an ip address ( or a ip class ) from the list of allowed slave ip access list .
2006-04-26 12:28:53 +00:00
*/
function del_slave_ip ( $ip ) {
2011-03-06 18:06:27 +00:00
global $db , $err ;
if ( ! checkip ( $ip )) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The IP address you entered is incorrect. " ));
2011-03-06 18:06:27 +00:00
return false ;
}
$db -> query ( " DELETE FROM slaveip WHERE ip=' $ip ' " );
$f = fopen ( SLAVE_FLAG , " w " );
fputs ( $f , " yopla " );
fclose ( $f );
return true ;
2006-04-26 12:28:53 +00:00
}
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Check for a slave account
2006-04-26 12:28:53 +00:00
*/
function check_slave_account ( $login , $pass ) {
2011-03-06 18:06:27 +00:00
global $db , $err ;
$db -> query ( " SELECT * FROM slaveaccount WHERE login=' $login ' AND pass=' $pass '; " );
if ( $db -> next_record ()) {
return true ;
}
return false ;
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Out ( echo ) the complete hosted domain list :
2006-04-26 12:28:53 +00:00
*/
function echo_domain_list () {
2011-03-06 18:06:27 +00:00
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 ;
2006-04-26 12:28:53 +00:00
}
2010-03-04 16:16:13 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Returns the complete hosted domain list :
2010-03-04 16:16:13 +00:00
*/
2010-05-24 11:40:39 +00:00
function get_domain_list ( $uid =- 1 ) {
2011-03-06 18:06:27 +00:00
global $db , $err ;
$uid = intval ( $uid );
$res = array ();
if ( $uid !=- 1 ) {
$sql = " AND compte=' $uid ' " ;
}
$db -> query ( " SELECT domaine FROM domaines WHERE gesdns=1 $sql ORDER BY domaine " );
while ( $db -> next_record ()) {
$res [] = $db -> f ( " domaine " );
}
return $res ;
2010-03-04 16:16:13 +00:00
}
2012-08-23 18:46:47 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Returns the name of a domain for the current user , from it ' s domain_id
2012-08-23 18:46:47 +00:00
* @ param $dom_id integer the domain_id to search for
* @ return string the domain name , or false with an error raised .
*/
function get_domain_byid ( $dom_id ) {
global $db , $err , $cuid ;
$dom_id = intval ( $dom_id );
$db -> query ( " SELECT domaine FROM domaines WHERE id= $dom_id AND compte= $cuid ; " );
if ( $db -> next_record ()) {
$domain = $db -> f ( " domaine " );
if ( ! $domain ) {
$err -> raise ( " dom " , _ ( " This domain is not installed in your account " ));
return false ;
} else {
return $domain ;
}
} else {
$err -> raise ( " dom " , _ ( " This domain is not installed in your account " ));
return false ;
}
}
2012-08-24 13:37:56 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Returns the id of a domain for the current user , from it ' s domain name
2012-08-24 13:37:56 +00:00
* @ param $domain string the domain name to search for
* @ return integer the domain id , or false with an error raised .
*/
function get_domain_byname ( $domain ) {
global $db , $err , $cuid ;
$domain = trim ( $domain );
$db -> query ( " SELECT id FROM domaines WHERE domaine=' " . addslashes ( $domain ) . " ' AND compte= $cuid ; " );
if ( $db -> next_record ()) {
$id = $db -> f ( " id " );
if ( ! $id ) {
$err -> raise ( " dom " , _ ( " This domain is not installed in your account " ));
return false ;
} else {
return $id ;
}
} else {
$err -> raise ( " dom " , _ ( " This domain is not installed in your account " ));
return false ;
}
}
2012-08-25 15:38:26 +00:00
2012-08-23 18:46:47 +00:00
2012-08-25 10:49:55 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Count all domains , for all users
2012-08-25 10:49:55 +00:00
*/
function count_domains_all () {
global $db , $err , $cuid ;
$db -> query ( " SELECT COUNT(*) AS count FROM domaines; " );
if ( $db -> next_record ()) {
return $db -> f ( 'count' );
} else {
return 0 ;
}
}
2012-08-23 18:46:47 +00:00
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Return the list of allowed slave accounts
2006-04-26 12:28:53 +00:00
*/
function enum_slave_account () {
2011-03-06 18:06:27 +00:00
global $db , $err ;
$db -> query ( " SELECT * FROM slaveaccount; " );
$res = array ();
while ( $db -> next_record ()) {
$res [] = $db -> Record ;
}
if ( ! count ( $res )) return false ;
return $res ;
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Add a slave account that will be allowed to access the domain list
2006-04-26 12:28:53 +00:00
*/
function add_slave_account ( $login , $pass ) {
2011-03-06 18:06:27 +00:00
global $db , $err ;
$db -> query ( " SELECT * FROM slaveaccount WHERE login=' $login ' " );
if ( $db -> next_record ()) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " The specified slave account already exists " ));
2011-03-06 18:06:27 +00:00
return false ;
}
$db -> query ( " INSERT INTO slaveaccount (login,pass) VALUES (' $login ',' $pass ') " );
return true ;
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Remove a slave account
2006-04-26 12:28:53 +00:00
*/
function del_slave_account ( $login ) {
2011-03-06 18:06:27 +00:00
global $db , $err ;
$db -> query ( " DELETE FROM slaveaccount WHERE login=' $login ' " );
return true ;
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/*************/
/* Private */
/*************/
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Try to lock a domain
2006-04-26 12:28:53 +00:00
* @ access private
*/
function lock () {
global $db , $err ;
$err -> log ( " dom " , " lock " );
if ( $this -> islocked ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " --- Program error --- Lock already obtained! " ));
2006-04-26 12:28:53 +00:00
}
while ( file_exists ( $this -> fic_lock_cron )) {
sleep ( 2 );
}
$this -> islocked = true ;
return true ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Unlock the cron for domain management
* return true
2006-04-26 12:28:53 +00:00
* @ access private
*/
function unlock () {
global $db , $err ;
$err -> log ( " dom " , " unlock " );
if ( ! $this -> islocked ) {
2012-08-27 08:18:25 +00:00
$err -> raise ( " dom " , _ ( " --- Program error --- No lock on the domains! " ));
2006-04-26 12:28:53 +00:00
}
$this -> islocked = false ;
return true ;
}
2011-06-04 14:28:57 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Declare that a domain ' s emails are hosted in this server :
2011-06-04 14:28:57 +00:00
* This adds 2 MX entries in this domain ( if required )
*/
function alternc_add_mx_domain ( $domain ) {
global $err ;
$err -> log ( " dom " , " alternc_add_mx_domain " );
$this -> set_sub_domain ( $domain , '' , $this -> type_defmx , '' );
if ( ! empty ( $GLOBALS [ 'L_DEFAULT_SECONDARY_MX' ])) {
$this -> set_sub_domain ( $domain , '' , $this -> type_defmx2 , '' );
}
return true ;
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
/**
2012-08-25 15:38:26 +00:00
* Delete an account ( all his domains )
2006-04-26 12:28:53 +00:00
*/
2012-08-25 15:38:26 +00:00
function hook_admin_del_member () {
2006-04-26 12:28:53 +00:00
global $err ;
$err -> log ( " dom " , " alternc_del_member " );
$li = $this -> enum_domains ();
foreach ( $li as $dom ) {
$this -> del_domain ( $dom );
}
return true ;
}
2011-06-04 14:28:57 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Returns the used quota for the $name service for the current user .
2006-04-26 12:28:53 +00:00
* @ param $name string name of the quota
* @ return integer the number of service used or false if an error occured
* @ access private
*/
2012-08-26 16:11:53 +00:00
function hook_quota_get () {
2006-04-26 12:28:53 +00:00
global $db , $err , $cuid ;
2012-08-26 16:11:53 +00:00
$err -> log ( " dom " , " get_quota " );
$q = Array ( " name " => " dom " , " description " => _ ( " Domain name " ), " used " => 0 );
$db -> query ( " SELECT COUNT(*) AS cnt FROM domaines WHERE compte=' $cuid ' " );
if ( $db -> next_record () ) {
$q [ 'used' ] = $db -> f ( " cnt " );
}
return $q ;
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
2012-02-28 14:48:45 +00:00
/*---------------------------------------------------------------------*/
2012-08-25 15:38:26 +00:00
/** Returns the global domain ( s ) configuration ( s ) of a particular user
* No parameters needed
**/
2012-02-28 14:48:45 +00:00
function alternc_export_conf () {
2006-04-26 12:28:53 +00:00
global $db , $err ;
$err -> log ( " dom " , " export " );
$this -> enum_domains ();
foreach ( $this -> domains as $d ) {
2012-08-25 15:38:26 +00:00
$str = " <domaines> \n " ;
$str .= " <nom> " . $d . " </nom> \n " ;
$this -> lock ();
$s = $this -> get_domain_all ( $d );
$this -> unlock ();
if ( empty ( $s [ " dns " ])){
$s [ dns ] = " non " ;
} else {
$s [ dns ] = " oui " ;
}
$str .= " <dns> " . $s [ dns ] . " </dns> \n " ;
if ( empty ( $s [ mx ])){
$s [ mx ] = " non " ;
} else {
$s [ mx ] = " oui " ;
}
$str .= " <mx> " . $s [ mx ] . " </mx> \n " ;
if ( empty ( $s [ mail ])){
$s [ mail ] = " non " ;
}
$str .= " <mail> " . $s [ mail ] . " </mail> \n " ;
if ( is_array ( $s [ sub ])) {
foreach ( $s [ sub ] as $sub ) {
$str .= " <subdomain> \n " ;
$str .= " <enabled> " . $sub [ " enable " ] . " </enabled> \n " ;
$str .= " <destination> " . $sub [ " dest " ] . " </destination> \n " ;
$str .= " <type> " . $sub [ " type " ] . " </type> \n " ;
$str .= " </subdomain> \n " ;
}
}
$str .= " </domaines> \n " ;
2006-04-26 12:28:53 +00:00
}
return $str ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
} /* Class m_domains */