4
0
mirror of https://github.com/cwinfo/envayasms.git synced 2025-07-03 21:57:43 +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

@ -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();