From d08db97540c923904a5d81663fc78aad887d6697 Mon Sep 17 00:00:00 2001 From: b Date: Tue, 26 Mar 2024 09:53:48 +0000 Subject: [PATCH] move error pages out to common library --- 2words.1.pl | 2 +- attach.1.pl | 4 +- bbcode.1.pl | 2 +- botm-common | 2 +- bsta_lib.1.pm | 158 -------------------------------------------------- chat.1.pl | 2 +- config | 2 +- frame.1.pl | 2 +- goto.1.pl | 4 +- info.1.pl | 2 +- opomba.1.pl | 5 +- settings.txt | 2 +- viewer.1.pl | 2 +- 13 files changed, 15 insertions(+), 174 deletions(-) diff --git a/2words.1.pl b/2words.1.pl index 1bc2d74..5f0f941 100644 --- a/2words.1.pl +++ b/2words.1.pl @@ -28,6 +28,7 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( 'HTTP_STATUS', + 'fail_method', 'fail_content_type', 'http_header_status', 'http_header_allow', 'merge_url', 'read_header_env', @@ -38,7 +39,6 @@ use botm_common ( use bsta_lib ( 'STATE', 'INTF_STATE', 'get_id', - 'fail_method', 'fail_content_type', 'print_html_start', 'print_html_end', 'print_html_head_start', 'print_html_head_end', 'print_html_body_start', 'print_html_body_end', diff --git a/attach.1.pl b/attach.1.pl index cb34f63..4adfce4 100644 --- a/attach.1.pl +++ b/attach.1.pl @@ -28,6 +28,8 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( 'HTTP_STATUS', + 'fail_method', 'fail_content_type', 'fail_attachment', 'fail_500', + 'redirect', 'read_header_env', 'url_query_decode', 'join_path', @@ -39,8 +41,6 @@ use bsta_lib ( 'STATE', 'merge_settings', 'get_id', 'get_password', - 'fail_method', 'fail_content_type', 'fail_attachment', 'fail_500', - 'redirect', 'read_settings', 'read_state', 'read_attachment' ); diff --git a/bbcode.1.pl b/bbcode.1.pl index 28e5e6d..089d557 100644 --- a/bbcode.1.pl +++ b/bbcode.1.pl @@ -28,6 +28,7 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( 'HTTP_STATUS', + 'fail_method', 'fail_content_type', 'read_header_env', 'url_query_decode', 'merge_url', @@ -35,7 +36,6 @@ use botm_common ( ); use bsta_lib ( 'STATE', - 'fail_method', 'fail_content_type', 'get_frame', 'get_password', 'merge_settings', 'eval_bb', 'bb_to_bbcode', diff --git a/botm-common b/botm-common index f0a6abf..599a7e9 160000 --- a/botm-common +++ b/botm-common @@ -1 +1 @@ -Subproject commit f0a6abfdebbbfd1b578d7339df1627f1afacd2be +Subproject commit 599a7e9a41f68c89f64cd982db730167d2acf28e diff --git a/bsta_lib.1.pm b/bsta_lib.1.pm index 0e45103..781ee0e 100644 --- a/bsta_lib.1.pm +++ b/bsta_lib.1.pm @@ -36,9 +36,6 @@ our @ISA = qw(Exporter); our @EXPORT = (); our @EXPORT_OK = ( 'STATE', 'TEXT_MODE', 'INTF_STATE', 'CHAT_STATE', 'CHAT_ACTION', - 'failpage', - 'fail_method', 'fail_content_type', 'fail_open_file', 'fail_attachment', 'fail_500', - 'redirect', 'get_remote_addr', 'get_id', 'get_frame', 'get_password', 'merge_settings', 'print_html_start', 'print_html_end', @@ -230,161 +227,6 @@ use constant tags_html => { }; -# Function to return an error page -# arguments: 1 - header fields, 2 - page title, 3 - error message, 4 method -sub failpage { - (my $header, my $title, my $message, my $method, my $hyperlink) = @_; - - if (ref($header)) { - foreach my $header_name (keys %$header) { - print http_header_line($header_name, $header->{$header_name}); - } - } - elsif($header ne '') { - print $header; - } - if($method eq 'HEAD') { - print "\n"; - return; - } - my $_title = html_entity_encode_dec($title , 1); - my $_message = html_entity_encode_dec($message , 1); - my $_hyperlink = html_entity_encode_dec($hyperlink, 1); - - print "Content-type: text/html; charset=UTF-8\n\n"; - - print ''."\n"; - print ' '."\n"; - print ' '."\n"; - print ' '."\n"; - if ($title ne '') { - print ' '.$_title.''."\n"; - } - print ' '."\n"; - print ' '."\n"; - if ($title ne '') { - print '

'.$_title.'

'."\n"; - } - if (($message ne '') || ($hyperlink ne '')) { - print "

\n"; - if ($message ne '') { - print ' '.$_message.($hyperlink ne '' ? '
' : '')."\n"; - } - if ($hyperlink ne '') { - print ' '.$_hyperlink."\n"; - } - print "

\n"; - } - print ' '."\n"; - print ''."\n"; -} - -sub fail_method { - (my $method, my $allowed) = @_; - - my $status = http_status(HTTP_STATUS->{'method_not_allowed'}); - my $header = - http_header_line('status', $status) . - http_header_allow($allowed); - - return failpage( - $header, - $status, - "The interface does not support the $method method.", - $method - ); -} - -sub fail_content_type -{ - (my $method, my $content_type) = @_; - - my $status = http_status(HTTP_STATUS->{'unsupported_media_type'}); - my $header = http_header_line('status', $status); - - return failpage( - $header, - $status, - "Unsupported Content-type: $content_type.", - $method - ); -} - -sub fail_open_file -{ - (my $method, my $type, my $path) = @_; - - my $status = http_status(HTTP_STATUS->{'not_found'}); - my $header = http_header_line('status', $status); - - return failpage( - $header, - $status, - "Can't open ". - ($type ne '' ? $type : 'file'). - ($path ne '' ? ': "'.$path.'"' : ''). - '.', - $method - ); -} - -sub fail_attachment -{ - (my $method, my $ID) = @_; - - my $status = http_status(HTTP_STATUS->{'not_found'}); - my $header = http_header_line('status', $status); - - return failpage( - $header, - $status, - "Attachment $ID not found.", - $method - ); -} - -sub fail_500 -{ - (my $method, my $text) = @_; - - my $status = http_status(HTTP_STATUS->{'internal_server_error'}); - my $header = http_header_line('status', $status); - - return failpage( - $header, - $status, - $text, - $method - ); -} - -sub redirect -{ - (my $method, my $uri, my $code) = @_; - my $header; - my $status; - 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 - # 307 Temporary Redirect - # 308 Permanent Redirect - $status = http_status($code); - $header = http_header_line('status', $status); - $header .= http_header_location($uri); - - return failpage( - $header, - $status, - '', - $method, - $uri - ); -} - # function to obtain address of remote agent sub get_remote_addr { diff --git a/chat.1.pl b/chat.1.pl index 90ea637..73c7ce9 100644 --- a/chat.1.pl +++ b/chat.1.pl @@ -29,6 +29,7 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( 'HTTP_STATUS', + 'fail_method', 'fail_content_type', 'read_header_env', 'url_query_decode', 'url_query_encode', 'merge_url', @@ -38,7 +39,6 @@ use botm_common ( ); use bsta_lib ( 'STATE', 'CHAT_STATE', 'CHAT_ACTION', - 'fail_method', 'fail_content_type', 'get_remote_addr', 'get_id', 'get_password', 'print_html_start', 'print_html_end', 'print_html_head_start', 'print_html_head_end', diff --git a/config b/config index fc9affe..352e86f 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit fc9affec336a16cde93b2675a836bdd01d1c2210 +Subproject commit 352e86fd3d4afab9adb6c340d236f501f3d91560 diff --git a/frame.1.pl b/frame.1.pl index a0a81fd..ea9db03 100644 --- a/frame.1.pl +++ b/frame.1.pl @@ -28,6 +28,7 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( 'HTTP_STATUS', + 'fail_method', 'fail_content_type', 'fail_open_file', 'fail_500', 'redirect', 'read_header_env', 'url_query_decode', 'join_path', @@ -37,7 +38,6 @@ use botm_common ( ); use bsta_lib ( 'STATE', 'INTF_STATE', - 'fail_method', 'fail_content_type', 'fail_open_file', 'fail_500', 'redirect', 'get_frame', 'get_password', 'merge_settings', 'get_frame_file', diff --git a/goto.1.pl b/goto.1.pl index 37feb23..8588e25 100644 --- a/goto.1.pl +++ b/goto.1.pl @@ -27,14 +27,14 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( + 'fail_method', 'fail_content_type', + 'redirect', 'read_header_env', 'url_query_decode', '_x_encoded' ); use bsta_lib ( 'STATE', - 'fail_method', 'fail_content_type', - 'redirect', 'get_password', 'print_goto', 'merge_settings', diff --git a/info.1.pl b/info.1.pl index 3778092..dfab493 100644 --- a/info.1.pl +++ b/info.1.pl @@ -28,6 +28,7 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( 'HTTP_STATUS', + 'fail_method', 'fail_content_type', 'http_header_status', 'read_header_env', 'write_data_file', @@ -35,7 +36,6 @@ use botm_common ( ); use bsta_lib ( 'STATE', - 'fail_method', 'fail_content_type', 'get_password', 'merge_settings', 'get_page_file', 'get_frame_file', diff --git a/opomba.1.pl b/opomba.1.pl index 639097a..1821df5 100644 --- a/opomba.1.pl +++ b/opomba.1.pl @@ -28,6 +28,8 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( 'HTTP_STATUS', + 'fail_method', 'fail_content_type', + 'redirect', 'read_header_env', 'url_query_decode', 'write_data_file', 'html_entity_encode_dec', @@ -40,8 +42,6 @@ use botm_common ( use bsta_lib ( 'TEXT_MODE', 'STATE', 'get_password', - 'fail_method', 'fail_content_type', - 'redirect', 'print_html_start', 'print_html_end', 'print_html_head_start', 'print_html_head_end', 'print_html_body_start', 'print_html_body_end', @@ -51,7 +51,6 @@ use bsta_lib ( 'read_settings', 'read_state', 'read_words', 'write_words', 'read_words_list', 'write_words_list' - ); ###PERL_PATH_SEPARATOR: PATH_SEPARATOR = / diff --git a/settings.txt b/settings.txt index 1d7117d..e5dd710 100644 --- a/settings.txt +++ b/settings.txt @@ -15,7 +15,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -_version: 1.2.8 +_version: 1.2.9 _SHEBANG: #!$0 diff --git a/viewer.1.pl b/viewer.1.pl index 97f0434..69c0aba 100644 --- a/viewer.1.pl +++ b/viewer.1.pl @@ -28,6 +28,7 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( 'HTTP_STATUS', + 'fail_method', 'fail_content_type', 'redirect', 'read_header_env', 'url_query_decode', 'join_path', @@ -37,7 +38,6 @@ use botm_common ( ); use bsta_lib ( 'STATE', 'TEXT_MODE', 'INTF_STATE', - 'fail_method', 'fail_content_type', 'redirect', 'get_remote_addr', 'get_frame', 'get_password', 'merge_settings', 'print_viewer_page', -- 2.30.2