How to use asterisk Include statement the right way? - include

I'm new to asterisk, and I have an issue about using include statement.
I have a context named "app-calltrace-perform" from FreePBX, used when people press *69 to trace their call.
[app-calltrace-perform]
include => app-calltrace-perform-custom
exten => s,1,Answer
...
exten => t,n,Macro(hangupcall,)
The "app-calltrace-perform" written in extensions_additional.conf which will be overwritten when users submit something about dialplan on the Web gui. So I have to write my own context "app-calltrace-perform-custom" on another file called extensions_custom.conf
[app-calltrace-perform-custom]
exten => s,1,Answer()
same => n,VERBOSE("Something here")
same => n,Playback(hello-world)
same => n,Hangup()
Note that extensions_additional.conf and extensions_custom.conf was already included from extensions.conf
Then I do dialplan reload and try again, but dialplan do not play my context at all (no verbose, no play hello-world).
I've found something useful in https://wiki.asterisk.org/wiki/display/AST/Include+Statements+Basics
Asterisk will always try to find a matching extension in the current context first, and only follow the include statement to a new context if there isn't anything that matches in the current context.
So now I dont know how to use my custom context for stuffs like this. Sorry if this a dumb question, but if you have any idea, pleas guide me through.
Edit
This is where app-calltrace-perform called from
[app-calltrace]
include => app-calltrace-custom
exten => *69,1,Goto(app-calltrace-perform,s,1)
Now i'm using another extension (*12345) defined in context app-calltrace-custom, It works well but is hard coded so cannot modified by the Web Gui
End Edit
Thanks in advance
Loi Dang

Asterisk dialplan matching work this way
[context1]
exten => 1,1,Noop(1)
include =>context2
include =>context3
exten => i,1,Noop(invalid extension)
[context2]
exten => 1,1,Noop(2)
exten => 2,1,Noop(3)
[context3]
exten => 1,1,Noop(4)
exten => 2,1,Noop(5)
exten => _X,1,Noop(other)
Let's say you call context1
when called 1 will be selected command from context1, becuase it EXIST in context. Same if you use wildcard.
When called 2 will be selected 2 from context2, first included context
When called any other number (for example 3) will be selected "other" in context3(becuase it not presented in context nor in prevous included context)
If called 12 which not present in any contextes, will be execute "invalid" extension

You'll need to have something that's distinguishing in your included context in order for the dialplan to know to use it. Since you've used the s extension in both, it uses the matching extension in the current context, first. As you've found in the documentation.
The s extension is the "start" extension, and used when there's no known dialed extension.
First, double check your file include is in the [globals] context in extensions.conf
[globals]
#include extensions_custom.conf
Then, include as you have done:
[app-calltrace-perform]
include => app-calltrace-perform-custom
exten => s,1,Answer
same => n,Noop(Testing 1234)
same => n,Hangup()
But, you need something differentiating in your included context. So for example:
[app-calltrace-perform-custom]
exten => *69,1,Answer()
same => n,Playback(hello-world)
same => n,Hangup()
So if you have a device that uses the [app-calltrace-perform] and they dial *69, they'll be subject to the [app-calltrace-perform-custom] extension.
Also, it's considered good practice to have a Hangup() ending each included context as you've done (good job). In order to prevent a possible mistake resulting in toll-fraud. Just wanted to note that for future stackoverflowers.

Related

How to increase CakePHP Debugger maximum depth

I'm trying to debug my program by logging information from an ajax call. This is something that doesn't render a view, just runs asynchronously. The log will only display arrays to a depth of 3, and the documentation doesn't seem to have any notion that someone might want more information than that.
Please, how do I increase this depth so I can have access to this information without finding weird ways to render my ajax call? Or, if doing this isn't the "Cake" way, is there a better way to output info to a log or console for debugging?
I think this is not the case of CakePHP but an issue with XDebug or PHP configuration itself. You can try to add this line to your php.ini
xdebug.var_display_max_depth = 5
It works if you debug with var_dump(). You should write how do you try to debug, bacause different methods depends on different mechanisms.
If it doesn't work you can try to make the Cake to display original PHP error messages instead of its own error handler messages. In your core.php find code like this:
Configure::write('Error', array(
'handler' => 'displayErrorWithoutCrap',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
And change it into this:
Configure::write('Error', array(
//'handler' => 'ErrorHandler::handleError',
'handler' => 'displayErrorWithoutCrap',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
and add this line at the end of bootstrap.php :
function displayErrorWithoutCrap() {
return false;
}
I ended up submitting a ticket to the Git project for CakePHP and it was confirmed that the debug depth for arrays is hard-coded for log files. The response indicated that it would be considered for a change in the next version.
I ended up finding the number in the Debug class and changed it to a larger number which gave me more depth. Not the best fix, but it works for now until support is added to the next version.

How to use translations in Yii console application?

I have created a console Yii application that works as a background worker for a web app - it sends out emails and it needs to send them with translated messages.
For some reason however, the messages are not translated when using Yii::t
If I set the language to something else than english with Yii::app->setLanguage('et_ee'), and check that it is really changed with Yii::app->getLanguage() the texts are always in english.
When I run this same command from web, the texts are correctly translated.
I guess there must be something special I have to do for the translatiosn to work in a console application?
I have this error to. I dont know how is fix it. I am get lang array trow require('path/to/message/ru/message.php') in to var and use it. It is wrong, but it is work for me.
You need to specify the messages component in your console.php configuration
'messages' => array(
'class' => 'CDbMessageSource',
'forceTranslation'=>true,
'sourceMessageTable' => 'source_message',
'translatedMessageTable' => 'translated_message',
),
Just add string (For example - russian languages):
'language' => 'ru'
in config/console.php.

How to do atomic update in Mongo/Mongomatic?

I'm having an awfully difficult time figuring out how to update a MongoDB document, using the atomic '$set' operator with Mongomatic. I'm pretty sure it's Mongo's criteria/update language I'm having troubles with, not Mongomatic, but I'm willing to be proven wrong.
The link to a gist with a standalone, runnable script is here: https://gist.github.com/3835672
I'm starting out by creating a document that looks like this:
{"videos":[{"video_id":"video1"},{"video_id":"video2"}],"_id":{"$oid": "506ddd53a114604ce3000001"}}
I can get that document using a model instantiated using Mongomatic:
video_group = VideoGroup.find_one('videos.video_id' => 'video1')
Then I'm trying to set a 'views' field, by doing this:
video_group.update!({ 'videos.video_id' => 'video1' }, '$set' => { 'videos.$.views' => 123 })
That's where Mongo blows up, with the following error:
can't append to array using string field name [$]
I know this is a very common question on StackOverflow. I understand generally that the problem is that the positional operator isn't getting any matches. But even reading through dozens of responses, I still can't figure out how to express this statement in a way that works.
Am I just starting out with the wrong data structure?
It is, in fact, a mongomatic problem. You need to pass the underlying mongo ruby driver the option {:multi => true}, as well as including your criteria with the specific _id for the update sent to mongodb instead of as part of the optional parameters. Looks like a bug in mongomatic. Here is the ruby debugger transcript that I used to find it: https://gist.github.com/3836797
Note that I made a change to the file you posted, adding the line debugger before line #41, and changing line #42-44 to this:
video_group.update!({ 'videos.video_id' => 'video1', :multi => true }, '$set' => {
'videos.$.views' => 123,
})

How can I create a Rails 3 route that will match all requests and direct to one resource / page?

I have a rails app (Rails 3.0) that I need to temporarily take out of service. While this is in effect, I want to create a new route that will direct all requests to a single piece of static content. I have a controller set up to serve my static pages.
I tried something like this:
match '*' => 'content#holding'
and
match '*/*' => 'content#holding'
to match a wildcard route as described here:Rails 3 route globbing without success.
This is probably a really simple answer, but I couldn't figure it out.
/EDIT/
Forgot to mention that I did have this rule at the very top of my routes.rb file.
Rails needs to bind the url parameters to a variable, try this:
match '*foo' => 'content#holding'
If you also want to match /, use parenthesis to specify that foo is optional:
match '(*foo)' => 'content#holding'
I did this just yesterday and first came up with the solution that klochner shows.
What I didn't like about this is the fact that whatever you enter in the URL, stays there after the page loads, and since I wanted a catch all route that redirects to my root_url, that wasn't very appealing.
What I came up with looks like this:
# in routes.rb
get '*ignore_me' => 'site#unknown_url'
# in SiteController
def unknown_url
redirect_to root_url
end
Remember to stick the routes entry at the very bottom of the file!
EDIT:
As Nick pointed out, you can also do the redirect directly in the routes file.
I ran into something like this where I had domain names as a parameter in my route:
match '/:domain_name/', :to => 'sitedetails#index', :domain_name => /.*/, :as =>'sitedetails'
The key piece to this was the /.*/ which was a wildcard for pretty much anything. So maybe you could do something like:
match '/:path/', :to => 'content#holding', :path=> /.*/, :as =>'whatever_you_want'
Where in "routes.rb" is this line located?
To have priority over other routes, it has to be placed first.
As an alternative, you can look into this: http://onehub.com/blog/posts/rails-maintenance-pages-done-right/
Or this: Rails: admin-only maintenance mode

Rails redirecting invalid route to root

If my website is www.foo.com if the user types www.foo.com/blahblahblah it will say that /blahblahblah is an invalid path (obviously). But I want it instead to redirect to the root_path so that the controller can process the URL -- the page www.foo.com should be rendered I want to pull the text blahblahblah and do something with it. How do I do this?
There are several possibilities. Here's one. You could add this to the bottom of your routes.rb:
match ':not_found' => 'my_controller#index',
:constraints => { :not_found => /.*/ }
which will establish a catch-all route to make MyController's index action handle any missing paths; it can detect them by looking at params[:not_found] and doing whatever it wants, such as redirecting to the root_path (redirect_to root_url), redirecting somewhere strategically based on the bad path, rendering something special, examining the referrer/referer for clues about the source, etc.
The :constraints option is necessary; otherwise the not_found param won't be able to contain special characters like slashes and dots.
Put this at the bottom of your routes because, obviously, it will match everything, and you want to give your other routes first crack at the path.
If you only want to redirect, nothing more, you could do this instead (again, at the bottom):
match ':not_found' => redirect('/'), :constraints => { :not_found => /.*/ }
in rails 4
get '*path' => redirect('/')

Resources