Exemplo n.º 1
0
def channel_modes(nick,host,chan,arg):
	auth = getauth(nick)
	hostmask = nick+"!"+host
	flag = getflag(chan,auth)
	hostflag = gethostflag(chan,hostmask)

	if flag == "n" or flag == "o" or hostflag == "o":
		_chandb.execute("update info set modes='%s' where channel='%s'" % (arg,chan))
		put("MODE %s %s" % (chan,arg))
Exemplo n.º 2
0
def invite(nick, host, chan, arg):
    auth = getauth(nick)
    flag = getflag(chan, auth)
    hostmask = nick + "!" + host
    hostflag = gethostflag(chan, hostmask)

    if flag == "n" or flag == "o" or hostflag == "o":
        for user in arg.split():
            put("INVITE %s %s" % (user, chan))
Exemplo n.º 3
0
def channel_topic(nick,host,chan,arg):
	auth = getauth(nick)
	hostmask = nick+"!"+host
	flag = getflag(chan,auth)
	hostflag = gethostflag(chan,hostmask)

	if flag == "n" or flag == "o" or hostflag == "o":
		_chandb.execute("update info set topic='%s' where channel='%s'" % (arg,chan))
		put("TOPIC %s :%s" % (chan,arg))
Exemplo n.º 4
0
def invite(nick,host,chan,arg):
	auth = getauth(nick)
	flag = getflag(chan,auth)
	hostmask = nick+"!"+host
	hostflag = gethostflag(chan,hostmask)

	if flag == "n" or flag == "o" or hostflag == "o":
		for user in arg.split():
			put("INVITE %s %s" % (user,chan))
Exemplo n.º 5
0
def exempt(nick, host, chan, arg):
    auth = getauth(nick)
    flag = getflag(chan, auth)
    hostmask = nick + "!" + host
    hostflag = gethostflag(chan, hostmask)

    if flag == "n" or flag == "o" or hostflag == "o":
        if len(arg.split()) > 0:
            target = arg.split()[0][1:]
            scut = arg.split()[0][0]

            if wmatch(target, "*!*@*"):
                if scut == "+":
                    entry = False

                    for data in _chandb.execute(
                            "select exempt from exempts where channel='%s' and exempt='%s'"
                            % (chan, target)):
                        entry = True

                    if entry is False:
                        _chandb.execute(
                            "insert into exempts values ('%s','%s')" %
                            (chan, target))
                        put("NOTICE %s :[%s] %s has been added to the exemptlist"
                            % (nick, chan, target))
                        whochan(chan)
                    else:
                        put("NOTICE %s :[%s] %s is already on the exemptlist" %
                            (nick, chan, target))
                elif scut == "-":
                    entry = False

                    for data in _chandb.execute(
                            "select exempt from exempts where channel='%s' and exempt='%s'"
                            % (chan, target)):
                        entry = True

                    if entry is True:
                        _chandb.execute(
                            "delete from exempts where channel='%s' and exempt='%s'"
                            % (chan, target))
                        put("NOTICE %s :[%s] %s has been removed from the exemptlist"
                            % (nick, chan, target))
                        put("MODE %s -b %s" % (chan, target))
                    else:
                        put("NOTICE %s :[%s] %s is not on the exemptlist" %
                            (nick, chan, target))
                else:
                    irc_send(nick, "$exempt +/-*!*example@*.example.com")
            else:
                irc_send(nick, "$exempt +/-*!*example@*.example.com")
        else:
            for data in _chandb.execute(
                    "select exempt from exempts where channel='%s'" % chan):
                irc_send(nick, "[%s] %s" % (chan, str(data[0])))
Exemplo n.º 6
0
def channel_modes(nick, host, chan, arg):
    auth = getauth(nick)
    hostmask = nick + "!" + host
    flag = getflag(chan, auth)
    hostflag = gethostflag(chan, hostmask)

    if flag == "n" or flag == "o" or hostflag == "o":
        _chandb.execute("update info set modes='%s' where channel='%s'" %
                        (arg, chan))
        put("MODE %s %s" % (chan, arg))
Exemplo n.º 7
0
def channel_drop(nick,uhost,arg):
	password = arg.split()[0]
	channel = arg.split()[1]

	if password == c.get("ADMIN", "password"):
		_chandb.execute("delete from list where channel='%s'" % channel)
		put("PART %s" % channel)
		put("NOTICE %s :%s has been removed from the database" % (nick,channel))
		_chandb.execute("delete from channel where channel='%s'" % channel)
		_chandb.execute("delete from info where channel='%s'" % channel)
Exemplo n.º 8
0
def channel_topic(nick, host, chan, arg):
    auth = getauth(nick)
    hostmask = nick + "!" + host
    flag = getflag(chan, auth)
    hostflag = gethostflag(chan, hostmask)

    if flag == "n" or flag == "o" or hostflag == "o":
        _chandb.execute("update info set topic='%s' where channel='%s'" %
                        (arg, chan))
        put("TOPIC %s :%s" % (chan, arg))
Exemplo n.º 9
0
def channel_register(nick,uhost,arg):
	password = arg.split()[0]
	channel = arg.split()[1]

	if password == c.get("ADMIN", "password"):
		_chandb.execute("insert into list values ('%s')" % channel)
		put("JOIN %s" % channel)
		put("NOTICE %s :%s has been added to the database ... You got owner flags" % (nick,channel))
		_chandb.execute("insert into channel values ('%s','%s','n')" % (channel,getauth(nick)))
		_chandb.execute("insert into info values ('%s','','')" % channel)
Exemplo n.º 10
0
def channel_drop(nick, uhost, arg):
    password = arg.split()[0]
    channel = arg.split()[1]

    if password == c.get("ADMIN", "password"):
        _chandb.execute("delete from list where channel='%s'" % channel)
        put("PART %s" % channel)
        put("NOTICE %s :%s has been removed from the database" %
            (nick, channel))
        _chandb.execute("delete from channel where channel='%s'" % channel)
        _chandb.execute("delete from info where channel='%s'" % channel)
Exemplo n.º 11
0
def on_nickchange(nick, uhost, newnick):
    for data in _cache.execute("select name from botnick"):
        if nick == str(data[0]):
            _cache.execute("update botnick set name='%s'" % newnick)

    if nick.lower() == _botnick.lower():
        _cache.execute("update botnick set name='%s'" % _botnick)
        put("NICK %s" % _botnick)

    _userdb.execute("delete from auth where nick='%s'" % nick)

    whois(newnick)
Exemplo n.º 12
0
def channel_register(nick, uhost, arg):
    password = arg.split()[0]
    channel = arg.split()[1]

    if password == c.get("ADMIN", "password"):
        _chandb.execute("insert into list values ('%s')" % channel)
        put("JOIN %s" % channel)
        put("NOTICE %s :%s has been added to the database ... You got owner flags"
            % (nick, channel))
        _chandb.execute("insert into channel values ('%s','%s','n')" %
                        (channel, getauth(nick)))
        _chandb.execute("insert into info values ('%s','','')" % channel)
Exemplo n.º 13
0
Arquivo: user.py Projeto: Pythonz/PIRB
def on_nickchange(nick,uhost,newnick):
	for data in _cache.execute("select name from botnick"):
		if nick == str(data[0]):
			_cache.execute("update botnick set name='%s'" % newnick)

	if nick.lower() == _botnick.lower():
		_cache.execute("update botnick set name='%s'" % _botnick)
		put("NICK %s" % _botnick)

	_userdb.execute("delete from auth where nick='%s'" % nick)

	whois(newnick)
Exemplo n.º 14
0
def kick(nick,host,chan,arg):
	auth = getauth(nick)
	flag = getflag(chan,auth)
	hostmask = nick+"!"+host
	hostflag = gethostflag(chan,hostmask)

	if flag == "n" or flag == "o" or hostflag == "o":
		if len(arg.split()) != 0:
			target = arg.split()[0]
			reason = "Requested."

			if len(arg.split()) != 1:
				reason = ' '.join(arg.split()[1:])

			put("KICK %s %s :%s" % (chan,target,reason))
Exemplo n.º 15
0
def kick(nick, host, chan, arg):
    auth = getauth(nick)
    flag = getflag(chan, auth)
    hostmask = nick + "!" + host
    hostflag = gethostflag(chan, hostmask)

    if flag == "n" or flag == "o" or hostflag == "o":
        if len(arg.split()) != 0:
            target = arg.split()[0]
            reason = "Requested."

            if len(arg.split()) != 1:
                reason = ' '.join(arg.split()[1:])

            put("KICK %s %s :%s" % (chan, target, reason))
Exemplo n.º 16
0
def exempt(nick,host,chan,arg):
	auth = getauth(nick)
	flag = getflag(chan,auth)
	hostmask = nick+"!"+host
	hostflag = gethostflag(chan,hostmask)

	if flag == "n" or flag == "o" or hostflag == "o":
		if len(arg.split()) > 0:
			target = arg.split()[0][1:]
			scut = arg.split()[0][0]

			if wmatch(target, "*!*@*"):
				if scut == "+":
					entry = False

					for data in _chandb.execute("select exempt from exempts where channel='%s' and exempt='%s'" % (chan,target)):
						entry = True

					if entry is False:
						_chandb.execute("insert into exempts values ('%s','%s')" % (chan,target))
						put("NOTICE %s :[%s] %s has been added to the exemptlist" % (nick,chan,target))
						whochan(chan)
					else:
						put("NOTICE %s :[%s] %s is already on the exemptlist" % (nick,chan,target))
				elif scut == "-":
					entry = False

					for data in _chandb.execute("select exempt from exempts where channel='%s' and exempt='%s'" % (chan,target)):
						entry = True

					if entry is True:
						_chandb.execute("delete from exempts where channel='%s' and exempt='%s'" % (chan,target))
						put("NOTICE %s :[%s] %s has been removed from the exemptlist" % (nick,chan,target))
						put("MODE %s -b %s" % (chan,target))
					else:
						put("NOTICE %s :[%s] %s is not on the exemptlist" % (nick,chan,target))
				else:
					irc_send(nick,"$exempt +/-*!*example@*.example.com")
			else:
				irc_send(nick,"$exempt +/-*!*example@*.example.com")
		else:
			for data in _chandb.execute("select exempt from exempts where channel='%s'" % chan):
				irc_send(nick,"[%s] %s" % (chan,str(data[0])))
Exemplo n.º 17
0
Arquivo: irc.py Projeto: Pythonz/PIRB
def irc_bans(text):
	chan = text.split()[3]
	host = text.split()[7]+"!"+text.split()[4]+"@"+text.split()[5]

	for data in _chandb.execute("select ban from bans where channel='%s'" % chan):
		if wmatch(host.lower(), str(data[0]).lower()):
			entry = False

			for data1 in _chandb.execute("select exempt from exempts where channel='%s'" % chan):
				if wmatch(host.lower(), str(data1[0]).lower()):
					entry = True

				for botnick in _cache.execute("select name from botnick"):
					if str(text.split()[7]).lower() == str(text.split()[2]).lower():
						entry = True

			if entry == False:
				put("MODE %s +b %s" % (chan,data[0]))
				put("KICK %s %s :Banned." % (chan,text.split()[7]))
Exemplo n.º 18
0
Arquivo: irc.py Projeto: Pythonz/PIRB
def irc_bans(text):
    chan = text.split()[3]
    host = text.split()[7] + "!" + text.split()[4] + "@" + text.split()[5]

    for data in _chandb.execute("select ban from bans where channel='%s'" %
                                chan):
        if wmatch(host.lower(), str(data[0]).lower()):
            entry = False

            for data1 in _chandb.execute(
                    "select exempt from exempts where channel='%s'" % chan):
                if wmatch(host.lower(), str(data1[0]).lower()):
                    entry = True

                for botnick in _cache.execute("select name from botnick"):
                    if str(text.split()[7]).lower() == str(
                            text.split()[2]).lower():
                        entry = True

            if entry == False:
                put("MODE %s +b %s" % (chan, data[0]))
                put("KICK %s %s :Banned." % (chan, text.split()[7]))
Exemplo n.º 19
0
def channel_auth(nick,host,chan,arg):
	whois(nick)
	put("NOTICE %s :[%s] Trying to auth ..." % (nick,chan))
	auth = getauth(nick)
	hostmask = nick+"!"+host
	put("NOTICE %s :[%s] Getting flag for %s (%s)..." % (nick,chan,auth,hostmask))
	flag = getflag(chan,auth)
	hostflag = gethostflag(chan,hostmask)
	put("NOTICE %s :[%s] Flag: %s, Hostflag: %s" % (nick,chan,flag,hostflag))

	if flag == "n" or flag == "o" or hostflag == "o":
		putf("MODE %s +o %s" % (chan,nick))
	elif flag == "v" or hostflag == "v":
		putf("MODE %s +v %s" % (chan,nick))
Exemplo n.º 20
0
def channel_auth(nick, host, chan, arg):
    whois(nick)
    put("NOTICE %s :[%s] Trying to auth ..." % (nick, chan))
    auth = getauth(nick)
    hostmask = nick + "!" + host
    put("NOTICE %s :[%s] Getting flag for %s (%s)..." %
        (nick, chan, auth, hostmask))
    flag = getflag(chan, auth)
    hostflag = gethostflag(chan, hostmask)
    put("NOTICE %s :[%s] Flag: %s, Hostflag: %s" %
        (nick, chan, flag, hostflag))

    if flag == "n" or flag == "o" or hostflag == "o":
        putf("MODE %s +o %s" % (chan, nick))
    elif flag == "v" or hostflag == "v":
        putf("MODE %s +v %s" % (chan, nick))
Exemplo n.º 21
0
def channel_listuser(nick,host,chan,arg):
	for owner in _chandb.execute("select auth from channel where channel='%s' and flags='n'" % chan):
		put("NOTICE %s :[%s] %s is the owner" % (nick,chan,owner[0]))

	op = list()

	for operator in _chandb.execute("select auth from channel where channel='%s' and flags='o'" % chan):
		op.append(str(operator[0]))

	operators = ' '.join(op)
	put("NOTICE %s :[%s] Operators: %s" % (nick,chan,operators))
	v = list()

	for voice in _chandb.execute("select auth from channel where channel='%s' and flags='v'" % chan):
		v.append(str(voice[0]))

	voices = ' '.join(v)
	put("NOTICE %s :[%s] Voices: %s" % (nick,chan,voices))
Exemplo n.º 22
0
def channel_msg_auth(nick,host,arg):
	if len(arg) == 0:
		irc_send(nick, "no channel specified")
	elif arg.startswith("#"):
		whois(nick)
		chan = arg.split()[0]
		put("NOTICE %s :[%s] Trying to auth ..." % (nick,chan))
		auth = getauth(nick)
		hostmask = nick+"!"+host
		put("NOTICE %s :[%s] Getting flag for %s (%s)..." % (nick,chan,auth,hostmask))
		flag = getflag(chan,auth)
		hostflag = gethostflag(chan,hostmask)
		put("NOTICE %s :[%s] Flag: %s, Hostflag: %s" % (nick,chan,flag,hostflag))

		if flag == "n" or flag == "o" or hostflag == "o":
			putf("MODE %s +o %s" % (chan,nick))
		elif flag == "v" or hostflag == "v":
			putf("MODE %s +v %s" % (chan,nick))
	else:
		irc_send(nick, "invalid channel")
Exemplo n.º 23
0
def channel_msg_auth(nick, host, arg):
    if len(arg) == 0:
        irc_send(nick, "no channel specified")
    elif arg.startswith("#"):
        whois(nick)
        chan = arg.split()[0]
        put("NOTICE %s :[%s] Trying to auth ..." % (nick, chan))
        auth = getauth(nick)
        hostmask = nick + "!" + host
        put("NOTICE %s :[%s] Getting flag for %s (%s)..." %
            (nick, chan, auth, hostmask))
        flag = getflag(chan, auth)
        hostflag = gethostflag(chan, hostmask)
        put("NOTICE %s :[%s] Flag: %s, Hostflag: %s" %
            (nick, chan, flag, hostflag))

        if flag == "n" or flag == "o" or hostflag == "o":
            putf("MODE %s +o %s" % (chan, nick))
        elif flag == "v" or hostflag == "v":
            putf("MODE %s +v %s" % (chan, nick))
    else:
        irc_send(nick, "invalid channel")
Exemplo n.º 24
0
def channel_listuser(nick, host, chan, arg):
    for owner in _chandb.execute(
            "select auth from channel where channel='%s' and flags='n'" %
            chan):
        put("NOTICE %s :[%s] %s is the owner" % (nick, chan, owner[0]))

    op = list()

    for operator in _chandb.execute(
            "select auth from channel where channel='%s' and flags='o'" %
            chan):
        op.append(str(operator[0]))

    operators = ' '.join(op)
    put("NOTICE %s :[%s] Operators: %s" % (nick, chan, operators))
    v = list()

    for voice in _chandb.execute(
            "select auth from channel where channel='%s' and flags='v'" %
            chan):
        v.append(str(voice[0]))

    voices = ' '.join(v)
    put("NOTICE %s :[%s] Voices: %s" % (nick, chan, voices))
Exemplo n.º 25
0
def channel_delvoice(nick, host, chan, arg):
    auth = getauth(nick)
    flag = getflag(chan, auth)
    target = getauth(arg.split()[0])
    uatarget = arg.split()[0]

    if flag == "n":
        if auth != target:
            if wmatch(uatarget, "*!*@*"):
                entry = True

                for data in _chandb.execute(
                        "select flags from channel where channel='%s' and auth = '%s' and flags='v'"
                        % (chan, uatarget)):
                    entry = False

                if entry is False:
                    _chandb.execute(
                        "delete from channel where channel='%s' and auth='%s' and flags='v'"
                        % (chan, uatarget))
                    put("NOTICE %s :[%s] %s has been removed from the voices list"
                        % (nick, chan, uatarget))
                else:
                    put("NOTICE %s :[%s] %s is not on the voices list" %
                        (nick, chan, uatarget))
            else:
                entry = True

                for data in _chandb.execute(
                        "select flags from channel where channel='%s' and auth='%s' and flags='v'"
                        % (chan, target)):
                    entry = False

                if entry is False:
                    _chandb.execute(
                        "delete from channel where channel='%s' and auth='%s' and flags='v'"
                        % (chan, target))
                    put("NOTICE %s :[%s] %s has been removed from the voices list"
                        % (nick, chan, target))
                    put("MODE %s -v %s" % (chan, arg.split()[0]))
                else:
                    put("NOTICE %s :[%s] %s is not on the voices list" %
                        (nick, chan, target))
        else:
            put("NOTICE %s :[%s] You cannot remove yourself!" % (nick, chan))
Exemplo n.º 26
0
def channel_addvoice(nick,host,chan,arg):
	auth = getauth(nick)
	flag = getflag(chan,auth)
	target = getauth(arg.split()[0])
	uatarget = arg.split()[0]

	if flag == "n":
		if auth != target:
			if wmatch(uatarget, "*!*@*"):
				entry = False

				for data in _chandb.execute("select flags from channel where channel='%s' and auth = '%s' and flags='v'" % (chan,uatarget)):
					entry = True

				if entry is False:
					_chandb.execute("insert into channel values ('%s','%s','v')" % (chan,uatarget))
					put("NOTICE %s :[%s] %s has been added to the voices list" % (nick,chan,uatarget))
				else:
					put("NOTICE %s :[%s] %s is already on the voices list" % (nick,chan,uatarget))
			else:
				entry = False

				for data in _chandb.execute("select flags from channel where channel='%s' and auth='%s' and flags='v'" % (chan,target)):
					entry = True

				if entry is False:
					_chandb.execute("insert into channel values ('%s','%s','v')" % (chan,target))
					put("NOTICE %s :[%s] %s has been added to the voices list" % (nick,chan,target))
					put("MODE %s +v %s" % (chan,arg.split()[0]))
				else:
					put("NOTICE %s :[%s] %s is already on the voices list" % (nick,chan,target))
		else:
			put("NOTICE %s :[%s] You cannot add yourself!" % (nick,chan))
Exemplo n.º 27
0
def channel_invite(nick, uhost, chan, target):
    if target.lower() == botnick().lower():
        for data in _chandb.execute(
                "select channel from list where channel='%s'" % chan):
            put("JOIN %s" % chan)
Exemplo n.º 28
0
def channel_addvoice(nick, host, chan, arg):
    auth = getauth(nick)
    flag = getflag(chan, auth)
    target = getauth(arg.split()[0])
    uatarget = arg.split()[0]

    if flag == "n":
        if auth != target:
            if wmatch(uatarget, "*!*@*"):
                entry = False

                for data in _chandb.execute(
                        "select flags from channel where channel='%s' and auth = '%s' and flags='v'"
                        % (chan, uatarget)):
                    entry = True

                if entry is False:
                    _chandb.execute(
                        "insert into channel values ('%s','%s','v')" %
                        (chan, uatarget))
                    put("NOTICE %s :[%s] %s has been added to the voices list"
                        % (nick, chan, uatarget))
                else:
                    put("NOTICE %s :[%s] %s is already on the voices list" %
                        (nick, chan, uatarget))
            else:
                entry = False

                for data in _chandb.execute(
                        "select flags from channel where channel='%s' and auth='%s' and flags='v'"
                        % (chan, target)):
                    entry = True

                if entry is False:
                    _chandb.execute(
                        "insert into channel values ('%s','%s','v')" %
                        (chan, target))
                    put("NOTICE %s :[%s] %s has been added to the voices list"
                        % (nick, chan, target))
                    put("MODE %s +v %s" % (chan, arg.split()[0]))
                else:
                    put("NOTICE %s :[%s] %s is already on the voices list" %
                        (nick, chan, target))
        else:
            put("NOTICE %s :[%s] You cannot add yourself!" % (nick, chan))
Exemplo n.º 29
0
def channel_invite(nick,uhost,chan,target):
	if target.lower() == botnick().lower():
		for data in _chandb.execute("select channel from list where channel='%s'" % chan):
			put("JOIN %s" % chan)
Exemplo n.º 30
0
Arquivo: ctcp.py Projeto: Pythonz/PIRB
def notice(target,text):
	put("NOTICE %s :%s" % (target,text))
Exemplo n.º 31
0
def on_quit(nick, uhost, arg):
    _userdb.execute("delete from auth where nick='%s'" % nick)

    if nick.lower() == _botnick.lower():
        _cache.execute("update botnick set name='%s'" % _botnick)
        put("NICK %s" % _botnick)
Exemplo n.º 32
0
def on_topic(nick,uhost,chan,arg):
	for mynick in _cache.execute("select name from botnick"):
		if nick != str(mynick[0]) and nick != "Q" and nick != "ChanServ":
			for data in _chandb.execute("select topic from info where channel='%s'" % chan):
				put("TOPIC %s :%s" % (chan,str(data[0])))
Exemplo n.º 33
0
def uname(nick,host,chan,arg):
	sysinfo = ' '.join(os.uname())
	put("PRIVMSG %s :%s" % (chan, sysinfo))
Exemplo n.º 34
0
def channel_join(text):
	putf("JOIN %s" % c.get("BOT", "channels"))

	for data in _chandb.execute("select channel from list"):
		put("JOIN %s" % data[0])
Exemplo n.º 35
0
def channel_kick(nick,uhost,chan,target,arg):
	for data in _cache.execute("select name from botnick"):
		for user in target.split(","):
			if user.lower() == str(data[0]).lower():
				put("JOIN %s" % chan)
Exemplo n.º 36
0
Arquivo: irc.py Projeto: Pythonz/PIRB
def irc_send(target,message):
	if target.startswith("#"):
		put("PRIVMSG %s :%s" % (target,message))
	else:
		put("NOTICE %s :%s" % (target,message))
Exemplo n.º 37
0
Arquivo: irc.py Projeto: Pythonz/PIRB
def irc_botnick(nick, host, chan, arg):
    for data in _cache.execute("select name from botnick"):
        put("PRIVMSG %s :My configured nick is %s and my current nick is %s." %
            (chan, _botnick, str(data[0])))
Exemplo n.º 38
0
def channel_join(text):
    putf("JOIN %s" % c.get("BOT", "channels"))

    for data in _chandb.execute("select channel from list"):
        put("JOIN %s" % data[0])
Exemplo n.º 39
0
Arquivo: ctcp.py Projeto: Pythonz/PIRB
def notice(target, text):
    put("NOTICE %s :%s" % (target, text))
Exemplo n.º 40
0
def channel_kick(nick, uhost, chan, target, arg):
    for data in _cache.execute("select name from botnick"):
        for user in target.split(","):
            if user.lower() == str(data[0]).lower():
                put("JOIN %s" % chan)
Exemplo n.º 41
0
    def client(self, sock, addr, servsock):
        try:
            printc("!! conntected with " + addr + " !!")
            self.send(sock, "Hello. I am %s." % c.get("BOT", "username"))
            self.send(sock, "Welcome to the remote interface of PIRB.")
            self.send(sock,
                      "Please enter the administrators password to unlock!")

            if str(sock.recv(100)).rstrip() == c.get("ADMIN", "password"):
                self.send(sock, "Access granted.")
                printc("!! " + addr + " logged in !!")
            else:
                self.send(sock, "Access denied.")
                printc("!! " + addr + " failed login !!")
                sock.close()

            while 1:
                raw = sock.recv(1024)
                data = raw.rstrip()

                if not data:
                    printc("!! losed connection with " + addr + " !!")
                    sock.close()

                if data:
                    cmd = data.split()[0].lower()

                    if cmd == "crypt":
                        sha = hashlib.sha1()
                        sha.update(data[6:])
                        self.send(sock, "Hash: %s" % str(sha.hexdigest()))
                    elif cmd == "put":
                        open(".put_query", "a").write(data[4:] + "\n")
                        self.send(sock, "Sent: %s" % data[4:])
                    elif cmd == "restart":
                        if os.access("pirb.pid", os.F_OK):
                            self.send(sock, "Restarting ...")
                            servsock.close()
                            sock.close()
                            shell("sh pirb restart")
                        else:
                            self.send(sock,
                                      "Cannot restart when debug is running")
                    elif cmd == "update":
                        _file = open("version", "r")
                        _old = _file.read()
                        _file.close()
                        _web = urllib2.urlopen(
                            "https://raw.github.com/Pythonz/PIRB/master/version"
                        )
                        _new = _web.read()
                        _web.close()

                        if _old != _new:
                            self.send(sock, "{0} -> {1}".format(_old, _new))
                            __cache = len(os.listdir("database/updates/cache"))
                            __chan = len(os.listdir("database/updates/chan"))
                            __user = len(os.listdir("database/updates/user"))
                            shell("git add .")
                            shell("git rm --cached database/*.db")
                            shell("git commit -m 'Save'")
                            shell("git pull")
                            ___cache = os.listdir("database/updates/cache")

                            if __cache < len(___cache):
                                while __cache != len(___cache):
                                    __cache += 1

                                    for sql in ___cache:
                                        if sql.startswith(str(__cache) + "_"):
                                            self.send(
                                                sock,
                                                " - Insert 'cache/{0}'".format(
                                                    sql))
                                            shell(
                                                "sqlite3 database/cache.db < database/updates/cache/{0}"
                                                .format(sql))

                            ___chan == os.listdir("database/updates/chan")

                            if __chan < len(___chan):
                                while __chan != len(___chan):
                                    __chan += 1

                                    for sql in ___chan:
                                        if sql.startswith(str(__chan) + "_"):
                                            self.send(
                                                sock,
                                                " - Insert 'chan/{0}'".format(
                                                    sql))
                                            shell(
                                                "sqlite3 database/chan.db < database/updates/chan/{0}"
                                                .format(sql))

                            ___user == os.listdir("database/updates/user")

                            if __user < len(___user):
                                while __user != len(___user):
                                    __user += 1

                                    for sql in ___user:
                                        if sql.startswith(str(__user) + "_"):
                                            self.send(
                                                sock,
                                                " - Insert 'user/{0}'".format(
                                                    sql))
                                            shell(
                                                "sqlite3 database/user.db < database/updates/user/{0}"
                                                .format(sql))

                            put("QUIT :Updating...")
                            servsock.close()
                            sock.close()
                            shell("sh pirb restart")
                        else:
                            self.send(sock, "No update available.")
                    elif cmd == "version":
                        file = open("version", "r")
                        self.send(sock, "PIRB " + file.read())
                        file.close()
                    elif cmd == "quit":
                        self.send(sock, "Bye :(")
                        sock.close()
                    elif cmd == "die":
                        servsock.close()
                        sock.close()
                        if os.access("pirb.pid", os.F_OK):
                            shell("sh pirb stop")
                        else:
                            sys.exit(2)
                    elif cmd == "help":
                        tbl = list()
                        tbl.append("help")
                        tbl.append("crypt")
                        tbl.append("put")
                        tbl.append("restart")
                        tbl.append("update")
                        tbl.append("version")
                        tbl.append("die")
                        tbl.append("quit")
                        for command in tbl:
                            self.send(sock, command.upper())
                    else:
                        self.send(
                            sock,
                            "unknown command '%s'. try 'HELP'" % cmd.upper())

        except Exception, e:
            printe(e)
Exemplo n.º 42
0
def on_mode(nick,uhost,chan,arg):
	for mynick in _cache.execute("select name from botnick"):
		if nick != str(mynick[0]):
			for data in _chandb.execute("select modes from info where channel='%s'" % chan):
				put("MODE %s %s" % (chan,str(data[0])))
Exemplo n.º 43
0
Arquivo: irc.py Projeto: Pythonz/PIRB
def irc_send(target, message):
    if target.startswith("#"):
        put("PRIVMSG %s :%s" % (target, message))
    else:
        put("NOTICE %s :%s" % (target, message))
Exemplo n.º 44
0
def channel_delvoice(nick,host,chan,arg):
	auth = getauth(nick)
	flag = getflag(chan,auth)
	target = getauth(arg.split()[0])
	uatarget = arg.split()[0]

	if flag == "n":
		if auth != target:
			if wmatch(uatarget, "*!*@*"):
				entry = True

				for data in _chandb.execute("select flags from channel where channel='%s' and auth = '%s' and flags='v'" % (chan,uatarget)):
					entry = False

				if entry is False:
					_chandb.execute("delete from channel where channel='%s' and auth='%s' and flags='v'" % (chan,uatarget))
					put("NOTICE %s :[%s] %s has been removed from the voices list" % (nick,chan,uatarget))
				else:
					put("NOTICE %s :[%s] %s is not on the voices list" % (nick,chan,uatarget))
			else:
				entry = True

				for data in _chandb.execute("select flags from channel where channel='%s' and auth='%s' and flags='v'" % (chan,target)):
					entry = False

				if entry is False:
					_chandb.execute("delete from channel where channel='%s' and auth='%s' and flags='v'" % (chan,target))
					put("NOTICE %s :[%s] %s has been removed from the voices list" % (nick,chan,target))
					put("MODE %s -v %s" % (chan,arg.split()[0]))
				else:
					put("NOTICE %s :[%s] %s is not on the voices list" % (nick,chan,target))
		else:
			put("NOTICE %s :[%s] You cannot remove yourself!" % (nick,chan))
Exemplo n.º 45
0
def on_topic(nick, uhost, chan, arg):
    for mynick in _cache.execute("select name from botnick"):
        if nick != str(mynick[0]) and nick != "Q" and nick != "ChanServ":
            for data in _chandb.execute(
                    "select topic from info where channel='%s'" % chan):
                put("TOPIC %s :%s" % (chan, str(data[0])))
Exemplo n.º 46
0
Arquivo: ctcp.py Projeto: Pythonz/PIRB
def ctcp(target, text):
    put(u"PRIVMSG %s :\u0001%s\u0001" % (target, text))
Exemplo n.º 47
0
def on_mode(nick, uhost, chan, arg):
    for mynick in _cache.execute("select name from botnick"):
        if nick != str(mynick[0]):
            for data in _chandb.execute(
                    "select modes from info where channel='%s'" % chan):
                put("MODE %s %s" % (chan, str(data[0])))
Exemplo n.º 48
0
	def client(self,sock,addr,servsock):
		try:
			printc("!! conntected with "+addr+" !!")
			self.send(sock,"Hello. I am %s." % c.get("BOT","username"))
			self.send(sock,"Welcome to the remote interface of PIRB.")
			self.send(sock,"Please enter the administrators password to unlock!")

			if str(sock.recv(100)).rstrip() == c.get("ADMIN", "password"):
				self.send(sock,"Access granted.")
				printc("!! "+addr+" logged in !!")
			else:
				self.send(sock,"Access denied.")
				printc("!! "+addr+" failed login !!")
				sock.close()

			while 1:
				raw = sock.recv(1024)
				data = raw.rstrip()

				if not data:
					printc("!! losed connection with "+addr+ " !!")
					sock.close()

				if data:
					cmd = data.split()[0].lower()

					if cmd == "crypt":
						sha = hashlib.sha1()
						sha.update(data[6:])
						self.send(sock,"Hash: %s" % str(sha.hexdigest()))
					elif cmd == "put":
						open(".put_query", "a").write(data[4:]+"\n")
						self.send(sock,"Sent: %s" % data[4:])
					elif cmd == "restart":
						if os.access("pirb.pid", os.F_OK):
							self.send(sock,"Restarting ...")
							servsock.close()
							sock.close()
							shell("sh pirb restart")
						else:
							self.send(sock,"Cannot restart when debug is running")
					elif cmd == "update":
						_file = open("version", "r")
						_old = _file.read()
						_file.close()
						_web = urllib2.urlopen("https://raw.github.com/Pythonz/PIRB/master/version")
						_new = _web.read()
						_web.close()

						if _old != _new:
							self.send(sock, "{0} -> {1}".format(_old, _new))
							__cache = len(os.listdir("database/updates/cache"))
							__chan = len(os.listdir("database/updates/chan"))
							__user = len(os.listdir("database/updates/user"))
							shell("git add .")
							shell("git rm --cached database/*.db")
							shell("git commit -m 'Save'")
							shell("git pull")
							___cache = os.listdir("database/updates/cache")

							if __cache < len(___cache):
								while __cache != len(___cache):
									__cache += 1

									for sql in ___cache:
										if sql.startswith(str(__cache)+"_"):
											self.send(sock, " - Insert 'cache/{0}'".format(sql))
											shell("sqlite3 database/cache.db < database/updates/cache/{0}".format(sql))

							___chan == os.listdir("database/updates/chan")

							if __chan < len(___chan):
								while __chan != len(___chan):
									__chan += 1

									for sql in ___chan:
										if sql.startswith(str(__chan)+"_"):
											self.send(sock, " - Insert 'chan/{0}'".format(sql))
											shell("sqlite3 database/chan.db < database/updates/chan/{0}".format(sql))

							___user == os.listdir("database/updates/user")

							if __user < len(___user):
								while __user != len(___user):
									__user += 1

									for sql in ___user:
										if sql.startswith(str(__user)+"_"):
											self.send(sock, " - Insert 'user/{0}'".format(sql))
											shell("sqlite3 database/user.db < database/updates/user/{0}".format(sql))

							put("QUIT :Updating...")
							servsock.close()
							sock.close()
							shell("sh pirb restart")
						else:
							self.send(sock, "No update available.")
					elif cmd == "version":
						file = open("version", "r")
						self.send(sock, "PIRB "+file.read())
						file.close()
					elif cmd == "quit":
						self.send(sock,"Bye :(")
						sock.close()
					elif cmd == "die":
						servsock.close()
						sock.close()
						if os.access("pirb.pid", os.F_OK):
							shell("sh pirb stop")
						else: sys.exit(2)
					elif cmd == "help":
						tbl = list()
						tbl.append("help")
						tbl.append("crypt")
						tbl.append("put")
						tbl.append("restart")
						tbl.append("update")
						tbl.append("version")
						tbl.append("die")
						tbl.append("quit")
						for command in tbl:
							self.send(sock, command.upper())
					else:
						self.send(sock,"unknown command '%s'. try 'HELP'" % cmd.upper())

		except Exception,e: printe(e)
Exemplo n.º 49
0
Arquivo: user.py Projeto: Pythonz/PIRB
def on_quit(nick,uhost,arg):
	_userdb.execute("delete from auth where nick='%s'" % nick)

	if nick.lower() == _botnick.lower():
		_cache.execute("update botnick set name='%s'" % _botnick)
		put("NICK %s" % _botnick)
Exemplo n.º 50
0
Arquivo: ctcp.py Projeto: Pythonz/PIRB
def ctcp(target,text):
	put(u"PRIVMSG %s :\u0001%s\u0001" % (target,text))
Exemplo n.º 51
0
Arquivo: irc.py Projeto: Pythonz/PIRB
def irc_botnick(nick,host,chan,arg):
	for data in _cache.execute("select name from botnick"):
		put("PRIVMSG %s :My configured nick is %s and my current nick is %s." % (chan,_botnick,str(data[0])))