diff -rup secondlife/samples/sltest.info temp/secondlife/samples/sltest.info --- secondlife/samples/sltest.info 2008-12-15 01:19:31.000000000 +0100 +++ temp/secondlife/samples/sltest.info 2008-12-15 04:36:29.000000000 +0100 @@ -1,7 +1,7 @@ ; $Id: sltest.info,v 1.4 2008/12/14 20:19:01 kbahey Exp $ name = Second Life test description = Second Life test and demo -dependencies = secondlife +dependencies[] = secondlife package = SecondLife core = 6.x diff -rup secondlife/samples/sltest.module temp/secondlife/samples/sltest.module --- secondlife/samples/sltest.module 2008-12-14 21:19:01.000000000 +0100 +++ temp/secondlife/samples/sltest.module 2008-12-15 03:53:17.000000000 +0100 @@ -1,5 +1,5 @@ response['message'] = "Hi there, $sl->ownername"; + $sl->response['message'] = "success;Hi there, $sl->ownername"; $sl->response['status'] = TRUE; break; case 'datetime': $date = format_date(time(), 'custom', 'Y-m-d G:i:s'); - $sl->response['message'] = "Server date/time: $date"; + $sl->response['message'] = "success;Server date/time: $date"; $sl->response['status'] = TRUE; break; case 'dump': + $output = array(); foreach($args as $k => $v) { - $output .= "$k : $v"; + array_push($output,"$k -> $v"); } - $sl->response['message'] = "ARGS: $output"; + $sl->response['message'] = "success;ARGS: ".implode(" : ",$output); $sl->response['status'] = TRUE; break; @@ -41,4 +43,3 @@ function sltest_dispatch($cmd, &$sl, $ar break; } } - Only in temp/secondlife/samples: testscript.lsl.txt diff -rup secondlife/secondlife.module temp/secondlife/secondlife.module --- secondlife/secondlife.module 2008-12-14 21:19:01.000000000 +0100 +++ temp/secondlife/secondlife.module 2008-12-15 06:07:02.000000000 +0100 @@ -1,6 +1,5 @@ t('User page'), 1 => t('Referrals page'), ); - $form[SECONDLIFE_SETTINGS_DEBUG] = array( + $form['secondlife_allowed_ips'] = array( + '#type' => 'textfield', + '#title' => t('Allowed Ips'), + '#default_value' => variable_get('secondlife_allowed_ips', SECONDLIFE_LINDEN_SERVERS), + '#description' => t('Enter the allowed Ips separated by a comma.'), + ); + + $form['secondlife_debug'] = array( '#type' => 'textfield', - '#title' => t('Debugging enabled?'), - '#default_value' => variable_get(SECONDLIFE_SETTINGS_DEBUG, ''), + '#title' => t('Debugging enabled ?'), + '#default_value' => variable_get('secondlife_debug', ''), '#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'), ); - $form[SECONDLIFE_SETTINGS_TIMER] = array( + $form['secondlife_timer'] = array( '#type' => 'radios', - '#title' => t('Enable timing of requests?'), - '#default_value' => variable_get(SECONDLIFE_SETTINGS_TIMER, 0), + '#title' => t('Enable timing of requests ?'), + '#default_value' => variable_get('secondlife_timer', 0), '#options' => array( 0 => t('Disabled'), 1 => t('Enabled') ), '#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).'), ); + $form['secondlife_separators'] = array( + '#type' => 'fieldset', + '#title' => t('Separators'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['secondlife_separators']['secondlife_args_separator'] = array( + '#type' => 'textfield', + '#title' => t('Arguments separator'), + '#size' => 5, + '#default_value' => variable_get('secondlife_args_separator', ':'), + '#description' => t('Enter the separator string for arguments.'), + ); + + $form['secondlife_fields_names'] = array( + '#type' => 'fieldset', + '#title' => t('Fields Names'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['secondlife_fields_names']['secondlife_app'] = array( + '#type' => 'textfield', + '#title' => t('App'), + '#default_value' => variable_get('secondlife_app', 'app'), + ); + $form['secondlife_fields_names']['secondlife_cmd'] = array( + '#type' => 'textfield', + '#title' => t('Cmd'), + '#default_value' => variable_get('secondlife_cmd', 'cmd'), + ); + $form['secondlife_fields_names']['secondlife_arg'] = array( + '#type' => 'textfield', + '#title' => t('Arg'), + '#default_value' => variable_get('secondlife_arg', 'arg'), + ); return system_settings_form($form); } - +/** + * Main function. + */ function secondlife_request() { + // check for server ips + $is_ll = FALSE; + $ll_subnets = explode(",", variable_get('secondlife_allowed_ips', SECONDLIFE_LINDEN_SERVERS) ); + foreach( $ll_subnets as $network) { + if(secondlife_netmatch($network,$_SERVER['REMOTE_ADDR'] )) { + $is_ll = TRUE; + break; + } + } + if ( !$is_ll ) + { + secondlife_debug("*********************************************************"); + secondlife_debug(" WRONG IP "); + secondlife_debug($_SERVER['REMOTE_ADDR']); + secondlife_debug("*********************************************************"); + secondlife_get_session(); + return; + } if (secondlife_timer()) { $start = _secondlife_getmillisecs(); } @@ -84,8 +146,13 @@ function secondlife_request() { secondlife_send_response($sl); } - +/** + * Get the http variables. + */ function secondlife_get_session() { +secondlife_debug("============================="); +secondlife_debug(format_date(time(), 'custom', 'Y-m-d G:i:s')); +secondlife_debug("============================="); foreach($_SERVER as $key => $value) { secondlife_debug("SERVER: $key: $value"); } @@ -96,20 +163,21 @@ function secondlife_get_session() { $sl = new stdClass(); - $sl->objectkey = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY']; - $sl->objectname = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_NAME']; - $sl->ownerkey = $_SERVER['HTTP_X_SECONDLIFE_OWNER_KEY']; - $sl->ownername = $_SERVER['HTTP_X_SECONDLIFE_OWNER_NAME']; - $sl->region = $_SERVER['HTTP_X_SECONDLIFE_REGION']; - $sl->position = $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']; - $sl->app = $_POST['app']; - $sl->cmd = $_POST['cmd']; - $sl->arg = $_POST['arg']; + $sl->objectkey = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY']; + $sl->objectname = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_NAME']; + $sl->ownerkey = $_SERVER['HTTP_X_SECONDLIFE_OWNER_KEY']; + $sl->ownername = $_SERVER['HTTP_X_SECONDLIFE_OWNER_NAME']; + $sl->region = $_SERVER['HTTP_X_SECONDLIFE_REGION']; + $sl->position = $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']; + $sl->app = $_POST[variable_get('secondlife_app', 'app')]; + $sl->cmd = $_POST[variable_get('secondlife_cmd', 'cmd')]; + $sl->arg = $_POST[variable_get('secondlife_arg', 'arg')]; + $sl->output_type = $_POST['output_type']; preg_match_all('/(.*) \((\d+), (\d+)\)/', $sl->region, $temp); $sl->region_name = $temp[1][0]; - $sl->region_x = $temp[2][0]; - $sl->region_y = $temp[3][0]; + $sl->region_x = $temp[2][0]; + $sl->region_y = $temp[3][0]; preg_match_all('/\((.*), (.*), (.*)\)/', $sl->position, $temp); $sl->position_x = $temp[1][0]; @@ -120,10 +188,12 @@ function secondlife_get_session() { return $sl; } - +/** + * Parse the POST arguments. + */ function secondlife_parse_args($arg) { $args = array(); - foreach(explode(':', $arg) as $pair) { + foreach(explode(variable_get('secondlife_args_separator', ':'), $arg) as $pair) { list($key, $value) = explode('=', $pair); $args[$key] = $value; secondlife_debug("ARGS: $key=$value"); @@ -131,7 +201,9 @@ function secondlife_parse_args($arg) { return $args; } - +/** + * Returns the value to SecondLife. + */ function secondlife_send_response(&$sl) { $sl->response['app'] = $sl->app; $sl->response['cmd'] = $sl->cmd; @@ -140,19 +212,33 @@ function secondlife_send_response(&$sl) secondlife_debug("RESPONSE: $key = $value"); } - foreach($sl->response as $key => $value) { - print "$key=$value:"; - } - print "\n"; + switch($sl->output_type) + { + default: + case 'full': + foreach($sl->response as $key => $value) { + print "$key=$value:"; + } + print "\n"; + break; + case 'message': + print $sl->response['message']; + break; + } + } - +/** + * Write the debug infos to the debug file. + */ function secondlife_debug($string) { $debug = variable_get('secondlife_debug', ''); if ($debug) { file_put_contents($debug, "$string\n", FILE_APPEND); } } - +/** + * Get a timer to compute the answer timing. + */ function secondlife_timer() { $timer = variable_get('secondlife_timer', ''); if ($timer) { @@ -160,9 +246,27 @@ function secondlife_timer() { } return FALSE; } - -function _secondlife_getmillisecs() -{ +/** + * Compute milliseconds. + */ +function _secondlife_getmillisecs() { list($usec, $sec) = explode (' ', microtime()); return (double) $sec + $usec; } +/** + * Check the ip. + * Authors: Falados Kapuskas, JoeTheCatboy Freelunch + */ + function secondlife_netmatch($network, $ip) { + // determines if a network in the form of 192.168.17.1/16 or + // 127.0.0.1/255.255.255.255 or 10.0.0.1 matches a given ip + $ip_arr = explode('/', $network); + $network_long = ip2long($ip_arr[0]); + + $x = ip2long($ip_arr[1]); + $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); + $ip_long = ip2long($ip); + + // echo ">".$ip_arr[1]."> ".decbin($mask)."\n"; + return ($ip_long & $mask) == ($network_long & $mask); +} \ No newline at end of file