Exemple #1
0
def import_all_apps_from_config():
    """Imports all the apps user has enabled in config file"""


    for module_path, options in config.yield_enabled_apps():

        try:
            import_subssh_app(module_path, options)
        except ImportError, e:
            # TODO: Should log the traceback
            tools.errln("Warning: Could not import app %s" % module_path)
            logger.error("Could not import app %s reason: %s"
                         % (module_path, e) )
Exemple #2
0
def run(user):
    # Log all commands that are ran
    # TODO: preserve history for prompt


    user.logger.info("%s %s" % (user.cmd, user.args))

    try:
        app = active.cmds[user.cmd]
    except KeyError:
        sys.stderr.write("Unknown command '%s'\n" % user.cmd)
        return 1



    try:
        # Ignore "user" which is always supplied.
        tools.assert_args(app, user.args, ignore=1)
        # Execute the app
        return app(user, *user.args)
    except tools.InvalidArguments, e:
        tools.errln("Invalid arguments. %s" % e.args[0])
        buildins.show_doc(user, user.cmd)
        return 1
Exemple #3
0
def standalone_xmlrpc_server():
    """Standalone XML-RPC server. Can be used to manage subssh users from 
remote machine.
    """
    parser = OptionParser(usage="%s [listen address] [port]"  % sys.argv[0],
                          description=standalone_xmlrpc_server.__doc__ )
                         
    
    
    options, args = parser.parse_args()
    
    
    try:
        listen = args[0]
    except IndexError:
        listen = config.XMLRPC_LISTEN
    
    try:
        port = int(args[1])
    except (IndexError, ValueError):
        port = config.XMLRPC_PORT
    
    
    server = setup_server(listen, port)

    
    tools.errln("\nWarning: This standalone server does not have any "
                "authentication system. So anyone able to connect can "
                "add subssh keys!\n")
    tools.errln("Starting XML-RPC server on http://%s:%s%s" % 
                (listen, port, RequestHandler.rpc_paths[0]),
                log=logger.info)
    
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        return 0
    except Exception, e:
        tools.errln("Got %s" % e)
        return 1
Exemple #4
0
        return 1



    try:
        # Ignore "user" which is always supplied.
        tools.assert_args(app, user.args, ignore=1)
        # Execute the app
        return app(user, *user.args)
    except tools.InvalidArguments, e:
        tools.errln("Invalid arguments. %s" % e.args[0])
        buildins.show_doc(user, user.cmd)
        return 1
    except tools.UserException, e:
        # Expected exception. Print error to user.
        tools.errln("%s: %s" % (e.__class__.__name__, e.args[0]))
        if config.DEBUG_USER:
            tools.set_text_color("green")
            tools.errln("USER DEBUG MODE (no real error):")
            traceback.print_exc()
            tools.reset_text_color()
        return 1
    except Exception, e:
        # Unexpected exception! Log it!

        #  We can just print the traceback if user is admin or if we are in debug mode
        if user.username == config.ADMIN or config.DEBUG:
            tools.set_text_color("red")
            traceback.print_exc()
            tools.reset_text_color()
        else: