|
| 1 | +# frozen_string_literal: true |
| 2 | +# |
| 3 | +# ronin-recon - A micro-framework and tool for performing reconnaissance. |
| 4 | +# |
| 5 | +# Copyright (c) 2023-2024 Hal Brodigan ([email protected]) |
| 6 | +# |
| 7 | +# ronin-recon is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Lesser General Public License as published |
| 9 | +# by the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# ronin-recon is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Lesser General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>. |
| 19 | +# |
| 20 | + |
| 21 | +require_relative '../../config_command' |
| 22 | + |
| 23 | +module Ronin |
| 24 | + module Recon |
| 25 | + class CLI |
| 26 | + module Commands |
| 27 | + class Config < Command |
| 28 | + # |
| 29 | + # Gets the concurrency or a param for a worker. |
| 30 | + # |
| 31 | + # ## Usage |
| 32 | + # |
| 33 | + # ronin-recon config get [options] {--concurrency WORKER | --param WORKER.NAME} |
| 34 | + # |
| 35 | + # ## Options |
| 36 | + # |
| 37 | + # -C, --config-file FILE Loads the configuration file |
| 38 | + # -c, --concurrency WORKER Gets the concurrency of a worker |
| 39 | + # -p, --param WORKER.PARAM Gets a param for a worker |
| 40 | + # -h, --help Print help information |
| 41 | + # |
| 42 | + # @since 0.2.0 |
| 43 | + # |
| 44 | + class Get < ConfigCommand |
| 45 | + |
| 46 | + usage '[options] {--concurrency WORKER | --param WORKER.NAME}' |
| 47 | + |
| 48 | + option :concurrency, short: '-c', |
| 49 | + value: { |
| 50 | + type: String, |
| 51 | + usage: 'WORKER' |
| 52 | + }, |
| 53 | + desc: 'Gets the concurrency for the worker' do |worker| |
| 54 | + @mode = :concurrency |
| 55 | + @worker = worker |
| 56 | + end |
| 57 | + |
| 58 | + option :param, short: '-p', |
| 59 | + value: { |
| 60 | + type: /\A([^\.\=\s]+)\.([^=\s]+)\z/, |
| 61 | + usage: 'WORKER.PARAM' |
| 62 | + }, |
| 63 | + desc: 'Gets the param for the worker' do |str,worker,param| |
| 64 | + @mode = :param |
| 65 | + @worker = worker |
| 66 | + @param = param.to_sym |
| 67 | + end |
| 68 | + |
| 69 | + description 'Gets the concurrency or a param for a worker' |
| 70 | + |
| 71 | + man_page 'ronin-recon-config-get.1' |
| 72 | + |
| 73 | + # Specifies whether to unset the worker's concurrency or param. |
| 74 | + # |
| 75 | + # @return [:concurrency, :param, nil] |
| 76 | + attr_reader :mode |
| 77 | + |
| 78 | + # The worker name. |
| 79 | + # |
| 80 | + # @return [String, nil] |
| 81 | + attr_reader :worker |
| 82 | + |
| 83 | + # The param name to unset. |
| 84 | + # |
| 85 | + # @return [Symbol, nil] |
| 86 | + attr_reader :param |
| 87 | + |
| 88 | + # |
| 89 | + # Runs the `ronin-recon config set` command. |
| 90 | + # |
| 91 | + def run |
| 92 | + load_config |
| 93 | + |
| 94 | + case @mode |
| 95 | + when :concurrency |
| 96 | + if (concurrency = @config.concurrency[@worker]) |
| 97 | + puts concurrency |
| 98 | + end |
| 99 | + when :param |
| 100 | + if (params = @config.params[@worker]) && |
| 101 | + (value = params[@param]) |
| 102 | + puts value |
| 103 | + end |
| 104 | + else |
| 105 | + print_error "--concurrency or --param options must be given" |
| 106 | + exit(-1) |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + end |
| 111 | + end |
| 112 | + end |
| 113 | + end |
| 114 | + end |
| 115 | +end |
0 commit comments