Skip to content

Commit

Permalink
Nice version now with custom contexts others can hook into. If a numb…
Browse files Browse the repository at this point in the history
…er is found we go to our own context then off to the hangup macro. Feels right.
  • Loading branch information
ghenry committed Feb 27, 2023
1 parent cb6e75a commit 7600dde
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ You can sign up for a free SentryPeer account at https://sentrypeer.com
![SentryPeer Module Menu](https://raw.githubusercontent.com/SentryPeer/SentryPeer-FreePBX-Module/main/assets/img/Screenshot%20from%202023-02-23%2021-38-23.png)
![SentryPeer Module Main Screen](https://raw.githubusercontent.com/SentryPeer/SentryPeer-FreePBX-Module/main/assets/img/Screenshot%20from%202023-02-23%2021-38-44.png)

### To Do

Add options to the SentryPeer module configuration page to allow the user to select the following actions when a number is found to be malicious:

1. [ ] Hangup
2. [ ] Play a message (from Recordings)
3. [ ] Send email

### Trademark

[**SENTRYPEER** is a registered trademark](https://trademarks.ipo.gov.uk/ipo-tmcase/page/Results/1/UK00003700947) of Gavin Henry
Expand Down
11 changes: 9 additions & 2 deletions Sentrypeer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ public function doDialplanHook(&$ext, $engine, $priority)
}
if ($dial_macro_exists) {
// splice - https://wiki.freepbx.org/pages/viewpage.action?pageId=98701336
$ext->splice($context, $exten, "gocall", new \ext_noop('Checking ${DIAL_NUMBER} with SentryPeer'), "", 1);
$ext->splice($context, $exten, "gocall", new \ext_agi('sentrypeer.php, ${DIAL_NUMBER}'), "", 2);
$ext->splice($context, $exten, '', new \ext_set('ORIGINAL_NUM_FOR_SENTRYPEER', '${ARG2}'), "", 1);
$ext->splice($context, $exten, "gocall", new \ext_noop('Checking ${ORIGINAL_NUM_FOR_SENTRYPEER} with SentryPeer'), "", 1);
$ext->splice($context, $exten, "gocall", new \ext_agi('sentrypeer.php, ${ORIGINAL_NUM_FOR_SENTRYPEER}'), "", 2);
$ext->splice($context, $exten, "gocall", new \ext_noop('SentryPeer Finished'), "", 3);

// Add our own custom context so others can hook into it via extensions_custom.conf
$ext->addInclude('macro-dialout-trunk', 'sentrypeer-context', 'For the SentryPeer service - https://sentypeer.com'); // Add the context to from-internal
$mcontext = 'sentrypeer-context';
$ext->add($mcontext, $exten, '', new \ext_noop('Number found on in the SentryPeer database. Hanging up the call.'));
$ext->add($mcontext, $exten, '', new \ext_goto('1', 'h', 'macro-dialout-trunk'));
}
}

Expand Down
12 changes: 5 additions & 7 deletions agi-bin/sentrypeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

if ($res_code == 404) {
$agi->verbose("SentryPeer API call res code is 404. Number not seen before. Allowing the call.");
exit(0);
} elseif ($res_code == 401) {
$agi->verbose("SentryPeer API call res code is 401. Getting a new Bearer token.");

Expand All @@ -40,19 +39,18 @@

if ($res_code == 404) {
$agi->verbose("SentryPeer has not seen this number before. Allowing the call.");
exit(0);
} else {
$agi->verbose("SentryPeer has seen this number before. Halting call.");
exit(1);
$agi->verbose("SentryPeer has seen this number before. Hanging up the call.");
$agi->goto_dest('sentrypeer-context', 's', 1);
}
} else {
$agi->verbose("SentryPeer Bearer token is still empty. Aborting.");
exit(1);
}
} else {
$agi->verbose("SentryPeer has seen this number before. Halting call.");
exit(1);
$agi->goto_dest('sentrypeer-context', 's', 1);
}
exit(0);

function checkPhoneNumber($sentrypeer, $agi, $phone_number_to_check)
{
Expand All @@ -65,7 +63,7 @@ function checkPhoneNumber($sentrypeer, $agi, $phone_number_to_check)
$agi->verbose("SentryPeer Bearer token is now set.");
} else {
$agi->verbose("SentryPeer Bearer token is still empty. Aborting.");
exit(1);
exit(0);
}
}

Expand Down

0 comments on commit 7600dde

Please sign in to comment.