How the script works
Grandstream phones by default request the configuration by using a HTTP (as long as HTTP has been configured instead of TFTP) path that can be configured on the phones and then adding the MAC address to the request, so for example if you configure the HTTP URL path on the phones to be http://freepbx.mydomain.lan/prov, when the phone requests for its configuration the full URL will look like this, http://freepbx.mydomain.lan/prov/cfg000b01020304, where 000b01020304 within the URL is the phones MAC address. Now as mentioned previously, the configuration files don’t actually exist on the server so we have to use some Apache configuration file magic to redirect requests within the prov directory to our provisioning PHP script. All that is needed to accommodate this is a Location directive in your apache configuration file (httpd.conf) that looks like this.
<location /prov>
Action genprov-php /genprov.php virtual
SetHandler genprov-php
</location>
What this does is basically tell Apache that any requests to the sub directory /prov should be handled by a PHP script that is in the root of the web server called genprov.php. The virtual directive also informs Apache that the file that’s being requested (cfg000b01020304 in this case) is virtual and doesn’t actually exist on disk.
There is one module that needs to be installed within FreePBX for the script to work, and that is the Inventory module. You add all the users to your inventory and configure the following for each
• Employee Name
• Extension
• UserName
• Phone Password
• MAC Address (most important as this is the key that is used to find the configuration for the phone)
Once you have done this, you need to alter the $sql_server, $sql_user and $sql_password at the top of the PHP script to valid values for your FreePBX database.
The final step is to put the Grandstream configuration text file in the same folder as the genprov.php script and call it gxp.txt.
The script will then take the original URL request (http://freepbx.mydomain.lan/prov/cfg000b01020304 for example), strip the MAC address from the request and look it up within the inventory table to extract the employee name, SIP username and SIP password. This information is then merged with the configuration options that remain static from the Grandstream configuration file and the generated configuration data is sent back to the phone.
Pages: 1 · 2

I modified the php for my needs and used a slightly different apache directive with mod_rewrite, as I have firmware in a sub directory of /prov.
One issue I came across is the DST rule. This wont be a problem if you are in the USA, but in the UK (and others no doubt) the rule is different from the default. (Why didn't GS embed the rules in the firmware?) Unfortunately, you can't send the rule as you would write it in the config file, because it has commas and semi-colons, which have special meaning in the request format of the config data. I used a str_replace to swap them for hex codes. It doesn't like the dashes encoded for some reason and don't use url_encode - I tried that and it screwed up the data and killed one of my phones! Good job they are cheap...
Thanks again.
You can find more information here
http://www.voip-info.org/wiki/view/Grandstream+Configuration+Tool