From 655f2c58574d7b1d6dc407282fe46e376ad47242 Mon Sep 17 00:00:00 2001 From: ijackson Date: Tue, 22 Jun 1999 17:45:34 +0000 Subject: [PATCH] Renewal/expiry. --- bcp5-registry.pl | 69 +++++++++++++++++++++++++++++++++++++++++++----- config.pl | 4 +++ database.pl | 2 +- notice.txt | 14 +++++----- 4 files changed, 75 insertions(+), 14 deletions(-) diff --git a/bcp5-registry.pl b/bcp5-registry.pl index 60a79bd..217beba 100755 --- a/bcp5-registry.pl +++ b/bcp5-registry.pl @@ -2,9 +2,21 @@ use POSIX; +@org_argv= @ARGV; +$needrenew= 0; + if ($ARGV[0] eq '--cgi') { shift @ARGV; $invokestyle= 'cgi'; +} elsif ($ARGV[0] eq '--expire-noconfirm') { + shift @ARGV; + $invokestyle= 'maintain'; +} elsif ($ARGV[0] eq '--expire-norenew') { + shift @ARGV; + $invokestyle= 'maintain'; + $needrenew= 1; +} elsif ($ARGV[0] =~ m/^--/) { + die "$ARGV[0] ?"; } elsif ($ENV{'SERVER_SOFTWARE'} =~ m/^Lynx/) { $invokestyle= 'lynxcgi'; } else { @@ -15,11 +27,11 @@ if ($invokestyle eq 'manual') { open DEBUG,">&STDERR" or die $!; } elsif ($invokestyle eq 'lynxcgi') { open DEBUG,">>debug.txt" or die $!; -} elsif ($invokestyle eq 'cgi') { +} elsif ($invokestyle eq 'cgi' || $invokestyle eq 'maintain') { open DEBUG,">/dev/null" or die $!; } -if ($invokestyle eq 'cgi') { +if ($invokestyle eq 'cgi' || $invokestyle eq 'maintain') { $scriptdir= shift @ARGV; $datadir= shift @ARGV; } else { @@ -27,7 +39,7 @@ if ($invokestyle eq 'cgi') { $datadir= '.'; } -if ($invokestyle ne 'manual') { +if (!($invokestyle eq 'manual' || $invokestyle eq 'maintain')) { $ct= 'BCP5REGISTRY_CONTENTTYPEDONE'; if (!$ENV{$ct}) { $|=1; @@ -47,7 +59,7 @@ require 'networks.pl'; require 'listdb.pl'; require 'passwords.pl'; -if ($invokestyle ne 'manual') { +if (!($invokestyle eq 'manual' || $invokestyle eq 'maintain')) { lock_database(); require 'cgi-lib.pl'; &ReadParse; @@ -90,7 +102,6 @@ $details= 0; $fulldetails= 0; $justcreated= 0; $justupdated= 0; -$needrenew= 0; $picked= 0; $listingall= 0; $passwordsent= 0; @@ -109,7 +120,53 @@ $listingoverlap= length $listoverlap; defined($now= time) or die $!; -if (length $in{'register'}) { +if ($invokestyle eq 'maintain') { + + lock_database(); + read_database(); + + if ($needrenew) { + $threshold_recent= $now - $renew_interval; + $threshold_old= $threshold_recent - $expire_norenew; + } else { + $threshold= $now - $expire_noconfirm; + } + + $changed= 0; + + foreach $id (keys %db) { + $ent= $db{$id}; + if ($needrenew) { + next unless $ent->{'changed'}; + next if $ent->{'changed'} >= $threshold_recent; + if ($ent->{'changed'} > $threshold_old) { + show_entry(); + send_password(); + print "sent renewal for $id ($net)\n" or die $!; + next; + } + show_entry(); + printf("deleted stale %s (%s, %x %x %x)\n", + $id, $net, $threshold_recent, $threshold_old, + $ent->{'changed'}) or die $!; + } else { + next if $ent->{'changed'}; + next if $ent->{'created'} >= $threshold; + show_entry(); + printf("deleted new %s (%s, %x %x)\n", + $id, $net, $threshold, $ent->{'created'}) or die $!; + } + delete $db{$id}; + $changed= 1; + } + + if ($changed) { + write_database(); + } + close STDOUT or die $!; + exit 0; + +} elsif (length $in{'register'}) { lock_database(); read_database(); diff --git a/config.pl b/config.pl index a9bb4c9..a87407e 100644 --- a/config.pl +++ b/config.pl @@ -7,4 +7,8 @@ $emailboxlen= 55; $nullemail= 'discard-all@chiark.greenend.org.uk'; $cgi= 'http://www.chiark.greenend.org.uk/ucgi/~ijackson/cam-grin'; +$expire_noconfirm= 48*3600; +$renew_interval= 356*86400; +$expire_norenew= 4*7*86400; + $ENV{'PATH'}= '/usr/local/bin:/bin:/usr/bin'; diff --git a/database.pl b/database.pl index 8bbd8fd..6204043 100644 --- a/database.pl +++ b/database.pl @@ -44,7 +44,7 @@ print DEBUG "locking\n"; die if $db_read; return if $ENV{$db_lock_env}; $ENV{$db_lock_env}= '1'; - exec 'with-lock-ex','-w','lockfile',"$0",@ARGV; + exec 'with-lock-ex','-w','lockfile',"$0",@org_argv; die "$ENV{'PATH'}: $!"; } diff --git a/notice.txt b/notice.txt index 0b10783..4fdf0fb 100644 --- a/notice.txt +++ b/notice.txt @@ -1,5 +1,5 @@ From: "@@@adminname@@@" (@@@whose@@@ G-RIN administrator) <@@@adminemail@@@> -To: "@@@contact@@@" <@@@email@@@> +To: "@@@contact@@@" <@@@alwaysemail@@@> @@@if:justcreated@@@ Subject: G-RIN entry @@@net@@@ created, please confirm @@ -19,8 +19,8 @@ mailed out for the following entry in the @@@whose@@@ G-RIN: Subject: G-RIN entry @@@net@@@ renewal @@@ The following database entry in the @@@whose@@@ G-RIN -is now due for renewal. It will be discarded from the database in few -weeks if you do not confirm it before then. +is now due for renewal. It will be discarded from the database +shortly if you do not confirm it before then. @@@endif:@@@ @@@ @@ -46,8 +46,8 @@ or you may simply visit the following URL for instant confirmation: @@@endif:@@@ @@@if:needrenew@@@ -You may renew it by using the G-RIN web page or you may simply visit -the following URL for instant renewal: +You can renew it by using the G-RIN web page or you may simply +visit the following URL for instant renewal: @@@endif:@@@ @@@if:justcreated|needrenew@@@ @@ -56,8 +56,8 @@ the following URL for instant renewal: @@@endif:@@@ @@@if:passwordsent@@@ -You may modify this entry via the G-RIN web page, or you may go -directly to the view/update page for this entry: +You can modify this entry via the G-RIN web pages, or you may +go directly to the view/update page for this entry: @@@ @@@cgi@@@?view=1&id=@@@id@@@&pw=@@@password@@@ @@@endif:@@@ -- 2.30.2