IcculusFinger_archiveplans.pl
author Ryan C. Gordon <icculus@icculus.org>
Sat, 27 May 2017 13:48:17 -0400
changeset 93 7f693fc30b66
parent 86 afdfeb6893d6
permissions -rwxr-xr-x
PHP scripts that deal with new URL style.

Eventually we should dump index.php and just have the perl script do it. Laziness.
icculus@0
     1
#!/usr/bin/perl -w
icculus@10
     2
#-----------------------------------------------------------------------------
icculus@10
     3
#
icculus@10
     4
#  Copyright (C) 2002 Ryan C. Gordon (icculus@icculus.org)
icculus@10
     5
#
icculus@10
     6
#  This program is free software; you can redistribute it and/or modify
icculus@10
     7
#  it under the terms of the GNU General Public License as published by
icculus@10
     8
#  the Free Software Foundation; either version 2 of the License, or
icculus@10
     9
#  (at your option) any later version.
icculus@10
    10
#
icculus@10
    11
#  This program is distributed in the hope that it will be useful,
icculus@10
    12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
icculus@10
    13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
icculus@10
    14
#  GNU General Public License for more details.
icculus@10
    15
#
icculus@10
    16
#  You should have received a copy of the GNU General Public License
icculus@10
    17
#  along with this program; if not, write to the Free Software
icculus@10
    18
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
icculus@10
    19
#
icculus@10
    20
#-----------------------------------------------------------------------------
icculus@0
    21
icculus@0
    22
use strict;
icculus@0
    23
use warnings;
icculus@0
    24
use DBI;
icculus@0
    25
use File::Basename;
icculus@0
    26
icculus@10
    27
icculus@10
    28
#-----------------------------------------------------------------------------#
icculus@10
    29
#             CONFIGURATION VARIABLES: Change to suit your needs...           #
icculus@10
    30
#-----------------------------------------------------------------------------#
icculus@10
    31
icculus@0
    32
# The ever important debug-spew-enabler...
icculus@0
    33
my $debug = 0;
icculus@0
    34
icculus@0
    35
# File must have not been touch within this many minutes to be archived.
icculus@0
    36
#  This prevents archiving of a file that is in the middle of being edited.
icculus@12
    37
my $update_delay = 60 * 24;  # 24 hours old.
icculus@0
    38
icculus@28
    39
my $use_homedir = 0;
icculus@28
    40
my $fingerspace = '/fingerspace';
icculus@0
    41
icculus@0
    42
my $dbhost = 'localhost';
icculus@0
    43
my $dbuser = 'fingermgr';
icculus@0
    44
icculus@22
    45
# This is the maximum amount of data that IcculusFinger will read from a
icculus@22
    46
#  planfile. If this cuts off in the middle of an opened formatting tag,
icculus@22
    47
#  tough luck. IcculusFinger reads the entire planfile (up to the max you
icculus@22
    48
#  specify here) into memory before processing tags. Theoretically, this could
icculus@22
    49
#  be changed to handle tags on the fly, in which case users that would
icculus@22
    50
#  otherwise be over the limit might not be after processing sections, etc,
icculus@22
    51
#  but this is not the case here and now.
icculus@22
    52
#  Note that images specified inside [img] tags, etc are not counted towards
icculus@22
    53
#  this limit (since the web browser would be requesting those images
icculus@22
    54
#  separately), and only applies to the max bytes to be read directly from the
icculus@22
    55
#  planfile. This is merely here to prevent someone from symlinking their
icculus@22
    56
#  planfile to /dev/zero or something that could fill all available memory.
icculus@22
    57
#  This value is specified in bytes. Data read from the database has no
icculus@22
    58
#  limit, but theoretically, if it had to pass through this script to get into
icculus@22
    59
#  the database, this is a practical limit for that, too.
icculus@22
    60
my $max_plan_size = (100 * 1024);
icculus@22
    61
icculus@0
    62
# The password can be entered in three ways: Either hardcode it into $dbpass,
icculus@0
    63
#  (which is a security risk, but is faster if you have a completely closed
icculus@0
    64
#  system), or leave $dbpass set to undef, in which case this script will try
icculus@0
    65
#  to read the password from the file specified in $dbpassfile (which means
icculus@0
    66
#  that this script and the database can be touched by anyone with read access
icculus@0
    67
#  to that file), or leave both undef to have DBI get the password from the
icculus@0
    68
#  DBI_PASS environment variable, which is the most secure, but least
icculus@0
    69
#  convenient.
icculus@0
    70
my $dbpass = undef;
icculus@0
    71
my $dbpassfile = '/etc/IcculusFinger_dbpass.txt';
icculus@0
    72
icculus@0
    73
my $dbname = 'IcculusFinger';
icculus@0
    74
my $dbtable_archive = 'finger_archive';
icculus@0
    75
icculus@0
    76
my $post_to_icculusnews = 1;
icculus@27
    77
my $newshost     = 'localhost';
icculus@27
    78
my $newsauthor   = 'fingermaster';
icculus@27
    79
my $newsposter   = '/usr/local/bin/IcculusNews_post.pl';
icculus@27
    80
my $newspass     = undef;
icculus@27
    81
my $newspassfile = '/etc/IcculusFinger_newspass.txt';
icculus@0
    82
icculus@10
    83
#-----------------------------------------------------------------------------#
icculus@10
    84
#     The rest is probably okay without you laying yer dirty mits on it.      #
icculus@10
    85
#-----------------------------------------------------------------------------#
icculus@10
    86
icculus@21
    87
my $force_archive = undef;
icculus@70
    88
my $replace_archive = 0;
icculus@0
    89
icculus@83
    90
sub strip_tags {
icculus@83
    91
    my $t = shift;
icculus@83
    92
    1 while ($t =~ s/\&(?!amp)/&amp;/s);
icculus@83
    93
    1 while ($t =~ s/</&lt;/s);
icculus@83
    94
    1 while ($t =~ s/>/&gt;/s);
icculus@83
    95
    1 while ($t =~ s/\[title\](.*?)\[\/title\](\n|\r\n|\b)//is);
icculus@83
    96
    1 while ($t =~ s/\[wittyremark\](.*?)\[\/wittyremark\](\n|\r\n|\b)//is);
icculus@83
    97
    1 while ($t =~ s/\[b\](.*?)\[\/b\]/<b>$1<\/b>/is);
icculus@83
    98
    1 while ($t =~ s/\[u\](.*?)\[\/u\]/<u>$1<\/u>/is);
icculus@83
    99
    1 while ($t =~ s/\[i\](.*?)\[\/i\]/<i>$1<\/i>/is);
icculus@83
   100
    1 while ($t =~ s/\[center\](.*?)\[\/center\]/<center>$1<\/center>/is);
icculus@83
   101
    1 while ($t =~ s/\[img=(".*?")\].*?\[\/img\]/<img src=$1>/is);
icculus@83
   102
    1 while ($t =~ s/\[link=(".*?")\](.*?)\[\/link\]/<a href=$1>$2<\/a>/is);
icculus@83
   103
    1 while ($t =~ s/\[defaultsection=".*?"\](\n|\r\n|\b)//is);
icculus@83
   104
    1 while ($t =~ s/\[section=".*?"\](\n|\r\n|\b)(.*?)\[\/section\](\n|\r\n|\b)/$2/is);
icculus@83
   105
    1 while ($t =~ s/\[font(.*?)\](.*?)\[\/font\]/<font $1>$2<\/font>/is);
icculus@83
   106
    1 while ($t =~ s/\[noarchive\](.*?)\[\/noarchive\]/$1/is);
icculus@83
   107
    1 while ($t =~ s/\[markdown\](.*?)\[\/markdown\]/$1/is);
icculus@83
   108
    1 while ($t =~ s/\[metadata=\].*?\[\/metadata\]//is);
icculus@83
   109
    return $t;
icculus@83
   110
}
icculus@83
   111
icculus@0
   112
sub run_external_updater {
icculus@0
   113
    my $u = shift;
icculus@0
   114
    my $d = shift;
icculus@0
   115
    my $t = shift;
icculus@0
   116
icculus@0
   117
    if ($post_to_icculusnews) {
icculus@0
   118
        print("   posting to IcculusNews's submission queue...\n") if $debug;
icculus@83
   119
        $t = strip_tags($t);
icculus@0
   120
        print("   parsed markup tags...\n") if $debug;
icculus@0
   121
        my $newssubj = "Notable .plan update from $u";
icculus@27
   122
        $ENV{'ICCNEWS_POST_PASS'} = $newspass if defined $newspass;
icculus@27
   123
        my $rc = open(PH, "|$newsposter '$newshost' '$newsauthor' '1' '$newssubj' -");
icculus@0
   124
        if (not $rc) {
icculus@0
   125
            print("   No pipe to IcculusNews: $!\n");
icculus@0
   126
        } else {
icculus@0
   127
            print PH "<i>$u updated his .plan file at $d" .
icculus@0
   128
                     " with the following info:</i>\n<p>\n<pre>$t</pre>\n</p>\n";
icculus@0
   129
            close(PH);
icculus@0
   130
            print("   posted to submission queue.\n") if $debug;
icculus@0
   131
        }
icculus@0
   132
    }
icculus@0
   133
}
icculus@0
   134
icculus@0
   135
icculus@28
   136
sub enumerate_planfiles {
icculus@28
   137
    my $dirname = (($use_homedir) ? '/home' : $fingerspace);
icculus@28
   138
    opendir(DIRH, $dirname) or return(undef);
icculus@60
   139
    my @dirents = sort readdir(DIRH);
icculus@0
   140
    closedir(DIRH);
icculus@28
   141
icculus@28
   142
    my @retval;
icculus@28
   143
icculus@28
   144
    if ($use_homedir) {
icculus@28
   145
        foreach (@dirents) {
icculus@28
   146
            next if (($_ eq '.') or ($_ eq '..'));
icculus@28
   147
            push @retval, "/home/$_/.plan";
icculus@28
   148
        }
icculus@28
   149
    } else {
icculus@28
   150
        foreach (@dirents) {
icculus@28
   151
            next if (($_ eq '.') or ($_ eq '..'));
icculus@28
   152
            push @retval, "$fingerspace/$_";
icculus@28
   153
        }
icculus@28
   154
    }
icculus@28
   155
icculus@0
   156
    return(@retval);
icculus@0
   157
}
icculus@0
   158
icculus@0
   159
icculus@0
   160
sub get_sqldate {
icculus@0
   161
    my $mtime = shift;
icculus@0
   162
    my @t = localtime($mtime);
icculus@0
   163
    $t[5] = "0000" . ($t[5] + 1900);
icculus@0
   164
    $t[5] =~ s/.*?(\d\d\d\d)\Z/$1/;
icculus@0
   165
    $t[4] = "00" . ($t[4] + 1);
icculus@0
   166
    $t[4] =~ s/.*?(\d\d)\Z/$1/;
icculus@0
   167
    $t[3] = "00" . $t[3];
icculus@0
   168
    $t[3] =~ s/.*?(\d\d)\Z/$1/;
icculus@0
   169
    $t[2] = "00" . $t[2];
icculus@0
   170
    $t[2] =~ s/.*?(\d\d)\Z/$1/;
icculus@0
   171
    $t[1] = "00" . $t[1];
icculus@0
   172
    $t[1] =~ s/.*?(\d\d)\Z/$1/;
icculus@0
   173
    $t[0] = "00" . $t[0];
icculus@0
   174
    $t[0] =~ s/.*?(\d\d)\Z/$1/;
icculus@0
   175
icculus@0
   176
    return('' .
icculus@0
   177
           ($t[5]) . '-' . ($t[4]) . '-' . ($t[3]) . ' ' .
icculus@0
   178
           ($t[2]) . ':' . ($t[1]) . ':' . ($t[0])
icculus@0
   179
          );
icculus@0
   180
}
icculus@0
   181
icculus@0
   182
icculus@0
   183
sub read_plantext {
icculus@0
   184
    my $link = shift;
icculus@0
   185
    my $filename = shift;
icculus@0
   186
    my $retval = '';
icculus@0
   187
icculus@22
   188
    open(PLAN_IN, '<', $filename) or die("Can't open $filename: $!\n");
icculus@22
   189
    if (not defined read(PLAN_IN, $retval, $max_plan_size)) {
icculus@22
   190
        die("Couldn't read planfile: $!");
icculus@0
   191
    }
icculus@0
   192
    close(PLAN_IN);
icculus@0
   193
icculus@59
   194
    return($retval);
icculus@0
   195
}
icculus@0
   196
icculus@0
   197
icculus@0
   198
sub update_planfile {
icculus@0
   199
    my $link = shift;
icculus@0
   200
    my $filename = shift;
icculus@0
   201
icculus@0
   202
    if (-d $filename) {
icculus@0
   203
        return;
icculus@0
   204
    }
icculus@0
   205
icculus@0
   206
    my $modtime = (stat($filename))[9];
icculus@0
   207
    my $fdate = get_sqldate($modtime);
icculus@0
   208
    my $sql = '';
icculus@15
   209
    my $plantext = undef;
icculus@0
   210
icculus@28
   211
    my $user = $filename;
icculus@28
   212
    if ($use_homedir) {
icculus@28
   213
        $user =~ s#\A/home/(.*?)/\.plan\Z#$1#;
icculus@28
   214
    } else {
icculus@28
   215
        $user = basename($filename);
icculus@28
   216
    }
icculus@28
   217
icculus@70
   218
    my $replace = 0;
icculus@21
   219
    if ((defined $force_archive) and ($force_archive eq $user)) {
icculus@21
   220
        print(" * Forcing archival of $user\'s .planfile...\n") if $debug;
icculus@21
   221
        $user = $link->quote($user);
icculus@70
   222
        $replace = $replace_archive;
icculus@21
   223
    } else {
icculus@21
   224
        print(" * Examining $user\'s .planfile (modtime $fdate)...\n") if $debug;
icculus@0
   225
icculus@21
   226
        $user = $link->quote($user);
icculus@0
   227
icculus@21
   228
        # ... get date of the latest archived .plan ...
icculus@21
   229
        $sql = "select postdate, text from $dbtable_archive where username=$user" .
icculus@21
   230
               " order by postdate desc limit 1";
icculus@21
   231
        my $sth = $link->prepare($sql);
icculus@21
   232
        $sth->execute() or die "can't execute the query: $sth->errstr";
icculus@0
   233
icculus@21
   234
        my @row = $sth->fetchrow_array();
icculus@58
   235
        $sth->finish();
icculus@21
   236
        if (not @row) {
icculus@21
   237
            print("   Don't seem to have a previous entry ...\n") if $debug;
icculus@27
   238
            if ( (stat($filename))[7] == 0 ) {
icculus@27
   239
                print("    ...but the .plan is empty. Skipping.\n") if $debug;
icculus@27
   240
                return;
icculus@27
   241
            }
icculus@0
   242
        } else {
icculus@21
   243
            my $t = time();
icculus@21
   244
            if ($t < $modtime) {
icculus@21
   245
                print("   WARNING: file timestamp is in the future!\n") if $debug;
icculus@58
   246
                `touch -c -m '$filename'`;  # force to now, retest next time for content change.
icculus@58
   247
                return;
icculus@21
   248
            } else {
icculus@21
   249
                if ( ($t - $modtime) < ($update_delay * 60) ) {
icculus@21
   250
                    if ($debug) {
icculus@21
   251
                        my $oktime = int($update_delay - (($t - $modtime) / 60));
icculus@21
   252
                        print("   File update is too new to archive.\n");
icculus@21
   253
                        print("   (Try again in $oktime minutes.)\n");
icculus@21
   254
                    }
icculus@21
   255
                    return;
icculus@0
   256
                }
icculus@21
   257
            }
icculus@21
   258
icculus@21
   259
            if ($debug) {
icculus@21
   260
                my $x = $row[0];
icculus@21
   261
                print("   dates: [$x] [$fdate]\n");
icculus@58
   262
            } 
icculus@21
   263
icculus@58
   264
            if ($row[0] eq $fdate) {
icculus@21
   265
                print("   Matches archive timestamp. Skipping.\n") if $debug;
icculus@0
   266
                return;
icculus@21
   267
            } else {
icculus@21
   268
                $plantext = read_plantext($link, $filename);
icculus@21
   269
                my $plancpy = $plantext;
icculus@21
   270
    	        # Ditch [noarchive][/noarchive] tag blocks and strcmp rest.
icculus@58
   271
    	        1 while ($row[1] =~ s/\[noarchive\].*?\[\/noarchive\]//is);
icculus@58
   272
    	        1 while ($plancpy =~ s/\[noarchive\].*?\[\/noarchive\]//is);
icculus@21
   273
                if ($row[1] ne $plancpy) {
icculus@58
   274
    	            print("   Newer revision needs archiving.\n") if $debug;
icculus@21
   275
    	        } else {
icculus@58
   276
    	            print("   Newer revision only changed [noarchive] section(s). Skipping.\n") if ($debug);
icculus@21
   277
                    return;
icculus@21
   278
    	        }
icculus@21
   279
    	    }
icculus@0
   280
        }
icculus@0
   281
    }
icculus@0
   282
icculus@15
   283
    $plantext = read_plantext($link, $filename) if (not defined $plantext);
icculus@83
   284
icculus@83
   285
    my $metadatastr = $plantext;
icculus@83
   286
    my %metadata = ();
icculus@83
   287
    1 while ($metadatastr =~ s/\r\n/\n/s);
icculus@83
   288
    1 while ($metadatastr =~ s/\r/\n/s);
icculus@83
   289
    while ($metadatastr =~ s/\[metadata=\"(.*?)\"\](\n|\b)(.*?)\[\/metadata\](\n|\b)//) {
icculus@83
   290
        my $k = $1;
icculus@83
   291
        my $v = $3;
icculus@83
   292
        $k =~ tr/A-Z/a-z/;
icculus@83
   293
        $metadata{$k} = $v;
icculus@83
   294
    }
icculus@83
   295
icculus@83
   296
    my $summary = $metadata{'summary'};
icculus@83
   297
    if (not defined $summary) {
icculus@83
   298
        my $str = $metadatastr;
icculus@83
   299
        1 while ($str =~ s/\[title\](.*?)\[\/title\](\n|\r\n|\b)//is);
icculus@83
   300
        1 while ($str =~ s/\[wittyremark\](.*?)\[\/wittyremark\](\n|\r\n|\b)//is);
icculus@83
   301
        1 while ($str =~ s/\[b\](.*?)\[\/b\]/$1/is);
icculus@83
   302
        1 while ($str =~ s/\[u\](.*?)\[\/u\]/$1/is);
icculus@83
   303
        1 while ($str =~ s/\[i\](.*?)\[\/i\]/$1/is);
icculus@83
   304
        1 while ($str =~ s/\[center\](.*?)\[\/center\]/$1/is);
icculus@83
   305
        1 while ($str =~ s/\[img=(".*?")\].*?\[\/img\]//is);
icculus@83
   306
        1 while ($str =~ s/\[link=(".*?")\](.*?)\[\/link\]/$2/is);
icculus@83
   307
        1 while ($str =~ s/\[defaultsection=".*?"\](\n|\r\n|\b)//is);
icculus@83
   308
        1 while ($str =~ s/\[section=".*?"\](\n|\r\n|\b)(.*?)\[\/section\](\n|\r\n|\b)/$2/is);
icculus@83
   309
        1 while ($str =~ s/\[font(.*?)\](.*?)\[\/font\]/$2/is);
icculus@83
   310
        1 while ($str =~ s/\[noarchive\](.*?)\[\/noarchive\]/$1/is);
icculus@83
   311
        1 while ($str =~ s/\[markdown\](.*?)\[\/markdown\]/$1/is);
icculus@83
   312
        1 while ($str =~ s/\[metadata=".*?"\](\n|\r\n|\b).*?\[\/metadata\](\n|\r\n|\b)//is);
icculus@83
   313
icculus@83
   314
        $str =~ s/\A\s+//;
icculus@83
   315
        $str =~ s/\s+\Z//;
icculus@83
   316
        $str =~ s/\A(.*?)[\r\n].*\Z/$1/s;
icculus@83
   317
icculus@83
   318
        $str =~ s/\A\s+//;
icculus@83
   319
        $str =~ s/\s+\Z//;
icculus@83
   320
icculus@83
   321
        $summary = $str;
icculus@86
   322
        $summary =~ s/\A(.{1,80})\b.*\Z/$1/;	
icculus@86
   323
        $summary =~ s/\A(.{15,}?[.?!]).*\Z/$1/;  # gross.
icculus@83
   324
    }
icculus@83
   325
icculus@83
   326
    1 while ($summary =~ s/\r\n/ /s);
icculus@83
   327
    1 while ($summary =~ s/\r/ /s);
icculus@83
   328
    1 while ($summary =~ s/\n/ /s);
icculus@86
   329
icculus@86
   330
    if (length($summary) > 80) {   
icculus@86
   331
        $summary =~ s/\A(.{1,80})\b.*\Z/$1/;	
icculus@86
   332
        $summary =~ s/\A(.{15,}?[.?!]).*\Z/$1/;  # gross.
icculus@86
   333
    } 
icculus@86
   334
icculus@86
   335
    #print("SUMMARY: $summary\n"); exit(0);
icculus@83
   336
icculus@83
   337
    $summary = $link->quote($summary);
icculus@83
   338
icculus@15
   339
    my $ftext = $link->quote($plantext);
icculus@70
   340
icculus@70
   341
    my $lastpost = undef;
icculus@70
   342
    if ($replace) {
icculus@70
   343
        # ... get date of the latest archived .plan ...
icculus@70
   344
        $sql = "select postdate from $dbtable_archive where username=$user" .
icculus@70
   345
               " order by postdate desc limit 1";
icculus@70
   346
        my $sth = $link->prepare($sql);
icculus@70
   347
        $sth->execute() or die "can't execute the query: $sth->errstr";
icculus@70
   348
icculus@70
   349
        my @row = $sth->fetchrow_array();
icculus@70
   350
        $sth->finish();
icculus@70
   351
        if (not @row) {
icculus@70
   352
            $replace = 0;  # no previous entry.
icculus@70
   353
        } else {
icculus@70
   354
            $lastpost = $row[0];
icculus@70
   355
        }
icculus@70
   356
    }
icculus@70
   357
icculus@70
   358
    if ($replace) {
icculus@83
   359
        $sql = "update $dbtable_archive set text=$ftext, summary=$summary" .
icculus@70
   360
               " where $user=$user and postdate='$lastpost'";
icculus@70
   361
        $lastpost =~ s/\d\d\d\d\-(\d\d)-(\d\d) (\d\d)\:(\d\d)\:(\d\d)/$1$2$3$4.$5/;
icculus@70
   362
        `touch -c -m -t '$lastpost' '$filename'`;  # force file to this date.
icculus@70
   363
    } else {
icculus@83
   364
        $sql = "insert into $dbtable_archive (username, postdate, summary, text)" .
icculus@83
   365
               " values ($user, '$fdate', $summary, $ftext)";
icculus@70
   366
    }
icculus@0
   367
icculus@0
   368
    $link->do($sql) or die "can't execute the query: $link->errstr";
icculus@0
   369
    print("   Revision added to archives.\n") if $debug;
icculus@0
   370
icculus@15
   371
    run_external_updater(basename($filename), $fdate, $plantext);
icculus@0
   372
}
icculus@0
   373
icculus@0
   374
icculus@0
   375
# the mainline.
icculus@0
   376
icculus@21
   377
for (my $i = 0; $i < scalar(@ARGV); $i++) {
icculus@21
   378
    my $arg = $ARGV[$i];
icculus@21
   379
    $debug = 1, next if ($arg eq '--debug');
icculus@70
   380
    $replace_archive = 1, next if ($arg eq '--replace');
icculus@21
   381
    $force_archive = $ARGV[++$i], next if ($arg eq '--force');
icculus@21
   382
icculus@21
   383
    #$username = $arg, next if (not defined $username);
icculus@21
   384
    #$subject = $arg, next if (not defined $subject);
icculus@21
   385
    #$text = $arg, next if (not defined $text);
icculus@0
   386
    #etc.
icculus@21
   387
icculus@21
   388
    print("Unknown argument \"$arg\".\n");
icculus@0
   389
}
icculus@0
   390
icculus@70
   391
if (($replace_archive) and (not defined $force_archive)) {
icculus@70
   392
    die("--replace without --force")
icculus@70
   393
}
icculus@70
   394
icculus@28
   395
my @planfiles = enumerate_planfiles();
icculus@28
   396
die("Failed to enumerate planfiles: $!\n") if not @planfiles;
icculus@0
   397
icculus@0
   398
if (not defined $dbpass) {
icculus@0
   399
    if (defined $dbpassfile) {
icculus@0
   400
        open(FH, $dbpassfile) or die("failed to open $dbpassfile: $!\n");
icculus@0
   401
        $dbpass = <FH>;
icculus@0
   402
        chomp($dbpass);
icculus@0
   403
        $dbpass =~ s/\A\s*//;
icculus@0
   404
        $dbpass =~ s/\s*\Z//;
icculus@0
   405
        close(FH);
icculus@0
   406
    }
icculus@0
   407
}
icculus@0
   408
icculus@27
   409
if ((not defined $newspass) && (not defined $ENV{'ICCNEWS_POST_PASS'})) {
icculus@27
   410
    if (defined $newspassfile) {
icculus@27
   411
        open(FH, $newspassfile) or die("failed to open $newspassfile: $!\n");
icculus@27
   412
        $newspass = <FH>;
icculus@27
   413
        chomp($newspass);
icculus@27
   414
        $newspass =~ s/\A\s*//;
icculus@27
   415
        $newspass =~ s/\s*\Z//;
icculus@27
   416
        close(FH);
icculus@27
   417
    }
icculus@27
   418
}
icculus@27
   419
icculus@0
   420
my $dsn = "DBI:mysql:database=$dbname;host=$dbhost";
icculus@0
   421
print(" * Connecting to [$dsn] ...\n") if $debug;
icculus@0
   422
icculus@0
   423
my $link = DBI->connect($dsn, $dbuser, $dbpass, {'RaiseError' => 1});
icculus@0
   424
icculus@0
   425
foreach (@planfiles) {
icculus@28
   426
    update_planfile($link, "$_");
icculus@0
   427
}
icculus@0
   428
icculus@0
   429
$link->disconnect();
icculus@0
   430
exit 0;
icculus@0
   431
icculus@0
   432
# end of IcculusFinger_archiveplans.pl ...
icculus@0
   433