Top Level Namespace

Defined Under Namespace

Classes: String

Constant Summary collapse

TYPE_INFO =

Constants

0
TYPE_ERROR =
1
TYPE_WARNING =
2
TYPE_DATA =
3
SCRIPT_VERSION =
'1.1'
LIST =
['upload', 'download', 'exit', 'menu', 'services'].sort

Instance Method Summary collapse

Instance Method Details

#check_directories(path, purpose) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/evil-winrm.rb', line 73

def check_directories(path, purpose)
    if path == "" then
        print_message("The directory used for " + purpose + " can't be empty. Please edit the script and set a path", TYPE_ERROR)
        custom_exit(1)
    end

    if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil then
        # Windows
        if path[-1] != "\\" then
            path.concat("\\")
        end
    else
        # Unix
        if path[-1] != "/" then
            path.concat("/")
        end
    end

    if !File.directory?(path) then
        print_message("The directory \"" + path + "\" used for " + purpose + " was not found", TYPE_ERROR)
        custom_exit(1)
    end

    if purpose == "scripts" then
        $scripts_path = path
    elsif purpose == "executables" then
        $executables_path = path
    end
end

#colorize(text, color = "default") ⇒ Object



41
42
43
44
45
# File 'lib/evil-winrm.rb', line 41

def colorize(text, color = "default")
    colors = {"default" => "38", "blue" => "34", "red" => "31", "yellow" => "1;33", "magenta" => "35"}
    color_code = colors[color]
    return "\033[0;#{color_code}m#{text}\033[0m"
end

#custom_exit(exit_code = 0) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/evil-winrm.rb', line 128

def custom_exit(exit_code = 0)
    if exit_code == 0 then
        puts()
        print_message("Exiting with code " + exit_code.to_s, TYPE_INFO)
    elsif exit_code == 1 then
        print_message("Exiting with code " + exit_code.to_s, TYPE_ERROR)
    else
        print_message("Exiting with code " + exit_code.to_s, TYPE_ERROR)
    end
    exit(exit_code)
end

#paths(directory) ⇒ Object



122
123
124
125
126
# File 'lib/evil-winrm.rb', line 122

def paths(directory)
    files = Dir.glob("#{directory}*.*", File::FNM_DOTMATCH)
    directories = Dir.glob("#{directory}*").select {|f| File.directory? f}
    return files + directories
end


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/evil-winrm.rb', line 47

def print_message(msg, msg_type)
    if msg_type == TYPE_INFO then
        msg_prefix = "Info: "
        color = "blue"
    elsif msg_type == TYPE_WARNING then
        msg_prefix = "Warning: "
        color = "yellow"
    elsif msg_type == TYPE_ERROR then
        msg_prefix = "Error: "
        color = "red"
    elsif msg_type == TYPE_DATA then
        msg_prefix = "Data: "
        color = 'magenta'
    else
        msg_prefix = "Error"
        color = "red"
    end

    if $colors_enabled then
        puts("#{colorize(msg_prefix + msg, color)}")
    else
        puts(msg_prefix + msg)
    end
    puts()
end

#read_executables(args) ⇒ Object



116
117
118
119
120
# File 'lib/evil-winrm.rb', line 116

def read_executables(args)
    executables = args
    files = Dir.glob("#{executables}*.exe", File::FNM_DOTMATCH)
    return files
end

#read_scripts(scripts) ⇒ Object



111
112
113
114
# File 'lib/evil-winrm.rb', line 111

def read_scripts(scripts)
    files = Dir.entries(scripts).select{ |f| File.file? File.join(scripts, f) }
    return files
end

#silent_warningsObject



103
104
105
106
107
108
109
# File 'lib/evil-winrm.rb', line 103

def silent_warnings
    old_stderr = $stderr
    $stderr = StringIO.new
    yield
ensure
    $stderr = old_stderr
end