mirror of
https://github.com/itflow-org/itflow
synced 2026-11-27 22:59:00 +00:00
Add phone system integration with FusionPBX: Admin Phone Systems with setup lines for mod_xml_cdr and mod_cidlookup, domains linked to clients with suggestions, a Calls page per client and contact with calls matched to contacts, Add to Ticket with talk time as time worked, and caller ID names from ITFlow on desk phones
This commit is contained in:
27
api/phone/cdr.php
Normal file
27
api/phone/cdr.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - call records from a phone system. FreeSWITCH's mod_xml_cdr posts each call's record
|
||||
* here as it hangs up - xml_cdr.conf.xml's url, as the system's setup window in Admin > Phone
|
||||
* Systems shows it, with log-http-and-disk so FusionPBX still imports its own. Each call is kept
|
||||
* once (phoneCallSave(), functions/phone.php): a record sent again puts it right. A second leg of a
|
||||
* call is taken and set aside - its first leg is the call. Anything that isn't a call record is
|
||||
* turned down (400), so FreeSWITCH keeps it in its error folder.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/phone_system.php';
|
||||
|
||||
$phone_cdr = phoneCdrParse(phoneCdrFromRequest());
|
||||
if (!$phone_cdr) {
|
||||
$phone_reply(400, 'No call record');
|
||||
}
|
||||
|
||||
// mod_xml_cdr names a leg with a_ or b_ in uuid when prefix-a-leg is on
|
||||
$phone_leg = (string) ($_REQUEST['uuid'] ?? '');
|
||||
if (str_starts_with($phone_leg, 'b_')) {
|
||||
$phone_cdr['b_leg'] = true;
|
||||
}
|
||||
|
||||
$phone_result = phoneCallSave($phone_system, $phone_cdr);
|
||||
|
||||
$phone_reply(200, $phone_result['saved'] ? 'OK' : 'OK - ' . $phone_result['why']);
|
||||
21
api/phone/cid.php
Normal file
21
api/phone/cid.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - caller ID names from a phone system's contacts. FreeSWITCH's mod_cidlookup asks here
|
||||
* as a call comes in (cidlookup.conf.xml's url, as the system's setup window shows it) and the
|
||||
* phone shows what it gets back: the contact and their client, the client for its main number,
|
||||
* nothing for a number nobody has (phoneCallerName(), functions/phone.php). With the call's
|
||||
* domain, a client's own domain only matches that client's contacts.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/phone_system.php';
|
||||
|
||||
$phone_number = phoneNumber($_GET['number'] ?? '');
|
||||
$phone_domain = phoneDomainName($_GET['domain'] ?? '');
|
||||
$phone_domain_client_id = 0;
|
||||
if ($phone_domain !== '') {
|
||||
$phone_domain_row = phoneDomain($phone_system, $phone_domain);
|
||||
$phone_domain_client_id = intval($phone_domain_row['phone_domain_client_id'] ?? 0);
|
||||
}
|
||||
|
||||
$phone_reply(200, $phone_number !== '' ? phoneCallerName($phone_number, $phone_domain_client_id) : '');
|
||||
41
api/phone/phone_system.php
Normal file
41
api/phone/phone_system.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - what every address under api/phone/ starts with: the phone system whose key came with
|
||||
* the request (functions/phone.php) as $phone_system. The key is the key field of the address, or
|
||||
* the password of HTTP Basic sign-in (mod_xml_cdr's cred, user:key). Without a known key there is
|
||||
* nothing here (404); a system that is turned off answers 503, so its sender knows.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../config.php';
|
||||
require_once __DIR__ . '/../../functions.php';
|
||||
require_once __DIR__ . '/../../includes/inc_set_timezone.php';
|
||||
require_once __DIR__ . '/../../includes/load_global_settings.php';
|
||||
|
||||
header('Cache-Control: no-store');
|
||||
|
||||
$phone_reply = function (int $status, string $text) {
|
||||
http_response_code($status);
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
echo $text;
|
||||
exit;
|
||||
};
|
||||
|
||||
// logAudit() reads these
|
||||
$session_ip = escapeSql(getIP());
|
||||
$session_user_agent = escapeSql($_SERVER['HTTP_USER_AGENT'] ?? '');
|
||||
$session_user_id = 0;
|
||||
$session_name = 'Phone system';
|
||||
|
||||
$phone_key = (string) ($_GET['key'] ?? '');
|
||||
if ($phone_key === '' && isset($_SERVER['PHP_AUTH_PW'])) {
|
||||
$phone_key = (string) $_SERVER['PHP_AUTH_PW'];
|
||||
}
|
||||
$phone_system = phoneSystemByKey($phone_key);
|
||||
if (!$phone_system || !phoneKind($phone_system)) {
|
||||
$phone_reply(404, 'Not found');
|
||||
}
|
||||
if (!intval($phone_system['phone_system_active'])) {
|
||||
$phone_reply(503, 'This phone system is turned off in ITFlow');
|
||||
}
|
||||
$session_name = escapeSql(phoneSystemName($phone_system));
|
||||
Reference in New Issue
Block a user