-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-radius-db.PL
executable file
·57 lines (54 loc) · 1.37 KB
/
install-radius-db.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl -w
# $Id: install-radius-db.PL,v 1.2 2004/12/18 04:51:17 andrew Exp $
my $source_dir = 'raddb';
my $raddb_dir = '/etc/raddb';
unless (-w $raddb_dir) {
# Cannot write to the raddb directory
unless (-x $raddb_dir) {
# Perhaps it just does not exists, so it can be created?
my @path = split('/', $raddb_dir);
pop(@path);
my $up = join('/', @path);
unless (-w $up and mkdir($raddb_dir) ) {
print STDERR "$raddb_dir directory does not exists and cannot be created\n";
print STDERR "Default RADIUS dictionaries are not installed.\n";
exit(0);
} else {
print "Created $raddb_dir\n";
}
} else {
print STDERR "Cannot copy the dictionary files in $raddb_dir\n";
print STDERR "Default RADIUS dictionaries are not installed.\n";
exit(0);
}
}
print "Installing the RADIUS dictionaries in $raddb_dir\n";
opendir(D, $source_dir);
while ($_ = readdir(D)) {
next if m/^\./;
my $dest = join('/', (split('/', $raddb_dir), $_));
print "Copying $_ to $dest ";
my $res = copyFile($source_dir.'/'.$_, $dest);
print $res ? ($res > 0 ? "- done." : "- ignored.") : "- error!";
print "\n";
}
closedir(D);
exit(0);
sub copyFile {
my ($f1, $f2) = @_;
unless (-f $f1) {
return -1;
}
if (-e $f2) {
return -1;
}
open(F1, $f1) or return;
unless (open(F2,">$f2")) {
close(F1); return;
}
while (<F1>) {
print F2 $_;
}
close(F1); close(F2);
return 1;
}