I have a setup where I have multiple offices that are sharing their extension space via a DUNDI cloud (part of the dialplan for an unknown local extension is to query the other servers to see if they own it, and sending the call to the appropriate server if so). However, we've had a couple instances recently where an admin forgot to check if an extension was in use on another server before creating it, and we wound up with the same extension in two different places. I figured it might be cool to hook into the extension creation process and do a lookup and reject the new extension as a duplicate if it already exists, but the closest hook available is after the extension is already created (presumably to allow you to do additional custom setup).
So it'd be really useful to me if there was a "before created" hook that would accept or deny the creation of the extension based on the result returned by the hook code.
I suppose for now I can hook the "After Created" hook and manually delete the freshly-created extension and throw an error as part of my hook if it's a duplicate... :)
true the only means of
true the only means of communication is what you send (like email) from your script.
Yeah, was hoping maybe if I
Yeah, was hoping maybe if I exited with an error it would display the STDERR output to the user or something. Oh well.
For shelling out to the
For shelling out to the "delete_multiple.cgi" script, what environment variables need to be set? And how did you discover them? Just curious as being able to do this with other Thirdlane cgi scripts could be very helpful to me.
The three that need to be set
The three that need to be set to make it actually work are WEBMIN_CONFIG, REMOTE_USER, and QUERY_STRING.
WEBMIN_CONFIG needs to be set to the path to your webmin configuration directory (90% of the time that'll be "/etc/webmin")
REMOTE_USER should be set to the username of a user that has sufficient permissions to perform the action (usually your admin user).
Then look at the variables that need to be set from the form that usually submits to perform that action, and put them as name/value pairs in QUERY_STRING.
You then have to cd into the asterisk module directory under webmin, and call the script using the full pathname to it (you need to be in that directory or the includes won't work, and have to use the full path to call it or the webmin libraries won't find it)
For example, to delete extension 570, I would do this:
[~/]# export WEBMIN_CONFIG="/etc/webmin"
[~/]# export REMOTE_USER="admin"
[~/]# export QUERY_STRING="deletetype=users&deletedata=570"
[~/]# cd /usr/libexec/webmin/asterisk/
[/usr/libexec/webmin/asterisk/]# /usr/libexec/webmin/asterisk/delete_multiple.cgi
If successful, it'll print a Location: header with the URL to redirect to (which will be wrong unless you set SERVER_NAME and SCRIPT_URI as well, but when you're calling it from the command line that stuff probably doesn't matter to you).
As for the part of figuring
As for the part of figuring out what to put into QUERY_STRING, the Web Developer Toolbar extension for Firefox is very useful for that. Use its function to "Display Form Data" when viewing a page you could perform that action from in the web UI.
Note that I'm also using STE, and in my extension delete example above there's likely another variable you need to set within QUERY_STRING to identify the tenant you're acting on when using MTE.
if you don't want to export
if you don't want to export them into the environment and want to contain it to a single scope.. have you considered..
[~/]# cd /usr/libexec/webmin/asterisk/
[/usr/libexec/webmin/asterisk/]# WEBMIN_CONFIG="/etc/webmin" REMOTE_USER="admin" QUERY_STRING="deletetype=users&deletedata=570" /usr/libexec/webmin/asterisk/delete_multiple.cgi
Normally you'd be doing it
Normally you'd be doing it from inside a script rather than directly on the command line anyway, and the export statements would still be scoped to your script when run from inside it (and putting them separate makes it easier to read in the script). But yeah, when doing it for real from the command line, putting them on the same line keeps you from polluting your environment. :)
Brilliant! Thanks for the
Brilliant! Thanks for the info. Especially the tip about the web developer toolbar :-) Much easier than the way I was thinking about doing it - gathering up all the field names with Firebug manually!
The after created hook doesn't appear to be useful for this... although I can actually delete the created extension (set a couple environment variables and shell out to /usr/libexec/webmin/asterisk/delete_multiple.cgi works like a charm), there's no way to communicate back to the user that I've done so as far as I can tell, so they have no idea that it's been rejected.