aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/README.md3
-rw-r--r--cli/_cli.php2
-rwxr-xr-xcli/create-user.php2
-rwxr-xr-xcli/delete-user.php2
-rwxr-xr-xcli/do-install.php46
-rwxr-xr-xcli/reconfigure.php58
6 files changed, 89 insertions, 24 deletions
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/)
diff --git a/cli/_cli.php b/cli/_cli.php
index 7d1a7c6b2..f5e36eabc 100644
--- a/cli/_cli.php
+++ b/cli/_cli.php
@@ -20,7 +20,7 @@ function fail($message) {
}
function cliInitUser($username) {
- if (!ctype_alnum($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 444264cc7..c9e350c14 100755
--- a/cli/create-user.php
+++ b/cli/create-user.php
@@ -17,7 +17,7 @@ if (empty($options['user'])) {
" --language en --email user@example.net --token 'longRandomString --no-default-feeds' )");
}
$username = $options['user'];
-if (!ctype_alnum($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 6f0e86e17..baa81b893 100755
--- a/cli/delete-user.php
+++ b/cli/delete-user.php
@@ -10,7 +10,7 @@ if (empty($options['user'])) {
fail('Usage: ' . basename(__FILE__) . " --user username");
}
$username = $options['user'];
-if (!ctype_alnum($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 100d4947f..16d03daaf 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,30 +32,11 @@ 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");
-$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 (!ctype_alnum($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,
@@ -73,12 +55,34 @@ 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];
}
}
+$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'), "<?php\n return " . var_export($config, true) . ";\n") === false) {
fail('FreshRSS could not write configuration file!: ' . join_path(DATA_PATH, 'config.php'));
}
diff --git a/cli/reconfigure.php b/cli/reconfigure.php
new file mode 100755
index 000000000..da451b3ef
--- /dev/null
+++ b/cli/reconfigure.php
@@ -0,0 +1,58 @@
+#!/usr/bin/php
+<?php
+require('_cli.php');
+
+$params = array(
+ 'environment:',
+ 'base_url:',
+ 'title:',
+ 'default_user:',
+ 'allow_anonymous',
+ 'allow_anonymous_refresh',
+ 'auth_type:',
+ 'api_enabled',
+ 'allow_robots',
+ 'disable_update',
+ );
+
+$dBparams = array(
+ 'db-type:',
+ 'db-host:',
+ 'db-user:',
+ 'db-password:',
+ 'db-base:',
+ 'db-prefix:',
+ );
+
+$options = getopt('', array_merge($params, $dBparams));
+
+fwrite(STDERR, 'Reconfiguring FreshRSS…' . "\n");
+
+$config = Minz_Configuration::get('system');
+foreach ($params as $param) {
+ $param = rtrim($param, ':');
+ if (isset($options[$param])) {
+ $config->$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 (!FreshRSS_user_Controller::checkUsername($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();