added radclient stuff
[ga4php.git] / authserver / usercmd.php
1 <?php
2 /*
3  * 
4  * 
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.
7  * 
8  * The simple web interface should also provide a mechanism for configuring freeradius itself
9  * 
10  */
11
12 require_once("lib/authClient.php");
13
14 $myAC = new GAAuthClient();
15
16 /*
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);
25
26  */
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 OTKID for a key\n";
39         echo "\tradauth: radauth <username> <pin> - for radius, only returns a code\n";
40         echo "\tsynctoken: synctoken <username> <tokenone> <tokentwo> - resync's a hotp token based on two token codes\n";
41         echo "\ttokentype: tokentype <username> - gets the token type for a user\n";
42         return 0;       
43 }
44
45 switch($argv[1]) {
46         case "tokentype":
47                 $msg = $myAC->getUserTokenType($argv[2]);
48                 echo "token type: $msg\n";
49                 break;
50         case "synctoken":
51                 if($myAC->syncUserToken($argv[2], $argv[3], $argv[4])) {
52                         echo "Token synced\n";
53                 } else {
54                         echo "Token not synced\n";
55                 }
56                 break;
57         case "radauth":
58                 if($myAC->authUserToken($argv[2], $argv[3])==1) {
59                         syslog(LOG_WARNING, "Got good request for user, ".$argv[2]);
60                         exit(0);
61                 } else {
62                         syslog(LOG_WARNING, "Got bad request for user, ".$argv[2]);
63                         exit(255);
64                 }
65                 break;
66         case "getotk":
67                 $val = $myAC->getOtkID($argv[2]);
68                 if($val === false) {
69                         echo "Failure\n";
70                 } else {
71                         echo "$val\n";
72                 }
73                 break;
74         case "auth":
75                 if($myAC->authUserToken($argv[2], $argv[3])==1) {
76                         echo "Pass!\n";
77                 } else {
78                         echo "Fail!\n";
79                 }
80                 break;
81         case "add":
82                 $return = $myAC->addUser($argv[2]);
83                 echo "Created user, ".$argv[2]." returned $return\n";
84                 break;
85         case "delete":
86                 $res = $myAC->deleteUser($argv[2]);
87                 if($res) {
88                         echo "Deleted\n";
89                 } else {
90                         echo "Failure?\n";
91                 }
92                 break;
93         case "authpass":
94                 $ret = $myAC->authUserPass($argv[2], $argv[3]);
95                 if($ret) echo "Authenticated\n";
96                 else echo "Failed\n";
97                 break;
98         case "setpass":
99                 $res = $myAC->setUserPass($argv[2], $argv[3]);
100                 if($res) echo "Password Set\n";
101                 else echo "Failure?\n";
102                 break;
103         case "setname":
104                 $ret = $myAC->setUserRealName($argv[2], $argv[3]);
105                 if($ret) echo "Real Name Set\n";
106                 else echo "Failure?\n";
107                 break;
108         case "settoken":
109                 $ret = $myAC->setUserToken($argv[2], $argv[3]);
110                 if($ret) echo "Token Set\n";
111                 else echo "Failure?\n";
112                 break;
113         case "settype":
114                 $ret = $myAC->setUserTokenType($argv[2], $argv[3]);
115                 if($ret) echo "Token Type Set\n";
116                 else echo "Failure?\n";
117                 break;
118         case "getusers":
119                 $users = $myAC->getUsers();
120                 foreach($users as $user) {
121                         if($user["realname"] != "") $realname = $user["realname"];
122                         else $realname = "- Not Set -";
123                         
124                         if($user["haspass"]) $haspass = "Yes";
125                         else $haspass = "No";
126                         
127                         if($user["hastoken"]) $hastoken = "Yes";
128                         else $hastoken = "No";
129                         
130                         echo "Username: ".$user["username"]."\n";
131                         echo "\tReal Name: ".$realname."\n";
132                         echo "\tHas Password?: ".$haspass."\n";
133                         echo "\tHas Token?: ".$hastoken."\n\n";
134                 }
135                 break;
136 }
137 ?>