def f_reload(self, origin, args): if not check_access(self, origin.target, origin.nick, "reload"): return folder="" name = args.params modules = os.path.join(os.getcwd(), 'modules') is_home=name+".py" in os.listdir(os.getcwd()) is_in_modules=name+".py" in os.listdir(modules) if not name: self.connection.notice(origin.nick, "module name expected") return elif not is_home and not is_in_modules: self.connection.notice(origin.nick, "unknown module") return module = getattr(__import__('modules.' + name), name) reload(module) self.register(vars(module)) self.bindrules() if hasattr(module, '__file__'): mtime = os.path.getmtime(module.__file__) modified = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime)) else: modified = 'unknown' msg = '%r (version: %s)' % (module, modified) self.connection.notice(origin.nick, origin.nick + ': ' + msg)
def f_group(self, origin, args): c = self.connection if check_access(self, origin.target, origin.nick, "nick"): c.privmsg("NickServ", "group") else: c.notice(origin.nick, "%s: Only my owner can change my nickname." % origin.nick)
def devoice(bot, evt, cmd): if check_access(self, origin.target, origin.nick, "nick"): pass else: self.connection.notice( origin.nick, "%s: You aren't allowed to do this operation." % origin.nick)
def voice(bot, evt, cmd): #/msg ChanServ voice #canale utente if check_access(self, origin.target, origin.nick, "nick"): pass else: self.connection.notice( origin.nick, "%s: You aren't allowed to do this operation." % origin.nick)
def f_nickname(self, origin, args): c = self.connection newnick = args.params if check_access(self, origin.target, origin.nick, "nick"): c.nick(newnick) else: c.notice(origin.nick, "%s: Only my owner can change my nickname." % origin.nick)
def f_allchans(self, origin, args): if check_access(self, origin.target, origin.nick, "ign"): if self.channels: chans = ', '.join(self.channels.keys()) self.msg(origin.nick, chans) else: self.msg(origin.nick, "%s: Only staff can use this command." % origin.nick)
def f_dontreport(self, origin, args): if check_access(self, origin.target, origin.nick, "reboot"): if self.chans.keys(): chans = ', '.join(self.chansDB) self.msg(origin.nick, chans) else: self.msg(origin.nick, "%s: Only staff can use this command." % origin.nick)
def f_part(self, origin, args): line = resolve2(origin.target, origin.nick, args.params.encode("utf-8"), self.channels.keys()) if check_access(self, origin.target, origin.nick, "part"): self.connection.part(line) else: self.connection.notice( origin.nick, "%s: Only my owner can do this operation." % origin.nick)
def op(bot, evt, cmd): """.op <channel> <nick> - (reserved) get op for <user> at <channel>""" chan, nick = parse_params(args.params, origin.target, origin.nick) if check_access(self, origin.target, origin.nick, "nick"): if chan and nick: self.msg("ChanServ", "OP %s %s" % (chan, nick)) else: self.connection.notice( origin.nick, "%s: You aren't allowed to do this operation." % origin.nick)
def deop(bot, evt, cmd): if not origin.target.startswith("#"): return chan, nick = parse_params(args.params, origin.target, origin.nick) if check_access(self, origin.target, origin.nick, "nick"): if chan and nick: self.msg("ChanServ", "DEOP %s %s" % (chan, nick)) else: self.connection.notice( origin.nick, "%s: You aren't allowed to do this operation." % origin.nick)
def f_quit(self, origin, args): if check_access(self, origin.target, origin.nick, "quit"): msg = "i'll come back, i swear!" if args.cmd == "reboot" else args.params.encode( "utf-8") or origin.nick self.die(msg) else: self.connection.notice( origin.nick, "%s: Only my owner can do this operation." % origin.nick)
def f_igns(self, origin, args): if check_access(self, origin.target, origin.nick, "unign"): if self.igns.keys(): users = ', '.join(self.igns.keys()) self.msg(origin.nick, users) else: self.msg(origin.nick, "there are no users ignored.") else: self.msg(origin.nick, "%s: Only staff can use this command." % origin.nick)
def f_chflag(self, origin, args): c = self.connection newop = args.params.strip().split(" ")[0] flag = args.params.strip().split(" ")[1] if check_access(self, origin.target, origin.nick, "nick"): self.accounts.set_flag(newop.encode("utf-8"), flag.encode("utf-8")) c.privmsg(self.mainchan, "Now %s is flagged as %s " % (newop, flag)) else: c.notice(origin.nick, "%s: Only my owner can change my nickname." % origin.nick)
def f_gochans(self, origin, args): if check_access(self, origin.target, origin.nick, "join"): chans = ",".join(self.otherchans) self.connection.join(chans) self.msg(origin.target, "I've joined channels.") else: self.connection.notice( origin.nick, "%s: Only my owner can make join me on other channels." % origin.nick)
def test_check_access(self): user = User.objects.create(username='******') collection = Collection.objects.create() self.assertEqual(False, check_access(user, collection, read=True)) AccessControl.objects.create( user=user, content_object=collection, read=True, write=True, ) self.assertTrue(check_access(user, collection, read=True)) self.assertTrue(check_access(user, collection, read=True, write=True)) self.assertFalse(check_access(user, collection, read=True, manage=True)) try: check_access(user, collection, read=True, manage=True, fail_if_denied=True) self.assertEqual('result', 'this code should not run') except PermissionDenied: pass
def f_unign(self, origin, args): if check_access(self, origin.target, origin.nick, "unign"): params = args.params.strip().lower() els = [] elim = [] if params == "*": self.igns = [] self.msg(origin.nick, "se han eliminados todos los registros") self.log( "igns", "- | all_log |: " + origin.nick + " :| " + time.strftime("%d-%m-%y %H:%M:%S")) return if ", " in params: els = params.split(", ") else: els = [params] for el in els: if re.search("\*|\?", el): el0 = el.replace(".*", "*").replace(".?", "?").replace( "*", ".*").replace("?", ".?") for el1 in self.igns.keys(): if re.search(r"(" + el0 + ")", el1, re.I): el2 = re.search(r"(" + el0 + ")", el1, re.I).group(1) if el1.lower() == el2.lower(): elim.append(el1) else: for el1 in self.igns.keys(): if el1.lower() == el.lower(): elim.append(el1) for el in elim: self.igns.remove(el) self.log( "igns", "- | " + el + " |: " + origin.nick + " :| " + time.strftime("%d-%m-%y %H:%M:%S")) if elim: msg = "elementos eliminados: %s" % (', '.join(elim)) self.msg(origin.nick, msg) time.sleep(len(msg) / 10) msg = "elementos restantes: %s" % (', '.join(self.igns.keys())) else: msg = "no se han encontrado coincidencias" self.msg(origin.nick, msg) else: self.connection.notice( origin.nick, "%s: Only staff can use this command." % origin.nick)
def angular(environ, start_response): config = f.WebConfig() db = DB(config.db_path + '/data/') request = WSGIHandler(db, environ) headers = [('Content-type', 'text/html; charset=UTF-8'), ("Access-Control-Allow-Origin", "*")] if config.access_control: if not request.authenticated: token = f.check_access(environ, config, db) if token: print >> sys.stderr, "ISSUING TOKEN" h, ts = token headers.append( ("Set-Cookie", "hash=%s" % h) ) headers.append( ("Set-Cookie", "timestamp=%s" % ts) ) else: print >> sys.stderr, "NOT AUTHENTICATED" start_response('200 OK', headers) return build_html_page(config)
def f_join(self, origin, args): chan = args.params.strip().encode("utf-8") if check_access(self, origin.target, origin.nick, "join"): if chan in clips: chan = clips[chan] elif chan == "<chans>": f_gochans(self, origin, args) self.msg( origin.target, origin.nick + ": recuerda, ahora el comando es @gochans, pronto no se podrá utilizar @j <chans>" ) elif not chan.startswith("#"): chan = "#" + chan if chan in self.channels.keys(): self.msg(origin.target, "I am already on %s" % chan) else: self.connection.join(chan) else: self.connection.notice( origin.nick, "%s: Only my owner can make join me on other channels." % origin.nick)
def f_ign(self, origin, args): if check_access(self, origin.target, origin.nick, "ign"): params = args.params.strip() els = [] nousigns = [] if ", " in params: els = args.split(", ") else: els = [params] if "*" in els: els.remove("*") for el in els: if "pasqual" in el.lower(): if origin.host.lower() != "wikipedia/pasqual": el = nick else: self.msg(origin.nick, "je je que cachondo!") continue if el and el not in self.igns.keys(): nousigns.append(el) self.log( "igns", "+ | " + el + " |: " + origin.nick + " :| " + time.strftime("%d-%m-%y %H:%M:%S")) if len(nousigns) == 1: els = "el siguiente nick" else: els = "los siguientes nicks" if nousigns: msg = u"se ha añadido %s a la lista de ignorados: %s" % ( els, ', '.join(nousigns)) self.igns.append(nousigns) else: igns = ', '.join(self.igns.keys()).encode("utf-8") msg = u"Error: no se han podido añadir los nuevos ignorados, el bot ignorará: %s" % igns msg = msg.encode("utf-8") self.msg(origin.nick, msg) else: self.connection.notice( origin.nick, "%s: Only staff can use this command." % origin.nick)
def angular(environ, start_response): headers = [('Content-type', 'text/html; charset=UTF-8'), ("Access-Control-Allow-Origin", "*")] config = f.WebConfig() db = DB(config.db_path + '/data/') if not config.valid_config: # This means we have an error in the webconfig file html = build_misconfig_page(config.traceback, 'webconfig.cfg') # TODO handle errors in db.locals.py else: request = WSGIHandler(db, environ) if config.access_control: if not request.authenticated: token = f.check_access(environ, config, db) if token: print >> sys.stderr, "ISSUING TOKEN" h, ts = token headers.append(("Set-Cookie", "hash=%s" % h)) headers.append(("Set-Cookie", "timestamp=%s" % ts)) else: print >> sys.stderr, "NOT AUTHENTICATED" html = build_html_page(config) start_response('200 OK', headers) return html
def test_check_access(self): user = User.objects.create(username='******') collection = Collection.objects.create() self.assertEqual(False, check_access(user, collection, read=True)) AccessControl.objects.create( user=user, content_object=collection, read=True, write=True, ) self.assertTrue(check_access(user, collection, read=True)) self.assertTrue(check_access(user, collection, read=True, write=True)) self.assertFalse( check_access(user, collection, read=True, manage=True)) try: check_access( user, collection, read=True, manage=True, fail_if_denied=True) self.assertEqual('result', 'this code should not run') except PermissionDenied: pass
def ban(bot, evt, cmd): if check_access(self, origin.target, origin.nick, "nick"): pass else: self.connection.notice(origin.nick, 'Illegal kick!')
def kick(bot, evt, cmd): if check_access(self, origin.target, origin.nick, "nick"): self.connection.kick(origin.target, args.params.encode("utf-8").strip()) else: self.connection.notice(origin.nick, 'Illegal kick!')
def f_identify(self, origin, args): if check_access(self, origin.target, origin.nick, "identify"): self.msg('NickServ', 'IDENTIFY %s' % self.config.passw) self.connection.notice(origin.nick, 'Identified!')
def f_chans(self, origin, args): if check_access(self, origin.target, origin.nick, "join"): self.msg(origin.target, str(self.channels.keys()))