1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 09:05:55 +00:00

wip: initial for config object

This commit is contained in:
Andrew Dolgov
2021-02-22 21:47:48 +03:00
parent 42173386b3
commit e4107ac952
30 changed files with 165 additions and 199 deletions

View File

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

View File

@@ -80,7 +80,9 @@
/* tunables end here */
if (DB_TYPE == "pgsql") {
require_once "autoload.php";
if (Config::get(Config::DB_TYPE) == "pgsql") {
define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE');
} else {
define('SUBSTRING_FOR_DATE', 'SUBSTRING');
@@ -375,9 +377,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 +399,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 +446,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 +469,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

@@ -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,17 +89,17 @@
$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>)");
}
}
@@ -125,8 +107,8 @@
array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".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

@@ -5,10 +5,11 @@
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 +38,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 +145,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',