clockwerk-tools – Diff between revs 23 and 24

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 23 Rev 24
1 #!/usr/bin/php 1 #!/usr/bin/php
2 <?php 2 <?php
3 3
4 ///////////////////////////////////////////////////////////// 4 /////////////////////////////////////////////////////////////
5 // Wizardry and Steamworks (c) was.fm - 2013, License: MIT // 5 // Wizardry and Steamworks (c) was.fm - 2013, 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 // CONFIGURATION // 33 // CONFIGURATION //
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 /////////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////////
50 // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // 50 // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 //
51 /////////////////////////////////////////////////////////////////////////// 51 ///////////////////////////////////////////////////////////////////////////
52 function wasChown($path, $uid, $gid) { 52 function wasChown($path, $uid, $gid) {
53 switch(filetype($path)) { 53 switch(filetype($path)) {
54 case 'dir': 54 case 'dir':
55 if(($dir = opendir($path)) === false) break; 55 if(($dir = opendir($path)) === false) break;
56 while(false !== ($file = readdir($dir))) { 56 while(false !== ($file = readdir($dir))) {
57 if($file == '.' || $file == '..') continue; 57 if($file == '.' || $file == '..') continue;
58 wasChown($path.'/'.$file, $uid, $gid); 58 wasChown($path.'/'.$file, $uid, $gid);
59 } 59 }
60 case 'file': 60 case 'file':
61 chown($path, $uid); 61 chown($path, $uid);
62 chgrp($path, $gid); 62 chgrp($path, $gid);
63 break; 63 break;
64 } 64 }
65 } 65 }
66   66  
67 require_once('/var/www/lib/wasRemoteAdmin.php'); 67 require_once('/var/www/lib/wasRemoteAdmin.php');
68   68  
69 if(!defined('STDIN')) { 69 if(!defined('STDIN')) {
70 print 'This script is meant to be run on the command line.'."\n"; 70 print 'This script is meant to be run on the command line.'."\n";
71 return 1; 71 return 1;
72 } 72 }
73 #if($argc < 2) { 73 #if($argc < 2) {
74 # print 'ERROR: Please specify OARs and IARs to filter on the command line.'."\n"; 74 # print 'ERROR: Please specify OARs and IARs to filter on the command line.'."\n";
75 # print 'Syntax: php '.$argv[0]. ' <First Name> <Last Name>'."\n"; 75 # print 'Syntax: php '.$argv[0]. ' <First Name> <Last Name>'."\n";
76 # return 1; 76 # return 1;
77 #} 77 #}
78   78  
79 $connection_ok = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD); 79 $connection_ok = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
80 if(!$connection_ok) { 80 if(!$connection_ok) {
81 print 'Could not connect to the OpenSim database. Please edit the script and make sure the credentials are correct.'."\n"; 81 print 'Could not connect to the OpenSim database. Please edit the script and make sure the credentials are correct.'."\n";
82 return 1; 82 return 1;
83 } 83 }
84 $db_selected = mysql_select_db(MYSQL_DATABASE); 84 $db_selected = mysql_select_db(MYSQL_DATABASE);
85 if(!$db_selected) { 85 if(!$db_selected) {
86 print 'Could not select the opensim database. Please edit this script and make sure the credentials are correct.'."\n"; 86 print 'Could not select the opensim database. Please edit this script and make sure the credentials are correct.'."\n";
87 return 1; 87 return 1;
88 } 88 }
89   89  
90 $query = 'SELECT RegionName FROM regions'; 90 $query = 'SELECT RegionName FROM regions';
91 $result = mysql_query($query); 91 $result = mysql_query($query);
92 $regions = array(); 92 $regions = array();
93 while($row = mysql_fetch_array($result)) { 93 while($row = mysql_fetch_array($result)) {
94 array_push($regions, $row[0]); 94 array_push($regions, $row[0]);
95 } 95 }
96   96  
97 // Now we can get rid of the script name. 97 // Now we can get rid of the script name.
98 array_shift($argv); 98 array_shift($argv);
99   99  
100 // Create the request 100 // Create the request
101 $req = new wasRemoteAdmin('http://localhost:10000', 'opensim'); 101 $req = new wasRemoteAdmin('http://localhost:10000', 'opensim');
102   102  
103 // ..and dump 103 // ..and dump
104 foreach($regions as $region) { 104 foreach($regions as $region) {
105 $_region = preg_replace('/\s/','_',$region); 105 $_region = preg_replace('/\s/','_',$region);
106 $REGION_FOLDER='/var/lib/oar/'.$_region; 106 $REGION_FOLDER='/var/lib/oar/'.$_region;
107 if(!is_dir($REGION_FOLDER)) mkdir($REGION_FOLDER); 107 if(!is_dir($REGION_FOLDER)) mkdir($REGION_FOLDER);
108 wasChown($REGION_FOLDER, 'opensim'); 108 wasChown($REGION_FOLDER, 'opensim', 'opensim');
109 $req->admin_console_command('change region '.$region); 109 $req->admin_console_command('change region '.$region);
110 $req->admin_console_command('save oar /'.$REGION_FOLDER.'/'.$_region.'.oar'); 110 $req->admin_console_command('save oar /'.$REGION_FOLDER.'/'.$_region.'.oar');
111 wasChown($REGION_FOLDER, 'www-data'); 111 wasChown($REGION_FOLDER, 'www-data', 'www-data');
112 } 112 }
113   113  
114   114