#!/bin/sh

##-----------------------------------------------------------------------------
## cron2do - fli4l configuration parameters                                 0.2
##
##        P L E A S E   R E A D   T H E   D O C U M E N T A T I O N
##
##        B I T T E  U N B E D I N G T   D I E   D O K U M E N T A T I O N
##                                  L E S E N
##
## Creation:     04.05.2002  tc
## Last Update:  05.05.2002  tc
##
## Copyright (c) 2002 Thomas Creutz <thomas.creutz@epost.de>
##
## 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.
##-----------------------------------------------------------------------------
port=`cat /var/run/imond.port`

usage="cron2do [Option]
--------------------------------------------------------------------------------
       [Option] =  Angabe was zu tun ist.
Format: setoff  = Setzt den Dialmode auf OFF
        seton   = Setzt den Dialmode auf MANUELL
        setauto = Setzt den Dialmode auf AUTO
        rmc     = Trennt die zweite Leitung bei einer Multiline-Verbindung(ISDN)
        addc    = Schaltet eine zweite Leitung zur aktuellen Verbindung(ISDN)
        dial	= Baut eine Verbindung auf
        def     = Wechselt zur automatischen Circuit-Route
--------------------------------------------------------------------------------"

if [ $# -ne 1 ] ; then
    echo "$usage"
    exit 1
fi

case "$1" in
    "setoff") ;;
    "seton") ;;
    "setauto") ;;
    "rmc") ;;
    "addc") ;;
    "dial") ;;
    "def") ;;
    *) echo "$usage"
       exit 1
       ;;
esac

#-----------------------------------------------
# Befehle fr setoff
#--------------------------------------------------

if [ "$1" = "setoff" ] ; then
	{ echo "dialmode off"; echo "quit"; } | netcat -w 15 localhost $port

	echo Der Dialmode wurde auf OFF gestellt.
	grep -v "setoff" /var/cron/tabs/root > /tmp/cron_root.tmp
	mv /tmp/cron_root.tmp /var/cron/tabs/root

fi

#-----------------------------------------------
# Befehle fr seton
#--------------------------------------------------

if [ "$1" = "seton" ] ; then
	{ echo "dialmode manual"; echo "quit"; } | netcat -w 15 localhost $port

	echo Der Dialmode wurde auf MANUAL gestellt.
	grep -v "seton" /var/cron/tabs/root > /tmp/cron_root.tmp
	mv /tmp/cron_root.tmp /var/cron/tabs/root
fi

#-----------------------------------------------
# Befehle fr setauto
#--------------------------------------------------

if [ "$1" = "setauto" ] ; then
	{ echo "dialmode auto"; echo "quit"; } | netcat -w 15 localhost $port

	echo Der Dialmode wurde auf AUTO gestellt.
	grep -v "setauto" /var/cron/tabs/root > /tmp/cron_root.tmp
	mv /tmp/cron_root.tmp /var/cron/tabs/root
fi

#-----------------------------------------------
# Befehle fr rmc
#--------------------------------------------------

if [ "$1" = "rmc" ] ; then
	{ echo "removelink 0"; echo "quit"; } | netcat -w 15 localhost $port

	echo Die zweite Leitung wurde getrennt.
	grep -v "rmc" /var/cron/tabs/root > /tmp/cron_root.tmp
	mv /tmp/cron_root.tmp /var/cron/tabs/root
fi

#-----------------------------------------------
# Befehle fr addc
#--------------------------------------------------

if [ "$1" = "addc" ] ; then
	{ echo "addlink 0"; echo "quit"; } | netcat -w 15 localhost $port

	echo Es wird versucht die zweite Leitung aufzubauen.
	grep -v "addc" /var/cron/tabs/root > /tmp/cron_root.tmp
	mv /tmp/cron_root.tmp /var/cron/tabs/root
fi

#-----------------------------------------------
# Befehle fr dial
#--------------------------------------------------

if [ "$1" = "dial" ] ; then
	{ echo "dial"; echo "quit"; } | netcat -w 15 localhost $port

	echo Es wird versucht die Verbindung aufzubauen.
	grep -v "dial" /var/cron/tabs/root > /tmp/cron_root.tmp
	mv /tmp/cron_root.tmp /var/cron/tabs/root
fi

#-----------------------------------------------
# Befehle fr def
#--------------------------------------------------

if [ "$1" = "def" ] ; then
	{ echo "route 0"; echo "quit"; } | netcat -w 15 localhost $port

	echo Die Default Route wurde auf Automatic gestellt.
	grep -v def /var/cron/tabs/root > /tmp/cron_root.tmp
	mv /tmp/cron_root.tmp /var/cron/tabs/root
fi

# Neustart des Cron um die nderungen wirksam zu machen
killall cron
/usr/sbin/cron

exit 0