#!/usr/bin/tclsh #all #class435 #class437 #quit #for -i in #iptables -D FORWARD $i namespace eval dropper { set version "1.0" set info "Easy Internet Connection Dropper for II of da REA by CoolCold (#rea on irc.rea.ru:6667)" set class435 "435" set class437 "437" set all "all" set quit "q" set dropswitch "--drop" set undropswitch "--undrop" set dropipswitch "--dropip" set undropipswitch "--undropip" set helpswitch "--help" set aboutswitch "--ibout" set infoline "Easy Internet Connection Dropper(EICD)" set "/var/log/eicd.log" } proc print {text} { puts stdout $text } proc ::dropper::dropselect { target } { variable class437;variable class435;variable all;variable quit print "Select what drop chain to enable" print "Varaints are:$class437 $class435 $all or $quit" if {$target==""} { gets stdin target } else {print "$target"} # switch -exact [string tolower $bla] { # "$class437" {print "hiynya!"} # } # print $bla addlog "Drop:Selected target:$target" switch -- $target "$class437" {if { [catch {exec ./437.sh} dropresult] } {print "Error while processing directive\r\n\Return value is:\r\n$dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1}} \ "$class435" {if {[catch {exec ./435.sh} dropresult]} {print "Error while processing directive\r\n\Return value is:\r\n$dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1} } \ "$all" { if {[catch {exec ./435.sh} dropresult] } {print "Error while processing directive\r\n\Return value is:\r\n$dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1} if {[catch {exec ./437.sh} dropresult] } {print "Error while processing directive\r\n\Return value is:\r\n$dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1} } \ "$quit" {print "quitting";addlog "quit";exit 0} \ default {print "no such element,please refine Your choice";addlog "no such element,please refine Your choice";return 2} #print "test blya" set piu [exec /sbin/iptables -L FORWARD] print $piu addlog "$piu" return 0 } proc ::dropper::undropselect { target } { variable class437;variable class435;variable all;variable quit print "Select what drop chain to disable" print "Varaints are:$class437 $class435 $all or $quit" if {$target==""} { gets stdin target } else {print "$target"} addlog "Undrop:Selected target $target" switch -- $target "$class437" {if { [catch {exec ./un437.sh} dropresult] } {print "Error while processing directive\r\n\Return value is:\r\n$dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1}} \ "$class435" {if {[catch {exec ./un435.sh} dropresult]} {print "Error while processing directive\r\n\Return value is:\r\n$dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1} } \ "$all" { if {[catch {exec ./un435.sh} dropresult] } {print "Error while processing directive\r\n\Return value is:\r\n$dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1} if {[catch {exec ./un437.sh} dropresult] } {print "Error while processing directive\r\n\Return value is:\r\n$dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1} } \ "$quit" {print "quitting";addlog "quit";exit 0} \ default {print "no such element,please refine Your choice";addlog "no such element,please refine Your choice";return 2} set piu [exec /sbin/iptables -L FORWARD] print $piu addlog "$piu" return 0 } proc ::dropper::init {} { variable helpswitch;variable dropswitch;variable aboutswitch variable dropipswitch;variable undropipswitch;variable undropswitch variable version;variable info;variable infoline variable logfile global argv #print "$argv" addlog $argv set c "0" foreach {i} $argv { incr c if {[string equal -nocase $i "$helpswitch"]} { print "$info version $version" print "" print "$infoline provides easy & user friendly internet connection dropper interface for iptables" print "available command line switches:" print "$helpswitch - shows this help" print "$aboutswitch - shows about screen\r\n" print "$dropswitch \[target\] - tryes to execute drop command for target" print "$undropswitch \[target\] - tryes to execute undrop command for target" print "$dropipswitch IP - drops single IP" print "$undropipswitch IP - undrops single IP\r\n" print "Files:" print "435.sh,437.sh,un435.sh,un437sh,dropip.sh,undropip.sh" print "Logging file:$logfile" } if {[string equal -nocase $i "$aboutswitch"]} { print "$info version $version" return 0 } if {[string equal -nocase $i "$dropswitch"]} { set piu [::dropper::dropselect [lindex $argv $c]] return 0 } if {[string equal -nocase $i "$undropswitch"]} { set piu [::dropper::undropselect [lindex $argv $c]] return 0 } if {[string equal -nocase $i "$dropipswitch"]} { set blabla [lindex $argv $c] print "dropping $blabla" addlog "Single ip drop:$blabla" if { [catch {exec ./dropip.sh $blabla} dropresult] } { print "dropip.sh failed.\r\nReturn value is:\r\n $dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1 } print "$blabla was added to FORWARD drop list" addlog "$blabla was added to FORWARD drop list" set piu [exec /sbin/iptables -L FORWARD] print $piu addlog "$piu" return 0 } if {[string equal -nocase $i "$undropipswitch"]} { set blabla [lindex $argv $c] print "undropping $blabla" addlog "Single ip undrop:$blabla" if { [catch {exec ./undropip.sh $blabla} dropresult] } { print "undropip.sh failed.\r\nReturn value is:\r\n $dropresult";addlog "Error while processing directive\r\n\Return value is:\r\n$dropresult";exit 1 } print "$blabla was deleted from FORWARD drop list" addlog "$blabla was deleted from FORWARD drop list" set piu [exec /sbin/iptables -L FORWARD] print $piu addlog "$piu" return 0 } } } proc ::dropper::addlog { text } { variable logfile set fid [open $logfile "APPEND WRONLY CREAT"] puts $fid "[clock format [clock seconds] -format "%a %d %b %Y %H:%M:%S"] $text" close $fid } ::dropper::init #::dropper::select