Тема: mpd5+freeradius2+mysql
Перевожу NAS'ы с mpd.secret и скриптов на сабж.
Скрипт для заливки mpd.secret в mysql:
#!/usr/bin/perl -w
use DBI;
my(%password, %ip);
open(FILE, "mpd.secret") or die 'Cannot open mpd.secret';
while (<FILE>) {
unless ( $_ =~ m/^#/ ) {
my @tmp = split(/\s+/, $_);
$password{$tmp[0]} = $tmp[1];
$ip{$tmp[0]} = $tmp[2];
}
}
close(FILE);
my $dsn = 'DBI:mysql:radius:localhost';
my $db_user_name = 'root';
my $db_password = 'your_sql_password123';
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
foreach my $login (sort keys %password) {
my $password_ = $password{$login};
my $ip_ = $ip{$login};
my $sth = $dbh->prepare(qq{INSERT INTO radcheck VALUES ('', "$login", 'Cleartext-Password', ':=', "$password_")});
$sth->execute();
$sth = $dbh->prepare(qq{INSERT INTO radreply VALUES ('', "$login", 'Framed-IP-Address', ':=', "$ip_")});
$sth->execute();
$sth = $dbh->prepare(qq{INSERT INTO radusergroup VALUES ("$login", 'users', 1)});
$sth->execute();
}