forked from viglesiasce/testlink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetInfo.cgi
More file actions
executable file
·68 lines (57 loc) · 1.76 KB
/
getInfo.cgi
File metadata and controls
executable file
·68 lines (57 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
#!/usr/bin/perl
# * File: load_graph_form.cgi
# *
# * Author: Victor Iglesias
# *
# * Purpose: Used to load product and version names into comboboxes
# *
# ******************************************************************************/
use strict;
use vars qw/$dbh/;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use DBI; # perl DBI module
use Net::Telnet;
my $PARAMS;
my $paramcount=0;
for (param()) {
$PARAMS->{$_} = param("$_");
$paramcount++;
}
my $ip = $PARAMS->{"ip"};
my $cmd = $PARAMS->{"command"};
my %blade_info = get_blade_info($ip, $cmd);
print "Content-type: text/xml\n\n";
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";
print "<dut_info>\n";
print "<result id=\"result\">\n". $blade_info{'result'} . "\n</result>\n";
print "<status id=\"status\">" . $blade_info{'status'} . "</status>\n";
print "</dut_info>\n";
sub get_blade_info(){
my $hostname = shift;
my %hash_return;
my $telnet = new Net::Telnet ( Timeout=>10 , Errmode => "return",Prompt => '/\> $/i', Input_log => 'inputlog.txt', Output_log => 'outputlog.txt');
my $ok = $telnet->open($hostname);
$telnet->waitfor('/:/i');
$telnet->print('occam');
$telnet->waitfor('/\>/i');
$telnet->print('enable');
$telnet->waitfor('/Password: $/i');
$telnet->print('razor');
$telnet->waitfor('/\#/i');
$telnet->prompt('/\#/i');
$telnet->cmd('terminal length 0');
$telnet->print($cmd);
my ($result_string) = $telnet->waitfor('/\#\s*?$/');
$telnet->cmd('no terminal length');
$result_string =~ s/\001/ /g;
$result_string =~ s/\020/ /g;
$hash_return{'result'} = $result_string;
if ($ok and $result_string ){
$hash_return{'status'}= 1;
}
else{
$hash_return{'status'}= 0;
}
return %hash_return;
}