diff options
author | Ted Trask <ttrask01@yahoo.com> | 2013-12-08 17:10:56 -0500 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2013-12-08 17:10:56 -0500 |
commit | a7ac20b54272bda016a4f320b9291e76c2652286 (patch) | |
tree | bab665d629ad388de4620ee6c8cb9328872aa8a7 | |
parent | ac604bc78e5800b139103a4dd503c10c6b819a4b (diff) | |
download | acf-freeswitch-vmail-a7ac20b54272bda016a4f320b9291e76c2652286.tar.bz2 acf-freeswitch-vmail-a7ac20b54272bda016a4f320b9291e76c2652286.tar.xz |
Add batch account creation
Contributed by alacerda alancordeiro@gmail.com
-rw-r--r-- | vmail-controller.lua | 4 | ||||
-rw-r--r-- | vmail-listusers-html.lsp | 7 | ||||
-rw-r--r-- | vmail-model.lua | 43 | ||||
-rw-r--r-- | vmail.roles | 4 |
4 files changed, 55 insertions, 3 deletions
diff --git a/vmail-controller.lua b/vmail-controller.lua index f706802..9999f75 100644 --- a/vmail-controller.lua +++ b/vmail-controller.lua @@ -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) diff --git a/vmail-listusers-html.lsp b/vmail-listusers-html.lsp index 766ef45..22e2499 100644 --- a/vmail-listusers-html.lsp +++ b/vmail-listusers-html.lsp @@ -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> diff --git a/vmail-model.lua b/vmail-model.lua index bab4484..e818a7f 100644 --- a/vmail-model.lua +++ b/vmail-model.lua @@ -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 diff --git a/vmail.roles b/vmail.roles index d325e20..43395b4 100644 --- a/vmail.roles +++ b/vmail.roles @@ -1,5 +1,5 @@ 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 |