Opensips 2.1 SIP Trunk configuration - trunk

I'm ahmed and I'm working on opensips.
Actually, I sow your questions on the forum and I have a problem that I think you have the answer.
Actually, I did a simple senario to route calls between users registered in opensips server, but when it comes to real IP phones( that each one has its own ip address ), it doasn't work. ( trunk ).
for example: my opensips address: 10.42.15.18
and my IP phone address is : 10.42.13.82
it is all about sip trunk I think.
I am blocked in this part and searched a lot for a solution, maybe there is a detail that I have missed.
which function is responsible for handling requests and responses with an IP phone ?
I used this code :
account only INVITEs
if ($rU=="49894614950666"){
$rU = $tU;
rewritehostport("10.42.13.82:5060");
$du = "sip:49894614950666#10.42.13.82;user=phone";
t_relay();
xlog("reference to URI of 'To' header ====> $tu");
xlog("reference to domain in URI of 'TO' header ====> $td");
# route the call out based on RURI
route(3);
}
route[3]{
seturi("sip:49894614950666#10.42.13.82;user=phone");
$du = "sip:49894614950666#10.42.13.82;user=phone";
rewriteuri("sip:49894614950666#10.42.13.82;user=phone");
xlog("route 2 : forwarding to $tU \n $ruri \n");
xlog("Received $rm from $fu (callid: $ci)\n");
forward();
if (is_method("INVITE")) {
t_on_branch("2");
t_on_reply("2");
t_on_failure("1");
}
if (!t_relay()) {
sl_reply_error();
};
exit;
}
When calling from a soft phone the requested number, the server sends a request INVITE as follow :
INVITE sip:49894614950666#10.42.15.18;transport=TCP SIP/2.0
Via: SIP/2.0/TCP 10.42.15.12:5060;branch=z9hG4bK-524287-1---dedd27ee7475c0f1
Max-Forwards: 70
Contact: <sip:test11#10.42.15.12:5060;transport=tcp>
To: <sip:49894614950666#10.42.15.18;transport=TCP>
From: <sip:test11#10.42.15.18;transport=TCP>;tag=2f025b44
Call-ID: tdO14DnlADH9Okx6Sr0p4A..
CSeq: 1 INVITE
Content-Type: application/sdp
User-Agent: Z 3.15.40006 rv2.8.20
Allow-Events: presence, kpml, talk
Content-Length: 237
and the target VM resend an INVITE request to Opensips server, but then, the server start to send to himself messages and not responding the target machine...
I wonder that the "To" field in the INVITE message is false !
opensips only sends a invite to the IP phone and ignore messages coming from it, does not respond after with any ack.
what should I add or modify ?
thank you a lot.

Why just not using lookup function ? It intended exactly for cases like your and will do all duty work in rewriting URI's automatically.
Something like that :
if (lookup("location","m")) {
xlog("[INCOMINGCALL][$rU # $si:$sp ] Forward call call to <$ru> via <$du>\n");
if (!t_relay()) {
send_reply("503","Internal Error");
};
exit;
}
t_reply("404", "Not Found");
exit;
The advantage of this technique you will be able to change locations at run time using 'opensipsctl address' command

Related

Erlang SMTP client WITH attachments

I'm looking for one of two things:
An Erlang library that supports sending of emails with attachments
An example of using gen_smtp to send an email with an attachment, since I have already successfully sent emails with this library
It seems there is very little in the way of SMTP client support with attachments out there, although there are plenty of modules that can send plain text emails via SMTP. Anyone have suggestions?
Also, using Windows - I'm not sure the sendmail route is available?
Agus, when I try that exact code, as well as similar code, I keep getting the following error, any ideas?:
** exception error: {badmap,[]}
in function maps:get/3
called as maps:get(content_type_params,[],[])
in call from mimemail:ensure_content_headers/7 (c:/temp/erlang/myapp/_build/default/lib/gen_smtp/src/mimemail.erl, line 667)
in call from mimemail:encode/2 (c:/temp/erlang/myapp/_build/default/lib/gen_smtp/src/mimemail.erl, line 161)
in call from email_test:send_email_with_attachment/0 (c:/temp/erlang/myapp/src/email_test.erl, line 14)
The version of gen_smtp I'm using in rebar.config:
{gen_smtp, ".*", {git, "git://github.com/gen-smtp/gen_smtp.git", {branch, master}}}
Short answer: you can use gen_smtp to send an email with attachment.
If you have used gen_smtp_client:send(Email, Options) or gen_smtp_client:send_blocking(Email, Options), then you can actually generate the Body's Email variable using mimemail:encode/2.
%% #doc Encode a MIME tuple to a binary.
encode({Type, Subtype, Headers, ContentTypeParams, Parts}, Options) ->
...
Below code shows how to send message with email inline body and 2 attachments (test1.txt and erlang.png respectively). The key here is to use multipart/mixed MIME type and construct the email body accordingly.
send_email_with_attachment() ->
From = "noreply#mydomain.com",
ToList = ["target_email#mydomain.com"],
Part2Filename = "/tmp/test1.txt",
{ok, Part2Binary} = file:read_file(Part2Filename),
Part3Filename = "/tmp/erlang.png",
{ok, Part3Binary} = file:read_file(Part3Filename),
Email = mimemail:encode(
{
<<"multipart">>, %%Type,
<<"mixed">>, %%Subtype,
%%Headers,
[
{<<"From">>, <<"No-Reply <noreply#mydomain.com>">>},
{<<"To">>, <<"target_email#mydomain.com">>},
{<<"Subject">>, <<"Mail Subject">>}
],
#{}, %%[], %%ContentTypeParams,
%%(Multi)Parts
[
%%Part 1: this is the inline mail body, note the {<<"disposition">>, <<"inline">>} tag
{
<<"text">>, %%Type,
<<"plain">>, %%Subtype,
%%Headers
[],
%%ContentTypeParams
#{
disposition => <<"inline">>
},
%%Part
<<"Email body (inline) is here blah blah..">>
},
%%Part 2: this is the text file as attachment, note the {<<"disposition">>, <<"attachment">>} tag
{
<<"text">>, %%Type,
<<"plain">>, %%Subtype,
%%Headers
[],
%%ContentTypeParams
#{
disposition => <<"attachment">>,
disposition_params => [{<<"filename">>, <<"test1.txt">>}]
},
%%Part
Part2Binary
},
%%Part 3: this is the PNG file as attachment, note the {<<"disposition">>, <<"attachment">>} tag
{
<<"image">>, %%Type,
<<"png">>, %%Subtype,
%%Headers
[],
%%ContentTypeParams
#{
disposition => <<"attachment">>,
disposition_params => [{<<"filename">>, <<"erlang.png">>}]
},
%%Part
Part3Binary
}
]
},
[] %%Options
),
Opts = [{relay, "smtp.mydomain.com"},
{tls, never}
],
gen_smtp_client:send({From, ToList, Email}, Opts).
This is what you will see in the mailbox:

How to fix: "Operation returned an invalid status code 'BadRequest’" when connecting PowerBI Embedded to an SSAS Multidimensional cube

I have an (on premise) SSAS (Multidimensional) cube with a live connection to Power BI. Then it has to be shown in a portal with Power BI Embedded. I used the method: 'App owns data' and with a 'master user' account. This part works.
But when i try to add Row Level Security(RLS), it keeps giving errors. The report will be shown to customers (outside the organization). Based on their login (the authentication is held by the portal itself), they need to see their own data.
I tried to connect, using JSON script, adding username, roles, datasets and customdata.
The username contains the actual active directory username which has permissions within SSAS.
The customdata contains the part i want to filter.
The role 'Test' is currently made for testing purposes.
The role 'Test' is setup in SSAS with read permissions and the specific 'company' dimension is setup with the following 'Allowed member set':
STRTOMEMBER('[Dim Company].[BK_Company].&[{'+CUSTOMDATA()+'}]')
This is based on another topic which used this as the solution.
I have tried using USERNAME() to be the filter of RLS, but it seems I can only use actual accountnames in this field. Our current active directory doesn't hold all customer names in it.
var rls = new EffectiveIdentity(#"domain\powerbiportal", new List { report.DatasetId }, new List { "Test" }, "19164");
var tokenRequest = new GenerateTokenRequest("view", identities: new List { rls });
var tokenResponse = client.Reports.GenerateTokenInGroupAsync("[ID]", report.Id, tokenRequest).Result;
Sending JSON
{
"accessLevel": "view",
"identities": [
{
"username": "domain\\powerbiportal",
"roles": [
"Test"
],
"datasets": [
"[dataset]"
],
"customData": "19164"
}
]
}
The error i get is the following:
Operation returned an invalid status code 'BadRequest’
After contacting Microsoft Support the problem was fixed.
First the solution was to uncheck the box 'enable read permissions' in the 'cell data' tab of the role. The cell was empty in my case, but for some reason it still created the problem.
Secondly the statement to filter had to be:
{STRTOMEMBER('[Dim Company].[BK_Company].&[' + CUSTOMDATA() + ']')}
instead of
STRTOMEMBER('[Dim Company].[BK_Company].&[{'+CUSTOMDATA()+'}]')

active admin strong parameters failing

I am trying to create a record in active admin. My activeadmin is set up with this:
ActiveAdmin.register MyObject do
permit_params :all_my_params, :client_id
end
The form should be submitting the params as such:
{"utf8"=>"✓", "authenticity_token"=>"WnStZr//M1rBDSwNWSrZs2rvCmcpji/MKaLywxuf9oG0Ef3b1uojy5jszs3yHEYmpvjt+qtJrmi3jz3KKJgUCQ==", "MyObject"=>{"client_id"=>"1", "all_my_params"=>"something here"}, "commit"=>"Create My Object"}
However, the form submits with an extra client_id outside of the MyObject hash like so:
{"utf8"=>"✓", "authenticity_token"=>"WnStZr//M1rBDSwNWSrZs2rvCmcpji/MKaLywxuf9oG0Ef3b1uojy5jszs3yHEYmpvjt+qtJrmi3jz3KKJgUCQ==", "MyObject"=>{"client_id"=>"1", "all_my_params"=>"something here"}, "commit"=>"Create My Object", "client_id"=>"1"}
(notice the extra client_id)
This gives me an error:
unpermitted parameter: client_id
because it is not expected outside my MyObject hash.
How can I fix this? I've been stuck on this for days!
My relevant routes: batch_action_admin_client_wedding_cakes POST /admin/clients/:client_id/wedding_cakes/batch_action(.:format) admin/wedding_cakes#batch_action
admin_client_wedding_cakes GET /admin/clients/:client_id/wedding_cakes(.:format) admin/wedding_cakes#index
POST /admin/clients/:client_id/wedding_cakes(.:format) admin/wedding_cakes#create
new_admin_client_wedding_cake GET /admin/clients/:client_id/wedding_cakes/new(.:format) admin/wedding_cakes#new
edit_admin_client_wedding_cake GET /admin/clients/:client_id/wedding_cakes/:id/edit(.:format) admin/wedding_cakes#edit
admin_client_wedding_cake GET /admin/clients/:client_id/wedding_cakes/:id(.:format) admin/wedding_cakes#show
where wedding_cake = MyObject in my previous code.
In essence, the client_id that is parsed from the url automatically which would normally be accepted in a rails controller is not getting accepted in activeadmin and I have no way of making it permitted since I can only permit things that are inside the wedding cakes hash in my params.

R: extracting data from password secured site

I am trying to extract data from a password secured site thru R. I have tried many options. But I am getting only the HTML of non-login page even after passing login credentials. Here is one of my attempts:
loginurl ="https://login.recruit.naukri.com/"
dataurl = "http://resdex.naukri.com/search/setSrchSess? SRCHTYPE=ez&SRCH_INC_KEYWORD=XXX"
pars=list(username="XXX", password="XXX")
curl = getCurlHandle()
curlSetOpt(cookiejar="", useragent = agent, followlocation = TRUE, curl=curl)
html=postForm(loginurl, .params = pars, curl=curl)
html=getURL(dataurl, curl=curl)
Both htmls are same and they are HTML of non-login page.
The same is happening with others commands also.

Gathering information from a textfile. Corona SDK

Earlier I asked about gathering information from API-Link, and I have managed to get out most of the details by using the answar I got.
Now ny problem is when another API to get more information
This time the file will contain this information:
{
"username":"UserName",
"confirmed_rewards":"0",
"round_estimate":"0.00000000",
"total_hashrate":"0.000",
"payout_history":"0",
"round_shares":"0",
"workers":{
"UserName.1":{
"alive":"0",
"hashrate":"0.000"
},
"UserName.2":{
"alive":"0",
"hashrate":"0.000"
},
"UserName.3":{
"alive":"1",
"hashrate":"1517.540",
"last_share_timestamp":1369598007
},
"UserName.4":{
"alive":"0",
"hashrate":"0.000"
}
}
}
And I want to gather each of the workers and print them out. This "workers" could contain multiple information, but always start with "UserName.x", where the username come from the "username" paramter each time.
The numbers will always vary from 0 and up
I want to gether the information in the same way by accessing the document, and decode and print out all the workers, whatever the numbers of them are.
By using the script provided in my last question(look at the link in the start), i was thinking that it would be something like
local t = json.decode( txt )
print("Workers: ".. t["workers.UserName.1"])
But this was not the way.
Due to the username changing all the time, I was also thinking somthing like
print("Workers: ".. t["workers" .. "." .. "username" .. "." .. "1"])
From here I have no clue about how I should gather the information, even when the names and numbers vary
Thanks in advance
Here is the perfect solution:
local json = require "json"
local t = json.decode( jsonFile( "data.json" )
local workers = t.workers
for name, user in pairs(workers) do
print("--------------------")
print(name)
for tag, value in pairs(user) do
print(tag , value)
end
end
Here are some more info:
http://www.coronalabs.com/blog/2011/08/03/tutorial-exploring-json-usage-in-corona/
http://www.coronalabs.com/blog/2011/06/21/understanding-lua-tables-in-corona-sdk/
http://lua-users.org/wiki/TablesTutorial