Beispiel #1
0
function SaveCyrusPassword()
{
    $ldap = new clladp();
    $_POST["SaveCyrusPassword"] = url_decode_special_tool(trim($_POST["SaveCyrusPassword"]));
    if ($_POST["SaveCyrusPassword"] == null) {
        echo "Error: No password defined\n";
        return;
    }
    if (strpos($_POST["SaveCyrusPassword"], '@') > 0) {
        echo "@,: denied character\n";
        return;
    }
    if (strpos($_POST["SaveCyrusPassword"], ':') > 0) {
        echo "@,: denied character\n";
        return;
    }
    $attrs["userPassword"][0] = $_POST["SaveCyrusPassword"];
    $dn = "cn=cyrus,dc=organizations,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        if (!$ldap->Ldap_modify($dn, $attrs)) {
            echo $ldap->ldap_last_error;
            return;
        }
    }
    $dn = "cn=cyrus,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        if (!$ldap->Ldap_modify($dn, $attrs)) {
            echo $ldap->ldap_last_error;
            return;
        }
    }
    $sock = new sockets();
    $sock->getFrameWork("cmd.php?cyrus-change-password="******"SaveCyrusPassword"]));
}
Beispiel #2
0
function BuildDHCP()
{
    $ldap = new clladp();
    if ($ldap->ldapFailed) {
        echo "Starting......: DHCP SERVER ldap connection failed,aborting\n";
        return;
    }
    if (!$ldap->ExistsDN("dc=organizations,{$ldap->suffix}")) {
        echo "Starting......: DHCP SERVER dc=organizations,{$ldap->suffix} no such branch, aborting\n";
        return;
    }
    echo "Starting......: DHCP SERVER ldap connection success\n";
    $dhcpd = new dhcpd();
    $conf = $dhcpd->BuildConf();
    $confpath = dhcp3Config();
    $unix = new unix();
    @mkdir(dirname($confpath), null, true);
    @file_put_contents($confpath, $conf);
    echo "Starting......: DHCP SERVER saving \"{$confpath}\" (" . strlen($conf) . " bytes) done\n";
    if (is_dir("/var/lib/dhcp3")) {
        shell_exec("/bin/chown -R dhcpd:dhcpd /var/lib/dhcp3");
        shell_exec("/bin/chmod 755 /var/lib/dhcp3");
    }
    $complain = $unix->find_program("aa-complain");
    if (is_file($complain)) {
        $dhcpd3 = $unix->find_program("dhcpd3");
        if (is_file($dhcpd3)) {
            shell_exec("{$complain} {$dhcpd3} >/dev/null 2>&1");
        }
    }
}
function add_isp_server_name()
{
    $ldap = new clladp();
    if (!$ldap->ExistsDN("cn=smtp_sasl_password_maps,cn=artica,{$ldap->suffix}")) {
        $upd["cn"][] = "smtp_sasl_password_maps";
        $upd["objectClass"][] = "top";
        $upd["objectClass"][] = "PostFixStructuralClass";
        $ldap->ldap_add("cn=smtp_sasl_password_maps,cn=artica,{$ldap->suffix}", $upd);
        unset($upd);
    }
    $cn = "cn={$_GET["isp_server_name"]},cn=smtp_sasl_password_maps,cn=artica,{$ldap->suffix}";
    if ($ldap->ExistsDN($cn)) {
        return null;
    }
    $upd["cn"] = $_GET["isp_server_name"];
    $upd["objectClass"][] = "top";
    $upd["objectClass"][] = "PostfixSmtpSaslPaswordMaps";
    $upd["SmtpSaslPasswordString"] = "{$_GET["username"]}:{$_GET["password"]}";
    $ldap->ldap_add($cn, $upd);
}
function DeleteSmtpSaslPasswordMaps()
{
    $ldap = new clladp();
    $server = base64_decode($_GET["DeleteSmtpSaslPasswordMaps"]);
    $dn = "cn={$server},cn=smtp_sasl_password_maps,cn=artica,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        if (!$ldap->ldap_delete($dn, true)) {
            echo "{$dn}\n{$ldap->ldap_last_error}";
            return;
        }
    }
    $sock = new sockets();
    $sock->getFrameWork("cmd.php?postfix-relayhost=yes");
}
function changecomputername()
{
    if (substr($_POST["userid"], strlen($_POST["userid"]) - 1, 1) != "\$") {
        $_POST["userid"] = $_POST["userid"] . "\$";
    }
    $comp = new computers($_POST["userid"]);
    $MAC = $comp->ComputerMacAddress;
    $_POST["NewHostname"] = trim(strtolower($_POST["NewHostname"]));
    $_POST["NewHostname"] = str_replace('$', '', $_POST["NewHostname"]);
    $actualdn = $comp->dn;
    $newrdn = "cn={$_POST["NewHostname"]}\$";
    $ldap = new clladp();
    if (!preg_match("#^cn=(.+?),[a-zA-Z\\s]+#", $actualdn, $re)) {
        echo "Unable to preg_match {$actualdn}\n";
        return;
    }
    $newDN = str_replace($re[1], $_POST["NewHostname"] . '$', $actualdn);
    if ($newDN == null) {
        echo "Unable to preg_match {$actualdn} -> {$re[1]}\n";
        return;
    }
    if ($ldap->ExistsDN("{$newrdn},ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}")) {
        $ldap->ldap_delete("{$newrdn},ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}");
    }
    $newParent = "ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}";
    if (!$ldap->Ldap_rename_dn($newrdn, $actualdn, $newParent)) {
        echo "Rename failed {$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\n\nActual DN:{$actualdn}\nExpected DN:{$newrdn}";
        return;
    }
    $upd["uid"][0] = $_POST["NewHostname"] . '$';
    if (!$ldap->Ldap_modify($newDN, $upd)) {
        echo "Update UID {$upd["uid"][0]} failed:\n{$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}\nExpected value:{$_POST["NewHostname"]}";
        return;
    }
    $ocs = new ocs($MAC);
    $ocs->ComputerName = $_POST["NewHostname"];
    $ocs->ComputerIP = $comp->ComputerIP;
    $ocs->EditComputer();
    if (IsPhysicalAddress($comp->ComputerMacAddress)) {
        include_once dirname(__FILE__) . "/ressources/class.mysql.inc";
        $uid = $comp->ComputerIDFromMAC($comp->ComputerMacAddress);
        $comp = new computers($uid);
        $sql = "UPDATE dhcpd_fixed SET `hostname`='{$comp->ComputerRealName}' WHERE `mac`='{$comp->ComputerMacAddress}'";
        $q = new mysql();
        $q->QUERY_SQL($sql, "artica_backup");
    }
}
Beispiel #6
0
function Loadtemplate()
{
    $ou = $_GET["ou"];
    $template_name = $_GET["template"];
    writequeries();
    $ldap = new clladp();
    $dn = "cn=artica_quarantine_settings,ou={$ou},dc=organizations,{$ldap->suffix}";
    if (isset($_GET["ArticaMaxDayTemplate"])) {
        $template_data = "<SUBJECT>{$_GET["subject"]}</SUBJECT>\n\t\t<FROM>{$_GET["from"]}</FROM>\n\t\t<TEMPLATE>{$_GET["ArticaMaxDayTemplate"]}</TEMPLATE>";
        $upd[$template_name][0] = $template_data;
        if (!$ldap->Ldap_modify($dn, $upd)) {
            echo "<H2>{$ldap->ldap_last_error}</H2>";
            exit;
        }
    }
    if (!$ldap->ExistsDN($dn)) {
        $upd["cn"][] = "artica_quarantine_settings";
        $upd["objectClass"][] = 'top';
        $upd["objectClass"][] = 'ArticaQuarantineTemplates';
        $upd["{$template_name}"][] = "DEFAULT";
        $ldap->ldap_add($dn, $upd);
        $template_data = "DEFAULT";
    } else {
        $hash = $ldap->Ldap_read($dn, '(ObjectClass=ArticaQuarantineTemplates)', array(strtolower($template_name)));
        if (!is_array($hash[0][strtolower($template_name)])) {
            unset($upd);
            $upd[$template_name] = "DEFAULT";
            $ldap->Ldap_add_mod($dn, $upd);
            $hash = $ldap->Ldap_read($dn, '(ObjectClass=ArticaQuarantineTemplates)', array(strtolower($template_name)));
        }
        $template_data = $hash[0][strtolower($template_name)][0];
    }
    if ($template_data == "DEFAULT") {
        $template_data = file_get_contents("ressources/databases/{$template_name}.cf");
    }
    if (preg_match('#<SUBJECT>(.+?)</SUBJECT>\\s+<FROM>(.+?)</FROM>\\s+<TEMPLATE>(.+?)</TEMPLATE>#is', $template_data, $reg)) {
        $subject = $reg[1];
        $from = $reg[2];
        $template_d = $reg[3];
    }
    $tiny = TinyMce('ArticaMaxDayTemplate', $template_d);
    $html = "\n\t<html>\n\t<head>\n\t<link href='css/styles_main.css' rel=\"styleSheet\" type='text/css' />\n\t<link href='css/styles_header.css' rel=\"styleSheet\" type='text/css' />\n\t<link href='css/styles_middle.css' rel=\"styleSheet\" type='text/css' />\n\t<link href='css/styles_forms.css' rel=\"styleSheet\" type='text/css' />\n\t<link href='css/styles_tables.css' rel=\"styleSheet\" type='text/css' />\n\t<script type='text/javascript' language='JavaScript' src='mouse.js'></script>\n\t<script type='text/javascript' language='javascript' src='XHRConnection.js'></script>\n\t<script type='text/javascript' language='javascript' src='default.js'></script>\n\t<script type='text/javascript' language='javascript' src='js/quarantine.ou.js'></script>\t\n\t</head>\n\t<body width=100% style='background-color:white'> \n\t\t<H5>{" . "{$template_name}}</H5>\n\t<form name='FFM1'>\n\t<table style='width:100%;margin:10px'>\n\t<tr>\n\t<td align='right'><strong>{from}:</strong></td>\n\t<td><input type='text' name='from' value='{$from}'></td>\n\t</tr>\n\t<tr>\n\t<td align='right'><strong>{subject}:</strong></td>\n\t<td><input type='text' name='subject' value='{$subject}'></td>\n\t</tr>\t\n\t</table>\n\t<div style='width:450px'>{$tiny}</div>\n\t<p class=caption>{template_token}</p>\n\t<input type='hidden' name='ou' value='{$ou}'>\n\t<input type='hidden' name='template' value='{$template_name}'>\n\t</form>\n\t</body>\n\t</html>";
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
Beispiel #7
0
function Confirm()
{
    $group = new groups($_GET["gpid"]);
    if ($_GET["delete-mailbox"] == 1) {
        if (is_array($gp->members_array)) {
            $members_array = $gp->members_array;
            while (list($num, $ligne) = each($members_array)) {
                if (trim($num) == null) {
                    continue;
                }
                $sock = new sockets();
                $sock->getFrameWork("cmd.php?DelMbx={$num}");
            }
        }
    }
    if ($_GET["DeleteUsers"] == 1) {
        if (is_array($gp->members_array)) {
            $members_array = $gp->members_array;
            while (list($num, $ligne) = each($members_array)) {
                if (trim($num) == null) {
                    continue;
                }
                $user = new user($num);
                $user->DeleteUser();
            }
        }
    } else {
        $ldap = new clladp();
        $default_dn_nogroup = "cn=nogroup,ou=groups,ou={$ou},dc=organizations,{$ldap->suffix}";
        if (!$ldap->ExistsDN($default_dn_nogroup)) {
            $ldap->AddGroup("nogroup", $group->ou);
        }
        $nogroup_id = $ldap->GroupIDFromName($group->ou, "nogroup");
        if (is_array($gp->members_array)) {
            $members_array = $gp->members_array;
            while (list($num, $val) = each($members_array)) {
                $ldap->AddUserToGroup($nogroup_id, $num);
                $group->DeleteUserFromThisGroup($num);
            }
        }
    }
    $group->Delete();
}
Beispiel #8
0
function bogo_add_spam_user()
{
    $ou = $_GET["ou"];
    $bogospam_user = $_GET["bogospam_user"];
    $bogospam_domain = $_GET["bogospam_domain"];
    $bogospam_type = $_GET["bogospam_type"];
    $userid = $bogospam_user;
    $password = "******";
    $group_id = 0;
    $email = "{$bogospam_user}@{$bogospam_domain}";
    $tpl = new templates();
    $userid = str_replace(" ", ".", $userid);
    $ldap = new clladp();
    $dn = "cn={$userid},ou={$ou},dc=organizations,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd["cn"][0] = $userid;
        $upd["ObjectClass"][0] = 'top';
        $upd["ObjectClass"][1] = 'userAccount';
        $upd["ObjectClass"][2] = 'organizationalPerson';
        $upd["ObjectClass"][3] = 'ArticaBogoFilterAdmin';
        $upd["uid"][0] = $userid;
        $upd["accountActive"][0] = "TRUE";
        $upd["mail"][0] = "{$email}";
        $upd["accountGroup"][0] = $group_id;
        $upd["domainName"][0] = $bogospam_domain;
        $upd["homeDirectory"][0] = "/home/{$userid}";
        $upd["mailDir"][0] = "/home/{$userid}/mail";
        $upd["sn"][0] = $userid;
        $upd["displayName"][0] = $userid . " bogofilter robot";
        $upd["userPassword"][0] = $password;
        $upd["BogoFilterMailType"][0] = "{$bogospam_type}";
        if (!$ldap->ldap_add($dn, $upd)) {
            echo "ERROR: {$ldap->ldap_last_error}";
            exit;
        }
    }
}
function rename_group()
{
    $tpl = new templates();
    if ($_SESSION["uid"] != -100) {
        if ($_GET["ou"] != $_SESSION["ou"]) {
        }
        echo $tpl->_ENGINE_parse_body("{ERROR_NO_PRIVS}");
        die;
    }
    $gp = new groups($_GET["group-id"]);
    if ($_SESSION["uid"] != -100) {
        if ($gp->ou != $_SESSION["ou"]) {
            echo $tpl->_ENGINE_parse_body("{ERROR_NO_PRIVS}");
            die;
        }
    }
    $ldap = new clladp();
    $newname = $_GET["new-name"];
    if (trim($newname) == null) {
        return null;
    }
    $actualdn = $gp->dn;
    if (preg_match('#cn=(.+?),(.+)#', $actualdn, $re)) {
        $branch = $re[2];
    }
    $newdn = "cn={$newname}";
    $newdn2 = "{$newdn},{$branch}";
    $ldap = new clladp();
    if ($ldap->ExistsDN($newdn2)) {
        return null;
    }
    writelogs("Rename {$actualdn} to {$newdn}", __CLASS__ . '/' . __FUNCTION__, __FILE__);
    if (!$ldap->Ldap_rename_dn($newdn, $actualdn, $branch)) {
        echo $tpl->_ENGINE_parse_body("{GROUP_RENAME} {failed}\n {$ldap->ldap_last_error}");
    }
}
Beispiel #10
0
function CyrusUser()
{
    $ldap = new clladp();
    $dn = "cn=cyrus,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $im = 'danger24.png';
    }
    $res = @ldap_read($ldap->ldap_connection, $dn, "(objectClass=*)", array());
    if ($res) {
        $hash = ldap_get_entries($ldap->ldap_connection, $res);
        $userpassword = $hash[0]["userpassword"][0];
    }
    if ($userpassword != null) {
        $im = 'ok24.png';
    } else {
        $im = 'danger24.png';
    }
    $html = "<H5>Cyrus account</h5>\n<table><tr><td width=1%><img src='img/{$im}'></td><td><strong>cyrus:{$userpassword}</strong></td></tr></table>";
    return RoundedLightGreen($html);
}
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;
}
function DNS_DEL_ENTRY($value)
{
    $hostname = base64_decode($value);
    $EXEC_NICE = EXEC_NICE();
    if (is_file("/usr/bin/nohup")) {
        $nohup = "/usr/bin/nohup ";
    }
    $reload_datas = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-dns >/dev/null 2>&1 &";
    include_once dirname(__FILE__) . "/ressources/class.pdns.inc";
    $ldap = new clladp();
    $upd = array();
    $tbl = explode(".", $hostname);
    $dc = "dc=" . @implode(",dc=", $tbl);
    if ($ldap->ExistsDN("{$dc},ou=dns,{$ldap->suffix}")) {
        if ($ldap->ldap_delete("{$dc},ou=dns,{$ldap->suffix}", true)) {
            send_email_events("Success deleting DNS entry {$hostname}", "DN removed was : {$dc},ou=dns,{$ldap->suffix}", "CLOUD");
            return true;
        }
    } else {
        events("unable to stat {$dc},ou=dns,{$ldap->suffix}", __FUNCTION__, __FILE__, __LINE__);
    }
    $suffix = "ou=dns,{$ldap->suffix}";
    $pattern = "(&(objectclass=*)(associatedDomain={$hostname}))";
    $sr = @ldap_search($ldap->ldap_connection, $suffix, "{$pattern}", array());
    if ($sr) {
        $hash = ldap_get_entries($ldap->ldap_connection, $sr);
        for ($i = 0; $i < $hash["count"]; $i++) {
            $dn = $hash[$i]["dn"];
            if (strlen($dn) > 0) {
                $dns[] = $dn;
                events("removing  associateddomain={$hostname} in {$dn}", __FUNCTION__, __FILE__, __LINE__);
                $upd["associateddomain"] = $hostname;
                if (!$ldap->Ldap_del_mod($dn, $upd)) {
                    $dns[] = $ldap->ldap_last_error;
                }
            }
        }
        send_email_events("Success executing remove DNS entry {$hostname}", @implode("\n", $dns), "CLOUD");
        return true;
    }
    events("Failed -> notify", __FUNCTION__, __FILE__, __LINE__);
    send_email_events("Failed remove DNS entry {$hostname} does not exists", null, "CLOUD");
    shell_exec($reload_datas);
    return true;
}
function build_virtual_alias_maps()
{
    $main = new maincf_multi("master", "master");
    $ldap = new clladp();
    if ($GLOBALS["DEBUG"]) {
        echo __FUNCTION__ . " -> virtual_alias_maps=" . count($GLOBALS["virtual_alias_maps"]) . " entries\n";
    }
    if (is_array($GLOBALS["virtual_alias_maps_emailing"])) {
        echo "Starting......: " . date("H:i:s") . " Postfix [" . __LINE__ . "] " . count($GLOBALS["virtual_alias_maps_emailing"]) . " distribution listes\n";
        while (list($num, $ligne) = each($GLOBALS["virtual_alias_maps_emailing"])) {
            $num = trim($num);
            $num = str_replace("\r", "", $num);
            $num = str_replace("\n", "", $num);
            if ($GLOBALS["VERBOSE"]) {
                echo "FINAL -> {$num}/\"{$ligne}\"\n";
            }
            if ($ligne == null) {
                continue;
            }
            $final[] = $ligne;
        }
    }
    //-----------------------------------------------------------------------------------
    if (is_array($GLOBALS["virtual_alias_maps"])) {
        echo "Starting......: " . date("H:i:s") . " Cleaning virtual aliase(s)\n";
        while (list($num, $ligne) = each($GLOBALS["virtual_alias_maps"])) {
            $ligne = trim($ligne);
            $ligne = str_replace("\r", "", $ligne);
            $ligne = str_replace("\n", "", $ligne);
            if ($ligne == null) {
                continue;
            }
            if (preg_match("#x500:#", $ligne)) {
                continue;
            }
            if (preg_match("#x400:#", $ligne)) {
                continue;
            }
            $final[] = $ligne;
        }
    }
    //-----------------------------------------------------------------------------------
    $dn = "cn=artica_smtp_sync,cn=artica,{$ldap->suffix}";
    $filter = "(&(objectClass=InternalRecipients)(cn=*))";
    if ($ldap->ExistsDN($dn)) {
        $attrs = array("cn");
        $hash = $ldap->Ldap_search($dn, $filter, $attrs);
        if ($hash["count"] > 0) {
            for ($i = 0; $i < $hash["count"]; $i++) {
                $email = $hash[$i]["cn"][0];
                $email = trim($email);
                $email = str_replace("\r", "", $email);
                $email = str_replace("\n", "", $email);
                if (trim($email) == null) {
                    continue;
                }
                $final[] = "{$email}\t{$email}";
            }
        }
    }
    //-----------------------------------------------------------------------------------
    if (isset($GLOBALS["LDAPDBS"]["virtual_alias_maps"])) {
        if (!is_array($GLOBALS["LDAPDBS"]["virtual_alias_maps"])) {
            $virtual_alias_maps_cf = $GLOBALS["LDAPDBS"]["virtual_alias_maps"];
        }
    }
    $sock = new sockets();
    $MailingListUseLdap = $sock->GET_INFO("MailingListUseLdap");
    if (!is_numeric($MailingListUseLdap)) {
        $MailingListUseLdap = 0;
    }
    if ($MailingListUseLdap == 1) {
        $virtual_alias_maps_cf[] = "ldap:/etc/postfix/mailinglist.ldap.cf";
        mailling_ldap();
    }
    $sql = "SELECT * FROM postfix_aliases_domains";
    $q = new mysql();
    $pre = '${1}';
    $li = array();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ligne["alias"] = trim($ligne["alias"]);
        $ligne["alias"] = strtolower($ligne["alias"]);
        $aliases = str_replace(".", "\\.", $ligne["alias"]);
        $domain = $ligne["domain"];
        $li[] = "/^(.*)@{$aliases}\$/\t{$pre}@{$domain}";
        $final[] = "{$ligne["alias"]}\tDOMAIN";
    }
    $main = new maincf_multi("master", "master");
    $virtual_mailing_addr = $main->mailling_list_mysql("master");
    if (is_array($virtual_mailing_addr)) {
        while (list($num, $ligne) = each($virtual_mailing_addr)) {
            $final[] = $ligne;
        }
    }
    echo "Starting......: " . date("H:i:s") . " Postfix " . count($final) . " virtual aliase(s)\n";
    echo "Starting......: " . date("H:i:s") . " Postfix " . count($li) . " virtual domain(s) aliases\n";
    $virtual_alias_maps_cf[] = "hash:/etc/postfix/virtual";
    $virtual_alias_maps_cf[] = "pcre:/etc/postfix/virtual.domains";
    if ($GLOBALS["DEBUG"]) {
        echo __FUNCTION__ . " -> writing /etc/postfix/virtual\n";
    }
    @file_put_contents("/etc/postfix/virtual", implode("\n", $final));
    @file_put_contents("/etc/postfix/virtual.domains", implode("\n", $li));
    echo "Starting......: " . date("H:i:s") . " Postfix compiling virtual aliase database /etc/postfix/virtual\n";
    if ($GLOBALS["DEBUG"]) {
        echo __FUNCTION__ . " -> {$GLOBALS["postmap"]} hash:/etc/postfix/virtual >/dev/null 2>&1\n";
    }
    shell_exec("{$GLOBALS["postmap"]} hash:/etc/postfix/virtual >/dev/null 2>&1");
    $dbmaps = new postfix_extern();
    $contz = $dbmaps->build_extern("master", "virtual_alias_maps");
    if ($contz != null) {
        $virtual_alias_maps_cf[] = $contz;
    }
    if (!is_array($virtual_alias_maps_cf)) {
        if ($GLOBALS["DEBUG"]) {
            echo __FUNCTION__ . " -> {$GLOBALS["postconf"]} -e \"virtual_alias_maps = \" >/dev/null 2>&1\n";
        }
        shell_exec("{$GLOBALS["postconf"]} -e \"virtual_alias_maps = \" >/dev/null 2>&1");
        echo "Starting......: " . date("H:i:s") . " Postfix No virtual aliases\n";
        return;
    } else {
        echo "Starting......: " . date("H:i:s") . " Postfix building virtual_alias_maps\n";
        shell_exec("{$GLOBALS["postconf"]} -e \"virtual_alias_maps = " . @implode(",", $virtual_alias_maps_cf) . $main->mailman_aliases() . "\" >/dev/null 2>&1");
    }
}
Beispiel #14
0
function add_auto_mount()
{
    $type = $_GET["type"];
    $mount_point = $_GET["mount-point"];
    $computer = $_GET["computer"];
    $src = $_GET["src"];
    if ($type == 'smbfs') {
        $cmp = new computers($computer);
        $ini = new Bs_IniHandler();
        $ini->loadString($cmp->ComputerCryptedInfos);
        $username = $ini->_params["ACCOUNT"]["USERNAME"];
        $password = $ini->_params["ACCOUNT"]["PASSWORD"];
        if ($username != null) {
            $options = ",username={$username},password={$password}";
        }
        $pattern = "-fstype=smbfs{$options} ://{$cmp->ComputerIP}/{$src}";
    }
    if (preg_match("#nfs[0-9]+#", $type)) {
        if ($type == 'nfs3') {
            $pattern = "-fstype={$type} {$cmp->ComputerIP}:{$src}";
        }
        if ($type == 'nfs4') {
            $pattern = "-fstype={$type} {$cmp->ComputerIP}:/";
        }
    }
    $ldap = new clladp();
    $autofs = new autofs();
    $dn = "cn={$mount_point},ou=auto.automounts,ou=mounts,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd["ObjectClass"][] = 'top';
        $upd["ObjectClass"][] = 'automount';
        $upd["cn"][] = $mount_point;
        $upd["automountInformation"][] = $pattern;
        if (!$ldap->ldap_add($dn, $upd)) {
            echo "function: " . __FUNCTION__ . "\n" . "file: " . __FILE__ . "\nline: " . __LINE__ . "\n" . $ldap->ldap_last_error;
            return false;
        }
    } else {
        $upd["automountInformation"][] = $pattern;
        if (!$ldap->Ldap_modify($dn, $upd)) {
            echo "function: " . __FUNCTION__ . "\n" . "file: " . __FILE__ . "\nline: " . __LINE__ . "\n" . $ldap->ldap_last_error;
            return false;
        }
    }
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body('{success}');
}
function CheckBranch()
{
    $ldap = new clladp();
    if (!$ldap->ExistsDN("dc=organizations,{$ldap->suffix}")) {
        writelogs("CheckBranch():: creating the new branch dc=organizations,{$ldap->suffix}", __FUNCTION__, __FILE__, __LINE__);
        $upd["objectClass"][] = "top";
        $upd["objectClass"][] = "organization";
        $upd["objectClass"][] = "dcObject";
        $upd["o"][] = "organizations";
        $upd["dc"][] = "organizations";
        if (!$ldap->ldap_add("dc=organizations,{$ldap->suffix}", $upd)) {
            writelogs("Unable to create new entry dc=organizations,{$ldap->suffix}", __FUNCTION__, __FILE__, __LINE__);
            writelogs($ldap->ldap_last_error, __FUNCTION__, __FILE__, __LINE__);
            return false;
        }
        return true;
    } else {
        writelogs("CheckBranch():: The new branch dc=organizations,{$ldap->suffix} exists", __FUNCTION__, __FILE__, __LINE__);
        return true;
    }
}
function CronAddArticaTasksSave()
{
    $task_name = $_GET["CronAddArticaTasksSave"];
    $ldap = new clladp();
    $tpl = new templates();
    $dn = "cn={$task_name},cn=system_cron_task,cn=artica,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        echo $tpl->_ENGINE_parse_body('{error_task_already_exists}');
        exit;
    }
    $cron = new cron();
    $upd['cn'][0] = "{$task_name}";
    $upd['objectClass'][0] = 'ArticaCronDatas';
    $upd['objectClass'][1] = 'top';
    $upd['CronFileCommand'][0] = $cron->array_artica_task[$task_name]["CronFileCommand"];
    $upd['CronFileDescriptions'][0] = $cron->array_artica_task[$task_name]["CronFileDescriptions"];
    $upd['CronFileMailto'][0] = $cron->array_artica_task[$task_name]["CronFileMailto"];
    $upd["CronFileToDelete"][0] = "no";
    $ldap->ldap_add($dn, $upd);
    echo $tpl->_ENGINE_parse_body('{success}');
}
function users_database()
{
    $tpl = new templates();
    $page = CurrentPageName();
    $ou = $_GET["ou"];
    $domain = $_GET["domain"];
    $ldap = new clladp();
    $trusted_smtp_domain = 0;
    $search = $_GET["search"];
    $search = "*" . $_GET["search"] . "*";
    $search = str_replace("**", "*", $search);
    $search = str_replace("*", "%", $search);
    $dn = "cn=@{$_GET["domain"]},cn=relay_recipient_maps,ou={$ou},dc=organizations,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        $trusted_smtp_domain = 1;
    }
    if ($trusted_smtp_domain == 1) {
        $html = "<div class=explain>{DOMAIN_TRUSTED_NO_USERDB_TEXT}</div>";
        echo $tpl->_ENGINE_parse_body($html);
        return;
    }
    $sql = "SELECT `email` FROM postfix_relais_domains_users WHERE\n\t`ou`='{$ou}' AND `domain`='{$domain}'\n\tAND `email` LIKE '{$search}' ORDER BY email LIMIT 0,90";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2>";
    }
    $html = "\n<p>&nbsp;</p>\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<tr>\n\t\t<th width=1%>" . imgtootltip("plus-24.png", "{import}", "ImportUsersRelayDomain()") . "</th>\n\t\t<th>{email}</th>\n\t\t<th>" . imgtootltip("delete-32.png", "{empty_database}", "EmptyUsersRelayDomain()") . "</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>";
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        $html = $html . "\n\t<tr  class={$classtr}>\n\t<td style='font-size:14px;font-weight:bold'><img src=img/fw_bold.gif></td>\n\t<td style='font-size:14px;font-weight:bold'>{$ligne["email"]}</a></td>\n\t<td width=1%>" . imgtootltip("delete-24.png", "{delete}", "POSTFIX_MULTI_INSTANCE_INFOS_DEL('{$ligne["ou"]}','{$ligne["ip_address"]}')") . "</td>\n\t</tR>";
    }
    $html = $html . "</table>\n";
    echo $tpl->_ENGINE_parse_body($html);
    return;
}
Beispiel #18
0
function post_form()
{
    $_POST["email"] = strtolower(trim($_POST["email"]));
    $_POST["password"] = trim($_POST["password"]);
    $tpl = new templates();
    $sock = new sockets();
    $ldap = new clladp();
    $EnableVirtualDomainsInMailBoxes = $sock->GET_INFO("EnableVirtualDomainsInMailBoxes");
    if (!ValidateMail($_POST["email"])) {
        echo "<H2>" . $tpl->_ENGINE_parse_body("{ERROR_INVALID_EMAIL_ADDR}: ({original_mail}:{$_POST["email"]})") . "</H2>";
        exit;
    }
    $domain = trim(strtolower($_POST["domain"]));
    $company = $_POST["company"];
    $password = $_POST["password"];
    $uid = trim(strtolower($_POST["username"]));
    $ou = $_POST["organization"];
    if ($ou == null) {
        $ou = $_POST["company"];
    }
    if ($company == null) {
        echo $tpl->_ENGINE_parse_body("<H2>{company}:{ERROR_VALUE_MISSING_PLEASE_FILL_THE_FORM}</H2>");
        exit;
    }
    if ($password == null) {
        echo $tpl->_ENGINE_parse_body("<H2>{password}:{ERROR_VALUE_MISSING_PLEASE_FILL_THE_FORM}</H2>");
        exit;
    }
    if ($_POST["domain"] == null) {
        echo $tpl->_ENGINE_parse_body("<H2>{domain}:{ERROR_VALUE_MISSING_PLEASE_FILL_THE_FORM}</H2>");
        exit;
    }
    if ($uid == null) {
        echo $tpl->_ENGINE_parse_body("<H2>{username}:{ERROR_VALUE_MISSING_PLEASE_FILL_THE_FORM}</H2>");
        exit;
    }
    if (isset($_POST["subdomain"])) {
        $_POST["subdomain"] = trim(strtolower($_POST["subdomain"]));
        if ($_POST["subdomain"] == null) {
            echo $tpl->_ENGINE_parse_body("<H2>{subdomain}:{ERROR_VALUE_MISSING_PLEASE_FILL_THE_FORM}</H2>");
            exit;
        }
        $domain = $_POST["subdomain"] . ".{$domain}";
    }
    $hashdoms = $ldap->hash_get_all_domains();
    if ($hashdoms[$domain] != null) {
        echo $tpl->_ENGINE_parse_body("<H2>{error_domain_exists} &raquo;<strong>{$domain}</strong></H2");
        exit;
    }
    $ou = $ldap->StripSpecialsChars($ou);
    $uid = $ldap->StripSpecialsChars($uid);
    if ($ou == "users") {
        echo "<H2>Error: Adding\n{$ou} words not permitted\n</H2>";
        exit;
    }
    if ($ou == "groups") {
        echo "<H2>Error: Adding\n{$ou} words not permitted\n</H2>";
        exit;
    }
    if ($ou == "computers") {
        echo "<H2>Error: Adding\n{$ou} words not permitted\n</H2>";
        exit;
    }
    if ($ou == "pureftpd") {
        echo "<H2>Error: Adding\n{$ou} words not permitted\n</H2>";
        exit;
    }
    $ldap = new clladp();
    $dn = "ou={$ou},dc=organizations,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        echo $tpl->_ENGINE_parse_body("<H2>{organization}:{ERROR_OBJECT_ALREADY_EXISTS}</H2>");
        exit;
    }
    if ($EnableVirtualDomainsInMailBoxes == 1) {
        $uidtests = "{$uid}@{$domain}";
        $u = new user($uidtests);
        if (!$u->DoesNotExists) {
            echo $tpl->_ENGINE_parse_body("<H2>{member}: &laquo;{$uid}&raquo; {ERROR_OBJECT_ALREADY_EXISTS}</H2>");
            exit;
        }
    }
    $u = new user($uid);
    if (!$u->DoesNotExists) {
        echo $tpl->_ENGINE_parse_body("<H2>{member}: &laquo;{$uid}&raquo; {ERROR_OBJECT_ALREADY_EXISTS}</H2>");
        exit;
    }
    $zmd5 = md5("{$_POST["email"]}{$ou}{$company}{$domain}{$uid}");
    $password = addslashes($password);
    $company = addslashes($company);
    $uid = addslashes($uid);
    $sql = "INSERT IGNORE INTO register_orgs(`email`,`ou`,`company`,`domain`,`username`,`password`,`zmd5`)\n\tVALUES('{$_POST["email"]}','{$ou}','{$company}','{$domain}','{$uid}','{$password}','{$zmd5}')\n\t";
    $q = new mysql();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2>";
        return;
    }
    $prefix = "http://";
    if ($_SERVER["HTTPS"] == "on") {
        $prefix = "https://";
    }
    $link = $prefix . $_SERVER["HTTP_HOST"] . '/' . CurrentPageName() . "?confirm={$zmd5}";
    $subject = $tpl->javascript_parse_text("{organization}: {$ou} {register_form}");
    $message = "{sendmail_request_form}\n----------------------\n{$link}\n----------------------\n";
    $RobotInternetUsers = $sock->GET_INFO("RobotInternetUsers");
    if ($RobotInternetUsers == null) {
        $RobotInternetUsers = "postmaster@{$user->fqdn}";
    }
    $email = $_POST["email"];
    mail($email, "{$subject}", $message, "From:" . $RobotInternetUsers);
    echo "<H2>" . $tpl->_ENGINE_parse_body("{thanks_registration_mail} <strong>{$email}</strong>");
}
function smtpd_client_restrictions_save()
{
    $ldap = new clladp();
    if (!$ldap->ExistsDN("cn=restrictions_classes,cn=artica,{$ldap->suffix}")) {
        $upd["objectClass"][] = "top";
        $upd["objectClass"][] = "top";
        $upd["objectClass"][] = "PostFixStructuralClass";
        $upd["cn"][0] = "restrictions_classes";
        if (!$ldap->ldap_add("cn=restrictions_classes,cn=artica,{$ldap->suffix}", $upd)) {
            echo "cn=restrictions_classes,cn=artica,{$ldap->suffix}\n{$ldap->ldap_last_error}";
            return null;
        }
    }
    if ($ldap->ExistsDN("cn=smtpd_client_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}")) {
        $ldap->ldap_delete("cn=smtpd_client_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}", false);
        $upd1["objectClass"][] = "top";
        $upd1["objectClass"][] = "PostFixRestrictionStandardClasses";
        $upd1["cn"][0] = "smtpd_client_restrictions";
        if (!$ldap->ldap_add("cn=smtpd_client_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}", $upd1)) {
            echo "Modify smtpd_client_restrictions branch\n{$ldap->ldap_last_error}";
            return null;
        }
    }
    unset($upd1);
    if ($ldap->ExistsDN("cn=smtpd_helo_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}")) {
        $ldap->ldap_delete("cn=smtpd_helo_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}", false);
    }
    if (!$ldap->ExistsDN("cn=smtpd_helo_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}")) {
        $upd1["objectClass"][] = "top";
        $upd1["objectClass"][] = "PostFixRestrictionStandardClasses";
        $upd1["cn"][0] = "smtpd_helo_restrictions";
        if (!$ldap->ldap_add("cn=smtpd_helo_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}", $upd1)) {
            echo "Modify smtpd_helo_restrictions branch\n{$ldap->ldap_last_error}";
            return null;
        }
    }
    $EnablePostfixAntispamPack = $_GET["EnablePostfixAntispamPack"];
    $upd_vals["PostFixRestrictionClassList"][] = "permit_mynetworks=\"\"";
    $upd_vals["PostFixRestrictionClassList"][] = "permit_sasl_authenticated=\"\"";
    $upd_vals["PostFixRestrictionClassList"][] = "check_client_access=\"hash:/etc/postfix/postfix_allowed_connections\"";
    if ($_GET["reject_unknown_client_hostname"] == 1) {
        $upd_vals["PostFixRestrictionClassList"][] = "reject_unknown_client_hostname=\"\"";
    }
    if ($_GET["reject_invalid_hostname"] == 1) {
        $upd_vals["PostFixRestrictionClassList"][] = "reject_invalid_hostname=\"\"";
    }
    if ($_GET["reject_unknown_reverse_client_hostname"] == 1) {
        $upd_vals["PostFixRestrictionClassList"][] = "reject_unknown_reverse_client_hostname=\"\"";
    }
    if ($_GET["reject_unknown_sender_domain"] == 1) {
        $upd_vals["PostFixRestrictionClassList"][] = "reject_unknown_sender_domain=\"\"";
    }
    if ($_GET["reject_non_fqdn_sender"] == 1) {
        $upd_vals["PostFixRestrictionClassList"][] = "reject_non_fqdn_sender=\"\"";
    }
    if ($EnablePostfixAntispamPack == 1) {
        $upd_vals["PostFixRestrictionClassList"][] = "reject_rbl_client=\"zen.spamhaus.org\"";
        $upd_vals["PostFixRestrictionClassList"][] = "reject_rbl_client=\"sbl.spamhaus.org\"";
        $upd_vals["PostFixRestrictionClassList"][] = "reject_rbl_client=\"cbl.abuseat.org\"";
    }
    $upd_vals["PostFixRestrictionClassList"][] = "permit=\"\"";
    $sock = new sockets();
    $sock->SET_INFO('EnablePostfixAntispamPack', $EnablePostfixAntispamPack);
    $sock->SET_INFO('reject_forged_mails', $_GET["reject_forged_mails"]);
    if (!$ldap->Ldap_modify("cn=smtpd_client_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}", $upd_vals)) {
        echo "Modify smtpd_client_restrictions branch\n{$ldap->ldap_last_error}";
        return null;
    }
    unset($upd_vals);
    if ($EnablePostfixAntispamPack == 1) {
        $upd_vals["PostFixRestrictionClassList"][] = "permit_mynetworks=\"\"";
        $upd_vals["PostFixRestrictionClassList"][] = "permit_sasl_authenticated=\"\"";
        $upd_vals["PostFixRestrictionClassList"][] = "check_client_access=\"hash:/etc/postfix/postfix_allowed_connections\"";
        $upd_vals["PostFixRestrictionClassList"][] = "reject_non_fqdn_hostname=\"\"";
        $upd_vals["PostFixRestrictionClassList"][] = "reject_invalid_hostname=\"\"";
        $upd_vals["PostFixRestrictionClassList"][] = "permit=\"\"";
        if (!$ldap->Ldap_modify("cn=smtpd_helo_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}", $upd_vals)) {
            echo "Modify datas in smtpd_helo_restrictions branch\n{$ldap->ldap_last_error}";
            return null;
        }
    }
    $main = new main_cf();
    $main->save_conf_to_server(1);
    $sock = new sockets();
    $tpl = new templates();
    $sock->getFrameWork("cmd.php?reconfigure-postfix=yes");
}
function autofs_connect()
{
    $auto = new autofs();
    $ldap = new clladp();
    $sock = new sockets();
    $_GET["LOCAL_DIR"] = strtolower($ldap->StripSpecialsChars($_GET["LOCAL_DIR"]));
    $upd = array();
    $dn = "cn={$_GET["LOCAL_DIR"]},ou=auto.automounts,ou=mounts,{$ldap->suffix}";
    if ($_GET["fs"] == null) {
        $prefix_pattern = "-fstype=auto,check=none,noatime";
    }
    if ($_GET["fs"] == "ext2") {
        $prefix_pattern = "-fstype=ext2,check=none,noatime";
    }
    if ($_GET["fs"] == "ext3") {
        $prefix_pattern = "-fstype=ext3,check=none,noatime,nodiratime,data=journal,user";
    }
    if ($_GET["fs"] == "ext4") {
        $prefix_pattern = "-fstype=ext4,check=none,noatime,commit=60,nodiratime,data=journal,user";
    }
    if ($_GET["fs"] == "vfat") {
        $prefix_pattern = "-fstype=vfat,uid=1000,gid=1010";
    }
    if ($_GET["fs"] == "ntfs") {
        $prefix_pattern = "-fstype=ntfs-3g,uid=1000,gid=1010";
    }
    if ($prefix_pattern == null) {
        $prefix_pattern = "-fstype=auto,check=none,noatime";
    }
    $pattern = "{$prefix_pattern} :{$_GET["dev"]}";
    if (!$ldap->ExistsDN($dn)) {
        $upd["ObjectClass"][] = 'top';
        $upd["ObjectClass"][] = 'automount';
        $upd["cn"][] = "{$_GET["LOCAL_DIR"]}";
        $upd["automountInformation"][] = $pattern;
        if (!$ldap->ldap_add($dn, $upd)) {
            echo "function: " . __FUNCTION__ . "\n" . "file: " . __FILE__ . "\nline: " . __LINE__ . "\n" . $ldap->ldap_last_error;
            return;
        }
        $sock->getFrameWork("cmd.php?autofs-reload=yes");
        return;
    }
    $upd["automountInformation"][] = $pattern;
    if (!$ldap->Ldap_modify($dn, $upd)) {
        echo "function: " . __FUNCTION__ . "\n" . "file: " . __FILE__ . "\nline: " . __LINE__ . "\n" . $ldap->ldap_last_error;
        return false;
    }
    $sock->getFrameWork("cmd.php?autofs-reload=yes");
}
}
$file = base64_decode($argv[1]);
$GLOBALS["OU"] = base64_decode($argv[2]);
$ou = $GLOBALS["OU"];
if ($GLOBALS["VERBOSE"]) {
    echo "file:{$file} ou:{$ou}\n";
}
if (!is_file($file)) {
    events("{$file}, no such file", 100);
    die;
}
$tbl = @explode("\n", @file_get_contents($file));
$ldap = new clladp();
$hashdoms = $ldap->hash_get_all_domains();
$dn = "cn=relay_domains,ou={$ou},dc=organizations,{$ldap->suffix}";
if (!$ldap->ExistsDN($dn)) {
    $upd['cn'][0] = "relay_domains";
    $upd['objectClass'][0] = 'PostFixStructuralClass';
    $upd['objectClass'][1] = 'top';
    if (!$ldap->ldap_add($dn, $upd)) {
        events("{$dn}: {$ldap->ldap_last_error}", 100);
        die;
    }
    unset($upd);
}
$dn = "cn=relay_recipient_maps,ou={$ou},dc=organizations,{$ldap->suffix}";
if (!$ldap->ExistsDN($dn)) {
    $upd['cn'][0] = "relay_recipient_maps";
    $upd['objectClass'][0] = 'PostFixStructuralClass';
    $upd['objectClass'][1] = 'top';
    if (!$ldap->ldap_add($dn, $upd)) {
function USER_ADD()
{
    $userid = $_GET["new_userid"];
    $password = $_GET["password"];
    $group_id = $_GET["group_id"];
    $tpl = new templates();
    $email = $_GET["email"] . "@" . $_GET["user_domain"];
    $user = new usersMenus();
    if ($user->EnableVirtualDomainsInMailBoxes == 1) {
        writelogs("Adding change {$userid} to \"{$email}\" in group {$group_id}", __FUNCTION__, __FILE__, __LINE__);
        $userid = $email;
    }
    $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 = $_GET["email"] . "@" . $_GET["user_domain"];
    $ou = $_GET["ou"];
    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 ($group_id == null) {
        $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 ($group_id == null) {
            $group_id = 0;
        }
    }
    $emT = explode('@', $email);
    //Verify domains --------------------------------------------------------------- 2008 10 05,P3
    $hash_domains_table = $ldap->hash_get_domains_ou($ou);
    if ($hash_domains_table[$_GET["user_domain"]] == null) {
        writelogs("{$userid} have no domains", __FUNCTION__, __FILE__, __LINE__);
        writelogs("Create a new local domain by default", __FUNCTION__, __FILE__, __LINE__);
        $ldap->AddDomainEntity($ou, $_GET["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 = $_GET["user_domain"];
    if ($password != null) {
        $users->password = $password;
    }
    $users->ou = $ou;
    if ($domains[$_GET["user_domain"]] == true) {
        writelogs("is a local domain {$_GET["user_domain"]}={$domains[$_GET["user_domain"]]}", __FUNCTION__, __FILE__, __LINE__);
        $upd["ObjectClass"][] = 'ArticaSettings';
        $users->MailboxActive = "TRUE";
    }
    if (!$users->add_user()) {
        echo "ERROR:" . $users->ldap_error;
        exit;
    }
    if ($group_id > 0) {
        $ldap->AddUserToGroup($group_id, $users->uid);
    }
    echo $users->uid;
}
Beispiel #23
0
 function Parse()
 {
     $ldap = new clladp();
     if (!$ldap->ExistsDN($this->dn)) {
         $upd["objectClass"][] = 'top';
         $upd["objectClass"][] = 'ArticaOuBigMailHTML';
         $upd["cn"][] = "html_blocker";
         $upd["BigMailHTMLEnabled"][] = 'no';
         $upd["BigMailHtmlConfig"][] = 'NONE';
         $upd["BigMailHtmlBody"][] = "original Attached files of this message are stored \nOn our server.You can download them by clicking on link at the bottom of this email";
         $ldap->ldap_add($this->dn, $upd);
     }
     $res = @ldap_read($ldap->ldap_connection, $this->dn, "(objectClass=ArticaOuBigMailHTML)", array());
     if ($res) {
         $hash = ldap_get_entries($ldap->ldap_connection, $res);
         $this->BigMailHTMLEnabled = $hash[0][strtolower('BigMailHTMLEnabled')][0];
         $this->BigMailHtmlConfig = $hash[0][strtolower('BigMailHtmlConfig')][0];
         if (!isset($hash[0][strtolower('BigMailHtmlBody')])) {
             $upd["BigMailHtmlBody"][] = "<b style='color:red'>original Attached files of this message are stored \n\t\t\t\t\t\t\t\t\t\t\ton our server<br>You can download them by clicking on link at the bottom of this email</b>";
             $ldap->Ldap_add_mod($this->dn, $upd);
             unset($upd);
         }
         $this->BigMailHtmlBody = $hash[0][strtolower('BigMailHtmlBody')][0];
         $ini = new Bs_IniHandler();
         $ini->loadString($this->BigMailHtmlConfig);
         $this->params = $ini->_params;
         for ($i = 0; $i < $hash[0][strtolower('BigMailHtmlRules')]["count"]; $i++) {
             $this->ruleslist[] = $hash[0][strtolower('BigMailHtmlRules')][$i];
         }
     }
 }
Beispiel #24
0
function check_client_access_add()
{
    $ip = $_GET["check_client_access_add"];
    $tpl = new templates();
    $ldap = new clladp();
    if (!$ldap->ExistsDN("cn=restrictions_classes,cn=artica,{$ldap->suffix}")) {
        $upd["objectClass"][] = 'top';
        $upd["objectClass"][] = 'PostFixStructuralClass';
        $upd["cn"] = "restrictions_classes";
        $ldap->ldap_add("cn=restrictions_classes,cn=artica,{$ldap->suffix}", $upd);
        unset($upd);
    }
    if (!$ldap->ExistsDN("cn=smtpd_client_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}")) {
        $upd["objectClass"][] = 'top';
        $upd["objectClass"][] = 'PostFixRestrictionStandardClasses';
        $upd["PostFixRestrictionClassDescription"][] = "bann ip addresses";
        $upd["PostFixRestrictionClassList"][] = 'check_client_access="ldap"';
        $upd["cn"] = "smtpd_client_restrictions";
        $ldap->ldap_add("cn=smtpd_client_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}", $upd);
        unset($upd);
    }
    $dn = "cn=check_client_access,cn=smtpd_client_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd["objectClass"][] = 'top';
        $upd["objectClass"][] = 'PostFixStructuralClass';
        $upd["cn"] = "check_client_access";
        $ldap->ldap_add($dn, $upd);
        unset($upd);
    }
    $dn = "cn={$ip},cn=check_client_access,cn=smtpd_client_restrictions,cn=restrictions_classes,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd["objectClass"][] = 'top';
        $upd["objectClass"][] = 'PostFixRestrictionCheckAccess';
        $upd["PostFixRestrictionTableAction"][] = 'REJECT';
        $upd["cn"] = "{$ip}";
        if (!$ldap->ldap_add($dn, $upd)) {
            echo "{$ip}\n{$ldap->ldap_last_error}\n";
        } else {
            echo $tpl->_ENGINE_parse_body("{$ip}:{success}");
        }
        unset($upd);
    }
}
function DeleteGroup()
{
    if (isset($_GET["DeleteGroup"])) {
        $gpid = $_GET["DeleteGroup"];
    }
    if (isset($_GET["delgroup"])) {
        $gpid = $_GET["delgroup"];
    }
    $ou = $_GET["ou"];
    $ldap = new clladp();
    $tpl = new templates();
    $classGroup = new groups($gpid);
    $hashgroup = $ldap->GroupDatas($gpid);
    $default_dn_nogroup = "cn=nogroup,ou=groups,ou={$ou},dc=organizations,{$ldap->suffix}";
    if (!$ldap->ExistsDN($default_dn_nogroup)) {
        $ldap->AddGroup("nogroup", $ou);
    }
    $nogroup_id = $ldap->GroupIDFromName($ou, "nogroup");
    if (is_array($hashgroup["members"])) {
        while (list($num, $val) = each($hashgroup["members"])) {
            $ldap->AddUserToGroup($nogroup_id, $num);
        }
    }
    $users = new usersMenus();
    if ($users->KAV_MILTER_INSTALLED) {
        $sock = new sockets();
        $sock->getfile("KavMilterDeleteRule:{$classGroup->groupName}.{$classGroup->ou}");
    }
    $kas_dn = "cn={$gpid},cn=kaspersky Antispam 3 rules,cn=artica,{$ldap->suffix}";
    if ($ldap->ExistsDN($kas_dn)) {
        $ldap->ldap_delete($kas_dn, false);
    }
    $ldap->ldap_delete($hashgroup["dn"], false);
    if ($ldap->ldap_last_error != null) {
        echo $ldap->ldap_last_error;
    } else {
        echo $tpl->_ENGINE_parse_body('{success}');
    }
}
Beispiel #26
0
function BuildRobots()
{
    $ldap = new clladp();
    $dn = "cn=PostfixRobots,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd['cn'][0] = "PostfixRobots";
        $upd['objectClass'][0] = 'PostFixStructuralClass';
        $upd['objectClass'][1] = 'top';
        if (!$ldap->ldap_add($dn, $upd)) {
            echo $ldap->ldap_last_error;
        }
        unset($upd);
    }
    $dn = "cn=artica,cn=PostfixRobots,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd['cn'][0] = "artica";
        $upd['objectClass'][0] = 'PostFixStructuralClass';
        $upd['objectClass'][1] = 'top';
        if (!$ldap->ldap_add($dn, $upd)) {
            echo $ldap->ldap_last_error;
        }
        unset($upd);
    }
    $dn = "cn=xspam@localhost.localdomain,cn=artica,cn=PostfixRobots,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd['cn'][0] = "*****@*****.**";
        $upd['objectClass'][0] = 'transportTable';
        $upd['objectClass'][1] = 'top';
        $upd["transport"][0] = "artica-spam:xspam@localhost.localdomain";
        if (!$ldap->ldap_add($dn, $upd)) {
            echo $ldap->ldap_last_error;
        }
        unset($upd);
    }
    $dn = "cn=relay_domains,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd['cn'][0] = "relay_domains";
        $upd['objectClass'][0] = 'PostFixStructuralClass';
        $upd['objectClass'][1] = 'top';
        if (!$ldap->ldap_add($dn, $upd)) {
            echo $ldap->ldap_last_error;
        }
        unset($upd);
    }
    $dn = "cn=relay_recipient_maps,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd['cn'][0] = "relay_recipient_maps";
        $upd['objectClass'][0] = 'PostFixStructuralClass';
        $upd['objectClass'][1] = 'top';
        if (!$ldap->ldap_add($dn, $upd)) {
            echo $ldap->ldap_last_error;
        }
        unset($upd);
    }
    $dn = "cn=localhost.localdomain,cn=relay_domains,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd['cn'][0] = "localhost.localdomain";
        $upd['objectClass'][0] = 'PostFixRelayDomains';
        $upd['objectClass'][1] = 'top';
        if (!$ldap->ldap_add($dn, $upd)) {
            echo $ldap->ldap_last_error;
        }
        unset($upd);
    }
    $dn = "cn=@localhost.localdomain,cn=relay_recipient_maps,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd['cn'][0] = "@localhost.localdomain";
        $upd['objectClass'][0] = 'PostfixRelayRecipientMaps';
        $upd['objectClass'][1] = 'top';
        if (!$ldap->ldap_add($dn, $upd)) {
            echo $ldap->ldap_last_error;
        }
        unset($upd);
    }
    $dn = "cn=transport_map,cn=artica,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd['cn'][0] = "transport_map";
        $upd['objectClass'][0] = 'PostFixStructuralClass';
        $upd['objectClass'][1] = 'top';
        $ldap->ldap_add($dn, $upd);
        unset($upd);
    }
    $dn = "cn=localhost.localdomain,cn=transport_map,cn=artica,{$ldap->suffix}";
    $upd['cn'][0] = "localhost.localdomain";
    $upd['objectClass'][0] = 'transportTable';
    $upd['objectClass'][1] = 'top';
    $upd["transport"][] = "artica-spam:xspam@localhost.localdomain";
    $ldap->ldap_add($dn, $upd);
    unset($upd);
}
function EditRelayDomain()
{
    $relayIP = $_GET["EditRelayDomainIP"];
    $relayPort = $_GET["EditRelayDomainPort"];
    $domain_name = $_GET["EditRelayDomainName"];
    $MX = $_GET["MX"];
    $ldap = new clladp();
    $ou = $_GET["ou"];
    $autoaliases = $_GET["autoaliases"];
    $trusted_smtp_domain = $_GET["trusted_smtp_domain"];
    $auto = new AutoAliases($ou);
    if ($autoaliases == "yes") {
        $auto->DomainsArray[$domain_name] = $domain_name;
    } else {
        unset($auto->DomainsArray[$domain_name]);
    }
    $auto->Save();
    writelogs("saving relay:{$relayIP}:{$relayPort} trusted_smtp_domain={$trusted_smtp_domain}", __FUNCTION__, __FILE__, __LINE__);
    $dn = "cn=transport_map,ou={$ou},dc=organizations,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd = array();
        $upd['cn'][0] = "transport_map";
        $upd['objectClass'][0] = 'PostFixStructuralClass';
        $upd['objectClass'][1] = 'top';
        $ldap->ldap_add($dn, $upd);
        unset($upd);
    }
    if ($MX == "no") {
        $relayIP = "[{$relayIP}]";
    }
    $dn = "cn={$domain_name},cn=transport_map,ou={$ou},dc=organizations,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        $ldap->ldap_delete($dn);
    }
    writelogs("Create {$dn}", __FUNCTION__, __FILE__);
    $upd = array();
    $upd['cn'][0] = "{$domain_name}";
    $upd['objectClass'][0] = 'transportTable';
    $upd['objectClass'][1] = 'top';
    $upd["transport"][] = "relay:{$relayIP}:{$relayPort}";
    if (!$ldap->ldap_add($dn, $upd)) {
        echo "Error\n" . "Line: " . __LINE__ . "\n{$ldap->ldap_last_error}";
        return;
    }
    unset($upd);
    $dn = "cn=relay_recipient_maps,ou={$ou},dc=organizations,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $upd = array();
        $upd['cn'][0] = "relay_recipient_maps";
        $upd['objectClass'][0] = 'PostFixStructuralClass';
        $upd['objectClass'][1] = 'top';
        if (!$ldap->ldap_add($dn, $upd)) {
            echo "Error\n" . "Line: " . __LINE__ . "\n{$ldap->ldap_last_error}";
            return;
        }
        unset($upd);
    }
    $dn = "cn=@{$domain_name},cn=relay_recipient_maps,ou={$ou},dc=organizations,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        $ldap->ldap_delete($dn);
    }
    if ($trusted_smtp_domain == 1) {
        $upd = array();
        $upd['cn'][0] = "@{$domain_name}";
        $upd['objectClass'][0] = 'PostfixRelayRecipientMaps';
        $upd['objectClass'][1] = 'top';
        if (!$ldap->ldap_add($dn, $upd)) {
            echo "Error\n" . "Line: " . __LINE__ . "\n{$ldap->ldap_last_error}";
            return;
        }
    }
    $sock = new sockets();
    $usr = new usersMenus();
    $sock->getFrameWork("cmd.php?postfix-transport-maps=yes");
}
function ExportOuDN($ou)
{
    $unix = new unix();
    $ldap = new clladp();
    $slapcat = $unix->find_program("slapcat");
    $ldapadd = $unix->find_program("ldapadd");
    $devnull = " >/dev/null 2>&1";
    @mkdir("/usr/share/artica-postfix/ressources/ldap-back/{$ou}", null, true);
    $dn = "ou={$ou},dc=organizations,{$ldap->suffix}";
    $tmpfile = "/usr/share/artica-postfix/ressources/ldap-back/{$ou}/backup.ldif";
    $cmd = "{$slapcat} -a \"(&(entryDN:dnSubtreeMatch:={$dn}))\" -l {$tmpfile} {$devnull}";
    echo "ExportOuDN():: Running {$cmd}\n";
    system($cmd);
    $dntemp = file_get_contents($tmpfile);
    $dn = "cn={$ou},cn=PostfixRobots,cn=artica,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        $cmd = "{$slapcat} -a \"(&(entryDN:dnSubtreeMatch:={$dn}))\" -l {$tmpfile} {$devnull}";
        echo "ExportOuDN():: Running {$cmd}\n";
        system($cmd);
        $dntemp = $dntemp . "\n" . file_get_contents($tmpfile);
    }
    $dn = "cn={$ou},cn=catch-all,cn=artica,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        $cmd = "{$slapcat} -a \"(&(entryDN:dnSubtreeMatch:={$dn}))\" -l {$tmpfile} {$devnull}";
        echo "ExportOuDN():: Running {$cmd}\n";
        system($cmd);
        $dntemp = $dntemp . "\n" . file_get_contents($tmpfile);
    }
    $dn = "dc={$ou},dc=NAB,{$ldap->suffix}";
    if ($ldap->ExistsDN($dn)) {
        $cmd = "{$slapcat} -a \"(&(entryDN:dnSubtreeMatch:={$dn}))\" -l {$tmpfile} {$devnull}";
        echo "ExportOuDN():: Running {$cmd}\n";
        system($cmd);
        $dntemp = $dntemp . "\n" . file_get_contents($tmpfile);
    }
    echo "ExportOuDN():: Saving {$tmpfile}\n";
    file_put_contents($tmpfile, $dntemp);
}
function add_domain()
{
    $domain = $_GET["add_domain"];
    $ou = $_GET["ou"];
    $tpl = new templates();
    $ldap = new clladp();
    $dn = "cn={$domain},cn=blackListedDomains,ou={$ou},dc=organizations,{$ldap->suffix}";
    if (!$ldap->ExistsDN($dn)) {
        $update_array["cn"][] = $domain;
        $update_array["objectClass"][] = 'DomainsBlackListOu';
        $update_array["objectClass"][] = 'top';
        if (!$ldap->ldap_add($dn, $update_array)) {
            echo $tpl->_ENGINE_parse_body("{$domain} -> {failed}\n{$ldap->ldap_last_error}");
        } else {
            echo $tpl->_ENGINE_parse_body('{success}');
        }
    } else {
        echo $tpl->_ENGINE_parse_body('{success}');
    }
}
Beispiel #30
0
function remove($servername)
{
    $apache = new vhosts();
    $GLOBALS["ADDLOG"] = "{$GLOBALS["ARTICALOGDIR"]}/{$servername}.log";
    $confs = $apache->SearchHosts($servername);
    events(__FUNCTION__ . ":: Check {$servername}");
    events(__FUNCTION__ . ":: remove files and directories");
    if (is_dir("/usr/share/artica-groupware/domains/{$servername}")) {
        shell_exec("/bin/rm -rf /usr/share/artica-groupware/domains/{$servername}");
    }
    $server_database = str_replace(" ", "_", $servername);
    $server_database = str_replace(".", "_", $servername);
    $server_database = str_replace("-", "_", $server_database);
    $q = new mysql();
    if ($q->DATABASE_EXISTS($server_database)) {
        $q->DELETE_DATABASE($server_database);
    }
    $flaseuser["root"] = true;
    $flaseuser["admin"] = true;
    $flaseuser["manager"] = true;
    $sql = "DELETE FROM `mysql`.`db` WHERE `db`.`Db` = '{$server_database}'";
    $q->QUERY_SQL($sql, "mysql");
    events(__FUNCTION__ . ":: removing ldap branch {$confs["dn"]}");
    $ldap = new clladp();
    if ($ldap->ExistsDN($confs["dn"])) {
        $ldap->ldap_delete($confs["dn"]);
    }
    events(__FUNCTION__ . ":: restarting HTTP service...");
    shell_exec("/etc/init.d/artica-postfix restart apache-groupware &");
}