]> andersk Git - moira.git/blob - gen/mailhosts.gen
892127e69b7e487aeee08bee9e1518eac1e1ced7
[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         ($mach_id) = $dbh->selectrow_array("SELECT mach_id FROM machine WHERE " .
36                                            "name = 'IMAP.EXCHANGE.MIT.EDU'");
37         if (defined($mach_id)) {
38             $pop_id = $mach_id;
39         }
40     }
41
42     if ($imap_id != 0) {
43         ($mach_id) = $dbh->selectrow_array("SELECT mach_id FROM filesys WHERE " .
44                                            "filsys_id = " . $dbh->quote($imap_id) .
45                                            " AND type = 'IMAP'");
46         if (defined($mach_id)) {
47             $pop_id = $mach_id;
48         }
49     }
50
51     ($hostname) = $dbh->selectrow_array("SELECT name FROM machine WHERE mach_id = " .
52                                         $dbh->quote($pop_id));
53
54
55     if ($pop_id != 0 && $potype ne "NONE") {
56
57         if (16 - length($login) > 8) {
58         $sp = "\t";
59     }
60     else {
61         $sp = "";
62     }
63     $row = "$login$sp\tIN\tCNAME\t$hostname.\n";
64     $row =~ s/\0//g;;
65     print OUT $row;
66 }
67 }
68
69 close(OUT);
70 $dbh->disconnect;
71
72 exit 0;
This page took 0.052286 seconds and 3 git commands to generate.