]> andersk Git - moira.git/blob - gen/mailhosts.gen
Revised EXCHANGE behavior.
[moira.git] / gen / mailhosts.gen
1 #!/moira/bin/perl -Tw
2
3 # $Id$
4
5 # The following exit codes are defined and MUST BE CONSISTENT with the
6 # error codes the library uses:
7 $MR_DBMS_ERR = 47836421;
8 $MR_OCONFIG = 4783640;
9
10 $outfile = '/moira/dcm/mailhosts.out';
11
12 use DBI;
13
14 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
15     || exit $MR_DBMS_ERR;
16
17 $sth = $dbh->prepare("SELECT login, potype, exchange_id, imap_id, pop_id FROM users WHERE " .
18                      "status = 1 OR status = 2 OR status = 5 OR status = 6") || exit $MR_DBMS_ERR;
19 $sth->execute || exit $MR_DBMS_ERR;
20
21 $tnow = localtime;
22 umask 022;
23 open(OUT, ">$outfile") || exit $MR_OCONFIG;
24
25 print OUT "; MIT Network Host Table\n;\n";
26 print OUT "; \t\$" . "Author:" . " \$\n";
27 print OUT "; \t\$" . "Date:" . " \$\n";
28 print OUT "; \t\$" . "Revision:" . " \$\n";
29 print OUT "; Host table generated by Moira at $tnow\n;\n";
30
31 while (($login, $potype, $exchange_id, $imap_id, $pop_id) = $sth->fetchrow_array) {
32     $login =~ tr/a-z/A-Z/;
33
34     if ($exchange_id != 0) {
35         $imap_filesystem = lc($login) . ".po";
36         ($mach_id) = $dbh->selectrow_array("SELECT mach_id FROM filesys " .
37                                            "WHERE label = " . $dbh->quote($imap_filesystem) .
38                                            "AND type = 'IMAP'");
39         if (defined($mach_id)) {
40             $pop_id = $mach_id;
41         } else {
42             ($mach_id) = $dbh->selectrow_array("SELECT mach_id FROM machine WHERE " .
43                                                "name = 'IMAP.EXCHANGE.MIT.EDU'");
44             if (defined($mach_id)) {
45                 $pop_id = $mach_id;
46             }
47         }
48     }
49
50     if ($imap_id != 0) {
51         ($mach_id) = $dbh->selectrow_array("SELECT mach_id FROM filesys WHERE " .
52                                            "filsys_id = " . $dbh->quote($imap_id) .
53                                            " AND type = 'IMAP'");
54         if (defined($mach_id)) {
55             $pop_id = $mach_id;
56         }
57     }
58
59     ($hostname) = $dbh->selectrow_array("SELECT name FROM machine WHERE mach_id = " .
60                                         $dbh->quote($pop_id));
61
62
63     if ($pop_id != 0 && $potype ne "NONE") {
64
65         if (16 - length($login) > 8) {
66         $sp = "\t";
67     }
68     else {
69         $sp = "";
70     }
71     $row = "$login$sp\tIN\tCNAME\t$hostname.\n";
72     $row =~ s/\0//g;;
73     print OUT $row;
74 }
75 }
76
77 close(OUT);
78 $dbh->disconnect;
79
80 exit 0;
This page took 0.496279 seconds and 5 git commands to generate.