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

Revision 24319, 2.1 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from SVN.
  • Property svn:executable set to *
Line 
1#!/moira/bin/perl -Tw
2
3# $Id: mailhosts.gen 3956 2010-01-05 20:56:56Z 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") || exit $MR_DBMS_ERR;
19$sth->execute || exit $MR_DBMS_ERR;
20
21$tnow = localtime;
22umask 022;
23open(OUT, ">$outfile") || exit $MR_OCONFIG;
24
25print OUT "; MIT Network Host Table\n;\n";
26print OUT "; \t\$" . "Author:" . " \$\n";
27print OUT "; \t\$" . "Date:" . " \$\n";
28print OUT "; \t\$" . "Revision:" . " \$\n";
29print OUT "; Host table generated by Moira at $tnow\n;\n";
30
31while (($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
77close(OUT);
78$dbh->disconnect;
79
80exit 0;
Note: See TracBrowser for help on using the repository browser.