diff --git a/conf/init.patch b/conf/init.patch new file mode 100644 index 0000000..2ae898d --- /dev/null +++ b/conf/init.patch @@ -0,0 +1,21 @@ +*** init.php 2015-01-22 17:56:31.641845090 +0100 +--- init.php.1 2015-02-20 09:23:16.515269911 +0100 +*************** +*** 69,74 **** +--- 69,84 ---- + db_query("UPDATE ttrss_users SET email = '$email' WHERE id = " . + $user_id); + } ++ // update user password to allow api access ++ if (isset($_SERVER['PHP_AUTH_PW'])){ ++ $currentpassword = $_SERVER['PHP_AUTH_PW']; ++ $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); ++ $new_password_hash = encrypt_password($currentpassword, $new_salt, true); ++ ++ db_query("UPDATE ttrss_users SET ++ pwd_hash = '$new_password_hash', salt = '$new_salt', otp_enabled = false ++ WHERE login = '$try_login'"); ++ } + } + + return $user_id; diff --git a/conf/update.patch b/conf/update.patch new file mode 100644 index 0000000..863766f --- /dev/null +++ b/conf/update.patch @@ -0,0 +1,21 @@ +*** update.php 2015-02-20 09:41:40.231462387 +0100 +--- update.php.1 2015-02-20 09:42:07.911466665 +0100 +*************** +*** 311,318 **** + _debug("WARNING: please backup your database before continuing."); + _debug("Type 'yes' to continue."); + +! if (read_stdin() != 'yes') +! exit; + + for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { + _debug("performing update up to version $i..."); +--- 311,318 ---- + _debug("WARNING: please backup your database before continuing."); + _debug("Type 'yes' to continue."); + +! //if (read_stdin() != 'yes') +! // exit; + + for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { + _debug("performing update up to version $i..."); diff --git a/scripts/install b/scripts/install index 7f15244..8b40724 100644 --- a/scripts/install +++ b/scripts/install @@ -27,7 +27,8 @@ sudo mkdir -p $final_path sudo cp -r ../source/* $final_path sudo cp ../conf/config.php $final_path/ sudo cp ../conf/ttrss.diff /tmp/ -sudo patch -d $final_path -p0 < /tmp/ttrss.diff +sudo patch -d $final_path -p0 < /tmp/update.patch +sudo patch -d $final_path/plugins/auth_remote/ -p0 < /tmp/init.patch # Change variables in ttrss configuration diff --git a/scripts/upgrade b/scripts/upgrade index fe7e276..93e1f85 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,8 +12,8 @@ sudo mkdir -p $final_path sudo cp -a ../source/* $final_path sudo cp ../conf/config.php $final_path/ sudo cp ../conf/ttrss.diff /tmp/ -sudo patch -d $final_path -p0 < /tmp/ttrss.diff - +sudo patch -d $final_path -p0 < /tmp/update.patch +sudo patch -d $final_path/plugins/auth_remote/ -p0 < /tmp/init.patch # Change variables in ttrss configuration sudo sed -i "s/yunouser/$db_user/g" $final_path/config.php diff --git a/source/plugins/auth_remote/init.php.ynh b/source/plugins/auth_remote/init.php.ynh deleted file mode 100644 index 626eebc..0000000 --- a/source/plugins/auth_remote/init.php.ynh +++ /dev/null @@ -1,97 +0,0 @@ -host = $host; - $this->base = new Auth_Base(); - - $host->add_hook($host::HOOK_AUTH_USER, $this); - } - - function get_login_by_ssl_certificate() { - $cert_serial = db_escape_string(get_ssl_certificate_id()); - - if ($cert_serial) { - $result = db_query("SELECT login FROM ttrss_user_prefs, ttrss_users - WHERE pref_name = 'SSL_CERT_SERIAL' AND value = '$cert_serial' AND - owner_uid = ttrss_users.id"); - - if (db_num_rows($result) != 0) { - return db_escape_string(db_fetch_result($result, 0, "login")); - } - } - - return ""; - } - - - function authenticate($login, $password) { - $try_login = db_escape_string($_SERVER["REMOTE_USER"]); - - // php-cgi - if (!$try_login) $try_login = db_escape_string($_SERVER["REDIRECT_REMOTE_USER"]); - - if (!$try_login) $try_login = $this->get_login_by_ssl_certificate(); -# if (!$try_login) $try_login = "test_qqq"; - - if ($try_login) { - $user_id = $this->base->auto_create_user($try_login, $password); - - if ($user_id) { - $_SESSION["fake_login"] = $try_login; - $_SESSION["fake_password"] = "******"; - $_SESSION["hide_hello"] = true; - $_SESSION["hide_logout"] = true; - - // LemonLDAP can send user informations via HTTP HEADER - if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE){ - // update user name - $fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN']; - if ($fullname){ - $fullname = db_escape_string($fullname); - db_query("UPDATE ttrss_users SET full_name = '$fullname' WHERE id = " . - $user_id); - } - // update user mail - $email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL']; - if ($email){ - $email = db_escape_string($email); - db_query("UPDATE ttrss_users SET email = '$email' WHERE id = " . - $user_id); - } - // update user password to allow api access - if (isset($_SERVER['PHP_AUTH_PW'])){ - $currentpassword = $_SERVER['PHP_AUTH_PW']; - $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); - $new_password_hash = encrypt_password($currentpassword, $new_salt, true); - - db_query("UPDATE ttrss_users SET - pwd_hash = '$new_password_hash', salt = '$new_salt', otp_enabled = false - WHERE login = '$try_login'"); - } - } - - return $user_id; - } - } - - return false; - } - - function api_version() { - return 2; - } - -} - -?> diff --git a/source/update.php b/source/update.php index 4254ff0..521b956 100755 --- a/source/update.php +++ b/source/update.php @@ -311,8 +311,8 @@ _debug("WARNING: please backup your database before continuing."); _debug("Type 'yes' to continue."); - //if (read_stdin() != 'yes') - // exit; + if (read_stdin() != 'yes') + exit; for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { _debug("performing update up to version $i..."); diff --git a/source/update.php.ynh b/source/update.php.ynh deleted file mode 100755 index 4254ff0..0000000 --- a/source/update.php.ynh +++ /dev/null @@ -1,359 +0,0 @@ -#!/usr/bin/env php -get_commands() as $command => $data) { - array_push($longopts, $command . $data["suffix"]); - } - - $options = getopt("", $longopts); - - if (!is_array($options)) { - die("error: getopt() failed. ". - "Most probably you are using PHP CGI to run this script ". - "instead of required PHP CLI. Check tt-rss wiki page on updating feeds for ". - "additional information.\n"); - } - - if (count($options) == 0 && !defined('STDIN')) { - ?> - - Tiny Tiny RSS data update script. - - - - - - -

- - - - - get_commands() as $command => $data) { - $args = $data['arghelp']; - printf(" --%-19s - %s\n", "$command $args", $data["description"]); - } - - return; - } - - if (!isset($options['daemon'])) { - require_once "errorhandler.php"; - } - - if (!isset($options['update-schema'])) { - $schema_version = get_schema_version(); - - if ($schema_version != SCHEMA_VERSION) { - die("Schema version is wrong, please upgrade the database.\n"); - } - } - - define('QUIET', isset($options['quiet'])); - - if (isset($options["log"])) { - _debug("Logging to " . $options["log"]); - define('LOGFILE', $options["log"]); - } - - if (!isset($options["daemon"])) { - $lock_filename = "update.lock"; - } else { - $lock_filename = "update_daemon.lock"; - } - - if (isset($options["task"])) { - _debug("Using task id " . $options["task"]); - $lock_filename = $lock_filename . "-task_" . $options["task"]; - } - - if (isset($options["pidlock"])) { - $my_pid = $options["pidlock"]; - $lock_filename = "update_daemon-$my_pid.lock"; - - } - - _debug("Lock: $lock_filename"); - - $lock_handle = make_lockfile($lock_filename); - $must_exit = false; - - if (isset($options["task"]) && isset($options["pidlock"])) { - $waits = $options["task"] * 5; - _debug("Waiting before update ($waits)"); - sleep($waits); - } - - // Try to lock a file in order to avoid concurrent update. - if (!$lock_handle) { - die("error: Can't create lockfile ($lock_filename). ". - "Maybe another update process is already running.\n"); - } - - if (isset($options["force-update"])) { - _debug("marking all feeds as needing update..."); - - db_query( "UPDATE ttrss_feeds SET last_update_started = '1970-01-01', - last_updated = '1970-01-01'"); - } - - if (isset($options["feeds"])) { - update_daemon_common(); - housekeeping_common(true); - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op); - } - - if (isset($options["feedbrowser"])) { - $count = update_feedbrowser_cache(); - print "Finished, $count feeds processed.\n"; - } - - if (isset($options["daemon"])) { - while (true) { - $quiet = (isset($options["quiet"])) ? "--quiet" : ""; - $log = isset($options['log']) ? '--log '.$options['log'] : ''; - - passthru(PHP_EXECUTABLE . " " . $argv[0] ." --daemon-loop $quiet $log"); - _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); - sleep(DAEMON_SLEEP_INTERVAL); - } - } - - if (isset($options["daemon-loop"])) { - if (!make_stampfile('update_daemon.stamp')) { - _debug("warning: unable to create stampfile\n"); - } - - update_daemon_common(isset($options["pidlock"]) ? 50 : DAEMON_FEED_LIMIT); - - if (!isset($options["pidlock"]) || $options["task"] == 0) - housekeeping_common(true); - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op); - } - - if (isset($options["cleanup-tags"])) { - $rc = cleanup_tags( 14, 50000); - _debug("$rc tags deleted.\n"); - } - - if (isset($options["indexes"])) { - _debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!"); - _debug("Type 'yes' to continue."); - - if (read_stdin() != 'yes') - exit; - - _debug("clearing existing indexes..."); - - if (DB_TYPE == "pgsql") { - $result = db_query( "SELECT relname FROM - pg_catalog.pg_class WHERE relname LIKE 'ttrss_%' - AND relname NOT LIKE '%_pkey' - AND relkind = 'i'"); - } else { - $result = db_query( "SELECT index_name,table_name FROM - information_schema.statistics WHERE index_name LIKE 'ttrss_%'"); - } - - while ($line = db_fetch_assoc($result)) { - if (DB_TYPE == "pgsql") { - $statement = "DROP INDEX " . $line["relname"]; - _debug($statement); - } else { - $statement = "ALTER TABLE ". - $line['table_name']." DROP INDEX ".$line['index_name']; - _debug($statement); - } - db_query( $statement, false); - } - - _debug("reading indexes from schema for: " . DB_TYPE); - - $fp = fopen("schema/ttrss_schema_" . DB_TYPE . ".sql", "r"); - if ($fp) { - while ($line = fgets($fp)) { - $matches = array(); - - if (preg_match("/^create index ([^ ]+) on ([^ ]+)$/i", $line, $matches)) { - $index = $matches[1]; - $table = $matches[2]; - - $statement = "CREATE INDEX $index ON $table"; - - _debug($statement); - db_query( $statement); - } - } - fclose($fp); - } else { - _debug("unable to open schema file."); - } - _debug("all done."); - } - - if (isset($options["convert-filters"])) { - _debug("WARNING: this will remove all existing type2 filters."); - _debug("Type 'yes' to continue."); - - if (read_stdin() != 'yes') - exit; - - _debug("converting filters..."); - - db_query( "DELETE FROM ttrss_filters2"); - - $result = db_query( "SELECT * FROM ttrss_filters ORDER BY id"); - - while ($line = db_fetch_assoc($result)) { - $owner_uid = $line["owner_uid"]; - - // date filters are removed - if ($line["filter_type"] != 5) { - $filter = array(); - - if (sql_bool_to_bool($line["cat_filter"])) { - $feed_id = "CAT:" . (int)$line["cat_id"]; - } else { - $feed_id = (int)$line["feed_id"]; - } - - $filter["enabled"] = $line["enabled"] ? "on" : "off"; - $filter["rule"] = array( - json_encode(array( - "reg_exp" => $line["reg_exp"], - "feed_id" => $feed_id, - "filter_type" => $line["filter_type"]))); - - $filter["action"] = array( - json_encode(array( - "action_id" => $line["action_id"], - "action_param_label" => $line["action_param"], - "action_param" => $line["action_param"]))); - - // Oh god it's full of hacks - - $_REQUEST = $filter; - $_SESSION["uid"] = $owner_uid; - - $filters = new Pref_Filters($_REQUEST); - $filters->add(); - } - } - - } - - if (isset($options["update-schema"])) { - _debug("checking for updates (" . DB_TYPE . ")..."); - - $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION); - - if ($updater->isUpdateRequired()) { - _debug("schema update required, version " . $updater->getSchemaVersion() . " to " . SCHEMA_VERSION); - _debug("WARNING: please backup your database before continuing."); - _debug("Type 'yes' to continue."); - - //if (read_stdin() != 'yes') - // exit; - - for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { - _debug("performing update up to version $i..."); - - $result = $updater->performUpdateTo($i); - - _debug($result ? "OK!" : "FAILED!"); - - if (!$result) return; - - } - } else { - _debug("update not required."); - } - - } - - if (isset($options["list-plugins"])) { - $tmppluginhost = new PluginHost(); - $tmppluginhost->load_all($tmppluginhost::KIND_ALL); - $enabled = array_map("trim", explode(",", PLUGINS)); - - echo "List of all available plugins:\n"; - - foreach ($tmppluginhost->get_plugins() as $name => $plugin) { - $about = $plugin->about(); - - $status = $about[3] ? "system" : "user"; - - if (in_array($name, $enabled)) $name .= "*"; - - printf("%-50s %-10s v%.2f (by %s)\n%s\n\n", - $name, $status, $about[0], $about[2], $about[1]); - } - - echo "Plugins marked by * are currently enabled for all users.\n"; - - } - - PluginHost::getInstance()->run_commands($options); - - if (file_exists(LOCK_DIRECTORY . "/$lock_filename")) - unlink(LOCK_DIRECTORY . "/$lock_filename"); -?>