From 026145159210da2056b0bee191bfa54080b590d6 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Fri, 12 Dec 2008 10:16:06 +0000 Subject: FreeSWITCH package event_socket no longer requires the LAN interface IP. Clearing away a problem of using the FreeSWITCH package on an Appliance with a single interface. --- packages/freeswitch/freeswitch.inc | 64 +++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 22 deletions(-) (limited to 'packages/freeswitch/freeswitch.inc') diff --git a/packages/freeswitch/freeswitch.inc b/packages/freeswitch/freeswitch.inc index 02360120..195bfb11 100644 --- a/packages/freeswitch/freeswitch.inc +++ b/packages/freeswitch/freeswitch.inc @@ -74,25 +74,45 @@ function pkg_is_service_running($servicename) function event_socket_create($host, $port, $password) { - $fp = fsockopen($host, $port, $errno, $errdesc) - or die("Connection to $host failed"); - socket_set_blocking($fp,false); - - if ($fp) { - while (!feof($fp)) { - $buffer = fgets($fp, 1024); - usleep(100); //allow time for reponse - if (trim($buffer) == "Content-Type: auth/request") { - fputs($fp, "auth $password\n\n"); - break; - } - } - return $fp; - } - else { - return false; - } -} + //$host has been deprecated + + //build the interface list + $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN'); + for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) { + $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; + } + + //get the interface ip addresses and try to connect to them + foreach ($ifdescrs as $ifdescr => $ifname){ + $ifinfo = get_interface_info($ifdescr); + $interface_ip_address = $ifinfo['ipaddr']; + + if (strlen($interface_ip_address) > 0) { + + $fp = fsockopen($interface_ip_address, $port, $errno, $errdesc, 1); + socket_set_blocking($fp,false); + + if (!$fp) { + //connection failed continue through the loop testing other addresses + //invalid handle + } + else { + //connected to the socket return the handle + + while (!feof($fp)) { + $buffer = fgets($fp, 1024); + usleep(100); //allow time for reponse + if (trim($buffer) == "Content-Type: auth/request") { + fputs($fp, "auth $password\n\n"); + break; + } + } + return $fp; + } + + } //end if interface_ip_address + } //end foreach +} //end function function event_socket_request($fp, $cmd) @@ -286,7 +306,7 @@ function sync_package_freeswitch_settings() $fout = fopen("/usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml","w"); $tmpxml = "\n"; $tmpxml .= " \n"; - $tmpxml .= " \n"; + $tmpxml .= " \n"; $tmpxml .= " \n"; $tmpxml .= " \n"; $tmpxml .= " \n"; @@ -378,7 +398,7 @@ function sync_package_freeswitch_extensions() foreach($config['installedpackages']['freeswitchextensions']['config'] as $rowhelper) { - $fout = fopen("/usr/local/freeswitch/conf/directory/default/".$rowhelper['extension'].".xml","w"); + $fout = fopen("/usr/local/freeswitch/conf/directory/default/".$rowhelper['extension'].".xml","w"); $tmpxml = "\n"; $tmpxml .= " \n"; @@ -1911,7 +1931,7 @@ function freeswitch_php_install_command() } $config['installedpackages']['freeswitchsettings']['config'][0]['freeswitch_version'] = "1.0.1 revision 10638."; - $config['installedpackages']['freeswitchsettings']['config'][0]['freeswitch_package_version'] = "0.4.2"; + $config['installedpackages']['freeswitchsettings']['config'][0]['freeswitch_package_version'] = "0.4.3"; conf_mount_ro(); -- cgit v1.2.3