]> bicyclesonthemoon.info Git - ott/bsta/blobdiff - 2words.1.pl
Adapted for new config tool.
[ott/bsta] / 2words.1.pl
index 590d88b8711232b9deef8e0b1c5add8b49abc0e5..03ef99f741887a08baa28f7a704ff9266d359cfc 100644 (file)
@@ -1,54 +1,59 @@
-###PERL;
-#
+###RUN_PERL: #!/usr/bin/perl
+
 # /bsta/2words
 # 2words is generated from 2words.1.pl.
-# 09.01.2023
 #
 # The wordgame interface
 #
-#    Copyright (C) 2016 - 2017, 2023  Balthasar Szczepański
+# Copyright (C) 2016 - 2017, 2023  Balthasar Szczepański
 #
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU Affero General Public License as
-#    published by the Free Software Foundation, either version 3 of the
-#    License, or (at your option) any later version.
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
 #
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU Affero General Public License for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
 #use warnings;
-###LIB;
+###PERL_LIB: use lib /botm/lib/bsta
 use bsta_lib qw(failpage gethttpheader getcgi entityencode readdatafile writedatafile urlencode bb2ht);
 use  File::Copy;
 
-###STORY_PATH;
-###LOGO_PATH;
-###FAVICON_PATH;
-###WEBSITE;
-###WEBSITE_NAME;
-###CSS_PATH;
-###TWOWORDS_PATH;
-###CGI_PATH;
-###SETTINGS_PATH;
-###INDEX_PATH;
-###INTF_DATE;
-###DATA_PATH;
-###VIEWER_PATH;
-###DEFAULT_PATH;
-###STATE_PATH;
-###WWW_PATH;
-###STORY_LENGTH;
-###PAGE_LENGTH;
-###FIRSTPAGE_LENGTH;
-###COIN_PATH;
-###COIN_DATE;
-###LIST_PATH;
+###PERL_CGI_PATH:           CGI_PATH           = /bsta/
+###PERL_CGI_2WORDS_PATH:    CGI_2WORDS_PATH    = /bsta/2words
+###PERL_CGI_CSS_PATH:       CGI_CSS_PATH       = /bsta/bsta.css
+###PERL_CGI_LOGO_PATH:      CGI_LOGO_PATH      = /bsta/botmlogo.png
+###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
+
+###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
+###PERL_DATA_COIN_PATH:     DATA_COIN_PATH     = /botm/data/bsta/coincidence
+###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
+###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
+###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
+###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
+###PERL_DATA_STORY_PATH:    DATA_STORY_PATH    = /botm/data/bsta/story
+
+###PERL_WWW_PATH:           WWW_PATH           = /botm/www/1190/bsta/
+###PERL_WWW_INDEX_PATH:     WWW_INDEX_PATH     = /botm/www/1190/bsta/index.htm
+
+###PERL_WEBSITE:            WEBSITE            = 1190.bicyclesonthemoon.info
+###PERL_WEBSITE_NAME:       WEBSITE_NAME       = Bicycles on the Moon
+###PERL_FAVICON_PATH:       FAVICON_PATH       = /img/favicon.png
+
+###PERL_COIN_DATE:          COIN_DATE          = 13-Nov-2016 22:15
+###PERL_INTF_DATE:          INTF_DATE          = 28-Sep-2016 20:34
+
+###PERL_STORY_LENGTH:       STORY_LENGTH       = 16
+###PERL_PAGE_LENGTH:        PAGE_LENGTH        = 16
+###PERL_FIRSTPAGE_LENGTH:   FIRSTPAGE_LENGTH   = 4
+
 
 my %http;
 my %cgi;
@@ -84,7 +89,7 @@ my $page;
 
 
 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
-###PATH;
+###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
 
 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
        $method=$1;
@@ -130,12 +135,12 @@ if ($cgi{'words'} ne '') {
        $words=$cgi{'words'};
 }
 
-%settings=readdatafile(SETTINGS_PATH);
-%state=readdatafile(STATE_PATH);
+%settings=readdatafile(DATA_SETTINGS_PATH);
+%state=readdatafile(DATA_STATE_PATH);
 $ongstate=int($state{'state'});
 
 $storylock=0;
-if (open ($storyfile,"+<",STORY_PATH)){
+if (open ($storyfile,"+<",DATA_STORY_PATH)){
        $storylock=1;
        if (flock($storyfile,2)) {
                $storylock=2;
@@ -176,7 +181,7 @@ if (open ($storyfile,"+<",STORY_PATH)){
                $story{'state'}='0';
                $turn=0;
                if($ongstate == 0) {
-                       writeindex(INDEX_PATH,0,0,0);
+                       writeindex(WWW_INDEX_PATH,0,0,0);
                }
                writedatafile($storyfile,%story);
        }
@@ -204,7 +209,7 @@ if (open ($storyfile,"+<",STORY_PATH)){
                                        
                                        if ($cgi{'next'} ne '') {
                                                if (split(/\r?\n/,$story{'content'}) >= (STORY_LENGTH-1)) {
-                                                       $storypath = STORY_PATH.$storyid;
+                                                       $storypath = DATA_STORY_PATH.$storyid;
                                                        writedatafile($storypath,%story);
                                                        $newstory{'id'} = $storyid + 1;
                                                        $newstory{'letter'}='';
@@ -217,7 +222,7 @@ if (open ($storyfile,"+<",STORY_PATH)){
                                                        $intfmode=0;
                                                        $intfpause=0;
                                                        if($ongstate == 0) {
-                                                               writeindex(INDEX_PATH,0,0,0);
+                                                               writeindex(WWW_INDEX_PATH,0,0,0);
                                                        }
                                                        writedatafile($storyfile,%newstory);
                                                }
@@ -231,14 +236,14 @@ if (open ($storyfile,"+<",STORY_PATH)){
                                                        $intfpass = 2;
                                                        $story{'pass'} = '2';
                                                        if($ongstate == 0) {
-                                                               writeindex(INDEX_PATH,2,0,0);
+                                                               writeindex(WWW_INDEX_PATH,2,0,0);
                                                        }
                                                }
                                                elsif(lc($2).' '.lc($4) eq $settings{'unlock'}) {
                                                        if ($intfpass == 0) {
                                                                if($ongstate == 0) {
                                                                        my %framedata = readdatafile(DATA_PATH.0);
-                                                                       my %default = readdatafile(DEFAULT_PATH);
+                                                                       my %default = readdatafile(DATA_DEFAULT_PATH);
                                                                        my $inpath;
                                                                        my $outpath;
                                                                        
@@ -246,7 +251,7 @@ if (open ($storyfile,"+<",STORY_PATH)){
                                                                        $gotolist{'title-0'} = $framedata{'title'};
                                                                        $gotolist{'ongtime-0'} = $framedata{'ongtime'};
                                                                        writedatafile(DATA_PATH.0,%framedata);
-                                                                       writedatafile(LIST_PATH,%gotolist);
+                                                                       writedatafile(DATA_LIST_PATH,%gotolist);
                                                                        
                                                                        foreach my $ind (keys %default) {
                                                                                unless(defined($framedata{$ind})){
@@ -264,7 +269,7 @@ if (open ($storyfile,"+<",STORY_PATH)){
                                                                                $intfpause=0;
                                                                                $story{'pass'} = '1';
                                                                                $story{'state'} = '0';
-                                                                               writeindex(INDEX_PATH,1,0,0);
+                                                                               writeindex(WWW_INDEX_PATH,1,0,0);
                                                                        }
                                                                }
                                                                else {
@@ -295,7 +300,7 @@ if (open ($storyfile,"+<",STORY_PATH)){
                        $intfmode -= 1;
                }
                $story{'state'} = $intfstate;
-               writeindex(INDEX_PATH,1,$intfmode,$intfpause);
+               writeindex(WWW_INDEX_PATH,1,$intfmode,$intfpause);
                writedatafile($storyfile,%story);
        }
        @storylines = split(/\r?\n/,$story{'content'});
@@ -316,9 +321,9 @@ print '<html lang="en"><head>'."\n";
 print '<title>Two words &bull; '.WEBSITE_NAME.'</title>'."\n";
 print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
 print '<link rel="icon" type="image/png" href="'.FAVICON_PATH.'">'."\n";
-print '<link rel="stylesheet" href="'.CSS_PATH.'">'."\n";
+print '<link rel="stylesheet" href="'.CGI_CSS_PATH.'">'."\n";
 print '</head><body>'."\n";
-print '<a href="/"><img id="botmlogo" src="'.LOGO_PATH.'" alt="'.WEBSITE.'"></a>'."\n";
+print '<a href="/"><img id="botmlogo" src="'.CGI_LOGO_PATH.'" alt="'.WEBSITE.'"></a>'."\n";
 print '<div id="all">'."\n";
 
 print '<div id="inst" class="ins">'."\n";
@@ -341,7 +346,7 @@ if ($page == 0) {
        }
        
        if ($turn) {
-               print '<form method="post" action="'.TWOWORDS_PATH.'">'."\n";
+               print '<form method="post" action="'.CGI_2WORDS_PATH.'">'."\n";
                if ($message eq '') {
                        if ($story{"content"} eq '') {
                                print 'Two words, please:<br>'."\n";
@@ -399,22 +404,22 @@ if(($intfpass == 1) && ($ongstate == 0)) {
 print '</div><div id="insb" class="ins">'."\n";
 print '<div id="undertext">'."\n";
 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) {
-       $storypath = STORY_PATH.$i;
+       $storypath = DATA_STORY_PATH.$i;
        %newstory = readdatafile($storypath);
        print '<p class="'.(($i&1)?'br':'ni').'" id="s'.$i.'">'.entityencode($newstory{'content'}).'</p>'."\n";
 }
 
 print '</div>'."\n";
 print '<div id="underlinks">'."\n";
-print '<a href="'.CGI_PATH.'">BSTA</a> | <a href="'.TWOWORDS_PATH.'">Once again</a>';
+print '<a href="'.CGI_PATH.'">BSTA</a> | <a href="'.CGI_2WORDS_PATH.'">Once again</a>';
 if(($storyid - ($page*PAGE_LENGTH)) - FIRSTPAGE_LENGTH > 0) {
-       print ' | <a href="'.TWOWORDS_PATH.'/'.($page+1).'">Before</a>';
+       print ' | <a href="'.CGI_2WORDS_PATH.'/'.($page+1).'">Before</a>';
 }
 if($page > 0) {
-       print ' | <a href="'.TWOWORDS_PATH.'/'.($page-1).'">Unbefore</a>';
+       print ' | <a href="'.CGI_2WORDS_PATH.'/'.($page-1).'">Unbefore</a>';
 }
 if(($storyid - ($page*PAGE_LENGTH)) - FIRSTPAGE_LENGTH > 0) {
-       print ' | <a href="'.TWOWORDS_PATH.'/'.(int(($storyid - FIRSTPAGE_LENGTH - 1) / PAGE_LENGTH) + 1).'">Initially</a>';
+       print ' | <a href="'.CGI_2WORDS_PATH.'/'.(int(($storyid - FIRSTPAGE_LENGTH - 1) / PAGE_LENGTH) + 1).'">Initially</a>';
 }
 if($turn) {
        print ' | (Entering words here is irreversible. Your actions might be remembered forever. So please be reasonable.)';
@@ -447,7 +452,7 @@ sub writeindex {
        $indexof = CGI_PATH;
        $indexof =~ s/\/$//g;
        
-       my %coin = readdatafile(COIN_PATH);
+       my %coin = readdatafile(DATA_COIN_PATH);
        
        if ($pass != 1) {
                print $indexfile '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'."\n";
@@ -473,7 +478,7 @@ sub writeindex {
                
                %framedata = readdatafile(DATA_PATH.0);
                %nextframedata = readdatafile(DATA_PATH.1);
-               %default=readdatafile(DEFAULT_PATH);
+               %default=readdatafile(DATA_DEFAULT_PATH);
                
                # if($mode == 16 && $pause) {
                        # $framedata{'ongtime'} = $time;
@@ -508,9 +513,9 @@ sub writeindex {
                print $indexfile '</title>'."\n";
                print $indexfile '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
                print $indexfile '<link rel="icon" type="image/png" href="'.FAVICON_PATH.'">'."\n";
-               print $indexfile '<link rel="stylesheet" href="'.CSS_PATH.'">'."\n";
+               print $indexfile '<link rel="stylesheet" href="'.CGI_CSS_PATH.'">'."\n";
                print $indexfile '</head><body>'."\n";
-               print $indexfile '<a href="/"><img id="botmlogo" src="'.LOGO_PATH.'" alt="'.WEBSITE.'"></a>'."\n";
+               print $indexfile '<a href="/"><img id="botmlogo" src="'.CGI_LOGO_PATH.'" alt="'.WEBSITE.'"></a>'."\n";
                print $indexfile '<div id="all">'."\n";
                
                print $indexfile '<div id="inst" class="ins">'."\n";
@@ -580,7 +585,7 @@ sub writeindex {
                elsif ($mode == 16) {
                        if($pause) {
                                print $indexfile '[<span class="br">00</span>:<span class="br">00</span>:<span class="br">00</span>]<br>'."\n";
-                               print $indexfile '&gt;<a href="'.VIEWER_PATH.'/1">'.entityencode($nextframedata{'title'}).'</a>'."\n";
+                               print $indexfile '&gt;<a href="'.CGI_VIEWER_PATH.'/1">'.entityencode($nextframedata{'title'}).'</a>'."\n";
                        }
                        else {
                                print $indexfile '[<span class="ni">--</span>:<span class="ni">--</span>:<span class="ni">--</span>]<br>'."\n";