]> bicyclesonthemoon.info Git - ott/bsta/blob - goto.1.pl
fix ONG; fix update; total reset
[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_decode',
33         '_x_encoded'
34 );
35 use bsta_lib (
36         'STATE',
37         'fail_method', 'fail_content_type',
38         'redirect',
39         'get_password',
40         'print_goto',
41         'merge_settings'
42 );
43
44 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
45
46 ###PERL_CGI_PATH:           CGI_PATH           = /bsta/
47 ###PERL_CGI_LIST_PATH:      CGI_LIST_PATH      = /bsta/goto.htm
48 ###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
49
50 ###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
51 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
52 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
53 ###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
54
55 ###PERL_WWW_GOTO_PATH:      WWW_GOTO_PATH      = /botm/www/1190/bsta/goto.htm
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 $no_cgi;
77
78 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
79 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
80
81 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
82         $method = $1;
83 }
84 else{
85         exit fail_method($ENV{'REQUEST_METHOD'}, ['GET', 'POST', 'HEAD']);
86 }
87
88 %http = read_header_env(\%ENV);
89 %cgi = url_query_decode($ENV{'QUERY_STRING'});
90
91 if ($method eq 'POST') {
92         if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
93                 my %cgi_post = url_query_decode( <STDIN> );
94                 %cgi = merge_settings(\%cgi, \%cgi_post);
95         }
96         # multipart not supported
97         else{
98                 exit fail_content_type($method, $http{'content-type'});
99         }
100 }
101
102 $no_cgi = (scalar (keys %cgi) == 0);
103
104 if ($no_cgi) {
105         if (_x_encoded('-f', WWW_GOTO_PATH())) {
106                 exit redirect($method, CGI_LIST_PATH());
107         }
108 }
109
110 $password = get_password(\%cgi);
111
112 %settings  = read_data_file(DATA_SETTINGS_PATH());
113 %state     = read_data_file(DATA_STATE_PATH());
114 %goto_list = read_data_file(DATA_LIST_PATH());
115
116 $password_ok = ($password eq $settings{'password'});
117
118 print "Content-type: text/html; charset=UTF-8\n";
119 print "\n";
120 if($method eq 'HEAD') {
121         exit;
122 }
123
124 print_goto(
125         \*STDOUT,
126         \%state,
127         \%settings,
128         \%goto_list,
129         $password_ok
130 );