function create_user($filename) { $tpl = new templates(); $unix = new unix(); $nohup = null; $path = "/usr/share/artica-postfix/ressources/logs/web/create-users/{$filename}"; echo "Path:{$path}\n"; build_progress("Open {$filename}", 10); if (!is_file($path)) { echo "{$path} no such file...\n"; return false; } $MAIN = unserialize(base64_decode(@file_get_contents($path))); build_progress("Create new member {$MAIN["login"]}", 15); $users = new user($MAIN["login"]); if ($users->password != null) { echo "User already exists {$MAIN["login"]}\n"; build_progress("{account_already_exists}", 110); @unlink($path); return; } $ou = $MAIN["ou"]; $password = url_decode_special_tool($MAIN["password"]); $MAIN["firstname"] = url_decode_special_tool($MAIN["firstname"]); $MAIN["lastname"] = url_decode_special_tool($MAIN["lastname"]); build_progress("{$MAIN["firstname"]} {$MAIN["lastname"]}", 20); if (trim($MAIN["internet_domain"]) == null) { $MAIN["internet_domain"] = "localhost.localdomain"; } echo "Add new user {$MAIN["login"]} {$MAIN["ou"]} {$MAIN["gpid"]}\n"; $users->ou = $MAIN["ou"]; $users->password = url_decode_special_tool($MAIN["password"]); $users->mail = "{$MAIN["email"]}@{$MAIN["internet_domain"]}"; $users->DisplayName = "{$MAIN["firstname"]} {$MAIN["lastname"]}"; $users->givenName = $MAIN["firstname"]; $users->sn = $MAIN["lastname"]; $users->group_id = $MAIN["gpid"]; $users->homeDirectory = "/home/{$MAIN["login"]}"; if (is_numeric($MAIN["gpid"])) { $gp = new groups($MAIN["gpid"]); echo "privileges: {$MAIN["gpid"]} -> AsComplexPassword = \"{$gp->Privileges_array["AsComplexPassword"]}\"\n"; if ($gp->Privileges_array["AsComplexPassword"] == "yes") { $ldap = new clladp(); $hash = $ldap->OUDatas($ou); $privs = $ldap->_ParsePrivieleges($hash["ArticaGroupPrivileges"], array(), true); $policiespwd = unserialize(base64_decode($privs["PasswdPolicy"])); if (is_array($policiespwd)) { $priv = new privileges(); if (!$priv->PolicyPassword($password, $policiespwd)) { build_progress("Need complex password", 110); echo "Need complex password"; @unlink($path); return; } } } } build_progress("{$MAIN["firstname"]} {$MAIN["lastname"]} {save}", 25); if (!$users->add_user()) { echo $users->error . "\n" . $users->ldap_error; build_progress("{failed}", 110); @unlink($path); return; } @mkdir("{$users->homeDirectory}"); @chown("{$users->homeDirectory}", $users->uid); if ($MAIN["ByZarafa"] == "yes") { $terminated = " >/dev/null"; $zarafa_admin = $unix->find_program("zarafa-admin"); if (!$GLOBALS["WAIT"]) { $nohup = $unix->find_program("nohup"); $terminated = null; } if (isset($MAIN["ZARAFA_LANG"])) { $users->SaveZarafaMbxLang($MAIN["ZARAFA_LANG"]); $langcmd = " --lang {$MAIN["ZARAFA_LANG"]} "; } $ldap = new clladp(); $dn = "ou={$MAIN["ou"]},dc=organizations,{$ldap->suffix}"; $upd["objectClass"] = "zarafa-company"; $upd["cn"] = $MAIN["ou"]; if (!$ldap->Ldap_add_mod("{$dn}", $upd)) { echo $ldap->ldap_last_error; build_progress("{failed} OpenLDAP Error", 110); @unlink($path); return; } build_progress("{create_store} {language}: {$MAIN["ZARAFA_LANG"]}", 30); $cmd = "{$nohup} {$zarafa_admin} {$langcmd}--create-store {$MAIN["login"]} >/dev/null 2>&1 &"; system(trim($cmd)); if (!$GLOBALS["WAIT"]) { $sock = new sockets(); $sock->getFrameWork("cmd.php?zarafa-hash=yes&rebuild=yes"); return; } @unlink("/usr/share/artica-postfix/ressources/databases/ZARAFA_DB_STATUS.db"); @unlink("/etc/artica-postfix/zarafa-export.db"); $cmd = LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.zarafa.build.stores.php --export-hash"; build_progress("{export_stores_data}", 35); echo "{$cmd}\n"; system($cmd); } echo "Remove {$path}\n"; @unlink($path); return true; }
function save() { $tpl = new templates(); $users = new user($_GET["login"]); if ($users->password != null) { writelogs("User already exists {$_GET["login"]} ", __FUNCTION__, __FILE__); echo $tpl->_ENGINE_parse_body('{account_already_exists}'); exit; } $ou = $_REQUEST["ou"]; $password = $_REQUEST["password"]; writelogs("Add new user {$_REQUEST["login"]} {$_REQUEST["ou"]} {$_REQUEST["gpid"]}", __FUNCTION__, __FILE__); $users->ou = $_REQUEST["ou"]; $users->password = $_REQUEST["password"]; $users->mail = "{$_REQUEST["email"]}@{$_REQUEST["internet_domain"]}"; $users->DisplayName = "{$_REQUEST["firstname"]} {$_REQUEST["lastname"]}"; $users->givenName = $_REQUEST["firstname"]; $users->sn = $_REQUEST["lastname"]; $users->group_id = $_REQUEST["gpid"]; if (is_numeric($_REQUEST["gpid"])) { $gp = new groups($_REQUEST["gpid"]); writelogs("privileges: {$_REQUEST["gpid"]} -> AsComplexPassword = \"{$gp->Privileges_array["AsComplexPassword"]}\"", __FUNCTION__, __FILE__, __LINE__); if ($gp->Privileges_array["AsComplexPassword"] == "yes") { $ldap = new clladp(); $hash = $ldap->OUDatas($ou); $privs = $ldap->_ParsePrivieleges($hash["ArticaGroupPrivileges"], array(), true); $policiespwd = unserialize(base64_decode($privs["PasswdPolicy"])); if (is_array($policiespwd)) { $priv = new privileges(); if (!$priv->PolicyPassword($password, $policiespwd)) { return false; } } } return false; } $users->add_user(); }
function USER_ADD() { $userid = $_REQUEST["new_userid"]; $password = $_REQUEST["password"]; $group_id = $_REQUEST["group_id"]; if (isset($_GET["encpass"])) { $password = url_decode_special_tool($password); } $ou = $_REQUEST["ou"]; $tpl = new templates(); if (preg_match("#(.+?)@(.+)#", $_REQUEST["email"], $re)) { $_REQUEST["user_domain"] = $re[2]; $_REQUEST["email"] = $re[1]; } $email = $_REQUEST["email"] . "@" . $_REQUEST["user_domain"]; $email = strtolower($email); $user = new usersMenus(); if ($user->EnableVirtualDomainsInMailBoxes == 1) { writelogs("Adding change {$userid} to \"{$email}\" in group {$group_id}", __FUNCTION__, __FILE__, __LINE__); $userid = $email; } if (is_numeric($group_id)) { $gp = new groups($group_id); writelogs("privileges: {$group_id} -> AsComplexPassword = \"{$gp->Privileges_array["AsComplexPassword"]}\"", __FUNCTION__, __FILE__, __LINE__); if ($gp->Privileges_array["AsComplexPassword"] == "yes") { $ldap = new clladp(); $hash = $ldap->OUDatas($ou); $privs = $ldap->_ParsePrivieleges($hash["ArticaGroupPrivileges"], array(), true); $policiespwd = unserialize(base64_decode($privs["PasswdPolicy"])); if (is_array($policiespwd)) { $priv = new privileges(); if (!$priv->PolicyPassword($password, $policiespwd)) { return false; } } } else { writelogs("privileges: {$group_id} -> AsComplexPassword = \"No\" -> continue", __FUNCTION__, __FILE__, __LINE__); } } $users = new user($userid); if ($users->UserExists) { echo $tpl->javascript_parse_text('ERROR: {account_already_exists}'); return false; } writelogs("Adding {$userid} in group {$group_id}", __FUNCTION__, __FILE__, __LINE__); $email = $_REQUEST["email"] . "@" . $_REQUEST["user_domain"]; if ($ou == null) { echo html_entity_decode($tpl->javascript_parse_text('ERROR:{error_no_ou}')); exit; } if ($userid == null) { echo html_entity_decode($tpl->javascript_parse_text('ERROR:{error_no_userid}')); exit; } if ($password == null) { echo html_entity_decode($tpl->javascript_parse_text('ERROR:{error_no_password}')); exit; } if ($email == null) { echo html_entity_decode($tpl->javascript_parse_text('ERROR:{error_no_email}')); exit; } $ldap = new clladp(); if (!is_numeric($group_id)) { writelogs("Groupid is not numeric", __FUNCTION__, __FILE__, __LINE__); $default_dn_group = "cn=nogroup,ou={$ou},dc=organizations,{$ldap->suffix}"; if (!$ldap->ExistsDN($default_dn_group)) { $ldap->AddGroup("nogroup", $ou); } $group_id = $ldap->GroupIDFromName($ou, "nogroup"); if (!is_numeric($group_id)) { $group_id = 0; } } $emT = explode('@', $email); //Verify domains --------------------------------------------------------------- 2008 10 05,P3 $hash_domains_table = $ldap->hash_get_domains_ou($ou); if (!isset($hash_domains_table[$_REQUEST["user_domain"]])) { writelogs("{$userid} have no domains", __FUNCTION__, __FILE__, __LINE__); writelogs("Create a new local domain by default", __FUNCTION__, __FILE__, __LINE__); $ldap->AddDomainEntity($ou, $_REQUEST["user_domain"]); } //------------------------------------------------------------------------------ $domains = $ldap->domains_get_locals_domains($ou); $dn = "cn={$userid},ou={$ou},dc=organizations,{$ldap->suffix}"; if ($ldap->ExistsDN($dn)) { writelogs("{$userid} ({$dn}) already exists", __FUNCTION__, __FILE__, __LINE__); echo $userid; exit; } $users = new user($userid); $users->mail = $email; $users->accountGroup = $group_id; $users->domainname = $_REQUEST["user_domain"]; if ($password != null) { $users->password = $password; } $users->ou = $ou; if ($domains[$_REQUEST["user_domain"]] == true) { $upd = array(); writelogs("is a local domain {$_REQUEST["user_domain"]}={$domains[$_REQUEST["user_domain"]]}", __FUNCTION__, __FILE__, __LINE__); $upd["ObjectClass"][] = 'ArticaSettings'; $users->MailboxActive = "TRUE"; } if (!$users->add_user()) { echo "ERROR: add_user(): " . $users->ldap_error . "\n" . basename(__FILE__) . "\nLine:" . __LINE__; exit; } writelogs("Success adding user, now, add user {$users->uid} to group {$group_id} ", __FUNCTION__, __FILE__, __LINE__); if ($group_id > 0) { $ldap->AddUserToGroup($group_id, $users->uid); } echo $users->uid; }