create_user.lua 535 B

123456789101112131415161718192021
  1. user_id = argv[1];
  2. if (user_id == nil or user_id == "") then os.exit() end
  3. conf = "/usr/local/freeswitch/conf"
  4. dir = conf .. "/directory/default"
  5. template = dir .. "/1001.xml"
  6. dest = dir .. "/" .. user_id .. ".xml"
  7. template_file = io.open(template, "r")
  8. dest_file = io.open(dest, "a+")
  9. print(dest_file)
  10. while true do
  11. line = template_file:read("*line")
  12. if line == nil then break end
  13. line = line:gsub("1001", user_id)
  14. print(line)
  15. dest_file:write(line .. "\n")
  16. end
  17. api = freeswitch.API()
  18. api:execute("reloadxml")