get the number dial by Caller - voip

I have asterisk server with assign a common voip number f.ex.:
- 48221111111
- 48222222222
How can i check/detect (in extension.conf) which number from this two above, the Caller dial to connect with my asterisk server?

You can use ${EXTEN} for that purpose or if in macro you can use ${MACRO_EXTEN}:
[macro-incoming_VOIP]
exten = s,1,LookupBlacklist(j)
exten = s,2,GotoIf( ${MACRO_EXTEN} = 48221111111?3:4)
exten = s,3,Goto(from-outside|24|1)
exten = s,4,Macro(timecondition,voicemenu-custom-1|660|1,voicemenu-custom-1|660|1)
exten = s,102,Goto(Blacklist-Handle,s,1)
If you execute a Macro than the calling extension, context, and priority are stored in ${MACRO_EXTEN}, ${MACRO_CONTEXT} and ${MACRO_PRIORITY} respectively.

Related

Accessing routing table from agent to get next hop

I've set up my routing algorithm from node itself. After this I want to send datagrams from physical layer in that route itself.
For example if my routes are 1 to 2 and 2 to 3 and I want to send a datagram from 1 to 3 I want my datagram to go through 2.
For this routing table for 1 will be as follows:
Routing table for 1
to: 3 nextHop: 2
to: 2 nextHop: 2
to: 1 nextHop: 1
So I want my process msg function to be as follows:
void processMessage(Message msg) {
if (msg instanceof DatagramNtf && msg.protocol == PING_PROTOCOL && msg.to != nodeInfo.addr)
def dG = new DatagramReq(to: routes.nextHop(msg.to), destination: msg.to)
send new DatagramReq(recipient: msg.sender, to: msg.from, protocol: Protocol.DATA)
}
also what routes.nextHop does is takes in the addr of the destination node and from the routing table gets the next hop.
I want to know to how to get the nextHop from routing table.
To send datagrams using route table entries, you need to use router agent, which inturn uses link and phy agents to send your datagram to the destination.Further routing of packets to the destination will be taken care by router agent itself.Hence I don't think you need to determine nextHop here for the to field in DatagramReq.
Your DatagramReq can be as-
router.send new DatagramReq(recipient: msg.sender, to: msg.from, protocol: Protocol.DATA)
Assuming router is the AgentID defined, and value of msg.from is your destination, and there is a valid route in the route table.
Further, nextHop or getNextHop() returns the address of neighbor node.

JS Puppeteer: enter multiple chars atomically

I'm trying to fill an html form with puppeteer using type. According to the docs:
page.type(selector, text[, options])
...
Sends a keydown, keypress/input, and keyup event for each character in the text.
I have an issue with other events interfering with my typing process. How can I type my text atomically? I.e. with a single keydown event?
you can do, page.keyboard.sendCharacter("text"), which will do something akin to pasting in the text all at once. Make sure to first focus the selector you want to type into.
await page.focus('selector');
await page.keyboard.sendCharacter('text');
I don't know if it fits your needs but if you want to avoid keyboard events you could set directly the input value
await page.evaluate(() => document.querySelector("YOUR_SELECTOR").value = "Puppeteer");
or, if you need just one keydown event, you can trick Puppeteer by setting the value to "almost" what you need
await page.evaluate(() => document.querySelector("YOUR_SELECTOR").value = "Puppetee");
and use type just for the last char
await page.type("YOUR_SELECTOR", "r");

Trying to delete "left_chat_member" messages with a Telegram Bot

I'm trying perform the following actions with a Telegram Bot:
When a user.first_name matches a regex:
Delete "join" message.
Kick user from the chat.
Delete "left" message.
The problem is that I don't know how to get the message.id for the "left" message since:
KickChatMember method does not return a message object, only true or false.
The sent message which contains left_chat_member has user.from set to the member who kicks (In this case, the bot itself).
A bot can't receive updates for his own message, so the previous message is not received.
So the question is:
Is possible to obtain the message.id for the message containing left_chat_member when is sent by the bot itself? Is there any other way to achieve this?
Maybe I could try to infer the message.id but I don't know if this would be possible or recommended.
A possible approximation, that emerged from a conversation with #eyaadh at https://t.me/BotTalk is:
When a new_chat_members happens, you have an message_id (let's say A)
Execute kick_chat_member (missing message_id)
And sent a message (arbitrary), you have an message_id (let's say B)
(step one is optional)
The message produced by kick_chat_member is B-1, with little probability that another message has entered right in the middle, that if the step 2 and 3 must go together in the code to reduce as much as possible the time between them.
And the A message serves to know the smallest id. In other words, the id in question is between A and B (guaranteed). If A + 2 is equal to B the message is B-1 (or A+1) guaranteed. Otherwise, there would be no certainty.
In my opinion left_chat_member should send the message to the bot that generates the output, with that the problem would be solved, or the execution of kick_chat_member should return that info.
A solution
When a new_chat_members is launched in the function that manages it, can do the following (three IDs will be used, id1, id2 and id3):
id1 is the identifier of the join message (the one that comes with new_chat_members).
Then kick_chat_member is executed (this generates the message that the ID is not known, id2).
(If the user was deleted) Any message is sent with sendMessage that will give us the id3.
Then we loop from id3 - 1 to id1 + 1 (including both): for each id in this loop we send a "message in response" with sendMessage (using in the reply_to_message_id parameter the id of the loop) and we check if the message that is generated contains in its parameter reply_to_message.left_chat_member the id of the user that we are deleting, if it is affirmative it is the message that we want to eliminate (eliminate, it is id2), at the end of the cycle we eliminate the "message in response" as well (the id for each step loop).
When the for cycle ends, we eliminate the messages with id1 and id3.
In this way the input and output (kicked) message is eliminated with total certainty, regardless of whether other messages appear between.
I tested it by putting a wait of 3 seconds between each action in the bot and writing in the group (while the bot went step by step).
Example in Python
https://github.com/schcriher/welcome-tg-bot/commit/0e4dbaa9cbff5272d682899b1433ff2b3c750a74
In summary: all the messages are answered (reply), from id3 - 1 to id1 + 1, and it is searched which contains the left_chat_member with the user id that has been kicked.
UPDATE
Now the bot gets the service message when kicked a member. It is enough to analyze if the exit message is issued by the bot, if so it is a kick to a member of the bot.
Try this codes in NodeJs
let TelegramBot = require('node-telegram-bot-api');
let bot = new TelegramBot(token, {polling: true});
let regex = 'givenUser'; /* Part of the user first name that you wanna kick him out*/
bot.on('new_chat_members', (data) => newMembers(data));
bot.on('left_chat_member', (data) => leftMember(data));
function newMembers(data) {
let chatId = data.chat.id;
let msgId = data.message_id;
let userId = data.new_chat_member.id;
let firstName = data.new_chat_member.first_name;
if (firstName.includes(regex)) {
bot.deleteMessage(chatId, msgId).catch(e => console.log(e));
bot.kickChatMember(chatId, userId).catch(e => console.log(e));
}
}
function leftMember(data) {
let chatId = data.chat.id;
let msgId = data.message_id;
let firstName = data.left_chat_member.first_name;
if (firstName.includes(regex)) {
bot.deleteMessage(chatId, msgId).catch(e => console.log(e));
}
}

Reusableforms Set from email to posted email

I have implemented Reusableforms on my site, everything is working fine apart from when I view received emails in the client, the emails are always from 'contact form' with the email 'forms#domain.com'.
How can I change this to display the senders name and email that is posted via the form? Here is the code from the handler.php included with reusableforms.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['Name','Email'])->areRequired()->maxLength(50);
$validator->field('Email')->isEmail();
$validator->field('Message')->maxLength(6000);
$pp->requireReCaptcha();
$pp->getReCaptcha()->initSecretKey('0000000000000000000000000000000');
$pp->sendEmailTo('orders#domain'); // ← Your email here
echo $pp->process($_POST);
I too been looking for help on this very subject.
I have got this to work - by chance - by having two instances of
'$pp = new FormHandler();'.
See my version of the code below.
I do not understand why it works.
<?php
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
/* The next 7 lines must be in this 1st section */
$mailer = $pp->getMailer();
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->SMTPSecure ="ssl";
$mailer->Host = "serverxxx.xxxx.com";
$mailer->Username = "contact#xxxxxxx.com";
$mailer->Password = "xxxxxxxxxxxxxx";
/* The next 2 lines work whether in the 1st or 2nd section */
$pp->requireReCaptcha();
$pp->getReCaptcha()->initSecretKey('xxxxxxxxxxxx');
/* Section 2
I do not understand it, but without the 2nd '$pp = new FormHandler()' below,
the SMTP send fails. The reported error is:
Sorry there was an error sending your form.
mail:SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I have tested changing the 2nd $pp to $pp2 and it also works.
*/
$pp = new FormHandler();
/* The next line has to be in this 2nd section.
If it is the last line in top section then it appears to be sent OK
but the email does not actually arrive.
Checking the SMTP logs shows it was never sent.*/
$pp->sendEmailTo(['leslie#xxxxxxxxxxx.com']);
/* The next 2 lines also must be here rather than in 1st section above. */
$mailer = $pp->getMailer();
$mailer->setFrom('contact#xxxxxxx.com','xxxxxxx Contact Form');
echo $pp->process($_POST);
To send a reply to the user email address on a ReusableForm, you'll need to get the value from the handler.php and add that to FormHandler.php above the 'setFrom' function using the addReplyTo function & $_POST global variable:
$this->mailer->addReplyTo($_POST['Email']);
$this->mailer->setFrom($from_email,'Contact Form',false);
These forms still work well in 2021 using PHP 7.3

how to order freeradius attributes

I am configuring Freeradius. Input message is Access-Request with Proxy-State = 3134
Freeradius succesfully performs authentication but he places Proxy-State at the bottom of Access-Accept. How can I canfigure that Freeradius places Framed-IP-Address at the bottom of the message?
It tried to configure "users" as:
381603854966 Auth-Type := Accept, User-Password == "123456"
Service-Type = Framed-User,
Framed-Protocol = PPP,
Framed-IP-Netmask = 255.255.255.0,
User-Name = 381603854966,
Framed-IP-Address = 10.10.40.22,
but without success - freeradius still puts Proxy-State and the bottom of Access-Accept. I also tried to configure policy.txt file like:
if (User-Name == "381603854966") {
reply .= {
Framed-IP-Address += "10.10.40.22"
}
}
I also tried this in policy.txt:
reply .= {
Framed-IP-Address = 10.10.40.22
}
didn't work. Anybody knows how can I place certain attribute at the bottom of the message?
Thank you, Mark
You can't. The server will add Proxy-State to the request before forwarding it upstream, and it'll always add it at the end of the list of attributes.
RFC 2865 section 5 states:
If multiple Attributes with the same Type are present, the order of
Attributes with the same Type MUST be preserved by any proxies. The
order of Attributes of different Types is not required to be
preserved. A RADIUS server or client MUST NOT have any dependencies
on the order of attributes of different types. A RADIUS server or
client MUST NOT require attributes of the same type to be contiguous.
If your application requires ordering of attributes of different types, it's not implementing the RADIUS protocol correctly and should be fixed.

Resources