]> bicyclesonthemoon.info Git - ott/bsta/blobdiff - goto.1.pl
input validation; goto form; show version; 2 words password
[ott/bsta] / goto.1.pl
index dcc2072bfaced33b5cdbbba1c36596d0c8e32b71..37feb2391c8998200426ea87d32912269da2daf2 100644 (file)
--- a/goto.1.pl
+++ b/goto.1.pl
-###PERL;
-#
+###RUN_PERL: #!/usr/bin/perl
+
 # /bsta/g
-# goto.pl is generated from goto.1.pl.
-# 02.07.2017
+# goto is generated from goto.1.pl.
 #
 # The frame list
 #
-#    Copyright (C) 2017  Balthasar Szczepański
+# Copyright (C) 2017, 2023, 2024  Balthasar Szczepański
 #
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU Affero General Public License as
-#    published by the Free Software Foundation, either version 3 of the
-#    License, or (at your option) any later version.
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
 #
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU Affero General Public License for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
-#use warnings;
-###LIB;
-use bsta_lib qw(failpage gethttpheader getcgi readdatafile printdatafile entityencode urlencode);
-use File::Copy;
-
-###DATA_PATH;
-###SETTINGS_PATH;
-###STATE_PATH;
-###LIST_PATH;
-###WEBSITE_NAME;
-###FAVICON_PATH;
-###CSS_PATH;
-###LOGO_PATH;
-###WEBSITE;
-###CGI_PATH;
-###VIEWER_PATH;
+use utf8;
+# use Encode::Locale ('decode_argv');
+use Encode ('encode', 'decode');
+
+###PERL_LIB: use lib /botm/lib/bsta
+use botm_common (
+       'read_header_env',
+       'url_query_decode',
+       '_x_encoded'
+);
+use bsta_lib (
+       'STATE',
+       'fail_method', 'fail_content_type',
+       'redirect',
+       'get_password',
+       'print_goto',
+       'merge_settings',
+       'read_settings', 'read_state', 'read_goto'
+);
+
+###PERL_CGI_PATH:           CGI_PATH           = /bsta/
+###PERL_CGI_LIST_PATH:      CGI_LIST_PATH      = /bsta/goto.htm
+###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
+
+###PERL_WWW_GOTO_PATH:      WWW_GOTO_PATH      = /botm/www/1190/bsta/goto.htm
+
+###PERL_WEBSITE_NAME:       WEBSITE_NAME       = Bicycles on the Moon
+
+binmode STDIN,  ':encoding(UTF-8)';
+binmode STDOUT, ':encoding(UTF-8)';
+binmode STDERR, ':encoding(UTF-8)';
+# decode_argv();
 
+my $time = time();
+srand ($time-$$);
 
 my %http;
 my %cgi;
 my %settings;
 my %state;
-my %gotolist;
-
-my @timetab;
-
-my $time = time();
-srand ($time-$$);
+my %goto_list;
 
 my $method;
 my $password;
-my $passwordOK;
-
-my $frame;
-my $last;
-my $title;
-my $ongtime;
-my $ongstate;
-my $line;
+my $password_ok;
+my $no_cgi;
 
 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
-###PATH;
+###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
 
 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
-       $method=$1;
+       $method = $1;
 }
 else{
-       exit failpage("Status: 405 Method Not Allowed\nAllow: GET, POST, HEAD\n","405 Method Not Allowed","The interface does not support the $ENV{'REQUEST_METHOD'} method.",$method);
+       exit fail_method($ENV{'REQUEST_METHOD'}, ['GET', 'POST', 'HEAD']);
 }
 
-%http = gethttpheader (\%ENV);
-%cgi = getcgi($ENV{'QUERY_STRING'});
+%http = read_header_env(\%ENV);
+%cgi = url_query_decode($ENV{'QUERY_STRING'});
 
 if ($method eq 'POST') {
        if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
-               my %cgipost=getcgi( <STDIN> );
-               foreach my $ind (keys %cgipost) {
-                       $cgi{$ind}=$cgipost{$ind};
-               }
+               my %cgi_post = url_query_decode( <STDIN> );
+               %cgi = merge_settings(\%cgi, \%cgi_post);
        }
        # multipart not supported
        else{
-               exit failpage("Status: 415 Unsupported Media Type\n","415 Unsupported Media Type","Unsupported Content-type: $http{'content-type'}.");
+               exit fail_content_type($method, $http{'content-type'});
        }
 }
 
-if ($cgi{'p'} =~ /^(.+)$/) {
-       $password=$1;
-}
-else {
-       $password='';
+$no_cgi = (scalar (keys %cgi) == 0);
+
+if ($no_cgi) {
+       if (_x_encoded('-f', WWW_GOTO_PATH())) {
+               exit redirect($method, CGI_LIST_PATH());
+       }
 }
 
-%settings=readdatafile(SETTINGS_PATH);
-%state=readdatafile(STATE_PATH);
-%gotolist=readdatafile(LIST_PATH);
+$password = get_password(\%cgi);
 
-if($password eq $settings{'password'}){
-       $passwordOK = 1;
-}
-else{
-       $passwordOK = 0;
-}
+%settings  = read_settings();
+%state     = read_state();
+%goto_list = read_goto();
 
-print "Content-type: text/html\n";
+$password_ok = ($password eq $settings{'password'});
+
+print "Content-type: text/html; charset=UTF-8\n";
 print "\n";
 if($method eq 'HEAD') {
        exit;
 }
 
-print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
-print '<html lang="en"><head>'."\n";
-print '<title>GOTO &bull; '.entityencode($settings{'story'}).' &bull; '.WEBSITE_NAME.'</title>'."\n";
-print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
-print '<link rel="icon" type="image/png" href="'.FAVICON_PATH.'">'."\n";
-print '<link rel="stylesheet" href="'.CSS_PATH.'">'."\n";
-print '</head><body>'."\n";
-print '<a href="/"><img id="botmlogo" src="'.LOGO_PATH.'" alt="'.WEBSITE.'"></a>'."\n";
-print '<div id="all">'."\n";
-
-print '<div id="inst" class="ins">'."\n";
-
-print '<div id="title">'."\n";
-print '<H1 id="titletext">'.entityencode($settings{'story'}).'</H1>'."\n";
-print '</div>'."\n";
-
-print '</div><div id="insb" class="ins">'."\n";
-
-print '<div id="chat">'."\n";
-
-$last=int($state{'last'});
-$ongstate=int($state{'state'});
-for ($frame=0; ; ++$frame) {
-       if((($frame > $last) || $ongstate<1) && !$passwordOK) {
-               last;
-       }
-       
-       $ongtime=$gotolist{'ongtime-'.$frame};
-       $title=$gotolist{'title-'.$frame};
-       if ($ongtime eq '') {
-               last;
-       }
-       @timetab=gmtime($ongtime);
-       
-       print '<span class="'.(($frame==$last && int($state{'state'}<2))?'ni':'br').'">'.sprintf('%03d',$frame).'</span> '.sprintf('%02d.%02d.%02d %02d:%02d',$timetab[3],$timetab[4]+1,$timetab[5]-100,$timetab[2],$timetab[1]).' <a href="'.VIEWER_PATH.'/'.$frame.($passwordOK?('?p='.urlencode($password)):'').'">'.entityencode($title).'</a><br>'."\n";
-}
-
-print '</div>'."\n";
-
-print '<div id="underlinks">'."\n";
-
-print '<a href="'.CGI_PATH.'">BSTA</a>'."\n";
-
-print '</div>'."\n";
-
-print '</div>'."\n";
-
-print '</div>'."\n";
-print '<a href="/" class="cz">'.WEBSITE.'</a>'."\n";
-
-
-print '</body></html>'."\n";
-
-
-
-
-
-
+print_goto(
+       \*STDOUT,
+       \%state,
+       \%settings,
+       \%goto_list,
+       $password_ok
+);