The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ
1
0
Fork 0

Started rewriting the new version

json_sms.php already reflects that. The old class files are still around, though.
master
Gergely Polonkai (W00d5t0ck) 10 years ago
parent 2fecdaf169
commit 80376ff566
  1. 10
      .htaccess
  2. 116
      json_sms.php
  3. 8
      src/SmsGateway/Backend/DatabaseBackend.php
  4. 6
      src/SmsGateway/BackendInterface.php
  5. 45
      src/SmsGateway/Logger/DatabaseLogger.php
  6. 27
      src/SmsGateway/LoggerInterface.php
  7. 67
      src/SmsGateway/RpcServer.php
  8. 8
      src/SmsGateway/Sender/GnokiiSender.php
  9. 6
      src/SmsGateway/SenderInterface.php

@ -0,0 +1,10 @@
<IfModule mod_rewrite.c>
RewriteEngine On
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ json_sms.php [QSA,L]
</IfModule>

@ -1,39 +1,107 @@
<?php
require_once 'jsonRPCServer.php';
require_once 'smsSender.php';
require_once 'postgresGatewayBackend.php';
require_once 'gnokiiSMSBackend.php';
require __DIR__.'/vendor/autoload.php';
session_start();
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
try
{
$dbBackend = new postgresGatewayBackend('localhost', 'sms_gateway', 'quaiy8Zu', 'sms_gateway');
use SmsGateway\Sender\GnokiiSender;
use SmsGateway\Logger\DatabaseLogger;
use SmsGateway\Backend\DatabaseBackend;
use SmsGateway\RpcServer;
$request = Request::createFromGlobals();
$routes = new RouteCollection();
$routes->add('jsonHandle', new Route('/', array('controller' => 'handleJson'), array('_method' => 'POST')));
$context = new RequestContext();
$context->fromRequest($request);
$matcher = new UrlMatcher($routes, $context);
try {
$parameters = $matcher->match($request->getPathInfo());
} catch (ResourceNotFoundException $e) {
$response = new Response('Bad Request', 400);
$response->send();
exit;
} catch (MethodNotAllowedException $e) {
$response = new Response('Bad Request', 400);
$response->send();
exit;
}
if ($request->getContentType() != 'json') {
$response = new Response('Bad Request', 400);
$response->send();
exit;
}
catch (PDOException $e)
{
header('Status: 500 Internal Server Error (DB)');
$jsonData = json_decode($request->getContent(), true);
if ($jsonData === null) {
$response = new Response('Bad Request', 400);
$response->send();
exit;
}
if (!array_key_exists('method', $jsonData) || !array_key_exists('params', $jsonData) || !is_array($jsonData['params'])) {
$response = new Response('Bad Request', 400);
$response->send();
exit;
}
$wantResponse = (!empty($jsonData['id']));
try
{
$smsBackend = new gnokiiSMSBackend();
try {
$sender = new GnokiiSender();
} catch (Exception $e) {
$response = new Response('Internal Server Error: Sender cannot be instantiated.', 500);
$response->send();
exit;
}
catch (Exception $e)
{
header('Status: 500 Internal Server Error (SMS)');
try {
$logger = new DatabaseLogger('pgsql:host=127.0.0.1;dbname=smsgateway', 'smsgateway', 'Imuiwai8');
} catch (PDOException $e) {
$response = new Response('Internal Server Error: Logger cannot be instantiated.', 500);
$response->send();
exit;
}
try
{
$smsSender = new smsSender($dbBackend, $smsBackend, session_id());
try {
$backend = new DatabaseBackend();
} catch (Exception $e) {
$response = new Response('Internal Server Error: Backend cannot be instantiated.', 500);
$response->send();
exit;
}
catch (Exception $e)
{
header('Status: 500 Internal Server Error');
$handler = new RpcServer($backend, $logger, $sender);
try {
$result = $handler->handle($request, $jsonData);
} catch (Exception $e) {
if ($wantResponse) {
$jsonResponse = array(
'id' => $jsonData['id'],
'result' => null,
'error' => $e->getMessage(),
);
$response = new Response(json_encode($jsonResponse));
$response->send();
}
exit;
}
jsonRPCServer::handle($smsSender);
if ($wantResponse) {
$jsonResponse = array(
'id' => $jsonData['id'],
'result' => $result,
'error' => null,
);
$response = new Response(json_encode($jsonResponse), 200, array('Content-Type' => 'application/json'));
$response->send();
}

@ -0,0 +1,8 @@
<?php
namespace SmsGateway\Backend;
use SmsGateway\BackendInterface;
class DatabaseBackend implements BackendInterface
{
}

@ -0,0 +1,6 @@
<?php
namespace SmsGateway;
interface BackendInterface
{
}

@ -0,0 +1,45 @@
<?php
namespace SmsGateway\Logger;
use SmsGateway\LoggerInterface;
use PDO;
class DatabaseLogger implements LoggerInterface
{
/**
* Constructor
*
* @param string $dsn The PDO datasource string
* @param string $username The username to use during the connection
* @param string $password The password for the above username
* @throws PDOException Upon database connection error
*/
public function __construct($dsn, $username, $password)
{
$this->dbh = new PDO($dsn, $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
/**
* Log an audit event
*
* @param integer $type The message type
* @param string $username The user this audit log connects to. Can be
* NULL if the user is unauthenticated
* @param string $message The audit message
* @return boolean TRUE if the message was saved, FALSE otherwise
*/
public function auditLog($type, $username, $message)
{
}
/**
* Log a sent message
*
* @param string $username The username who sent this message
* @param string $recipient The recipient of the message
* @param string $message The message itself
*/
public function messageLog($username, $recipient, $message)
{
}
}

@ -0,0 +1,27 @@
<?php
namespace SmsGateway;
interface LoggerInterface
{
const SMSSENDER_AUDIT_LOGIN = 1;
/**
* Log an audit event
*
* @param integer $type The message type
* @param string $username The user this audit log connects to. Can be
* NULL if the user is unauthenticated
* @param string $message The audit message
* @return boolean TRUE if the message was saved, FALSE otherwise
*/
public function auditLog($type, $username, $message);
/**
* Log a sent message
*
* @param string $username The username who sent this message
* @param string $recipient The recipient of the message
* @param string $message The message itself
*/
public function messageLog($username, $recipient, $message);
}

@ -0,0 +1,67 @@
<?php
namespace SmsGateway;
use Symfony\Component\HttpFoundation\Request;
use SmsGateway\BackendInterface;
use SmsGateway\LoggerInterface;
use SmsGateway\SenderInterface;
class RpcServer
{
/**
* The user backend
*
* @var SmsGateway\BackendInterface $backend
*/
private $backend;
/**
* The logger
*
* @var SmsGateway\LoggerInterface $logger
*/
private $logger;
/**
* The sender
*
* @var SmsGateway\SenderInterface $sender
*/
private $sender;
public function __construct(BackendInterface $backend, LoggerInterface $logger, SenderInterface $sender)
{
}
protected function login(array $params)
{
return true;
}
protected function send(array $params)
{
return true;
}
protected function logout(array $params)
{
return true;
}
public function handle(Request $request, array $jsonData)
{
$params = $jsonData['params'];
switch ($jsonData['method']) {
case 'login':
break;
case 'send':
break;
case 'logout':
break;
default:
throw new \Exception('Invalid request');
}
return 'ajaj';
}
}

@ -0,0 +1,8 @@
<?php
namespace SmsGateway\Sender;
use SmsGateway\SenderInterface;
class GnokiiSender implements SenderInterface
{
}

@ -0,0 +1,6 @@
<?php
namespace SmsGateway;
interface SenderInterface
{
}
Loading…
Cancel
Save