| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Id: m_admin.php,v 1.16 2006/02/09 20:12:22 benjamin Exp $ |
|---|
| 4 | ---------------------------------------------------------------------- |
|---|
| 5 | AlternC - Web Hosting System |
|---|
| 6 | Copyright (C) 2006 Le réseau Koumbit Inc. |
|---|
| 7 | http://koumbit.org/ |
|---|
| 8 | ---------------------------------------------------------------------- |
|---|
| 9 | LICENSE |
|---|
| 10 | |
|---|
| 11 | This program is free software; you can redistribute it and/or |
|---|
| 12 | modify it under the terms of the GNU General Public License (GPL) |
|---|
| 13 | as published by the Free Software Foundation; either version 2 |
|---|
| 14 | of the License, or (at your option) any later version. |
|---|
| 15 | |
|---|
| 16 | This program is distributed in the hope that it will be useful, |
|---|
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | GNU General Public License for more details. |
|---|
| 20 | |
|---|
| 21 | To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|---|
| 22 | ---------------------------------------------------------------------- |
|---|
| 23 | Original Author of file: Benjamin Sonntag |
|---|
| 24 | Purpose of file: Administrate members and rights. |
|---|
| 25 | ---------------------------------------------------------------------- |
|---|
| 26 | */ |
|---|
| 27 | /* ----------------------------------------------------------------- */ |
|---|
| 28 | /** |
|---|
| 29 | * Classe de gestion de l'administration du serveur par les super-admin. |
|---|
| 30 | * |
|---|
| 31 | * Cette classe permet de créer / modifier / détruire les comptes, ainsi que de |
|---|
| 32 | * modifier les paramètres du serveur.<br /> |
|---|
| 33 | * Copyleft {@link http://alternc.net/ AlternC Team} |
|---|
| 34 | * |
|---|
| 35 | * |
|---|
| 36 | */ |
|---|
| 37 | class m_admin { |
|---|
| 38 | |
|---|
| 39 | /* ----------------------------------------------------------------- */ |
|---|
| 40 | /** |
|---|
| 41 | * $enabled precises if the logged user is super-admin or not |
|---|
| 42 | */ |
|---|
| 43 | var $enabled=0; |
|---|
| 44 | |
|---|
| 45 | /* ----------------------------------------------------------------- */ |
|---|
| 46 | /** List of the controls made for each TLD |
|---|
| 47 | * |
|---|
| 48 | * $tldmode is used by the administration panel, while choosing |
|---|
| 49 | * the authorized TLDs. It's an array of strings explaining the current state of the TLD. |
|---|
| 50 | */ |
|---|
| 51 | |
|---|
| 52 | var $tldmode=array( |
|---|
| 53 | 0 => "This TLD is forbidden", |
|---|
| 54 | 1 => "primary DNS is checked in WHOIS db", |
|---|
| 55 | 2 => "primary & secondary DNS are checked in WHOIS db", |
|---|
| 56 | 3 => "Domain must exist, but don't do any DNS check", |
|---|
| 57 | 4 => "Domain can be installed, no check at all", |
|---|
| 58 | 5 => "Domain can be installed, force NO DNS hosting" |
|---|
| 59 | ); |
|---|
| 60 | |
|---|
| 61 | /* ----------------------------------------------------------------- */ |
|---|
| 62 | /** |
|---|
| 63 | * Constructeur |
|---|
| 64 | */ |
|---|
| 65 | function m_admin() { |
|---|
| 66 | global $db,$cuid; |
|---|
| 67 | $db->query("SELECT su FROM membres WHERE uid='$cuid';"); |
|---|
| 68 | $db->next_record(); |
|---|
| 69 | $this->enabled=$db->f("su"); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | /* ----------------------------------------------------------------- */ |
|---|
| 73 | /** |
|---|
| 74 | * Returns the known information about a hosted account |
|---|
| 75 | * |
|---|
| 76 | * Returns all what we know about an account (contents of the tables |
|---|
| 77 | * <code>membres</code> et <code>local</code>) |
|---|
| 78 | * Ckecks if the account is super-admin |
|---|
| 79 | * @param integer $uid a unique integer identifying the account |
|---|
| 80 | * @return an associative array containing all the fields of the |
|---|
| 81 | * table <code>membres</code> and <code>local</code> of the corresponding account. |
|---|
| 82 | * Returns FALSE if an error occurs. |
|---|
| 83 | * |
|---|
| 84 | * Retourne tout ce que l'on sait sur un membre (contenu des tables <code>membres et local</code>) |
|---|
| 85 | * vérifie que le compte appelant est super-admin |
|---|
| 86 | * @param integer $uid Numéro de l'utilisateur dont on veut les informations. |
|---|
| 87 | * @return array Retourne un tableau associatif contenant l'ensemble des champs des tables 'membres' |
|---|
| 88 | * et 'local' pour le membre demandé. Retourne FALSE si une erreur s'est produite. |
|---|
| 89 | * |
|---|
| 90 | */ |
|---|
| 91 | function get($uid) { |
|---|
| 92 | global $err,$db; |
|---|
| 93 | // $err->log("admin","get",$uid); |
|---|
| 94 | if (!$this->enabled) { |
|---|
| 95 | $err->raise("admin",1); |
|---|
| 96 | return false; |
|---|
| 97 | } |
|---|
| 98 | $db->query("SELECT * FROM membres WHERE uid='$uid';"); |
|---|
| 99 | if ($db->num_rows()) { |
|---|
| 100 | $db->next_record(); |
|---|
| 101 | $c=$db->Record; |
|---|
| 102 | } else { |
|---|
| 103 | $err->raise("admin",2); |
|---|
| 104 | return false; |
|---|
| 105 | } |
|---|
| 106 | $db->query("SELECT * FROM local WHERE uid='$uid';"); |
|---|
| 107 | if ($db->num_rows()) { |
|---|
| 108 | $db->next_record(); |
|---|
| 109 | reset($db->Record); |
|---|
| 110 | while (list($key,$val)=each($db->Record)) { |
|---|
| 111 | $c[$key]=$val; |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | return $c; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /* ----------------------------------------------------------------- */ |
|---|
| 118 | /** |
|---|
| 119 | * @return TRUE if there's only ONE admin account |
|---|
| 120 | * Retourne true s'il n'existe qu'un seul compte administrateur |
|---|
| 121 | */ |
|---|
| 122 | function onesu() { |
|---|
| 123 | global $db; |
|---|
| 124 | $db->query("SELECT COUNT(*) AS cnt FROM membres WHERE su=1"); |
|---|
| 125 | $db->next_record(); |
|---|
| 126 | return ($db->f("cnt")==1); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | /* ----------------------------------------------------------------- */ |
|---|
| 130 | /** |
|---|
| 131 | * Returns the list of the hosted accounts |
|---|
| 132 | * Retourne la liste des membres hébergés |
|---|
| 133 | * |
|---|
| 134 | * Returns all what we know about ALL the accounts (contents of the tables |
|---|
| 135 | * <code>membres</code> et <code>local</code>) |
|---|
| 136 | * Check for super-admin accounts |
|---|
| 137 | * @param |
|---|
| 138 | * @return an associative array containing all the fields of the |
|---|
| 139 | * table <code>membres</code> and <code>local</code> of all the accounts. |
|---|
| 140 | * Returns FALSE if an error occurs. |
|---|
| 141 | * |
|---|
| 142 | * Retourne tout ce que l'on sait sur LES membres (contenu de membres et local) |
|---|
| 143 | * vérifie que le compte appelant est super-admin |
|---|
| 144 | * @return array Retourne un tableau indexé de tableaux associatifs contenant l'ensemble des |
|---|
| 145 | * champs des tables 'membres' et 'local' pour les membre. Retourne FALSE si une erreur s'est |
|---|
| 146 | * produite. |
|---|
| 147 | * |
|---|
| 148 | */ |
|---|
| 149 | function get_list($all=0) { |
|---|
| 150 | // PATCHBEN pour ne voir que les comptes que l'on a créé (sauf root) |
|---|
| 151 | global $err,$mem,$cuid; |
|---|
| 152 | $err->log("admin","get_list"); |
|---|
| 153 | if (!$this->enabled) { |
|---|
| 154 | $err->raise("admin",1); |
|---|
| 155 | return false; |
|---|
| 156 | } |
|---|
| 157 | $db=new DB_System(); |
|---|
| 158 | if ($mem->user[uid]==2000 || $all) { |
|---|
| 159 | $db->query("SELECT uid FROM membres ORDER BY login;"); |
|---|
| 160 | } else { |
|---|
| 161 | $db->query("SELECT uid FROM membres WHERE creator='".$cuid."' ORDER BY login;"); |
|---|
| 162 | } |
|---|
| 163 | if ($db->num_rows()) { |
|---|
| 164 | while ($db->next_record()) { |
|---|
| 165 | $c[]=$this->get($db->f("uid")); |
|---|
| 166 | } |
|---|
| 167 | return $c; |
|---|
| 168 | } else { |
|---|
| 169 | $err->raise("admin",3); |
|---|
| 170 | return false; |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | /* ----------------------------------------------------------------- */ |
|---|
| 175 | /** |
|---|
| 176 | * Check if I am the creator of the member $uid |
|---|
| 177 | * |
|---|
| 178 | * @param integer $uid a unique integer identifying the account |
|---|
| 179 | */ |
|---|
| 180 | function checkcreator($uid) { |
|---|
| 181 | global $err,$mem,$db,$cuid; |
|---|
| 182 | // DONE PATCHBEN Check that the current user is editing one of it's own account ! |
|---|
| 183 | // but ROOT (always uid 2000) is almighty |
|---|
| 184 | if ($cuid==2000) { |
|---|
| 185 | return true; |
|---|
| 186 | } |
|---|
| 187 | $db->query("SELECT creator FROM membres WHERE uid='$uid';"); |
|---|
| 188 | $db->next_record(); |
|---|
| 189 | if ($db->Record[creator]!=$cuid) { |
|---|
| 190 | $err->raise("admin",1); |
|---|
| 191 | return false; |
|---|
| 192 | } |
|---|
| 193 | return true; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | /* ----------------------------------------------------------------- */ |
|---|
| 197 | /** |
|---|
| 198 | * Creates a new hosted account |
|---|
| 199 | * |
|---|
| 200 | * Creates a new hosted account (in the tables <code>membres</code> |
|---|
| 201 | * and <code>local</code>). Prevents any manipulation of the account if |
|---|
| 202 | * the account $mid is not super-admin. |
|---|
| 203 | * |
|---|
| 204 | * @param $login string Login name like [a-z][a-z0-9]* |
|---|
| 205 | * @param $pass string Password (max. 64 characters) |
|---|
| 206 | * @param $nom string Name of the account owner |
|---|
| 207 | * @param $prenom string First name of the account owner |
|---|
| 208 | * @param $mail string Email address of the account owner, useful to get |
|---|
| 209 | * one's lost password |
|---|
| 210 | * @pararm $type string Account type for quotas |
|---|
| 211 | * @return boolean Returns FALSE if an error occurs, TRUE if not. |
|---|
| 212 | * |
|---|
| 213 | * |
|---|
| 214 | * Crée un nouveau membre hébergé |
|---|
| 215 | * Création d'un nouveau membre (dans membres et local) Refuse l'utilisation de l'objet |
|---|
| 216 | * si le compte $mid n'est pas super-admin |
|---|
| 217 | * |
|---|
| 218 | * @param $login Nom d'utilisateur, de la forme [a-z][a-z0-9]* |
|---|
| 219 | * @param $pass Mot de passe, maxi 64 caractères |
|---|
| 220 | * @param $nom Nom de la personne ou structure |
|---|
| 221 | * @param $prenom Prénom de la personne ou structure |
|---|
| 222 | * @param $mail Adresse email du propriétaire du compte, permet de récupérer son mot de passe |
|---|
| 223 | * @param $type Type de compte pour les quotas |
|---|
| 224 | * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. |
|---|
| 225 | * |
|---|
| 226 | */ |
|---|
| 227 | function add_mem($login, $pass, $nom, $prenom, $mail, $canpass=1, $type='default') { |
|---|
| 228 | global $err,$quota,$classes,$cuid,$mem,$L_MYSQL_DATABASE,$L_MYSQL_LOGIN; |
|---|
| 229 | $err->log("admin","add_mem",$login."/".$mail); |
|---|
| 230 | if (!$this->enabled) { |
|---|
| 231 | $err->raise("admin",1); |
|---|
| 232 | return false; |
|---|
| 233 | } |
|---|
| 234 | if (($login=="")||($pass=="")||($mail=="")){ |
|---|
| 235 | $err->raise("admin",6); |
|---|
| 236 | return false; |
|---|
| 237 | } |
|---|
| 238 | if (checkmail($mail)!=0){ |
|---|
| 239 | $err->raise("admin",5); |
|---|
| 240 | return false; |
|---|
| 241 | } |
|---|
| 242 | // Vérification de la conformité du login |
|---|
| 243 | $login=strtolower($login); |
|---|
| 244 | if (!ereg("^[a-z0-9]*$",$login)) { //$ |
|---|
| 245 | $err->raise("admin",10); |
|---|
| 246 | return false; |
|---|
| 247 | } |
|---|
| 248 | if (strlen($login) > 16) { |
|---|
| 249 | $err->raise("admin",13); |
|---|
| 250 | return false; |
|---|
| 251 | } |
|---|
| 252 | // Il ne peut pas être égal au login ou au nom de base systeme ! |
|---|
| 253 | if ($login==$L_MYSQL_DATABASE || $login==$L_MYSQL_LOGIN) { |
|---|
| 254 | $err->raise("admin",10); |
|---|
| 255 | return false; |
|---|
| 256 | } |
|---|
| 257 | $pass=_md5cr($pass); |
|---|
| 258 | $db=new DB_System(); |
|---|
| 259 | // vérification de l'inexistence du membre dans system.membres |
|---|
| 260 | $db->query("SELECT count(*) AS cnt FROM membres WHERE login='$login';"); |
|---|
| 261 | $db->next_record(); |
|---|
| 262 | if (!$db->f("cnt")) { |
|---|
| 263 | $db->query("SELECT m.uid+1 as nextid FROM membres m LEFT JOIN membres n ON m.uid=n.uid-1 WHERE n.uid IS NULL ORDER BY 1 LIMIT 0,1"); |
|---|
| 264 | if (!$db->next_record()) { |
|---|
| 265 | $uid=2000; |
|---|
| 266 | } else { |
|---|
| 267 | $uid=$db->Record["nextid"]; |
|---|
| 268 | if ($uid<=2000) $uid=2000; |
|---|
| 269 | } |
|---|
| 270 | // on le créé ensuite dans system.membres et system.local |
|---|
| 271 | $db->query("INSERT INTO membres (uid,login,pass,mail,creator,canpass,type) VALUES ('$uid','$login','$pass','$mail','$cuid','$canpass', '$type');"); |
|---|
| 272 | $db->query("INSERT INTO local(uid,nom,prenom) VALUES('$uid','$nom','$prenom');"); |
|---|
| 273 | exec("/usr/lib/alternc/mem_add ".$login." ".$uid); |
|---|
| 274 | // Declenchons les autres classes. |
|---|
| 275 | $mem->su($uid); |
|---|
| 276 | foreach($classes as $c) { |
|---|
| 277 | if (method_exists($GLOBALS[$c],"alternc_add_member")) { |
|---|
| 278 | $GLOBALS[$c]->alternc_add_member(); |
|---|
| 279 | } |
|---|
| 280 | } |
|---|
| 281 | $mem->unsu(); |
|---|
| 282 | return $uid; |
|---|
| 283 | } else { |
|---|
| 284 | $err->raise("admin",3); |
|---|
| 285 | return false; |
|---|
| 286 | } |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | /* ----------------------------------------------------------------- */ |
|---|
| 290 | /** |
|---|
| 291 | * Modifies an account |
|---|
| 292 | * |
|---|
| 293 | * Modifies an account (in the tables <code>membres</code> |
|---|
| 294 | * and <code>local</code>). Prevents any manipulation of the account if |
|---|
| 295 | * the account $mid is not super-admin. |
|---|
| 296 | * |
|---|
| 297 | * @param $uid integer the uid number of the account we want to modify |
|---|
| 298 | * @param login string new login name like [a-z][a-z0-9]* |
|---|
| 299 | * @param $pass string new password (max. 64 characters) |
|---|
| 300 | * @param $nom string new name of the account owner |
|---|
| 301 | * @param $prenom string new first name of the account owner |
|---|
| 302 | * @param $mail string new email address of the account owner |
|---|
| 303 | * @param $enabled integer (value: 0 or 1) activates or desactivates the |
|---|
| 304 | * @param $type string new type of account |
|---|
| 305 | * access to the virtual desktop of this account. |
|---|
| 306 | * @return boolean Returns FALSE if an error occurs, TRUE if not. |
|---|
| 307 | * |
|---|
| 308 | * Modifie un membre hébergé |
|---|
| 309 | * |
|---|
| 310 | * modifie les données d'un membre. Refuse l'utilisation de l'objet |
|---|
| 311 | * si le compte $mid n'est pas super-admin |
|---|
| 312 | * |
|---|
| 313 | * @param $uid integer Numéro uid de l'utilisateur que l'on souhaite modifier. |
|---|
| 314 | * @param $mail string Nouvelle adresse email |
|---|
| 315 | * @param $nom $prenom string Nouveaux nom et prénom de l'utilisateur |
|---|
| 316 | * @param $pass string Nouveau mot de passe. |
|---|
| 317 | * @param $enabled integer vaut 0 ou 1, active ou désactive l'accès au bureau virtuel de ce compte. |
|---|
| 318 | * @param $type string Nouveau type de compte |
|---|
| 319 | * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. |
|---|
| 320 | * |
|---|
| 321 | */ |
|---|
| 322 | function update_mem($uid, $mail, $nom, $prenom, $pass, $enabled, $canpass, $type, $type='default') { |
|---|
| 323 | global $err,$db; |
|---|
| 324 | global $cuid, $quota; |
|---|
| 325 | |
|---|
| 326 | $cuid = $uid; |
|---|
| 327 | $err->log("admin","update_mem",$uid); |
|---|
| 328 | if (!$this->enabled) { |
|---|
| 329 | $err->raise("admin",1); |
|---|
| 330 | return false; |
|---|
| 331 | } |
|---|
| 332 | $db=new DB_System(); |
|---|
| 333 | if ($pass) { |
|---|
| 334 | // on modifie aussi le password : |
|---|
| 335 | $pass=_md5cr($pass); |
|---|
| 336 | $ssq=" ,pass='$pass' "; |
|---|
| 337 | } else { |
|---|
| 338 | $ssq=""; |
|---|
| 339 | } |
|---|
| 340 | if (($db->query("UPDATE local SET nom='$nom', prenom='$prenom' WHERE uid='$uid';")) |
|---|
| 341 | &&($db->query("UPDATE membres SET mail='$mail', canpass='$canpass', enabled='$enabled', type='$type' $ssq WHERE uid='$uid';"))){ |
|---|
| 342 | if($_POST['reset_quotas'] == "on") |
|---|
| 343 | $quota->addquotas(); |
|---|
| 344 | return true; |
|---|
| 345 | } |
|---|
| 346 | else { |
|---|
| 347 | $err->raise("admin",2); |
|---|
| 348 | return false; |
|---|
| 349 | } |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | /* ----------------------------------------------------------------- */ |
|---|
| 353 | /** |
|---|
| 354 | * Lock an account |
|---|
| 355 | * |
|---|
| 356 | * Lock an account and prevent the user to access its account. |
|---|
| 357 | * |
|---|
| 358 | * @param $uid integer the uid number of the account we want to lock |
|---|
| 359 | * @return boolean Returns FALSE if an error occurs, TRUE if not. |
|---|
| 360 | */ |
|---|
| 361 | function lock_mem($uid) { |
|---|
| 362 | global $err,$db; |
|---|
| 363 | $err->log("admin","lock_mem",$uid); |
|---|
| 364 | if (!$this->enabled) { |
|---|
| 365 | $err->raise("admin",1); |
|---|
| 366 | return false; |
|---|
| 367 | } |
|---|
| 368 | $db=new DB_System(); |
|---|
| 369 | if ($db->query("UPDATE membres SET enabled='0' WHERE uid='$uid';")) { |
|---|
| 370 | return true; |
|---|
| 371 | } |
|---|
| 372 | else { |
|---|
| 373 | $err->raise("admin",2); |
|---|
| 374 | return false; |
|---|
| 375 | } |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | /* ----------------------------------------------------------------- */ |
|---|
| 380 | /** |
|---|
| 381 | * UnLock an account |
|---|
| 382 | * |
|---|
| 383 | * UnLock an account and prevent the user to access its account. |
|---|
| 384 | * |
|---|
| 385 | * @param $uid integer the uid number of the account we want to unlock |
|---|
| 386 | * @return boolean Returns FALSE if an error occurs, TRUE if not. |
|---|
| 387 | */ |
|---|
| 388 | function unlock_mem($uid) { |
|---|
| 389 | global $err,$db; |
|---|
| 390 | $err->log("admin","unlock_mem",$uid); |
|---|
| 391 | if (!$this->enabled) { |
|---|
| 392 | $err->raise("admin",1); |
|---|
| 393 | return false; |
|---|
| 394 | } |
|---|
| 395 | $db=new DB_System(); |
|---|
| 396 | if ($db->query("UPDATE membres SET enabled='1' WHERE uid='$uid';")) { |
|---|
| 397 | return true; |
|---|
| 398 | } |
|---|
| 399 | else { |
|---|
| 400 | $err->raise("admin",2); |
|---|
| 401 | return false; |
|---|
| 402 | } |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | /* ----------------------------------------------------------------- */ |
|---|
| 408 | /** |
|---|
| 409 | * Deletes an account |
|---|
| 410 | * |
|---|
| 411 | * Deletes the specified account. Prevents any manipulation of the account if |
|---|
| 412 | * the account $mid is not super-admin. |
|---|
| 413 | * |
|---|
| 414 | * @param $uid integer the uid number of the account we want to delete |
|---|
| 415 | * @return boolean Returns FALSE if an error occurs, TRUE if not. |
|---|
| 416 | * |
|---|
| 417 | * |
|---|
| 418 | * Efface un membre hébergé |
|---|
| 419 | * |
|---|
| 420 | * Supprime le membre spécifié. Refuse l'utilisation de l'objet si le compte $mid n'est pas super-admin |
|---|
| 421 | * @param $uid Numéro du membre à supprimer. |
|---|
| 422 | * @return Retourne FALSE si une erreur s'est produite, TRUE sinon. |
|---|
| 423 | * |
|---|
| 424 | */ |
|---|
| 425 | function del_mem($uid) { |
|---|
| 426 | global $err,$quota,$classes,$cuid,$mem,$dom; |
|---|
| 427 | $err->log("admin","del_mem",$uid); |
|---|
| 428 | |
|---|
| 429 | if (!$this->enabled) { |
|---|
| 430 | $err->raise("admin",1); |
|---|
| 431 | return false; |
|---|
| 432 | } |
|---|
| 433 | $db=new DB_System(); |
|---|
| 434 | $tt=$this->get($uid); |
|---|
| 435 | |
|---|
| 436 | // On devient l'utilisateur : |
|---|
| 437 | $mem->su($uid); |
|---|
| 438 | |
|---|
| 439 | // WE MUST call m_dom before all others because of conflicts ... |
|---|
| 440 | $dom->alternc_del_member(); |
|---|
| 441 | |
|---|
| 442 | // Send the event to the other classes : |
|---|
| 443 | foreach($classes as $c) { |
|---|
| 444 | if (method_exists($GLOBALS[$c],"alternc_del_member")) { |
|---|
| 445 | $GLOBALS[$c]->alternc_del_member(); |
|---|
| 446 | } |
|---|
| 447 | } |
|---|
| 448 | if (($db->query("DELETE FROM membres WHERE uid='$uid';")) && |
|---|
| 449 | ($db->query("DELETE FROM local WHERE uid='$uid';"))) { |
|---|
| 450 | exec("/usr/lib/alternc/mem_del ".$tt["login"]); |
|---|
| 451 | $mem->unsu(); |
|---|
| 452 | return true; |
|---|
| 453 | } else { |
|---|
| 454 | $err->raise("admin",2); |
|---|
| 455 | $mem->unsu(); |
|---|
| 456 | return false; |
|---|
| 457 | } |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | /* ----------------------------------------------------------------- */ |
|---|
| 461 | /** |
|---|
| 462 | * Turns a common account into a super-admin account |
|---|
| 463 | * |
|---|
| 464 | * @param $uid integer the uid number of the common account we want to turn into a |
|---|
| 465 | * super-admin account. |
|---|
| 466 | * @return Returns FALSE if an error occurs, TRUE if not. |
|---|
| 467 | * |
|---|
| 468 | * |
|---|
| 469 | * Transforme un membre Normal en membre Administrateur |
|---|
| 470 | * |
|---|
| 471 | * @param $uid Numéro du compte à transformer |
|---|
| 472 | * @return Retourne FALSE si une erreur s'est produite. |
|---|
| 473 | * |
|---|
| 474 | */ |
|---|
| 475 | function normal2su($uid) { |
|---|
| 476 | global $err,$db; |
|---|
| 477 | $db->query("SELECT su FROM membres WHERE uid='$uid';"); |
|---|
| 478 | if (!$db->next_record()) { |
|---|
| 479 | $err->raise("admin",2); |
|---|
| 480 | return false; |
|---|
| 481 | } |
|---|
| 482 | if ($db->Record["su"]!=0) { |
|---|
| 483 | $err->raise("admin",8); |
|---|
| 484 | return false; |
|---|
| 485 | } |
|---|
| 486 | $db->query("UPDATE membres SET su=1 WHERE uid='$uid';"); |
|---|
| 487 | return true; |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | /* ----------------------------------------------------------------- */ |
|---|
| 491 | /** |
|---|
| 492 | * Turns a super-admin account into a common account |
|---|
| 493 | * |
|---|
| 494 | * @param $uid integer the uid number of the super-admin account we want to turn into a |
|---|
| 495 | * common account. |
|---|
| 496 | * @return boolean Returns FALSE if an error occurs, TRUE if not. |
|---|
| 497 | * |
|---|
| 498 | * |
|---|
| 499 | * Transforme un membre Administrateur en membre Normal |
|---|
| 500 | * @param integer $uid Numéro du compte à transformer |
|---|
| 501 | * @return boolean Retourne FALSE si une erreur s'est produite. |
|---|
| 502 | * |
|---|
| 503 | */ |
|---|
| 504 | function su2normal($uid) { |
|---|
| 505 | global $err,$db; |
|---|
| 506 | $db->query("SELECT su FROM membres WHERE uid='$uid';"); |
|---|
| 507 | if (!$db->next_record()) { |
|---|
| 508 | $err->raise("admin",2); |
|---|
| 509 | return false; |
|---|
| 510 | } |
|---|
| 511 | if ($db->Record["su"]!=1) { |
|---|
| 512 | $err->raise("admin",9); |
|---|
| 513 | return false; |
|---|
| 514 | } |
|---|
| 515 | $db->query("UPDATE membres SET su=0 WHERE uid='$uid';"); |
|---|
| 516 | return true; |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | /* ----------------------------------------------------------------- */ |
|---|
| 520 | /** |
|---|
| 521 | * List of the authorized TLDs |
|---|
| 522 | * |
|---|
| 523 | * Returns the list of the authorized TLDs and also the way they are |
|---|
| 524 | * authorized. A TLD is the last members (or the last two) of a |
|---|
| 525 | * domain. For example, "com", "org" etc... AlternC keeps a table |
|---|
| 526 | * containing the list of the TLDs authorized to be installed on the |
|---|
| 527 | * server with the instructions to validate the installation of a |
|---|
| 528 | * domain for each TLD (if necessary). |
|---|
| 529 | * |
|---|
| 530 | * @return array An associative array like $r["tld"], $r["mode"] where tld |
|---|
| 531 | * is the tld and mode is the authorized mode. |
|---|
| 532 | * |
|---|
| 533 | * |
|---|
| 534 | * Liste des TLD autorisés |
|---|
| 535 | * |
|---|
| 536 | * Retourne la liste des tld autorisés, ainsi que la façon dont ils sont autorisés. |
|---|
| 537 | * Les tld sont le dernier membre (ou parfois les 2 derniers membres) d'un domaine. |
|---|
| 538 | * Par exemple "org" "com" etc. AlternC conserve une table "tld" qui contient la liste |
|---|
| 539 | * des TLD autorisés à être installé sur le serveur, accompagné des vérifications à effectuer |
|---|
| 540 | * pour chaque TLD. Par exemple, on peux vérifier que les DNS du domaine pointent bien vers |
|---|
| 541 | * notre serveur, ou juste que le domaine existe etc. |
|---|
| 542 | * <p><b>Note</b> : Il faudrait pouvoir effectuer une requete DNS, et pouvoir juste vérifier les DNS |
|---|
| 543 | * via DIG et pas seulement via Whois</p> |
|---|
| 544 | * |
|---|
| 545 | * @return array Retourne un tableau de tableau associatif du type $r["tld"], $r["mode"]. |
|---|
| 546 | * TLD est le tld et MODE est le mode autorisé |
|---|
| 547 | * |
|---|
| 548 | */ |
|---|
| 549 | function listtld() { |
|---|
| 550 | global $db; |
|---|
| 551 | $db->query("SELECT tld,mode FROM tld ORDER BY tld;"); |
|---|
| 552 | while ($db->next_record()) { |
|---|
| 553 | $c[]=$db->Record; |
|---|
| 554 | } |
|---|
| 555 | return $c; |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | /* ----------------------------------------------------------------- */ |
|---|
| 559 | /** |
|---|
| 560 | * List the hosted domains on this server |
|---|
| 561 | * |
|---|
| 562 | * Return the list of hosted domains on this server, (an array of associative arrays) |
|---|
| 563 | * @return array $r[$i] / [domaine][member][noerase][gesdns][gesmx] |
|---|
| 564 | */ |
|---|
| 565 | function dom_list() { |
|---|
| 566 | global $db; |
|---|
| 567 | $db->query("SELECT m.login,d.domaine,d.gesdns,d.gesmx,d.noerase FROM domaines d LEFT JOIN membres m ON m.uid=d.compte ORDER BY domaine;"); |
|---|
| 568 | while ($db->next_record()) { |
|---|
| 569 | $c[]=$db->Record; |
|---|
| 570 | } |
|---|
| 571 | return $c; |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | /* ----------------------------------------------------------------- */ |
|---|
| 575 | /** |
|---|
| 576 | * Lock / Unlock a domain |
|---|
| 577 | * |
|---|
| 578 | * Lock (or unlock) a domain, so that the member will be (not be) able to delete it |
|---|
| 579 | * from its account |
|---|
| 580 | * @param $dom string Domain name to lock / unlock |
|---|
| 581 | * @return boolean TRUE if the domain has been locked/unlocked or FALSE if it does not exist. |
|---|
| 582 | */ |
|---|
| 583 | function dom_lock($domain) { |
|---|
| 584 | global $db,$err; |
|---|
| 585 | $db->query("SELECT compte FROM domaines WHERE domaine='$domain';"); |
|---|
| 586 | if (!$db->next_record()) { |
|---|
| 587 | $err->raise("dom",1); |
|---|
| 588 | return false; |
|---|
| 589 | } |
|---|
| 590 | $db->query("UPDATE domaines SET noerase=1-noerase WHERE domaine='$domain';"); |
|---|
| 591 | return true; |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | /* ----------------------------------------------------------------- */ |
|---|
| 596 | /** |
|---|
| 597 | * Add a new TLD to the list of the authorized TLDs |
|---|
| 598 | * |
|---|
| 599 | * @param $tld string top-level domain to add (org, com...) |
|---|
| 600 | * @param $mode integer number of the authorized mode (0 to 5) |
|---|
| 601 | * @return boolean TRUE if the tld has been successfully added, FALSE if not. |
|---|
| 602 | * |
|---|
| 603 | * |
|---|
| 604 | * Ajoute un nouveau TLD autorisé à la liste des tld autorisés. |
|---|
| 605 | * |
|---|
| 606 | * @param $tld Top-Level Domain à ajouter (org, com ...) |
|---|
| 607 | * @param $mode Numéro du mode autorisé (0->5) |
|---|
| 608 | * @return boolean True si le tld a bien été ajouté, False sinon. |
|---|
| 609 | * |
|---|
| 610 | */ |
|---|
| 611 | function gettld($tld) { |
|---|
| 612 | global $db,$err; |
|---|
| 613 | $db->query("SELECT mode FROM tld WHERE tld='$tld';"); |
|---|
| 614 | if (!$db->next_record()) { |
|---|
| 615 | $err->raise("admin",11); |
|---|
| 616 | return false; |
|---|
| 617 | } |
|---|
| 618 | return $db->Record["mode"]; |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | /* ----------------------------------------------------------------- */ |
|---|
| 622 | /** |
|---|
| 623 | * Prints the list of the actually authorized TLDs |
|---|
| 624 | * |
|---|
| 625 | * @param $current integer Value to select in the list |
|---|
| 626 | * |
|---|
| 627 | * Affiche (echo) la liste déroulante des TLD actuellement autorisés. |
|---|
| 628 | * |
|---|
| 629 | * @param $current Valeur par défaut à sélectionner dans la liste |
|---|
| 630 | * |
|---|
| 631 | */ |
|---|
| 632 | function selecttldmode($current=false) { |
|---|
| 633 | for($i=0;$i<count($this->tldmode);$i++) { |
|---|
| 634 | echo "<option value=\"$i\""; |
|---|
| 635 | if ($current==$i) echo " selected=\"selected\""; |
|---|
| 636 | echo ">"._($this->tldmode[$i])."</option>\n"; |
|---|
| 637 | } |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | /* ----------------------------------------------------------------- */ |
|---|
| 641 | /** |
|---|
| 642 | * Deletes the specified tld in the list of the authorized TLDs |
|---|
| 643 | * <b>Note</b> : This function does not delete the domains depending |
|---|
| 644 | * on this TLD |
|---|
| 645 | * |
|---|
| 646 | * @param $tld string The TLD you want to delete |
|---|
| 647 | * @return boolean returns true if the TLD has been deleted, or |
|---|
| 648 | * false if an error occured. |
|---|
| 649 | * |
|---|
| 650 | * |
|---|
| 651 | * Supprime le tld indiqué de la liste des TLD autorisés à l'installation |
|---|
| 652 | * |
|---|
| 653 | * <b>Note</b> : Cela ne supprime pas les domaines utilisant ce TLD ! |
|---|
| 654 | * |
|---|
| 655 | * @param $tld TLD que l'on souhaite détruire |
|---|
| 656 | * @return boolean retourne true si le TLD a bien été effacé, false sinon |
|---|
| 657 | * |
|---|
| 658 | */ |
|---|
| 659 | function deltld($tld) { |
|---|
| 660 | global $db,$err; |
|---|
| 661 | $db->query("SELECT tld FROM tld WHERE tld='$tld';"); |
|---|
| 662 | if (!$db->next_record()) { |
|---|
| 663 | $err->raise("admin",11); |
|---|
| 664 | return false; |
|---|
| 665 | } |
|---|
| 666 | $db->query("DELETE FROM tld WHERE tld='$tld';"); |
|---|
| 667 | return true; |
|---|
| 668 | } |
|---|
| 669 | |
|---|
| 670 | /* ----------------------------------------------------------------- */ |
|---|
| 671 | /** |
|---|
| 672 | * Add a TLD to the list of the authorized TLDs during the |
|---|
| 673 | * installation |
|---|
| 674 | * |
|---|
| 675 | * @param $tld string TLD we want to authorize |
|---|
| 676 | * @param $mode integer Controls to make on this TLD. |
|---|
| 677 | * <b>Note: </b> If you check in the whois, be sure that |
|---|
| 678 | * <code>m_domains</code> knows how to name the whois of the specified |
|---|
| 679 | * domain ! |
|---|
| 680 | * @return boolean TRUE if the TLD has been successfully |
|---|
| 681 | * added. FALSE if not. |
|---|
| 682 | * |
|---|
| 683 | * |
|---|
| 684 | * |
|---|
| 685 | * Ajoute un TLD à la liste des TLD autorisés à l'installation |
|---|
| 686 | * |
|---|
| 687 | * @param $tld TLD que l'on souhaite autoriser. |
|---|
| 688 | * @param $mode Contrôles à effectuer sur ce TLD. <b>Note : </b> |
|---|
| 689 | * Si vous demandez le controle dans le Whois, assurez-vous que m_domains |
|---|
| 690 | * connaisse bien comment appeler le whois du domaine correspondant ! |
|---|
| 691 | * @return boolean retourne true si le TLD a bien été ajouté, false sinon |
|---|
| 692 | * |
|---|
| 693 | */ |
|---|
| 694 | function addtld($tld,$mode) { |
|---|
| 695 | global $db,$err; |
|---|
| 696 | if (!$tld) { |
|---|
| 697 | $err->raise("admin",12); |
|---|
| 698 | return false; |
|---|
| 699 | } |
|---|
| 700 | $db->query("SELECT tld FROM tld WHERE tld='$tld';"); |
|---|
| 701 | if ($db->next_record()) { |
|---|
| 702 | $err->raise("admin",12); |
|---|
| 703 | return false; |
|---|
| 704 | } |
|---|
| 705 | if (substr($tld,0,1)==".") $tld=substr($tld,1); |
|---|
| 706 | $mode=intval($mode); |
|---|
| 707 | if ($mode==0) $mode="0"; |
|---|
| 708 | $db->query("INSERT INTO tld (tld,mode) VALUES ('$tld','$mode');"); |
|---|
| 709 | return true; |
|---|
| 710 | } |
|---|
| 711 | |
|---|
| 712 | /* ----------------------------------------------------------------- */ |
|---|
| 713 | /** |
|---|
| 714 | * Modify a TLD of the list of the authorized TLDs |
|---|
| 715 | * |
|---|
| 716 | * @param $tld string TLD we want to modify |
|---|
| 717 | * @param $mode integer Controls to make on this TLD. |
|---|
| 718 | * @return boolean TRUE if the TLD has been successfully |
|---|
| 719 | * modified. FALSE if not. |
|---|
| 720 | * |
|---|
| 721 | * |
|---|
| 722 | * Modifie un TLD autorisé de la liste des tld autorisés. |
|---|
| 723 | * |
|---|
| 724 | * @param $tld Top-Level Domain à modifier (org, com ...) |
|---|
| 725 | * @param $mode Numéro du mode autorisé (0->5) |
|---|
| 726 | * @return boolean True si le tld a bien été modifié, False sinon. |
|---|
| 727 | * |
|---|
| 728 | */ |
|---|
| 729 | function edittld($tld,$mode) { |
|---|
| 730 | global $db,$err; |
|---|
| 731 | $db->query("SELECT tld FROM tld WHERE tld='$tld';"); |
|---|
| 732 | if (!$db->next_record()) { |
|---|
| 733 | $err->raise("admin",11); |
|---|
| 734 | return false; |
|---|
| 735 | } |
|---|
| 736 | $mode=intval($mode); |
|---|
| 737 | if ($mode==0) $mode="0"; |
|---|
| 738 | $db->query("UPDATE tld SET mode='$mode' WHERE tld='$tld';"); |
|---|
| 739 | return true; |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | } /* Classe ADMIN */ |
|---|
| 743 | |
|---|
| 744 | ?> |
|---|