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
34 'write_static_viewer_page', 'write_index', 'write_static_goto',
35 'read_default', 'read_frame_data', 'read_settings', 'read_goto',
36 'read_state', 'write_state'
39 ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
41 binmode STDIN, ':encoding(UTF-8)';
42 binmode STDOUT, ':encoding(UTF-8)';
43 binmode STDERR, ':encoding(UTF-8)';
69 $ongtime = int($time / 3600) * 3600; # check time as if it was last full hour!
71 print $time.' - '.$ongtime."\n";
73 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
74 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
76 unless (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
77 print "NO STATEFILE\n\n";
80 unless (flock($fh, 2)) {
81 print "NO STATELOCK\n\n";
85 %state = read_state($fh);
86 $ongstate = int($state{'state'});
87 print 'state: '.$ongstate."\n";
88 unless ($ongstate > STATE->{'inactive'}) {
93 $next_ong = int($state{'nextong'});
94 print 'ongtime: '.$next_ong."\n";
96 unless ($ongtime >= $next_ong) {
102 %settings = read_settings();
103 $static_timer = int($settings{'ongtime'});
104 $timer = int($settings{'dynamicongtime'});
105 $last = int($settings{'last'});
106 $frame = int($state {'last'})+1;
108 if (($timer > 0) && ($frame < $last)) {
109 $timer = int($timer / ($last - $frame));
115 if ($static_timer > $timer) {
116 $timer = $static_timer;
118 $next_ong = $ongtime + ($timer*3600);
119 $state{'nextong'} = $next_ong;
120 print 'next ongtime: '.$next_ong.' (+'.$timer.")\n";
121 $state{'ongtime'}=$timer;
123 if ($ongstate == STATE->{'ready'}) {
124 print 'next frame: '.$frame."\n";
126 %default = read_default();
127 %frame_data = read_frame_data($frame);
128 # %goto_list = read_goto());
131 $new_state{'last'} = $frame;
132 $new_state{'state'} = 1;
133 $new_state{'ip1'} = '';
134 $new_state{'ip2'} = '';
135 $new_state{'ip3'} = '';
136 $new_state{'ongtime'}= $timer;
139 %frame_1_data = read_frame_data($frame-1);
142 %frame_2_data = read_frame_data($frame-2);
145 %frame_3_data = read_frame_data($frame-3);
151 $timer, # timer to next ONG
159 if ($r && ($frame >= 2)) {
160 print 'static page '.($frame-1);
161 $r = write_static_viewer_page(
166 \%frame_1_data, # frame data
167 \%frame_2_data, # prev frame data
168 \%frame_data, # next frame data
171 print (($r) ? " OK\n" : " FAIL\n");
173 if ($r && ($frame >= 3)) {
174 print 'static page '.($frame-2);
175 $r = write_static_viewer_page(
180 \%frame_2_data, # frame data
181 \%frame_3_data, # prev frame data
182 \%frame_1_data, # next frame data
185 print (($r) ? " OK\n" : " FAIL\n");
187 if ($r && ($frame <= 2)) {
193 print (($r) ? " OK\n" : " FAIL\n");
197 $r = write_static_goto(
202 print (($r) ? " OK\n" : " FAIL\n");
212 write_state($fh, \%state);