Hi guys
as you may already have notice I am trying to learn PHP and practicing by installing PHP authentication function.
I have downloaded this function from some website written by a good person, unfortunately one of the function he used which so called "socket_fd_alloc()" in sockets extensions have been removed from php after ver 4.1.x and I am using 4.3.5, so I was hoping if we can change it to work it out? I couldn't find much about this function though I don't know much about php.
here's how code looks like:
thanks alot
Seyed
function RADIUS_AUTHENTICATION($username,$password)
{
global $debug;
global $SERVER_ADDR;
$radiushost="";
$sharedsecret="";
$suffix="";
init_radiusconfig(&$radiushost,&$radiusport,&$sharedsecret,&$suffix);
// check your /etc/services. Some radius servers
// listen on port 1812, some on 1645.
if ($radiusport==0)
$radiusport=getservbyname("radius","udp");
$nasIP="192.168.0.1";
$ip=gethostbyname($radiushost);
echo "IP= $ip, Nas IP ";
// 17 is UDP, formerly known as PROTO_UDP
$sock=socket_create(AF_INET,SOCK_DGRAM,17);
$retval=socket_connect($sock,$ip,$radiusport);
if (!preg_match("/@/",$username))
$username.=$suffix;
if ($debug)
echo "<br>radius-port: $radiusport<br>radius-host: $radiushost<br>username: $username<br>suffix: $suffix<hr>\n";
$RA=pack("CCCCCCCCCCCCCCCC", // auth code
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255);
$encryptedpassword=Encrypt($password,$sharedsecret,$RA);
$length=4+ // header
16+ // auth code
6+ // service type
2+strlen($username)+ // username
2+strlen($encryptedpassword)+ // userpassword
6+ // nasIP
6; // nasPort
$thisidentifier=rand()%256;
// v v v v v v v v
$data=pack("CCCCa*CCCCCCCCa*CCa*CCCCCCCCCCCC",
1,$thisidentifier,$length/256,$length%256, // header
$RA, // authcode
6,6,0,0,0,1, // service type
1,2+strlen($username),$username, // username
2,2+strlen($encryptedpassword),$encryptedpassword, // userpassword
4,6,$nasIP[0],$nasIP[1],$nasIP[2],$nasIP[3], // nasIP
5,3,0,0,0,0 // nasPort
);
socket_write($sock,$data,$length);
if ($debug)
echo "<br>writing $length bytes<hr>\n";
// Wait at most five seconds for the answer.
$set=socket_fd_alloc();
socket_fd_zero($set);
socket_fd_set($set,$sock);
echo "Set = $set, Sock = $Sock";
socket_select($set,$write=NULL,$except=NULL,5);
if (!socket_fd_isset($set,$sock)) {
echo "No answer from radius server, aborting\n";
exit(0);
}
socket_fd_free($set);
$readdata=socket_read($sock,1);
socket_close($sock);
return ord($readdata);
// 2 -> Access-Accept
// 3 -> Access-Reject
// See RFC2138 for this.
}
as you may already have notice I am trying to learn PHP and practicing by installing PHP authentication function.
I have downloaded this function from some website written by a good person, unfortunately one of the function he used which so called "socket_fd_alloc()" in sockets extensions have been removed from php after ver 4.1.x and I am using 4.3.5, so I was hoping if we can change it to work it out? I couldn't find much about this function though I don't know much about php.
here's how code looks like:
thanks alot
Seyed
function RADIUS_AUTHENTICATION($username,$password)
{
global $debug;
global $SERVER_ADDR;
$radiushost="";
$sharedsecret="";
$suffix="";
init_radiusconfig(&$radiushost,&$radiusport,&$sharedsecret,&$suffix);
// check your /etc/services. Some radius servers
// listen on port 1812, some on 1645.
if ($radiusport==0)
$radiusport=getservbyname("radius","udp");
$nasIP="192.168.0.1";
$ip=gethostbyname($radiushost);
echo "IP= $ip, Nas IP ";
// 17 is UDP, formerly known as PROTO_UDP
$sock=socket_create(AF_INET,SOCK_DGRAM,17);
$retval=socket_connect($sock,$ip,$radiusport);
if (!preg_match("/@/",$username))
$username.=$suffix;
if ($debug)
echo "<br>radius-port: $radiusport<br>radius-host: $radiushost<br>username: $username<br>suffix: $suffix<hr>\n";
$RA=pack("CCCCCCCCCCCCCCCC", // auth code
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255);
$encryptedpassword=Encrypt($password,$sharedsecret,$RA);
$length=4+ // header
16+ // auth code
6+ // service type
2+strlen($username)+ // username
2+strlen($encryptedpassword)+ // userpassword
6+ // nasIP
6; // nasPort
$thisidentifier=rand()%256;
// v v v v v v v v
$data=pack("CCCCa*CCCCCCCCa*CCa*CCCCCCCCCCCC",
1,$thisidentifier,$length/256,$length%256, // header
$RA, // authcode
6,6,0,0,0,1, // service type
1,2+strlen($username),$username, // username
2,2+strlen($encryptedpassword),$encryptedpassword, // userpassword
4,6,$nasIP[0],$nasIP[1],$nasIP[2],$nasIP[3], // nasIP
5,3,0,0,0,0 // nasPort
);
socket_write($sock,$data,$length);
if ($debug)
echo "<br>writing $length bytes<hr>\n";
// Wait at most five seconds for the answer.
$set=socket_fd_alloc();
socket_fd_zero($set);
socket_fd_set($set,$sock);
echo "Set = $set, Sock = $Sock";
socket_select($set,$write=NULL,$except=NULL,5);
if (!socket_fd_isset($set,$sock)) {
echo "No answer from radius server, aborting\n";
exit(0);
}
socket_fd_free($set);
$readdata=socket_read($sock,1);
socket_close($sock);
return ord($readdata);
// 2 -> Access-Accept
// 3 -> Access-Reject
// See RFC2138 for this.
}