Ejemplo n.º 1
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();
            }
        }
    }
}