"Fossies" - the Fresh Open Source Software Archive

Member "coarseknocking-0.0.6/bin/coarseknockingcfg" (27 Mar 2006, 4636 Bytes) of package /linux/privat/old/coarseknocking-0.0.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 ###############################################################################
    3 # File: coarseknockingcfg - Coarse Knocking Configurator
    4 # Copyright (C) 2005  - http://coarseknocking.sourceforge.net
    5 #
    6 # By Andre Luiz Rodrigues Ferreira - si0ux - <andrelrf@gmail.com>
    7 # From Orlandia - SP - Brazil
    8 # 
    9 # This is a simple implementation of Port Knocking techniques.
   10 # This sniffs network packets with determined keys and executes commands like 
   11 # firewall to open and close ports. In the client mode injects packets with 
   12 # key to server.
   13 # This is a personal project of the your author and is available for everybody 
   14 # by your GPL Licence.
   15 #
   16 # WARNING: Depends of ngrep (http://ngrep.sourceforge.net) and 
   17 #          nemesis (http://nemesis.sourceforge.net) network tools.
   18 #          This software was been tested on Debian GNU/Linux 3.1 system.
   19 #
   20 # More information: 
   21 # http://www.portknocking.org
   22 # http://coarseknocking.sourceforge.net
   23 #
   24 ################################################################################
   25 # LICENCE:
   26 # CoarseKnocking is free software; you can redistribute it and/or modify it 
   27 # under the terms of the GNU General Public License as published by the Free
   28 # Software Foundation; either version 2 of the License, or (at your option) any 
   29 # later version.
   30 #
   31 # CoarseKnocking is distributed in the hope that it will be useful, but WITHOUT 
   32 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
   33 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
   34 #
   35 # You should have received a copy of the GNU General Public License along with 
   36 # CoarseKnocking; if not, write to the Free Software Foundation, Inc., 59 
   37 # Temple Place, Suite 330, Boston, MA  02111-1307  USA
   38 #
   39 ##############################################################################
   40 
   41 if [ $DISPLAY ]
   42 then
   43     dialog="Xdialog"
   44 else
   45     dialog="dialog"
   46 fi
   47 
   48 cfgfile="/etc/coarseknocking/coarse-server.conf"
   49 
   50 if [ $UID != "0" ]
   51 then
   52     $dialog --msgbox "ERROR: User must be root..." 0 0
   53     exit 1
   54 fi
   55                         
   56 if [ -f $cfgfile ]
   57 then
   58     source $cfgfile
   59     srchost_new=$srchost
   60     dsthost_new=$dsthost
   61     dport_new=$dport
   62     command_open_new=$command_open
   63     command_close_new=$command_close
   64     key_open_new=$key_open
   65     key_close_new=$key_close
   66     interface_new=$interface
   67 else
   68     $dialog --msgbox "ERROR: Configuration file $cfgfile doesn't exist..." 0 0
   69     exit 1
   70 fi
   71                                                    
   72 while :
   73 do
   74     source $cfgfile
   75     
   76     backtitle="Coarse Port Knocking configuration tool"
   77     option=$( $dialog --stdout --backtitle "$backtitle" --title "Configuration" --menu "Choose your option:" 18 70 8 "1" "Client Source address" "2" "Server Destination Address" "3" "Destination TCP Port to knocking" "4" "Key waited to execute open command" "5" "Key waited to execute close command" "6" "Interface to listen" "7" "Save configuration" "0" "Exit" )
   78     [ $? -ne 0 ] && break
   79     
   80     case $option in
   81     1) 
   82         srchost_new=$( $dialog --backtitle "$backtitle" --stdout --inputbox "Source Host Address:" 0 0 $srchost_new )
   83         [ $? -eq 1 ] && srchost_new=$srchost
   84     ;;
   85     2)
   86         dsthost_new=$( $dialog --backtitle "$backtitle" --stdout --inputbox "Destination Host Address:" 0 0 $dsthost_new )
   87         [ $? -eq 1 ] && dsthost_new=$dsthost
   88     ;;
   89     3)
   90         dport_new=$( $dialog --backtitle "$backtitle"  --stdout --inputbox "Destination TCP Port to knocking:" 0 0 $dport_new )
   91         [ $? -eq 1 ] && dport_new=$dport
   92     ;;
   93     4)
   94         key_open_new=$( $dialog --backtitle "$backtitle" --stdout --passwordbox "Key waited to execute open command:" 0 0 )
   95         [ $? -eq 1 ] && key_open_new=$key_open
   96     ;;
   97     5)
   98         key_close_new=$( $dialog --backtitle "$backtitle" --stdout --passwordbox "Key waited to execute close command:" 0 0 )
   99         [ $? -eq 1 ] && key_close_new=$key_close
  100     ;;
  101     6)
  102         interface_new=$( $dialog --backtitle "$backtitle" --stdout --inputbox "Interface to listen:" 0 0 $interface_new )
  103         [ $? -eq 1 ] && interface_new=$interface
  104     ;;
  105     7)
  106         $dialog --backtitle "$backtitle" --title 'Warning' --yesno 'Save your configuration?' 0 0
  107         if [ $? = 0 ]
  108         then
  109             # Saving configuration...
  110             cp $cfgfile $cfgfile.bkp
  111             sed -i "s/srchost=\"$srchost\"/srchost=\"$srchost_new\"/g" $cfgfile
  112             sed -i "s/dsthost=\"$dsthost\"/dsthost=\"$dsthost_new\"/g" $cfgfile
  113             sed -i "s/dport=$dport/dport=$dport_new/g" $cfgfile
  114             sed -i "s/key_open=\"$key_open\"/key_open=\"$key_open_new\"/g" $cfgfile
  115             sed -i "s/key_close=\"$key_close\"/key_close=\"$key_close_new\"/g" $cfgfile
  116             sed -i "s/interface=$interface/interface=$interface_new/g" $cfgfile
  117             $dialog --backtitle "$backtitle" --msgbox "Configuration saved in: \n $cfgfile !" 10 50
  118         fi
  119     ;;
  120     0) 
  121         break 
  122     ;;
  123     esac
  124 done
  125 
  126 exit 0
  127 # End of Code ###