FluxTuna 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,106 @@
1
+ ### Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
+ ###
3
+ ### Permission to use, copy, modify, and/or distribute this software for
4
+ ### any purpose with or without fee is hereby granted, provided that the
5
+ ### above copyright notice and this permission notice appear in all copies.
6
+ ###
7
+ ### THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ ### WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ ### MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ### ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ ### WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ### ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ ### OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+ ###
15
+
16
+ module WhiteCloth::CLI::Commands
17
+
18
+ # @author Denis Defreyne
19
+ # @author David Love
20
+ #
21
+ # The +help+ command show the user a brief summary of the available
22
+ # sub-commands, and the short description of each of those commands.
23
+ #
24
+ # Further help is available to the user, if one of the sub-commands
25
+ # is named as an argument to this command. In that case, the longer
26
+ # help for the command is displayed.
27
+ #
28
+ # @note This class is merely a helper class: the actual text, options
29
+ # and other details are drawn directly from the source code of those
30
+ # commands. In the execution of this command, we rely on the +cri+
31
+ # and +cli+ libraries to do the hard work of actually processing the
32
+ # sub-commands.
33
+ class Help < Cri::Command
34
+
35
+ # The name of the sub-command (as it appears in the command line app)
36
+ def name
37
+ 'help'
38
+ end
39
+
40
+ # The aliases this sub-command is known by
41
+ def aliases
42
+ []
43
+ end
44
+
45
+ # A short help text describing the purpose of this command
46
+ def short_desc
47
+ 'Show help for a command'
48
+ end
49
+
50
+ # A longer description, detailing both the purpose and the
51
+ # use of this command
52
+ def long_desc
53
+ 'Show help for the given command, or show general help. When no ' +
54
+ 'command is given, a list of available commands is displayed, as ' +
55
+ 'well as a list of global command-line options. When a command is ' +
56
+ 'given, a command description as well as command-specific ' +
57
+ 'command-line options are shown.'
58
+ end
59
+
60
+ # Show the user the basic syntax of this command
61
+ def usage
62
+ "whitecloth help [command]"
63
+ end
64
+
65
+ # Execute the command
66
+ def run(options, arguments)
67
+ # Check arguments
68
+ if arguments.size > 1
69
+ $stderr.puts "usage: #{usage}"
70
+ exit 1
71
+ end
72
+
73
+ if arguments.length == 0
74
+ # Build help text
75
+ text = ''
76
+
77
+ # Add title
78
+ text << "A command-line tool for managing WhiteCloth realms.\n"
79
+
80
+ # Add available commands
81
+ text << "\n"
82
+ text << "Available commands:\n"
83
+ text << "\n"
84
+ @base.commands.sort.each do |command|
85
+ text << sprintf(" %-20s %s\n", command.name, command.short_desc)
86
+ end
87
+
88
+ # Add global options
89
+ text << "\n"
90
+ text << "Global options:\n"
91
+ text << "\n"
92
+ @base.global_option_definitions.sort { |x,y| x[:long] <=> y[:long] }.each do |opt_def|
93
+ text << sprintf(" -%1s --%-15s %s\n", opt_def[:short], opt_def[:long], opt_def[:desc])
94
+ end
95
+
96
+ # Display text
97
+ puts text
98
+ elsif arguments.length == 1
99
+ command = @base.command_named(arguments[0])
100
+ puts command.help
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,87 @@
1
+ # Copyright (c) 2011 David Love
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for
4
+ # any purpose with or without fee is hereby granted, provided that the
5
+ # above copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+ #
15
+ #
16
+ # @author David Love
17
+ #
18
+
19
+ module WhiteCloth::CLI::Commands
20
+
21
+ # @author David Love
22
+ #
23
+ # Displays a summary of the realm data found in the configured WhiteCloth
24
+ # server.
25
+ class Show < Cri::Command
26
+
27
+ # The name of the sub-command (as it appears in the command line app)
28
+ def name
29
+ 'show-status'
30
+ end
31
+
32
+ # The aliases this sub-command is known by
33
+ def aliases
34
+ []
35
+ end
36
+
37
+ # A short help text describing the purpose of this command
38
+ def short_desc
39
+ 'Create or update information from the network'
40
+ end
41
+
42
+ # A longer description, detailing both the purpose and the
43
+ # use of this command
44
+ def long_desc
45
+ "Displays the current state of the evironemnt " +
46
+ "to update the host files (held in the 'hosts' directory). Existing " +
47
+ "information will be updated, and missing information inserted.\n"
48
+ end
49
+
50
+ # Show the user the basic syntax of this command
51
+ def usage
52
+ "bootstrap show-status"
53
+ end
54
+
55
+ # Define the options for this command
56
+ def option_definitions
57
+ []
58
+ end
59
+
60
+ # Execute the command
61
+ def run(options, arguments)
62
+
63
+ # Load the list of groups
64
+ group_list = YAML::load( File.open("config/groups.yaml"))
65
+
66
+ # Load the list of networks
67
+ network_list = YAML::load( File.open("config/networks.yaml"))
68
+
69
+ # Update the information in each group-network directory
70
+ gn_name_list = Array.new
71
+
72
+ network_list.each{|network|
73
+ puts network[1]
74
+
75
+ net_block = network[1]['ip4-address-block'].to_s
76
+
77
+ # Scan this network
78
+ # parser = Nmap::Parser.parsescan("nmap", "-sVC " + net_block)
79
+
80
+ puts parser
81
+ }
82
+
83
+ end
84
+
85
+ end
86
+
87
+ end
@@ -0,0 +1,29 @@
1
+ # Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for
4
+ # any purpose with or without fee is hereby granted, provided that the
5
+ # above copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ # @author David Love
16
+ #
17
+ # The +Commands+ module acts as the gathering place for all the sub-commands
18
+ # which the +whitecloth+ command can deal with. Each sub-command defines both
19
+ # the command action, options, and associated help text.
20
+ #
21
+ # All commands should live under +lib/whitecloth/cli/commands+, with the
22
+ # file-name named after the sub-command defined within it.
23
+ module WhiteCloth::CLI::Commands
24
+ end
25
+
26
+ require 'whitecloth/cli/commands/help'
27
+
28
+ require 'whitecloth/cli/commands/bootstrap'
29
+ require 'whitecloth/cli/commands/show'
@@ -0,0 +1,88 @@
1
+ # Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for
4
+ # any purpose with or without fee is hereby granted, provided that the
5
+ # above copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+ #
15
+
16
+ require 'singleton'
17
+ require 'facets'
18
+
19
+ module WhiteCloth::CLI
20
+
21
+ # WhiteCloth::CLI::Logger is a singleton class responsible for generating
22
+ # feedback in the terminal.
23
+ class Logger
24
+
25
+ # ANSI console codes (escape sequences) for highlighting particular
26
+ # log outputs.
27
+ ACTION_COLORS = {
28
+ :error => "\e[1m" + "\e[31m", # bold + red
29
+ :warning => "\e[1m" + "\e[33m", # bold + yellow
30
+ :info => "\e[1m" + "\e[32m", # bold + green
31
+ }
32
+
33
+ include Singleton
34
+
35
+ # The log level, which can be :high, :low or :off (which will log all
36
+ # messages, only high-priority messages, or no messages at all,
37
+ # respectively).
38
+ attr_accessor :level
39
+
40
+ # Whether to use color in log messages or not
41
+ attr_accessor :color
42
+ alias_method :color?, :color
43
+
44
+ def initialize
45
+ @level = :high
46
+ @color = true
47
+ end
48
+
49
+ # Logs a messsage, using appropriate colours to highlight different
50
+ # levels.
51
+ #
52
+ # +level+:: The importance of this action. Can be :high or :low.
53
+ #
54
+ # +action+:: The kind of file action. Can be :create, :update or
55
+ # :identical.
56
+ #
57
+ # +message+:: The identifier of the item the action was performed on.
58
+ def log_level(level, action, message)
59
+ log(
60
+ level,
61
+ '%s%12s%s: %s' % [
62
+ color? ? ACTION_COLORS[action.to_sym] : '',
63
+ action.capitalize,
64
+ color? ? "\e[0m" : '',
65
+ message.word_wrap(60).indent(15).lstrip
66
+ ]
67
+ )
68
+ end
69
+
70
+ # Logs a message.
71
+ #
72
+ # +level+:: The importance of this message. Can be :high or :low.
73
+ #
74
+ # +message+:: The message to be logged.
75
+ #
76
+ # +io+:: The IO instance to which the message will be written. Defaults to
77
+ # standard output.
78
+ def log(level, message, io=$stdout)
79
+ # Don't log when logging is disabled
80
+ return if @level == :off
81
+
82
+ # Log when level permits it
83
+ io.puts(message) if (@level == :low or @level == level)
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,29 @@
1
+ ### Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
+ ###
3
+ ### Permission to use, copy, modify, and/or distribute this software for
4
+ ### any purpose with or without fee is hereby granted, provided that the
5
+ ### above copyright notice and this permission notice appear in all copies.
6
+ ###
7
+ ### THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ ### WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ ### MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ### ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ ### WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ### ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ ### OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+ ###
15
+
16
+ require 'rubygems'
17
+
18
+ # Load command line handling library
19
+ require 'cri'
20
+
21
+ # Install module for command line
22
+ # interface
23
+ module WhiteCloth:CLI
24
+ end
25
+
26
+ # Load the command line handling modules
27
+ require 'whitecloth/cli/logger'
28
+ require 'whitecloth/cli/commands'
29
+ require 'whitecloth/cli/base'