summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-10-29 00:45:42 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-10-29 00:45:42 +0100
commit9f97f7df8822ed2f32a9bc9d46ece92dee93089c (patch)
treea807ad69acd8e0db815eace379863b562a113c69
parent00127f07c5fc784130d658e3f26519b0279fc6b8 (diff)
Ne pas rafraîchir les flux des utilisateurs non logués depuis x jours
https://github.com/marienfressinaud/FreshRSS/issues/681 Warning: needs some testing
-rw-r--r--CHANGELOG2
-rw-r--r--app/Controllers/userController.php3
-rw-r--r--app/Models/Auth.php13
-rw-r--r--app/Models/UserDAO.php10
-rwxr-xr-xapp/actualize_script.php10
-rw-r--r--lib/Minz/Configuration.php7
6 files changed, 33 insertions, 12 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 688a286e3..a556fcc13 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,7 +3,7 @@
##
* Configuration
- * New options in config.php for cache duration, timeout, max number of feeds and categories per user.
+ * New options in config.php for cache duration, timeout, max inactivity, max number of feeds and categories per user.
## 2014-09-26 FreshRSS 0.8.0 / 0.9.0 (beta)
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php
index 2343520ca..39db1d879 100644
--- a/app/Controllers/userController.php
+++ b/app/Controllers/userController.php
@@ -95,9 +95,8 @@ class FreshRSS_user_Controller extends Minz_ActionController {
Minz_View::prependTitle(_t('gen.title.user_management') . ' · ');
// Get the correct current user.
- $userDAO = new FreshRSS_UserDAO();
$username = Minz_Request::param('u', Minz_Session::param('currentUser'));
- if (!$userDAO->exist($username)) {
+ if (!FreshRSS_UserDAO::exist($username)) {
$username = Minz_Session::param('currentUser');
}
$this->view->current_user = $username;
diff --git a/app/Models/Auth.php b/app/Models/Auth.php
index cc23d7974..2971d65c8 100644
--- a/app/Models/Auth.php
+++ b/app/Models/Auth.php
@@ -20,10 +20,11 @@ class FreshRSS_Auth {
Minz_Session::_param('currentUser', $current_user);
}
- $access_ok = self::accessControl();
-
- if ($access_ok) {
+ if (self::$login_ok) {
self::giveAccess();
+ } elseif (self::accessControl()) {
+ self::giveAccess();
+ FreshRSS_UserDAO::touch($current_user);
} else {
// Be sure all accesses are removed!
self::removeAccess();
@@ -38,11 +39,7 @@ class FreshRSS_Auth {
*
* @return boolean true if user can be connected, false else.
*/
- public static function accessControl() {
- if (self::$login_ok) {
- return true;
- }
-
+ private static function accessControl() {
switch (Minz_Configuration::authType()) {
case 'form':
$credentials = FreshRSS_FormAuth::getCredentialsFromCookie();
diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php
index 85b45c4a7..60fca71b1 100644
--- a/app/Models/UserDAO.php
+++ b/app/Models/UserDAO.php
@@ -54,7 +54,15 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {
}
}
- public function exist($username) {
+ public static function exist($username) {
return file_exists(DATA_PATH . '/' . $username . '_user.php');
}
+
+ public static function touch($username) {
+ return touch(DATA_PATH . '/' . $username . '_user.php');
+ }
+
+ public static function mtime($username) {
+ return @filemtime(DATA_PATH . '/' . $username . '_user.php');
+ }
}
diff --git a/app/actualize_script.php b/app/actualize_script.php
index 9fe499cc9..6ce4178cd 100755
--- a/app/actualize_script.php
+++ b/app/actualize_script.php
@@ -22,7 +22,17 @@ if (Minz_Configuration::defaultUser() !== ''){
$users = array_unique($users);
}
+$limits = Minz_Configuration::limits();
+$minLastActivity = time() - $limits['max_inactivity'];
+
foreach ($users as $myUser) {
+ if (($myUser !== Minz_Configuration::defaultUser()) && (FreshRSS_UserDAO::mtime($myUser) < $minLastActivity)) {
+ syslog(LOG_INFO, 'FreshRSS skip inactive user ' . $myUser);
+ if (defined('STDOUT')) {
+ fwrite(STDOUT, 'FreshRSS skip inactive user ' . $myUser . "\n"); //Unbuffered
+ }
+ continue;
+ }
syslog(LOG_INFO, 'FreshRSS actualize ' . $myUser);
if (defined('STDOUT')) {
fwrite(STDOUT, 'Actualize ' . $myUser . "...\n"); //Unbuffered
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 9511cb357..6cbc9fc0b 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -64,6 +64,7 @@ class Minz_Configuration {
private static $limits = array(
'cache_duration' => 800, //SimplePie cache duration in seconds
'timeout' => 10, //SimplePie timeout in seconds
+ 'max_inactivity' => PHP_INT_MAX, //Time in seconds after which a user who has not used the account is considered inactive (no auto-refresh of feeds).
'max_feeds' => Minz_Configuration::MAX_SMALL_INT,
'max_categories' => Minz_Configuration::MAX_SMALL_INT,
);
@@ -317,6 +318,12 @@ class Minz_Configuration {
self::$limits['timeout'] = $v;
}
}
+ if (isset($limits['max_inactivity'])) {
+ $v = intval($limits['max_inactivity']);
+ if ($v > 0) {
+ self::$limits['max_inactivity'] = $v;
+ }
+ }
if (isset($limits['max_feeds'])) {
$v = intval($limits['max_feeds']);
if ($v > 0 && $v < Minz_Configuration::MAX_SMALL_INT) {