Class: Mu::Command::Cmd_musl

Inherits:
Mu::Command show all
Includes:
MuSL
Defined in:
lib/mu/command/cmd_musl.rb

Constant Summary

Constants inherited from Mu::Command

Api

Constants included from Helper

Helper::ESCAPES

Instance Attribute Summary collapse

Attributes inherited from Mu::Command

#options, #opts

Instance Method Summary collapse

Methods included from Helper

#ask, #bin2hex, #error, #escape, #format_float, #get_file_as_string_array, #make_xml, #msg, #shift, #to_boolean

Constructor Details

#initializeCmd_musl

Returns a new instance of Cmd_musl.



13
14
15
16
17
18
# File 'lib/mu/command/cmd_musl.rb', line 13

def initialize
    super
    @options.strip_large_content = false
    @options.large_content_size  = nil
    # TO-DO clean up variable usage and declaration
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



11
12
13
# File 'lib/mu/command/cmd_musl.rb', line 11

def arguments
  @arguments
end

#harObject

Returns the value of attribute har.



11
12
13
# File 'lib/mu/command/cmd_musl.rb', line 11

def har
  @har
end

#ignoresObject

Returns the value of attribute ignores.



11
12
13
# File 'lib/mu/command/cmd_musl.rb', line 11

def ignores
  @ignores
end

#scenarioObject

Returns the value of attribute scenario.



11
12
13
# File 'lib/mu/command/cmd_musl.rb', line 11

def scenario
  @scenario
end

Instance Method Details

#cmd_bin2hex(argv) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/mu/command/cmd_musl.rb', line 106

def cmd_bin2hex argv
    if setup argv
    else
        raise "Invalid command line options"
    end
    result   = bin2hex @options.in_files[0]
    if !@options.print_stdout
        File.open(@options.out_file,'w') do |file|
          file.write "#{result[0]}"
        end
        puts "Created hex file: #{@options.out_file}"
    else
        puts result[0].to_s
    end

end

#cmd_escape(argv) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/mu/command/cmd_musl.rb', line 90

def cmd_escape argv
    if setup argv
    else
        raise "Invalid command line options"
    end
    result = escape File.read(@options.in_files[0])     
    if !@options.print_stdout
        File.open(@options.out_file,'w') do |file|
          file.write "#{result}"
        end
        puts "Created html escaped file: #{@options.out_file}"
    else
        puts result
    end
end

#cmd_from_har(argv) ⇒ Object

Turns a har file into a musl scenario file



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mu/command/cmd_musl.rb', line 67

def cmd_from_har argv
    # Check if our command line arguments are valid
    if setup argv
        # Get har object and hosts
        har_file     = @options.har_files[0]
        @har         = Har.new har_file, @options, @ignores
        File.open(@options.scenario,'w') do |file|
            created_musl = @har.generate file
            file.write created_musl
        end
        puts "You have successfully generated a scenario: #{@options.scenario}"
    else
        # Handle failure logic here
        raise "Invalid Command Line Options"
    end
end

#cmd_from_pcap(argv) ⇒ Object

Turns a pcap into a scenario file



85
86
87
88
# File 'lib/mu/command/cmd_musl.rb', line 85

def cmd_from_pcap argv
    # TODO LATER
    raise "This command isn't implemented yet"
end

#cmd_help(argv) ⇒ Object

displays command-line help



22
23
24
# File 'lib/mu/command/cmd_musl.rb', line 22

def cmd_help argv
    setup argv
end

#setup(argv) ⇒ Object

checks and parses the command line arguments, displays help if missing



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/mu/command/cmd_musl.rb', line 27

def setup argv
    @arguments = argv
    @ignores   = Array.new

    # If options are parsed and args are valid setup is good else show help
    if parsed_options? && arguments_valid?
        true
    else
        cmds = [
            "mu cmd_musl:help",
            "mu cmd_musl:from_har <options> <har_file>",
            "mu cmd_musl:escape <infile> [-o outfile]",
            "mu cmd_musl:bin2hex <infile> [-o outfile]"
        ]

        puts "#{@opts}"
        puts
        puts "Available Commands:"
        cmds.each do | c |
            puts c
        end
        puts
        puts "NetExport Information: http://www.softwareishard.com/blog/netexport/"
        puts "NetExport Extension:   http://getfirebug.com/releases/netexport/"
        puts
        puts "from_har Outputs:"
        puts "Scenario file: <harfilename>.msl by default or filename from -s"
        puts
        puts "escape Outputs:"
        puts "html escaped output sent to stdout or file"
        puts
        puts "bin2hex Outputs:"
        puts "hexadecimal output sent to stdout or file"
        
        false
    end
        
end