Пример #1
0
function squid_admin_notifs_check($nopid = false)
{
    squid_admin_mysql_check(true);
    squid_admin_enforce_check(true);
    webupdate_admin_mysql_check(true);
}
Пример #2
0
function squid_admin_notifs_check($nopid = false)
{
    $f = array();
    $unix = new unix();
    if ($nopid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid)) {
            writelogs("Already running pid {$pid}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        $t = 0;
    }
    $BaseWorkDir = "{$GLOBALS["ARTICALOGDIR"]}/squid_admin_notifs";
    if (!is_dir($BaseWorkDir)) {
        return;
    }
    if (!($handle = opendir($BaseWorkDir))) {
        echo "Failed open {$BaseWorkDir}\n";
        return;
    }
    $sock = new sockets();
    $users = new usersMenus();
    $UfdbguardSMTPNotifs = unserialize(base64_decode($sock->GET_INFO("UfdbguardSMTPNotifs")));
    if (!isset($UfdbguardSMTPNotifs["ENABLED_SQUID_WATCHDOG"])) {
        $UfdbguardSMTPNotifs["ENABLED_SQUID_WATCHDOG"] = 0;
    }
    if (!is_numeric($UfdbguardSMTPNotifs["ENABLED_SQUID_WATCHDOG"])) {
        $UfdbguardSMTPNotifs["ENABLED_SQUID_WATCHDOG"] = 0;
    }
    // removed : foreach (glob("{$GLOBALS["ARTICALOGDIR"]}/system_admin_events/*") as $filename) {
    include_once dirname(__FILE__) . '/ressources/class.mail.inc';
    include_once dirname(__FILE__) . "/ressources/smtp/class.phpmailer.inc";
    if (!isset($UfdbguardSMTPNotifs["smtp_dest"])) {
        return;
    }
    if (!isset($UfdbguardSMTPNotifs["smtp_sender"])) {
        $UfdbguardSMTPNotifs["smtp_sender"] = null;
    }
    $smtp_dest = $UfdbguardSMTPNotifs["smtp_dest"];
    $smtp_sender = $UfdbguardSMTPNotifs["smtp_sender"];
    if ($smtp_dest == null) {
        return;
    }
    if ($smtp_sender == null) {
        $smtp_sender = "*****@*****.**";
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "{$BaseWorkDir}/{$filename}";
        if ($unix->file_time_min($targetFile) > 240) {
            @unlink($targetFile);
            continue;
        }
        $array = unserialize(@file_get_contents($targetFile));
        if (!is_array($array)) {
            @unlink($targetFile);
            continue;
        }
        if ($UfdbguardSMTPNotifs["ENABLED_SQUID_WATCHDOG"] == 0) {
            continue;
        }
        if (!is_numeric($array["TASKID"])) {
            $array["TASKID"] = 0;
        }
        $content = $array["text"];
        $content_array = explode("\n", $content);
        if (count($content_array) > 0) {
            for ($i = 0; $i < count($content_array); $i++) {
                if (trim($content_array[$i]) == null) {
                    continue;
                }
                if ($GLOBALS["VERBOSE"]) {
                    echo "Strip `{$content_array[$i]}` line " . __LINE__ . "\n";
                }
                $subject = substr($content_array[$i], 0, 75) . "...";
                break;
            }
            $content = @implode("\r\n", $content_array);
        } else {
            if ($GLOBALS["VERBOSE"]) {
                echo "Strip `{$content}`\n";
            }
            $subject = substr($content, 0, 75) . "...";
        }
        unset($array["text"]);
        $content = $content . "\r\n------------------------------------------\r\n";
        while (list($key, $value) = each($array)) {
            $content = $content . "{$key}.....: {$value}\r\n";
        }
        $subject = "[{$users->hostname}]: {$subject}";
        $mail = new PHPMailer(true);
        $mail->IsSMTP();
        $mail->AddAddress($smtp_dest, $smtp_dest);
        $mail->AddReplyTo($smtp_sender, $smtp_sender);
        $mail->From = $smtp_sender;
        $mail->Subject = $subject;
        $mail->Body = $content;
        $mail->Host = $UfdbguardSMTPNotifs["smtp_server_name"];
        $mail->Port = $UfdbguardSMTPNotifs["smtp_server_port"];
        if ($UfdbguardSMTPNotifs["smtp_auth_user"] != null && $UfdbguardSMTPNotifs["smtp_auth_passwd"] != null) {
            $mail->SMTPAuth = true;
            $mail->Username = $UfdbguardSMTPNotifs["smtp_auth_user"];
            $mail->Password = $UfdbguardSMTPNotifs["smtp_auth_passwd"];
            if ($UfdbguardSMTPNotifs["tls_enabled"] == 1) {
                $mail->SMTPSecure = 'tls';
            }
            if ($UfdbguardSMTPNotifs["ssl_enabled"] == 1) {
                $mail->SMTPSecure = 'ssl';
            }
        }
        if (!$mail->Send()) {
            return false;
        }
        @unlink($targetFile);
    }
    squid_admin_mysql_check(true);
    squid_admin_enforce_check(true);
}