1

Тема: 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();
}
Мир, труд, май - модем, линукс, пиво
OS: FreeBSD 6.4 --> FreeBSD 7.4 --> FreeBSD 8.4
http://yoip.com.ua/_res/userbar/bl-bar.gif