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', 'write_static_goto'
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_LIST_PATH: DATA_LIST_PATH = /botm/data/bsta/list
44 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
45 ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
47 binmode STDIN, ':encoding(UTF-8)';
48 binmode STDOUT, ':encoding(UTF-8)';
49 binmode STDERR, ':encoding(UTF-8)';
75 $ongtime = int($time / 3600) * 3600; # check time as if it was last full hour!
77 print $time.' - '.$ongtime."\n";
79 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
80 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
82 unless (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
83 print "NO STATEFILE\n\n";
86 unless (flock($fh, 2)) {
87 print "NO STATELOCK\n\n";
91 %state = read_data_file($fh);
92 $ongstate = int($state{'state'});
93 print 'state: '.$ongstate."\n";
94 unless ($ongstate > STATE->{'inactive'}) {
99 $next_ong = int($state{'nextong'});
100 print 'ongtime: '.$next_ong."\n";
102 unless ($ongtime >= $next_ong) {
108 %settings = read_data_file(DATA_SETTINGS_PATH());
109 $static_timer = int($settings{'ongtime'});
110 $timer = int($settings{'dynamicongtime'});
111 $last = int($settings{'last'});
112 $frame = int($state {'last'})+1;
114 if (($timer > 0) && ($frame < $last)) {
115 $timer = int($timer / ($last - $frame));
121 if ($static_timer > $timer) {
122 $timer = $static_timer;
124 $next_ong = $ongtime + ($timer*3600);
125 $state{'nextong'} = $next_ong;
126 print 'next ongtime: '.$next_ong.' (+'.$timer.")\n";
127 $state{'ongtime'}=$timer;
129 if ($ongstate == STATE->{'ready'}) {
130 print 'next frame: '.$frame."\n";
132 %default = read_data_file(DATA_DEFAULT_PATH());
133 %frame_data = read_data_file(
134 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame)
136 # %goto_list = read_data_file(DATA_LIST_PATH());
139 $new_state{'last'} = $frame;
140 $new_state{'state'} = 1;
141 $new_state{'ip1'} = '';
142 $new_state{'ip2'} = '';
143 $new_state{'ip3'} = '';
144 $new_state{'ongtime'}= $timer;
147 %frame_1_data = read_data_file(
148 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-1)
152 %frame_2_data = read_data_file(
153 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-2)
157 %frame_3_data = read_data_file(
158 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-3)
165 $timer, # timer to next ONG
173 if ($r && ($frame >= 2)) {
174 print 'static page '.($frame-1);
175 $r = write_static_viewer_page(
180 \%frame_1_data, # frame data
181 \%frame_2_data, # prev frame data
182 \%frame_data, # next frame data
185 print (($r) ? " OK\n" : " FAIL\n");
187 if ($r && ($frame >= 3)) {
188 print 'static page '.($frame-2);
189 $r = write_static_viewer_page(
194 \%frame_2_data, # frame data
195 \%frame_3_data, # prev frame data
196 \%frame_1_data, # next frame data
199 print (($r) ? " OK\n" : " FAIL\n");
201 if ($r && ($frame <= 2)) {
207 print (($r) ? " OK\n" : " FAIL\n");
211 $r = write_static_goto(
216 print (($r) ? " OK\n" : " FAIL\n");
226 write_data_file($fh, \%state);