1 ###RUN_PERL: #!/usr/bin/perl
3 # reset is generated from reset.1.pl.
7 # Copyright (C) 2016, 2017, 2018, 2023, 2024 Balthasar SzczepaĆski
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as
11 # published by the Free Software Foundation, either version 3 of the
12 # License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU Affero General Public License for more details.
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 use Encode::Locale ('decode_argv');
25 use Encode ('encode', 'decode');
27 ###PERL_LIB: use lib /botm/lib/bsta
30 'opendir_encoded', 'readdir_decoded', 'unlink_encoded',
34 'STATE', 'INTF_STATE', 'CHAT_STATE',
37 'get_page_file', 'get_frame_file',
38 'read_settings', 'read_default', 'read_frame_data', 'read_attachment', 'read_state'
41 binmode STDIN, ':encoding(UTF-8)';
42 binmode STDOUT, ':encoding(UTF-8)';
43 binmode STDERR, ':encoding(UTF-8)';
46 ###PERL_PATH_SEPARATOR: PATH_SEPARATOR = /
48 ###PERL_DATA_CHAT_PATH: DATA_CHAT_PATH = /botm/data/bsta/chat
49 ###PERL_DATA_DEFAULT_PATH: DATA_DEFAULT_PATH = /botm/data/bsta/default
50 ###PERL_DATA_LIST_PATH: DATA_LIST_PATH = /botm/data/bsta/list
51 ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
52 ###PERL_DATA_STORY_PATH: DATA_STORY_PATH = /botm/data/bsta/story
53 ###PERL_DATA_WORDS_PATH: DATA_WORDS_PATH = /botm/data/bsta/words/
55 ###PERL_WWW_PATH: WWW_PATH = /botm/www/
57 ###PERL_RESET_PASSWORD: RESET_PASSWORD = ''
68 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
69 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
71 %settings = read_settings();
72 %state = read_state();
75 ($ARGV[0] eq $settings{'password'}) ||
76 ($ARGV[0] eq RESET_PASSWORD())
79 print STDERR "Wrong password; no reset.\n";
83 $last_frame = (int($settings{'last'}) > int($state{'last'})) ?
84 int($settings{'last'}) : int($state{'last'});
85 %default = read_default();
87 for (my $frame=0; $frame<=$last_frame; $frame+=1) {
88 my %frame_data = read_frame_data($frame, \%default);
89 unless ($frame == 0) {
90 push @remove_list, get_page_file($frame, \%frame_data, \%settings);
92 push @remove_list, get_frame_file($frame, \%frame_data, \%settings);
94 push @remove_list, 'goto.htm';
95 for (my $i=0; ;$i+=1) {
98 %file_data = read_attachment($i);
99 if ($file_data{'frame'} eq '') {
102 if ($file_data{'content'} ne '') {
105 push @remove_list, $file_data{'filename'};
109 'state' => STATE->{'inactive'},
120 'lastip' => '0.0.0.0',
123 'state' => INTF_STATE->{'X'}
127 'state' => CHAT_STATE->{'disconnected'},
133 write_data_file(DATA_STATE_PATH(), \%state);
134 write_data_file(DATA_STORY_PATH(), \%story);
135 write_data_file(DATA_CHAT_PATH() , \%chat);
136 write_data_file(DATA_LIST_PATH() , \%goto_list);
146 if (opendir_encoded(my $dir, DATA_WORDS_PATH())) {
147 while (defined (my $file_name = readdir_decoded($dir))) {
148 if ($file_name !~ /^[0-9]+$/) {
151 my $full_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $file_name);
152 # print "RM $full_path\n";
153 unlink_encoded ($full_path);
156 foreach my $file_name (@remove_list) {
157 my $full_path = join_path(PATH_SEPARATOR(), WWW_PATH(), $file_name);
158 # print "RM $full_path\n";
159 unlink_encoded ($full_path);