Merge branch 'wip-config-object'

This commit is contained in:
Andrew Dolgov 2021-02-23 08:34:37 +03:00
commit 5229cc58b2
44 changed files with 400 additions and 516 deletions

26
.gitignore vendored
View File

@ -1,25 +1,13 @@
Thumbs.db
/.app_is_ready
/deploy.exclude
/deploy.sh
/messages.mo
/node_modules
/locale/**/*.po~
/package-lock.json
*~
*.DS_Store
#*
.idea/*
plugins.local/*
themes.local/*
config.php
feed-icons/*
cache/*/*
lock/*
tags
cache/htmlpurifier/*/*ser
lib/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/*/*ser
web.config
/.save.cson
/.tags*
/.gutentags
/plugins.local/*
/themes.local/*
/config.php
/feed-icons/*
/cache/*/*
/lock/*
/.vscode/settings.json

View File

@ -1,8 +1,6 @@
<?php
error_reporting(E_ERROR | E_PARSE);
require_once "../config.php";
set_include_path(__DIR__ . PATH_SEPARATOR .
dirname(__DIR__) . PATH_SEPARATOR .
dirname(__DIR__) . "/include" . PATH_SEPARATOR .
@ -14,7 +12,6 @@
define('NO_SESSION_AUTOSTART', true);
require_once "autoload.php";
require_once "db-prefs.php";
require_once "functions.php";
require_once "sessions.php";

View File

@ -26,8 +26,6 @@
require_once "autoload.php";
require_once "sessions.php";
require_once "functions.php";
require_once "config.php";
require_once "db-prefs.php";
$op = (string)clean($op);
$method = (string)clean($method);
@ -40,7 +38,7 @@
header("Content-Type: text/json; charset=utf-8");
if (SINGLE_USER_MODE) {
if (Config::get(Config::SINGLE_USER_MODE)) {
UserHelper::authenticate( "admin", null);
}

View File

@ -57,7 +57,7 @@ class API extends Handler {
$password = clean($_REQUEST["password"]);
$password_base64 = base64_decode(clean($_REQUEST["password"]));
if (SINGLE_USER_MODE) $login = "admin";
if (Config::get(Config::SINGLE_USER_MODE)) $login = "admin";
if ($uid = UserHelper::find_user_by_login($login)) {
if (get_pref("ENABLE_API_ACCESS", $uid)) {
@ -361,9 +361,10 @@ class API extends Handler {
}
function getConfig() {
$config = array(
"icons_dir" => ICONS_DIR,
"icons_url" => ICONS_URL);
$config = [
"icons_dir" => Config::get(Config::ICONS_DIR),
"icons_url" => Config::get(Config::ICONS_URL)
];
$config["daemon_is_running"] = file_is_locked("update_daemon.lock");

View File

@ -85,7 +85,7 @@ class Article extends Handler_Protected {
content = ?, content_hash = ? WHERE id = ?");
$sth->execute([$content, $content_hash, $ref_id]);
if (DB_TYPE == "pgsql"){
if (Config::get(Config::DB_TYPE) == "pgsql") {
$sth = $pdo->prepare("UPDATE ttrss_entries
SET tsvector_combined = to_tsvector( :ts_content)
WHERE id = :id");
@ -130,7 +130,7 @@ class Article extends Handler_Protected {
if ($row = $sth->fetch()) {
$ref_id = $row["id"];
if (DB_TYPE == "pgsql"){
if (Config::get(Config::DB_TYPE) == "pgsql"){
$sth = $pdo->prepare("UPDATE ttrss_entries
SET tsvector_combined = to_tsvector( :ts_content)
WHERE id = :id");
@ -475,7 +475,7 @@ class Article extends Handler_Protected {
// purge orphaned posts in main content table
if (DB_TYPE == "mysql")
if (Config::get(Config::DB_TYPE) == "mysql")
$limit_qpart = "LIMIT 5000";
else
$limit_qpart = "";

142
classes/config.php Normal file
View File

@ -0,0 +1,142 @@
<?php
class Config {
private const _ENVVAR_PREFIX = "TTRSS_";
// override defaults, defined below in _DEFAULTS[], via environment: DB_TYPE becomes TTRSS_DB_TYPE, etc
const DB_TYPE = "DB_TYPE";
const DB_HOST = "DB_HOST";
const DB_USER = "DB_USER";
const DB_NAME = "DB_NAME";
const DB_PASS = "DB_PASS";
const DB_PORT = "DB_PORT";
const MYSQL_CHARSET = "MYSQL_CHARSET";
const SELF_URL_PATH = "SELF_URL_PATH";
const SINGLE_USER_MODE = "SINGLE_USER_MODE";
const SIMPLE_UPDATE_MODE = "SIMPLE_UPDATE_MODE";
const PHP_EXECUTABLE = "PHP_EXECUTABLE";
const LOCK_DIRECTORY = "LOCK_DIRECTORY";
const CACHE_DIR = "CACHE_DIR";
const ICONS_DIR = "ICONS_DIR";
const ICONS_URL = "ICONS_URL";
const AUTH_AUTO_CREATE = "AUTH_AUTO_CREATE";
const AUTH_AUTO_LOGIN = "AUTH_AUTO_LOGIN";
const FORCE_ARTICLE_PURGE = "FORCE_ARTICLE_PURGE";
const ENABLE_REGISTRATION = "ENABLE_REGISTRATION";
const SESSION_COOKIE_LIFETIME = "SESSION_COOKIE_LIFETIME";
const SMTP_FROM_NAME = "SMTP_FROM_NAME";
const SMTP_FROM_ADDRESS = "SMTP_FROM_ADDRESS";
const DIGEST_SUBJECT = "DIGEST_SUBJECT";
const CHECK_FOR_UPDATES = "CHECK_FOR_UPDATES";
const PLUGINS = "PLUGINS";
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 = [
Config::DB_TYPE => "pgsql",
Config::DB_HOST => "db",
Config::DB_USER => "",
Config::DB_NAME => "",
Config::DB_PASS => "",
Config::DB_PORT => "5432",
Config::MYSQL_CHARSET => "UTF8",
Config::SELF_URL_PATH => "",
Config::SINGLE_USER_MODE => "",
Config::SIMPLE_UPDATE_MODE => "",
Config::PHP_EXECUTABLE => "/usr/bin/php",
Config::LOCK_DIRECTORY => "lock",
Config::CACHE_DIR => "cache",
Config::ICONS_DIR => "feed-icons",
Config::ICONS_URL => "feed-icons",
Config::AUTH_AUTO_CREATE => "true",
Config::AUTH_AUTO_LOGIN => "true",
Config::FORCE_ARTICLE_PURGE => 0,
Config::ENABLE_REGISTRATION => "",
Config::SESSION_COOKIE_LIFETIME => 86400,
Config::SMTP_FROM_NAME => "Tiny Tiny RSS",
Config::SMTP_FROM_ADDRESS => "noreply@localhost",
Config::DIGEST_SUBJECT => "[tt-rss] New headlines for last 24 hours",
Config::CHECK_FOR_UPDATES => "true",
Config::PLUGINS => "auth_internal",
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 static $instance;
private $params = [];
public static function get_instance() {
if (self::$instance == null)
self::$instance = new self();
return self::$instance;
}
function __construct() {
$ref = new ReflectionClass(get_class($this));
foreach ($ref->getConstants() as $const => $cvalue) {
if (strpos($const, "_") !== 0) {
$override = getenv($this::_ENVVAR_PREFIX . $const);
$this->params[$cvalue] = !empty($override) ? $override : $this::_DEFAULTS[$const];
}
}
}
private function _get(string $param) {
return $this->params[$param];
}
private function _add(string $param, string $default) {
$override = getenv($this::_ENVVAR_PREFIX . $param);
$this->params[$param] = !empty($override) ? $override : $default;
}
static function add(string $param, string $default) {
$instance = self::get_instance();
return $instance->_add($param, $default);
}
static function get(string $param) {
$instance = self::get_instance();
return $instance->_get($param);
}
}

View File

@ -17,13 +17,13 @@ class Db
// normal usage is Db::pdo()->prepare(...) etc
public function pdo_connect() {
$db_port = defined('DB_PORT') && DB_PORT ? ';port=' . DB_PORT : '';
$db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : '';
$db_port = Config::get(Config::DB_PORT) ? ';port=' . Config::get(Config::DB_PORT) : '';
$db_host = Config::get(Config::DB_HOST) ? ';host=' . Config::get(Config::DB_HOST) : '';
try {
$pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port,
DB_USER,
DB_PASS);
$pdo = new PDO(Config::get(Config::DB_TYPE) . ':dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port,
Config::get(Config::DB_USER),
Config::get(Config::DB_PASS));
} catch (Exception $e) {
print "<pre>Exception while creating PDO object:" . $e->getMessage() . "</pre>";
exit(101);
@ -31,18 +31,18 @@ class Db
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$pdo->query("set client_encoding = 'UTF-8'");
$pdo->query("set datestyle = 'ISO, european'");
$pdo->query("set TIME ZONE 0");
$pdo->query("set cpu_tuple_cost = 0.5");
} else if (DB_TYPE == "mysql") {
} else if (Config::get(Config::DB_TYPE) == "mysql") {
$pdo->query("SET time_zone = '+0:0'");
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
$pdo->query("SET NAMES " . MYSQL_CHARSET);
if (defined('Config::get(Config::MYSQL_CHARSET)') && Config::get(Config::MYSQL_CHARSET)) {
$pdo->query("SET NAMES " . Config::get(Config::MYSQL_CHARSET));
}
}
@ -68,7 +68,7 @@ class Db
}
public static function sql_random_function() {
if (DB_TYPE == "mysql") {
if (Config::get(Config::DB_TYPE) == "mysql") {
return "RAND()";
} else {
return "RANDOM()";

View File

@ -8,9 +8,9 @@ class Digest
Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit");
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'";
} else /* if (DB_TYPE == "mysql") */ {
} else /* if (Config::get(Config::DB_TYPE) == "mysql") */ {
$interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)";
}
@ -48,11 +48,11 @@ class Digest
$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"],
"to_address" => $line["email"],
"subject" => DIGEST_SUBJECT,
"subject" => Config::get(Config::DIGEST_SUBJECT),
"message" => $digest_text,
"message_html" => $digest]);
@ -91,19 +91,19 @@ class Digest
$tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
$tpl->setVariable('CUR_TIME', date('G:i', $local_ts));
$tpl->setVariable('TTRSS_HOST', 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_TIME', date('G:i', $local_ts));
$tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH);
$tpl_t->setVariable('TTRSS_HOST', Config::get(Config::get(Config::SELF_URL_PATH)));
$affected_ids = array();
$days = (int) $days;
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'";
} else /* if (DB_TYPE == "mysql") */ {
} else /* if (Config::get(Config::DB_TYPE) == "mysql") */ {
$interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)";
}

View File

@ -191,7 +191,7 @@ class DiskCache {
];
public function __construct($dir) {
$this->dir = CACHE_DIR . "/" . basename(clean($dir));
$this->dir = Config::get(Config::CACHE_DIR) . "/" . basename(clean($dir));
}
public function get_dir() {
@ -339,7 +339,7 @@ class DiskCache {
}
static function expire() {
$dirs = array_filter(glob(CACHE_DIR . "/*"), "is_dir");
$dirs = array_filter(glob(Config::get(Config::CACHE_DIR) . "/*"), "is_dir");
foreach ($dirs as $cache_dir) {
$num_deleted = 0;
@ -349,7 +349,7 @@ class DiskCache {
if ($files) {
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);
++$num_deleted;
@ -396,7 +396,7 @@ class DiskCache {
$tmppluginhost = new PluginHost();
$tmppluginhost->load(PLUGINS, PluginHost::KIND_SYSTEM);
$tmppluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_SYSTEM);
//$tmppluginhost->load_data();
if ($tmppluginhost->run_hooks_until(PluginHost::HOOK_SEND_LOCAL_FILE, true, $filename))

View File

@ -179,7 +179,7 @@ abstract class FeedItem_Common extends FeedItem {
$cat = preg_replace('/[,\'\"]/', "", $cat);
if (DB_TYPE == "mysql") {
if (Config::get(Config::DB_TYPE) == "mysql") {
$cat = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $cat);
}

View File

@ -186,7 +186,7 @@ class Feeds extends Handler_Protected {
$id = $line["id"];
// frontend doesn't expect pdo returning booleans as strings on mysql
if (DB_TYPE == "mysql") {
if (Config::get(Config::DB_TYPE) == "mysql") {
foreach (["unread", "marked", "published"] as $k) {
$line[$k] = $line[$k] === "1";
}
@ -576,7 +576,7 @@ class Feeds extends Handler_Protected {
function search() {
print json_encode([
"show_language" => DB_TYPE == "pgsql",
"show_language" => Config::get(Config::DB_TYPE) == "pgsql",
"show_syntax_help" => count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0,
"all_languages" => Pref_Feeds::get_ts_languages(),
"default_language" => get_pref('DEFAULT_SEARCH_LANGUAGE')
@ -716,21 +716,21 @@ class Feeds extends Handler_Protected {
switch ($mode) {
case "1day":
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$date_qpart = "date_entered < NOW() - INTERVAL '1 day' ";
} else {
$date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) ";
}
break;
case "1week":
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$date_qpart = "date_entered < NOW() - INTERVAL '1 week' ";
} else {
$date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) ";
}
break;
case "2week":
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$date_qpart = "date_entered < NOW() - INTERVAL '2 week' ";
} else {
$date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) ";
@ -807,7 +807,7 @@ class Feeds extends Handler_Protected {
$intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE");
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$match_part = "date_entered > NOW() - INTERVAL '$intl hour' ";
} else {
$match_part = "date_entered > DATE_SUB(NOW(),
@ -900,7 +900,7 @@ class Feeds extends Handler_Protected {
$intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
} else {
$match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
@ -1056,11 +1056,11 @@ class Feeds extends Handler_Protected {
}
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) {
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) {
@ -1084,7 +1084,7 @@ class Feeds extends Handler_Protected {
$icon = self::_get_icon_file($id);
if ($icon && file_exists($icon)) {
return ICONS_URL . "/" . basename($icon) . "?" . filemtime($icon);
return Config::get(Config::ICONS_URL) . "/" . basename($icon) . "?" . filemtime($icon);
}
}
break;
@ -1332,7 +1332,7 @@ class Feeds extends Handler_Protected {
list($search_query_part, $search_words) = self::_search_to_sql($search, $search_language, $owner_uid);
}
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$test_sth = $pdo->prepare("select $search_query_part
FROM ttrss_entries, ttrss_user_entries WHERE id = ref_id limit 1");
@ -1469,7 +1469,7 @@ class Feeds extends Handler_Protected {
} else if ($feed == -6) { // recently read
$query_strategy_part = "unread = false AND last_read IS NOT NULL";
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$query_strategy_part .= " AND last_read > NOW() - INTERVAL '1 DAY' ";
} else {
$query_strategy_part .= " AND last_read > DATE_SUB(NOW(), INTERVAL 1 DAY) ";
@ -1486,7 +1486,7 @@ class Feeds extends Handler_Protected {
$intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
} else {
$query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
@ -1605,7 +1605,7 @@ class Feeds extends Handler_Protected {
if ($feed == -3)
$first_id_query_strategy_part = "true";
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND";
$yyiw_qpart = "to_char(date_entered, 'IYYY-IW') AS yyiw";
@ -1705,7 +1705,7 @@ class Feeds extends Handler_Protected {
} else {
// browsing by tag
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$distinct_columns = str_replace("desc", "", strtolower($order_by));
$distinct_qpart = "DISTINCT ON (id, $distinct_columns)";
} else {
@ -1948,10 +1948,10 @@ class Feeds extends Handler_Protected {
if ($row = $sth->fetch()) {
$owner_uid = $row["owner_uid"];
if (FORCE_ARTICLE_PURGE != 0) {
Debug::log("purge_feed: FORCE_ARTICLE_PURGE is set, overriding interval to " . FORCE_ARTICLE_PURGE, Debug::$LOG_VERBOSE);
if (Config::get(Config::FORCE_ARTICLE_PURGE) != 0) {
Debug::log("purge_feed: FORCE_ARTICLE_PURGE is set, overriding interval to " . Config::get(Config::FORCE_ARTICLE_PURGE), Debug::$LOG_VERBOSE);
$purge_unread = true;
$purge_interval = FORCE_ARTICLE_PURGE;
$purge_interval = Config::get(Config::FORCE_ARTICLE_PURGE);
} else {
$purge_unread = get_pref("PURGE_UNREAD_ARTICLES", $owner_uid, false);
}
@ -1970,7 +1970,7 @@ class Feeds extends Handler_Protected {
else
$query_limit = "";
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$sth = $pdo->prepare("DELETE FROM ttrss_user_entries
USING ttrss_entries
WHERE ttrss_entries.id = ref_id AND
@ -2153,7 +2153,7 @@ class Feeds extends Handler_Protected {
array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')");
} else {
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$k = mb_strtolower($k);
array_push($search_query_leftover, $not ? "!$k" : $k);
} else {
@ -2168,7 +2168,7 @@ class Feeds extends Handler_Protected {
if (count($search_query_leftover) > 0) {
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
// if there's no joiners consider this a "simple" search and
// concatenate everything with &, otherwise don't try to mess with tsquery syntax

View File

@ -43,7 +43,7 @@ class Handler_Public extends Handler {
$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
$tmppluginhost = new PluginHost();
$tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL);
$tmppluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL);
$tmppluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid);
//$tmppluginhost->load_data();
@ -309,7 +309,7 @@ class Handler_Public extends Handler {
$format = clean($_REQUEST['format'] ?? "atom");
$orig_guid = clean($_REQUEST["orig_guid"] ?? false);
if (SINGLE_USER_MODE) {
if (Config::get(Config::SINGLE_USER_MODE)) {
UserHelper::authenticate("admin", null);
}
@ -347,7 +347,7 @@ class Handler_Public extends Handler {
}
function login() {
if (!SINGLE_USER_MODE) {
if (!Config::get(Config::SINGLE_USER_MODE)) {
$login = clean($_POST["login"]);
$password = clean($_POST["password"]);
@ -355,7 +355,7 @@ class Handler_Public extends Handler {
$safe_mode = checkbox_to_sql_bool(clean($_POST["safe_mode"] ?? false));
if ($remember_me) {
@session_set_cookie_params(SESSION_COOKIE_LIFETIME);
@session_set_cookie_params(Config::get(Config::SESSION_COOKIE_LIFETIME));
} else {
@session_set_cookie_params(0);
}
@ -398,7 +398,7 @@ class Handler_Public extends Handler {
$return = clean($_REQUEST['return']);
if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) {
if ($_REQUEST['return'] && mb_strpos($return, Config::get(Config::SELF_URL_PATH)) === 0) {
header("Location: " . clean($_REQUEST['return']));
} else {
header("Location: " . get_self_url_prefix());
@ -559,7 +559,7 @@ class Handler_Public extends Handler {
$tpl->setVariable('LOGIN', $login);
$tpl->setVariable('RESETPASS_LINK', $resetpass_link);
$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
$tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
$tpl->addBlock('message');
@ -613,7 +613,7 @@ class Handler_Public extends Handler {
function dbupdate() {
startup_gettext();
if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
if (!Config::get(Config::SINGLE_USER_MODE) && $_SESSION["access_level"] < 10) {
$_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
$this->_render_login_form();
exit;
@ -660,7 +660,7 @@ class Handler_Public extends Handler {
<?php
@$op = clean($_REQUEST["subop"]);
$updater = new DbUpdater(Db::pdo(), DB_TYPE, SCHEMA_VERSION);
$updater = new DbUpdater(Db::pdo(), Config::get(Config::DB_TYPE), SCHEMA_VERSION);
if ($op == "performupdate") {
if ($updater->is_update_required()) {
@ -709,7 +709,7 @@ class Handler_Public extends Handler {
print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).",
$updater->get_schema_version(), SCHEMA_VERSION)."</h2>";
if (DB_TYPE == "mysql") {
if (Config::get(Config::DB_TYPE) == "mysql") {
print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ".
"Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>");
} else {

View File

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

View File

@ -11,15 +11,15 @@ class Mailer {
$subject = $params["subject"];
$message = $params["message"];
$message_html = $params["message_html"];
$from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME;
$from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS;
$from_name = $params["from_name"] ? $params["from_name"] : Config::get(Config::SMTP_FROM_NAME);
$from_address = $params["from_address"] ? $params["from_address"] : Config::get(Config::SMTP_FROM_ADDRESS);
$additional_headers = $params["headers"] ? $params["headers"] : [];
$from_combined = $from_name ? "$from_name <$from_address>" : $from_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");
// HOOK_SEND_MAIL plugin instructions:

View File

@ -594,7 +594,7 @@ class OPML extends Handler_Protected {
}
if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) {
$tmp_file = (string)tempnam(CACHE_DIR . '/upload', 'opml');
$tmp_file = (string)tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'opml');
$result = move_uploaded_file($_FILES['opml_file']['tmp_name'],
$tmp_file);

View File

@ -9,7 +9,7 @@ class Pref_Feeds extends Handler_Protected {
public static function get_ts_languages() {
$rv = [];
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$dbh = Db::pdo();
$res = $dbh->query("SELECT cfgname FROM pg_ts_config");
@ -441,7 +441,7 @@ class Pref_Feeds extends Handler_Protected {
$sth->execute([$feed_id, $_SESSION['uid']]);
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'
where id = ?");
@ -453,7 +453,7 @@ class Pref_Feeds extends Handler_Protected {
header("Content-type: text/html");
if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) {
$tmp_file = tempnam(CACHE_DIR . '/upload', 'icon');
$tmp_file = tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'icon');
if (!$tmp_file)
return;
@ -479,7 +479,7 @@ class Pref_Feeds extends Handler_Protected {
$sth->execute([$feed_id, $_SESSION['uid']]);
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);
@ -529,7 +529,7 @@ class Pref_Feeds extends Handler_Protected {
$local_update_intervals = $update_intervals;
$local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]);
if (FORCE_ARTICLE_PURGE == 0) {
if (Config::get(Config::FORCE_ARTICLE_PURGE) == 0) {
$local_purge_intervals = $purge_intervals;
$default_purge_interval = get_pref("PURGE_OLD_DAYS");
@ -539,7 +539,7 @@ class Pref_Feeds extends Handler_Protected {
$local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled"));
} else {
$purge_interval = FORCE_ARTICLE_PURGE;
$purge_interval = Config::get(Config::FORCE_ARTICLE_PURGE);
$local_purge_intervals = [ T_nsprintf('%d day', '%d days', $purge_interval, $purge_interval) ];
}
@ -550,13 +550,13 @@ class Pref_Feeds extends Handler_Protected {
"select" => \Controls\select_feeds_cats("cat_id", $row["cat_id"]),
],
"plugin_data" => $plugin_data,
"force_purge" => (int)FORCE_ARTICLE_PURGE,
"force_purge" => (int)Config::get(Config::FORCE_ARTICLE_PURGE),
"intervals" => [
"update" => $local_update_intervals,
"purge" => $local_purge_intervals,
],
"lang" => [
"enabled" => DB_TYPE == "pgsql",
"enabled" => Config::get(Config::DB_TYPE) == "pgsql",
"default" => get_pref('DEFAULT_SEARCH_LANGUAGE'),
"all" => $this::get_ts_languages(),
]
@ -614,7 +614,7 @@ class Pref_Feeds extends Handler_Protected {
</fieldset>
<?php } ?>
<?php if (DB_TYPE == "pgsql") { ?>
<?php if (Config::get(Config::DB_TYPE) == "pgsql") { ?>
<fieldset>
<label><?= __('Language:') ?></label>
<?= \Controls\select_tag("feed_language", "", $this::get_ts_languages(), ["disabled"=> 1]) ?>
@ -632,7 +632,7 @@ class Pref_Feeds extends Handler_Protected {
<?= $this->_batch_toggle_checkbox("update_interval") ?>
</fieldset>
<?php if (FORCE_ARTICLE_PURGE == 0) { ?>
<?php if (Config::get(Config::FORCE_ARTICLE_PURGE) == 0) { ?>
<fieldset>
<label><?= __('Article purging:') ?></label>
<?= \Controls\select_hash("purge_interval", "", $local_purge_intervals, ["disabled" => 1]) ?>
@ -1147,7 +1147,7 @@ class Pref_Feeds extends Handler_Protected {
function inactiveFeeds() {
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$interval_qpart = "NOW() - INTERVAL '3 months'";
} else {
$interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
@ -1228,8 +1228,8 @@ class Pref_Feeds extends Handler_Protected {
$pdo->commit();
if (file_exists(ICONS_DIR . "/$id.ico")) {
unlink(ICONS_DIR . "/$id.ico");
if (file_exists(Config::get(Config::ICONS_DIR) . "/$id.ico")) {
unlink(Config::get(Config::ICONS_DIR) . "/$id.ico");
}
} else {

View File

@ -236,7 +236,7 @@ class Pref_Prefs extends Handler_Protected {
$tpl->setVariable('LOGIN', $row["login"]);
$tpl->setVariable('NEWMAIL', $email);
$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
$tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
$tpl->addBlock('message');
@ -625,7 +625,7 @@ class Pref_Prefs extends Handler_Protected {
continue;
}
if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && DB_TYPE != "pgsql") {
if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && Config::get(Config::DB_TYPE) != "pgsql") {
continue;
}
@ -705,7 +705,7 @@ class Pref_Prefs extends Handler_Protected {
array_push($listed_boolean_prefs, $pref_name);
if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
if ($pref_name == "PURGE_UNREAD_ARTICLES" && Config::get(Config::FORCE_ARTICLE_PURGE) != 0) {
$is_disabled = true;
$is_checked = true;
} else {
@ -719,9 +719,9 @@ class Pref_Prefs extends Handler_Protected {
} else if (in_array($pref_name, ['FRESH_ARTICLE_MAX_AGE',
'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT'])) {
if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
if ($pref_name == "PURGE_OLD_DAYS" && Config::get(Config::FORCE_ARTICLE_PURGE) != 0) {
$attributes = ["disabled" => true, "required" => true];
$value = FORCE_ARTICLE_PURGE;
$value = Config::get(Config::FORCE_ARTICLE_PURGE);
} else {
$attributes = ["required" => true];
}
@ -829,7 +829,7 @@ class Pref_Prefs extends Handler_Protected {
private function index_plugins_system() {
print_notice("System plugins are enabled in <strong>config.php</strong> for all users.");
$system_enabled = array_map("trim", explode(",", (string)PLUGINS));
$system_enabled = array_map("trim", explode(",", (string)Config::get(Config::PLUGINS)));
$tmppluginhost = new PluginHost();
$tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true);
@ -862,7 +862,7 @@ class Pref_Prefs extends Handler_Protected {
}
private function index_plugins_user() {
$system_enabled = array_map("trim", explode(",", (string)PLUGINS));
$system_enabled = array_map("trim", explode(",", (string)Config::get(Config::PLUGINS)));
$user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
$tmppluginhost = new PluginHost();
@ -1135,7 +1135,7 @@ class Pref_Prefs extends Handler_Protected {
$tpl->readTemplateFromFile("otp_disabled_template.txt");
$tpl->setVariable('LOGIN', $row["login"]);
$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
$tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
$tpl->addBlock('message');

View File

@ -153,10 +153,10 @@ class Pref_System extends Handler_Administrative {
<div dojoType='dijit.layout.AccordionContainer' region='center'>
<div dojoType='dijit.layout.AccordionPane' style='padding : 0' title='<i class="material-icons">report</i> <?= __('Event Log') ?>'>
<?php
if (LOG_DESTINATION == "sql") {
if (Config::get(Config::LOG_DESTINATION) == "sql") {
$this->_log_viewer($page, $severity);
} 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>

View File

@ -86,7 +86,7 @@ class Pref_Users extends Handler_Administrative {
<?php while ($row = $sth->fetch()) { ?>
<li>
<?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";
?>

View File

@ -165,8 +165,9 @@ class RPC extends Handler_Protected {
function setpanelmode() {
$wide = (int) clean($_REQUEST["wide"]);
// FIXME should this use SESSION_COOKIE_LIFETIME and be renewed periodically?
setcookie("ttrss_widescreen", (string)$wide,
time() + COOKIE_LIFETIME_LONG);
time() + 86400*365);
print json_encode(array("wide" => $wide));
}
@ -174,7 +175,7 @@ class RPC extends Handler_Protected {
static function updaterandomfeed_real() {
// Test if the feed need a update (update interval exceded).
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$update_limit_qpart = "AND ((
ttrss_feeds.update_interval = 0
AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
@ -199,7 +200,7 @@ class RPC extends Handler_Protected {
}
// Test if feed is currently being updated by another process.
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')";
} else {
$updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))";
@ -328,7 +329,7 @@ class RPC extends Handler_Protected {
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"]);
if ($content) {
@ -359,9 +360,9 @@ class RPC extends Handler_Protected {
}
$params["safe_mode"] = !empty($_SESSION["safe_mode"]);
$params["check_for_updates"] = CHECK_FOR_UPDATES;
$params["icons_url"] = ICONS_URL;
$params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME;
$params["check_for_updates"] = Config::get(Config::CHECK_FOR_UPDATES);
$params["icons_url"] = Config::get(Config::ICONS_URL);
$params["cookie_lifetime"] = Config::get(Config::SESSION_COOKIE_LIFETIME);
$params["default_view_mode"] = get_pref("_DEFAULT_VIEW_MODE");
$params["default_view_limit"] = (int) get_pref("_DEFAULT_VIEW_LIMIT");
$params["default_view_order_by"] = get_pref("_DEFAULT_VIEW_ORDER_BY");
@ -390,15 +391,10 @@ class RPC extends Handler_Protected {
$params["self_url_prefix"] = get_self_url_prefix();
$params["max_feed_id"] = (int) $max_feed_id;
$params["num_feeds"] = (int) $num_feeds;
$params["hotkeys"] = $this->get_hotkeys_map();
$params["widescreen"] = (int) ($_COOKIE["ttrss_widescreen"] ?? 0);
$params['simple_update'] = SIMPLE_UPDATE_MODE;
$params['simple_update'] = Config::get(Config::SIMPLE_UPDATE_MODE);
$params["icon_indicator_white"] = $this->image_to_base64("images/indicator_white.gif");
$params["labels"] = Labels::get_all($_SESSION["uid"]);
return $params;
@ -432,8 +428,8 @@ class RPC extends Handler_Protected {
$data['cdm_expanded'] = get_pref('CDM_EXPANDED');
$data["labels"] = Labels::get_all($_SESSION["uid"]);
if (LOG_DESTINATION == 'sql' && $_SESSION['access_level'] >= 10) {
if (DB_TYPE == 'pgsql') {
if (Config::get(Config::LOG_DESTINATION) == 'sql' && $_SESSION['access_level'] >= 10) {
if (Config::get(Config::DB_TYPE) == 'pgsql') {
$log_interval = "created_at > NOW() - interval '1 hour'";
} else {
$log_interval = "created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)";
@ -452,13 +448,13 @@ class RPC extends Handler_Protected {
}
}
if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.lock")) {
$data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
if (time() - ($_SESSION["daemon_stamp_check"] ?? 0) > 30) {
$stamp = (int) @file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
$stamp = (int) @file_get_contents(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.stamp");
if ($stamp) {
$stamp_delta = time() - $stamp;

View File

@ -34,9 +34,9 @@ class RSSUtils {
$pdo = Db::pdo();
$sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ?");
// check icon files once every CACHE_MAX_DAYS days
$icon_files = array_filter(glob(ICONS_DIR . "/*.ico"),
function($f) { return filemtime($f) < time() - 86400*CACHE_MAX_DAYS; });
// check icon files once every Config::get(Config::CACHE_MAX_DAYS) days
$icon_files = array_filter(glob(Config::get(Config::ICONS_DIR) . "/*.ico"),
function($f) { return filemtime($f) < time() - 86400 * Config::get(Config::CACHE_MAX_DAYS); });
foreach ($icon_files as $icon) {
$feed_id = basename($icon, ".ico");
@ -52,26 +52,28 @@ 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();
if (!$limit) $limit = Config::get(Config::DAEMON_FEED_LIMIT);
if ($schema_version != SCHEMA_VERSION) {
die("Schema version is wrong, please upgrade the database.\n");
}
$pdo = Db::pdo();
if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) {
if (DB_TYPE == "pgsql") {
$login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'";
if (!Config::get(Config::SINGLE_USER_MODE) && Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT) > 0) {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT)." days'";
} 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 {
$login_thresh_qpart = "";
}
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$update_limit_qpart = "AND ((
ttrss_feeds.update_interval = 0
AND ttrss_user_prefs.value != '-1'
@ -96,7 +98,7 @@ class RSSUtils {
}
// Test if feed is currently being updated by another process.
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$updstart_thresh_qpart = "AND (last_update_started IS NULL OR last_update_started < NOW() - INTERVAL '10 minutes')";
} else {
$updstart_thresh_qpart = "AND (last_update_started IS NULL OR last_update_started < DATE_SUB(NOW(), INTERVAL 10 MINUTE))";
@ -106,7 +108,7 @@ class RSSUtils {
// Update the least recently updated feeds first
$query_order = "ORDER BY last_updated";
if (DB_TYPE == "pgsql") $query_order .= " NULLS FIRST";
if (Config::get(Config::DB_TYPE) == "pgsql") $query_order .= " NULLS FIRST";
$query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated
FROM
@ -182,7 +184,7 @@ class RSSUtils {
if (self::function_enabled('passthru')) {
$exit_code = 0;
passthru(PHP_EXECUTABLE . " update.php --update-feed " . $tline["id"] . " --pidlock feed-" . $tline["id"] . " $quiet $log $log_level", $exit_code);
passthru(Config::get(Config::PHP_EXECUTABLE) . " update.php --update-feed " . $tline["id"] . " --pidlock feed-" . $tline["id"] . " $quiet $log $log_level", $exit_code);
Debug::log(sprintf("<= %.4f (sec) exit code: %d", microtime(true) - $fstarted, $exit_code));
@ -275,7 +277,7 @@ class RSSUtils {
$pluginhost = new PluginHost();
$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
$pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
$pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL);
$pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid);
//$pluginhost->load_data();
@ -288,7 +290,7 @@ class RSSUtils {
if (!$basic_info) {
$feed_data = UrlHelper::fetch($fetch_url, false,
$auth_login, $auth_pass, false,
FEED_FETCH_TIMEOUT,
Config::get(Config::FEED_FETCH_TIMEOUT),
0);
$feed_data = trim($feed_data);
@ -395,12 +397,12 @@ class RSSUtils {
$date_feed_processed = date('Y-m-d H:i');
$cache_filename = CACHE_DIR . "/feeds/" . sha1($fetch_url) . ".xml";
$cache_filename = Config::get(Config::CACHE_DIR) . "/feeds/" . sha1($fetch_url) . ".xml";
$pluginhost = new PluginHost();
$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
$pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
$pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL);
$pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid);
//$pluginhost->load_data();
@ -455,7 +457,7 @@ class RSSUtils {
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);
$force_refetch = true;
@ -469,7 +471,7 @@ class RSSUtils {
"url" => $fetch_url,
"login" => $auth_login,
"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
]);
@ -488,7 +490,7 @@ class RSSUtils {
}
// cache vanilla feed data for re-use
if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/feeds")) {
if ($feed_data && !$auth_pass && !$auth_login && is_writable(Config::get(Config::CACHE_DIR) . "/feeds")) {
$new_rss_hash = sha1($feed_data);
if ($new_rss_hash != $rss_hash) {
@ -561,7 +563,7 @@ class RSSUtils {
Debug::log("language: $feed_language", Debug::$LOG_VERBOSE);
Debug::log("processing feed data...", Debug::$LOG_VERBOSE);
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
} else {
$favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
@ -591,7 +593,7 @@ class RSSUtils {
/* terrible hack: if we crash on floicon shit here, we won't check
* 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;
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);
// Yet another episode of "mysql utf8_general_ci is gimped"
if (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++) {
if (is_string($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);
// Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077
if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") {
if (Config::get(Config::DB_TYPE) == "mysql" && Config::get(Config::MYSQL_CHARSET) != "UTF8MB4") {
foreach ($article as $k => $v) {
// i guess we'll have to take the risk of 4byte unicode labels & tags here
if (is_string($article[$k])) {
@ -1079,7 +1081,7 @@ class RSSUtils {
Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE);
if (DB_TYPE == "pgsql")
if (Config::get(Config::DB_TYPE) == "pgsql")
$tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),";
else
$tsvector_qpart = "";
@ -1107,7 +1109,7 @@ class RSSUtils {
":lang" => $entry_language,
":id" => $ref_id];
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$params[":ts_lang"] = $feed_language;
$params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000);
}
@ -1298,7 +1300,7 @@ class RSSUtils {
$file_content = UrlHelper::fetch(array("url" => $src,
"http_referrer" => $src,
"max_size" => MAX_CACHE_FILE_SIZE));
"max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)));
if ($file_content) {
$cache->put($local_filename, $file_content);
@ -1328,7 +1330,7 @@ class RSSUtils {
$file_content = UrlHelper::fetch(array("url" => $url,
"http_referrer" => $url,
"max_size" => MAX_CACHE_FILE_SIZE));
"max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)));
if ($file_content) {
$cache->put($local_filename, $file_content);
@ -1375,7 +1377,7 @@ class RSSUtils {
$pdo = Db::pdo();
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$pdo->query("DELETE FROM ttrss_error_log
WHERE created_at < NOW() - INTERVAL '7 days'");
} else {
@ -1396,8 +1398,8 @@ class RSSUtils {
$num_deleted = 0;
if (is_writable(LOCK_DIRECTORY)) {
$files = glob(LOCK_DIRECTORY . "/*.lock");
if (is_writable(Config::get(Config::LOCK_DIRECTORY))) {
$files = glob(Config::get(Config::LOCK_DIRECTORY) . "/*.lock");
if ($files) {
foreach ($files as $file) {
@ -1589,9 +1591,9 @@ class RSSUtils {
$days = DAEMON_UNSUCCESSFUL_DAYS_LIMIT;
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$interval_query = "last_successful_update < NOW() - INTERVAL '$days days' AND last_updated > NOW() - INTERVAL '1 days'";
} else /* if (DB_TYPE == "mysql") */ {
} else /* if (Config::get(Config::DB_TYPE) == "mysql") */ {
$interval_query = "last_successful_update < DATE_SUB(NOW(), INTERVAL $days DAY) AND last_updated > DATE_SUB(NOW(), INTERVAL 1 DAY)";
}
@ -1643,7 +1645,7 @@ class RSSUtils {
}
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);
if (!$favicon_url) {
@ -1654,7 +1656,7 @@ class RSSUtils {
// Limiting to "image" type misses those served with text/plain
$contents = UrlHelper::fetch([
'url' => $favicon_url,
'max_size' => MAX_FAVICON_FILE_SIZE,
'max_size' => Config::get(Config::MAX_FAVICON_FILE_SIZE),
//'type' => 'image',
]);
if (!$contents) {

View File

@ -209,7 +209,7 @@ class UrlHelper {
$last_modified = isset($options["last_modified"]) ? $options["last_modified"] : "";
$useragent = isset($options["useragent"]) ? $options["useragent"] : false;
$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_referrer = isset($options["http_referrer"]) ? $options["http_referrer"] : false;
@ -250,8 +250,8 @@ class UrlHelper {
if (count($curl_http_headers) > 0)
curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : Config::get(Config::FILE_FETCH_CONNECT_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_MAXREDIRS, 20);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
@ -395,7 +395,7 @@ class UrlHelper {
),
'method' => 'GET',
'ignore_errors' => true,
'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
'timeout' => $timeout ? $timeout : Config::get(Config::FILE_FETCH_TIMEOUT),
'protocol_version'=> 1.1)
);
@ -417,7 +417,7 @@ class UrlHelper {
$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)) {
$fetch_last_error = "URL received after redirection failed extended validation.";

View File

@ -2,7 +2,7 @@
class UserHelper {
static function authenticate(string $login = null, string $password = null, bool $check_only = false, string $service = null) {
if (!SINGLE_USER_MODE) {
if (!Config::get(Config::SINGLE_USER_MODE)) {
$user_id = false;
$auth_module = false;
@ -88,7 +88,7 @@ class UserHelper {
static function login_sequence() {
$pdo = Db::pdo();
if (SINGLE_USER_MODE) {
if (Config::get(Config::SINGLE_USER_MODE)) {
@session_start();
self::authenticate("admin", null);
startup_gettext();
@ -98,7 +98,7 @@ class UserHelper {
if (empty($_SESSION["uid"])) {
if (AUTH_AUTO_LOGIN && self::authenticate(null, null)) {
if (Config::get(Config::AUTH_AUTO_LOGIN) && self::authenticate(null, null)) {
$_SESSION["ref_schema_version"] = get_schema_version(true);
} else {
self::authenticate(null, null, true);

View File

@ -1,146 +1,18 @@
<?php
// *******************************************
// *** Database configuration (important!) ***
// *******************************************
/*
This file can be used to customize global defaults if environment method is not available (i.e. no Docker).
define('DB_TYPE', '%DB_TYPE'); // pgsql or mysql
define('DB_HOST', '%DB_HOST');
define('DB_USER', '%DB_USER');
define('DB_NAME', '%DB_NAME');
define('DB_PASS', '%DB_PASS');
define('DB_PORT', '%DB_PORT'); // usually 5432 for PostgreSQL, 3306 for MySQL
Use the following syntax to override defaults (options are declared in classes/config.php, prefixed by TTRSS_):
define('MYSQL_CHARSET', 'UTF8');
// Connection charset for MySQL. If you have a legacy database and/or experience
// garbage unicode characters with this option, try setting it to a blank string.
putenv('TTRSS_DB_HOST=myserver')
putenv('TTRSS_SELF_URL_PATH=http://example.com/tt-rss')
// ***********************************
// *** Basic settings (important!) ***
// ***********************************
Plugin-required constants also go here, using define():
define('SELF_URL_PATH', '%SELF_URL_PATH');
// This should be set to a fully qualified URL used to access
// your tt-rss instance over the net, such as: https://example.org/tt-rss/
// The value should be a constant string literal. Please don't use
// PHP server variables here - you might introduce security
// issues on your install and cause hard to debug problems.
// If your tt-rss instance is behind a reverse proxy, use the external URL.
define('LEGACY_CONSTANT', 'value');
define('SINGLE_USER_MODE', false);
// Operate in single user mode, disables all functionality related to
// multiple users and authentication. Enabling this assumes you have
// your tt-rss directory protected by other means (e.g. http auth).
etc.
define('SIMPLE_UPDATE_MODE', false);
// Enables fallback update mode where tt-rss tries to update feeds in
// background while tt-rss is open in your browser.
// If you don't have a lot of feeds and don't want to or can't run
// background processes while not running tt-rss, this method is generally
// viable to keep your feeds up to date.
// Still, there are more robust (and recommended) updating methods
// available, you can read about them here: https://tt-rss.org/wiki/UpdatingFeeds
See this page for more information: https://tt-rss.org/wiki/GlobalConfig
*/
// *****************************
// *** Files and directories ***
// *****************************
define('PHP_EXECUTABLE', '/usr/bin/php');
// Path to PHP *COMMAND LINE* executable, used for various command-line tt-rss
// programs and update daemon. Do not try to use CGI binary here, it won't work.
// If you see HTTP headers being displayed while running tt-rss scripts,
// then most probably you are using the CGI binary. If you are unsure what to
// put in here, ask your hosting provider.
define('LOCK_DIRECTORY', 'lock');
// Directory for lockfiles, must be writable to the user you run
// daemon process or cronjobs under.
define('CACHE_DIR', 'cache');
// Local cache directory for RSS feed content.
define('ICONS_DIR', "feed-icons");
define('ICONS_URL', "feed-icons");
// Local and URL path to the directory, where feed favicons are stored.
// Unless you really know what you're doing, please keep those relative
// to tt-rss main directory.
// **********************
// *** Authentication ***
// **********************
// Please see PLUGINS below to configure various authentication modules.
define('AUTH_AUTO_CREATE', true);
// Allow authentication modules to auto-create users in tt-rss internal
// database when authenticated successfully.
define('AUTH_AUTO_LOGIN', true);
// Automatically login user on remote or other kind of externally supplied
// authentication, otherwise redirect to login form as normal.
// If set to true, users won't be able to set application language
// and settings profile.
// *********************
// *** Feed settings ***
// *********************
define('FORCE_ARTICLE_PURGE', 0);
// When this option is not 0, users ability to control feed purging
// intervals is disabled and all articles (which are not starred)
// older than this amount of days are purged.
// **********************************
// *** Cookies and login sessions ***
// **********************************
define('SESSION_COOKIE_LIFETIME', 86400);
// Default lifetime of a session (e.g. login) cookie. In seconds,
// 0 means cookie will be deleted when browser closes.
// *********************************
// *** Email and digest settings ***
// *********************************
// Tiny Tiny RSS sends mail via PHP mail() function, unless handled
// by a plugin.
// If you need SMTP support, take a look here:
// https://git.tt-rss.org/fox/ttrss-mailer-smtp
define('SMTP_FROM_NAME', 'Tiny Tiny RSS');
define('SMTP_FROM_ADDRESS', 'noreply@your.domain.dom');
// Name, address and subject for sending outgoing mail. This applies
// to password reset notifications, digest emails and any other mail.
define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');
// Subject line for email digests
// ***************************************
// *** Other settings (less important) ***
// ***************************************
define('CHECK_FOR_UPDATES', true);
// Check for updates automatically if running Git version
define('PLUGINS', 'auth_internal, note');
// Comma-separated list of plugins to load automatically for all users.
// System plugins have to be specified here. Please enable at least one
// authentication plugin here (auth_*).
// Users may enable other user plugins from Preferences/Plugins but may not
// disable plugins specified in this list.
// Disabling auth_internal in this list would automatically disable
// reset password link on the login form.
define('LOG_DESTINATION', 'sql');
// Error log destination to use. Possible values: sql (uses internal logging
// you can read in Preferences -> System), syslog - logs to system log.
// Setting this to blank uses PHP logging (usually to http server
// error.log).
// Note that feed updating daemons don't use this logging facility
// for normal output.
define('CONFIG_VERSION', 26);
// Expected config version. Please update this option in config.php
// if necessary (after migrating all new options from this file).
// vim:ft=php

View File

@ -1,6 +1,4 @@
<?php
require_once "functions.php";
spl_autoload_register(function($class) {
$namespace = '';
$class_name = $class;

View File

@ -1,8 +0,0 @@
<?php
function get_pref($pref_name, $user_id = false, $die_on_error = false) {
return Db_Prefs::get()->read($pref_name, $user_id, $die_on_error);
}
function set_pref($pref_name, $value, $user_id = false, $strip_tags = true) {
return Db_Prefs::get()->write($pref_name, $value, $user_id, $strip_tags);
}

View File

@ -1,16 +1,9 @@
<?php
define('EXPECTED_CONFIG_VERSION', 26);
define('SCHEMA_VERSION', 140);
define('LABEL_BASE_INDEX', -1024);
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_code = false;
$fetch_last_content_type = false;
@ -37,55 +30,26 @@
ini_set('display_errors', "false");
ini_set('display_startup_errors', "false");
require_once 'config.php';
// config.php is optional
if (stream_resolve_include_path("config.php"))
require_once "config.php";
/* Some tunables you can override in config.php using define(): */
require_once "autoload.php";
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 */
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE');
} else {
define('SUBSTRING_FOR_DATE', 'SUBSTRING');
}
function get_pref($pref_name, $user_id = false, $die_on_error = false) {
return Db_Prefs::get()->read($pref_name, $user_id, $die_on_error);
}
function set_pref($pref_name, $value, $user_id = false, $strip_tags = true) {
return Db_Prefs::get()->write($pref_name, $value, $user_id, $strip_tags);
}
function get_translations() {
$t = array(
"auto" => __("Detect automatically"),
@ -196,7 +160,6 @@
}
}
require_once 'db-prefs.php';
require_once 'controls.php';
require_once 'controls_compat.php';
@ -375,9 +338,9 @@
}
function file_is_locked($filename) {
if (file_exists(LOCK_DIRECTORY . "/$filename")) {
if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/$filename")) {
if (function_exists('flock')) {
$fp = @fopen(LOCK_DIRECTORY . "/$filename", "r");
$fp = @fopen(Config::get(Config::LOCK_DIRECTORY) . "/$filename", "r");
if ($fp) {
if (flock($fp, LOCK_EX | LOCK_NB)) {
flock($fp, LOCK_UN);
@ -397,11 +360,11 @@
}
function make_lockfile($filename) {
$fp = fopen(LOCK_DIRECTORY . "/$filename", "w");
$fp = fopen(Config::get(Config::LOCK_DIRECTORY) . "/$filename", "w");
if ($fp && flock($fp, LOCK_EX | LOCK_NB)) {
$stat_h = fstat($fp);
$stat_f = stat(LOCK_DIRECTORY . "/$filename");
$stat_f = stat(Config::get(Config::LOCK_DIRECTORY) . "/$filename");
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
if ($stat_h["ino"] != $stat_f["ino"] ||
@ -444,15 +407,15 @@
}
function is_prefix_https() {
return parse_url(SELF_URL_PATH, PHP_URL_SCHEME) == 'https';
return parse_url(Config::get(Config::SELF_URL_PATH), PHP_URL_SCHEME) == 'https';
}
// this returns SELF_URL_PATH sans ending slash
// this returns Config::get(Config::SELF_URL_PATH) sans ending slash
function get_self_url_prefix() {
if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH)-1) {
return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH)-1);
if (strrpos(Config::get(Config::SELF_URL_PATH), "/") === strlen(Config::get(Config::SELF_URL_PATH))-1) {
return substr(Config::get(Config::SELF_URL_PATH), 0, strlen(Config::get(Config::SELF_URL_PATH))-1);
} else {
return SELF_URL_PATH;
return Config::get(Config::SELF_URL_PATH);
}
}
@ -467,7 +430,7 @@
} // function encrypt_password
function init_plugins() {
PluginHost::getInstance()->load(PLUGINS, PluginHost::KIND_ALL);
PluginHost::getInstance()->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL);
return true;
}

View File

@ -16,8 +16,8 @@
} ?>
<?php if (theme_exists(LOCAL_OVERRIDE_STYLESHEET)) {
echo stylesheet_tag(get_theme_path(LOCAL_OVERRIDE_STYLESHEET));
<?php if (theme_exists(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET))) {
echo stylesheet_tag(get_theme_path(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET)));
} ?>
<style type="text/css">
@ -79,7 +79,7 @@
},
bwLimitChange: function(elem) {
Cookie.set("ttrss_bwlimit", elem.checked,
<?php print SESSION_COOKIE_LIFETIME ?>);
<?php print Config::get(Config::SESSION_COOKIE_LIFETIME) ?>);
}
};
@ -122,7 +122,7 @@
onblur="UtilityApp.fetchProfiles()"
value="<?= $_SESSION["fake_password"] ?? "" ?>"/>
</fieldset>
<?php if (strpos(PLUGINS, "auth_internal") !== false) { ?>
<?php if (strpos(Config::get(Config::PLUGINS), "auth_internal") !== false) { ?>
<fieldset class="align-right">
<a href="public.php?op=forgotpass"><?= __("I forgot my password") ?></a>
</fieldset>
@ -161,7 +161,7 @@
<div dojoType="dijit.Tooltip" connectId="safe_mode_label" position="below" style="display:none">
<?= __("Uses default theme and prevents all plugins from loading."); ?>
</div>
<?php if (SESSION_COOKIE_LIFETIME > 0) { ?>
<?php if (Config::get(Config::SESSION_COOKIE_LIFETIME) > 0) { ?>
<fieldset class="narrow">
<label> </label>

View File

@ -21,7 +21,7 @@
$sth = $pdo->prepare("SELECT engine, table_name FROM information_schema.tables WHERE
table_schema = ? AND table_name LIKE 'ttrss_%' AND engine != 'InnoDB'");
$sth->execute([DB_NAME]);
$sth->execute([Config::get(Config::DB_NAME)]);
$bad_tables = [];
@ -44,8 +44,8 @@
array_push($errors, "Please copy config.php-dist to config.php");
}
if (strpos(PLUGINS, "auth_") === false) {
array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php");
if (strpos(Config::get(Config::PLUGINS), "auth_") === false) {
array_push($errors, "Please enable at least one authentication module via Config::get(Config::PLUGINS) constant in config.php");
}
if (function_exists('posix_getuid') && posix_getuid() == 0) {
@ -60,43 +60,25 @@
array_push($errors, "PHP UConverter class is missing, it's provided by the Internationalization (intl) module.");
}
if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) {
array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value.");
if (!is_writable(Config::get(Config::CACHE_DIR) . "/images")) {
array_push($errors, "Image cache is not writable (chmod -R 777 ".Config::get(Config::CACHE_DIR)."/images)");
}
if (!is_writable(CACHE_DIR . "/images")) {
array_push($errors, "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)");
if (!is_writable(Config::get(Config::CACHE_DIR) . "/upload")) {
array_push($errors, "Upload cache is not writable (chmod -R 777 ".Config::get(Config::CACHE_DIR)."/upload)");
}
if (!is_writable(CACHE_DIR . "/upload")) {
array_push($errors, "Upload cache is not writable (chmod -R 777 ".CACHE_DIR."/upload)");
if (!is_writable(Config::get(Config::CACHE_DIR) . "/export")) {
array_push($errors, "Data export cache is not writable (chmod -R 777 ".Config::get(Config::CACHE_DIR)."/export)");
}
if (!is_writable(CACHE_DIR . "/export")) {
array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)");
}
require_once "sanity_config.php";
if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) {
array_push($errors,
"Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh");
}
foreach (get_required_defines() as $d) {
if (!defined($d)) {
array_push($errors,
"Required configuration file parameter $d is not defined in config.php. You might need to copy it from config.php-dist.");
}
}
if (SINGLE_USER_MODE && class_exists("PDO")) {
if (Config::get(Config::SINGLE_USER_MODE) && class_exists("PDO")) {
$pdo = Db::pdo();
$res = $pdo->query("SELECT id FROM ttrss_users WHERE id = 1");
if (!$res->fetch()) {
array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found.");
array_push($errors, "Config::get(Config::SINGLE_USER_MODE) is enabled in config.php but default admin account is not found.");
}
}
@ -107,26 +89,26 @@
$ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path);
}
if (SELF_URL_PATH == "http://example.org/tt-rss/") {
if (Config::get(Config::SELF_URL_PATH) == "http://example.org/tt-rss/") {
$hint = $ref_self_url_path ? "(possible value: <b>$ref_self_url_path</b>)" : "";
array_push($errors,
"Please set SELF_URL_PATH to the correct value for your server: $hint");
"Please set Config::get(Config::SELF_URL_PATH) to the correct value for your server: $hint");
}
if ($ref_self_url_path &&
(!defined('_SKIP_SELF_URL_PATH_CHECKS') || !_SKIP_SELF_URL_PATH_CHECKS) &&
SELF_URL_PATH != $ref_self_url_path && SELF_URL_PATH != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path)-1)) {
Config::get(Config::SELF_URL_PATH) != $ref_self_url_path && Config::get(Config::SELF_URL_PATH) != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path)-1)) {
array_push($errors,
"Please set SELF_URL_PATH to the correct value detected for your server: <b>$ref_self_url_path</b> (you're using: <b>" . SELF_URL_PATH . "</b>)");
"Please set Config::get(Config::SELF_URL_PATH) to the correct value detected for your server: <b>$ref_self_url_path</b> (you're using: <b>" . Config::get(Config::SELF_URL_PATH) . "</b>)");
}
}
if (!is_writable(ICONS_DIR)) {
array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n");
if (!is_writable(Config::get(Config::ICONS_DIR))) {
array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".Config::get(Config::ICONS_DIR).").\n");
}
if (!is_writable(LOCK_DIRECTORY)) {
array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 ".LOCK_DIRECTORY.").\n");
if (!is_writable(Config::get(Config::LOCK_DIRECTORY))) {
array_push($errors, "Config::get(Config::LOCK_DIRECTORY) defined in config.php is not writable (chmod -R 777 ".Config::get(Config::LOCK_DIRECTORY).").\n");
}
if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
@ -161,7 +143,7 @@
array_push($errors, "PHP support for DOMDocument is required, but was not found.");
}
if (DB_TYPE == "mysql") {
if (Config::get(Config::DB_TYPE) == "mysql") {
$bad_tables = check_mysql_tables();
if (count($bad_tables) > 0) {

View File

@ -1,3 +0,0 @@
<?php # This file has been generated at: Mon Feb 22 14:17:27 MSK 2021
define('GENERATED_CONFIG_CHECK', 26);
function get_required_defines() { return [ 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'SESSION_COOKIE_LIFETIME', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'CHECK_FOR_UPDATES', 'PLUGINS', 'LOG_DESTINATION', 'CONFIG_VERSION']; }

View File

@ -3,12 +3,12 @@
// Original from http://www.daniweb.com/code/snippet43.html
require_once "config.php";
require_once "autoload.php";
require_once "functions.php";
require_once "errorhandler.php";
require_once "lib/gettext/gettext.inc.php";
$session_expire = min(2147483647 - time() - 1, max(SESSION_COOKIE_LIFETIME, 86400));
$session_expire = min(2147483647 - time() - 1, max(\Config::get(\Config::SESSION_COOKIE_LIFETIME), 86400));
$session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME;
if (is_server_https()) {
@ -37,7 +37,7 @@
}
function validate_session() {
if (SINGLE_USER_MODE) return true;
if (\Config::get(\Config::SINGLE_USER_MODE)) return true;
if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version()) {
$_SESSION["login_error_msg"] =
@ -144,7 +144,7 @@
return true;
}
if (!SINGLE_USER_MODE /* && DB_TYPE == "pgsql" */) {
if (!\Config::get(\Config::SINGLE_USER_MODE)) {
session_set_save_handler('\Sessions\ttrss_open',
'\Sessions\ttrss_close', '\Sessions\ttrss_read',
'\Sessions\ttrss_write', '\Sessions\ttrss_destroy',

View File

@ -1,9 +1,4 @@
<?php
if (!file_exists("config.php")) {
print "<b>Fatal Error</b>: You forgot to copy
<b>config.php-dist</b> to <b>config.php</b> and edit it.\n";
exit;
}
// we need a separate check here because functions.php might get parsed
// incorrectly before 5.3 because of :: syntax.
@ -19,8 +14,6 @@
require_once "sessions.php";
require_once "functions.php";
require_once "sanity_check.php";
require_once "config.php";
require_once "db-prefs.php";
if (!init_plugins()) return;
@ -42,8 +35,8 @@
}
} ?>
<?php if (theme_exists(LOCAL_OVERRIDE_STYLESHEET)) {
echo stylesheet_tag(get_theme_path(LOCAL_OVERRIDE_STYLESHEET));
<?php if (theme_exists(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET))) {
echo stylesheet_tag(get_theme_path(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET)));
} ?>
<script type="text/javascript">

View File

@ -1,7 +1,8 @@
parameters:
level: 5
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.#'
- '#Access to an undefined property DOMNode::\$tagName.#'
- '#Call to an undefined method DOMNode::(get|remove|set)Attribute\(\).#'

View File

@ -68,7 +68,7 @@ class Af_Proxy_Http extends Plugin {
header("Location: " . $this->cache->get_url($local_filename));
return;
} 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 ($this->cache->put($local_filename, $data)) {

View File

@ -134,7 +134,7 @@ class Af_Psql_Trgm extends Plugin {
title="<i class='material-icons'>extension</i> <?= __('Mark similar articles as read (af_psql_trgm)') ?>">
<?php
if (DB_TYPE != "pgsql") {
if (Config::get(Config::DB_TYPE) != "pgsql") {
print_error("Database type not supported.");
} else {
$res = $this->pdo->query("select 'similarity'::regproc");
@ -258,7 +258,7 @@ class Af_Psql_Trgm extends Plugin {
function hook_article_filter($article) {
if (DB_TYPE != "pgsql") return $article;
if (Config::get(Config::DB_TYPE) != "pgsql") return $article;
$res = $this->pdo->query("select 'similarity'::regproc");
if (!$res || !$res->fetch()) return $article;

View File

@ -530,7 +530,7 @@ class Af_RedditImgur extends Plugin {
$entry_guid = $article["guid_hashed"];
$owner_uid = $article["owner_uid"];
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$interval_qpart = "date_entered < NOW() - INTERVAL '1 day'";
} else {
$interval_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY)";

View File

@ -244,7 +244,7 @@ class Auth_Internal extends Auth_Base {
$tpl->readTemplateFromFile("password_change_template.txt");
$tpl->setVariable('LOGIN', $row["login"]);
$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
$tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
$tpl->addBlock('message');

View File

@ -21,7 +21,7 @@ class Bookmarklets extends Plugin {
}
function subscribe() {
if (SINGLE_USER_MODE) {
if (Config::get(Config::SINGLE_USER_MODE)) {
UserHelper::login_sequence();
}
@ -172,7 +172,7 @@ class Bookmarklets extends Plugin {
}
function sharepopup() {
if (SINGLE_USER_MODE) {
if (Config::get(Config::SINGLE_USER_MODE)) {
UserHelper::login_sequence();
}

View File

@ -136,7 +136,7 @@ class Cache_Starred_Images extends Plugin {
if (!$this->cache->exists($local_filename)) {
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)
return $this->cache->put($local_filename, $data);;

View File

@ -2,18 +2,10 @@
set_include_path(__DIR__ ."/include" . PATH_SEPARATOR .
get_include_path());
if (!file_exists("config.php")) {
print "<b>Fatal Error</b>: You forgot to copy
<b>config.php-dist</b> to <b>config.php</b> and edit it.\n";
exit;
}
require_once "autoload.php";
require_once "sessions.php";
require_once "functions.php";
require_once "sanity_check.php";
require_once "config.php";
require_once "db-prefs.php";
if (!init_plugins()) return;
@ -34,8 +26,8 @@
}
} ?>
<?php if (theme_exists(LOCAL_OVERRIDE_STYLESHEET)) {
echo stylesheet_tag(get_theme_path(LOCAL_OVERRIDE_STYLESHEET));
<?php if (theme_exists(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET))) {
echo stylesheet_tag(get_theme_path(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET)));
} ?>
<script type="text/javascript">

View File

@ -6,8 +6,6 @@
require_once "sessions.php";
require_once "functions.php";
require_once "sanity_check.php";
require_once "config.php";
require_once "db-prefs.php";
startup_gettext();

View File

@ -9,12 +9,10 @@
require_once "autoload.php";
require_once "functions.php";
require_once "config.php";
require_once "sanity_check.php";
require_once "db-prefs.php";
function make_stampfile($filename) {
$fp = fopen(LOCK_DIRECTORY . "/$filename", "w");
$fp = fopen(Config::get(Config::LOCK_DIRECTORY) . "/$filename", "w");
if (flock($fp, LOCK_EX | LOCK_NB)) {
fwrite($fp, time() . "\n");
@ -30,9 +28,9 @@
$days = (int) $days;
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$interval_query = "date_updated < NOW() - INTERVAL '$days days'";
} else /*if (DB_TYPE == "mysql") */ {
} else /*if (Config::get(Config::DB_TYPE) == "mysql") */ {
$interval_query = "date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)";
}
@ -212,7 +210,7 @@
}
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();
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, $options);
@ -224,10 +222,10 @@
$log = isset($options['log']) ? '--log '.$options['log'] : '';
$log_level = isset($options['log-level']) ? '--log-level '.$options['log-level'] : '';
passthru(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
$spawn_interval = max(60, DAEMON_SLEEP_INTERVAL);
$spawn_interval = max(60, Config::get(Config::DAEMON_SLEEP_INTERVAL));
Debug::log("Sleeping for $spawn_interval seconds...");
sleep($spawn_interval);
@ -255,7 +253,7 @@
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)
RSSUtils::housekeeping_common();
@ -277,7 +275,7 @@
Debug::log("clearing existing indexes...");
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$sth = $pdo->query( "SELECT relname FROM
pg_catalog.pg_class WHERE relname LIKE 'ttrss_%'
AND relname NOT LIKE '%_pkey'
@ -288,7 +286,7 @@
}
while ($line = $sth->fetch()) {
if (DB_TYPE == "pgsql") {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$statement = "DROP INDEX " . $line["relname"];
Debug::log($statement);
} else {
@ -299,9 +297,9 @@
$pdo->query($statement);
}
Debug::log("reading indexes from schema for: " . DB_TYPE);
Debug::log("reading indexes from schema for: " . Config::get(Config::DB_TYPE));
$fp = fopen("schema/ttrss_schema_" . DB_TYPE . ".sql", "r");
$fp = fopen("schema/ttrss_schema_" . Config::get(Config::DB_TYPE) . ".sql", "r");
if ($fp) {
while ($line = fgets($fp)) {
$matches = array();
@ -375,14 +373,14 @@
}
if (isset($options["update-schema"])) {
Debug::log("Checking for updates (" . DB_TYPE . ")...");
Debug::log("Checking for updates (" . Config::get(Config::DB_TYPE) . ")...");
$updater = new DbUpdater(Db::pdo(), DB_TYPE, SCHEMA_VERSION);
$updater = new DbUpdater(Db::pdo(), Config::get(Config::DB_TYPE), SCHEMA_VERSION);
if ($updater->is_update_required()) {
Debug::log("Schema update required, version " . $updater->get_schema_version() . " to " . SCHEMA_VERSION);
if (DB_TYPE == "mysql")
if (Config::get(Config::DB_TYPE) == "mysql")
Debug::Log("READ THIS: Due to MySQL limitations, your database is not completely protected while updating.\n".
"Errors may put it in an inconsistent state requiring manual rollback.\nBACKUP YOUR DATABASE BEFORE CONTINUING.");
else
@ -460,7 +458,7 @@
if (isset($options["list-plugins"])) {
$tmppluginhost = new PluginHost();
$tmppluginhost->load_all($tmppluginhost::KIND_ALL);
$enabled = array_map("trim", explode(",", PLUGINS));
$enabled = array_map("trim", explode(",", Config::get(Config::PLUGINS)));
echo "List of all available plugins:\n";
@ -515,8 +513,8 @@
PluginHost::getInstance()->run_commands($options);
if (file_exists(LOCK_DIRECTORY . "/$lock_filename"))
if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/$lock_filename"))
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
fclose($lock_handle);
unlink(LOCK_DIRECTORY . "/$lock_filename");
unlink(Config::get(Config::LOCK_DIRECTORY) . "/$lock_filename");
?>

View File

@ -10,16 +10,7 @@
require_once "autoload.php";
require_once "functions.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 "db-prefs.php";
if (!function_exists('pcntl_fork')) {
die("error: This script requires PHP compiled with PCNTL module.\n");
@ -78,7 +69,7 @@
foreach (array_keys($ctimes) as $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...");
posix_kill($pid, SIGKILL);
}
@ -98,9 +89,9 @@
function shutdown($caller_pid) {
if ($caller_pid == posix_getpid()) {
if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.lock")) {
Debug::log("Removing lockfile (master)...");
unlink(LOCK_DIRECTORY . "/update_daemon.lock");
unlink(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.lock");
}
}
}
@ -108,9 +99,9 @@
function task_shutdown() {
$pid = posix_getpid();
if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) {
if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon-$pid.lock")) {
Debug::log("Removing task lockfile for PID $pid...");
unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock");
unlink(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon-$pid.lock");
}
}
@ -143,9 +134,9 @@
print " --log FILE - log messages to FILE\n";
print " --log-level N - log verbosity level\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 " default: " . SPAWN_INTERVAL . " seconds.\n";
print " default: " . Config::get(Config::DAEMON_SLEEP_INTERVAL) . " seconds.\n";
print " --quiet - don't output messages to stdout\n";
return;
}
@ -170,14 +161,14 @@
Debug::log("Set to spawn " . $options["tasks"] . " children.");
$max_jobs = $options["tasks"];
} else {
$max_jobs = MAX_JOBS;
$max_jobs = Config::get(Config::DAEMON_MAX_JOBS);
}
if (isset($options["interval"])) {
Debug::log("Spawn interval: " . $options["interval"] . " seconds.");
$spawn_interval = $options["interval"];
} 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
@ -249,7 +240,7 @@
$my_pid = posix_getpid();
passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
passthru(Config::get(Config::PHP_EXECUTABLE) . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
sleep(1);

View File

@ -1,17 +0,0 @@
#!/bin/sh
DESTINATION="include/sanity_config.php"
echo "<?php # This file has been generated at: " `date` > $DESTINATION
echo -n "define('GENERATED_CONFIG_CHECK', " >> $DESTINATION
grep CONFIG_VERSION config.php-dist | awk -F ' |\)' '{ print $2 }' | xargs echo -n >> $DESTINATION
echo ");" >> $DESTINATION
echo -n "function get_required_defines() { return [ " >> $DESTINATION
grep define\( config.php-dist | awk -F\' '{ print "*" $2 "*," }' | grep -v DB_PORT | xargs echo -n | sed -e s/,$// -e s/*/\'/g >> $DESTINATION
echo "]; }" >> $DESTINATION