update otp_hotp() to support 6,7,8,9 digit otp's
[freeradius.git] / dialup_admin / lib / sql / find.php3
1 <?php
2 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
3         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
4 else{
5         echo "<b>Could not include SQL library</b><br>\n";
6         exit();
7 }
8
9 unset($found_users);
10
11 $link = @da_sql_pconnect($config);
12 if ($link){
13         $search = da_sql_escape_string($search);
14         if (!is_numeric($max))
15                 $max = 10;
16         if ($max > 500)
17                 $max = 10;
18         if (($search_IN == 'name' || $search_IN == 'department' || $search_IN == 'username') && 
19                         $config[sql_use_user_info_table] == 'true'){
20                 $res = @da_sql_query($link,$config,
21                 "SELECT " . da_sql_limit($max,0,$config) . " username FROM $config[sql_user_info_table] WHERE
22                 lower($search_IN) LIKE '%$search%' " .
23                 da_sql_limit($max,1,$config) . " " . da_sql_limit($max,2,$config) . " ;");
24                 if ($res){
25                         while(($row = @da_sql_fetch_array($res,$config)))
26                                 $found_users[] = $row[username];
27                 }
28                 else
29                         "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
30         }
31         else if ($search_IN == 'radius' && $radius_attr != ''){
32                 require("../lib/sql/attrmap.php3");
33                 if ($attrmap["$radius_attr"] == ''){
34                         $attrmap["$radius_attr"] = $radius_attr;
35                         $attr_type["$radius_attr"] = 'replyItem';
36                 }
37                 $table = ($attr_type[$radius_attr] == 'checkItem') ? $config[sql_check_table] : $config[sql_reply_table];
38                 $attr = $attrmap[$radius_attr];
39                 $attr = da_sql_escape_string($attr);
40                 $res = @da_sql_query($link,$config,
41                 "SELECT " . da_sql_limit($max,0,$config) . " username FROM $table WHERE attribute = '$attr'
42                 AND value LIKE '%$search%' " . da_sql_limit($max,1,$config) . " " . da_sql_limit($max,2,$config) . " ;");
43                 if ($res){
44                         while(($row = @da_sql_fetch_array($res,$config)))
45                                 $found_users[] = $row[username];
46                 }
47                 else
48                         "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
49         }
50 }
51 else
52         echo "<b>Could not connect to SQL database</b><br>\n";
53 ?>