When we have a tunneled MS-CHAP2-Success attribute, it goes
[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 $link = @da_sql_pconnect($config);
16 if ($link){
17         $Members = preg_split("/[\n\s]+/",$members,-1,PREG_SPLIT_NO_EMPTY);
18         if (!empty($Members)){
19                 foreach ($Members as $member){
20                         $member = da_sql_escape_string($member);
21                         $res = @da_sql_query($link,$config,
22                         "INSERT INTO $config[sql_usergroup_table] (username,groupname)
23                         VALUES ('$member','$login');");
24                         if (!$res || !@da_sql_affected_rows($link,$res,$config)){
25                                 echo "<b>Unable to add user $member in group $login: " . da_sql_error($link,$config) . "</b><br>\n";
26                                 $da_abort=1;
27                         }
28                 }
29         } else {
30                 $res = @da_sql_query($link,$config,
31                 "INSERT INTO $config[sql_usergroup_table] (groupname)
32                 VALUES ('$login');");
33                 if (!$res || !@da_sql_affected_rows($link,$res,$config)){
34                         echo "<b>Unable to create group $login: " . da_sql_error($link,$config) . "</b><br>\n";
35                         $da_abort=1;
36                 }
37         }
38         if (!$da_abort){
39                 foreach($show_attrs as $key => $attr){
40                         if ($attrmap["$key"] == 'none')
41                                 continue;
42                         if ($attrmap["$key"] == ''){
43                                 $attrmap["$key"] = $key;
44                                 $attr_type["$key"] = 'replyItem';
45                                 $rev_attrmap["$key"] = $key;
46                         }
47                         if ($attr_type["$key"] == 'checkItem'){
48                                 $table = "$config[sql_groupcheck_table]";
49                                 $type = 1;
50                         }
51                         else if ($attr_type["$key"] == 'replyItem'){
52                                 $table = "$config[sql_groupreply_table]";
53                                 $type = 2;
54                         }
55                         $val = $$attrmap["$key"];
56                         $val = da_sql_escape_string($val);
57                         $op_name = $attrmap["$key"] . '_op';
58                         $op_val = $$op_name;
59                         if ($op_val != ''){
60                                 if (check_operator($op_val,$type) == -1){
61                                         echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
62                                         coninue;
63                                 }
64                                 $op_val2 = ",'$op_val'";
65                         }
66                         if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
67                                 continue;
68                         $res = @da_sql_query($link,$config,
69                         "INSERT INTO $table (attribute,value,groupname $text)
70                         VALUES ('$attrmap[$key]','$val','$login' $op_val2);");
71                         if (!$res || !@da_sql_affected_rows($link,$res,$config))
72                                 echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
73                 }
74         }
75         echo "<b>Group created successfully</b><br>\n";
76 }
77 else
78         echo "<b>Could not connect to SQL database</b><br>\n";
79 ?>