5990e873f9502e0d893ccb885f0716496f214f35
[clearscm.git] / maps / bin / exportlist.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: exportlist.cgi,v $
5 # Revision:  $Revision: 1.1 $
6 # Description:  Export an address list
7 # Author:       Andrew@DeFaria.com
8 # Created:      Mon Jan 16 20:25:32 PST 2006
9 # Modified:     $Date: 2013/06/12 14:05:47 $
10 # Language:     perl
11 #
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 #
14 ################################################################################
15 use strict;
16
17 use FindBin;
18 local $0 = $FindBin::Script;
19
20 use lib "$FindBin::Bin/../lib";
21
22 use MAPS;
23 use MAPSWeb;
24
25 use CGI qw/:standard *table/;
26 use CGI::Carp "fatalsToBrowser";
27
28 my $type     = param('type');
29 my $userid   = cookie("MAPSUser");
30    $userid //= $ENV{USER};
31 my $Userid   = ucfirst $userid;
32
33 sub PrintList($) {
34   my ($type) = @_;
35
36   my $year = substr((scalar(localtime)), 20, 4);
37
38   print "\################################################################################\n";
39   print "\#\n";
40   print "\# MAPS:\t\tMail Authorization and Permission System (MAPS)\n";
41   print "\# $type.list:\t${Userid}'s $type.list file\n";
42   print "\# Exported:\t" . localtime . "\n";
43   print "\#\n";
44   print "\# Copyright 2001-" . $year . ", Andrew\@DeFaria.com, all rights reserved.\n";
45   print "\#\n";
46   print "\################################################################################\n";
47
48   FindList(
49     userid   => $userid,
50     type     => $type,
51   );
52
53   while (my $rec = GetList) {
54     $rec->{pattern}   //= '';
55     $rec->{domain}    //= '';
56     $rec->{comment}   //= '';
57     $rec->{hit_count} //= 0;
58     $rec->{last_hit}  //= '';
59     $rec->{retention} //= '';
60
61     if ($rec->{domain} eq '') {
62       print "$rec->{pattern},$rec->{comment},$rec->{hit_count},$rec->{last_hit},$rec->{retention}\n";
63     } else {
64       print "$rec->{pattern}\@$rec->{domain},$rec->{comment},$rec->{hit_count},$rec->{last_hit},$rec->{retention}\n";
65     } # if
66   } # while
67
68   return;
69 } # PrintList
70
71 # Main
72 SetContext($userid);
73
74 print header(
75   -type        => "application/octet-stream",
76   -attachment  => "$type.list",
77 );
78
79 PrintList($type);
80
81 exit;