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 'fail_method', 'fail_content_type',
39 'get_frame', 'get_password',
41 'eval_bb', 'bb_to_bbcode',
43 'read_frame_data', 'read_default', 'read_noaccess',
44 'read_settings', 'read_state'
47 ###PERL_CGI_PATH: CGI_PATH = /bsta/
48 ###PERL_CGI_VIEWER_PATH: CGI_VIEWER_PATH = /bsta/v
50 ###PERL_DATA_PATH: DATA_PATH = /botm/data/bsta/
52 ###PERL_SCHEME: SCHEME = http
53 ###PERL_WEBSITE: WEBSITE = 1190.bicyclesonthemoon.info
55 binmode STDIN, ':encoding(UTF-8)';
56 binmode STDOUT, ':encoding(UTF-8)';
57 binmode STDERR, ':encoding(UTF-8)';
81 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
82 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
84 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
88 exit fail_method($ENV{'REQUEST_METHOD'}, ['GET', 'POST', 'HEAD']);
91 %http = read_header_env(\%ENV);
92 %cgi = url_query_decode($ENV{'QUERY_STRING'});
94 if ($method eq 'POST') {
95 if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
96 my %cgi_post = url_query_decode( <STDIN> );
97 %cgi = merge_settings(\%cgi, \%cgi_post);
99 # multipart not supported
101 exit fail_content_type($method, $http{'content-type'});
105 $frame = get_frame(\%cgi);
106 $password = get_password(\%cgi);
108 %settings = read_settings();
109 %default = read_default();
110 %state = read_state();
112 $ong_state = int($state{'state'});
113 $last_frame = int($state{'last'});
115 $password_ok = ($password eq $settings{'password'});
118 $frame = $last_frame + $frame +1;
120 %frame_data = read_frame_data($frame, \%default);
124 ($ong_state >= STATE->{'waiting'}) &&
125 ($frame <= $last_frame) &&
133 %frame_data = read_noaccess(\%default);
135 $frame_file = get_frame_file($frame, \%frame_data, \%settings);
137 print "Content-type: text/plain; charset=UTF-8\n";
139 print http_header_status(HTTP_STATUS->{'forbidden'});
142 if($method eq 'HEAD') {
146 my $viewer_url = merge_url(
147 {'scheme' => SCHEME(), 'host' => WEBSITE()},
148 {'path' => CGI_VIEWER_PATH()},
151 my $frame_url = merge_url(
152 {'scheme' => SCHEME(), 'host' => WEBSITE()},
153 {'path' => CGI_PATH()},
154 {'path' => $frame_file}
156 my $content = bb_to_bbcode(
158 $frame_data{'content'},
163 print '[quote][center][size=200]'.$frame_data{'title'}.'[/size]'."\n";
164 print '[url='.$viewer_url.'][img]'.$frame_url.'[/img][/url][/center]'."\n";
165 print $content.'[/quote]'."\n";