summaryrefslogtreecommitdiff
blob: 147fa28f8f2a0eb234ee796129956ccae4e18ba1 (plain)
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
from adodb import *
from modules.client import *

def get_client_groups(db,id)
	#options.  
	option = 'NO_RECURSE' #  * If $option == 'RECURSE' it will get all ancestor groups. defaults to only get direct parents.
	#	 * @return array Array of Group ID #'s, or FALSE if Failed
	print "get_object_groups(): Object ID: %s id Option: %s\n" % (id, option)
	object_type = 'axo'
	group_table = 'gacl_axo_groups'
	map_table = 'gacl_groups_axo_map'

	if not id:
		print "get_object_groups(): Object ID: (%s ) is empty, this is required" % str(id)
		return false
		

	if option == 'RECURSE':
	    query = """
			SELECT		DISTINCT g.id AS group_id
			FROM		%s gm
			LEFT JOIN	%s g1 ON g1.id=gm.group_id
			LEFT JOIN	%s g ON g.lft<=g1.lft AND g.rgt>=g1.rgt
			""" % (map_table,group_table,group_table)
	else:
	    query = """
	    	SELECT		gm.group_id
	    	FROM		%s gm
			""" % map_table
			
	query += " WHERE	gm.axo_id=%s " % str(id)
	print query
	cursor = db.conn.Execute(query)
	#fixme error check the return
	
	while (not cursor.EOF):
		row = cursor.FetchRow()
		retarr.append(row[0])
	
	return retarr


	
#			# Add the client into the gacl AXO table
#		db.conn.Execute('LOCK TABLES `gacl_axo_seq` WRITE');
#		# we add one to get the next valid free id
#		id = db.conn.GetRow('SELECT id FROM `gacl_axo_seq`')[0] + 1;
#		result = db.conn.Execute('UPDATE `gacl_axo_seq` SET id=%s', id);
#		db.conn.Execute('UNLOCK TABLES');
		
#		result2 = db.conn.Execute('INSERT INTO `gacl_axo` (id,section_value,value,order_value,name,hidden) VALUES (%s,%s,%s,%s,%s,%s)', (id,'clients',client_info['hostname'],1,client_info['hostname'],0) );

def get_group_clients(db, group):
	"""This function gets the members of groups. Returns an array
	containing those clients, empty otherwise"""

	# Missing recursive groups
	members = []
	query = "SELECT axo_id FROM gacl_groups_axo_map WHERE group_id = %s" % group
	print query
	cursor = db.conn.Execute(query)
	while (not cursor.EOF):
		members.append(cursor.FetchRow()[0])
	return members