From 69a65aa41349b9f93a7d8cf55de28fe6480cdee9 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Sat, 15 Mar 2014 00:11:28 +0800 Subject: [PATCH] add create user and gateway lua scripts --- scripts/lua/portal/create_gateway.lua | 23 +++++++++++++++++++++++ scripts/lua/portal/create_user.lua | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 scripts/lua/portal/create_gateway.lua create mode 100644 scripts/lua/portal/create_user.lua diff --git a/scripts/lua/portal/create_gateway.lua b/scripts/lua/portal/create_gateway.lua new file mode 100644 index 0000000000..0e8a848142 --- /dev/null +++ b/scripts/lua/portal/create_gateway.lua @@ -0,0 +1,23 @@ +name = argv[1]; +realm = argv[2]; +username = argv[3]; +password = argv[4]; +register = argv[5]; + +conf = "/usr/local/freeswitch/conf" +dir = conf .. "/sip_profiles/external/" +file_name = dir .. "/" .. name .. ".xml" + +conf_file = io.open(file_name, "w+") + +conf_file:write('\n') +conf_file:write(' \n') +conf_file:write(' \n') +conf_file:write(' \n') +conf_file:write(' \n') +conf_file:write(' \n') +conf_file:write(' \n') +conf_file:write('\n') + +api = freeswitch.API() +api:execute("sofia profile external rescan") diff --git a/scripts/lua/portal/create_user.lua b/scripts/lua/portal/create_user.lua new file mode 100644 index 0000000000..b1abb20c4d --- /dev/null +++ b/scripts/lua/portal/create_user.lua @@ -0,0 +1,21 @@ +user_id = argv[1]; +if (user_id == nil or user_id == "") then os.exit() end + +conf = "/usr/local/freeswitch/conf" +dir = conf .. "/directory/default" +template = dir .. "/1001.xml" +dest = dir .. "/" .. user_id .. ".xml" + +template_file = io.open(template, "r") +dest_file = io.open(dest, "a+") +print(dest_file) +while true do + line = template_file:read("*line") + if line == nil then break end + line = line:gsub("1001", user_id) + print(line) + dest_file:write(line .. "\n") +end + +api = freeswitch.API() +api:execute("reloadxml")