Thank you very much! That worked as you said it should.
My magics for other poor souls that might stumble across this via google or whatever...
1) For the sake of getting up and going, I manually created /AMPUSER/EXTEN/device: EXTEN entries in my AstDB. I probably should set up some sort of bash script or something that goes through my hotdesk MySQL table and keeps the extensions up to date, but that'll be a "later" project.
2) Within the dialplan, when a user successfully logs in, fire this dialplan logic (besides the part to log the user in). Note that ${LOCATION} is the SIP device the user logged into, and ${E} is the user's extension.
same => n,UserEvent(UserDeviceAdded,${E},SIP/${LOCATION})
same => n,Set(DB(DEVICE/${E}/dial)=SIP/${LOCATION})
3) Within the dialplan, when a user successfully logs out, fire this dialplan logic (besides the part to log the user out). NOte that ${LOCATION} is the SIP device the user logged out of, and ${E} is the user's extension.
same => n,UserEvent(UserDeviceRemoved,${E},SIP/${LOCATION})
same => n,Set(LOGOUT=${DB_DELETE(DEVICE/${E}/dial)})
4) Within the FOP2 config files:
fop2.cfg:
#exec autousers.sh
buttonfile=autobuttons.cfg
autousers.sh:
#!/bin/bash
DBNAME=MyDBName
DBUSER=MyDBUser
DBPASSWORD=MyDBPassword
DBHOST=MyDBHost
while read EXTEN PIN
do
echo "user=${EXTEN}:${PIN}:all"
done < <(mysql -h ${DBHOST} ${DBNAME} -u ${DBUSER} -p${DBPASSWORD} -se "SELECT extension, pin FROM ast_hotdesk")
autobuttons.cfg:
#exec autobuttons.sh
*snip My Static Buttons (Queues, Trunks, etc)*
autobuttons.sh:
#!/bin/bash
DBNAME=MyDBName
DBUSER=MyDBUser
DBPASSWORD=MyDBPassword
DBHOST=MyDBHost
while read EXTEN VMCONTEXT NAME
do
echo "[USER/${EXTEN}]"
echo "type=extension"
echo "extension=${EXTEN}"
echo "context=MyContext"
echo "label=${NAME}"
echo "mailbox=${EXTEN}@${VMCONTEXT}"
done < <(mysql -h ${DBHOST} ${DBNAME} -u ${DBUSER} -p${DBPASSWORD} -se "SELECT extension, vmcontext, cid_name FROM ast_hotdesk ORDER BY extension ASC")
It's important to have cid_name last in your mysql query if you have spaces in your cid_names, otherwise the bash script will split on the space within the cid_name and everything will be messy.
---
I do have two questions. I see some reference in the documentation to "when fop2 is reloaded". Is it possible to fire an event that will reload fop2 from within the Asterisk dialplan?
Related... If I am logged into FOP2 in IE when I change the buttons config file on the server and run service fop2 restart from the server CLI, when IE "reconnects" to FOP2, it doesn't pickup the changed buttons config (and usually this winds up with the "existing" buttons being horribly messed up). Is there a way to fix this, or something I have misconfigured that is causing it?