Beispiel #1
0
    def test_netInterfaces(self):
        """
        CompleteNetInterfaces produces zsh shell-code that completes system
        network interface names.
        """
        c = usage.CompleteNetInterfaces()
        out = c._shellCode('some-option', usage._ZSH)
        self.assertEqual(out, ':some-option:_net_interfaces')

        c = usage.CompleteNetInterfaces(descr='some action', repeat=True)
        out = c._shellCode('some-option', usage._ZSH)
        self.assertEqual(out, '*:some action:_net_interfaces')
Beispiel #2
0
class Options(usage.Options):
    synopsis = "[-i <interface>] [-p <port>] [-l <file>]"
    optParameters = [["interface", "i", "127.0.0.1", "local interface to which we listen"],
                  ["port", "p", 1080, "Port on which to listen"],
                  ["log", "l", None, "file to log connection data to"]]

    compData = usage.Completions(
        optActions={"log": usage.CompleteFiles("*.log"),
                    "interface": usage.CompleteNetInterfaces()}
        )

    longdesc = "Makes a SOCKSv4 server."
Beispiel #3
0
class Options(usage.Options, strcred.AuthOptionMixin):
    synopsis = "[-i <interface>] [-p <port>] [-d <dir>] "
    longdesc = (
        "Makes a Conch SSH server.  If no authentication methods are "
        "specified, the default authentication methods are UNIX passwords, "
        "SSH public keys, and PAM if it is available.  If --auth options are "
        "passed, only the measures specified will be used.")
    optParameters = [
        ["interface", "i", "", "local interface to which we listen"],
        ["port", "p", "tcp:22", "Port on which to listen"],
        ["data", "d", "/etc", "directory to look for host keys in"],
        [
            "moduli", "", None, "directory to look for moduli in "
            "(if different from --data)"
        ]
    ]
    compData = usage.Completions(
        optActions={
            "data": usage.CompleteDirs(descr="data directory"),
            "moduli": usage.CompleteDirs(descr="moduli directory"),
            "interface": usage.CompleteNetInterfaces()
        })

    def __init__(self, *a, **kw):
        usage.Options.__init__(self, *a, **kw)

        # call the default addCheckers (for backwards compatibility) that will
        # be used if no --auth option is provided - note that conch's
        # UNIXPasswordDatabase is used, instead of twisted.plugins.cred_unix's
        # checker
        super(Options, self).addChecker(conch_checkers.UNIXPasswordDatabase())
        super(Options, self).addChecker(
            conch_checkers.SSHPublicKeyChecker(
                conch_checkers.UNIXAuthorizedKeysFiles()))
        if pamauth is not None:
            super(Options, self).addChecker(
                checkers.PluggableAuthenticationModulesChecker())
        self._usingDefaultAuth = True

    def addChecker(self, checker):
        """
        Add the checker specified.  If any checkers are added, the default
        checkers are automatically cleared and the only checkers will be the
        specified one(s).
        """
        if self._usingDefaultAuth:
            self['credCheckers'] = []
            self['credInterfaces'] = {}
            self._usingDefaultAuth = False
        super(Options, self).addChecker(checker)
Beispiel #4
0
class Options(usage.Options):
    synopsis = "[-i <interface>] [-p <port>] [-d <dir>] "
    longdesc = "Makes a Conch SSH server."
    optParameters = [
        ["interface", "i", "", "local interface to which we listen"],
        ["port", "p", "tcp:22", "Port on which to listen"],
        ["data", "d", "/etc", "directory to look for host keys in"],
        [
            "moduli", "", None, "directory to look for moduli in "
            "(if different from --data)"
        ]
    ]
    compData = usage.Completions(
        optActions={
            "data": usage.CompleteDirs(descr="data directory"),
            "moduli": usage.CompleteDirs(descr="moduli directory"),
            "interface": usage.CompleteNetInterfaces()
        })
Beispiel #5
0
class Options(usage.Options):
    synopsis = "[options]"

    groups = None
    servers = None
    subscriptions = None

    optParameters = [["port", "p", "119", "Listen port"],
                     ["interface", "i", "", "Interface to which to bind"],
                     ["datadir", "d", "news.db", "Root data storage path"],
                     [
                         "mailhost", "m", "localhost",
                         "Host of SMTP server to use"
                     ]]
    compData = usage.Completions(
        optActions={
            "datadir": usage.CompleteDirs(),
            "mailhost": usage.CompleteHostnames(),
            "interface": usage.CompleteNetInterfaces()
        })

    def __init__(self):
        usage.Options.__init__(self)
        self.groups = []
        self.servers = []
        self.subscriptions = []

    def opt_group(self, group):
        """The name of a newsgroup to carry."""
        self.groups.append([group, None])

    def opt_moderator(self, moderator):
        """The email of the moderator for the most recently passed group."""
        self.groups[-1][1] = moderator

    def opt_subscription(self, group):
        """A newsgroup to list as a recommended subscription."""
        self.subscriptions.append(group)

    def opt_server(self, server):
        """The address of a Usenet server to pass messages to and receive messages from."""
        self.servers.append(server)
Beispiel #6
0
class Options(usage.Options):
    optParameters = [
        ["interface", "i", "", "The interface to which to bind"],
        ["port", "p", "53", "The port on which to listen"],
        [
            "resolv-conf",
            None,
            None,
            "Override location of resolv.conf (implies --recursive)",
        ],
        ["hosts-file", None, None, "Perform lookups with a hosts file"],
    ]

    optFlags = [
        ["cache", "c", "Enable record caching"],
        ["recursive", "r", "Perform recursive lookups"],
        ["verbose", "v", "Log verbosely"],
    ]

    compData = usage.Completions(
        optActions={"interface": usage.CompleteNetInterfaces()}
    )

    zones = None
    zonefiles = None

    def __init__(self):
        usage.Options.__init__(self)
        self["verbose"] = 0
        self.bindfiles = []
        self.zonefiles = []
        self.secondaries = []

    def opt_pyzone(self, filename):
        """Specify the filename of a Python syntax zone definition"""
        if not os.path.exists(filename):
            raise usage.UsageError(filename + ": No such file")
        self.zonefiles.append(filename)

    def opt_bindzone(self, filename):
        """Specify the filename of a BIND9 syntax zone definition"""
        if not os.path.exists(filename):
            raise usage.UsageError(filename + ": No such file")
        self.bindfiles.append(filename)

    def opt_secondary(self, ip_domain):
        """Act as secondary for the specified domain, performing
        zone transfers from the specified IP (IP/domain)
        """
        args = ip_domain.split("/", 1)
        if len(args) != 2:
            raise usage.UsageError("Argument must be of the form IP[:port]/domain")
        address = args[0].split(":")
        if len(address) == 1:
            address = (address[0], dns.PORT)
        else:
            try:
                port = int(address[1])
            except ValueError:
                raise usage.UsageError(
                    "Specify an integer port number, not %r" % (address[1],)
                )
            address = (address[0], port)
        self.secondaries.append((address, [args[1]]))

    def opt_verbose(self):
        """Increment verbosity level"""
        self["verbose"] += 1

    def postOptions(self):
        if self["resolv-conf"]:
            self["recursive"] = True

        self.svcs = []
        self.zones = []
        for f in self.zonefiles:
            try:
                self.zones.append(authority.PySourceAuthority(f))
            except Exception:
                traceback.print_exc()
                raise usage.UsageError("Invalid syntax in " + f)
        for f in self.bindfiles:
            try:
                self.zones.append(authority.BindAuthority(f))
            except Exception:
                traceback.print_exc()
                raise usage.UsageError("Invalid syntax in " + f)
        for f in self.secondaries:
            svc = secondary.SecondaryAuthorityService.fromServerAddressAndDomains(*f)
            self.svcs.append(svc)
            self.zones.append(self.svcs[-1].getAuthority())
        try:
            self["port"] = int(self["port"])
        except ValueError:
            raise usage.UsageError("Invalid port: %r" % (self["port"],))