Changeset 63 for trunk/instant_messenger/IMManager.php
- Timestamp:
- 08/29/07 08:55:50 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/instant_messenger/IMManager.php
r55 r63 1 1 #!/usr/bin/php -Cq 2 2 <?php 3 //error_reporting(0); 4 //ini_set( 'track_errors', '1' ); 5 ### 6 # This file is prepared for receive dependable connections but 7 # exists a BUG in the PHP related with the library OpenSSL that 8 # doesn't permit the enable crypto in connection created. 9 # 10 # See [Bug #40993 stream_socket_accept() : accept failed] in 11 # http://bugs.php.net/bug.php?id=40993&edit=1 12 # 13 # 14 ### 3 15 4 require_once('inc/IMConfigure.php'); 16 5 … … 18 7 # definitions of socket - BEGIN 19 8 # 20 /***21 * This file is prepared for receive dependable connections but22 * exists a BUG in the PHP related with the library OpenSSL that23 * doesn't permit the enable crypto in connection created.24 *25 * See [Bug #40993 stream_socket_accept() : accept failed] in26 * http://bugs.php.net/bug.php?id=40993&edit=127 *28 *29 * It's necessary to remove all the comments made with '//'30 * for safe connection31 *32 *33 * WARNING - DANGER:34 *35 * Before remove all the comments made with '//' for safe36 * connection, it's necessary to remove all the comments37 * made with '//' in the file IMConfigure.php38 * If this will not be made will happen many ERRORS39 ***/40 41 //define("CONTEXT", stream_context_create());42 43 9 define('URI', '0.0.0.0'); 44 45 10 define('TARGET_NON_SECURITY', TRANSPORT_NON_SECURITY . '://' . URI . ':' . PORT_NON_SECURITY); 46 //define('TARGET_SECURITY', TRANSPORT_SECURITY . '://' . URI . ':' . PORT_SECURITY);47 48 //stream_context_set_option(CONTEXT, 'ssl', 'local_cert', './apache.pem'); # local_cert must be in PEM format49 //stream_context_set_option(CONTEXT, 'ssl', 'allow_self_signed', true);50 //stream_context_set_option(CONTEXT, 'ssl', 'verify_peer', false);51 52 11 define('SOCKET_NON_SECURITY', stream_socket_server(TARGET_NON_SECURITY, $errno_non_security, $errstr_non_security, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN)); 53 //define('SOCKET_SECURITY', stream_socket_server(TARGET_SECURITY, $errno_security, $errstr_security, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, CONTEXT));54 12 # 55 13 # definitions of socket - END 56 14 ### 57 15 58 //if ( !SOCKET_NON_SECURITY || !SOCKET_SECURITY ) # It's necessary to remove the next line for safe connection 16 59 17 if ( !SOCKET_NON_SECURITY ) 60 18 { 61 19 printf("NON SECURITY:\n(%d) %s", $errno_non_security, $errstr_non_security); 62 //printf("SECURITY:\n(%d) %s", $errno_security, $errstr_security);63 20 exit(0); 64 21 } … … 66 23 include 'inc/Jabberd2.abstract.php'; 67 24 68 //$master = array(SOCKET_NON_SECURITY, SOCKET_SECURITY); # It's necessary to remove the next line for safe connection69 25 $master = array(SOCKET_NON_SECURITY); 70 26 … … 79 35 $_e = NULL; 80 36 81 $mod_fd = @stream_select($read, $_w , $_e , READ_SOCKET_AFTER_OF );37 $mod_fd = @stream_select($read, $_w , $_e , READ_SOCKET_AFTER_OF ); 82 38 83 39 if ( $mod_fd === FALSE ) … … 85 41 86 42 for ( $i = 0; $i < $mod_fd; ++$i ) 43 { 87 44 if ( $read[$i] === SOCKET_NON_SECURITY ) 88 45 { 89 46 $conn_non_security = stream_socket_accept(SOCKET_NON_SECURITY); 90 # fwrite($conn_non_security, "Hello! The time is " . date("n/j/Y g:i:s a"));91 47 $master[] = &$conn_non_security; 92 48 } 93 //else if ( $read[$i] === SOCKET_SECURITY )94 //{95 // $conn_security = stream_socket_accept(SOCKET_SECURITY);96 // fwrite($conn_security, "Hello! The time is " . date("n/j/Y g:i:s a")."\n");97 // $master[] = &$conn_security;98 //}99 49 else 100 50 { … … 102 52 if ( strlen($sock_data) === 0 ) 103 53 { 104 printf("Connection closed");105 54 $key_to_del = array_search($read[$i], $master, TRUE); 106 55 fclose($read[$i]); … … 109 58 else if ( $sock_data === FALSE ) 110 59 { 111 printf("Something bad happened");112 60 $key_to_del = array_search($read[$i], $master, TRUE); 113 61 unset($master[$key_to_del]); … … 115 63 else 116 64 { 117 # printf("\n\n%s\n\n", $sock_data);118 65 $headers = (split("\n", $sock_data)); 119 66 … … 121 68 preg_match('/^Host: \w*:(.+)/', $headers[1], $host); 122 69 123 //if ( (int)$host[1] == PORT_NON_SECURITY ) 124 $conn = &$conn_non_security; 125 //else 126 // $conn = &$conn_security; 70 $conn = &$conn_non_security; 127 71 128 72 $request = explode(';', $request[2]); 129 73 130 74 if ( $request[0] == CONNECT && isset($request[1]) && !isset($users[$request[1]]) ) 75 { 131 76 connect($users, $request[1]); 77 } 132 78 133 79 if ( $request[0] == CLOSE && isset($request[1]) && isset($users[$request[1]]) ) 134 close($request[1]); 80 { 81 close($request[1]); 82 } 135 83 136 84 fclose($read[$i]); … … 138 86 } 139 87 } 140 88 } 89 141 90 foreach ( $users as $key => $val ) 142 91 { 143 if ( (time() - $users[$key]['time'] > DISCONNECT_AFTERWARDS_OF) ) 144 if ( $users[$key]['attempt'] > 2 ) 145 { 146 $users[$key]['attempt'] = 0; 147 close($key); 148 } 149 else 150 { 151 $users[$key]['attempt']++; 152 readSocket($users, $key); 153 } 92 if($users[$key]['time0'] != $users[$key]['time1'] ) 93 { 94 $users[$key]['time1'] = $users[$key]['time0']; 95 $users[$key]['attempt'] = 0; 96 readSocket($key); 97 //readSocket($users, $key); 98 } 154 99 else 155 100 { 156 $users[$key]['attempt'] = 0; 157 readSocket($users, $key); 158 } 101 $users[$key]['attempt']++; 102 if( $users[$key]['attempt'] > 5 ) 103 { 104 $users[$key]['jabber']->disconnect(); 105 unset($users[$key]); 106 } 107 else 108 { 109 readSocket($key); 110 //readSocket($users, $key); 111 } 112 } 113 114 //print_r("Session : " . $key . " | Count : " . count($users) . " | time 0 : " . $users[$key]['time0'] . " | time 1 : " . $users[$key]['time1'] . " | tentativas : " . $users[$key]['attempt'] . " \n"); 159 115 } 160 116 161 //print_r($users);162 } 163 117 } 118 119 164 120 exit(0); 165 121 122 166 123 function connect(&$pUsers, $pSession) 167 124 { … … 203 160 $pUsers[$pSession] = array(); 204 161 $pUsers[$pSession]['jabber'] = $a; 205 $pUsers[$pSession]['time'] = $_time; 162 $pUsers[$pSession]['time0'] = $_time; 163 $pUsers[$pSession]['time1'] = 0; 206 164 $pUsers[$pSession]['attempt'] = 0; 207 165 } … … 224 182 } 225 183 226 function readSocket(&$pUsers, $pSession) 227 { 184 //function readSocket(&$pUsers, $pSession) 185 function readSocket($pSession) 186 { 187 global $users; 228 188 global $send; 229 189 $sessionpath = explode(';', session_save_path()); … … 244 204 if ( $is_user ) 245 205 { 246 $ pUsers[$pSession]['time'] = $_SESSION['phpgw_info']['instant_messenger']['time'];247 $readSocket = @$pUsers[$pSession]['jabber']->readSocket();206 $users[$pSession]['time0'] = $_SESSION['phpgw_info']['instant_messenger']['time']; 207 $readSocket = $users[$pSession]['jabber']->readSocket(); 248 208 249 209 if ( $readSocket !== false ) … … 261 221 if ( !is_null($value) ) 262 222 { 263 $ pUsers[$pSession]['jabber']->writeSocket($value);223 $users[$pSession]['jabber']->writeSocket($value); 264 224 $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] = NULL; 265 225 } … … 271 231 foreach ( $value as $key => $val ) 272 232 { 273 $ pUsers[$pSession]['jabber']->getVcard($val);233 $users[$pSession]['jabber']->getVcard($val); 274 234 unset($_SESSION['phpgw_info']['instant_messenger']['socket']['out']['vcard'][$key]); 275 235 } … … 278 238 else 279 239 { 280 if ( method_exists($ pUsers[$pSession]['jabber'], $action) )240 if ( method_exists($users[$pSession]['jabber'], $action) ) 281 241 if ( $value ) 282 $ pUsers[$pSession]['jabber']->$action($value);242 $users[$pSession]['jabber']->$action($value); 283 243 else 284 $ pUsers[$pSession]['jabber']->$action();244 $users[$pSession]['jabber']->$action(); 285 245 unset($_SESSION['phpgw_info']['instant_messenger']['socket']['out'][$action]); 286 246 }
Note: See TracChangeset
for help on using the changeset viewer.