summaryrefslogtreecommitdiffstats
path: root/config/update_device_params.lua
diff options
context:
space:
mode:
Diffstat (limited to 'config/update_device_params.lua')
-rw-r--r--config/update_device_params.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/config/update_device_params.lua b/config/update_device_params.lua
index 974f339..80b5b81 100644
--- a/config/update_device_params.lua
+++ b/config/update_device_params.lua
@@ -1,6 +1,10 @@
-- This is the script run after editing device params
local functions, params, oldparams = ...
+require("posix")
+
+local root = "/var/www/provisioning/htdocs/"
+
APP.logevent("got to update_device_params script")
local function findip(mac)
@@ -24,6 +28,20 @@ local notify_device = function(mac, extension)
end
end
+-- If the mac address changed, we need to move the associated config files
+if oldparams.value.device and oldparams.value.device.value.mac and oldparams.value.device.value.mac.value ~= "" and params.value.device and params.value.device.value.mac and params.value.device.value.mac.value ~= oldparams.value.device.value.mac.value then
+ if string.match(oldparams.value.device.label, "Polycom") then
+ local path = root.."Polycom/"
+ for d in posix.files(path) do
+ if string.match(d, string.lower(oldparams.value.device.value.mac.value)) and posix.stat(path..d, "type") == "regular" then
+ local newfile = string.gsub(d, string.lower(oldparams.value.device.value.mac.value), string.lower(params.value.device.value.mac.value))
+ APP.logevent("moving "..path..d.." to "..path..newfile)
+ os.rename(path..d, path..newfile)
+ end
+ end
+ end
+end
+
-- Notify the phone to pull it's config
-- Try to get a valid extension currently on the device
local oldexten = ""