From 8c678febe012eabbe1b42f74fcb3e1e9847191ca Mon Sep 17 00:00:00 2001 From: Gergely POLONKAI Date: Sat, 6 Oct 2012 23:21:08 +0200 Subject: [PATCH] Removed unnecessary files --- .gitignore | 2 + README.md | 8 ++-- jsonRPCServer.php | 86 ----------------------------------------- smsBackend.php | 6 --- smsSender.php | 98 ----------------------------------------------- smsToken.php | 29 -------------- 6 files changed, 7 insertions(+), 222 deletions(-) delete mode 100644 jsonRPCServer.php delete mode 100644 smsBackend.php delete mode 100644 smsSender.php delete mode 100644 smsToken.php diff --git a/.gitignore b/.gitignore index 84848ad..4574922 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /nbproject/private/ vendor +app +senders diff --git a/README.md b/README.md index 4ddd730..a0b7b65 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,12 @@ Features -------- * Senders to support SMS sending as many ways as possible - * Currently only Gnokii is supported, but with SenderInterface, anyone can -write a new one. + * GnokiiSender to send using gnokii + * FileSender to store messages in files * Authentication backends for authentication purposes * DatabaseAuth for a PDO based backend - * NullAuth to accept everyone without a password + * FileAuth to store users and passwords in a shadow-like file + * NullAuth to accept everyone without a password (TODO) * Logger backends for audit and message logging * DatabaseLogger for PDO based logging + * FileLogger to log messages to files diff --git a/jsonRPCServer.php b/jsonRPCServer.php deleted file mode 100644 index b3dc75d..0000000 --- a/jsonRPCServer.php +++ /dev/null @@ -1,86 +0,0 @@ - - -This file is part of JSON-RPC PHP. - -JSON-RPC PHP is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -JSON-RPC PHP is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with JSON-RPC PHP; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/** - * This class build a json-RPC Server 1.0 - * http://json-rpc.org/wiki/specification - * - * @author sergio - */ -class jsonRPCServer { - /** - * This function handle a request binding it to a given object - * - * @param object $object - * @return boolean - */ - public static function handle($object) { - - // checks if a JSON-RCP request has been received - if ( - $_SERVER['REQUEST_METHOD'] != 'POST' || - empty($_SERVER['CONTENT_TYPE']) || - $_SERVER['CONTENT_TYPE'] != 'application/json' - ) { - // This is not a JSON-RPC request - return false; - } - - // reads the input data - $request_string = file_get_contents('php://input'); - $request = json_decode($request_string,true); - - // executes the task on local object - try { - if ($result = @call_user_func_array(array($object,$request['method']),$request['params'])) { - $response = array ( - 'id' => $request['id'], - 'result' => $result, - 'error' => NULL - ); - } else { - $response = array ( - 'id' => $request['id'], - 'result' => NULL, - 'error' => 'unknown method or incorrect parameters' - ); - } - } catch (Exception $e) { - $response = array ( - 'id' => $request['id'], - 'result' => NULL, - 'error' => $e->getMessage() - ); - } - - // output the response - if (!empty($request['id'])) { // notifications don't want response - header('content-type: text/javascript'); - echo json_encode($response); - } - - // finish - return true; - } -} -?> diff --git a/smsBackend.php b/smsBackend.php deleted file mode 100644 index bc5c3fc..0000000 --- a/smsBackend.php +++ /dev/null @@ -1,6 +0,0 @@ -'; - - public function __construct($dbBackend, $smsBackend, $sessionId) - { - $this->sessionId = $sessionId; - $this->dbBackend = $dbBackend; - $this->smsBackend = $smsBackend; - } - - public function login($username, $password) - { - $token = ''; - - try - { - $token = $this->dbBackend->getToken($username, $password, $_SERVER['REMOTE_ADDR'], $this->sessionId); - } - catch (Exception $e) - { - throw new Exception('Authentication failed. Reason: ' . $e->getMessage()); - } - $this->dbBackend->auditLog($_SERVER['REMOTE_ADDR'], 'login', 'Successful login by ' . $username); - return $token; - } - - public function send($token, $recipient, $message, $passwordLocations) - { - try - { - $tokenObj = $this->dbBackend->checkToken($token, $this->sessionId, $_SERVER['REMOTE_ADDR']); - } - catch (Exception $e) - { - $this->dbBackend->auditLog($_SERVER['REMOTE_ADDR'], 'send', 'Message sending attempt by invalid token ' . $token); - throw new Exception('Authentication failed. Reason: Bad Token', 0, $e); - } - - try - { - $this->smsBackend->sendSMS($recipient, $message); - $this->dbBackend->auditLog($_SERVER['REMOTE_ADDR'], 'send', 'Successful SMS sending by ' . $tokenObj->getUsername()); - $this->dbBackend->messageLog($tokenObj->getUserId(), $recipient, $this->maskPasswords($message, $passwordLocations), $_SERVER['REMOTE_ADDR']); - return 'success'; - } - catch (PDOException $e) - { - error_log('SMS sending cannot be logged due to a database error!'); - $this->dbBackend->auditLog($_SERVER['REMOTE_ADDR'], 'send', 'SMS sending by ' . $tokenObj->getUserName() . ' cannot be logged due to a database error'); - } - catch (Exception $e) - { - $this->dbBackend->auditLog($_SERVER['REMOTE_ADDR'], 'send', 'Error during SMS sending by user ' . $token->getUserName() . ': ' . $e->getMessage()); - error_log('Error during SMS sending: ' . $e->getMessage()); - } - throw new Exception('Send failed: Unknown Error'); - } - - protected function maskPasswords($message, $passwordLocations) - { - $msg = $message; - - $mod = 0; - foreach ($passwordLocations as $loc) - { - $msg = substr_replace($msg, self::password_mask, $loc[0] + $mod, $loc[1]); - $mod += (strlen(self::password_mask) - $loc[1]); - } - - return $msg; - } - - public function logout($token) - { - try - { - $username = $this->dbBackend->removeToken($_SERVER['REMOTE_ADDR'], $this->sessionId, $token); - $this->dbBackend->auditLog($_SERVER['REMOTE_ADDR'], 'logout', $username . ' logged out successfully'); - session_destroy(); - session_id(''); - unset($_COOKIE['PHPSESSID']); - return 'success'; - } - catch (Exception $e) - { - error_log('Logout failed: ' . $e->getMessage()); - $this->dbBackend->auditLog('Logout failed: ' . $e->getMessage()); - throw new Exception('Logout failed: Internal Server Error'); - } - } -} diff --git a/smsToken.php b/smsToken.php deleted file mode 100644 index 15acfd2..0000000 --- a/smsToken.php +++ /dev/null @@ -1,29 +0,0 @@ -userId = $userId; - $this->userName = $userName; - $this->sessionId = $sessionId; - $this->ip = $ip; - $this->token = $token; - } - - public function getUserId() - { - return $this->userId; - } - - public function getUserName() - { - return $this->userName; - } -} -