chiark / gitweb /
wip login/logout handling
[nj-awaymsg.git] / AwayMsg.pm
index d6f63a5b3e42bb96769845f7a57602b4d3d541d4..72c594695e69c9bd1ad84bc2f4e2c4d13d6de7ae 100644 (file)
@@ -12,8 +12,7 @@ BEGIN {
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
-    @EXPORT      = qw(db_connect db_commit
-                      expires2timet expirestime2show
+    @EXPORT      = qw(db_connect db_commit www_begin hquote
                       $dbh);
     %EXPORT_TAGS = ( );
     @EXPORT_OK   = qw();
                       $dbh);
     %EXPORT_TAGS = ( );
     @EXPORT_OK   = qw();
@@ -21,16 +20,19 @@ BEGIN {
 
 our ($dbh);
 
 
 our ($dbh);
 
+sub www_begin ($$) {
+    my ($r,$m) = @_;
+    $r->header_out("Cache-Control: no-cache");
+}
+
+sub hquote ($) {
+    my ($raw) = @_;
+    return pack "H*", $raw;
+}
+
 sub db_connect () {
 sub db_connect () {
-    my $dbf;
-    foreach my $d (@INC) {
-       $dbf = "$d/away.db";
-       if (stat $dbf) {
-           chdir($d) or die $!;
-           last;
-       }
-    }
-    $dbh = DBI->connect("dbi:SQLite:away.db",
+    my $dbf = "$ENV{'NJAWAYMSG'}/data/away.db";
+    $dbh = DBI->connect("dbi:SQLite:$dbf",'','',
                         { AutoCommit=>0,
                           RaiseError=>1, ShowErrorStatement=>1
                         })
                         { AutoCommit=>0,
                           RaiseError=>1, ShowErrorStatement=>1
                         })
@@ -48,27 +50,6 @@ sub nooutput ($) {
     }
 }
 
     }
 }
 
-sub expires2timet ($) {
-    my ($str) = @_;
-    if ($str eq '' or $str =~ m/never/i) {
-       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 expirestime2show ($) {
-    my ($tt) = @_;
-    if (!defined $tt) {
-       return 'never';
-    } else {
-       return strftime("%Y-%m-%d %H:%M");
-    }
-}
-
 sub db_commit () {
     nooutput("SELECT * FROM addresses LEFT JOIN config".
             " USING (emailaddr) WHERE forwardfile IS NULL");
 sub db_commit () {
     nooutput("SELECT * FROM addresses LEFT JOIN config".
             " USING (emailaddr) WHERE forwardfile IS NULL");