diff options
author | Ted Trask <ttrask01@yahoo.com> | 2013-01-01 16:19:11 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2013-01-01 16:19:11 +0000 |
commit | ee4114e7f28ecd64c458143defa1b339c9203a32 (patch) | |
tree | b97b01090ebdc6e6359317946a564514c4ffbe98 | |
parent | 8a068d1d1e53019ba014142f309a1d7015ee96e9 (diff) | |
download | acf-kamailio-ee4114e7f28ecd64c458143defa1b339c9203a32.tar.bz2 acf-kamailio-ee4114e7f28ecd64c458143defa1b339c9203a32.tar.xz |
Replaced io.popen with modelfunction.run_executable
-rw-r--r-- | kamailio-model.lua | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/kamailio-model.lua b/kamailio-model.lua index 2f921de..94138b8 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -13,7 +13,6 @@ local packagename = "kamailio" local baseurl = "/etc/kamailio" local kamctlrc_file = "/etc/kamailio/kamctlrc" -local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " local env local con local DBENGINE @@ -187,13 +186,12 @@ function list_files() end local function parse_db_show(table) - local cmd = path .. "kamctl db show "..(table or "") - local f = io.popen(cmd) + local f = modelfunctions.run_executable({"kamctl", "db", "show", table}) -- These settings work for Postgres and DBTEXT database local delimiter = "\'?%s*[,|]%s*\'?" local results = {} local errtxt - for line in f:lines() do + for line in string.gmatch(f, "[^\n]+") do if #results == 0 and string.match(line, "^ERROR:") then errtxt = line results = nil @@ -208,7 +206,6 @@ local function parse_db_show(table) end end end - f:close() return results, errtxt end @@ -243,13 +240,7 @@ end function create_new_user(self, user) local success = validate_user(user) if success then - local cmd = path .. "kamctl add "..format.escapespecialcharacters(user.value.username.value).." "..format.escapespecialcharacters(user.value.password.value) - --if user.value.email_address.value ~= "" then - -- cmd = cmd.." "..format.escapespecialcharacters(user.value.email_address.value) - --end - local f = io.popen(cmd) - user.descr = f:read("*a") - f:close() + user.descr, user.errtxt = modelfunctions.run_executable({"kamctl", "add", user.value.username.value, user.value.password.value}) else user.errtxt = "Failed to create new user" end @@ -268,11 +259,7 @@ function delete_user(self, user) user.value.username.errtxt = "Invalid username" user.errtxt = "Failed to delete user" else - local cmd = path .. "kamctl rm "..format.escapespecialcharacters(user.value.username.value) - local f = io.popen(cmd) - local result = f:read("*a") - f:close() - user.descr = result + user.descr, user.errtxt = modelfunctions.run_executable({"kamctl", "rm", user.value.username.value}) end return user end @@ -295,10 +282,7 @@ end function update_user(self, user) local success = validate_user(user) if success then - local cmd = path .. "kamctl passwd "..format.escapespecialcharacters(user.value.username.value).." "..format.escapespecialcharacters(user.value.password.value) - local f = io.popen(cmd) - user.descr = f:read("*a") - f:close() + user.descr, user.errtxt = modelfunctions.run_executable({"kamctl", "passwd", user.value.username.value, user.value.password.value}) else user.errtxt = "Failed to update user" end @@ -512,10 +496,7 @@ function get_create_database(self, clientdata) end function create_database(self, create_db) - local cmd = path.."echo -e 'y\ny\n' | "..path.."kamdbctl create 2>&1" - local f = io.popen(cmd) - create_db.descr = f:read("*a") - f:close() + create_db.descr, create_db.errtxt = modelfunctions.run_executable({"kamdbctl", "create"}, true, 'y\ny\n') return create_db end |