MasterVitronic / fusionpbx

Automatically exported from code.google.com/p/fusionpbx
0 stars 0 forks source link

SIP Registrations Page fails with carrots in the Agent string #303

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Register a device with an Agent string containing '<' or '>'
2.
3.

What is the expected output? What do you see instead?
I expect to see all devices which are registered. I get text that states 
"String could not be parsed as XML".

What version of the product are you using? On what operating system?
FusionPBX 3.1.1
FreeSWITCH 1.3.0+git~20120828T181731Z~227ed3036e
CentOS 6.3 64bit

Please provide any additional information below.
Below is the device that triggers the event in my installation.

Call-ID:        qZ8jV0-3bI1pCDtN2@2792.abc.com
User:           180@2792.abc.com
Contact:        PI FAX <sip:180@192.168.1.100:5060>
Agent:          Patton Smartlink 4020 <3.01.002 20 EN n0 (1214)><00a0ba017198>
Status:         Registered(UDP)(unknown) EXP(2012-08-28 17:49:28) EXPSECS(3581)
Host:           freeswitch.abc.com
IP:             192.168.1.100
Port:           5060
Auth-User:      180
Auth-Realm:     2792.abc.com
MWI-Account:    180@2792.abc.com

Original issue reported on code.google.com by gilbert....@gmail.com on 29 Aug 2012 at 12:11

GoogleCodeExporter commented 9 years ago
I forgot to note that the URL that is having the issue is: 
http://freeswitch.abc.com/app/registrations/v_status_registrations.php?show_reg=
1&profile=internal

Original comment by gilbert....@gmail.com on 29 Aug 2012 at 12:13

GoogleCodeExporter commented 9 years ago
I added the following code after line 72 of v_status_registrations.php to 
temporarily fix my issue...

$xml_response = str_replace("Patton Smartlink 4020 <3.01.002 20 EN n0 
(1214)><00a0ba017198>", "Patton Smartlink 4020", $xml_response);

Unfortunately, I am not a PHP developer and do not know how to manipulate the 
string in xml_response for other possible agents that may have '<' or '>' 
without ruining the xml. I am quick enough though to do the basic modification 
I made. If someone would like to help me, I would be happy to work with them 
and knock this out.

Original comment by gilbert....@gmail.com on 29 Aug 2012 at 11:01

GoogleCodeExporter commented 9 years ago
^ is a carrot.
< is a less than sign.
> is a greater than sign.

To show the symbols correctly I added 'htmlentities'
echo "  <td 
class='".$row_style[$c]."'> ".htmlentities($row['agent'])." </td>\n";

Please test to confirm this is fixed.

Original comment by markjcrane@gmail.com on 30 Aug 2012 at 12:42

GoogleCodeExporter commented 9 years ago
Sorry about the delayed response. I understand that I made a mistake in my 
statement by labeling it carrot.

I tried adding your supplied line and it still failed with the same error (I 
replaced line 165).

If I replace line 165 with the line below it still throws the error (ie. the 
error is above the line modified)
echo "       <td></td>\n";

I believe that it is failing at line 74.
$xml = new SimpleXMLElement($xml_response);
I think SimpleXMLElement is interpreting the information bracketed by the <> as 
xml tags. Since there are no identical tags with leading forward slashes, it is 
having issues. This is conjecture and I am not sure 100%.

Original comment by gilbert....@gmail.com on 31 Aug 2012 at 6:13

GoogleCodeExporter commented 9 years ago
This is a FreeSWITCH bug. A request is made to get the registration info as 
XML. FreeSWITCH should escape the special characters the < and > and that is 
not being done.

There are two commands in FreeSWITCH that can get registration information.
show registrations as xml

Try this one and report back if the characters still show up as < and > in the 
agent string or if they are escaped.

Original comment by markjcrane@gmail.com on 31 Aug 2012 at 6:28

GoogleCodeExporter commented 9 years ago
Here is my solution... It is a little dirty since I am not a coder... I 
inserted this after line 72, "$xml_response = str_replace("</profile-info>", 
"</profile_info>", $xml_response);"

            // Initialize variables to clean agent string
            $agentstring0 = $xml_response;
            $agentstring1 = '';
            $xml_response = '';
            // Find first position of the word <agent>
            $y = strpos($agentstring0, '<agent>');
            // Run loop until the word <agent> is no longer found
            while( $y != 0 ) {
                // Increment position by 7, the length of the word <agent>
                $y = $y + 7;
                // Capture everthing following the word <agent> and store it in $agentstring1
                $agentstring1 = substr($agentstring0, $y);
                // Add all text prior to the word <agent> to the xml_response
                $xml_response = $xml_response . substr($agentstring0, 0, $y);
                // Find the position of the word </agent>
                $y = strpos($agentstring1, '</agent>');
                if ( $y != 0 ) {
                    // Capture everthing following the word </agent> and store it in $agentstring0
                    $agentstring0 = substr($agentstring1, $y);
                    // Cleanup text between agent tags and add it to the xml_response
                    $xml_response = $xml_response . htmlentities(substr($agentstring1, 0, $y));
                    // Find the next occurance of the word <agent>
                    $y = strpos($agentstring0, '<agent>');
                    // If the last agent tag was found, append everything that followed </agent> to the xml_response
                    if ( $y == 0 ) {
                        $xml_response = $xml_response . $agentstring0;
                    }
                }
                else {
                    // Error, there is no closing XML tag
                    exit;
                }
            }

Original comment by gilbert....@gmail.com on 31 Aug 2012 at 10:37

GoogleCodeExporter commented 9 years ago
The comment "// Capture everthing following the word </agent> and store it in 
$agentstring0" should read "// Capture everthing following and including the 
word </agent> and store it in $agentstring0"

Original comment by gilbert....@gmail.com on 31 Aug 2012 at 10:39

GoogleCodeExporter commented 9 years ago
Also, I believe my patch requires php 5.3+.

Original comment by gilbert....@gmail.com on 31 Aug 2012 at 10:41

GoogleCodeExporter commented 9 years ago
Mark,
You are correct that it is not encoding the characters properly. Running "sofia 
xmlstatus profile internal reg" returns the following for the agent in 
question...

<agent>Patton Smartlink 4020 <3.01.002 20 EN n0 (1214)><00a0ba017198></agent> 
and not returning < or >. My code above though fixes that but will probably 
break things if Freeswitch changes their behavior.

Original comment by gilbert....@gmail.com on 1 Sep 2012 at 12:04

GoogleCodeExporter commented 9 years ago
The appropriate place to fix this is in FreeSWITCH. Please report this to 
FreeSWITCH dev team by adding a JIRA ticket.

Original comment by markjcrane@gmail.com on 3 Sep 2012 at 9:35

GoogleCodeExporter commented 9 years ago
This has been fixed by freeswitch.

http://jira.freeswitch.org/browse/FS-3971

I have tested the freeswitch patch as well as tested the latest git and the 
issue is resolved.

output from "sofia xmlstatus profile internal reg" now returns the following:

<agent>Patton Smartlink 4020 <3.01.002 20 EN n0 (1214)><00a0ba017198></agent>

Original comment by gilbert....@gmail.com on 4 Sep 2012 at 6:14

GoogleCodeExporter commented 9 years ago
Thanks for reporting the issue to FreeSWITCH and then reporting back that it is 
fixed.

Original comment by markjcrane@gmail.com on 7 Sep 2012 at 6:18