]> bicyclesonthemoon.info Git - ott/bsta/blob - goto.1.pl
improve GOTO handling
[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         'url_query_decode',
32         '_x_encoded'
33 );
34 use bsta_lib (
35         'STATE',
36         'fail_method', 'fail_content_type',
37         'redirect',
38         'get_password',
39         'print_goto',
40         'merge_settings',
41         'read_settings', 'read_state', 'read_goto'
42 );
43
44 ###PERL_CGI_PATH:           CGI_PATH           = /bsta/
45 ###PERL_CGI_LIST_PATH:      CGI_LIST_PATH      = /bsta/goto.htm
46 ###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
47
48 ###PERL_WWW_GOTO_PATH:      WWW_GOTO_PATH      = /botm/www/1190/bsta/goto.htm
49
50 ###PERL_WEBSITE_NAME:       WEBSITE_NAME       = Bicycles on the Moon
51
52 binmode STDIN,  ':encoding(UTF-8)';
53 binmode STDOUT, ':encoding(UTF-8)';
54 binmode STDERR, ':encoding(UTF-8)';
55 # decode_argv();
56
57 my $time = time();
58 srand ($time-$$);
59
60 my %http;
61 my %cgi;
62 my %settings;
63 my %state;
64 my %goto_list;
65
66 my $method;
67 my $password;
68 my $password_ok;
69 my $no_cgi;
70
71 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
72 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
73
74 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
75         $method = $1;
76 }
77 else{
78         exit fail_method($ENV{'REQUEST_METHOD'}, ['GET', 'POST', 'HEAD']);
79 }
80
81 %http = read_header_env(\%ENV);
82 %cgi = url_query_decode($ENV{'QUERY_STRING'});
83
84 if ($method eq 'POST') {
85         if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
86                 my %cgi_post = url_query_decode( <STDIN> );
87                 %cgi = merge_settings(\%cgi, \%cgi_post);
88         }
89         # multipart not supported
90         else{
91                 exit fail_content_type($method, $http{'content-type'});
92         }
93 }
94
95 $no_cgi = (scalar (keys %cgi) == 0);
96
97 if ($no_cgi) {
98         if (_x_encoded('-f', WWW_GOTO_PATH())) {
99                 exit redirect($method, CGI_LIST_PATH());
100         }
101 }
102
103 $password = get_password(\%cgi);
104
105 %settings  = read_settings();
106 %state     = read_state();
107 %goto_list = read_goto();
108
109 $password_ok = ($password eq $settings{'password'});
110
111 print "Content-type: text/html; charset=UTF-8\n";
112 print "\n";
113 if($method eq 'HEAD') {
114         exit;
115 }
116
117 print_goto(
118         \*STDOUT,
119         \%state,
120         \%settings,
121         \%goto_list,
122         $password_ok
123 );