From 7236b1b65077dd97499d6678fae858567fc9d04e Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 9 Jul 2015 15:53:01 -0400 Subject: Modify the process_put script to revert bad changes If the set_device_params function fails, notify the phone to pull its config and revert the change (cherry picked from commit 1805de3c2b759ac9a5309bba551b81c862d0c489) --- config/process_put.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 -- cgit v1.2.3