source: trunk/third/moira/gen/mailhosts.gen @ 26024

Revision 26024, 2.1 KB checked in by jdreed, 11 years ago (diff)
In moira: * Snapshot moira at r4113 to pick up new firewall-related changes
  • Property svn:executable set to *
Line 
1#!/moira/bin/perl -Tw
2
3# $Id: mailhosts.gen 4113 2013-05-28 14:29:10Z zacheiss $
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
12use 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 OR status = 10 OR status = 11 OR status = 12")
19    || exit $MR_DBMS_ERR;
20
21$sth->execute || exit $MR_DBMS_ERR;
22
23$tnow = localtime;
24umask 022;
25open(OUT, ">$outfile") || exit $MR_OCONFIG;
26
27print OUT "; MIT Network Host Table\n;\n";
28print OUT "; \t\$" . "Author:" . " \$\n";
29print OUT "; \t\$" . "Date:" . " \$\n";
30print OUT "; \t\$" . "Revision:" . " \$\n";
31print OUT "; Host table generated by Moira at $tnow\n;\n";
32
33while (($login, $potype, $exchange_id, $imap_id, $pop_id) = $sth->fetchrow_array) {
34    $login =~ tr/a-z/A-Z/;
35
36    if ($exchange_id != 0) {
37        $imap_filesystem = lc($login) . ".po";
38        ($mach_id) = $dbh->selectrow_array("SELECT mach_id FROM filesys " .
39                                           "WHERE label = " . $dbh->quote($imap_filesystem) .
40                                           "AND type = 'IMAP'");
41        if (defined($mach_id)) {
42            $pop_id = $mach_id;
43        } else {
44            ($mach_id) = $dbh->selectrow_array("SELECT mach_id FROM machine WHERE " .
45                                               "name = 'IMAP.EXCHANGE.MIT.EDU'");
46            if (defined($mach_id)) {
47                $pop_id = $mach_id;
48            }
49        }
50    }
51
52    if ($imap_id != 0) {
53        ($mach_id) = $dbh->selectrow_array("SELECT mach_id FROM filesys WHERE " .
54                                           "filsys_id = " . $dbh->quote($imap_id) .
55                                           " AND type = 'IMAP'");
56        if (defined($mach_id)) {
57            $pop_id = $mach_id;
58        }
59    }
60
61    ($hostname) = $dbh->selectrow_array("SELECT name FROM machine WHERE mach_id = " .
62                                        $dbh->quote($pop_id));
63
64
65    if ($pop_id != 0 && $potype ne "NONE") {
66
67        if (16 - length($login) > 8) {
68        $sp = "\t";
69    }
70    else {
71        $sp = "";
72    }
73    $row = "$login$sp\tIN\tCNAME\t$hostname.\n";
74    $row =~ s/\0//g;;
75    print OUT $row;
76}
77}
78
79close(OUT);
80$dbh->disconnect;
81
82exit 0;
Note: See TracBrowser for help on using the repository browser.