Beispiel #1
0
function start()
{
    $unix = new unix();
    $pidfile = $GLOBALS["MYPID"];
    $WORKDIR = $GLOBALS["WORKDIR"];
    $SERV_NAME = $GLOBALS["SERV_NAME"];
    $mysql_pid_file = "/var/run/amavis-db.pid";
    $MYSQL_SOCKET = "/var/run/mysqld/amavis-db.sock";
    $mysqlserv = new mysql_services();
    $mysqlserv->WORKDIR = $GLOBALS["WORKDIR"];
    $mysqlserv->MYSQL_PID_FILE = $mysql_pid_file;
    $mysqlserv->MYSQL_SOCKET = $MYSQL_SOCKET;
    $mysqlserv->SERV_NAME = $SERV_NAME;
    $mysqlserv->TokenParams = "AmavisDBMysqlParams";
    $mysqlserv->InnoDB = true;
    $pid = $unix->get_pid_from_file($pidfile);
    $sock = new sockets();
    $AmavisPerUser = $sock->GET_INFO("AmavisPerUser");
    if (!is_numeric($AmavisPerUser)) {
        $AmavisPerUser = 0;
    }
    $EnableStopPostfix = $sock->GET_INFO("EnableStopPostfix");
    if (!is_numeric($EnableStopPostfix)) {
        $EnableStopPostfix = 0;
    }
    if ($EnableStopPostfix == 1) {
        $AmavisPerUser = 0;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Starting Task Already running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $mysql_install_db = $unix->find_program("mysql_install_db");
    if ($AmavisPerUser == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} is disabled...\n";
        }
        stop();
        die(0);
    }
    $mysqld = $unix->find_program("mysqld");
    if (!is_file($mysqld)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} is not installed...\n";
        }
        return;
    }
    if (!is_file($mysql_install_db)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} mysql_install_db no such binary...\n";
        }
        return;
    }
    $pid = DBPID();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL Database Engine already running pid {$pid} since {$time}mn\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} writing init.d\n";
    }
    initd();
    $TMP = $unix->FILE_TEMP();
    $cmdline = $mysqlserv->BuildParams();
    $nohup = $unix->find_program("nohup");
    if ($GLOBALS["VERBOSE"]) {
        echo $cmdline . "\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} Starting MySQL daemon ({$SERV_NAME})\n";
    }
    shell_exec("{$nohup} {$cmdline} >{$TMP} 2>&1 &");
    sleep(1);
    for ($i = 0; $i < 10; $i++) {
        $pid = DBPID();
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) started pid .{$pid}..\n";
            }
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: MySQL daemon wait {$i}/10\n";
        }
        sleep(1);
    }
    sleep(1);
    $pid = DBPID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) failed to start\n";
        }
        $f = explode("\n", @file_get_contents($TMP));
        while (list($num, $ligne) = each($TMP)) {
            if (trim($ligne) == null) {
                continue;
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} {$ligne}\n";
            }
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) success\n";
        }
        $q = new amavisdb();
        $q->checkTables();
    }
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} {$cmdline}\n";
        }
    }
    $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " --databasesize");
}
function SearchQuery()
{
    $SearchQuery = string_to_flexquery();
    $q = new amavisdb();
    $page = CurrentPageName();
    $usersZ = new usersMenus();
    $tpl = new templates();
    $boot = new boostrap_form();
    $sql = "SELECT * FROM `policy` WHERE ou='{$_SESSION["ou"]}' {$SearchQuery} ORDER BY policy_name LIMIT 0,150 ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<p class=text-error>{$q->mysql_error}<br>{$sql}<hr></p>";
    }
    $t = time();
    while ($ligne = mysql_fetch_assoc($results)) {
        $id = $ligne["id"];
        $policy_name = $ligne["policy_name"];
        $tr[] = "\n\t\t<tr id='{$id}' " . $boot->trswitch("Loadjs('{$page}?policy-id-js={$id}')") . ">\n\t\t<td width=30%><i class='icon-filter'></i> {$policy_name}</td>\n\t\t<td width=1%><i class='icon-eye-open'></i> {$ligne["spam_tag_level"]}</td>\n\t\t<td width=1%><i class='icon-fire'></i> {$ligne["spam_tag2_level"]}</td>\n\t\t<td width=1%><i class='icon-trash'></i> {$ligne["spam_kill_level"]}</td>\n\t\t<td style='text-align:center'>" . imgsimple("delete-32.png", null, "Delete{$t}('{$id}')") . "</td>\n\t\t</tr>\n\t\t";
    }
    $page = CurrentPageName();
    $ouF = null;
    $delete = $tpl->javascript_parse_text("{delete} {rule} ?");
    echo $tpl->_ENGINE_parse_body("<table class='table table-bordered table-hover'>\n\n\t\t\t<thead>\n\t\t\t<tr>\n\t\t\t<th>{policy}</th>\n\t\t\t<th width=1% nowrap>TAG {level}</th>\n\t\t\t<th width=1% nowrap>QUAR {level}</th>\n\t\t\t<th width=1% nowrap>KILL {level}</th>\n\t\t\t<th width=1% nowrap>&nbsp;</th>\n\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t<tbody>\n\t\t\t") . @implode("\n", $tr) . " </tbody>\n\t\t\t</table>\n<script>\n\tvar meme{$t}='';\n\tvar xDelete{$t}= function (obj) {\n\t\t\tvar results=obj.responseText;\n\t\t\tif(results.length>3){alert(results);return;}\n\t\t\t\$('#'+meme{$t}).remove();\n\t}\n\n\n\tfunction Delete{$t}(xmd5){\n\t\tmeme{$t}=xmd5;\n\t\tif(!confirm('{$delete}')){return;}\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('delete-md5',xmd5);\n\t\t\tXHR.sendAndLoad('{$page}', 'POST',xDelete{$t});\n\t}\n\t\t\t\t\t\t\n</script>";
}
function policies_search()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $t = time();
    $html = "<p class=text-info>{amavis_users_policies_explain}</p>";
    $boot = new boostrap_form();
    $user = new user($_SESSION["uid"]);
    $mails = $user->HASH_ALL_MAILS;
    $amavis = new amavisdb();
    $search = string_to_flexregex();
    while (list($b, $email) = each($mails)) {
        if ($search != null) {
            if (!preg_match("#{$search}#", $email)) {
                continue;
            }
        }
        $id = $amavis->policyid_from_mail($email);
        $ligne = $amavis->policy_array($id);
        $policy_name = $ligne["policy_name"];
        $tr[] = "\n\t\t<tr id='{$id}' " . $boot->trswitch("Loadjs('{$page}?policy-email-js={$email}')") . ">\n\t\t<td width=30%><i class='icon-envelope'></i> {$email}</td>\n\t\t<td width=30%><i class='icon-filter'></i> {$policy_name}</td>\n\t\t<td width=1%><i class='icon-eye-open'></i> {$ligne["spam_tag_level"]}</td>\n\t\t<td width=1%><i class='icon-fire'></i> {$ligne["spam_tag2_level"]}</td>\n\t\t<td width=1%><i class='icon-trash'></i> {$ligne["spam_kill_level"]}</td>\n\t\t\n\t\t</tr>\n\t\t";
    }
    echo $tpl->_ENGINE_parse_body("<table class='table table-bordered table-hover'>\n\t\n\t\t\t<thead>\n\t\t\t<tr>\n\t\t\t\t<th>{email} &laquo;{$_SESSION["uid"]}&raquo;</th>\n\t\t\t\t<th>{policy}</th>\n\t\t\t\t<th width=1% nowrap>TAG {level}</th>\n\t\t\t\t<th width=1% nowrap>QUAR {level}</th>\n\t\t\t\t<th width=1% nowrap>KILL {level}</th>\n\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t<tbody>\n\t\t\t") . @implode("\n", $tr) . " </tbody>\n\t\t\t\t</table>";
}
function domains_search()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $t = time();
    $boot = new boostrap_form();
    $ldap = new clladp();
    $mails = $ldap->hash_get_domains_ou($_SESSION["ou"], true);
    $amavis = new amavisdb();
    $search = string_to_flexregex();
    while (list($b, $domain) = each($mails)) {
        if ($search != null) {
            if (!preg_match("#{$search}#", $domain)) {
                continue;
            }
        }
        $id = $amavis->policyid_from_mail("@{$domain}");
        $ligne = $amavis->policy_array($id);
        $policy_name = $ligne["policy_name"];
        $tr[] = "\n\t\t<tr id='{$id}' " . $boot->trswitch("Loadjs('{$page}?policy-domain-js={$domain}')") . ">\n\t\t<td width=30%><i class='icon-envelope'></i> {$domain}</td>\n\t\t<td width=30%><i class='icon-filter'></i> {$policy_name}</td>\n\t\t<td width=1%><i class='icon-eye-open'></i> {$ligne["spam_tag_level"]}</td>\n\t\t<td width=1%><i class='icon-fire'></i> {$ligne["spam_tag2_level"]}</td>\n\t\t<td width=1%><i class='icon-trash'></i> {$ligne["spam_kill_level"]}</td>\n\t\n\t\t</tr>\n\t\t";
    }
    echo $tpl->_ENGINE_parse_body("<table class='table table-bordered table-hover'>\n\t\n\t\t\t<thead>\n\t\t\t<tr>\n\t\t\t<th>{domains_policies} &laquo;{$_SESSION["ou"]}&raquo;</th>\n\t\t\t<th>{policy}</th>\n\t\t\t<th width=1% nowrap>TAG {level}</th>\n\t\t\t<th width=1% nowrap>QUAR {level}</th>\n\t\t\t<th width=1% nowrap>KILL {level}</th>\n\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t<tbody>\n\t\t\t") . @implode("\n", $tr) . " </tbody>\n\t\t\t</table>";
}