]> git.gir.st - ttxd.git/blob - src/vtx2ascii-src/vtx.cgi
initial code import
[ttxd.git] / src / vtx2ascii-src / vtx.cgi
1 #!/usr/bin/perl
2 use CGI;
3
4 # config
5 $SPOOL="/home/kraxel/vtx";
6 $VTX2ASCII="/home/kraxel/bin/vtx2ascii";
7
8 #######################################################################
9 # create time string
10
11 @WEEK = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
12 @MON = ('Jan','Feb','Mar','Apr','May','Jun',
13 'Jul','Aug','Sep','Oct','Nov','Dec');
14
15 sub time2str {
16 @tm = gmtime($_[0]);
17 sprintf ("%s, %02d %s %04d %02d:%02d:%02d GMT",
18 $WEEK[$tm[6]],$tm[3],$MON[$tm[4]],$tm[5]+1900,$tm[2],$tm[1],$tm[0]);
19 }
20
21 #######################################################################
22 # helper functions
23
24 sub start_page {
25 local($title,$file) = @_;
26
27 if ($file ne "") {
28 @inode = stat $file;
29 printf("Last-modified: %s\n",time2str(@inode[9]));
30 }
31 print <<EOF;
32 Content-Type: text/html
33
34 <html>
35 <head>
36 <title>videotext: $title</title>
37 </html>
38 <body bgcolor=white color=black link=royalblue vlink=darkblue>
39 EOF
40 }
41
42 sub finish_page {
43 print "</body></html>\n";
44 }
45
46 sub panic {
47 local($text) = @_;
48
49 start_page("PANIC");
50 print "<h2>PANIC</h2>$text";
51 &finish_page;
52 exit;
53 }
54
55 sub addlink() {
56 local($nr) = @_;
57
58 $links{$nr} = 1;
59 return $nr;
60 }
61
62 #######################################################################
63 # main
64
65 $cgi = new CGI;
66
67 if ($cgi->path_info eq "" || $cgi->path_info =~ /^\/[^\/]+$/) {
68 print $cgi->redirect($cgi->url . $cgi->path_info . "/");
69 exit;
70 }
71 ($dummy,$station,$page) = split(/\//,$cgi->path_info);
72
73 # entry page - station list
74 if ($station !~ /\S/) {
75 opendir DIR, $SPOOL || panic("can't open dir $SPOOL: $@");
76 &start_page("station list",$SPOOL);
77 print "<h2>station list</h2>\n<ul>\n";
78 while ($file = readdir(DIR)) {
79 next if ($file =~ /^\./);
80 next unless -d "$SPOOL/$file";
81 print "<li><a href=\"$file/\">$file</a>\n";
82 }
83 print "</ul>\n";
84 &finish_page;
85 exit;
86 }
87
88 # station dir - spage list
89 if ($page !~ /\S/) {
90 opendir DIR, "$SPOOL/$station" ||
91 panic("can't open dir $SPOOL/$station: $@");
92 &start_page("$station - page list","$SPOOL/$station");
93 print "<h2>$station - page list</h2>\n\n";
94 print "<a href=\"../\">[station list]</a><hr noshade><ul>\n";
95 while ($file = readdir(DIR)) {
96 next unless ($file =~ /\.vtx/);
97 print "<li><a href=\"$file\">$file</a>\n";
98 }
99 print "</ul>\n";
100 &finish_page;
101 exit;
102 }
103
104 # print page
105 unless (-f "$SPOOL/$station/$page") {
106 # sub-page check
107 if ($page =~ s/_00.vtx/_01.vtx/ && -f "$SPOOL/$station/$page") {
108 print $cgi->redirect($cgi->url . "/$station/$page");
109 exit;
110 }
111 panic("$SPOOL/$station/$page: not found");
112 }
113
114 # read
115 undef $/;
116 open VTX,"$VTX2ASCII -h $SPOOL/$station/$page |" ||
117 panic("can't run $VTX2ASCII: $@");
118 $data = <VTX>;
119 close VTX;
120
121 # look for links
122 $data =~ s/(\d\d\d)/&addlink($1)/eg;
123
124 # print
125 start_page("$station - $page","$SPOOL/$station/$page");
126 print "<h2>$station - $page</h2>\n";
127 print "<a href=\"../\">[station list]</a> &nbsp; ";
128 print "<a href=\"./\">[page list]</a> &nbsp; ";
129 if ($page =~ /(\d\d\d)_(\d\d).vtx/ && $2 > 0) {
130 printf "<a href=\"%03d_%02d.vtx\">[prev subpage]</a> &nbsp; ",$1,$2-1;
131 printf "<a href=\"%03d_%02d.vtx\">[next subpage]</a> &nbsp; ",$1,$2+1;
132 }
133 print "<br>\n";
134 foreach $item (sort keys %links) {
135 print "<a href=\"${item}_00.vtx\">$item</a>\n";
136 }
137 print "<hr noshade>\n";
138 print "$data";
139 &finish_page;
140 exit;
Imprint / Impressum