update otp_hotp() to support 6,7,8,9 digit otp's
[freeradius.git] / dialup_admin / lib / sql / create_group.php3
1 <?php
2 require_once('../lib/functions.php3');
3 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
4         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
5 else{
6         echo "<b>Could not include SQL library</b><br>\n";
7         exit();
8 }
9 if ($config[sql_use_operators] == 'true'){
10         include("../lib/operators.php3");
11         $text = ',op';
12         $passwd_op = ",':='";
13 }
14 $da_abort=0;
15 $op_val2 = '';
16 $link = @da_sql_pconnect($config);
17 if ($link){
18         $Members = preg_split("/[\n\s]+/",$members,-1,PREG_SPLIT_NO_EMPTY);
19         if (!empty($Members)){
20                 foreach ($Members as $member){
21                         $member = da_sql_escape_string($member);
22                         $res = @da_sql_query($link,$config,
23                         "INSERT INTO $config[sql_usergroup_table] (username,groupname)
24                         VALUES ('$member','$login');");
25                         if (!$res || !@da_sql_affected_rows($link,$res,$config)){
26                                 echo "<b>Unable to add user $member in group $login: " . da_sql_error($link,$config) . "</b><br>\n";
27                                 $da_abort=1;
28                         }
29                 }
30         }
31         else
32                 echo "<b>Members list is empty!!</b><br>\n";
33         if (!$da_abort){
34                 foreach($show_attrs as $key => $attr){
35                         if ($attrmap["$key"] == 'none')
36                                 continue;
37                         if ($attrmap["$key"] == ''){
38                                 $attrmap["$key"] = $key;
39                                 $attr_type["$key"] = 'replyItem';
40                                 $rev_attrmap["$key"] = $key;
41                         }
42                         if ($attr_type["$key"] == 'checkItem'){
43                                 $table = "$config[sql_groupcheck_table]";
44                                 $type = 1;
45                         }
46                         else if ($attr_type["$key"] == 'replyItem'){
47                                 $table = "$config[sql_groupreply_table]";
48                                 $type = 2;
49                         }
50                         $val = $$attrmap["$key"];
51                         $val = da_sql_escape_string($val);
52                         $op_name = $attrmap["$key"] . '_op';
53                         $op_val = $$op_name;
54                         if ($op_val != ''){
55                                 $op_val = da_sql_escape_string($op_val);
56                                 if (check_operator($op_val,$type) == -1){
57                                         echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
58                                         coninue;
59                                 }
60                                 $op_val2 = ",'$op_val'";
61                         }
62                         if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
63                                 continue;
64                         $res = @da_sql_query($link,$config,
65                         "INSERT INTO $table (attribute,value,groupname $text)
66                         VALUES ('$attrmap[$key]','$val','$login' $op_val2);");
67                         if (!$res || !@da_sql_affected_rows($link,$res,$config))
68                                 echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
69                 }
70                 echo "<b>Group created successfully</b><br>\n";
71         }
72 }
73 else
74         echo "<b>Could not connect to SQL database</b><br>\n";
75 ?>