1 ###RUN_PERL: #!/usr/bin/perl
3 # ong.pl is generated from ong.1.pl.
7 # Copyright (C) 2016, 2017, 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
29 'read_data_file', 'write_data_file',
36 'write_static_viewer_page', 'write_index'
39 ###PERL_PATH_SEPARATOR: PATH_SEPARATOR = /
41 ###PERL_DATA_PATH: DATA_PATH = /botm/data/bsta/
42 ###PERL_DATA_DEFAULT_PATH: DATA_DEFAULT_PATH = /botm/data/bsta/default
43 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
44 ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
46 binmode STDIN, ':encoding(UTF-8)';
47 binmode STDOUT, ':encoding(UTF-8)';
48 binmode STDERR, ':encoding(UTF-8)';
70 $ongtime = int($time / 3600) * 3600; # check time as if it was last full hour!
72 print $time.' - '.$ongtime."\n";
74 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
75 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
77 unless (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
78 print "NO STATEFILE\n";
81 unless (flock($fh, 2)) {
82 print "NO STATELOCK\n";
85 %state = read_data_file($fh);
86 $ongstate = int($state{'state'});
87 print 'state: '.$ongstate."\n";
88 unless ($ongstate > STATE->{'inactive'}) {
92 $next_ong = int($state{'nextong'});
93 print 'ongtime: '.$next_ong."\n";
95 unless ($ongtime >= $next_ong) {
99 %settings = read_data_file(DATA_SETTINGS_PATH());
100 $static_timer = int($settings{'ongtime'});
101 $timer = int($settings{'dynamicongtime'});
102 $last = int($settings{'last'});
103 $frame = int($state {'last'})+1;
105 if (($timer > 0) && ($frame < $last)) {
106 $timer = int($timer / ($last - $frame));
112 if ($static_timer > $timer) {
113 $timer = $static_timer;
115 $next_ong = $ongtime + ($timer*3600);
116 $state{'nextong'} = $next_ong;
117 print 'next ongtime: '.$next_ong.' (+'.$timer.")\n";
118 $state{'ongtime'}=$timer;
120 if ($ongstate == STATE->{'ready'}) {
121 print 'next frame: '.$frame."\n";
123 %default = read_data_file(DATA_DEFAULT_PATH());
124 %frame_data = read_data_file(
125 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame)
131 $timer, # timer to next ONG
140 $state{'last'} = $frame;
145 $state{'ongtime'}= $timer;
152 %frame_1_data = read_data_file(
153 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-1)
157 %frame_2_data = read_data_file(
158 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-2)
162 %frame_3_data = read_data_file(
163 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-3)
168 print 'static page '.($frame-1);
169 $r = write_static_viewer_page(
174 \%frame_1_data, # frame data
175 \%frame_2_data, # prev frame data
176 \%frame_data, # next frame data
179 print (($r) ? " OK\n" : " FAIL\n");
183 print 'static page '.($frame-2);
184 $r = write_static_viewer_page(
189 \%frame_2_data, # frame data
190 \%frame_3_data, # prev frame data
191 \%frame_1_data, # next frame data
194 print (($r) ? " OK\n" : " FAIL\n");
202 print (($r) ? " OK\n" : " FAIL\n");
209 write_data_file($fh, \%state);