Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion doc/Admin Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ occ twofactorauth:gateway:configure sms
URL: https://www.plivo.com
Stability: Experimental

Use the HTTPS service provided by clicksend.com for sending SMS.
Use the HTTPS service provided by plivo.com for sending SMS.

Interactive admin configuration:
```bash
Expand Down
12 changes: 7 additions & 5 deletions lib/Command/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ private function configureSignal(InputInterface $input, OutputInterface $output)

private function configureSms(InputInterface $input, OutputInterface $output) {
$helper = $this->getHelper('question');

$providerQuestion = new Question('Please choose a SMS provider (websms, playsms, clockworksms, plivo, puzzelsms, ecallsms, voipms, huawei_e3531, spryng, sms77io, ovh, clickatellcentral, clicksend): ', 'websms');
$providerArray = ['websms', 'playsms', 'clockworksms', 'puzzelsms', 'ecallsms', 'voipms', 'huawei_e3531', 'spryng', 'sms77io', 'ovh', 'clickatellcentral', 'clicksend', 'plivo'];
sort($providerArray);
$strOfProviders = implode(',',$providerArray);
$providerQuestion = new Question('Please choose a SMS provider ('.$strOfProviders.'): ', 'websms');
$provider = $helper->ask($input, $output, $providerQuestion);

/** @var SMSConfig $config */
Expand Down Expand Up @@ -326,16 +328,16 @@ private function configureSms(InputInterface $input, OutputInterface $output) {
$authTokenQuestion = new Question('Please enter your plivo authentication token (Auth Token): ');
$authToken = $helper->ask($input, $output, $authTokenQuestion);

$srcNumberQuestion = new Question('Please enter your plivo phone number (in E.164 format): ');
$srcNumberQuestion = new Question("Please enter your plivo phone number (in E.164 format '+12345678901'): ");
$srcNumber = $helper->ask($input, $output, $srcNumberQuestion);

$callbackUrlQuestion = new Question('Please enter your plivo callback url: ');
$callbackUrl = $helper->ask($input, $output, $callbackUrlQuestion);

$providerConfig->setValue($providerConfig::AUTH_ID_KEY,$authId);
$providerConfig->setValue($providerConfig::AUTH_TOKEN_KEY, $authToken);
$providerConfig->setValue($providerConfig::CALLBACK_URL, $srcNumber);
$providerConfig->setValue($providerConfig::SRC_NUMBER_KEY, $callbackUrl);
$providerConfig->setValue($providerConfig::CALLBACK_URL, $callbackUrl);
$providerConfig->setValue($providerConfig::SRC_NUMBER_KEY, $srcNumber);

break;

Expand Down
10 changes: 5 additions & 5 deletions lib/Service/Gateway/SMS/Provider/Plivo.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public function send(string $identifier, string $message) {
try {
$this->client->get("https://api.plivo.com/v1/Account/$authID/Message/", [
'body' => json_encode([
'to' => $identifier,
'src' => $srcNumber,
'txt' => $message,
'url' => $callbackUrl
],JSON_FORCE_OBJECT),
'to' => $identifier,
'src' => $srcNumber,
'txt' => $message,
'url' => $callbackUrl
],JSON_FORCE_OBJECT),
'headers' => [
'Content-Type' => "application/json",
'Authorization' => "Basic " . base64_encode($authID.':'.$authToken)
Expand Down
27 changes: 13 additions & 14 deletions lib/Service/Gateway/SMS/Provider/PlivoConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;


use function array_intersect;
use OCA\TwoFactorGateway\AppInfo\Application;
use OCA\TwoFactorGateway\Exception\ConfigurationException;
Expand All @@ -40,11 +39,11 @@ class PlivoConfig implements IProviderConfig {
public const SRC_NUMBER_KEY = 'plivo_src_number';

private const EXPECTED_KEYS = [
self::AUTH_ID_KEY,
self::AUTH_TOKEN_KEY,
self::CALLBACK_URL,
self::SRC_NUMBER_KEY
];
self::AUTH_ID_KEY,
self::AUTH_TOKEN_KEY,
self::CALLBACK_URL,
self::SRC_NUMBER_KEY
];

public function __construct(IConfig $config) {
$this->config = $config;
Expand All @@ -59,20 +58,20 @@ private function getInternalValue(string $key): string {
}

public function getValue(string $key): string {
return $this->getInternalValue($key);
}
return $this->getInternalValue($key);
}

public function setValue(string $key, string $value) {
$this->config->setAppValue(Application::APP_NAME, $key, $value);
}
public function isComplete(): bool {
public function setValue(string $key, string $value) {
$this->config->setAppValue(Application::APP_NAME, $key, $value);
}
public function isComplete(): bool {
$set = $this->config->getAppKeys(Application::APP_NAME);
return count(array_intersect($set,self::EXPECTED_KEYS)) === count($expected);
}

public function remove() {
foreach(self::EXPECTED_KEYS as $key) {
foreach (self::EXPECTED_KEYS as $key) {
$this->config->deleteAppValue(Application::APP_NAME, $key);
}
}
Expand Down