Example #1
0
function create_group()
{
    $ldap = new clladp();
    $tpl = new templates();
    $sock = new sockets();
    $page = CurrentPageName();
    $q = new mysql();
    $sql = "SELECT * FROM register_orgs WHERE `zmd5`='{$_GET["key"]}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    $ou = $ligne["ou"];
    if ($ligne["ou"] == null) {
        echo $tpl->_ENGINE_parse_body("{please_register_first}");
        return;
    }
    $domain = $ligne["domain"];
    $user = $ligne["username"];
    $password = $ligne["password"];
    $gp = new groups();
    if (!$gp->add_new_group("administrators", $ou)) {
        $html = "\n\t\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/42-red.png'></td>\n\t\t\t<td valign='top' style='font-size:16px'>{group}: administrators {failed} {$gp->ldap_error}</td>\n\t\t</tr>\n\t\t</table>";
        echo $tpl->_ENGINE_parse_body($html);
        return;
    }
    $update_array = array();
    $values[] = "[AllowEditOuSecurity]=\"yes\"";
    $values[] = "[AsOrgPostfixAdministrator]=\"yes\"";
    $values[] = "[AsQuarantineAdministrator]=\"yes\"";
    $values[] = "[AsOrgStorageAdministrator]=\"yes\"";
    $values[] = "[AsMessagingOrg]=\"yes\"";
    $values[] = "[AsOrgAdmin]=\"yes\"";
    $gppid = $gp->GroupIDFromName($ou, "administrators");
    $gp = new groups($gppid);
    $update_array["ArticaGroupPrivileges"][0] = @implode("\n", $values);
    $ldap->Ldap_modify($gp->dn, $update_array);
    if ($ldap->ldap_last_error != null) {
        $html = "\n\t\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/42-red.png'></td>\n\t\t\t<td valign='top' style='font-size:16px'>{group}: administrators ({$gppid}) {permissions} {failed} {$ldap->ldap_last_error}</td>\n\t\t</tr>\n\t\t</table>";
        echo $tpl->_ENGINE_parse_body($html);
        return;
    }
    $EnableVirtualDomainsInMailBoxes = $sock->GET_INFO("EnableVirtualDomainsInMailBoxes");
    $uid = $user;
    if ($EnableVirtualDomainsInMailBoxes == 1) {
        $uid = "{$user}@{$domain}";
    }
    if (!$gp->AddUsertoThisGroup($uid)) {
        $html = "\n\t\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/42-red.png'></td>\n\t\t\t<td valign='top' style='font-size:16px'>{group}: administrators ({$gppid}) {affect} {$uid} {$ldap->ldap_last_error}</td>\n\t\t</tr>\n\t\t</table>";
        echo $tpl->_ENGINE_parse_body($html);
        return;
    }
    $html = "\n\t\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/42-green.png'></td>\n\t\t\t<td valign='top' style='font-size:16px'>{group}: administrators &raquo {$uid} {success}</td>\n\t\t</tr>\n\t\t</table>\n\t\t<div id='step-5'></div>\n\t\t<script>\n\t\t\tLoadAjax('step-5','{$page}?create-groupwares=yes&key={$_GET["key"]}');\n\t\t</script>\t\t\n\t\t";
    echo $tpl->_ENGINE_parse_body($html);
    return;
}
function GROUP_ADD($value)
{
    include_once dirname(__FILE__) . '/ressources/class.user.inc';
    include_once dirname(__FILE__) . '/ressources/class.groups.inc';
    $array = unserialize(base64_decode($value));
    if (!is_array($array)) {
        send_email_events("Failed to add group, not an array", "", "CLOUD");
        return true;
    }
    $guid = $array["gid"];
    $ou = $array["ou"];
    $groupname = $array["groupname"];
    events("Adding new group \"{$ou}\" gid:{$guid} Ou:{$ou} ", __FUNCTION__, __FILE__, __LINE__);
    $group = new groups();
    if ($group->add_new_group($groupname, $ou, $guid)) {
        send_email_events("Success to add group {$groupname}", "", "CLOUD");
        events("Adding new group success", __FUNCTION__, __FILE__, __LINE__);
    } else {
        send_email_events("Failed to add group {$groupname}", "", "CLOUD");
        events("Adding new group Failed", __FUNCTION__, __FILE__, __LINE__);
    }
    sys_THREAD_COMMAND_SET(LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.artica.meta.users.php --export-all-groups");
    return true;
}
Example #3
0
function import($ou, $path)
{
    $usersM = new usersMenus();
    $unix = new unix();
    if (!is_file($path)) {
        echo "{$path}, no such file\n";
        die;
    }
    $ldap = new clladp();
    $oudn = "ou={$ou},dc=organizations,{$ldap->suffix}";
    if (!$ldap->ExistsDN($oudn)) {
        $ldap->AddOrganization($ou);
    }
    $tmpfile = $unix->FILE_TEMP();
    uncompress($path, $tmpfile);
    $datas = unserialize(base64_decode(@file_get_contents($tmpfile)));
    if (!is_array($datas)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Unable to import {$ou} {$path}, no such array\n";
            return;
        }
        $unix->send_email_events(basename(__FILE__) . "::Unable to import {$ou} {$path}, no such array", null, "import");
        die;
    }
    $usersArray = $datas["USERS"];
    $groupsArray = $datas["GROUPS"];
    unset($datas);
    echo "Creating groups in `{$ou}`";
    while (list($num, $hash) = each($groupsArray)) {
        $ORG_GID = $hash["main_array"]["gid"];
        $gp = new groups();
        $gpid = $gp->GroupIDFromName($ou, $hash["groupName"]);
        if (!is_numeric($gpid)) {
            $gp->groupName = $hash["groupName"];
            $gp->add_new_group($hash["groupName"], $ou);
            $gpid = $gp->GroupIDFromName($ou, $hash["groupName"]);
        }
        $gp = new groups($gpid);
        $members = $hash["members"];
        while (list($a, $b) = each($members)) {
            echo "Insert {$b} user to {$hash["groupName"]}/{$gpid}\n";
            $gp->AddUsertoThisGroup($b);
        }
        $gp->saveDescription($hash["main_array"]["description"]);
        $gp->ArticaGroupPrivileges = $hash["main_array"]["ArticaGroupPrivileges"];
        $gp->Privileges_array = $hash["Privileges_array"];
        $gp->SavePrivileges();
        $GROUPSORGS[$ORG_GID] = $gpid;
    }
    while (list($num, $hash) = each($usersArray)) {
        $array_groups = $hash["array_groups"];
        unset($hash["dn"]);
        unset($hash["UserExists"]);
        unset($hash["ou"]);
        unset($hash["local_sid"]);
        unset($hash["objectClass_array"]);
        unset($hash["group_id"]);
        unset($hash["sambaPrimaryGroupSID"]);
        unset($hash["accountGroup"]);
        unset($hash["uidNumber"]);
        unset($hash["sambaSID"]);
        unset($hash["sambaPrimaryGroupGID"]);
        unset($hash["gidNumber_array"]);
        $samba_groups = $hash["samba_groups"];
        unset($hash["ldapClass"]);
        unset($hash["attributs_array"]);
        unset($hash["samba_groups"]);
        $users = new user($hash["uid"]);
        $users->ou = $ou;
        $users->group_id = $GROUPSORGS[$array_groups[0]];
        while (list($a, $orgd) = each($hash)) {
            $users->a = $orgd;
        }
        $users->add_user();
        if ($usersM->SAMBA_INSTALLED) {
            if (!$hash["NotASambaUser"]) {
                $users->Samba_edit_user();
            }
        }
    }
}
function AddNewComputerGroup()
{
    $group = new groups();
    if (!$group->add_new_group($_GET["AddNewComputerGroup"])) {
        echo $group->ldap_error;
        return;
    }
    $gpid = $group->GroupIDFromName(null, $_GET["AddNewComputerGroup"]);
    $group = new groups($gpid);
    $group->TransformGroupToSmbGroup();
}
Example #5
0
function import($ligne)
{
    $unix = new unix();
    $Tmpdir = $unix->TEMP_DIR();
    $connection = $ligne["connection"];
    $username = $ligne["username"];
    $password = $ligne["password"];
    $folder = $ligne["folder"];
    $filename = $ligne["filename"];
    $ID = $ligne["ID"];
    $folder = str_replace("\\", "/", $folder);
    if (strpos($folder, "/") > 0) {
        $FF = explode("/", $folder);
        $SharedDir = $FF[0];
        unset($FF[0]);
        $folder = @implode("/", $FF);
    }
    $mountpoint = "{$Tmpdir}/{$ligne["ID"]}";
    if ($folder != null) {
        $targetdir = "{$mountpoint}/{$folder}";
    } else {
        $targetdir = $mountpoint;
    }
    if (!is_file("{$targetdir}/{$filename}")) {
        system_admin_events("{$connection}: {$targetdir}/{$filename}, no such file", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]);
        $mount = new mount();
        $mount->umount($mountpoint);
        return false;
    }
    if (is_file("{$targetdir}/{$filename}.scanned")) {
        $SCANNED = unserialize(@file_get_contents("{$targetdir}/{$filename}.scanned"));
    }
    $md5file = md5_file("{$targetdir}/{$filename}");
    if ($md5file == $ligne["lastmd5"]) {
        return true;
    }
    $handle = @fopen("{$targetdir}/{$filename}", "r");
    if (!$handle) {
        system_admin_events("{$connection}: {$targetdir}/{$filename}, fatal error", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]);
        return;
    }
    $c = 0;
    $ldap = new clladp();
    $OUS = $ldap->hash_get_ou(true);
    $defaultgroup = $ligne["ldapgroup"];
    if ($defaultgroup > 0) {
        $gp = new groups($defaultgroup);
        $DefaultOu = $gp->ou;
        $defaultGroupName = $gp->groupName;
        if ($GLOBALS["VERBOSE"]) {
            echo "Default group: {$defaultgroup}/ {$gp->groupName}/{$DefaultOu}\n";
        }
    }
    $t1 = time();
    $c = 0;
    $d = 0;
    while (!feof($handle)) {
        $line = trim(fgets($handle, 1024));
        $line = str_replace("\"", "", $line);
        if ($line == null) {
            continue;
        }
        if (strpos($line, ";") == 0) {
            continue;
        }
        $SCANMD = md5($line);
        $tr = explode(";", $line);
        $account = $tr[0];
        $password = $tr[1];
        $email = $tr[2];
        $groupname = $tr[3];
        $organization = $tr[4];
        if ($organization == "organization") {
            continue;
        }
        if ($account == "account") {
            continue;
        }
        $Telephon = $tr[5];
        $mobile = $tr[6];
        $d++;
        if (isset($SCANNED[$SCANMD])) {
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "--------------- {$d} ----------------- {$SCANMD}\n";
        }
        if ($organization == null) {
            if ($defaultgroup == 0) {
                continue;
            }
        }
        if ($organization == null) {
            if ($DefaultOu != null) {
                $organization = $DefaultOu;
            }
        }
        if ($groupname == null) {
            $groupname = $defaultGroupName;
        }
        if ($groupname == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$organization} NO GroupName !!\n";
            }
            continue;
        }
        if (!isset($OUS[$organization])) {
            if (!$ldap->AddOrganization($organization)) {
                system_admin_events("fatal error failed to create entry {$organization}", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]);
                return;
            }
            $OUS = $ldap->hash_get_ou(true);
        }
        if (!isset($GLOBALS["GROUPS"][$organization])) {
            $GLOBALS["GROUPS"][$organization] = $ldap->hash_groups($organization);
        }
        if (!isset($GLOBALS["GROUPS"][$organization][$groupname])) {
            $gp = new groups();
            $gp->ou = $organization;
            $gp->groupName = $groupname;
            if (!$gp->add_new_group($groupname, $organization)) {
                system_admin_events("fatal error failed to create entry {$groupname}/{$organization}", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]);
                return;
            }
            $GLOBALS["GROUPS"][$organization] = $ldap->hash_groups($organization);
        }
        if (!isset($GLOBALS["GROUPS"][$organization][$groupname]["gid"])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$groupname}/{$organization} NO GID!!\n";
            }
            continue;
        }
        $gid = $GLOBALS["GROUPS"][$organization][$groupname]["gid"];
        if ($password == null) {
            $password = $account;
        }
        $UPDATE = FALSE;
        $user = new user($account);
        if (!is_numeric($user->uidNumber)) {
            $UPDATE = true;
        }
        if ($email != null) {
            if ($user->mail != $email) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "mail {$email}\n";
                }
                $user->mail = $email;
                $UPDATE = true;
            }
        }
        if ($password != null) {
            if ($user->password != $password) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "password {$password}\n";
                }
                $user->password = $password;
                $UPDATE = true;
            }
        }
        if ($Telephon != null) {
            if ($user->telephoneNumber != $Telephon) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "telephoneNumber {$Telephon}\n";
                }
                $user->telephoneNumber = $Telephon;
                $UPDATE = true;
            }
        }
        if ($mobile != null) {
            if ($user->mobile != $mobile) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "mobile {$mobile}\n";
                }
                $user->mobile = $mobile;
                $UPDATE = true;
            }
        }
        if ($user->ou != $organization) {
            if ($GLOBALS["VERBOSE"]) {
                echo "ou {$organization}\n";
            }
            $user->ou = $organization;
            $UPDATE = true;
        }
        $user->group_id = $gid;
        if ($UPDATE) {
            $c++;
            if (!$user->SaveUser()) {
                continue;
            }
        }
        $SCANNED[$SCANMD] = time();
        @file_put_contents("{$targetdir}/{$filename}.scanned", serialize($SCANNED));
        if ($d > 500) {
            if (system_is_overloaded()) {
                system_admin_events("{$connection}: Overloaded system, aborting task", __FUNCTION__, __FILE__, __LINE__);
                return false;
            }
            $distance = $unix->distanceOfTimeInWords($t1, time(), true);
            system_admin_events("{$connection}: {$c} lines processed in {$distance}", __FUNCTION__, __FILE__, __LINE__);
            $d = 0;
        }
    }
    $date = date("Y-m-d H:i:s");
    $q = new mysql();
    $q->QUERY_SQL("UPDATE `texttoldap` SET `lastmd5`='{$md5file}',`lastscan`='{$date}' WHERE ID='{$ID}'", "artica_backup");
    $distance = $unix->distanceOfTimeInWords($t1, time(), true);
    system_admin_events("{$connection}: {$c} lines processed in {$distance}", __FUNCTION__, __FILE__, __LINE__);
    $umount = $unix->find_program("umount");
    shell_exec("{$umount} -l {$mountpoint}");
    return true;
}