]> bicyclesonthemoon.info Git - ott/bsta/blob - goto.1.pl
add license information
[ott/bsta] / goto.1.pl
1 ###RUN_PERL: #!/usr/bin/perl
2
3 # /bsta/g
4 # goto is generated from goto.1.pl.
5 #
6 # The frame list
7 #
8 # Copyright (C) 2017, 2023, 2024  Balthasar SzczepaƄski
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as
12 # published by the Free Software Foundation, either version 3 of the
13 # License, or (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU Affero General Public License for more details.
19 #
20 # You should have received a copy of the GNU Affero General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 use strict;
24 use utf8;
25 # use Encode::Locale ('decode_argv');
26 use Encode ('encode', 'decode');
27
28 ###PERL_LIB: use lib /botm/lib/bsta
29 use botm_common (
30         'read_header_env',
31         'read_data_file',
32         'url_query_encode', 'url_query_decode',
33         'merge_url',
34         'join_path',
35         'html_entity_encode_dec'
36 );
37 use bsta_lib (
38         'STATE',
39         'fail_method', 'fail_content_type',
40         'get_password',
41         'print_html_start', 'print_html_end',
42         'print_html_head_start', 'print_html_head_end',
43         'print_html_body_start', 'print_html_body_end',
44         'write_index'
45 );
46
47 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
48
49 ###PERL_CGI_PATH:           CGI_PATH           = /bsta/
50 ###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
51
52 ###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
53 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
54 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
55 ###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
56
57 ###PERL_WEBSITE_NAME:       WEBSITE_NAME       = Bicycles on the Moon
58
59 binmode STDIN,  ':encoding(UTF-8)';
60 binmode STDOUT, ':encoding(UTF-8)';
61 binmode STDERR, ':encoding(UTF-8)';
62 # decode_argv();
63
64 my $time = time();
65 srand ($time-$$);
66
67 my %http;
68 my %cgi;
69 my %settings;
70 my %state;
71 my %goto_list;
72
73 my $method;
74 my $password;
75 my $password_ok;
76 my $password_query;
77 my $frame;
78 my $last_frame;
79 my $ong_state;
80 my $line;
81
82 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
83 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
84
85 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
86         $method = $1;
87 }
88 else{
89         exit fail_method($ENV{'REQUEST_METHOD'}, 'GET, POST, HEAD');
90 }
91
92 %http = read_header_env(\%ENV);
93 %cgi = url_query_decode($ENV{'QUERY_STRING'});
94
95 if ($method eq 'POST') {
96         if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
97                 my %cgi_post = url_query_decode( <STDIN> );
98                 %cgi = merge_settings(\%cgi, \%cgi_post);
99         }
100         # multipart not supported
101         else{
102                 exit fail_content_type($method, $http{'content-type'});
103         }
104 }
105
106 $password = get_password(\%cgi);
107
108 %settings  = read_data_file(DATA_SETTINGS_PATH());
109 %state     = read_data_file(DATA_STATE_PATH());
110 %goto_list = read_data_file(DATA_LIST_PATH());
111
112 $last_frame = int($state{'last'});
113 $ong_state  = int($state{'state'});
114
115 $password_ok = ($password eq $settings{'password'});
116 $password_query = url_query_encode({'p', $settings{'password'}});
117
118 print "Content-type: text/html\n";
119 print "\n";
120 if($method eq 'HEAD') {
121         exit;
122 }
123
124 my $_title        = html_entity_encode_dec($settings{'story'}, 1);
125 my $_website_name = html_entity_encode_dec(WEBSITE_NAME()    , 1);
126 my $_base_url     = html_entity_encode_dec(CGI_PATH()        , 1);
127
128 print_html_start(\*STDOUT);
129 print_html_head_start(\*STDOUT);
130
131 print '  <title>GOTO &bull; '.$_title.' &bull; '.$_website_name.'</title>'."\n";
132
133 print_html_head_end(\*STDOUT);
134 print_html_body_start(\*STDOUT);
135
136 print '   <div id="inst" class="ins">'."\n";
137
138 print '    <div id="title">'."\n";
139 print '     <h1 id="titletext">'.$_title.'</h1>'."\n";
140 print '    </div>'."\n";
141
142 print '   </div>'."\n";
143 print '   <div id="insb" class="ins">'."\n";
144
145 print '    <div id="chat">'."\n";
146 for ($frame = 0; ; $frame += 1) {
147         unless (
148                 $password_ok || (
149                         ($frame <= $last_frame) &&
150                         ($ong_state >= STATE->{'waiting'})
151                 )
152         ) {
153                 last;
154         }
155         my $title;
156         my $ongtime;
157         my @time_tab;
158         my $time_text;
159         my $timer_color;
160         my $frame_text;
161         my $viewer_url;
162         
163         $ongtime = $goto_list{'ongtime-'.$frame};
164         $title   = $goto_list{'title-'  .$frame};
165         if (($ongtime eq '') && ($title eq '')) {
166                 my $frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
167                 my %frame_data = read_data_file($frame_data_path);
168                 $ongtime = $frame_data{'ongtime'};
169                 $title   = $frame_data{'title'};
170                 unless (keys %frame_data) {
171                         last;
172                 }
173         }
174         
175         if ($ongtime ne '') {
176                 @time_tab = gmtime($ongtime);
177                 $time_text = sprintf(
178                         '%02d.%02d.%02d %02d:%02d',
179                         $time_tab[3],
180                         $time_tab[4]+1,
181                         $time_tab[5]-100,
182                         $time_tab[2],
183                         $time_tab[1]
184                 );
185         }
186         else {
187                 $time_text = (($frame <= $last_frame) && ($ong_state >= STATE->{'waiting'})) ?
188                         'EE.EE.EE EE:EE' : '--.--.-- --:--';
189         }
190         if ($title eq '') {
191                 $title = '_';
192         }
193         $timer_color = (($frame > $last_frame) || ($ong_state < STATE->{'waiting'})) ?
194                 'cz' : (
195                         (($frame == $last_frame) && ($ong_state < STATE->{'ready'})) ?
196                                 'ni' : 'br'
197                 );
198         $frame_text = sprintf('%03d',$frame);
199         $viewer_url = merge_url(
200                 {'path' => CGI_VIEWER_PATH()},
201                 {'path' => $frame}
202         );
203         if ($password_ok) {
204                 $viewer_url = merge_url($viewer_url, {'query' => $password_query, 'append_query' => 1});
205         }
206         
207         my $_viewer_url = html_entity_encode_dec($viewer_url, 1);
208         my $_title      = html_entity_encode_dec($title     , 1);
209         
210         print '     <span class="'.$timer_color.'">'.$frame_text.'</span> '.$time_text.' <a href="'.$_viewer_url.'">'.$_title.'</a><br>'."\n";
211 }
212 print '    </div>'."\n";
213
214 print '    <div id="underlinks">'."\n";
215 print '     <a href="'.$_base_url.'">BSTA</a>'."\n";
216 print '    </div>'."\n";
217
218 print '   </div>'."\n";
219
220 print_html_body_end(\*STDOUT, $ong_state == STATE->{'inactive'});
221 print_html_end(\*STDOUT);