Exemplo n.º 1
0
function RelayCountryPlugin()
{
    $user = new usersMenus();
    CleanConf($user->spamassassin_conf_path);
    if (!$user->spamassassin_ipcountry) {
        write_syslog("wants  to add IP countries but IP::Country::Fast is not installed.", __FILE__);
        return null;
    }
    $spam = new spamassassin();
    $RelayCountryPlugin_path = dirname($user->spamassassin_conf_path) . "/RelayCountryPlugin.cf";
    $init_pre = dirname($user->spamassassin_conf_path) . "/init.pre";
    if (is_array($spam->main_country)) {
        while (list($country_code, $array) = each($spam->main_country)) {
            if (trim($country_code) == null) {
                continue;
            }
            $count = $count + 1;
            $conf = $conf . "header\tRELAYCOUNTRY_{$country_code} X-Relay-Countries =~ /{$country_code}/\n";
            $conf = $conf . "describe        RELAYCOUNTRY_{$country_code} Relayed through {$array["country_name"]}\n";
            $conf = $conf . "score           RELAYCOUNTRY_{$country_code} {$array["score"]}\n\n";
        }
    }
    file_put_contents($RelayCountryPlugin_path, $conf);
    write_syslog("Saved {$count} Countries into spamassassin configuration", __FILE__);
    if ($count > 1) {
        $file = file_get_contents($user->spamassassin_conf_path);
        $file = $file . "\n##### Relay Countries\ninclude\t{$RelayCountryPlugin_path}\n";
        $file = $file . "add_header all Relay-Country _RELAYCOUNTRY_\n\n";
        file_put_contents($user->spamassassin_conf_path, $file);
        $file = null;
        $file = file_get_contents($init_pre);
        $file = $file . "\nloadplugin\tMail::SpamAssassin::Plugin::RelayCountry\n";
        file_put_contents($init_pre, $file);
    }
}
function BuildDayTable()
{
    $q = new mysql();
    $q->BuildTables();
    if (!$q->TABLE_EXISTS('smtp_logs_day', 'artica_events')) {
        send_email_events("Mysql error on smtp_logs_day table", "Artica was unable to create or detect smtp_logs_day table...", "system");
        return false;
    }
    $today = date('Y-m-d');
    $sql = "SELECT COUNT(id) as tcount,delivery_domain,DATE_FORMAT(time_stamp,'%Y-%m-%d') as tdate,bounce_error FROM \n\tsmtp_logs \n\tGROUP BY delivery_domain,tdate,bounce_error HAVING tdate<'{$today}' ORDER BY tdate DESC";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo "Wrong sql query {$q->mysql_error}\n";
        write_syslog("Wrong sql query {$q->mysql_error}", __FILE__);
        return false;
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $count = $count + 1;
        $emails = $ligne["tcount"];
        $delivery_domain = $ligne["delivery_domain"];
        $date = $ligne["tdate"];
        $bounce_error = $ligne["bounce_error"];
        $md5 = md5($delivery_domain . $date . $bounce_error . $emails);
        $sql = "INSERT INTO smtp_logs_day (`key`,`day`,`delivery_domain`,`bounce_error`,`emails`)\n\t\tVALUES('{$md5}','{$date}','{$delivery_domain}','{$bounce_error}','{$emails}')";
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            echo "Wrong sql query {$q->mysql_error}\n";
            write_syslog("Wrong sql query \"{$sql}\" {$q->mysql_error}", __FILE__);
            return false;
        }
    }
    return true;
}
Exemplo n.º 3
0
function RoundRobin()
{
    $filename = "/etc/artica-postfix/settings/Daemons/RoundRobinHosts";
    if (!is_file($filename)) {
        write_syslog("no round robin servers set", __FILE__);
    }
    RoundRobinClean();
    RoundRobinClean();
    $ini = new Bs_IniHandler($filename);
    if (!is_array($ini->_params)) {
        return null;
    }
    while (list($num, $ligne) = each($ini->_params)) {
        if ($num == null) {
            continue;
        }
        if ($ini->_params[$num]["IP"] != null) {
            $ips = explode(",", $ini->_params[$num]["IP"]);
            $server = $ini->_params[$num]["servername"];
            $array = RoundRobinIncrement($ips, $server, $array);
        }
    }
    if (is_array($array)) {
        $hosts = file_get_contents("/etc/hosts");
        $hosts = str_replace("\n\n", "\n", $hosts);
        $hosts = $hosts . "\n";
        $hosts = $hosts . "# Round Robin (added by Artica) dont touch this line !!...\n";
        $hosts = $hosts . implode("\n", $array);
        $hosts = $hosts . "\n";
        $hosts = $hosts . "# EOF Round Robin (added by Artica) dont touch this line !...\n";
        @file_put_contents("/etc/hosts", $hosts);
    }
}
Exemplo n.º 4
0
function RoundRobinClean()
{
    $DisableEtcHosts = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableEtcHosts"));
    if ($DisableEtcHosts == 1) {
        write_syslog("Unable to open /etc/hosts, DisableEtcHosts is active aborting", __FILE__);
        return;
    }
    $datas = @file_get_contents("/etc/hosts");
    if (strlen($datas) == 0) {
        return null;
    }
    $tbl = explode("\n", $datas);
    $start = false;
    while (list($num, $ligne) = each($tbl)) {
        if (preg_match("#^\\#.*Round Robin#", $ligne)) {
            $start = true;
            unset($tbl[$num]);
        }
        if ($start) {
            if (preg_match("#^\\#.*EOF#", $ligne)) {
                unset($tbl[$num]);
                break;
            } else {
                unset($tbl[$num]);
            }
        }
    }
    $file = implode("\n", $tbl);
    @file_put_contents("/etc/hosts", $file);
    shell_exec(LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.samba.php --fix-etc-hosts");
}
Exemplo n.º 5
0
function fixdb()
{
    $q = new mysql();
    if (!$q->TABLE_EXISTS('Profile', 'obm2')) {
        write_syslog("Create Profile table in obm2 database", __FILE__);
        $sql = "CREATE TABLE `Profile` (\n\t  `profile_id` int(8) NOT NULL auto_increment,\n\t  `profile_domain_id` int(8) NOT NULL,\n\t  `profile_timeupdate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n\t  `profile_timecreate` timestamp NOT NULL default '0000-00-00 00:00:00',\n\t  `profile_userupdate` int(8) default NULL,\n\t  `profile_usercreate` int(8) default NULL,\n\t  `profile_name` varchar(64) default NULL,\n\t  PRIMARY KEY  (`profile_id`)\n\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "obm2");
    }
    if (!$q->TABLE_EXISTS('ProfileModule', 'obm2')) {
        write_syslog("Create ProfileModule table in obm2 database", __FILE__);
        $sql = "CREATE TABLE `ProfileModule` (\n\t  `profilemodule_id` int(8) NOT NULL auto_increment,\n\t  `profilemodule_domain_id` int(8) NOT NULL,\n\t  `profilemodule_profile_id` int(8) default NULL,\n\t  `profilemodule_module_name` varchar(64) NOT NULL default '',\n\t  `profilemodule_right` int(2) default NULL,\n\t  PRIMARY KEY  (`profilemodule_id`),\n\t  KEY `profilemodule_profile_id_profile_id_fkey` (`profilemodule_profile_id`),\n\t  CONSTRAINT `profilemodule_profile_id_profile_id_fkey` FOREIGN KEY (`profilemodule_profile_id`) REFERENCES `Profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE\n\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "obm2");
    }
    if (!$q->TABLE_EXISTS('ProfileModule', 'obm2')) {
        write_syslog("Create ProfileModule table in obm2 database", __FILE__);
        $sql = "\n\t\tCREATE TABLE `ProfileProperty` (\n\t\t  `profileproperty_id` int(8) NOT NULL auto_increment,\n\t\t  `profileproperty_profile_id` int(8) default NULL,\n\t\t  `profileproperty_name` varchar(32) NOT NULL default '',\n\t\t  `profileproperty_value` text NOT NULL,\n\t\t  PRIMARY KEY  (`profileproperty_id`),\n\t\t  KEY `profileproperty_profile_id_profile_id_fkey` (`profileproperty_profile_id`),\n\t\t  CONSTRAINT `profileproperty_profile_id_profile_id_fkey` FOREIGN KEY (`profileproperty_profile_id`) REFERENCES `Profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "obm2");
    }
}
Exemplo n.º 6
0
function stop($id)
{
    $unix = new unix();
    $sql = "SELECT * FROM imapsync WHERE ID='{$id}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        write_syslog("Mysql error {$q->mysql_error}", __FILE__);
        die;
    }
    $pid_org = $ligne["pid"];
    $ligne["imap_server"] = str_replace(".", "\\.", $ligne["imap_server"]);
    $ligne["username"] = str_replace(".", "\\.", $ligne["username"]);
    exec($unix->find_program("pgrep") . " -f \"imapsync.+?--host1 {$ligne["imap_server"]}.+?--user1 {$ligne["username"]}\"", $pids);
    while (list($index, $pid) = each($pids)) {
        if ($pid > 5) {
            unix_system_kill_force($pid);
        }
    }
    unix_system_kill_force($pid_org);
}
Exemplo n.º 7
0
function CreateThisUser($email)
{
    if (!preg_match("#(.+?)@(.+)#", $email, $re)) {
        return null;
    }
    $domain = $re[2];
    $uid = $re[1];
    $ldap = new clladp();
    $ou = $ldap->ou_by_smtp_domain($domain);
    if ($ou == null) {
        write_syslog("CreateThisUser():: Unable to detect organization by domain \"{$domain}\"", __FILE__);
        return null;
    }
    $ct = new user($uid);
    $ct->ou = $ou;
    $ct->mail = $email;
    $ct->uid = $uid;
    if (!$ct->add_user()) {
        write_syslog("CreateThisUser():: Unable to Create user {$uid} \"{$email}\"", __FILE__);
        return null;
    }
    $uid2 = $ldap->uid_from_email($email);
    write_syslog("CreateThisUser():: new user \"{$uid2}\"", __FILE__);
    return $uid2;
}
Exemplo n.º 8
0
function DeleteCronFilesBackupComputer()
{
    $path = "/etc/cron.d";
    $dir_handle = @opendir($path);
    if (!$dir_handle) {
        write_syslog("Unable to open \"{$path}\"", __FILE__);
        return array();
    }
    $count = 0;
    while ($file = readdir($dir_handle)) {
        if ($file == '.') {
            continue;
        }
        if ($file == '..') {
            continue;
        }
        if (!is_file("{$path}/{$file}")) {
            continue;
        }
        if (preg_match("#artica.+?-bcmp\$#", $file)) {
            events("Deleting cron job {$path}/{$file}");
            @unlink("{$path}/{$file}");
            continue;
        }
    }
    if (!is_array($array)) {
        return array();
    }
    @closedir($dir_handle);
}
Exemplo n.º 9
0
    exit(0);
}
$tbl = explode("\n", file_get_contents("/etc/imapd.conf"));
if (!is_array($tbl)) {
    die;
}
while (list($num, $ligne) = each($tbl)) {
    if (preg_match("#^([a-z0-9\\_\\-]+):(.+)#", $ligne, $re)) {
        $ri[trim($re[1])] = trim($re[2]);
    }
}
if (!is_array($ri)) {
    die;
}
$sock = new sockets();
$CyrusPartitionDefault = $sock->GET_INFO("CyrusPartitionDefault");
if ($ri["partition-default"] == null) {
    $sock = new sockets();
    if ($CyrusPartitionDefault != null) {
        $ri["partition-default"] = $CyrusPartitionDefault;
    } else {
        $ri["partition-default"] = "/var/spool/cyrus/mail";
    }
}
while (list($num, $ligne) = each($ri)) {
    $conf = $conf . "{$num}:{$ligne}\n";
}
echo $conf . "\n";
write_syslog("Cleaning /etc/imapd.conf done with " . strlen($conf) + ' bytes', __FILE__);
file_put_contents("/etc/imapd.conf", $conf);
die;
Exemplo n.º 10
0
include_once dirname(__FILE__) . '/ressources/class.ini.inc';
include_once dirname(__FILE__) . '/ressources/class.user.inc';
include_once dirname(__FILE__) . "/framework/class.unix.inc";
include_once dirname(__FILE__) . "/framework/frame.class.inc";
cpulimit();
if ($argv[1] = '--verbose') {
    $_GET["debug"] = true;
}
if (!Build_pid_func(__FILE__, "MAIN")) {
    writelogs(basename(__FILE__) . ":Already executed.. aborting the process", basename(__FILE__), __FILE__, __LINE__);
    die;
}
$pid = getmypid();
$users = new usersMenus();
if (!$users->GNUPLOT_PNG) {
    write_syslog("gnuplot is not compiled with png support... aborting", __FILE__);
    die;
}
topmem();
topcpu();
function topcpu()
{
    if (!is_file("/var/log/artica-postfix/dstat_topcpu.csv")) {
        events("Processing dstat unable to stat/var/log/artica-postfix/dstat_topcpu.csv");
        return null;
    }
    events("Processing dstat content file /var/log/artica-postfix/dstat_topcpu.csv");
    $content = file_get_contents("/var/log/artica-postfix/dstat_topcpu.csv");
    $content = explode("\n", $content);
    $maxline = count($content);
    events("Processing {$maxline} rows");
Exemplo n.º 11
0
function AddSite($domain){
	$domainMD5=md5($domain);
	
	
if(!$_GET["DD"][$domainMD5]){
		if($_GET["DEBUG"]){echo "Adding site $domain\n";}
		$q=new mysql();
		$sql="INSERT INTO dansguardian_sites(website_md5,website) VALUES('$domainMD5','$domain');";
		echo "Adding domain index $domain\n";
		$q->QUERY_SQL($sql,"artica_events");
		if(!$q->ok){write_syslog("AddSite():: Failed : \"$sql\" ($q->mysql_error)",__FILE__);}
		$_GET["DD"][$domainMD5]=TRUE;
	}else{
	if($_GET["DEBUG"]){echo "$domain already exists in database\n";}	
	}
	
}
Exemplo n.º 12
0
        }
        continue;
    }
    sleep(5);
    $TTLSeconds = $TTL + 5;
    try {
        $PROCESSES_CLASS->ParseLocalQueue();
    } catch (Exception $e) {
        ToSyslog("Fatal while running function ParseLocalQueue {$e}");
    }
    if (is_file("/etc/artica-postfix/ARTICA_STATUS_RELOAD")) {
        ToSyslog("Reloading settings and libraries...");
        Reload();
    }
}
write_syslog("Shutdown after {$TTLSeconds} seconds. stop_server={$stop_server}");
events("!!! STOPPED DAEMON....die()...", "MAIN", __LINE__);
function sig_handler($signo)
{
    global $stop_server;
    global $reload;
    switch ($signo) {
        case SIGTERM:
            $GLOBALS["SHUTDOWN_COUNT"] = $GLOBALS["SHUTDOWN_COUNT"] + 1;
            if ($GLOBALS["SHUTDOWN_COUNT"] > 3) {
                $stop_server = true;
            }
            events("Memory: " . round(memory_get_usage() / 1024 / 1000, 2) . " Asked to shutdown {$GLOBALS["SHUTDOWN_COUNT"]}/3", __FUNCTION__, __LINE__);
            break;
        case 1:
            $reload = true;
Exemplo n.º 13
0
function AddSite($domain)
{
    $domainMD5 = md5($domain);
    if (!$_GET["DD"][$domainMD5]) {
        if ($_GET["DEBUG"]) {
            echo "Adding site {$domain}\n";
        }
        $q = new mysql();
        $sql = "INSERT INTO dansguardian_sites(website_md5,website) VALUES('{$domainMD5}','{$domain}');";
        echo "Adding domain index {$domain}\n";
        $q->QUERY_SQL($sql, "squidlogs");
        if (!$q->ok) {
            write_syslog("AddSite():: Failed : \"{$sql}\" ({$q->mysql_error})", __FILE__);
        }
        $_GET["DD"][$domainMD5] = TRUE;
    } else {
        if ($_GET["DEBUG"]) {
            echo "{$domain} already exists in database\n";
        }
    }
}
Exemplo n.º 14
0
function sync($id)
{
    $unix = new unix();
    $users = new usersMenus();
    write_syslog("Mail synchronization: Running task {$id}", basename(__FILE__));
    $GLOBALS["unique_id"] = $id;
    $ASOfflineImap = false;
    $sql = "SELECT * FROM imapsync WHERE ID='{$id}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        write_syslog("Mysql error {$q->mysql_error}", __FILE__);
        die;
    }
    $pid = $ligne["pid"];
    if ($unix->process_exists($pid)) {
        die;
    }
    update_pid(getmypid());
    if (!is_file($unix->find_program("imapsync"))) {
        update_status(-1, "Could not find imapsync program");
        return;
    }
    update_status(1, "Executed");
    include_once dirname(__FILE__) . '/ressources/class.user.inc';
    $ct = new user($ligne["uid"]);
    $parameters = unserialize(base64_decode($ligne["parameters"]));
    $parameters["sep"] = trim($parameters["sep"]);
    $parameters["sep2"] = trim($parameters["sep2"]);
    $parameters["maxage"] = trim($parameters["maxage"]);
    if ($parameters["maxage"] == null) {
        $parameters["maxage"] = 0;
    }
    if ($parameters["UseOfflineImap"] == 1) {
        $ASOfflineImap = true;
    }
    $offlineImapConf[] = "[general]";
    $offlineImapConf[] = "metadata = /var/lib/offlineimap/{$ligne["uid"]}";
    if ($ASOfflineImap) {
        @mkdir("/var/lib/offlineimap/{$ligne["uid"]}", null, true);
    }
    $offlineImapConf[] = "accounts = Myaccount";
    $offlineImapConf[] = "maxsyncaccounts = 1";
    $offlineImapConf[] = "ui =Noninteractive.Basic, Noninteractive.Quiet";
    $offlineImapConf[] = "ignore-readonly = no";
    $offlineImapConf[] = "socktimeout = 60";
    $offlineImapConf[] = "fsync = true";
    $offlineImapConf[] = "";
    $offlineImapConf[] = "[ui.Curses.Blinkenlights]";
    $offlineImapConf[] = "statuschar = .";
    $offlineImapConf[] = "";
    $offlineImapConf[] = "[Account Myaccount]";
    $offlineImapConf[] = "localrepository = TargetServer";
    $offlineImapConf[] = "remoterepository = SourceServer";
    $offlineImapConf[] = "# autorefresh = 5";
    $offlineImapConf[] = "# quick = 10";
    $offlineImapConf[] = "# presynchook = imapfilter";
    $offlineImapConf[] = "# postsynchook = notifysync.sh";
    $offlineImapConf[] = "# presynchook = imapfilter -c someotherconfig.lua";
    $offlineImapConf[] = "# maxsize = 2000000";
    if ($parameters["maxage"] > 0) {
        $offlineImapConf[] = "maxage = {$parameters["maxage"]}";
    }
    $array_folders = unserialize(base64_decode($ligne["folders"]));
    if ($users->cyrus_imapd_installed) {
        $local_mailbox = true;
    }
    if ($users->ZARAFA_INSTALLED) {
        $local_mailbox = true;
    }
    if ($local_mailbox) {
        if ($parameters["local_mailbox"] == null) {
            $parameters["local_mailbox"] = 1;
        }
        if ($parameters["local_mailbox_source"] == null) {
            $parameters["local_mailbox_source"] = 1;
        }
    } else {
        $parameters["local_mailbox"] = 0;
        $parameters["local_mailbox_source"] = 0;
    }
    if ($parameters["dest_imap_server"] == null) {
        if ($parameters["local_mailbox"] == 1) {
            $parameters["dest_imap_server"] = "127.0.0.1";
        }
    }
    if (!$local_mailbox) {
        if ($parameters["remote_imap_server"] == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unable to get SOURCE imap server\n";
            }
            update_status(-1, "unable to get SOURCE imap server");
            return;
        }
        if ($parameters["dest_imap_server"] == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Cyrus: {$user->cyrus_imapd_installed}; Zarafa:{$user->ZARAFA_INSTALLED}\n";
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "unable to get DESTINATION imap server Local server:{$local_mailbox}; Parms:local_mailbox={$parameters["local_mailbox"]}\n";
            }
            update_status(-1, "unable to get DESTINATION imap server");
            return;
        }
    }
    if ($parameters["local_mailbox_source"] == 0) {
        if ($parameters["remote_imap_server"] == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unable to get SOURCE imap server\n";
            }
            update_status(-1, "unable to get SOURCE imap server");
            return;
        }
    }
    if ($parameters["local_mailbox"] == 0) {
        if ($parameters["dest_imap_server"] == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unable to get DESTINATION imap server\n";
            }
            update_status(-1, "unable to get destination DESTINATION server");
            return;
        }
    }
    if ($parameters["local_mailbox"] == 1) {
        if ($parameters["local_mailbox_source"] == 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "DESTINATION imap mailbox cannot be the same has SOURCE imap mailbox\n";
            }
            update_status(-1, "DESTINATION imap mailbox cannot be the same has SOURCE imap mailbox");
            return;
        }
    }
    if ($parameters["local_mailbox"] == 1) {
        $host2 = "127.0.0.1";
        $user2 = $ct->uid;
        $password2 = $ct->password;
        $md52 = md5("{$host2}{$user2}{$password2}");
    } else {
        $host2 = $parameters["dest_imap_server"];
        $user2 = $parameters["dest_imap_username"];
        $password2 = $parameters["dest_imap_password"];
        $md52 = md5("{$host2}{$user2}{$password2}");
    }
    if ($parameters["local_mailbox_source"] == 1) {
        $host1 = "127.0.0.1";
        $user1 = $ct->uid;
        $password1 = $ct->password;
        $md51 = md5("{$host1}{$user1}{$password1}");
    } else {
        $host1 = $ligne["imap_server"];
        $user1 = $ligne["username"];
        $password1 = $ligne["password"];
        $md51 = md5("{$host1}{$user1}{$password1}");
    }
    if ($md51 == $md52) {
        if ($GLOBALS["VERBOSE"]) {
            echo "DESTINATION imap mailbox cannot be the same has SOURCE imap mailbox\n";
        }
        update_status(-1, "DESTINATION imap mailbox cannot be the same has SOURCE imap mailbox");
        return;
    }
    $offlineImapUseSSL1 = "no";
    $offlineImapUseSSL1port = "143";
    $offlineImapUseSSL2 = "no";
    $offlineImapUseSSL2port = "143";
    $expunge1 = "no";
    if ($parameters["use_ssl"] == 1) {
        $ssl1 = " --ssl1";
        $offlineImapUseSSL1 = "yes";
        $offlineImapUseSSL1port = "993";
    }
    if ($parameters["dest_use_ssl"] == 1) {
        $ssl2 = " --ssl2";
        $offlineImapUseSSL2 = "yes";
        $offlineImapUseSSL2port = "993";
    }
    if ($parameters["syncinternaldates"] == null) {
        $parameters["syncinternaldates"] = 1;
    }
    if ($parameters["noauthmd5"] == null) {
        $parameters["noauthmd5"] = 1;
    }
    if ($parameters["allowsizemismatch"] == null) {
        $parameters["allowsizemismatch"] = 1;
    }
    if ($parameters["nosyncacls"] == null) {
        $parameters["nosyncacls"] = 1;
    }
    if ($parameters["skipsize"] == null) {
        $parameters["skipsize"] = 0;
    }
    if ($parameters["nofoldersizes"] == null) {
        $parameters["nofoldersizes"] = 1;
    }
    if ($parameters["useSep1"] == null) {
        $parameters["useSep1"] = 0;
    }
    if ($parameters["useSep2"] == null) {
        $parameters["useSep2"] = 0;
    }
    if ($parameters["usePrefix1"] == null) {
        $parameters["usePrefix1"] = 0;
    }
    if ($parameters["usePrefix2"] == null) {
        $parameters["usePrefix2"] = 0;
    }
    if ($parameters["delete_messages"] == 1) {
        $delete = " --delete --expunge1";
        $expunge1 = "yes";
    }
    if ($parameters["syncinternaldates"] == 1) {
        $syncinternaldates = " --syncinternaldate";
    }
    if ($parameters["noauthmd5"] == 1) {
        $noauthmd5 = " --noauthmd5";
    }
    if ($parameters["allowsizemismatch"] == 1) {
        $allowsizemismatch = " --allowsizemismatch";
    }
    if ($parameters["nosyncacls"] == 1) {
        $nosyncacls = " --nosyncacls";
    }
    if ($parameters["skipsize"] == 1) {
        $skipsize = " --skipsize";
    }
    if ($parameters["nofoldersizes"] == 1) {
        $nofoldersizes = " --nofoldersizes";
    }
    if ($parameters["useSep1"] == 1) {
        $sep = " --sep1 \"{$parameters["sep"]}\"";
    }
    if ($parameters["useSep2"] == 1) {
        $sep2 = " --sep2 \"{$parameters["sep2"]}\"";
    }
    if ($parameters["usePrefix1"] == 1) {
        $prefix1 = " --prefix1 \"{$parameters["prefix1"]}\"";
    }
    if ($parameters["usePrefix2"] == 1) {
        $prefix2 = " --prefix2 \"{$parameters["prefix2"]}\"";
    }
    if ($parameters["maxage"] > 0) {
        $maxage = " --maxage {$parameters["maxage"]}";
    }
    if (count($array_folders["FOLDERS"]) > 0) {
        while (list($num, $folder) = each($array_folders["FOLDERS"])) {
            if (trim($folder) == null) {
                continue;
            }
            $cleaned[trim($folder)] = trim($folder);
        }
        while (list($num, $folder) = each($cleaned)) {
            $foldersr[] = $folder;
            $offlineImapFolders[] = "'{$folder}'";
        }
        $folders_replicate = @implode(" --folder ", $foldersr);
    }
    $offlineImapConf[] = "";
    $offlineImapConf[] = "[Repository SourceServer]";
    $offlineImapConf[] = "type = IMAP";
    $offlineImapConf[] = "remotehost = {$host1}";
    $offlineImapConf[] = "ssl = {$offlineImapUseSSL1}";
    $offlineImapConf[] = "remoteport = {$offlineImapUseSSL1port}";
    $offlineImapConf[] = "remoteuser = {$user1}";
    $offlineImapConf[] = "remotepass = {$password1}";
    $offlineImapConf[] = "# reference = Mail";
    $offlineImapConf[] = "maxconnections = 1";
    $offlineImapConf[] = "holdconnectionopen = no";
    $offlineImapConf[] = "# keepalive = 60";
    $offlineImapConf[] = "expunge = {$expunge1}";
    $offlineImapConf[] = "subscribedonly = no";
    if ($parameters["useSep1"] == 1) {
        $offlineImapConf[] = "sep = {$parameters["sep"]}";
    }
    $offlineImapConf[] = "nametrans = lambda foldername: re.sub('^INBOX\\.*', '.', foldername)";
    if (count($offlineImapFolders) > 0) {
        $offlineImapConf[] = "folderincludes = [" . @implode(",", $offlineImapFolders) . "]";
    }
    $offlineImapConf[] = "";
    $offlineImapConf[] = "[Repository TargetServer]";
    $offlineImapConf[] = "type = IMAP";
    $offlineImapConf[] = "remotehost = {$host2}";
    $offlineImapConf[] = "ssl = {$offlineImapUseSSL2}";
    $offlineImapConf[] = "remoteport = {$offlineImapUseSSL2port}";
    $offlineImapConf[] = "remoteuser = {$user2}";
    $offlineImapConf[] = "remotepass = {$password2}";
    $offlineImapConf[] = "# reference = Mail";
    $offlineImapConf[] = "maxconnections = 1";
    $offlineImapConf[] = "holdconnectionopen = no";
    $offlineImapConf[] = "# keepalive = 60";
    $offlineImapConf[] = "expunge = no";
    $offlineImapConf[] = "subscribedonly = no";
    if ($parameters["useSep2"] == 1) {
        $offlineImapConf[] = "sep = {$parameters["sep2"]}";
    }
    $offlineImapConf[] = "nametrans = lambda foldername: re.sub('^INBOX\\.*', '.', foldername)";
    if (count($offlineImapFolders) > 0) {
        $offlineImapConf[] = "folderincludes = [" . @implode(",", $offlineImapFolders) . "]";
    }
    $file_temp = "/usr/share/artica-postfix/ressources/logs/imapsync.{$id}.logs";
    $cmd = $unix->find_program("imapsync") . " --buffersize 8192000{$nosyncacls} --subscribe{$syncinternaldates}";
    $cmd = $cmd . " --host1 {$host1} --user1 \"{$user1}\" --password1 \"{$password1}\"{$ssl1}{$prefix1}{$sep} --host2 {$host2} --user2 \"{$user2}\"";
    $cmd = $cmd . " --password2 \"{$password2}\"{$ssl2}{$prefix2}{$sep2}{$folders_replicate}{$delete}{$noauthmd5}{$allowsizemismatch}{$skipsize}{$nofoldersizes}{$maxage} >{$file_temp} 2>&1";
    if ($ASOfflineImap) {
        if (is_file($file_temp)) {
            @unlink($file_temp);
        }
        $cmd = $unix->find_program("offlineimap") . " -o -u Noninteractive.Basic -c /tmp/offlineimap-{$ligne["uid"]} -l {$file_temp}";
        @file_put_contents("/tmp/offlineimap-{$ligne["uid"]}", @implode("\n", $offlineImapConf));
        if ($GLOBALS["VERBOSE"]) {
            $cmd_show = $cmd . "\n";
            $datas = @implode("\n", $offlineImapConf);
            $datas = str_replace("remotepass = {$password2}", "remotepass = MASKED", $datas);
            $datas = str_replace("remotepass = {$password1}", "remotepass = MASKED", $datas);
            echo "{$cmd_show}\nConfiguration file:\n---------------------------\n\n{$datas}";
            return;
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        $cmd_show = $cmd;
        $cmd_show = str_replace("--password1 {$password1}", "--password1 MASKED", $cmd_show);
        $cmd_show = str_replace("--password2 {$password2}", "--password2 MASKED", $cmd_show);
        echo "{$cmd_show}\n";
        return;
    }
    shell_exec($cmd);
    update_status(0, addslashes(@file_get_contents($file_temp)));
}
Exemplo n.º 15
0
function CleanStorage()
{
    $users = new usersMenus();
    $sock = new sockets();
    $Enable = $sock->GET_INFO("StorageAutoCleanEnabled");
    $MaxDay = $sock->GET_INFO("StorageMaxDayToLive");
    if ($MaxDay == null) {
        $MaxDay = 60;
    }
    if ($Enable == null) {
        $Enable = 1;
    }
    if ($Enable != 1) {
        return;
    }
    echo "\n\n####### Max day to live: {$MaxDay} days  in storage #######\n\n";
    $sql = "SELECT count(MessageID) AS tcount FROM storage WHERE zDate<DATE_SUB(NOW(),INTERVAL {$MaxDay} DAY)";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if ($ligne["tcount"] < 1) {
        echo "Nothing to do ....\n\n";
        return;
    }
    $count = $ligne["tcount"];
    echo "{$ligne["tcount"]} messages to clean...\n";
    $sql = "DELETE FROM storage WHERE zDate<DATE_SUB(NOW(),INTERVAL {$MaxDay} DAY)";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "Mysql error {$q->mysql_error}\n";
    }
    $date = date('Y-m-d H:i:s');
    $filename = "/var/log/artica-postfix/events/" + md5($date);
    $ini = new Bs_IniHandler();
    $ini->_params["LOG"]["processname"] = dirname(__FILE__);
    $ini->_params["LOG"]["date"] = $date;
    $ini->_params["LOG"]["context"] = "system";
    $ini->_params["LOG"]["text"] = "{$count} storage mails has been cleaned from disk and database";
    $ini->_params["LOG"]["text"] = "[{$date}]{$count} storage mails has been cleaned";
    file_put_contents($filename, $ini->toString());
    write_syslog("{$ligne["tcount"]} messages cleaned...", __FILE__);
    echo "messages cleaned in storage...\n";
}
function GeneratStats($ou)
{
    $sql_domain = sql_domain($ou);
    if ($sql_domain == null) {
        return null;
    }
    $sql = "SELECT COUNT(ID) as tcount,bounce_error FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' )\nGROUP BY bounce_error";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $bounce_error = TransFormBounceError($ligne["bounce_error"]);
        if ($bounce_error == null) {
            $bounce_error = "Sended";
        }
        $arr[] = "\"{$ligne["tcount"]}\"=>\"{$bounce_error}\"";
    }
    if (!is_array($arr)) {
        $day_camember = "array()";
    } else {
        $day_camember = "array(" . implode(",\n", $arr) . ");";
    }
    $sql = "SELECT COUNT(ID) as tcount,sender_domain FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' ) AND (\n\tSPAM=1 OR\n\tspammy=1 \n\tOR bounce_error='Discard' \n\tOR bounce_error='RBL'\n\tOR bounce_error='Greylisting'\n\tOR bounce_error='Domain not found'\n\tOR bounce_error='Relay access denied'\n\tOR bounce_error='Relaying denied'\n\t\n\t)\nGROUP BY sender_domain ORDER BY tcount DESC LIMIT 0,10";
    $sql_log_1 = "{$sql}\n";
    unset($arr);
    $results = $q->QUERY_SQL($sql, "artica_events");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $arr1[] = "\"{$ligne["tcount"]}\"=>\"{$ligne["sender_domain"]}\"";
    }
    if (!is_array($arr1)) {
        $top_10_spammers = "array()";
    } else {
        $top_10_spammers = "array(" . implode(",\n", $arr1) . ");";
    }
    //--------------------------------------------------------------------------------------------------------------------------
    $sql = "\n\nSELECT COUNT(ID) as tcount FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' ) AND (SPAM=1 OR bounce_error='Discard')";
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
    $spams = $ligne["tcount"];
    $sql = "SELECT COUNT(ID) as tcount FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' ) AND (whitelisted=1)";
    $sql_log_3 = $sql;
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
    $whitelisted = $ligne["tcount"];
    if ($whitelisted == null) {
        $whitelisted = 0;
    }
    if ($spams == null) {
        $spams = 0;
    }
    //--------------------------------------------------------------------------------------------------------------------------
    $sql = "SELECT COUNT(ID) as tcount, DATE_FORMAT( time_sended, '%k' ) as th FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' ) GROUP BY th ORDER BY th";
    $sql_log_2 = "{$sql}\n";
    $results = $q->QUERY_SQL($sql, "artica_events");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $arr3[] = "\"{$ligne["tcount"]}\"=>\"{$ligne["th"]}\"";
    }
    if (!is_array($arr3)) {
        $flow_hour = "array()";
    } else {
        $flow_hour = "array(" . implode(",\n", $arr3) . ");";
    }
    $file = "<?php\n";
    $file = $file . "/*\n{$sql_log_1}\n----------\n{$sql_log_3}\n----------\n{$sql_log_2}\n*/\n";
    $file = $file . "\$today_cam_flow={$day_camember}\n";
    $file = $file . "\$today_cam_top_ten_spammers={$top_10_spammers};\n";
    $file = $file . "\$whitelisted=array('spam'=>{$spams},'whitelisted'=>{$whitelisted});\n";
    $file = $file . "\$flow_hour={$flow_hour};\n";
    $file = $file . "?>";
    write_syslog("Generate mail statistics for {$num} \"" . dirname(__FILE__) . "/ressources/logs/ou-stats/{$ou}/", __FILE__);
    @mkdir(dirname(__FILE__) . "/ressources/logs");
    @mkdir(dirname(__FILE__) . "/ressources/logs/ou-stats");
    @mkdir(dirname(__FILE__) . "/ressources/logs/ou-stats/{$ou}");
    @file_put_contents(dirname(__FILE__) . "/ressources/logs/ou-stats/{$ou}/day.inc", $file);
    chmod(dirname(__FILE__) . "/ressources/logs/ou-stats/{$ou}/day.inc", 0755);
}
Exemplo n.º 17
0
function SyncOrg($ou)
{
    $ldap = new clladp();
    $hash = $ldap->UserSearch($ou, "");
    for ($i = 0; $i < $hash["count"]; $i++) {
        $uid = $hash[$i]["uid"][0];
        write_syslog("Checking {$uid}", __FILE__);
        $obm = new obm_user($uid);
    }
}
Exemplo n.º 18
0
function TransFormToHtml($file)
{
    if (!is_file($file)) {
        return false;
    }
    $original_file = trim(file_get_contents("{$file}"));
    $attachmentdir = dirname($file);
    $fullmessagesdir = dirname($file);
    $attachmenturl = 'images.listener.php?mailattach=';
    $cmd = '/usr/bin/mhonarc ';
    $cmd = $cmd . "-attachmentdir {$attachmentdir} ";
    $cmd = $cmd . "-attachmenturl {$attachmenturl} ";
    $cmd = $cmd . '-nodoc ';
    $cmd = $cmd . '-nofolrefs ';
    $cmd = $cmd . '-nomsgpgs ';
    $cmd = $cmd . '-nospammode ';
    $cmd = $cmd . '-nosubjectthreads ';
    $cmd = $cmd . '-idxfname storage ';
    $cmd = $cmd . '-nosubjecttxt "no subject" ';
    $cmd = $cmd . '-single ';
    $cmd = $cmd . $original_file . ' ';
    $cmd = $cmd . ">{$attachmentdir}/message.html 2>&1";
    system($cmd);
    $size = filesize("{$attachmentdir}/message.html");
    write_syslog("Creating html  {$attachmentdir}/message.html ({$size} bytes)", __FILE__);
}
Exemplo n.º 19
0
<?php

include_once dirname(__FILE__) . '/ressources/class.ldap.inc';
include_once dirname(__FILE__) . '/ressources/class.computers.inc';
writelogs("user executed : " . posix_getuid(), __FUNCTION__, __FILE__, __LINE__);
if (posix_getuid() != 0) {
    write_syslog("requested has " . posix_getuid() . " uid \"{$argv[1]}\" but Cannot be used in web server mode", __FILE__);
    die;
}
$log = false;
$username = $argv[1];
$verbose = $argv[2];
if ($verbose == '--verbose') {
    $_GET["log"] = true;
}
if (trim($username) == null) {
    die;
}
$GLOBALS["ADDLOG"] = "/usr/share/artica-postfix/ressources/logs/web/samba-add-computer.log";
writelogs("Adding new computer {$username}", __FUNCTION__, __FILE__, __LINE__);
$computer = new computers($username);
if ($computer->Add()) {
    write_syslog("Success adding new computer {$username}", __FILE__);
} else {
    write_syslog("Failed adding new computer {$username}", __FILE__);
}
Exemplo n.º 20
0
	die();
}



if($argv[1]=="--amavis-full"){
	$conf[]=spamassassin();
	$conf[]=clamd();
	$conf[]=amavis();
	$conf[]=amavis_milter();
	echo @implode("\n",$conf);
	die();
}

if(strlen($argv[1])>0){
	write_syslog("Unable to understand {$argv[1]}",basename(__FILE__));
	die();
}

$pidfile="/etc/artica-postfix/".basename(__FILE__).".pid";
$unix=new unix();
if($unix->process_exists(@file_get_contents($pidfile))){
	print "Starting......: artica-status Already executed...\n";
	die();
}
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB artica-status Memory {$GLOBALS["TOTAL_MEMORY_MB"]}MB","MAIN",__LINE__);
print "Starting......: artica-status Memory {$GLOBALS["TOTAL_MEMORY_MB"]}MB\n";
if(!function_exists("pcntl_fork")){$nofork=true;}
if($GLOBALS["TOTAL_MEMORY_MB"]<400){$nofork=true;}

Exemplo n.º 21
0
function DirEML($path)
{
    $dir_handle = @opendir($path);
    if (!$dir_handle) {
        write_syslog("Unable to open \"{$path}\"", __FILE__);
        return array();
    }
    $count = 0;
    while ($file = readdir($dir_handle)) {
        if ($file == '.') {
            continue;
        }
        if ($file == '..') {
            continue;
        }
        if (!is_file("{$path}/{$file}")) {
            continue;
        }
        if (preg_match("#\\.eml\$#", $file)) {
            $array[$file] = $file;
            continue;
        }
    }
    if (!is_array($array)) {
        return array();
    }
    @closedir($dir_handle);
    return $array;
}
Exemplo n.º 22
0
dhcpd_logs("dhcpd.leases.dmp: {$md5Local} / {$md5Tampon}");
if ($GLOBALS["VERBOSE"]) {
    echo " --> MD5LOCAL={$md5Local} / MD5Tampon={$md5Tampon}\n";
}
if (!$GLOBALS["FORCE"]) {
    if ($md5Local == $md5Tampon) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> {$md5Local} == {$md5Tampon}, abort\n";
        }
        die;
    }
}
@unlink($cache_file);
@file_put_contents($cache_file, $md5Tampon);
writelogs("LOCAL:{$md5Local} !== REMOTE:{$md5Tampon}", "MAIN", __FILE__, __LINE__);
write_syslog("integrity of dhcpd.leases has been modified ( from {$md5Local} to {$md5Tampon}), analyze the leases", basename(__FILE__));
if ($GLOBALS["VERBOSE"]) {
    echo " --> CleanFile()\n";
}
CleanFile();
if ($GLOBALS["VERBOSE"]) {
    echo " --> /var/lib/dhcp3/dhcpd.leases\n";
}
$datas = @file_get_contents("/var/lib/dhcp3/dhcpd.leases");
$md5 = md5($datas);
if (!preg_match_all("#lease\\s+(.+?)\\s+{(.+?)\\}#is", $datas, $re)) {
    if ($GLOBALS["VERBOSE"]) {
        echo " --> Unable to preg_match\n";
    }
    events("Unable to preg_match", "main", __LINE__);
    die;
Exemplo n.º 23
0
function smtp_mail($sendto_email, $subject, $body, $From = '', $FromName = '')
{
    global $_CFG;
    require_once QISHI_ROOT_PATH . 'phpmailer/class.phpmailer.php';
    $mail = new PHPMailer();
    $mailconfig = get_cache('mailconfig');
    $mailconfig['smtpservers'] = explode('|-_-|', $mailconfig['smtpservers']);
    $mailconfig['smtpusername'] = explode('|-_-|', $mailconfig['smtpusername']);
    $mailconfig['smtppassword'] = explode('|-_-|', $mailconfig['smtppassword']);
    $mailconfig['smtpfrom'] = explode('|-_-|', $mailconfig['smtpfrom']);
    $mailconfig['smtpport'] = explode('|-_-|', $mailconfig['smtpport']);
    for ($i = 0; $i < count($mailconfig['smtpservers']); $i++) {
        $mailconfigarray[] = array('smtpservers' => $mailconfig['smtpservers'][$i], 'smtpusername' => $mailconfig['smtpusername'][$i], 'smtppassword' => $mailconfig['smtppassword'][$i], 'smtpfrom' => $mailconfig['smtpfrom'][$i], 'smtpport' => $mailconfig['smtpport'][$i]);
    }
    $mc = array_rand($mailconfigarray, 1);
    $mc = $mailconfigarray[$mc];
    $mailconfig['smtpservers'] = $mc['smtpservers'];
    $mailconfig['smtpusername'] = $mc['smtpusername'];
    $mailconfig['smtppassword'] = $mc['smtppassword'];
    $mailconfig['smtpfrom'] = $mc['smtpfrom'];
    $mailconfig['smtpport'] = $mc['smtpport'];
    $From = $From ? $From : $mailconfig['smtpfrom'];
    $FromName = $FromName ? $FromName : $_CFG['site_name'];
    if ($mailconfig['method'] == "1") {
        if (empty($mailconfig['smtpservers']) || empty($mailconfig['smtpusername']) || empty($mailconfig['smtppassword']) || empty($mailconfig['smtpfrom'])) {
            write_syslog(2, 'MAIL', "邮件配置信息不完整");
            return false;
        }
        $mail->IsSMTP();
        $mail->Host = $mailconfig['smtpservers'];
        $mail->SMTPDebug = 0;
        $mail->SMTPAuth = true;
        $mail->Username = $mailconfig['smtpusername'];
        $mail->Password = $mailconfig['smtppassword'];
        $mail->Port = $mailconfig['smtpport'];
        $mail->From = $mailconfig['smtpfrom'];
        $mail->FromName = $FromName;
    } elseif ($mailconfig['method'] == "2") {
        $mail->IsSendmail();
    } elseif ($mailconfig['method'] == "3") {
        $mail->IsMail();
    }
    $mail->CharSet = QISHI_CHARSET;
    $mail->Encoding = "base64";
    $mail->AddReplyTo($From, $FromName);
    $mail->AddAddress($sendto_email, "");
    $mail->IsHTML(true);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AltBody = "text/html";
    if ($mail->Send()) {
        write_sys_email_log($mailconfig['smtpusername'], $sendto_email, $subject, $body, "1");
        return true;
    } else {
        write_syslog(2, 'MAIL', $mail->ErrorInfo);
        write_sys_email_log($mailconfig['smtpusername'], $sendto_email, $subject, $body, "2");
        return false;
    }
}
Exemplo n.º 24
0
function BuildReport($uid, $ou)
{
    $usr = new usersMenus();
    $user = new user($uid);
    $emailsnumbers = count($user->HASH_ALL_MAILS);
    if ($emailsnumbers == 0) {
        write_syslog("BuildReport() user=<{$uid}> has no email addresses", __FILE__);
        return null;
    }
    $ouU = strtoupper($ou);
    $ini = new Bs_IniHandler("/etc/artica-postfix/settings/Daemons/OuSendQuarantineReports{$ouU}");
    $days = $ini->_params["NEXT"]["days"];
    if ($days == null) {
        $days = 2;
    }
    if ($ini->_params["NEXT"]["title1"] == null) {
        $ini->_params["NEXT"]["title1"] = "Quarantine domain senders";
    }
    if ($ini->_params["NEXT"]["title2"] == null) {
        $ini->_params["NEXT"]["title2"] = "Quarantine list";
    }
    if ($ini->_params["NEXT"]["explain"] == null) {
        $ini->_params["NEXT"]["explain"] = "You will find here all mails stored in your quarantine area";
    }
    if ($ini->_params["NEXT"]["externalLink"] == null) {
        $ini->_params["NEXT"]["externalLink"] = "https://{$usr->hostname}:9000/user.quarantine.query.php";
    }
    if (preg_match("#([0-9]+) (jours|days)#", $_GET["subject"], $re)) {
        write_syslog("Change to {$re[1]} days from subject", __FILE__);
        $days = $re[1];
    }
    write_syslog("Starting HTML report ({$days} days) for {$uid} {$user->DisplayName} ({$emailsnumbers} recipient emails)", __FILE__);
    $date = date('Y-m-d');
    $font_normal = "<FONT FACE=\"Arial, Helvetica, sans-serif\" SIZE=2>";
    $font_title = "<FONT FACE=\"Arial, Helvetica, sans-serif\" SIZE=4>";
    while (list($num, $ligne) = each($user->HASH_ALL_MAILS)) {
        $recipient_sql[] = "mailto='{$ligne}'";
    }
    $recipients = implode(" OR ", $recipient_sql);
    $sql = "SELECT mailfrom,zDate,MessageID,DATE_FORMAT(zdate,'%W %D %H:%i') as tdate,subject FROM quarantine\n\tWHERE (zDate>DATE_ADD('{$date}', INTERVAL -{$days} DAY)) AND ({$recipients})  ORDER BY zDate DESC;";
    $q = new mysql();
    //	echo "$sql\n";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        write_syslog("Wrong sql query {$q->mysql_error}", __FILE__);
        return null;
    }
    $style = "font-size:11px;border-bottom:1px solid #CCCCCC;margin:3px;padding:3px";
    $session = md5($user->password);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $subject = htmlspecialchars($ligne["subject"]);
        $from = trim($ligne["mailfrom"]);
        $zDate = $ligne["tdate"];
        $MessageID = $ligne["MessageID"];
        if ($from == null) {
            $from = "unknown";
        }
        $domain = "unknown";
        if (preg_match("#(.+?)@(.+)#", $from, $re)) {
            $domain = $re[2];
        }
        $uri = "<a href=\"{$ini->_params["NEXT"]["externalLink"]}?uid={$user->uid}&session={$session}&mail={$MessageID}\">";
        $array[$domain][] = "<tr>\n\t\t<td style=\"{$style}\" nowrap>{$uri}{$font_normal}{$zDate}</FONT></a></td>\n\t\t<td style=\"{$style}\" nowrap>{$uri}{$font_normal}<code>{$from}</code></FONT></a></td>\n\t\t<td style=\"{$style}\">{$uri}{$font_normal}<strong>{$subject}</strong></FONT></a></td>\n\t\t\n\t\t</tr>";
    }
    write_syslog("BuildReport: Single ???=<{$_GET["SINGLE"]}>", __FILE__);
    $count_domains = count($array);
    if (!$_GET["SINGLE"]) {
        if ($count_domains == 0) {
            write_syslog("BuildReport() user=<{$uid}> has no spam domains senders", __FILE__);
            return null;
        }
    }
    $html = "<H1>{$font_title}{$days} {$ini->_params["NEXT"]["title1"]}</FONT></H1>\n<p style=\"font-size:12px;font-weight:bold\">{$font_title}{$ini->_params["NEXT"]["explain"]}</FONT> </p>\n<hr>\n<H2>{$font_title}{$count_domains} Domains</FONT></H2>\n<table style=\"width:100%\">";
    if (is_array($array)) {
        while (list($num, $ligne) = each($array)) {
            $html = $html . "<tr><td><li><strong style=\"font-size:12px\">{$font}{$num}</FONT></li></td></tr>\n";
        }
        reset($array);
    }
    $html = $html . "</table>\n<hr>\n<h2>{$font_title}{$ini->_params["NEXT"]["title2"]}</FONT></h2>\n<table style=\"width:100%;border:1px solid #CCCCCC;margin:5px;padding:5px\">";
    if (is_array($array)) {
        while (list($num, $ligne) = each($array)) {
            $html = $html . "<hr>\n\t<table border=1 style=\"width:100%;border:1px solid #CCCCCC;margin:5px;padding:5px\">\n\t<tr>\n\t\t<td colspan=3><strong style=\"font-size:16px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$font_title}{$num}</FONT></td>\n\t</tr>\n\t" . implode("\n", $ligne);
            $html = $html . "\n\t</table>\n\t";
        }
    }
    if ($ini->_params["NEXT"]["mailfrom"] == null) {
        $ini->_params["NEXT"]["mailfrom"] = $_GET["mailfrom"];
    }
    if ($ini->_params["NEXT"]["mailfrom"] == null) {
        $ini->_params["NEXT"]["mailfrom"] = "root@localhostlocaldomain";
    }
    if ($ini->_params["NEXT"]["subject"] == null) {
        $ini->_params["NEXT"]["subject"] = $_GET["subject"];
    }
    if ($ini->_params["NEXT"]["subject"] == null) {
        $ini->_params["NEXT"]["subject"] = "Daily Quarantine report";
    }
    $tpl = new templates();
    $subject = $ini->_params["NEXT"]["subject"];
    $mail = new Rmail();
    $mail->setFrom("quarantine <{$ini->_params["NEXT"]["mailfrom"]}>");
    $mail->setSubject($subject);
    $mail->setPriority('normal');
    $mail->setText(strip_tags($html));
    $mail->setHTML($html);
    $address = $user->mail;
    $result = $mail->send(array($address));
    write_syslog("From=<{$ini->_params["NEXT"]["mailfrom"]}> to=<{$user->mail}> Send Quarantine Report=<{$result}>", __FILE__);
}
Exemplo n.º 25
0
function sync($id)
{
    $unix = new unix();
    $users = new usersMenus();
    $GLOBALS["unique_id"] = $id;
    $sql = "SELECT * FROM imapsync WHERE ID='{$id}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        write_syslog("Mysql error {$q->mysql_error}", __FILE__);
        die;
    }
    $pid = $ligne["pid"];
    if ($unix->process_exists($pid)) {
        die;
    }
    update_pid(getmypid());
    if (!is_file($unix->find_program("imapsync"))) {
        update_status(-1, "Could not find imapsync program");
        return;
    }
    update_status(1, "Executed");
    $ct = new user($ligne["uid"]);
    $parameters = unserialize(base64_decode($ligne["parameters"]));
    $parameters["sep"] = trim($parameters["sep"]);
    $parameters["sep2"] = trim($parameters["sep2"]);
    $array_folders = unserialize(base64_decode($ligne["folders"]));
    if ($user->cyrus_imapd_installed) {
        $local_mailbox = true;
    }
    if ($user->ZARAFA_INSTALLED) {
        $local_mailbox = true;
    }
    if ($local_mailbox) {
        if ($parameters["local_mailbox"] == null) {
            $parameters["local_mailbox"] = 1;
        }
        if ($parameters["local_mailbox_source"] == null) {
            $parameters["local_mailbox_source"] = 1;
        }
    } else {
        $parameters["local_mailbox"] = 0;
        $parameters["local_mailbox_source"] = 0;
    }
    if (!$local_mailbox) {
        if ($parameters["remote_imap_server"] == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unable to get SOURCE imap server\n";
            }
            update_status(-1, "unable to get SOURCE imap server");
            return;
        }
        if ($parameters["dest_imap_server"] == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unable to get DESTINATION imap server\n";
            }
            update_status(-1, "unable to get DESTINATION imap server");
            return;
        }
    }
    if ($parameters["local_mailbox_source"] == 0) {
        if ($parameters["remote_imap_server"] == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unable to get SOURCE imap server\n";
            }
            update_status(-1, "unable to get SOURCE imap server");
            return;
        }
    }
    if ($parameters["local_mailbox"] == 0) {
        if ($parameters["dest_imap_server"] == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unable to get DESTINATION imap server\n";
            }
            update_status(-1, "unable to get destination DESTINATION server");
            return;
        }
    }
    if ($parameters["local_mailbox"] == 1) {
        if ($parameters["local_mailbox_source"] == 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "DESTINATION imap mailbox cannot be the same has SOURCE imap mailbox\n";
            }
            update_status(-1, "DESTINATION imap mailbox cannot be the same has SOURCE imap mailbox");
            return;
        }
    }
    if ($parameters["local_mailbox"] == 1) {
        $host2 = "127.0.0.1";
        $user2 = $ct->uid;
        $password2 = $ct->password;
        $md52 = md5("{$host2}{$user2}{$password2}");
    } else {
        $host2 = $parameters["dest_imap_server"];
        $user2 = $parameters["dest_imap_username"];
        $password2 = $parameters["dest_imap_password"];
        $md52 = md5("{$host2}{$user2}{$password2}");
    }
    if ($parameters["local_mailbox_source"] == 1) {
        $host1 = "127.0.0.1";
        $user1 = $ct->uid;
        $password1 = $ct->password;
        $md51 = md5("{$host1}{$user1}{$password1}");
    } else {
        $host1 = $ligne["imap_server"];
        $user1 = $ligne["username"];
        $password1 = $ligne["password"];
        $md51 = md5("{$host1}{$user1}{$password1}");
    }
    if ($md51 == $md52) {
        if ($GLOBALS["VERBOSE"]) {
            echo "DESTINATION imap mailbox cannot be the same has SOURCE imap mailbox\n";
        }
        update_status(-1, "DESTINATION imap mailbox cannot be the same has SOURCE imap mailbox");
        return;
    }
    if ($parameters["use_ssl"] == 1) {
        $ssl1 = " --ssl1";
    }
    if ($parameters["dest_use_ssl"] == 1) {
        $ssl2 = " --ssl2";
    }
    if ($parameters["syncinternaldates"] == null) {
        $parameters["syncinternaldates"] = 1;
    }
    if ($parameters["noauthmd5"] == null) {
        $parameters["noauthmd5"] = 1;
    }
    if ($parameters["allowsizemismatch"] == null) {
        $parameters["allowsizemismatch"] = 1;
    }
    if ($parameters["nosyncacls"] == null) {
        $parameters["nosyncacls"] = 1;
    }
    if ($parameters["skipsize"] == null) {
        $parameters["skipsize"] = 0;
    }
    if ($parameters["nofoldersizes"] == null) {
        $parameters["nofoldersizes"] = 1;
    }
    if ($parameters["useSep1"] == null) {
        $parameters["useSep1"] = 0;
    }
    if ($parameters["useSep2"] == null) {
        $parameters["useSep2"] = 0;
    }
    if ($parameters["usePrefix1"] == null) {
        $parameters["usePrefix1"] = 0;
    }
    if ($parameters["usePrefix2"] == null) {
        $parameters["usePrefix2"] = 0;
    }
    if (count($array_folders["FOLDERS"]) > 0) {
        while (list($num, $folder) = each($array_folders["FOLDERS"])) {
            if (trim($folder) == null) {
                continue;
            }
            $cleaned[trim($folder)] = trim($folder);
        }
        while (list($num, $folder) = each($cleaned)) {
            $foldersr[] = $folder;
        }
        $folders_replicate = @implode(" --folder ", $foldersr);
    }
    if ($parameters["delete_messages"] == 1) {
        $delete = " --delete --expunge1";
    }
    if ($parameters["syncinternaldates"] == 1) {
        $syncinternaldates = " --syncinternaldate";
    }
    if ($parameters["noauthmd5"] == 1) {
        $noauthmd5 = " --noauthmd5";
    }
    if ($parameters["allowsizemismatch"] == 1) {
        $allowsizemismatch = " --allowsizemismatch";
    }
    if ($parameters["nosyncacls"] == 1) {
        $nosyncacls = " --nosyncacls";
    }
    if ($parameters["skipsize"] == 1) {
        $skipsize = " --skipsize";
    }
    if ($parameters["nofoldersizes"] == 1) {
        $nofoldersizes = " --nofoldersizes";
    }
    if ($parameters["useSep1"] == 1) {
        $sep = " --sep1 \"{$parameters["sep"]}\"";
    }
    if ($parameters["useSep2"] == 1) {
        $sep2 = " --sep2 \"{$parameters["sep2"]}\"";
    }
    if ($parameters["usePrefix1"] == 1) {
        $prefix1 = " --prefix1 \"{$parameters["prefix1"]}\"";
    }
    if ($parameters["usePrefix2"] == 1) {
        $prefix2 = " --prefix2 \"{$parameters["prefix2"]}\"";
    }
    $file_temp = "/usr/share/artica-postfix/ressources/logs/imapsync.{$id}.logs";
    $cmd = $unix->find_program("imapsync") . " --buffersize 8192000{$nosyncacls} --subscribe{$syncinternaldates}";
    $cmd = $cmd . " --host1 {$host1} --user1 {$user1} --password1 {$password1}{$ssl1}{$prefix1}{$sep} --host2 {$host2} --user2 {$user2}";
    $cmd = $cmd . " --password2 {$password2}{$ssl2}{$prefix2}{$sep2}{$folders_replicate}{$delete}{$noauthmd5}{$allowsizemismatch}{$skipsize}{$nofoldersizes} >{$file_temp} 2>&1";
    if ($GLOBALS["VERBOSE"]) {
        $cmd_show = $cmd;
        $cmd_show = str_replace("--password1 {$password1}", "--password1 MASKED", $cmd_show);
        $cmd_show = str_replace("--password2 {$password2}", "--password2 MASKED", $cmd_show);
        echo "{$cmd_show}\n";
        return;
    }
    shell_exec($cmd);
    update_status(0, addslashes(@file_get_contents($file_temp)));
}
Exemplo n.º 26
0
function corrupted_file($filesource)
{
    if (preg_match("#\\/var\\/spool\\/artica-emailing\\/queues\\/([0-9]+)\\/emailrelay\\.#", $filesource, $re)) {
        $ID = $re[1];
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "corrupted_file:: ID:{$ID}\n";
    }
    if (strpos($filesource, "envelope.busy") > 0) {
        $replace_source = "envelope.busy";
    }
    if (strpos($filesource, "envelope.bad") > 0) {
        $replace_source = "envelope.bad";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "corrupted_file:: replace:{$replace_source}\n";
    }
    $enveloppe = str_replace("{$replace_source}", "envelope", $filesource);
    $content = str_replace("{$replace_source}", "content", $filesource);
    if ($GLOBALS["VERBOSE"]) {
        echo "corrupted_file:: enveloppe:{$enveloppe}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "corrupted_file:: content..:{$content}\n";
    }
    $f = explode("\n", @file_get_contents($enveloppe));
    if (is_array($f)) {
        while (list($num, $line) = each($f)) {
            if (preg_match("#X-MailRelay-From:\\s+(.+?)\$#", $line, $re)) {
                $mailfrom = trim($re[1]);
            }
            if (preg_match("#X-MailRelay-To-Remote:\\s+(.+?)\$#", $line, $re)) {
                $mailto = trim($re[1]);
            }
        }
    }
    $basename = basename($enveloppe);
    if ($GLOBALS["VERBOSE"]) {
        echo "corrupted_file:: {$basename} from=<{$mailfrom}>\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "corrupted_file:: {$basename} to=<{$mailto}>\n";
    }
    @unlink($enveloppe);
    @unlink($content);
    write_syslog("[{$ID}]: Corrupted file {$basename} from {$mailfrom} to {$mailto}", basename(__FILE__));
    if (is_numeric($ID)) {
        if ($ID > 0) {
            send_email_events("[emailing instance {$ID}]: Corrupted file {$basename} from {$mailfrom} to {$mailto}", "files {$enveloppe}\n{$content} has been removed from queue", "system");
            emailing_emailrelay_start($ID);
        }
    }
    //;
}
Exemplo n.º 27
0
function CreateNAB(){
	$ldap=new clladp();
	$dn="dc=NAB,$ldap->suffix";
	if(!$ldap->ExistsDN($dn)){
		$upd["objectClass"][]="top";
		$upd["objectClass"][]="organization";
		$upd["objectClass"][]="dcObject";
		$upd["o"][]="NAB";
		$upd["dc"][]="NAB";
		if(!$ldap->ldap_add($dn,$upd)){
			write_syslog("failed creating $dn",__FILE__);
		}
		
	}

}
Exemplo n.º 28
0
function DirList($path)
{
    $dir_handle = @opendir($path);
    $array = array();
    if (!$dir_handle) {
        if ($GLOBALS["VERBOSE"]) {
            write_syslog("Unable to open \"{$path}\"", __FILE__);
        }
        return array();
    }
    $count = 0;
    while ($file = readdir($dir_handle)) {
        if ($file == '.') {
            continue;
        }
        if ($file == '..') {
            continue;
        }
        if (!is_file("{$path}/{$file}")) {
            continue;
        }
        $array[$file] = $file;
    }
    if (!is_array($array)) {
        return array();
    }
    @closedir($dir_handle);
    return $array;
}
Exemplo n.º 29
0
    write_syslog("wants pflogsumm reporting but no recipients set", __FILE__);
    die;
}
while (list($num, $email) = each($rec)) {
    if (trim($email) == null) {
        continue;
    }
    $recipients[$email] = $email;
}
if (!is_array($recipients)) {
    write_syslog("wants pflogsumm reporting but no recipients set", __FILE__);
    die;
}
if (!is_file("{$maillog}")) {
    write_syslog("wants pflogsumm reporting but cannot stat maillog or mail.log", __FILE__);
    die;
}
system("/usr/sbin/pflogsumm -d today --verbose_msg_detail {$maillog} >/tmp/pflogsumm 2>&1");
$reporting = file_get_contents("/tmp/pflogsumm");
write_syslog("pflogsumm reporting generated for " . count($recipients) . " recipients with " . strlen($reporting) . " bytes length", __FILE__);
@unlink("/tmp/pflogsumm");
while (list($num, $email) = each($recipients)) {
    if (trim($email) == null) {
        continue;
    }
    if ($use_send_mail == 1) {
        SendMailNotifWithSendMail($reporting, $subject, $smtp_sender, $email, $debug);
    } else {
        SendMailNotif($reporting, $subject, $smtp_sender, $email, $debug);
    }
}