Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## config
- stomp_host = amq1
- stomp_port = 6163
- stomp_user = user
- stomp_password = pass
- statustopic = /topic/amqconsumer
- consumer = Ipblocker
- subscribe = /topic/ipblocker.command
- daemonize = 1
- ## code
- require 'socket'
- module AMQConsumer
- module Consumer
- class Ipblocker
- def initialize(config)
- end
- def handlemsg(msg, amq)
- if msg.body =~ /^blockip.(\d+\.\d+\.\d+\.\d+)$/
- system("/sbin/iptables -A junk_filter -s #{$1} -j DROP")
- system("/usr/bin/logger -i -t ipblocker 'Added #{$1} to iptables junk_filter chain on #{Socket.gethostname}'")
- elsif msg.body =~ /^unblockip.(\d+\.\d+\.\d+\.\d+)$/
- system("/sbin/iptables -D junk_filter -s #{$1} -j DROP")
- system("/usr/bin/logger -i -t ipblocker 'Removed #{$1} from iptables junk_filter chain on #{Socket.gethostname}'")
- else
- system("/usr/bin/logger -i -t ipblocker 'Unknown msg: #{msg.body} received on #{Socket.gethostname}'")
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment