clockwerk-tools – Rev 24
?pathlinks?
#!/usr/bin/php
<?php
/////////////////////////////////////////////////////////////
// Wizardry and Steamworks (c) was.fm - 2013, License: MIT //
// //
// Permission is hereby granted, free of charge, to any //
// person obtaining a copy of this software and associated //
// documentation files (the "Software"), to deal in the //
// Software without restriction, //including without //
// limitation the rights to use, copy, modify, merge, //
// publish, distribute, sublicense, and/or sell copies of //
// the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the //
// following conditions: //
// //
// The above copyright notice and this permission notice //
// shall be included in all copies or substantial portions //
// of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF //
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT //
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS //
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO //
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE //
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER //
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
// CONFIGURATION //
/////////////////////////////////////////////////////////////
// Hostname or IP of your OpenSim MySQL server.
define("MYSQL_HOSTNAME", "localhost");
// Username of the OpenSim MySQL user.
define("MYSQL_USERNAME", "opensim");
// Password of the OpenSim MySQL user.
define("MYSQL_PASSWORD", "***");
// Name of the OpenSim database on the MySQL server.
define("MYSQL_DATABASE", "opensim");
/////////////////////////////////////////////////////////////
// INTERNALS //
/////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
function wasChown($path, $uid, $gid) {
switch(filetype($path)) {
case 'dir':
if(($dir = opendir($path)) === false) break;
while(false !== ($file = readdir($dir))) {
if($file == '.' || $file == '..') continue;
wasChown($path.'/'.$file, $uid, $gid);
}
case 'file':
chown($path, $uid);
chgrp($path, $gid);
break;
}
}
require_once('/var/www/lib/wasRemoteAdmin.php');
if(!defined('STDIN')) {
print 'This script is meant to be run on the command line.'."\n";
return 1;
}
#if($argc < 2) {
# print 'ERROR: Please specify OARs and IARs to filter on the command line.'."\n";
# print 'Syntax: php '.$argv[0]. ' <First Name> <Last Name>'."\n";
# return 1;
#}
$connection_ok = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
if(!$connection_ok) {
print 'Could not connect to the OpenSim database. Please edit the script and make sure the credentials are correct.'."\n";
return 1;
}
$db_selected = mysql_select_db(MYSQL_DATABASE);
if(!$db_selected) {
print 'Could not select the opensim database. Please edit this script and make sure the credentials are correct.'."\n";
return 1;
}
$query = 'SELECT RegionName FROM regions';
$result = mysql_query($query);
$regions = array();
while($row = mysql_fetch_array($result)) {
array_push($regions, $row[0]);
}
// Now we can get rid of the script name.
array_shift($argv);
// Create the request
$req = new wasRemoteAdmin('http://localhost:10000', 'opensim');
// ..and dump
foreach($regions as $region) {
$_region = preg_replace('/\s/','_',$region);
$REGION_FOLDER='/var/lib/oar/'.$_region;
if(!is_dir($REGION_FOLDER)) mkdir($REGION_FOLDER);
wasChown($REGION_FOLDER, 'opensim', 'opensim');
$req->admin_console_command('change region '.$region);
$req->admin_console_command('save oar /'.$REGION_FOLDER.'/'.$_region.'.oar');
wasChown($REGION_FOLDER, 'www-data', 'www-data');
}