Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new pull request #3

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
4130593
polling
niryariv Jan 15, 2011
aee1061
initial import of polling code
niryariv Jan 15, 2011
8e31033
new icon
niryariv Jan 15, 2011
ec1dc62
simplify polling UI to use fixed, 15 min intervals
niryariv Jan 15, 2011
2089450
cleanup home screen text
niryariv Jan 16, 2011
3ed1958
add a poll=true parameter
niryariv Jan 16, 2011
448eafe
Move post-parse sms sending to TargetUrlRequest
niryariv Jan 18, 2011
9473ab1
use POST in http requests; use different url for outgoing sms; poll f…
Sep 11, 2011
fc6cda4
do http requests in AsyncTask so they don't freeze the UI thread; imp…
Sep 12, 2011
8f15a8c
add menu with options to test server connection, or edit settings
Sep 12, 2011
d5b9734
fix null pointer exception; remove dependency on Base64 for android 1…
Sep 12, 2011
cb8d95e
PHP server library with example implementation; add 'check now' butto…
Sep 12, 2011
aff22e5
use string status codes instead of integers
Sep 13, 2011
0a0f50a
fix comments for php server example
Sep 13, 2011
da334a0
remove test action to simplify server implementation; add icons from …
Sep 13, 2011
307f354
add help screen
Sep 13, 2011
2911111
keep messages waiting to be sent in memory; if forwarding fails (in e…
Sep 13, 2011
d29e7b2
start alarm to poll for outgoing messages when phone boots; add optio…
Sep 13, 2011
e4cea3b
use alarm to schedule retries; fix bug where sms notfications were dr…
Sep 13, 2011
bead453
set phone number and api version as regular post fields instead of cu…
Sep 13, 2011
e535266
instead of deleting messages from inbox, prevent them from getting th…
Sep 13, 2011
e79fe7c
refactoring
Sep 13, 2011
61d24b2
add setting to enable/disable sms gateway
Sep 13, 2011
41141fa
add menu option to forward existing messages from inbox (delivered wh…
Sep 14, 2011
0071efd
improve ForwardInbox with help from http://www.marvinlabs.com/2010/10…
Sep 14, 2011
2f22c29
github generated gh-pages branch
youngj Sep 15, 2011
e78598c
refactor App to subclass Application; retain log messages in App clas…
Sep 15, 2011
46710c2
organize code into subpackages
Sep 16, 2011
60d4941
launching Main activity on boot is no longer necessary
Sep 16, 2011
d994b10
support for incoming MMS
Sep 18, 2011
72a893e
Merge branch 'gh-pages' of github.com:youngj/KalSMS
Sep 18, 2011
7bc88cf
updated readme
Sep 18, 2011
e834488
avoid exceeding Android limit of 100 outgoing SMS/app/hour; allow eff…
Sep 18, 2011
d720412
most README content moved to http://youngj.github.com/KalSMS/
Sep 19, 2011
430aeca
enable user to change wifi sleep policy on kalsms settings page for c…
Sep 19, 2011
3357de7
assume http:// scheme for server URLs
Sep 19, 2011
eb80837
add test mode to allow testing KalSMS on a phone that is also being u…
Sep 19, 2011
a793a5f
use http connection pooling to improve performance (especially over ssl)
Sep 20, 2011
9a574b3
add foreground service to keep App in memory (otherwise rate-limiting…
Sep 20, 2011
9440fdb
android's ForegroundService example code is surprisingly buggy
Sep 20, 2011
4b0010f
display version number
Sep 20, 2011
687400f
use kalsms version code in http requests
Sep 20, 2011
b6a372d
avoid forwarding sms from network; unregister mms observer when kalsm…
Sep 21, 2011
dbf3536
update url in readme
Sep 21, 2011
73bc3c9
MMS fixes: prevent httpclient from using transfer-encoding: chunked s…
Sep 22, 2011
7df89cd
rename to EnvayaSMS; add icon
Sep 22, 2011
1cf69e8
update links
Sep 23, 2011
6384942
handle sending and receiving multipart sms messages > 160 chars
Sep 24, 2011
986b50f
fix bug where outgoing sms would be cut off if they contain xml entities
Sep 25, 2011
bf14f23
fix encoding problem for post requests, make test a separate action
Sep 27, 2011
03d5f55
update php server library and example
Sep 27, 2011
faffc6c
don't request delivery reports but leave option open in future; fix b…
Sep 28, 2011
3108512
keep backlogged outgoing messages in priority queue; allow server to …
Sep 28, 2011
1081f57
automatic failover between wifi/mobile if server cannot be reached; s…
Sep 29, 2011
d7f803e
add PendingMessages activity for viewing/retrying/deleting pending me…
Oct 1, 2011
cf1deec
queue incoming messages like outgoing messages
Oct 1, 2011
dedfdb5
improve performance of displaying log in Main activity
Oct 1, 2011
79ec4c1
add note about local.properties and sdk.dir to README
Oct 4, 2011
af1f8af
add html page for simulating EnvayaSMS requests
Oct 9, 2011
f253f54
update license and readme files for request simulator
Oct 9, 2011
2889bf9
send new log messages to server on each HTTP request; notify server o…
Oct 10, 2011
f430ddb
set http user-agent header
Nov 13, 2011
22f8c26
add settings screen for ignored phone numbers; allow user to specify …
Nov 26, 2011
c18a28b
enable long polling - increase socket timeout, start only one PollerT…
Nov 30, 2011
6f19970
increment version to 2.0.4
Nov 30, 2011
d93ff76
update httpserver submodule to latest version
youngj Mar 15, 2012
f53ccc3
add support for incoming call notifications; fix intermittent NullPoi…
youngj Mar 16, 2012
239ee1f
version 3.0 - real-time AMQP connections; change server API format f…
youngj Apr 4, 2012
9d65fc1
remove stray references to telerivet
youngj Apr 4, 2012
69a05ac
remove code added for debugging
youngj Apr 4, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PHP server library with example implementation; add 'check now' butto…
…n on menu
Jesse Young committed Sep 12, 2011
commit cb8d95ebd58a4cf31e38882946e45b5e8cca2040
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "server/php/example/httpserver"]
path = server/php/example/httpserver
url = git://github.com/youngj/httpserver.git
3 changes: 3 additions & 0 deletions res/menu/mainmenu.xml
Original file line number Diff line number Diff line change
@@ -6,4 +6,7 @@
<item android:id="@+id/test"
android:icon="@drawable/icon"
android:title="@string/test" />
<item android:id="@+id/check_now"
android:icon="@drawable/icon"
android:title="@string/check_now" />
</menu>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -3,4 +3,5 @@
<string name="app_name">KalSMS 2</string>
<string name="settings">Settings</string>
<string name="test">Test</string>
<string name="check_now">Check Now</string>
</resources>
177 changes: 177 additions & 0 deletions server/php/KalSMS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

/*
* PHP server library for KalSMS
*
* For example usage see example/www/index.php
*/

class KalSMS
{
const ACTION_INCOMING = 'incoming';
const ACTION_OUTGOING = 'outgoing';
const ACTION_SEND_STATUS = 'send_status';
const ACTION_TEST = 'test';

const STATUS_QUEUED = 1;
const STATUS_FAILED = 2;
const STATUS_SENT = 3;

static function new_from_request()
{
$version = @$_SERVER['HTTP_X_KALSMS_VERSION'];

return new KalSMS();
}

static function escape($val)
{
return htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
}

function get_request_action()
{
switch (@$_POST['action'])
{
case static::ACTION_INCOMING:
return new KalSMS_Action_Incoming($this);
case static::ACTION_OUTGOING:
return new KalSMS_Action_Outgoing($this);
case static::ACTION_SEND_STATUS:
return new KalSMS_Action_SendStatus($this);
case static::ACTION_TEST:
return new KalSMS_Action_Test($this);
default:
return new KalSMS_Action($this);
}
}

function get_request_phone_number()
{
return @$_SERVER['HTTP_X_KALSMS_PHONENUMBER'];
}

function is_validated_request($correct_password)
{
$signature = @$_SERVER['HTTP_X_KALSMS_SIGNATURE'];
if (!$signature)
{
return false;
}

$is_secure = (!empty($_SERVER['HTTPS']) AND filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN));
$protocol = $is_secure ? 'https' : 'http';
$full_url = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

$correct_signature = $this->compute_signature($full_url, $_POST, $correct_password);

//error_log("Correct signature: '$correct_signature'");

return $signature === $correct_signature;
}

function compute_signature($url, $data, $password)
{
ksort($data);

$input = $url;
foreach($data as $key => $value)
$input .= ",$key=$value";

$input .= ",$password";

//error_log("Signed data: '$input'");

return base64_encode(sha1($input, true));
}
}

class KalSMS_OutgoingMessage
{
public $id = '';
public $to;
public $message;
}

class KalSMS_Action
{
public $type;
public $kalsms;

function __construct($kalsms)
{
$this->kalsms = $kalsms;
}
}

class KalSMS_Action_Test extends KalSMS_Action
{
function __construct($kalsms)
{
parent::__construct($kalsms);
$this->type = KalSMS::ACTION_TEST;
}
}

class KalSMS_Action_Incoming extends KalSMS_Action
{
public $from;
public $message;

function __construct($kalsms)
{
parent::__construct($kalsms);
$this->type = KalSMS::ACTION_INCOMING;
$this->from = $_POST['from'];
$this->message = $_POST['message'];
}

function get_response_xml($messages)
{
ob_start();
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo "<Response>";
foreach ($messages as $message)
{
echo "<Sms id='".KalSMS::escape($message->id)."'>".KalSMS::escape($message->message)."</Sms>";
}
echo "</Response>";
return ob_get_clean();
}
}

class KalSMS_Action_Outgoing extends KalSMS_Action
{
function __construct($kalsms)
{
parent::__construct($kalsms);
$this->type = KalSMS::ACTION_OUTGOING;
}

function get_response_xml($messages)
{
ob_start();
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo "<Messages>";
foreach ($messages as $message)
{
echo "<Sms id='".KalSMS::escape($message->id)."' to='".KalSMS::escape($message->to)."'>".
KalSMS::escape($message->message)."</Sms>";
}
echo "</Messages>";
return ob_get_clean();
}
}

class KalSMS_Action_SendStatus extends KalSMS_Action
{
public $status;
public $id;

function __construct($type)
{
$this->type = KalSMS::ACTION_SEND_STATUS;
$this->status = (int)$_POST['status'];
$this->id = $_POST['id'];
}
}
25 changes: 25 additions & 0 deletions server/php/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

PHP server library for KalSMS, with example implementation

The KalSMS.php library is intended to be used as part of a PHP application
running on an HTTP server that receives incoming SMS messages from, and sends
outgoing SMS messages to an Android phone running KalSMS.

To run the example implementation, the example/www/ directory should be made available
via a web server running PHP (e.g. Apache). You can also use the included standalone
PHP web server, by running the following commands:
git submodule init
php server.php

example/config.php contains the list of phone numbers and passwords for phones running KalSMS.

On a phone running KalSMS, go to Menu -> Settings and enter:
* Server URL: The URL to example/www/index.php.
If you're using server.php, this will be http://<your_ip_address>:8002/
* Your phone number: One of the phone numbers listed in example/config.php
* Password: The corresponding password in example/config.php

To send an outgoing SMS, use
php example/send_sms.php

See KalSMS.php and example/www/index.php
9 changes: 9 additions & 0 deletions server/php/example/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$PASSWORDS = array(
'16505551212' => 'rosebud',
'16505551213' => 's3krit',
);
$PHONE_NUMBERS = array_keys($PASSWORDS);

$OUTGOING_DIR_NAME = __DIR__."/outgoing_sms";
1 change: 1 addition & 0 deletions server/php/example/httpserver
Submodule httpserver added at 95a38a
41 changes: 41 additions & 0 deletions server/php/example/send_sms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

// invoke from command line

require_once __DIR__."/config.php";

$arg_len = sizeof($argv);

if ($arg_len == 4)
{
$from = $argv[1];
$to = $argv[2];
$message = $argv[3];
}
else if ($arg_len == 3)
{
$from = $PHONE_NUMBERS[0];
$to = $argv[1];
$message = $argv[2];
}
else
{
error_log("Usage: php send_sms.php [<from>] <to> \"<message>\"");
error_log("Examples: ");
error_log(" php send_sms.php 16505551212 16504449876 \"hello world\"");
error_log(" php send_sms.php 16504449876 \"hello world\"");
die;
}

$id = uniqid("");

$filename = "$OUTGOING_DIR_NAME/$id.json";

file_put_contents($filename, json_encode(array(
'from' => $from,
'to' => $to,
'message' => $message,
'id' => $id
)));

echo "Message $id added to outgoing queue\n";
46 changes: 46 additions & 0 deletions server/php/example/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* Example standalone HTTP server that routes all .php URIs to PHP files under ./example_www,
* and routes all other URIs to static files under ./example_www.
*
* index.php is used as the directory index.
*
* Just run it on the command line like "php example_server.php".
*/

require_once __DIR__ . '/httpserver/httpserver.php';

class ExampleServer extends HTTPServer
{
function __construct()
{
parent::__construct(array(
'port' => 8002,
));
}

function route_request($request)
{
$uri = $request->uri;

$doc_root = __DIR__ . '/www';

if (preg_match('#/$#', $uri))
{
$uri .= "index.php";
}

if (preg_match('#\.php$#', $uri))
{
return $this->get_php_response($request, "$doc_root$uri");
}
else
{
return $this->get_static_response($request, "$doc_root$uri");
}
}
}

$server = new ExampleServer();
$server->run_forever();
6 changes: 6 additions & 0 deletions server/php/example/test_sms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

require_once __DIR__."/config.php";
require_once __DIR__."/lib.php";

var_dump(get_outgoing_sms("16505551212"));
Loading