def on_privmsg(self, address, target, text): nickname = address.split('!')[0] if target == self.irc.nickname: if text.startswith('perform'): params = text.split() if params[0] != 'perform': return user = Auth.get_user_by_hostmask(self.irc.id, address) if user is None or 'n' not in user.flags: self.irc.notice(nickname, 'Insufficient privileges') elif len(params) == 1: self.irc.notice(nickname, 'Available commands: list add delete') elif params[1] == 'list': lines = Perform.list_lines(self.irc.id) self.irc.notice(nickname, 'Id Line') for l in lines: self.irc.notice(nickname, '%s %s' % l) self.irc.notice(nickname, 'End of list') elif params[1] == 'add': if len(params) < 3: self.irc.notice(nickname, 'Usage: perform add <line>') else: pid = Perform.add(self.irc.id, ' '.join(params[2:])) self.irc.notice(nickname, 'Done. Id: {}'.format(pid)) elif params[1] == 'delete': if len(params) < 3: self.irc.notice(nickname, 'Usage: perform delete <id>') else: if Perform.delete(self.irc.id, params[2]): self.irc.notice(nickname, 'Done') else: self.irc.notice(nickname, 'Unable to delete line')
def main(): parser = argparse.ArgumentParser() parser.add_argument('--api-key', help='The API key to encode in the token.') parser.add_argument('--secret', help='The secret to build the JWT with.') parser.add_argument('--stage', choices=Config.Stages.ALL, help='The stage to load from the config file') args = parser.parse_args() api_keys = [] api_key = args.api_key secret = args.secret stage = args.stage if stage: print('Loading secret and API keys from configuration for: {0}'.format(stage)) ssm_config = Config.open_local('private.ssm.env.json', stage=stage) secret = ssm_config['JWT_SECRET'] if not api_key: api_keys = ssm_config['JWT_API_KEYS'].split(',') else: if not api_key and not secret: print('Secret and API key are required when not using --stage.') return api_keys.append(api_key) for key in api_keys: token = Auth.encode_jwt(secret, key) print('-' * 80) print('API Key: {0}'.format(key)) print('JWT: {0}'.format(token))
def login(self): validator = Validator({ "email": { "type": "string", "regex": '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$', "required": True, }, "password": { "type": "string", "minlength": 6, "required": True, }, }) validate = validator.validate(request.post()) if not validate: return res().response(status_code=422, error=validator.errors) user = User.where("email", request.post('email')).first() if not user: return res().response(status_code=404) check_password = check_password_hash(user.password, request.post('password')) # check_password = Auth.verify_password(user.password, request.post('password')) if not check_password: return res().response(status_code=401) if Auth.login(user) is False: return res().response(message="error in login", status_code=400) user.token() return res().response(data=user.token.to_dict())
def main(): parser = argparse.ArgumentParser() parser.add_argument('secret', help='The secret to build the JWT with.') parser.add_argument('api_key', metavar='api-key', help='The API key to encode in the token.') args = parser.parse_args() token = Auth.encode_jwt(args.secret, args.api_key) print('Token: {0}'.format(token))
def on_privmsg(self, address, target, text): nickname = address.split('!')[0] if target == self.irc.nickname: user = Auth.get_user_by_hostmask(self.irc.id, address) command = text.strip().split(' ', 1)[0] params = text.split()[1:] if user is None or 'n' not in user.flags: self.irc.notice(nickname, 'Insufficient privileges') return if command == 'rehash': self.irc.factory.reload_modules() self.irc.notice(nickname, 'Done') elif command == 'sendline': self.irc.sendLine(' '.join(params)) elif command == 'whitelist': try: command = text.split()[1] params = text.split()[2:] except IndexError: command = None params = [] if not command: self.irc.notice(nickname, 'Available commands: add delete listauths listpermissions') elif command == 'add': if len(params) == 2: Whitelist.add_permission(self.irc.id, params[0], params[1]) self.irc.notice(nickname, 'Added permission successfully') else: self.irc.notice(nickname, 'Syntax: whitelist add <network_auth> <permission>') elif command == 'delete': if len(params) == 2: if Whitelist.delete_permission(self.irc.id, params[0], params[1]): self.irc.notice(nickname, 'Deleted permission successfully') else: self.irc.notice(nickname, 'This auth name has no permissions') else: self.irc.notice(nickname, 'Syntax: whitelist delete <network_auth> <permission>') elif command == 'listauths': auths = Whitelist.list_auths(self.irc.id) if auths: auths = ', '.join([x[0] for x in auths]) self.irc.notice(nickname, 'Auths: {}'.format(auths)) elif command == 'listpermissions': if len(params) == 1: permissions = Whitelist.get_permissions(self.irc.id, params[0]) if permissions: permissions = ', '.join(permissions) self.irc.notice(nickname, '{}\'s permissions: {}'.format(params[0], permissions)) else: self.irc.notice(nickname, 'Syntax: whitelist listpermissions <network_auth>')
def del_quote(self, target, address, params, **kwargs): nickname, username, hostname = split_address(address) user = Auth.get_user_by_hostmask(self.irc.id, address) if user is None or 'q' not in user.flags: return self.irc.notice(nickname, 'Insufficient privileges') if len(params) < 2: return self.irc.notice(nickname, 'delquote <channel> <quote_id>') channel = params[0] try: quote_id = int(params[1]) except ValueError: return self.irc.notice(nickname, 'Invalid quote id') deleted = Quote.delete(self.irc.id, channel, quote_id) if deleted: self.irc.notice(nickname, 'Quote #{} deleted successfully'.format(quote_id)) else: self.irc.notice(nickname, 'Invalid quote id')
def service(): inp = input("创建FTP用户|启动FTPServer,A|其他任意键:>>") if inp.lower() == 'a': while True: username = input("输入用户名:>>").strip() password = input("输入密码:>>").strip() quota = input("设定家目录大小(Mb):>>").strip() if not quota.isdigit(): print("请输入数字字符") inp_continue = input("退出或重新录入,q|其他任意键:>>").strip() if inp_continue.lower() == 'q': break continue if Auth().create_user(username, password, quota): break else: FTPService().run()
def on_privmsg(self, address, target, text): if target == self.irc.nickname and text.startswith('ircpaint'): params = text.split() if params[0] != 'ircpaint': return nickname = address.split('!')[0] user = Auth.get_user_by_hostmask(self.irc.id, address) if user is None or 'n' not in user.flags: self.irc.notice(nickname, 'Insufficient privileges') elif len(params) < 3: self.irc.notice(nickname, 'Usage: ircpaint <target> <id>') else: try: drawing = self.get_drawing(params[2]) except urllib2.HTTPError as e: self.irc.notice(nickname, 'Unable to get drawing: {}'.format(e)) else: drawing = drawing.split() for line in drawing: self.irc.msg(params[1], line.strip())
import core.cover def openAddonSettings(addonId, id1=None, id2=None): xbmc.executebuiltin('Addon.OpenSettings(%s)' % addonId) if id1 != None: xbmc.executebuiltin('SetFocus(%i)' % (id1 + 200)) if id2 != None: xbmc.executebuiltin('SetFocus(%i)' % (id2 + 100)) if (sys.argv[1] == 'clear_cache'): CACHE = xbmcup.db.Cache(xbmcup.system.fs('sandbox://' + CACHE_DATABASE)) CACHE.flush() SQL = xbmcup.db.SQL(xbmcup.system.fs('sandbox://' + CACHE_DATABASE)) SQL.set('DELETE FROM search') xbmcup.gui.message('Кеш успешно очищен') if (sys.argv[1] == 'login'): is_logged = Auth().autorize() if (is_logged): xbmcup.gui.message('Вы успешно авторизованы') else: xbmcup.gui.message('Войти не удалось, проверьте логин и пароль') openAddonSettings(PLUGIN_ID, 1, 0) if (sys.argv[1] == 'logout'): Auth().reset_auth(True) xbmcup.gui.message('Вы успешно вышли') openAddonSettings(PLUGIN_ID, 1, 0)
def on_privmsg(self, address, target, text): if target.startswith('#') and 'http' in text and self.api: status_search = self.tweet_regex.search(text) if status_search is not None: status_id = status_search.groups()[0] try: tweet = self.get_status(status_id) except TwitterError: pass else: message = u'' if tweet['user']['verified']: message += u'{bold}\u2713{bold}'.format(bold=chr(2)) message += u'{bold}@{screen_name}{bold} {italics}({name}){italics}: {full_text}'.format(bold=chr(2), italics=chr(29), screen_name=tweet['user']['screen_name'], name=tweet['user']['name'], full_text=paragraphy_string(html_parser.unescape(tweet['full_text']))) self.irc.msg(target, message) if target == self.tweet_channel: if text[0] not in base.prefix: return nickname, username, hostname = split_address(address) command = text.strip().split(' ', 1)[0][1:] if 'tweet' not in command: return params = text.split()[1:] user = self.irc.network.get_user_by_nickname(nickname) if not user or not user.networkauth or not Whitelist.has_permission(self.irc.id, user.networkauth, 'twitter'): return if command == 'tweet' and len(params): r = self.tweet(' '.join(params), networkauth=user.networkauth) self.irc.msg(target, r) if command == 'tweetreply' and len(params) > 1: r = self.tweet(' '.join(params[1:]), reply_to=params[0], networkauth=user.networkauth) self.irc.msg(target, r) if command == 'tweetmedia' and len(params) > 1: r = self.tweet(' '.join(params[1:]), media=params[0], networkauth=user.networkauth) self.irc.msg(target, r) if command == 'tweetmediareply' and len(params) > 1: r = self.tweet(' '.join(params[2:]), reply_to=params[0], media=params[0], networkauth=user.networkauth) self.irc.msg(target, r) elif command == 'deltweet' and len(params): tweetid = params[0] tweetauth = Tweet.get_auth_by_tweet(tweetid) user = Auth.get_user_by_hostmask(self.irc.id, address) if tweetauth or user is not None and 't' in user.flags: if tweetauth == user.networkauth or flags is not None and 't' in flags[1]: r = self.tweet_delete(tweetid) self.irc.msg(target, r) else: self.irc.msg(target, 'You are not the tweet author (author: {})'.format(tweetauth)) else: self.irc.msg(target, 'No such tweet on record') elif command == 'whotweeted' and len(params): tweetid = params[0] tweetauth = Tweet.get_auth_by_tweet(tweetid) if tweetauth: self.irc.msg(target, 'Author: {}'.format(tweetauth)) else: self.irc.msg(target, 'No such tweet on record') elif target == self.irc.nickname and text.split(' ', 1)[0] == 'twitter': try: command = text.split()[1] params = text.split()[2:] except IndexError: command = None params = [] nickname, username, hostname = split_address(address) user = Auth.get_user_by_hostmask(self.irc.id, address) if user is None or 't' not in user.flags: self.irc.notice(nickname, 'Insufficient privileges') elif not command: self.irc.notice(nickname, 'Available commands: tweet deltweet whotweeted') elif command == 'tweet': if len(params): r = self.tweet(' '.join(params)) self.irc.notice(nickname, r) else: self.irc.notice(nickname, 'No text provided') elif command == 'whotweeted': if len(params): tweetauth = Tweet.get_auth_by_tweet(params[0]) if tweetauth: self.irc.notice(nickname, 'Author: {}'.format(tweetauth)) else: self.irc.notice(nickname, 'No such tweet on record') else: self.irc.notice(nickname, 'No tweet id provided') if command == 'deltweet': if len(params): r = self.deleteTweet(params[0]) self.irc.notice(nickname, r) else: self.irc.notice(nickname, 'No tweet id provided')
def logout(self): Auth.logout() return res().response()
def user(self): user = Auth.user() if not user: return res().response(status_code=403) return res().response(data=user.to_dict())