diff options
author | Ted Trask <ttrask01@yahoo.com> | 2015-07-09 15:53:01 -0400 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2015-07-13 14:51:45 -0400 |
commit | 7236b1b65077dd97499d6678fae858567fc9d04e (patch) | |
tree | 5753a637078d9e66a37088772427ecd995451074 | |
parent | 2d27a7f333f3cdf421d3558505f9b54dfa734f54 (diff) | |
download | acf-provisioning-7236b1b65077dd97499d6678fae858567fc9d04e.tar.bz2 acf-provisioning-7236b1b65077dd97499d6678fae858567fc9d04e.tar.xz |
Modify the process_put script to revert bad changes0.7-stable
If the set_device_params function fails, notify the phone to pull its config and revert the change
(cherry picked from commit 1805de3c2b759ac9a5309bba551b81c862d0c489)
-rw-r--r-- | config/process_put.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/config/process_put.lua b/config/process_put.lua index 1fed1ae..e203cf0 100644 --- a/config/process_put.lua +++ b/config/process_put.lua @@ -3,6 +3,26 @@ local functions, mac, data, device_id = ... --functions.logevent("got to process_put 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~*'"..functions.escape(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 + --functions.logevent("Notifying "..ipaddr.." to update for "..(mac or "")) + os.execute("/etc/provisioning/notify_device "..ipaddr.." "..extension) + else + --functions.logevent("Warning - could not find IP address for "..(mac or "")) + end +end + -- Get the params local params = functions.get_device_params(device_id) @@ -75,5 +95,14 @@ end -- Update the params local params = functions.set_device_params(params) +-- If the update fails, notify the phone to revert the config change +if params.errtxt and params.value.device and params.value.device.value.mac then + exten = "" + if params.value.reg1 and params.value.reg1.value.extension then + exten = params.value.reg1.value.extension.value + end + notify_device(params.value.device.value.mac.value, exten) +end + -- Return the updated data return data |