|
30 | 30 | use OCA\TwoFactorGateway\Service\Gateway\SMS\GatewayConfig as SMSConfig; |
31 | 31 | use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClickSendConfig; |
32 | 32 | use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClockworkSMSConfig; |
| 33 | +use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\CustomSMS; |
| 34 | +use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\CustomSMSConfig; |
33 | 35 | use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\EcallSMSConfig; |
34 | 36 | use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PlaySMSConfig; |
35 | 37 | use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\Sms77IoConfig; |
@@ -110,12 +112,101 @@ private function configureSignal(InputInterface $input, OutputInterface $output) |
110 | 112 | private function configureSms(InputInterface $input, OutputInterface $output) { |
111 | 113 | $helper = $this->getHelper('question'); |
112 | 114 |
|
113 | | - $providerQuestion = new Question('Please choose a SMS provider (websms, playsms, clockworksms, puzzelsms, ecallsms, voipms, voipbuster, huawei_e3531, spryng, sms77io, ovh, clickatellcentral, clicksend): ', 'websms'); |
| 115 | + $providerQuestion = new Question('Please choose a SMS provider (customsms, websms, playsms, clockworksms, puzzelsms, ecallsms, voipms, voipbuster, huawei_e3531, spryng, sms77io, ovh, clickatellcentral, clicksend): ', 'customsms'); |
114 | 116 | $provider = $helper->ask($input, $output, $providerQuestion); |
115 | 117 |
|
116 | 118 | /** @var SMSConfig $config */ |
117 | 119 | $config = $this->smsGateway->getConfig(); |
118 | 120 | switch ($provider) { |
| 121 | + case 'customsms': |
| 122 | + $config->setProvider($provider); |
| 123 | + /** @var CustomSMSConfig $providerConfig */ |
| 124 | + $providerConfig = $config->getProvider()->getConfig(); |
| 125 | + |
| 126 | + ReTypeUrl: |
| 127 | + $urlQuestion = new Question('Please enter the web service URL: '); |
| 128 | + $url = $helper->ask($input, $output, $urlQuestion); |
| 129 | + |
| 130 | + if(!filter_var($url, FILTER_VALIDATE_URL)) |
| 131 | + { |
| 132 | + $output->writeln('Invalid URL '.$url); |
| 133 | + goto ReTypeUrl; |
| 134 | + } |
| 135 | + |
| 136 | + ReTypeMethod: |
| 137 | + $methodQuestion = new Question('Please enter the web service method (GET or POST): '); |
| 138 | + $method = (string)$helper->ask($input, $output, $methodQuestion); |
| 139 | + |
| 140 | + if(strtolower($method) != 'get' && strtolower($method) != 'post') |
| 141 | + { |
| 142 | + $output->writeln('Invalid method '.$method); |
| 143 | + goto ReTypeMethod; |
| 144 | + } |
| 145 | + |
| 146 | + ReTypeIdentifier: |
| 147 | + $identifierQuestion = new Question('Please enter the identifier parameter for mobile number (Eg. mobile or number): '); |
| 148 | + $identifier = $helper->ask($input, $output, $identifierQuestion); |
| 149 | + |
| 150 | + if(empty($identifier)) |
| 151 | + { |
| 152 | + $output->writeln('Mobile number parameter cannot be empty'); |
| 153 | + goto ReTypeIdentifier; |
| 154 | + } |
| 155 | + |
| 156 | + ReTypeMessage: |
| 157 | + $messageQuestion = new Question('Please enter the message parameter (Eg. msg, sms, message): '); |
| 158 | + $message = $helper->ask($input, $output, $messageQuestion); |
| 159 | + |
| 160 | + if(empty($message)) |
| 161 | + { |
| 162 | + $output->writeln('Message parameter cannot be empty'); |
| 163 | + goto ReTypeMessage; |
| 164 | + } |
| 165 | + |
| 166 | + ReTypeHeaders: |
| 167 | + $headersQuestion = new Question('Please enter any http headers (Eg. x-api-key=123456789&x-api-token=ABCD12345 etc.): '); |
| 168 | + $headers = $helper->ask($input, $output, $headersQuestion); |
| 169 | + |
| 170 | + if(!empty($headers)) |
| 171 | + { |
| 172 | + parse_str($headers, $headers_array); |
| 173 | + if(!is_array($headers_array)) |
| 174 | + { |
| 175 | + $output->writeln('headers is invalid'); |
| 176 | + goto ReTypeHeaders; |
| 177 | + } |
| 178 | + } |
| 179 | + else |
| 180 | + { |
| 181 | + $headers=''; |
| 182 | + } |
| 183 | + |
| 184 | + ReTypeParameters: |
| 185 | + $parametersQuestion = new Question('Please enter any extra parameters (Eg. sender=nextcloud&username=nextcloud&password=1234 etc.): '); |
| 186 | + $parameters = $helper->ask($input, $output, $parametersQuestion); |
| 187 | + |
| 188 | + if(!empty($parameters)) |
| 189 | + { |
| 190 | + parse_str($parameters, $parameters_array); |
| 191 | + if(!is_array($parameters_array)) |
| 192 | + { |
| 193 | + $output->writeln('Extra parameters is invalid'); |
| 194 | + goto ReTypeParameters; |
| 195 | + } |
| 196 | + } |
| 197 | + else |
| 198 | + { |
| 199 | + $parameters=''; |
| 200 | + } |
| 201 | + |
| 202 | + $providerConfig->setUrl($url); |
| 203 | + $providerConfig->setMethod($method); |
| 204 | + $providerConfig->setIdentifier($identifier); |
| 205 | + $providerConfig->setMessage($message); |
| 206 | + $providerConfig->setHeaders($headers); |
| 207 | + $providerConfig->setParameters($parameters); |
| 208 | + |
| 209 | + break; |
119 | 210 | case 'websms': |
120 | 211 | $config->setProvider($provider); |
121 | 212 | /** @var WebSmsConfig $providerConfig */ |
|
0 commit comments