1 ###RUN_PERL: #!/usr/bin/perl
4 # bbcode.pl is generated from bbcode.1.pl.
8 # Copyright (C) 2017, 2023, 2024 Balthasar SzczepaĆski
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.
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.
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/>.
25 # use Encode::Locale ('decode_argv');
26 use Encode ('encode', 'decode');
28 ###PERL_LIB: use lib /botm/lib/bsta
31 'read_data_file', 'write_data_file',
38 'fail_method', 'fail_content_type',
39 'get_frame', 'get_password',
41 'eval_bb', 'bb_to_bbcode'
44 ###PERL_PATH_SEPARATOR: PATH_SEPARATOR = /
46 ###PERL_CGI_PATH: CGI_PATH = /bsta/
47 ###PERL_CGI_VIEWER_PATH: CGI_VIEWER_PATH = /bsta/v
49 ###PERL_DATA_PATH: DATA_PATH = /botm/data/bsta/
50 ###PERL_DATA_DEFAULT_PATH: DATA_DEFAULT_PATH = /botm/data/bsta/default
51 ###PERL_DATA_NOACCESS_PATH: DATA_NOACCESS_PATH = /botm/data/bsta/noaccess
52 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
53 ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
55 ###PERL_SCHEME: SCHEME = http
56 ###PERL_WEBSITE: WEBSITE = 1190.bicyclesonthemoon.info
58 binmode STDIN, ':encoding(UTF-8)';
59 binmode STDOUT, ':encoding(UTF-8)';
60 binmode STDERR, ':encoding(UTF-8)';
84 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
85 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
87 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
91 exit fail_method($ENV{'REQUEST_METHOD'}, 'GET, POST, HEAD');
94 %http = read_header_env(\%ENV);
95 %cgi = url_query_decode($ENV{'QUERY_STRING'});
97 if ($method eq 'POST') {
98 if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
99 my %cgi_post = url_query_decode( <STDIN> );
100 %cgi = merge_settings(\%cgi, \%cgi_post);
102 # multipart not supported
104 exit fail_content_type($method, $http{'content-type'});
108 $frame = get_frame(\%cgi);
109 $password = get_password(\%cgi);
111 %settings = read_data_file(DATA_SETTINGS_PATH());
112 %default = read_data_file(DATA_DEFAULT_PATH());
113 %state = read_data_file(DATA_STATE_PATH());
115 $ong_state = int($state{'state'});
116 $last_frame = int($state{'last'});
118 $password_ok = ($password eq $settings{'password'});
121 $frame = $last_frame + $frame +1;
123 $frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
124 %frame_data = read_data_file($frame_data_path);
125 %frame_data = merge_settings(\%default, \%frame_data);
129 ($ong_state >= STATE->{'waiting'}) &&
130 ($frame <= $last_frame) &&
138 %frame_data = read_data_file(DATA_NOACCESS_PATH());
139 %frame_data = merge_settings(\%default, \%frame_data);
141 if ($frame_data{'frame'} ne '') {
142 $frame_file = $frame_data{'frame'};
145 $frame_file = sprintf(
147 $frame, $frame_data{'ext'}
151 print "Content-type: text/plain\n";
153 print "Status: 403 Forbidden\n";
156 if($method eq 'HEAD') {
160 my $viewer_url = merge_url(
161 {'scheme' => SCHEME(), 'host' => WEBSITE()},
162 {'path' => CGI_VIEWER_PATH()},
165 my $frame_url = merge_url(
166 {'scheme' => SCHEME(), 'host' => WEBSITE()},
167 {'path' => CGI_PATH()},
168 {'path' => $frame_file}
170 my $content = bb_to_bbcode(eval_bb($frame_data{'content'}, 1));
172 print '[quote][center][size=200]'.$frame_data{'title'}.'[/size]'."\n";
173 print '[url='.$viewer_url.'][img]'.$frame_url.'[/img][/url][/center]'."\n";
174 print $content.'[/quote]'."\n";