diff options
author | Ted Trask <ttrask01@yahoo.com> | 2011-10-10 19:34:59 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2011-10-10 19:34:59 +0000 |
commit | 1d895ace660869053830ed33302e0708efb6065e (patch) | |
tree | 0ed844a6a408042ec0c6f4a11726db7a7915881b /config/update_device_params.lua | |
parent | b802504e41cccda64b8f903973d01897bbec7451 (diff) | |
download | acf-provisioning-1d895ace660869053830ed33302e0708efb6065e.tar.bz2 acf-provisioning-1d895ace660869053830ed33302e0708efb6065e.tar.xz |
Added in configuration files / scripts and cgi-bin scripts.
Diffstat (limited to 'config/update_device_params.lua')
-rw-r--r-- | config/update_device_params.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/config/update_device_params.lua b/config/update_device_params.lua new file mode 100644 index 0000000..974f339 --- /dev/null +++ b/config/update_device_params.lua @@ -0,0 +1,41 @@ +-- This is the script run after editing device params +local functions, params, oldparams = ... + +APP.logevent("got to update_device_params script") + +local function findip(mac) + if not mac or mac == "" then + return nil + end + local ipaddr = functions.getselectresponse("SELECT ip FROM provisioning_requests WHERE mac~*'"..mac.."'") + if ipaddr and ipaddr[1] then + return ipaddr[1].ip + end +end + +local notify_device = function(mac, extension) + local ipaddr = findip(mac) + if ipaddr then + APP.logevent("Notifying "..ipaddr.." to update for "..(mac or "")) + os.execute("/etc/provisioning/notify_device "..ipaddr.." "..extension) + addfuturenotify(ipaddr, extension) + else + APP.logevent("Warning - could not find IP address for "..(mac or "")) + end +end + +-- Notify the phone to pull it's config +-- Try to get a valid extension currently on the device +local oldexten = "" +for name,val in pairs(oldparams.value) do + if string.match(name, "^reg") and val.value.extension and val.value.extension.value ~= "" then + oldexten = val.value.extension.value + break + end +end +if params.value.device and params.value.device.value.mac and params.value.device.value.mac.value ~= "" then + notify_device(params.value.device.value.mac.value, oldexten) +end +if oldparams.value.device and oldparams.value.device.value.mac and oldparams.value.device.value.mac.value ~= "" then + notify_device(oldparams.value.device.value.mac.value, oldexten) +end |