5 * This file is designed as a "script" extension to freeradius (or some such tool) for radius authentication.
6 * Also provided is a simple web interface for managing users in freeradius.
8 * The simple web interface should also provide a mechanism for configuring freeradius itself
12 require_once("lib/authClient.php");
14 $myAC = new GAAuthClient();
17 define("MSG_AUTH_USER_TOKEN", 1);
18 define("MSG_ADD_USER_TOKEN", 2);
19 define("MSG_DELETE_USER", 3);
20 define("MSG_AUTH_USER_PASSWORD", 4);
21 define("MSG_SET_USER_PASSWORD", 5);
22 define("MSG_SET_USER_REALNAME", 6);
23 define("MSG_SET_USER_TOKEN", 7);
24 define("MSG_SET_USER_TOKEN_TYPE", 8);
27 if(!isset($argv[1])) {
28 echo "Usage: ".$argv[0]." command username [args]\n";
29 echo "\tadd: add <username> - returns token code url\n";
30 echo "\tauth: auth <username> <passcode> - returns 0/1 for pass/fail\n";
31 echo "\tdelete: delete <username> - deletes user\n";
32 echo "\tauthpass: authpass <username> <password> - returns 0/1 for pass/fail\n";
33 echo "\tsetpass: setpass <username> <password> - sets a password for a user (x to remove pass)\n";
34 echo "\tsetname: setname <username> <realname> - sets the real name for a user\n";
35 echo "\tsettoken: settoken <username> <tokenkey> - sets the key (hex) for a token\n";
36 echo "\tsettype: settype <username> <tokentype> - sets a token type for a user\n";
37 echo "\tgetusers: getusers - gets a list of users\n";
38 echo "\tgetotk: getotk <username> - gets the OTK png for a key\n";
44 $val = $myAC->getOtkPng($argv[2]);
48 $hand = fopen("val.png", "w");
55 if($myAC->authUserToken($argv[2], $argv[3])==1) {
62 $return = $myAC->addUser($argv[2]);
63 echo "Created user, ".$argv[2]." returned $return\n";
66 $res = $myAC->deleteUser($argv[2]);
74 $ret = $myAC->authUserPass($argv[2], $argv[3]);
75 if($ret) echo "Authenticated\n";
79 $res = $myAC->setUserPass($argv[2], $argv[3]);
80 if($res) echo "Password Set\n";
81 else echo "Failure?\n";
84 $ret = $myAC->setUserRealName($argv[2], $argv[3]);
85 if($ret) echo "Real Name Set\n";
86 else echo "Failure?\n";
89 $ret = $myAC->setUserToken($argv[2], $argv[3]);
90 if($ret) echo "Token Set\n";
91 else echo "Failure?\n";
94 $ret = $myAC->setUserTokenType($argv[2], $argv[3]);
95 if($ret) echo "Token Type Set\n";
96 else echo "Failure?\n";
99 $users = $myAC->getUsers();
100 foreach($users as $user) {
101 if($user["realname"] != "") $realname = $user["realname"];
102 else $realname = "- Not Set -";
104 if($user["haspass"]) $haspass = "Yes";
105 else $haspass = "No";
107 if($user["hastoken"]) $hastoken = "Yes";
108 else $hastoken = "No";
110 echo "Username: ".$user["username"]."\n";
111 echo "\tReal Name: ".$realname."\n";
112 echo "\tHas Password?: ".$haspass."\n";
113 echo "\tHas Token?: ".$hastoken."\n\n";