def _do_command(self): a = self.config.get_auth(self.options.name) if not a: print(_("Auth %s does not exist.") % self.options.name) sys.exit(1) if self.options.username: a.username = self.options.username if self.options.password: a.password = get_password(a.username, RHO_AUTH_PASSWORD) if self.options.filename: sshkey = _read_key_file(self.options.filename) if a.type == config.SSH_TYPE: cred = config.SshKeyAuth({"name": a.name, "key":sshkey, "username": a.username, "password": a.password, "type":"ssh_key"}) # remove the old ssh, and new key type self.config.remove_auth(self.options.name) self.config.add_auth(cred) elif a.type == config.SSH_KEY_TYPE: a.key = sshkey c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print(_("Auth %s updated" % self.options.name))
def _do_command(self): g = self.config.get_profile(self.options.name) if not g: print(_("Profile %s does not exist.") % self.options.name) sys.exit(1) if self.options.ranges: g.ranges = self.options.ranges if self.options.hosts: g.ranges += _read_hosts_file(self.options.hosts) if self.options.ports: g.ports = self.options.ports.strip().split(",") self._validate_ports(g.ports) if len(self.options.auth) > 0: g.auth_names = [] for auth in self.options.auth: for a in auth.strip().split(","): g.auth_names.append(a) # unfortunately can't valid these in _validate_options # as we don't have a config at that point for auth in self.options.auth: for a in auth.strip().split(","): try: self.config.get_auth(a) except config.NoSuchAuthError as e: print _("ERROR: No such auth: %s") % e.authname sys.exit(1) c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print(_("Profile %s edited" % self.options.name))
def _do_command(self): a = self.config.get_auth(self.options.name) if not a: print(_("Auth %s does not exist.") % self.options.name) sys.exit(1) if self.options.username: a.username = self.options.username if self.options.password: a.password = get_password(a.username, RHO_AUTH_PASSWORD) if self.options.filename: sshkey = _read_key_file(self.options.filename) if a.type == config.SSH_TYPE: cred = config.SshKeyAuth({ "name": a.name, "key": sshkey, "username": a.username, "password": a.password, "type": "ssh_key" }) # remove the old ssh, and new key type self.config.remove_auth(self.options.name) self.config.add_auth(cred) elif a.type == config.SSH_KEY_TYPE: a.key = sshkey c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print(_("Auth %s updated" % self.options.name))
def _do_command(self): ports = [] if self.options.ports: ports = self.options.ports.strip().split(",") self._validate_ports(ports) if self.options.hosts: self.options.ranges += _read_hosts_file(self.options.hosts) auth_names = [] for auth in self.options.auth: for a in auth.strip().split(","): auth_names.append(a) # unfortunately can't valid these in _validate_options # as we don't have a config at that point for auth in self.options.auth: for a in auth.strip().split(","): try: self.config.get_auth(a) except config.NoSuchAuthError as e: print _("ERROR: No such auth: %s") % e.authname sys.exit(1) g = config.Profile(name=self.options.name, ranges=self.options.ranges, auth_names=auth_names, ports=ports) self.config.add_profile(g) c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase)
def _do_command(self): if self.options.name: self.config.remove_auth(self.options.name) elif self.options.all: self.config.clear_auths() c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase)
def _do_command(self): if self.options.name: self.config.remove_credential(self.options.name) elif self.options.all: self.config.clear_credentials() c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase)
def _do_command(self): if self.options.name: raise NotImplementedError elif self.options.all: self.config.clear_groups() c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print (_("All network profiles removed"))
def _save_cred(self, cred): try: self.config.add_credentials(cred) except config.DuplicateNameError: # FIXME: need to handle this better... -akl print _("The auth name %s already exists" % cred.name) return c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase)
def _do_command(self): fields = self.options.fields.strip().split(',') g = config.Report(name=self.options.name, report_format=fields, output_filename=self.options.output_filename) self.config.add_report(g) c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase)
def _do_command(self): """ Executes the command. """ f = open(self.options.sourcefile, 'r') json_buf = f.read() imported_config = config.ConfigBuilder().build_config(json_buf) c = config.ConfigBuilder().dump_config(imported_config) crypto.write_file(self.options.config, c, self.passphrase)
def _do_command(self): ports = [] auths = [] if self.options.ports: ports = self.options.ports.strip().split(",") # self.options.auth can be None, so don't pass it to Group() if self.options.auth: auths = self.options.auth g = config.Group(name=self.options.name, ranges=self.options.ranges, credential_names=auths, ports=ports) self.config.add_group(g) c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase)
def _do_command(self): if self.options.name: if self.config.has_profile(self.options.name): self.config.remove_profile(self.options.name) c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print(_("Profile %s removed" % self.options.name)) else: print(_("ERROR: No such profile: %s") % self.options.name) sys.exit(1) elif self.options.all: self.config.clear_profiles() c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print(_("All network profiles removed"))
def _do_command(self): if self.options.name: if self.config.has_report(self.options.name): self.config.remove_report(self.options.name) c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print(_("report %s removed" % self.options.name)) else: print(_("ERROR: No such report: %s") % self.options.name) sys.exit(1) elif self.options.all: self.config.clear_reports() c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print(_("All reports removed"))
def _do_command(self): r = self.config.get_report(self.options.name) if not r: print(_("report %s does not exist.") % self.options.name) sys.exit(1) if self.options.output_filename: r.output_filename = self.options.output_filename if self.options.fields: fields = self.options.fields.strip().split(",") if self.options.add: r.report_format.extend(fields) elif self.options.remove: r.report_format = [field for field in r.report_format if field not in fields] else: r.report_format = fields c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase) print(_("Report %s edited" % self.options.name))
class ProfileAddCommand(CliCommand): def __init__(self): usage = _("usage: %prog profile add [options]") shortdesc = _("add a network profile") desc = _("add a network profile") CliCommand.__init__(self, "profile add", usage, shortdesc, desc) self.parser.add_option("--name", dest="name", metavar="NAME", help=_("NAME of the profile - REQUIRED")) self.parser.add_option( "--range", dest="ranges", action="append", metavar="RANGE", default=[], help=_("IP range to scan. See 'man rho' for supported formats.")) self.parser.add_option( "--ports", dest="ports", metavar="PORTS", help=_("list of ssh ports to try i.e. '22, 2222, 5402'")), self.parser.add_option("--auth", dest="auth", metavar="AUTH", action="append", default=[], help=_("auth class to associate with profile")) self.parser.set_defaults(ports="22") def _validate_options(self): CliCommand._validate_options(self) if self.options.ranges: self._validate_ranges(self.options.ranges) if not self.options.name: self.parser.print_help() sys.exit(1) def _do_command(self): ports = [] if self.options.ports: ports = self.options.ports.strip().split(",") self._validate_ports(ports) auth_names = [] for auth in self.options.auth: for a in auth.strip().split(","): auth_names.append(a) # unfortunately can't valid these in _validate_options # as we don't have a config at that point for auth in self.options.auth: for a in auth.strip().split(","): try: self.config.get_auth(a) except config.NoSuchAuthError, e: print _("ERROR: No such auth: %s") % e.authname sys.exit(1) g = config.Profile(name=self.options.name, ranges=self.options.ranges, auth_names=auth_names, ports=ports) self.config.add_profile(g) c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase)
def _save_cred(self, cred): self.config.add_auth(cred) c = config.ConfigBuilder().dump_config(self.config) crypto.write_file(self.options.config, c, self.passphrase)
def _write_config(self, new_config): c = config.ConfigBuilder().dump_config(new_config) crypto.write_file(self.options.config, c, self.passphrase)