From f699cff2bf432235372d0bbbaab9ff0813321cbd Mon Sep 17 00:00:00 2001 From: inextrix Date: Sat, 19 Aug 2023 16:41:23 +0530 Subject: [PATCH 1/3] [IMP]NATing issue with external profile --- .../astpp/application/libraries/astpp/common.php | 6 ++++-- .../modules/freeswitch/controllers/freeswitch.php | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/web_interface/astpp/application/libraries/astpp/common.php b/web_interface/astpp/application/libraries/astpp/common.php index e672ead8d..e23180eea 100755 --- a/web_interface/astpp/application/libraries/astpp/common.php +++ b/web_interface/astpp/application/libraries/astpp/common.php @@ -2015,10 +2015,12 @@ function get_timezone_offset() { } return $gmtoffset; } - function sip_profile_date() { - $defualt_profile_data = '{"rtp-ip":"$${local_ip_v4}","dialplan":"XML","user-agent-string":"ASTPP","debug":"0","sip-trace":"no","tls":"false","inbound-reg-force-matching-username":"true","disable-transcoding":"true","all-reg-options-ping":"false","unregister-on-options-fail":"true","log-auth-failures":"true","status":"0","inbound-bypass-media":"false","inbound-proxy-media":"false","disable-transfer":"true","enable-100rel":"false","rtp-timeout-sec":"60","dtmf-duration":"2000","manual-redirect":"false","aggressive-nat-detection":"false","enable-timer":"false","minimum-session-expires":"120","session-timeout-pt":"1800","auth-calls":"true","apply-inbound-acl":"default","inbound-codec-prefs":"PCMU,PCMA,G729","outbound-codec-prefs":"PCMU,PCMA,G729","inbound-late-negotiation":"false"}'; + // ASTPPCOM-1321 Ashish start + function sip_profile_date($sipprofile_name) { + $defualt_profile_data = '{"rtp-ip":"$${local_ip_v4}","dialplan":"XML","user-agent-string":"ASTPP","debug":"0","sip-trace":"no","tls":"false","inbound-reg-force-matching-username":"true","disable-transcoding":"true","all-reg-options-ping":"false","unregister-on-options-fail":"true","log-auth-failures":"true","status":"0","inbound-bypass-media":"false","inbound-proxy-media":"false","disable-transfer":"true","enable-100rel":"false","rtp-timeout-sec":"60","dtmf-duration":"2000","manual-redirect":"false","aggressive-nat-detection":"true","enable-timer":"false","minimum-session-expires":"120","session-timeout-pt":"1800","auth-calls":"true","apply-inbound-acl":"'.$sipprofile_name.'","inbound-codec-prefs":"PCMU,PCMA,G729","outbound-codec-prefs":"PCMU,PCMA,G729","inbound-late-negotiation":"false","ext-rtp-ip":"$${local_ip_v4}","ext-sip-ip":"$${local_ip_v4}","sip-capture":"no","rtp-timer-name":"soft","rtp-hold-timeout-sec":"1800","rfc2833-pt":"101","presence-privacy":"$${presence_privacy}","presence-hosts":"$${domain},$${local_ip_v4}","pass-callee-id":"false","nonce-ttl":"60","manage-presence":"true","inbound-codec-negotiation":"generous","hold-music":"$${hold_music}","forward-unsolicited-mwi-notify":"false","dtmf_type":"rfc2833","context":"default","challenge-realm":"auto_from","auth-all-packets":"false"}'; return $defualt_profile_data; } + // ASTPPCOM-1321 Ashish end function set_refill_coupon_status($select = '', $table = '', $status = '') { $refill_coupon_array = array ( "" => gettext ( "--Select--" ), diff --git a/web_interface/astpp/application/modules/freeswitch/controllers/freeswitch.php b/web_interface/astpp/application/modules/freeswitch/controllers/freeswitch.php index 8b34606ac..b8ddf110b 100755 --- a/web_interface/astpp/application/modules/freeswitch/controllers/freeswitch.php +++ b/web_interface/astpp/application/modules/freeswitch/controllers/freeswitch.php @@ -1119,7 +1119,9 @@ function fssipprofile_add($add = '') $sipprofile_data['created_date'] = gmdate('Y-m-d H:i:s'); - $sipprofile_data['profile_data'] = $this->common->sip_profile_date(); + // ASTPPCOM-1321 Ashish start + $sipprofile_data['profile_data'] = $this->common->sip_profile_date($sipprofile_data['name']); + // ASTPPCOM-1321 Ashish end $sipprofile_data['name'] = trim($sipprofile_data['name']); $insert = $this->db->insert("sip_profiles", $sipprofile_data); @@ -1152,9 +1154,20 @@ function fssipprofile_add($add = '') unset($sipprofile_data['action']); unset($sipprofile_data['sipstatus']); $insert_arr = $sipprofile_data; + // ASTPPCOM-1321 Ashish start + $where_data = array( + 'id' => $sipprofile_data['id'] + ); + $sip_data = $this->db_model->getSelect("*", "sip_profiles", $where_data)->result_array(); + $final_sip_data = (array) json_decode($sip_data[0]['profile_data']); + // ASTPPCOM-1321 Ashish end if ($check_authentication->num_rows() == 0) { $insert_arr['last_modified_date'] = gmdate("Y-m-d H:i:s"); $insert_arr['name'] = trim($insert_arr['name']); + // ASTPPCOM-1321 Ashish start + $final_sip_data['apply-inbound-acl'] = $insert_arr['name']; + $insert_arr['profile_data'] = json_encode($final_sip_data); + // ASTPPCOM-1321 Ashish end $update = $this->db->update("sip_profiles", $insert_arr, array( 'id' => $sipprofile_data['id'] )); From 255058e4ccf4c183e97eb0809885209aa6648cdc Mon Sep 17 00:00:00 2001 From: inextrix Date: Tue, 22 Aug 2023 12:22:55 +0530 Subject: [PATCH 2/3] [IMP]NATing issue with external profile --- freeswitch/fs/lib/astpp.xml.php | 114 +++++++++++++++++++------------- 1 file changed, 69 insertions(+), 45 deletions(-) diff --git a/freeswitch/fs/lib/astpp.xml.php b/freeswitch/fs/lib/astpp.xml.php index 1ac4fad7c..f3e746b35 100755 --- a/freeswitch/fs/lib/astpp.xml.php +++ b/freeswitch/fs/lib/astpp.xml.php @@ -36,55 +36,82 @@ function xml_not_found() { } // Build acl xml +// ASTPPCOM-1321 Ashish start function load_acl($logger, $db, $config) { $xml = "\n"; $xml .= "\n"; $xml .= "
\n"; $xml .= " \n"; $xml .= " \n"; - $xml .= " \n"; - - // For customer and provider ips - $query = "SELECT ip FROM ip_map,accounts WHERE ip_map.accountid=accounts.id AND ip_map.status=0 AND accounts.status=0 AND accounts.deleted=0"; - $logger->log ( "ACL Query : " . $query ); - $res_acl = $db->run ( $query ); - $logger->log ( $res_acl ); - - foreach ( $res_acl as $res_acl_key => $res_acl_value ) { - if(preg_match("/[a-zA-Z\-]/i", $res_acl_value ['ip'])){ - $ips = gethostbynamel($res_acl_value ['ip']); - foreach ($ips as $ip => $value){ - $res_acl_value ['ip'] = $value . "/32"; - } - } - $xml .= " \n"; - } - - // For gateways -/* $query = "SELECT * FROM gateways WHERE status=0"; - $logger->log ( "Sofia Gateway Query : " . $query ); - $sp_gw = $db->run ( $query ); - $logger->log ( $sp_gw ); - - foreach ( $sp_gw as $sp_gw_key => $sp_gw_value ) { - - $sp_gw_settings = json_decode ( $sp_gw_value ['gateway_data'], true ); - foreach ( $sp_gw_settings as $sp_gw_settings_key => $sp_gw_settings_value ) { - if ($sp_gw_settings_value != "" && $sp_gw_settings_key == "proxy") { - $tmp_ip_arr = explode ( ":", $sp_gw_settings_value ); - if (filter_var($tmp_ip_arr [0], FILTER_VALIDATE_IP) || preg_match("/^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/", $tmp_ip_arr [0])) { - if(preg_match("/[a-zA-Z\-]/i", $tmp_ip_arr [0])){ - $ips = gethostbynamel($tmp_ip_arr [0]); - foreach ($ips as $ip => $value){ - $tmp_ip_arr [0] = $value; - } - } - $xml .= " \n"; + $sp_query = "select id,profile_data from sip_profiles;"; + $logger->log("sp Query : " . $sp_query); + $sp_result = $db->run($sp_query); + $logger->log($sp_query); + $logger->log("SIP_PROFILE RESULT count::" . count($sp_result) . "::::::::::::::::::::::::::"); + if (!empty($sp_result)) { + $apply_inbound_acl = array(); + foreach ($sp_result as $sp_value) { + $logger->log("SIP_PROFILE ID::" . $sp_value['id'] . "::::::::::::::::::::::::::"); + $sp_value_decode = json_decode($sp_value['profile_data'], true); + $logger->log("apply-inbound-acl::" . $sp_value_decode['apply-inbound-acl']); + if (isset($sp_value_decode['apply-inbound-acl']) && $sp_value_decode['apply-inbound-acl'] != "" && !in_array($sp_value_decode['apply-inbound-acl'], $apply_inbound_acl)) { + $apply_inbound_acl[] = $sp_value_decode['apply-inbound-acl']; + $xml .= " \n"; + $query = "select freeswitch_host,freeswitch_pubip from freeswich_servers;"; + $logger->log("freeswich_servers Query : " . $query); + $res_acl = $db->run($query); + $logger->log($res_acl); + $ip = ''; + foreach ($res_acl as $res_acl_key => $res_acl_value) { + if ($res_acl_value['freeswitch_pubip'] == '' && empty($res_acl_value['freeswitch_pubip'])) { + $ip = $res_acl_value['freeswitch_host']; + } else { + $ip = $res_acl_value['freeswitch_pubip']; + } + if ($ip) { + $ips = gethostbynamel($ip); + foreach ($ips as $freeswitch_pubip => $value) { + $ip = $value . "/32"; + } + } + $xml .= " \n"; + } + // For customer and provider ips + $query = "SELECT ip FROM ip_map,accounts WHERE ip_map.accountid=accounts.id AND ip_map.status=0 AND accounts.status=0 AND accounts.deleted=0 "; + $logger->log("ip_map Query : " . $query); + $res_acl = $db->run($query); + $logger->log($res_acl); + foreach ($res_acl as $res_acl_key => $res_acl_value) { + if (preg_match("/[a-zA-Z\-]/i", $res_acl_value['ip'])) { + $ips = gethostbynamel($res_acl_value['ip']); + foreach ($ips as $ip => $value) { + $res_acl_value['ip'] = $value . "/32"; + } + } + $xml .= " \n"; + } + $logger->log("opensips_domain HHHH : " . $config['opensips_domain']); + // For opensips + if ($config['opensips'] == '0') { + $logger->log("opensips_domain HHHH : " . $config['opensips_domain']); + if (preg_match("/[a-zA-Z\-]/i", $config['opensips_domain'])) { + $logger->log("opensips_domain HHHH : " . $config['opensips_domain']); + + $ips = gethostbynamel($config['opensips_domain']); + foreach ($ips as $ip => $value) { + $config['opensips_domain'] = $value; + } + } + $xml .= " \n"; + $xml .= " \n"; + } else { + $xml .= " \n"; } } } - }*/ - + $logger->log("HP xml : " . $xml); + } + // For opensips if ($config ['opensips'] == '0') { if(preg_match("/[a-zA-Z\-]/i", $config ['opensips_domain'])){ @@ -94,7 +121,6 @@ function load_acl($logger, $db, $config) { } } $xml .= "\n"; - $xml .= " \n"; // For loopback $xml .= "\n"; $xml .= "\n"; @@ -104,13 +130,10 @@ function load_acl($logger, $db, $config) { $xml .= "\n"; } else{ - $xml .= " \n"; // For event handing $xml .= "\n"; } - - $xml .= "\n"; - $xml .= "\n"; + $xml .= " \n"; $xml .= " \n"; $xml .= " \n"; $xml .= "
\n"; @@ -118,6 +141,7 @@ function load_acl($logger, $db, $config) { $logger->log ( $xml ); return $xml; } +// ASTPPCOM-1321 Ashish end // Build sofia xml function load_sofia($logger, $db, $config) { From 0c81abc86e4a1fbe2ed9aa5d66311ae11e27baf8 Mon Sep 17 00:00:00 2001 From: inextrix Date: Tue, 22 Aug 2023 13:43:31 +0530 Subject: [PATCH 3/3] [IMP]NATing issue with external profile --- freeswitch/fs/lib/astpp.xml.php | 103 +++--------------- .../application/libraries/astpp/common.php | 8 +- .../freeswitch/controllers/freeswitch.php | 15 +-- 3 files changed, 21 insertions(+), 105 deletions(-) diff --git a/freeswitch/fs/lib/astpp.xml.php b/freeswitch/fs/lib/astpp.xml.php index f3e746b35..49f78cb11 100755 --- a/freeswitch/fs/lib/astpp.xml.php +++ b/freeswitch/fs/lib/astpp.xml.php @@ -43,97 +43,26 @@ function load_acl($logger, $db, $config) { $xml .= "
\n"; $xml .= " \n"; $xml .= " \n"; - $sp_query = "select id,profile_data from sip_profiles;"; - $logger->log("sp Query : " . $sp_query); - $sp_result = $db->run($sp_query); - $logger->log($sp_query); - $logger->log("SIP_PROFILE RESULT count::" . count($sp_result) . "::::::::::::::::::::::::::"); - if (!empty($sp_result)) { - $apply_inbound_acl = array(); - foreach ($sp_result as $sp_value) { - $logger->log("SIP_PROFILE ID::" . $sp_value['id'] . "::::::::::::::::::::::::::"); - $sp_value_decode = json_decode($sp_value['profile_data'], true); - $logger->log("apply-inbound-acl::" . $sp_value_decode['apply-inbound-acl']); - if (isset($sp_value_decode['apply-inbound-acl']) && $sp_value_decode['apply-inbound-acl'] != "" && !in_array($sp_value_decode['apply-inbound-acl'], $apply_inbound_acl)) { - $apply_inbound_acl[] = $sp_value_decode['apply-inbound-acl']; - $xml .= " \n"; - $query = "select freeswitch_host,freeswitch_pubip from freeswich_servers;"; - $logger->log("freeswich_servers Query : " . $query); - $res_acl = $db->run($query); - $logger->log($res_acl); - $ip = ''; - foreach ($res_acl as $res_acl_key => $res_acl_value) { - if ($res_acl_value['freeswitch_pubip'] == '' && empty($res_acl_value['freeswitch_pubip'])) { - $ip = $res_acl_value['freeswitch_host']; - } else { - $ip = $res_acl_value['freeswitch_pubip']; - } - if ($ip) { - $ips = gethostbynamel($ip); - foreach ($ips as $freeswitch_pubip => $value) { - $ip = $value . "/32"; - } - } - $xml .= " \n"; - } - // For customer and provider ips - $query = "SELECT ip FROM ip_map,accounts WHERE ip_map.accountid=accounts.id AND ip_map.status=0 AND accounts.status=0 AND accounts.deleted=0 "; - $logger->log("ip_map Query : " . $query); - $res_acl = $db->run($query); - $logger->log($res_acl); - foreach ($res_acl as $res_acl_key => $res_acl_value) { - if (preg_match("/[a-zA-Z\-]/i", $res_acl_value['ip'])) { - $ips = gethostbynamel($res_acl_value['ip']); - foreach ($ips as $ip => $value) { - $res_acl_value['ip'] = $value . "/32"; - } - } - $xml .= " \n"; - } - $logger->log("opensips_domain HHHH : " . $config['opensips_domain']); - // For opensips - if ($config['opensips'] == '0') { - $logger->log("opensips_domain HHHH : " . $config['opensips_domain']); - if (preg_match("/[a-zA-Z\-]/i", $config['opensips_domain'])) { - $logger->log("opensips_domain HHHH : " . $config['opensips_domain']); - - $ips = gethostbynamel($config['opensips_domain']); - foreach ($ips as $ip => $value) { - $config['opensips_domain'] = $value; - } - } - $xml .= " \n"; - $xml .= " \n"; - } else { - $xml .= " \n"; - } - } - } - $logger->log("HP xml : " . $xml); - } + $xml .= " \n"; + + // For customer and provider ips + $query = "SELECT ip FROM ip_map,accounts WHERE ip_map.accountid=accounts.id AND ip_map.status=0 AND accounts.status=0 AND accounts.deleted=0"; + $logger->log ( "ACL Query : " . $query ); + $res_acl = $db->run ( $query ); + $logger->log ( $res_acl ); - // For opensips - if ($config ['opensips'] == '0') { - if(preg_match("/[a-zA-Z\-]/i", $config ['opensips_domain'])){ - $ips = gethostbynamel($config ['opensips_domain']); - foreach ($ips as $ip => $value){ - $config ['opensips_domain'] = $value; + foreach ( $res_acl as $res_acl_key => $res_acl_value ) { + if(preg_match("/[a-zA-Z\-]/i", $res_acl_value ['ip'])){ + $ips = gethostbynamel($res_acl_value ['ip']); + foreach ($ips as $ip => $value){ + $res_acl_value ['ip'] = $value . "/32"; } } - $xml .= "\n"; - // For loopback - $xml .= "\n"; - $xml .= "\n"; - $xml .= "\n"; - // For event handing - $xml .= "\n"; - $xml .= "\n"; + $xml .= " \n"; } - else{ - // For event handing - $xml .= "\n"; - } - $xml .= " \n"; + + $xml .= "\n"; + $xml .= "\n"; $xml .= " \n"; $xml .= " \n"; $xml .= "
\n"; diff --git a/web_interface/astpp/application/libraries/astpp/common.php b/web_interface/astpp/application/libraries/astpp/common.php index e23180eea..d22114c88 100755 --- a/web_interface/astpp/application/libraries/astpp/common.php +++ b/web_interface/astpp/application/libraries/astpp/common.php @@ -2015,12 +2015,12 @@ function get_timezone_offset() { } return $gmtoffset; } - // ASTPPCOM-1321 Ashish start - function sip_profile_date($sipprofile_name) { - $defualt_profile_data = '{"rtp-ip":"$${local_ip_v4}","dialplan":"XML","user-agent-string":"ASTPP","debug":"0","sip-trace":"no","tls":"false","inbound-reg-force-matching-username":"true","disable-transcoding":"true","all-reg-options-ping":"false","unregister-on-options-fail":"true","log-auth-failures":"true","status":"0","inbound-bypass-media":"false","inbound-proxy-media":"false","disable-transfer":"true","enable-100rel":"false","rtp-timeout-sec":"60","dtmf-duration":"2000","manual-redirect":"false","aggressive-nat-detection":"true","enable-timer":"false","minimum-session-expires":"120","session-timeout-pt":"1800","auth-calls":"true","apply-inbound-acl":"'.$sipprofile_name.'","inbound-codec-prefs":"PCMU,PCMA,G729","outbound-codec-prefs":"PCMU,PCMA,G729","inbound-late-negotiation":"false","ext-rtp-ip":"$${local_ip_v4}","ext-sip-ip":"$${local_ip_v4}","sip-capture":"no","rtp-timer-name":"soft","rtp-hold-timeout-sec":"1800","rfc2833-pt":"101","presence-privacy":"$${presence_privacy}","presence-hosts":"$${domain},$${local_ip_v4}","pass-callee-id":"false","nonce-ttl":"60","manage-presence":"true","inbound-codec-negotiation":"generous","hold-music":"$${hold_music}","forward-unsolicited-mwi-notify":"false","dtmf_type":"rfc2833","context":"default","challenge-realm":"auto_from","auth-all-packets":"false"}'; + function sip_profile_date() { + // ASTPPCOM-1321 Ashish start + $defualt_profile_data = '{"rtp-ip":"$${local_ip_v4}","dialplan":"XML","user-agent-string":"ASTPP","debug":"0","sip-trace":"no","tls":"false","inbound-reg-force-matching-username":"true","disable-transcoding":"true","all-reg-options-ping":"false","unregister-on-options-fail":"true","log-auth-failures":"true","status":"0","inbound-bypass-media":"false","inbound-proxy-media":"false","disable-transfer":"true","enable-100rel":"false","rtp-timeout-sec":"60","dtmf-duration":"2000","manual-redirect":"false","aggressive-nat-detection":"true","enable-timer":"false","minimum-session-expires":"120","session-timeout-pt":"1800","auth-calls":"true","apply-inbound-acl":"default","inbound-codec-prefs":"PCMU,PCMA,G729","outbound-codec-prefs":"PCMU,PCMA,G729","inbound-late-negotiation":"false","ext-rtp-ip":"$${local_ip_v4}","ext-sip-ip":"$${local_ip_v4}","sip-capture":"no","rtp-timer-name":"soft","rtp-hold-timeout-sec":"1800","rfc2833-pt":"101","presence-privacy":"$${presence_privacy}","presence-hosts":"$${domain},$${local_ip_v4}","pass-callee-id":"false","nonce-ttl":"60","manage-presence":"true","inbound-codec-negotiation":"generous","hold-music":"$${hold_music}","forward-unsolicited-mwi-notify":"false","dtmf_type":"rfc2833","context":"default","challenge-realm":"auto_from","auth-all-packets":"false"}'; + // ASTPPCOM-1321 Ashish end return $defualt_profile_data; } - // ASTPPCOM-1321 Ashish end function set_refill_coupon_status($select = '', $table = '', $status = '') { $refill_coupon_array = array ( "" => gettext ( "--Select--" ), diff --git a/web_interface/astpp/application/modules/freeswitch/controllers/freeswitch.php b/web_interface/astpp/application/modules/freeswitch/controllers/freeswitch.php index b8ddf110b..8b34606ac 100755 --- a/web_interface/astpp/application/modules/freeswitch/controllers/freeswitch.php +++ b/web_interface/astpp/application/modules/freeswitch/controllers/freeswitch.php @@ -1119,9 +1119,7 @@ function fssipprofile_add($add = '') $sipprofile_data['created_date'] = gmdate('Y-m-d H:i:s'); - // ASTPPCOM-1321 Ashish start - $sipprofile_data['profile_data'] = $this->common->sip_profile_date($sipprofile_data['name']); - // ASTPPCOM-1321 Ashish end + $sipprofile_data['profile_data'] = $this->common->sip_profile_date(); $sipprofile_data['name'] = trim($sipprofile_data['name']); $insert = $this->db->insert("sip_profiles", $sipprofile_data); @@ -1154,20 +1152,9 @@ function fssipprofile_add($add = '') unset($sipprofile_data['action']); unset($sipprofile_data['sipstatus']); $insert_arr = $sipprofile_data; - // ASTPPCOM-1321 Ashish start - $where_data = array( - 'id' => $sipprofile_data['id'] - ); - $sip_data = $this->db_model->getSelect("*", "sip_profiles", $where_data)->result_array(); - $final_sip_data = (array) json_decode($sip_data[0]['profile_data']); - // ASTPPCOM-1321 Ashish end if ($check_authentication->num_rows() == 0) { $insert_arr['last_modified_date'] = gmdate("Y-m-d H:i:s"); $insert_arr['name'] = trim($insert_arr['name']); - // ASTPPCOM-1321 Ashish start - $final_sip_data['apply-inbound-acl'] = $insert_arr['name']; - $insert_arr['profile_data'] = json_encode($final_sip_data); - // ASTPPCOM-1321 Ashish end $update = $this->db->update("sip_profiles", $insert_arr, array( 'id' => $sipprofile_data['id'] ));