]> bicyclesonthemoon.info Git - ott/bsta/blob - 2words.1.pl
Adapted for new config tool.
[ott/bsta] / 2words.1.pl
1 ###RUN_PERL: #!/usr/bin/perl
2
3 # /bsta/2words
4 # 2words is generated from 2words.1.pl.
5 #
6 # The wordgame interface
7 #
8 # Copyright (C) 2016 - 2017, 2023  Balthasar SzczepaƄski
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as
12 # published by the Free Software Foundation, either version 3 of the
13 # License, or (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU Affero General Public License for more details.
19 #
20 # You should have received a copy of the GNU Affero General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 use strict;
24 #use warnings;
25 ###PERL_LIB: use lib /botm/lib/bsta
26 use bsta_lib qw(failpage gethttpheader getcgi entityencode readdatafile writedatafile urlencode bb2ht);
27 use  File::Copy;
28
29 ###PERL_CGI_PATH:           CGI_PATH           = /bsta/
30 ###PERL_CGI_2WORDS_PATH:    CGI_2WORDS_PATH    = /bsta/2words
31 ###PERL_CGI_CSS_PATH:       CGI_CSS_PATH       = /bsta/bsta.css
32 ###PERL_CGI_LOGO_PATH:      CGI_LOGO_PATH      = /bsta/botmlogo.png
33 ###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
34
35 ###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
36 ###PERL_DATA_COIN_PATH:     DATA_COIN_PATH     = /botm/data/bsta/coincidence
37 ###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
38 ###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
39 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
40 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
41 ###PERL_DATA_STORY_PATH:    DATA_STORY_PATH    = /botm/data/bsta/story
42
43 ###PERL_WWW_PATH:           WWW_PATH           = /botm/www/1190/bsta/
44 ###PERL_WWW_INDEX_PATH:     WWW_INDEX_PATH     = /botm/www/1190/bsta/index.htm
45
46 ###PERL_WEBSITE:            WEBSITE            = 1190.bicyclesonthemoon.info
47 ###PERL_WEBSITE_NAME:       WEBSITE_NAME       = Bicycles on the Moon
48 ###PERL_FAVICON_PATH:       FAVICON_PATH       = /img/favicon.png
49
50 ###PERL_COIN_DATE:          COIN_DATE          = 13-Nov-2016 22:15
51 ###PERL_INTF_DATE:          INTF_DATE          = 28-Sep-2016 20:34
52
53 ###PERL_STORY_LENGTH:       STORY_LENGTH       = 16
54 ###PERL_PAGE_LENGTH:        PAGE_LENGTH        = 16
55 ###PERL_FIRSTPAGE_LENGTH:   FIRSTPAGE_LENGTH   = 4
56
57
58 my %http;
59 my %cgi;
60 my %story;
61 my %newstory;
62 my %settings;
63 my %state;
64 my %gotolist;
65
66 my $time = time();
67 srand ($time-$$);
68
69 my $method;
70 my $IP;
71 my $words;
72 my $color2;
73 my $lastip;
74 my $storyid;
75 my $turn;
76 my $message;
77 my $firstletter;
78 my $secondletter;
79 my $intfstate;
80 my $intfpass;
81 my $intfpause;
82 my $intfmode;
83 my $storypath;
84 my $storyfile;
85 my $storylock;
86 my @storylines;
87 my $ongstate;
88 my $page;
89
90
91 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
92 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
93
94 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
95         $method=$1;
96 }
97 else{
98         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);
99 }
100
101 %http = gethttpheader (\%ENV);
102 %cgi = getcgi($ENV{'QUERY_STRING'});
103
104 if ($method eq 'POST') {
105         if ($http{'content-type'} eq 'application/x-www-form-urlencoded') {
106                 my %cgipost=getcgi( <STDIN> );
107                 foreach my $ind (keys %cgipost) {
108                         $cgi{$ind}=$cgipost{$ind};
109                 }
110         }
111         # multipart not supported
112         else{
113                 exit failpage("Status: 415 Unsupported Media Type\n","415 Unsupported Media Type","Unsupported Content-type: $http{'content-type'}.");
114         }
115 }
116
117 if ($ENV{'PATH_INFO'} =~ /^\/(.+)$/) {
118         $page=int($1);
119 }
120 else {
121         $page=0;
122 }
123
124 if ($ENV{'HTTP_X_FORWARDED_FOR'} =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/) {
125         $IP=$1;
126 }
127 elsif ($ENV{'REMOTE_ADDR'} =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/) {
128         $IP=$1;
129 }
130 else {
131         $IP='0.0.0.0';
132 }
133
134 if ($cgi{'words'} ne '') {
135         $words=$cgi{'words'};
136 }
137
138 %settings=readdatafile(DATA_SETTINGS_PATH);
139 %state=readdatafile(DATA_STATE_PATH);
140 $ongstate=int($state{'state'});
141
142 $storylock=0;
143 if (open ($storyfile,"+<",DATA_STORY_PATH)){
144         $storylock=1;
145         if (flock($storyfile,2)) {
146                 $storylock=2;
147         }
148         %story=readdatafile($storyfile);
149         
150         if ($story{'lastip'} =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/) {
151                 $lastip=$1;
152         }
153         else {
154                 $lastip='0.0.0.0';
155         }
156         
157         $storyid = int($story{'id'});
158         $intfpass = int($story{'pass'});
159         $intfstate = int($story{'state'});
160         $intfmode = $intfstate;
161         $intfpause = $intfstate & 1;
162         if ($intfpause) {
163                 $intfmode -= 1;
164         }
165         
166         if ($IP ne $lastip) {
167                 $turn = 1;
168         }
169         else {
170                 $turn = 0       ;
171         }
172         
173         if($words =~ /^bstaaaclear(all)?$/ || $intfstate < 0) {
174                 if($words eq 'bstaaaclearall' || $intfstate < -1) {
175                         $story{'id'}=0;
176                 }
177                 $story{'content'}='';
178                 $story{'lastip'}='0.0.0.0';
179                 $story{'letter'}='';
180                 $story{'pass'}='0';
181                 $story{'state'}='0';
182                 $turn=0;
183                 if($ongstate == 0) {
184                         writeindex(WWW_INDEX_PATH,0,0,0);
185                 }
186                 writedatafile($storyfile,%story);
187         }
188         
189         if ($words ne '') {
190                 if (!$turn) {
191                         $message = "It's not your turn.";
192                 }
193                 else {
194                         if ($words =~ /^([!"\(\),\.:;\?][ \t]*)?([A-Za-z][A-Za-z'\-]*[A-Za-z']?)([!"\(\),\.:;\? \t][ \t]*)([A-Za-z][A-Za-z'\-]*[A-Za-z']?)([!"\(\),\.:;\?]?[ \t]*)$/) {
195                                 
196                                 $firstletter = lc(substr($2,0,1));
197                                 $secondletter = lc(substr($4,0,1));
198                                 if (($firstletter ne $story{'letter'})&&($story{'letter'} ne '')) {
199                                         $message = 'The first word must start with '.uc($story{'letter'}).'.';
200                                 }
201                                 elsif ($firstletter eq $secondletter) {
202                                         $message = 'The second word can\'t also start with '.uc($firstletter).'.';
203                                 }
204                                 else {
205                                         $story{'content'} = $story{'content'} . $words."\n";
206                                         $turn = 0;
207                                         $story{'lastip'} = $IP;
208                                         $story{'letter'} = $secondletter;
209                                         
210                                         if ($cgi{'next'} ne '') {
211                                                 if (split(/\r?\n/,$story{'content'}) >= (STORY_LENGTH-1)) {
212                                                         $storypath = DATA_STORY_PATH.$storyid;
213                                                         writedatafile($storypath,%story);
214                                                         $newstory{'id'} = $storyid + 1;
215                                                         $newstory{'letter'}='';
216                                                         $newstory{'lastip'}=$IP;
217                                                         $newstory{'content'}='';
218                                                         $newstory{'pass'}='0';
219                                                         $newstory{'state'}='0';
220                                                         $intfstate=0;
221                                                         $intfpass=0;
222                                                         $intfmode=0;
223                                                         $intfpause=0;
224                                                         if($ongstate == 0) {
225                                                                 writeindex(WWW_INDEX_PATH,0,0,0);
226                                                         }
227                                                         writedatafile($storyfile,%newstory);
228                                                 }
229                                                 else {
230                                                         $message = 'To early to finish this wordgame.';
231                                                         writedatafile($storyfile,%story);
232                                                 }
233                                         }
234                                         else {
235                                                 if ($intfpass == 1){
236                                                         $intfpass = 2;
237                                                         $story{'pass'} = '2';
238                                                         if($ongstate == 0) {
239                                                                 writeindex(WWW_INDEX_PATH,2,0,0);
240                                                         }
241                                                 }
242                                                 elsif(lc($2).' '.lc($4) eq $settings{'unlock'}) {
243                                                         if ($intfpass == 0) {
244                                                                 if($ongstate == 0) {
245                                                                         my %framedata = readdatafile(DATA_PATH.0);
246                                                                         my %default = readdatafile(DATA_DEFAULT_PATH);
247                                                                         my $inpath;
248                                                                         my $outpath;
249                                                                         
250                                                                         $framedata{'ongtime'} = $time;
251                                                                         $gotolist{'title-0'} = $framedata{'title'};
252                                                                         $gotolist{'ongtime-0'} = $framedata{'ongtime'};
253                                                                         writedatafile(DATA_PATH.0,%framedata);
254                                                                         writedatafile(DATA_LIST_PATH,%gotolist);
255                                                                         
256                                                                         foreach my $ind (keys %default) {
257                                                                                 unless(defined($framedata{$ind})){
258                                                                                         $framedata{$ind}=$default{$ind};
259                                                                                 }
260                                                                         }
261                                                                         
262                                                                         $inpath = DATA_PATH.sprintf($settings{'frame'},0,$framedata{'ext'});
263                                                                         $outpath = WWW_PATH.sprintf($settings{'frame'},0,$framedata{'ext'});
264                                                                         
265                                                                         if(copy ($inpath, $outpath)) {
266                                                                                 $intfpass = 1;
267                                                                                 $intfstate = 0;
268                                                                                 $intfmode=0;
269                                                                                 $intfpause=0;
270                                                                                 $story{'pass'} = '1';
271                                                                                 $story{'state'} = '0';
272                                                                                 writeindex(WWW_INDEX_PATH,1,0,0);
273                                                                         }
274                                                                 }
275                                                                 else {
276                                                                         $message = "???";
277                                                                 }
278                                                         }
279                                                         else {
280                                                                 $message = 'The password has already been used in this story.';
281                                                         }
282                                                 }
283                                                 writedatafile($storyfile,%story);
284                                         }
285                                 }
286                         }
287                         else {
288                                 $message = 'Please, two words, not more, not less (some punctuation is allowed).';
289                         }
290                 }
291         }
292         elsif (($cgi{'s'} ne '') && ($intfpass==1) && ($ongstate == 0)) {
293                 $intfstate = int($cgi{'s'});
294                 if($intfstate > 63 || $intfstate <0) {
295                         $intfstate = 0;
296                 }
297                 $intfmode = $intfstate;
298                 $intfpause = $intfstate & 1;
299                 if ($intfpause) {
300                         $intfmode -= 1;
301                 }
302                 $story{'state'} = $intfstate;
303                 writeindex(WWW_INDEX_PATH,1,$intfmode,$intfpause);
304                 writedatafile($storyfile,%story);
305         }
306         @storylines = split(/\r?\n/,$story{'content'});
307         if(@storylines & 1) {
308                 $turn = !$turn;
309         }
310         
311         close($storyfile);
312 }
313
314 print "Content-type: text/html\n\n";
315 if($method eq 'HEAD') {
316         exit;
317 }
318
319 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
320 print '<html lang="en"><head>'."\n";
321 print '<title>Two words &bull; '.WEBSITE_NAME.'</title>'."\n";
322 print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
323 print '<link rel="icon" type="image/png" href="'.FAVICON_PATH.'">'."\n";
324 print '<link rel="stylesheet" href="'.CGI_CSS_PATH.'">'."\n";
325 print '</head><body>'."\n";
326 print '<a href="/"><img id="botmlogo" src="'.CGI_LOGO_PATH.'" alt="'.WEBSITE.'"></a>'."\n";
327 print '<div id="all">'."\n";
328
329 print '<div id="inst" class="ins">'."\n";
330
331 print '<div id="title">'."\n";
332 print '<H1 id="titletext">Two words</H1>'."\n";
333 print '</div>'."\n";
334
335 if ($page == 0) {
336         print '<div id="storypuzzle">'."\n";
337         for (my $i = 0; $i < @storylines; ++$i){
338                 print '<span class="'.($turn?'ni':'br').'">'.entityencode($storylines[$i]).'</span>'."\n";
339                 $turn = !$turn;
340         }
341         print '</div>'."\n";
342
343         print '<div id="command">'."\n";
344         if ($message ne '') {
345                 print '<span class="br">'.entityencode($message).'</span>'."\n";
346         }
347         
348         if ($turn) {
349                 print '<form method="post" action="'.CGI_2WORDS_PATH.'">'."\n";
350                 if ($message eq '') {
351                         if ($story{"content"} eq '') {
352                                 print 'Two words, please:<br>'."\n";
353                         }
354                         else {
355                                 print 'Please continue, two words:<br>'."\n";
356                         }
357                 }
358                 print '<input class="intx" type="text" name="words">'."\n";
359                 print '<input class="inbt" type="submit" value="enter">'."\n";
360                 if(@storylines >= (STORY_LENGTH-1)) {
361                         print '<input class="inbt" type="submit" name="next" value="enter and then start a new one">'."\n";
362                 }
363                 print '</form>'."\n";
364         }
365         else {
366                 if ($message eq '') {
367                         print 'Wait for it.'."\n";
368                 }
369         }
370         print '</div>'."\n";
371 }
372 elsif ($message ne '') {
373         print '<div id="command">'."\n";
374         print '<span class="br">'.entityencode($message).'</span>'."\n";
375         print '</div>'."\n";
376 }
377
378 if(($intfpass == 1) && ($ongstate == 0)) {
379         print '</div><div id="framespace">'."\n";
380         print '<table id="intftable" cellspacing="0" cellpadding="0"><tr class="intf">'."\n";
381         
382         print '<td colspan="6" class="intf"><img src="'.CGI_PATH.'intf-00';
383         if ($intfmode == 4) {
384                 print '_04';
385         }
386         elsif ($intfmode == 8) {
387                 print '_08';
388         }
389         elsif ($intfstate == 16) {
390                 print '_10';
391         }       
392         print'.gif" alt="" class="intf"></td>'."\n";
393         
394         print '</tr><tr class="intf">'."\n";
395         print '<td class="intf"><img src="'.CGI_PATH.'intf-20.gif" alt="o" class="intf"></td>'."\n";
396         print '<td class="intf"><a href="'.CGI_PATH.'2words?s='.($intfpause?17:16).'"><img src="'.CGI_PATH.'intf-10'.(($intfmode==16)?'_':'').'.gif" class="intf" alt="&gt"></td>'."\n";
397         print '<td class="intf"><a href="'.CGI_PATH.'2words?s='.($intfpause?9:8).'"><img src="'.CGI_PATH.'intf-08'.(($intfmode==8)?'_':'').'.gif" class="intf" alt="&lt;&lt;"></td>'."\n";
398         print '<td class="intf"><a href="'.CGI_PATH.'2words?s='.($intfpause?5:4).'"><img src="'.CGI_PATH.'intf-04'.(($intfmode==4)?'_':'').'.gif" class="intf" alt="&gt;&gt;"></td>'."\n";
399         print '<td class="intf"><a href="'.CGI_PATH.'2words?s='.($intfpause?0:0).'"><img src="'.CGI_PATH.'intf-02.gif" class="intf" alt="^"></td>'."\n";
400         print '<td class="intf"><a href="'.CGI_PATH.'2words?s='.($intfpause?$intfmode:$intfmode+1).'"><img src="'.CGI_PATH.'intf-01'.($intfpause?'_':'').'.gif" class="intf" alt="||"></td>'."\n";
401         print '</tr></table>'."\n";
402 }
403
404 print '</div><div id="insb" class="ins">'."\n";
405 print '<div id="undertext">'."\n";
406 for (my $i = $storyid-1-(($page!=0)?((($page-1)*PAGE_LENGTH)+FIRSTPAGE_LENGTH):0); $i > ($storyid-1-($page*PAGE_LENGTH)- FIRSTPAGE_LENGTH) && $i >= 0; --$i) {
407         $storypath = DATA_STORY_PATH.$i;
408         %newstory = readdatafile($storypath);
409         print '<p class="'.(($i&1)?'br':'ni').'" id="s'.$i.'">'.entityencode($newstory{'content'}).'</p>'."\n";
410 }
411
412 print '</div>'."\n";
413 print '<div id="underlinks">'."\n";
414 print '<a href="'.CGI_PATH.'">BSTA</a> | <a href="'.CGI_2WORDS_PATH.'">Once again</a>';
415 if(($storyid - ($page*PAGE_LENGTH)) - FIRSTPAGE_LENGTH > 0) {
416         print ' | <a href="'.CGI_2WORDS_PATH.'/'.($page+1).'">Before</a>';
417 }
418 if($page > 0) {
419         print ' | <a href="'.CGI_2WORDS_PATH.'/'.($page-1).'">Unbefore</a>';
420 }
421 if(($storyid - ($page*PAGE_LENGTH)) - FIRSTPAGE_LENGTH > 0) {
422         print ' | <a href="'.CGI_2WORDS_PATH.'/'.(int(($storyid - FIRSTPAGE_LENGTH - 1) / PAGE_LENGTH) + 1).'">Initially</a>';
423 }
424 if($turn) {
425         print ' | (Entering words here is irreversible. Your actions might be remembered forever. So please be reasonable.)';
426 }
427 print "\n";
428 print '</div>'."\n";
429
430 print '</div>'."\n";
431 print '</div>'."\n";
432 print '<a href="/" class="cz">'.WEBSITE.'</a>'."\n";
433 print '</body></html>'."\n";
434
435 sub writeindex {
436         (my $indexpath, my $pass, my $mode, my $pause) = @_;
437         my $indexfile;
438         my $indexof;
439                 
440         if(ref($indexpath)) {
441                 $indexfile=$indexpath;
442                 unless (seek($indexfile, 0, 0)) {
443                         return 0;
444                 }
445         }
446         else {
447                 unless (open ($indexfile, ">", $indexpath)) {
448                         return 0;
449                 }
450         }
451         
452         $indexof = CGI_PATH;
453         $indexof =~ s/\/$//g;
454         
455         my %coin = readdatafile(DATA_COIN_PATH);
456         
457         if ($pass != 1) {
458                 print $indexfile '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'."\n";
459                 print $indexfile '<html>'."\n";
460                 print $indexfile ' <head>'."\n";
461                 print $indexfile '  <title>Index of '.$indexof.'</title>'."\n";
462                 print $indexfile ' </head>'."\n";
463                 print $indexfile ' <body>'."\n";
464                 print $indexfile '<h1>Index of '.$indexof.'</h1>'."\n";
465                 print $indexfile '<table><tr><th><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr><tr><th colspan="5"><hr></th></tr>'."\n";
466                 print $indexfile '<tr><td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td><td><a href="/">Parent Directory</a></td><td>&nbsp;</td><td align="right">  - </td><td>&nbsp;</td></tr>'."\n";
467                 print $indexfile '<tr><td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td><td><a href="2words/">2words/</a></td><td align="right">'.INTF_DATE.'  </td><td align="right">  - </td><td>&nbsp;</td></tr>'."\n";
468                 print $indexfile '<tr><td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td><td><a href="coin/">coin/</a></td><td align="right">'.COIN_DATE.'  </td><td align="right">  - </td><td> Coincidence </td></tr>'."\n";
469                 print $indexfile '<tr><th colspan="5"><hr></th></tr>'."\n";
470                 print $indexfile '</table>'."\n";
471                 print $indexfile '<address>Apache/2.2.22 (Debian) Server at '.WEBSITE.' Port 80</address>'."\n";
472                 print $indexfile '</body></html>'."\n";
473         }
474         else {
475                 my %framedata;
476                 my %nextframedata;
477                 my %default;
478                 
479                 %framedata = readdatafile(DATA_PATH.0);
480                 %nextframedata = readdatafile(DATA_PATH.1);
481                 %default=readdatafile(DATA_DEFAULT_PATH);
482                 
483                 # if($mode == 16 && $pause) {
484                         # $framedata{'ongtime'} = $time;
485                         # writedatafile(DATA_PATH.0,%framedata);
486                 # }
487                 
488                 foreach my $ind (keys %default) {
489                         unless(defined($framedata{$ind})){
490                                 $framedata{$ind}=$default{$ind};
491                         }
492                         unless(defined($nextframedata{$ind})){
493                                 $nextframedata{$ind}=$default{$ind};
494                         }
495                 }
496                 
497                 
498                 print $indexfile '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
499                 print $indexfile '<html lang="en"><head>'."\n";
500                 print $indexfile '<title>';
501                 if($mode == 8 || $mode == 4) {
502                         print $indexfile 'Index of';
503                 }
504                 elsif($mode == 16) {
505                         print $indexfile entityencode($settings{'story'});
506                         if($pause) {
507                                 print $indexfile ' &bull; '.WEBSITE_NAME;
508                         }
509                 }
510                 else {
511                         print $indexfile 'Index of '.$indexof;
512                 }
513                 print $indexfile '</title>'."\n";
514                 print $indexfile '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
515                 print $indexfile '<link rel="icon" type="image/png" href="'.FAVICON_PATH.'">'."\n";
516                 print $indexfile '<link rel="stylesheet" href="'.CGI_CSS_PATH.'">'."\n";
517                 print $indexfile '</head><body>'."\n";
518                 print $indexfile '<a href="/"><img id="botmlogo" src="'.CGI_LOGO_PATH.'" alt="'.WEBSITE.'"></a>'."\n";
519                 print $indexfile '<div id="all">'."\n";
520                 
521                 print $indexfile '<div id="inst" class="ins">'."\n";
522                 
523                 print $indexfile '<div id="title">'."\n";
524                 print $indexfile '<H1 id="titletext">';
525                 if($mode == 8 || $mode == 4) {
526                         print $indexfile 'Index of';
527                 }
528                 elsif($mode == 16) {
529                         print $indexfile entityencode($settings{'story'});
530                 }
531                 else {
532                         print $indexfile 'Index of '.$indexof;
533                 }
534                 print $indexfile '</H1>'."\n";
535                 print $indexfile '</div>'."\n";
536                 
537                 print $indexfile '</div><div id="framespace">'."\n";
538                 print $indexfile '<img src="'.CGI_PATH;
539                 if($mode == 8) {
540                         print $indexfile 'intf-ll.gif'
541                 }
542                 elsif($mode == 4) {
543                         print $indexfile 'intf-pp.gif'
544                 }
545                 elsif($mode == 16) {
546                         if($pause) {
547                                 print $indexfile sprintf($settings{'frame'},0,$framedata{'ext'}).'" title="'.entityencode($framedata{'title'});
548                         }
549                         else {
550                                 print $indexfile 'intf-tr.gif'
551                         }
552                 }
553                 else {
554                         print $indexfile 'intf-kw.gif'
555                 }
556                 print $indexfile '" alt="0" id="frame">'."\n";
557                 
558                 print $indexfile '</div><div id="insb" class="ins">'."\n";
559                 print $indexfile '<div id="undertext">'."\n";
560                 if($mode == 8 || $mode == 4) {
561                         print $indexfile '<img src="/icons/back.gif" alt="[DIR]"> <a href="/">Parent Directory</a><br><img src="/icons/folder.gif" alt="[DIR]"> <a href="#">yyyyb/</a>'."\n";
562                 }
563                 elsif ($mode == 16) {
564                         if($pause) {
565                                 print $indexfile bb2ht($framedata{'content'})."\n";
566                         }
567                         else {
568                                 print $indexfile "...\n";
569                         }
570                 }
571                 else {
572                         print $indexfile '<img src="/icons/back.gif" alt="[DIR]"> <a href="/">Parent Directory</a><br>'."\n";
573                         print $indexfile '<img src="/icons/folder.gif" alt="[DIR]"> <a href="2words/">2words/</a> '.INTF_DATE.' - <br>'."\n";
574                         print $indexfile '<img src="/icons/folder.gif" alt="[DIR]"> <a href="coin/">coin/</a> '.COIN_DATE.' - '.entityencode($coin{'server'})."\n";
575                 }
576                 print $indexfile '</div>'."\n";
577                 
578                 print $indexfile '<div id="command">'."\n";
579                 if ($mode == 8) {
580                         print $indexfile '[<span class="br">EE</span>:<span class="br">EE</span>:<span class="br">EE</span>]'."\n";
581                 }
582                 elsif ($mode == 4) {
583                         print $indexfile '[<span class="ni">EE</span>:<span class="ni">EE</span>:<span class="ni">EE</span>]'."\n";
584                 }
585                 elsif ($mode == 16) {
586                         if($pause) {
587                                 print $indexfile '[<span class="br">00</span>:<span class="br">00</span>:<span class="br">00</span>]<br>'."\n";
588                                 print $indexfile '&gt;<a href="'.CGI_VIEWER_PATH.'/1">'.entityencode($nextframedata{'title'}).'</a>'."\n";
589                         }
590                         else {
591                                 print $indexfile '[<span class="ni">--</span>:<span class="ni">--</span>:<span class="ni">--</span>]<br>'."\n";
592                                 print $indexfile '&gt;...<span class="inp">_</span>'."\n";
593                         }
594                 }
595                 else {
596                 }
597                 print $indexfile '</div>'."\n";
598                 
599                 print $indexfile '</div>'."\n";
600                 
601                 print $indexfile '</div>'."\n";
602                 print $indexfile '<a href="/" class="cz">'.WEBSITE.'</a>'."\n";
603                 
604                 print $indexfile '</body></html>'."\n";
605         }
606         
607         unless (ref($indexpath)) {
608                 close ($indexfile);
609         }
610         else {
611                 truncate ($indexfile , tell($indexfile));
612         }
613         
614         return 1;
615 }