diff options
author | Ted Trask <ttrask01@yahoo.com> | 2011-10-11 15:35:02 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2011-10-11 15:35:02 +0000 |
commit | fe1e3e76b8174f3aa0c5adeb9abc10821b8f2013 (patch) | |
tree | f90b3a6dd1e24074f559604bbaf62edfbca16817 /config | |
parent | 6b6de1fd8e91f2fe812db929fea4bef9d1224585 (diff) | |
download | acf-provisioning-fe1e3e76b8174f3aa0c5adeb9abc10821b8f2013.tar.bz2 acf-provisioning-fe1e3e76b8174f3aa0c5adeb9abc10821b8f2013.tar.xz |
Delete / move other (put) files when delete / change mac for Polycom phone
Diffstat (limited to 'config')
-rw-r--r-- | config/delete_device.lua | 13 | ||||
-rw-r--r-- | config/update_device_params.lua | 18 |
2 files changed, 30 insertions, 1 deletions
diff --git a/config/delete_device.lua b/config/delete_device.lua index 6e5a907..ea69da2 100644 --- a/config/delete_device.lua +++ b/config/delete_device.lua @@ -1,11 +1,22 @@ -- This is the script run after deleting a device (and all of its params) local functions, olddevice, oldparams = ... -local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " +require("posix") + +local root = "/var/www/provisioning/htdocs/" APP.logevent("got to delete_device script") -- First, we delete the associated config files +if oldparams.value.device and string.match(oldparams.value.device.label, "Polycom") and oldparams.value.device.value.mac 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 + APP.logevent("deleting "..path..d) + os.remove(path..d) + end + end +end -- We'll handle the deleting of the device by handling the resulting changing of the params -- First, have to create a new set of params (with blank extensions) 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 = "" |