Exemple #1
0
 def parseOptions(self, options):
     config = registry.getConfig()
     usage.Options.parseOptions(self, options)
     # check options
     gameType = self.get(const.GAME_TYPE)
     if gameType and gameType not in self.legalGameTypes:
         msg = "'%s' is not a supported game type'" % gameType
         raise exceptions.UnsupportedGameType(msg)
     storyDir = self.get(const.STORY_DIR)
     storyFile = self.get(const.STORY_FILE)
     storyModule = self.get(const.STORY_MODULE)
     bannerFile = os.path.abspath(os.path.join(storyDir, self.get(const.BANNER_FILE)))
     if not storyDir == config.game.storydir:
         config.game.storydir = storyDir
         config.game.storyfile = os.path.abspath(os.path.join(storyDir, storyFile))
         config.game.storymodule = storyModule
         with open(bannerFile) as bannerFile:
             config.game.banner = util.renderBanner(config.ssh.banner, bannerFile.read(), config.game.helpprompt)
     if self.subCommand == const.KEYGEN:
         scripts.KeyGen()
         sys.exit(const.OK)
     elif self.subCommand == const.SHELL:
         scripts.ConnectToShell()
         sys.exit(const.OK)
     elif self.subCommand == const.STOP:
         scripts.StopDaemon()
         sys.exit(const.OK)
     # do the non-twisted game types
     if gameType == const.LOCAL:
         util.setupLogging(self.get(const.LOG_FILE))
         runner.runLocal()
Exemple #2
0
from zope.interface import implements

from twisted.cred import checkers, portal
from twisted.web import guard, http, resource, static

from carapace.sdk import registry


config = registry.getConfig()


class BasicAuthRealm(object):
    """
    """
    implements(portal.IRealm)

    def __init__(self, resource):
        self.resource = resource

    def requestAvatar(self, avatarId, mind, *interfaces):
        if resource.IResource in interfaces:
            return (
                resource.IResource,
                self.resource,
                lambda: None)
        raise NotImplementedError()


def guardResourceWithBasicAuth(resource, realm, db):
    checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(**db)
    logPortal = portal.Portal(BasicAuthRealm(resource), [checker])
Exemple #3
0
from pprint import pprint
from operator import itemgetter

from carapace.sdk import registry

from hydeyhole.app import shell


config = registry.getConfig()


class CommandRegistry(object):
    """
    This class provides a global registry that tracks all the "commands"
    (API methods) that have been set as allowed for exposure to end users.
    """
    registry = []

    def add(self, func):
        """
        This methods is intended to be used as a decorator on API methods. Any
        method that has been decorated with it will have an entry in the command
        registry.
        """
        self.registry.append(func.func_name)

        def wrapper(*args, **kwargs):
            return func(*args, **kwargs)

        wrapper.wrapper = func
        return wrapper
Exemple #4
0
 def __init__(self):
     self.config = registry.getConfig()
     self.run()