Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add dirname and filename in log table to be able to filter on these. …
Browse files Browse the repository at this point in the history
…Pass a "files" array to the log method when possible.
  • Loading branch information
cdujeu committed Oct 20, 2015
1 parent 8a1ea18 commit 3be5742
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 43 deletions.
15 changes: 8 additions & 7 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -437,7 +437,7 @@ public function switchAction($action, $httpVars, $fileVars)
$code = $httpVars["content"];
$currentNode = $selection->getUniqueNode();
$fileName = $currentNode->getUrl();
$this->logInfo("Online Edition", array("file"=>$fileName));
$this->logInfo("Online Edition", array("files"=> $this->addSlugToPath($fileName)));
if (isSet($httpVars["encode"]) && $httpVars["encode"] == "base64") {
$code = base64_decode($code);
} else {
Expand Down Expand Up @@ -578,7 +578,7 @@ public function switchAction($action, $httpVars, $fileVars)
if(!isSet($nodesDiffs)) $nodesDiffs = $this->getNodesDiffArray();
if($dest == null) $dest = AJXP_Utils::safeDirname($file);
$nodesDiffs["UPDATE"][$file] = new AJXP_Node($this->urlBase.$dest."/".$filename_new);
$this->logInfo("Rename", array("original"=>$this->addSlugToPath($file), "new"=>$filename_new));
$this->logInfo("Rename", array("files"=>$this->addSlugToPath($file), "original"=>$this->addSlugToPath($file), "new"=>$filename_new));

break;

Expand Down Expand Up @@ -618,7 +618,7 @@ public function switchAction($action, $httpVars, $fileVars)
$messages[] = $messtmp;
$newNode = new AJXP_Node($this->urlBase.$parentDir."/".$basename);
array_push($nodesDiffs["ADD"], $newNode);
$this->logInfo("Create Dir", array("dir"=>$this->addSlugToPath($parentDir)."/".$basename));
$this->logInfo("Create Dir", array("dir"=>$this->addSlugToPath($parentDir)."/".$basename, "files"=>$this->addSlugToPath($parentDir)."/".$basename));
}
if(count($errors)){
if(!count($messages)){
Expand Down Expand Up @@ -662,7 +662,7 @@ public function switchAction($action, $httpVars, $fileVars)
$logMessage = $messtmp;
//$reloadContextNode = true;
//$pendingSelection = $dir."/".$filename;
$this->logInfo("Create File", array("file"=>$this->addSlugToPath($dir)."/".$filename));
$this->logInfo("Create File", array("files"=>$this->addSlugToPath($dir)."/".$filename));
$newNode = new AJXP_Node($this->urlBase.$dir."/".$filename);
if(!isSet($nodesDiffs)) $nodesDiffs = $this->getNodesDiffArray();
array_push($nodesDiffs["ADD"], $newNode);
Expand All @@ -683,7 +683,7 @@ public function switchAction($action, $httpVars, $fileVars)
$this->chmod($fileName, $chmod_value, ($recursive=="on"), ($recursive=="on"?$recur_apply_to:"both"), $changedFiles);
}
$logMessage="Successfully changed permission to ".$chmod_value." for ".count($changedFiles)." files or folders";
$this->logInfo("Chmod", array("dir"=>$this->addSlugToPath($dir), "filesCount"=>count($changedFiles)));
$this->logInfo("Chmod", array("dir"=>$this->addSlugToPath($dir), "files"=>$this->addSlugToPath($dir), "filesCount"=>count($changedFiles)));
if(!isSet($nodesDiffs)) $nodesDiffs = $this->getNodesDiffArray();
$nodesDiffs["UPDATE"] = array_merge($nodesDiffs["UPDATE"], $selection->buildNodes());

Expand Down Expand Up @@ -793,7 +793,8 @@ public function switchAction($action, $httpVars, $fileVars)
clearstatcache(true, $createdNode->getUrl());
$createdNode->loadNodeInfo(true);
$logMessage.="$mess[34] ".SystemTextEncoding::toUTF8($userfile_name)." $mess[35] $dir";
$this->logInfo("Upload File", array("file"=>$this->addSlugToPath(SystemTextEncoding::fromUTF8($dir))."/".$userfile_name));
$logFile = $this->addSlugToPath(SystemTextEncoding::fromUTF8($dir))."/".$userfile_name;
$this->logInfo("Upload File", array("file"=>$logFile, "files"=> $logFile ) );

if($partialUpload){
$this->logDebug("Return Partial Upload: SUCESS but no event yet");
Expand Down Expand Up @@ -1982,7 +1983,7 @@ private function purge($fileName)
AJXP_Controller::applyHook("node.before_path_change", array($node));
unlink($fileName);
AJXP_Controller::applyHook("node.change", array($node));
$this->logInfo("Purge", array("file" => $fileName));
$this->logInfo("Purge", array("file" => $fileName, "files" => $fileName));
print(" - Purging document : ".$fileName."\n");
}

Expand Down
4 changes: 4 additions & 0 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -923,6 +923,7 @@ public function writePubliclet(&$data, $accessDriver, $repository)
$url = $this->buildPublicletLink($hash);
$this->logInfo("New Share", array(
"file" => "'".$copy->display.":/".$data['FILE_PATH']."'",
"files" => "'".$copy->display.":/".$data['FILE_PATH']."'",
"url" => $url,
"expiration" => $data['EXPIRE_TIME'],
"limit" => $data['DOWNLOAD_LIMIT'],
Expand Down Expand Up @@ -1706,8 +1707,10 @@ public function createSharedMinisite($httpVars, $repository, $accessDriver)
return $e->getMessage();
}
$url = $this->buildPublicletLink($hash);
$files = $userSelection->getFiles();
$this->logInfo("New Share", array(
"file" => "'".$httpVars['file']."'",
"files" => $files,
"url" => $url,
"expiration" => $data['EXPIRE_TIME'],
"limit" => $data['DOWNLOAD_LIMIT'],
Expand Down Expand Up @@ -1740,6 +1743,7 @@ public function createSharedMinisite($httpVars, $repository, $accessDriver)
$url = $this->buildPublicletLink($hash);
$this->logInfo("Update Share", array(
"file" => "'".$httpVars['file']."'",
"files" => "'".$httpVars['file']."'",
"url" => $url,
"expiration" => $data['EXPIRE_TIME'],
"limit" => $data['DOWNLOAD_LIMIT'],
Expand Down
15 changes: 10 additions & 5 deletions core/src/plugins/core.log/class.AJXP_Logger.php
Expand Up @@ -59,16 +59,17 @@ public function getLoggerInstance()
/**
* Use current logger instance and write a message at the desired loglevel
* @static
* @param string $level The log level
* @param string $source The source of the message (plugin id or classname)
* @param string $prefix A quick description
* @param string $level The log level
* @param string $source The source of the message (plugin id or classname)
* @param string $prefix A quick description
* @param array $messages An array of messages (string or array).
* @return void
* @param array $nodePathes Optional array of pathes
*/
public static function log2($level, $source, $prefix, $messages = array())
{
$res = "";
$i = 0;
$nodePathes = array();
foreach ($messages as $value) {
if($i > 0) $res .= "\t";
$i++;
Expand All @@ -77,6 +78,10 @@ public static function log2($level, $source, $prefix, $messages = array())
$res .= $value;
} else if (is_array($value) && count($value)) {
$res .= self::arrayToString($value);
if(isSet($value["files"])) {
if(is_array($value["files"])) $nodePathes = $value["files"];
else $nodePathes[] = $value["files"];
}
} else if (!empty($value)) {
$res .= print_r($value, true);
}
Expand All @@ -87,7 +92,7 @@ public static function log2($level, $source, $prefix, $messages = array())
$logger = self::getInstance();
if ($logger != null) {
try {
$logger->write2($level, $ip, $user, $source, $prefix, $res);
$logger->write2($level, $ip, $user, $source, $prefix, $res, $nodePathes);
if ( $level == LOG_LEVEL_ERROR && self::$globalOptions["ERROR_TO_ERROR_LOG"] === true) {
error_log("[PYDIO] IP $ip | user $user | $level | $prefix | from $source | ".$res);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/core.log/class.AbstractLogDriver.php
Expand Up @@ -59,7 +59,7 @@ abstract class AbstractLogDriver extends AJXP_Plugin
* @param String $message The message to log
*
*/
public function write2($level, $ip, $user, $source, $prefix, $message)
public function write2($level, $ip, $user, $source, $prefix, $message, $nodePathes = array())
{
//for backward compatibility
$this->write($source."\t".$prefix."\t".$message, $level);
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.audio/class.AudioPreviewer.php
Expand Up @@ -77,7 +77,7 @@ public function switchAction($action, $httpVars, $postProcessData)
fclose($stream);

AJXP_Controller::applyHook("node.read", array($node));
$this->logInfo('Preview', 'Read content of '.$node->getUrl());
$this->logInfo('Preview', 'Read content of '.$node->getUrl(), array("files" => $node->getUrl()));
//exit(1);

} else if ($action == "ls") {
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.browser/class.FileMimeSender.php
Expand Up @@ -104,7 +104,7 @@ public function switchAction($action, $httpVars, $filesVars)
fclose($stream);

AJXP_Controller::applyHook("node.read", array($selectedNode));
$this->logInfo('Download', 'Read content of '.$selectedNodeUrl);
$this->logInfo('Download', 'Read content of '.$selectedNodeUrl, array("files" => $selectedNodeUrl));

}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.diaporama/class.ImagePreviewer.php
Expand Up @@ -49,7 +49,7 @@ public function switchAction($action, $httpVars, $filesVars)
header("Content-Length: 0");
return;
}
$this->logInfo('Preview', 'Preview content of '.$file);
$this->logInfo('Preview', 'Preview content of '.$file, array("files" =>$selection->getUniqueFile()));
if (isSet($httpVars["get_thumb"]) && $httpVars["get_thumb"] == "true" && $this->getFilteredOption("GENERATE_THUMBNAIL", $repository->getId())) {
$dimension = 200;
if(isSet($httpVars["dimension"]) && is_numeric($httpVars["dimension"])) $dimension = $httpVars["dimension"];
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.imagick/class.IMagickPreviewer.php
Expand Up @@ -67,7 +67,7 @@ public function switchAction($action, $httpVars, $filesVars)
throw new Exception("Cannot find file");
}
if(isSet($httpVars["all"])) {
$this->logInfo('Preview', 'Preview content of '.$file);
$this->logInfo('Preview', 'Preview content of '.$file, array("files" => $file));
$this->extractAll = true;
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/editor.pixlr/class.PixlrEditor.php
Expand Up @@ -51,7 +51,7 @@ public function switchAction($action, $httpVars, $filesVars)
$target = rtrim(base64_decode($httpVars["parent_url"]), '/') ."/plugins/editor.pixlr";
$tmp = AJXP_MetaStreamWrapper::getRealFSReference($selectedNodeUrl);
$tmp = SystemTextEncoding::fromUTF8($tmp);
$this->logInfo('Preview', 'Sending content of '.$selectedNodeUrl.' to Pixlr server.');
$this->logInfo('Preview', 'Sending content of '.$selectedNodeUrl.' to Pixlr server.', array("files" => $selectedNodeUrl));
AJXP_Controller::applyHook("node.read", array($selectedNode));


Expand Down Expand Up @@ -100,7 +100,7 @@ public function switchAction($action, $httpVars, $filesVars)
$file = AJXP_Utils::decodeSecureMagic($httpVars["original_file"]);
$selectedNode = new AJXP_Node($selection->currentBaseUrl() . $file);
$selectedNode->loadNodeInfo();
$this->logInfo('Edit', 'Retrieving content of '.$file.' from Pixlr server.');
$this->logInfo('Edit', 'Retrieving content of '.$file.' from Pixlr server.', array("files" => $file));
AJXP_Controller::applyHook("node.before_change", array(&$selectedNode));
$url = $httpVars["new_url"];
$urlParts = parse_url($url);
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/editor.video/class.VideoReader.php
Expand Up @@ -66,7 +66,7 @@ public function switchAction($action, $httpVars, $filesVars)
$offsets = explode('-', $ranges[1]);
$offset = floatval($offsets[0]);
if($offset == 0){
$this->logInfo('Preview', 'Streaming content of '.$filename);
$this->logInfo('Preview', 'Streaming content of '.$filename, array("files" => $filename));
}

$length = floatval($offsets[1]) - $offset + 1;
Expand Down Expand Up @@ -104,7 +104,7 @@ public function switchAction($action, $httpVars, $filesVars)
}
fclose($file);
} else {
$this->logInfo('Preview', 'Streaming content of '.$filename);
$this->logInfo('Preview', 'Streaming content of '.$filename, array("files" => $filename));
header("Content-Length: ".$filesize);
header("Content-Range: bytes 0-" . ($filesize - 1) . "/" . $filesize. ";");
header('Cache-Control: public');
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/editor.zoho/class.ZohoEditor.php
Expand Up @@ -124,7 +124,7 @@ public function switchAction($action, $httpVars, $filesVars)

$node = new AJXP_Node($destStreamURL.$file);
AJXP_Controller::applyHook("node.read", array($node));
$this->logInfo('Preview', 'Posting content of '.$file.' to Zoho server');
$this->logInfo('Preview', 'Posting content of '.$file.' to Zoho server', array("files" => $file));

$extension = strtolower(pathinfo(urlencode(basename($file)), PATHINFO_EXTENSION));
$httpClient = new http_class();
Expand Down Expand Up @@ -220,7 +220,7 @@ public function switchAction($action, $httpVars, $filesVars)
echo "MODIFIED";
}
}
$this->logInfo('Edit', 'Retrieved content of '.$node->getUrl());
$this->logInfo('Edit', 'Retrieved content of '.$node->getUrl(), array("files" => $node->getUrl()));
AJXP_Controller::applyHook("node.change", array(null, &$node));
}

Expand Down
53 changes: 36 additions & 17 deletions core/src/plugins/log.sql/class.sqlLogDriver.php
Expand Up @@ -104,7 +104,8 @@ protected function processOneQuery($queryName, $start, $count, $frequency="auto"
$endDate = date($endFormat, strtotime("-$start day", $ref));
$dateCursor = "logdate > '$startDate' AND logdate <= '$endDate'";
foreach($additionalFilters as $filterField => $filterValue){
$dateCursor .= " AND [".AJXP_Utils::sanitize($filterField, AJXP_SANITIZE_ALPHANUM)."] = '".AJXP_Utils::sanitize($filterValue, AJXP_SANITIZE_EMAILCHARS)."'";
$comparator = (strpos($filterValue, "%") !== false ? "LIKE" : "=");
$dateCursor .= " AND [".AJXP_Utils::sanitize($filterField, AJXP_SANITIZE_ALPHANUM)."] $comparator '".AJXP_Utils::sanitize($filterValue, AJXP_SANITIZE_EMAILCHARS)."'";
}

$q = $query["SQL"];
Expand Down Expand Up @@ -207,6 +208,13 @@ public function processQuery($actionName, &$httpVars, &$fileVars){
$additionalFilters = array();
if(isSet($httpVars["user"])) $additionalFilters["user"] = AJXP_Utils::sanitize($httpVars["user"], AJXP_SANITIZE_EMAILCHARS);
if(isSet($httpVars["ws_id"])) $additionalFilters["repository_id"] = AJXP_Utils::sanitize($httpVars["ws_id"], AJXP_SANITIZE_ALPHANUM);
if(isSet($httpVars["filename_filter"])){
$additionalFilters["basename"] = str_replace("*", "%", AJXP_Utils::sanitize($httpVars["filename_filter"], AJXP_SANITIZE_FILENAME));
}
if(isSet($httpVars["dirname_filter"])){
$additionalFilters["dirname"] = str_replace("*", "%", AJXP_Utils::sanitize($httpVars["dirname_filter"], AJXP_SANITIZE_DIRNAME));
}


$queries = explode(",", $query_name);
$meta = array();
Expand Down Expand Up @@ -323,11 +331,11 @@ public function formatXmlLogItem($node, $icon, $dateattrib, $filename, $remote_i
* @param String $ip The client ip
* @param String $user The user login
* @param String $source The source of the message
* @param String $prefix The prefix of the message
* @param String $prefix The prefix of the message
* @param String $message The message to log
*
* @param array $nodesPathes
*/
public function write2($level, $ip, $user, $source, $prefix, $message)
public function write2($level, $ip, $user, $source, $prefix, $message, $nodesPathes = array())
{
if($prefix == "Log In" && $message=="context=API"){
// Limit the number of logs
Expand All @@ -344,22 +352,33 @@ public function write2($level, $ip, $user, $source, $prefix, $message)
return;
}
}
$files = array(array("dirname"=>"", "basename"=>""));
if(AJXP_Utils::detectXSS($message)){
$message = "XSS Detected in Message!";
}else if(count($nodesPathes)){
$files = array();
foreach($nodesPathes as $path){
$parts = pathinfo($path);
$files[] = array("dirname"=>$parts["dirname"], "basename"=>$parts["basename"]);
}
}
foreach($files as $fileDef){
$log_row = Array(
'logdate' => new DateTime('NOW'),
'remote_ip' => $this->inet_ptod($ip),
'severity' => strtoupper((string) $level),
'user' => $user,
'source' => $source,
'message' => $prefix,
'params' => $message,
'repository_id' => ConfService::getInstance()->getContextRepositoryId(),
'device' => $_SERVER['HTTP_USER_AGENT'],
'dirname' => $fileDef["dirname"],
'basename' => $fileDef["basename"]
);
//we already handle exception for write2 in core.log
dibi::query('INSERT INTO [ajxp_log]', $log_row);
}
$log_row = Array(
'logdate' => new DateTime('NOW'),
'remote_ip' => $this->inet_ptod($ip),
'severity' => strtoupper((string) $level),
'user' => $user,
'source' => $source,
'message' => $prefix,
'params' => $message,
'repository_id' => ConfService::getInstance()->getContextRepositoryId(),
'device' => $_SERVER['HTTP_USER_AGENT']
);
//we already handle exception for write2 in core.log
dibi::query('INSERT INTO [ajxp_log]', $log_row);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion core/src/plugins/log.sql/create.mysql
Expand Up @@ -9,8 +9,12 @@ CREATE TABLE IF NOT EXISTS `ajxp_log` (
`params` TEXT,
`repository_id` VARCHAR(32),
`device` VARCHAR(255),
`dirname` VARCHAR(255),
`basename` VARCHAR(255),
INDEX `source` (`source`),
INDEX `repository_id` (`repository_id`),
INDEX `logdate` (`logdate`),
INDEX `severity` (`severity`)
INDEX `severity` (`severity`),
INDEX `dirname` (`dirname`),
INDEX `basename` (`basename`)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;
2 changes: 1 addition & 1 deletion core/src/plugins/log.syslog/class.sysLogDriver.php
Expand Up @@ -117,7 +117,7 @@ public function init($options)
* @param String $message The message to log
*
*/
public function write2($level, $ip, $user, $source, $prefix, $message)
public function write2($level, $ip, $user, $source, $prefix, $message, $nodePathes = array())
{
//syslog already take care of timestamp and log severity
$textMessage = "$ip\t$user\t$source\t$prefix\t$message";
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/log.text/class.textLogDriver.php
Expand Up @@ -157,7 +157,7 @@ public function init($options)
* @throws Exception
* @return void
*/
public function write2($level, $ip, $user, $source, $prefix, $message)
public function write2($level, $ip, $user, $source, $prefix, $message, $nodePathes = array())
{
if(AJXP_Utils::detectXSS($message)) $message = "XSS Detected in message!";
$textMessage = date("m-d-y") . " " . date("H:i:s") . "\t";
Expand Down

0 comments on commit 3be5742

Please sign in to comment.