FOP2 & hot desking

  1. 12 years ago

    I recently deployed a vanilla Asterisk 10 server with MySQL based hot desking (more or less as per the example here: http://ofps.oreilly.com/titles/97805965 ... sk-DB.html). Since I'm not using the "private queue" workaround for the hot desk users, I don't really have a fixed device to monitor for my users other than a custom device I'm manipulating through dialplan magic, and FOP2 kicks a fuss if I try to tell it to use [Custom/${EXTEN}] (I fill in the substitution myself, but for example's sake...)

    Two questions:

    1. Is there a straightforward way for me to get FOP2 to monitor my users instead of a device?
    2. Is there a supported way to get FOP2 to use the login credentials out of my existing MySQL database for the hotdesking, so I can let people have the same PIN for logging into both the phones and FOP2?
  2. admin

    23 Feb 2012 Administrator

    Fop2 supports hotdesking via freepbx device&user mode, if you can replicate that in your setup, fop2 will work, the button definition will have to be

    [USER/200]

    The thing is that the mode in freepbx requires several astdb entries to be set in a kind of unorganized manner, and also userevents in the manager should be fired whenever a user logs in or out.

    Regarding the user/passwords, you can customize the autoconfig-users-freepbx.sh to your needs or write any custom script accesing any kind of database or system.

    Best regards,

  3. Okay, thank you. Does anyone have a sample of what the buttons.cfg file winds up "looking like" in device&user mode for FreePBX to give me a nudge in the right direction?

  4. admin

    24 Feb 2012 Administrator

    The button config file is easy, I posted the important part above:

    [USER/200]
    type=extension
    extension=200
    domain=from-internal
    label=John

    The hard part is to replicate the ASTDB entries and fire the proper UserEvents when a user logs in or out. I do not recall from memory, and it is not straightforward at all, it seems in FreePBX the feature was an after though or a kind of convoluted implementation, because there are several ASTDB entries to set/check.

    Here is an example entry:

    /AMPUSER/1002/device : 1002
    /DEVICE/1002/dial : SIP/john

    Whit those entries, fop2 will monitor SIP/john for USER/1002

    Then the manager userevent should have this information when a user logs in or out:

    Event: UserDeviceAdded
    Data: 1002,SIP/john

    Event: UserDeviceRemoved
    Data: 1002,SIP/john

    Best regards,

  5. Edited 9 years ago by admin

    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?

  6. admin

    25 Feb 2012 Administrator

    Thanks for your detailed example, I am sure it will help other users!

    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?

    A module reload in asterisk should trigger a FOP2 reload too.

    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?

    The client is supposed to detect button configuration changes and force a reload when that happens, but now that I think of it, it might do that on reload only and not on restart. I will make some tests next monday/tuesday and try to remember to update this post with my findings.

    Best regards,

or Sign Up to reply!