Some updates
This commit is contained in:
parent
80376ff566
commit
61d0399828
12
README.md
12
README.md
@ -6,7 +6,11 @@ SmsGateway is a JSON-RPC based SMS Gateway.
|
|||||||
Features
|
Features
|
||||||
--------
|
--------
|
||||||
|
|
||||||
* Sender interfaces
|
* Senders to support SMS sending as many ways as possible
|
||||||
* Multiple SMS sending interfaces. Currently only Gnokii is supported, but
|
* Currently only Gnokii is supported, but with SenderInterface, anyone can
|
||||||
with SenderInterface, anyone can write a new one.
|
write a new one.
|
||||||
* Database backends
|
* Authentication backends for authentication purposes
|
||||||
|
* DatabaseAuth for a PDO based backend
|
||||||
|
* NullAuth to accept everyone without a password
|
||||||
|
* Logger backends for audit and message logging
|
||||||
|
* DatabaseLogger for PDO based logging
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once 'smsBackend.php';
|
|
||||||
class gnokiiSMSBackend implements smsBackend
|
|
||||||
{
|
|
||||||
protected $gnokii_path = '/usr/bin/gnokii';
|
|
||||||
|
|
||||||
public function __construct($gnokii_path = null)
|
|
||||||
{
|
|
||||||
if ($gnokii_path !== null)
|
|
||||||
{
|
|
||||||
$this->gnokii_path = $gnokii_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_executable($this->gnokii_path))
|
|
||||||
{
|
|
||||||
throw new Exception('Gnokii executable not found (should be at ' . $this->gnokii_path . ')');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* sendSMS() Sends an SMS message to the given recipient
|
|
||||||
*
|
|
||||||
* @param String $recipient
|
|
||||||
* @param String $message
|
|
||||||
* @return Boolean
|
|
||||||
*/
|
|
||||||
public function sendSMS($recipient, $message)
|
|
||||||
{
|
|
||||||
$descriptors = array(
|
|
||||||
0 => array('pipe', 'r'),
|
|
||||||
1 => array('pipe', 'w'),
|
|
||||||
2 => array('pipe', 'w'),
|
|
||||||
);
|
|
||||||
$cmd = escapeshellcmd($this->gnokii_path) . ' --sendsms ' . escapeshellarg($recipient);
|
|
||||||
$process = proc_open($cmd, $descriptors, $pipes);
|
|
||||||
if (is_resource($process))
|
|
||||||
{
|
|
||||||
fwrite($pipes[0], $message);
|
|
||||||
fclose($pipes[0]);
|
|
||||||
|
|
||||||
$stdout = stream_get_contents($pipes[1]);
|
|
||||||
$stderr = stream_get_contents($pipes[2]);
|
|
||||||
|
|
||||||
$return_value = proc_close($process);
|
|
||||||
if ($return_value != 0)
|
|
||||||
{
|
|
||||||
throw new Exception('Unable to send SMS: ' . $stderr . '; ' . $stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception('Unable to send SMS: cannot start gnokii');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
8
src/SmsGateway/Auth/DatabaseAuth.php
Normal file
8
src/SmsGateway/Auth/DatabaseAuth.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
namespace SmsGateway\Backend;
|
||||||
|
|
||||||
|
use SmsGateway\AuthInterface;
|
||||||
|
|
||||||
|
class DatabaseAuth implements AuthInterface
|
||||||
|
{
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SmsGateway;
|
namespace SmsGateway;
|
||||||
|
|
||||||
interface BackendInterface
|
interface AuthInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace SmsGateway\Backend;
|
|
||||||
|
|
||||||
use SmsGateway\BackendInterface;
|
|
||||||
|
|
||||||
class DatabaseBackend implements BackendInterface
|
|
||||||
{
|
|
||||||
}
|
|
@ -5,4 +5,18 @@ use SmsGateway\SenderInterface;
|
|||||||
|
|
||||||
class GnokiiSender implements SenderInterface
|
class GnokiiSender implements SenderInterface
|
||||||
{
|
{
|
||||||
|
private $gnokiiPath;
|
||||||
|
|
||||||
|
public function __construct($gnokiiPath)
|
||||||
|
{
|
||||||
|
$this->gnokiiPath = $gnokiiPath;
|
||||||
|
|
||||||
|
if (!is_executable($this->gnokiiPath)) {
|
||||||
|
throw new \Exception('Specified Gnokii executable is not executable by me!');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send($recipient, $message)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,4 +3,12 @@ namespace SmsGateway;
|
|||||||
|
|
||||||
interface SenderInterface
|
interface SenderInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $recipient
|
||||||
|
* @param string $message
|
||||||
|
* @return boolean true upon success. On error, throws exceptions.
|
||||||
|
* @throws Exception Upon sending error. Gnokii output will be
|
||||||
|
* stored in $e->message
|
||||||
|
public function send($recipient, $message);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user