#! /bin/sh
#
# Copyright (C) 2007 Kevin Cody Jr. <kcody@vegaresearch.com>
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# RCSID $Id: _showstatus.in


LED_START=$IPSEC_STATUS_LED_START
LED_VALID=$IPSEC_STATUS_LED_VALID

[ -z "$LED_START" ] && LED_START="ses_orange"
[ -z "$LED_VALID" ] && LED_VALID="ses_white"


setled() {
	led=$1
	st=$2

	[ -n "$led" -a -n "$st" ] || return
	
	if [ -w "/proc/diag/led/$led" ] ; then
		echo "$st" > "/proc/diag/led/$led"
	fi

	# integrate other led control methods here

}


case "$1" in
	'start')
		[ -n "$LED_VALID" ] && setled "$LED_START" 1
		[ -z "$LED_VALID" ] && setled "$LED_START" f
		setled "$LED_VALID" 0
		;;
	'stop')
		setled "$LED_START" 0
		setled "$LED_VALID" 0
		;;
	'valid')
		setled "$LED_VALID" 1
		;;
	'invalid')
		setled "$LED_VALID" 0
		;;
	'up')
		[ -n "$LED_VALID" ] && setled "$LED_START" 0
		[ -z "$LED_VALID" ] && setled "$LED_START" 1
		setled "$LED_VALID" 1
		;;
	'down')
		[ -n "$LED_VALID" ] && setled "$LED_START" 1
		[ -z "$LED_VALID" ] && setled "$LED_START" f
		setled "$LED_VALID" f
		;;
	*)
		echo "$0: unknown status $status" >&2
		;;
esac

