#!/bin/sh
##-----------------------------------------------------------------------------
## cron2do_x                                                              0.6.1
##
## Creation:     04.05.2002  tc
## Last Update:  26.02.2003  tc
##
## Copyright (c) 2003 Thomas Creutz <thomas.creutz@epost.de>
##                    http://projekte.alientxc.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.
##-----------------------------------------------------------------------------


usage="cron2do_x [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	= Verbindung herstellen
        hangup  = Verbindung trennen
        def     = Wechselt zur automatischen Circuit-Route
--------------------------------------------------------------------------------"

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

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

port=`cat /var/run/imond.port`

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

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

	echo Der Dialmode wurde auf OFF gestellt.
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.
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.
fi

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

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

	echo Die zweite Leitung wurde getrennt.
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."
fi

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

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

	echo "Es wird versucht die Verbindung aufzubauen."
fi

#-----------------------------------------------
# Befehle fr hangup
#--------------------------------------------------

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

	echo "Die Verbindung wird beendet."
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."
fi

exit 0
