/** Creates a new hosted account * * Creates a new hosted account (in the tables <code>membres</code> * and <code>local</code>). Prevents any manipulation of the account if * the account $mid is not super-admin. * * * @global m_err $err * @global m_quota $quota * @global array $classes * @global int $cuid * @global m_mem $mem * @global string $L_MYSQL_DATABASE * @global string $L_MYSQL_LOGIN * @global m_hooks $hooks * @global m_action $action * @param string $login Login name like [a-z][a-z0-9]* * @param string $pass Password (max. 64 characters) * @param string $nom Name of the account owner * @param string $prenom First name of the account owner * @param string $mail Email address of the account owner, useful to get * one's lost password * @param integer $canpass * @param string $type Account type for quotas * @param int $duration * @param string $notes * @param integer $force * @param string $create_dom * @param int $db_server_id * @return boolean Returns FALSE if an error occurs, TRUE if not. */ function add_mem($login, $pass, $nom, $prenom, $mail, $canpass = 1, $type = 'default', $duration = 0, $notes = "", $force = 0, $create_dom = '', $db_server_id) { global $err, $quota, $classes, $cuid, $mem, $L_MYSQL_DATABASE, $L_MYSQL_LOGIN, $hooks, $action; $err->log("admin", "add_mem", $login . "/" . $mail); if (!$this->enabled) { $err->raise("admin", _("-- Only administrators can access this page! --")); return false; } if (empty($db_server_id)) { $err->raise("admin", _("Missing db_server field")); return false; } if ($login == "" || $pass == "") { $err->raise("admin", _("All fields are mandatory")); return false; } if (!$force) { if ($mail == "") { $err->raise("admin", _("All fields are mandatory")); return false; } //@todo remove cf functions.php if (checkmail($mail) != 0) { $err->raise("admin", _("Please enter a valid email address")); return false; } } $login = strtolower($login); if (!preg_match("#^[a-z0-9]+\$#", $login)) { //$ $err->raise("admin", _("Login can only contains characters a-z and 0-9")); return false; } if (strlen($login) > 14) { // Not an arbitrary value : MySQL user names can be up to 16 characters long // If we want to allow people to create a few mysql_user (and we want to!) // we have to limit the login lenght $err->raise("admin", _("The login is too long (14 chars max)")); return false; } // Some login are not allowed... if ($login == $L_MYSQL_DATABASE || $login == $L_MYSQL_LOGIN || $login == "mysql" || $login == "root") { $err->raise("admin", _("Login can only contains characters a-z, 0-9 and -")); return false; } $pass = _md5cr($pass); $db = new DB_System(); $notes = mysql_real_escape_string($notes); // Already exist? $db->query("SELECT count(*) AS cnt FROM membres WHERE login='******';"); $db->next_record(); if (!$db->f("cnt")) { $db->query("SELECT max(m.uid)+1 as nextid FROM membres m"); if (!$db->next_record()) { $uid = 2000; } else { $uid = $db->Record["nextid"]; if ($uid <= 2000) { $uid = 2000; } } $db->query("INSERT INTO membres (uid,login,pass,mail,creator,canpass,type,created,notes,db_server_id) VALUES ('{$uid}','{$login}','{$pass}','{$mail}','{$cuid}','{$canpass}', '{$type}', NOW(), '{$notes}', '{$db_server_id}');"); $db->query("INSERT INTO local(uid,nom,prenom) VALUES('{$uid}','{$nom}','{$prenom}');"); $this->renew_update($uid, $duration); #exec("sudo /usr/lib/alternc/mem_add ".$login." ".$uid); $action->create_dir(getuserpath("{$login}")); $action->fix_user($uid); // Triggering hooks $mem->su($uid); // TODO: old hook method FIXME: when unused remove this /* foreach($classes as $c) { if (method_exists($GLOBALS[$c],"alternc_add_member")) { $GLOBALS[$c]->alternc_add_member(); } } */ $hooks->invoke("alternc_add_member"); // New hook way $hooks->invoke("hook_admin_add_member", array(), array('quota')); // First !!! The quota !!! Etherway, we can't be sure to be able to create all $hooks->invoke("hook_admin_add_member"); $mem->unsu(); if (!empty($create_dom)) { $this->add_shared_domain($uid, $create_dom); } return $uid; } else { $err->raise("admin", _("This login already exists")); return false; } }
/** * This function is called on each class when a domain name is uninstalled * @param string $dom the domain to uninstall */ function alternc_del_domain($dom) { global $err, $cuid; $err->log("aws", "alternc_del_domain", $dom); $db = new DB_System(); $db->query("SELECT id,hostname FROM aws WHERE uid='{$cuid}' AND (hostname='{$dom}' OR hostname like '%.{$dom}')"); $t = array(); while ($db->next_record()) { $t[] = array($db->f("hostname"), $db->f("id")); } foreach ($t as $i) { $db->query("DELETE FROM aws WHERE uid='{$cuid}' AND hostname='" . $i[0] . "';"); $db->query("DELETE FROM aws_access WHERE uid='{$cuid}' AND id='" . $i[1] . "';"); $this->_delconf($i[0]); } return $this->_createhtpasswd(); }