From 481c2a671913cdd6099a1b6ee4d5491dff16c0bf Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 24 Oct 2015 22:25:48 +0200 Subject: [PATCH] Clean logs Reduced login of API and PubSubHubbub (both are quite stable now). When clearing logs as admin, also clear API and PubSubHubbub logs. https://github.com/FreshRSS/FreshRSS/issues/988 --- app/Controllers/feedController.php | 4 ++-- app/Models/LogDAO.php | 5 ++++ p/api/greader.php | 38 +++++++++++++++--------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index ec3dce777..4ec661115 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -307,9 +307,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $pubSubHubbubEnabled = $pubsubhubbubEnabledGeneral && $feed->pubSubHubbubEnabled(); if ((!$simplePiePush) && (!$id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) { - $text = 'Skip pull of feed using PubSubHubbub: ' . $url; + //$text = 'Skip pull of feed using PubSubHubbub: ' . $url; //Minz_Log::debug($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + //file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); continue; //When PubSubHubbub is used, do not pull refresh so often } diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php index 4c56e3150..ab258cd58 100644 --- a/app/Models/LogDAO.php +++ b/app/Models/LogDAO.php @@ -21,5 +21,10 @@ class FreshRSS_LogDAO { public static function truncate() { file_put_contents(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), ''); + if (FreshRSS_Auth::hasAccess('admin')) { + file_put_contents(join_path(DATA_PATH, 'users', '_', 'log.txt'), ''); + file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_api.txt'), ''); + file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_pshb.txt'), ''); + } } } diff --git a/p/api/greader.php b/p/api/greader.php index 5a23af006..b9942f0bc 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -77,7 +77,7 @@ class MyPDO extends Minz_ModelPdo { } function logMe($text) { - file_put_contents(join_path(USERS_PATH, '_', 'log_api.txt'), $text, FILE_APPEND); + file_put_contents(join_path(USERS_PATH, '_', 'log_api.txt'), date('c') . "\t" . $text . "\n", FILE_APPEND); } function debugInfo() { @@ -96,7 +96,7 @@ function debugInfo() { } function badRequest() { - logMe("badRequest()\n"); + logMe("badRequest()"); logMe(debugInfo()); header('HTTP/1.1 400 Bad Request'); header('Content-Type: text/plain; charset=UTF-8'); @@ -104,7 +104,7 @@ function badRequest() { } function unauthorized() { - logMe("unauthorized()\n"); + logMe("unauthorized()"); logMe(debugInfo()); header('HTTP/1.1 401 Unauthorized'); header('Content-Type: text/plain; charset=UTF-8'); @@ -113,7 +113,7 @@ function unauthorized() { } function notImplemented() { - logMe("notImplemented()\n"); + logMe("notImplemented()"); logMe(debugInfo()); header('HTTP/1.1 501 Not Implemented'); header('Content-Type: text/plain; charset=UTF-8'); @@ -121,14 +121,14 @@ function notImplemented() { } function serviceUnavailable() { - logMe("serviceUnavailable()\n"); + logMe("serviceUnavailable()"); header('HTTP/1.1 503 Service Unavailable'); header('Content-Type: text/plain; charset=UTF-8'); die('Service Unavailable!'); } function checkCompatibility() { - logMe("checkCompatibility()\n"); + logMe("checkCompatibility()"); header('Content-Type: text/plain; charset=UTF-8'); if (PHP_INT_SIZE < 8 && !function_exists('gmp_init')) { die('FAIL 64-bit or GMP extension!'); @@ -159,7 +159,7 @@ function authorizationToUser() { if ($headerAuthX[1] === sha1($system_conf->salt . $user . $conf->apiPasswordHash)) { return $user; } else { - logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1] . "\n"); + logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); unauthorized(); } @@ -172,7 +172,7 @@ function authorizationToUser() { } function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html - logMe('clientLogin(' . $email . ")\n"); + //logMe('clientLogin(' . $email . ")"); if (ctype_alnum($email)) { if (!function_exists('password_verify')) { include_once(LIB_PATH . '/password_compat.php'); @@ -205,7 +205,7 @@ function token($conf) { //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php $user = Minz_Session::param('currentUser', '_'); - logMe('token('. $user . ")\n"); //TODO: Implement real token that expires + //logMe('token('. $user . ")"); //TODO: Implement real token that expires $system_conf = Minz_Configuration::get('system'); $token = str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; @@ -215,7 +215,7 @@ function token($conf) { function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken $user = Minz_Session::param('currentUser', '_'); - logMe('checkToken(' . $token . ")\n"); + //logMe('checkToken(' . $token . ")"); $system_conf = Minz_Configuration::get('system'); if ($token === str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { return true; @@ -224,7 +224,7 @@ function checkToken($conf, $token) { } function tagList() { - logMe("tagList()\n"); + //logMe("tagList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -249,7 +249,7 @@ function tagList() { } function subscriptionList() { - logMe("subscriptionList()\n"); + //logMe("subscriptionList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -283,7 +283,7 @@ function subscriptionList() { } function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count - logMe("unreadCount()\n"); + //logMe("unreadCount()"); header('Content-Type: application/json; charset=UTF-8'); $totalUnreads = 0; @@ -330,7 +330,7 @@ function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-googl function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation) { //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed - logMe("streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation)\n"); + //logMe("streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation)"); header('Content-Type: application/json; charset=UTF-8'); $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -436,7 +436,7 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed - logMe("streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)\n"); + //logMe("streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)"); $type = 'A'; $id = ''; @@ -484,7 +484,7 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude } function editTag($e_ids, $a, $r) { - logMe("editTag()\n"); + //logMe("editTag()"); foreach ($e_ids as $i => $e_id) { $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/' @@ -520,7 +520,7 @@ function editTag($e_ids, $a, $r) { } function markAllAsRead($streamId, $olderThanId) { - logMe("markAllAsRead($streamId, $olderThanId)\n"); + //logMe("markAllAsRead($streamId, $olderThanId)"); $entryDAO = FreshRSS_Factory::createEntryDao(); if (strpos($streamId, 'feed/') === 0) { $f_id = basename($streamId); @@ -538,7 +538,7 @@ function markAllAsRead($streamId, $olderThanId) { exit(); } -logMe('----------------------------------------------------------------'."\n"); +//logMe('----------------------------------------------------------------'); //logMe(debugInfo()); $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']); @@ -560,7 +560,7 @@ if ($user !== '') { $conf = get_user_configuration($user); } -logMe('User => ' . $user . "\n"); +//logMe('User => ' . $user); Minz_Session::_param('currentUser', $user);