setDataPath(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR); } echo ' ' . $title . ' '; // Navbar echo '
'; // FAQ Modal echo ''; echo '
'; echo '

PulseBridge' . $smsgateway->getVersion() . '

'; echo '

SMS gateway web-application with an HTTP interface to connect with a PulseBridge android app and send/receive SMS.

'; echo '

App Version: ' . $smsgateway->getVersion() . '

'; echo '
'; } public static function renderFooter() { echo '
'; // Close the container div echo ''; echo ''; echo ''; } } // Create an Pulsebridge instance if not done yet, and define the flat-file data folder if (!isset($smsgateway)) { $smsgateway = new Pulsebridge(); $smsgateway->setDataPath(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR); } // Detect the URL with php file //$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . ($_SERVER['PHP_SELF']); // Detect the URL without php file $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST']; // Retrieve some parameters $command = isset($_GET["m"]) ? "m" : (isset($_GET["i"]) ? "i" : (isset($_GET["e"]) ? "e" : "")); $h = isset($_GET["h"]) ? $_GET["h"] : ""; $mid = isset($_GET["mid"]) ? $_GET["mid"] : ""; // Correct the international format of the phone number if needed $to = isset($_GET["to"]) ? $_GET["to"] : ""; // Validate the "to" field if (!empty($to) && !preg_match('/^\d{10}$/', $to)) { // Handle validation error (e.g., redirect to an error page) header("Location: error.php?message=Invalid phone number"); exit(); } if ("00" == substr($to, 0, 2)) { $to = "+" . substr($to, 2, strlen($to) - 2); } // Define a default message if needed $message = isset($_GET["message"]) ? $_GET["message"] : ""; // Hello World πŸ˜‰ // Validate the "message" field if (!empty($message) && strlen($message) < 5) { // Handle validation error (e.g., redirect to an error page) header("Location: error.php?message=Message should be at least 5 characters"); exit(); } // Retrieve the device id $id = isset($_GET["id"]) ? $_GET["id"] : ""; $device_id = $id; if ((!empty($to)) && empty($device_id)) { $device_id = substr(md5(uniqid("", true)), 0, 16); } elseif ((empty($to)) && (!empty($device_id)) && (!file_exists($smsgateway->getDataPath() . $device_id))) { $device_id = ""; } // Calculate the device hash based on the secret $device_h = $smsgateway->calculateAuthenticationHash($device_id); // Check if device hash is valid for an existing device, otherwise flush the device id if ((!empty($id)) && ($h != $device_h)) { $device_id = ""; } else { $smsgateway->updateDataStructure($id); } if ((!empty($mid)) && (!empty($device_id))) { $message_state = "MISSING"; $message_array = $smsgateway->readSentStatus($id, $mid); if (isset($message_array[0]['status'])) { $message_state = $message_array[0]['status']; } echo $message_state; } elseif ("e" == $command) { // An enhanced command can be implemented here } elseif (("m" == $command) && (!empty($device_id))) { PageRenderer::renderHeader('Pulsebridge App'); //include 'header.php'; echo ''; echo '
'; // Back Button with Bootstrap styling and centered echo '
Back
'; // Display messages resume for the "m" command echo '
'; echo '
'; // New SMS messages received echo '
'; echo '
'; echo '

'; echo ''; echo '

'; echo '
'; echo '
'; echo '
'; $new_messages = $smsgateway->readNewMessages($id); if (count($new_messages) > 0) { foreach ($new_messages as $message) { echo '
'; echo '
'; echo '

' . date("Y-m-d H:i:s", $message['sms_received'] / 1000) . '

'; echo '' . $message['from'] . ': ' . $message['content']; echo '
'; echo '
'; } } else { echo '

No messages to display.

'; } echo '
'; echo '
'; echo '
'; // All SMS messages received echo '
'; echo '
'; echo '

'; echo ''; echo '

'; echo '
'; echo '
'; echo '
'; $all_messages = $smsgateway->readAllMessages($id); if (count($all_messages) > 0) { foreach ($all_messages as $message) { echo '
'; echo '
'; echo '

' . date("Y-m-d H:i:s", $message['sms_received'] / 1000) . '

'; echo '' . $message['from'] . ': ' . $message['content']; echo '
'; echo '
'; } } else { echo '

No messages to display.

'; } echo '
'; echo '
'; echo '
'; // All SMS messages sent echo '
'; echo '
'; echo '

'; echo ''; echo '

'; echo '
'; echo '
'; echo '
'; $sent_messages = $smsgateway->readAllSentStatus($id); if (count($sent_messages) > 0) { foreach ($sent_messages as $message) { echo '
'; echo '
'; echo '

' . date("Y-m-d H:i:s", $message['last_update'] / 1000) . '

'; $statusBadgeClass = ($message['status'] === 'DELIVERED') ? 'badge badge-success' : 'badge badge-secondary'; echo '' . $message['status'] . ''; echo ' Track'; echo ' : ' . $message['content']; echo '
'; echo '
'; } } else { echo '

No messages to display.

'; } echo '
'; echo '
'; echo '
'; echo '
'; // Closing accordion container echo '
'; echo '
'; //include 'footer.php'; PageRenderer::renderFooter(); echo ''; } elseif (empty($device_id) || ("i" == $command)) { // Display basic usage info if ("" == $to) { $autofocus_to = "autofocus=\"autofocus\""; $autofocus_message = ""; } else { $autofocus_to = ""; $autofocus_message = "autofocus=\"autofocus\""; } //include header; PageRenderer::renderHeader('Pulsebridge App'); echo '
'; if (!empty($id)) { // Back Button with Bootstrap styling and centered echo ''; echo '
'; echo ' '; echo ' '; echo '
'; if (!empty($h)) { echo '
'; echo ' '; echo ' '; echo '
'; } } $outputForm = '
'; $outputForm .= '

'; $outputForm .= '
'; if ("" == $h) { $outputForm .= '
'; $outputForm .= '... or send a first message calling this URL: '; $outputForm .= '
'; $outputForm .= '
'; $outputForm .= ' ' . $url . '?to=0123456789&message=Hello+world'; $outputForm .= '
'; $outputForm .= '
'; } else { $outputForm .= '... or send a direct message calling this URL: '; $outputForm .= '
'; $outputForm .= '
'; $outputForm .= ' ' . $url . '?id=' . $id . '&h=' . $h . '&to=' . (("" != $to) ? $to : "0123456789") . '&message=' . urlencode(("" != $message) ? $message : "Hello world πŸ™‚") . ''; $outputForm .= '
'; $outputForm .= '
'; } $outputForm .= '
'; echo $outputForm; PageRenderer::renderFooter(); //include 'footer.php'; echo ' '; } elseif (!empty($to)) { // Push the message on the server $message_id = $smsgateway->sendMessage($device_id, $to, $message); $outputSent = '
'; if (empty($message_id)) { header('X-SMSGateway-State: FAILED'); $outputSent .= ' '; } else { header('X-SMSGateway-State: NEW'); header('X-SMSGateway-State-Url: ' . $url . '?id=' . $id . '&h=' . $h . '&mid=' . $message_id); header('X-SMSGateway-Message-Id: ' . $message_id); $outputSent .= ' '; } //include Header PageRenderer::renderHeader('Pulsebridge App'); // Display usage information $outputSent .= '
'; if (empty($messageId)) { $outputSent .= ''; $outputSent .= ''; } else { $outputSent .= ''; } $outputSent .= '
'; $outputSent .= '
'; $outputSent .= '

Installation Instructions

'; $outputSent .= '

If not done yet, please install the Android Pulsebridge App by clicking the link below:

'; $outputSent .= ' Download SMSGatewayApp

'; $outputSent .= '

App Configuration

'; $outputSent .= '

Set the following URL in the Settings of the Android App:

'; $outputSent .= '
'; $outputSent .= ''; $outputSent .= ''; $outputSent .= '
'; $outputSent .= 'Click "Copy URL" to copy the configuration URL to the clipboard.
'; $outputSent .= 'Open Pulsebridge app -> Settings -> Paste url to pulsebride url field'; $outputSent .= '
'; $outputSent .= '
'; $outputSent .= '

Actions

'; $outputSent .= '

Check SMS messages or send more SMS messages:

'; $outputSent .= 'Check SMS Messages '; $outputSent .= 'Send More SMS Messages '; $outputSent .= '

Dev Usage

'; $outputSent .= '

Send Messages using HTTP GET on this URL from your application::

'; $outputSent .= '
'; $outputSent .= ''; $outputSent .= '
'; $outputSent .= '
'; $outputSent .= '
'; $outputSent .= '
'; $outputSent .= ''; echo $outputSent; //include 'footer'; PageRenderer::renderFooter(); } else { // Run the API server $smsgateway->apiServer(); }