Commit a7ac20b5 authored by Ted Trask's avatar Ted Trask

Add batch account creation

Contributed by alacerda alancordeiro@gmail.com
parent ac604bc7
......@@ -110,6 +110,10 @@ mymodule.createuser = function( self )
return self.handle_form(self, self.model.get_usersettings, self.model.create_usersettings, self.clientdata, "Create", "Create User", "User Created")
end
mymodule.createmanyusers = function( self )
return self.handle_form(self, self.model.get_bunchsettings, self.model.set_bunchsettings, self.clientdata, "Create Many", "Create Users", "User Created")
end
mymodule.processdialplanxml = function( self )
self.conf.viewtype = "xml"
return self.model.process_dialplan_xml_request(self.clientdata)
......
......@@ -62,8 +62,13 @@ html = require("acf.html")
<H2>Create New User</H2>
<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller) %>/createuser" method="POST">
<input class="hidden" type="hidden" name="redir" value="<%= html.html_escape(page_info.orig_action) %>" >
<dl><dt></dt><dd><input class="submit" type="submit" value="Create"></dd></dl>
<dl><dt></dt><dd><input class="submit" type="submit" value="Create"></dd>
</form>
<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller) %>/createmanyusers" method="POST">
<input class="hidden" type="hidden" name="redir" value="<%= html.html_escape(page_info.orig_action) %>" >
<dt></dt><dd><input class="submit" type="submit" value="Create Many"></dd></dl>
</form>
<% end %>
</DL>
......@@ -695,6 +695,49 @@ mymodule.set_delete_user = function(self, deleterequest)
return deleterequest
end
mymodule.get_bunchsettings = function (self)
local bunch = cfe({ name="list", label="List", type="longtext", descr="Each line will be seen as a new extension. To separate fields make use of colons. Follow the formmat:\n\nExtension:Name:Lastname:Password"})
return cfe({ type="group", value={bunch=bunch}, label="Voicemail Users List" })
end
mymodule.set_bunchsettings = function (self, clientdata)
local connected = databaseconnect()
local nExts = {}
tFile = assert(io.tmpfile())
tFile:write(clientdata.value.bunch.value)
tFile:seek("set",0)
for line in tFile:lines() do
for ext, fname, lname, pass in string.gmatch(line, "(%w+):(%w+):(%w+):(%w+)") do
nExts.username = ext or nil
nExts.firstname = fname or nil
nExts.lastname = lname or nil
nExts.password = pass or nil
sql = "INSERT INTO voicemail_users VALUES(null, '"..escape(nExts.username).."')"
runsqlcommand(sql)
sql = "SELECT uid FROM voicemail_users where username ='"..escape(nExts.username).."'";
uid = getselectresponse(sql)
nExts.uid = uid[1].uid or nil
sql = "INSERT INTO voicemail_values VALUES('"..uid[1].uid.."', '2', '"..escape(tostring(nExts.firstname)).."')"
runsqlcommand(sql)
sql = "INSERT INTO voicemail_values VALUES('"..uid[1].uid.."', '3', '"..escape(tostring(nExts.lastname)).."')"
runsqlcommand(sql)
sql = "INSERT INTO voicemail_prefs (username, domain, password) VALUES ('"..escape(nExts.username).."', '"..config.domain.."', '"..escape(nExts.password).."')"
runsqlcommand(sql)
end
end
if connected then databasedisconnect() end
return clientdata
end
mymodule.get_usersettings = function(self, clientdata)
local retval = {}
local errtxt
......
GUEST=vmail:processdialplanxml,vmail:processdirectoryxml
USER=vmail:listfolders,vmail:listusers,vmail:listmymessages,vmail:downloadmymessage,vmail:deletemymessage,vmail:editmyusersettings,vmail:forwardmymessage,vmail:movemymessage,vmail:emailmymessage,vmail:callbackmymessage
EDITOR=vmail:editusers,vmail:createuser,vmail:deleteuser,vmail:editusersettings
EDITOR=vmail:editusers,vmail:createuser,vmail:createmanyusers,vmail:deleteuser,vmail:editusersettings
EXPERT=vmail:editconfig,vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage
ADMIN=vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage,vmail:editusersettings,vmail:listfolders,vmail:listusers,vmail:editusers,vmail:createuser,vmail:deleteuser,vmail:editconfig
ADMIN=vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage,vmail:editusersettings,vmail:listfolders,vmail:listusers,vmail:editusers,vmail:createuser,vmail:createmanyusers,vmail:deleteuser,vmail:editconfig
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment