4 # info.pl is generated from info.1.pl.
7 # The frame/story info interface
9 # Copyright (C) 2017 Balthasar SzczepaĆski
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU Affero General Public License as
13 # published by the Free Software Foundation, either version 3 of the
14 # License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Affero General Public License for more details.
21 # You should have received a copy of the GNU Affero General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 use bsta_lib qw(failpage gethttpheader getcgi readdatafile printdatafile);
56 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
59 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
63 exit failpage("Status: 405 Method Not Allowed\nAllow: GET, POST, HEAD\n","405 Method Not Allowed","The interface does not support the $ENV{'REQUEST_METHOD'} method.",$method);
66 %http = gethttpheader (\%ENV);
67 %cgi = getcgi($ENV{'QUERY_STRING'});
69 if ($method eq 'POST') {
70 if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
71 my %cgipost=getcgi( <STDIN> );
72 foreach my $ind (keys %cgipost) {
73 $cgi{$ind}=$cgipost{$ind};
76 # multipart not supported
78 exit failpage("Status: 415 Unsupported Media Type\n","415 Unsupported Media Type","Unsupported Content-type: $http{'content-type'}.");
82 if ($cgi{'f'} =~ /^(.+)$/) {
85 elsif ($ENV{'PATH_INFO'} =~ /^\/(.+)$/) {
92 if ($cgi{'p'} =~ /^(.+)$/) {
99 %settings=readdatafile(SETTINGS_PATH);
100 %default=readdatafile(DEFAULT_PATH);
101 %framedata=readdatafile(DATA_PATH.$frame);
102 %state=readdatafile(STATE_PATH);
103 if($password eq $settings{'password'}){
111 unless($passwordOK) {
112 if ($state{'ip1'} ne '') {
115 if ($state{'ip2'} ne '') {
118 if ($state{'ip3'} ne '') {
122 print "Content-type: text/plain\n\n";
123 if($method eq 'HEAD') {
126 printdatafile(%state);
131 $frame = int($state{'last'}) + $frame +1;
132 %framedata=readdatafile(DATA_PATH.$frame);
135 %nextframedata=readdatafile(DATA_PATH.($frame+1));
137 foreach my $ind (keys %default) {
138 unless(defined($framedata{$ind})){
139 $framedata{$ind}=$default{$ind};
141 unless(defined($nextframedata{$ind})){
142 $nextframedata{$ind}=$default{$ind};
145 $seconds=int($state{'nextong'})-$time;
146 $ongtime=int($state{'ongtime'});
148 $ongtime=int($settings{'ongtime'})
150 $showcommand = ($seconds < ($ongtime*3600/3));
152 if ($passwordOK || (int($state{'state'}) >= 1 && $frame <= int($state{'last'}) && $frame >= 0)) {
155 if ($passwordOK || $frame<int($state{'last'}) || (int($state{'state'}) >= 2 && $showcommand)) {
156 $framedata{'command'}=$nextframedata{'title'};
158 $framedata{'frame'}=sprintf($settings{'frame'},$frame,$framedata{'ext'});
162 %framedata = readdatafile(NOACCESS_PATH);
163 foreach my $ind (keys %default) {
164 unless(defined($framedata{$ind})){
165 $framedata{$ind}=$default{$ind};
170 # $framedata{'frame'}=sprintf($settings{'frame'},$frame,$framedata{'ext'});
172 print "Content-type: text/plain\n";
174 print "Status: 403 Forbidden\n";
177 if($method eq 'HEAD') {
180 printdatafile(%framedata);