def run(server, irc, con, event): try: reason = "" host = "" if "G:Line" in event.arguments()[0] and event.source() in source and 'bots/clones' in event.arguments()[0].lower(): arguments = event.arguments()[0].split(" ") if arguments[2] == "added": reason = event.arguments()[0].split(":")[6] reason = reason[0:len(reason)-1] reason.replace(" ", "") host = event.arguments()[0].split("@")[1].split(" ")[0] type = "add" elif arguments[1] == "removed": reason = event.arguments()[0].split(":")[4] reason = reason[0:len(reason)-1] reason.replace(" ", "") host = event.arguments()[0].split("@")[2].split(" ")[0] type = "remove" elif arguments[1] == "Expiring": reason = event.arguments()[0].split(":")[2].split(")")[0] reason.replace(" ", "") host = event.arguments()[0].split("@")[1].split(")")[0] type = "remove" additional = None if "-" in reason: additional = reason.split("-")[1].split(" ")[0] try: ip = socket.gethostbyname(host) except: print "Cannot resolve host " + host + " and therefore cannot add it to the blacklist." return ''' if additional == None: additional = "null" settings.httprequestQ.append(page + "?action=%s&ip=%s&additional=%s" % (type, ip, additional)) for url in settings.httprequestQ: try: f = urllib.urlopen(url) f.read() settings.httprequestQ.remove(url) if len(settings.httprequestQ) > 10: time.sleep(1) except: return ''' #server.privmsg("#Home", "%s record %s%s (%s)" % (type, glob.f.reversebit(ip), dnsbldomain, additional)) if type == "add": try: import MySQLdb except: print "No MySQLdb, no DNSbl." return try: conn = MySQLdb.connect (host = settings.mysql_host, user = settings.mysql_user, passwd = settings.mysql_password, db = settings.mysql_database) cursor = conn.cursor () cursor.execute("insert into rr(zone, name,type,data) values(8,'%s','A','127.0.0.2')" % (f.reversebit(ip))) cursor.close() conn.commit() conn.close() print "Added " + ip + " to dnsbl." except MySQLdb.Error, e: if "duplicate" in e.args[1]: #We don't want to hear it! pass print "Error %d: %s" % (e.args[0], e.args[1]) finally: try: cursor.close() conn.commit() conn.close() return except: pass return return
def run(server, irc, con, event): nick = event.source().split("!")[0] host = event.source().split("@")[1] message = event.arguments()[0] arguments = message.split(" ") if arguments[0].lower() == server.get_nickname().lower() and checkAccess( host): command = arguments[1] if command == "remove": if len(arguments) == 2: server.privmsg( nick, "Syntax: %s remove ipaddress" % (server.get_nickname())) server.privmsg( nick, "Example: %s remove 92.158.43.23" % (server.get_nickname())) elif len(arguments) > 2: ip = arguments[2] server.privmsg(nick, "Debug: Removing %s..." % (ip)) try: import MySQLdb except: server.privmsg( nick, "Debug: Error! No MySQLdb module - tell Alex ") return global conn, cursor try: conn = MySQLdb.connect(host=settings.mysql_host, user=settings.mysql_user, passwd=settings.mysql_password, db=settings.mysql_database) cursor = conn.cursor() #cursor.execute("insert into rr(zone, name,type,data) values(8,'%s','A','127.0.0.2')" % (f.reversebit(ip))) cursor.execute( '''delete from rr where zone=8 and name="%s"''' % (f.reversebit(ip))) if cursor.rowcount > 1: conn.rollback() server.privmsg( nick, "Something went wrong, and the syntax affected more than one line in the database. Please report this to Alex." ) elif cursor.rowcount == 0: server.privmsg( nick, "There was no record for %s in the database." % (ip)) else: server.privmsg( nick, "The IP was successfully removed from the database." ) server.privmsg( nick, "Please take note that DNS results may be cached in the BOPM for up to 5 minutes." ) cursor.close() conn.commit() conn.close() except MySQLdb.Error, e: if "exists" in e.args[1]: conn.close() pass print "Error %d: %s" % (e.args[0], e.args[1]) conn.rollback() conn.close() pass elif command == "check": if len(arguments) > 2: try: import MySQLdb except: server.privmsg( nick, "Debug: Error! No MySQLdb module - tell Alex ") return ip = arguments[2] try: conn = MySQLdb.connect(host=settings.mysql_host, user=settings.mysql_user, passwd=settings.mysql_password, db=settings.mysql_database) cursor = conn.cursor() #cursor.execute("insert into rr(zone, name,type,data) values(8,'%s','A','127.0.0.2')" % (f.reversebit(ip))) cursor.execute( '''select * from rr where zone=8 and name="%s"''' % (f.reversebit(ip))) if cursor.rowcount >= 1: server.privmsg(nick, "The IP exists in the database.") else: server.privmsg( nick, "The IP does not exist in the database.") cursor.close() conn.close() except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) server.privmsg(nick, "Error %d: %s" % (e.args[0], e.args[1]))
def run(server, irc, con, event): try: reason = "" host = "" if "G:Line" in event.arguments()[0] and event.source( ) in source and 'bots/clones' in event.arguments()[0].lower(): arguments = event.arguments()[0].split(" ") if arguments[2] == "added": reason = event.arguments()[0].split(":")[6] reason = reason[0:len(reason) - 1] reason.replace(" ", "") host = event.arguments()[0].split("@")[1].split(" ")[0] type = "add" elif arguments[1] == "removed": reason = event.arguments()[0].split(":")[4] reason = reason[0:len(reason) - 1] reason.replace(" ", "") host = event.arguments()[0].split("@")[2].split(" ")[0] type = "remove" elif arguments[1] == "Expiring": reason = event.arguments()[0].split(":")[2].split(")")[0] reason.replace(" ", "") host = event.arguments()[0].split("@")[1].split(")")[0] type = "remove" additional = None if "-" in reason: additional = reason.split("-")[1].split(" ")[0] try: ip = socket.gethostbyname(host) except: print "Cannot resolve host " + host + " and therefore cannot add it to the blacklist." return ''' if additional == None: additional = "null" settings.httprequestQ.append(page + "?action=%s&ip=%s&additional=%s" % (type, ip, additional)) for url in settings.httprequestQ: try: f = urllib.urlopen(url) f.read() settings.httprequestQ.remove(url) if len(settings.httprequestQ) > 10: time.sleep(1) except: return ''' #server.privmsg("#Home", "%s record %s%s (%s)" % (type, glob.f.reversebit(ip), dnsbldomain, additional)) if type == "add": try: import MySQLdb except: print "No MySQLdb, no DNSbl." return try: conn = MySQLdb.connect(host=settings.mysql_host, user=settings.mysql_user, passwd=settings.mysql_password, db=settings.mysql_database) cursor = conn.cursor() cursor.execute( "insert into rr(zone, name,type,data) values(8,'%s','A','127.0.0.2')" % (f.reversebit(ip))) cursor.close() conn.commit() conn.close() print "Added " + ip + " to dnsbl." except MySQLdb.Error, e: if "duplicate" in e.args[1]: #We don't want to hear it! pass print "Error %d: %s" % (e.args[0], e.args[1]) finally: try: cursor.close() conn.commit() conn.close() return except: pass return return
def run(server, irc, con, event): nick = event.source().split("!")[0] host = event.source().split("@")[1] message = event.arguments()[0] arguments = message.split(" ") if arguments[0].lower() == server.get_nickname().lower() and checkAccess(host): command = arguments[1] if command == "remove": if len(arguments) == 2: server.privmsg(nick, "Syntax: %s remove ipaddress" % (server.get_nickname())) server.privmsg(nick, "Example: %s remove 92.158.43.23" % (server.get_nickname())) elif len(arguments) > 2: ip = arguments[2] server.privmsg(nick, "Debug: Removing %s..." % (ip)) try: import MySQLdb except: server.privmsg(nick, "Debug: Error! No MySQLdb module - tell Alex ") return global conn, cursor try: conn = MySQLdb.connect (host = settings.mysql_host, user = settings.mysql_user, passwd = settings.mysql_password, db = settings.mysql_database) cursor = conn.cursor () #cursor.execute("insert into rr(zone, name,type,data) values(8,'%s','A','127.0.0.2')" % (f.reversebit(ip))) cursor.execute('''delete from rr where zone=8 and name="%s"''' % (f.reversebit(ip))) if cursor.rowcount > 1: conn.rollback() server.privmsg(nick, "Something went wrong, and the syntax affected more than one line in the database. Please report this to Alex.") elif cursor.rowcount == 0: server.privmsg(nick, "There was no record for %s in the database." % (ip)) else: server.privmsg(nick, "The IP was successfully removed from the database.") server.privmsg(nick, "Please take note that DNS results may be cached in the BOPM for up to 5 minutes.") cursor.close() conn.commit() conn.close() except MySQLdb.Error, e: if "exists" in e.args[1]: conn.close() pass print "Error %d: %s" % (e.args[0], e.args[1]) conn.rollback() conn.close() pass elif command == "check": if len(arguments) > 2: try: import MySQLdb except: server.privmsg(nick, "Debug: Error! No MySQLdb module - tell Alex ") return ip = arguments[2] try: conn = MySQLdb.connect (host = settings.mysql_host, user = settings.mysql_user, passwd = settings.mysql_password, db = settings.mysql_database) cursor = conn.cursor () #cursor.execute("insert into rr(zone, name,type,data) values(8,'%s','A','127.0.0.2')" % (f.reversebit(ip))) cursor.execute('''select * from rr where zone=8 and name="%s"''' % (f.reversebit(ip))) if cursor.rowcount >= 1: server.privmsg(nick, "The IP exists in the database.") else: server.privmsg(nick, "The IP does not exist in the database.") cursor.close() conn.close() except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) server.privmsg(nick, "Error %d: %s" % (e.args[0], e.args[1]))