chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 30 Aug 2012 00:19:52 +0000 (01:19 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 30 Aug 2012 00:19:52 +0000 (01:19 +0100)
AwayMsg.pm
mason/main

index e20d6b6acc39f5b825a8fce78657bc45c79c4494..483345524ee2dedb1eae5678b601e78e97494b70 100644 (file)
@@ -5,13 +5,15 @@ use strict;
 use warnings;
 
 use DBI;
 use warnings;
 
 use DBI;
+use Data::Dumper;
 
 BEGIN {
     use Exporter ();
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
 
 BEGIN {
     use Exporter ();
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
-    @EXPORT      = qw(&db_connect &db_commit $dbh);
+    @EXPORT      = qw(db_connect db_commit expires2timet
+                      $dbh);
     %EXPORT_TAGS = ( );
     @EXPORT_OK   = qw();
 }
     %EXPORT_TAGS = ( );
     @EXPORT_OK   = qw();
 }
@@ -45,10 +47,23 @@ sub nooutput ($) {
     }
 }
 
     }
 }
 
+sub expires2timet ($) {
+    my ($str) = @_;
+    if ($str eq '') {
+       return undef;
+    }
+    open F, "-|", qw(date -d),'$str',qw(+%s) or die $!;
+    my $dtime = <F>;
+    $?=0; $!=0; close F or die "$? $!";
+    $dtime =~ m/^\d+$/ or die "$dtime ?";
+    return $dtime+0;
+}
 
 sub db_commit () {
 
 sub db_commit () {
-    nooutput("SELECT * FROM addresses LEFT JOIN config USING (emailaddr)");
-    nooutput("SELECT * FROM addresses LEFT JOIN texts USING (textid)");
+    nooutput("SELECT * FROM addresses LEFT JOIN config".
+            " USING (emailaddr) WHERE forwardfile IS NULL");
+    nooutput("SELECT * FROM addresses LEFT JOIN texts".
+            " USING (textid) WHERE name IS NULL");
     $dbh->do("COMMIT");
 }
 
     $dbh->do("COMMIT");
 }
 
index ec7c6536abc0158f524c84bcae49484c4778b5fd..5997c3af035faf164ad6dc953b3a72ce68143101 100755 (executable)
@@ -6,39 +6,44 @@ db_connect();
 <title>Email "out of office" setup</title>
 </head><body>
 <h1>Email "out of office" setup</h1>
 <title>Email "out of office" setup</title>
 </head><body>
 <h1>Email "out of office" setup</h1>
-<h2>Our email addresses</h2>
+<h2>Email addresses and their configuration</h2>
 
 
 <%perl>
 my %row;
 my $sth = $dbh->prepare(<<END);
 
 
 <%perl>
 my %row;
 my $sth = $dbh->prepare(<<END);
-    SELECT emailaddr, textid, expires
-     FROM        config
-       LEFT JOIN addresses USING (emailaddr)
+    SELECT *
+     FROM        addresses
+       LEFT JOIN config    USING (emailaddr)
        LEFT JOIN texts     USING (textid)
      ORDER BY emailaddr
 END
 </%perl>
 
        LEFT JOIN texts     USING (textid)
      ORDER BY emailaddr
 END
 </%perl>
 
-<table>
+<table rules="all">
 <tr>
 <td>Address</td>
 <tr>
 <td>Address</td>
-<td>O-o-o status</td>
+<td>Status</td>
 <td>Which message?</td>
 <td>Expiry date</td>
 </tr><tr>
 <td>Which message?</td>
 <td>Expiry date</td>
 </tr><tr>
+% $sth->execute();
 % while (my $row= $sth->fetchrow_hashref()) {
 <tr>
 <td><% $row->{'emailaddr'} |h %></td>
 %     if (defined $row->{'textid'}) {
 % while (my $row= $sth->fetchrow_hashref()) {
 <tr>
 <td><% $row->{'emailaddr'} |h %></td>
 %     if (defined $row->{'textid'}) {
-%         my $expiry = expires2timet($row->{'expires'});
-%        if ($expiry > time) {
-<td>active</td>
-%         } else {
+%         my $expires = expires2timet($row->{'expires'});
+%        if (defined($expires) && $expires < time) {
 <td>expired</td>
 <td>expired</td>
+%         } else {
+<td>active</td>
 %         }
 %         }
-<td><% $row->{'textid'} |h %></td>
+<td><% $row->{'name'} |h %></td>
+%         if (defined $expires) {
 <td><% $row->{'expires'} |h %></td>
 <td><% $row->{'expires'} |h %></td>
+%         } else {
+<td>never</td>
+%         }
 %     } else {
 <td>inactive</td>
 <td></td>
 %     } else {
 <td>inactive</td>
 <td></td>