tSIP: updating settings from Lua / provisioning

Combination of curl and built-in Lua scripting used for provisioning. Updating main config file (not BLF settings and not phonebook) from file located on HTTP/HTTPS server.

tSIP is using JSON format for configuration. Built-in Lua UpdateSettings function updates current settings with one from supplied text. Settings that are not present in supplied text are not changed (well, unless I've messed something in tSIP code...) - overall this should be similar to merging with supplied text being used to override current settings. Simplest way to create update file might be taking existing tSIP.json file and deleting from it using JSONedit all the nodes that are not intended to be changed.

Following script is intented to be assigned to "on startup" and/or "on timer" (or "on timer 2") events (with timer set to 900000 ms or similar large period). Script expects curl.exe (one with SSL support if https would be used) to be placed next to tSIP.exe. Modify resource location, optional token (e.g. changing also to .php instead of .json) and credentials (admin:password) to match your setup.


local filename = GetExeName()
local index = string.find(filename:reverse(), "\\")
local dir = string.sub(filename, 1, -index)
local exe = dir .. "curl.exe"

ShellExecute("open", exe,
	"-o update.json http://tomeko.net/tmp/update.json?token=ABCDEFGH --insecure --anyauth --user admin:password", nil, 0)
Sleep(3000)

local f = io.open("update.json", "r")
if f == nil then
	print("Config update not found\n")
	return
end
local configStr = f:read("*all")
f.close()

os.remove("update.json")
print(string.format("Updating settings:\n%s\n", configStr))
UpdateSettings(configStr)
print("Config updated\n")

Note: "token" above is optional, intented to allow to distinguish users to generate their configuration dynamically from e.g. php script. You might ask user for the token (e.g. username) using InputQuery function and store it in separate file using Lua io module to be loaded and used next time (e.g. each 15 minutes).

Example file (linked in script above as http://tomeko.net/tmp/update.json) updating configuration - changing just registration expiration time for test purposes:

{
   "Accounts" : [
      {
         "reg_expires" : 61
      }
   ]
}

Updating programmable buttons

For updating configuration of programmable buttons UpdateButtons(json) Lua function was added in tSIP version 0.1.73.4. Configuration from passed json text is merged into existing configuration and elements that do not need updating may be skipped. If whole button do not need any change - use empty object ({} string). Same as with main settings file json text could be fetched from some server using curl or loaded from some network drive.

Example changing caption of second button:

UpdateButtons('{"btnConf":[{},{"caption":"    Flash"}]}')

Back to howto list.


 "Cookie monsters": 6036002    Parse time: 0.001 s