| 1 |
<?php |
<?php |
| 2 |
define('SECONDLIFE_SETTINGS_TIMER', 'secondlife_timer'); |
|
| 3 |
define('SECONDLIFE_SETTINGS_DEBUG', 'secondlife_debug'); |
// $Id$ |
| 4 |
define('SECONDLIFE_SETTINGS_ARGS_SEPARATOR', 'secondlife_args_separator'); |
|
|
define('SECONDLIFE_SETTINGS_ARGS_ALLOWED_IPS', 'secondlife_allowed_ips'); |
|
| 5 |
define('SECONDLIFE_LINDEN_SERVERS', '8.2.32.0/22,63.210.156.0/22,64.129.40.0/22,64.129.44.0/22,64.154.220.0/22,8.4.128.0/22,8.10.144.0/21,216.82.0.0/18'); |
define('SECONDLIFE_LINDEN_SERVERS', '8.2.32.0/22,63.210.156.0/22,64.129.40.0/22,64.129.44.0/22,64.154.220.0/22,8.4.128.0/22,8.10.144.0/21,216.82.0.0/18'); |
| 6 |
|
|
| 7 |
/** |
/** |
| 9 |
*/ |
*/ |
| 10 |
function secondlife_help($section) { |
function secondlife_help($section) { |
| 11 |
switch ($section) { |
switch ($section) { |
| 12 |
case 'admin/help#sl': |
case 'admin/help#secondlife': |
| 13 |
$output = '<p>'. t('SecondLife integration library') .'</p>'; |
return '<p>' . t('SecondLife integration library') . '</p>'; |
|
return $output; |
|
|
break; |
|
| 14 |
} |
} |
| 15 |
} |
} |
| 16 |
/** |
/** |
| 17 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 18 |
*/ |
*/ |
| 19 |
function secondlife_menu() { |
function secondlife_menu() { |
| 20 |
$items['admin/settings/secondlife'] = array( |
$items['admin/settings/secondlife'] = array( |
| 21 |
'title' => t('Second Life'), |
'title' => t('Second Life'), |
| 22 |
'description' => t('Settings for the Second Life Framework module.'), |
'description' => t('Settings for the Second Life Framework module.'), |
| 23 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 24 |
'page arguments' => array('secondlife_settings'), |
'page arguments' => array('secondlife_settings'), |
| 25 |
'access arguments' => array('administer site configuration'), |
'access arguments' => array('administer site configuration'), |
| 26 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 27 |
); |
); |
| 28 |
|
|
| 29 |
$items['secondlife'] = array( |
$items['secondlife'] = array( |
| 30 |
'page callback' => 'secondlife_request', |
'page callback' => 'secondlife_request', |
| 31 |
'access callback' => TRUE, |
'access callback' => TRUE, |
| 32 |
'type' => MENU_LOCAL_TASK |
'type' => MENU_LOCAL_TASK |
| 33 |
); |
); |
| 34 |
|
|
| 35 |
return $items; |
return $items; |
| 36 |
} |
} |
| 37 |
/** |
/** |
| 43 |
1 => t('Referrals page'), |
1 => t('Referrals page'), |
| 44 |
); |
); |
| 45 |
|
|
| 46 |
$form[SECONDLIFE_SETTINGS_DEBUG] = array( |
$form['secondlife_allowed_ips'] = array( |
| 47 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 48 |
'#title' => t('Debugging enabled ?'), |
'#title' => t('Allowed Ips'), |
| 49 |
'#default_value' => variable_get(SECONDLIFE_SETTINGS_DEBUG, ''), |
'#default_value' => variable_get('secondlife_allowed_ips', SECONDLIFE_LINDEN_SERVERS), |
| 50 |
'#description' => t('Enable debugging output of server/client interactions. Enter the full path name of the file to write the debugging output to, such as /tmp/secondlife.debug. It must be writable to the user who runs your web server. Leave blank for no debugging'), |
'#description' => t('Enter the allowed Ips separated by a comma.'), |
| 51 |
); |
); |
| 52 |
|
|
| 53 |
$form[SECONDLIFE_SETTINGS_TIMER] = array( |
$form['secondlife_debug'] = array( |
| 54 |
'#type' => 'radios', |
'#type' => 'textfield', |
| 55 |
'#title' => t('Enable timing of requests ?'), |
'#title' => t('Debugging enabled ?'), |
| 56 |
'#default_value' => variable_get(SECONDLIFE_SETTINGS_TIMER, 0), |
'#default_value' => variable_get('secondlife_debug', ''), |
| 57 |
'#options' => array( 0 => t('Disabled'), 1 => t('Enabled') ), |
'#description' => t('Enable debugging output of server/client interactions. Enter the full path name of the file to write the debugging output to, such as /tmp/secondlife.debug. It must be writable to the user who runs your web server. Leave blank for no debugging'), |
| 58 |
'#description' => t('Select whether you want to record timing information for how much it takes to process requests from the clients. A "timer=" is send with the response to the client, and if also writting to the debugging output (if enabled).'), |
); |
| 59 |
); |
|
| 60 |
|
$form['secondlife_timer'] = array( |
| 61 |
$form[SECONDLIFE_SETTINGS_ARGS_SEPARATOR] = array( |
'#type' => 'radios', |
| 62 |
'#type' => 'textfield', |
'#title' => t('Enable timing of requests ?'), |
| 63 |
'#title' => t('Arguments separator'), |
'#default_value' => variable_get('secondlife_timer', 0), |
| 64 |
'#size' => 5, |
'#options' => array( 0 => t('Disabled'), 1 => t('Enabled') ), |
| 65 |
'#default_value' => variable_get(SECONDLIFE_SETTINGS_ARGS_SEPARATOR, ':'), |
'#description' => t('Select whether you want to record timing information for how much it takes to process requests from the clients. A "timer=" is send with the response to the client, and if also writting to the debugging output (if enabled).'), |
| 66 |
'#description' => t('Enter the separator string for arguments.'), |
); |
| 67 |
); |
|
| 68 |
|
$form['secondlife_separators'] = array( |
| 69 |
$form[SECONDLIFE_SETTINGS_ARGS_ALLOWED_IPS] = array( |
'#type' => 'fieldset', |
| 70 |
'#type' => 'textfield', |
'#title' => t('Separators'), |
| 71 |
'#title' => t('Allowed Ips'), |
'#collapsible' => TRUE, |
| 72 |
'#default_value' => variable_get(SECONDLIFE_SETTINGS_ARGS_ALLOWED_IPS, SECONDLIFE_LINDEN_SERVERS), |
'#collapsed' => TRUE, |
| 73 |
'#description' => t('Enter the allowed Ips separated by a comma.'), |
); |
| 74 |
|
$form['secondlife_separators']['secondlife_args_separator'] = array( |
| 75 |
|
'#type' => 'textfield', |
| 76 |
|
'#title' => t('Arguments separator'), |
| 77 |
|
'#size' => 5, |
| 78 |
|
'#default_value' => variable_get('secondlife_args_separator', ':'), |
| 79 |
|
'#description' => t('Enter the separator string for arguments.'), |
| 80 |
|
); |
| 81 |
|
|
| 82 |
|
$form['secondlife_fields_names'] = array( |
| 83 |
|
'#type' => 'fieldset', |
| 84 |
|
'#title' => t('Fields Names'), |
| 85 |
|
'#collapsible' => TRUE, |
| 86 |
|
'#collapsed' => TRUE, |
| 87 |
|
); |
| 88 |
|
$form['secondlife_fields_names']['secondlife_app'] = array( |
| 89 |
|
'#type' => 'textfield', |
| 90 |
|
'#title' => t('App'), |
| 91 |
|
'#default_value' => variable_get('secondlife_app', 'app'), |
| 92 |
|
); |
| 93 |
|
$form['secondlife_fields_names']['secondlife_cmd'] = array( |
| 94 |
|
'#type' => 'textfield', |
| 95 |
|
'#title' => t('Cmd'), |
| 96 |
|
'#default_value' => variable_get('secondlife_cmd', 'cmd'), |
| 97 |
|
); |
| 98 |
|
$form['secondlife_fields_names']['secondlife_arg'] = array( |
| 99 |
|
'#type' => 'textfield', |
| 100 |
|
'#title' => t('Arg'), |
| 101 |
|
'#default_value' => variable_get('secondlife_arg', 'arg'), |
| 102 |
); |
); |
| 103 |
return system_settings_form($form); |
return system_settings_form($form); |
| 104 |
} |
} |
| 106 |
* Main function. |
* Main function. |
| 107 |
*/ |
*/ |
| 108 |
function secondlife_request() { |
function secondlife_request() { |
| 109 |
// check for server ips |
// check for server ips |
| 110 |
$is_ll = FALSE; |
$is_ll = FALSE; |
| 111 |
$ll_subnets = explode(",", variable_get(SECONDLIFE_SETTINGS_ARGS_ALLOWED_IPS, SECONDLIFE_LINDEN_SERVERS) ); |
$ll_subnets = explode(",", variable_get('secondlife_allowed_ips', SECONDLIFE_LINDEN_SERVERS) ); |
| 112 |
foreach( $ll_subnets as $network) { |
foreach( $ll_subnets as $network) { |
| 113 |
if(secondlife_netmatch($network,$_SERVER['REMOTE_ADDR'] )) { |
if(secondlife_netmatch($network,$_SERVER['REMOTE_ADDR'] )) { |
| 114 |
$is_ll = TRUE; |
$is_ll = TRUE; |
| 115 |
break; |
break; |
| 116 |
} |
} |
| 117 |
} |
} |
| 118 |
if ( !$is_ll ) |
if ( !$is_ll ) { |
| 119 |
{ |
secondlife_debug("*********************************************************"); |
| 120 |
secondlife_debug("*********************************************************"); |
secondlife_debug(" WRONG IP "); |
| 121 |
secondlife_debug(" WRONG IP "); |
secondlife_debug($_SERVER['REMOTE_ADDR']); |
| 122 |
secondlife_debug($_SERVER['REMOTE_ADDR']); |
secondlife_debug("*********************************************************"); |
| 123 |
secondlife_debug("*********************************************************"); |
secondlife_get_session(); |
| 124 |
secondlife_get_session(); |
return; |
| 125 |
return; |
} |
|
} |
|
| 126 |
if (secondlife_timer()) { |
if (secondlife_timer()) { |
| 127 |
$start = _secondlife_getmillisecs(); |
$start = _secondlife_getmillisecs(); |
| 128 |
} |
} |
| 151 |
* Get the http variables. |
* Get the http variables. |
| 152 |
*/ |
*/ |
| 153 |
function secondlife_get_session() { |
function secondlife_get_session() { |
| 154 |
secondlife_debug("============================="); |
secondlife_debug("============================="); |
| 155 |
secondlife_debug(format_date(time(), 'custom', 'Y-m-d G:i:s')); |
secondlife_debug(format_date(time(), 'custom', 'Y-m-d G:i:s')); |
| 156 |
secondlife_debug("============================="); |
secondlife_debug("============================="); |
| 157 |
foreach($_SERVER as $key => $value) { |
foreach($_SERVER as $key => $value) { |
| 158 |
secondlife_debug("SERVER: $key: $value"); |
secondlife_debug("SERVER: $key: $value"); |
| 159 |
} |
} |
| 164 |
|
|
| 165 |
$sl = new stdClass(); |
$sl = new stdClass(); |
| 166 |
|
|
| 167 |
$sl->objectkey = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY']; |
$sl->objectkey = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY']; |
| 168 |
$sl->objectname = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_NAME']; |
$sl->objectname = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_NAME']; |
| 169 |
$sl->ownerkey = $_SERVER['HTTP_X_SECONDLIFE_OWNER_KEY']; |
$sl->ownerkey = $_SERVER['HTTP_X_SECONDLIFE_OWNER_KEY']; |
| 170 |
$sl->ownername = $_SERVER['HTTP_X_SECONDLIFE_OWNER_NAME']; |
$sl->ownername = $_SERVER['HTTP_X_SECONDLIFE_OWNER_NAME']; |
| 171 |
$sl->region = $_SERVER['HTTP_X_SECONDLIFE_REGION']; |
$sl->region = $_SERVER['HTTP_X_SECONDLIFE_REGION']; |
| 172 |
$sl->position = $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']; |
$sl->position = $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']; |
| 173 |
$sl->app = $_POST['app']; |
$sl->app = $_POST[variable_get('secondlife_app', 'app')]; |
| 174 |
$sl->cmd = $_POST['cmd']; |
$sl->cmd = $_POST[variable_get('secondlife_cmd', 'cmd')]; |
| 175 |
$sl->arg = $_POST['arg']; |
$sl->arg = $_POST[variable_get('secondlife_arg', 'arg')]; |
| 176 |
$sl->output_type = $_POST['output_type']; |
$sl->output_type = $_POST['output_type']; |
| 177 |
|
|
| 178 |
preg_match_all('/(.*) \((\d+), (\d+)\)/', $sl->region, $temp); |
preg_match_all('/(.*) \((\d+), (\d+)\)/', $sl->region, $temp); |
| 179 |
$sl->region_name = $temp[1][0]; |
$sl->region_name = $temp[1][0]; |
| 181 |
$sl->region_y = $temp[3][0]; |
$sl->region_y = $temp[3][0]; |
| 182 |
|
|
| 183 |
preg_match_all('/\((.*), (.*), (.*)\)/', $sl->position, $temp); |
preg_match_all('/\((.*), (.*), (.*)\)/', $sl->position, $temp); |
| 184 |
$sl->position_x = $temp[1][0]; |
$sl->position_x = $temp[1][0]; |
| 185 |
$sl->position_y = $temp[2][0]; |
$sl->position_y = $temp[2][0]; |
| 186 |
$sl->position_z = $temp[3][0]; |
$sl->position_z = $temp[3][0]; |
| 187 |
|
|
| 188 |
secondlife_debug("SL: " . print_r($sl, TRUE) . "\n", FILE_APPEND); |
secondlife_debug("SL: " . print_r($sl, TRUE) . "\n", FILE_APPEND); |
| 189 |
|
|
| 194 |
*/ |
*/ |
| 195 |
function secondlife_parse_args($arg) { |
function secondlife_parse_args($arg) { |
| 196 |
$args = array(); |
$args = array(); |
| 197 |
foreach(explode(variable_get(SECONDLIFE_SETTINGS_ARGS_SEPARATOR, ':'), $arg) as $pair) { |
foreach(explode(variable_get('secondlife_args_separator', ':'), $arg) as $pair) { |
| 198 |
list($key, $value) = explode('=', $pair); |
list($key, $value) = explode('=', $pair); |
| 199 |
$args[$key] = $value; |
$args[$key] = $value; |
| 200 |
secondlife_debug("ARGS: $key=$value"); |
secondlife_debug("ARGS: $key=$value"); |
| 213 |
secondlife_debug("RESPONSE: $key = $value"); |
secondlife_debug("RESPONSE: $key = $value"); |
| 214 |
} |
} |
| 215 |
|
|
| 216 |
switch($sl->output_type) |
switch($sl->output_type) { |
| 217 |
{ |
default: |
| 218 |
default: |
case 'full': |
| 219 |
case 'full': |
foreach($sl->response as $key => $value) { |
| 220 |
foreach($sl->response as $key => $value) { |
print "$key=$value:"; |
| 221 |
print "$key=$value:"; |
} |
| 222 |
} |
print "\n"; |
| 223 |
print "\n"; |
break; |
| 224 |
break; |
case 'message': |
| 225 |
case 'message': |
print $sl->response['message']; |
| 226 |
print $sl->response['message']; |
break; |
| 227 |
break; |
} |
| 228 |
} |
|
|
|
|
| 229 |
} |
} |
| 230 |
/** |
/** |
| 231 |
* Write the debug infos to the debug file. |
* Write the debug infos to the debug file. |
| 246 |
} |
} |
| 247 |
return FALSE; |
return FALSE; |
| 248 |
} |
} |
| 249 |
|
|
| 250 |
/** |
/** |
| 251 |
* Compute milliseconds. |
* Compute milliseconds. |
| 252 |
*/ |
*/ |
| 254 |
list($usec, $sec) = explode (' ', microtime()); |
list($usec, $sec) = explode (' ', microtime()); |
| 255 |
return (double) $sec + $usec; |
return (double) $sec + $usec; |
| 256 |
} |
} |
| 257 |
|
|
| 258 |
/** |
/** |
| 259 |
* Check the ip. |
* Check the ip. |
| 260 |
* Authors: Falados Kapuskas, JoeTheCatboy Freelunch |
* Authors: Falados Kapuskas, JoeTheCatboy Freelunch |
| 261 |
*/ |
*/ |
| 262 |
function secondlife_netmatch($network, $ip) { |
function secondlife_netmatch($network, $ip) { |
| 263 |
// determines if a network in the form of 192.168.17.1/16 or |
// determines if a network in the form of 192.168.17.1/16 or |
| 264 |
// 127.0.0.1/255.255.255.255 or 10.0.0.1 matches a given ip |
// 127.0.0.1/255.255.255.255 or 10.0.0.1 matches a given ip |
| 265 |
$ip_arr = explode('/', $network); |
$ip_arr = explode('/', $network); |
| 266 |
$network_long = ip2long($ip_arr[0]); |
$network_long = ip2long($ip_arr[0]); |
| 267 |
|
|
| 268 |
$x = ip2long($ip_arr[1]); |
$x = ip2long($ip_arr[1]); |
| 269 |
$mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); |
$mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); |
| 270 |
$ip_long = ip2long($ip); |
$ip_long = ip2long($ip); |
| 271 |
|
|
| 272 |
|
return ($ip_long & $mask) == ($network_long & $mask); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
/** |
| 276 |
|
* XML-RPC Helpers |
| 277 |
|
*/ |
| 278 |
|
function secondlife_get_data_between($src, $left, $right) { |
| 279 |
|
// function to return the data between two tokens (VERY USEFUL) |
| 280 |
|
$ids = stripos($src,$left) + strlen($left); |
| 281 |
|
if($ids === false) return false; |
| 282 |
|
$ide = stripos($src,$right,$ids); |
| 283 |
|
if($ide === false) return false; |
| 284 |
|
return(substr($src,$ids,$ide - $ids)); |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
function secondlife_rpc ($channel, $intVal, $stringVal) { |
| 288 |
|
// function to emulate xml-rpc for SL remote data connections |
| 289 |
|
// encapsulate request data in xml |
| 290 |
|
$xml = "<?xml version=\"1.0\"?> |
| 291 |
|
<methodCall><methodName>llRemoteData</methodName><params><param><value><struct><member><name>Channel</name> |
| 292 |
|
<value><string>{$channel}</string></value></member><member><name>IntValue</name> |
| 293 |
|
<value><int>{$intVal}</int></value></member><member><name>StringValue</name> |
| 294 |
|
<value><string>{$stringVal}</string></value></member> |
| 295 |
|
</struct></value></param></params></methodCall>"; |
| 296 |
|
|
| 297 |
|
// open connection to xmlrpc server |
| 298 |
|
$socket = fsockopen('xmlrpc.secondlife.com', 80); |
| 299 |
|
// send HTTP header |
| 300 |
|
fputs($socket, "POST /cgi-bin/xmlrpc.cgi HTTP/1.1\r\n"); |
| 301 |
|
fputs($socket, "Host: xmlrpc.secondlife.com\r\n"); |
| 302 |
|
fputs($socket, "Content-type: text/xml\r\n"); |
| 303 |
|
fputs($socket, "Content-length: ".strlen($xml)."\r\n"); |
| 304 |
|
fputs($socket, "Connection: close\r\n\r\n"); |
| 305 |
|
// send xml data |
| 306 |
|
fputs($socket, $xml); |
| 307 |
|
|
| 308 |
|
// read response from rpc server |
| 309 |
|
while(!feof($socket)) $response .= fgets($socket); |
| 310 |
|
|
| 311 |
|
// close the connection |
| 312 |
|
fclose($socket); |
| 313 |
|
|
| 314 |
|
// parse out the returned data |
| 315 |
|
$sVal = get_data_between($response, 'StringValue</name><value><string>','</string>'); |
| 316 |
|
$iVal = get_data_between($response, '<value><int>','</int></value>'); |
| 317 |
|
|
| 318 |
// echo ">".$ip_arr[1]."> ".decbin($mask)."\n"; |
// return the response data in an array |
| 319 |
return ($ip_long & $mask) == ($network_long & $mask); |
return array('channel' => $channel, 'string' => $sVal, 'integer' => $iVal); |
| 320 |
} |
} |