# -*- text -*-
#
#  ippool/mongo/queries.conf -- Mongo queries for rlm_sqlippool
#
#  $Id: eedf0a041da17ba48863bb2252939d33c2a09266 $

#
#  The IP Pool queries expect a result like:
#
#	{
#		pool_key: "bob"
#		pool_name: "my_pool"
#		expiry_time: xxx
#		value: "192.168.1.1"
#	}
#
#  i.e. the results are in "value", and not "framed_ip_address".
#
#  When using dynamic expansions such as "%{sql:... mongo query ...}",
#  Mongo uses a lot of curly brackets, {..}.  Any closing braces have
#  to be escaped as %}.  Sorry, that is a limitation of the FreeRADIUS
#  parser.
# 

allocate_begin = ""

#
#  This query allocates an IP address from the Pool
#
allocate_find = "db.mypool_collection.findAndModify( \
	{ \
		'query': {' \
			'$and': [ \
				{ \
					'pool_name': '%{control:Pool-Name}' \
				}, \
				{ \
					'nas_ip': '%{Nas-IP-Address}' \
				}, \
				{ \
					'$or': [ \
						{ \
							'calling_station_id': '%{Calling-Station-Id}' \
						}, \
						{ \
							'locked': 0 \
						} \
					] \
				} \
			] \
		}, \
		'update': { \
			'locked': 1', \
			'calling_station_id': '%{Calling-Station-Id'}' \
		}, \
		'fields': { \
			'_id': 0, 'framed_ip_address': 1 \
		} \
	})"

allocate_update = ""

allocate_clear = "db.mypool_collection.findAndModify( \
	{ \
		'query': { \
			'$and': [ \
				{ \
					'pool_name': '%{Control:Pool-Name}' \
				}, \
				{ \
					'nas_ip': '%{Nas-IP-Address}' \
				}, \
				{ \
					'calling_station_id': '%{Calling-Station-Id}' \
				}, \
				{ \
					'locked': 1 \
				} \
			] \
		}, \
		'update': { \
			'locked': 0, \
			'calling_station_id': '' \
		} \
	})"

allocate_commit = ""

start_update = ""

stop_clear = ""

alive_update = ""

on_clear = ""
off_clear = ""

