]> bicyclesonthemoon.info Git - ott/bsta/blobdiff - frame.1.pl
update static page after comment
[ott/bsta] / frame.1.pl
index b175644aa98747e62aec6a109f36e2fdf570c9b7..9bea1c2a91c5ef12152886e14be93afbfcee84e0 100644 (file)
@@ -5,7 +5,7 @@
 #
 # The frame interface
 #
-# Copyright (C) 2016, 2023  Balthasar Szczepański
+# Copyright (C) 2016, 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
@@ -27,11 +27,14 @@ use Encode ('encode', 'decode');
 
 ###PERL_LIB: use lib /botm/lib/bsta
 use botm_common (
+       'HTTP_STATUS',
        'read_header_env',
        'url_query_decode',
        'read_data_file',
        'join_path',
-       'merge_url'
+       'merge_url',
+       'open_encoded', 'stat_encoded',
+       'http_header_line', 'http_header_content_length', 'http_header_content_disposition'
 );
 use bsta_lib (
        'STATE', 'INTF_STATE',
@@ -74,7 +77,7 @@ my $password;
 my $password_ok;
 my $IP;
 my $access;
-my $frame_indirect;
+my $try_onged;
 my $frame_path;
 my $frame_data_path;
 my $frame_file;
@@ -91,7 +94,7 @@ if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
        $method = $1;
 }
 else{
-       exit fail_method($ENV{'REQUEST_METHOD'}, 'GET, POST, HEAD');
+       exit fail_method($ENV{'REQUEST_METHOD'}, ['GET', 'POST', 'HEAD']);
 }
 
 %http = read_header_env(\%ENV);
@@ -99,10 +102,8 @@ else{
 
 if ($method eq 'POST') {
        if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
-               my %cgi_post=url_query_decode( <STDIN> );
-               foreach my $ind (keys %cgi_post) {
-                       $cgi{$ind} = $cgi_post{$ind};
-               }
+               my %cgi_post = url_query_decode( <STDIN> );
+               %cgi = merge_settings(\%cgi, \%cgi_post);
        }
        # multipart not supported
        else{
@@ -149,7 +150,7 @@ elsif (
        }
 }
 
-$frame_indirect = !(
+$try_onged = (
        (!$access) || (
                ($frame <= $last_frame) &&
                ($ong_state > STATE->{'inactive'})
@@ -175,21 +176,21 @@ else {
        );
 }
 
-unless ($frame_indirect) {
+if ($try_onged) {
        $frame_path = join_path(PATH_SEPARATOR(), WWW_PATH(), $frame_file);
-       $r = open($fh, '<' , encode('locale_fs', $frame_path));
+       $r = open_encoded($fh, '<' , $frame_path);
        if ($r) {
                close($r);
                $frame_path = merge_url(
                        {'path' => CGI_PATH()},
                        {'path' => $frame_file}
                );
-               exit redirect ($method, $frame_path, 303);
+               exit redirect ($method, $frame_path, HTTP_STATUS->{'see_other'});
        }
 }
 unless ($r) {
        $frame_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame_file);
-       $r = open($fh, '<' , encode('locale_fs', $frame_path));
+       $r = open_encoded($fh, '<' , $frame_path);
        unless ($r) {
                exit fail_open_file($method, 'image file', $frame_file);
        }
@@ -199,10 +200,15 @@ unless (binmode($fh)) {
        exit fail_500("Can't switch file to binary mode.");
 }
 
-if (my @file_info = stat($frame_path)){
-       print 'Content-length: '.$file_info[7]."\n";
+if (my @file_info = stat_encoded($frame_path)){
+       print http_header_content_length($file_info[7]);
+}
+if ($frame_data{'content-type'} ne '') {
+       print http_header_line('content-type', $frame_data{'content-type'});
+}
+if ($frame_file ne '') {
+       print http_header_content_disposition('inline', $frame_file);
 }
-print 'Content-type: '.$frame_data{'content-type'}."\n";
 unless (binmode STDOUT) {
        close($fh);
        exit fail_500("Can't switch output to binary mode.");