Académique Documents
Professionnel Documents
Culture Documents
http://fonality.com/trixbox/forums/trixbox-forums/help/change-extension-c...
Home
Forums
Products
Technical Support
FAQ
Wiki
Downloads
Partners trixbox CE
Free & Open
trixbox.com
Search
Go
trixbox CE Support
Professional Help
Certified Partners
Hardware & Providers
Main
News Recent Posts Dev Blog Wiki
Hi all I am running trixbox CE 2.8.0 on an HP server. I have setup a new context for my extensions which does not have access to outside lines. I now want some way of switching an extension between the normal context [from-internal] where they can dial out to the blocked one [from-internal-blocked] but it needs to be triggered from an outside source i.e. a custom database. This is much as you would with a hotel where you need to block a phone from dialing out once the room has checked out. This facility works if I login to the trixbox configuration page and manually change
User login
Username: Password:
the extension's context. Is there a way using the Asterisk Manager or something similar that I could change
Log in
Create new account Request new password
an extension's context without having to login to the trixbox's web configuration page? I have the Asterisk Manager doing an auto dial feature from our internal database so
Who's online
There are currently 1 user and 82 guests online.
I am OK with the programming side but cannot figure this one out despite intensive searching. Your help would be appreciated. regards Mike X-Lite works, SPA-942 does not [Solved] Adding automated IVR for all public holidays (in addition to existing time conditions) -Newbie but lovin' it!
Login or register to post comments
Recent News
Fonality Experiences Rapid Ado... Fonality Delivers One Billion... Fonality Releases 2011 Edition... Fonality Earns SixthConsecuti... Fonality Survey Finds Knowledg...
Mon, 03/29/2010 - 1:57pm
fireman_biff
Posts: 50 Member Since: 2010-02-16
[ more ] I have been working on something like this, where I can block a specific extension from making calls by dialing a custom feature code. The way it works is that you dial *1234 and (when prompted) the extension number to block, and it will get added to a mysql table listing blocked extensions. To undo it you dial *1236 and then the extension. Any time a call is made through the outbound route I want blocked, asterisk will check to see if the extension is blocked, and if so it will play a message and end the call. To implement it, add the following to extensions_custom.conf with the [frominternal-custom] context: exten => *1234,1,Answer exten => *1234,n,Playback(please-enter-the) exten => *1234,n,Playback(number) exten => *1234,n,Read(xtn,,4) exten => *1234,n,SayDigits(${xtn}) exten => *1234,n,MYSQL(Connect connid localhost root passw0rd asterisk) exten => *1234,n,MYSQL(Query resultid ${connid} INSERT\ INTO\ \`blocked\`\ SET\ \`extension\`=\'${xtn}\'\ ON\ DUPLICATE\ KEY\ UPDATE\ \`time \`=CURRENT_TIMESTAMP\(\)) exten => *1234,n,MYSQL(Clear ${resultid}) exten => *1234,n,MYSQL(Disconnect ${connid}) exten => *1234,n,Playback(goodbye) exten => *1234,n,Hangup exten => *1236,1,Answer
1 of 4
18/05/2011 12:02
http://fonality.com/trixbox/forums/trixbox-forums/help/change-extension-c...
morpion
Posts: 23 Member Since: 2009-08-10
Where I got to
Tue, 03/30/2010 - 12:57am
What I had done is to create a webpage on our internal system which logged into the sip table of the Asterisk database on trixbox. The webpage altered the context setting for the extension in the MySQL database. Unfortunately I can't work out how to reload the trixbox settings (like clicking on the Apply configuration changes button) using the asterisk manager. I've tried loads of combinations of reload and restart but it never seems to refresh the extension data from the database. If I alter the context using my new webpage then it shows up as changed on the extension page of trixbox and it applies the change when I click on Apply configuration changes but I wanted to do that automatically once our web page had updated the database. regards Mike -Newbie but lovin' it!
Login or register to post comments
morpion
Posts: 23 Member Since: 2009-08-10
Well here is what I've done now which is a mix of my earlier idea and the Fireman's suggestion (thank you). Extensions who are going to be switchable are given the default context of [frominternal-rooms]. In the extensions_custom.conf I have added the following: [from-internal-rooms] ; Default context for rooms allows switching on and off for external calls ; Allow the following calls exten => _XXXX,1,Goto(from-internal-rooms-dial,${EXTEN},1) ; Allow internal calls exten => 0,1,Goto(from-internal-rooms-dial,${EXTEN},1) ; Allow internal operator calls exten => _999,1,Goto(from-internal-rooms-dial,${EXTEN},1) ; Allow emergency calls exten => _911,1,Goto(from-internal-rooms-dial,${EXTEN},1) ; Allow emergency calls exten => _112,1,Goto(from-internal-rooms-dial,${EXTEN},1) ; Allow emergency calls ; Check other calls exten => _X.,1,Goto(from-internal-rooms-check,${EXTEN},1) ; Check all other calls [from-internal-rooms-check] exten => _X.,1,NoOp(from-internal-rooms-check ${EXTEN}) ;check database of blocked extensions exten => _X.,n,MYSQL(Connect connid localhost root passw0rd asterisk) exten => _X.,n,MYSQL(Query resultid ${connid} SELECT\ extension\ FROM\ blocked\ WHERE\ extension=\'${CALLERID(num)}\'\ AND\ blocked='1'\ LIMIT\ 1) exten => _X.,n,MYSQL(Fetch fetchid ${resultid}) exten => _X.,n,NoOp(FetchID - ${fetchid}) exten => _X.,n,MYSQL(Clear ${resultid}) exten => _X.,n,MYSQL(Disconnect ${connid}) ;If extension is shown as blocked then playback message and hangup exten => _X.,n,ExecIf($[${fetchid}]|Playback|im-sorry) exten => _X.,n,ExecIf($[${fetchid}]|Playback|the-number-u-dialed) exten => _X.,n,ExecIf($[${fetchid}]|Playback|is) exten => _X.,n,ExecIf($[${fetchid}]|Playback|unavailable) exten => _X.,n,ExecIf($[${fetchid}]|Hangup) ;If not blocked then pass to dialing context exten => _X.,n,Goto(from-internal-rooms-dial,${EXTEN},1) ; dial out [from-internal-rooms-dial] ;Not blocked so pass to internal transfer to dial out as normal include => from-internal-xfer
Copyright 2010 Fonality Trademark Policy. Privacy Policy. Asterisk is a trademark of Digium, Inc. Fonality and trixbox are not affiliated with, nor endorsed by Digium, Inc.
2 of 4
18/05/2011 12:02
http://fonality.com/trixbox/forums/trixbox-forums/help/change-extension-c...
pbillx
Posts: 8 Member Since: 2008-08-03
Nice so far
Mon, 04/05/2010 - 11:04am
.... But then we have a small problem: The cdr records this call as answered and you have one billsec. i have done it in a other way: - change in the database the extension to ext-local - run retrieve_conf (in /var/lib/asterisk/bin) with php -q retrieve_conf - and reload the extensions So you don't need a special block table, you can use direct the database of the asterisk. Here a php script for this: <? $phonevar=$_GET['PhoneNumber']; $blockvar=$_GET['blocked']; $connection = @mysql_connect("localhost","root","passw0rd"); if (!$connection) { echo "error"; exit; } if ($blockvar <> "0") { $qryString = "UPDATE sip SET data='from-internal' WHERE id= $phonevar and keyword='context'"; } else { $qryString = "UPDATE sip SET data='ext-local' WHERE id= $phonevar and keyword='context'"; } $resultofqry = mysql_db_query("asterisk",$qryString,$connection); system("php -q retrieve_conf"); system("/usr/sbin/asterisk -rx " . escapeshellarg("sip reload")); echo $resultofqry; ?> you have to copy retrieve_conf and libfreepbx.confgen.php to the place where you place your php file to make it accessible. In this way the context will really be changed. If you name your php file i.e. block.php, then you can call in IExplore: http:///block.php?PhoneNumber=&blocked=<0 or 1> and it is changing the context. -Fred Montero www.pbillx.org
Login or register to post comments
pbillx
Posts: 8 Member Since: 2008-08-03
<?php function String2File($sIn, $sFileOut) { $mystring=$sIn; $handle = fopen($sFileOut, "w"); echo $handle; if (fwrite($handle, $mystring) === FALSE) { echo "Cannot write to file ($filename)"; } else { echo "written"; } echo fclose($handle); } function updateconffile ($filename,$sctSearch,$toRemove,$toInsert) { $myfile=$filename; $buffer=""; $Sectionfound="0";
3 of 4
18/05/2011 12:02
http://fonality.com/trixbox/forums/trixbox-forums/help/change-extension-c...
morpion
Posts: 23 Member Since: 2009-08-10
Thanks for your hard work chaps. I'll give it a go. Mike -Newbie but lovin' it!
Login or register to post comments
osek2112
Posts: 1 Member Since: 2011-01-28
Thanks
Fri, 01/28/2011 - 9:21am
Thanks for the code I used it and it works perfectly. But I have a question: This works in pure Asterisk? I mean, with another contexts. I have this in extensions.conf ;Contexto para los usuarios [bloqueo] include => anexos [gerentes] include => anexos include => conferencia-general include => conferencia-gerencia include => usa-canada include => international include => celular-g include => fijo-ldn-g include => fijo-local-g include => usa-tollfree I want to block outgoing lines at night and only works [bloqueo] just to call inside the office and then unblock in the morning using [gerentes] I'm new at this so I appreciate your help. Thanks in advance.
Login or register to post comments
Select your preferred way to display the comments and click "Save settings" to activate your changes.
4 of 4
18/05/2011 12:02