Updating dictionary.erx based on Juniper documentation
[freeradius.git] / scripts / clients.pl
1 #!/usr/bin/env perl
2 #
3 #  Convert old-style "clients" file to new "clients.conf" format.
4 #
5 #  Usage: clients.pl clients [naslist] new-clients.conf
6 #       The "new-clients.conf" will be created if it does not exist.
7 #       If it does exist, it will be over-written.
8 #
9 #
10 #       $Id$
11 #
12 if (($#ARGV < 1) || ($#ARGV > 2)) {
13     print "Usage: clients.pl clients [naslist] new-clients.conf\n";
14     print "       The \"new-clients.conf\" will be created if it does not exist.\n";
15     print "       If it does exist, it will be over-written.\n";
16     exit(1);
17 }
18
19 $old = shift;
20 $new = shift;
21
22 if ($new =~ /naslist/) {
23     $naslist = $new;
24     $new = shift;
25 }
26
27 open OLD, "< $old" or die "Failed to open $old: $!\n";
28
29 while (<OLD>) {
30     next if (/^\s*\#/);
31     next if (/^\s*$/);
32
33     split;
34
35     $clients{$_[0]}{"secret"} = $_[1];
36 }
37 close OLD;
38
39 if (defined $naslist) {
40     open OLD, "< $naslist" or die "Failed to open $naslist: $!\n";
41
42     while (<OLD>) {
43         next if (/^\s*\#/);
44         next if (/^\s*$/);
45
46         split;
47
48         if (!defined $clients{$_[0]}) {
49             print "WARNING! client $_[0] is defined in naslist, but not in clients!";
50             next;
51         }
52
53         $clients{$_[0]}{"shortname"} = $_[1];
54         $clients{$_[0]}{"nastype"} = $_[2];
55     }
56 }
57
58 open NEW, "> $new" or die "Failed to open $new: $!\n";
59 foreach $client (keys %clients) {
60     print NEW "client $client {\n";
61     print NEW "\tsecret = ", $clients{$client}{"secret"}, "\n";
62     if (defined $clients{$client}{"shortname"}) {
63         print NEW "\tshortname = ", $clients{$client}{"shortname"}, "\n";
64         print NEW "\tnastype = ", $clients{$client}{"nastype"}, "\n";
65     }
66     print NEW "}\n";
67     print NEW "\n";
68 }