4
0
mirror of https://github.com/cwinfo/envayasms.git synced 2025-07-04 05:57:44 +00:00

send new log messages to server on each HTTP request; notify server of changes in device status (currently power/battery state)

This commit is contained in:
Jesse Young
2011-10-10 16:19:38 -07:00
parent f253f54704
commit 2889bf9b4b
11 changed files with 259 additions and 31 deletions

View File

@ -11,12 +11,18 @@ class EnvayaSMS
const ACTION_INCOMING = 'incoming';
const ACTION_OUTGOING = 'outgoing';
const ACTION_SEND_STATUS = 'send_status';
const ACTION_DEVICE_STATUS = 'device_status';
const ACTION_TEST = 'test';
const STATUS_QUEUED = 'queued';
const STATUS_FAILED = 'failed';
const STATUS_SENT = 'sent';
const DEVICE_STATUS_POWER_CONNECTED = "power_connected";
const DEVICE_STATUS_POWER_DISCONNECTED = "power_disconnected";
const DEVICE_STATUS_BATTERY_LOW = "battery_low";
const DEVICE_STATUS_BATTERY_OKAY = "battery_okay";
const MESSAGE_TYPE_SMS = 'sms';
const MESSAGE_TYPE_MMS = 'mms';
@ -49,11 +55,13 @@ class EnvayaSMS_Request
public $version;
public $phone_number;
public $log;
function __construct()
{
$this->version = $_POST['version'];
$this->phone_number = $_POST['phone_number'];
$this->log = @$_POST['log'];
}
function get_action()
@ -77,6 +85,8 @@ class EnvayaSMS_Request
return new EnvayaSMS_Action_SendStatus($this);
case EnvayaSMS::ACTION_TEST:
return new EnvayaSMS_Action_Test($this);
case EnvayaSMS::ACTION_DEVICE_STATUS:
return new EnvayaSMS_Action_DeviceStatus($this);
default:
return new EnvayaSMS_Action($this);
}
@ -247,4 +257,16 @@ class EnvayaSMS_Action_SendStatus extends EnvayaSMS_Action
$this->id = $_POST['id'];
$this->error = $_POST['error'];
}
}
}
class EnvayaSMS_Action_DeviceStatus extends EnvayaSMS_Action
{
public $status; // EnvayaSMS::DEVICE_STATUS_* values
function __construct($request)
{
parent::__construct($request);
$this->type = EnvayaSMS::ACTION_DEVICE_STATUS;
$this->status = $_POST['status'];
}
}

1
server/php/example/log/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.log

View File

@ -22,6 +22,16 @@ if (!isset($password) || !$request->is_validated($password))
return;
}
// append to EnvayaSMS app log
$app_log = $request->log;
if ($app_log)
{
$log_file = dirname(__DIR__)."/log/sms_".preg_replace('#[^\w]#', '', $request->phone_number).".log";
$f = fopen($log_file, "a");
fwrite($f, $app_log);
fclose($f);
}
$action = $request->get_action();
switch ($action->type)
@ -79,6 +89,10 @@ switch ($action->type)
echo "invalid id";
}
return;
case EnvayaSMS::ACTION_DEVICE_STATUS:
error_log("device_status = {$action->status}");
echo "OK";
return;
case EnvayaSMS::ACTION_TEST:
echo "OK";
return;

View File

@ -1,6 +1,6 @@
<html>
<head>
<title>EnvayaSMS Request Simulator</title>
<style type='text/css'>
body
{
@ -30,10 +30,12 @@ body
<tr><th>Server URL</th><td><input id='server_url' type='text' size='40' /></td></tr>
<tr><th>Phone Number</th><td><input id='phone_number' type='text' /></td></tr>
<tr><th>Password</th><td><input id='password' type='password' /></td></tr>
<tr><th>Log Messages</th><td><textarea id='log' style='width:250px'></textarea></td></tr>
<tr><th>Action</th><td><select id='action' onchange='actionChanged()' onkeypress='actionChanged()'>
<option value='incoming'>incoming</option>
<option value='outgoing'>outgoing</option>
<option value='send_status'>send_status</option>
<option value='device_status'>device_status</option>
<option value='test'>test</option>
</select></td></tr>
</table>
@ -46,7 +48,7 @@ body
<option value='sms'>sms</option>
<option value='mms'>mms</option>
</select></td></tr>
<tr><th>Message</th><td><textarea id='message'></textarea></td></tr>
<tr><th>Message</th><td><textarea id='message' style='width:250px'></textarea></td></tr>
<tr><th>Timestamp</th><td><input id='timestamp' type='text' /></td></tr>
</table>
</div>
@ -70,6 +72,17 @@ body
<h4>Parameters for action=test:</h4>
(None)
</div>
<div id='action_device_status' style='display:none'>
<h4>Parameters for action=device_status:</h4>
<table class='smsTable'>
<tr><th>Status</th><td><select id='device_status'>
<option value='power_connected'>power_connected</option>
<option value='power_disconnected'>power_disconnected</option>
<option value='battery_low'>battery_low</option>
<option value='battery_okay'>battery_okay</option>
</select></td></tr>
</table>
</div>
<script type='text/javascript'>
@ -100,6 +113,7 @@ function performAction() {
version: '13',
phone_number: $('phone_number').value,
action: action,
log: $('log').value
};
if (action == 'incoming')
@ -115,6 +129,10 @@ function performAction() {
params.status = $('status').value;
params.error = $('error').value;
}
else if (action == 'device_status')
{
params.status = $('device_status').value;
}
var xhr = (window.ActiveXObject && !window.XMLHttpRequest) ? new ActiveXObject("Msxml2.XMLHTTP") : new XMLHttpRequest();