Example #1
0
function build_allreports()
{
    $t = time();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$ID}.pid";
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        ufdbguard_admin_events("Already executed pid {$pid}", __FUNCTION__, __FILE__, __LINE__, "reports");
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid}\n";
        }
        return;
    }
    $t = time();
    $sql = "SELECT ID,report FROM TrackMembers WHERE scheduled=1";
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL($sql);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $report = utf8_decode($ligne["report"]);
        $c++;
        $tt = time();
        build_report($ID);
        ufdbguard_admin_events("{$report} builded, took " . $unix->distanceOfTimeInWords($tt, time(), true), __FUNCTION__, __FILE__, __LINE__, "reports");
    }
    ufdbguard_admin_events("{$c} reports builded, took " . $unix->distanceOfTimeInWords($t, time(), true), __FUNCTION__, __FILE__, __LINE__, "reports");
}
Example #2
0
function generate_report($server_cfg, $game_cfg, $timestamp, $period)
{
    $report = build_report($server_cfg, $game_cfg, $period, $timestamp);
    if ($report === null) {
        return null;
    }
    send_mail($server_cfg, $game_cfg, $report);
}
function xrun()
{
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        $GLOBALS["FORCE"] = true;
    }
    $pidtime = "/etc/artica-postfix/pids/exec.squid.watchdog.ad.start_watchdog.time";
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $watch = new squid_watchdog();
    $sock = new sockets();
    $MonitConfig = $watch->MonitConfig;
    $CHECK_AD_INTERVAL = intval($MonitConfig["CHECK_AD_INTERVAL"]);
    if ($CHECK_AD_INTERVAL < 1) {
        $CHECK_AD_INTERVAL = 5;
    }
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        $pptime = $unix->PROCCESS_TIME_MIN($pid, 10);
        events("[INFO]:Process already running PID {$pid} since {$pptime}Mn");
        return;
    }
    @file_put_contents($pidFile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        $time = $unix->file_time_min($pidtime);
        if ($time < $CHECK_AD_INTERVAL) {
            events("[INFO]: Currently {$time}Mn need to wait {$CHECK_AD_INTERVAL}Mn");
            return;
        }
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    $sock = new sockets();
    $WaitWinbindPID = 2;
    $EnableKerbAuth = intval($sock->GET_INFO("EnableKerbAuth"));
    if ($EnableKerbAuth == 0) {
        return;
    }
    $KerbAuthWatchEv = intval($sock->GET_INFO("KerbAuthWatchEv"));
    $ActiveDirectoryEmergency = intval($sock->GET_INFO("ActiveDirectoryEmergency"));
    $ActiveDirectoryEmergencyReboot = intval($sock->GET_INFO("ActiveDirectoryEmergencyReboot"));
    $ActiveDirectoryEmergencyFailOver = intval($sock->GET_INFO("ActiveDirectoryEmergencyFailOver"));
    $ActiveDirectoryEmergencyNone = intval($sock->GET_INFO("ActiveDirectoryEmergencyNone"));
    if ($ActiveDirectoryEmergency == 1) {
        events("[INFO]:Running into Active Directory Emergency mode [SKIP]");
        return;
    }
    if ($ActiveDirectoryEmergencyReboot == 1) {
        events("[INFO]:Running into Active Directory after a reboot, wait winbind for 10mn [SKIP]");
        $WaitWinbindPID = 10;
        return;
    }
    if ($ActiveDirectoryEmergencyFailOver > 0) {
        if ($unix->time_min($ActiveDirectoryEmergencyFailOver) < 10) {
            events("[INFO]:Running into Active Directory after a failover, wait for 10mn [SKIP]");
            return;
        }
        $sock->SET_INFO("ActiveDirectoryEmergencyFailOver", 0);
    }
    if ($ActiveDirectoryEmergencyNone > 0) {
        if ($unix->time_min($ActiveDirectoryEmergencyNone) < 10) {
            events("[INFO]:Running into Active Directory after a NONE EMERGENCY, wait for 10mn [SKIP]");
            return;
        }
        $sock->SET_INFO("ActiveDirectoryEmergencyNone", 0);
    }
    $pid = WINBIND_PID();
    events("[INFO]:Winbind PID: {$pid}");
    if (!$unix->process_exists($pid)) {
        events("[FATAL]:Winbind is not running start it...");
        $KerbAuthWatchEv++;
        squid_admin_mysql(0, "[Active Directory]: {$KerbAuthWatchEv}) Winbind is not running, start it [action=start]", null, __FILE__, __LINE__);
        if (MAX_ATTEMPTS_AD($KerbAuthWatchEv)) {
            return;
        }
        $sock->SET_INFO("KerbAuthWatchEv", $KerbAuthWatchEv);
        shell_exec("/etc/init.d/winbind start");
        return;
    }
    if (!ping_winbind()) {
        $KerbAuthWatchEv++;
        if (MAX_ATTEMPTS_AD($KerbAuthWatchEv)) {
            return;
        }
        $sock->SET_INFO("KerbAuthWatchEv", $KerbAuthWatchEv);
        return;
    }
    $pidtime = $unix->PROCCESS_TIME_MIN($pid);
    if ($pidtime < $WaitWinbindPID) {
        events("[INFO]:Winbind PID: {$pid} TTL = {$pidtime}Mn must wait minimal {$WaitWinbindPID}Mn");
        return;
    }
    events("[INFO]:Winbind PID: {$pid} TTL = {$pidtime}Mn");
    $wbinfo = $unix->find_program("wbinfo");
    $php = $unix->LOCATE_PHP5_BIN();
    $net = $unix->find_program("net");
    if (!wbinfo(true)) {
        events("[INFO]:winbinfo -t \"FAILED\"");
        $text = build_report();
        $KerbAuthWatchEv++;
        if (MAX_ATTEMPTS_AD($KerbAuthWatchEv)) {
            return;
        }
        $sock->SET_INFO("KerbAuthWatchEv", $KerbAuthWatchEv);
        squid_admin_mysql(0, "[Active Directory]: {$KerbAuthWatchEv}) Active Directory connection failed (winbinfo -t) [action=reconnect]", $text, __FILE__, __LINE__);
        exec("{$php} /usr/share/artica-postfix/exec.kerbauth.php --join --verbose 2>&1", $join);
        if (!wbinfo(true)) {
            squid_admin_mysql(0, "[Active Directory]: Join Active Directory task failed", @implode("\n", $join), __FILE__, __LINE__);
        } else {
            squid_admin_mysql(1, "Join Active Directory task success", @implode("\n", $join), __FILE__, __LINE__);
            $sock->SET_INFO("KerbAuthWatchEv", 0);
            $sock->SET_INFO("ActiveDirectoryEmergency", 0);
            $sock->SET_INFO("ActiveDirectoryEmergencyReboot", 0);
            $sock->SET_INFO("ActiveDirectoryEmergencyNone", 0);
            action_enable_ActiveDirectory();
        }
        return;
    }
    if (!testjoin()) {
        events("[INFO]:testjoin \"FAILED\"");
        $KerbAuthWatchEv++;
        if (MAX_ATTEMPTS_AD($KerbAuthWatchEv)) {
            return;
        }
        $sock->SET_INFO("KerbAuthWatchEv", $KerbAuthWatchEv);
        $text = build_report();
        squid_admin_mysql(0, "[Active Directory]: {$KerbAuthWatchEv}) Active Directory failed (testjoin) [action=reconnect]", $text, __FILE__, __LINE__);
        exec("{$php} /usr/share/artica-postfix/exec.kerbauth.php --join --verbose 2>&1", $join);
        if (!testjoin()) {
            squid_admin_mysql(0, "[Active Directory]: Join Active Directory task failed", @implode("\n", $join), __FILE__, __LINE__);
        } else {
            squid_admin_mysql(1, "Join Active Directory task success", @implode("\n", $join), __FILE__, __LINE__);
            $sock->SET_INFO("KerbAuthWatchEv", 0);
            $sock->SET_INFO("ActiveDirectoryEmergency", 0);
            $sock->SET_INFO("ActiveDirectoryEmergencyReboot", 0);
            $sock->SET_INFO("ActiveDirectoryEmergencyNone", 0);
            action_enable_ActiveDirectory();
        }
        return;
    }
    $sock->SET_INFO("KerbAuthWatchEv", 0);
    $sock->SET_INFO("ActiveDirectoryEmergency", 0);
    $sock->SET_INFO("ActiveDirectoryEmergencyReboot", 0);
    $sock->SET_INFO("ActiveDirectoryEmergencyNone", 0);
    action_enable_ActiveDirectory();
}
function buildFinalObject($OLP)
{
    //-- OLP = one long page
    $Final_Object = new nuReport($OLP, $OLP->displayJavaScript());
    $Final_Object->page_height = $OLP->page_height;
    $Final_Object->page_width = $OLP->page_width;
    $new_page = new nuPage();
    $reportSectionsArray = $GLOBALS['nuSections'];
    unset($GLOBALS['nuSections']);
    for ($G = 0; $G < count($reportSectionsArray); $G++) {
        unset($section_array);
        unset($record);
        unset($controls);
        unset($S);
        $nuS = gzuncompress($reportSectionsArray[$G]['the_section']);
        eval($nuS);
        //-- make section_array, record and controls from table record
        $S = new nuSection($emptySection, $new_page);
        //-- build a section using nothing
        $S->load_from_array($section_array, $record);
        for ($ct = 0; $ct < count($controls); $ct++) {
            //-- add controls to rebuilt section
            $S->controls[$ct] = new nuControl(null, null);
            $S->controls[$ct]->load_from_array($controls[$ct]);
        }
        if ($S->original_height > $OLP->get_remaining_height()) {
            //====start another page because the next section won't fit
            $new_section = new nuSection($S, $new_page);
            $new_section->height = $OLP->get_remaining_height();
            //-- build a blank section the size of the remaining height
            $new_section->name = 'Padding';
            //-- name this section as 'PageBreak'
            buildClassCode($new_section, count($Final_Object->pages));
            //==========page footer===========================
            if ($S->name != "Report_Header") {
                $page_footer = $OLP->page_footer;
                $temp_section = new nuSection($page_footer, $new_page);
                for ($pf = 0; $pf < count($page_footer->controls); $pf++) {
                    $temp_control = new nuControl($page_footer->controls[$pf], $S);
                    $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
                    $temp_section->controls[] = $temp_control;
                }
                $temp_section->record = $new_section->record;
                buildClassCode($temp_section, count($Final_Object->pages));
            }
            //==========end page footer=======================
            $Final_Object->pages[] = $new_page;
            $new_page = new nuPage();
            //-- build new page
            //==========page header===========================
            if ($S->name != "Report_Header") {
                $page_header = $OLP->page_header;
                $temp_section = new nuSection($page_header, $new_page);
                for ($pf = 0; $pf < count($page_header->controls); $pf++) {
                    $temp_control = new nuControl($page_header->controls[$pf], $S);
                    $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
                    $temp_section->controls[] = $temp_control;
                }
                $temp_section->record = $new_section->record;
                buildClassCode($temp_section, count($Final_Object->pages));
            }
            //==========end page header=======================
            $OLP->reset_remaining_height();
        }
        while (!$S->finished('while')) {
            $new_section = new nuSection($S, $new_page);
            for ($c = 0; $c < count($S->controls); $c++) {
                //-- LOOP THROUGH ALL CONTROLS
                if ($S->controls[$c]->top + 1 < $OLP->get_remaining_height()) {
                    $new_control = new nuControl($S->controls[$c], $S);
                    //-- setup control properties
                    if ($new_control->type == 'PageBreak') {
                        $new_section->height = $new_section->section_height();
                        //-- resize height to lowest control
                        $OLP->reduce_remaining_height($new_section->height);
                        //-- reset the remaining height of the page
                        buildClassCode($new_section, count($Final_Object->pages));
                        $new_section = new nuSection($S, $new_page);
                        $new_section->height = $OLP->get_remaining_height();
                        //-- build a blank section the size of the remaining height
                        $new_section->name = 'PageBreak';
                        //-- name this section as 'PageBreak'
                        break;
                    } else {
                        $new_control->top = $S->controls[$c]->top();
                        //-- set height to 0 if not first time through
                        $usable_height = $OLP->get_remaining_height() - $new_control->top;
                        //-- area this control has to fit in
                        $new_control->text_string = $S->controls[$c]->get_lines($usable_height);
                        //-- put fittable rows into the control
                        if ($new_control->type == 'Graph') {
                            $new_control->last_used = 0;
                            //-- set graph as completed
                        }
                        $new_control->height = count($new_control->text_string) * $new_control->height;
                        //-- resize height of this control
                        $new_section->controls[] = $new_control;
                        //-- add control to current section
                    }
                } else {
                    if ($OLP->get_remaining_height() > 0) {
                        $S->controls[$c]->top = $S->controls[$c]->top - $OLP->get_remaining_height();
                        //-- reduce control's top for next section
                    }
                }
            }
            if ($new_control->type != 'PageBreak') {
                $new_section->height = $new_section->section_height();
                //-- resize height to lowest control
            }
            $OLP->reduce_remaining_height($new_section->height);
            //-- reset the remaining height of the page
            buildClassCode($new_section, count($Final_Object->pages));
            if (!$S->finished('if') or $new_control->type == 'PageBreak') {
                //-- add a page break
                $new_section = new nuSection($S, $new_page);
                $new_section->height = $OLP->get_remaining_height();
                //-- build a blank section the size of the remaining height
                $new_section->name = 'Padding';
                //-- name this section as 'PageBreak'
                buildClassCode($new_section, count($Final_Object->pages));
                //==========page footer===========================
                if ($S->name != "Report_Header") {
                    $page_footer = $OLP->page_footer;
                    $temp_section = new nuSection($page_footer, $new_page);
                    for ($pf = 0; $pf < count($page_footer->controls); $pf++) {
                        $temp_control = new nuControl($page_footer->controls[$pf], $S);
                        $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
                        $temp_section->controls[] = $temp_control;
                    }
                    $temp_section->record = $new_section->record;
                    buildClassCode($temp_section, count($Final_Object->pages));
                }
                //==========end page footer=======================
                $Final_Object->pages[] = $new_page;
                $new_page = new nuPage();
                //-- build new page
                //==========page header===========================
                if ($S->name != "Report_Header") {
                    $page_header = $OLP->page_header;
                    $temp_section = new nuSection($page_header, $new_page);
                    for ($pf = 0; $pf < count($page_header->controls); $pf++) {
                        $temp_control = new nuControl($page_header->controls[$pf], $S);
                        $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
                        $temp_section->controls[] = $temp_control;
                    }
                    $temp_section->record = $new_section->record;
                    buildClassCode($temp_section, count($Final_Object->pages));
                }
                //==========end page header=======================
                //-- push down remaining objects by the remaining gap that couldn't be used on this page
                $push_down_from = $S->push_down_from();
                $add_height = $OLP->get_remaining_height();
                $grow_section = false;
                for ($pd = $push_down_from; $pd < count($S->controls); $pd++) {
                    $S->controls[$pd]->top = $S->controls[$pd]->top + $add_height;
                    $grow_section = true;
                }
                if ($grow_section) {
                    $S->height = $S->height + $add_height;
                }
                $OLP->reset_remaining_height();
            }
        }
    }
    //==========padding between report footer and page footer
    $new_section = new nuSection($S, $new_page);
    $new_section->height = $OLP->get_remaining_height();
    //-- build a blank section the size of the remaining height
    $new_section->name = 'PageBreak';
    //-- name this section as 'PageBreak'
    buildClassCode($new_section, count($Final_Object->pages));
    //==========page footer===========================
    $page_footer = $OLP->page_footer;
    $temp_section = new nuSection($page_footer, $new_page);
    $temp_section->record = $S->record;
    for ($pf = 0; $pf < count($page_footer->controls); $pf++) {
        $temp_control = new nuControl($page_footer->controls[$pf], $S);
        $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
        $temp_section->controls[] = $temp_control;
    }
    $temp_section->record = $new_section->record;
    buildClassCode($temp_section, count($Final_Object->pages));
    $Final_Object->pages[] = $new_page;
    build_report($Final_Object);
    tofile('end ' . date('Y-m-d H:i:s'));
}