]> the.earth.li Git - autodns.git/blob - contrib/add-dns.pl
53a0e3ad1cbd47ac7b5e7051b74227a2880c9594
[autodns.git] / contrib / add-dns.pl
1 #!/usr/bin/perl -w
2 #
3 # add-dns.pl version 0.0.4alpha
4 # Dominic Hargreaves <dom@earth.li>
5 #
6 # Use this to tell nameservers supporting AutoDNS
7 # (http://www.earth.li/projectpurple/progs/autodns.html) to slave for you.
8 #
9 # Changelog:
10 #
11 # 03/07/01 dom: Added remotehelp and remove command for AutoDNS 0.0.4alpha
12 #               Changed to header to ns1 (from terry)
13 # 22/05/01 dom: Initial code completed for AutoDNS 0.0.3
14
15 use strict;
16 use IPC::Open3;
17
18 sub usage;
19
20 my $sendmail = "/usr/sbin/sendmail";
21 my $gpg = "/usr/bin/gpg";
22
23 my $to = 'dns-auto@tuschin.blackcatnetworks.co.uk,
24       dns-auto@ns1.blackcatnetworks.co.uk';
25 #my $to = 'dom';
26 my $from = 'Urchin Hostmaster <hostmaster@urchin.earth.li>';
27 my $cc = $from;
28 #my $cc = "";
29 my $keyid = "25B2616D";
30 my $command;
31 my @validcommands = qw(add remove list remotehelp);
32
33 # Only proceed if we have been given a valid command
34
35 die usage unless $ARGV[0];
36
37 my $ok = 0;
38 for (@validcommands) {
39    if ($ARGV[0] eq $_) {
40       $ok = 1;
41    }
42 }
43
44 die usage unless ($ok == 1);
45
46 # Open gpg filehandle
47
48 open3(\*GPGIN, \*GPGOUT, \*GPGERR, "$gpg --default-key $keyid --clearsign");
49
50 # Generate AutoDNS commands
51
52 print GPGIN "BEGIN\n";
53
54 $command = shift(@ARGV);
55
56 if ($command eq "list") {
57    print GPGIN "LIST\n";
58 } elsif ($command eq "remotehelp") {
59    print GPGIN "HELP\n";
60 } elsif ($command eq "add") {
61    for (@ARGV) {
62       print GPGIN "ADD $_\n";
63    }
64 } elsif ($command eq "remove") {
65    for (@ARGV) {
66       print GPGIN "DEL $_\n";
67    }
68 } else {
69    die usage;
70 }
71
72 print GPGIN "END\n";
73
74 close GPGIN;
75
76 my @gpgerror=<GPGERR>;
77 my @gpgout=<GPGOUT>;
78 close GPGERR;
79 close GPGOUT;
80
81 # Show user any error output from gpg...
82
83 for (@gpgerror) {
84    print STDERR $_;
85 }
86
87 # ...and what we intend to send
88
89 for (@gpgout) {
90    print $_;
91 }
92
93 # Ask user whether this is ok
94
95 print "Send this mail to:\n";
96 print $to;
97 print "\nand\n";
98 print $cc;
99 print "\n? (y/n): ";
100
101 my $mark = "0";
102 while (<STDIN>) {
103    if (/^y/i) {
104       $mark = "1";
105       last;
106    }
107    /^n/i and last;
108 }
109
110 if (!($mark eq "1")) {
111    print "Mail NOT sent.\n";
112    exit 1;
113 }
114
115 # Compose email
116
117 open MAIL, "|$sendmail -t -oi" or die $!;
118 print MAIL "From: $from\n" or die "Configuration error: $!";
119 print MAIL "To: $to\n" or die "Configuration error: $!";
120 print MAIL "Cc: $cc\n" if $cc;
121 print MAIL "Subject: AutoDNS commands\n";
122 print MAIL "X-Mailer: add-dns.pl 0.0.4alpha\n\n";
123
124 for (@gpgout) {
125    print MAIL $_;
126 }
127
128 print MAIL "\n";
129
130 # Send email
131
132 close MAIL;
133
134 sub usage {
135    print<<EOF;
136 Usage: $0 <command> [list of domains]
137
138 Possible commands: add: Adds domains
139                    remove: Removes domains
140                    list: Lists current domains
141                    remotehelp: Requests help from remote end
142
143 (You must have the private key $keyid in your gpg keyring
144 for this to work)
145 EOF
146
147 }
148