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
69
70
71
72
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
#!/usr/bin/perl -w
use strict;
use Carp;
use MyCGI;
use XML::RPC;
use MonitorGUI::View;
use vars qw ($THIS_URL $GRID_SERVER_URL $DEFAULT_PROXY_PORT);
$THIS_URL = "http://10.8.1.165/monitorgui/monitor.cgi";
$GRID_SERVER_URL = "http://10.8.1.165/opensim/grid.cgi";
$DEFAULT_PROXY_PORT = 9000;
my %ACTIONS = (
# Region commands
move => \&move_command,
split => \&split_command,
merge => \&merge_command,
# display commands
default => \&main_screen,
refresh => \&refresh,
);
# ##################
# main
my $param = &MyCGI::getParam;
my $act = $param->{A} || "default";
my $contents = "";
if (!$ACTIONS{$act}) {
&gui_error("404 NOT FOUND");
} else {
eval {
$ACTIONS{$act}->($param);
};
if ($@) {
&gui_error($@);
}
}
# #################
# Region Commands
sub move_command {
my $param = shift;
# from
my $from_ip = $param->{from_ip} || Carp::croak("not enough params (from_ip)");
my $from_port = $param->{from_port} || Carp::croak("not enough params (from_port)");
my $from_url = "http://" . $param->{from_ip} . ":" . $DEFAULT_PROXY_PORT;
# to
my $to_ip = $param->{to_ip} || Carp::croak("not enough params (to_ip)");
my $to_port = $param->{to_port} || Carp::croak("not enough params (to_port)");
my $to_url = "http://" . $param->{to_ip} . ":" . $DEFAULT_PROXY_PORT;
# commands
eval {
&OpenSim::Utility::XMLRPCCall_array($from_url, "SerializeRegion", [$from_ip, $from_port]);
&OpenSim::Utility::XMLRPCCall_array($to_url, "DeserializeRegion_Move", [$from_ip, $from_port, $to_ip, $to_port]);
&OpenSim::Utility::XMLRPCCall_array($from_url, "TerminateRegion", [$from_port]);
};
if ($@) {
print STDERR "Get Status Error: $@\n";
}
# client refresh
&redirect_refresh({wait=>5, force=>"$from_url|$to_url", msg=>"Move region $from_ip:$from_port from $from_url to $to_url"});
}
sub split_command {
my $param = shift;
# from
my $from_ip = $param->{from_ip} || Carp::croak("not enough params (from_ip)");
my $from_port = $param->{from_port} || Carp::croak("not enough params (from_port)");
my $from_url = "http://" . $param->{from_ip} . ":" . $DEFAULT_PROXY_PORT;
# to
my $to_ip = $param->{to_ip} || Carp::croak("not enough params (to_ip)");
my $to_port = $param->{to_port} || Carp::croak("not enough params (to_port)");
my $to_url = "http://" . $param->{to_ip} . ":" . $DEFAULT_PROXY_PORT;
# commands
eval {
&OpenSim::Utility::XMLRPCCall_array($from_url, "SerializeRegion", [$from_ip, $from_port]);
&OpenSim::Utility::XMLRPCCall_array($to_url, "DeserializeRegion_Clone", [$from_ip, $from_port, $to_ip, $to_port]);
};
if ($@) {
print STDERR "Get Status Error: $@\n";
}
&redirect_refresh({wait=>5, force=>"$from_url", msg=>"Split region $from_ip:$from_port"});
}
sub merge_command {
my $param = shift;
# from
my $from_ip = $param->{from_ip} || Carp::croak("not enough params (from_ip)");
my $url = "http://" . $param->{from_ip} . ":" . $DEFAULT_PROXY_PORT;
# ports
my $master_port = $param->{master_port} || Carp::croak("not enough params (master_port)");
my $slave_ip = $param->{slave_ip} || Carp::croak("not enough params (slave_ip)");
my $slave_port = $param->{slave_port} || Carp::croak("not enough params (slave_port)");
my $slave_url = "http://" . $param->{slave_ip} . ":" . $DEFAULT_PROXY_PORT;
# commands
eval {
&XMLRPCCall_array($url, "MergeRegions", [$from_ip, $master_port]);
&XMLRPCCall_array($slave_url, "TerminateRegion", [$slave_port]);
};
if ($@) {
print STDERR "Get Status Error: $@\n";
}
&redirect_refresh({wait=>5, force=>"$url", msg=>"Merge region $from_ip:$master_port, $slave_port"});
}
# #################
# Display
sub main_screen {
my %xml_rpc_param = (
# TODO: should be 0 - 65535 ?
xmin => 999, ymin => 999, xmax => 1010, ymax => 1010,
);
my $res_obj = undef;
eval {
$res_obj = &XMLRPCCall($GRID_SERVER_URL, "map_block", \%xml_rpc_param);
};
if ($@) {
&gui_error("map_block Error: " . $@);
}
my %copy_obj = %$res_obj;
my $getstatus_failed = "<font color=\"red\">GetStatus Failed</font>";
my $regions_list = $res_obj->{"sim-profiles"};
foreach(@$regions_list) {
if ($_->{sim_ip} && $_->{sim_port}) {
my $url = "http://" . $_->{sim_ip} . ":" . $DEFAULT_PROXY_PORT;
my $port = $_->{sim_port};
my $res = undef;
eval {
$res = &XMLRPCCall_array($url, "GetStatus", [$port]);
};
if ($@) {
print STDERR "Get Status Error: $@\n";
}
$_->{get_scene_presence_filter} = $res ? $res->{get_scene_presence_filter} : $getstatus_failed;
$_->{get_scene_presence} = $res ? $res->{get_scene_presence} : $getstatus_failed;
$_->{get_avatar_filter} = $res ? $res->{get_avatar_filter} : $getstatus_failed;
$_->{get_avatar} = $res ? $res->{get_avatar} : $getstatus_failed;
$_->{avatar_names} = $res ? $res->{avatar_names} : "NO USER";
}
}
my $html = &MonitorGUI::View::html(\%copy_obj);
&MyCGI::outputHtml("UTF-8", &MonitorGUI::View::screen_header . $html . &MonitorGUI::View::screen_footer);
}
sub gui_error {
my $msg = shift;
&MyCGI::outputHtml("UTF-8", "<h1>ERROR</h1><hr />$msg");
}
sub redirect_refresh {
my $args = shift;
my $wait = $args->{wait};
my $force = $args->{force} || "";
my $msg = $args->{msg} || "";
my $param = "A=refresh&wait=$wait&ip=$force&msg=$msg";
my $dist_url = $THIS_URL . "?" . $param;
&MyCGI::redirect($dist_url);
}
sub refresh {
my $param = shift;
my $msg = $param->{msg} || "";
my $wait = $param->{wait} || 0;
my $force = $param->{ip} || "";
#my $jump_url = $force ? "$THIS_URL?A=force&ip=$force" : $THIS_URL;
my $jump_url = $THIS_URL;
my $html =<< "HTML";
<html>
<head>
<meta http-equiv="Refresh" content="$wait;URL=$jump_url" />
<title>Region Monitor GUI REFRESH</title>
</head>
<body>
<h3>$msg</h3>
<br>
wait <font color="red"><b>$wait</b></font> sec for server to take effect ... <br>
(* The page will jump to "Monitor Screen" automatically)
</body>
</html>
HTML
&MyCGI::outputHtml("UTF-8", $html);
}
# ##################
# Utility
sub XMLRPCCall {
my ($url, $methodname, $param) = @_;
my $xmlrpc = new XML::RPC($url);
my $result = $xmlrpc->call($methodname, $param);
return $result;
}
sub XMLRPCCall_array {
my ($url, $methodname, $param) = @_;
my $xmlrpc = new XML::RPC($url);
my $result = $xmlrpc->call($methodname, @$param);
return $result;
}
|