migrate the rest into Config::

master
Andrew Dolgov 4 years ago
parent 383f4ca04a
commit 211f699aa0

@ -1,5 +1,8 @@
<?php <?php
class Config { class Config {
private const _ENVVAR_PREFIX = "TTRSS_";
/* overriding defaults (defined below in _DEFAULTS[]) via environment: DB_TYPE becomes TTRSS_DB_TYPE, etc */
const DB_TYPE = "DB_TYPE"; const DB_TYPE = "DB_TYPE";
const DB_HOST = "DB_HOST"; const DB_HOST = "DB_HOST";
@ -27,6 +30,23 @@ class Config {
const CHECK_FOR_UPDATES = "CHECK_FOR_UPDATES"; const CHECK_FOR_UPDATES = "CHECK_FOR_UPDATES";
const PLUGINS = "PLUGINS"; const PLUGINS = "PLUGINS";
const LOG_DESTINATION = "LOG_DESTINATION"; const LOG_DESTINATION = "LOG_DESTINATION";
const LOCAL_OVERRIDE_STYLESHEET = "LOCAL_OVERRIDE_STYLESHEET";
const DAEMON_MAX_CHILD_RUNTIME = "DAEMON_MAX_CHILD_RUNTIME";
const DAEMON_MAX_JOBS = "DAEMON_MAX_JOBS";
const FEED_FETCH_TIMEOUT = "FEED_FETCH_TIMEOUT";
const FEED_FETCH_NO_CACHE_TIMEOUT = "FEED_FETCH_NO_CACHE_TIMEOUT";
const FILE_FETCH_TIMEOUT = "FILE_FETCH_TIMEOUT";
const FILE_FETCH_CONNECT_TIMEOUT = "FILE_FETCH_CONNECT_TIMEOUT";
const DAEMON_UPDATE_LOGIN_LIMIT = "DAEMON_UPDATE_LOGIN_LIMIT";
const DAEMON_FEED_LIMIT = "DAEMON_FEED_LIMIT";
const DAEMON_SLEEP_INTERVAL = "DAEMON_SLEEP_INTERVAL";
const MAX_CACHE_FILE_SIZE = "MAX_CACHE_FILE_SIZE";
const MAX_DOWNLOAD_FILE_SIZE = "MAX_DOWNLOAD_FILE_SIZE";
const MAX_FAVICON_FILE_SIZE = "MAX_FAVICON_FILE_SIZE";
const CACHE_MAX_DAYS = "CACHE_MAX_DAYS";
const MAX_CONDITIONAL_INTERVAL = "MAX_CONDITIONAL_INTERVAL";
const DAEMON_UNSUCCESSFUL_DAYS_LIMIT = "DAEMON_UNSUCCESSFUL_DAYS_LIMIT";
const LOG_SENT_MAIL = "LOG_SENT_MAIL";
private const _DEFAULTS = [ private const _DEFAULTS = [
Config::DB_TYPE => "pgsql", Config::DB_TYPE => "pgsql",
@ -55,9 +75,25 @@ class Config {
Config::CHECK_FOR_UPDATES => "true", Config::CHECK_FOR_UPDATES => "true",
Config::PLUGINS => "auth_internal", Config::PLUGINS => "auth_internal",
Config::LOG_DESTINATION => "sql", Config::LOG_DESTINATION => "sql",
Config::LOCAL_OVERRIDE_STYLESHEET => "local-overrides.css",
Config::DAEMON_MAX_CHILD_RUNTIME => 1800,
Config::DAEMON_MAX_JOBS => 2,
Config::FEED_FETCH_TIMEOUT => 45,
Config::FEED_FETCH_NO_CACHE_TIMEOUT => 15,
Config::FILE_FETCH_TIMEOUT => 45,
Config::FILE_FETCH_CONNECT_TIMEOUT => 15,
Config::DAEMON_UPDATE_LOGIN_LIMIT => 30,
Config::DAEMON_FEED_LIMIT => 500,
Config::DAEMON_SLEEP_INTERVAL => 120,
Config::MAX_CACHE_FILE_SIZE => 64*1024*1024,
Config::MAX_DOWNLOAD_FILE_SIZE => 16*1024*1024,
Config::MAX_FAVICON_FILE_SIZE => 1*1024*1024,
Config::CACHE_MAX_DAYS => 7,
Config::MAX_CONDITIONAL_INTERVAL => 3600*12,
Config::DAEMON_UNSUCCESSFUL_DAYS_LIMIT => 30,
Config::LOG_SENT_MAIL => "",
]; ];
private const _ENVVAR_PREFIX = "TTRSS_";
private static $instance; private static $instance;
private $params = []; private $params = [];

@ -41,8 +41,8 @@ class Db
} else if (Config::get(Config::DB_TYPE) == "mysql") { } else if (Config::get(Config::DB_TYPE) == "mysql") {
$pdo->query("SET time_zone = '+0:0'"); $pdo->query("SET time_zone = '+0:0'");
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { if (defined('Config::get(Config::MYSQL_CHARSET)') && Config::get(Config::MYSQL_CHARSET)) {
$pdo->query("SET NAMES " . MYSQL_CHARSET); $pdo->query("SET NAMES " . Config::get(Config::MYSQL_CHARSET));
} }
} }

@ -48,11 +48,11 @@ class Digest
$mailer = new Mailer(); $mailer = new Mailer();
//$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text); //$rc = $mail->quickMail($line["email"], $line["login"], Config::get(Config::DIGEST_SUBJECT), $digest, $digest_text);
$rc = $mailer->mail(["to_name" => $line["login"], $rc = $mailer->mail(["to_name" => $line["login"],
"to_address" => $line["email"], "to_address" => $line["email"],
"subject" => DIGEST_SUBJECT, "subject" => Config::get(Config::DIGEST_SUBJECT),
"message" => $digest_text, "message" => $digest_text,
"message_html" => $digest]); "message_html" => $digest]);
@ -91,11 +91,11 @@ class Digest
$tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); $tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
$tpl->setVariable('CUR_TIME', date('G:i', $local_ts)); $tpl->setVariable('CUR_TIME', date('G:i', $local_ts));
$tpl->setVariable('TTRSS_HOST', Config::get(Config.Config::get(Config::SELF_URL_PATH))); $tpl->setVariable('TTRSS_HOST', Config::get(Config::get(Config::SELF_URL_PATH)));
$tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); $tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
$tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts)); $tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts));
$tpl_t->setVariable('TTRSS_HOST', Config::get(Config.Config::get(Config::SELF_URL_PATH))); $tpl_t->setVariable('TTRSS_HOST', Config::get(Config::get(Config::SELF_URL_PATH)));
$affected_ids = array(); $affected_ids = array();

@ -349,7 +349,7 @@ class DiskCache {
if ($files) { if ($files) {
foreach ($files as $file) { foreach ($files as $file) {
if (time() - filemtime($file) > 86400*CACHE_MAX_DAYS) { if (time() - filemtime($file) > 86400*Config::get(Config::CACHE_MAX_DAYS)) {
unlink($file); unlink($file);
++$num_deleted; ++$num_deleted;

@ -1056,11 +1056,11 @@ class Feeds extends Handler_Protected {
} }
static function _get_icon_file($feed_id) { static function _get_icon_file($feed_id) {
return ICONS_DIR . "/$feed_id.ico"; return Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
} }
static function _has_icon($id) { static function _has_icon($id) {
return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0; return is_file(Config::get(Config::ICONS_DIR) . "/$id.ico") && filesize(Config::get(Config::ICONS_DIR) . "/$id.ico") > 0;
} }
static function _get_icon($id) { static function _get_icon($id) {
@ -1084,7 +1084,7 @@ class Feeds extends Handler_Protected {
$icon = self::_get_icon_file($id); $icon = self::_get_icon_file($id);
if ($icon && file_exists($icon)) { if ($icon && file_exists($icon)) {
return ICONS_URL . "/" . basename($icon) . "?" . filemtime($icon); return Config::get(Config::ICONS_URL) . "/" . basename($icon) . "?" . filemtime($icon);
} }
} }
break; break;

@ -42,7 +42,7 @@ class Logger {
} }
function __construct() { function __construct() {
switch (LOG_DESTINATION) { switch (Config::get(Config::LOG_DESTINATION)) {
case "sql": case "sql":
$this->adapter = new Logger_SQL(); $this->adapter = new Logger_SQL();
break; break;

@ -11,15 +11,15 @@ class Mailer {
$subject = $params["subject"]; $subject = $params["subject"];
$message = $params["message"]; $message = $params["message"];
$message_html = $params["message_html"]; $message_html = $params["message_html"];
$from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; $from_name = $params["from_name"] ? $params["from_name"] : Config::get(Config::SMTP_FROM_NAME);
$from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; $from_address = $params["from_address"] ? $params["from_address"] : Config::get(Config::SMTP_FROM_ADDRESS);
$additional_headers = $params["headers"] ? $params["headers"] : []; $additional_headers = $params["headers"] ? $params["headers"] : [];
$from_combined = $from_name ? "$from_name <$from_address>" : $from_address; $from_combined = $from_name ? "$from_name <$from_address>" : $from_address;
$to_combined = $to_name ? "$to_name <$to_address>" : $to_address; $to_combined = $to_name ? "$to_name <$to_address>" : $to_address;
if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) if (Config::get(Config::LOG_SENT_MAIL))
Logger::get()->log(E_USER_NOTICE, "Sending mail from $from_combined to $to_combined [$subject]: $message"); Logger::get()->log(E_USER_NOTICE, "Sending mail from $from_combined to $to_combined [$subject]: $message");
// HOOK_SEND_MAIL plugin instructions: // HOOK_SEND_MAIL plugin instructions:

@ -441,7 +441,7 @@ class Pref_Feeds extends Handler_Protected {
$sth->execute([$feed_id, $_SESSION['uid']]); $sth->execute([$feed_id, $_SESSION['uid']]);
if ($row = $sth->fetch()) { if ($row = $sth->fetch()) {
@unlink(ICONS_DIR . "/$feed_id.ico"); @unlink(Config::get(Config::ICONS_DIR) . "/$feed_id.ico");
$sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL, favicon_last_checked = '1970-01-01' $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL, favicon_last_checked = '1970-01-01'
where id = ?"); where id = ?");
@ -479,7 +479,7 @@ class Pref_Feeds extends Handler_Protected {
$sth->execute([$feed_id, $_SESSION['uid']]); $sth->execute([$feed_id, $_SESSION['uid']]);
if ($row = $sth->fetch()) { if ($row = $sth->fetch()) {
$new_filename = ICONS_DIR . "/$feed_id.ico"; $new_filename = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
if (file_exists($new_filename)) unlink($new_filename); if (file_exists($new_filename)) unlink($new_filename);
@ -1228,8 +1228,8 @@ class Pref_Feeds extends Handler_Protected {
$pdo->commit(); $pdo->commit();
if (file_exists(ICONS_DIR . "/$id.ico")) { if (file_exists(Config::get(Config::ICONS_DIR) . "/$id.ico")) {
unlink(ICONS_DIR . "/$id.ico"); unlink(Config::get(Config::ICONS_DIR) . "/$id.ico");
} }
} else { } else {

@ -153,10 +153,10 @@ class Pref_System extends Handler_Administrative {
<div dojoType='dijit.layout.AccordionContainer' region='center'> <div dojoType='dijit.layout.AccordionContainer' region='center'>
<div dojoType='dijit.layout.AccordionPane' style='padding : 0' title='<i class="material-icons">report</i> <?= __('Event Log') ?>'> <div dojoType='dijit.layout.AccordionPane' style='padding : 0' title='<i class="material-icons">report</i> <?= __('Event Log') ?>'>
<?php <?php
if (LOG_DESTINATION == "sql") { if (Config::get(Config::LOG_DESTINATION) == "sql") {
$this->_log_viewer($page, $severity); $this->_log_viewer($page, $severity);
} else { } else {
print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging."); print_notice("Please set Config::get(Config::LOG_DESTINATION) to 'sql' in config.php to enable database logging.");
} }
?> ?>
</div> </div>

@ -86,7 +86,7 @@ class Pref_Users extends Handler_Administrative {
<?php while ($row = $sth->fetch()) { ?> <?php while ($row = $sth->fetch()) { ?>
<li> <li>
<?php <?php
$icon_file = ICONS_URL . "/" . $row["id"] . ".ico"; $icon_file = Config::get(Config::ICONS_URL) . "/" . $row["id"] . ".ico";
$icon = file_exists($icon_file) ? $icon_file : "images/blank_icon.gif"; $icon = file_exists($icon_file) ? $icon_file : "images/blank_icon.gif";
?> ?>

@ -165,8 +165,9 @@ class RPC extends Handler_Protected {
function setpanelmode() { function setpanelmode() {
$wide = (int) clean($_REQUEST["wide"]); $wide = (int) clean($_REQUEST["wide"]);
// FIXME should this use SESSION_COOKIE_LIFETIME and be renewed periodically?
setcookie("ttrss_widescreen", (string)$wide, setcookie("ttrss_widescreen", (string)$wide,
time() + COOKIE_LIFETIME_LONG); time() + 86400*365);
print json_encode(array("wide" => $wide)); print json_encode(array("wide" => $wide));
} }
@ -328,7 +329,7 @@ class RPC extends Handler_Protected {
get_version($git_commit, $git_timestamp); get_version($git_commit, $git_timestamp);
if (defined('CHECK_FOR_UPDATES') && CHECK_FOR_UPDATES && $_SESSION["access_level"] >= 10 && $git_timestamp) { if (defined('Config::get(Config::CHECK_FOR_UPDATES)') && Config::get(Config::CHECK_FOR_UPDATES) && $_SESSION["access_level"] >= 10 && $git_timestamp) {
$content = @UrlHelper::fetch(["url" => "https://tt-rss.org/version.json"]); $content = @UrlHelper::fetch(["url" => "https://tt-rss.org/version.json"]);
if ($content) { if ($content) {
@ -359,8 +360,8 @@ class RPC extends Handler_Protected {
} }
$params["safe_mode"] = !empty($_SESSION["safe_mode"]); $params["safe_mode"] = !empty($_SESSION["safe_mode"]);
$params["check_for_updates"] = CHECK_FOR_UPDATES; $params["check_for_updates"] = Config::get(Config::CHECK_FOR_UPDATES);
$params["icons_url"] = ICONS_URL; $params["icons_url"] = Config::get(Config::ICONS_URL);
$params["cookie_lifetime"] = Config::get(Config::SESSION_COOKIE_LIFETIME); $params["cookie_lifetime"] = Config::get(Config::SESSION_COOKIE_LIFETIME);
$params["default_view_mode"] = get_pref("_DEFAULT_VIEW_MODE"); $params["default_view_mode"] = get_pref("_DEFAULT_VIEW_MODE");
$params["default_view_limit"] = (int) get_pref("_DEFAULT_VIEW_LIMIT"); $params["default_view_limit"] = (int) get_pref("_DEFAULT_VIEW_LIMIT");
@ -390,15 +391,10 @@ class RPC extends Handler_Protected {
$params["self_url_prefix"] = get_self_url_prefix(); $params["self_url_prefix"] = get_self_url_prefix();
$params["max_feed_id"] = (int) $max_feed_id; $params["max_feed_id"] = (int) $max_feed_id;
$params["num_feeds"] = (int) $num_feeds; $params["num_feeds"] = (int) $num_feeds;
$params["hotkeys"] = $this->get_hotkeys_map(); $params["hotkeys"] = $this->get_hotkeys_map();
$params["widescreen"] = (int) ($_COOKIE["ttrss_widescreen"] ?? 0); $params["widescreen"] = (int) ($_COOKIE["ttrss_widescreen"] ?? 0);
$params['simple_update'] = Config::get(Config::SIMPLE_UPDATE_MODE);
$params['simple_update'] = SIMPLE_UPDATE_MODE;
$params["icon_indicator_white"] = $this->image_to_base64("images/indicator_white.gif"); $params["icon_indicator_white"] = $this->image_to_base64("images/indicator_white.gif");
$params["labels"] = Labels::get_all($_SESSION["uid"]); $params["labels"] = Labels::get_all($_SESSION["uid"]);
return $params; return $params;
@ -432,7 +428,7 @@ class RPC extends Handler_Protected {
$data['cdm_expanded'] = get_pref('CDM_EXPANDED'); $data['cdm_expanded'] = get_pref('CDM_EXPANDED');
$data["labels"] = Labels::get_all($_SESSION["uid"]); $data["labels"] = Labels::get_all($_SESSION["uid"]);
if (LOG_DESTINATION == 'sql' && $_SESSION['access_level'] >= 10) { if (Config::get(Config::LOG_DESTINATION) == 'sql' && $_SESSION['access_level'] >= 10) {
if (Config::get(Config::DB_TYPE) == 'pgsql') { if (Config::get(Config::DB_TYPE) == 'pgsql') {
$log_interval = "created_at > NOW() - interval '1 hour'"; $log_interval = "created_at > NOW() - interval '1 hour'";
} else { } else {

@ -34,9 +34,9 @@ class RSSUtils {
$pdo = Db::pdo(); $pdo = Db::pdo();
$sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ?"); $sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ?");
// check icon files once every CACHE_MAX_DAYS days // check icon files once every Config::get(Config::CACHE_MAX_DAYS) days
$icon_files = array_filter(glob(ICONS_DIR . "/*.ico"), $icon_files = array_filter(glob(Config::get(Config::ICONS_DIR) . "/*.ico"),
function($f) { return filemtime($f) < time() - 86400*CACHE_MAX_DAYS; }); function($f) { return filemtime($f) < time() - 86400 * Config::get(Config::CACHE_MAX_DAYS); });
foreach ($icon_files as $icon) { foreach ($icon_files as $icon) {
$feed_id = basename($icon, ".ico"); $feed_id = basename($icon, ".ico");
@ -52,20 +52,22 @@ class RSSUtils {
} }
} }
static function update_daemon_common($limit = DAEMON_FEED_LIMIT, $options = []) { static function update_daemon_common($limit = null, $options = []) {
$schema_version = get_schema_version(); $schema_version = get_schema_version();
if (!$limit) $limit = Config::get(Config::DAEMON_FEED_LIMIT);
if ($schema_version != SCHEMA_VERSION) { if ($schema_version != SCHEMA_VERSION) {
die("Schema version is wrong, please upgrade the database.\n"); die("Schema version is wrong, please upgrade the database.\n");
} }
$pdo = Db::pdo(); $pdo = Db::pdo();
if (!Config::get(Config::SINGLE_USER_MODE) && DAEMON_UPDATE_LOGIN_LIMIT > 0) { if (!Config::get(Config::SINGLE_USER_MODE) && Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT) > 0) {
if (Config::get(Config::DB_TYPE) == "pgsql") { if (Config::get(Config::DB_TYPE) == "pgsql") {
$login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'"; $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT)." days'";
} else { } else {
$login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)"; $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT)." DAY)";
} }
} else { } else {
$login_thresh_qpart = ""; $login_thresh_qpart = "";
@ -288,7 +290,7 @@ class RSSUtils {
if (!$basic_info) { if (!$basic_info) {
$feed_data = UrlHelper::fetch($fetch_url, false, $feed_data = UrlHelper::fetch($fetch_url, false,
$auth_login, $auth_pass, false, $auth_login, $auth_pass, false,
FEED_FETCH_TIMEOUT, Config::get(Config::FEED_FETCH_TIMEOUT),
0); 0);
$feed_data = trim($feed_data); $feed_data = trim($feed_data);
@ -455,7 +457,7 @@ class RSSUtils {
Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE); Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE);
} }
if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) { if (time() - strtotime($last_unconditional) > Config::get(Config::MAX_CONDITIONAL_INTERVAL)) {
Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE); Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE);
$force_refetch = true; $force_refetch = true;
@ -469,7 +471,7 @@ class RSSUtils {
"url" => $fetch_url, "url" => $fetch_url,
"login" => $auth_login, "login" => $auth_login,
"pass" => $auth_pass, "pass" => $auth_pass,
"timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, "timeout" => $no_cache ? Config::get(Config::FEED_FETCH_NO_CACHE_TIMEOUT) : Config::get(Config::FEED_FETCH_TIMEOUT),
"last_modified" => $force_refetch ? "" : $stored_last_modified "last_modified" => $force_refetch ? "" : $stored_last_modified
]); ]);
@ -591,7 +593,7 @@ class RSSUtils {
/* terrible hack: if we crash on floicon shit here, we won't check /* terrible hack: if we crash on floicon shit here, we won't check
* the icon avgcolor again (unless the icon got updated) */ * the icon avgcolor again (unless the icon got updated) */
$favicon_file = ICONS_DIR . "/$feed.ico"; $favicon_file = Config::get(Config::ICONS_DIR) . "/$feed.ico";
$favicon_modified = file_exists($favicon_file) ? filemtime($favicon_file) : -1; $favicon_modified = file_exists($favicon_file) ? filemtime($favicon_file) : -1;
Debug::log("checking favicon for feed $feed...", Debug::$LOG_VERBOSE); Debug::log("checking favicon for feed $feed...", Debug::$LOG_VERBOSE);
@ -755,7 +757,7 @@ class RSSUtils {
$e->type, $e->length, $e->title, $e->width, $e->height); $e->type, $e->length, $e->title, $e->width, $e->height);
// Yet another episode of "mysql utf8_general_ci is gimped" // Yet another episode of "mysql utf8_general_ci is gimped"
if (Config::get(Config::DB_TYPE) == "mysql" && MYSQL_CHARSET != "UTF8MB4") { if (Config::get(Config::DB_TYPE) == "mysql" && Config::get(Config::MYSQL_CHARSET) != "UTF8MB4") {
for ($i = 0; $i < count($e_item); $i++) { for ($i = 0; $i < count($e_item); $i++) {
if (is_string($e_item[$i])) { if (is_string($e_item[$i])) {
$e_item[$i] = self::strip_utf8mb4($e_item[$i]); $e_item[$i] = self::strip_utf8mb4($e_item[$i]);
@ -833,7 +835,7 @@ class RSSUtils {
Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE); Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE);
// Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077 // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077
if (Config::get(Config::DB_TYPE) == "mysql" && MYSQL_CHARSET != "UTF8MB4") { if (Config::get(Config::DB_TYPE) == "mysql" && Config::get(Config::MYSQL_CHARSET) != "UTF8MB4") {
foreach ($article as $k => $v) { foreach ($article as $k => $v) {
// i guess we'll have to take the risk of 4byte unicode labels & tags here // i guess we'll have to take the risk of 4byte unicode labels & tags here
if (is_string($article[$k])) { if (is_string($article[$k])) {
@ -1298,7 +1300,7 @@ class RSSUtils {
$file_content = UrlHelper::fetch(array("url" => $src, $file_content = UrlHelper::fetch(array("url" => $src,
"http_referrer" => $src, "http_referrer" => $src,
"max_size" => MAX_CACHE_FILE_SIZE)); "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)));
if ($file_content) { if ($file_content) {
$cache->put($local_filename, $file_content); $cache->put($local_filename, $file_content);
@ -1328,7 +1330,7 @@ class RSSUtils {
$file_content = UrlHelper::fetch(array("url" => $url, $file_content = UrlHelper::fetch(array("url" => $url,
"http_referrer" => $url, "http_referrer" => $url,
"max_size" => MAX_CACHE_FILE_SIZE)); "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)));
if ($file_content) { if ($file_content) {
$cache->put($local_filename, $file_content); $cache->put($local_filename, $file_content);
@ -1643,7 +1645,7 @@ class RSSUtils {
} }
static function check_feed_favicon($site_url, $feed) { static function check_feed_favicon($site_url, $feed) {
$icon_file = ICONS_DIR . "/$feed.ico"; $icon_file = Config::get(Config::ICONS_DIR) . "/$feed.ico";
$favicon_url = self::get_favicon_url($site_url); $favicon_url = self::get_favicon_url($site_url);
if (!$favicon_url) { if (!$favicon_url) {
@ -1654,7 +1656,7 @@ class RSSUtils {
// Limiting to "image" type misses those served with text/plain // Limiting to "image" type misses those served with text/plain
$contents = UrlHelper::fetch([ $contents = UrlHelper::fetch([
'url' => $favicon_url, 'url' => $favicon_url,
'max_size' => MAX_FAVICON_FILE_SIZE, 'max_size' => Config::get(Config::MAX_FAVICON_FILE_SIZE),
//'type' => 'image', //'type' => 'image',
]); ]);
if (!$contents) { if (!$contents) {

@ -209,7 +209,7 @@ class UrlHelper {
$last_modified = isset($options["last_modified"]) ? $options["last_modified"] : ""; $last_modified = isset($options["last_modified"]) ? $options["last_modified"] : "";
$useragent = isset($options["useragent"]) ? $options["useragent"] : false; $useragent = isset($options["useragent"]) ? $options["useragent"] : false;
$followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true; $followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true;
$max_size = isset($options["max_size"]) ? $options["max_size"] : MAX_DOWNLOAD_FILE_SIZE; // in bytes $max_size = isset($options["max_size"]) ? $options["max_size"] : Config::get(Config::MAX_DOWNLOAD_FILE_SIZE); // in bytes
$http_accept = isset($options["http_accept"]) ? $options["http_accept"] : false; $http_accept = isset($options["http_accept"]) ? $options["http_accept"] : false;
$http_referrer = isset($options["http_referrer"]) ? $options["http_referrer"] : false; $http_referrer = isset($options["http_referrer"]) ? $options["http_referrer"] : false;
@ -250,8 +250,8 @@ class UrlHelper {
if (count($curl_http_headers) > 0) if (count($curl_http_headers) > 0)
curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers); curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : Config::get(Config::FILE_FETCH_CONNECT_TIMEOUT));
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : Config::get(Config::FILE_FETCH_TIMEOUT));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir") && $followlocation); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir") && $followlocation);
curl_setopt($ch, CURLOPT_MAXREDIRS, 20); curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
@ -395,7 +395,7 @@ class UrlHelper {
), ),
'method' => 'GET', 'method' => 'GET',
'ignore_errors' => true, 'ignore_errors' => true,
'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT, 'timeout' => $timeout ? $timeout : Config::get(Config::FILE_FETCH_TIMEOUT),
'protocol_version'=> 1.1) 'protocol_version'=> 1.1)
); );
@ -417,7 +417,7 @@ class UrlHelper {
$old_error = error_get_last(); $old_error = error_get_last();
$fetch_effective_url = self::resolve_redirects($url, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT); $fetch_effective_url = self::resolve_redirects($url, $timeout ? $timeout : Config::get(Config::FILE_FETCH_CONNECT_TIMEOUT));
if (!self::validate($fetch_effective_url, true)) { if (!self::validate($fetch_effective_url, true)) {
$fetch_last_error = "URL received after redirection failed extended validation."; $fetch_last_error = "URL received after redirection failed extended validation.";

@ -131,7 +131,7 @@
// Disabling auth_internal in this list would automatically disable // Disabling auth_internal in this list would automatically disable
// reset password link on the login form. // reset password link on the login form.
define('LOG_DESTINATION', 'sql'); define('Config::get(Config::LOG_DESTINATION)', 'sql');
// Error log destination to use. Possible values: sql (uses internal logging // Error log destination to use. Possible values: sql (uses internal logging
// you can read in Preferences -> System), syslog - logs to system log. // you can read in Preferences -> System), syslog - logs to system log.
// Setting this to blank uses PHP logging (usually to http server // Setting this to blank uses PHP logging (usually to http server

@ -5,12 +5,6 @@
define('LABEL_BASE_INDEX', -1024); define('LABEL_BASE_INDEX', -1024);
define('PLUGIN_FEED_BASE_INDEX', -128); define('PLUGIN_FEED_BASE_INDEX', -128);
define('COOKIE_LIFETIME_LONG', 86400*365);
// this CSS file is included for everyone (if it exists in themes.local)
// on login, registration, and main (index and prefs) pages
define('LOCAL_OVERRIDE_STYLESHEET', '.local-overrides.css');
$fetch_last_error = false; $fetch_last_error = false;
$fetch_last_error_code = false; $fetch_last_error_code = false;
$fetch_last_content_type = false; $fetch_last_content_type = false;
@ -37,49 +31,7 @@
ini_set('display_errors', "false"); ini_set('display_errors', "false");
ini_set('display_startup_errors', "false"); ini_set('display_startup_errors', "false");
require_once 'config.php'; require_once "config.php";
/* Some tunables you can override in config.php using define(): */
if (!defined('FEED_FETCH_TIMEOUT')) define('FEED_FETCH_TIMEOUT', 45);
// How may seconds to wait for response when requesting feed from a site
if (!defined('FEED_FETCH_NO_CACHE_TIMEOUT')) define('FEED_FETCH_NO_CACHE_TIMEOUT', 15);
// How may seconds to wait for response when requesting feed from a
// site when that feed wasn't cached before
if (!defined('FILE_FETCH_TIMEOUT')) define('FILE_FETCH_TIMEOUT', 45);
// Default timeout when fetching files from remote sites
if (!defined('FILE_FETCH_CONNECT_TIMEOUT')) define('FILE_FETCH_CONNECT_TIMEOUT', 15);
// How many seconds to wait for initial response from website when
// fetching files from remote sites
if (!defined('DAEMON_UPDATE_LOGIN_LIMIT')) define('DAEMON_UPDATE_LOGIN_LIMIT', 30);
// stop updating feeds if users haven't logged in for X days
if (!defined('DAEMON_FEED_LIMIT')) define('DAEMON_FEED_LIMIT', 500);
// feed limit for one update batch
if (!defined('DAEMON_SLEEP_INTERVAL')) define('DAEMON_SLEEP_INTERVAL', 120);
// default sleep interval between feed updates (sec)
if (!defined('MAX_CACHE_FILE_SIZE')) define('MAX_CACHE_FILE_SIZE', 64*1024*1024);
// do not cache files larger than that (bytes)
if (!defined('MAX_DOWNLOAD_FILE_SIZE')) define('MAX_DOWNLOAD_FILE_SIZE', 16*1024*1024);
// do not download general files larger than that (bytes)
if (!defined('MAX_FAVICON_FILE_SIZE')) define('MAX_FAVICON_FILE_SIZE', 1*1024*1024);
// do not download favicon files larger than that (bytes)
if (!defined('CACHE_MAX_DAYS')) define('CACHE_MAX_DAYS', 7);
// max age in days for various automatically cached (temporary) files
if (!defined('MAX_CONDITIONAL_INTERVAL')) define('MAX_CONDITIONAL_INTERVAL', 3600*12);
// max interval between forced unconditional updates for servers
// not complying with http if-modified-since (seconds)
// if (!defined('MAX_FETCH_REQUESTS_PER_HOST')) define('MAX_FETCH_REQUESTS_PER_HOST', 25);
// a maximum amount of allowed HTTP requests per destination host
// during a single update (i.e. within PHP process lifetime)
// this is used to not cause excessive load on the origin server on
// e.g. feed subscription when all articles are being processes
// (not implemented)
if (!defined('DAEMON_UNSUCCESSFUL_DAYS_LIMIT')) define('DAEMON_UNSUCCESSFUL_DAYS_LIMIT', 30);
// automatically disable updates for feeds which failed to
// update for this amount of days; 0 disables
/* tunables end here */
require_once "autoload.php"; require_once "autoload.php";
if (Config::get(Config::DB_TYPE) == "pgsql") { if (Config::get(Config::DB_TYPE) == "pgsql") {

@ -16,8 +16,8 @@
} ?> } ?>
<?php if (theme_exists(LOCAL_OVERRIDE_STYLESHEET)) { <?php if (theme_exists(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET))) {
echo stylesheet_tag(get_theme_path(LOCAL_OVERRIDE_STYLESHEET)); echo stylesheet_tag(get_theme_path(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET)));
} ?> } ?>
<style type="text/css"> <style type="text/css">

@ -103,8 +103,8 @@
} }
} }
if (!is_writable(ICONS_DIR)) { if (!is_writable(Config::get(Config::ICONS_DIR))) {
array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n"); array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".Config::get(Config::ICONS_DIR).").\n");
} }
if (!is_writable(Config::get(Config::LOCK_DIRECTORY))) { if (!is_writable(Config::get(Config::LOCK_DIRECTORY))) {

@ -17,7 +17,6 @@
get_include_path()); get_include_path());
require_once "autoload.php"; require_once "autoload.php";
require_once "sessions.php"; require_once "sessions.php";
require_once "functions.php"; require_once "functions.php";
require_once "sanity_check.php"; require_once "sanity_check.php";
@ -44,8 +43,8 @@
} }
} ?> } ?>
<?php if (theme_exists(LOCAL_OVERRIDE_STYLESHEET)) { <?php if (theme_exists(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET))) {
echo stylesheet_tag(get_theme_path(LOCAL_OVERRIDE_STYLESHEET)); echo stylesheet_tag(get_theme_path(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET)));
} ?> } ?>
<script type="text/javascript"> <script type="text/javascript">

@ -2,6 +2,7 @@ parameters:
level: 5 level: 5
ignoreErrors: ignoreErrors:
# - '#Constant.*not found#' # - '#Constant.*not found#'
- '#Constant.*\b(SUBSTRING_FOR_DATE|SCHEMA_VERSION|SELF_USER_AGENT|LABEL_BASE_INDEX|PLUGIN_FEED_BASE_INDEX)\b.*not found#'
- '#Comparison operation ">" between int<1, max> and 0 is always true.#' - '#Comparison operation ">" between int<1, max> and 0 is always true.#'
- '#Access to an undefined property DOMNode::\$tagName.#' - '#Access to an undefined property DOMNode::\$tagName.#'
- '#Call to an undefined method DOMNode::(get|remove|set)Attribute\(\).#' - '#Call to an undefined method DOMNode::(get|remove|set)Attribute\(\).#'

@ -68,7 +68,7 @@ class Af_Proxy_Http extends Plugin {
header("Location: " . $this->cache->get_url($local_filename)); header("Location: " . $this->cache->get_url($local_filename));
return; return;
} else { } else {
$data = UrlHelper::fetch(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); $data = UrlHelper::fetch(["url" => $url, "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)]);
if ($data) { if ($data) {
if ($this->cache->put($local_filename, $data)) { if ($this->cache->put($local_filename, $data)) {

@ -136,7 +136,7 @@ class Cache_Starred_Images extends Plugin {
if (!$this->cache->exists($local_filename)) { if (!$this->cache->exists($local_filename)) {
Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE); Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE);
$data = UrlHelper::fetch(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); $data = UrlHelper::fetch(["url" => $url, "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)]);
if ($data) if ($data)
return $this->cache->put($local_filename, $data);; return $this->cache->put($local_filename, $data);;

@ -34,8 +34,8 @@
} }
} ?> } ?>
<?php if (theme_exists(LOCAL_OVERRIDE_STYLESHEET)) { <?php if (theme_exists(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET))) {
echo stylesheet_tag(get_theme_path(LOCAL_OVERRIDE_STYLESHEET)); echo stylesheet_tag(get_theme_path(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET)));
} ?> } ?>
<script type="text/javascript"> <script type="text/javascript">

@ -212,7 +212,7 @@
} }
if (isset($options["feeds"])) { if (isset($options["feeds"])) {
RSSUtils::update_daemon_common(DAEMON_FEED_LIMIT, $options); RSSUtils::update_daemon_common(Config::get(Config::DAEMON_FEED_LIMIT), $options);
RSSUtils::housekeeping_common(); RSSUtils::housekeeping_common();
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, $options); PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, $options);
@ -227,7 +227,7 @@
passthru(Config::get(Config::PHP_EXECUTABLE) . " " . $argv[0] ." --daemon-loop $quiet $log $log_level"); passthru(Config::get(Config::PHP_EXECUTABLE) . " " . $argv[0] ." --daemon-loop $quiet $log $log_level");
// let's enforce a minimum spawn interval as to not forkbomb the host // let's enforce a minimum spawn interval as to not forkbomb the host
$spawn_interval = max(60, DAEMON_SLEEP_INTERVAL); $spawn_interval = max(60, Config::get(Config::DAEMON_SLEEP_INTERVAL));
Debug::log("Sleeping for $spawn_interval seconds..."); Debug::log("Sleeping for $spawn_interval seconds...");
sleep($spawn_interval); sleep($spawn_interval);
@ -255,7 +255,7 @@
Debug::log("warning: unable to create stampfile\n"); Debug::log("warning: unable to create stampfile\n");
} }
RSSUtils::update_daemon_common(isset($options["pidlock"]) ? 50 : DAEMON_FEED_LIMIT, $options); RSSUtils::update_daemon_common(isset($options["pidlock"]) ? 50 : Config::get(Config::DAEMON_FEED_LIMIT), $options);
if (!isset($options["pidlock"]) || $options["task"] == 0) if (!isset($options["pidlock"]) || $options["task"] == 0)
RSSUtils::housekeeping_common(); RSSUtils::housekeeping_common();

@ -11,13 +11,6 @@
require_once "autoload.php"; require_once "autoload.php";
require_once "functions.php"; require_once "functions.php";
require_once "config.php"; require_once "config.php";
// defaults
if (!defined('PURGE_INTERVAL')) define('PURGE_INTERVAL', 3600); // seconds
if (!defined('MAX_CHILD_RUNTIME')) define('MAX_CHILD_RUNTIME', 1800); // seconds
if (!defined('MAX_JOBS')) define('MAX_JOBS', 2);
if (!defined('SPAWN_INTERVAL')) define('SPAWN_INTERVAL', DAEMON_SLEEP_INTERVAL); // seconds
require_once "sanity_check.php"; require_once "sanity_check.php";
require_once "db-prefs.php"; require_once "db-prefs.php";
@ -78,7 +71,7 @@
foreach (array_keys($ctimes) as $pid) { foreach (array_keys($ctimes) as $pid) {
$started = $ctimes[$pid]; $started = $ctimes[$pid];
if (time() - $started > MAX_CHILD_RUNTIME) { if (time() - $started > Config::get(Config::DAEMON_MAX_CHILD_RUNTIME)) {
Debug::log("Child process with PID $pid seems to be stuck, aborting..."); Debug::log("Child process with PID $pid seems to be stuck, aborting...");
posix_kill($pid, SIGKILL); posix_kill($pid, SIGKILL);
} }
@ -143,9 +136,9 @@
print " --log FILE - log messages to FILE\n"; print " --log FILE - log messages to FILE\n";
print " --log-level N - log verbosity level\n"; print " --log-level N - log verbosity level\n";
print " --tasks N - amount of update tasks to spawn\n"; print " --tasks N - amount of update tasks to spawn\n";
print " default: " . MAX_JOBS . "\n"; print " default: " . Config::get(Config::DAEMON_MAX_JOBS) . "\n";
print " --interval N - task spawn interval\n"; print " --interval N - task spawn interval\n";
print " default: " . SPAWN_INTERVAL . " seconds.\n"; print " default: " . Config::get(Config::DAEMON_SLEEP_INTERVAL) . " seconds.\n";
print " --quiet - don't output messages to stdout\n"; print " --quiet - don't output messages to stdout\n";
return; return;
} }
@ -170,14 +163,14 @@
Debug::log("Set to spawn " . $options["tasks"] . " children."); Debug::log("Set to spawn " . $options["tasks"] . " children.");
$max_jobs = $options["tasks"]; $max_jobs = $options["tasks"];
} else { } else {
$max_jobs = MAX_JOBS; $max_jobs = Config::get(Config::DAEMON_MAX_JOBS);
} }
if (isset($options["interval"])) { if (isset($options["interval"])) {
Debug::log("Spawn interval: " . $options["interval"] . " seconds."); Debug::log("Spawn interval: " . $options["interval"] . " seconds.");
$spawn_interval = $options["interval"]; $spawn_interval = $options["interval"];
} else { } else {
$spawn_interval = SPAWN_INTERVAL; $spawn_interval = Config::get(Config::DAEMON_SLEEP_INTERVAL);
} }
// let's enforce a minimum spawn interval as to not forkbomb the host // let's enforce a minimum spawn interval as to not forkbomb the host

Loading…
Cancel
Save