| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,342 @@ |
| 1 |
+<?php |
|
| 2 |
+/** |
|
| 3 |
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
| 4 |
+ * |
|
| 5 |
+ * @author Double Bastion LLC |
|
| 6 |
+ * |
|
| 7 |
+ * @license GNU AGPL version 3 or any later version |
|
| 8 |
+ * |
|
| 9 |
+ * This program is free software; you can redistribute it and/or |
|
| 10 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
| 11 |
+ * License as published by the Free Software Foundation; either |
|
| 12 |
+ * version 3 of the License, or any later version. |
|
| 13 |
+ * |
|
| 14 |
+ * This program is distributed in the hope that it will be useful, |
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
| 18 |
+ * |
|
| 19 |
+ * You should have received a copy of the GNU Affero General Public |
|
| 20 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 |
+ * |
|
| 22 |
+ */ |
|
| 23 |
+ |
|
| 24 |
+declare(strict_types=1); |
|
| 25 |
+ |
|
| 26 |
+namespace OCA\PaxFax\Service; |
|
| 27 |
+ |
|
| 28 |
+use OCP\DB\QueryBuilder\IQueryBuilder; |
|
| 29 |
+use OCP\IDBConnection; |
|
| 30 |
+use OCP\Security\ICrypto; |
|
| 31 |
+use OCP\AppFramework\ApiController; |
|
| 32 |
+use OCP\IRequest; |
|
| 33 |
+use OCP\AppFramework\Controller; |
|
| 34 |
+use OCP\Files\IAppData; |
|
| 35 |
+use OCP\AppFramework\App; |
|
| 36 |
+use OCP\Files\NotPermittedException; |
|
| 37 |
+use OCP\Files\Folder; |
|
| 38 |
+use OC\Files\Filesystem; |
|
| 39 |
+use \ReflectionClass; |
|
| 40 |
+ |
|
| 41 |
+use Phaxio; |
|
| 42 |
+use Phaxio\OperationResult; |
|
| 43 |
+use Phaxio\Error\AuthenticationException; |
|
| 44 |
+use Phaxio\Error\NotFoundException; |
|
| 45 |
+use Phaxio\Error\InvalidRequestException; |
|
| 46 |
+use Phaxio\Error\RateLimitException; |
|
| 47 |
+use Phaxio\Error\APIConnectionException; |
|
| 48 |
+use Phaxio\Error\GeneralException; |
|
| 49 |
+ |
|
| 50 |
+ |
|
| 51 |
+class PaxfaxService {
|
|
| 52 |
+ |
|
| 53 |
+ private $connection; |
|
| 54 |
+ |
|
| 55 |
+ private $crypto; |
|
| 56 |
+ |
|
| 57 |
+ public function __construct(IDBConnection $connection, ICrypto $crypto) {
|
|
| 58 |
+ |
|
| 59 |
+ $this->connection = $connection; |
|
| 60 |
+ |
|
| 61 |
+ $this->crypto = $crypto; |
|
| 62 |
+ } |
|
| 63 |
+ |
|
| 64 |
+ |
|
| 65 |
+ /** |
|
| 66 |
+ * @NoAdminRequired |
|
| 67 |
+ */ |
|
| 68 |
+ public function object_to_array($obj) {
|
|
| 69 |
+ if(is_object($obj)) $obj = (array)$this->dismount($obj); |
|
| 70 |
+ if(is_array($obj)) {
|
|
| 71 |
+ $new = array(); |
|
| 72 |
+ foreach($obj as $key => $val) {
|
|
| 73 |
+ $new[$key] = $this->object_to_array($val); |
|
| 74 |
+ } |
|
| 75 |
+ } |
|
| 76 |
+ else $new = $obj; |
|
| 77 |
+ return $new; |
|
| 78 |
+ } |
|
| 79 |
+ |
|
| 80 |
+ |
|
| 81 |
+ /** |
|
| 82 |
+ * @NoAdminRequired |
|
| 83 |
+ */ |
|
| 84 |
+ public function dismount($object) {
|
|
| 85 |
+ $reflectionClass = new ReflectionClass(get_class($object)); |
|
| 86 |
+ $array = array(); |
|
| 87 |
+ foreach ($reflectionClass->getProperties() as $property) {
|
|
| 88 |
+ $property->setAccessible(true); |
|
| 89 |
+ $array[$property->getName()] = $property->getValue($object); |
|
| 90 |
+ $property->setAccessible(false); |
|
| 91 |
+ } |
|
| 92 |
+ return $array; |
|
| 93 |
+ } |
|
| 94 |
+ |
|
| 95 |
+ |
|
| 96 |
+ /** |
|
| 97 |
+ * @NoAdminRequired |
|
| 98 |
+ * |
|
| 99 |
+ */ |
|
| 100 |
+ public function getsettings($userId) {
|
|
| 101 |
+ |
|
| 102 |
+ $sql = $this->connection->prepare('
|
|
| 103 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `sinch_project_id`, `sinch_key_id`, `sinch_key_secret`, `sinch_service_id`, `sinch_callback_url`, `get_notification`, `notification_email` |
|
| 104 |
+ FROM `*PREFIX*pax_fax` |
|
| 105 |
+ WHERE `user_id` = ?'); |
|
| 106 |
+ $result = $sql->execute([$userId]); |
|
| 107 |
+ $settingsfromdb = $result->fetch(); |
|
| 108 |
+ $result->closeCursor(); |
|
| 109 |
+ |
|
| 110 |
+ if ($settingsfromdb) {
|
|
| 111 |
+ |
|
| 112 |
+ if ($settingsfromdb['api_key'] != '') {
|
|
| 113 |
+ |
|
| 114 |
+ // Send a placeholder to the browser, instead of the real data |
|
| 115 |
+ $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 116 |
+ } |
|
| 117 |
+ if ($settingsfromdb['api_secret'] != '') {
|
|
| 118 |
+ $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 119 |
+ } |
|
| 120 |
+ if ($settingsfromdb['webhook_token'] != '') {
|
|
| 121 |
+ $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 122 |
+ } |
|
| 123 |
+ if ($settingsfromdb['receive_url'] != '') {
|
|
| 124 |
+ $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 125 |
+ } |
|
| 126 |
+ if ($settingsfromdb['sinch_project_id'] != '') {
|
|
| 127 |
+ $settingsfromdb['sinch_project_id'] = "%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 128 |
+ } |
|
| 129 |
+ if ($settingsfromdb['sinch_key_id'] != '') {
|
|
| 130 |
+ $settingsfromdb['sinch_key_id'] = "%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 131 |
+ } |
|
| 132 |
+ if ($settingsfromdb['sinch_key_secret'] != '') {
|
|
| 133 |
+ $settingsfromdb['sinch_key_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 134 |
+ } |
|
| 135 |
+ if ($settingsfromdb['sinch_service_id'] != '') {
|
|
| 136 |
+ $settingsfromdb['sinch_service_id'] = "%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 137 |
+ } |
|
| 138 |
+ if ($settingsfromdb['sinch_callback_url'] != '') {
|
|
| 139 |
+ $settingsfromdb['sinch_callback_url'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 140 |
+ } |
|
| 141 |
+ return $settingsfromdb; |
|
| 142 |
+ } |
|
| 143 |
+ } |
|
| 144 |
+ |
|
| 145 |
+ |
|
| 146 |
+ /** |
|
| 147 |
+ * @NoAdminRequired |
|
| 148 |
+ * |
|
| 149 |
+ */ |
|
| 150 |
+ public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $sinchProjectId, $sinchKeyId, $sinchKeySecret, $sinchServiceId, $sinchCallbackUrl, $getNotification, $notificationEmail) {
|
|
| 151 |
+ |
|
| 152 |
+ $sqlsel = $this->connection->prepare('
|
|
| 153 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `sinch_project_id`, `sinch_key_id`, `sinch_key_secret`, `sinch_service_id`, `sinch_callback_url`, `get_notification`, `notification_email` |
|
| 154 |
+ FROM `*PREFIX*pax_fax` |
|
| 155 |
+ WHERE `user_id` = ?'); |
|
| 156 |
+ $resultsel = $sqlsel->execute([$userId]); |
|
| 157 |
+ $row = $resultsel->fetch(); |
|
| 158 |
+ $resultsel->closeCursor(); |
|
| 159 |
+ |
|
| 160 |
+ if ($resultsel && !$row) {
|
|
| 161 |
+ |
|
| 162 |
+ if ($apiKey != '') {
|
|
| 163 |
+ $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 164 |
+ } else { $apikeystrenc = ''; }
|
|
| 165 |
+ |
|
| 166 |
+ if ($apiSecret != '') {
|
|
| 167 |
+ $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 168 |
+ } else { $apisecretstrenc = ''; }
|
|
| 169 |
+ |
|
| 170 |
+ if ($webhookToken != '') {
|
|
| 171 |
+ $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 172 |
+ } else { $webhookTokenenc = ''; }
|
|
| 173 |
+ |
|
| 174 |
+ if ($receiveUrl != '') {
|
|
| 175 |
+ $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 176 |
+ } else { $receiveUrlenc = ''; }
|
|
| 177 |
+ |
|
| 178 |
+ if ($sinchProjectId != '') {
|
|
| 179 |
+ $sinchProjectIdenc = $this->crypto->encrypt($sinchProjectId); |
|
| 180 |
+ } else { $sinchProjectIdenc = ''; }
|
|
| 181 |
+ |
|
| 182 |
+ if ($sinchKeyId != '') {
|
|
| 183 |
+ $sinchKeyIdenc = $this->crypto->encrypt($sinchKeyId); |
|
| 184 |
+ } else { $sinchKeyIdenc = ''; }
|
|
| 185 |
+ |
|
| 186 |
+ if ($sinchKeySecret != '') {
|
|
| 187 |
+ $sinchKeySecretenc = $this->crypto->encrypt($sinchKeySecret); |
|
| 188 |
+ } else { $sinchKeySecretenc = ''; }
|
|
| 189 |
+ |
|
| 190 |
+ if ($sinchServiceId != '') {
|
|
| 191 |
+ $sinchServiceIdenc = $this->crypto->encrypt($sinchServiceId); |
|
| 192 |
+ } else { $sinchServiceIdenc = ''; }
|
|
| 193 |
+ |
|
| 194 |
+ if ($sinchCallbackUrl != '') {
|
|
| 195 |
+ $sinchCallbackUrlenc = $this->crypto->encrypt($sinchCallbackUrl); |
|
| 196 |
+ } else { $sinchCallbackUrlenc = ''; }
|
|
| 197 |
+ |
|
| 198 |
+ $sqlns = $this->connection->prepare('
|
|
| 199 |
+ INSERT INTO `*PREFIX*pax_fax` |
|
| 200 |
+ (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `sinch_project_id`, `sinch_key_id`, `sinch_key_secret`, `sinch_service_id`, `sinch_callback_url`, `get_notification`, `notification_email`) |
|
| 201 |
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); |
|
| 202 |
+ $sqlns->execute([$userId, $apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $sinchProjectIdenc, $sinchKeyIdenc, $sinchKeySecretenc, $sinchServiceIdenc, $sinchCallbackUrlenc, $getNotification, $notificationEmail]); |
|
| 203 |
+ |
|
| 204 |
+ } elseif ($resultsel && $row) {
|
|
| 205 |
+ |
|
| 206 |
+ if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 207 |
+ $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 208 |
+ } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 209 |
+ $apikeystrenc = $row['api_key']; |
|
| 210 |
+ } elseif ($apiKey == '') {
|
|
| 211 |
+ $apikeystrenc = ''; |
|
| 212 |
+ } |
|
| 213 |
+ |
|
| 214 |
+ if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 215 |
+ $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 216 |
+ } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 217 |
+ $apisecretstrenc = $row['api_secret']; |
|
| 218 |
+ } elseif ($apiSecret == '') {
|
|
| 219 |
+ $apisecretstrenc = ''; |
|
| 220 |
+ } |
|
| 221 |
+ |
|
| 222 |
+ if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 223 |
+ $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 224 |
+ } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 225 |
+ $webhookTokenenc = $row['webhook_token']; |
|
| 226 |
+ } elseif ($webhookToken == '') {
|
|
| 227 |
+ $webhookTokenenc = ''; |
|
| 228 |
+ } |
|
| 229 |
+ |
|
| 230 |
+ if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 231 |
+ $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 232 |
+ } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 233 |
+ $receiveUrlenc = $row['receive_url']; |
|
| 234 |
+ } elseif ($receiveUrl == '') {
|
|
| 235 |
+ $receiveUrlenc = ''; |
|
| 236 |
+ } |
|
| 237 |
+ |
|
| 238 |
+ if ($sinchProjectId != '' && $sinchProjectId != "%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 239 |
+ $sinchProjectIdenc = $this->crypto->encrypt($sinchProjectId); |
|
| 240 |
+ } elseif ($sinchProjectId == "%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 241 |
+ $sinchProjectIdenc = $row['sinch_project_id']; |
|
| 242 |
+ } elseif ($sinchProjectId == '') {
|
|
| 243 |
+ $sinchProjectIdenc = ''; |
|
| 244 |
+ } |
|
| 245 |
+ |
|
| 246 |
+ if ($sinchKeyId != '' && $sinchKeyId != "%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 247 |
+ $sinchKeyIdenc = $this->crypto->encrypt($sinchKeyId); |
|
| 248 |
+ } elseif ($sinchKeyId == "%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 249 |
+ $sinchKeyIdenc = $row['sinch_key_id']; |
|
| 250 |
+ } elseif ($sinchKeyId == '') {
|
|
| 251 |
+ $sinchKeyIdenc = ''; |
|
| 252 |
+ } |
|
| 253 |
+ |
|
| 254 |
+ if ($sinchKeySecret != '' && $sinchKeySecret != "%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 255 |
+ $sinchKeySecretenc = $this->crypto->encrypt($sinchKeySecret); |
|
| 256 |
+ } elseif ($sinchKeySecret == "%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 257 |
+ $sinchKeySecretenc = $row['sinch_key_secret']; |
|
| 258 |
+ } elseif ($sinchKeySecret == '') {
|
|
| 259 |
+ $sinchKeySecretenc = ''; |
|
| 260 |
+ } |
|
| 261 |
+ |
|
| 262 |
+ if ($sinchServiceId != '' && $sinchServiceId != "%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 263 |
+ $sinchServiceIdenc = $this->crypto->encrypt($sinchServiceId); |
|
| 264 |
+ } elseif ($sinchServiceId == "%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 265 |
+ $sinchServiceIdenc = $row['sinch_service_id']; |
|
| 266 |
+ } elseif ($sinchServiceId == '') {
|
|
| 267 |
+ $sinchServiceIdenc = ''; |
|
| 268 |
+ } |
|
| 269 |
+ |
|
| 270 |
+ if ($sinchCallbackUrl != '' && $sinchCallbackUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 271 |
+ $sinchCallbackUrlenc = $this->crypto->encrypt($sinchCallbackUrl); |
|
| 272 |
+ } elseif ($sinchCallbackUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 273 |
+ $sinchCallbackUrlenc = $row['sinch_callback_url']; |
|
| 274 |
+ } elseif ($sinchCallbackUrl == '') {
|
|
| 275 |
+ $sinchCallbackUrlenc = ''; |
|
| 276 |
+ } |
|
| 277 |
+ |
|
| 278 |
+ $sqlup = $this->connection->prepare('
|
|
| 279 |
+ UPDATE `*PREFIX*pax_fax` |
|
| 280 |
+ SET `api_key` = ?, `api_secret` = ?, `webhook_token` = ?, `receive_url` = ?, `sinch_project_id` = ?, `sinch_key_id` = ?, `sinch_key_secret` = ?, `sinch_service_id` = ?, `sinch_callback_url` = ?, `get_notification` = ?, `notification_email` = ? |
|
| 281 |
+ WHERE `user_id` = ?'); |
|
| 282 |
+ $updateRes = $sqlup->execute([$apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $sinchProjectIdenc, $sinchKeyIdenc, $sinchKeySecretenc, $sinchServiceIdenc, $sinchCallbackUrlenc, $getNotification, $notificationEmail, $userId]); |
|
| 283 |
+ $updateRes->closeCursor(); |
|
| 284 |
+ } |
|
| 285 |
+ } |
|
| 286 |
+ |
|
| 287 |
+ /** |
|
| 288 |
+ * @NoAdminRequired |
|
| 289 |
+ */ |
|
| 290 |
+ public function getapicredentials($userId) {
|
|
| 291 |
+ |
|
| 292 |
+ $sqlselcr = $this->connection->prepare('
|
|
| 293 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `sinch_project_id`, `sinch_key_id`, `sinch_key_secret`, `sinch_service_id`, `sinch_callback_url`, `get_notification`, `notification_email` |
|
| 294 |
+ FROM `*PREFIX*pax_fax` |
|
| 295 |
+ WHERE `user_id` = ?'); |
|
| 296 |
+ $resultselcr = $sqlselcr->execute([$userId]); |
|
| 297 |
+ $settingsfrdb = $resultselcr->fetch(); |
|
| 298 |
+ $resultselcr->closeCursor(); |
|
| 299 |
+ |
|
| 300 |
+ if (($settingsfrdb['api_key'] != '') && ($settingsfrdb['api_key'] != 'undefined') && ($settingsfrdb['api_key'] != null)) {
|
|
| 301 |
+ $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key']); |
|
| 302 |
+ } else { $apikeystr = ''; }
|
|
| 303 |
+ |
|
| 304 |
+ if (($settingsfrdb['api_secret'] != '') && ($settingsfrdb['api_secret'] != 'undefined') && ($settingsfrdb['api_secret'] != null)) {
|
|
| 305 |
+ $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret']); |
|
| 306 |
+ } else { $apisecretstr = ''; }
|
|
| 307 |
+ |
|
| 308 |
+ if (($settingsfrdb['webhook_token'] != '') && ($settingsfrdb['webhook_token'] != 'undefined') && ($settingsfrdb['webhook_token'] != null)) {
|
|
| 309 |
+ $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token']); |
|
| 310 |
+ } else { $webhookToken = ''; }
|
|
| 311 |
+ |
|
| 312 |
+ if (($settingsfrdb['receive_url'] != '') && ($settingsfrdb['receive_url'] != 'undefined') && ($settingsfrdb['receive_url'] != null)) {
|
|
| 313 |
+ $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url']); |
|
| 314 |
+ } else { $receiveUrl = ''; }
|
|
| 315 |
+ |
|
| 316 |
+ if (($settingsfrdb['sinch_project_id'] != '') && ($settingsfrdb['sinch_project_id'] != 'undefined') && ($settingsfrdb['sinch_project_id'] != null)) {
|
|
| 317 |
+ $sinchProjectId = $this->crypto->decrypt($settingsfrdb['sinch_project_id']); |
|
| 318 |
+ } else { $sinchProjectId = ''; }
|
|
| 319 |
+ |
|
| 320 |
+ if (($settingsfrdb['sinch_key_id'] != '') && ($settingsfrdb['sinch_key_id'] != 'undefined') && ($settingsfrdb['sinch_key_id'] != null)) {
|
|
| 321 |
+ $sinchKeyId = $this->crypto->decrypt($settingsfrdb['sinch_key_id']); |
|
| 322 |
+ } else { $sinchKeyId = ''; }
|
|
| 323 |
+ |
|
| 324 |
+ if (($settingsfrdb['sinch_key_secret'] != '') && ($settingsfrdb['sinch_key_secret'] != 'undefined') && ($settingsfrdb['sinch_key_secret'] != null)) {
|
|
| 325 |
+ $sinchKeySecret = $this->crypto->decrypt($settingsfrdb['sinch_key_secret']); |
|
| 326 |
+ } else { $sinchKeySecret = ''; }
|
|
| 327 |
+ |
|
| 328 |
+ if (($settingsfrdb['sinch_service_id'] != '') && ($settingsfrdb['sinch_service_id'] != 'undefined') && ($settingsfrdb['sinch_service_id'] != null)) {
|
|
| 329 |
+ $sinchServiceId = $this->crypto->decrypt($settingsfrdb['sinch_service_id']); |
|
| 330 |
+ } else { $sinchServiceId = ''; }
|
|
| 331 |
+ |
|
| 332 |
+ if (($settingsfrdb['sinch_callback_url'] != '') && ($settingsfrdb['sinch_callback_url'] != 'undefined') && ($settingsfrdb['sinch_callback_url'] != null)) {
|
|
| 333 |
+ $sinchCallbackUrl = $this->crypto->decrypt($settingsfrdb['sinch_callback_url']); |
|
| 334 |
+ } else { $sinchCallbackUrl = ''; }
|
|
| 335 |
+ |
|
| 336 |
+ $getnotification = $settingsfrdb['get_notification']; |
|
| 337 |
+ $notifyemail = $settingsfrdb['notification_email']; |
|
| 338 |
+ |
|
| 339 |
+ return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $sinchProjectId, $sinchKeyId, $sinchKeySecret, $sinchServiceId, $sinchCallbackUrl, $getnotification, $notifyemail]; |
|
| 340 |
+ } |
|
| 341 |
+ |
|
| 342 |
+} |
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,248 +0,0 @@ |
| 1 |
-<?php |
|
| 2 |
-/** |
|
| 3 |
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
| 4 |
- * |
|
| 5 |
- * @author Double Bastion LLC |
|
| 6 |
- * |
|
| 7 |
- * @license GNU AGPL version 3 or any later version |
|
| 8 |
- * |
|
| 9 |
- * This program is free software; you can redistribute it and/or |
|
| 10 |
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
| 11 |
- * License as published by the Free Software Foundation; either |
|
| 12 |
- * version 3 of the License, or any later version. |
|
| 13 |
- * |
|
| 14 |
- * This program is distributed in the hope that it will be useful, |
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 |
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
| 18 |
- * |
|
| 19 |
- * You should have received a copy of the GNU Affero General Public |
|
| 20 |
- * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 |
- * |
|
| 22 |
- */ |
|
| 23 |
- |
|
| 24 |
-declare(strict_types=1); |
|
| 25 |
- |
|
| 26 |
-namespace OCA\PaxFax\Service; |
|
| 27 |
- |
|
| 28 |
-use OCP\DB\QueryBuilder\IQueryBuilder; |
|
| 29 |
-use OCP\IDBConnection; |
|
| 30 |
-use OCP\Security\ICrypto; |
|
| 31 |
-use OCP\AppFramework\ApiController; |
|
| 32 |
-use OCP\IRequest; |
|
| 33 |
-use OCP\AppFramework\Controller; |
|
| 34 |
-use OCP\Files\IAppData; |
|
| 35 |
-use OCP\AppFramework\App; |
|
| 36 |
-use OCP\Files\NotPermittedException; |
|
| 37 |
-use OCP\Files\Folder; |
|
| 38 |
-use OC\Files\Filesystem; |
|
| 39 |
-use \ReflectionClass; |
|
| 40 |
- |
|
| 41 |
-use Phaxio; |
|
| 42 |
-use Phaxio\OperationResult; |
|
| 43 |
-use Phaxio\Error\AuthenticationException; |
|
| 44 |
-use Phaxio\Error\NotFoundException; |
|
| 45 |
-use Phaxio\Error\InvalidRequestException; |
|
| 46 |
-use Phaxio\Error\RateLimitException; |
|
| 47 |
-use Phaxio\Error\APIConnectionException; |
|
| 48 |
-use Phaxio\Error\GeneralException; |
|
| 49 |
- |
|
| 50 |
- |
|
| 51 |
-class PaxfaxService {
|
|
| 52 |
- |
|
| 53 |
- private $connection; |
|
| 54 |
- |
|
| 55 |
- private $crypto; |
|
| 56 |
- |
|
| 57 |
- public function __construct(IDBConnection $connection, ICrypto $crypto) {
|
|
| 58 |
- |
|
| 59 |
- $this->connection = $connection; |
|
| 60 |
- |
|
| 61 |
- $this->crypto = $crypto; |
|
| 62 |
- } |
|
| 63 |
- |
|
| 64 |
- |
|
| 65 |
- /** |
|
| 66 |
- * @NoAdminRequired |
|
| 67 |
- */ |
|
| 68 |
- public function object_to_array($obj) {
|
|
| 69 |
- if(is_object($obj)) $obj = (array)$this->dismount($obj); |
|
| 70 |
- if(is_array($obj)) {
|
|
| 71 |
- $new = array(); |
|
| 72 |
- foreach($obj as $key => $val) {
|
|
| 73 |
- $new[$key] = $this->object_to_array($val); |
|
| 74 |
- } |
|
| 75 |
- } |
|
| 76 |
- else $new = $obj; |
|
| 77 |
- return $new; |
|
| 78 |
- } |
|
| 79 |
- |
|
| 80 |
- |
|
| 81 |
- /** |
|
| 82 |
- * @NoAdminRequired |
|
| 83 |
- */ |
|
| 84 |
- public function dismount($object) {
|
|
| 85 |
- $reflectionClass = new ReflectionClass(get_class($object)); |
|
| 86 |
- $array = array(); |
|
| 87 |
- foreach ($reflectionClass->getProperties() as $property) {
|
|
| 88 |
- $property->setAccessible(true); |
|
| 89 |
- $array[$property->getName()] = $property->getValue($object); |
|
| 90 |
- $property->setAccessible(false); |
|
| 91 |
- } |
|
| 92 |
- return $array; |
|
| 93 |
- } |
|
| 94 |
- |
|
| 95 |
- |
|
| 96 |
- /** |
|
| 97 |
- * @NoAdminRequired |
|
| 98 |
- * |
|
| 99 |
- */ |
|
| 100 |
- public function getsettings($userId) {
|
|
| 101 |
- |
|
| 102 |
- $sql = $this->connection->prepare('
|
|
| 103 |
- SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 104 |
- FROM `*PREFIX*pax_fax` |
|
| 105 |
- WHERE `user_id` = ?'); |
|
| 106 |
- $result = $sql->execute([$userId]); |
|
| 107 |
- $settingsfromdb = $result->fetch(); |
|
| 108 |
- $result->closeCursor(); |
|
| 109 |
- |
|
| 110 |
- if ($settingsfromdb) {
|
|
| 111 |
- |
|
| 112 |
- if ($settingsfromdb['api_key'] != '') {
|
|
| 113 |
- |
|
| 114 |
- // Send a placeholder to the browser, instead of the real data |
|
| 115 |
- $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 116 |
- } |
|
| 117 |
- if ($settingsfromdb['api_secret'] != '') {
|
|
| 118 |
- $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 119 |
- } |
|
| 120 |
- if ($settingsfromdb['webhook_token'] != '') {
|
|
| 121 |
- $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 122 |
- } |
|
| 123 |
- if ($settingsfromdb['receive_url'] != '') {
|
|
| 124 |
- $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 125 |
- } |
|
| 126 |
- |
|
| 127 |
- return $settingsfromdb; |
|
| 128 |
- } |
|
| 129 |
- } |
|
| 130 |
- |
|
| 131 |
- |
|
| 132 |
- /** |
|
| 133 |
- * @NoAdminRequired |
|
| 134 |
- * |
|
| 135 |
- */ |
|
| 136 |
- public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
|
|
| 137 |
- |
|
| 138 |
- $sqlsel = $this->connection->prepare('
|
|
| 139 |
- SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 140 |
- FROM `*PREFIX*pax_fax` |
|
| 141 |
- WHERE `user_id` = ?'); |
|
| 142 |
- $resultsel = $sqlsel->execute([$userId]); |
|
| 143 |
- $row = $resultsel->fetch(); |
|
| 144 |
- $resultsel->closeCursor(); |
|
| 145 |
- |
|
| 146 |
- if ($resultsel && !$row) {
|
|
| 147 |
- |
|
| 148 |
- if ($apiKey != '') {
|
|
| 149 |
- $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 150 |
- } else { $apikeystrenc = ''; }
|
|
| 151 |
- |
|
| 152 |
- if ($apiSecret != '') {
|
|
| 153 |
- $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 154 |
- } else { $apisecretstrenc = ''; }
|
|
| 155 |
- |
|
| 156 |
- if ($webhookToken != '') {
|
|
| 157 |
- $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 158 |
- } else { $webhookTokenenc = ''; }
|
|
| 159 |
- |
|
| 160 |
- if ($receiveUrl != '') {
|
|
| 161 |
- $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 162 |
- } else { $receiveUrlenc = ''; }
|
|
| 163 |
- |
|
| 164 |
- $sqlns = $this->connection->prepare('
|
|
| 165 |
- INSERT INTO `*PREFIX*pax_fax` |
|
| 166 |
- (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`) |
|
| 167 |
- VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
| 168 |
- $sqlns->execute([$userId, $apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail]); |
|
| 169 |
- |
|
| 170 |
- } elseif ($resultsel && $row) {
|
|
| 171 |
- |
|
| 172 |
- if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 173 |
- $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 174 |
- } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 175 |
- $apikeystrenc = $row['api_key']; |
|
| 176 |
- } elseif ($apiKey == '') {
|
|
| 177 |
- $apikeystrenc = ''; |
|
| 178 |
- } |
|
| 179 |
- |
|
| 180 |
- if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 181 |
- $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 182 |
- } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 183 |
- $apisecretstrenc = $row['api_secret']; |
|
| 184 |
- } elseif ($apiSecret == '') {
|
|
| 185 |
- $apisecretstrenc = ''; |
|
| 186 |
- } |
|
| 187 |
- |
|
| 188 |
- if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 189 |
- $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 190 |
- } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 191 |
- $webhookTokenenc = $row['webhook_token']; |
|
| 192 |
- } elseif ($webhookToken == '') {
|
|
| 193 |
- $webhookTokenenc = ''; |
|
| 194 |
- } |
|
| 195 |
- |
|
| 196 |
- if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 197 |
- $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 198 |
- } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 199 |
- $receiveUrlenc = $row['receive_url']; |
|
| 200 |
- } elseif ($receiveUrl == '') {
|
|
| 201 |
- $receiveUrlenc = ''; |
|
| 202 |
- } |
|
| 203 |
- |
|
| 204 |
- $sqlup = $this->connection->prepare('
|
|
| 205 |
- UPDATE `*PREFIX*pax_fax` |
|
| 206 |
- SET `api_key` = ?, `api_secret` = ?, `webhook_token` = ?, `receive_url` = ?, `get_notification` = ?, `notification_email` = ? |
|
| 207 |
- WHERE `user_id` = ?'); |
|
| 208 |
- $updateRes = $sqlup->execute([$apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail, $userId]); |
|
| 209 |
- $updateRes->closeCursor(); |
|
| 210 |
- } |
|
| 211 |
- } |
|
| 212 |
- |
|
| 213 |
- /** |
|
| 214 |
- * @NoAdminRequired |
|
| 215 |
- */ |
|
| 216 |
- public function getapicredentials($userId) {
|
|
| 217 |
- |
|
| 218 |
- $sqlselcr = $this->connection->prepare('
|
|
| 219 |
- SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 220 |
- FROM `*PREFIX*pax_fax` |
|
| 221 |
- WHERE `user_id` = ?'); |
|
| 222 |
- $resultselcr = $sqlselcr->execute([$userId]); |
|
| 223 |
- $settingsfrdb = $resultselcr->fetch(); |
|
| 224 |
- $resultselcr->closeCursor(); |
|
| 225 |
- |
|
| 226 |
- if (($settingsfrdb['api_key'] != '') && ($settingsfrdb['api_key'] != 'undefined') && ($settingsfrdb['api_key'] != null)) {
|
|
| 227 |
- $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key']); |
|
| 228 |
- } else { $apikeystr = ''; }
|
|
| 229 |
- |
|
| 230 |
- if (($settingsfrdb['api_secret'] != '') && ($settingsfrdb['api_secret'] != 'undefined') && ($settingsfrdb['api_secret'] != null)) {
|
|
| 231 |
- $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret']); |
|
| 232 |
- } else { $apisecretstr = ''; }
|
|
| 233 |
- |
|
| 234 |
- if (($settingsfrdb['webhook_token'] != '') && ($settingsfrdb['webhook_token'] != 'undefined') && ($settingsfrdb['webhook_token'] != null)) {
|
|
| 235 |
- $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token']); |
|
| 236 |
- } else { $webhookToken = ''; }
|
|
| 237 |
- |
|
| 238 |
- if (($settingsfrdb['receive_url'] != '') && ($settingsfrdb['receive_url'] != 'undefined') && ($settingsfrdb['receive_url'] != null)) {
|
|
| 239 |
- $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url']); |
|
| 240 |
- } else { $receiveUrl = ''; }
|
|
| 241 |
- |
|
| 242 |
- $getnotification = $settingsfrdb['get_notification']; |
|
| 243 |
- $notifyemail = $settingsfrdb['notification_email']; |
|
| 244 |
- |
|
| 245 |
- return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail]; |
|
| 246 |
- } |
|
| 247 |
- |
|
| 248 |
-} |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,248 @@ |
| 1 |
+<?php |
|
| 2 |
+/** |
|
| 3 |
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
| 4 |
+ * |
|
| 5 |
+ * @author Double Bastion LLC |
|
| 6 |
+ * |
|
| 7 |
+ * @license GNU AGPL version 3 or any later version |
|
| 8 |
+ * |
|
| 9 |
+ * This program is free software; you can redistribute it and/or |
|
| 10 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
| 11 |
+ * License as published by the Free Software Foundation; either |
|
| 12 |
+ * version 3 of the License, or any later version. |
|
| 13 |
+ * |
|
| 14 |
+ * This program is distributed in the hope that it will be useful, |
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
| 18 |
+ * |
|
| 19 |
+ * You should have received a copy of the GNU Affero General Public |
|
| 20 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 |
+ * |
|
| 22 |
+ */ |
|
| 23 |
+ |
|
| 24 |
+declare(strict_types=1); |
|
| 25 |
+ |
|
| 26 |
+namespace OCA\PaxFax\Service; |
|
| 27 |
+ |
|
| 28 |
+use OCP\DB\QueryBuilder\IQueryBuilder; |
|
| 29 |
+use OCP\IDBConnection; |
|
| 30 |
+use OCP\Security\ICrypto; |
|
| 31 |
+use OCP\AppFramework\ApiController; |
|
| 32 |
+use OCP\IRequest; |
|
| 33 |
+use OCP\AppFramework\Controller; |
|
| 34 |
+use OCP\Files\IAppData; |
|
| 35 |
+use OCP\AppFramework\App; |
|
| 36 |
+use OCP\Files\NotPermittedException; |
|
| 37 |
+use OCP\Files\Folder; |
|
| 38 |
+use OC\Files\Filesystem; |
|
| 39 |
+use \ReflectionClass; |
|
| 40 |
+ |
|
| 41 |
+use Phaxio; |
|
| 42 |
+use Phaxio\OperationResult; |
|
| 43 |
+use Phaxio\Error\AuthenticationException; |
|
| 44 |
+use Phaxio\Error\NotFoundException; |
|
| 45 |
+use Phaxio\Error\InvalidRequestException; |
|
| 46 |
+use Phaxio\Error\RateLimitException; |
|
| 47 |
+use Phaxio\Error\APIConnectionException; |
|
| 48 |
+use Phaxio\Error\GeneralException; |
|
| 49 |
+ |
|
| 50 |
+ |
|
| 51 |
+class PaxfaxService {
|
|
| 52 |
+ |
|
| 53 |
+ private $connection; |
|
| 54 |
+ |
|
| 55 |
+ private $crypto; |
|
| 56 |
+ |
|
| 57 |
+ public function __construct(IDBConnection $connection, ICrypto $crypto) {
|
|
| 58 |
+ |
|
| 59 |
+ $this->connection = $connection; |
|
| 60 |
+ |
|
| 61 |
+ $this->crypto = $crypto; |
|
| 62 |
+ } |
|
| 63 |
+ |
|
| 64 |
+ |
|
| 65 |
+ /** |
|
| 66 |
+ * @NoAdminRequired |
|
| 67 |
+ */ |
|
| 68 |
+ public function object_to_array($obj) {
|
|
| 69 |
+ if(is_object($obj)) $obj = (array)$this->dismount($obj); |
|
| 70 |
+ if(is_array($obj)) {
|
|
| 71 |
+ $new = array(); |
|
| 72 |
+ foreach($obj as $key => $val) {
|
|
| 73 |
+ $new[$key] = $this->object_to_array($val); |
|
| 74 |
+ } |
|
| 75 |
+ } |
|
| 76 |
+ else $new = $obj; |
|
| 77 |
+ return $new; |
|
| 78 |
+ } |
|
| 79 |
+ |
|
| 80 |
+ |
|
| 81 |
+ /** |
|
| 82 |
+ * @NoAdminRequired |
|
| 83 |
+ */ |
|
| 84 |
+ public function dismount($object) {
|
|
| 85 |
+ $reflectionClass = new ReflectionClass(get_class($object)); |
|
| 86 |
+ $array = array(); |
|
| 87 |
+ foreach ($reflectionClass->getProperties() as $property) {
|
|
| 88 |
+ $property->setAccessible(true); |
|
| 89 |
+ $array[$property->getName()] = $property->getValue($object); |
|
| 90 |
+ $property->setAccessible(false); |
|
| 91 |
+ } |
|
| 92 |
+ return $array; |
|
| 93 |
+ } |
|
| 94 |
+ |
|
| 95 |
+ |
|
| 96 |
+ /** |
|
| 97 |
+ * @NoAdminRequired |
|
| 98 |
+ * |
|
| 99 |
+ */ |
|
| 100 |
+ public function getsettings($userId) {
|
|
| 101 |
+ |
|
| 102 |
+ $sql = $this->connection->prepare('
|
|
| 103 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 104 |
+ FROM `*PREFIX*pax_fax` |
|
| 105 |
+ WHERE `user_id` = ?'); |
|
| 106 |
+ $result = $sql->execute([$userId]); |
|
| 107 |
+ $settingsfromdb = $result->fetch(); |
|
| 108 |
+ $result->closeCursor(); |
|
| 109 |
+ |
|
| 110 |
+ if ($settingsfromdb) {
|
|
| 111 |
+ |
|
| 112 |
+ if ($settingsfromdb['api_key'] != '') {
|
|
| 113 |
+ |
|
| 114 |
+ // Send a placeholder to the browser, instead of the real data |
|
| 115 |
+ $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 116 |
+ } |
|
| 117 |
+ if ($settingsfromdb['api_secret'] != '') {
|
|
| 118 |
+ $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 119 |
+ } |
|
| 120 |
+ if ($settingsfromdb['webhook_token'] != '') {
|
|
| 121 |
+ $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 122 |
+ } |
|
| 123 |
+ if ($settingsfromdb['receive_url'] != '') {
|
|
| 124 |
+ $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 125 |
+ } |
|
| 126 |
+ |
|
| 127 |
+ return $settingsfromdb; |
|
| 128 |
+ } |
|
| 129 |
+ } |
|
| 130 |
+ |
|
| 131 |
+ |
|
| 132 |
+ /** |
|
| 133 |
+ * @NoAdminRequired |
|
| 134 |
+ * |
|
| 135 |
+ */ |
|
| 136 |
+ public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
|
|
| 137 |
+ |
|
| 138 |
+ $sqlsel = $this->connection->prepare('
|
|
| 139 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 140 |
+ FROM `*PREFIX*pax_fax` |
|
| 141 |
+ WHERE `user_id` = ?'); |
|
| 142 |
+ $resultsel = $sqlsel->execute([$userId]); |
|
| 143 |
+ $row = $resultsel->fetch(); |
|
| 144 |
+ $resultsel->closeCursor(); |
|
| 145 |
+ |
|
| 146 |
+ if ($resultsel && !$row) {
|
|
| 147 |
+ |
|
| 148 |
+ if ($apiKey != '') {
|
|
| 149 |
+ $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 150 |
+ } else { $apikeystrenc = ''; }
|
|
| 151 |
+ |
|
| 152 |
+ if ($apiSecret != '') {
|
|
| 153 |
+ $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 154 |
+ } else { $apisecretstrenc = ''; }
|
|
| 155 |
+ |
|
| 156 |
+ if ($webhookToken != '') {
|
|
| 157 |
+ $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 158 |
+ } else { $webhookTokenenc = ''; }
|
|
| 159 |
+ |
|
| 160 |
+ if ($receiveUrl != '') {
|
|
| 161 |
+ $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 162 |
+ } else { $receiveUrlenc = ''; }
|
|
| 163 |
+ |
|
| 164 |
+ $sqlns = $this->connection->prepare('
|
|
| 165 |
+ INSERT INTO `*PREFIX*pax_fax` |
|
| 166 |
+ (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`) |
|
| 167 |
+ VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
| 168 |
+ $sqlns->execute([$userId, $apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail]); |
|
| 169 |
+ |
|
| 170 |
+ } elseif ($resultsel && $row) {
|
|
| 171 |
+ |
|
| 172 |
+ if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 173 |
+ $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 174 |
+ } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 175 |
+ $apikeystrenc = $row['api_key']; |
|
| 176 |
+ } elseif ($apiKey == '') {
|
|
| 177 |
+ $apikeystrenc = ''; |
|
| 178 |
+ } |
|
| 179 |
+ |
|
| 180 |
+ if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 181 |
+ $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 182 |
+ } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 183 |
+ $apisecretstrenc = $row['api_secret']; |
|
| 184 |
+ } elseif ($apiSecret == '') {
|
|
| 185 |
+ $apisecretstrenc = ''; |
|
| 186 |
+ } |
|
| 187 |
+ |
|
| 188 |
+ if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 189 |
+ $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 190 |
+ } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 191 |
+ $webhookTokenenc = $row['webhook_token']; |
|
| 192 |
+ } elseif ($webhookToken == '') {
|
|
| 193 |
+ $webhookTokenenc = ''; |
|
| 194 |
+ } |
|
| 195 |
+ |
|
| 196 |
+ if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 197 |
+ $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 198 |
+ } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 199 |
+ $receiveUrlenc = $row['receive_url']; |
|
| 200 |
+ } elseif ($receiveUrl == '') {
|
|
| 201 |
+ $receiveUrlenc = ''; |
|
| 202 |
+ } |
|
| 203 |
+ |
|
| 204 |
+ $sqlup = $this->connection->prepare('
|
|
| 205 |
+ UPDATE `*PREFIX*pax_fax` |
|
| 206 |
+ SET `api_key` = ?, `api_secret` = ?, `webhook_token` = ?, `receive_url` = ?, `get_notification` = ?, `notification_email` = ? |
|
| 207 |
+ WHERE `user_id` = ?'); |
|
| 208 |
+ $updateRes = $sqlup->execute([$apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail, $userId]); |
|
| 209 |
+ $updateRes->closeCursor(); |
|
| 210 |
+ } |
|
| 211 |
+ } |
|
| 212 |
+ |
|
| 213 |
+ /** |
|
| 214 |
+ * @NoAdminRequired |
|
| 215 |
+ */ |
|
| 216 |
+ public function getapicredentials($userId) {
|
|
| 217 |
+ |
|
| 218 |
+ $sqlselcr = $this->connection->prepare('
|
|
| 219 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 220 |
+ FROM `*PREFIX*pax_fax` |
|
| 221 |
+ WHERE `user_id` = ?'); |
|
| 222 |
+ $resultselcr = $sqlselcr->execute([$userId]); |
|
| 223 |
+ $settingsfrdb = $resultselcr->fetch(); |
|
| 224 |
+ $resultselcr->closeCursor(); |
|
| 225 |
+ |
|
| 226 |
+ if (($settingsfrdb['api_key'] != '') && ($settingsfrdb['api_key'] != 'undefined') && ($settingsfrdb['api_key'] != null)) {
|
|
| 227 |
+ $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key']); |
|
| 228 |
+ } else { $apikeystr = ''; }
|
|
| 229 |
+ |
|
| 230 |
+ if (($settingsfrdb['api_secret'] != '') && ($settingsfrdb['api_secret'] != 'undefined') && ($settingsfrdb['api_secret'] != null)) {
|
|
| 231 |
+ $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret']); |
|
| 232 |
+ } else { $apisecretstr = ''; }
|
|
| 233 |
+ |
|
| 234 |
+ if (($settingsfrdb['webhook_token'] != '') && ($settingsfrdb['webhook_token'] != 'undefined') && ($settingsfrdb['webhook_token'] != null)) {
|
|
| 235 |
+ $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token']); |
|
| 236 |
+ } else { $webhookToken = ''; }
|
|
| 237 |
+ |
|
| 238 |
+ if (($settingsfrdb['receive_url'] != '') && ($settingsfrdb['receive_url'] != 'undefined') && ($settingsfrdb['receive_url'] != null)) {
|
|
| 239 |
+ $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url']); |
|
| 240 |
+ } else { $receiveUrl = ''; }
|
|
| 241 |
+ |
|
| 242 |
+ $getnotification = $settingsfrdb['get_notification']; |
|
| 243 |
+ $notifyemail = $settingsfrdb['notification_email']; |
|
| 244 |
+ |
|
| 245 |
+ return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail]; |
|
| 246 |
+ } |
|
| 247 |
+ |
|
| 248 |
+} |
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,245 +0,0 @@ |
| 1 |
-<?php |
|
| 2 |
-/** |
|
| 3 |
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
| 4 |
- * |
|
| 5 |
- * @author Double Bastion LLC |
|
| 6 |
- * |
|
| 7 |
- * @license GNU AGPL version 3 or any later version |
|
| 8 |
- * |
|
| 9 |
- * This program is free software; you can redistribute it and/or |
|
| 10 |
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
| 11 |
- * License as published by the Free Software Foundation; either |
|
| 12 |
- * version 3 of the License, or any later version. |
|
| 13 |
- * |
|
| 14 |
- * This program is distributed in the hope that it will be useful, |
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 |
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
| 18 |
- * |
|
| 19 |
- * You should have received a copy of the GNU Affero General Public |
|
| 20 |
- * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 |
- * |
|
| 22 |
- */ |
|
| 23 |
- |
|
| 24 |
-declare(strict_types=1); |
|
| 25 |
- |
|
| 26 |
-namespace OCA\PaxFax\Service; |
|
| 27 |
- |
|
| 28 |
-use OCP\DB\QueryBuilder\IQueryBuilder; |
|
| 29 |
-use OCP\IDBConnection; |
|
| 30 |
-use OCP\Security\ICrypto; |
|
| 31 |
-use OCP\AppFramework\ApiController; |
|
| 32 |
-use OCP\IRequest; |
|
| 33 |
-use OCP\AppFramework\Controller; |
|
| 34 |
-use OCP\Files\IAppData; |
|
| 35 |
-use OCP\AppFramework\App; |
|
| 36 |
-use OCP\Files\NotPermittedException; |
|
| 37 |
-use OCP\Files\Folder; |
|
| 38 |
-use OC\Files\Filesystem; |
|
| 39 |
-use \ReflectionClass; |
|
| 40 |
- |
|
| 41 |
-use Phaxio; |
|
| 42 |
-use Phaxio\OperationResult; |
|
| 43 |
-use Phaxio\Error\AuthenticationException; |
|
| 44 |
-use Phaxio\Error\NotFoundException; |
|
| 45 |
-use Phaxio\Error\InvalidRequestException; |
|
| 46 |
-use Phaxio\Error\RateLimitException; |
|
| 47 |
-use Phaxio\Error\APIConnectionException; |
|
| 48 |
-use Phaxio\Error\GeneralException; |
|
| 49 |
- |
|
| 50 |
- |
|
| 51 |
-class PaxfaxService {
|
|
| 52 |
- |
|
| 53 |
- private $connection; |
|
| 54 |
- |
|
| 55 |
- private $crypto; |
|
| 56 |
- |
|
| 57 |
- public function __construct(IDBConnection $connection, ICrypto $crypto) {
|
|
| 58 |
- |
|
| 59 |
- $this->connection = $connection; |
|
| 60 |
- |
|
| 61 |
- $this->crypto = $crypto; |
|
| 62 |
- } |
|
| 63 |
- |
|
| 64 |
- |
|
| 65 |
- /** |
|
| 66 |
- * @NoAdminRequired |
|
| 67 |
- */ |
|
| 68 |
- public function object_to_array($obj) {
|
|
| 69 |
- if(is_object($obj)) $obj = (array)$this->dismount($obj); |
|
| 70 |
- if(is_array($obj)) {
|
|
| 71 |
- $new = array(); |
|
| 72 |
- foreach($obj as $key => $val) {
|
|
| 73 |
- $new[$key] = $this->object_to_array($val); |
|
| 74 |
- } |
|
| 75 |
- } |
|
| 76 |
- else $new = $obj; |
|
| 77 |
- return $new; |
|
| 78 |
- } |
|
| 79 |
- |
|
| 80 |
- |
|
| 81 |
- /** |
|
| 82 |
- * @NoAdminRequired |
|
| 83 |
- */ |
|
| 84 |
- public function dismount($object) {
|
|
| 85 |
- $reflectionClass = new ReflectionClass(get_class($object)); |
|
| 86 |
- $array = array(); |
|
| 87 |
- foreach ($reflectionClass->getProperties() as $property) {
|
|
| 88 |
- $property->setAccessible(true); |
|
| 89 |
- $array[$property->getName()] = $property->getValue($object); |
|
| 90 |
- $property->setAccessible(false); |
|
| 91 |
- } |
|
| 92 |
- return $array; |
|
| 93 |
- } |
|
| 94 |
- |
|
| 95 |
- |
|
| 96 |
- /** |
|
| 97 |
- * @NoAdminRequired |
|
| 98 |
- * |
|
| 99 |
- */ |
|
| 100 |
- public function getsettings($userId) {
|
|
| 101 |
- |
|
| 102 |
- $sql = $this->connection->prepare('
|
|
| 103 |
- SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 104 |
- FROM `*PREFIX*pax_fax` |
|
| 105 |
- WHERE `user_id` = ?'); |
|
| 106 |
- $result = $sql->execute([$userId]); |
|
| 107 |
- $settingsfromdb = $result->fetch(); |
|
| 108 |
- $result->closeCursor(); |
|
| 109 |
- |
|
| 110 |
- if ($settingsfromdb['api_key'] != '') {
|
|
| 111 |
- |
|
| 112 |
- // Send a placeholder to the browser, instead of the real data |
|
| 113 |
- $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 114 |
- } |
|
| 115 |
- if ($settingsfromdb['api_secret'] != '') {
|
|
| 116 |
- $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 117 |
- } |
|
| 118 |
- if ($settingsfromdb['webhook_token'] != '') {
|
|
| 119 |
- $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 120 |
- } |
|
| 121 |
- if ($settingsfromdb['receive_url'] != '') {
|
|
| 122 |
- $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 123 |
- } |
|
| 124 |
- |
|
| 125 |
- return $settingsfromdb; |
|
| 126 |
- } |
|
| 127 |
- |
|
| 128 |
- |
|
| 129 |
- /** |
|
| 130 |
- * @NoAdminRequired |
|
| 131 |
- * |
|
| 132 |
- */ |
|
| 133 |
- public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
|
|
| 134 |
- |
|
| 135 |
- $sqlsel = $this->connection->prepare('
|
|
| 136 |
- SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 137 |
- FROM `*PREFIX*pax_fax` |
|
| 138 |
- WHERE `user_id` = ?'); |
|
| 139 |
- $resultsel = $sqlsel->execute([$userId]); |
|
| 140 |
- $row = $resultsel->fetch(); |
|
| 141 |
- $resultsel->closeCursor(); |
|
| 142 |
- |
|
| 143 |
- if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) {
|
|
| 144 |
- |
|
| 145 |
- if ($apiKey != '') {
|
|
| 146 |
- $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 147 |
- } else { $apikeystrenc = ''; }
|
|
| 148 |
- |
|
| 149 |
- if ($apiSecret != '') {
|
|
| 150 |
- $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 151 |
- } else { $apisecretstrenc = ''; }
|
|
| 152 |
- |
|
| 153 |
- if ($webhookToken != '') {
|
|
| 154 |
- $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 155 |
- } else { $webhookTokenenc = ''; }
|
|
| 156 |
- |
|
| 157 |
- if ($receiveUrl != '') {
|
|
| 158 |
- $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 159 |
- } else { $receiveUrlenc = ''; }
|
|
| 160 |
- |
|
| 161 |
- $sqlns = $this->connection->prepare('
|
|
| 162 |
- INSERT INTO `*PREFIX*pax_fax` |
|
| 163 |
- (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`) |
|
| 164 |
- VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
| 165 |
- $sqlns->execute([$userId, $apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail]); |
|
| 166 |
- |
|
| 167 |
- } else {
|
|
| 168 |
- |
|
| 169 |
- if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 170 |
- $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 171 |
- } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 172 |
- $apikeystrenc = $row['api_key']; |
|
| 173 |
- } elseif ($apiKey == '') {
|
|
| 174 |
- $apikeystrenc = ''; |
|
| 175 |
- } |
|
| 176 |
- |
|
| 177 |
- if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 178 |
- $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 179 |
- } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 180 |
- $apisecretstrenc = $row['api_secret']; |
|
| 181 |
- } elseif ($apiSecret == '') {
|
|
| 182 |
- $apisecretstrenc = ''; |
|
| 183 |
- } |
|
| 184 |
- |
|
| 185 |
- if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 186 |
- $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 187 |
- } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 188 |
- $webhookTokenenc = $row['webhook_token']; |
|
| 189 |
- } elseif ($webhookToken == '') {
|
|
| 190 |
- $webhookTokenenc = ''; |
|
| 191 |
- } |
|
| 192 |
- |
|
| 193 |
- if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 194 |
- $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 195 |
- } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 196 |
- $receiveUrlenc = $row['receive_url']; |
|
| 197 |
- } elseif ($receiveUrl == '') {
|
|
| 198 |
- $receiveUrlenc = ''; |
|
| 199 |
- } |
|
| 200 |
- |
|
| 201 |
- $sqlup = $this->connection->prepare('
|
|
| 202 |
- UPDATE `*PREFIX*pax_fax` |
|
| 203 |
- SET `api_key` = ?, `api_secret` = ?, `webhook_token` = ?, `receive_url` = ?, `get_notification` = ?, `notification_email` = ? |
|
| 204 |
- WHERE `user_id` = ?'); |
|
| 205 |
- $updateRes = $sqlup->execute([$apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail, $userId]); |
|
| 206 |
- $updateRes->closeCursor(); |
|
| 207 |
- } |
|
| 208 |
- } |
|
| 209 |
- |
|
| 210 |
- /** |
|
| 211 |
- * @NoAdminRequired |
|
| 212 |
- */ |
|
| 213 |
- public function getapicredentials($userId) {
|
|
| 214 |
- |
|
| 215 |
- $sqlselcr = $this->connection->prepare('
|
|
| 216 |
- SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 217 |
- FROM `*PREFIX*pax_fax` |
|
| 218 |
- WHERE `user_id` = ?'); |
|
| 219 |
- $resultselcr = $sqlselcr->execute([$userId]); |
|
| 220 |
- $settingsfrdb = $resultselcr->fetch(); |
|
| 221 |
- $resultselcr->closeCursor(); |
|
| 222 |
- |
|
| 223 |
- if (($settingsfrdb['api_key'] != '') && ($settingsfrdb['api_key'] != 'undefined') && ($settingsfrdb['api_key'] != null)) {
|
|
| 224 |
- $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key']); |
|
| 225 |
- } else { $apikeystr = ''; }
|
|
| 226 |
- |
|
| 227 |
- if (($settingsfrdb['api_secret'] != '') && ($settingsfrdb['api_secret'] != 'undefined') && ($settingsfrdb['api_secret'] != null)) {
|
|
| 228 |
- $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret']); |
|
| 229 |
- } else { $apisecretstr = ''; }
|
|
| 230 |
- |
|
| 231 |
- if (($settingsfrdb['webhook_token'] != '') && ($settingsfrdb['webhook_token'] != 'undefined') && ($settingsfrdb['webhook_token'] != null)) {
|
|
| 232 |
- $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token']); |
|
| 233 |
- } else { $webhookToken = ''; }
|
|
| 234 |
- |
|
| 235 |
- if (($settingsfrdb['receive_url'] != '') && ($settingsfrdb['receive_url'] != 'undefined') && ($settingsfrdb['receive_url'] != null)) {
|
|
| 236 |
- $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url']); |
|
| 237 |
- } else { $receiveUrl = ''; }
|
|
| 238 |
- |
|
| 239 |
- $getnotification = $settingsfrdb['get_notification']; |
|
| 240 |
- $notifyemail = $settingsfrdb['notification_email']; |
|
| 241 |
- |
|
| 242 |
- return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail]; |
|
| 243 |
- } |
|
| 244 |
- |
|
| 245 |
-} |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,245 @@ |
| 1 |
+<?php |
|
| 2 |
+/** |
|
| 3 |
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
| 4 |
+ * |
|
| 5 |
+ * @author Double Bastion LLC |
|
| 6 |
+ * |
|
| 7 |
+ * @license GNU AGPL version 3 or any later version |
|
| 8 |
+ * |
|
| 9 |
+ * This program is free software; you can redistribute it and/or |
|
| 10 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
| 11 |
+ * License as published by the Free Software Foundation; either |
|
| 12 |
+ * version 3 of the License, or any later version. |
|
| 13 |
+ * |
|
| 14 |
+ * This program is distributed in the hope that it will be useful, |
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
| 18 |
+ * |
|
| 19 |
+ * You should have received a copy of the GNU Affero General Public |
|
| 20 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 |
+ * |
|
| 22 |
+ */ |
|
| 23 |
+ |
|
| 24 |
+declare(strict_types=1); |
|
| 25 |
+ |
|
| 26 |
+namespace OCA\PaxFax\Service; |
|
| 27 |
+ |
|
| 28 |
+use OCP\DB\QueryBuilder\IQueryBuilder; |
|
| 29 |
+use OCP\IDBConnection; |
|
| 30 |
+use OCP\Security\ICrypto; |
|
| 31 |
+use OCP\AppFramework\ApiController; |
|
| 32 |
+use OCP\IRequest; |
|
| 33 |
+use OCP\AppFramework\Controller; |
|
| 34 |
+use OCP\Files\IAppData; |
|
| 35 |
+use OCP\AppFramework\App; |
|
| 36 |
+use OCP\Files\NotPermittedException; |
|
| 37 |
+use OCP\Files\Folder; |
|
| 38 |
+use OC\Files\Filesystem; |
|
| 39 |
+use \ReflectionClass; |
|
| 40 |
+ |
|
| 41 |
+use Phaxio; |
|
| 42 |
+use Phaxio\OperationResult; |
|
| 43 |
+use Phaxio\Error\AuthenticationException; |
|
| 44 |
+use Phaxio\Error\NotFoundException; |
|
| 45 |
+use Phaxio\Error\InvalidRequestException; |
|
| 46 |
+use Phaxio\Error\RateLimitException; |
|
| 47 |
+use Phaxio\Error\APIConnectionException; |
|
| 48 |
+use Phaxio\Error\GeneralException; |
|
| 49 |
+ |
|
| 50 |
+ |
|
| 51 |
+class PaxfaxService {
|
|
| 52 |
+ |
|
| 53 |
+ private $connection; |
|
| 54 |
+ |
|
| 55 |
+ private $crypto; |
|
| 56 |
+ |
|
| 57 |
+ public function __construct(IDBConnection $connection, ICrypto $crypto) {
|
|
| 58 |
+ |
|
| 59 |
+ $this->connection = $connection; |
|
| 60 |
+ |
|
| 61 |
+ $this->crypto = $crypto; |
|
| 62 |
+ } |
|
| 63 |
+ |
|
| 64 |
+ |
|
| 65 |
+ /** |
|
| 66 |
+ * @NoAdminRequired |
|
| 67 |
+ */ |
|
| 68 |
+ public function object_to_array($obj) {
|
|
| 69 |
+ if(is_object($obj)) $obj = (array)$this->dismount($obj); |
|
| 70 |
+ if(is_array($obj)) {
|
|
| 71 |
+ $new = array(); |
|
| 72 |
+ foreach($obj as $key => $val) {
|
|
| 73 |
+ $new[$key] = $this->object_to_array($val); |
|
| 74 |
+ } |
|
| 75 |
+ } |
|
| 76 |
+ else $new = $obj; |
|
| 77 |
+ return $new; |
|
| 78 |
+ } |
|
| 79 |
+ |
|
| 80 |
+ |
|
| 81 |
+ /** |
|
| 82 |
+ * @NoAdminRequired |
|
| 83 |
+ */ |
|
| 84 |
+ public function dismount($object) {
|
|
| 85 |
+ $reflectionClass = new ReflectionClass(get_class($object)); |
|
| 86 |
+ $array = array(); |
|
| 87 |
+ foreach ($reflectionClass->getProperties() as $property) {
|
|
| 88 |
+ $property->setAccessible(true); |
|
| 89 |
+ $array[$property->getName()] = $property->getValue($object); |
|
| 90 |
+ $property->setAccessible(false); |
|
| 91 |
+ } |
|
| 92 |
+ return $array; |
|
| 93 |
+ } |
|
| 94 |
+ |
|
| 95 |
+ |
|
| 96 |
+ /** |
|
| 97 |
+ * @NoAdminRequired |
|
| 98 |
+ * |
|
| 99 |
+ */ |
|
| 100 |
+ public function getsettings($userId) {
|
|
| 101 |
+ |
|
| 102 |
+ $sql = $this->connection->prepare('
|
|
| 103 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 104 |
+ FROM `*PREFIX*pax_fax` |
|
| 105 |
+ WHERE `user_id` = ?'); |
|
| 106 |
+ $result = $sql->execute([$userId]); |
|
| 107 |
+ $settingsfromdb = $result->fetch(); |
|
| 108 |
+ $result->closeCursor(); |
|
| 109 |
+ |
|
| 110 |
+ if ($settingsfromdb['api_key'] != '') {
|
|
| 111 |
+ |
|
| 112 |
+ // Send a placeholder to the browser, instead of the real data |
|
| 113 |
+ $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 114 |
+ } |
|
| 115 |
+ if ($settingsfromdb['api_secret'] != '') {
|
|
| 116 |
+ $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 117 |
+ } |
|
| 118 |
+ if ($settingsfromdb['webhook_token'] != '') {
|
|
| 119 |
+ $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 120 |
+ } |
|
| 121 |
+ if ($settingsfromdb['receive_url'] != '') {
|
|
| 122 |
+ $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 123 |
+ } |
|
| 124 |
+ |
|
| 125 |
+ return $settingsfromdb; |
|
| 126 |
+ } |
|
| 127 |
+ |
|
| 128 |
+ |
|
| 129 |
+ /** |
|
| 130 |
+ * @NoAdminRequired |
|
| 131 |
+ * |
|
| 132 |
+ */ |
|
| 133 |
+ public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
|
|
| 134 |
+ |
|
| 135 |
+ $sqlsel = $this->connection->prepare('
|
|
| 136 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 137 |
+ FROM `*PREFIX*pax_fax` |
|
| 138 |
+ WHERE `user_id` = ?'); |
|
| 139 |
+ $resultsel = $sqlsel->execute([$userId]); |
|
| 140 |
+ $row = $resultsel->fetch(); |
|
| 141 |
+ $resultsel->closeCursor(); |
|
| 142 |
+ |
|
| 143 |
+ if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) {
|
|
| 144 |
+ |
|
| 145 |
+ if ($apiKey != '') {
|
|
| 146 |
+ $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 147 |
+ } else { $apikeystrenc = ''; }
|
|
| 148 |
+ |
|
| 149 |
+ if ($apiSecret != '') {
|
|
| 150 |
+ $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 151 |
+ } else { $apisecretstrenc = ''; }
|
|
| 152 |
+ |
|
| 153 |
+ if ($webhookToken != '') {
|
|
| 154 |
+ $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 155 |
+ } else { $webhookTokenenc = ''; }
|
|
| 156 |
+ |
|
| 157 |
+ if ($receiveUrl != '') {
|
|
| 158 |
+ $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 159 |
+ } else { $receiveUrlenc = ''; }
|
|
| 160 |
+ |
|
| 161 |
+ $sqlns = $this->connection->prepare('
|
|
| 162 |
+ INSERT INTO `*PREFIX*pax_fax` |
|
| 163 |
+ (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`) |
|
| 164 |
+ VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
| 165 |
+ $sqlns->execute([$userId, $apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail]); |
|
| 166 |
+ |
|
| 167 |
+ } else {
|
|
| 168 |
+ |
|
| 169 |
+ if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 170 |
+ $apikeystrenc = $this->crypto->encrypt($apiKey); |
|
| 171 |
+ } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 172 |
+ $apikeystrenc = $row['api_key']; |
|
| 173 |
+ } elseif ($apiKey == '') {
|
|
| 174 |
+ $apikeystrenc = ''; |
|
| 175 |
+ } |
|
| 176 |
+ |
|
| 177 |
+ if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 178 |
+ $apisecretstrenc = $this->crypto->encrypt($apiSecret); |
|
| 179 |
+ } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 180 |
+ $apisecretstrenc = $row['api_secret']; |
|
| 181 |
+ } elseif ($apiSecret == '') {
|
|
| 182 |
+ $apisecretstrenc = ''; |
|
| 183 |
+ } |
|
| 184 |
+ |
|
| 185 |
+ if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 186 |
+ $webhookTokenenc = $this->crypto->encrypt($webhookToken); |
|
| 187 |
+ } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 188 |
+ $webhookTokenenc = $row['webhook_token']; |
|
| 189 |
+ } elseif ($webhookToken == '') {
|
|
| 190 |
+ $webhookTokenenc = ''; |
|
| 191 |
+ } |
|
| 192 |
+ |
|
| 193 |
+ if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 194 |
+ $receiveUrlenc = $this->crypto->encrypt($receiveUrl); |
|
| 195 |
+ } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 196 |
+ $receiveUrlenc = $row['receive_url']; |
|
| 197 |
+ } elseif ($receiveUrl == '') {
|
|
| 198 |
+ $receiveUrlenc = ''; |
|
| 199 |
+ } |
|
| 200 |
+ |
|
| 201 |
+ $sqlup = $this->connection->prepare('
|
|
| 202 |
+ UPDATE `*PREFIX*pax_fax` |
|
| 203 |
+ SET `api_key` = ?, `api_secret` = ?, `webhook_token` = ?, `receive_url` = ?, `get_notification` = ?, `notification_email` = ? |
|
| 204 |
+ WHERE `user_id` = ?'); |
|
| 205 |
+ $updateRes = $sqlup->execute([$apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail, $userId]); |
|
| 206 |
+ $updateRes->closeCursor(); |
|
| 207 |
+ } |
|
| 208 |
+ } |
|
| 209 |
+ |
|
| 210 |
+ /** |
|
| 211 |
+ * @NoAdminRequired |
|
| 212 |
+ */ |
|
| 213 |
+ public function getapicredentials($userId) {
|
|
| 214 |
+ |
|
| 215 |
+ $sqlselcr = $this->connection->prepare('
|
|
| 216 |
+ SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` |
|
| 217 |
+ FROM `*PREFIX*pax_fax` |
|
| 218 |
+ WHERE `user_id` = ?'); |
|
| 219 |
+ $resultselcr = $sqlselcr->execute([$userId]); |
|
| 220 |
+ $settingsfrdb = $resultselcr->fetch(); |
|
| 221 |
+ $resultselcr->closeCursor(); |
|
| 222 |
+ |
|
| 223 |
+ if (($settingsfrdb['api_key'] != '') && ($settingsfrdb['api_key'] != 'undefined') && ($settingsfrdb['api_key'] != null)) {
|
|
| 224 |
+ $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key']); |
|
| 225 |
+ } else { $apikeystr = ''; }
|
|
| 226 |
+ |
|
| 227 |
+ if (($settingsfrdb['api_secret'] != '') && ($settingsfrdb['api_secret'] != 'undefined') && ($settingsfrdb['api_secret'] != null)) {
|
|
| 228 |
+ $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret']); |
|
| 229 |
+ } else { $apisecretstr = ''; }
|
|
| 230 |
+ |
|
| 231 |
+ if (($settingsfrdb['webhook_token'] != '') && ($settingsfrdb['webhook_token'] != 'undefined') && ($settingsfrdb['webhook_token'] != null)) {
|
|
| 232 |
+ $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token']); |
|
| 233 |
+ } else { $webhookToken = ''; }
|
|
| 234 |
+ |
|
| 235 |
+ if (($settingsfrdb['receive_url'] != '') && ($settingsfrdb['receive_url'] != 'undefined') && ($settingsfrdb['receive_url'] != null)) {
|
|
| 236 |
+ $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url']); |
|
| 237 |
+ } else { $receiveUrl = ''; }
|
|
| 238 |
+ |
|
| 239 |
+ $getnotification = $settingsfrdb['get_notification']; |
|
| 240 |
+ $notifyemail = $settingsfrdb['notification_email']; |
|
| 241 |
+ |
|
| 242 |
+ return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail]; |
|
| 243 |
+ } |
|
| 244 |
+ |
|
| 245 |
+} |
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,226 +0,0 @@ |
| 1 |
-<?php |
|
| 2 |
-/** |
|
| 3 |
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
| 4 |
- * |
|
| 5 |
- * @author Double Bastion LLC |
|
| 6 |
- * |
|
| 7 |
- * @license GNU AGPL version 3 or any later version |
|
| 8 |
- * |
|
| 9 |
- * This program is free software; you can redistribute it and/or |
|
| 10 |
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
| 11 |
- * License as published by the Free Software Foundation; either |
|
| 12 |
- * version 3 of the License, or any later version. |
|
| 13 |
- * |
|
| 14 |
- * This program is distributed in the hope that it will be useful, |
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 |
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
| 18 |
- * |
|
| 19 |
- * You should have received a copy of the GNU Affero General Public |
|
| 20 |
- * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 |
- * |
|
| 22 |
- */ |
|
| 23 |
- |
|
| 24 |
-declare(strict_types=1); |
|
| 25 |
- |
|
| 26 |
-namespace OCA\PaxFax\Service; |
|
| 27 |
- |
|
| 28 |
-use OCP\DB\QueryBuilder\IQueryBuilder; |
|
| 29 |
-use OCP\IDBConnection; |
|
| 30 |
-use OCP\Security\ICrypto; |
|
| 31 |
- |
|
| 32 |
-use OCP\AppFramework\ApiController; |
|
| 33 |
-use OCP\IRequest; |
|
| 34 |
-use OCP\AppFramework\Controller; |
|
| 35 |
-use OCP\Files\IAppData; |
|
| 36 |
-use OCP\AppFramework\App; |
|
| 37 |
-use OCP\Files\NotPermittedException; |
|
| 38 |
-use OCP\Files\Folder; |
|
| 39 |
-use OC\Files\Filesystem; |
|
| 40 |
-use \ReflectionClass; |
|
| 41 |
- |
|
| 42 |
-use Phaxio; |
|
| 43 |
-use Phaxio\OperationResult; |
|
| 44 |
-use Phaxio\Error\AuthenticationException; |
|
| 45 |
-use Phaxio\Error\NotFoundException; |
|
| 46 |
-use Phaxio\Error\InvalidRequestException; |
|
| 47 |
-use Phaxio\Error\RateLimitException; |
|
| 48 |
-use Phaxio\Error\APIConnectionException; |
|
| 49 |
-use Phaxio\Error\GeneralException; |
|
| 50 |
- |
|
| 51 |
- |
|
| 52 |
-class PaxfaxService {
|
|
| 53 |
- |
|
| 54 |
- private $connection; |
|
| 55 |
- |
|
| 56 |
- private $crypto; |
|
| 57 |
- |
|
| 58 |
- public function __construct(IDBConnection $connection, ICrypto $crypto) {
|
|
| 59 |
- |
|
| 60 |
- $this->connection = $connection; |
|
| 61 |
- |
|
| 62 |
- $this->crypto = $crypto; |
|
| 63 |
- } |
|
| 64 |
- |
|
| 65 |
- |
|
| 66 |
- /** |
|
| 67 |
- * @NoAdminRequired |
|
| 68 |
- */ |
|
| 69 |
- public function object_to_array($obj) {
|
|
| 70 |
- if(is_object($obj)) $obj = (array)$this->dismount($obj); |
|
| 71 |
- if(is_array($obj)) {
|
|
| 72 |
- $new = array(); |
|
| 73 |
- foreach($obj as $key => $val) {
|
|
| 74 |
- $new[$key] = $this->object_to_array($val); |
|
| 75 |
- } |
|
| 76 |
- } |
|
| 77 |
- else $new = $obj; |
|
| 78 |
- return $new; |
|
| 79 |
- } |
|
| 80 |
- |
|
| 81 |
- |
|
| 82 |
- /** |
|
| 83 |
- * @NoAdminRequired |
|
| 84 |
- */ |
|
| 85 |
- public function dismount($object) {
|
|
| 86 |
- $reflectionClass = new ReflectionClass(get_class($object)); |
|
| 87 |
- $array = array(); |
|
| 88 |
- foreach ($reflectionClass->getProperties() as $property) {
|
|
| 89 |
- $property->setAccessible(true); |
|
| 90 |
- $array[$property->getName()] = $property->getValue($object); |
|
| 91 |
- $property->setAccessible(false); |
|
| 92 |
- } |
|
| 93 |
- return $array; |
|
| 94 |
- } |
|
| 95 |
- |
|
| 96 |
- |
|
| 97 |
- /** |
|
| 98 |
- * @NoAdminRequired |
|
| 99 |
- * |
|
| 100 |
- */ |
|
| 101 |
- public function getsettings($userId) {
|
|
| 102 |
- |
|
| 103 |
- $sql0 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'"; |
|
| 104 |
- |
|
| 105 |
- $res0 = $this->connection->prepare($sql0); |
|
| 106 |
- $res0->execute(); |
|
| 107 |
- |
|
| 108 |
- $settingsfromdb = $res0->fetch(); |
|
| 109 |
- if ($settingsfromdb['api_key'] != '') {
|
|
| 110 |
- |
|
| 111 |
- // Send a placeholder to the browser, instead of the real API key |
|
| 112 |
- $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 113 |
- } |
|
| 114 |
- if ($settingsfromdb['api_secret'] != '') {
|
|
| 115 |
- $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 116 |
- } |
|
| 117 |
- if ($settingsfromdb['webhook_token'] != '') {
|
|
| 118 |
- $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 119 |
- } |
|
| 120 |
- if ($settingsfromdb['receive_url'] != '') {
|
|
| 121 |
- $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 122 |
- } |
|
| 123 |
- $res0->closeCursor(); |
|
| 124 |
- |
|
| 125 |
- return $settingsfromdb; |
|
| 126 |
- } |
|
| 127 |
- |
|
| 128 |
- |
|
| 129 |
- /** |
|
| 130 |
- * @NoAdminRequired |
|
| 131 |
- * |
|
| 132 |
- */ |
|
| 133 |
- public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
|
|
| 134 |
- |
|
| 135 |
- $sql1 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'"; |
|
| 136 |
- $res1 = $this->connection->prepare($sql1); |
|
| 137 |
- $res1->execute(); |
|
| 138 |
- |
|
| 139 |
- $row = $res1->fetch(); |
|
| 140 |
- $res1->closeCursor(); |
|
| 141 |
- |
|
| 142 |
- if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) {
|
|
| 143 |
- |
|
| 144 |
- if ($apiKey != '') {
|
|
| 145 |
- $apikeystrenc = $this->crypto->encrypt($apiKey, $password = ''); |
|
| 146 |
- } else { $apikeystrenc = ''; }
|
|
| 147 |
- |
|
| 148 |
- if ($apiSecret != '') {
|
|
| 149 |
- $apisecretstrenc = $this->crypto->encrypt($apiSecret, $password = ''); |
|
| 150 |
- } else { $apisecretstrenc = ''; }
|
|
| 151 |
- |
|
| 152 |
- if ($webhookToken != '') {
|
|
| 153 |
- $webhookTokenenc = $this->crypto->encrypt($webhookToken, $password = ''); |
|
| 154 |
- } else { $webhookTokenenc = ''; }
|
|
| 155 |
- |
|
| 156 |
- if ($receiveUrl != '') {
|
|
| 157 |
- $receiveUrlenc = $this->crypto->encrypt($receiveUrl, $password = ''); |
|
| 158 |
- } else { $receiveUrlenc = ''; }
|
|
| 159 |
- |
|
| 160 |
- $sql2 = "INSERT INTO `*PREFIX*pax_fax` (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`) VALUES ('$userId', '$apikeystrenc', '$apisecretstrenc', '$webhookTokenenc', '$receiveUrlenc', '$getNotification', '$notificationEmail')";
|
|
| 161 |
- $res2 = $this->connection->prepare($sql2); |
|
| 162 |
- $res2->execute(); |
|
| 163 |
- |
|
| 164 |
- } else {
|
|
| 165 |
- |
|
| 166 |
- if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 167 |
- $apikeystrenc = $this->crypto->encrypt($apiKey, $password = ''); |
|
| 168 |
- } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 169 |
- $apikeystrenc = $row['api_key']; |
|
| 170 |
- } elseif ($apiKey == '') {
|
|
| 171 |
- $apikeystrenc = ''; |
|
| 172 |
- } |
|
| 173 |
- |
|
| 174 |
- if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 175 |
- $apisecretstrenc = $this->crypto->encrypt($apiSecret, $password = ''); |
|
| 176 |
- } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 177 |
- $apisecretstrenc = $row['api_secret']; |
|
| 178 |
- } elseif ($apiSecret == '') {
|
|
| 179 |
- $apisecretstrenc = ''; |
|
| 180 |
- } |
|
| 181 |
- |
|
| 182 |
- if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 183 |
- $webhookTokenenc = $this->crypto->encrypt($webhookToken, $password = ''); |
|
| 184 |
- } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 185 |
- $webhookTokenenc = $row['webhook_token']; |
|
| 186 |
- } elseif ($webhookToken == '') {
|
|
| 187 |
- $webhookTokenenc = ''; |
|
| 188 |
- } |
|
| 189 |
- |
|
| 190 |
- if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 191 |
- $receiveUrlenc = $this->crypto->encrypt($receiveUrl, $password = ''); |
|
| 192 |
- } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 193 |
- $receiveUrlenc = $row['receive_url']; |
|
| 194 |
- } elseif ($receiveUrl == '') {
|
|
| 195 |
- $receiveUrlenc = ''; |
|
| 196 |
- } |
|
| 197 |
- |
|
| 198 |
- $sql3 = "UPDATE `*PREFIX*pax_fax` SET `api_key` = '$apikeystrenc', `api_secret` = '$apisecretstrenc', `webhook_token` = '$webhookTokenenc', `receive_url` = '$receiveUrlenc', `get_notification` = '$getNotification', `notification_email` = '$notificationEmail' WHERE `user_id` = '$userId'"; |
|
| 199 |
- $res3 = $this->connection->prepare($sql3); |
|
| 200 |
- $res3->execute(); |
|
| 201 |
- } |
|
| 202 |
- } |
|
| 203 |
- |
|
| 204 |
- /** |
|
| 205 |
- * @NoAdminRequired |
|
| 206 |
- */ |
|
| 207 |
- public function getapicredentials($userId) {
|
|
| 208 |
- |
|
| 209 |
- $sql7 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'"; |
|
| 210 |
- $res7 = $this->connection->prepare($sql7); |
|
| 211 |
- $res7->execute(); |
|
| 212 |
- $settingsfrdb = $res7->fetch(); |
|
| 213 |
- $res7->closeCursor(); |
|
| 214 |
- |
|
| 215 |
- $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key'], $password = ''); |
|
| 216 |
- $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret'], $password = ''); |
|
| 217 |
- $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token'], $password = ''); |
|
| 218 |
- $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url'], $password = ''); |
|
| 219 |
- $getnotification = $settingsfrdb['get_notification']; |
|
| 220 |
- $notifyemail = $settingsfrdb['notification_email']; |
|
| 221 |
- |
|
| 222 |
- return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail]; |
|
| 223 |
- |
|
| 224 |
- } |
|
| 225 |
- |
|
| 226 |
-} |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,226 @@ |
| 1 |
+<?php |
|
| 2 |
+/** |
|
| 3 |
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
| 4 |
+ * |
|
| 5 |
+ * @author Double Bastion LLC |
|
| 6 |
+ * |
|
| 7 |
+ * @license GNU AGPL version 3 or any later version |
|
| 8 |
+ * |
|
| 9 |
+ * This program is free software; you can redistribute it and/or |
|
| 10 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
| 11 |
+ * License as published by the Free Software Foundation; either |
|
| 12 |
+ * version 3 of the License, or any later version. |
|
| 13 |
+ * |
|
| 14 |
+ * This program is distributed in the hope that it will be useful, |
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
| 18 |
+ * |
|
| 19 |
+ * You should have received a copy of the GNU Affero General Public |
|
| 20 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 |
+ * |
|
| 22 |
+ */ |
|
| 23 |
+ |
|
| 24 |
+declare(strict_types=1); |
|
| 25 |
+ |
|
| 26 |
+namespace OCA\PaxFax\Service; |
|
| 27 |
+ |
|
| 28 |
+use OCP\DB\QueryBuilder\IQueryBuilder; |
|
| 29 |
+use OCP\IDBConnection; |
|
| 30 |
+use OCP\Security\ICrypto; |
|
| 31 |
+ |
|
| 32 |
+use OCP\AppFramework\ApiController; |
|
| 33 |
+use OCP\IRequest; |
|
| 34 |
+use OCP\AppFramework\Controller; |
|
| 35 |
+use OCP\Files\IAppData; |
|
| 36 |
+use OCP\AppFramework\App; |
|
| 37 |
+use OCP\Files\NotPermittedException; |
|
| 38 |
+use OCP\Files\Folder; |
|
| 39 |
+use OC\Files\Filesystem; |
|
| 40 |
+use \ReflectionClass; |
|
| 41 |
+ |
|
| 42 |
+use Phaxio; |
|
| 43 |
+use Phaxio\OperationResult; |
|
| 44 |
+use Phaxio\Error\AuthenticationException; |
|
| 45 |
+use Phaxio\Error\NotFoundException; |
|
| 46 |
+use Phaxio\Error\InvalidRequestException; |
|
| 47 |
+use Phaxio\Error\RateLimitException; |
|
| 48 |
+use Phaxio\Error\APIConnectionException; |
|
| 49 |
+use Phaxio\Error\GeneralException; |
|
| 50 |
+ |
|
| 51 |
+ |
|
| 52 |
+class PaxfaxService {
|
|
| 53 |
+ |
|
| 54 |
+ private $connection; |
|
| 55 |
+ |
|
| 56 |
+ private $crypto; |
|
| 57 |
+ |
|
| 58 |
+ public function __construct(IDBConnection $connection, ICrypto $crypto) {
|
|
| 59 |
+ |
|
| 60 |
+ $this->connection = $connection; |
|
| 61 |
+ |
|
| 62 |
+ $this->crypto = $crypto; |
|
| 63 |
+ } |
|
| 64 |
+ |
|
| 65 |
+ |
|
| 66 |
+ /** |
|
| 67 |
+ * @NoAdminRequired |
|
| 68 |
+ */ |
|
| 69 |
+ public function object_to_array($obj) {
|
|
| 70 |
+ if(is_object($obj)) $obj = (array)$this->dismount($obj); |
|
| 71 |
+ if(is_array($obj)) {
|
|
| 72 |
+ $new = array(); |
|
| 73 |
+ foreach($obj as $key => $val) {
|
|
| 74 |
+ $new[$key] = $this->object_to_array($val); |
|
| 75 |
+ } |
|
| 76 |
+ } |
|
| 77 |
+ else $new = $obj; |
|
| 78 |
+ return $new; |
|
| 79 |
+ } |
|
| 80 |
+ |
|
| 81 |
+ |
|
| 82 |
+ /** |
|
| 83 |
+ * @NoAdminRequired |
|
| 84 |
+ */ |
|
| 85 |
+ public function dismount($object) {
|
|
| 86 |
+ $reflectionClass = new ReflectionClass(get_class($object)); |
|
| 87 |
+ $array = array(); |
|
| 88 |
+ foreach ($reflectionClass->getProperties() as $property) {
|
|
| 89 |
+ $property->setAccessible(true); |
|
| 90 |
+ $array[$property->getName()] = $property->getValue($object); |
|
| 91 |
+ $property->setAccessible(false); |
|
| 92 |
+ } |
|
| 93 |
+ return $array; |
|
| 94 |
+ } |
|
| 95 |
+ |
|
| 96 |
+ |
|
| 97 |
+ /** |
|
| 98 |
+ * @NoAdminRequired |
|
| 99 |
+ * |
|
| 100 |
+ */ |
|
| 101 |
+ public function getsettings($userId) {
|
|
| 102 |
+ |
|
| 103 |
+ $sql0 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'"; |
|
| 104 |
+ |
|
| 105 |
+ $res0 = $this->connection->prepare($sql0); |
|
| 106 |
+ $res0->execute(); |
|
| 107 |
+ |
|
| 108 |
+ $settingsfromdb = $res0->fetch(); |
|
| 109 |
+ if ($settingsfromdb['api_key'] != '') {
|
|
| 110 |
+ |
|
| 111 |
+ // Send a placeholder to the browser, instead of the real API key |
|
| 112 |
+ $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 113 |
+ } |
|
| 114 |
+ if ($settingsfromdb['api_secret'] != '') {
|
|
| 115 |
+ $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 116 |
+ } |
|
| 117 |
+ if ($settingsfromdb['webhook_token'] != '') {
|
|
| 118 |
+ $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 119 |
+ } |
|
| 120 |
+ if ($settingsfromdb['receive_url'] != '') {
|
|
| 121 |
+ $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"; |
|
| 122 |
+ } |
|
| 123 |
+ $res0->closeCursor(); |
|
| 124 |
+ |
|
| 125 |
+ return $settingsfromdb; |
|
| 126 |
+ } |
|
| 127 |
+ |
|
| 128 |
+ |
|
| 129 |
+ /** |
|
| 130 |
+ * @NoAdminRequired |
|
| 131 |
+ * |
|
| 132 |
+ */ |
|
| 133 |
+ public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
|
|
| 134 |
+ |
|
| 135 |
+ $sql1 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'"; |
|
| 136 |
+ $res1 = $this->connection->prepare($sql1); |
|
| 137 |
+ $res1->execute(); |
|
| 138 |
+ |
|
| 139 |
+ $row = $res1->fetch(); |
|
| 140 |
+ $res1->closeCursor(); |
|
| 141 |
+ |
|
| 142 |
+ if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) {
|
|
| 143 |
+ |
|
| 144 |
+ if ($apiKey != '') {
|
|
| 145 |
+ $apikeystrenc = $this->crypto->encrypt($apiKey, $password = ''); |
|
| 146 |
+ } else { $apikeystrenc = ''; }
|
|
| 147 |
+ |
|
| 148 |
+ if ($apiSecret != '') {
|
|
| 149 |
+ $apisecretstrenc = $this->crypto->encrypt($apiSecret, $password = ''); |
|
| 150 |
+ } else { $apisecretstrenc = ''; }
|
|
| 151 |
+ |
|
| 152 |
+ if ($webhookToken != '') {
|
|
| 153 |
+ $webhookTokenenc = $this->crypto->encrypt($webhookToken, $password = ''); |
|
| 154 |
+ } else { $webhookTokenenc = ''; }
|
|
| 155 |
+ |
|
| 156 |
+ if ($receiveUrl != '') {
|
|
| 157 |
+ $receiveUrlenc = $this->crypto->encrypt($receiveUrl, $password = ''); |
|
| 158 |
+ } else { $receiveUrlenc = ''; }
|
|
| 159 |
+ |
|
| 160 |
+ $sql2 = "INSERT INTO `*PREFIX*pax_fax` (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`) VALUES ('$userId', '$apikeystrenc', '$apisecretstrenc', '$webhookTokenenc', '$receiveUrlenc', '$getNotification', '$notificationEmail')";
|
|
| 161 |
+ $res2 = $this->connection->prepare($sql2); |
|
| 162 |
+ $res2->execute(); |
|
| 163 |
+ |
|
| 164 |
+ } else {
|
|
| 165 |
+ |
|
| 166 |
+ if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 167 |
+ $apikeystrenc = $this->crypto->encrypt($apiKey, $password = ''); |
|
| 168 |
+ } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 169 |
+ $apikeystrenc = $row['api_key']; |
|
| 170 |
+ } elseif ($apiKey == '') {
|
|
| 171 |
+ $apikeystrenc = ''; |
|
| 172 |
+ } |
|
| 173 |
+ |
|
| 174 |
+ if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 175 |
+ $apisecretstrenc = $this->crypto->encrypt($apiSecret, $password = ''); |
|
| 176 |
+ } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 177 |
+ $apisecretstrenc = $row['api_secret']; |
|
| 178 |
+ } elseif ($apiSecret == '') {
|
|
| 179 |
+ $apisecretstrenc = ''; |
|
| 180 |
+ } |
|
| 181 |
+ |
|
| 182 |
+ if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 183 |
+ $webhookTokenenc = $this->crypto->encrypt($webhookToken, $password = ''); |
|
| 184 |
+ } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 185 |
+ $webhookTokenenc = $row['webhook_token']; |
|
| 186 |
+ } elseif ($webhookToken == '') {
|
|
| 187 |
+ $webhookTokenenc = ''; |
|
| 188 |
+ } |
|
| 189 |
+ |
|
| 190 |
+ if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 191 |
+ $receiveUrlenc = $this->crypto->encrypt($receiveUrl, $password = ''); |
|
| 192 |
+ } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
|
|
| 193 |
+ $receiveUrlenc = $row['receive_url']; |
|
| 194 |
+ } elseif ($receiveUrl == '') {
|
|
| 195 |
+ $receiveUrlenc = ''; |
|
| 196 |
+ } |
|
| 197 |
+ |
|
| 198 |
+ $sql3 = "UPDATE `*PREFIX*pax_fax` SET `api_key` = '$apikeystrenc', `api_secret` = '$apisecretstrenc', `webhook_token` = '$webhookTokenenc', `receive_url` = '$receiveUrlenc', `get_notification` = '$getNotification', `notification_email` = '$notificationEmail' WHERE `user_id` = '$userId'"; |
|
| 199 |
+ $res3 = $this->connection->prepare($sql3); |
|
| 200 |
+ $res3->execute(); |
|
| 201 |
+ } |
|
| 202 |
+ } |
|
| 203 |
+ |
|
| 204 |
+ /** |
|
| 205 |
+ * @NoAdminRequired |
|
| 206 |
+ */ |
|
| 207 |
+ public function getapicredentials($userId) {
|
|
| 208 |
+ |
|
| 209 |
+ $sql7 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'"; |
|
| 210 |
+ $res7 = $this->connection->prepare($sql7); |
|
| 211 |
+ $res7->execute(); |
|
| 212 |
+ $settingsfrdb = $res7->fetch(); |
|
| 213 |
+ $res7->closeCursor(); |
|
| 214 |
+ |
|
| 215 |
+ $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key'], $password = ''); |
|
| 216 |
+ $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret'], $password = ''); |
|
| 217 |
+ $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token'], $password = ''); |
|
| 218 |
+ $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url'], $password = ''); |
|
| 219 |
+ $getnotification = $settingsfrdb['get_notification']; |
|
| 220 |
+ $notifyemail = $settingsfrdb['notification_email']; |
|
| 221 |
+ |
|
| 222 |
+ return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail]; |
|
| 223 |
+ |
|
| 224 |
+ } |
|
| 225 |
+ |
|
| 226 |
+} |