From 08857c679d700b982a1af21ce11c4b25e125e44a Mon Sep 17 00:00:00 2001 From: Clément Date: Wed, 15 Feb 2017 14:20:49 +0100 Subject: add - _ and . in accepted char --- cli/create-user.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/create-user.php b/cli/create-user.php index 444264cc7..e5b4493e3 100755 --- a/cli/create-user.php +++ b/cli/create-user.php @@ -16,8 +16,9 @@ if (empty($options['user'])) { fail('Usage: ' . basename(__FILE__) . " --user username ( --password 'password' --api-password 'api_password'" . " --language en --email user@example.net --token 'longRandomString --no-default-feeds' )"); } +$aValid = array('-', '_', '.'); $username = $options['user']; -if (!ctype_alnum($username)) { +if (!ctype_alnum(str_replace($aValid, '', $username))) { fail('FreshRSS error: invalid username “' . $username . '”'); } -- cgit v1.2.3 From 8d2b76334cd60356c85810bf4902124105d54ad4 Mon Sep 17 00:00:00 2001 From: Clément Date: Thu, 16 Feb 2017 14:27:45 +0100 Subject: Possibility to register user having a '-', a '_' or a '.' in username --- app/Controllers/userController.php | 6 ++++-- app/Models/Auth.php | 5 +++-- app/install.php | 2 +- app/views/auth/formLogin.phtml | 2 +- app/views/user/manage.phtml | 2 +- cli/_cli.php | 4 +++- cli/delete-user.php | 3 ++- cli/do-install.php | 3 ++- 8 files changed, 17 insertions(+), 10 deletions(-) (limited to 'cli') diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index 9d6ae18e6..6199ff218 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -103,8 +103,9 @@ class FreshRSS_user_Controller extends Minz_ActionController { if (!is_array($userConfig)) { $userConfig = array(); } + $aValid = array('-', '_', '.'); - $ok = ($new_user_name != '') && ctype_alnum($new_user_name); + $ok = ($new_user_name != '') && ctype_alnum(str_replace($aValid, '', $new_user_name)); if ($ok) { $languages = Minz_Translate::availableLanguages(); @@ -187,7 +188,8 @@ class FreshRSS_user_Controller extends Minz_ActionController { $db = FreshRSS_Context::$system_conf->db; require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php'); - $ok = ctype_alnum($username); + $aValid = array('-', '_', '.'); + $ok = ctype_alnum(str_replace($aValid, '', $username)); if ($ok) { $default_user = FreshRSS_Context::$system_conf->default_user; $ok &= (strcasecmp($username, $default_user) !== 0); //It is forbidden to delete the default user diff --git a/app/Models/Auth.php b/app/Models/Auth.php index b3255cfbd..e63a24b27 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -182,7 +182,8 @@ class FreshRSS_Auth { class FreshRSS_FormAuth { public static function checkCredentials($username, $hash, $nonce, $challenge) { - if (!ctype_alnum($username) || + $aValid = array('-', '_', '.'); + if (!ctype_alnum(str_replace($aValid, '', $username)) || !ctype_graph($challenge) || !ctype_alnum($nonce)) { Minz_Log::debug('Invalid credential parameters:' . @@ -211,7 +212,7 @@ class FreshRSS_FormAuth { // Token has expired (> 1 month) or does not exist. // TODO: 1 month -> use a configuration instead @unlink($token_file); - return array(); + return array(); } $credentials = @file_get_contents($token_file); diff --git a/app/install.php b/app/install.php index 986a7dc60..1b23254de 100644 --- a/app/install.php +++ b/app/install.php @@ -553,7 +553,7 @@ function printStep2() {
- +
diff --git a/app/views/auth/formLogin.phtml b/app/views/auth/formLogin.phtml index a8213b7ae..6cfe6764a 100644 --- a/app/views/auth/formLogin.phtml +++ b/app/views/auth/formLogin.phtml @@ -9,7 +9,7 @@
- +
diff --git a/app/views/user/manage.phtml b/app/views/user/manage.phtml index a32247d14..334650e56 100644 --- a/app/views/user/manage.phtml +++ b/app/views/user/manage.phtml @@ -22,7 +22,7 @@
- +
diff --git a/cli/_cli.php b/cli/_cli.php index 7d1a7c6b2..885199659 100644 --- a/cli/_cli.php +++ b/cli/_cli.php @@ -20,7 +20,9 @@ function fail($message) { } function cliInitUser($username) { - if (!ctype_alnum($username)) { + $aValid = array('-', '_', '.'); + + if (!ctype_alnum(str_replace($aValid, '', $username))) { fail('FreshRSS error: invalid username: ' . $username . "\n"); } diff --git a/cli/delete-user.php b/cli/delete-user.php index 6f0e86e17..82605fb27 100755 --- a/cli/delete-user.php +++ b/cli/delete-user.php @@ -9,8 +9,9 @@ $options = getopt('', array( if (empty($options['user'])) { fail('Usage: ' . basename(__FILE__) . " --user username"); } +$aValid = array('-', '_', '.'); $username = $options['user']; -if (!ctype_alnum($username)) { +if (!ctype_alnum(str_replace($aValid, '', $username))) { fail('FreshRSS error: invalid username “' . $username . '”'); } diff --git a/cli/do-install.php b/cli/do-install.php index 100d4947f..eb46c7e93 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -47,7 +47,8 @@ if ($requirements['all'] !== 'ok') { fail($message); } -if (!ctype_alnum($options['default_user'])) { +$aValid = array('-', '_', '.'); +if (!ctype_alnum(str_replace($aValid, '', $options['default_user']))) { fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $options['default_user']); } -- cgit v1.2.3 From 4eeae5171b885b6dda392f5dd68d6dd78a0c7858 Mon Sep 17 00:00:00 2001 From: Clément Date: Thu, 16 Feb 2017 18:54:59 +0100 Subject: use function with preg_match to check username --- app/Controllers/userController.php | 11 +++++++---- app/Models/Auth.php | 3 +-- cli/_cli.php | 4 +--- cli/create-user.php | 3 +-- cli/delete-user.php | 3 +-- cli/do-install.php | 3 +-- 6 files changed, 12 insertions(+), 15 deletions(-) (limited to 'cli') diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index 6199ff218..246be1bfe 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -34,6 +34,11 @@ class FreshRSS_user_Controller extends Minz_ActionController { return $passwordHash == '' ? '' : $passwordHash; } + public static function checkUsername($username) { + $match = '/^[a-zA-Z_]{1,38}$/'; + return preg_match($match, $username) === 1; + } + /** * This action displays the user profile page. */ @@ -103,9 +108,8 @@ class FreshRSS_user_Controller extends Minz_ActionController { if (!is_array($userConfig)) { $userConfig = array(); } - $aValid = array('-', '_', '.'); - $ok = ($new_user_name != '') && ctype_alnum(str_replace($aValid, '', $new_user_name)); + $ok = self::checkUsername($new_user_name); if ($ok) { $languages = Minz_Translate::availableLanguages(); @@ -188,8 +192,7 @@ class FreshRSS_user_Controller extends Minz_ActionController { $db = FreshRSS_Context::$system_conf->db; require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php'); - $aValid = array('-', '_', '.'); - $ok = ctype_alnum(str_replace($aValid, '', $username)); + $ok = self::checkUsername($username); if ($ok) { $default_user = FreshRSS_Context::$system_conf->default_user; $ok &= (strcasecmp($username, $default_user) !== 0); //It is forbidden to delete the default user diff --git a/app/Models/Auth.php b/app/Models/Auth.php index e63a24b27..476627e10 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -182,8 +182,7 @@ class FreshRSS_Auth { class FreshRSS_FormAuth { public static function checkCredentials($username, $hash, $nonce, $challenge) { - $aValid = array('-', '_', '.'); - if (!ctype_alnum(str_replace($aValid, '', $username)) || + if (!FreshRSS_user_Controller::checkUsername($username) || !ctype_graph($challenge) || !ctype_alnum($nonce)) { Minz_Log::debug('Invalid credential parameters:' . diff --git a/cli/_cli.php b/cli/_cli.php index 885199659..f5e36eabc 100644 --- a/cli/_cli.php +++ b/cli/_cli.php @@ -20,9 +20,7 @@ function fail($message) { } function cliInitUser($username) { - $aValid = array('-', '_', '.'); - - if (!ctype_alnum(str_replace($aValid, '', $username))) { + if (!FreshRSS_user_Controller::checkUsername($username)) { fail('FreshRSS error: invalid username: ' . $username . "\n"); } diff --git a/cli/create-user.php b/cli/create-user.php index e5b4493e3..c9e350c14 100755 --- a/cli/create-user.php +++ b/cli/create-user.php @@ -16,9 +16,8 @@ if (empty($options['user'])) { fail('Usage: ' . basename(__FILE__) . " --user username ( --password 'password' --api-password 'api_password'" . " --language en --email user@example.net --token 'longRandomString --no-default-feeds' )"); } -$aValid = array('-', '_', '.'); $username = $options['user']; -if (!ctype_alnum(str_replace($aValid, '', $username))) { +if (!FreshRSS_user_Controller::checkUsername($username)) { fail('FreshRSS error: invalid username “' . $username . '”'); } diff --git a/cli/delete-user.php b/cli/delete-user.php index 82605fb27..baa81b893 100755 --- a/cli/delete-user.php +++ b/cli/delete-user.php @@ -9,9 +9,8 @@ $options = getopt('', array( if (empty($options['user'])) { fail('Usage: ' . basename(__FILE__) . " --user username"); } -$aValid = array('-', '_', '.'); $username = $options['user']; -if (!ctype_alnum(str_replace($aValid, '', $username))) { +if (!FreshRSS_user_Controller::checkUsername($username)) { fail('FreshRSS error: invalid username “' . $username . '”'); } diff --git a/cli/do-install.php b/cli/do-install.php index eb46c7e93..064a64ab2 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -47,8 +47,7 @@ if ($requirements['all'] !== 'ok') { fail($message); } -$aValid = array('-', '_', '.'); -if (!ctype_alnum(str_replace($aValid, '', $options['default_user']))) { +if (!FreshRSS_user_Controller::checkUsername($options['default_user'])) { fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $options['default_user']); } -- cgit v1.2.3 From efcab77470d2571be6537a92b59fc1e44cecddb9 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Thu, 23 Feb 2017 18:53:08 +0100 Subject: Fixed empty db-prefix in do-install.php --- cli/do-install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/do-install.php b/cli/do-install.php index 100d4947f..1f9072060 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -73,7 +73,7 @@ if ((!empty($config['base_url'])) && server_is_public($config['base_url'])) { foreach ($dBparams as $dBparam) { $dBparam = rtrim($dBparam, ':'); - if (!empty($options[$dBparam])) { + if (isset($options[$dBparam])) { $param = substr($dBparam, strlen('db-')); $config['db'][$param] = $options[$dBparam]; } -- cgit v1.2.3 From 9e931d1bc52443aeaf9ccf7e2b3d6eaa135368ec Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Fri, 24 Feb 2017 07:20:50 +0100 Subject: Added disable_update option to cli/do-install.php --- cli/do-install.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/do-install.php b/cli/do-install.php index 100d4947f..483ec5224 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -13,6 +13,7 @@ $params = array( 'auth_type:', 'api_enabled', 'allow_robots', + 'disable_update', ); $dBparams = array( @@ -31,7 +32,7 @@ if (empty($options['default_user'])) { " --environment production --base_url https://rss.example.net/" . " --title FreshRSS --allow_anonymous --api_enabled" . " --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123" . - " --db-base freshrss --db-prefix freshrss_ )"); + " --db-base freshrss --db-prefix freshrss_ --disable_update )"); } fwrite(STDERR, 'FreshRSS install…' . "\n"); -- cgit v1.2.3 From 1fc3054c2f85478df53b19365c1b0ebc46c372af Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Fri, 24 Feb 2017 07:54:31 +0100 Subject: Added cli tool to reconfigure FreshRSS --- cli/reconfigure.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 cli/reconfigure.php (limited to 'cli') diff --git a/cli/reconfigure.php b/cli/reconfigure.php new file mode 100755 index 000000000..5294dd2df --- /dev/null +++ b/cli/reconfigure.php @@ -0,0 +1,58 @@ +#!/usr/bin/php +$param = $options[$param] === false ? true : $options[$param]; + } +} +$db = $config->db; +foreach ($dBparams as $dBparam) { + $dBparam = rtrim($dBparam, ':'); + if (isset($options[$dBparam])) { + $param = substr($dBparam, strlen('db-')); + $db[$param] = $options[$dBparam]; + } +} +$config->db = $db; + +if (!ctype_alnum($config->default_user)) { + fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $config->default_user); +} + +if (isset($config->auth_type) && !in_array($config->auth_type, array('form', 'http_auth', 'none'))) { + fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }: ' . $config->auth_type); +} + +$config->save(); + +done(); -- cgit v1.2.3 From 745f0ae0141607aaf751630e68f5685957e3d398 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 24 Feb 2017 23:21:23 +0100 Subject: Changelog 1436, 1439 https://github.com/FreshRSS/FreshRSS/issues/1424 https://github.com/FreshRSS/FreshRSS/issues/1432 https://github.com/FreshRSS/FreshRSS/pull/1436 https://github.com/FreshRSS/FreshRSS/pull/1439 --- CHANGELOG.md | 3 +++ cli/README.md | 3 +++ 2 files changed, 6 insertions(+) (limited to 'cli') diff --git a/CHANGELOG.md b/CHANGELOG.md index adbd0885b..4738b7360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,11 @@ ## 2017-03-xx FreshRSS 1.6.3-dev * Features + * New option `disable_update` (also from CLI) to hide the system to update to new FreshRSS versions [#1436](https://github.com/FreshRSS/FreshRSS/pull/1436) * Share with Ⓚnown [#1420](https://github.com/FreshRSS/FreshRSS/pull/1420) * Share with GNU social [#1422](https://github.com/FreshRSS/FreshRSS/issues/1422) +* CLI + * New command `./cli/reconfigure.php` to update an existing installation [#1439](https://github.com/FreshRSS/FreshRSS/pull/1439) * UI * Chrome parity with Firefox: auto-focus tab when clicking on notification [#1409](https://github.com/FreshRSS/FreshRSS/pull/1409) * Bug fixing diff --git a/cli/README.md b/cli/README.md index e4d3409a2..5662e2d83 100644 --- a/cli/README.md +++ b/cli/README.md @@ -39,6 +39,9 @@ cd /usr/share/FreshRSS # --db-prefix is an optional prefix in front of the names of the tables. We suggest using 'freshrss_' # This command does not create the default user. Do that with ./cli/create-user.php +./cli/reconfigure.php +# Same parameters as for do-install.php. Used to update an existing installation. + ./cli/create-user.php --user username ( --password 'password' --api-password 'api_password' --language en --email user@example.net --token 'longRandomString' --no-default-feeds ) # --language can be: 'en' (default), 'fr', or one of the [supported languages](../app/i18n/) -- cgit v1.2.3 From 271a1fdc8900a8b2c32675c22dce1cc458209de4 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 25 Feb 2017 12:39:08 +0100 Subject: Missing checkUsername and const patten https://github.com/FreshRSS/FreshRSS/pull/1423 https://github.com/YunoHost-Apps/freshrss_ynh/issues/27#issuecomment-279792363 --- app/Controllers/javascriptController.php | 2 +- app/Controllers/userController.php | 9 +++++++-- app/Models/Feed.php | 2 +- app/Models/UserDAO.php | 2 +- app/install.php | 2 +- app/views/auth/formLogin.phtml | 2 +- app/views/auth/register.phtml | 2 +- app/views/user/manage.phtml | 2 +- cli/reconfigure.php | 2 +- lib/lib_rss.php | 2 +- p/api/greader.php | 2 +- 11 files changed, 17 insertions(+), 12 deletions(-) (limited to 'cli') diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php index 00a7b5c38..6336106a9 100755 --- a/app/Controllers/javascriptController.php +++ b/app/Controllers/javascriptController.php @@ -26,7 +26,7 @@ class FreshRSS_javascript_Controller extends Minz_ActionController { header('Pragma: no-cache'); $user = isset($_GET['user']) ? $_GET['user'] : ''; - if (ctype_alnum($user)) { + if (FreshRSS_user_Controller::checkUsername($user)) { try { $salt = FreshRSS_Context::$system_conf->salt; $conf = get_user_configuration($user); diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index 718207734..13a6fce67 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -34,9 +34,14 @@ class FreshRSS_user_Controller extends Minz_ActionController { return $passwordHash == '' ? '' : $passwordHash; } + /** + * The username is also used as folder name, and part of SQL table name. + * '_' is a reserved internal username. + */ + const USERNAME_PATTERN = '[0-9a-zA-Z]|[0-9a-zA-Z_]{2,38}'; + public static function checkUsername($username) { - $match = '/^[0-9a-zA-Z_]{1,38}$/'; - return preg_match($match, $username) === 1; + return preg_match('/^' . self::USERNAME_PATTERN . '$/', $username) === 1; } /** diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 97cb1c47e..7a9cf8612 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -442,7 +442,7 @@ class FreshRSS_Feed extends Minz_Model { file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); } $currentUser = Minz_Session::param('currentUser'); - if (ctype_alnum($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) { + if (FreshRSS_user_Controller::checkUsername($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) { touch($path . '/' . $currentUser . '.txt'); } } diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php index 32bc6de2f..a60caf395 100644 --- a/app/Models/UserDAO.php +++ b/app/Models/UserDAO.php @@ -85,7 +85,7 @@ class FreshRSS_UserDAO extends Minz_ModelPdo { } public static function touch($username = '') { - if (($username == '') || (!ctype_alnum($username))) { + if (!FreshRSS_user_Controller::checkUsername($username)) { $username = Minz_Session::param('currentUser', '_'); } return touch(join_path(DATA_PATH , 'users', $username, 'config.php')); diff --git a/app/install.php b/app/install.php index 8c65a0977..58674e3a7 100644 --- a/app/install.php +++ b/app/install.php @@ -553,7 +553,7 @@ function printStep2() {
- +
diff --git a/app/views/auth/formLogin.phtml b/app/views/auth/formLogin.phtml index 24cb14c6e..2f881dde7 100644 --- a/app/views/auth/formLogin.phtml +++ b/app/views/auth/formLogin.phtml @@ -9,7 +9,7 @@
- +
diff --git a/app/views/auth/register.phtml b/app/views/auth/register.phtml index d7997f5f5..fce7e1388 100644 --- a/app/views/auth/register.phtml +++ b/app/views/auth/register.phtml @@ -5,7 +5,7 @@
- +
diff --git a/app/views/user/manage.phtml b/app/views/user/manage.phtml index 10bee5507..9238a01b9 100644 --- a/app/views/user/manage.phtml +++ b/app/views/user/manage.phtml @@ -22,7 +22,7 @@
- +
diff --git a/cli/reconfigure.php b/cli/reconfigure.php index 5294dd2df..da451b3ef 100755 --- a/cli/reconfigure.php +++ b/cli/reconfigure.php @@ -45,7 +45,7 @@ foreach ($dBparams as $dBparam) { } $config->db = $db; -if (!ctype_alnum($config->default_user)) { +if (!FreshRSS_user_Controller::checkUsername($config->default_user)) { fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $config->default_user); } diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 560e5b256..cdd08719d 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -285,7 +285,7 @@ function uSecString() { } function invalidateHttpCache($username = '') { - if (($username == '') || (!ctype_alnum($username))) { + if (!FreshRSS_user_Controller::checkUsername($username)) { Minz_Session::_param('touch', uTimeString()); $username = Minz_Session::param('currentUser', '_'); } diff --git a/p/api/greader.php b/p/api/greader.php index 4965ffd3b..01eca6d4f 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -152,7 +152,7 @@ function authorizationToUser() { $headerAuthX = explode('/', $headerAuth, 2); if (count($headerAuthX) === 2) { $user = $headerAuthX[0]; - if (ctype_alnum($user)) { + if (FreshRSS_user_Controller::checkUsername($user)) { FreshRSS_Context::$user_conf = get_user_configuration($user); if (FreshRSS_Context::$user_conf == null) { Minz_Log::warning('Invalid API user ' . $user . ': configuration cannot be found.'); -- cgit v1.2.3 From 17296f99d26ef3eb5a2e73428e3d67e418846ab7 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 28 Feb 2017 21:12:47 +0100 Subject: Fix CLI install bug with SQLite And improve requirements check https://github.com/FreshRSS/FreshRSS/issues/1443 --- cli/do-install.php | 41 ++++++++++++++++++++++------------------- lib/lib_install.php | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 23 deletions(-) (limited to 'cli') diff --git a/cli/do-install.php b/cli/do-install.php index c2f5b286d..16d03daaf 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -37,25 +37,6 @@ if (empty($options['default_user'])) { fwrite(STDERR, 'FreshRSS install…' . "\n"); -$requirements = checkRequirements(); -if ($requirements['all'] !== 'ok') { - $message = 'FreshRSS install failed requirements:' . "\n"; - foreach ($requirements as $requirement => $check) { - if ($check !== 'ok' && $requirement !== 'all') { - $message .= '• ' . $requirement . "\n"; - } - } - fail($message); -} - -if (!FreshRSS_user_Controller::checkUsername($options['default_user'])) { - fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $options['default_user']); -} - -if (isset($options['auth_type']) && !in_array($options['auth_type'], array('form', 'http_auth', 'none'))) { - fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }: ' . $options['auth_type']); -} - $config = array( 'salt' => generateSalt(), 'db' => FreshRSS_Context::$system_conf->db, @@ -80,6 +61,28 @@ foreach ($dBparams as $dBparam) { } } +$requirements = checkRequirements($config['db']['type']); +if ($requirements['all'] !== 'ok') { + $message = 'FreshRSS install failed requirements:' . "\n"; + foreach ($requirements as $requirement => $check) { + if ($check !== 'ok' && !in_array($requirement, array('all', 'pdo', 'message'))) { + $message .= '• ' . $requirement . "\n"; + } + } + if (!empty($requirements['message'])) { + $message .= '• ' . $requirements['message'] . "\n"; + } + fail($message); +} + +if (!FreshRSS_user_Controller::checkUsername($options['default_user'])) { + fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $options['default_user']); +} + +if (isset($options['auth_type']) && !in_array($options['auth_type'], array('form', 'http_auth', 'none'))) { + fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }: ' . $options['auth_type']); +} + if (file_put_contents(join_path(DATA_PATH, 'config.php'), "= 0; $minz = file_exists(join_path(LIB_PATH, 'Minz')); $curl = extension_loaded('curl'); $pdo_mysql = extension_loaded('pdo_mysql'); $pdo_sqlite = extension_loaded('pdo_sqlite'); $pdo_pgsql = extension_loaded('pdo_pgsql'); - $pdo = $pdo_mysql || $pdo_sqlite || $pdo_pgsql; + $message = ''; + switch ($dbType) { + case 'mysql': + $pdo_sqlite = $pdo_pgsql = true; + $pdo = $pdo_mysql; + break; + case 'sqlite': + $pdo_mysql = $pdo_pgsql = true; + $pdo = $pdo_sqlite; + break; + case 'pgsql': + $pdo_mysql = $pdo_sqlite = true; + $pdo = $pdo_pgsql; + break; + case '': + $pdo = $pdo_mysql || $pdo_sqlite || $pdo_pgsql; + break; + default: + $pdo_mysql = $pdo_sqlite = $pdo_pgsql = true; + $pdo = false; + $message = 'Invalid database type!'; + break; + } $pcre = extension_loaded('pcre'); $ctype = extension_loaded('ctype'); $fileinfo = extension_loaded('fileinfo'); @@ -44,8 +66,9 @@ function checkRequirements() { 'users' => $users ? 'ok' : 'ko', 'favicons' => $favicons ? 'ok' : 'ko', 'http_referer' => $http_referer ? 'ok' : 'ko', + 'message' => $message ?: 'ok', 'all' => $php && $minz && $curl && $pdo && $pcre && $ctype && $fileinfo && $dom && $xml && - $data && $cache && $users && $favicons && $http_referer ? + $data && $cache && $users && $favicons && $http_referer && $message == '' ? 'ok' : 'ko' ); } @@ -77,7 +100,11 @@ function checkDb(&$dbOptions) { break; case 'sqlite': include_once(APP_PATH . '/SQL/install.sql.sqlite.php'); - $dsn = 'sqlite:' . join_path(USERS_PATH, $dbOptions['default_user'], 'db.sqlite'); + $path = join_path(USERS_PATH, $dbOptions['default_user']); + if (!is_dir($path)) { + mkdir($path); + } + $dsn = 'sqlite:' . join_path($path, 'db.sqlite'); $driver_options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ); -- cgit v1.2.3 From 992a811df66de7be66c64d3703e854c15a58d337 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 2 Mar 2017 23:04:38 +0100 Subject: CLI add language to install https://github.com/FreshRSS/FreshRSS/issues/1445 --- cli/do-install.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/do-install.php b/cli/do-install.php index 16d03daaf..4cd7597fe 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -6,6 +6,7 @@ require(LIB_PATH . '/lib_install.php'); $params = array( 'environment:', 'base_url:', + 'language:', 'title:', 'default_user:', 'allow_anonymous', @@ -30,7 +31,7 @@ $options = getopt('', array_merge($params, $dBparams)); if (empty($options['default_user'])) { fail('Usage: ' . basename(__FILE__) . " --default_user admin ( --auth_type form" . " --environment production --base_url https://rss.example.net/" . - " --title FreshRSS --allow_anonymous --api_enabled" . + " --language en --title FreshRSS --allow_anonymous --api_enabled" . " --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123" . " --db-base freshrss --db-prefix freshrss_ --disable_update )"); } -- cgit v1.2.3 From ae1bf1f56fcfa920db3d5092cb18dced4cbcb434 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 3 Mar 2017 11:47:04 +0100 Subject: CLI do no list un-created user admin https://github.com/FreshRSS/FreshRSS/issues/1448 --- cli/list-users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/list-users.php b/cli/list-users.php index e690ff451..610a9dd7b 100755 --- a/cli/list-users.php +++ b/cli/list-users.php @@ -4,7 +4,7 @@ require('_cli.php'); $users = listUsers(); sort($users); -if (FreshRSS_Context::$system_conf->default_user !== '') { +if (FreshRSS_Context::$system_conf->default_user !== '' && in_array(FreshRSS_Context::$system_conf->default_user, $users, true)) { array_unshift($users, FreshRSS_Context::$system_conf->default_user); $users = array_unique($users); } -- cgit v1.2.3 From c544f510d26377684aefe8a27b484ee22bbd4f69 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 3 Mar 2017 11:55:58 +0100 Subject: CLI: install language https://github.com/FreshRSS/FreshRSS/issues/1445#issuecomment-283908468 --- cli/README.md | 3 ++- cli/reconfigure.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/README.md b/cli/README.md index 5662e2d83..cbab699dc 100644 --- a/cli/README.md +++ b/cli/README.md @@ -32,10 +32,11 @@ Options in parenthesis are optional. ```sh cd /usr/share/FreshRSS -./cli/do-install.php --default_user admin ( --auth_type form --environment production --base_url https://rss.example.net/ --title FreshRSS --allow_anonymous --api_enabled --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123 --db-base freshrss --db-prefix freshrss ) +./cli/do-install.php --default_user admin ( --auth_type form --environment production --base_url https://rss.example.net/ --language en --title FreshRSS --allow_anonymous --api_enabled --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123 --db-base freshrss --db-prefix freshrss ) # --auth_type can be: 'form' (default), 'http_auth' (using the Web server access control), 'none' (dangerous) # --db-type can be: 'sqlite' (default), 'mysql' (MySQL or MariaDB), 'pgsql' (PostgreSQL) # --environment can be: 'production' (default), 'development' (for additional log messages) +# --language can be: 'en' (default), 'fr', or one of the [supported languages](../app/i18n/) # --db-prefix is an optional prefix in front of the names of the tables. We suggest using 'freshrss_' # This command does not create the default user. Do that with ./cli/create-user.php diff --git a/cli/reconfigure.php b/cli/reconfigure.php index da451b3ef..c6902da67 100755 --- a/cli/reconfigure.php +++ b/cli/reconfigure.php @@ -5,6 +5,7 @@ require('_cli.php'); $params = array( 'environment:', 'base_url:', + 'language:', 'title:', 'default_user:', 'allow_anonymous', -- cgit v1.2.3 From ada94465e62d5809303afffc636fdae87aff2738 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 3 Mar 2017 23:01:33 +0100 Subject: CLI: More infos in user-info https://github.com/FreshRSS/FreshRSS/issues/1449#issuecomment-283927614 --- cli/README.md | 3 ++- cli/user-info.php | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'cli') diff --git a/cli/README.md b/cli/README.md index cbab699dc..5434d1964 100644 --- a/cli/README.md +++ b/cli/README.md @@ -63,7 +63,8 @@ cd /usr/share/FreshRSS ./cli/user-info.php -h --user username # -h is to use a human-readable format # --user can be a username, or '*' to loop on all users -# Returns a * if the user is admin, the name of the user, the date/time of last action, and the size occupied +# Returns a * if the user is admin, the name of the user, the date/time of last action, the size occupied, +# and the number of: feeds, read articles, unread articles, and favourites ``` diff --git a/cli/user-info.php b/cli/user-info.php index dd38e6c7f..aa3e239b8 100755 --- a/cli/user-info.php +++ b/cli/user-info.php @@ -14,22 +14,36 @@ $users = $options['user'] === '*' ? listUsers() : array($options['user']); foreach ($users as $username) { $username = cliInitUser($username); + echo $username === FreshRSS_Context::$system_conf->default_user ? '*' : ' ', "\t"; + $catDAO = new FreshRSS_CategoryDAO(); + $feedDAO = FreshRSS_Factory::createFeedDao($username); $entryDAO = FreshRSS_Factory::createEntryDao($username); - echo $username === FreshRSS_Context::$system_conf->default_user ? '*' : ' ', "\t"; + $nbEntries = $entryDAO->countUnreadRead(); + $nbFavorites = $entryDAO->countUnreadReadFavorites(); if (isset($options['h'])) { //Human format echo $username, "\t", date('c', FreshRSS_UserDAO::mtime($username)), "\t", format_bytes($entryDAO->size()), "\t", + $catDAO->count(), " categories\t", + count($feedDAO->listFeedsIds()), " feeds\t", + $nbEntries['read'], " reads\t", + $nbEntries['unread'], " unreads\t", + $nbFavorites['all'], " favourites\t", "\n"; } else { echo $username, "\t", FreshRSS_UserDAO::mtime($username), "\t", $entryDAO->size(), "\t", + $catDAO->count(), "\t", + count($feedDAO->listFeedsIds()), "\t", + $nbEntries['read'], "\t", + $nbEntries['unread'], "\t", + $nbFavorites['all'], "\t", "\n"; } } -- cgit v1.2.3 From 37957d45b24306f494554ee1e6c911998ca68643 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 3 Mar 2017 23:15:50 +0100 Subject: Allows do-install.php only if data/do-install.txt exists https://github.com/FreshRSS/FreshRSS/issues/1449 --- cli/do-install.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cli') diff --git a/cli/do-install.php b/cli/do-install.php index 4cd7597fe..143ca5c3e 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -3,6 +3,10 @@ require('_cli.php'); require(LIB_PATH . '/lib_install.php'); +if (!file_exists(DATA_PATH . '/do-install.txt')) { + fail('FreshRSS looks to be already installed! Please use `./cli/reconfigure.php` instead.'); +} + $params = array( 'environment:', 'base_url:', -- cgit v1.2.3 From f6148e1f32548f98401de3676e07d3be5e7c5331 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 5 Mar 2017 00:23:23 +0100 Subject: CLI user-info readme https://github.com/FreshRSS/FreshRSS/issues/1449#issuecomment-284191560 https://github.com/FreshRSS/FreshRSS/issues/1447 --- cli/README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'cli') diff --git a/cli/README.md b/cli/README.md index 5434d1964..0123e8d6e 100644 --- a/cli/README.md +++ b/cli/README.md @@ -63,15 +63,15 @@ cd /usr/share/FreshRSS ./cli/user-info.php -h --user username # -h is to use a human-readable format # --user can be a username, or '*' to loop on all users -# Returns a * if the user is admin, the name of the user, the date/time of last action, the size occupied, -# and the number of: feeds, read articles, unread articles, and favourites +# Returns: 1) a * iff the user is admin, 2) the name of the user, +# 3) the date/time of last user action, 4) the size occupied, +# and the number of: 5) categories, 6) feeds, 7) read articles, 8) unread articles, and 9) favourites ``` ## Unix piping It is possible to invoke a command multiple times, e.g. with different usernames, thanks to the `xargs -n1` command. - Example showing user information for all users which username starts with 'a': ```sh @@ -83,3 +83,9 @@ Example showing all users ranked by date of last activity: ```sh ./cli/user-info.php -h --user '*' | sort -k2 -r ``` + +Example to get the number of feeds of a given user: + +```sh +./cli/user-info.php --user alex | cut -f6 +``` -- cgit v1.2.3