I just wrote a Perl service hook for the Billmax billing and provision to use freeradius with MySQL. I am releasing this under GPL. I hope someone else will be able to use it as I found it very helpful. Just trying to give back. Any questions about this script type --help as a switch. Email me if you find bugs or have problems. Thanks for FreeRadius!!!
#!/usr/local/perl ################################################## # This is the radius add coded by Dustin Wish # for INDCO.Net on 02/22/05 for Billmax # Billing system email:[EMAIL PROTECTED] # Under the GPL license! IT's FREE!!! ################################################## use Getopt::Long; use DBI; use strict; my %table_hash; #this will be used to store the list of db(s)/table(s) we need to back up my @commands; #this will be the list of mysqldump commands to execute my ($dbname,$dsn,$dbh,$base_command,$command); #various vars we should scope. # set the defaults for the options array my %options = (name=>'',action=>'create',pass=>'',host=>'localhost', db=>'radius',user=>'root',login=>''); my $actions; #see if the user wants a list of their options. if(($#ARGV >= 0) && $ARGV[0] eq "--help") { print "########################################################################### #################\n", "# addraduser.pl Ver 0.1 for FreeRadius and Billmax on Linux\n", "# By Dustin Wish, released under permission from\n", "# INDCO.Net, Batesville AR. Modify it to your hearts content.\n", "# If you make a usefull addition, feel free to distribute it as long as this\n", "# help message remains intact. This software comes with NO WARRANTY and if it\n", "# blows up your system, it's not my fault!!! :-)\n", "# \n", "# addraduser.pl is a script to add, edit, remove users from FreeRadius for\n", "# BillMax -- all rights and trademarks reserved by their own parties.\n", "# For locking and performance issues I have added a table to the radius MySQL\n", "# structure called changed. I did this to keep track of changes made to the db\n", "# and to only do inserts and deletes. The create for this table is:\n", "#\n", "# # Database: radius\n", "# # Table: 'changed'\n", "# # \n", "# CREATE TABLE `changed` (\n", "# `changedID` int(11) NOT NULL auto_increment,\n", "# `currentusername` varchar(100) NOT NULL default '',\n", "# `newusername` varchar(100) NOT NULL default '',\n", "# `reason` varchar(100) NOT NULL default '',\n", "# `createdate` timestamp(14) NOT NULL,\n", "# PRIMARY KEY (`changedID`)\n", "# ) TYPE=MyISAM; \n", "#\n", "#\n", "########################################################################### ################\n", "\n", " Usage: mybackup [OPTIONS] \n", "\n", "\t-n, --name=\t\tUsername of radius user\n", "\t-a, --action=\t\tDefines the servive action to perform: \n", "\t create: it adds new radius user \n", "\t delete: removes radius user\n", "\t suspend: suspends their account\n", "\t enable: reenables their account\n", "\t rename: renames the user login\n", "\t update: updates the password \n", "\t-r, --rename=\t\tNew User name\n", "\t-p, --pass=\t\tPassword for radius user\n", "\t-h, --host=\t\tHost to connect to. Default=localhost\n", "\t-d, --database=\t\tDatabase to select from. Default=*==radius\n", "\t-u, --user=\t\tUser to conect as. Default=root\n", "\t-l, --login=\t\tPassword to connect to DB. Default is ''\n", "\n"; exit; } # Read in the options GetOptions( "name|n=s" => \$options{name}, "action|a=s" => \$options{action}, "rename|r=s" => \$options{rename}, "pass|p=s" => \$options{pass}, "host|h=s" => \$options{host}, "database|d=s" => \$options{db}, "user|u=s" => \$options{user}, "login|l:s" => \$options{login}, ); #connect to the db.. couldn't see how to use dbi without selecting a dbname so I used mysql.. $dsn = "DBI:mysql:host=$options{host};dbname=radius"; $dbh = DBI->connect($dsn, $options{user}, $options{login}) || die "Could not connect to database: $DBI::errstr"; ############################################# # # check for options pass to script # ############################################# $actions = $options{action}; if ($actions eq "create"){ my ($dbname) = shift; my ($sth,$query); #scope local variables. $query = "Insert into radcheck(UserName,Attribute,Value) Values ('$options{name}','password','$options{pass}')"; #print $query; $sth = $dbh->prepare($query); $sth->execute(); if($sth) { #call finish.. make perl happy.. $sth->finish(); } } elsif ($actions eq "delete"){ my ($dbname) = shift; my ($sth,$delquery); #scope local variables. $delquery = "Insert into changed(currentusername,reason) Values ('$options{name}','removal')"; $sth = $dbh->prepare($delquery); $sth->execute(); $delquery = ''; $delquery = "delete from radcheck where UserName = '$options{name}'"; $sth = $dbh->prepare($delquery); $sth->execute(); if($sth) { #call finish.. make perl happy.. $sth->finish(); } } elsif ($actions eq "enable"){ my ($dbname) = shift; my ($sth,$delquery); #scope local variables. $delquery = "Insert into changed(currentusername,reason) Values ('$options{name}','reenabled')"; $sth = $dbh->prepare($delquery); $sth->execute(); $delquery = ''; $delquery = "Insert into radcheck(UserName,Attribute,Value) Values ('$options{name}','password','$options{pass}')"; $sth = $dbh->prepare($delquery); $sth->execute(); if($sth) { #call finish.. make perl happy.. $sth->finish(); } } elsif ($actions eq "disable"){ my ($dbname) = shift; my ($sth,$delquery); #scope local variables. $delquery = "Insert into changed(currentusername,reason) Values ('$options{name}','disabled')"; $sth = $dbh->prepare($delquery); $sth->execute(); $delquery = ''; $delquery = "delete from radcheck where UserName = '$options{name}'"; $sth = $dbh->prepare($delquery); $sth->execute(); if($sth) { #call finish.. make perl happy.. $sth->finish(); } } elsif ($actions eq "rename"){ my ($dbname) = shift; my ($sth,$delquery); #scope local variables. $delquery = "Insert into changed(currentusername,newusername,reason) Values ('$options{name}','$options{rename}','disabled')"; $sth = $dbh->prepare($delquery); $sth->execute(); $delquery = ''; $delquery = "delete from radcheck where UserName = '$options{name}'"; $sth = $dbh->prepare($delquery); $sth->execute(); $delquery = ''; $delquery = "Insert into radcheck(UserName,Attribute,Value) Values ('$options{name}','password','$options{pass}')"; $sth = $dbh->prepare($delquery); $sth->execute(); if($sth) { #call finish.. make perl happy.. $sth->finish(); } } elsif ($actions eq "update"){ my ($dbname) = shift; my ($sth,$delquery); #scope local variables. $delquery = "delete from radcheck where UserName = '$options{name}'"; $sth = $dbh->prepare($delquery); $sth->execute(); $delquery = ''; $delquery = "Insert into radcheck(UserName,Attribute,Value) Values ('$options{name}','password','$options{pass}')"; $sth = $dbh->prepare($delquery); $sth->execute(); if($sth) { #call finish.. make perl happy.. $sth->finish(); } }else {print "Error: No action supplied!"} --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005 - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html