예제 #1
0
파일: module.php 프로젝트: Prescia/Prescia
 function onCron($isDay = false)
 {
     # cron Triggered, isDay or isHour
     ###### -> Construct should add this module to the onCron array
     if ($isDay) {
         // delete week old entries (select data, detect files, delete files, delete data)
         $core =& $this->parent;
         $undoModule = $this->parent->loaded($this->moduleRelation);
         $sql = "SELECT id, files FROM " . $undoModule->dbname . " WHERE files<>'' AND data<NOW() - INTERVAL 1 WEEK";
         $core->dbo->query($sql, $r, $n);
         if ($n > 0) {
             for ($c = 0; $c < $n; $c++) {
                 list($id, $files) = $core->dbo->fetch_row($r);
                 $files = @unserialize($files);
                 if ($files) {
                     foreach ($files as $file) {
                         if (is_file(CONS_FMANAGER . "_undodata/" . $file)) {
                             @unlink(CONS_FMANAGER . "_undodata/" . $file);
                         }
                     }
                 }
             }
         }
         $core->dbo->simpleQuery("DELETE FROM " . $undoModule->dbname . " WHERE data<NOW() - INTERVAL 1 WEEK");
         # Find orphan files and delete them
         $lastWeek = date("Y-m-d") . " 00:00:00";
         $lastWeek = datecalc($lastWeek, 0, 0, -7);
         $lastWeek = tomktime($lastWeek);
         $files = listFiles(CONS_FMANAGER . "_undodata/", '@^(.*)$@', true);
         foreach ($files as $file) {
             $ft = filemtime(CONS_FMANAGER . "_undodata/" . $file);
             if ($ft < $lastWeek) {
                 @unlink(CONS_FMANAGER . "_undodata/" . $file);
             } else {
                 break;
             }
             // the list is ordered by date, so the first not to match means none will
         }
     }
 }
예제 #2
0
파일: module.php 프로젝트: Prescia/Prescia
 function log($die = true)
 {
     function appendErrors(&$core, &$output, &$template, $data)
     {
         foreach ($data as $line) {
             $line = explode("|", $line);
             # date|id_client|uri|errCode|module|parameters|extended parameters|log[|...]
             $thisData = array();
             $thisData['date'] = array_shift($line);
             $thisData['id_client'] = array_shift($line);
             $thisData['uri'] = array_shift($line);
             $thisData['errCode'] = array_shift($line);
             $thisData['module'] = array_shift($line);
             $thisData['parameters'] = array_shift($line);
             $thisData['extended'] = array_shift($line);
             $thisData['log'] = implode("|", $line);
             if (is_numeric($thisData['errCode']) && isset($core->errorControl->ERRORS[$thisData['errCode']])) {
                 $errorLevel = $core->errorControl->ERRORS[$thisData['errCode']];
                 $thisData['level'] = $errorLevel < 10 ? 0 : ($errorLevel < 20 ? 1 : 2);
                 $output .= $template->techo($thisData);
             }
         }
     }
     $outputTemplate = "<div style='line-height:25px;border-bottom:1px solid #999999;margin-bottom:3px;'>{date} {id_client}: <span style='color:red'>{errCode} ({_t}e{errCode}{/t})</span> [{module}] {parameters} (<strong>{extended}</strong>) @ {uri}</div>";
     $template = new CKTemplate($this->parent->template);
     $template->tbreak($outputTemplate);
     $this->parent->close(false);
     $temp = "";
     // 1 day ago
     $previousDay = datecalc(date("Y-m-d"), 0, 0, -1);
     $previousDay = str_replace("-", "", $previousDay);
     if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/err" . $previousDay . ".log")) {
         appendErrors($this->parent, $temp, $template, explode("\n", cReadFile(CONS_PATH_LOGS . $_SESSION['CODE'] . "/err" . $previousDay . ".log")));
     }
     # Today
     $previousDay = date("Ymd");
     if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/err" . $previousDay . ".log")) {
         appendErrors($this->parent, $temp, $template, explode("\n", cReadFile(CONS_PATH_LOGS . $_SESSION['CODE'] . "/err" . $previousDay . ".log")));
     }
     if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/out" . $previousDay . ".log")) {
         $temp .= nl2br(cReadFile(CONS_PATH_LOGS . $_SESSION['CODE'] . "/out" . $previousDay . ".log"));
     }
     echo "Log files are located at " . CONS_PATH_LOGS . $_SESSION['CODE'] . "/<br/><br/>";
     echo $temp;
     echo "<br/><hr>";
     # httpd log?
     if (CONS_HTTPD_ERRFILE != '') {
         $httpderrlog = str_replace("{Y}", date("Y"), CONS_HTTPD_ERRFILE);
         $httpderrlog = str_replace("{m}", date("m"), $httpderrlog);
         $httpderrlog = str_replace("{d}", date("d"), $httpderrlog);
         if (is_file(CONS_HTTPD_ERRDIR . $httpderrlog)) {
             echo "<div style='font-color:red;margin-top:5px'>HTTPD errors detected on {$httpderrlog} log file:</div><br/><pre>";
             echo cReadFile(CONS_HTTPD_ERRDIR . $httpderrlog);
             echo "</pre>";
         }
     }
     if ($die) {
         $this->parent->close(true);
         die;
     }
 }
예제 #3
0
$yesterday = datecalc(date("Y-m-d"), 0, 0, -1);
$day = $yesterday;
$output = array();
$outputstr = "[";
for ($i = 0; $i < $STATEDbrowsers; $i++) {
    $outputstr .= ($i != 0 ? "," : "") . '["' . $simpleList[$i]['browser'] . '","' . $simpleList[$i]['color'] . '"]';
}
$core->template->assign("browsernames", $outputstr . "]");
for ($c = 0; $c < 31; $c++) {
    $dados = array();
    $dados[0] = $day;
    for ($i = 0; $i < $STATEDbrowsers; $i++) {
        $dados[$i + 1] = isset($dias[$day]) ? $dias[$day][$i] : 0;
    }
    $output[] = $dados;
    $day = datecalc($day, 0, 0, -1);
}
$outputstr = "[";
$addComma = false;
foreach ($output as $data) {
    if ($addComma) {
        $outputstr .= ",";
    } else {
        $addComma = true;
    }
    $outputstr .= "[" . implode(",", $data) . "]";
}
$core->template->assign("statsbrowser", $outputstr . "]");
// complete stats
$sql = "SELECT sum(hits) as hits, browser FROM " . $statsb->dbname . " WHERE data>=NOW() - INTERVAL 31 DAY GROUP BY browser ORDER BY hits DESC";
$core->dbo->query($sql, $r, $n);
예제 #4
0
function echoCalendar(&$containerTP, $width = 0, $month = 0, $year = 0, $highlights = array(), $dayborder = 0, $prevquery = "", $nextquery = "", $divname = "inlinecalendar")
{
    /*
      width should be divisible by 7
      highlights is an array, each with the following:
     	'day' => # day
     	'title' => title on the cell (if nothing, will use the day #)
     	'link' => link if click on the cell (if nothing, no link)
     	'class' => (optional) class for the cell
      dayborder is the number in pixels of border (+margin +padding) you will use on each cell
    */
    $tp = new CKTemplate($containerTP);
    if (!is_file(CONS_PATH_SETTINGS . "defaults/calendar.html")) {
        return "echoCalendar: File not found";
    }
    $tp->fetch(CONS_PATH_SETTINGS . "defaults/calendar.html");
    if ($month == 0) {
        $month = date("m");
    }
    if ($year == 0) {
        $year = date("Y");
    }
    $width = 7 * floor($width / 7);
    $widthDay = floor($width / 7) - 2 * $dayborder;
    $month = (int) $month;
    $year = (int) $year;
    if ($year < 100) {
        $year += 2000;
    }
    if ($month < 10) {
        $month = "0" . $month;
    }
    $initDay = $year . "-" . $month . "-01";
    $endDate = datecalc($initDay, 0, 1);
    $monthLine = $tp->get("_line");
    $dayTp = $tp->get("_day");
    $temp = "";
    // <-- main
    $tempL = "";
    // <-- a line
    $column = date("w", tomktime($initDay));
    // where this month starts
    $today = date("Y-m-d");
    $daysOnPreviousMonth = $column;
    while ($daysOnPreviousMonth > 0) {
        $tempL .= $dayTp->techo(array('class' => 'calendarDayEmpty', "title" => "&nbsp;", "widthday" => $widthDay));
        $daysOnPreviousMonth--;
    }
    while (datecompare($endDate, $initDay)) {
        // while we are within the month (loop will increase initDay)
        $isWeekend = $column == 0 || $column == 6;
        $isToday = $initDay == $today;
        $day = substr($initDay, 8, 2);
        // the following line will put the appropriate class on the day depending on start/end of the project, weekend or deadline
        $output = array("class" => $isToday ? "calendarDayToday" : ($isWeekend ? "calendarDayWeekend" : "calendarDayNormal"), "title" => (int) $day, "widthday" => $widthDay);
        // now we check if we have a highlight
        foreach ($highlights as $high) {
            if ($high['day'] == $day) {
                $output['class'] = isset($high['class']) && $high['class'] != '' ? $high['class'] : "calendarDayHighlight";
                $output['title'] = isset($high['title']) ? $high['title'] : (int) $day;
                if (isset($high['link']) && $high['link'] != '') {
                    $output['title'] = "<a href=\"" . $high['link'] . "\">" . $output['title'] . "</a>";
                }
            }
        }
        $tempL .= $dayTp->techo($output);
        if ($column == 6) {
            // end of a line
            $temp .= $monthLine->techo(array("_day" => $tempL));
            // <-- echo line
            $tempL = "";
        }
        $column++;
        if ($column >= 7) {
            $column = 0;
        }
        $initDay = datecalc($initDay, 0, 0, 1);
    }
    if ($column != 0) {
        // we might not have finished the last line ... check it:
        for ($column = $column; $column < 7; $column++) {
            $tempL .= $dayTp->techo(array('class' => 'calendarDayEmpty', "title" => "", "widthday" => $widthDay));
        }
        $temp .= $monthLine->techo(array("_day" => $tempL));
        // <-- echo line
        $tempL = "";
    }
    $tp->assign("width", $width);
    $tp->assign("month", $month);
    $tp->assign("year", $year);
    $tp->assign("widthday", $widthDay);
    $tp->assign("_line", $temp);
    $tp->assign("calendar", $divname);
    if ($prevquery != '' && $nextquery != '') {
        $tp->assign("ajaxcommandprev", $prevquery);
        $tp->assign("ajaxcommandnext", $nextquery);
    } else {
        $tp->assign("_prevnext");
    }
    return $tp->techo();
}
예제 #5
0
파일: cron.php 프로젝트: Prescia/Prescia
                         $this->errorControl->raise(111, 'cleanup-stage');
                         $this->safety = true;
                         # aborts cron as of now
                         return;
                     }
                 }
                 $this->safety = true;
             }
         }
     }
 }
 if (!$this->nearTimeLimit()) {
     # cleans old (90days) logs
     $arquivos = listFiles(CONS_PATH_LOGS . $_SESSION['CODE'] . "/", "/^([^\\.]+)\\.log\$/");
     $hoje = date("Y-m-d");
     $mes = (int) str_replace("-", "", datecalc($hoje, 0, -3));
     # 3 monthes
     foreach ($arquivos as $x => $arquivo) {
         if (substr($arquivo, 0, 3) == "err" || substr($arquivo, 0, 3) == "out" || substr($arquivo, 0, 3) == "act" || substr($arquivo, 0, 3) == "sec") {
             $dt = (int) substr($arquivo, 3, 8);
             // err, out, act, sec
             if ($dt < $mes) {
                 @unlink(CONS_PATH_LOGS . $_SESSION['CODE'] . "/" . $arquivo);
             }
         } else {
             $dt = (int) substr($arquivo, 4, 8);
             // warn
             if ($dt < $mes) {
                 @unlink(CONS_PATH_LOGS . $_SESSION['CODE'] . "/" . $arquivo);
             }
         }
예제 #6
0
파일: logs.php 프로젝트: Prescia/Prescia
$temp = "";
$template = $core->template->get("_actions");
//3 day ago
$previousDay = datecalc(date("Y-m-d"), 0, 0, -3);
$previousDay = str_replace("-", "", $previousDay);
if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/act" . $previousDay . ".log")) {
    appendActs($core, $temp, $template, explode("\n", cReadFile(CONS_PATH_LOGS . $_SESSION['CODE'] . "/act" . $previousDay . ".log")));
}
// 2 day ago
$previousDay = datecalc(date("Y-m-d"), 0, 0, -2);
$previousDay = str_replace("-", "", $previousDay);
if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/act" . $previousDay . ".log")) {
    appendActs($core, $temp, $template, explode("\n", cReadFile(CONS_PATH_LOGS . $_SESSION['CODE'] . "/act" . $previousDay . ".log")));
}
// 1 day ago
$previousDay = datecalc(date("Y-m-d"), 0, 0, -1);
$previousDay = str_replace("-", "", $previousDay);
if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/act" . $previousDay . ".log")) {
    appendActs($core, $temp, $template, explode("\n", cReadFile(CONS_PATH_LOGS . $_SESSION['CODE'] . "/act" . $previousDay . ".log")));
}
# Today
$previousDay = date("Ymd");
if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/act" . $previousDay . ".log")) {
    appendActs($core, $temp, $template, explode("\n", cReadFile(CONS_PATH_LOGS . $_SESSION['CODE'] . "/act" . $previousDay . ".log")));
}
$core->template->assign("_actions", $temp);
//404 errors 24h
if (isset($_REQUEST['clean404'])) {
    @unlink(CONS_PATH_LOGS . $_SESSION['CODE'] . "/404.log");
} else {
    if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/404.log")) {
예제 #7
0
파일: module.php 프로젝트: Prescia/Prescia
 function onCron($isDay = false)
 {
     # cron Triggered, isDay or isHour
     if (!$isDay) {
         # hourly
         $totalTime = scriptTime() * 1000;
         $data = array(date("H"), 0, 0, 0, 0, 0);
         $data[0] = date("H");
         if (CONS_CACHE && $this->parent->cacheControl->contentFromCache) {
             $data[2] = $totalTime;
         } else {
             $data[1] = $totalTime;
         }
         $this->resetSTdata($data);
     } else {
         # daily
         $core =& $this->parent;
         # daily statistics:
         $previousDay = datecalc(date("Y-m-d"), 0, 0, -1);
         $x = $core->dbo->fetch("SELECT hits FROM " . $core->modules['statsdaily']->dbname . " WHERE data='" . $previousDay . "'");
         if ($x === false) {
             # nothing yet registered on history
             if ($core->dbo->query("SELECT SUM(hits), SUM(uhits), SUM(bhits), SUM(rhits), hid, page,lang FROM " . $core->modules['stats']->dbname . " WHERE data='" . $previousDay . "' GROUP BY hid, page, lang", $r, $n)) {
                 for ($c = 0; $c < $n; $c++) {
                     list($hits, $uhits, $bhits, $rhits, $hid, $page, $lang) = $core->dbo->fetch_row($r);
                     $core->dbo->simpleQuery("INSERT INTO " . $core->modules['statsdaily']->dbname . " SET lang='{$lang}', hid='{$hid}', data='{$previousDay}', page=\"{$page}\", hits={$hits}, uhits={$uhits}, bhits={$bhits}, rhits={$rhits}");
                 }
             }
         }
         # daily referers:
         $x = $core->dbo->fetch("SELECT hits FROM " . $core->modules['statsrefdaily']->dbname . " WHERE data='" . $previousDay . "'");
         if ($x === false) {
             # nothing yet registered on history
             if ($core->dbo->query("SELECT referer,entrypage,hits FROM " . $core->modules['statsref']->dbname . " WHERE data='" . $previousDay . "'", $r, $n)) {
                 for ($c = 0; $c < $n; $c++) {
                     list($ref, $ep, $hits) = $core->dbo->fetch_row($r);
                     $core->dbo->simpleQuery("INSERT INTO " . $core->modules['statsrefdaily']->dbname . " SET data='{$previousDay}', referer=\"{$ref}\", hits={$hits}, entrypage=\"{$ep}\"");
                 }
             }
         }
     }
     # done
 }
예제 #8
0
for ($c = 0; $c < $n; $c++) {
    list($data, $hits, $uhits, $bhits, $rhits) = $core->dbo->fetch_row($r);
    $outputArr[$data] = array($hits, $uhits, $bhits, $rhits, 0);
}
$sql = "SELECT data,sum(hits) FROM " . $statsrObj->dbname . " WHERE referer=\"\" GROUP BY data ORDER BY data DESC";
$core->dbo->query($sql, $r, $n);
for ($c = 0; $c < $n; $c++) {
    list($data, $khits) = $core->dbo->fetch_row($r);
    if (isset($outputArr[$data])) {
        $outputArr[$data][4] = $khits;
    } else {
        $outputArr[$data] = array($khits, $khits, 0, 0, $khits);
    }
}
$yesterday = datecalc(date("Y-m-d"), 0, 0, -1);
$output = array();
while (isset($outputArr[$yesterday])) {
    $output[] = array($yesterday, $outputArr[$yesterday][0], $outputArr[$yesterday][1], $outputArr[$yesterday][2], $outputArr[$yesterday][3], $outputArr[$yesterday][4]);
    $yesterday = datecalc($yesterday, 0, 0, -1);
}
$outputstr = "# DATE, HITS, UNIQUE, ACCEPTED UNIQUE, RETURN IN 24h UNIQUE, CAME FROM BOOKMARK UNIQUE\n";
foreach ($output as $o) {
    $outputstr .= "\"" . array_shift($o) . "\"," . implode(",", $o) . "\n";
}
header("Content-Description: File Transfer");
header("Content-Length: " . strlen($outputstr));
header("Pragma: public");
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=\"statistics" . date("Y-m-d") . ".csv\"");
echo $outputstr;
$core->close();
예제 #9
0
파일: module.php 프로젝트: Prescia/Prescia
 function notifyEvent(&$module, $action, $data, $startedAt = "", $earlyNotify = false)
 {
     if ($module === false && $action == "fmanager_upload") {
         // if this is a safe upload, apply user permission
         $arquivo = $data;
         $core =& $this->parent;
         $mod = $this->parent->loaded($this->moduleRelation);
         if ($arquivo[0] != '/') {
             $arquivo = "/" . $arquivo;
         }
         if (substr($arquivo, 0, strlen("/" . CONS_FMANAGER . CONS_FMANAGER_SAFE . "/")) == "/" . CONS_FMANAGER . CONS_FMANAGER_SAFE . "/") {
             // yes, it is
             $arquivo = substr($arquivo, strlen(CONS_FMANAGER . CONS_FMANAGER_SAFE) + 2);
             // +2 for the /.../
             $data = array('filenm' => $arquivo, 'has_expiration' => $core->dimconfig['default_fm_time'] == 0 ? 'n' : 'y', 'id_allowed_group' => '0', 'allowed_users' => $_SESSION[CONS_SESSION_ACCESS_USER]['id'], 'expiration_date' => '0000-00-00');
             if ($core->dimconfig['default_fm_time'] != '0') {
                 $today = date("Y-m-d");
                 $today = datecalc($today, 0, 0, $core->dimconfig['default_fm_time']);
                 $data['expiration_date'] = $today;
             }
             $buffer = $core->safety;
             $core->safety = false;
             $sql = "SELECT filenm FROM " . $mod->dbname . " WHERE filenm LIKE \"" . $arquivo . "\"";
             $hasData = $core->dbo->fetch($sql) !== false;
             if ($hasData) {
                 $core->runAction($mod, CONS_ACTION_UPDATE, $data);
             } else {
                 $core->runAction($mod, CONS_ACTION_INCLUDE, $data);
             }
             $core->safety = $buffer;
         }
     } else {
         if ($module === false && $action == "fmanager_delete") {
             $arquivo = $data;
             $core =& $this->parent;
             $mod = $this->parent->loaded($this->moduleRelation);
             if ($arquivo[0] != '/') {
                 $arquivo = "/" . $arquivo;
             }
             if (substr($arquivo, 0, strlen("/" . CONS_FMANAGER . CONS_FMANAGER_SAFE . "/")) == "/" . CONS_FMANAGER . CONS_FMANAGER_SAFE . "/") {
                 $arquivo = substr($arquivo, strlen(CONS_FMANAGER . CONS_FMANAGER_SAFE) + 2);
                 // +2 for the /.../
                 $sql = "DELETE FROM " . $mod->dbname . " WHERE filenm LIKE \"" . $arquivo . "\"";
                 $buffer = $core->safety;
                 $core->safety = false;
                 $core->dbo->simpleQuery($sql);
                 $core->safety = $buffer;
             }
         }
     }
 }
예제 #10
0
    if ($data[1] > $biggest) {
        $biggest = $data[1];
    }
}
$graphObj = $core->template->get("_day");
$dataObj = $core->template->get("_day2");
$outputTop = "";
$outputBottom = "";
$day = $weekAgo;
for ($c = 0; $c < 7; $c++) {
    $ph = $dias[$day]['hits'] / $biggest;
    $dias[$day]['top'] = $graphHeight - ceil($ph * $graphHeight);
    $dias[$day]['height'] = ceil($ph * $graphHeight);
    $outputTop .= $graphObj->techo($dias[$day]);
    $outputBottom .= $dataObj->techo($dias[$day]);
    $day = datecalc($day, 0, 0, 1);
}
$core->template->assign("_day", $outputTop);
$core->template->assign("_day2", $outputBottom);
$outputTop = "";
$outputBorrom = "";
unset($dias);
## how many hits in this interval the page had? ##
$phits = $core->dbo->fetch("SELECT sum(hits) FROM " . $statsh->dbname . " WHERE data >= '{$dataini}' AND data < '{$datafim}' AND page=\"{$page}\"");
## ENTRY PAGES ##
$statspath = $core->loaded('statspath');
$sql = "SELECT sum(hits) as shits, page FROM " . $statspath->dbname . " WHERE pagefoward='{$page}' AND data >= '{$dataini}' AND data < '{$datafim}' GROUP BY page ORDER BY shits DESC";
$core->dbo->query($sql, $r, $n);
$graphObj = $core->template->get("_pg");
$output = "";
$pages = array();