]> bicyclesonthemoon.info Git - ott/bsta/blob - bbcode.1.pl
Done comment system
[ott/bsta] / bbcode.1.pl
1 ###RUN_PERL: #!/usr/bin/perl
2
3 # /bsta/b
4 # bbcode.pl is generated from bbcode.1.pl.
5 #
6 # The bbcode interface
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_decode',
33         'join_path',
34         'merge_url'
35 );
36 use bsta_lib (
37         'STATE',
38         'fail_method', 'fail_content_type',
39         'get_frame', 'get_password',
40         'merge_settings',
41         'eval_bb', 'bb_to_bbcode'
42 );
43
44 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
45
46 ###PERL_CGI_PATH:           CGI_PATH           = /bsta/
47 ###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
48
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
54
55 ###PERL_SCHEME:             SCHEME             = http
56 ###PERL_WEBSITE:            WEBSITE            = 1190.bicyclesonthemoon.info
57
58 binmode STDIN,  ':encoding(UTF-8)';
59 binmode STDOUT, ':encoding(UTF-8)';
60 binmode STDERR, ':encoding(UTF-8)';
61 # decode_argv();
62
63 my $time = time();
64 srand ($time-$$);
65
66 my %http;
67 my %cgi;
68 my %frame_data;
69 my %default;
70 my %settings;
71 my %state;
72
73 my $method;
74 my $frame;
75 my $password;
76 my $password_ok;
77 my $access;
78 my $ongtime;
79 my $ong_state;
80 my $last_frame;
81 my $frame_data_path;
82 my $frame_file;
83
84 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
85 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
86
87 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
88         $method = $1;
89 }
90 else{
91         exit fail_method($ENV{'REQUEST_METHOD'}, 'GET, POST, HEAD');
92 }
93
94 %http = read_header_env(\%ENV);
95 %cgi = url_query_decode($ENV{'QUERY_STRING'});
96
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);
101         }
102         # multipart not supported
103         else{
104                 exit fail_content_type($method, $http{'content-type'});
105         }
106 }
107
108 $frame  = get_frame(\%cgi);
109 $password = get_password(\%cgi);
110
111 %settings   = read_data_file(DATA_SETTINGS_PATH());
112 %default    = read_data_file(DATA_DEFAULT_PATH());
113 %state      = read_data_file(DATA_STATE_PATH());
114
115 $ong_state  = int($state{'state'});
116 $last_frame = int($state{'last'});
117
118 $password_ok = ($password eq $settings{'password'});
119
120 if ($frame < 0) {
121         $frame = $last_frame + $frame +1;
122 }
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);
126
127 if (
128         $password_ok || (
129                 ($ong_state >= STATE->{'waiting'}) &&
130                 ($frame <= $last_frame) &&
131                 ($frame >= 0)
132         )
133 ) {
134         $access = 1;
135 }
136 else {
137         $access=0;
138         %frame_data = read_data_file(DATA_NOACCESS_PATH());
139         %frame_data = merge_settings(\%default, \%frame_data);
140 }
141 if ($frame_data{'frame'} ne '') {
142         $frame_file = $frame_data{'frame'};
143 }
144 else {
145         $frame_file = sprintf(
146                 $settings{'frame'},
147                 $frame, $frame_data{'ext'}
148         );
149 }
150
151 print "Content-type: text/plain\n";
152 if(!$access) {
153         print "Status: 403 Forbidden\n";
154 }
155 print "\n";
156 if($method eq 'HEAD') {
157         exit;
158 }
159
160 my $viewer_url = merge_url(
161         {'scheme' => SCHEME(), 'host' => WEBSITE()},
162         {'path' => CGI_VIEWER_PATH()},
163         {'path' => $frame}
164 );
165 my $frame_url = merge_url(
166         {'scheme' => SCHEME(), 'host' => WEBSITE()},
167         {'path' => CGI_PATH()},
168         {'path' => $frame_file}
169 );
170 my $content = bb_to_bbcode(eval_bb($frame_data{'content'}, 1));
171
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";