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 | |
---|
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 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; |
---|
24 | umask 022; |
---|
25 | open(OUT, ">$outfile") || exit $MR_OCONFIG; |
---|
26 | |
---|
27 | print OUT "; MIT Network Host Table\n;\n"; |
---|
28 | print OUT "; \t\$" . "Author:" . " \$\n"; |
---|
29 | print OUT "; \t\$" . "Date:" . " \$\n"; |
---|
30 | print OUT "; \t\$" . "Revision:" . " \$\n"; |
---|
31 | print OUT "; Host table generated by Moira at $tnow\n;\n"; |
---|
32 | |
---|
33 | while (($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 | |
---|
79 | close(OUT); |
---|
80 | $dbh->disconnect; |
---|
81 | |
---|
82 | exit 0; |
---|