[1900] in Moira

home help back first fref pref prev next nref lref last post

mailhosts.gen

daemon@ATHENA.MIT.EDU (Mark Silis)
Fri Nov 30 14:15:16 2001

Date: Fri, 30 Nov 2001 14:13:53 -0500
From: Mark Silis <mark@MIT.EDU>
To: moiradev@MIT.EDU
Cc: postmaster@MIT.EDU
Message-ID: <20011130141353.A11549@I-fear-reorgs.MIT.EDU>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

This program is for generating the user to post office mappings for the
mail.mit.edu subdomain. It will be analagous to the hosts service.

-- Mark


--- /dev/null	Fri Nov 30 13:49:46 2001
+++ mailhosts.gen	Fri Nov 30 12:09:42 2001
@@ -0,0 +1,55 @@
+#!/moira/bin/perl -Tw
+
+# $Id$
+
+# The following exit codes are defined and MUST BE CONSISTENT with the
+# error codes the library uses:
+$MR_DBMS_ERR = 47836421;
+$MR_OCONFIG = 4783640;
+
+$outfile = '/moira/dcm/mailhosts.out';
+
+use DBI;
+use POSIX;
+
+$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
+    || exit $MR_DBMS_ERR;
+
+$sth = $dbh->prepare("SELECT f.label, m.address ".
+		     "FROM filesys f, machine m, nfsphys p, serverhosts s ".
+		     "WHERE s.service='POSTOFFICE' AND s.mach_id=f.mach_id ".
+		     "AND f.mach_id=m.mach_id AND f.type='IMAP' ".
+		     "AND f.createflg!=0 AND f.mach_id=p.mach_id ".
+		     "AND f.phys_id=p.nfsphys_id ".
+		     "ORDER BY f.label")
+    || exit $MR_DBMS_ERR;
+$sth->execute || exit $MR_DBMS_ERR;
+
+$tnow = ctime(time());
+umask 022;
+open(OUT, ">$outfile") || exit $MR_OCONFIG;
+
+print OUT "; MIT Network Host Table\n;\n";
+print OUT "; \t\$Author: \$\n";
+print OUT "; \t\$Date: \$\n";
+print OUT "; \t\$Revision: \$\n;\n";
+print OUT "; Host table generated by Moira at $tnow;\n";
+
+while (($label, $address) = $sth->fetchrow_array) {
+    $label =~ s/\.po$//;
+    $label =~ tr/a-z/A-Z/;
+    if (16 - length($label) > 8) {
+	$sp = "\t";
+    }
+    else {
+	$sp = "";
+    }
+    $row = "$label$sp\tIN\tA\t$address\n";
+    $row =~ s/\0//g;;
+    print OUT $row;
+}
+
+close(OUT);
+$dbh->disconnect;
+
+exit 0;

home help back first fref pref prev next nref lref last post