File: create_group.php3

package info (click to toggle)
freeradius 2.0.4%2Bdfsg-6
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 14,884 kB
  • ctags: 9,109
  • sloc: ansic: 73,328; sh: 12,392; php: 6,679; perl: 3,075; makefile: 1,316; sql: 1,197; python: 171; tcl: 35; sed: 23
file content (81 lines) | stat: -rw-r--r-- 2,607 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
require_once('../lib/functions.php3');
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
else{
	echo "<b>Could not include SQL library</b><br>\n";
	exit();
}
if ($config[sql_use_operators] == 'true'){
	include("../lib/operators.php3");
	$text = ',op';
	$passwd_op = ",':='";
}
$da_abort=0;
$op_val2 = '';
$link = @da_sql_pconnect($config);
if ($link){
	$Members = preg_split("/[\n\s]+/",$members,-1,PREG_SPLIT_NO_EMPTY);
	if (!empty($Members)){
		foreach ($Members as $member){
			$member = da_sql_escape_string($member);
			$res = @da_sql_query($link,$config,
			"INSERT INTO $config[sql_usergroup_table] (username,groupname)
			VALUES ('$member','$login');");
			if (!$res || !@da_sql_affected_rows($link,$res,$config)){
				echo "<b>Unable to add user $member in group $login: " . da_sql_error($link,$config) . "</b><br>\n";
				$da_abort=1;
			}
		}
	} else {
		$res = @da_sql_query($link,$config,
		"INSERT INTO $config[sql_usergroup_table] (groupname)
		VALUES ('$login');");
		if (!$res || !@da_sql_affected_rows($link,$res,$config)){
			echo "<b>Unable to create group $login: " . da_sql_error($link,$config) . "</b><br>\n";
			$da_abort=1;
		}
	}
	if (!$da_abort){
		foreach($show_attrs as $key => $attr){
			if ($attrmap["$key"] == 'none')
				continue;
			if ($attrmap["$key"] == ''){
				$attrmap["$key"] = $key;
				$attr_type["$key"] = 'replyItem';
				$rev_attrmap["$key"] = $key;
			}
			if ($attr_type["$key"] == 'checkItem'){
				$table = "$config[sql_groupcheck_table]";
				$type = 1;
			}
			else if ($attr_type["$key"] == 'replyItem'){
				$table = "$config[sql_groupreply_table]";
				$type = 2;
			}
			$val = $$attrmap["$key"];
			$val = da_sql_escape_string($val);
			$op_name = $attrmap["$key"] . '_op';
			$op_val = $$op_name;
			if ($op_val != ''){
				$op_val = da_sql_escape_string($op_val);
				if (check_operator($op_val,$type) == -1){
					echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
					coninue;
				}
				$op_val2 = ",'$op_val'";
			}
			if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
				continue;
			$res = @da_sql_query($link,$config,
			"INSERT INTO $table (attribute,value,groupname $text)
			VALUES ('$attrmap[$key]','$val','$login' $op_val2);");
			if (!$res || !@da_sql_affected_rows($link,$res,$config))
				echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
		}
		echo "<b>Group created successfully</b><br>\n";
	}
}
else
	echo "<b>Could not connect to SQL database</b><br>\n";
?>