opensim-tools – Diff between revs 68 and 70
?pathlinks?
Rev 68 | Rev 70 | |||
---|---|---|---|---|
1 | #!/usr/bin/php |
1 | #!/usr/bin/php |
|
2 | <?php |
2 | <?php |
|
3 | |
3 | |
|
4 | ///////////////////////////////////////////////////////////// |
4 | ///////////////////////////////////////////////////////////// |
|
5 | // Wizardry and Steamworks (c) was.fm - 2014, License: MIT // |
5 | // Wizardry and Steamworks (c) was.fm - 2014, License: MIT // |
|
6 | // // |
6 | // // |
|
7 | // Permission is hereby granted, free of charge, to any // |
7 | // Permission is hereby granted, free of charge, to any // |
|
8 | // person obtaining a copy of this software and associated // |
8 | // person obtaining a copy of this software and associated // |
|
9 | // documentation files (the "Software"), to deal in the // |
9 | // documentation files (the "Software"), to deal in the // |
|
10 | // Software without restriction, //including without // |
10 | // Software without restriction, //including without // |
|
11 | // limitation the rights to use, copy, modify, merge, // |
11 | // limitation the rights to use, copy, modify, merge, // |
|
12 | // publish, distribute, sublicense, and/or sell copies of // |
12 | // publish, distribute, sublicense, and/or sell copies of // |
|
13 | // the Software, and to permit persons to whom the // |
13 | // the Software, and to permit persons to whom the // |
|
14 | // Software is furnished to do so, subject to the // |
14 | // Software is furnished to do so, subject to the // |
|
15 | // following conditions: // |
15 | // following conditions: // |
|
16 | // // |
16 | // // |
|
17 | // The above copyright notice and this permission notice // |
17 | // The above copyright notice and this permission notice // |
|
18 | // shall be included in all copies or substantial portions // |
18 | // shall be included in all copies or substantial portions // |
|
19 | // of the Software. // |
19 | // of the Software. // |
|
20 | // // |
20 | // // |
|
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // |
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // |
|
22 | // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // |
22 | // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // |
|
23 | // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS // |
23 | // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS // |
|
24 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO // |
24 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO // |
|
25 | // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // |
25 | // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // |
|
26 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER // |
26 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER // |
|
27 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // |
27 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // |
|
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR // |
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR // |
|
29 | // THE USE OR OTHER DEALINGS IN THE SOFTWARE. // |
29 | // THE USE OR OTHER DEALINGS IN THE SOFTWARE. // |
|
30 | ///////////////////////////////////////////////////////////// |
30 | ///////////////////////////////////////////////////////////// |
|
31 | |
31 | |
|
32 | ///////////////////////////////////////////////////////////// |
32 | ///////////////////////////////////////////////////////////// |
|
33 | // CONFIGfURATION // |
33 | // CONFIGfURATION // |
|
34 | ///////////////////////////////////////////////////////////// |
34 | ///////////////////////////////////////////////////////////// |
|
35 | |
35 | |
|
36 | // Hostname or IP of your OpenSim MySQL server. |
36 | // Hostname or IP of your OpenSim MySQL server. |
|
37 | define("MYSQL_HOSTNAME", "localhost"); |
37 | define("MYSQL_HOSTNAME", "localhost"); |
|
38 | // Username of the OpenSim MySQL user. |
38 | // Username of the OpenSim MySQL user. |
|
39 | define("MYSQL_USERNAME", "opensim"); |
39 | define("MYSQL_USERNAME", "opensim"); |
|
40 | // Password of the OpenSim MySQL user. |
40 | // Password of the OpenSim MySQL user. |
|
41 | define("MYSQL_PASSWORD", "***"); |
41 | define("MYSQL_PASSWORD", "***"); |
|
42 | // Name of the OpenSim database on the MySQL server. |
42 | // Name of the OpenSim database on the MySQL server. |
|
43 | define("MYSQL_DATABASE", "opensim"); |
43 | define("MYSQL_DATABASE", "opensim"); |
|
44 | |
44 | |
|
45 | ///////////////////////////////////////////////////////////// |
45 | ///////////////////////////////////////////////////////////// |
|
46 | // INTERNALS // |
46 | // INTERNALS // |
|
47 | ///////////////////////////////////////////////////////////// |
47 | ///////////////////////////////////////////////////////////// |
|
48 | |
48 | |
|
49 | require_once('/var/www/lib/wasRemoteAdmin.php'); |
49 | require_once('/var/www/lib/wasRemoteAdmin.php'); |
|
50 | |
50 | |
|
51 | if(!defined('STDIN')) { |
51 | if(!defined('STDIN')) { |
|
52 | print 'This script is meant to be run on the command line.'."\n"; |
52 | print 'This script is meant to be run on the command line.'."\n"; |
|
53 | return 1; |
53 | return 1; |
|
54 | } |
54 | } |
|
55 | |
55 | |
|
56 | $connection_ok = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD); |
56 | $connection_ok = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD); |
|
57 | if(!$connection_ok) { |
57 | if(!$connection_ok) { |
|
58 | print 'Could not connect to the OpenSim database. Please edit the script and make sure the credentials are correct.'."\n"; |
58 | print 'Could not connect to the OpenSim database. Please edit the script and make sure the credentials are correct.'."\n"; |
|
59 | return 1; |
59 | return 1; |
|
60 | } |
60 | } |
|
61 | $db_selected = mysql_select_db(MYSQL_DATABASE); |
61 | $db_selected = mysql_select_db(MYSQL_DATABASE); |
|
62 | if(!$db_selected) { |
62 | if(!$db_selected) { |
|
63 | print 'Could not select the opensim database. Please edit this script and make sure the credentials are correct.'."\n"; |
63 | print 'Could not select the opensim database. Please edit this script and make sure the credentials are correct.'."\n"; |
|
64 | return 1; |
64 | return 1; |
|
65 | } |
65 | } |
|
66 | |
66 | |
|
67 | $query = 'SELECT RegionName FROM regions'; |
67 | $query = 'SELECT RegionName FROM regions'; |
|
68 | $result = mysql_query($query); |
68 | $result = mysql_query($query); |
|
69 | $regions = array(); |
69 | $regions = array(); |
|
70 | while($row = mysql_fetch_array($result)) { |
70 | while($row = mysql_fetch_array($result)) { |
|
- | 71 | if(!preg_match("/^http:\/\/", $row[0])) { |
||
71 | array_push($regions, $row[0]); |
72 | array_push($regions, $row[0]); |
|
- | 73 | } |
||
72 | } |
74 | } |
|
73 | |
75 | |
|
74 | $agents = 0; |
76 | $agents = 0; |
|
75 | $req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim'); |
77 | $req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim'); |
|
76 | foreach($regions as $region) { |
78 | foreach($regions as $region) { |
|
77 | $rep = new SimpleXMLElement($req->admin_get_agents($region, "false")); |
79 | $rep = new SimpleXMLElement($req->admin_get_agents($region, "false")); |
|
78 | foreach($rep->params->param->value->struct->member as $member) { |
80 | foreach($rep->params->param->value->struct->member as $member) { |
|
79 | if($member->name == "regions") { |
81 | if($member->name == "regions") { |
|
80 | foreach($member->value->array->data->value->struct->member as $member) { |
82 | foreach($member->value->array->data->value->struct->member as $member) { |
|
81 | if($member->name == "agents") { |
83 | if($member->name == "agents") { |
|
82 | $agents = count($member->value->array->data->value); |
84 | $agents = count($member->value->array->data->value); |
|
83 | goto counted; |
85 | goto counted; |
|
84 | } |
86 | } |
|
85 | } |
87 | } |
|
86 | } |
88 | } |
|
87 | } |
89 | } |
|
88 | } |
90 | } |
|
89 | |
91 | |
|
90 | counted: |
92 | counted: |
|
91 | |
93 | |
|
92 | if($agents == 0) { |
94 | if($agents == 0) { |
|
93 | $rep = new SimpleXMLElement($req->admin_console_command("scripts suspend")); |
95 | $rep = new SimpleXMLElement($req->admin_console_command("scripts suspend")); |
|
94 | return 0; |
96 | return 0; |
|
95 | } |
97 | } |
|
96 | $rep = new SimpleXMLElement($req->admin_console_command("scripts resume")); |
98 | $rep = new SimpleXMLElement($req->admin_console_command("scripts resume")); |
|
97 | return 0; |
99 | return 0; |
|
98 | |
100 | |