Koozali.org: home of the SME Server

Obsolete Releases => SME VoIP (Asterisk, SAIL etc) => Topic started by: compsos on October 10, 2011, 11:18:58 AM

Title: Generating new Phone configuration files
Post by: compsos on October 10, 2011, 11:18:58 AM
Sail 3.1.0-128
Asterisk 1.8.6
SME ver 8.6B7

Problem: Building new ext configuration files creates a file with the file name as the 1st line
Code: [Select]
["SEPe8b74815f73f.cfg"
Modify the code and reapply "commit" the file does not change. Edit the file from the console and remove first line and then just re-Commit, the file does not change. Delete the file and re-Commit and the 1st line with the file name is back.

It would seem to be 2 errors
   [li]the configuration file once written is does not edit from the Sail screen. Permissions are [/li][/list]
Code: [Select]
-rw-rw-rw- 1 root root 2108 Oct 10 18:49 SEPe8b74815f73f.cfgAnyone seen this issue? Looking at the tftpSQL.php file if we can not write to the file it should "die" but the Sail screen is reporting correct operation "Updates have been Committed"

Workaround for the moment is to create the files as normal and then correct in the console and hope the webpage does not edit on Commit.

Sip definition for Cisco SPA504G
Code: [Select]
["SEP$mac.cfg"
<flat-profile>
<Station_Name ua="na">$ext</Station_Name>
<Display_Name_1_ ua="na">$ext</Display_Name_1_>
<User_ID_1_ ua="na">$ext</User_ID_1_>
<Password_1_ ua="na">$password</Password_1_>
<Resync_Periodic>432000</Resync_Periodic>
<Mailbox_ID_1_ ua="na">$ext</Mailbox_ID_1>
<Application_LED ua="na"></Application_LED>
<Serv_Subscribe_Failed_LED ua="na"></Serv_Subscribe_Failed_LED>
<Serv_Subscribing_LED ua="na"></Serv_Subscribing_LED>
<SNRM_Day_Mode_LED ua="na"></SNRM_Day_Mode_LED>
<SNRM_Night_Mode_LED ua="na"></SNRM_Night_Mode_LED>
<Parking_Lot_Idle_LED ua="na"></Parking_Lot_Idle_LED>
<Parking_Lot_Busy_LED ua="na"></Parking_Lot_Busy_LED>
<BLF_Idle_LED ua="na"></BLF_Idle_LED>
<BLF_Ringing_LED ua="na"></BLF_Ringing_LED>
<BLF_Busy_LED ua="na"></BLF_Busy_LED>
<BLF_Held_LED ua="na"></BLF_Held_LED>
<Unit_1_Key_1 ua="na"></Unit_1_Key_1>
<Unit_1_Key_2 ua="na"></Unit_1_Key_2>
<Unit_1_Key_3 ua="na"></Unit_1_Key_3>
<Unit_1_Key_4 ua="na"></Unit_1_Key_4>
<Unit_1_Key_5 ua="na"></Unit_1_Key_5>
<Unit_1_Key_6 ua="na"></Unit_1_Key_6>
<Unit_1_Key_7 ua="na"></Unit_1_Key_7>
<Unit_1_Key_8 ua="na"></Unit_1_Key_8>
<Unit_1_Key_9 ua="na"></Unit_1_Key_9>
<Unit_1_Key_10 ua="na"></Unit_1_Key_10>
<Unit_1_Key_11 ua="na"></Unit_1_Key_11>
<Unit_1_Key_12 ua="na"></Unit_1_Key_12>
<Unit_1_Key_13 ua="na"></Unit_1_Key_13>
<Unit_1_Key_14 ua="na"></Unit_1_Key_14>
<Unit_1_Key_15 ua="na"></Unit_1_Key_15>
<Unit_1_Key_16 ua="na"></Unit_1_Key_16>
<Unit_1_Key_17 ua="na"></Unit_1_Key_17>
<Unit_1_Key_18 ua="na"></Unit_1_Key_18>
<Unit_1_Key_19 ua="na"></Unit_1_Key_19>
<Unit_1_Key_20 ua="na"></Unit_1_Key_20>
<Unit_1_Key_21 ua="na"></Unit_1_Key_21>
<Unit_1_Key_22 ua="na"></Unit_1_Key_22>
<Unit_1_Key_23 ua="na"></Unit_1_Key_23>
<Unit_1_Key_24 ua="na"></Unit_1_Key_24>
<Unit_1_Key_25 ua="na"></Unit_1_Key_25>
<Unit_1_Key_26 ua="na"></Unit_1_Key_26>
<Unit_1_Key_27 ua="na"></Unit_1_Key_27>
<Unit_1_Key_28 ua="na"></Unit_1_Key_28>
<Unit_1_Key_29 ua="na"></Unit_1_Key_29>
<Unit_1_Key_30 ua="na"></Unit_1_Key_30>
<Unit_1_Key_31 ua="na"></Unit_1_Key_31>
<Unit_1_Key_32 ua="na"></Unit_1_Key_32>
<Unit_2_Key_1 ua="na"></Unit_2_Key_1>
<Unit_2_Key_2 ua="na"></Unit_2_Key_2>
<Unit_2_Key_3 ua="na"></Unit_2_Key_3>
<Unit_2_Key_4 ua="na"></Unit_2_Key_4>
<Unit_2_Key_5 ua="na"></Unit_2_Key_5>
<Unit_2_Key_6 ua="na"></Unit_2_Key_6>
<Unit_2_Key_7 ua="na"></Unit_2_Key_7>
<Unit_2_Key_8 ua="na"></Unit_2_Key_8>
<Unit_2_Key_9 ua="na"></Unit_2_Key_9>
<Unit_2_Key_10 ua="na"></Unit_2_Key_10>
<Unit_2_Key_11 ua="na"></Unit_2_Key_11>
<Unit_2_Key_12 ua="na"></Unit_2_Key_12>
<Unit_2_Key_13 ua="na"></Unit_2_Key_13>
<Unit_2_Key_14 ua="na"></Unit_2_Key_14>
<Unit_2_Key_15 ua="na"></Unit_2_Key_15>
<Unit_2_Key_16 ua="na"></Unit_2_Key_16>
<Unit_2_Key_17 ua="na"></Unit_2_Key_17>
<Unit_2_Key_18 ua="na"></Unit_2_Key_18>
<Unit_2_Key_19 ua="na"></Unit_2_Key_19>
<Unit_2_Key_20 ua="na"></Unit_2_Key_20>
<Unit_2_Key_21 ua="na"></Unit_2_Key_21>
<Unit_2_Key_22 ua="na"></Unit_2_Key_22>
<Unit_2_Key_23 ua="na"></Unit_2_Key_23>
<Unit_2_Key_24 ua="na"></Unit_2_Key_24>
<Unit_2_Key_25 ua="na"></Unit_2_Key_25>
<Unit_2_Key_26 ua="na"></Unit_2_Key_26>
<Unit_2_Key_27 ua="na"></Unit_2_Key_27>
<Unit_2_Key_28 ua="na"></Unit_2_Key_28>
<Unit_2_Key_29 ua="na"></Unit_2_Key_29>
<Unit_2_Key_30 ua="na"></Unit_2_Key_30>
<Unit_2_Key_31 ua="na"></Unit_2_Key_31>
<Unit_2_Key_32 ua="na"></Unit_2_Key_32>
</flat-profile>
]

TIA
Title: Re: Generating new Phone configuration files
Post by: SARK devs on October 21, 2011, 04:29:51 PM
HI Gordon

I just tried this on a test system (admittedly -131, but nothing has changed in this area) and I can't get it to misbehave.    I created a template exactly the same as yours and then used it to make an extension.   In my test, the filename was not reflected in the generated tftp file and I can change both the extension and the template from the sail screen without issues. 

Have I understood or am I missing something?

Best

S

 




Title: Re: Generating new Phone configuration files
Post by: compsos on October 22, 2011, 01:15:17 AM
Hi Jeff
Thank you for the reply. This is a confusing one as it does not happen on all phones on the one system. I have deleted a phone and recreated and all looks good and then later worked on a different phone only to find the original has gone back to being problematic.
Your tests with our code are fine? Could it be the underlying PHP or Perl code? Is the fact that the phones do not appear Network Scan and had to entered manually? What would hinder the automatic discovery of Cisco 504G phones? I did get 1 Lynksys phone on 1 of the systems but then could not define the model. The only choice was General SIP. Can we add the company part of the mac address to the DB for phone recognition?

Sorry for all the questions but the Ciscos seem to only want to play their way or not at all.
Title: Re: Generating new Phone configuration files
Post by: compsos on October 23, 2011, 10:11:50 AM
Hi Jeff
Now got 3 systems doing it. We had an issue a little while back when the first line was blank which upset xml files. Could this be related?

This is the phone section from tftpSQL.php. Is it correct? Thanks

Code: [Select]
//  Phones
//
    $sql = "SELECT * FROM IPphone WHERE location='local' AND macaddr<>'' AND provision<>''";
    foreach ($dbh->query($sql) as $row) {
                $lmacaddr = strtolower($row['macaddr']);
                $umacaddr = strtoupper($row['macaddr']);
                if ( array_key_exists( 'hausecluster', $row ) ) {
                   if ($row['hausecluster'] == "YES") {
                                $row['provision'] = preg_replace ( '/\$localip/',"$haclusterip", $row['provision'] );
                   }
                }
                else {
                                $row['provision'] = preg_replace ( '/\$localip/',"$localip", $row['provision'] );
                }
                $row['provision'] = preg_replace ( '/\$MAC/',"$umacaddr", $row['provision'] );
                $row['provision'] = preg_replace ( '/\$mac/',"$lmacaddr", $row['provision'] );
                $files = split ("\n]",$row['provision']);
                foreach ($files as $thisfile) {
                        $row['provision'] = preg_replace ( '/\n]/',"", $row['provision'] );
                        if (preg_match(' /\["(.*)"/ ',$thisfile,$matches)) {
                                $cfgfilename = "/tftpboot/" . $matches[1];
                                //
                                // remove support for Grandstream and spa 2/3 for initial release
                                //
                                if (preg_match(" /Grandstream/",$row['device'])) {
                                        continue;
                                        if (!file_exists("/usr/local/src/GS_CFG_GEN/bin/encode.sh")) {
                                                continue;
                                        }
                                        $row['provision'] = preg_replace ( ' /\["(.*)"/ ',"", $row['provision'] );
                                        $fh = fopen("/tftpboot/gsconfig", 'w') or die('Could not open file!');
                                        fwrite($fh,$row['provision']) or die('Could not write to file');
                                        fclose($fh);
                                        `/usr/local/src/GS_CFG_GEN/bin/encode.sh $fmacaddr /tftpboot/gsconfig tftpboot/$cfgfilename`;
                                }
                                elseif (preg_match(" /SPA-2/",$row['device'])) {
                                        continue;
                                        if (file_exists ($cfgfilename . 'line1')) {
                                                $row['provision'] = preg_replace ( '/\_x_/','/_2_/', $row['provision'] );
                                                $cfgfilename .= ".line2";
                                        }
                                        else {
                                                $row['provision'] = preg_replace ( '/\_x_/','/_1_/', $row['provision'] );
                                                $cfgfilename .= ".line1";
                                        }
                                        $fh = fopen($cfgfilename, 'w') or die('Could not open file!');
                                        fwrite($fh,$row['provision']) or die('Could not write to file');
                                        fclose($fh);
                                }
                                elseif (preg_match(" /SPA-3/",$row['device'])) {
                                        continue;
                                        $cfgfilename .= ".line";
                                        $fh = fopen($cfgfilename, 'w') or die('Could not open file!');
                                        fwrite($fh,$row['provision']) or die('Could not write to file');
                                        fclose($fh);
                                }
                                else {
                                        $row['provision'] = preg_replace ( ' /\["(.*)"\n/ ',"", $row['provision'] );
                                        $fh = fopen($cfgfilename, 'w') or die('Could not open file!');
                                        fwrite($fh,$row['provision']) or die('Could not write to file');
                                        fclose($fh);
                              }
                        }
                }
        }
/*
Title: Re: Generating new Phone configuration files
Post by: SARK devs on October 23, 2011, 08:03:47 PM
Your code will be the same as ours for the same release (assuming you've made no changes).  This area of code doesn't change much because it doesn't do much. 

To be honest I'm still unclear what the problem is.   

Quote
Problem: Building new ext configuration files creates a file with the file name as the 1st line

Do you mean in the tftpboot generated file?  Can you show me an example?
You also mention the tftfpboot permissions but you don't say what, if any, problem they are causing.
Finally, you comment that files cannot be edited from the sail screen but I find this very confusing because you cannot directly edit a generated file from sail anyway.  You can however, modify the provisioning data in the extensions panel. 

I think we need to start again with the problem definition so that understand what you are telling me and in a way that I can re-create it on my system here.

Kind Regards

S
 





 
Title: Re: Generating new Phone configuration files
Post by: compsos on October 24, 2011, 12:06:28 AM
Hi Jeff

The 1st 2 lines of the phone's file from tftpboot
Code: [Select]
["0004f2179387.cfg"
<?xml version="1.0" standalone="yes"?>
1st lines in Sip definition file from IP devices
Code: [Select]
["$mac.cfg"
[ 0.0.0.4 ]
path = /yealink/config/Setting/autop.cfg

Code: [Select]
["snom-m9-000413303F9A.xml"
<?xml version="1.0" encoding="utf-8"?>
<settings>

Every time we regenerate from sail the files get modified like the sample above. Until it hit my system it was not on every extension so I assumed it may be something in the IP devices definition files. But on this system they have not been changed except for 1 extension that has been replaced. Also the other systems were built from the iso file with sail included. Mine has "evolved" over time through updates.

The only modification to the file came from http://forums.contribs.org/index.php/topic,47658.0.html (http://http//forums.contribs.org/index.php/topic,47658.0.html)
Code: [Select]
$row['provision'] = preg_replace ( ' /\["(.*)"\n/ ',"", $row['provision'] );
Initially saw the issue on Cisco and Lynksys phones but now on all types of phones (Aastra, Polycom, Snom, Cisco and Lynksys). Could we be falling into this code that uses line1 and line2
Code: [Select]
                                        if (file_exists ($cfgfilename . 'line1')) {
                                                $row['provision'] = preg_replace ( '/\_x_/','/_2_/', $row['provision'] );
                                                $cfgfilename .= ".line2";
                                        }
                                        else {
                                                $row['provision'] = preg_replace ( '/\_x_/','/_1_/', $row['provision'] );
                                                $cfgfilename .= ".line1";
                                        }
Will try and set up some debugs in the file to see when it adds the filename to the output.
Thanks for the help.
Title: Re: Generating new Phone configuration files
Post by: compsos on October 24, 2011, 04:23:44 AM
Could this be a CR/LF line feed between windows and Unix?

In the definition screen for provisioning it looks OK but as less the filename in the console it displays like this
Code: [Select]
["SEPc89c1d6e1531.cfg"
<flat-profile>
<Station_Name group="Ext_1/Subscriber_Information"> 4100</Station_Name>
<Display_Name_1_ group="Ext_1/Subscriber_Information"> 4100</Display_Name_1_><User_ID_1_ group="Ext_1/Subscriber_Information"> 4100</User_ID_1_>
<Password_1_ group="Ext_1/Subscriber_Information"> password</Password_1_>
<Resync_Periodic>43200</Resync_Periodic>
<Mailbox_ID_1_ group="Ext_1/Subscriber_Information"> 4100</Mailbox_ID_1>
<Application_LED ua="na"></Application_LED>
<Serv_Subscribe_Failed_LED ua="na"></Serv_Subscribe_Failed_LED><Serv_Subscribing_LED ua="na"></Serv_Subscribing_LED>
<SNRM_Day_Mode_LED ua="na"></SNRM_Day_Mode_LED>
<SNRM_Night_Mode_LED ua="na"></SNRM_Night_Mode_LED>
<Parking_Lot_Idle_LED ua="na"></Parking_Lot_Idle_LED>
<Parking_Lot_Busy_LED ua="na"></Parking_Lot_Busy_LED>
<BLF_Idle_LED ua="na"></BLF_Idle_LED>
<BLF_Ringing_LED ua="na"></BLF_Ringing_LED>
<BLF_Busy_LED ua="na"></BLF_Busy_LED>
<BLF_Held_LED ua="na"></BLF_Held_LED>
<Unit_1_Key_1 ua="na">fnc=sd+blf+cp;sub=4101@10.1.11;nme=4101</Unit_1_Key_1><Unit_1_Key_2 ua="na">fnc=sd+blf+cp;sub=4102@10.1.11;nme=4102</Unit_1_Key_2><Unit_1_Key_3 ua="na">fnc=sd+blf+cp;sub=4103@10.1.11;nme=4103</Unit_1_Key_3><Unit_1_Key_4 ua="na">fnc=sd+blf+cp;sub=4104@10.1.11;nme=4104</Unit_1_Key_4><Unit_1_Key_5 ua="na">fnc=sd+blf+cp;sub=4105@10.1.11;nme=4105</Unit_1_Key_5><Unit_1_Key_6 ua="na">fnc=sd+blf+cp;sub=4106@10.1.11;nme=4106</Unit_1_Key_6><Unit_1_Key_7 ua="na">fnc=sd+blf+cp;sub=4107@10.1.11;nme=4107</Unit_1_Key_7><Unit_1_Key_8 ua="na">fnc=sd+blf+cp;sub=4108@10.1.11;nme=4108</Unit_1_Key_8><Unit_1_Key_9 ua="na">fnc=sd+blf+cp;sub=4109@10.1.11;nme=4109</Unit_1_Key_9><Unit_1_Key_10 ua="na">fnc=sd+blf+cp;sub=4110@10.1.11;nme=4110</Unit_1_Key_10><Unit_1_Key_11 ua="na">fnc=sd+blf+cp;sub=4111@10.1.11;nme=4111</Unit_1_Key_11>
<Unit_1_Key_12 ua="na"></Unit_1_Key_12>
<Unit_1_Key_13 ua="na"></Unit_1_Key_13>
<Unit_1_Key_14 ua="na"></Unit_1_Key_14>
<Unit_1_Key_15 ua="na"></Unit_1_Key_15>
<Unit_1_Key_16 ua="na"></Unit_1_Key_16>
<Unit_1_Key_17 ua="na"></Unit_1_Key_17>
<Unit_1_Key_18 ua="na"></Unit_1_Key_18>
<Unit_1_Key_19 ua="na"></Unit_1_Key_19>
<Unit_1_Key_20 ua="na"></Unit_1_Key_20>
<Unit_1_Key_21 ua="na"></Unit_1_Key_21>
<Unit_1_Key_22 ua="na"></Unit_1_Key_22>
<Unit_1_Key_23 ua="na"></Unit_1_Key_23>
<Unit_1_Key_24 ua="na"></Unit_1_Key_24>
<Unit_1_Key_25 ua="na"></Unit_1_Key_25>
<Unit_1_Key_26 ua="na"></Unit_1_Key_26>
<Unit_1_Key_27 ua="na"></Unit_1_Key_27>
<Unit_1_Key_28 ua="na"></Unit_1_Key_28>
<Unit_1_Key_29 ua="na"></Unit_1_Key_29>
<Unit_1_Key_30 ua="na"></Unit_1_Key_30>
<Unit_1_Key_31 ua="na"></Unit_1_Key_31>
<Unit_1_Key_32 ua="na"></Unit_1_Key_32>
</flat-profile>
The files that are troublesome display a "^" at the end of each line sometimes with a space preceding in mcedit. Converting from dos2unix removes the extra characters.
Could this be disturbing the construction of the file?
Title: Re: Generating new Phone configuration files
Post by: compsos on October 25, 2011, 08:01:27 AM
Putting a var_dump($row['provision']) in front of the close $fh line for the "else" section of the tftpsql.php file produced
1st 2 lines
Code: [Select]
string(442) "["00085D1A24FE.cfg"
download protocol: TFTP

so it looks like the command

Code: [Select]
$row['provision'] = preg_replace ( ' /\["(.*)"\n/ ',"", $row['provision'] );
fails to see the first line and edit it out.

Just built a new test system which initially did not show the problem but after
How to reproduce
File will now have the error. It seems to be something within the edit screen which is not called for a non modified extension.
The issue appears to be in the sarkinternal.pl code. Any ideas on how to trap.
Title: Re: Generating new Phone configuration files
Post by: compsos on October 26, 2011, 12:52:34 PM
This seems to solve the problem
Replace line 110 with these 2 lines

Code: [Select]
$test = preg_replace ( ' /\["(.*)"/ ',"", $row['provision'] );
$row['provision'] = trim($test,"\r\n ");

So far the files have generated correctly.
Title: Re: Generating new Phone configuration files
Post by: SARK devs on October 28, 2011, 10:10:19 PM
Hi Gordon

I find this exceedingly strange.  I cannot, no matter what I do, recreate your problem here.   I've tried several different browsers on both Windows and Ubuntu but it just keeps on working correctly.  In addition, we ourselves have got hundreds of copies of this release in the field and they are all just ticking along with no complaints.

I will anyway look to put your fix into the next release because it doesn't look as tho' it will do any harm and if it works for you then all well and good.

Kind Regards

Jeff   
Title: Re: Generating new Phone configuration files
Post by: SARK devs on October 28, 2011, 10:32:19 PM
Doh! - OK I've figured it.

All of our in-house definitions have a CR/LF immediately after the filename parameter.  If you put a space between the filename and the CR/LF then it will give the error you've seen.

"$MAC.cfg"CR/LF

NOT

"$MAC.cfg" CR/LF

Easily fixed (with the code you suggest) I think but for now make sure you don't introduce any spaces into the name line and it should work OK.

Kind Regards

S

Title: Re: Generating new Phone configuration files
Post by: compsos on October 29, 2011, 01:08:44 AM
It was very confusing until we found a reliable method to always reproduce. We had adding and removing a space before and after but that did not produce the right result. The code does.