From: b Date: Tue, 2 Jan 2024 10:35:56 +0000 (+0000) Subject: redirect attachment if already ONGed X-Git-Tag: v1.0.0~36 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=361e1c9ba7a8fae39654d4640b154c0f81c1f3ce;p=botm%2Foldlogs redirect attachment if already ONGed --- diff --git a/attach.1.pl b/attach.1.pl index d61c2fd..26ed413 100644 --- a/attach.1.pl +++ b/attach.1.pl @@ -5,7 +5,7 @@ # # The attachment interface # -# Copyright (C) 2016, 2023 - 2024 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 @@ -30,22 +30,27 @@ use botm_common ( 'read_header_env', 'url_query_decode', 'read_data_file', - 'join_path' + 'join_path', + 'merge_url' ); use bsta_lib ( 'STATE', 'merge_settings', 'get_id', 'get_password', - 'fail_attachment', 'fail_500' + 'fail_attachment', 'fail_500', 'redirect' ); ###PERL_PATH_SEPARATOR: PATH_SEPARATOR = / +###PERL_CGI_PATH: CGI_PATH = /bsta/ + ###PERL_DATA_PATH: DATA_PATH = /botm/data/bsta ###PERL_DATA_ATTACH_PATH: DATA_ATTACH_PATH = /botm/data/bsta/a ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state +###PERL_WWW_PATH: WWW_PATH = /botm/www/1190/bsta/ + binmode STDIN, ':encoding(UTF-8)'; binmode STDOUT, ':encoding(UTF-8)'; binmode STDERR, ':encoding(UTF-8)'; @@ -63,13 +68,18 @@ my %file_data; my $method; my $ID; my $frame; +my $last_frame; +my $ong_state; my $password; my $password_ok; my $IP; +my $try_onged; my $buffer; my $fh; my $file_path; +my $file_name; my $direct; +my $r = 0; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin; @@ -104,14 +114,17 @@ $password = get_password(\%cgi); %state = read_data_file(DATA_STATE_PATH()); %file_data = read_data_file(DATA_ATTACH_PATH().$ID); $frame = ($file_data{'frame'} ne '') ? int($file_data{'frame'}) : -1; +$last_frame = int($state{'last'}); +$ong_state = int($state{'state'}); +$file_name = $file_data{'filename'}; $password_ok = ($password eq $settings{'password'}); unless ( - ($file_data{'filename'} ne '') && ( + ($file_name ne '') && ( $password_ok || ( - (int($state{'state'}) >= STATE->{'waiting'}) && - ($frame <= int($state{'last'})) && + ($ong_state >= STATE->{'waiting'}) && + ($frame <= $last_frame) && ($frame >=0) ) ) @@ -124,9 +137,29 @@ if ($file_data{'content'} ne '') { } else { $direct = 0; - $file_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $file_data{'filename'}); - unless (open($fh,'<', encode('locale_fs', $file_path))) { - exit fail_attachment($method, $ID); + $try_onged = ( + ($ong_state >= STATE->{'waiting'}) && + ($frame <= $last_frame) && + ($frame >=0) + ); + if ($try_onged) { + $file_path = join_path(PATH_SEPARATOR(), WWW_PATH(), $file_name); + $r = open($fh, '<' , encode('locale_fs', $file_path)); + if ($r) { + close($r); + $file_path = merge_url( + {'path' => CGI_PATH()}, + {'path' => $file_name} + ); + exit redirect ($method, $file_path, 303); + } + } + unless ($r) { + $file_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $file_name); + $r = open($fh,'<', encode('locale_fs', $file_path)); + unless ($r) { + exit fail_attachment($method, $ID); + } } unless(binmode($fh)) { close($fh); @@ -137,7 +170,7 @@ else { } } print 'Content-type: '.$file_data{'content-type'}."\n"; -print 'Content-disposition: attachment; filename="'.$file_data{'filename'}.'"'."\n"; +print 'Content-disposition: attachment; filename="'.$file_name.'"'."\n"; unless ($direct) { unless (binmode STDOUT) { close($fh); diff --git a/frame.1.pl b/frame.1.pl index c6f87ae..b8fb99d 100644 --- a/frame.1.pl +++ b/frame.1.pl @@ -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 @@ -74,7 +74,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; @@ -147,7 +147,7 @@ elsif ( } } -$frame_indirect = !( +$try_onged = ( (!$access) || ( ($frame <= $last_frame) && ($ong_state > STATE->{'inactive'}) @@ -173,7 +173,7 @@ 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)); if ($r) {