| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Id: m_dom.php,v 1.27 2006/02/17 18:34:30 olivier Exp $ |
|---|
| 4 | ---------------------------------------------------------------------- |
|---|
| 5 | LICENSE |
|---|
| 6 | |
|---|
| 7 | This program is free software; you can redistribute it and/or |
|---|
| 8 | modify it under the terms of the GNU General Public License (GPL) |
|---|
| 9 | as published by the Free Software Foundation; either version 2 |
|---|
| 10 | of the License, or (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | This program is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|---|
| 18 | ---------------------------------------------------------------------- |
|---|
| 19 | Original Author of file: Benjamin Sonntag |
|---|
| 20 | Purpose of file: PHP Class that manage domain names installed on the server |
|---|
| 21 | ---------------------------------------------------------------------- |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | define('SLAVE_FLAG', "/var/run/alternc/refresh_slave"); |
|---|
| 25 | |
|---|
| 26 | /** |
|---|
| 27 | * Classe de gestion des domaines de l'hébergé. |
|---|
| 28 | * |
|---|
| 29 | * Cette classe permet de gérer les domaines / sous-domaines, redirections |
|---|
| 30 | * dns et mx des domaines d'un membre hébergé.<br /> |
|---|
| 31 | * Copyleft {@link http://alternc.net/ AlternC Team} |
|---|
| 32 | * |
|---|
| 33 | * @copyright AlternC-Team 2002-11-01 http://alternc.net/ |
|---|
| 34 | * |
|---|
| 35 | */ |
|---|
| 36 | class m_dom { |
|---|
| 37 | |
|---|
| 38 | /** $domains : Cache des domaines du membre |
|---|
| 39 | * @access private |
|---|
| 40 | */ |
|---|
| 41 | var $domains; |
|---|
| 42 | |
|---|
| 43 | /** $dns : Liste des dns trouvés par la fonction whois |
|---|
| 44 | * @access private |
|---|
| 45 | */ |
|---|
| 46 | var $dns; |
|---|
| 47 | |
|---|
| 48 | /** Flag : a-t-on trouvé un sous-domaine Webmail pour ce domaine ? |
|---|
| 49 | * @access private |
|---|
| 50 | */ |
|---|
| 51 | var $webmail; |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * Système de verrouillage du cron |
|---|
| 55 | * Ce fichier permet de verrouiller le cron en attendant la validation |
|---|
| 56 | * du domaine par update_domains.sh |
|---|
| 57 | * @access private |
|---|
| 58 | */ |
|---|
| 59 | var $fic_lock_cron="/var/run/alternc/cron.lock"; |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * Le cron a-t-il été bloqué ? |
|---|
| 63 | * Il faut appeler les fonctions privées lock et unlock entre les |
|---|
| 64 | * appels aux domaines. |
|---|
| 65 | * @access private |
|---|
| 66 | */ |
|---|
| 67 | var $islocked=false; |
|---|
| 68 | |
|---|
| 69 | var $type_local = "0"; |
|---|
| 70 | var $type_url = "1"; |
|---|
| 71 | var $type_ip = "2"; |
|---|
| 72 | var $type_webmail = "3"; |
|---|
| 73 | |
|---|
| 74 | var $action_insert = "0"; |
|---|
| 75 | var $action_update= "1"; |
|---|
| 76 | var $action_delete = "2"; |
|---|
| 77 | |
|---|
| 78 | /* ----------------------------------------------------------------- */ |
|---|
| 79 | /** |
|---|
| 80 | * Constructeur |
|---|
| 81 | */ |
|---|
| 82 | function m_dom() { |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | /* ----------------------------------------------------------------- */ |
|---|
| 86 | /** |
|---|
| 87 | * Quota name |
|---|
| 88 | */ |
|---|
| 89 | function alternc_quota_names() { |
|---|
| 90 | return "dom"; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | /* ----------------------------------------------------------------- */ |
|---|
| 94 | /** |
|---|
| 95 | * Retourne un tableau contenant les domaines d'un membre. |
|---|
| 96 | * |
|---|
| 97 | * @return array retourne un tableau indexé contenant la liste des |
|---|
| 98 | * domaines hébergés sur le compte courant. Retourne FALSE si une |
|---|
| 99 | * erreur s'est produite. |
|---|
| 100 | */ |
|---|
| 101 | function enum_domains() { |
|---|
| 102 | global $db,$err,$cuid; |
|---|
| 103 | $err->log("dom","enum_domains"); |
|---|
| 104 | $db->query("select * from domaines where compte='$cuid';"); |
|---|
| 105 | $this->domains=array(); |
|---|
| 106 | if ($db->num_rows()>0) { |
|---|
| 107 | while ($db->next_record()) { |
|---|
| 108 | $this->domains[]=$db->f("domaine"); |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | return $this->domains; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /* ----------------------------------------------------------------- */ |
|---|
| 115 | /** |
|---|
| 116 | * Efface un domaine du membre courant, et tous ses sous-domaines |
|---|
| 117 | * |
|---|
| 118 | * Cette fonction efface un domaine et tous ses sous-domaines, ainsi que |
|---|
| 119 | * les autres services attachés à celui-ci. Elle appelle donc les autres |
|---|
| 120 | * classe. Chaque classe peut déclarer une fonction del_dom qui sera |
|---|
| 121 | * appellée lors de la destruction d'un domaine. |
|---|
| 122 | * |
|---|
| 123 | * @param string $dom nom de domaine à effacer |
|---|
| 124 | * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. |
|---|
| 125 | */ |
|---|
| 126 | function del_domain($dom) { |
|---|
| 127 | global $db,$err,$classes,$cuid; |
|---|
| 128 | $err->log("dom","del_domain",$dom); |
|---|
| 129 | $dom=strtolower($dom); |
|---|
| 130 | $db->query("SELECT * FROM domaines WHERE domaine='$dom';"); |
|---|
| 131 | if ($db->num_rows()==0) { |
|---|
| 132 | $err->raise("dom",1,$dom); |
|---|
| 133 | return false; |
|---|
| 134 | } |
|---|
| 135 | $db->next_record(); |
|---|
| 136 | if ($db->f("compte")!=$cuid) { |
|---|
| 137 | $err->raise("dom",2,$dom); |
|---|
| 138 | return false; |
|---|
| 139 | } |
|---|
| 140 | $db->query("INSERT INTO domaines_standby (compte,domaine,mx,gesdns,gesmx,action) SELECT compte,domaine,mx,gesdns,gesmx,2 FROM domaines WHERE domaine='$dom'"); // DELETE |
|---|
| 141 | $db->query("DELETE FROM domaines WHERE domaine='$dom';"); |
|---|
| 142 | $db->query("DELETE FROM sub_domaines WHERE domaine='$dom';"); |
|---|
| 143 | |
|---|
| 144 | // DEPENDANCE : |
|---|
| 145 | // Lancement de del_dom sur les classes domain_sensitive : |
|---|
| 146 | // Declenchons les autres classes. |
|---|
| 147 | foreach($classes as $c) { |
|---|
| 148 | if (method_exists($GLOBALS[$c],"alternc_del_domain")) { |
|---|
| 149 | $GLOBALS[$c]->alternc_del_domain($dom); |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | foreach($classes as $c) { |
|---|
| 153 | if (method_exists($GLOBALS[$c],"alternc_del_mx_domain")) { |
|---|
| 154 | $GLOBALS[$c]->alternc_del_mx_domain($dom); |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | return true; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | /* ----------------------------------------------------------------- */ |
|---|
| 161 | /** |
|---|
| 162 | * Installe un domaine sur le compte courant. |
|---|
| 163 | * |
|---|
| 164 | * <p>Si le domaine existe déjà ou est interdit, ou est celui du serveur, |
|---|
| 165 | * l'installation est refusée. Si l'hébergement DNS est demandé, la fonction |
|---|
| 166 | * checkhostallow vérifiera que le domaine peut être installé conformément |
|---|
| 167 | * aux demandes des super-admin. |
|---|
| 168 | * Si le dns n'est pas demandé, le domaine peut être installé s'il est en |
|---|
| 169 | * seconde main d'un tld (exemple : test.eu.org ou test.com, mais pas |
|---|
| 170 | * toto.test.org ou test.test.asso.fr)</p> |
|---|
| 171 | * <p>Chaque classe peut définir une fonction add_dom($dom) qui sera |
|---|
| 172 | * appellée lors de l'installation d'un nouveau domaine.</p> |
|---|
| 173 | * |
|---|
| 174 | * @param string $dom nom fqdn du domaine à installer |
|---|
| 175 | * @param integer $dns 1 ou 0 pour héberger le DNS du domaine ou pas. |
|---|
| 176 | * @param integer $noerase 1 ou 0 pour rendre le domaine inamovible ou non |
|---|
| 177 | * @param integer $force 1 ou 0, si 1, n'effectue pas les tests de DNS. |
|---|
| 178 | * force ne devrait être utilisé que par le super-admin. |
|---|
| 179 | $ @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. |
|---|
| 180 | */ |
|---|
| 181 | function add_domain($domain,$dns,$noerase=0,$force=0) { |
|---|
| 182 | global $db,$err,$quota,$classes,$L_MX,$L_FQDN,$tld,$cuid; |
|---|
| 183 | $err->log("dom","add_domain",$domain); |
|---|
| 184 | $mx="1"; |
|---|
| 185 | // Locked ? |
|---|
| 186 | if (!$this->islocked) { |
|---|
| 187 | $err->raise("dom",3); |
|---|
| 188 | return false; |
|---|
| 189 | } |
|---|
| 190 | // Verifie que le domaine est rfc-compliant |
|---|
| 191 | $domain=strtolower($domain); |
|---|
| 192 | $t=checkfqdn($domain); |
|---|
| 193 | if ($t) { |
|---|
| 194 | $err->raise("dom",3+$t); |
|---|
| 195 | return false; |
|---|
| 196 | } |
|---|
| 197 | // Interdit les domaines clés (table forbidden_domains) sauf en cas FORCE |
|---|
| 198 | $db->query("select domain from forbidden_domains where domain='$domain'"); |
|---|
| 199 | if ($db->num_rows() && !$force) { |
|---|
| 200 | $err->raise("dom",22); |
|---|
| 201 | return false; |
|---|
| 202 | } |
|---|
| 203 | if ($domain==$L_FQDN || $domain=="www.$L_FQDN") { |
|---|
| 204 | $err->raise("dom",18); |
|---|
| 205 | return false; |
|---|
| 206 | } |
|---|
| 207 | $db->query("SELECT compte FROM domaines WHERE domaine='$domain';"); |
|---|
| 208 | if ($db->num_rows()) { |
|---|
| 209 | $err->raise("dom",8); |
|---|
| 210 | return false; |
|---|
| 211 | } |
|---|
| 212 | $db->query("SELECT compte FROM `sub_domaines` WHERE sub != \"\" AND concat( sub, \".\", domaine )='$domain' OR domaine='$domain';"); |
|---|
| 213 | if ($db->num_rows()) { |
|---|
| 214 | $err->raise("dom",8); |
|---|
| 215 | return false; |
|---|
| 216 | } |
|---|
| 217 | $db->query("select compte from domaines_standby where domaine='$domain';"); |
|---|
| 218 | if ($db->num_rows()!=0) { |
|---|
| 219 | $err->raise("dom",9); |
|---|
| 220 | return false; |
|---|
| 221 | } |
|---|
| 222 | $this->dns=$this->whois($domain); |
|---|
| 223 | if (!$force) { |
|---|
| 224 | $v=checkhostallow($domain,$this->dns); |
|---|
| 225 | if ($v==-1) { |
|---|
| 226 | $err->raise("dom",7); // TLD interdit |
|---|
| 227 | return false; |
|---|
| 228 | } |
|---|
| 229 | if ($dns && $v==-2) { |
|---|
| 230 | $err->raise("dom",12); // Domaine non trouvé dans le whois |
|---|
| 231 | return false; |
|---|
| 232 | } |
|---|
| 233 | if ($dns && $v==-3) { |
|---|
| 234 | $err->raise("dom",23); // Domaine non trouvé dans le whois |
|---|
| 235 | return false; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | if ($dns) $dns="1"; else $dns="0"; |
|---|
| 239 | |
|---|
| 240 | // mode 5 : force DNS to NO. |
|---|
| 241 | if ($tld[$v]==5) $dns=0; |
|---|
| 242 | // It must be a real domain (no subdomain) |
|---|
| 243 | if (!$dns) { |
|---|
| 244 | $v=checkhostallow_nodns($domain); |
|---|
| 245 | if ($v) { |
|---|
| 246 | $err->raise("dom",22); |
|---|
| 247 | return false; |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | } |
|---|
| 251 | // Check the quota : |
|---|
| 252 | if (!$quota->cancreate("dom")) { |
|---|
| 253 | $err->raise("dom",10); |
|---|
| 254 | return false; |
|---|
| 255 | } |
|---|
| 256 | if ($noerase) $noerase="1"; else $noerase="0"; |
|---|
| 257 | $db->query("insert into domaines (compte,domaine,mx,gesdns,gesmx,noerase) values ('$cuid','$domain','$L_MX','$dns','$mx','$noerase');"); |
|---|
| 258 | $db->query("insert into domaines_standby (compte,domaine,mx,gesdns,gesmx,action) values ('$cuid','$domain','$L_MX','$dns','$mx',0);"); // INSERT |
|---|
| 259 | // Creation des 3 sous-domaines par défaut : Vide, www et mail |
|---|
| 260 | $this->set_sub_domain($domain, '', $this->type_url, 'add', 'http://www.'.$domain); |
|---|
| 261 | $this->set_sub_domain($domain, 'www', $this->type_local, 'add', '/'); |
|---|
| 262 | $this->set_sub_domain($domain, 'mail', $this->type_webmail, 'add', ''); |
|---|
| 263 | // DEPENDANCE : |
|---|
| 264 | // Lancement de add_dom sur les classes domain_sensitive : |
|---|
| 265 | // Declenchons les autres classes. |
|---|
| 266 | foreach($classes as $c) { |
|---|
| 267 | if (method_exists($GLOBALS[$c],"alternc_add_domain")) { |
|---|
| 268 | $GLOBALS[$c]->alternc_add_domain($domain); |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | foreach($classes as $c) { |
|---|
| 272 | if (method_exists($GLOBALS[$c],"alternc_add_mx_domain")) { |
|---|
| 273 | $GLOBALS[$c]->alternc_add_mx_domain($domain); |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | return true; |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | /* ----------------------------------------------------------------- */ |
|---|
| 280 | /** |
|---|
| 281 | * Retourne les entrées DNS du domaine $domain issues du WHOIS. |
|---|
| 282 | * |
|---|
| 283 | * Cette fonction effectue un appel WHOIS($domain) sur Internet, |
|---|
| 284 | * et extrait du whois les serveurs DNS du domaine demandé. En fonction |
|---|
| 285 | * du TLD, on sait (ou pas) faire le whois correspondant. |
|---|
| 286 | * Actuellement, les tld suivants sont supportés : |
|---|
| 287 | * .com .net .org .be .info .ca .cx .fr .biz .name |
|---|
| 288 | * |
|---|
| 289 | * @param string $domain Domaine fqdn dont on souhaite les serveurs DNS |
|---|
| 290 | * @return array Retourne un tableau indexé avec les NOMS fqdn des dns |
|---|
| 291 | * du domaine demandé. Retourne FALSE si une erreur s'est produite. |
|---|
| 292 | * |
|---|
| 293 | */ |
|---|
| 294 | function whois($domain) { |
|---|
| 295 | global $db,$err; |
|---|
| 296 | $err->log("dom","whois",$domain); |
|---|
| 297 | // pour ajouter un nouveau TLD, utiliser le code ci-dessous. |
|---|
| 298 | // echo "whois : $domain<br />"; |
|---|
| 299 | ereg(".*\.([^\.]*)",$domain,$out); |
|---|
| 300 | $ext=$out[1]; |
|---|
| 301 | // pour ajouter un nouveau TLD, utiliser le code ci-dessous. |
|---|
| 302 | // echo "ext: $ext<br />"; |
|---|
| 303 | $egal=""; |
|---|
| 304 | switch($ext) { |
|---|
| 305 | case "com": |
|---|
| 306 | case "net": |
|---|
| 307 | $serveur="rs.internic.net"; |
|---|
| 308 | $egal="="; |
|---|
| 309 | break; |
|---|
| 310 | case "org": |
|---|
| 311 | $serveur="whois.pir.org"; |
|---|
| 312 | break; |
|---|
| 313 | case "be": |
|---|
| 314 | $serveur="whois.dns.be"; |
|---|
| 315 | break; |
|---|
| 316 | case "eu": |
|---|
| 317 | $serveur="195.234.53.193"; |
|---|
| 318 | break; |
|---|
| 319 | case "info": |
|---|
| 320 | $serveur="whois.afilias.net"; |
|---|
| 321 | break; |
|---|
| 322 | case "ca": |
|---|
| 323 | $serveur="whois.cira.ca"; |
|---|
| 324 | break; |
|---|
| 325 | case "cx": |
|---|
| 326 | $serveur="whois.nic.cx"; |
|---|
| 327 | break; |
|---|
| 328 | case "it": |
|---|
| 329 | $serveur="whois.nic.it"; |
|---|
| 330 | break; |
|---|
| 331 | case "fr": |
|---|
| 332 | $serveur="whois.nic.fr"; |
|---|
| 333 | break; |
|---|
| 334 | case "biz": |
|---|
| 335 | $serveur="whois.nic.biz"; |
|---|
| 336 | break; |
|---|
| 337 | case "name": |
|---|
| 338 | $serveur="whois.nic.name"; |
|---|
| 339 | break; |
|---|
| 340 | case "ws": |
|---|
| 341 | $serveur="whois.samoanic.ws"; |
|---|
| 342 | break; |
|---|
| 343 | default: |
|---|
| 344 | $err->raise("dom",7); |
|---|
| 345 | return false; |
|---|
| 346 | break; |
|---|
| 347 | } |
|---|
| 348 | // pour ajouter un nouveau TLD, utiliser le code ci-dessous. |
|---|
| 349 | // echo "serveur : $serveur <br />"; |
|---|
| 350 | if (($fp=fsockopen($serveur, 43))>0) { |
|---|
| 351 | fputs($fp, "$egal$domain\r\n"); |
|---|
| 352 | $found = false; |
|---|
| 353 | $state=0; |
|---|
| 354 | while (!feof($fp)) { |
|---|
| 355 | $ligne = fgets($fp,128); |
|---|
| 356 | // pour ajouter un nouveau TLD, utiliser le code ci-dessous. |
|---|
| 357 | // echo "| $ligne<br />"; |
|---|
| 358 | switch($ext) { |
|---|
| 359 | case "org": |
|---|
| 360 | case "com": |
|---|
| 361 | case "net": |
|---|
| 362 | case "info": |
|---|
| 363 | case "biz": |
|---|
| 364 | case "name": |
|---|
| 365 | if (ereg("Name Server:", $ligne)) { |
|---|
| 366 | $found = true; |
|---|
| 367 | $tmp=strtolower(ereg_replace(chr(10), "",ereg_replace(chr(13),"",ereg_replace(" ","", ereg_replace("Name Server:","", $ligne))))); |
|---|
| 368 | if ($tmp) |
|---|
| 369 | $server[]=$tmp; |
|---|
| 370 | } |
|---|
| 371 | break; |
|---|
| 372 | case "cx": |
|---|
| 373 | $ligne = ereg_replace(chr(10), "",ereg_replace(chr(13),"",ereg_replace(" ","", $ligne))); |
|---|
| 374 | if ($ligne=="" && $state==1) |
|---|
| 375 | $state=2; |
|---|
| 376 | if ($state==1) |
|---|
| 377 | $server[]=strtolower($ligne); |
|---|
| 378 | if ($ligne=="Nameservers:" && $state==0) { |
|---|
| 379 | $state=1; |
|---|
| 380 | $found = true; |
|---|
| 381 | } |
|---|
| 382 | break; |
|---|
| 383 | case "ca": |
|---|
| 384 | $ligne=ereg_replace(chr(10), "",ereg_replace(chr(13),"",ereg_replace(" ","", $ligne))); |
|---|
| 385 | if ($ligne=="Status:EXIST") |
|---|
| 386 | $found=true; |
|---|
| 387 | if (ereg("NS.-Hostname:", $ligne)) { |
|---|
| 388 | $tmp=strtolower(ereg_replace("NS.-Hostname:","", $ligne)); |
|---|
| 389 | if ($tmp) |
|---|
| 390 | $server[]=$tmp; |
|---|
| 391 | } |
|---|
| 392 | break; |
|---|
| 393 | case "eu": |
|---|
| 394 | case "be": |
|---|
| 395 | $ligne=ereg_replace(chr(10), "",ereg_replace(chr(13),"",ereg_replace(" ","", $ligne))); |
|---|
| 396 | if($found) |
|---|
| 397 | $tmp = trim($ligne); |
|---|
| 398 | if ($tmp) |
|---|
| 399 | $server[]=$tmp; |
|---|
| 400 | if ($ligne=="Nameservers:") { |
|---|
| 401 | $state=1; |
|---|
| 402 | $found=true; |
|---|
| 403 | } |
|---|
| 404 | break; |
|---|
| 405 | case "it": |
|---|
| 406 | if (ereg("nserver:", $ligne)) { |
|---|
| 407 | $found=true; |
|---|
| 408 | $tmp=strtolower(preg_replace("/nserver:\s*[^ ]*\s*([^\s]*)$/","\\1", $ligne)); |
|---|
| 409 | if ($tmp) |
|---|
| 410 | $server[]=$tmp; |
|---|
| 411 | } |
|---|
| 412 | break; |
|---|
| 413 | case "fr": |
|---|
| 414 | if (ereg("nserver:", $ligne)) { |
|---|
| 415 | $found=true; |
|---|
| 416 | $tmp=strtolower(preg_replace("/nserver:\s*([^\s]*)\s*.*$/","\\1", $ligne)); |
|---|
| 417 | if ($tmp) |
|---|
| 418 | $server[]=$tmp; |
|---|
| 419 | } |
|---|
| 420 | break; |
|---|
| 421 | case "ws"; |
|---|
| 422 | /* e.g. |
|---|
| 423 | Welcome to the .WS Whois Server |
|---|
| 424 | |
|---|
| 425 | Use of this service for any purpose other |
|---|
| 426 | than determining the availability of a domain |
|---|
| 427 | in the .WS TLD to be registered is strictly |
|---|
| 428 | prohibited. |
|---|
| 429 | |
|---|
| 430 | Domain Name: DRONE.WS |
|---|
| 431 | |
|---|
| 432 | Registrant: Registered through Go Daddy Software, Inc. (GoDaddy.com |
|---|
| 433 | |
|---|
| 434 | Domain created on 2005-01-11 08:56:25 |
|---|
| 435 | Domain last updated on 2005-01-11 08:56:25 |
|---|
| 436 | |
|---|
| 437 | Name servers: |
|---|
| 438 | |
|---|
| 439 | ns2.koumbit.net |
|---|
| 440 | ns1.koumbit.net |
|---|
| 441 | */ |
|---|
| 442 | |
|---|
| 443 | /* |
|---|
| 444 | failure: |
|---|
| 445 | |
|---|
| 446 | Welcome to the .WS Whois Server |
|---|
| 447 | |
|---|
| 448 | Use of this service for any purpose other |
|---|
| 449 | than determining the availability of a domain |
|---|
| 450 | in the .WS TLD to be registered is strictly |
|---|
| 451 | prohibited. |
|---|
| 452 | |
|---|
| 453 | No match for "dronefdasfsa.ws". |
|---|
| 454 | |
|---|
| 455 | */ |
|---|
| 456 | if (ereg('^[[:space:]]*Name servers:[[:space:]]*$', $ligne)) { |
|---|
| 457 | // found the server |
|---|
| 458 | $state = 1; |
|---|
| 459 | } elseif ($state) { |
|---|
| 460 | if ($ligne = ereg_replace('[[:space:]]', "", $ligne)) { |
|---|
| 461 | // first non-whitespace line is considered to be the nameservers themselves |
|---|
| 462 | $found = true; |
|---|
| 463 | $server[] = $ligne; |
|---|
| 464 | } |
|---|
| 465 | } |
|---|
| 466 | break; |
|---|
| 467 | } // switch |
|---|
| 468 | } // while |
|---|
| 469 | fclose($fp); |
|---|
| 470 | } else { |
|---|
| 471 | $err->raise("dom",11); |
|---|
| 472 | return false; |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | if ($found) { |
|---|
| 476 | return $server; |
|---|
| 477 | } else { |
|---|
| 478 | $err->raise("dom",12); |
|---|
| 479 | return false; |
|---|
| 480 | } |
|---|
| 481 | } // whois |
|---|
| 482 | |
|---|
| 483 | /* ----------------------------------------------------------------- */ |
|---|
| 484 | /** |
|---|
| 485 | * vérifie la presence d'un champs mx valide sur un serveur DNS |
|---|
| 486 | * |
|---|
| 487 | */ |
|---|
| 488 | |
|---|
| 489 | function checkmx($domaine,$mx) { |
|---|
| 490 | //initialise variables |
|---|
| 491 | $mxhosts = array(); |
|---|
| 492 | |
|---|
| 493 | //récupére les champs mx |
|---|
| 494 | if (!getmxrr($domaine,$mxhosts)) { |
|---|
| 495 | //aucune hôte mx spécifié |
|---|
| 496 | return 1; |
|---|
| 497 | } |
|---|
| 498 | else { |
|---|
| 499 | //vérifie qu'un des hôtes est bien sur alternc |
|---|
| 500 | $bolmx = 0; |
|---|
| 501 | //décompose les différents champ MX coté alternc |
|---|
| 502 | $arrlocalmx = split(",",$mx) |
|---|
| 503 | //parcours les différents champ MX retournés |
|---|
| 504 | foreach($mxhosts as $mxhost) { |
|---|
| 505 | foreach($arrlocalmx as localmx) { |
|---|
| 506 | if ($mxhost==$localmx) { |
|---|
| 507 | $bolmx = 1; |
|---|
| 508 | } |
|---|
| 509 | } |
|---|
| 510 | } |
|---|
| 511 | //définition de l'erreur selon reponse du parcours de mxhosts |
|---|
| 512 | if ($bolmx == 0) { |
|---|
| 513 | //aucun des champs MX ne correspond au serveur |
|---|
| 514 | return 2; |
|---|
| 515 | } |
|---|
| 516 | else { |
|---|
| 517 | //un champ mx correct a été trouvé |
|---|
| 518 | return 0; |
|---|
| 519 | } |
|---|
| 520 | } |
|---|
| 521 | } //checkmx |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | /* ----------------------------------------------------------------- */ |
|---|
| 527 | /** |
|---|
| 528 | * retourne TOUTES les infos d'un domaine |
|---|
| 529 | * |
|---|
| 530 | * <b>Note</b> : si le domaine est en attente (présent dans |
|---|
| 531 | * domaines_standby), une erreur est retournée |
|---|
| 532 | * |
|---|
| 533 | * @param string $dom Domaine dont on souhaite les informations |
|---|
| 534 | * @return array Retourne toutes les infos du domaine sous la forme d'un |
|---|
| 535 | * tableau associatif comme suit :<br /><pre> |
|---|
| 536 | * $r["name"] = Nom fqdn |
|---|
| 537 | * $r["dns"] = Gestion du dns ou pas ? |
|---|
| 538 | * $r["mx"] = Valeur du champs MX si "dns"=true |
|---|
| 539 | * $r["mail"] = Heberge-t-on le mail ou pas ? (si "dns"=false) |
|---|
| 540 | * $r["nsub"] = Nombre de sous-domaines |
|---|
| 541 | * $r["sub"] = tableau associatif des sous-domaines |
|---|
| 542 | * $r["sub"][0-(nsub-1)]["name"] = nom du sous-domaine (NON-complet) |
|---|
| 543 | * $r["sub"][0-(nsub-1)]["dest"] = Destination (url, ip, local ...) |
|---|
| 544 | * $r["sub"][0-(nsub-1)]["type"] = Type (0-n) de la redirection. |
|---|
| 545 | * </pre> |
|---|
| 546 | * Retourne FALSE si une erreur s'est produite. |
|---|
| 547 | * |
|---|
| 548 | */ |
|---|
| 549 | function get_domain_all($dom) { |
|---|
| 550 | global $db,$err,$cuid; |
|---|
| 551 | $err->log("dom","get_domain_all",$dom); |
|---|
| 552 | // Locked ? |
|---|
| 553 | if (!$this->islocked) { |
|---|
| 554 | $err->raise("dom",3); |
|---|
| 555 | return false; |
|---|
| 556 | } |
|---|
| 557 | $t=checkfqdn($dom); |
|---|
| 558 | if ($t) { |
|---|
| 559 | $err->raise("dom",3+$t); |
|---|
| 560 | return false; |
|---|
| 561 | } |
|---|
| 562 | $r["name"]=$dom; |
|---|
| 563 | $db->query("select * from domaines_standby where compte='$cuid' and domaine='$dom'"); |
|---|
| 564 | if ($db->num_rows()>0) { |
|---|
| 565 | $err->raise("dom",13); |
|---|
| 566 | return false; |
|---|
| 567 | } |
|---|
| 568 | $db->query("select * from domaines where compte='$cuid' and domaine='$dom'"); |
|---|
| 569 | if ($db->num_rows()==0) { |
|---|
| 570 | $err->raise("dom",1,$dom); |
|---|
| 571 | return false; |
|---|
| 572 | } |
|---|
| 573 | $db->next_record(); |
|---|
| 574 | $r["dns"]=$db->Record["gesdns"]; |
|---|
| 575 | $r["mail"]=$db->Record["gesmx"]; |
|---|
| 576 | $r["mx"]=$db->Record["mx"]; |
|---|
| 577 | $r[noerase]=$db->Record[noerase]; |
|---|
| 578 | $db->free(); |
|---|
| 579 | $db->query("select count(*) as cnt from sub_domaines where compte='$cuid' and domaine='$dom'"); |
|---|
| 580 | $db->next_record(); |
|---|
| 581 | $r["nsub"]=$db->Record["cnt"]; |
|---|
| 582 | $db->free(); |
|---|
| 583 | $db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom'"); |
|---|
| 584 | // Pas de webmail, on le cochera si on le trouve. |
|---|
| 585 | $this->webmail=0; |
|---|
| 586 | for($i=0;$i<$r["nsub"];$i++) { |
|---|
| 587 | $db->next_record(); |
|---|
| 588 | $r["sub"][$i]=array(); |
|---|
| 589 | $r["sub"][$i]["name"]=$db->Record["sub"]; |
|---|
| 590 | $r["sub"][$i]["dest"]=$db->Record["valeur"]; |
|---|
| 591 | $r["sub"][$i]["type"]=$db->Record["type"]; |
|---|
| 592 | if ($db->Record["type"]==3) { // Webmail |
|---|
| 593 | $this->webmail=1; |
|---|
| 594 | $r["sub"][$i]["dest"]=_("Webmail access"); |
|---|
| 595 | } |
|---|
| 596 | } |
|---|
| 597 | $db->free(); |
|---|
| 598 | return $r; |
|---|
| 599 | } // get_domain_all |
|---|
| 600 | |
|---|
| 601 | /* ----------------------------------------------------------------- */ |
|---|
| 602 | /** |
|---|
| 603 | * Retourne TOUTES les infos d'un sous domaine du compte courant. |
|---|
| 604 | * |
|---|
| 605 | * @param string $dom Domaine fqdn concerné |
|---|
| 606 | * @param string $sub Sous-domaine dont on souhaite les informations |
|---|
| 607 | * @return arrray Retourne un tableau associatif contenant les |
|---|
| 608 | * informations du sous-domaine demandé.<pre> |
|---|
| 609 | * $r["name"]= nom du sous-domaine (NON-complet) |
|---|
| 610 | * $r["dest"]= Destination (url, ip, local ...) |
|---|
| 611 | * </pre> |
|---|
| 612 | * $r["type"]= Type (0-n) de la redirection. |
|---|
| 613 | * Retourne FALSE si une erreur s'est produite. |
|---|
| 614 | */ |
|---|
| 615 | function get_sub_domain_all($dom,$sub) { |
|---|
| 616 | global $db,$err,$cuid; |
|---|
| 617 | $err->log("dom","get_sub_domain_all",$dom."/".$sub); |
|---|
| 618 | // Locked ? |
|---|
| 619 | if (!$this->islocked) { |
|---|
| 620 | $err->raise("dom",3); |
|---|
| 621 | return false; |
|---|
| 622 | } |
|---|
| 623 | $t=checkfqdn($dom); |
|---|
| 624 | if ($t) { |
|---|
| 625 | $err->raise("dom",3+$t); |
|---|
| 626 | return false; |
|---|
| 627 | } |
|---|
| 628 | $db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub'"); |
|---|
| 629 | if ($db->num_rows()==0) { |
|---|
| 630 | $err->raise("dom",14); |
|---|
| 631 | return false; |
|---|
| 632 | } |
|---|
| 633 | $db->next_record(); |
|---|
| 634 | $r=array(); |
|---|
| 635 | $r["name"]=$db->Record["sub"]; |
|---|
| 636 | $r["dest"]=$db->Record["valeur"]; |
|---|
| 637 | $r["type"]=$db->Record["type"]; |
|---|
| 638 | $db->free(); |
|---|
| 639 | return $r; |
|---|
| 640 | } // get_sub_domain_all |
|---|
| 641 | |
|---|
| 642 | /* ----------------------------------------------------------------- */ |
|---|
| 643 | /** |
|---|
| 644 | * Modifier les information du sous-domaine demandé. |
|---|
| 645 | * |
|---|
| 646 | * <b>Note</b> : si le sous-domaine $sub.$dom n'existe pas, il est créé.<br /> |
|---|
| 647 | * <b>Note : TODO</b> : vérification de concordance de $dest<br /> |
|---|
| 648 | * |
|---|
| 649 | * @param string $dom Domaine dont on souhaite modifier/ajouter un sous domaine |
|---|
| 650 | * @param string $subk Sous domaine à modifier / créer |
|---|
| 651 | * @param integer $type Type de sous-domaine (local, ip, url ...) |
|---|
| 652 | * @param string $action Action : vaut "add" ou "edit" selon que l'on |
|---|
| 653 | * Crée (add) ou Modifie (edit) le sous-domaine |
|---|
| 654 | * @param string $dest Destination du sous-domaine, dépend de la valeur |
|---|
| 655 | * de $type (url, ip, dossier...) |
|---|
| 656 | * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. |
|---|
| 657 | */ |
|---|
| 658 | function set_sub_domain($dom,$sub,$type,$action,$dest) { |
|---|
| 659 | global $db,$err,$cuid; |
|---|
| 660 | $err->log("dom","set_sub_domain",$dom."/".$sub); |
|---|
| 661 | // Locked ? |
|---|
| 662 | if (!$this->islocked) { |
|---|
| 663 | $err->raise("dom",3); |
|---|
| 664 | return false; |
|---|
| 665 | } |
|---|
| 666 | $dest=trim($dest); |
|---|
| 667 | $dom=strtolower($dom); |
|---|
| 668 | $sub=strtolower($sub); |
|---|
| 669 | if ($sub != '*' && $sub != '' && preg_match('`[^a-z0-9-]`', $sub)) { |
|---|
| 670 | $err->raise("dom",24); |
|---|
| 671 | return false; |
|---|
| 672 | } |
|---|
| 673 | if ($type==2) { // IP |
|---|
| 674 | if (!checkip($dest)) { |
|---|
| 675 | $err->raise("dom",19); |
|---|
| 676 | return false; |
|---|
| 677 | } |
|---|
| 678 | } |
|---|
| 679 | if ($type==1) { // URL |
|---|
| 680 | if (!checkurl($dest)) { |
|---|
| 681 | $err->raise("dom",20); |
|---|
| 682 | return false; |
|---|
| 683 | } |
|---|
| 684 | } |
|---|
| 685 | if ($type==0) { // LOCAL |
|---|
| 686 | if (substr($dest,0,1)!="/") { |
|---|
| 687 | $dest="/".$dest; |
|---|
| 688 | } |
|---|
| 689 | if (!checkuserpath($dest)) { |
|---|
| 690 | $err->raise("dom",21); |
|---|
| 691 | return false; |
|---|
| 692 | } |
|---|
| 693 | } |
|---|
| 694 | // On a épuré $dir des problèmes eventuels ... On est en DESSOUS du dossier de l'utilisateur. |
|---|
| 695 | $t=checkfqdn($dom); |
|---|
| 696 | if ($t) { |
|---|
| 697 | $err->raise("dom",3+$t); |
|---|
| 698 | return false; |
|---|
| 699 | } |
|---|
| 700 | if (!$r=$this->get_sub_domain_all($dom,$sub)) { |
|---|
| 701 | // Le sous-domaine n'existe pas, on le crée seulement si $action vaut add |
|---|
| 702 | if ($action=="add") { |
|---|
| 703 | $db->query("insert into sub_domaines (compte,domaine,sub,valeur,type) values ('$cuid','$dom','$sub','$dest',$type);"); |
|---|
| 704 | $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub';"); |
|---|
| 705 | $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',0);"); // INSERT |
|---|
| 706 | } else { |
|---|
| 707 | $err->raise("dom",14); |
|---|
| 708 | return false; |
|---|
| 709 | } |
|---|
| 710 | } else { |
|---|
| 711 | if ($action=="edit") { |
|---|
| 712 | // On vérifie que des modifications ont bien eu lieu :) |
|---|
| 713 | if ($r["type"]==$type && $r["dest"]==$dest) { |
|---|
| 714 | $err->raise("dom",15); |
|---|
| 715 | return false; |
|---|
| 716 | } |
|---|
| 717 | // OK, des modifs ont été faites, on valide : |
|---|
| 718 | $db->query("update sub_domaines set type='$type', valeur='$dest' where domaine='$dom' and sub='$sub'"); |
|---|
| 719 | $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub'"); |
|---|
| 720 | $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',1);"); // UPDATE |
|---|
| 721 | } else { |
|---|
| 722 | $err->raise("dom",16); |
|---|
| 723 | return false; |
|---|
| 724 | } |
|---|
| 725 | } |
|---|
| 726 | return true; |
|---|
| 727 | } // set_sub_domain |
|---|
| 728 | |
|---|
| 729 | /* ----------------------------------------------------------------- */ |
|---|
| 730 | /** |
|---|
| 731 | * Supprime le sous-domaine demandé |
|---|
| 732 | * |
|---|
| 733 | * @param string $dom Domaine dont on souhaite supprimer un sous-domaine |
|---|
| 734 | * @param string $sub Sous-domaine que l'on souhaite supprimer |
|---|
| 735 | * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. |
|---|
| 736 | * |
|---|
| 737 | */ |
|---|
| 738 | function del_sub_domain($dom,$sub) { |
|---|
| 739 | global $db,$err,$cuid; |
|---|
| 740 | $err->log("dom","del_sub_domain",$dom."/".$sub); |
|---|
| 741 | // Locked ? |
|---|
| 742 | if (!$this->islocked) { |
|---|
| 743 | $err->raise("dom",3); |
|---|
| 744 | return false; |
|---|
| 745 | } |
|---|
| 746 | $t=checkfqdn($dom); |
|---|
| 747 | if ($t) { |
|---|
| 748 | $err->raise("dom",3+$t); |
|---|
| 749 | return false; |
|---|
| 750 | } |
|---|
| 751 | if (!$r=$this->get_sub_domain_all($dom,$sub)) { |
|---|
| 752 | // Le sous-domaine n'existe pas, erreur |
|---|
| 753 | $err->raise("dom",14); |
|---|
| 754 | return false; |
|---|
| 755 | } else { |
|---|
| 756 | // OK, on valide : |
|---|
| 757 | $db->query("delete from sub_domaines where domaine='$dom' and sub='$sub'"); |
|---|
| 758 | $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub'"); |
|---|
| 759 | $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','".$r["dest"]."','".$r["type"]."',2);"); // DELETE |
|---|
| 760 | } |
|---|
| 761 | return true; |
|---|
| 762 | } // del_sub_domain |
|---|
| 763 | |
|---|
| 764 | /* ----------------------------------------------------------------- */ |
|---|
| 765 | /** |
|---|
| 766 | * Modifie les information du domaine précisé. |
|---|
| 767 | * |
|---|
| 768 | * @param string $dom Domaine du compte courant que l'on souhaite modifier |
|---|
| 769 | * @param integer $dns Vaut 1 ou 0 pour héberger ou pas le DNS du domaine |
|---|
| 770 | * @param integer $mx Nom fqdn du serveur mx, si le mx local est précisé, |
|---|
| 771 | * on héberge alors les mails du domaine. |
|---|
| 772 | * @return boolean appelle $mail->add_dom ou $ma->del_dom si besoin, en |
|---|
| 773 | * fonction du champs MX. Retourne FALSE si une erreur s'est produite, |
|---|
| 774 | * TRUE sinon. |
|---|
| 775 | * |
|---|
| 776 | */ |
|---|
| 777 | function edit_domain($dom,$dns,$mx) { |
|---|
| 778 | global $db,$err,$L_MX,$classes,$cuid; |
|---|
| 779 | $err->log("dom","edit_domain",$dom); |
|---|
| 780 | // Locked ? |
|---|
| 781 | if (!$this->islocked) { |
|---|
| 782 | $err->raise("dom",3); |
|---|
| 783 | return false; |
|---|
| 784 | } |
|---|
| 785 | if ($dns == 1) { |
|---|
| 786 | $this->dns=$this->whois($dom); |
|---|
| 787 | $v=checkhostallow($dom,$this->dns); |
|---|
| 788 | if ($v==-1) { |
|---|
| 789 | $err->raise("dom",7); // TLD interdit |
|---|
| 790 | return false; |
|---|
| 791 | } |
|---|
| 792 | if ($dns && $v==-2) { |
|---|
| 793 | $err->raise("dom",12); // Domaine non trouvé dans le whois |
|---|
| 794 | return false; |
|---|
| 795 | } |
|---|
| 796 | if ($dns && $v==-3) { |
|---|
| 797 | $err->raise("dom",23); // Domaine non trouvé dans le whois |
|---|
| 798 | return false; |
|---|
| 799 | } |
|---|
| 800 | } |
|---|
| 801 | $t=checkfqdn($dom); |
|---|
| 802 | if ($t) { |
|---|
| 803 | $err->raise("dom",3+$t); |
|---|
| 804 | return false; |
|---|
| 805 | } |
|---|
| 806 | if (!$r=$this->get_domain_all($dom)) { |
|---|
| 807 | // Le domaine n'existe pas, Failure |
|---|
| 808 | $err->raise("dom",4,$dom); |
|---|
| 809 | return false; |
|---|
| 810 | } |
|---|
| 811 | if ($dns!="1") $dns="0"; |
|---|
| 812 | // On vérifie que des modifications ont bien eu lieu :) |
|---|
| 813 | if ($r["dns"]==$dns && $r["mx"]==$mx) { |
|---|
| 814 | $err->raise("dom",15); |
|---|
| 815 | return false; |
|---|
| 816 | } |
|---|
| 817 | // MX ? |
|---|
| 818 | if ($mx==$L_MX) |
|---|
| 819 | $gesmx="1"; |
|---|
| 820 | else |
|---|
| 821 | $gesmx="0"; |
|---|
| 822 | |
|---|
| 823 | //si gestion mx uniquement, vérification du dns externe |
|---|
| 824 | if ($dns=="0" && $gesmx=="1") { |
|---|
| 825 | $vmx = checkmx($dom,$mx) |
|---|
| 826 | if ($vmx == 1) { |
|---|
| 827 | //aucun champ mx de spécifié sur le dns |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | if ($vmx == 2) { |
|---|
| 831 | //serveur non spécifié parmi les champx mx |
|---|
| 832 | } |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| 835 | // OK, des modifs ont été faites, on valide : |
|---|
| 836 | // DEPENDANCE : |
|---|
| 837 | if ($gesmx && !$r["mail"]) { // on a associé le MX : on cree donc l'entree dans LDAP |
|---|
| 838 | // Lancement de add_dom sur les classes domain_sensitive : |
|---|
| 839 | foreach($classes as $c) { |
|---|
| 840 | if (method_exists($GLOBALS[$c],"alternc_add_mx_domain")) { |
|---|
| 841 | $GLOBALS[$c]->alternc_add_mx_domain($dom); |
|---|
| 842 | } |
|---|
| 843 | } |
|---|
| 844 | } |
|---|
| 845 | |
|---|
| 846 | if (!$gesmx && $r["mail"]) { // on a dissocié le MX : on détruit donc l'entree dans LDAP |
|---|
| 847 | // Lancement de del_dom sur les classes domain_sensitive : |
|---|
| 848 | foreach($classes as $c) { |
|---|
| 849 | if (method_exists($GLOBALS[$c],"alternc_del_mx_domain")) { |
|---|
| 850 | $GLOBALS[$c]->alternc_del_mx_domain($dom); |
|---|
| 851 | } |
|---|
| 852 | } |
|---|
| 853 | } |
|---|
| 854 | |
|---|
| 855 | $db->query("update domaines set gesdns='$dns', mx='$mx', gesmx='$gesmx' where domaine='$dom'"); |
|---|
| 856 | $db->query("insert into domaines_standby (compte,domaine,mx,gesdns,gesmx,action) values ('$cuid','$dom','$mx','$dns','$gesmx',1);"); |
|---|
| 857 | // UPDATE |
|---|
| 858 | return true; |
|---|
| 859 | } // edit_domain |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | /****************************/ |
|---|
| 864 | /* Slave dns ip managment */ |
|---|
| 865 | /****************************/ |
|---|
| 866 | /* ----------------------------------------------------------------- */ |
|---|
| 867 | /** |
|---|
| 868 | * Return the list of ip addresses and classes that are allowed access to domain list |
|---|
| 869 | * through AXFR Transfers from the bind server. |
|---|
| 870 | */ |
|---|
| 871 | function enum_slave_ip() { |
|---|
| 872 | global $db,$err; |
|---|
| 873 | $db->query("SELECT * FROM slaveip;"); |
|---|
| 874 | if (!$db->next_record()) { |
|---|
| 875 | return false; |
|---|
| 876 | } |
|---|
| 877 | do { |
|---|
| 878 | $res[]=$db->Record; |
|---|
| 879 | } while ($db->next_record()); |
|---|
| 880 | return $res; |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | /* ----------------------------------------------------------------- */ |
|---|
| 884 | /** |
|---|
| 885 | * Add an ip address (or a ip class) to the list of allowed slave ip access list. |
|---|
| 886 | */ |
|---|
| 887 | function add_slave_ip($ip,$class="32") { |
|---|
| 888 | global $db,$err; |
|---|
| 889 | if (!checkip($ip)) { |
|---|
| 890 | $err->raise("dom",19); |
|---|
| 891 | return false; |
|---|
| 892 | } |
|---|
| 893 | $class=intval($class); |
|---|
| 894 | if ($class<8 || $class>32) $class=32; |
|---|
| 895 | $db->query("SELECT * FROM slaveip WHERE ip='$ip' AND class='$class';"); |
|---|
| 896 | if ($db->next_record()) { |
|---|
| 897 | $err->raise("err",22); |
|---|
| 898 | return false; |
|---|
| 899 | } |
|---|
| 900 | $db->query("INSERT INTO slaveip (ip,class) VALUES ('$ip','$class');"); |
|---|
| 901 | $f=fopen(SLAVE_FLAG,"w"); |
|---|
| 902 | fputs($f,"yopla"); |
|---|
| 903 | fclose($f); |
|---|
| 904 | return true; |
|---|
| 905 | } |
|---|
| 906 | |
|---|
| 907 | /* ----------------------------------------------------------------- */ |
|---|
| 908 | /** |
|---|
| 909 | * Remove an ip address (or a ip class) from the list of allowed slave ip access list. |
|---|
| 910 | */ |
|---|
| 911 | function del_slave_ip($ip) { |
|---|
| 912 | global $db,$err; |
|---|
| 913 | if (!checkip($ip)) { |
|---|
| 914 | $err->raise("dom",19); |
|---|
| 915 | return false; |
|---|
| 916 | } |
|---|
| 917 | $db->query("DELETE FROM slaveip WHERE ip='$ip'"); |
|---|
| 918 | $f=fopen(SLAVE_FLAG,"w"); |
|---|
| 919 | fputs($f,"yopla"); |
|---|
| 920 | fclose($f); |
|---|
| 921 | return true; |
|---|
| 922 | } |
|---|
| 923 | |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | /* ----------------------------------------------------------------- */ |
|---|
| 927 | /** |
|---|
| 928 | * Check for a slave account |
|---|
| 929 | */ |
|---|
| 930 | function check_slave_account($login,$pass) { |
|---|
| 931 | global $db,$err; |
|---|
| 932 | $db->query("SELECT * FROM slaveaccount WHERE login='$login' AND pass='$pass';"); |
|---|
| 933 | if ($db->next_record()) { |
|---|
| 934 | return true; |
|---|
| 935 | } |
|---|
| 936 | return false; |
|---|
| 937 | } |
|---|
| 938 | |
|---|
| 939 | /* ----------------------------------------------------------------- */ |
|---|
| 940 | /** |
|---|
| 941 | * Out (echo) the complete hosted domain list : |
|---|
| 942 | */ |
|---|
| 943 | function echo_domain_list() { |
|---|
| 944 | global $db,$err; |
|---|
| 945 | $db->query("SELECT domaine FROM domaines WHERE gesdns=1 ORDER BY domaine"); |
|---|
| 946 | while ($db->next_record()) { |
|---|
| 947 | echo $db->f("domaine")."\n"; |
|---|
| 948 | } |
|---|
| 949 | return true; |
|---|
| 950 | } |
|---|
| 951 | |
|---|
| 952 | /* ----------------------------------------------------------------- */ |
|---|
| 953 | /** |
|---|
| 954 | * Return the list of allowed slave accounts |
|---|
| 955 | */ |
|---|
| 956 | function enum_slave_account() { |
|---|
| 957 | global $db,$err; |
|---|
| 958 | $db->query("SELECT * FROM slaveaccount;"); |
|---|
| 959 | $res=array(); |
|---|
| 960 | while ($db->next_record()) { |
|---|
| 961 | $res[]=$db->Record; |
|---|
| 962 | } |
|---|
| 963 | if (!count($res)) return false; |
|---|
| 964 | return $res; |
|---|
| 965 | } |
|---|
| 966 | |
|---|
| 967 | /* ----------------------------------------------------------------- */ |
|---|
| 968 | /** |
|---|
| 969 | * Add a slave account that will be allowed to access the domain list |
|---|
| 970 | */ |
|---|
| 971 | function add_slave_account($login,$pass) { |
|---|
| 972 | global $db,$err; |
|---|
| 973 | $db->query("SELECT * FROM slaveaccount WHERE login='$login'"); |
|---|
| 974 | if ($db->next_record()) { |
|---|
| 975 | $err->raise("err",23); |
|---|
| 976 | return false; |
|---|
| 977 | } |
|---|
| 978 | $db->query("INSERT INTO slaveaccount (login,pass) VALUES ('$login','$pass')"); |
|---|
| 979 | return true; |
|---|
| 980 | } |
|---|
| 981 | |
|---|
| 982 | /* ----------------------------------------------------------------- */ |
|---|
| 983 | /** |
|---|
| 984 | * Remove a slave account |
|---|
| 985 | */ |
|---|
| 986 | function del_slave_account($login) { |
|---|
| 987 | global $db,$err; |
|---|
| 988 | $db->query("DELETE FROM slaveaccount WHERE login='$login'"); |
|---|
| 989 | return true; |
|---|
| 990 | } |
|---|
| 991 | |
|---|
| 992 | /*************/ |
|---|
| 993 | /* Private */ |
|---|
| 994 | /*************/ |
|---|
| 995 | |
|---|
| 996 | |
|---|
| 997 | /* ----------------------------------------------------------------- */ |
|---|
| 998 | /** |
|---|
| 999 | * Lock tente de verrouiller le fichier lock du cron. Si tout va bien (toujours?) |
|---|
| 1000 | * retourne True, sinon retourne False |
|---|
| 1001 | * NOTE : le systeme de lock est asymétrique, si on a un fichier CRONLOCK, on |
|---|
| 1002 | * attends (que le cron ait fini son execution). |
|---|
| 1003 | * @access private |
|---|
| 1004 | */ |
|---|
| 1005 | function lock() { |
|---|
| 1006 | global $db,$err; |
|---|
| 1007 | $err->log("dom","lock"); |
|---|
| 1008 | if ($this->islocked) { |
|---|
| 1009 | $err->raise("dom",17); |
|---|
| 1010 | } |
|---|
| 1011 | while (file_exists($this->fic_lock_cron)) { |
|---|
| 1012 | sleep(2); |
|---|
| 1013 | } |
|---|
| 1014 | $this->islocked=true; |
|---|
| 1015 | return true; |
|---|
| 1016 | } |
|---|
| 1017 | |
|---|
| 1018 | /* ----------------------------------------------------------------- */ |
|---|
| 1019 | /** |
|---|
| 1020 | * unlock déverrouille le fichier lock du cron. Si tout va bien (toujours?) |
|---|
| 1021 | * retourne True, sinon retourne False |
|---|
| 1022 | * NOTE : actuellement, vu le système de lock asymetrique, on ne fait rien ;) |
|---|
| 1023 | * @access private |
|---|
| 1024 | */ |
|---|
| 1025 | function unlock() { |
|---|
| 1026 | global $db,$err; |
|---|
| 1027 | $err->log("dom","unlock"); |
|---|
| 1028 | if (!$this->islocked) { |
|---|
| 1029 | $err->raise("dom",3); |
|---|
| 1030 | } |
|---|
| 1031 | $this->islocked=false; |
|---|
| 1032 | return true; |
|---|
| 1033 | } |
|---|
| 1034 | |
|---|
| 1035 | /* ----------------------------------------------------------------- */ |
|---|
| 1036 | /** |
|---|
| 1037 | * Efface un compte (tous ses domaines) |
|---|
| 1038 | */ |
|---|
| 1039 | function alternc_del_member() { |
|---|
| 1040 | global $err; |
|---|
| 1041 | $err->log("dom","alternc_del_member"); |
|---|
| 1042 | $li=$this->enum_domains(); |
|---|
| 1043 | foreach($li as $dom) { |
|---|
| 1044 | $this->del_domain($dom); |
|---|
| 1045 | } |
|---|
| 1046 | return true; |
|---|
| 1047 | } |
|---|
| 1048 | |
|---|
| 1049 | /* ----------------------------------------------------------------- */ |
|---|
| 1050 | /** |
|---|
| 1051 | * Returns the used quota for the $name service for the current user. |
|---|
| 1052 | * @param $name string name of the quota |
|---|
| 1053 | * @return integer the number of service used or false if an error occured |
|---|
| 1054 | * @access private |
|---|
| 1055 | */ |
|---|
| 1056 | function alternc_get_quota($name) { |
|---|
| 1057 | global $db,$err,$cuid; |
|---|
| 1058 | if ($name=="dom") { |
|---|
| 1059 | $err->log("dom","get_quota"); |
|---|
| 1060 | $db->query("SELECT COUNT(*) AS cnt FROM domaines WHERE compte='$cuid'"); |
|---|
| 1061 | $db->next_record(); |
|---|
| 1062 | return $db->f("cnt"); |
|---|
| 1063 | } else return false; |
|---|
| 1064 | } |
|---|
| 1065 | |
|---|
| 1066 | |
|---|
| 1067 | /* ----------------------------------------------------------------- */ |
|---|
| 1068 | /** |
|---|
| 1069 | * Exporte toutes les informations domaine du compte. |
|---|
| 1070 | * @access private |
|---|
| 1071 | * EXPERIMENTAL 'sid' function ;) |
|---|
| 1072 | */ |
|---|
| 1073 | function alternc_export() { |
|---|
| 1074 | global $db,$err; |
|---|
| 1075 | $err->log("dom","export"); |
|---|
| 1076 | $this->enum_domains(); |
|---|
| 1077 | $str="<dom>\n"; |
|---|
| 1078 | foreach ($this->domains as $d) { |
|---|
| 1079 | $str.=" <domain>\n <name>".xml_entities($d)."</name>\n"; |
|---|
| 1080 | $s=$this->get_domain_all($d); |
|---|
| 1081 | $str.=" <hasdns>".xml_entities($s[dns])."</hasdns>\n"; |
|---|
| 1082 | $str.=" <hasmx>".xml_entities($s[mx])."</hasmx>\n"; |
|---|
| 1083 | $str.=" <mx>".xml_entities($s[mail])."</mx>\n"; |
|---|
| 1084 | if (is_array($s[sub])) { |
|---|
| 1085 | foreach ($s[sub] as $sub) { |
|---|
| 1086 | $str.=" <subdomain>"; |
|---|
| 1087 | $str.="<name>".xml_entities($sub[name])."</name>"; |
|---|
| 1088 | $str.="<dest>".xml_entities($sub[dest])."</dest>"; |
|---|
| 1089 | $str.="<type>".xml_entities($sub[type])."</type>"; |
|---|
| 1090 | $str.="</subdomain>\n"; |
|---|
| 1091 | } |
|---|
| 1092 | } |
|---|
| 1093 | $str.=" </domain>\n"; |
|---|
| 1094 | } |
|---|
| 1095 | $str.="</dom>\n"; |
|---|
| 1096 | return $str; |
|---|
| 1097 | } |
|---|
| 1098 | |
|---|
| 1099 | |
|---|
| 1100 | } /* Class m_domains */ |
|---|
| 1101 | |
|---|
| 1102 | ?> |
|---|