22
23
24
25
26
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/automate-em/interfaces/OLD CODE/telnet/telnet.rb', line 22
def received
@input_lock.synchronize {
data = @receive_queue.pop(true)
if data == "\b"
if @input.length > 0
send_data " \b"
@input.chop!
else
send_data " "
end
elsif data =~ /.*\r\n$/
if @input =~ /^(quit|exit)$/i
disconnect
return
end
if @input != "" && !@input.nil?
if @selected.nil?
if @input =~ /^\d+$/
@selected = Communicator.select(self, @input.to_i)
else
@selected = Communicator.select(self, @input)
end
send_line " system #{@input} selected...", :green
else
thecommand = @input.split(/\s|\./, 3)
@input = ""
on_fail = lambda {
send_line(" invalid command", :green)
send_prompt("> ", :green)
send_prompt(@input)
}
if thecommand[0] =~ /register/i
@selected.register(self, thecommand[1], thecommand[2], &on_fail)
elsif thecommand[0] =~ /unregister/i
@selected.unregister(self, thecommand[1], thecommand[2], &on_fail)
elsif thecommand[2].nil?
@selected.send_command(thecommand[0], thecommand[1], &on_fail)
elsif ['{','['].include?(thecommand[2][0])
@selected.send_command(thecommand[0], thecommand[1], JSON.parse(thecommand[2], {:symbolize_names => true}), &on_fail)
else
@selected.send_command(thecommand[0], thecommand[1], thecommand[2], &on_fail)
end
send_line " sent...", :green
end
end
send_prompt("> ", :green)
@input = ""
else @input << data
end
}
end
|