#!/usr/bin/perl
# addppp.pl - by Richard Windmann (richardw@mail.telegroup.com)
# Version 1.0, 03/13/97
# This is for use with Merit Radius, but it can be used for Livingston's
# Radius by simply taking out the line that says "killall -9 radiusd"
# This was written in a day, but I haven't found a bug so far. There
# is no checking, with the exception of the creation code/password, so
# it is your responsibility to enter information in all the fields.
# I am a Unix admin by trade, and not a perl/cgi programmer. So don't
# write me email saying my code sucks - there is nothing else out there,
# and this DOES work. However, if you'd like to point out something, or
# give me some advice, please by all means write me at the above address.
# Unless I find something better, I will continue to develop this. You
# will have to modify the paths in the script to suit the organization
# of your OS/machine and put in your creation code. Also, I've only
# tested it on Apache/FreeBSD 2.1.7 so far. Will test it on
# Linux/Solaris/SunOS/IRIX with Apache tomorrow.
# Get the input.
read(STDIN, $buffer, $ENV{CONTENT_LENGTH});
# Separate the form-inputs.
@forminputs = split(/&/, $buffer);
foreach $forminput (@forminputs)
{
# Separate the name of the input from its value.
($name, $value) = split(/=/, $forminput);
# Un-webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Results array
$results{$name}=$value;
}
# Check to see if account creation code is correct.
# Also, this is where you put the password or creation code.
if (!$results{'code'} || ($results{'code'} ne "put_password_here"))
{
# If the code is bad, tell them so!
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Wrong Account Creation Code</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<H1>Wrong Account Creation Code!</H1>";
print "You entered the wrong Account Creation Code!<br><br>";
print "You can <a href=\"http://www.yoursite.com/index.html\">try again</a>
if you like.";
print "</BODY>\n";
print "</HTML>\n";
}
else
{
# Backup the users file in TWO places before you fart with it!
system("cp /usr/private/etc/raddb/users /usr/backup/users~");
system("cp /usr/private/etc/raddb/users /usr/private/etc/raddb/users~");
open (USERS, ">>/usr/private/etc/raddb/users");
print USERS "# Name: $results{'firstname'} $results{'lastname'}\n";
print USERS "# Department $results{'department'}\n";
print USERS "# Added By $results{'ops'}\n";
print USERS "$results{'loginname'}\tPassword = $results{'password'}\n";
# Customize the following for your users or situation.
print USERS "\tPort-Limit = 1,\n";
print USERS "\tService-Type = Framed,\n";
print USERS "\tFramed-Protocol = PPP,\n";
print USERS "\tFramed-IP-Netmask = 255.255.255.0,\n";
print USERS "\tFramed-IP-Address = 255.255.255.254,\n";
print USERS "\tFramed-Routing = None,\n";
print USERS "\tFramed-MTU = 1500,\n";
print USERS "\tFramed-Compression = Van-Jacobson-TCP-IP,\n";
print USERS "\tIdle-Timeout = 3600\n";
print USERS "#\n";
close (USERS);
# Make a log for Christ's sake!
open (LOG, ">>/usr/private/etc/raddb/adduser.log");
print LOG "User Added $results{'loginname'} - $results{'firstname'}
$results{'lastname'} by $results{'ops'}\n";
close (LOG);
# Backup the new one for Christ's sake!
system("cp /usr/private/etc/raddb/users /usr/backup/users");
# Kill it if it is Merit for Christ's sake!
# Remove the following line if you're running Livingston Radius.
system("killall -9 radiusd");
# Tell them what a wonderful job they have done!
print "Location: http://www.yoursite.com/success.html\n\n";
exit;
}