#!/bin/sh


if [ $# -eq 0 ]; then
    /usr/bin/ICTApplication/ICTCliGateLite --call LoggerModule:redirect
    else

if [ $# -eq 1 ]; then

case $1 in --help) 
echo " __________________________________________________________________ "
echo "|                                                                  |"
echo "| OBJECT : Command used to change destination                      |"
echo "|          config parameters in the syslog-ng configuration        |"
echo "|          file                                                    |"
echo "|                                                                  |"
echo "|                                                                  |"
echo "|   ====================================                           |"
echo "|   |redirect with no input parameters |                           |"
echo "|   ====================================                           |"
echo "|                                                                  |"
echo "|   COMMAND :redirect                                              |"
echo "|                                                                  |"
echo "|   Result : a table with all the syslog-ng configurations         |"
echo "|   EXAMPLE of redirect output :                                   |"
echo "|                                                                  |"
echo "|   <Activity>    <Level>        <Destination>         <Support>   |"
echo "|    ictaudio     warning    /var/log/ictaudio.log       file      |"
echo "|    ictsipua     err        IP :00.11.22.33 port (5&4)  udp       |"	
echo "|                                                                  |"
echo "|   ====================================                           |"
echo "|   |redirect with one input parameter |                           |"
echo "|   ====================================                           |"
echo "|                                                                  |"
echo "|   COMMAND :redirect --help                                       |"
echo "|                                                                  |"
echo "|   Print to the help to the terminal                              |"
echo "|                                                                  |"
echo "|   ======================================                         |"
echo "|   | Redirect with two input parameters |                         |"
echo "|   ======================================                         |"
echo "|                                                                  |"
echo "|   COMMAND : redirect <activity> <destination>                    |"
echo "|                                                                  |"
echo "|   <activity>         : the name of a facility                    |"
echo "|   <destination> list : V24                                       |"
echo "|                                                                  |"
echo "|    EXAMPLE :                                                     |"
echo "|    redirect ictaudio V24                                         |"
echo "|      --> redirect ictaudio syslog-ng stream to V24 serial output |"
echo "|                                                                  |"
echo "|    redirect all init                                             |"
echo "|      --> redirect all activities to  /var/log/<activity>.log     |"
echo "|                                                                  |"
echo "|   ========================================                       |"
echo "|   | Redirect with three input parameters |                       |"
echo "|   ========================================                       |"
echo "|                                                                  |"
echo "|   COMMAND :redirect <activity> <support> <destination>           |"
echo "|                                                                  |"
echo "|   <activity>            : the name of a activity                 |"
echo "|   <support>     list    : ram, flash, usertty, all               |"
echo "|   <destination> list    :                                        |"
echo "|   -a file name without any path--> "/" and "~" are forbidden     |"
echo "|   -a valid username      format : usertty <username>             |"
echo "|                                                                  |"
echo "|   EXAMPLE : - redirect ictaudio flash ictaudio.log               |"
echo "|             - redirect ictaudio usertty <username>               |"
echo "|                                                                  |"
echo "|   Use of particular activity :  all                              |"
echo "|   ===========================                                    |"
echo "|   The commands :                                                 |"
echo "|   redirect all init --> redirect all the syslog-ng streams       |"
echo "|                         to the predefined destination files      |"
echo "|   redirect all ram ictaudio.log                                  |"
echo "|                     --> redirect all the syslog-ng streams       |"
echo "|                         to one log file  : /var/log/ictaudio.log |"
echo "|                                                                  |"
echo "|   ======================================                         |"
echo "|   |redirect with four input parameters |                         |"
echo "|   ======================================                         |"
echo "|                                                                  |"
echo "|   COMMAND :redirect <activity> <support> <destination> <port>    |"
echo "|                                                                  |"
echo "|   <activity>             : the name of the activity              |"
echo "|   <support>     list     : udp, tcp                              |"	
echo "|   <destination> list     : a valid ip destination :              |"
echo "|     - ipv4 : xxx.xxx.xxx.xxx                                     |" 
echo "|   <port>                 : a valid IP port number < 65535        |"
echo "|                                                                  |"
echo "|   EXAMPLE : redirect ictaudio udp 172.24.40.189 418              |"
echo "|                                                                  |"
echo "|   Redirect all syslog streams to one destination :               |"
echo "|   ==============================================                 |"
echo "|                                                                  |"
echo "|   Use of a particular activity : all                             |"
echo "|   =============================                                  |"
echo "|   Format: redirect all udp 172.24.40.189 418                     |"
echo "|           --> Redirect all activities to one IP                  |"
echo "|               address with port 514 as communication port        |"
echo "|                                                                  |"
echo "|                 -----------End of Help -----------               |"
echo "|__________________________________________________________________|"
;;
esac       
else

        if [ $# -eq 2 ]; then
         /usr/bin/ICTApplication/ICTCliGateLite --call LoggerModule:redirect --args $1 $2
           else
              if [ $# -eq 3 ]; then
       		  /usr/bin/ICTApplication/ICTCliGateLite --call LoggerModule:redirect --args $1 $2 $3
          	 else
		    if [ $# -eq 4 ]; then
                       /usr/bin/ICTApplication/ICTCliGateLite --call LoggerModule:redirect --args $1 $2 $3 $4
                       else
                         echo "number of parameters invalid !"
               	    fi
               fi
         fi
    fi
fi
      
