Skip to content

Instantly share code, notes, and snippets.

@GaeaKat
Last active August 29, 2015 14:24
Show Gist options
  • Save GaeaKat/c834ce475d61edfa2e2f to your computer and use it in GitHub Desktop.
Save GaeaKat/c834ce475d61edfa2e2f to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'bundler/setup'
require 'cinch'
require 'yaml'
require 'pp'
require 'Proxifier'
require './app'
Dir[File.dirname(__FILE__) + '/libs/*'].each {|file| require file }
$botconfiguration = YAML::load(IO.read('config/bot.yml'))
$bot = Cinch::Bot.new do
configure do |c|
c.server = $botconfiguration['server']['ip']
c.channels = $botconfiguration['server']['channels']
c.nick=$botconfiguration['server']['name']
c.realname=$botconfiguration['server']['realname']
c.sasl.username=$botconfiguration['server']['username']
c.sasl.password=$botconfiguration['server']['password']
c.plugins.plugins = [OpMe,WatchConnect,PortCommands]
c.modes=["B"]
end
end
$bot.start
#Goes in libs/OpMe.rb
class OpMe
include Cinch::Plugin
match /operup/i
help = "Just ops on command"
def execute(m)
bot.oper("password","user")
bot.set_mode("s +cC")
end
end
#Goes in libs/PortCommands.rb
class PortCommands
include Cinch::Plugin
match /port add (.*) (\d.*)/, method: :addPort
match /port list/, method: :listPorts
match /port del (.*) (\d.*)/,method: :delPort
def addPort(m,type,portNumber)
if(m.user.oper?)
if(type!="SOCKS4" && type!="SOCKS5")
m.reply "Type must be SOCKS4 or SOCKS5",true
return
end
port=Port.find_or_create_by(number: portNumber, proxyType: type)
port.save
m.reply "Port number #{portNumber} added to list.",true
end
end
def delPort(m,type,portNumber)
if(m.user.oper?)
parameters={:portNumber=>portNumber, :proxyType=>type}
p=Port.where(number: portNumber,proxyType: type).first
p.destroy
m.reply "Port #{portNumber} type #{type} removed ",true
end
end
def listPorts(m)
if(m.user.oper?)
Port.find_each do |port|
m.reply "Port #{port.number} type #{port.proxyType} ",true
end
end
end
end
#Goes in libs/WatchConnect.rb
class WatchConnect
include Cinch::Plugin
match /\*\*\* .*CONNECT: Client connecting.*: ([^ ]+)!([^@]+)@([^\\)]+) [\[\(]([0-9\\.]+)[\]\)] \[.*\]/, use_prefix: false, method: :notice, react_on: :notice
def notice(m,nick,ident,host,ip)
pp "#{nick} connected with ident #{ident} at host #{host} (#{ip})"
if(Whitelist.where(ip: ip).empty?)
found=false
Port.find_each do |port|
if(port.proxyType=="SOCKS4")
url="socks4://"
else
url="socks5://"
end
url=url+host+":"+port.number.to_s
pp "Checking #{url} for a proxy"
begin
proxy = Proxifier::Proxy(url)
proxy.open("8.8.8.8",80)
pp "proxy found at #{url}"
found=true
rescue
pp "no proxy found at #{url}"
end
end
if(found)
pp "Proxy found, taking action"
bot.irc.send("gline #{nick}@#{host} 180d :Sorry, we do not allow open proxies on snoonet, please modmail /r/snoonet if you believe this is in error")
else
pp "No proxy, is okay"
white=Whitelist.find_or_create_by(ip: ip)
white.save
end
end
else
pp "Whitelisted, no need to check"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment