summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/process_put.lua29
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