/[drupal]/contributions/modules/secondlife/secondlife.module
ViewVC logotype

Diff of /contributions/modules/secondlife/secondlife.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.4, Sun Dec 14 20:19:01 2008 UTC revision 1.4.2.1, Mon Dec 15 04:51:15 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  define('SECONDLIFE_SETTINGS_TIMER', 'secondlife_timer');  define('SECONDLIFE_SETTINGS_TIMER', 'secondlife_timer');
3  define('SECONDLIFE_SETTINGS_DEBUG', 'secondlife_debug');  define('SECONDLIFE_SETTINGS_DEBUG', 'secondlife_debug');
4    define('SECONDLIFE_SETTINGS_ARGS_SEPARATOR', 'secondlife_args_separator');
5    define('SECONDLIFE_SETTINGS_ARGS_ALLOWED_IPS', 'secondlife_allowed_ips');
6    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');
7    
8  /**  /**
9   * Implementation of hook_help().   * Implementation of hook_help().
# Line 13  function secondlife_help($section) { Line 16  function secondlife_help($section) {
16                          break;                          break;
17    }    }
18  }  }
   
19  /**  /**
20   * Implementation of hook_menu().   * Implementation of hook_menu().
21   */   */
# Line 34  function secondlife_menu() { Line 36  function secondlife_menu() {
36                  );                  );
37    return $items;    return $items;
38  }  }
39    /**
40     * Settings Administration Panel.
41     */
42  function secondlife_settings() {  function secondlife_settings() {
43    $options = array(    $options = array(
44      0 => t('User page'),      0 => t('User page'),
# Line 43  function secondlife_settings() { Line 47  function secondlife_settings() {
47    
48    $form[SECONDLIFE_SETTINGS_DEBUG] = array(    $form[SECONDLIFE_SETTINGS_DEBUG] = array(
49      '#type' => 'textfield',      '#type' => 'textfield',
50      '#title' => t('Debugging enabled?'),      '#title' => t('Debugging enabled ?'),
51      '#default_value' => variable_get(SECONDLIFE_SETTINGS_DEBUG, ''),      '#default_value' => variable_get(SECONDLIFE_SETTINGS_DEBUG, ''),
52      '#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('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'),
53    );    );
54    
55    $form[SECONDLIFE_SETTINGS_TIMER] = array(    $form[SECONDLIFE_SETTINGS_TIMER] = array(
56      '#type' => 'radios',      '#type' => 'radios',
57      '#title' => t('Enable timing of requests?'),      '#title' => t('Enable timing of requests ?'),
58      '#default_value' => variable_get(SECONDLIFE_SETTINGS_TIMER, 0),      '#default_value' => variable_get(SECONDLIFE_SETTINGS_TIMER, 0),
59      '#options' => array( 0 => t('Disabled'), 1 => t('Enabled') ),      '#options' => array( 0 => t('Disabled'), 1 => t('Enabled') ),
60      '#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).'),      '#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).'),
61    );    );
62    
63            $form[SECONDLIFE_SETTINGS_ARGS_SEPARATOR] = array(
64        '#type' => 'textfield',
65        '#title' => t('Arguments separator'),
66                    '#size' => 5,
67        '#default_value' => variable_get(SECONDLIFE_SETTINGS_ARGS_SEPARATOR, ':'),
68        '#description' => t('Enter the separator string for arguments.'),
69      );
70    
71            $form[SECONDLIFE_SETTINGS_ARGS_ALLOWED_IPS] = array(
72        '#type' => 'textfield',
73        '#title' => t('Allowed Ips'),
74        '#default_value' => variable_get(SECONDLIFE_SETTINGS_ARGS_ALLOWED_IPS, SECONDLIFE_LINDEN_SERVERS),
75        '#description' => t('Enter the allowed Ips separated by a comma.'),
76      );
77    return system_settings_form($form);    return system_settings_form($form);
78  }  }
79    /**
80     * Main function.
81     */
82  function secondlife_request() {  function secondlife_request() {
83            // check for server ips
84            $is_ll = FALSE;
85            $ll_subnets = explode(",", variable_get(SECONDLIFE_SETTINGS_ARGS_ALLOWED_IPS, SECONDLIFE_LINDEN_SERVERS) );
86            foreach( $ll_subnets as $network) {
87                            if(secondlife_netmatch($network,$_SERVER['REMOTE_ADDR'] )) {
88                                            $is_ll = TRUE;
89                                            break;
90                            }
91            }
92            if ( !$is_ll )
93            {
94                    secondlife_debug("*********************************************************");
95                    secondlife_debug(" WRONG IP ");
96                    secondlife_debug($_SERVER['REMOTE_ADDR']);
97                    secondlife_debug("*********************************************************");
98                    secondlife_get_session();
99                    return;
100            }
101    if (secondlife_timer()) {    if (secondlife_timer()) {
102      $start = _secondlife_getmillisecs();      $start = _secondlife_getmillisecs();
103    }    }
# Line 84  function secondlife_request() { Line 122  function secondlife_request() {
122    
123    secondlife_send_response($sl);    secondlife_send_response($sl);
124  }  }
125    /**
126     * Get the http variables.
127     */
128  function secondlife_get_session() {  function secondlife_get_session() {
129    secondlife_debug("=============================");
130    secondlife_debug(format_date(time(), 'custom', 'Y-m-d G:i:s'));
131    secondlife_debug("=============================");
132    foreach($_SERVER as $key => $value) {    foreach($_SERVER as $key => $value) {
133      secondlife_debug("SERVER: $key: $value");      secondlife_debug("SERVER: $key: $value");
134    }    }
# Line 105  function secondlife_get_session() { Line 148  function secondlife_get_session() {
148    $sl->app        = $_POST['app'];    $sl->app        = $_POST['app'];
149    $sl->cmd        = $_POST['cmd'];    $sl->cmd        = $_POST['cmd'];
150    $sl->arg        = $_POST['arg'];    $sl->arg        = $_POST['arg'];
151            $sl->output_type = $_POST['output_type'];
152    
153    preg_match_all('/(.*) \((\d+), (\d+)\)/', $sl->region, $temp);    preg_match_all('/(.*) \((\d+), (\d+)\)/', $sl->region, $temp);
154    $sl->region_name = $temp[1][0];    $sl->region_name = $temp[1][0];
# Line 120  function secondlife_get_session() { Line 164  function secondlife_get_session() {
164    
165    return $sl;    return $sl;
166  }  }
167    /**
168     * Parse the POST arguments.
169     */
170  function secondlife_parse_args($arg) {  function secondlife_parse_args($arg) {
171    $args = array();    $args = array();
172    foreach(explode(':', $arg) as $pair) {    foreach(explode(variable_get(SECONDLIFE_SETTINGS_ARGS_SEPARATOR, ':'), $arg) as $pair) {
173      list($key, $value) = explode('=', $pair);      list($key, $value) = explode('=', $pair);
174      $args[$key] = $value;      $args[$key] = $value;
175      secondlife_debug("ARGS: $key=$value");      secondlife_debug("ARGS: $key=$value");
# Line 131  function secondlife_parse_args($arg) { Line 177  function secondlife_parse_args($arg) {
177    
178    return $args;    return $args;
179  }  }
180    /**
181     * Returns the value to SecondLife.
182     */
183  function secondlife_send_response(&$sl) {  function secondlife_send_response(&$sl) {
184    $sl->response['app'] = $sl->app;    $sl->response['app'] = $sl->app;
185    $sl->response['cmd'] = $sl->cmd;    $sl->response['cmd'] = $sl->cmd;
# Line 140  function secondlife_send_response(&$sl) Line 188  function secondlife_send_response(&$sl)
188      secondlife_debug("RESPONSE: $key = $value");      secondlife_debug("RESPONSE: $key = $value");
189    }    }
190    
191    foreach($sl->response as $key => $value) {          switch($sl->output_type)
192      print "$key=$value:";          {
193    }                  default:
194    print "\n";                  case 'full':
195                            foreach($sl->response as $key => $value) {
196                                    print "$key=$value:";
197                            }
198                            print "\n";
199                            break;
200                    case 'message':
201                            print $sl->response['message'];
202                            break;
203            }
204    
205  }  }
206    /**
207     * Write the debug infos to the debug file.
208     */
209  function secondlife_debug($string) {  function secondlife_debug($string) {
210    $debug = variable_get('secondlife_debug', '');    $debug = variable_get('secondlife_debug', '');
211    if ($debug) {    if ($debug) {
212      file_put_contents($debug, "$string\n", FILE_APPEND);      file_put_contents($debug, "$string\n", FILE_APPEND);
213    }    }
214  }  }
215    /**
216     * Get a timer to compute the answer timing.
217     */
218  function secondlife_timer() {  function secondlife_timer() {
219    $timer = variable_get('secondlife_timer', '');    $timer = variable_get('secondlife_timer', '');
220    if ($timer) {    if ($timer) {
# Line 160  function secondlife_timer() { Line 222  function secondlife_timer() {
222    }    }
223    return FALSE;    return FALSE;
224  }  }
225    /**
226  function _secondlife_getmillisecs()   * Compute milliseconds.
227  {   */
228    function _secondlife_getmillisecs() {
229    list($usec, $sec) = explode (' ', microtime());    list($usec, $sec) = explode (' ', microtime());
230    return (double) $sec + $usec;    return (double) $sec + $usec;
231  }  }
232    /**
233     * Check the ip.
234     * Authors: Falados Kapuskas, JoeTheCatboy Freelunch
235     */
236     function secondlife_netmatch($network, $ip) {
237          // determines if a network in the form of 192.168.17.1/16 or
238          // 127.0.0.1/255.255.255.255 or 10.0.0.1 matches a given ip
239          $ip_arr = explode('/', $network);
240          $network_long = ip2long($ip_arr[0]);
241    
242          $x = ip2long($ip_arr[1]);
243          $mask =  long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]);
244          $ip_long = ip2long($ip);
245    
246          // echo ">".$ip_arr[1]."> ".decbin($mask)."\n";
247          return ($ip_long & $mask) == ($network_long & $mask);
248    }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.4.2.1

  ViewVC Help
Powered by ViewVC 1.1.2