James Rose */ include "root.php"; //luarun /var/www/fusionpbx/app/sms/sms.lua TO FROM 'BODY' $debug = false; require_once "resources/require.php"; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $data = json_decode(file_get_contents("php://input")); if ($debug) { error_log('DATA: ' . print_r($data, true)); } //create the even socket connection and send the event socket command $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if (!$fp) { //error message echo "
Connection to Event Socket failed.
"; } else { $to = preg_replace('/(^[1])/','', $data->to); if ($debug) { error_log("TO: " . print_r($to,true)); } $sql = "select domain_name, "; $sql .= "dialplan_detail_data, "; $sql .= "v_domains.domain_uuid as domain_uuid "; $sql .= "from v_destinations, "; $sql .= "v_dialplan_details, "; $sql .= "v_domains "; $sql .= "where v_destinations.dialplan_uuid = v_dialplan_details.dialplan_uuid "; $sql .= "and v_destinations.domain_uuid = v_domains.domain_uuid"; $sql .= " and destination_number like '" . $to . "' and dialplan_detail_type = 'transfer'"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $domain_name = $row["domain_name"]; preg_match('/(\d{2,7})/',$row["dialplan_detail_data"],$match); $domain_uuid = $row["domain_uuid"]; break; //limit to 1 row } unset ($prep_statement); if ($debug) { error_log("MATCH: " . print_r($match,true)); error_log("DOMAIN_NAME: " . print_r($domain_name,true)); } $sql = "select destination_number "; $sql .= "from v_ring_groups, v_ring_group_destinations "; $sql .= "where v_ring_groups.ring_group_uuid = v_ring_group_destinations.ring_group_uuid "; $sql .= "and ring_group_extension = '" . $match[0] . "' "; $sql .= "and v_ring_groups.domain_uuid = '" . $domain_uuid . "'"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (count($result)) { foreach ($result as &$row) { $switch_cmd = "api luarun app.lua sms inbound "; $switch_cmd .= $row['destination_number'] . "@" . $domain_name; $switch_cmd .= " " . $data->from . " '" . $data->body . "'"; if ($debug) { error_log(print_r($switch_cmd,true)); } $result2 = trim(event_socket_request($fp, $switch_cmd)); } } else { $switch_cmd = "api luarun app.lua sms inbound " . $match[0] . "@" . $domain_name . " " . $data->from . " '" . $data->body . "'"; if ($debug) { error_log(print_r($switch_cmd,true)); } $result2 = trim(event_socket_request($fp, $switch_cmd)); } if ($debug) { error_log("RESULT: " . print_r($result2,true)); } unset ($prep_statement); } } die(); ?>