Skip to content

Commit

Permalink
Merge branch 'develop' into ush-1415
Browse files Browse the repository at this point in the history
  • Loading branch information
Mh-Asmi authored Oct 24, 2024
2 parents d0d6aaa + 54d057f commit 259092d
Show file tree
Hide file tree
Showing 62 changed files with 1,173 additions and 1,086 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM ushahidi/php-fpm-nginx:php-7.4
LABEL org.opencontainers.image.source="https://github.com/ushahidi/platform"

# TODO: non-root user container setup
ENV COMPOSER_ALLOW_SUPERUSER=1

COPY docker-php-ext-enable /usr/local/bin/
RUN apt-get update
RUN apt-get install -y php-pear php${PHP_MAJOR_VERSION}-dev
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"nyholm/psr7": "^1.5",
"ohanzee/database": "dev-namespaces",
"php-http/curl-client": "^2.2",
"predis/predis": "~1.1",
"predis/predis": "^2.2.2",
"robmorgan/phinx": "~0.11.2",
"sentry/sentry-laravel": "^1.9|^2.11",
"symfony/event-dispatcher": "^5.4",
Expand Down
31 changes: 13 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/data-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'africastalking' => false,
'httpsms' => false,
'infobip' => false,
'sislog' => false,
],

'authenticable-providers' => [
Expand All @@ -40,6 +41,7 @@
'twitter' => [],
'nexmo' => [],
'frontlinesms' => [],
'sislog'=>[],
'gmail' => [
'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob',
'authenticated' => false
Expand Down
1 change: 1 addition & 0 deletions config/features.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'africastalking' => false,
'httpsms' => true,
'infobip' => true,
'sislog' => true,
],

// Client limits
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
ports:
- "33061:3306"
redis:
image: redis:4-alpine
image: redis:7.2-alpine
platform:
build: .
environment:
Expand Down
6 changes: 6 additions & 0 deletions src/Ushahidi/DataSource/DataSourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DataSourceManager
'smssync' => SMSSync\SMSSync::class,
'twilio' => Twilio\Twilio::class,
'twitter' => Twitter\Twitter::class,
'sislog' => Sislog\Sislog::class,
];

/**
Expand Down Expand Up @@ -334,4 +335,9 @@ function ($consumer_key, $consumer_secret, $oauth_access_token, $oauth_access_to
}
);
}

protected function createSislogSource(array $config)
{
return new Sislog\Sislog($config, new \GuzzleHttp\Client());
}
}
181 changes: 181 additions & 0 deletions src/Ushahidi/DataSource/Sislog/Sislog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php

namespace Ushahidi\DataSource\Sislog;

/**
* Sislog Data Provider
*
* @author Ushahidi Team <[email protected]>
* @package DataSource\Sislog
* @copyright 2024 Ushahidi
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License Version 3 (GPLv3)
*/

use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Log;
use Ushahidi\DataSource\Contracts\MessageType;
use Ushahidi\DataSource\Contracts\MessageStatus;
use Ushahidi\DataSource\Contracts\CallbackDataSource;
use Ushahidi\DataSource\Contracts\OutgoingDataSource;
use Ushahidi\DataSource\Concerns\MapsInboundFields;

class Sislog implements CallbackDataSource, OutgoingDataSource
{
use MapsInboundFields;

protected $config;

/**
* Client to talk to the sislog API
*
* @var \Vonage\Message\Client
*/
private $client;

protected $defaultServer = '';

/**
* Constructor function for DataSource
*/
public function __construct(array $config, \GuzzleHttp\Client $client = null)
{
$this->config = $config;
$this->client = $client;
}

public function getName()
{
return 'Sislog';
}

public function getId()
{
return strtolower($this->getName());
}

public function getServices()
{
return [MessageType::SMS];
}

public function getOptions()
{
return [
'server_url' => [
'label' => 'FrontlineSMS Server URL',
'input' => 'text',
'description' => 'The URL where the Sislog server is installed, i.e. https://server.url.com/',
'rules' => ['required']
],
'from' => [
'label' => 'From',
'input' => 'text',
'description' => 'The from number',
'rules' => ['required']
],
'api_username' => [
'label' => 'Username',
'input' => 'text',
'description' => 'The API username',
'rules' => ['required']
],
'api_password' => [
'label' => 'Password',
'input' => 'text',
'description' => 'The API password',
'rules' => ['required']
],
// 'api_secret' => [
// 'label' => 'API secret',
// 'input' => 'text',
// 'description' => 'The API secret',
// 'rules' => ['required']
// ]
];
}

public function getInboundFields()
{
return [
'Message' => 'text'
];
}

public function isUserConfigurable()
{
return true;
}

/**
* @return mixed
*/
public function send($to, $message, $title = "", $contact_type = null)
{
// Obtain server url, ensure it ends with '/'
$serverUrl = $this->config['server_url'] ?? $this->defaultServer;
if (substr($serverUrl, -1) != '/') {
$serverUrl = $serverUrl . '/';
}
// Check we have the required config
if (!isset($this->config['api_username']) || !isset($this->config['api_password'])) {
Log::warning('Could not send message with Sislog, incomplete config');
return [MessageStatus::FAILED, false];
}

$auth = 'Authorization: Basic ' . base64_encode("$this->config['api_username']:$this->config['api_password']");


// Prepare data to send to frontline cloud
$data = [
"From" => "",
"To" => $to,
"Content" => $message
// "ClientReference" => $message
];

// Make a POST request to send the data to frontline cloud

try {
$response = $this->client->request('POST', $serverUrl, [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => $auth
],
'json' => $data
]);
// Successfully executed the request

if ($response->getStatusCode() === 200) {
return [MessageStatus::SENT, false];
}

// Log warning to log file.
$status = $response->getStatusCode();
Log::warning(
'Could not make a successful POST request',
['message' => $response->messages[$status], 'status' => $status]
);
} catch (\GuzzleHttp\Exception\ClientException | \GuzzleHttp\Exception\RequestException $e) {
// Log warning to log file.
Log::warning(
'Could not make a successful POST request',
['message' => $e->getMessage()]
);
}
}

public static function registerRoutes(Router $router)
{
$router->post('sms/sislog', 'Ushahidi\DataSource\Sislog\SislogController@handleRequest');
}

public function verifySecret($secret)
{
if (isset($this->config['secret']) and $secret === $this->config['secret']) {
return true;
}

return false;
}
}
Loading

0 comments on commit 259092d

Please sign in to comment.