2014-10-07 15:58:46 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
function mktimeDate ($date)
|
|
|
|
|
{
|
|
|
|
|
$arrayAux = getdate( strtotime( $date ) );
|
|
|
|
|
$mktDate = mktime( $arrayAux["hours"], $arrayAux["minutes"], $arrayAux["seconds"], $arrayAux["mon"], $arrayAux["mday"], $arrayAux["year"] );
|
|
|
|
|
return $mktDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function auditLogArraySet ($str, $filter)
|
|
|
|
|
{
|
|
|
|
|
$arrayAux = explode( "|", $str );
|
|
|
|
|
$date = "";
|
|
|
|
|
$workspace = "";
|
|
|
|
|
$action = "";
|
2014-10-13 11:50:17 -04:00
|
|
|
$ip = "";
|
2014-10-07 15:58:46 -04:00
|
|
|
$user = "";
|
|
|
|
|
$description = "";
|
|
|
|
|
|
|
|
|
|
if (count( $arrayAux ) > 1) {
|
|
|
|
|
$date = (isset( $arrayAux[0] )) ? trim( $arrayAux[0] ) : "";
|
|
|
|
|
$workspace = (isset( $arrayAux[1] )) ? trim( $arrayAux[1] ) : "";
|
2014-10-08 09:50:54 -04:00
|
|
|
$ip = (isset( $arrayAux[2] )) ? trim( $arrayAux[2] ) : "";
|
|
|
|
|
$user = (isset( $arrayAux[4] )) ? trim( $arrayAux[4] ) : "";
|
|
|
|
|
$action = (isset( $arrayAux[5] )) ? trim( $arrayAux[5] ) : "";
|
|
|
|
|
$description = (isset( $arrayAux[6] )) ? trim( $arrayAux[6] ) : "";
|
2014-10-07 15:58:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mktDate = (! empty( $date )) ? mktimeDate( $date ) : 0;
|
|
|
|
|
|
|
|
|
|
//Filter
|
|
|
|
|
$sw = 1;
|
|
|
|
|
if ($workspace != $filter["workspace"]) {
|
|
|
|
|
$sw = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-10 12:19:34 -04:00
|
|
|
if ($filter["action"] != "ALL") {
|
|
|
|
|
if ($action != $filter["action"]) {
|
|
|
|
|
$sw = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 15:58:46 -04:00
|
|
|
if ($filter["dateFrom"] && $mktDate > 0) {
|
|
|
|
|
if (! (mktimeDate( $filter["dateFrom"] ) <= $mktDate)) {
|
|
|
|
|
$sw = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($filter["dateTo"] && $mktDate > 0) {
|
|
|
|
|
if (! ($mktDate <= mktimeDate( $filter["dateTo"] . " 23:59:59" ))) {
|
|
|
|
|
$sw = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($filter["description"]) {
|
|
|
|
|
$sw = 0;
|
|
|
|
|
$string = $filter["description"];
|
|
|
|
|
|
2014-10-08 09:50:54 -04:00
|
|
|
if ( (stristr($date, $string) !== false) || (stristr($ip, $string) !== false) || (stristr($user, $string) !== false) || (stristr($action, $string) !== false) || (stristr($description, $string) !== false) ) {
|
2014-10-07 15:58:46 -04:00
|
|
|
$sw = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arrayData = array ();
|
2014-10-10 12:19:34 -04:00
|
|
|
$newAction = preg_replace('/([A-Z])/', '_$1', $action);
|
|
|
|
|
$newAction = "ID".strtoupper($newAction);
|
2014-10-07 15:58:46 -04:00
|
|
|
|
|
|
|
|
if ($sw == 1) {
|
2014-10-10 12:19:34 -04:00
|
|
|
$arrayData = array ("DATE" => $date, "USER" => $user, "IP" =>$ip, "ACTION" => G::LoadTranslation($newAction), "DESCRIPTION" => $description);
|
2014-10-07 15:58:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $arrayData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getAuditLogData ($filter, $r, $i)
|
|
|
|
|
{
|
|
|
|
|
$arrayData = array ();
|
|
|
|
|
$strAux = null;
|
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
|
|
$file = PATH_DATA . "log" . PATH_SEP . "audit.log";
|
|
|
|
|
|
|
|
|
|
if (file_exists($file)) {
|
|
|
|
|
$arrayFileData = file($file);
|
|
|
|
|
|
|
|
|
|
for ($k = 0; $k < count($arrayFileData); $k++) {
|
|
|
|
|
|
|
|
|
|
$strAux = $arrayFileData[$k];
|
|
|
|
|
|
|
|
|
|
if ($strAux) {
|
|
|
|
|
$arrayAux = auditLogArraySet($strAux, $filter);
|
|
|
|
|
if (count($arrayAux) > 0) {
|
|
|
|
|
$count = $count + 1;
|
|
|
|
|
|
|
|
|
|
if ($count > $i && count($arrayData) < $r) {
|
|
|
|
|
$arrayData[] = $arrayAux;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-10 12:19:34 -04:00
|
|
|
|
2014-10-07 15:58:46 -04:00
|
|
|
return array($count, $arrayData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$option = (isset( $_REQUEST["option"] )) ? $_REQUEST["option"] : null;
|
|
|
|
|
|
|
|
|
|
$response = array ();
|
|
|
|
|
|
|
|
|
|
switch ($option) {
|
|
|
|
|
case "LST":
|
|
|
|
|
$pageSize = $_REQUEST["pageSize"];
|
|
|
|
|
$workspace = SYS_SYS;
|
2014-10-10 12:19:34 -04:00
|
|
|
$action = $_REQUEST["action"];
|
2014-10-07 15:58:46 -04:00
|
|
|
$description = $_REQUEST["description"];
|
|
|
|
|
$dateFrom = $_REQUEST["dateFrom"];
|
|
|
|
|
$dateTo = $_REQUEST["dateTo"];
|
|
|
|
|
|
2014-10-10 12:19:34 -04:00
|
|
|
$arrayFilter = array ("workspace" => $workspace, "action" => $action, "description" => $description,"dateFrom" => str_replace( "T00:00:00", null, $dateFrom ),"dateTo" => str_replace( "T00:00:00", null, $dateTo )
|
2014-10-07 15:58:46 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$limit = isset( $_REQUEST["limit"] ) ? $_REQUEST["limit"] : $pageSize;
|
|
|
|
|
$start = isset( $_REQUEST["start"] ) ? $_REQUEST["start"] : 0;
|
|
|
|
|
|
|
|
|
|
list ($count, $data) = getAuditLogData( $arrayFilter, $limit, $start );
|
|
|
|
|
$response = array ("success" => true,"resultTotal" => $count,"resultRoot" => $data
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case "EMPTY":
|
|
|
|
|
$status = 1;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$file = PATH_DATA . "log" . PATH_SEP . "cron.log";
|
|
|
|
|
|
|
|
|
|
if (file_exists( $file )) {
|
|
|
|
|
unlink( $file );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response["status"] = "OK";
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$response["message"] = $e->getMessage();
|
|
|
|
|
$status = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($status == 0) {
|
|
|
|
|
$response["status"] = "ERROR";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo G::json_encode( $response );
|