FreePBX Device User Mode – “User” password change using touchtone keypad (or a feature code)

One client requested this as his entire office of 200 users use the Device User mode of FreePBX 2.11. This office is also a hybrid office use and call center of up to 20 agents.
With this feature, users can dial a code and change whenever they want. Firstly, you need to have the following in your setup: – FreePBX 2.9 or higher (i used 2.11)
– Asterisk 1.6 or higher (i used 11.x) This dialplan is intended to be used with FreePBX since it uses MySQL to write most of its configs in. This dialplan changes stuff in MySQL directly with the Asterisk’s MYSQL app. Follow as guided and you will get this running in no time. Steps in short: 1) Create a low privilege user in MySQL
2) Put up a custom code dialplan
3) Enable the custom dialplan code in FreePBX

1) Create low privilege user in MySQL

Since we want this low priv user to only query and write to very little table fields, we give it that much permission a) Log into MySQL, login as root with the password you’ve previously set,
NOTE: If you have trouble running these commands, be sure to check using single quotes and double quote per the guide. If something other than that appear when pasting, change accordingly. #mysql –u root –p

When inside MySQL, copy paste the following; and this guide creates a user called “pwdmgr” with password “letmeinbaby” CREATE USER ‘pwdmgr’@localhost IDENTIFIED BY “letmeinbaby”;
GRANT SELECT (extension) ON asterisk.users TO pwdmgr@localhost;
GRANT SELECT,UPDATE (password) ON asterisk.users TO pwdmgr@localhost;
FLUSH PRIVILEGES;

2) Paste the following dialplan into extensions_custom.conf

[macro-change-loginpw]
exten => s,1,Answer()
    same => n,NoOp(User password changing app)
    same => n,ExecIf($[“${AMPUSER}” = “”]?Hangup(16))
    same => n,Set(DEVICETYPE=${DB(DEVICE/${AMPUSER}/type)})
    same => n,ExecIf($[“${DEVICETYPE}” = “fixed”]?Hangup(16))
    same => n,Set(CURRENTPW=${DB(AMPUSER/${AMPUSER}/password)})
    same => n,Authenticate(${CURRENTPW})
    same => n,Read(NEWPASS,vm-newpassword)
    same => n,Set(DB(AMPUSER/${AMPUSER}/password)=${NEWPASS})
    same => n,MYSQL(Connect connid localhost pwdmgr letmeinbaby asterisk)
    same => n,MYSQL(Query resultid ${connid} UPDATE users set password=’${NEWPASS}’ WHERE extension=’${AMPUSER}’)
    same => n,MYSQL(Disconnect ${connid})
    same => n,PlayBack(your&vm-password&has-been-changed-to)
    same => n,SayDigits(${NEWPASS})
    same => n,Hangup(16)

Save and exit!.

3) Set it up in FreePBX to invoke that custom macro you did above using feature code like dialing

Go to FreePBX, select Admin, then select Custom Extensions, add like below
Custom Destination=macro-change-loginpw,s,1
Description: AnythingYouLike
image
  Then click on Submit Changes Next, go to Applications, select Misc Application, do like below Description=Anything you like
Feature Code: Any code not conflicting with current FeatureCodes, e.g. 15 is not really used in a Standard FreePBX setup
Status: Enabled (you can disable this in FreePBX)
Destination: The Custom Destination you created just now. image   Click Submit Changes, now click the Apply Conf button.   All done, now go ahead and try it out for yourself, dial
15 on a logged on user. You can also hack the dialplan to ask for username in case you want to change for non-logged on user. As usual, do suggest improvements and report bugs.