function logrotatelogs($nopid = false) { $unix = new unix(); $sock = new sockets(); if ($nopid) { $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidpath); if ($unix->process_exists($pid)) { $pidtime = $unix->PROCCESS_TIME_MIN($pid); system_admin_events(basename(__FILE__) . ":: " . __FUNCTION__ . " Already process {$pid} running since {$pidtime} Mn.. Aborting", __FUNCTION__, __FILE__, __LINE__); return; } @file_put_contents($pidpath, getmypid()); } $echo = $unix->find_program("echo"); $LogsRotateDeleteSize = $sock->GET_INFO("LogsRotateDeleteSize"); if (!is_numeric($LogsRotateDeleteSize)) { $LogsRotateDeleteSize = 5000; } include_once dirname(__FILE__) . "/ressources/class.mysql.syslog.inc"; if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . " line:" . __LINE__ . "\n"; } $q = new mysql_syslog(); if ($q->COUNT_ROWS("logrotate") == 0) { $q->CheckDefaults(); } $sql = "SELECT RotateFiles FROM logrotate WHERE enabled=1"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { echo $q->mysql_error; } while ($ligne = mysql_fetch_assoc($results)) { $filepath = $ligne["RotateFiles"]; if (strpos($filepath, "*") > 0) { if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . ":: Scanning {$filepath} line:" . __LINE__ . "\n"; } foreach (glob($filepath) as $filename) { $size = $unix->file_size($filename); $size = $size / 1024; $size = round($size / 1000, 2); $ARRAY[$filename] = $size; } } else { if (is_file($filepath)) { $size = $unix->file_size($filepath); $size = $size / 1024; $size = round($size / 1000, 2); $ARRAY[$filepath] = $size; } if (is_dir($filepath)) { while (list($num, $filename) = each($f)) { $filepath = "/var/log/{$filename}"; $f = $unix->DirFiles("{$filepath}"); $size = $unix->file_size($filepath); $size = $size / 1024; $size = round($size / 1000, 2); $ARRAY[$filepath] = $size; } } } } $f = $unix->DirFiles("/var/log"); while (list($num, $filename) = each($f)) { $filepath = "/var/log/{$filename}"; $size = $unix->file_size($filepath); $size = $size / 1024; $size = round($size / 1000, 2); $ARRAY[$filepath] = $size; } $f = $unix->DirFiles("/var/log/artica-postfix"); while (list($num, $filename) = each($f)) { $filepath = "/var/log/artica-postfix/{$filename}"; $size = $unix->file_size($filepath); $size = $size / 1024; $size = round($size / 1000, 2); $ARRAY[$filepath] = $size; } $restart = false; while (list($filepath, $sizeM) = each($ARRAY)) { if ($sizeM > $LogsRotateDeleteSize) { shell_exec("{$echo} \"\" >{$filepath}"); $restart = true; $unix->send_email_events("{$filepath} was cleaned ({$sizeM}M)", "It exceed maximal size {$LogsRotateDeleteSize}M", "system"); } } if ($restart) { shell_exec("/etc/init.d/syslog restart"); shell_exec("/etc/init.d/artica-syslog restart"); shell_exec("/etc/init.d/auth-tail restart"); shell_exec("/etc/init.d/postfix-logger restart"); } }
function search() { $tpl = new templates(); $MyPage = CurrentPageName(); $q = new mysql_syslog(); $search = '%'; $table = "logrotate"; $page = 1; $ORDER = "ORDER BY ID DESC"; $sock = new sockets(); $t = $_GET["t"]; if (!$q->TABLE_EXISTS($table)) { $q->CheckTables(); } if ($q->COUNT_ROWS($table) == 0) { $q->CheckDefaults(); } $total = 0; if ($q->COUNT_ROWS($table, $database) == 0) { $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); echo json_encode($data); return; } if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if (isset($_POST['page'])) { $page = $_POST['page']; } if ($_POST["query"] != null) { $_POST["query"] = "*" . $_POST["query"] . "*"; $_POST["query"] = str_replace("**", "*", $_POST["query"]); $_POST["query"] = str_replace("**", "*", $_POST["query"]); $_POST["query"] = str_replace("*", "%", $_POST["query"]); $search = $_POST["query"]; $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')"; $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$searchstring}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database)); $total = $ligne["TCOUNT"]; } else { $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database)); $total = $ligne["TCOUNT"]; } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } $pageStart = ($page - 1) * $rp; $limitSql = "LIMIT {$pageStart}, {$rp}"; $sql = "SELECT * FROM `{$table}` WHERE 1 {$searchstring} {$ORDER} {$limitSql}"; writelogs($sql, __FUNCTION__, __FILE__, __LINE__); $results = $q->QUERY_SQL($sql, $database); $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); if (!$q->ok) { $data['rows'][] = array('id' => $ligne[time() + 1], 'cell' => array($q->mysql_error, "", "", "")); $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", "")); echo json_encode($data); return; } //######" //TimeText TimeDescription TaskType enabled $q2 = new mysql(); while ($ligne = mysql_fetch_assoc($results)) { $color = "black"; $events = " "; $md5 = md5("RotateTask{$ligne['ID']}"); $jstaskexplain = $tpl->javascript_parse_text($q->tasks_array[$ligne["TaskType"]]); $ligne["TaskType"] = $tpl->_ENGINE_parse_body($q->tasks_array[$ligne["TaskType"]]); $enable = Field_checkbox($md5, 1, $ligne["enabled"], "RotateTaskEnable('{$md5}',{$ligne['ID']})"); $delete = imgtootltip("delete-24.png", "{delete} {$ligne['ID']}", "RotateTaskDelete('{$ligne['ID']}')"); if ($ligne["enabled"] == 0) { $color = "#A0A0A0"; } $jsEdit = "Loadjs('{$MyPage}?Rotate-js=yes&ID={$ligne['ID']}&t={$t}');"; $RotateFreq = $tpl->_ENGINE_parse_body("{{$ligne["RotateFreq"]}}"); $description = utf8_encode($tpl->_ENGINE_parse_body("{$ligne["description"]}")); $description = htmlentities($description); $span = "<a href=\"javascript:blur();\" OnClick=\"javascript:{$jsEdit}\"\n\t\t style='font-size:16px;font-weight:bold;color:{$color};text-decoration:underline'>"; //rowSquidTask $data['rows'][] = array('id' => "RotateTask" . $ligne['ID'], 'cell' => array("{$span}{$ligne['ID']}</a>", "{$span}{$ligne["RotateFiles"]}</a>", "{$span}{$ligne["MaxSize"]}M</a>", "{$span}{$RotateFreq}</span>", $description, "<div style='margin-top:5px'>{$enable}</div>", $delete)); } echo json_encode($data); }