AgentLogin powered by MySQL
In a previous article, I showed an alternative method of AgentCallBackLogin. In that example, the agents were authenticated via voicemail.conf. I made a comment that I would create a dialplan with it authenticating against a MySQL database.
So let’s start by creating our database:
CREATE TABLE IF NOT EXISTS `asterisk`.`agent_users` (
`id` int(11) NOT NULL auto_increment,
`user` varchar(10) NOT NULL default '',
`pass` varchar(32) NOT NULL default '',
`name` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM
And I’ll go ahead and drop same data into that database:
INSERT INTO `asterisk`.`agent_users` (`id`, `user`, `pass`, `name`) VALUES
(1, '1050', '1234', 'Robert');
Now for our dialplan:
exten => login,1,Answer()
exten => login,2,Read(user|/home/Sounds/user-id) ; I created an audio file which asks for the user id.
exten => login,3,Read(pass|/home/Sounds/user-pass) ; I created an audio file which asks for the user password.
exten => login,4,MYSQL(Connect connid localhost dbuser dbpassword asterisk)
exten => login,5,MYSQL(Query resultid ${connid} SELECT\ 'pass'\ FROM\ 'agent_users'\ WHERE\ 'user'\='${user}'\)
exten => login,6,MYSQL(Fetch fetchid ${resultid} password)
exten => login,7,NoOp(Password is: ${password}) ; This line isn't required, but I have it here to output the results of our query.
exten => login,8,MYSQL(Clear ${resultid})
exten => login,9,MYSQL(Disconnect ${connid})
exten => login,10,GotoIf($["${password}" = "${pass}"]?incorrect,1:login,11)
exten => login,11,AddQueueMember(SALES|local/${user}@agents/n)
exten => login,12,AddQueueMember(SUPPORT|local/${user}@agents/n)
exten => login,13,Playback(goodbye)
exten => login,14,Hangup()
exten => incorrect,1,Playback(/home/Sounds/incorrect-pass) ; This is an audio file to tell that the password is incorrect
exten => incorrect,2,Goto(login,1)
Yes, this dialplan is a little longer. But you won’t have to worry with voicemail.conf being your authentication method, or of VMAuthenticate depreciating.
In addition to the above, you can always port voicemail.conf to MySQL via Asterisk Realtime. You can learn more Asterisk Realtime here.

I was just thinking about this option further. With Asterisk Realtime you can port voicemail.conf to MySQL. Asterisk would than be authenticating against MYSQL, only in a different way.