From 3c746d86369feedc456d8c448126b8ff3b177373 Mon Sep 17 00:00:00 2001 From: b Date: Tue, 5 Jan 2016 19:54:11 +0000 Subject: [PATCH] script for removing old access files. git-svn-id: svn://botcastle1b/yplom/facebug1@14 7dec801f-c475-4e67-ba99-809552d69c55 --- configure.pl | 2 +- interface.1.pl | 4 ++-- makefile.1.mak | 11 +++++++---- rmaccess.1.pl | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ settings | 4 ++-- 5 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 rmaccess.1.pl diff --git a/configure.pl b/configure.pl index 258e3b6..bf642c2 100644 --- a/configure.pl +++ b/configure.pl @@ -93,7 +93,7 @@ $def{'CGI_ALIAS'} = 'ScriptAlias '.$set{'interface_path'}.'/view '.$set{'bin_pa $def{'PATH_ALIAS'} = 'Alias '.$set{'interface_path'}.' '.$wwwpath; $def{'BOT_CRONTAB'} = $set{'bot_crontab'}.' '.$set{'bin_path'}.'bot'.(($set{'bot_args'} ne '')?(' '.$set{'bot_args'}):'').' >'.$set{'log_path'}.'bot.log'; -$def{'RM_ACCESS_CRONTAB'} = $set{'rm_access_crontab'}.' '.$set{'rm'}.' '.$set{'data_path'}.'access/*'; +$def{'RM_ACCESS_CRONTAB'} = $set{'rm_access_crontab'}.' '.$set{'bin_path'}.'rmaccess'; $def{'OLDLOGS_CRONTAB'} = $set{'oldlogs_crontab'}.' '.$set{'proxy_bin_path'}.'oldlogs '.$set{'log_path'}.' '.$set{'log_size_limit'}.' '.$set{'logs_total'}.' '.$set{'logs_uncompressed'}; $def{'CC'} = 'CC='.$set{'gcc'}; diff --git a/interface.1.pl b/interface.1.pl index 8a6a7bd..31cb963 100644 --- a/interface.1.pl +++ b/interface.1.pl @@ -1,7 +1,7 @@ ###PERL; # interface.pl is generated from interface.1.pl -# 02.01.2015 +# 05.01.2015 # # This is the software of the facebook interface, to access archived groups, # threads, images, etc. @@ -993,7 +993,7 @@ sub login { } # if password confirmed create the key and the access file - $key=key(KEY_BITS); + $key=$time.'f'.key(KEY_BITS); $accesspath=ACCESS_PATH.$key; open ($accessfile,">",$accesspath) or return loginpage("Couldn't create temporary file $accesspath.","Status: 500 Internal Server Error\n"); diff --git a/makefile.1.mak b/makefile.1.mak index 9472bf7..33ffcc4 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -14,8 +14,8 @@ all: moveout moveoutlib copyoutwww remove config.txt -moveout: bot interface interface.pl setuid exec - $(MV) bot interface interface.pl $(OD) +moveout: bot interface interface.pl rmaccess setuid exec + $(MV) bot interface interface.pl rmaccess $(OD) moveoutlib: facebug_lib.pm setuid exec $(MV) facebug_lib.pm $(LD) @@ -26,8 +26,8 @@ copyoutwww: if.css setuid exec setuid: interface $(CM) u+s interface -exec: bot interface.pl - $(CM) +x bot interface.pl +exec: bot interface.pl rmaccess + $(CM) +x bot interface.pl rmaccess remove: interface interface.c copyoutwww moveout moveoutlib setuid exec $(RM) interface.c @@ -45,6 +45,9 @@ interface: interface.c bot: bot.1.pl configure.pl settings $(PL) configure.pl settings bot +rmaccess: rmaccess.1.pl configure.pl settings + $(PL) configure.pl settings rmaccess + config.txt: config.1.txt configure.pl settings $(PL) configure.pl settings config.txt diff --git a/rmaccess.1.pl b/rmaccess.1.pl new file mode 100644 index 0000000..f6fde5f --- /dev/null +++ b/rmaccess.1.pl @@ -0,0 +1,53 @@ +###PERL; + +# rmaccess is generated from rmaccess.1.pl. +# 05.01.2016 +# +# This script removes old access files. +# +# Copyright (C) 2015-2016 Balthasar Szczepański +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +###ACCESS_PATH; +###TIMEOUT_UNLOCK; +###TIMEOUT_INACT; + +my $time = time(); +srand ($time-$$); + +my $dir; +my $path; +my $unlocktime; +my $lasttime; +my $timeout_unlock = TIMEOUT_UNLOCK*60; +my $timeout_inact = TIMEOUT_INACT*60; + +if (opendir ($dir, ACCESS_PATH)) { + while (defined($path = readdir $dir)) { + if (open ($file, '<', ACCESS_PATH.$path)) { + $unlocktime=<$accessfile>; + $lasttime=<$accessfile>; + close($file); + + if (($unlocktime !~ /^([0-9]+)$/) || ($lasttime !~ /^([0-9]+)$/)) { + unlink (ACCESS_PATH.$path); + } + elsif ((abs($time-$unlocktime)>$timeout_unlock) or (abs($time-$lasttime)>$timeout_inact)){ + unlink (ACCESS_PATH.$path); + } + } + } + closedir($dir); +} diff --git a/settings b/settings index 84f167c..2a980cb 100644 --- a/settings +++ b/settings @@ -17,8 +17,8 @@ interface_path = /facebug #Please WITHOUT "/" at the end! It's an URL path and #not a directory path #Time in minutes -timeout_unlock = 90 # log out this many minutes after logging in -timeout_inact = 30 # log out this many minutes after last activity +timeout_unlock = 51840 # log out this many minutes after logging in +timeout_inact = 2160 # log out this many minutes after last activity path = /usr/local/bin:/usr/bin:/bin #The path environment variable. Must be #overwritten if SETUID. Otherwise -- 2.30.2