26 define(
'SLAVE_FLAG',
"/var/run/alternc/refresh_slave");
87 $this->tld_no_check_at_all =
variable_get(
'tld_no_check_at_all', 0,
'Disable ALL check on the TLD (users will be able to add any domain)', array(array(
'desc'=>
'Disabled',
'type'=>
'boolean')));
88 variable_get(
'mailname_bounce',
'%%FQDN%%',
'FQDN of the mail server, used to create vhost virtual mail_adress.', array(array(
'desc'=>
'FQDN',
'type'=>
'string')));
93 $err->log(
"dom",
"get_panel_url_list");
94 $db->query(
"SELECT sd.id as sub_id, if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) as fqdn from sub_domaines sd where type = 'PANEL';");
96 while ($db->next_record()) {
97 $t[intval($db->f(
'sub_id'))] = $db->f(
'fqdn');
104 $err->log(
"dom",
"get_sub_domain_by_name");
105 $fqdn=mysql_real_escape_string($fqdn);
106 $db->query(
"select sd.* from sub_domaines sd where if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) = '$fqdn';");
107 if (! $db->next_record())
return false;
108 return array(
'sub_id'=>intval($db->f(
'id')),
'member_id'=> intval($db->f(
'compte') ));
114 'title' => _(
"Domains"),
115 'ico' =>
'images/dom.png',
121 if ( $quota->cancreate(
"dom") ) {
124 'ico' =>
'images/new.png',
125 'txt' => _(
"Add a domain"),
126 'url' =>
"dom_add.php",
133 'txt' => htmlentities($d),
134 'url' =>
"dom_edit.php?domain=".urlencode($d),
152 $err->log(
"dom",
"domains_type_lst");
153 $db->query(
"select * from domaines_type order by advanced;");
155 while ($db->next_record()) {
158 return $this->domains_type_lst;
163 $err->log(
"dom",
"domains_type_target_values");
164 $db->query(
"desc domaines_type;");
166 while ($db->next_record()) {
167 if ($db->f(
'Field') ==
'enable') {
168 $tab = explode(
",", substr($db->f(
'Type'), 5, -1));
169 foreach(
$tab as
$t) {
$r[]=substr($t,1,-1); }
177 $err->log(
"dom",
"domains_type_target_values");
178 if (is_null($type)) {
179 $db->query(
"desc domaines_type;");
181 while ($db->next_record()) {
182 if ($db->f(
'Field') ==
'target') {
183 $tab = explode(
",", substr($db->f(
'Type'), 5, -1));
184 foreach(
$tab as
$t) {
$r[]=substr($t,1,-1); }
189 $db->query(
"select target from domaines_type where name='$type';");
190 if (! $db->next_record())
return false;
191 return $db->f(
'target');
199 $err->raise(
'dom', _(
"Err: failed to prepare the zone"));
205 foreach (explode(
"\n", $zone) as $z) {
207 if (empty($z))
continue;
215 $err->log(
"dom",
"import_manual_dns_entry");
217 if (empty($zone))
return false;
221 $err->raise(
"dom", _(
"Missing domain name"));
227 'comment' =>
'no val',
228 'entry_old' => $zone,
229 'entry_new' => array(
'domain'=>
$domain),
234 if ( preg_match(
'/^;/', $zone, $ret) ) {
235 $val[
'status'] =
'ok';
236 $val[
'comment'] =
'Just a comment, do not import';
240 if ( preg_match(
'/^\$TTL\h+(?P<ttl>[\dMHDmhd]+)/', $zone, $ret) ) {
241 $val[
'status'] =
'ok';
242 $val[
'comment'] =
'Set TTL to '.$ret[
'ttl'];
243 $val[
'entry_new'][
'type'] =
'set_ttl';
244 $val[
'entry_new'][
'value'] = $ret[
'ttl'];
250 if ( preg_match(
'/^(?P<sub>[\w\.@\-]*)\h*(?P<ttl>\d*)\h*IN\h+AAAA\h+(?P<target>[0-9A-F:]{2,40})/i', $zone, $ret) ) {
253 if ( substr($ret[
'sub'], -1) ==
'.' ) {
254 $url=
"http://".$ret[
'sub'];
256 if ( $ret[
'sub'] ==
'@' || empty($ret[
'sub']) ) {
257 $url=
"http://".$domain;
259 $url=
"http://".$ret[
'sub'].
".".
$domain;
263 $val[
'status'] =
'warn';
264 $val[
'comment'] =
"Became a redirect to $dst_url";
265 $val[
'entry_new'][
'type'] =
'URL';
266 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
267 $val[
'entry_new'][
'value'] = $dst_url;
269 $val[
'status'] =
'ok';
270 $val[
'comment'] =
"Create entry AAAA with ".$ret[
'sub'].
" go to ".$ret[
'target'].
" with ttl ".$ret[
'ttl'];
271 $val[
'entry_new'][
'type'] =
'IPV6';
272 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
273 $val[
'entry_new'][
'value'] = $ret[
'target'];
281 if ( preg_match(
'/^(?P<sub>[\w\.@\-]*)\h*(?P<ttl>\d*)\h*IN\h+A\h+(?P<target>\d+\.\d+\.\d+\.\d+)/i', $zone, $ret) ) {
283 if ( substr($ret[
'sub'], -1) ==
'.' ) {
284 $url=
"http://".$ret[
'sub'];
286 if ( $ret[
'sub'] ==
'@' || empty($ret[
'sub']) ) {
287 $url=
"http://".$domain;
289 $url=
"http://".$ret[
'sub'].
".".
$domain;
293 $val[
'status'] =
'warn';
294 $val[
'comment'] =
"Became a redirect to $dst_url";
295 $val[
'entry_new'][
'type'] =
'URL';
296 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
297 $val[
'entry_new'][
'value'] = $dst_url;
299 $val[
'status'] =
'ok';
300 $val[
'comment'] =
"Create entry A with ".$ret[
'sub'].
" go to ".$ret[
'target'].
" with ttl ".$ret[
'ttl'];
301 $val[
'entry_new'][
'type'] =
'IP';
302 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
303 $val[
'entry_new'][
'value'] = $ret[
'target'];
310 if ( preg_match(
'/^(?P<sub>[\-\w\.@]*)\h*(?P<ttl>\d*)\h*IN\h+NS\h+(?P<target>[\w\.\-]+)/i', $zone, $ret) ) {
311 if ( empty($ret[
'sub']) || $ret[
'sub'] ==
'@' ) {
312 $val[
'status'] =
'warn';
313 $val[
'comment'] =
"Won't migrate it, there will get a new value";
315 $val[
'status'] =
'ok';
316 $val[
'comment'] =
"Create entry NS with ".$ret[
'sub'].
" go to ".$ret[
'target'].
" with ttl ".$ret[
'ttl'];
317 $val[
'entry_new'][
'type'] =
'FIXME-NS';
318 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
319 $val[
'entry_new'][
'value'] = $ret[
'target'];
326 if ( preg_match(
'/^(?P<sub>[\-\w\.@]*)\h*(?P<ttl>\d*)\h*IN\h+CNAME\h+(?P<target>[@\w+\.\-]+)/i', $zone, $ret) ) {
327 if ( substr($ret[
'sub'], -1) ==
'.' ) {
328 $url=
"http://".$ret[
'sub'];
330 if ( $ret[
'sub'] ==
'@' || empty($ret[
'sub']) ) {
331 $url=
"http://".$domain;
333 $url=
"http://".$ret[
'sub'].
".".
$domain;
337 $val[
'status'] =
'warn';
338 $val[
'comment'] =
"Became a redirect to $dst_url";
339 $val[
'entry_new'][
'type'] =
'URL';
340 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
341 $val[
'entry_new'][
'value'] = $dst_url;
343 $val[
'status'] =
'ok';
344 $val[
'comment'] =
"Create entry CNAME with ".$ret[
'sub'].
" go to ".$ret[
'target'].
" with ttl ".$ret[
'ttl'];
345 $val[
'entry_new'][
'type'] =
'CNAME';
346 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
347 $val[
'entry_new'][
'value'] = $ret[
'target'];
354 if ( preg_match(
'/^(?P<sub>[\-\w\.@]*)\h*(?P<ttl>\d*)\h*IN\h+MX\h+(?P<weight>\d+)\h+(?P<target>[@\w+\.\-]+)/i', $zone, $ret) ) {
355 $val[
'status'] =
'warn';
356 $val[
'comment'] =
"Create entry MX with ".$ret[
'sub'].
" go to ".$ret[
'target'].
" with ttl ".$ret[
'ttl'].
" and weight 5 (initial weight was ".$ret[
'weight'].
")";
357 $val[
'entry_new'][
'type'] =
'MX';
358 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
359 $val[
'entry_new'][
'value'] = $ret[
'target'];
364 if ( preg_match(
'/^(?P<sub>[\_\w\.@\-]+)\h+(?P<ttl>\d*)\h*IN\h+SRV\h+/i', $zone, $ret) ) {
365 $val[
'status']=
'err';
366 $val[
'comment'] =
"Please add yourself the entry $zone";
371 if ( preg_match(
'/^(?P<sub>[\_\w\.@\-]*)\h*(?P<ttl>\d*)\h*IN\h+TXT\h+\"(?P<target>.+)\"/i', $zone, $ret) ) {
373 $val[
'comment'] =
"Create TXT entry with ".$ret[
'sub'].
" go to ".$ret[
'target'];
374 $val[
'entry_new'][
'type'] =
'TXT';
375 $val[
'entry_new'][
'sub'] = $ret[
'sub'];
376 $val[
'entry_new'][
'value'] = $ret[
'target'];
380 $val[
'comment'] =
"Unknow: $zone";
392 $entry[
'did_it'] = 0;
393 if ( $entry[
'status'] ==
'err' ) {
397 $val=$entry[
'entry_new'];
399 if (empty(
$val[
'type']))
return false;
401 switch(
$val[
'type']) {
410 echo
"what is this shit ?\n";
416 if (
$val[
'sub'] ==
'@')
$val[
'sub'] =
'';
435 $err->raise(
'dom',
"Error adding domain");
443 foreach(
$d[
'sub'] as $sd) {
457 $params = array(
'http' => array(
459 'ignore_errors' =>
true
462 $context = stream_context_create($params);
463 $fp = @fopen($url,
'rb',
false, $context);
464 $result = @stream_get_contents($fp);
466 if ($result ===
false) {
467 throw new Exception(
"Could not read data from {$url}");
470 if ( strstr($http_response_header[0],
'301') || strstr($http_response_header[0],
'302')) {
472 if ( preg_match(
'/Location:\h+(?P<target>[\-\w:\/.\?\=.]+)/', implode(
"\n",$http_response_header), $ret ) ) {
474 preg_match(
'/\/\/(?P<host>[\w\.\-]+)\//', ( substr($url,-1)==
'/'?$url:$url.
'/') , $original_cname);
475 preg_match(
'/\/\/(?P<host>[\w\.\-]+)\//', $ret[
'target'], $target_url);
476 if (
isset($target_url[
'host']) && ( $target_url[
'host'] == $original_cname[
'host'] ) ) {
482 if ( substr($ret[
'target'],0,4) !=
'http' ) {
483 return 'http://'.$original_cname[
'host'].
'/'.$ret[
'target'];
485 return $ret[
'target'];
490 }
catch (Exception $e) {
497 $name=mysql_real_escape_string($name);
498 $db->query(
"update sub_domaines set web_action='UPDATE' where lower(type) = lower('$name') ;");
499 $db->query(
"update domaines d, sub_domaines sd set d.dns_action = 'UPDATE' where lower(sd.type)=lower('$name');");
505 $name=mysql_real_escape_string($name);
506 $db->query(
"select * from domaines_type where name='$name' ;");
513 $name=mysql_real_escape_string($name);
514 $db->query(
"delete domaines_type where name='$name';");
518 function domains_type_update($name, $description, $target, $entry, $compatibility, $enable, $only_dns, $need_dns,$advanced,$create_tmpdir,$create_targetdir) {
521 if (!preg_match(
"#^[a-z0-9]+$#",$name)) {
522 $err->raise(
"dom", _(
"The name MUST contain only letter and digits"));
525 $name=mysql_real_escape_string($name); $description=mysql_real_escape_string($description); $target=mysql_real_escape_string($target);
526 $entry=mysql_real_escape_string($entry); $compatibility=mysql_real_escape_string($compatibility); $enable=mysql_real_escape_string($enable);
527 $only_dns=intval($only_dns); $need_dns=intval($need_dns); $advanced=intval($advanced); $create_tmpdir=intval($create_tmpdir); $create_targetdir=intval($create_targetdir);
528 $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',create_tmpdir=$create_tmpdir,create_targetdir=$create_targetdir where name='$name';");
534 $err->log(
"dom",
"sub_domain_change_status");
535 $sub_id=intval($sub_id);
536 $status=strtoupper($status);
537 if (! in_array($status,array(
'ENABLE',
'DISABLE')))
return false;
540 if ($status ==
'ENABLE') {
542 $err->raise(
"dom", _(
"The parameters for this subdomain and domain type are invalid. Please check for subdomain entries incompatibility"));
547 $db->query(
"update sub_domaines set enable='$status' where id = '".intval($sub_id).
"';");
564 $err->log(
"dom",
"enum_domains");
566 $db->query(
"SELECT * FROM domaines WHERE compte='{$uid}' ORDER BY domaine ASC;");
567 $this->domains=array();
568 if ($db->num_rows()>0) {
569 while ($db->next_record()) {
570 $this->domains[]=$db->f(
"domaine");
578 $err->log(
"dom",
"del_domaini_canl",
$dom);
580 $db->query(
"UPDATE sub_domaines SET web_action='UPDATE' WHERE domaine='$dom';");
583 # TODO : some work with domain sensitive classes
602 $err->log(
"dom",
"del_domain",
$dom);
613 $hooks->invoke(
"alternc_del_domain",array(
$dom));
614 $hooks->invoke(
"alternc_del_mx_domain",array(
$dom));
616 $hooks->invoke(
"hook_dom_del_domain",array(
$r[
"id"]));
617 $hooks->invoke(
"hook_dom_del_mx_domain",array(
$r[
"id"]));
620 $db->query(
"UPDATE sub_domaines SET web_action='DELETE' WHERE domaine='$dom';");
627 return str_replace(
"-",
"",str_replace(
".",
"",empty(
$sub)?
"":
"$sub.").
$dom );
653 $err->log(
"dom",
"add_domain",
$domain);
656 if (!$this->islocked) {
657 $err->raise(
"dom",_(
"--- Program error --- No lock on the domains!"));
664 $err->raise(
"dom",_(
"The domain name is syntaxically incorrect"));
668 $db->query(
"SELECT domain FROM forbidden_domains WHERE domain='$domain'");
669 if ($db->num_rows() && !
$force) {
670 $err->raise(
"dom",_(
"The requested domain is forbidden in this server, please contact the administrator"));
674 $err->raise(
"dom",_(
"This domain is the server's domain! You cannot host it on your account!"));
677 $db->query(
"SELECT compte FROM domaines WHERE domaine='$domain';");
678 if ($db->num_rows()) {
679 $err->raise(
"dom",_(
"The domain already exist"));
682 $db->query(
"SELECT compte FROM `sub_domaines` WHERE sub != \"\" AND concat( sub, \".\", domaine )='$domain' OR domaine='$domain';");
683 if ($db->num_rows()) {
684 $err->raise(
"dom",_(
"The domain already exist"));
691 $err->raise(
"dom",_(
"The last member of the domain name is incorrect or cannot be hosted in that server"));
694 if (
$dns && $v==-2) {
695 $err->raise(
"dom",_(
"The domain cannot be found in the whois database"));
698 if (
$dns && $v==-3) {
699 $err->raise(
"dom",_(
"The domain cannot be found in the whois database"));
706 if ($tld[$v]==5)
$dns=0;
711 $err->raise(
"dom",_(
"The requested domain is forbidden in this server, please contact the administrator"));
717 if (!$quota->cancreate(
"dom")) {
718 $err->raise(
"dom",_(
"Your domain quota is over, you cannot create more domain names"));
721 if ($noerase) $noerase=
"1";
else $noerase=
"0";
722 if (
$dns) $gesmx=
"1";
else $gesmx=
"0";
723 $db->query(
"INSERT INTO domaines (compte,domaine,gesdns,gesmx,noerase,dns_action) VALUES ('$cuid','$domain','$dns','$gesmx','$noerase','UPDATE');");
724 if (!($id=$db->lastid())) {
725 $err->raise(
"dom",_(
"An unexpected error occured when creating the domain"));
731 $db->query(
"SELECT domaine FROM domaines WHERE compte='$cuid' AND domaine='$slavedom';");
733 if (!$db->Record[
"domaine"]) {
734 $err->raise(
"dom",_(
"Domain '%s' not found"),$slavedom);
745 $hooks->invoke(
"alternc_add_domain",array(
$domain));
747 $hooks->invoke(
"alternc_add_slave_domain",array(
$domain));
750 $hooks->invoke(
"hook_dom_add_domain",array($id));
751 if ($gesmx) $hooks->invoke(
"hook_dom_add_mx_domain",array($id));
753 $hooks->invoke(
"hook_dom_add_slave_domain",array($id, $slavedom));
760 $err->log(
"dom",
"create_default_subdomains",
$domain);
761 $query=
"SELECT sub, domain_type, domain_type_parameter FROM default_subdomains WHERE (concerned = 'SLAVE' or concerned = 'BOTH') and enabled=1;";
762 if(empty($target_domain)) {
763 $query=
"SELECT sub, domain_type, domain_type_parameter FROM default_subdomains WHERE (concerned = 'MAIN' or concerned = 'BOTH') and enabled=1;";
768 while ($db->next_record()) {
769 $jj[]=Array(
"domain_type_parameter"=>$db->f(
'domain_type_parameter'),
"sub"=>$db->f(
'sub'),
"domain_type"=>$db->f(
'domain_type'));
771 $src_var=array(
"%%SUB%%",
"%%DOMAIN%%",
"%%DOMAINDIR%%",
"%%TARGETDOM%%");
773 $trg_var=array($j[
'sub'],
$domain,$domaindir,$target_domain);
774 $domain_type_parameter=str_ireplace($src_var,$trg_var,$j[
'domain_type_parameter']);
781 $dest_root = $bro->get_userid_root($cuid);
782 # return $dest_root."/www/".$this->domshort($domain);
783 return "/www/".$this->domshort(
$domain);
787 exec(
'/usr/bin/dig AXFR "'.escapeshellcmd(
$domain).
'" @"'.escapeshellcmd($ns).
'"', $axfr);
794 $err->log(
"dom",
"lst_default_subdomains");
796 $db->query(
"select * from default_subdomains;");
798 while($db->next_record()) {
799 $c[]=array(
'id'=>$db->f(
'id'),
800 'sub'=>$db->f(
'sub'),
801 'domain_type'=>$db->f(
'domain_type'),
802 'domain_type_parameter'=>$db->f(
'domain_type_parameter'),
803 'concerned'=>$db->f(
'concerned'),
804 'enabled'=>$db->f(
'enabled')
814 $err->log(
"dom",
"update_default_subdomains");
816 foreach ($arr as $a) {
817 if (!
isset($a[
'id'])) $a[
'id']=null;
818 if(!empty($a[
'sub']) || !empty($a[
'domain_type_parameter'])){
820 if (!
isset($a[
'enabled'])) $a[
'enabled']=0;
821 if (! $this->
update_one_default($a[
'domain_type'],$a[
'sub'], $a[
'domain_type_parameter'], $a[
'concerned'], $a[
'enabled'],$a[
'id']) ) {
831 $err->log(
"dom",
"update_one_default");
834 $db->query(
"INSERT INTO default_subdomains values ('','".addslashes(
$sub).
"','".addslashes($domain_type).
"','".addslashes($domain_type_parameter).
"','".addslashes($concerned).
"','".addslashes($enabled).
"');");
836 $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).
";");
845 $err->log(
"dom",
"del_default_type");
847 if(!$db->query(
"delete from default_subdomains where id=$id;")){
848 $err->raise(
"dom",_(
"Could not delete default type"));
874 $err->log(
"dom",
"whois",
$domain);
877 preg_match(
"#.*\.([^\.]*)#",
$domain,$out);
883 if (($fp=@fsockopen(
"whois.iana.org", 43))>0) {
884 fputs($fp,
"$domain\r\n");
888 $ligne = fgets($fp,128);
889 if (preg_match(
'#^whois:#', $ligne)) { $serveur=preg_replace(
'/whois:\ */',
'',$ligne,1); }
892 $serveur=str_replace(array(
" ",
"\n"),
"",$serveur);
905 if (($fp=@fsockopen($serveur, 43))>0) {
906 fputs($fp,
"$egal$domain\r\n");
910 $ligne = fgets($fp,128);
921 if (preg_match(
"#Name Server:#", $ligne)) {
923 $tmp=strtolower(str_replace(chr(10),
"",str_replace(chr(13),
"",str_replace(
" ",
"", str_replace(
"Name Server:",
"", $ligne)))));
929 $ligne = str_replace(chr(10),
"",str_replace(chr(13),
"",str_replace(
" ",
"", $ligne)));
930 if ($ligne==
"" && $state==1)
933 $server[]=strtolower($ligne);
934 if ($ligne==
"Nameservers:" && $state==0) {
941 $ligne=preg_replace(
"/^ *([^ ]*) \(.*\)$/",
"\\1",trim($ligne));
946 if ($ligne==
"Nameservers:") {
952 if (preg_match(
'/Name Server:/', $ligne)) {
955 $tmp = strtolower(preg_replace(
'/Name Server: ([^ ]+)\..$/',
"\\1", $ligne));
956 $tmp = preg_replace(
'/[^-_a-z0-9\.]/',
'', $tmp);
962 if (preg_match(
"#nserver:#", $ligne)) {
964 $tmp=strtolower(preg_replace(
"/nserver:\s*[^ ]*\s*([^\s]*)$/",
"\\1", $ligne));
971 if (preg_match(
"#nserver:#", $ligne)) {
973 $tmp=strtolower(preg_replace(
"#nserver:\s*([^\s]*)\s*.*$#",
"\\1", $ligne));
980 if (preg_match(
'#Name servers#', $ligne)) {
984 if (preg_match(
'#^[^%]#', $ligne) && $ligne = preg_replace(
'#[[:space:]]#',
"", $ligne)) {
992 if (preg_match(
'#Host Name:\s*([^\s]+)#', $ligne, $matches)) {
994 $server[] = $matches[1];
1000 $err->raise(
"dom",_(
"The Whois database is unavailable, please try again later"));
1007 $err->raise(
"dom",_(
"The domain cannot be found in the Whois database"));
1022 global $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX ;
1024 if ( $ref_domain ) {
1025 getmxrr($ref_domain, $ref_mx);
1027 $ref_mx = array($L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX);
1030 if (empty($ref_mx)) {
1036 if (!getmxrr($domaine,$mxhosts)) {
1041 if ( empty($mxhosts) ) {
1046 $intersect = array_intersect($mxhosts, $ref_mx);
1048 if ( empty($intersect) ) {
1079 $err->log(
"dom",
"get_domain_all",
$dom);
1081 if (!$this->islocked) {
1082 $err->raise(
"dom",_(
"--- Program error --- No lock on the domains!"));
1087 $err->raise(
"dom",_(
"The domain name is syntaxically incorrect"));
1091 $db->query(
"SELECT * FROM domaines WHERE compte='$cuid' AND domaine='$dom'");
1092 if ($db->num_rows()==0) {
1093 $err->raise(
"dom",sprintf(_(
"Domain '%s' not found"),
$dom));
1097 $r[
"id"]=$db->Record[
"id"];
1098 $r[
"dns"]=$db->Record[
"gesdns"];
1099 $r[
"dns_action"]=$db->Record[
"dns_action"];
1100 $r[
"dns_result"]=$db->Record[
"dns_result"];
1101 $r[
"mail"]=$db->Record[
"gesmx"];
1102 $r[
"zonettl"]=$db->Record[
"zonettl"];
1103 $r[
'noerase']=$db->Record[
'noerase'];
1105 $db->query(
"SELECT COUNT(*) AS cnt FROM sub_domaines WHERE compte='$cuid' AND domaine='$dom'");
1107 $r[
"nsub"]=$db->Record[
"cnt"];
1109 #$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");
1110 $db->query(
"SELECT sd.*, dt.description AS type_desc, dt.only_dns FROM sub_domaines sd LEFT JOIN domaines_type dt on UPPER(dt.name)=UPPER(sd.type) WHERE compte='$cuid' AND domaine='$dom' ORDER BY sd.sub,sd.type ;");
1115 $r[
"sub"][
$i]=array();
1116 $r[
"sub"][
$i][
"id"]=$db->Record[
"id"];
1117 $r[
"sub"][
$i][
"name"]=$db->Record[
"sub"];
1118 $r[
"sub"][
$i][
"dest"]=$db->Record[
"valeur"];
1119 $r[
"sub"][
$i][
"type"]=$db->Record[
"type"];
1120 $r[
"sub"][
$i][
"enable"]=$db->Record[
"enable"];
1121 $r[
"sub"][
$i][
"type_desc"]=$db->Record[
"type_desc"];
1122 $r[
"sub"][
$i][
"only_dns"]=$db->Record[
"only_dns"];
1123 $r[
"sub"][
$i][
"web_action"]=$db->Record[
"web_action"];
1124 $r[
"sub"][
$i][
"fqdn"]= ((!empty($r[
"sub"][
$i][
"name"]))?$r[
"sub"][$i][
"name"].
".":
"").$r[
"name"] ;
1146 $err->log(
"dom",
"get_sub_domain_all",$sub_domain_id);
1148 if (!$this->islocked) {
1149 $err->raise(
"dom",_(
"--- Program error --- No lock on the domains!"));
1152 $db->query(
"select sd.*, dt.description as type_desc, dt.only_dns from sub_domaines sd, domaines_type dt where compte='$cuid' and sd.id='$sub_domain_id' and upper(dt.name)=upper(sd.type);");
1153 if ($db->num_rows()==0) {
1154 $err->raise(
"dom",_(
"The sub-domain does not exist"));
1159 $r[
"id"]=$db->Record[
"id"];
1160 $r[
"name"]=$db->Record[
"sub"];
1161 $r[
"domain"]=$db->Record[
"domaine"];
1162 $r[
"dest"]=$db->Record[
"valeur"];
1163 $r[
"enable"]=$db->Record[
"enable"];
1164 $r[
"type"]=$db->Record[
"type"];
1165 $r[
"type_desc"]=$db->Record[
"type_desc"];
1166 $r[
"only_dns"]=$db->Record[
"only_dns"];
1167 $r[
"web_action"]=$db->Record[
"web_action"];
1182 if(filter_var(
$value, FILTER_VALIDATE_URL)){
1185 $err->raise(
"dom",_(
"invalid url"));
1191 if (substr(
$value,0,1)!=
"/") {
1195 $err->raise(
"dom",_(
"The folder you entered is incorrect or does not exist"));
1204 $err->raise(
"dom",_(
"The ip address is invalid"));
1212 $err->raise(
"dom",_(
"The ip address is invalid"));
1220 $err->raise(
"dom",_(
"The name you entered is incorrect"));
1228 $err->raise(
"dom",_(
"The TXT value you entered is incorrect"));
1233 $err->raise(
"dom",_(
"Invalid domain type selected, please check"));
1252 $err->log(
"dom",
"can_create_subdomain",
$dom.
"/".
$sub);
1255 $db->query(
"select upper(compatibility) as compatibility from domaines_type where upper(name)=upper('$type');");
1256 if (!$db->next_record())
return false;
1257 $compatibility_lst = explode(
",",$db->f(
'compatibility'));
1260 $db->query(
"select * from sub_domaines where sub='$sub' and domaine='$dom' and not id = $sub_domain_id and web_action != 'DELETE' and enabled not in ('DISABLED', 'DISABLE') ");
1261 #$db->query("select * from sub_domaines where sub='$sub' and domaine='$dom';");
1262 while ($db->next_record()) {
1264 if (! in_array(strtoupper($db->f(
'type')),$compatibility_lst))
return false;
1289 $err->log(
"dom",
"set_sub_domain",
$dom.
"/".
$sub.
"/".$type.
"/".$dest);
1291 if (!$this->islocked) {
1292 $err->raise(
"dom",_(
"--- Program error --- No lock on the domains!"));
1303 if ((
$sub !=
'*' &&
$sub!=
'') && !($fqdn==0 || $fqdn==4)) {
1304 $err->raise(
"dom",_(
"There is some forbidden characters in the sub domain (only A-Z 0-9 and - are allowed)"));
1310 #$err->raise("dom",_("Invalid domain type selected, please check"));
1316 $err->raise(
"dom",_(
"The domain name is syntaxically incorrect"));
1321 $err->raise(
"dom", _(
"The parameters for this subdomain and domain type are invalid. Please check for subdomain entries incompatibility"));
1325 if (! is_null($sub_domain_id )) {
1330 if (! $db->query(
"replace into sub_domaines (compte,domaine,sub,valeur,type,web_action) values ('$cuid','$dom','$sub','$dest','$type','UPDATE');") ) {
1331 echo
"query failed: ".$db->Error;
1336 $dest_root = $bro->get_userid_root($cuid);
1338 $db->query(
"select create_tmpdir, create_targetdir from domaines_type where name = '$type';");
1340 if ($db->f(
'create_tmpdir')) {
1341 if (! is_dir($dest_root .
"/tmp")) {
1342 if(!@mkdir($dest_root .
"/tmp",0777,
true)){
1343 $err->raise(
"dom",_(
"Cannot write to the destination folder"));
1347 if ($db->f(
'create_targetdir')) {
1348 $dirr=$dest_root.$dest;
1349 $dirr=str_replace(
'//',
'/',$dirr);
1351 if (! is_dir($dirr)) {
1353 if(!@mkdir($dirr,0770,
true)){
1354 $err->raise(
"dom",_(
"Cannot write to the destination folder"));
1361 $db->query(
"update domaines set dns_action='UPDATE' where domaine='$dom';");
1378 $err->log(
"dom",
"del_sub_domain",$sub_domain_id);
1380 if (!$this->islocked) {
1381 $err->raise(
"dom",_(
"--- Program error --- No lock on the domains!"));
1385 $err->raise(
"dom",_(
"The sub-domain does not exist"));
1388 $db->query(
"update sub_domaines set web_action='DELETE' where id='$sub_domain_id'; ");
1389 $db->query(
"update domaines set dns_action='UPDATE' where domaine='".
$r[
'domain'].
"';");
1397 $err->log(
"dom",
"set_ttl",
"$dom_id / $ttl");
1422 $err->log(
"dom",
"edit_domain",
$dom.
"/".
$dns.
"/".$gesmx);
1424 if (!$this->islocked && !
$force) {
1425 $err->raise(
"dom",_(
"--- Program error --- No lock on the domains!"));
1432 $err->raise(
"dom",_(
"The last member of the domain name is incorrect or cannot be hosted in that server"));
1435 if (
$dns && $v==-2) {
1436 $err->raise(
"dom",_(
"The domain cannot be found in the Whois database"));
1439 if (
$dns && $v==-3) {
1440 $err->raise(
"dom",_(
"The DNS of this domain do not match the server's DNS. Please change your domain's DNS before you install it again"));
1445 # Can't have ttl == 0. There is also a check in function_dns
1446 if ( $ttl == 0 ) { $ttl = 86400; }
1450 $err->raise(
"dom",_(
"The domain name is syntaxically incorrect"));
1455 $err->raise(
"dom",_(
"The domain name %s does not exist"),
$dom);
1460 if (
$r[
"dns"]==
$dns &&
$r[
"mail"]==$gesmx &&
$r[
"zonettl"]==$ttl) {
1461 $err->raise(
"dom",_(
"No change has been requested..."));
1469 $err->raise(
"dom",_(
"There is no MX record pointing to this server, and you are asking us to host the mail here. Make sure to update your MX entries or no mail will be received"));
1474 $err->raise(
"dom",_(
"There is no MX record pointing to this server, and you are asking us to host the mail here. Make sure to update your MX entries or no mail will be received"));
1478 if ($gesmx && !
$r[
"mail"]) {
1479 $hooks->invoke(
"hook_dom_add_mx_domain",array(
$r[
"id"]));
1482 if (!$gesmx &&
$r[
"mail"]) {
1483 $hooks->invoke(
"hook_dom_del_mx_domain",array(
$r[
"id"]));
1486 $db->query(
"UPDATE domaines SET gesdns='$dns', gesmx='$gesmx', zonettl='$ttl' WHERE domaine='$dom'");
1487 $dom->set_dns_action(
$dom,
'UPDATE');
1504 $db->query(
"SELECT * FROM slaveip;");
1505 if (!$db->next_record()) {
1510 }
while ($db->next_record());
1521 $err->raise(
"dom",_(
"The IP address you entered is incorrect"));
1524 $class=intval($class);
1525 if ($class<8 || $class>32) $class=32;
1526 $db->query(
"SELECT * FROM slaveip WHERE ip='$ip' AND class='$class';");
1527 if ($db->next_record()) {
1528 $err->raise(
"err",_(
"The requested domain is forbidden in this server, please contact the administrator"));
1531 $db->query(
"INSERT INTO slaveip (ip,class) VALUES ('$ip','$class');");
1545 $err->raise(
"dom",_(
"The IP address you entered is incorrect"));
1548 $db->query(
"DELETE FROM slaveip WHERE ip='$ip'");
1561 $db->query(
"SELECT * FROM slaveaccount WHERE login='$login' AND pass='$pass';");
1562 if ($db->next_record()) {
1574 $db->query(
"SELECT domaine FROM domaines WHERE gesdns=1 ORDER BY domaine");
1576 while ($db->next_record()) {
1577 #echo $db->f("domaine")."\n";
1578 $tt.=$db->f(
"domaine").
"\n";
1596 $sql=
" AND compte='$uid' ";
1598 $db->query(
"SELECT domaine FROM domaines WHERE gesdns=1 $sql ORDER BY domaine");
1599 while ($db->next_record()) {
1600 $res[]=$db->f(
"domaine");
1608 $db->query(
"SELECT domaine, gesdns, gesmx, dns_action, zonettl FROM domaines ORDER BY domaine");
1609 while ($db->next_record()) {
1610 $res[$db->f(
"domaine")] = array(
1611 "gesdns" => $db->f(
"gesdns"),
1612 "gesmx" => $db->f(
"gesmx"),
1613 "dns_action" => $db->f(
"dns_action"),
1614 "zonettl" => $db->f(
"zonettl"),
1628 $dom_id=intval($dom_id);
1629 $db->query(
"SELECT domaine FROM domaines WHERE id=$dom_id AND compte=$cuid;");
1630 if ($db->next_record()) {
1633 $err->raise(
"dom",_(
"This domain is not installed in your account"));
1639 $err->raise(
"dom",_(
"This domain is not installed in your account"));
1653 $db->query(
"SELECT id FROM domaines WHERE domaine='".addslashes(
$domain).
"' AND compte=$cuid;");
1654 if ($db->next_record()) {
1657 $err->raise(
"dom",_(
"This domain is not installed in your account"));
1663 $err->raise(
"dom",_(
"This domain is not installed in your account"));
1674 $db->query(
"SELECT COUNT(*) AS count FROM domaines;");
1675 if ($db->next_record()) {
1676 return $db->f(
'count');
1688 $db->query(
"SELECT * FROM slaveaccount;");
1690 while ($db->next_record()) {
1693 if (!count(
$res))
return false;
1703 $db->query(
"SELECT * FROM slaveaccount WHERE login='$login'");
1704 if ($db->next_record()) {
1705 $err->raise(
"dom",_(
"The specified slave account already exists"));
1708 $db->query(
"INSERT INTO slaveaccount (login,pass) VALUES ('$login','$pass')");
1718 $db->query(
"DELETE FROM slaveaccount WHERE login='$login'");
1734 $err->log(
"dom",
"lock");
1735 if ($this->islocked) {
1736 $err->raise(
"dom",_(
"--- Program error --- Lock already obtained!"));
1738 while (file_exists($this->fic_lock_cron)) {
1741 $this->islocked=
true;
1753 $err->log(
"dom",
"unlock");
1754 if (!$this->islocked) {
1755 $err->raise(
"dom",_(
"--- Program error --- No lock on the domains!"));
1757 $this->islocked=
false;
1769 $err->log(
"dom",
"hook_dom_add_mx_domain");
1771 if (! empty($GLOBALS[
'L_DEFAULT_SECONDARY_MX'])) {
1784 $err->log(
"dom",
"alternc_del_member");
1786 foreach($li as
$dom) {
1801 $err->log(
"dom",
"get_quota");
1802 $q=Array(
"name"=>
"dom",
"description"=>_(
"Domain name"),
"used"=>0);
1803 $db->query(
"SELECT COUNT(*) AS cnt FROM domaines WHERE compte='$cuid'");
1804 if ($db->next_record() ) {
1805 $q[
'used']=$db->f(
"cnt");
1817 $err->log(
"dom",
"export");
1819 foreach ($this->domains as
$d) {
1820 $str=
" <domaines>\n";
1821 $str.=
" <nom>".$d.
"</nom>\n";
1825 if(empty($s[
"dns"])){
1830 $str.=
" <dns>".$s[
"dns"].
"</dns>\n";
1832 if(empty($s[
"mx"])){
1838 $str.=
" <mx>".$s[
"mx"].
"</mx>\n";
1840 if(empty($s[
"mail"])){
1843 $str.=
" <mail>".$s[
"mail"].
"</mail>\n";
1844 if (is_array($s[
"sub"])) {
1845 foreach ($s[
"sub"] as
$sub) {
1846 $str.=
" <subdomain>\n";
1847 $str.=
" <enabled>".$sub[
"enable"].
" </enabled>\n";
1848 $str.=
" <destination>".$sub[
"dest"].
" </destination>\n";
1849 $str.=
" <type>".$sub[
"type"].
" </type>\n";
1850 $str.=
" </subdomain>\n";
1854 $str.=
" </domaines>\n";
1869 $err->log(
"dom",
"generation_parameters");
1871 if (! is_null($id) && intval($id)==$id ) {
1873 $params=
" AND sd.id = $id ";
1876 $params.=
" and dt.only_dns is false ";
1883 lower(sd.type) as type,
1886 if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) as fqdn,
1887 concat_ws('@',m.login,v.value) as mail,
1890 sub_domaines sd left join membres m on sd.compte=m.uid,
1894 v.name='mailname_bounce'
1895 and lower(dt.name) = lower(sd.type)
1903 while ($db->next_record()) {
1904 $r[ $db->Record[
'sub_id'] ] = $db->Record;
1919 foreach ($dom->domains_type_lst() as $k => $v) {
1920 if ( $v[
'only_dns'] ==
true )
continue;
1922 die(
"Error: missing file for $k");
1934 if (!
isset($lst_sub[strtoupper($action)]) || empty( $lst_sub[strtoupper($action)] )) {
1938 $lst_by_type = $lst_sub[strtoupper($action)] ;
1940 foreach ( $lst_by_type as $type => $lid_arr) {
1941 $script =
"/etc/alternc/functions_hosting/hosting_".strtolower($type).
".sh";
1942 if (! @is_executable($script) ) {
1945 foreach ($lid_arr as $lid ) {
1946 $o = $sub_obj[$lid];
1947 $cmd = $script.
" ".escapeshellcmd(strtolower($action)).
" ";
1948 $cmd .= escapeshellcmd($o[
'fqdn']).
" ".escapeshellcmd($o[
'valeur']);
1967 $check_dup = array();
1970 foreach ($lst as
$p ) {
1972 if ( in_array($p[
'fqdn'], $check_dup) ) {
1973 die(
"Error: duplicate fqdn : ".$p[
'fqdn']);
1975 $check_dup[] = $p[
'fqdn'];
1979 $tpl = $gdt[ $p[
'type'] ] [
'tpl'];
1982 $tpl = strtr($tpl, array(
1983 "%%LOGIN%%"=> $p[
'login'],
1984 "%%fqdn%%"=> $p[
'fqdn'],
1985 "%%document_root%%"=>
getuserpath($p[
'login']).$p[
'valeur'],
1987 "%%redirect%%"=> $p[
'valeur'],
1988 "%%UID%%"=> $p[
'uid'],
1989 "%%GID%%"=> $p[
'uid'],
1990 "%%mail_account%%"=> $p[
'mail'],
1991 "%%user%%"=>
"FIXME",
1995 if ( $p[
'uid'] < 1999 ) {
1996 $ret.=
"# ERROR: Sub_id: ".$p[
'sub_id'].
"- The uid seem to be dangerous\n";
2001 $ret.=
"# Sub_id: ".$p[
'sub_id'].
"\n".$tpl;
2010 $err->log(
"dom",
"generation_todo");
2011 $db->query(
"select id as sub_id, web_action, type from sub_domaines where web_action !='ok';");
2013 while ($db->next_record()) {
2014 $r[ strtoupper($db->Record[
'web_action']) ][ strtoupper($db->Record[
'type']) ][] = $db->f(
'sub_id');
2021 $sub_domain_id=intval($sub_domain_id);
2022 switch (strtolower($action)) {
2024 $sql=
"DELETE FROM sub_domaines WHERE id =$sub_domain_id;";
2027 $sql=
"UPDATE sub_domaines SET web_action='OK' WHERE id='$sub_domain_id'; ";
2035 $db->query(
"UPDATE domaines SET dns_action='".mysql_escape_string($dns_action).
"' WHERE domaine='".mysql_escape_string(
$domain).
"'; ");
2041 $db->query(
"UPDATE domaines SET dns_result='".mysql_escape_string($dns_result).
"' WHERE domaine='".mysql_escape_string(
$domain).
"'; ");
2053 "dns-tcp" => array(
"port" => 53,
"protocol" =>
"tcp",
"mandatory" => 1),
2054 "dns-udp" => array(
"port" => 53,
"protocol" =>
"udp",
"mandatory" => 1),
2069 foreach ( $da[
'sub'] as
$sub ) {
2070 if ( ! $sub[
'only_dns'] ) {
2071 if (!
isset($tmp[$sub[
'fqdn']])) {
2072 $tmp[$sub[
'fqdn']] = 0;
2074 $tmp[$sub[
'fqdn']]++;
2075 if ($tmp[$sub[
'fqdn']] >= 2 ) {
2076 $errors[$sub[
'fqdn']]=sprintf(_(
"Problem on %s: there is more than 1 web configuration going to be generated for this sub-domain."), $sub[
'fqdn']);
2083 foreach ( $da[
'sub'] as $sub ) {
2084 if (is_null($sub[
'type_desc'])) {
2085 $errors[$sub[
'fqdn']]=sprintf(_(
"Problem on %s: we do not know domain's type <b>%s</b>."),$sub[
'fqdn'], $sub[
'type']);
2096 _(
"Locally hosted");
2097 _(
"URL redirection");
2099 _(
"Webmail access");
2100 _(
"Squirrelmail Webmail access");
2101 _(
"Roundcube Webmail access");
2103 _(
"CNAME DNS entry");
2106 _(
"secondary MX DNS entry");
2107 _(
"Default mail server");
2108 _(
"Default backup mail server");
2109 _(
"AlternC panel access");