Merge branch 'Alkarex/Logging'

https://github.com/FreshRSS/FreshRSS/pull/815
pull/826/head
Alexandre Alapetite 10 years ago
commit f3aef1e59b
  1. 6
      app/Models/Feed.php
  2. 1
      data/config.default.php
  3. 41
      lib/SimplePie/SimplePie.php
  4. 7
      lib/SimplePie/SimplePie/File.php
  5. 10
      lib/SimplePie/SimplePie/Misc.php
  6. 13
      lib/lib_rss.php

@ -240,16 +240,16 @@ class FreshRSS_Feed extends Minz_Model {
$subscribe_url = $feed->subscribe_url(true);
}
$clean_url = url_remove_credentials($subscribe_url);
$clean_url = SimplePie_Misc::url_remove_credentials($subscribe_url);
if ($subscribe_url !== null && $subscribe_url !== $url) {
$this->_url($clean_url);
}
if (($mtime === true) || ($mtime > $this->lastUpdate)) {
Minz_Log::notice('FreshRSS no cache ' . $mtime . ' > ' . $this->lastUpdate . ' for ' . $clean_url);
//Minz_Log::debug('FreshRSS no cache ' . $mtime . ' > ' . $this->lastUpdate . ' for ' . $clean_url);
$this->loadEntries($feed); // et on charge les articles du flux
} else {
Minz_Log::notice('FreshRSS use cache for ' . $clean_url);
//Minz_Log::debug('FreshRSS use cache for ' . $clean_url);
$this->entries = array();
}

@ -12,6 +12,7 @@ return array(
'auth_type' => 'none',
'api_enabled' => false,
'unsafe_autologin_enabled' => false,
'simplepie_syslog_enabled' => true,
'limits' => array(
'cache_duration' => 800,
'timeout' => 10,

@ -74,6 +74,12 @@ define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed
*/
define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
/**
* Use syslog to report HTTP requests done by SimplePie.
* @see SimplePie::set_syslog()
*/
define('SIMPLEPIE_SYSLOG', true); //FreshRSS
/**
* No Autodiscovery
* @see SimplePie::set_autodiscovery_level()
@ -622,6 +628,12 @@ class SimplePie
*/
public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
/**
* Use syslog to report HTTP requests done by SimplePie.
* @see SimplePie::set_syslog()
*/
public $syslog_enabled = SIMPLEPIE_SYSLOG;
/**
* The SimplePie class contains feed level data and options
*
@ -1136,7 +1148,7 @@ class SimplePie
$this->sanitize->strip_attributes($attribs);
}
public function add_attributes($attribs = '')
public function add_attributes($attribs = '') //FreshRSS
{
if ($attribs === '')
{
@ -1145,6 +1157,14 @@ class SimplePie
$this->sanitize->add_attributes($attribs);
}
/**
* Use syslog to report HTTP requests done by SimplePie.
*/
public function set_syslog($value = SIMPLEPIE_SYSLOG) //FreshRSS
{
$this->syslog_enabled = $value == true;
}
/**
* Set the output encoding
*
@ -1231,7 +1251,8 @@ class SimplePie
$this->enable_exceptions = $enable;
}
function cleanMd5($rss) { //FreshRSS
function cleanMd5($rss) //FreshRSS
{
return md5(preg_replace(array('#<(lastBuildDate|pubDate|updated|feedDate|dc:date|slash:comments)>[^<]+</\\1>#', '#<!--.+?-->#s'), '', $rss));
}
@ -1329,7 +1350,8 @@ class SimplePie
list($headers, $sniffed) = $fetched;
if (isset($this->data['md5'])) { //FreshRSS
if (isset($this->data['md5'])) //FreshRSS
{
$md5 = $this->data['md5'];
}
}
@ -1455,7 +1477,8 @@ class SimplePie
{
// Load the Cache
$this->data = $cache->load();
if ($cache->mtime() + $this->cache_duration > time()) { //FreshRSS
if ($cache->mtime() + $this->cache_duration > time()) //FreshRSS
{
$this->raw_data = false;
return true; // If the cache is still valid, just return true
}
@ -1529,11 +1552,17 @@ class SimplePie
{ //FreshRSS
$md5 = $this->cleanMd5($file->body);
if ($this->data['md5'] === $md5) {
// syslog(LOG_DEBUG, 'SimplePie MD5 cache match for ' . $this->feed_url);
if ($this->syslog_enabled)
{
syslog(LOG_DEBUG, 'SimplePie MD5 cache match for ' . SimplePie_Misc::url_remove_credentials($this->feed_url));
}
$cache->touch();
return true; //Content unchanged even though server did not send a 304
} else {
// syslog(LOG_DEBUG, 'SimplePie MD5 cache no match for ' . $this->feed_url);
if ($this->syslog_enabled)
{
syslog(LOG_DEBUG, 'SimplePie MD5 cache no match for ' . SimplePie_Misc::url_remove_credentials($this->feed_url));
}
$this->data['md5'] = $md5;
}
}

@ -66,7 +66,7 @@ class SimplePie_File
var $method = SIMPLEPIE_FILE_SOURCE_NONE;
var $permanent_url; //FreshRSS
public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false, $syslog_enabled = SIMPLEPIE_SYSLOG)
{
if (class_exists('idna_convert'))
{
@ -79,7 +79,10 @@ class SimplePie_File
$this->useragent = $useragent;
if (preg_match('/^http(s)?:\/\//i', $url))
{
// syslog(LOG_INFO, 'SimplePie GET ' . $url); //FreshRSS
if ($syslog_enabled)
{
syslog(LOG_INFO, 'SimplePie GET ' . SimplePie_Misc::url_remove_credentials($url)); //FreshRSS
}
if ($useragent === null)
{
$useragent = ini_get('user_agent');

@ -2240,5 +2240,15 @@ function embed_wmedia(width, height, link) {
{
// No-op
}
/**
* Sanitize a URL by removing HTTP credentials.
* @param $url the URL to sanitize.
* @return the same URL without HTTP credentials.
*/
public static function url_remove_credentials($url) //FreshRSS
{
return preg_replace('#^(https?://)[^/:@]+:[^/:@]+@#i', '$1', $url);
}
}

@ -123,6 +123,7 @@ function customSimplePie() {
$limits = $system_conf->limits;
$simplePie = new SimplePie();
$simplePie->set_useragent(_t('gen.freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
$simplePie->set_syslog($system_conf->simplepie_syslog_enabled);
$simplePie->set_cache_location(CACHE_PATH);
$simplePie->set_cache_duration($limits['cache_duration']);
$simplePie->set_timeout($limits['timeout']);
@ -180,7 +181,7 @@ function sanitizeHTML($data, $base = '') {
function get_content_by_parsing ($url, $path) {
require_once (LIB_PATH . '/lib_phpQuery.php');
Minz_Log::notice('FreshRSS GET ' . url_remove_credentials($url));
Minz_Log::notice('FreshRSS GET ' . SimplePie_Misc::url_remove_credentials($url));
$html = file_get_contents ($url);
if ($html) {
@ -429,13 +430,3 @@ function array_push_unique(&$array, $value) {
function array_remove(&$array, $value) {
$array = array_diff($array, array($value));
}
/**
* Sanitize a URL by removing HTTP credentials.
* @param $url the URL to sanitize.
* @return the same URL without HTTP credentials.
*/
function url_remove_credentials($url) {
return preg_replace('/[^\/]*:[^:]*@/', '', $url);
}

Loading…
Cancel
Save