################################################################################
# Filename: ./src/plugins/ldap/include/ldap-functions
# 
# The contents of this file are subject to the Qlusters Public License
# Version 1.1 (the License); you may not use this file except in compliance
# with the License.
# You may obtain a copy of the License at
# http://www.openqrm.org/content/view/33/69/.
# 
# Software distributed under the License is distributed on an AS IS basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
# the specific language governing rights and limitations under the License.
# 
# The Original Code is openQRM.
# 
# The Initial Developer of the Original Code is Qlusters Corporation. Portions
# created by Qlusters Corporation are Copyright (C) 2003-2005. All Rights
# Reserved.
# 
# Contributor(s):
# 
# Description:
# 
# Comments:
################################################################################
function ldap_install() {
	echo "Installing ldap"	
	${QRM_PLUGIN_BASE_DIR}/bin/qrm-ldap-install
}

function ldap_uninstall() {
	echo "Uninstalling ldap"

	file=$QRM_SERVER_BASE_DIR/qrm/usr/tomcat/conf/jaas.config.tmpl
	check=`ls ${file}.ldap-bak_* 2>/dev/null`
	if [ -z "$check" ] ; then
		echo "I don't see ldap installation files, not running uninstallation"
		return 1
	fi

	idx=1
	echo "Please enter the number of the backup file you would like to restore:"
	for i in ${file}.ldap-bak_* ; do
		bak[$idx]=`echo $i | sed s/^.*tmpl.ldap-bak_//`
		echo -e "\t[$idx] ${bak[$idx]}  (`date -r $i`)"
		(( idx++ ))
	done

	havefile=0
	while [ $havefile -eq "0" ] ; do
		echo -n "[enter number] > "
		read num
		oldfile=$file.ldap-bak_${bak[$num]}
		if [ -f "$oldfile" ] ; then
			havefile=1
		else
			echo "Please enter a valid number from above:"
		fi
	done

	backup=$file.ldap-bak_`date +%s`
	echo -e "Backing up the original file to: \n\t$backup "
	mv $file $backup

	echo -e "Restoring file \n\t $oldfile \nto file: \n\t$file"
	cp $oldfile $file

	echo "Done."
}

function ldap_run_once() {
	: # code that will run once by the server
}

function ldap_start() {
	echo "Starting ldap"
}

function ldap_stop() {
	echo "Stopping ldap"
}

