]> bicyclesonthemoon.info Git - botm/oldlogs/commitdiff
viewer redirects to static page; info includes static page;
authorb <rowerynaksiezycu@gmail.com>
Sat, 27 Jan 2024 21:26:56 +0000 (21:26 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sat, 27 Jan 2024 21:26:56 +0000 (21:26 +0000)
fixed directory scanning for comment reset & old logs

bsta_lib.1.pm
info.1.pl
oldlogs.1.pl
ong.1.pl
reset.1.pl
viewer.1.pl

index 5629795940285ae6dbbd9d6241e7d1a935a04b96..262d852947ef44e85ce0190d762a056e309abcdd 100644 (file)
@@ -354,6 +354,7 @@ sub redirect
        if ($code eq '') {
                $code = HTTP_STATUS->{'found'};
        }
+       # https://insanecoding.blogspot.com/2014/02/http-308-incompetence-expected.html
        # 301 Moved Permanently
        # 302 Found
        # 303 See Other
@@ -1215,9 +1216,23 @@ sub print_viewer_page {
                if ($show_command) {
                        $frame_data->{'command'} = $command;
                }
-               if ($context->{'access'}) {
+               if ($access) {
                        $frame_data->{'frame'} = $frame_file;
                }
+               if ($frame_data->{'page'} eq '') {
+                       unless (($access) && ($frame < $last_frame)) {
+                               $frame_data->{'page'} = '';
+                       }
+                       elsif ($frame == 0) {
+                               $frame_data->{'page'} = 'index.htm';
+                       }
+                       else {
+                               $frame_data->{'page'} = sprintf(
+                                       $settings->{'frame'},
+                                       $frame, 'htm'
+                               );
+                       }
+               }
        }
        
        # everything determined, now start generating
index fc236682bb1728d7aa8d26517e992c4f51cc74b2..d5c0ec8b85e26e84055c736e595f69a758303f4d 100644 (file)
--- a/info.1.pl
+++ b/info.1.pl
@@ -242,11 +242,23 @@ else {
        }
 }
 if (
-       ($info_data{'frame'} eq '') &&
        ($attachment eq '') &&
        ($words eq '')
 ) {
-       $info_data{'frame'} = sprintf($settings{'frame'}, $frame, $info_data{'ext'});
+       if ($info_data{'frame'} eq '') {
+               $info_data{'frame'} = sprintf($settings{'frame'}, $frame, $info_data{'ext'});
+       }
+       if ($info_data{'page'} eq '') {
+               unless (($access) && ($frame < $last_frame)) {
+                       $info_data{'page'} = '';
+               }
+               elsif ($frame == 0) {
+                       $info_data{'page'} = 'index.htm';
+               }
+               else {
+                       $info_data{'page'} = sprintf($settings{'frame'}, $frame, 'htm');
+               }
+       }
 }
 
 print "Content-type: text/plain; charset=UTF-8\n";
index 7a0959f877e664bebd9edbef5b825e7f8c31d9f8..dbb44211990620cd92b3dbcef1448169997acd76 100644 (file)
@@ -55,7 +55,7 @@ my $logs_total        = ($ARGV[2] =~ /^[0-9]+$/) ? int($&) : LOGS_TOTAL();
 my $logs_uncompressed = ($ARGV[3] =~ /^[0-9]+$/) ? int($&) : LOGS_UNCOMPRESSED();
 
 if (opendir_encoded(my $dir, $log_path)) {
-       while (my $file_name = readdir_decoded($dir)) {
+       while (defined (my $file_name = readdir_decoded($dir))) {
                if ($file_name !~ /\.log$/) {
                        next;
                }
index aec693a24adab7f97dbe9795ed3061ce41aeadf3..8c243c0a05803f615c53d4597719c4344a9ee2fd 100644 (file)
--- a/ong.1.pl
+++ b/ong.1.pl
@@ -182,7 +182,7 @@ else {
                                                {
                                                        print 'static page '.($frame-2);
                                                        $r = write_static_viewer_page(
-                                                               $frame-1, # frame ID
+                                                               $frame-2, # frame ID
                                                                \%state,
                                                                \%settings,
                                                                \%default,
index 9e2dfccc734f6efea4f55b31a50fdbd23ab243cb..c43e3683a4d49b94c89c67c6f5bfe499e75d033e 100644 (file)
@@ -110,7 +110,7 @@ write_index(
 );
 
 if (opendir_encoded(my $dir, DATA_WORDS_PATH())) {
-       while (my $file_name = readdir_decoded($dir)) {
+       while (defined (my $file_name = readdir_decoded($dir))) {
                if ($file_name !~ /^[0-9]+$/) {
                        next;
                }
index 33c90edcb079ba8a18b60a3830160fbc3515ffbe..4e8cc0e2039bf027bcfa0fb1dce2926979781add 100644 (file)
@@ -32,12 +32,13 @@ use botm_common (
        'read_data_file', 'write_data_file',
        'url_query_decode',
        'join_path',
-       'open_encoded',
+       'open_encoded', '_x_encoded',
        'http_header_status',
+       'merge_url'
 );
 use bsta_lib (
        'STATE', 'TEXT_MODE', 'INTF_STATE',
-       'fail_method', 'fail_content_type',
+       'fail_method', 'fail_content_type', 'redirect',
        'get_remote_addr', 'get_frame', 'get_password',
        'merge_settings',
        'print_viewer_page', 'write_index',
@@ -46,6 +47,9 @@ use bsta_lib (
 
 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
 
+###PERL_CGI_PATH:           CGI_PATH           = /bsta/
+###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
+
 ###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
 ###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
 ###PERL_DATA_NOACCESS_PATH: DATA_NOACCESS_PATH = /botm/data/bsta/noaccess
@@ -54,6 +58,8 @@ use bsta_lib (
 ###PERL_DATA_STORY_PATH:    DATA_STORY_PATH    = /botm/data/bsta/story
 ###PERL_DATA_WORDS_PATH:    DATA_WORDS_PATH    = /botm/data/bsta/words/
 
+###PERL_WWW_PATH:           WWW_PATH           = /botm/www/
+
 binmode STDIN,  ':encoding(UTF-8)';
 binmode STDOUT, ':encoding(UTF-8)';
 binmode STDERR, ':encoding(UTF-8)';
@@ -91,6 +97,8 @@ my $ongtime;
 my $text_mode;
 my $words_page;
 my $words_data_path;
+my $no_cgi;
+my $force_redirect;
 
 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
@@ -115,6 +123,7 @@ if ($method eq 'POST') {
                exit fail_content_type($method, $http{'content-type'});
        }
 }
+$no_cgi = (scalar (keys %cgi) == 0);
 
 $IP = get_remote_addr();
 $frame = get_frame(\%cgi);
@@ -138,8 +147,11 @@ if (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
                
                if ($frame < 0) {
                        $frame = int($state{'last'}) + $frame +1;
-                       $frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
-                       %frame_data = read_data_file($frame_data_path);
+                       if ($frame >= 0) {
+                               $force_redirect = 1;
+                               $frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
+                               %frame_data = read_data_file($frame_data_path);
+                       }
                }
                
                if (
@@ -235,6 +247,73 @@ else {
        $state{'state'} = STATE->{'inactive'};
 }
 
+$access = (
+       $password_ok || (
+               (int($state{'state'}) >= STATE->{'waiting'}) &&
+               ($frame <= int($state{'last'})) &&
+               ($frame >= 0)
+       )
+);
+
+if ($access) {
+       if ($no_cgi) {
+               # no CGI - static page is OK
+               if ($frame == 0) {
+                       exit redirect($method, CGI_PATH(), HTTP_STATUS->{'see_other'});
+               }
+               elsif ($frame < int($state{'last'})) {
+                       my $page_file;
+                       if ($frame_data{'page'} ne '') {
+                               $page_file = $frame_data{'page'};
+                       }
+                       else {
+                               $page_file = sprintf(
+                                       $settings{'frame'},
+                                       $frame, 'htm'
+                               );
+                       }
+                       if (_x_encoded('-f',
+                               join_path(PATH_SEPARATOR(), WWW_PATH() , $page_file)
+                       )) {
+                               my $static_url = merge_url(
+                                       {'path' => CGI_PATH()},
+                                       {'path' => $page_file}
+                               );
+                               exit redirect($method, $static_url, HTTP_STATUS->{'see_other'});
+                       }
+               }
+       }
+       if ($force_redirect) {
+               my $redirect_url = merge_url(
+                       {'path' => CGI_VIEWER_PATH()},
+                       {'path' => $frame}
+               );
+               unless ($no_cgi) {
+                       $redirect_url = merge_url(
+                               {'path' => $redirect_url},
+                               {'query' => \%cgi}
+                       );
+               }
+               exit redirect($method, $redirect_url, HTTP_STATUS->{'see_other'});
+       }
+       
+       if ($frame > 0) {
+               $prev_frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-1);
+               %prev_frame_data = read_data_file($prev_frame_data_path);
+       }
+       $next_frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame+1);
+       %next_frame_data = read_data_file($next_frame_data_path);
+       
+       %frame_data      = merge_settings(\%default,      \%frame_data);
+       %prev_frame_data = merge_settings(\%default, \%prev_frame_data);
+       %next_frame_data = merge_settings(\%default, \%next_frame_data);
+}
+else {
+       # replace frame data with fail state replacement
+       %frame_data = read_data_file(DATA_NOACCESS_PATH());
+       %frame_data = merge_settings(\%default, \%frame_data);
+}
+
 $timer   = int($state{'nextong'}) - $time;
 $ongtime = int($state{'ongtime'});
 if($ongtime == 0) {
@@ -258,32 +337,6 @@ else {
        $timer_unlocked = 0;
 }
 
-if (
-               $password_ok || (
-                       (int($state{'state'}) >= STATE->{'waiting'}) &&
-                       ($frame <= int($state{'last'})) &&
-                       ($frame >= 0)
-               )
-       ) {
-       $access = 1;
-       if ($frame > 0) {
-               $prev_frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-1);
-               %prev_frame_data = read_data_file($prev_frame_data_path);
-       }
-       $next_frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame+1);
-       %next_frame_data = read_data_file($next_frame_data_path);
-       
-       %frame_data      = merge_settings(\%default,      \%frame_data);
-       %prev_frame_data = merge_settings(\%default, \%prev_frame_data);
-       %next_frame_data = merge_settings(\%default, \%next_frame_data);
-}
-else {
-       $access = 0;
-       # replace frame data with fail state replacement
-       %frame_data = read_data_file(DATA_NOACCESS_PATH());
-       %frame_data = merge_settings(\%default, \%frame_data);
-}
-
 $text_mode = int($cgi{'b'});
 if($text_mode > TEXT_MODE->{'words'}) {
        $text_mode = TEXT_MODE->{'normal'};