From 4058ff3ff4631bcc2c9cba534162c80db5cf2b65 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 7 Oct 2017 13:51:45 +0200 Subject: Remove SimplePie name from HTTP User-Agent string https://github.com/FreshRSS/FreshRSS/issues/1622#issuecomment-334928486 https://github.com/FreshRSS/FreshRSS/issues/1627 https://github.com/FreshRSS/FreshRSS/issues/1607 --- app/Models/Feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/Models/Feed.php') diff --git a/app/Models/Feed.php b/app/Models/Feed.php index d8fe03197..44d518a47 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -484,7 +484,7 @@ class FreshRSS_Feed extends Minz_Model { CURLOPT_URL => $hubJson['hub'], CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, - CURLOPT_USERAGENT => 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ')', + CURLOPT_USERAGENT => FRESHRSS_USERAGENT, CURLOPT_POSTFIELDS => http_build_query(array( 'hub.verify' => 'sync', 'hub.mode' => $state ? 'subscribe' : 'unsubscribe', -- cgit v1.2.3 From 1eb19409b5435546774425c00523b9f88d4fccf9 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 8 Oct 2017 17:26:43 +0200 Subject: CURLOPT_FOLLOWLOCATION open_basedir bug (#1657) CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set https://github.com/FreshRSS/FreshRSS/issues/1655#issuecomment-334999448 https://stackoverflow.com/questions/6918623/curlopt-followlocation-cannot-be-activated --- CHANGELOG.md | 2 ++ app/Models/Feed.php | 27 +++++++++++++++------------ lib/favicons.php | 4 ++-- 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'app/Models/Feed.php') diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a644478..4b24cd116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * SimplePie * Remove "SimplePie" name from HTTP User-Agent string [#1656](https://github.com/FreshRSS/FreshRSS/pull/1656) +* Bug fixing + * Work-around for `CURLOPT_FOLLOWLOCATION` `open_basedir` bug in favicons and PubSubHubbub [#1655](https://github.com/FreshRSS/FreshRSS/issues/1655) * Misc. * Travis translation validation tool [#1653](https://github.com/FreshRSS/FreshRSS/pull/1653) diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 44d518a47..85273d3f7 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -481,18 +481,21 @@ class FreshRSS_Feed extends Minz_Model { } $ch = curl_init(); curl_setopt_array($ch, array( - CURLOPT_URL => $hubJson['hub'], - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_USERAGENT => FRESHRSS_USERAGENT, - CURLOPT_POSTFIELDS => http_build_query(array( - 'hub.verify' => 'sync', - 'hub.mode' => $state ? 'subscribe' : 'unsubscribe', - 'hub.topic' => $url, - 'hub.callback' => $callbackUrl, - )) - ) - ); + CURLOPT_URL => $hubJson['hub'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POSTFIELDS => http_build_query(array( + 'hub.verify' => 'sync', + 'hub.mode' => $state ? 'subscribe' : 'unsubscribe', + 'hub.topic' => $url, + 'hub.callback' => $callbackUrl, + )), + CURLOPT_USERAGENT => FRESHRSS_USERAGENT, + CURLOPT_MAXREDIRS => 10, + )); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir bug + if (defined('CURLOPT_ENCODING')) { + curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings + } $response = curl_exec($ch); $info = curl_getinfo($ch); diff --git a/lib/favicons.php b/lib/favicons.php index 80246ee74..2d6f7aab7 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -31,12 +31,12 @@ function downloadHttp(&$url, $curlOptions = array()) { } $ch = curl_init($url); curl_setopt_array($ch, array( - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, CURLOPT_USERAGENT => FRESHRSS_USERAGENT, + CURLOPT_MAXREDIRS => 10, )); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir bug if (defined('CURLOPT_ENCODING')) { curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings } -- cgit v1.2.3 From b1c317a253445a6458f1263c1b622a788cc7cd0e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 10 Dec 2017 21:31:41 +0100 Subject: Log rotation, use Minz_Log, new log constants ADMIN_LOG, API_LOG, PSHB_LOG --- app/Controllers/feedController.php | 4 ++-- app/Models/Feed.php | 14 +++++------- app/Models/LogDAO.php | 6 ++--- app/actualize_script.php | 13 ++++------- constants.php | 7 ++++-- lib/Minz/Log.php | 22 ++++++++++++++---- p/api/greader.php | 47 +++++++++----------------------------- p/api/pshb.php | 40 +++++++++++++++----------------- 8 files changed, 66 insertions(+), 87 deletions(-) (limited to 'app/Models/Feed.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 45cba9e98..883f7af05 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -263,7 +263,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if ((!$simplePiePush) && (!$feed_id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) { //$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); + //Minz_Log::debug($text, PSHB_LOG); continue; //When PubSubHubbub is used, do not pull refresh so often } @@ -371,7 +371,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if ($pubSubHubbubEnabled && !$simplePiePush) { //We use push, but have discovered an article by pull! $text = 'An article was discovered by pull although we use PubSubHubbub!: Feed ' . $url . ' GUID ' . $entry->guid(); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); Minz_Log::warning($text); $pubSubHubbubEnabled = false; $feed->pubSubHubbubError(true); diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 85273d3f7..75d9f6d6f 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -403,8 +403,7 @@ class FreshRSS_Feed extends Minz_Model { if (!isset($hubJson['error']) || $hubJson['error'] !== (bool)$error) { $hubJson['error'] = (bool)$error; file_put_contents($hubFilename, json_encode($hubJson)); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" - . 'Set error to ' . ($error ? 1 : 0) . ' for ' . $url . "\n", FILE_APPEND); + Minz_Log::warning('Set error to ' . ($error ? 1 : 0) . ' for ' . $url, PSHB_LOG); } return false; } @@ -419,7 +418,7 @@ class FreshRSS_Feed extends Minz_Model { if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key'])) { $text = 'Invalid JSON for PubSubHubbub: ' . $this->url; Minz_Log::warning($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); return false; } if ((!empty($hubJson['lease_end'])) && ($hubJson['lease_end'] < (time() + (3600 * 23)))) { //TODO: Make a better policy @@ -427,7 +426,7 @@ class FreshRSS_Feed extends Minz_Model { . date('c', empty($hubJson['lease_end']) ? time() : $hubJson['lease_end']) . ' and needs renewal: ' . $this->url; Minz_Log::warning($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); $key = $hubJson['key']; //To renew our lease } elseif (((!empty($hubJson['error'])) || empty($hubJson['lease_end'])) && (empty($hubJson['lease_start']) || $hubJson['lease_start'] < time() - (3600 * 23))) { //Do not renew too often @@ -445,7 +444,7 @@ class FreshRSS_Feed extends Minz_Model { file_put_contents(PSHB_PATH . '/keys/' . $key . '.txt', base64url_encode($this->selfUrl)); $text = 'PubSubHubbub prepared for ' . $this->url; Minz_Log::debug($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::debug($text, PSHB_LOG); } $currentUser = Minz_Session::param('currentUser'); if (FreshRSS_user_Controller::checkUsername($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) { @@ -499,9 +498,8 @@ class FreshRSS_Feed extends Minz_Model { $response = curl_exec($ch); $info = curl_getinfo($ch); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . - 'PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url . - ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response . "\n", FILE_APPEND); + Minz_Log::warning('PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url . + ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response, PSHB_LOG); if (substr($info['http_code'], 0, 1) == '2') { return true; diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php index ab258cd58..5bce466d5 100644 --- a/app/Models/LogDAO.php +++ b/app/Models/LogDAO.php @@ -22,9 +22,9 @@ 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'), ''); + file_put_contents(ADMIN_LOG, ''); + file_put_contents(API_LOG, ''); + file_put_contents(PSHB_LOG, ''); } } } diff --git a/app/actualize_script.php b/app/actualize_script.php index deaa1bf7c..d4908d3ea 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -20,10 +20,6 @@ $_GET['ajax'] = 1; $_GET['force'] = true; $_SERVER['HTTP_HOST'] = ''; - -$log_file = join_path(USERS_PATH, '_', 'log.txt'); - - $app = new FreshRSS(); $system_conf = Minz_Configuration::get('system'); @@ -45,13 +41,13 @@ $min_last_activity = time() - $limits['max_inactivity']; foreach ($users as $user) { if (($user !== $system_conf->default_user) && (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) { - Minz_Log::notice('FreshRSS skip inactive user ' . $user, $log_file); + Minz_Log::notice('FreshRSS skip inactive user ' . $user, ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'FreshRSS skip inactive user ' . $user . "\n"); //Unbuffered } continue; } - Minz_Log::notice('FreshRSS actualize ' . $user, $log_file); + Minz_Log::notice('FreshRSS actualize ' . $user, ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'Actualize ' . $user . "...\n"); //Unbuffered } @@ -66,8 +62,7 @@ foreach ($users as $user) { if (!invalidateHttpCache()) { - Minz_Log::notice('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), - $log_file); + Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG); if (defined('STDERR')) { fwrite(STDERR, 'Write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n"); } @@ -75,7 +70,7 @@ foreach ($users as $user) { } -Minz_Log::notice('FreshRSS actualize done.', $log_file); +Minz_Log::notice('FreshRSS actualize done.', ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'Done.' . "\n"); $end_date = date_create('now'); diff --git a/constants.php b/constants.php index b48c1be96..576be09b9 100644 --- a/constants.php +++ b/constants.php @@ -8,8 +8,8 @@ define('FRESHRSS_USERAGENT', 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; // PHP text output compression http://php.net/ob_gzhandler (better to do it at Web server level) define('PHP_COMPRESSION', false); -// maximum log file size, before it will be purged (defaults to 512000 = 500kB) -define('MAX_LOG_SIZE', 512000); +// Maximum log file size in Bytes, before it will be divided by two +define('MAX_LOG_SIZE', 1048576); // Constantes de chemins define('FRESHRSS_PATH', dirname(__FILE__)); @@ -22,7 +22,10 @@ define('FRESHRSS_PATH', dirname(__FILE__)); define('DATA_PATH', FRESHRSS_PATH . '/data'); define('UPDATE_FILENAME', DATA_PATH . '/update.php'); define('USERS_PATH', DATA_PATH . '/users'); + define('ADMIN_LOG', USERS_PATH . '/_/log.txt'); + define('API_LOG', USERS_PATH . '/_/log_api.txt'); define('CACHE_PATH', DATA_PATH . '/cache'); + define('PSHB_LOG', USERS_PATH . '/_/log_pshb.txt'); define('PSHB_PATH', DATA_PATH . '/PubSubHubbub'); define('LIB_PATH', FRESHRSS_PATH . '/lib'); diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index 6231754fa..5e7831cdb 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -71,7 +71,7 @@ class Minz_Log { . ' [' . $level_label . ']' . ' --- ' . $information . "\n"; - self::checkLogfileSize($file_name); + self::ensureMaxLogSize($file_name); if (file_put_contents($file_name, $log, FILE_APPEND | LOCK_EX) === false) { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); @@ -88,12 +88,24 @@ class Minz_Log { * @param $file_name * @throws Minz_PermissionDeniedException */ - protected static function checkLogfileSize($file_name) { - $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 512000; - if (@filesize($file_name) > $maxSize) { - if (file_put_contents($file_name, '') === false) { + protected static function ensureMaxLogSize($file_name) { + $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576; + if ($maxSize > 0 && @filesize($file_name) > $maxSize) { + $fp = fopen($file_name, 'c+'); + if ($fp && flock($fp, LOCK_EX)) { + fseek($fp, -intval($maxSize / 2), SEEK_END); + $content = fread($fp, $maxSize); + rewind($fp); + ftruncate($fp, 0); + fwrite($fp, $content ? $content : ''); + fflush($fp); + flock($fp, LOCK_UN); + } else { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); } + if ($fp) { + fclose($fp); + } } } diff --git a/p/api/greader.php b/p/api/greader.php index f086ee442..b27f5bd43 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -78,10 +78,6 @@ class MyPDO extends Minz_ModelPdo { } } -function logMe($text) { - file_put_contents(join_path(USERS_PATH, '_', 'log_api.txt'), date('c') . "\t" . $text . "\n", FILE_APPEND); -} - function debugInfo() { if (function_exists('getallheaders')) { $ALL_HEADERS = getallheaders(); @@ -107,16 +103,14 @@ function debugInfo() { } function badRequest() { - logMe("badRequest()"); - logMe(debugInfo()); + Minz_Log::warning('badRequest() ' . debugInfo(), API_LOG); header('HTTP/1.1 400 Bad Request'); header('Content-Type: text/plain; charset=UTF-8'); die('Bad Request!'); } function unauthorized() { - logMe("unauthorized()"); - logMe(debugInfo()); + Minz_Log::warning('unauthorized() ' . debugInfo(), API_LOG); header('HTTP/1.1 401 Unauthorized'); header('Content-Type: text/plain; charset=UTF-8'); header('Google-Bad-Token: true'); @@ -124,22 +118,21 @@ function unauthorized() { } function notImplemented() { - logMe("notImplemented()"); - logMe(debugInfo()); + Minz_Log::warning('notImplemented() ' . debugInfo(), API_LOG); header('HTTP/1.1 501 Not Implemented'); header('Content-Type: text/plain; charset=UTF-8'); die('Not Implemented!'); } function serviceUnavailable() { - logMe("serviceUnavailable()"); + Minz_Log::warning('serviceUnavailable() ' . debugInfo(), API_LOG); header('HTTP/1.1 503 Service Unavailable'); header('Content-Type: text/plain; charset=UTF-8'); die('Service Unavailable!'); } function checkCompatibility() { - logMe("checkCompatibility()"); + Minz_Log::warning('checkCompatibility() ' . debugInfo(), API_LOG); header('Content-Type: text/plain; charset=UTF-8'); if (PHP_INT_SIZE < 8 && !function_exists('gmp_init')) { die('FAIL 64-bit or GMP extension!'); @@ -170,7 +163,7 @@ function authorizationToUser() { if ($headerAuthX[1] === sha1(FreshRSS_Context::$system_conf->salt . $user . FreshRSS_Context::$user_conf->apiPasswordHash)) { return $user; } else { - logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); + Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1], API_LOG); Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); unauthorized(); } @@ -183,7 +176,6 @@ function authorizationToUser() { } function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html - //logMe('clientLogin(' . $email . ")"); if (ctype_alnum($email)) { if (!function_exists('password_verify')) { include_once(LIB_PATH . '/password_compat.php'); @@ -215,7 +207,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 . ")"); //TODO: Implement real token that expires + //Minz_Log::debug('token('. $user . ')', API_LOG); //TODO: Implement real token that expires $token = str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; exit(); @@ -224,7 +216,6 @@ 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 . ")"); if ($token === str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { return true; } @@ -232,7 +223,6 @@ function checkToken($conf, $token) { } function userInfo() { //https://github.com/theoldreader/api#user-info - //logMe("userInfo()"); $user = Minz_Session::param('currentUser', '_'); exit(json_encode(array( 'userId' => $user, @@ -243,7 +233,6 @@ function userInfo() { //https://github.com/theoldreader/api#user-info } function tagList() { - //logMe("tagList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -268,7 +257,6 @@ function tagList() { } function subscriptionList() { - //logMe("subscriptionList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -303,7 +291,6 @@ function subscriptionList() { } function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '') { - //logMe("subscriptionEdit()"); //https://github.com/mihaip/google-reader-api/blob/master/wiki/ApiSubscriptionEdit.wiki switch ($action) { case 'subscribe': @@ -360,7 +347,7 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' $feed = FreshRSS_feed_Controller::addFeed($streamName, $title, $addCatId, $c_name, $http_auth); continue; } catch (Exception $e) { - logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + Minz_Log::error('subscriptionEdit error subscribe: ' . $e->getMessage(), API_LOG); } } badRequest(); @@ -389,7 +376,6 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' } function quickadd($url) { - //logMe("quickadd($url)"); try { $feed = FreshRSS_feed_Controller::addFeed($url); exit(json_encode(array( @@ -397,7 +383,7 @@ function quickadd($url) { 'streamId' => $feed->id(), ))); } catch (Exception $e) { - logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + Minz_Log::error('quickadd error: ' . $e->getMessage(), API_LOG); die(json_encode(array( 'numResults' => 0, 'error' => $e->getMessage(), @@ -406,7 +392,6 @@ function quickadd($url) { } function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count - //logMe("unreadCount()"); header('Content-Type: application/json; charset=UTF-8'); $totalUnreads = 0; @@ -453,7 +438,6 @@ 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)"); header('Content-Type: application/json; charset=UTF-8'); $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -562,8 +546,6 @@ 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)"); - $type = 'A'; $id = ''; if ($streamId === 'user/-/state/com.google/reading-list') { @@ -610,8 +592,6 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude } function editTag($e_ids, $a, $r) { - //logMe("editTag()"); - foreach ($e_ids as $i => $e_id) { $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/' } @@ -645,7 +625,6 @@ function editTag($e_ids, $a, $r) { } function renameTag($s, $dest) { - //logMe("renameTag()"); if ($s != '' && strpos($s, 'user/-/label/') === 0 && $dest != '' && strpos($dest, 'user/-/label/') === 0) { $s = substr($s, 13); @@ -661,7 +640,6 @@ function renameTag($s, $dest) { } function disableTag($s) { - //logMe("disableTag($s)"); if ($s != '' && strpos($s, 'user/-/label/') === 0) { $s = substr($s, 13); $categoryDAO = new FreshRSS_CategoryDAO(); @@ -679,7 +657,6 @@ function disableTag($s) { } function markAllAsRead($streamId, $olderThanId) { - //logMe("markAllAsRead($streamId, $olderThanId)"); $entryDAO = FreshRSS_Factory::createEntryDao(); if (strpos($streamId, 'feed/') === 0) { $f_id = basename($streamId); @@ -696,8 +673,8 @@ function markAllAsRead($streamId, $olderThanId) { exit('OK'); } -//logMe('----------------------------------------------------------------'); -//logMe(debugInfo()); +//Minz_Log::debug('----------------------------------------------------------------', API_LOG); +//Minz_Log::debug(debugInfo(), API_LOG); $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']); $pathInfos = explode('/', $pathInfo); @@ -718,8 +695,6 @@ if ($user !== '') { FreshRSS_Context::$user_conf = get_user_configuration($user); } -//logMe('User => ' . $user); - Minz_Session::_param('currentUser', $user); if (count($pathInfos) < 3) { diff --git a/p/api/pshb.php b/p/api/pshb.php index ed8326cf5..578681cc4 100644 --- a/p/api/pshb.php +++ b/p/api/pshb.php @@ -2,18 +2,18 @@ require('../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -define('MAX_PAYLOAD', 3145728); +const MAX_PAYLOAD = 3145728; header('Content-Type: text/plain; charset=UTF-8'); header('X-Content-Type-Options: nosniff'); -function logMe($text) { - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); -} - $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, MAX_PAYLOAD); -//logMe(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true)); +Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); +$system_conf = Minz_Configuration::get('system'); +$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) + +//Minz_Log::debug(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true), PSHB_LOG); $key = isset($_GET['k']) ? substr($_GET['k'], 0, 128) : ''; if (!ctype_xdigit($key)) { @@ -24,31 +24,31 @@ chdir(PSHB_PATH); $canonical64 = @file_get_contents('keys/' . $key . '.txt'); if ($canonical64 === false) { if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'unsubscribe') { - logMe('Warning: Accept unknown unsubscribe'); + Minz_Log::warning('Warning: Accept unknown unsubscribe', PSHB_LOG); header('Connection: close'); exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : ''); } header('HTTP/1.1 404 Not Found'); - logMe('Warning: Feed key not found!: ' . $key); + Minz_Log::warning('Warning: Feed key not found!: ' . $key, PSHB_LOG); die('Feed key not found!'); } $canonical64 = trim($canonical64); if (!preg_match('/^[A-Za-z0-9_-]+$/D', $canonical64)) { header('HTTP/1.1 500 Internal Server Error'); - logMe('Error: Invalid key reference!: ' . $canonical64); + Minz_Log::error('Error: Invalid key reference!: ' . $canonical64, PSHB_LOG); die('Invalid key reference!'); } $hubFile = @file_get_contents('feeds/' . $canonical64 . '/!hub.json'); if ($hubFile === false) { header('HTTP/1.1 404 Not Found'); unlink('keys/' . $key . '.txt'); - logMe('Error: Feed info not found!: ' . $canonical64); + Minz_Log::error('Error: Feed info not found!: ' . $canonical64, PSHB_LOG); die('Feed info not found!'); } $hubJson = json_decode($hubFile, true); if (!$hubJson || empty($hubJson['key']) || $hubJson['key'] !== $key) { header('HTTP/1.1 500 Internal Server Error'); - logMe('Error: Invalid key cross-check!: ' . $key); + Minz_Log::error('Error: Invalid key cross-check!: ' . $key, PSHB_LOG); die('Invalid key cross-check!'); } chdir('feeds/' . $canonical64); @@ -56,7 +56,7 @@ $users = glob('*.txt', GLOB_NOSORT); if (empty($users)) { header('HTTP/1.1 410 Gone'); $url = base64url_decode($canonical64); - logMe('Warning: Nobody subscribes to this feed anymore!: ' . $url); + Minz_Log::warning('Warning: Nobody subscribes to this feed anymore!: ' . $url, PSHB_LOG); unlink('../../keys/' . $key . '.txt'); Minz_Configuration::register('system', DATA_PATH . '/config.php', @@ -101,10 +101,6 @@ if ($ORIGINAL_INPUT == '') { die('Missing XML payload!'); } -Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); -$system_conf = Minz_Configuration::get('system'); -$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) - $simplePie = customSimplePie(); $simplePie->set_raw_data($ORIGINAL_INPUT); $simplePie->init(); @@ -115,7 +111,7 @@ $self = isset($links[0]) ? $links[0] : null; if ($self !== base64url_decode($canonical64)) { //header('HTTP/1.1 422 Unprocessable Entity'); - logMe('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64)); + Minz_Log::warning('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64), PSHB_LOG); //die('Self URL does not match registered canonical URL!'); $self = base64url_decode($canonical64); } @@ -124,7 +120,7 @@ $nb = 0; foreach ($users as $userFilename) { $username = basename($userFilename, '.txt'); if (!file_exists(USERS_PATH . '/' . $username . '/config.php')) { - logMe('Warning: Removing broken user link: ' . $username . ' for ' . $self); + Minz_Log::warning('Warning: Removing broken user link: ' . $username . ' for ' . $self, PSHB_LOG); unlink($userFilename); continue; } @@ -140,11 +136,11 @@ foreach ($users as $userFilename) { if ($updated_feeds > 0 || $feed != false) { $nb++; } else { - logMe('Warning: User ' . $username . ' does not subscribe anymore to ' . $self); + Minz_Log::warning('Warning: User ' . $username . ' does not subscribe anymore to ' . $self, PSHB_LOG); unlink($userFilename); } } catch (Exception $e) { - logMe('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self); + Minz_Log::error('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self, PSHB_LOG); } } @@ -153,12 +149,12 @@ unset($simplePie); if ($nb === 0) { header('HTTP/1.1 410 Gone'); - logMe('Warning: Nobody subscribes to this feed anymore after all!: ' . $self); + Minz_Log::warning('Warning: Nobody subscribes to this feed anymore after all!: ' . $self, PSHB_LOG); die('Nobody subscribes to this feed anymore after all!'); } elseif (!empty($hubJson['error'])) { $hubJson['error'] = false; file_put_contents('./!hub.json', json_encode($hubJson)); } -logMe('PubSubHubbub ' . $self . ' done: ' . $nb); +Minz_Log::notice('PubSubHubbub ' . $self . ' done: ' . $nb, PSHB_LOG); exit('Done: ' . $nb . "\n"); -- cgit v1.2.3 From e399bc4b929b660908e60f1928014ae6445327f5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 17 Dec 2017 20:14:20 +0100 Subject: Remove warning for CURLOPT_FOLLOWLOCATION with open_basedir (#1734) For PHP 5.6.0- http://www.php.net/ChangeLog-5.php#5.6.0 https://bugs.php.net/bug.php?id=65646 https://github.com/FreshRSS/FreshRSS/pull/1733 https://github.com/FreshRSS/FreshRSS/pull/1657 https://github.com/FreshRSS/FreshRSS/issues/1655 --- app/Models/Feed.php | 4 +++- lib/favicons.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'app/Models/Feed.php') diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 75d9f6d6f..560f7415d 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -491,7 +491,9 @@ class FreshRSS_Feed extends Minz_Model { CURLOPT_USERAGENT => FRESHRSS_USERAGENT, CURLOPT_MAXREDIRS => 10, )); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir bug + if (version_compare(PHP_VERSION, '5.6.0') >= 0 || ini_get('open_basedir') == '') { + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir PHP bug 65646 + } if (defined('CURLOPT_ENCODING')) { curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings } diff --git a/lib/favicons.php b/lib/favicons.php index 75e40900a..fe2e65f1f 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -36,8 +36,8 @@ function downloadHttp(&$url, $curlOptions = array()) { CURLOPT_USERAGENT => FRESHRSS_USERAGENT, CURLOPT_MAXREDIRS => 10, )); - if (ini_get('open_basedir') == '') { // see PHP bug 65646 - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + if (version_compare(PHP_VERSION, '5.6.0') >= 0 || ini_get('open_basedir') == '') { + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir PHP bug 65646 } if (defined('CURLOPT_ENCODING')) { curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings -- cgit v1.2.3