'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',
###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
###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)';
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;
exit fail_content_type($method, $http{'content-type'});
}
}
+$no_cgi = (scalar (keys %cgi) == 0);
$IP = get_remote_addr();
$frame = get_frame(\%cgi);
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 (
$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) {
$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'};