From: b Date: Sat, 30 Dec 2023 11:24:26 +0000 (+0000) Subject: reworked reset and added reset password X-Git-Tag: v1.0.0~40 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=1a71d88f0a4bd255d583ab3974820c74581c3057;p=botm%2Foldlogs reworked reset and added reset password --- diff --git a/bsta.1.cron b/bsta.1.cron index 52f63d3..96c38df 100644 --- a/bsta.1.cron +++ b/bsta.1.cron @@ -2,4 +2,4 @@ ###CRON_OLDLOGS_SCHEDULE; ###CRON_USER; ###CRON_OLDLOGS; ###CRON_LOG; ###CRON_LOG_SIZE_LIMIT; ###CRON_LOGS_TOTAL; ###CRON_LOGS_UNCOMPRESSED; ###CRON_ONG_SCHEDULE; ###CRON_USER; ###CRON_ONG; >> ###CRON_ONG_LOG; -###CRON_RESET_SCHEDULE; ###CRON_USER; ###CRON_RESET; +###CRON_RESET_SCHEDULE; ###CRON_USER; ###CRON_RESET; ###CRON_RESET_PASSWORD; diff --git a/reset.1.pl b/reset.1.pl index 998096a..7c8fada 100644 --- a/reset.1.pl +++ b/reset.1.pl @@ -20,99 +20,81 @@ # along with this program. If not, see . use strict; -#use warnings; +use utf8; +use Encode::Locale ('decode_argv'); +use Encode ('encode', 'decode'); + ###PERL_LIB: use lib /botm/lib/bsta -use bsta_lib qw(writedatafile); +use botm_common ( + 'read_data_file', 'write_data_file', +); +use bsta_lib ( + 'STATE', 'INTF_STATE', + 'write_index' +); -###PERL_CGI_PATH: CGI_PATH = /bsta/ +binmode STDIN, ':encoding(UTF-8)'; +binmode STDOUT, ':encoding(UTF-8)'; +binmode STDERR, ':encoding(UTF-8)'; +decode_argv(); ###PERL_DATA_CHAT_PATH: DATA_CHAT_PATH = /botm/data/bsta/chat +###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/state ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state ###PERL_DATA_STORY_PATH: DATA_STORY_PATH = /botm/data/bsta/story -###PERL_WWW_INDEX_PATH: WWW_INDEX_PATH = /botm/www/1190/bsta/index.htm +###PERL_RESET_PASSWORD: RESET_PASSWORD = '' -###PERL_WEBSITE: WEBSITE = 1190.bicyclesonthemoon.info +my %story; +my %state; +my %chat; +my %settings; -###PERL_COIN_DATE: COIN_DATE = 13-Nov-2016 22:15 -###PERL_INTF_DATE: INTF_DATE = 28-Sep-2016 20:34 +delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; +###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin; -my %story = ( - 'id' => '0', - 'letter' => '', - 'lastip' => '0.0.0.0', - 'content' => '', - 'pass' => '0', - 'state' => '0' -); -my %state = ( - 'state' => '0', - 'last' => '0', +%settings = read_data_file(DATA_SETTINGS_PATH()); +unless ( + ($ARGV[0] ne '') && ( + ($ARGV[0] eq $settings{'password'}) || + ($ARGV[0] eq RESET_PASSWORD()) + ) +) { + print STDERR "Wrong password; no reset.\n"; + exit 1; +} + +%state = ( + 'state' => STATE->{'inactive'}, + 'last' => 0, 'ongtime' => '', 'nextong' => '', 'ip1' => '', 'ip2' => '', 'ip3' => '' ); -my %chat = ( - 'id' => '0', - 'state' => '0', +%story = ( + 'id' => 0, + 'letter' => '', + 'lastip' => '0.0.0.0', + 'content' => '', + 'pass' => 0, + 'state' => INTF_STATE->{'X'} +); +%chat = ( + 'id' => 0, + 'state' => 0, # TODO chat state enum? 'content' => '' ); -delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; -###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin; - -writedatafile(DATA_STATE_PATH,%state); -writedatafile(DATA_STORY_PATH,%story); -writedatafile(DATA_CHAT_PATH,%chat); - -writeindex(WWW_INDEX_PATH); +write_data_file(DATA_STATE_PATH(), '', '', \%state); +write_data_file(DATA_STORY_PATH(), '', '', \%story); +write_data_file(DATA_CHAT_PATH() , '', '', \%chat); -#function borrowed from 2words.pl - keep consistent! -sub writeindex { - (my $indexpath) = @_; - my $indexfile; - my $indexof; - - if(ref($indexpath)) { - $indexfile=$indexpath; - unless (seek($indexfile, 0, 0)) { - return 0; - } - } - else { - unless (open ($indexfile, ">", $indexpath)) { - return 0; - } - } - - $indexof = CGI_PATH; - $indexof =~ s/\/$//g; - - print $indexfile ''."\n"; - print $indexfile ''."\n"; - print $indexfile ' '."\n"; - print $indexfile ' Index of '.$indexof.''."\n"; - print $indexfile ' '."\n"; - print $indexfile ' '."\n"; - print $indexfile '

Index of '.$indexof.'

'."\n"; - print $indexfile ''."\n"; - print $indexfile ''."\n"; - print $indexfile ''."\n"; - print $indexfile ''."\n"; - print $indexfile ''."\n"; - print $indexfile '
[ICO]NameLast modifiedSizeDescription

[DIR]Parent Directory  -  
[DIR]2words/'.INTF_DATE.' -  
[DIR]coin/'.COIN_DATE.' - Coincidence

'."\n"; - print $indexfile '
Apache/2.2.22 (Debian) Server at '.WEBSITE.' Port 80
'."\n"; - print $indexfile ''."\n"; - - - unless (ref($indexpath)) { - close ($indexfile); - } - else { - truncate ($indexfile , tell($indexfile)); - } - - return 1; -} +write_index( + \%state, + \%settings, + $story{'pass'}, + $story{'state'}, + 0 # pause +); diff --git a/settings-again.txt b/settings-again.txt index 10b67c0..0e5c207 100644 --- a/settings-again.txt +++ b/settings-again.txt @@ -69,6 +69,7 @@ ong_schedule: 0 * * * * # When to RESET EVERYTHING reset_schedule: 33 4 * * * +reset_password: again cron_user: b diff --git a/settings-bsta.txt b/settings-bsta.txt index e2426f1..6e2fbb3 100644 --- a/settings-bsta.txt +++ b/settings-bsta.txt @@ -69,6 +69,7 @@ ong_schedule: 0 * * * * # When to RESET EVERYTHING reset_schedule: #33 4 * * * +reset_password: cron_user: b diff --git a/settings-debug.txt b/settings-debug.txt index ec1a28c..c53dfd3 100644 --- a/settings-debug.txt +++ b/settings-debug.txt @@ -69,6 +69,7 @@ ong_schedule: #0 * * * * # When to RESET EVERYTHING reset_schedule: #33 4 * * * +reset_password: bstreset cron_user: b diff --git a/settings-tbst.txt b/settings-tbst.txt index 2365d73..bc183ce 100644 --- a/settings-tbst.txt +++ b/settings-tbst.txt @@ -69,6 +69,7 @@ ong_schedule: #0 * * * * # When to RESET EVERYTHING reset_schedule: #33 4 * * * +reset_password: cron_user: b diff --git a/settings.txt b/settings.txt index a346d99..45bd400 100644 --- a/settings.txt +++ b/settings.txt @@ -102,6 +102,7 @@ CRON_USER = $cron_user CRON_OLDLOGS_SCHEDULE = $oldlogs_schedule CRON_ONG_SCHEDULE = $ong_schedule CRON_RESET_SCHEDULE = $reset_schedule +CRON_RESET_PASSWORD = $reset_password CRON_LOG_SIZE_LIMIT = $log_size_limit CRON_LOGS_UNCOMPRESSED = $logs_uncompressed @@ -180,6 +181,8 @@ PERL_INTF_DATE = @_PERL_CONSTANT_STR( INTF_DATE, $intf_date) PERL_GZIP = @_PERL_CONSTANT_STR( GZIP, $gzip) +PERL_RESET_PASSWORD = @_PERL_CONSTANT_STR( RESET_PASSWORD, $reset_password) + PERL_LOG_SIZE_LIMIT = @_PERL_CONSTANT( LOG_SIZE_LIMIT , $log_size_limit) PERL_LOGS_UNCOMPRESSED = @_PERL_CONSTANT( LOGS_UNCOMPRESSED, $logs_uncompressed) PERL_LOGS_TOTAL = @_PERL_CONSTANT( LOGS_TOTAL , $logs_total)