File: functions.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 (154 lines) | stat: -rw-r--r-- 3,857 bytes parent folder | download | duplicates (6)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
function da_sql_limit($limit,$point,$config)
{
	switch($point){
		case 0:
			return '';
		case 1:
			return '';
		case 2:
			return "LIMIT $limit";
	}
}
function da_sql_host_connect($server,$config)
{
	if ($config[sql_use_http_credentials] == 'yes'){
		global $HTTP_SERVER_VARS;
		$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
		$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
	}
	else{
		$SQL_user = $config[sql_username];
		$SQL_passwd = $config[sql_password];
	}
	if ($config[sql_debug] == 'true')
		print "<b>DEBUG(SQL,PG DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd </b><br>\n";
	return @pg_connect("host=$server port=$config[sql_port]
			dbname=$config[sql_database] user=$SQL_user
			password=$SQL_passwd");
}

function da_sql_connect($config)
{
	if ($config[sql_use_http_credentials] == 'yes'){
		global $HTTP_SERVER_VARS;
		$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
		$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
	}
	else{
		$SQL_user = $config[sql_username];
		$SQL_passwd = $config[sql_password];
	}
	if ($config[sql_debug] == 'true')
		print "<b>DEBUG(SQL,PG DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd </b><br>\n";
	return @pg_connect("host=$config[sql_server] port=$config[sql_port]
			dbname=$config[sql_database] user=$SQL_user
			password=$SQL_passwd");
}

function da_sql_pconnect($config)
{
	if ($config[sql_use_http_credentials] == 'yes'){
		global $HTTP_SERVER_VARS;
		$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
		$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
	}
	else{
		$SQL_user = $config[sql_username];
		$SQL_passwd = $config[sql_password];
	}
	if ($config[sql_debug] == 'true')
		print "<b>DEBUG(SQL,PG DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd </b><br>\n";
	return @pg_pconnect("host=$config[sql_server] port=$config[sql_port]
			dbname=$config[sql_database] user=$SQL_user
			password=$SQL_passwd");
}

function da_sql_close($link,$config)
{
	@pg_close($link);
}

function da_sql_escape_string($string)
{
	return addslashes($string);
}

function da_sql_query($link,$config,$query)
{
	if ($config[sql_debug] == 'true')
		print "<b>DEBUG(SQL,PG DRIVER): Query: <i>$query</i></b><br>\n";
	return @pg_query($link,$query);
}

function da_sql_num_rows($result,$config)
{
	if ($config[sql_debug] == 'true')
		print "<b>DEBUG(SQL,PG DRIVER): Query Result: Num rows:: " . @pg_numrows($result) . "</b><br>\n";
	return @pg_numrows($result);
}

function da_sql_fetch_array($result,$config)
{
	$row = @pg_fetch_array($result,$config[tmp_pg_array_num][$result]++,PGSQL_ASSOC);
	if ($row && $config[sql_debug] == 'true'){
		print "<b>DEBUG(SQL,PG DRIVER): Query Result: <pre>";
		print_r($row);
		print  "</b></pre>\n";
	}
	if (!$row)
		$config[tmp_pg_array_num][$result] = 0;
	return $row;
}

function da_sql_affected_rows($link,$result,$config)
{
	if ($config[sql_debug] == 'true')
		print "<b>DEBUG(SQL,PG DRIVER): Query Result: Affected rows:: " . @pg_cmdtuples($result) . "</b><br>\n";
	return @pg_cmdtuples($result);
}

function da_sql_list_fields($table,$link,$config)
{
	$res = @pg_query($link,
		"select count(*) from pg_attribute where attnum > '0' and
		attrelid = (select oid from pg_class where relname='$table');");
	if ($res){
		$row = @pg_fetch_row($res,0);
		if ($row){
			if (!$row[0])
				return NULL;
			$fields[num] = $row[0];
		}
	}
	$res = @pg_query($link,
		"select attname from pg_attribute where attnum > '0' and
		attrelid = (select oid from pg_class where relname='$table');");
	if ($res)
		$fields[res]=$res;
	else
		return NULL;

	return $fields;
}

function da_sql_num_fields($fields,$config)
{
	if ($fields)
		return $fields[num];
}

function da_sql_field_name($fields,$num,$config)
{
	if ($fields){
		$row = @pg_fetch_row($fields[res],$num);
		if ($row)
			return $row[0];
	}
}

function da_sql_error($link,$config)
{
	return pg_errormessage($link);
}
?>