def authorize(request): # Make sure that the given request is correctly constructed. assert_subclass(request, AuthorizationRequest) assert_subclass(request.action, Action) print("Action:", request.action) print("Policies:", request.action.policies) # Evaluate all the policies of this action. all_inapplicable = True for policy in request.action.policies: print("Evaluating policy:", policy) try: if policy.evaluate(request): return AuthorizationResult.PERMIT else: all_inapplicable = False except Exception as error: print("Inapplicable policy: %s %s" % (type(error), error)) print_traceback(error.__traceback__) # If we get to this point, then none of the policies evaluated to true. if all_inapplicable: # If every policy threw an error, then the authorization request is # inapplicable. return AuthorizationResult.NOT_APPLICABLE else: # Otherwise, at least one policy evaluated to false. return AuthorizationResult.DENY
def __init__(self, protocol, args): self._protocol = protocol # Not a factory! :-) self._args = args # args[0] must be full path of binary. self._event_loop = events.get_event_loop() self._buffer = [] self._eof = False rstdin, self._wstdin = os.pipe() self._rstdout, wstdout = os.pipe() # TODO: This is incredibly naive. Should look at # subprocess.py for all the precautions around fork/exec. pid = os.fork() if not pid: # Child. try: os.dup2(rstdin, 0) os.dup2(wstdout, 1) # TODO: What to do with stderr? os.execv(args[0], args) except: try: traceback.print_traceback() finally: os._exit(127) # Parent. os.close(rstdin) os.close(wstdout) _setnonblocking(self._wstdin) _setnonblocking(self._rstdout) self._event_loop.call_soon(self._protocol.connection_made, self) self._event_loop.add_reader(self._rstdout, self._stdout_callback)
def adminnotes_command(sender, command, label, args): if not sender.hasPermission(an_permission): noperm(sender) return try: arglen = len(args) # arg length not valid if arglen == 0: show_all_notes(sender) return # Shows note help subcmd = args[0].lower() if subcmd == "help": show_an_help(sender) return # Delete note if subcmd == "del": if arglen != 2: show_an_help(sender) return if not args[1].isdigit(): msg(sender, "&cThe ID has to be numeric (check /an if you're unsure)") return note_id = int(args[1]) - 1 if note_id >= len(notes): msg(sender, "&cThere is no note with that ID!") return # Deletes note by index del notes[note_id] save_notes() msg(sender, "&aSuccessfully deleted note #%s!" % str(note_id + 1)) return message = " ".join(args) name = sender.getName() if name in continued_messages: message = continued_messages[name] + " " + message del continued_messages[name] if message[-2:] == "++": message = message[:-2] continued_messages[name] = message msg(sender, "&6You can continue writing by using &e/an <text ...>") else: notes.append([name, message, time.time()]) save_notes() msg(sender, "&eNew note:&6 " + message) broadcast(an_permission, "&a%s just added a new note! &2Type /an" % name) except: error(print_traceback())
def adminnotes_command(sender, command, label, args): if not sender.hasPermission(an_permission): noperm(sender) return try: arglen = len(args) # arg length not valid if arglen == 0: show_all_notes(sender) return # Shows note help subcmd = args[0].lower() if subcmd == "help": show_an_help(sender) return # Delete note if subcmd == "del": if arglen != 2: show_an_help(sender) return if not args[1].isdigit(): msg(sender, "&cThe ID has to be numeric (check /an if you're unsure)") return note_id = int(args[1])-1 if note_id >= len(notes): msg(sender, "&cThere is no note with that ID!") return # Deletes note by index del notes[note_id] save_notes() msg(sender, "&aSuccessfully deleted note #%s!" % str(note_id+1)) return message = " ".join(args) name = sender.getName() if name in continued_messages: message = continued_messages[name] + " " + message del continued_messages[name] if message[-2:] == "++": message = message[:-2] continued_messages[name] = message msg(sender, "&6You can continue writing by using &e/an <text ...>") else: notes.append([name, message, time.time()]) save_notes() msg(sender, "&eNew note:&6 " + message) broadcast(an_permission, "&a%s just added a new note! &2Type /an" % name) except: error(print_traceback())
def cli(): """OMS.py Generator. Usage: oms-generate [<entrypoint>] Generates a oms.yml file, based on the oms.py Microservice entrypoint given. Options: -h --help Show this screen. """ sys.path += [os.getcwd()] args = docopt(cli.__doc__) entrypoint = args['<entrypoint>'] # Sane defaults. entrypoint = entrypoint if entrypoint else 'service:service' # Import the microservice. try: service = import_entrypoint(entrypoint=entrypoint) except (ImportError, ModuleNotFoundError) as e: print(f'Problem importing {entrypoint!r}.') traceback.print_traceback(e) print('Aborting.') sys.exit(1) # Run ensure on microservice. try: service = service.ensure(skip_if_exists=False) print() print('{!r} written to disk!'.format('oms.yml')) except AttributeError: print( f'The entrypoint provided ({entrypoint!r}) does not appear to be a Microservice instance.' ) print('Aborting.') sys.exit(1)
def get_all_data(sender, player): data = ip_info(player) msg(sender, "") try: msg(sender, "&7 -- Data provided by Redstoner") msg(sender, "&6> UUID: &e%s" % str(uid(player))) msg(sender, "&6> First joined: &7(y-m-d h:m:s) &e%s" % get_first_join(player)) msg(sender, "&6> Last seen: &7(y-m-d h:m:s) &e%s" % get_last_seen(player)) website = get_website_data(player) msg(sender, "&6> Website account: &e%s" % website[0]) msg(sender, "&6> email: &e%s" % website[1]) msg(sender, "&7 -- Data provided by ipinfo.io") msg(sender, "&6> Country: &e%s" % get_country(data)) msg(sender, "&7 -- Data provided by Mojang") msg(sender, "&6> All ingame names used so far: &e%s" % get_all_names(player)) except: # can throw exceptions such as timeouts when Mojang API is down warn(print_traceback()) msg(sender, "&cSorry, something went wrong while fetching data")
def exception_handler(type, value, tb): logger.exception("Uncaught exception: {0}".format(str(value))) logger.exception(traceback.print_traceback(tb))
__plugin_name__ = "RedstonerUtils" __plugin_version__ = "3.0" __plugin_mainclass__ = "foobar" import sys from traceback import format_exc as print_traceback # damn pythonloader changed the PATH sys.path += ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7', '/usr/lib/pyshared/python2.7'] try: # Library that adds a bunch of re-usable methods which are used in nearly all other modules from wrapper import * except: print("[RedstonerUtils] ERROR: Failed to import Wrapper:") print(print_traceback()) @hook.enable def on_enable(): info("RedstonerUtils enabled!") @hook.disable def on_disable(): #shared["modules"]["reports"].stop_reporting() info("RedstonerUtils disabled!") info("Loading RedstonerUtils...")
def wrapper(*args): try: wrapped(*args) except: print(print_traceback())
def wrapper(event): try: wrapped(py_event(event)) except: print(print_traceback())
# damn pythonloader changed the PATH sys.path += [ '', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7', '/usr/lib/pyshared/python2.7' ] try: # Library that adds a bunch of re-usable methods which are used in nearly all other modules from helpers import * except: print("[RedstonerUtils] ERROR: Failed to import helpers:") print(print_traceback()) @hook.enable def on_enable(): if "blockplacemods" in shared["modules"]: shared["modules"]["blockplacemods"].schedule_torch_breaker() if "imbusy" in shared["modules"]: shared["modules"]["imbusy"].replace_ess_commands() if "serversigns" in shared["modules"]: shared["modules"]["serversigns"].check_all_signs_and_force_commands() info("RedstonerUtils enabled!") @hook.disable def on_disable():
""" Welcome to "NP Fuzz" which is a REST API Fuzzing with State Diversity. This program must need 1) *.yaml which is a swagger yaml file of target 2) config.yaml For example: $ python main.py --target swagger.yaml --config config.yaml If you want to know how to use this program, command: $ python main.py --help """ parser = argparse.ArgumentParser( description='REST API Fuzzing with State Diversity') parser.add_argument('--target', required=True, metavar='*.yaml', help='swagger yaml file of target') parser.add_argument('--config', required=True, metavar='config.yaml', help='configuration file') #main(parser.parse_args()) try: main(parser.parse_args()) except TerminateException as e: print('\033[1;31m' + str(e.message) + '\033[0;0m') exit() except Exception as e: print("UNHANDLED EXCEPTION OCCUR") print(e) print_traceback()