Browse code

added appinfo/info.xml appinfo/signature.json CHANGELOG.txt lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php

DoubleBastionAdmin authored on 02/05/2024 21:10:10
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1243 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\Share\IManager;
49
+use OCP\Constants;
50
+use OCP\IGroupManager;
51
+use OCP\IDBConnection;
52
+use OCP\IUserManager;
53
+use OC\URLGenerator;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $shareManager;
64
+    private $groupManager;
65
+    private $connection;
66
+    private $userManager;
67
+    private $urlGenerator;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->shareManager = $shareManager;
78
+        $this->groupManager = $groupManager;
79
+        $this->connection = $connection;
80
+        $this->userManager = $userManager;
81
+        $this->urlGenerator = $urlGenerator;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getappdirectory($userId) {
120
+        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
+        $apprelpatharr = explode("/", $apprelpath);
122
+        $currentappdir = $apprelpatharr[1];
123
+        return $currentappdir;
124
+    }
125
+
126
+
127
+    /**
128
+     * @NoAdminRequired
129
+     */
130
+    public function createMessageId() {
131
+             // Create a random string to use as message id for messages that don't have it
132
+	     $keypassin = substr(sha1((string) mt_rand()), 0, 32);
133
+	     $keysaltin = openssl_random_pseudo_bytes(24);
134
+	     $keyLengthin = 32;
135
+	     $iterationin = 50;
136
+	     $generated_keyin = openssl_pbkdf2($keypassin, $keysaltin, $keyLengthin, $iterationin, 'sha256');
137
+	     $ctdMessageId = "generated-id-" . bin2hex($generated_keyin);
138
+             return $ctdMessageId;
139
+    }
140
+
141
+
142
+    /**
143
+     * @NoAdminRequired
144
+     */
145
+    public function getbalancetel($userId) {
146
+
147
+        $telsmsapicred = $this->service->getapicredentials($this->userId, 'telnyx');
148
+
149
+        $telapikey = $telsmsapicred[0];
150
+        $ch = curl_init();
151
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
152
+
153
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
154
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
155
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
156
+        $responsetel = curl_exec($ch);
157
+        $recdatatel = json_decode($responsetel, TRUE);
158
+        $telbalresponse = $recdatatel['data']['balance'];
159
+        $currentbalancetel = round(floatval($telbalresponse), 3);
160
+        curl_close($ch);
161
+
162
+        return $currentbalancetel;
163
+    }
164
+
165
+
166
+    /**
167
+     * @NoAdminRequired
168
+     */
169
+    public function getbalancenex($userId) {
170
+
171
+        $smsapicred = $this->service->getapicredentials($this->userId, 'plivo');
172
+        $smsapikey = $smsapicred[5];
173
+        $smsapisecret = $smsapicred[6];
174
+
175
+        if ($smsapikey == '' || $smsapisecret == '') {
176
+            $currentbalancenex = "N/A";
177
+        } else {
178
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
179
+            $mesdata = file_get_contents($getmesdata);
180
+            $datainit = json_decode($mesdata);
181
+            $balancenex = $datainit->cash_credits;
182
+            $currentbalancenex = round(floatval($balancenex), 3);
183
+        }
184
+        return $currentbalancenex;
185
+    }
186
+
187
+
188
+    /**
189
+     * @NoAdminRequired
190
+     */
191
+    public function getbalancetwil($userId) {
192
+
193
+        $smsapicred = $this->service->getapicredentials($this->userId, 'twilio');
194
+        $smsapisid = $smsapicred[15];
195
+        $smsapitoken = $smsapicred[16];
196
+
197
+        if ($smsapisid == '' || $smsapitoken == '') {
198
+            $currentbalancetwil = "N/A";
199
+        } else {
200
+
201
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
202
+            $balancetwil = $twilbalance->balance;
203
+
204
+            $currentbalancetwil = round(floatval($balancetwil), 3);
205
+        }
206
+        return $currentbalancetwil;
207
+    }
208
+
209
+
210
+    /**
211
+     * @NoAdminRequired
212
+     */
213
+    public function getbalanceflow($userId) {
214
+
215
+        $currentbalanceflow = 'n/a';
216
+        return $currentbalanceflow;
217
+    }
218
+
219
+
220
+    /**
221
+     * @NoAdminRequired
222
+     */
223
+    public function getsmsnumbers($userId) {
224
+
225
+        return $this->service->getsmsnumbers($this->userId);
226
+    }
227
+
228
+
229
+    /**
230
+     * @NoAdminRequired
231
+     */
232
+    public function refreshavailablenumbers($userId) {
233
+
234
+        return $this->service->refreshavailablenumbers($this->userId);
235
+    }
236
+
237
+
238
+    /**
239
+     * @NoAdminRequired
240
+     */
241
+    public function cleantempdir($userId) {
242
+
243
+        // Create the temporary folder if it doesn't exist
244
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
245
+            $this->folder->newFolder('SMS_Relentless/temp_files');
246
+        }
247
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
248
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
249
+        $fileSystemIterator = new FilesystemIterator($targetdir);
250
+
251
+        $dirfiles = [];
252
+        foreach ($fileSystemIterator as $fileInfo) {
253
+                 $dirfiles[] = $fileInfo->getFilename();
254
+        }
255
+
256
+        foreach ($dirfiles as $key => $indfile) {
257
+                 $thisuserroot = $this->view->getRoot();
258
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
259
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
260
+        }
261
+     }
262
+
263
+
264
+    /**
265
+     * @NoAdminRequired
266
+     */
267
+    public function cleanmultrecdir($userId) {
268
+
269
+        // Create the temporary folder if it doesn't exist
270
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
271
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
272
+        }
273
+        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
274
+        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
275
+        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
276
+
277
+        $dirfilesmrc = [];
278
+        foreach ($fileSystemIteratormrc as $fileInfomrc){
279
+                 $dirfilesmrc[] = $fileInfomrc->getFilename();
280
+        }
281
+
282
+        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
283
+                 $thisuserrootmrc = $this->view->getRoot();
284
+                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
285
+                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
286
+        }
287
+     }
288
+
289
+
290
+    /**
291
+     * @NoAdminRequired
292
+     */
293
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
294
+
295
+        // Create the temporary folder if it doesn't exist
296
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
297
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
298
+        }
299
+
300
+        // First delete any file that has been previously uploaded
301
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
302
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
303
+        $fileSystemIterator = new FilesystemIterator($targetdir);
304
+
305
+        $dirfiles = [];
306
+        foreach ($fileSystemIterator as $fileInfo){
307
+                 $dirfiles[] = $fileInfo->getFilename();
308
+        }
309
+
310
+        foreach ($dirfiles as $key => $indfile) {
311
+                 $thisuserroot = $this->view->getRoot();
312
+                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
313
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
314
+        }
315
+
316
+        // Upload the new file
317
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
318
+        $fileName = $_FILES['uploadfileforsms']['name'];
319
+
320
+        $userroot = $this->view->getRoot();
321
+        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
322
+
323
+        $target = $this->folder->newFile($targetfile);
324
+        $target->putContent($fileContent);
325
+
326
+        // Extract the phone numbers from the file
327
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
328
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
329
+        $numberarrayfourth = explode(",", $numberarraytert);
330
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
331
+        $numberarray = array_unique($numberarrayfifth);
332
+
333
+        return $numberarray;
334
+    }
335
+
336
+
337
+    /**
338
+     * @NoAdminRequired
339
+     */
340
+    public function uploadfile($uploadfileformms) {
341
+
342
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
343
+           $fileName = $_FILES['uploadfileformms']['name'];
344
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
345
+           $fileSize = $fileSizeinit / 1024;
346
+
347
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
348
+               $this->folder->newFolder('SMS_Relentless/temp_files');
349
+           }
350
+
351
+           $userroot = $this->view->getRoot();
352
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
353
+
354
+           $target = $this->folder->newFile($targetfile);
355
+           $target->putContent($fileContent);
356
+
357
+           // Get the cumulative files size of the uploaded files
358
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
359
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
360
+
361
+           $fileSystemIterator = new FilesystemIterator($targetdir);
362
+
363
+           $dirfiles = [];
364
+           foreach ($fileSystemIterator as $fileInfo){
365
+                    $dirfiles[] = $fileInfo->getFilename();
366
+           }
367
+
368
+           $totalflsizeinit = 0;
369
+           foreach ($dirfiles as $key => $indfile) {
370
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
371
+                    $mbSize = round($fileSizeinit / 1024, 4);
372
+                    $totalflsizeinit += $mbSize;
373
+           }
374
+
375
+           $totalflsize = round($totalflsizeinit, 4);
376
+
377
+           return $totalflsize;
378
+    }
379
+
380
+
381
+    /**
382
+     * @NoAdminRequired
383
+     */
384
+    public function pickfile($path) {
385
+
386
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
387
+               $this->folder->newFolder('SMS_Relentless/temp_files');
388
+           }
389
+
390
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
391
+
392
+           $fltgt = $datadir . $this->userId . "/files" . $path;
393
+
394
+           $fileContent = file_get_contents($fltgt);
395
+
396
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
397
+
398
+           $patharr = explode("/", $path);
399
+
400
+           $revarr = array_reverse($patharr);
401
+
402
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
403
+
404
+           $target = $this->folder->newFile($relflpath);
405
+
406
+           $target->putContent($fileContent);
407
+
408
+           // Get the cumulative files size of the uploaded files
409
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
410
+
411
+           $fileSystemIterator = new FilesystemIterator($targetdir);
412
+
413
+           $dirfiles = [];
414
+           foreach ($fileSystemIterator as $fileInfo) {
415
+                    $dirfiles[] = $fileInfo->getFilename();
416
+           }
417
+
418
+           $totalflsizeinit = 0;
419
+
420
+           foreach ($dirfiles as $key => $indfile) {
421
+
422
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
423
+                    $mbSize = round($fileSizeinit / 1024, 4);
424
+                    $totalflsizeinit += $mbSize;
425
+           }
426
+
427
+           $totalflsize = round($totalflsizeinit, 4);
428
+
429
+           $pickresult = [$totalflsize, $pkfilesize];
430
+
431
+           return $pickresult;
432
+    }
433
+
434
+
435
+    /**
436
+     * @NoAdminRequired
437
+     */
438
+    public function removeupfile($removedfilename) {
439
+
440
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
441
+
442
+           $removefile = $this->view->unlink($tmpfl);
443
+
444
+           // Get the cumulative files size of the uploaded files
445
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
446
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
447
+           $fileSystemIterator = new FilesystemIterator($targetdir);
448
+
449
+           $dirfiles = [];
450
+           foreach ($fileSystemIterator as $fileInfo){
451
+                    $dirfiles[] = $fileInfo->getFilename();
452
+           }
453
+
454
+           $totalflsizeinit = 0;
455
+
456
+           foreach ($dirfiles as $key => $indfile) {
457
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
458
+                    $mbSize = round($fileSizeinit / 1024, 4);
459
+                    $totalflsizeinit += $mbSize;
460
+           }
461
+
462
+           $totalflsize = round($totalflsizeinit, 4);
463
+
464
+           return $totalflsize;
465
+    }
466
+
467
+
468
+    /**
469
+     * @NoAdminRequired
470
+     */
471
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
472
+
473
+         $telsmsapicred = $this->service->getapicredentials($this->userId, 'telnyx');
474
+         $telnyxkey = $telsmsapicred[0];
475
+         $teldelrecurl = $telsmsapicred[3];
476
+         $messagingprofid = $telsmsapicred[4];
477
+         $addDisplName = $telsmsapicred[24];
478
+
479
+         // Get the Display Name of the current user
480
+         $crtuser = $this->userManager->get($this->userId);
481
+         $displayname = $crtuser->getDisplayName();
482
+
483
+         if ($addDisplName == 1) {
484
+             $sentsmstext = $displayname . ": " . $sentsmstext;
485
+         }
486
+
487
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
488
+
489
+         $microinterval = $waitinterval * 1000;
490
+
491
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
492
+
493
+             usleep($microinterval);
494
+
495
+             $messagedate = date("Y-m-d H:i:s");
496
+
497
+             if ($ismms == 0) {
498
+
499
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
500
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
501
+                 } else {
502
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
503
+                 }
504
+
505
+                 $messagetexttel = $sentsmstext;
506
+
507
+             } else {
508
+
509
+                 $mediaURLarr = [];
510
+                 $includedMediaFiles = '';
511
+
512
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
513
+
514
+                      $userroot = $this->view->getRoot();
515
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
516
+
517
+                      $flsharetarget = $this->folder->newFile($filetoshare);
518
+
519
+	              $share = $this->shareManager->newShare();
520
+	              $share->setNode($flsharetarget);
521
+	              $share->setPermissions(Constants::PERMISSION_READ);
522
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
523
+	              $share->setSharedBy($this->userId);
524
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
525
+                      $expirydate->add(new \DateInterval('P1D'));
526
+                      $share->setExpirationDate($expirydate);
527
+                      $shared = $this->shareManager->createShare($share);
528
+                      $shareToken = $shared->getToken();
529
+
530
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
531
+
532
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
533
+
534
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
535
+                 }
536
+
537
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
538
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
539
+                 } else {
540
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
541
+                 }
542
+
543
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
544
+             }
545
+
546
+             if ($message) {
547
+                 if (isset($message['id'])) { $messageid = $message['id']; } else { $messageid = $this->createMessageId(); }
548
+             } else { $messageid = $this->createMessageId(); }
549
+
550
+             $messagefrom = "Telnyx: " . $fromsender;
551
+             $messageto = $tonumber;
552
+             $messagenetwork = null;
553
+             $messageprice = null;
554
+             $messagestatus = $message['to'][0]['status'];
555
+             $messagedelivery = null;
556
+
557
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
558
+
559
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
560
+         }
561
+         return $displayname;
562
+    }
563
+
564
+
565
+    /**
566
+     * @NoAdminRequired
567
+     */
568
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
569
+
570
+         $plsmsapicred = $this->service->getapicredentials($this->userId, 'plivo');
571
+
572
+         $smsapikey = $plsmsapicred[5];
573
+         $smsapisecret = $plsmsapicred[6];
574
+         $smsapideliveryrecurl = $plsmsapicred[8];
575
+         $addDisplName = $plsmsapicred[24];
576
+
577
+         // Get the Display Name of the current user
578
+         $crtuser = $this->userManager->get($this->userId);
579
+         $displayname = $crtuser->getDisplayName();
580
+
581
+         if ($addDisplName == 1) {
582
+             $sentsmstext = $displayname . ": " . $sentsmstext;
583
+         }
584
+
585
+         $microinterval = $waitinterval * 1000;
586
+
587
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
588
+
589
+             usleep($microinterval);
590
+
591
+             $messagedatepl = date("Y-m-d H:i:s");
592
+
593
+             if ($ismms == 0) {
594
+
595
+                 $client = new RestClient($smsapikey, $smsapisecret);
596
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
597
+                 $messagetextpl = $sentsmstext;
598
+	         $messageidinit = $response->getmessageUuid(0);
599
+                 $messageid = $messageidinit[0];
600
+
601
+                 if (property_exists($response, 'error')) { 
602
+                     $messagestatus = "Error: " . $response->error;
603
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
604
+
605
+             } else {
606
+
607
+                 $mediaURLarr = [];
608
+                 $includedMediaFiles = '';
609
+
610
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
611
+
612
+                      $userroot = $this->view->getRoot();
613
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
614
+
615
+                      $flsharetarget = $this->folder->newFile($filetoshare);
616
+
617
+	              $share = $this->shareManager->newShare();
618
+	              $share->setNode($flsharetarget);
619
+	              $share->setPermissions(Constants::PERMISSION_READ);
620
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
621
+	              $share->setSharedBy($this->userId);
622
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
623
+                      $expirydate->add(new \DateInterval('P1D'));
624
+                      $share->setExpirationDate($expirydate);
625
+                      $shared = $this->shareManager->createShare($share);
626
+                      $shareToken = $shared->getToken();
627
+
628
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
629
+
630
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
631
+
632
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
633
+                 }
634
+
635
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
636
+		 $postedparamspl = json_encode($datatosendpl);
637
+
638
+		 $chpl = curl_init();
639
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
640
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
641
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
642
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
643
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
644
+		 curl_setopt($chpl, CURLOPT_POST, 1);
645
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
646
+		 $resultpl = curl_exec ($chpl);
647
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
648
+		 curl_close ($chpl);
649
+
650
+		 $decresultpl = json_decode($resultpl);
651
+
652
+                 if ($decresultpl) {
653
+                     if (property_exists($decresultpl, 'message_uuid')) {
654
+                         $messageidinit = $decresultpl->message_uuid;
655
+                         $messageid = $messageidinit[0];
656
+                     } else { $messageid = $this->createMessageId(); }
657
+                 } else { $messageid = $this->createMessageId(); }
658
+
659
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
660
+
661
+                     if (property_exists($decresultpl, 'error')) {
662
+                         $messagestatus = "Error: " . $decresultpl->error;
663
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
664
+
665
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
666
+
667
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
668
+             }
669
+
670
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
671
+                 $messagefrom = "Plivo: " . $fromsender;
672
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
673
+
674
+             $messageto = $tonumber;
675
+             $messagenetwork = '';
676
+             $messageprice = '';
677
+
678
+             $messagedelivery = '';
679
+
680
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
681
+
682
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
683
+         }
684
+         return $displayname;
685
+    }
686
+
687
+
688
+    /**
689
+     * @NoAdminRequired
690
+     */
691
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
692
+
693
+         $twsmsapicred = $this->service->getapicredentials($this->userId, 'twilio');
694
+
695
+         $sid = $twsmsapicred[15];
696
+         $token = $twsmsapicred[16];
697
+         $smsapirecurltw = $twsmsapicred[18];
698
+         $addDisplName = $twsmsapicred[24];
699
+
700
+         // Get the Display Name of the current user
701
+         $crtuser = $this->userManager->get($this->userId);
702
+         $displayname = $crtuser->getDisplayName();
703
+
704
+         if ($addDisplName == 1) {
705
+             $sentsmstext = $displayname . ": " . $sentsmstext;
706
+         }
707
+
708
+         $microinterval = $waitinterval * 1000;
709
+
710
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
711
+
712
+             usleep($microinterval);
713
+
714
+             $messagedatetw = date("Y-m-d H:i:s");
715
+
716
+             if ($ismms == 0) {
717
+
718
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
719
+                 $sentsmstextfintw = $sentsmstext;
720
+
721
+             } else {
722
+
723
+                 $mediaURLs = [];
724
+                 $includedMediaFiles = '';
725
+
726
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
727
+
728
+                      $userroot = $this->view->getRoot();
729
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
730
+
731
+                      $flsharetarget = $this->folder->newFile($filetoshare);
732
+
733
+	              $share = $this->shareManager->newShare();
734
+	              $share->setNode($flsharetarget);
735
+	              $share->setPermissions(Constants::PERMISSION_READ);
736
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
737
+	              $share->setSharedBy($this->userId);
738
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
739
+                      $expirydate->add(new \DateInterval('P1D'));
740
+                      $share->setExpirationDate($expirydate);
741
+                      $shared = $this->shareManager->createShare($share);
742
+                      $shareToken = $shared->getToken();
743
+
744
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
745
+
746
+                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
747
+
748
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
749
+                 }
750
+
751
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
752
+
753
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
754
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
755
+                 }
756
+
757
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
758
+             }
759
+
760
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
761
+
762
+	     $chtw = curl_init();
763
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
764
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
765
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
766
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
767
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
768
+	     curl_setopt($chtw, CURLOPT_POST, 1);
769
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
770
+
771
+	     $resulttw = curl_exec ($chtw);
772
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
773
+	     curl_close ($chtw);
774
+
775
+             $decresulttw = json_decode($resulttw);
776
+
777
+             if ($decresulttw) {
778
+                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = $this->createMessageId(); }
779
+             } else { $messageidtw = $this->createMessageId(); }
780
+
781
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
782
+                 $messagestatustw = 'The message has been accepted for delivery.';
783
+             } else {
784
+                 $messagestatustw = 'An error occurred while trying to send the message.';
785
+             }
786
+
787
+             $messagefromtw = "Twilio: " . $fromsender;
788
+
789
+             $messagenetworktw = '';
790
+             $messagepricetw = '';
791
+             $messagedeliverytw = '';
792
+
793
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
794
+
795
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
796
+         }
797
+         return $displayname;
798
+    }
799
+
800
+
801
+    /**
802
+     * @NoAdminRequired
803
+     */
804
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
805
+
806
+         $flsmsapicred = $this->service->getapicredentials($this->userId, 'flowroute');
807
+
808
+         $flowapikey = $flsmsapicred[20];
809
+         $flowapisecret = $flsmsapicred[21];
810
+         $flowdelrecurl = $flsmsapicred[23];
811
+         $addDisplName = $flsmsapicred[24];
812
+
813
+         // Get the Display Name of the current user
814
+         $crtuser = $this->userManager->get($this->userId);
815
+         $displayname = $crtuser->getDisplayName();
816
+
817
+         if ($addDisplName == 1) {
818
+             $sentsmstext = $displayname . ": " . $sentsmstext;
819
+         }
820
+
821
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
822
+
823
+         $microinterval = $waitinterval * 1000;
824
+
825
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
826
+
827
+             usleep($microinterval);
828
+
829
+             $messagedatefl = date("Y-m-d H:i:s");
830
+
831
+             if ($ismms == 0) {
832
+
833
+                 $messagetextfinfl = $sentsmstext;
834
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
835
+
836
+             } else {
837
+
838
+		 $mediaurlsarr = [];
839
+		 $includedMediaFiles = '';
840
+
841
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
842
+
843
+		      $userroot = $this->view->getRoot();
844
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
845
+
846
+		      $flsharetarget = $this->folder->newFile($filetoshare);
847
+
848
+		      $share = $this->shareManager->newShare();
849
+		      $share->setNode($flsharetarget);
850
+		      $share->setPermissions(Constants::PERMISSION_READ);
851
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
852
+		      $share->setSharedBy($this->userId);
853
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
854
+                      $expirydate->add(new \DateInterval('P1D'));
855
+                      $share->setExpirationDate($expirydate);
856
+		      $shared = $this->shareManager->createShare($share);
857
+		      $shareToken = $shared->getToken();
858
+
859
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
860
+
861
+		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
862
+
863
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
864
+		 }
865
+
866
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
867
+
868
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
869
+             }
870
+
871
+	     $chfl = curl_init();
872
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
873
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
874
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
875
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
876
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
877
+	     curl_setopt($chfl, CURLOPT_POST, 1);
878
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
879
+	     $resultfl = curl_exec ($chfl);
880
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
881
+	     curl_close ($chfl);
882
+
883
+             $decresultfl = json_decode($resultfl);
884
+
885
+             if ($decresultfl) {
886
+                 if (isset($decresultfl->data->id)) { 
887
+                     $messageidfl = $decresultfl->data->id;
888
+                 } else { $messageidfl = $this->createMessageId(); }
889
+             } else { $messageidfl = $this->createMessageId(); }
890
+
891
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
892
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
893
+             } else { 
894
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
895
+             }
896
+
897
+             $messagefromfl = "Flowroute: " . $fromsender;
898
+             $messagetofl = $tonumberfl;
899
+             $messagenetworkfl = '';
900
+             $messagepricefl = '';
901
+             $messagedeliveryfl = '';
902
+
903
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
904
+
905
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
906
+         }
907
+         return $displayname;
908
+    }
909
+
910
+
911
+    /**
912
+     * @NoAdminRequired
913
+     */
914
+    public function saveoldrecrows($userId, $oldrecRows) {
915
+
916
+           // Create the folder for removed messages if it doesn't exist
917
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
918
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
919
+           }
920
+           $savecheck = 0;
921
+
922
+           if (count($oldrecRows) > 1) {
923
+               $msfileContent = implode("", $oldrecRows);
924
+
925
+               $delrowsdate = date("Y-m-d_H-i-s");
926
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
927
+
928
+               $userroot = $this->view->getRoot();
929
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
930
+
931
+               $target = $this->folder->newFile($targetfile);
932
+               $target->putContent($msfileContent);
933
+
934
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
935
+                   $savecheck = 1;
936
+               }
937
+           }
938
+
939
+           return $savecheck;
940
+    }
941
+
942
+
943
+    /**
944
+     * @NoAdminRequired
945
+     */
946
+    public function saveoldsentrows($userId, $oldsentRows) {
947
+
948
+           // Create the folder for removed messages if it doesn't exist
949
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
950
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
951
+           }
952
+           $savesentcheck = 0;
953
+
954
+           if (count($oldsentRows) > 1) {
955
+               $sntfileContent = implode("", $oldsentRows);
956
+
957
+               $delsentrowsdate = date("Y-m-d_H-i-s");
958
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
959
+
960
+               $userroot = $this->view->getRoot();
961
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
962
+
963
+               $snttarget = $this->folder->newFile($snttargetfile);
964
+               $snttarget->putContent($sntfileContent);
965
+
966
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
967
+                   $savesentcheck = 1;
968
+               }
969
+           }
970
+
971
+           return $savesentcheck;
972
+    }
973
+
974
+
975
+    /**
976
+     * @NoAdminRequired
977
+     */
978
+    public function getreceivedtable($userId) {
979
+           return $this->service->getreceivedtable($this->userId);
980
+    }
981
+
982
+    /**
983
+     * @NoAdminRequired
984
+     */
985
+    public function getreceivedtablefordel($userId) {
986
+           return $this->service->getreceivedtablefordel($this->userId);
987
+    }
988
+
989
+    /**
990
+     * @NoAdminRequired
991
+     */
992
+    public function removerecrows($userId, $recmessagedbIDs) {
993
+
994
+           // Get the Display Name of the current user
995
+           $crtuserdel = $this->userManager->get($this->userId);
996
+           $userDelDspName = $crtuserdel->getDisplayName();
997
+
998
+           return $this->service->removerecrows($this->userId, $userDelDspName, $recmessagedbIDs);
999
+    }
1000
+
1001
+    /**
1002
+     * @NoAdminRequired
1003
+     */
1004
+    public function getsenttable($userId) {
1005
+           return $this->service->getsenttable($this->userId);
1006
+    }
1007
+
1008
+    /**
1009
+     * @NoAdminRequired
1010
+     */
1011
+    public function getsenttablefordel($userId) {
1012
+           return $this->service->getsenttablefordel($this->userId);
1013
+    }
1014
+
1015
+    /**
1016
+     * @NoAdminRequired
1017
+     */
1018
+    public function removesentrows($userId, $sentmessagedbIDs) {
1019
+
1020
+           // Get the Display Name of the current user
1021
+           $crtuserstdel = $this->userManager->get($this->userId);
1022
+           $userstDelDspName = $crtuserstdel->getDisplayName();
1023
+
1024
+           return $this->service->removesentrows($this->userId, $userstDelDspName, $sentmessagedbIDs);
1025
+    }
1026
+
1027
+    /**
1028
+     * @NoAdminRequired
1029
+     */
1030
+    public function getconversations($userId) {
1031
+           return $this->service->getconversations($this->userId);
1032
+    }
1033
+
1034
+    /**
1035
+     * @NoAdminRequired
1036
+     */
1037
+    public function archiveconv($userId, $conversationId) {
1038
+
1039
+           // Get the Display Name of the current user
1040
+           $crtusergt = $this->userManager->get($this->userId);
1041
+           $userDspNameArch = $crtusergt->getDisplayName();
1042
+
1043
+           return $this->service->archiveconv($this->userId, $userDspNameArch, $conversationId);
1044
+    }
1045
+
1046
+    /**
1047
+     * @NoAdminRequired
1048
+     */
1049
+    public function unarchiveconv($userId, $conversationId) {
1050
+
1051
+           // Get the Display Name of the current user
1052
+           $crtusergtun = $this->userManager->get($this->userId);
1053
+           $userDspNameUnarch = $crtusergtun->getDisplayName();
1054
+
1055
+           return $this->service->unarchiveconv($this->userId, $userDspNameUnarch, $conversationId);
1056
+    }
1057
+
1058
+    /**
1059
+     * @NoAdminRequired
1060
+     */
1061
+    public function saveconvdescription($userId, $convDescription, $convId) {
1062
+
1063
+           // Get the Display Name of the current user
1064
+           $crtuserdesc = $this->userManager->get($this->userId);
1065
+           $userDspNameDesc = $crtuserdesc->getDisplayName();
1066
+
1067
+           return $this->service->saveconvdescription($this->userId, $userDspNameDesc, $convDescription, $convId);
1068
+    }
1069
+
1070
+    /**
1071
+     * @NoAdminRequired
1072
+     */
1073
+    public function saveconvtag($userId, $convTag, $convId) {
1074
+
1075
+           // Get the Display Name of the current user
1076
+           $crtusertag = $this->userManager->get($this->userId);
1077
+           $userDspNameTag = $crtusertag->getDisplayName();
1078
+
1079
+           return $this->service->saveconvtag($this->userId, $userDspNameTag, $convTag, $convId);
1080
+    }
1081
+
1082
+    /**
1083
+     * @NoAdminRequired
1084
+     */
1085
+    public function saveconvflag($userId, $convFlag, $convId) {
1086
+
1087
+           // Get the Display Name of the current user
1088
+           $crtuserflag = $this->userManager->get($this->userId);
1089
+           $userDspNameFlag = $crtuserflag->getDisplayName();
1090
+
1091
+           return $this->service->saveconvflag($this->userId, $userDspNameFlag, $convFlag, $convId);
1092
+    }
1093
+
1094
+    /**
1095
+     * @NoAdminRequired
1096
+     */
1097
+    public function removeconvmsgs($userId, $conversationId) {
1098
+           return $this->service->removeconvmsgs($this->userId, $conversationId);
1099
+    }
1100
+
1101
+    /**
1102
+     * @NoAdminRequired
1103
+     */
1104
+    public function getgroupedtable($userId) {
1105
+           return $this->service->getgroupedtable($this->userId);
1106
+    }
1107
+
1108
+    /**
1109
+     * @NoAdminRequired
1110
+     */
1111
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1112
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1113
+    }
1114
+
1115
+    /**
1116
+     * @NoAdminRequired
1117
+     */
1118
+    public function getmsgsperpgnewmsgarchnb($userId) {
1119
+           return $this->service->getmsgsperpgnewmsgarchnb($this->userId);
1120
+    }
1121
+
1122
+    /**
1123
+     * @NoAdminRequired
1124
+     */
1125
+    public function getnewmsgindicator($userId) {
1126
+           return $this->service->getnewmsgindicator($this->userId);
1127
+    }
1128
+
1129
+    /**
1130
+     * @NoAdminRequired
1131
+     */
1132
+    public function getdelrecsettings($userId) {
1133
+           return $this->service->getdelrecsettings($this->userId);
1134
+    }
1135
+
1136
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1137
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1138
+    }
1139
+
1140
+    public function updatekeysallowedusers($userId, $groups, $users, $groupsdel, $usersdel, $provider) {
1141
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $groupsdel, $usersdel, $provider);
1142
+    }
1143
+
1144
+    public function removenumberrestrictions($userId, $phoneNumber) {
1145
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1146
+    }
1147
+
1148
+    /**
1149
+     * @NoAdminRequired
1150
+     */
1151
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1152
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1153
+    }
1154
+
1155
+    /**
1156
+     * @NoAdminRequired
1157
+     */
1158
+    public function removeautoreplies($userId, $phoneNumber) {
1159
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1160
+    }
1161
+
1162
+    /**
1163
+     * @NoAdminRequired
1164
+     */
1165
+    public function getsettings($userId) {
1166
+           return $this->service->getsettings($this->userId);
1167
+    }
1168
+
1169
+    public function getadminsettings($userId) {
1170
+           return $this->service->getadminsettings($this->userId);
1171
+    }
1172
+
1173
+    /**
1174
+     * @NoAdminRequired
1175
+     */
1176
+    public function getautoreplyconf($userId) {
1177
+
1178
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1179
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1180
+
1181
+           // Get the display name of the current user
1182
+           $usrid = $this->userId;
1183
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1184
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1185
+	   $getusrdnmdata = $getusrdnmres->fetch();
1186
+	   $userDisplayNm = $getusrdnmdata['value'];
1187
+	   $getusrdnmres->closeCursor();
1188
+
1189
+           // Get the auto-replies for the available phone numbers
1190
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1191
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1192
+	   $getautorplres = $getautorpl->execute();
1193
+           $autorplconf = [];
1194
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1195
+                  $autorplconf[] = $acdatausrdnadm;
1196
+           }
1197
+	   $getautorplres->closeCursor();
1198
+
1199
+           if ($autorplconf) {
1200
+
1201
+               $autoreplyconf = [];
1202
+               foreach ($autorplconf as $arkey => $arvalue) {
1203
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1204
+                            $autoreplyconf[] = $arvalue;
1205
+                        }
1206
+               }
1207
+
1208
+           } else { $autoreplyconf = ''; }
1209
+
1210
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1211
+
1212
+           return $autoreplyfdb;
1213
+    }
1214
+
1215
+    /**
1216
+     * @NoAdminRequired
1217
+     */
1218
+    public function getgroupedpernumber($userId, $phoneNumber) {
1219
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1220
+    }
1221
+
1222
+    /**
1223
+     * @NoAdminRequired
1224
+     */
1225
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1226
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1227
+    }
1228
+
1229
+    /**
1230
+     * @NoAdminRequired
1231
+     */
1232
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1233
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1234
+    }
1235
+
1236
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1237
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1238
+    }
1239
+
1240
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1241
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1242
+    }
1243
+}
Browse code

removed appinfo/info.xml appinfo/signature.json CHANGELOG.txt lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php

DoubleBastionAdmin authored on 02/05/2024 21:05:50
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1243 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\Share\IManager;
49
-use OCP\Constants;
50
-use OCP\IGroupManager;
51
-use OCP\IDBConnection;
52
-use OCP\IUserManager;
53
-use OC\URLGenerator;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $shareManager;
64
-    private $groupManager;
65
-    private $connection;
66
-    private $userManager;
67
-    private $urlGenerator;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->shareManager = $shareManager;
78
-        $this->groupManager = $groupManager;
79
-        $this->connection = $connection;
80
-        $this->userManager = $userManager;
81
-        $this->urlGenerator = $urlGenerator;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getappdirectory($userId) {
120
-        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
-        $apprelpatharr = explode("/", $apprelpath);
122
-        $currentappdir = $apprelpatharr[1];
123
-        return $currentappdir;
124
-    }
125
-
126
-
127
-    /**
128
-     * @NoAdminRequired
129
-     */
130
-    public function createMessageId() {
131
-             // Create a random string to use as message id for messages that don't have it
132
-	     $keypassin = substr(sha1((string) mt_rand()), 0, 32);
133
-	     $keysaltin = openssl_random_pseudo_bytes(24);
134
-	     $keyLengthin = 32;
135
-	     $iterationin = 50;
136
-	     $generated_keyin = openssl_pbkdf2($keypassin, $keysaltin, $keyLengthin, $iterationin, 'sha256');
137
-	     $ctdMessageId = "generated-id-" . bin2hex($generated_keyin);
138
-             return $ctdMessageId;
139
-    }
140
-
141
-
142
-    /**
143
-     * @NoAdminRequired
144
-     */
145
-    public function getbalancetel($userId) {
146
-
147
-        $telsmsapicred = $this->service->getapicredentials($this->userId, 'telnyx');
148
-
149
-        $telapikey = $telsmsapicred[0];
150
-        $ch = curl_init();
151
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
152
-
153
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
154
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
155
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
156
-        $responsetel = curl_exec($ch);
157
-        $recdatatel = json_decode($responsetel, TRUE);
158
-        $telbalresponse = $recdatatel['data']['balance'];
159
-        $currentbalancetel = round(floatval($telbalresponse), 3);
160
-        curl_close($ch);
161
-
162
-        return $currentbalancetel;
163
-    }
164
-
165
-
166
-    /**
167
-     * @NoAdminRequired
168
-     */
169
-    public function getbalancenex($userId) {
170
-
171
-        $smsapicred = $this->service->getapicredentials($this->userId, 'plivo');
172
-        $smsapikey = $smsapicred[5];
173
-        $smsapisecret = $smsapicred[6];
174
-
175
-        if ($smsapikey == '' || $smsapisecret == '') {
176
-            $currentbalancenex = "N/A";
177
-        } else {
178
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
179
-            $mesdata = file_get_contents($getmesdata);
180
-            $datainit = json_decode($mesdata);
181
-            $balancenex = $datainit->cash_credits;
182
-            $currentbalancenex = round(floatval($balancenex), 3);
183
-        }
184
-        return $currentbalancenex;
185
-    }
186
-
187
-
188
-    /**
189
-     * @NoAdminRequired
190
-     */
191
-    public function getbalancetwil($userId) {
192
-
193
-        $smsapicred = $this->service->getapicredentials($this->userId, 'twilio');
194
-        $smsapisid = $smsapicred[15];
195
-        $smsapitoken = $smsapicred[16];
196
-
197
-        if ($smsapisid == '' || $smsapitoken == '') {
198
-            $currentbalancetwil = "N/A";
199
-        } else {
200
-
201
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
202
-            $balancetwil = $twilbalance->balance;
203
-
204
-            $currentbalancetwil = round(floatval($balancetwil), 3);
205
-        }
206
-        return $currentbalancetwil;
207
-    }
208
-
209
-
210
-    /**
211
-     * @NoAdminRequired
212
-     */
213
-    public function getbalanceflow($userId) {
214
-
215
-        $currentbalanceflow = 'n/a';
216
-        return $currentbalanceflow;
217
-    }
218
-
219
-
220
-    /**
221
-     * @NoAdminRequired
222
-     */
223
-    public function getsmsnumbers($userId) {
224
-
225
-        return $this->service->getsmsnumbers($this->userId);
226
-    }
227
-
228
-
229
-    /**
230
-     * @NoAdminRequired
231
-     */
232
-    public function refreshavailablenumbers($userId) {
233
-
234
-        return $this->service->refreshavailablenumbers($this->userId);
235
-    }
236
-
237
-
238
-    /**
239
-     * @NoAdminRequired
240
-     */
241
-    public function cleantempdir($userId) {
242
-
243
-        // Create the temporary folder if it doesn't exist
244
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
245
-            $this->folder->newFolder('SMS_Relentless/temp_files');
246
-        }
247
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
248
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
249
-        $fileSystemIterator = new FilesystemIterator($targetdir);
250
-
251
-        $dirfiles = [];
252
-        foreach ($fileSystemIterator as $fileInfo) {
253
-                 $dirfiles[] = $fileInfo->getFilename();
254
-        }
255
-
256
-        foreach ($dirfiles as $key => $indfile) {
257
-                 $thisuserroot = $this->view->getRoot();
258
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
259
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
260
-        }
261
-     }
262
-
263
-
264
-    /**
265
-     * @NoAdminRequired
266
-     */
267
-    public function cleanmultrecdir($userId) {
268
-
269
-        // Create the temporary folder if it doesn't exist
270
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
271
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
272
-        }
273
-        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
274
-        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
275
-        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
276
-
277
-        $dirfilesmrc = [];
278
-        foreach ($fileSystemIteratormrc as $fileInfomrc){
279
-                 $dirfilesmrc[] = $fileInfomrc->getFilename();
280
-        }
281
-
282
-        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
283
-                 $thisuserrootmrc = $this->view->getRoot();
284
-                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
285
-                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
286
-        }
287
-     }
288
-
289
-
290
-    /**
291
-     * @NoAdminRequired
292
-     */
293
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
294
-
295
-        // Create the temporary folder if it doesn't exist
296
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
297
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
298
-        }
299
-
300
-        // First delete any file that has been previously uploaded
301
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
302
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
303
-        $fileSystemIterator = new FilesystemIterator($targetdir);
304
-
305
-        $dirfiles = [];
306
-        foreach ($fileSystemIterator as $fileInfo){
307
-                 $dirfiles[] = $fileInfo->getFilename();
308
-        }
309
-
310
-        foreach ($dirfiles as $key => $indfile) {
311
-                 $thisuserroot = $this->view->getRoot();
312
-                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
313
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
314
-        }
315
-
316
-        // Upload the new file
317
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
318
-        $fileName = $_FILES['uploadfileforsms']['name'];
319
-
320
-        $userroot = $this->view->getRoot();
321
-        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
322
-
323
-        $target = $this->folder->newFile($targetfile);
324
-        $target->putContent($fileContent);
325
-
326
-        // Extract the phone numbers from the file
327
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
328
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
329
-        $numberarrayfourth = explode(",", $numberarraytert);
330
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
331
-        $numberarray = array_unique($numberarrayfifth);
332
-
333
-        return $numberarray;
334
-    }
335
-
336
-
337
-    /**
338
-     * @NoAdminRequired
339
-     */
340
-    public function uploadfile($uploadfileformms) {
341
-
342
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
343
-           $fileName = $_FILES['uploadfileformms']['name'];
344
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
345
-           $fileSize = $fileSizeinit / 1024;
346
-
347
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
348
-               $this->folder->newFolder('SMS_Relentless/temp_files');
349
-           }
350
-
351
-           $userroot = $this->view->getRoot();
352
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
353
-
354
-           $target = $this->folder->newFile($targetfile);
355
-           $target->putContent($fileContent);
356
-
357
-           // Get the cumulative files size of the uploaded files
358
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
359
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
360
-
361
-           $fileSystemIterator = new FilesystemIterator($targetdir);
362
-
363
-           $dirfiles = [];
364
-           foreach ($fileSystemIterator as $fileInfo){
365
-                    $dirfiles[] = $fileInfo->getFilename();
366
-           }
367
-
368
-           $totalflsizeinit = 0;
369
-           foreach ($dirfiles as $key => $indfile) {
370
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
371
-                    $mbSize = round($fileSizeinit / 1024, 4);
372
-                    $totalflsizeinit += $mbSize;
373
-           }
374
-
375
-           $totalflsize = round($totalflsizeinit, 4);
376
-
377
-           return $totalflsize;
378
-    }
379
-
380
-
381
-    /**
382
-     * @NoAdminRequired
383
-     */
384
-    public function pickfile($path) {
385
-
386
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
387
-               $this->folder->newFolder('SMS_Relentless/temp_files');
388
-           }
389
-
390
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
391
-
392
-           $fltgt = $datadir . $this->userId . "/files" . $path;
393
-
394
-           $fileContent = file_get_contents($fltgt);
395
-
396
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
397
-
398
-           $patharr = explode("/", $path);
399
-
400
-           $revarr = array_reverse($patharr);
401
-
402
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
403
-
404
-           $target = $this->folder->newFile($relflpath);
405
-
406
-           $target->putContent($fileContent);
407
-
408
-           // Get the cumulative files size of the uploaded files
409
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
410
-
411
-           $fileSystemIterator = new FilesystemIterator($targetdir);
412
-
413
-           $dirfiles = [];
414
-           foreach ($fileSystemIterator as $fileInfo) {
415
-                    $dirfiles[] = $fileInfo->getFilename();
416
-           }
417
-
418
-           $totalflsizeinit = 0;
419
-
420
-           foreach ($dirfiles as $key => $indfile) {
421
-
422
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
423
-                    $mbSize = round($fileSizeinit / 1024, 4);
424
-                    $totalflsizeinit += $mbSize;
425
-           }
426
-
427
-           $totalflsize = round($totalflsizeinit, 4);
428
-
429
-           $pickresult = [$totalflsize, $pkfilesize];
430
-
431
-           return $pickresult;
432
-    }
433
-
434
-
435
-    /**
436
-     * @NoAdminRequired
437
-     */
438
-    public function removeupfile($removedfilename) {
439
-
440
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
441
-
442
-           $removefile = $this->view->unlink($tmpfl);
443
-
444
-           // Get the cumulative files size of the uploaded files
445
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
446
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
447
-           $fileSystemIterator = new FilesystemIterator($targetdir);
448
-
449
-           $dirfiles = [];
450
-           foreach ($fileSystemIterator as $fileInfo){
451
-                    $dirfiles[] = $fileInfo->getFilename();
452
-           }
453
-
454
-           $totalflsizeinit = 0;
455
-
456
-           foreach ($dirfiles as $key => $indfile) {
457
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
458
-                    $mbSize = round($fileSizeinit / 1024, 4);
459
-                    $totalflsizeinit += $mbSize;
460
-           }
461
-
462
-           $totalflsize = round($totalflsizeinit, 4);
463
-
464
-           return $totalflsize;
465
-    }
466
-
467
-
468
-    /**
469
-     * @NoAdminRequired
470
-     */
471
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
472
-
473
-         $telsmsapicred = $this->service->getapicredentials($this->userId, 'telnyx');
474
-         $telnyxkey = $telsmsapicred[0];
475
-         $teldelrecurl = $telsmsapicred[3];
476
-         $messagingprofid = $telsmsapicred[4];
477
-         $addDisplName = $telsmsapicred[24];
478
-
479
-         // Get the Display Name of the current user
480
-         $crtuser = $this->userManager->get($this->userId);
481
-         $displayname = $crtuser->getDisplayName();
482
-
483
-         if ($addDisplName == 1) {
484
-             $sentsmstext = $displayname . ": " . $sentsmstext;
485
-         }
486
-
487
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
488
-
489
-         $microinterval = $waitinterval * 1000;
490
-
491
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
492
-
493
-             usleep($microinterval);
494
-
495
-             $messagedate = date("Y-m-d H:i:s");
496
-
497
-             if ($ismms == 0) {
498
-
499
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
500
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
501
-                 } else {
502
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
503
-                 }
504
-
505
-                 $messagetexttel = $sentsmstext;
506
-
507
-             } else {
508
-
509
-                 $mediaURLarr = [];
510
-                 $includedMediaFiles = '';
511
-
512
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
513
-
514
-                      $userroot = $this->view->getRoot();
515
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
516
-
517
-                      $flsharetarget = $this->folder->newFile($filetoshare);
518
-
519
-	              $share = $this->shareManager->newShare();
520
-	              $share->setNode($flsharetarget);
521
-	              $share->setPermissions(Constants::PERMISSION_READ);
522
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
523
-	              $share->setSharedBy($this->userId);
524
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
525
-                      $expirydate->add(new \DateInterval('P1D'));
526
-                      $share->setExpirationDate($expirydate);
527
-                      $shared = $this->shareManager->createShare($share);
528
-                      $shareToken = $shared->getToken();
529
-
530
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
531
-
532
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
533
-
534
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
535
-                 }
536
-
537
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
538
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
539
-                 } else {
540
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
541
-                 }
542
-
543
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
544
-             }
545
-
546
-             if ($message) {
547
-                 if (isset($message['id'])) { $messageid = $message['id']; } else { $messageid = $this->createMessageId(); }
548
-             } else { $messageid = $this->createMessageId(); }
549
-
550
-             $messagefrom = "Telnyx: " . $fromsender;
551
-             $messageto = $tonumber;
552
-             $messagenetwork = null;
553
-             $messageprice = null;
554
-             $messagestatus = $message['to'][0]['status'];
555
-             $messagedelivery = null;
556
-
557
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
558
-
559
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
560
-         }
561
-         return $displayname;
562
-    }
563
-
564
-
565
-    /**
566
-     * @NoAdminRequired
567
-     */
568
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
569
-
570
-         $plsmsapicred = $this->service->getapicredentials($this->userId, 'plivo');
571
-
572
-         $smsapikey = $plsmsapicred[5];
573
-         $smsapisecret = $plsmsapicred[6];
574
-         $smsapideliveryrecurl = $plsmsapicred[8];
575
-         $addDisplName = $plsmsapicred[24];
576
-
577
-         // Get the Display Name of the current user
578
-         $crtuser = $this->userManager->get($this->userId);
579
-         $displayname = $crtuser->getDisplayName();
580
-
581
-         if ($addDisplName == 1) {
582
-             $sentsmstext = $displayname . ": " . $sentsmstext;
583
-         }
584
-
585
-         $microinterval = $waitinterval * 1000;
586
-
587
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
588
-
589
-             usleep($microinterval);
590
-
591
-             $messagedatepl = date("Y-m-d H:i:s");
592
-
593
-             if ($ismms == 0) {
594
-
595
-                 $client = new RestClient($smsapikey, $smsapisecret);
596
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
597
-                 $messagetextpl = $sentsmstext;
598
-	         $messageidinit = $response->getmessageUuid(0);
599
-                 $messageid = $messageidinit[0];
600
-
601
-                 if (property_exists($response, 'error')) { 
602
-                     $messagestatus = "Error: " . $response->error;
603
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
604
-
605
-             } else {
606
-
607
-                 $mediaURLarr = [];
608
-                 $includedMediaFiles = '';
609
-
610
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
611
-
612
-                      $userroot = $this->view->getRoot();
613
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
614
-
615
-                      $flsharetarget = $this->folder->newFile($filetoshare);
616
-
617
-	              $share = $this->shareManager->newShare();
618
-	              $share->setNode($flsharetarget);
619
-	              $share->setPermissions(Constants::PERMISSION_READ);
620
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
621
-	              $share->setSharedBy($this->userId);
622
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
623
-                      $expirydate->add(new \DateInterval('P1D'));
624
-                      $share->setExpirationDate($expirydate);
625
-                      $shared = $this->shareManager->createShare($share);
626
-                      $shareToken = $shared->getToken();
627
-
628
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
629
-
630
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
631
-
632
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
633
-                 }
634
-
635
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
636
-		 $postedparamspl = json_encode($datatosendpl);
637
-
638
-		 $chpl = curl_init();
639
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
640
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
641
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
642
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
643
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
644
-		 curl_setopt($chpl, CURLOPT_POST, 1);
645
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
646
-		 $resultpl = curl_exec ($chpl);
647
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
648
-		 curl_close ($chpl);
649
-
650
-		 $decresultpl = json_decode($resultpl);
651
-
652
-                 if ($decresultpl) {
653
-                     if (property_exists($decresultpl, 'message_uuid')) {
654
-                         $messageidinit = $decresultpl->message_uuid;
655
-                         $messageid = $messageidinit[0];
656
-                     } else { $messageid = $this->createMessageId(); }
657
-                 } else { $messageid = $this->createMessageId(); }
658
-
659
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
660
-
661
-                     if (property_exists($decresultpl, 'error')) {
662
-                         $messagestatus = "Error: " . $decresultpl->error;
663
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
664
-
665
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
666
-
667
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
668
-             }
669
-
670
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
671
-                 $messagefrom = "Plivo: " . $fromsender;
672
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
673
-
674
-             $messageto = $tonumber;
675
-             $messagenetwork = '';
676
-             $messageprice = '';
677
-
678
-             $messagedelivery = '';
679
-
680
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
681
-
682
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
683
-         }
684
-         return $displayname;
685
-    }
686
-
687
-
688
-    /**
689
-     * @NoAdminRequired
690
-     */
691
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
692
-
693
-         $twsmsapicred = $this->service->getapicredentials($this->userId, 'twilio');
694
-
695
-         $sid = $twsmsapicred[15];
696
-         $token = $twsmsapicred[16];
697
-         $smsapirecurltw = $twsmsapicred[18];
698
-         $addDisplName = $twsmsapicred[24];
699
-
700
-         // Get the Display Name of the current user
701
-         $crtuser = $this->userManager->get($this->userId);
702
-         $displayname = $crtuser->getDisplayName();
703
-
704
-         if ($addDisplName == 1) {
705
-             $sentsmstext = $displayname . ": " . $sentsmstext;
706
-         }
707
-
708
-         $microinterval = $waitinterval * 1000;
709
-
710
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
711
-
712
-             usleep($microinterval);
713
-
714
-             $messagedatetw = date("Y-m-d H:i:s");
715
-
716
-             if ($ismms == 0) {
717
-
718
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
719
-                 $sentsmstextfintw = $sentsmstext;
720
-
721
-             } else {
722
-
723
-                 $mediaURLs = [];
724
-                 $includedMediaFiles = '';
725
-
726
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
727
-
728
-                      $userroot = $this->view->getRoot();
729
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
730
-
731
-                      $flsharetarget = $this->folder->newFile($filetoshare);
732
-
733
-	              $share = $this->shareManager->newShare();
734
-	              $share->setNode($flsharetarget);
735
-	              $share->setPermissions(Constants::PERMISSION_READ);
736
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
737
-	              $share->setSharedBy($this->userId);
738
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
739
-                      $expirydate->add(new \DateInterval('P1D'));
740
-                      $share->setExpirationDate($expirydate);
741
-                      $shared = $this->shareManager->createShare($share);
742
-                      $shareToken = $shared->getToken();
743
-
744
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
745
-
746
-                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
747
-
748
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
749
-                 }
750
-
751
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
752
-
753
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
754
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
755
-                 }
756
-
757
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
758
-             }
759
-
760
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
761
-
762
-	     $chtw = curl_init();
763
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
764
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
765
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
766
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
767
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
768
-	     curl_setopt($chtw, CURLOPT_POST, 1);
769
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
770
-
771
-	     $resulttw = curl_exec ($chtw);
772
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
773
-	     curl_close ($chtw);
774
-
775
-             $decresulttw = json_decode($resulttw);
776
-
777
-             if ($decresulttw) {
778
-                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = $this->createMessageId(); }
779
-             } else { $messageidtw = $this->createMessageId(); }
780
-
781
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
782
-                 $messagestatustw = 'The message has been accepted for delivery.';
783
-             } else {
784
-                 $messagestatustw = 'An error occurred while trying to send the message.';
785
-             }
786
-
787
-             $messagefromtw = "Twilio: " . $fromsender;
788
-
789
-             $messagenetworktw = '';
790
-             $messagepricetw = '';
791
-             $messagedeliverytw = '';
792
-
793
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
794
-
795
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
796
-         }
797
-         return $displayname;
798
-    }
799
-
800
-
801
-    /**
802
-     * @NoAdminRequired
803
-     */
804
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
805
-
806
-         $flsmsapicred = $this->service->getapicredentials($this->userId, 'flowroute');
807
-
808
-         $flowapikey = $flsmsapicred[20];
809
-         $flowapisecret = $flsmsapicred[21];
810
-         $flowdelrecurl = $flsmsapicred[23];
811
-         $addDisplName = $flsmsapicred[24];
812
-
813
-         // Get the Display Name of the current user
814
-         $crtuser = $this->userManager->get($this->userId);
815
-         $displayname = $crtuser->getDisplayName();
816
-
817
-         if ($addDisplName == 1) {
818
-             $sentsmstext = $displayname . ": " . $sentsmstext;
819
-         }
820
-
821
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
822
-
823
-         $microinterval = $waitinterval * 1000;
824
-
825
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
826
-
827
-             usleep($microinterval);
828
-
829
-             $messagedatefl = date("Y-m-d H:i:s");
830
-
831
-             if ($ismms == 0) {
832
-
833
-                 $messagetextfinfl = $sentsmstext;
834
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
835
-
836
-             } else {
837
-
838
-		 $mediaurlsarr = [];
839
-		 $includedMediaFiles = '';
840
-
841
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
842
-
843
-		      $userroot = $this->view->getRoot();
844
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
845
-
846
-		      $flsharetarget = $this->folder->newFile($filetoshare);
847
-
848
-		      $share = $this->shareManager->newShare();
849
-		      $share->setNode($flsharetarget);
850
-		      $share->setPermissions(Constants::PERMISSION_READ);
851
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
852
-		      $share->setSharedBy($this->userId);
853
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
854
-                      $expirydate->add(new \DateInterval('P1D'));
855
-                      $share->setExpirationDate($expirydate);
856
-		      $shared = $this->shareManager->createShare($share);
857
-		      $shareToken = $shared->getToken();
858
-
859
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
860
-
861
-		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
862
-
863
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
864
-		 }
865
-
866
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
867
-
868
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
869
-             }
870
-
871
-	     $chfl = curl_init();
872
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
873
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
874
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
875
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
876
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
877
-	     curl_setopt($chfl, CURLOPT_POST, 1);
878
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
879
-	     $resultfl = curl_exec ($chfl);
880
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
881
-	     curl_close ($chfl);
882
-
883
-             $decresultfl = json_decode($resultfl);
884
-
885
-             if ($decresultfl) {
886
-                 if (property_exists($decresultfl, 'data')) { 
887
-                     $messageidfl = $decresultfl->data->id;
888
-                 } else { $messageidfl = $this->createMessageId(); }
889
-             } else { $messageidfl = $this->createMessageId(); }
890
-
891
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
892
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
893
-             } else { 
894
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
895
-             }
896
-
897
-             $messagefromfl = "Flowroute: " . $fromsender;
898
-             $messagetofl = $tonumberfl;
899
-             $messagenetworkfl = '';
900
-             $messagepricefl = '';
901
-             $messagedeliveryfl = '';
902
-
903
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
904
-
905
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
906
-         }
907
-         return $displayname;
908
-    }
909
-
910
-
911
-    /**
912
-     * @NoAdminRequired
913
-     */
914
-    public function saveoldrecrows($userId, $oldrecRows) {
915
-
916
-           // Create the folder for removed messages if it doesn't exist
917
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
918
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
919
-           }
920
-           $savecheck = 0;
921
-
922
-           if (count($oldrecRows) > 1) {
923
-               $msfileContent = implode("", $oldrecRows);
924
-
925
-               $delrowsdate = date("Y-m-d_H-i-s");
926
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
927
-
928
-               $userroot = $this->view->getRoot();
929
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
930
-
931
-               $target = $this->folder->newFile($targetfile);
932
-               $target->putContent($msfileContent);
933
-
934
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
935
-                   $savecheck = 1;
936
-               }
937
-           }
938
-
939
-           return $savecheck;
940
-    }
941
-
942
-
943
-    /**
944
-     * @NoAdminRequired
945
-     */
946
-    public function saveoldsentrows($userId, $oldsentRows) {
947
-
948
-           // Create the folder for removed messages if it doesn't exist
949
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
950
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
951
-           }
952
-           $savesentcheck = 0;
953
-
954
-           if (count($oldsentRows) > 1) {
955
-               $sntfileContent = implode("", $oldsentRows);
956
-
957
-               $delsentrowsdate = date("Y-m-d_H-i-s");
958
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
959
-
960
-               $userroot = $this->view->getRoot();
961
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
962
-
963
-               $snttarget = $this->folder->newFile($snttargetfile);
964
-               $snttarget->putContent($sntfileContent);
965
-
966
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
967
-                   $savesentcheck = 1;
968
-               }
969
-           }
970
-
971
-           return $savesentcheck;
972
-    }
973
-
974
-
975
-    /**
976
-     * @NoAdminRequired
977
-     */
978
-    public function getreceivedtable($userId) {
979
-           return $this->service->getreceivedtable($this->userId);
980
-    }
981
-
982
-    /**
983
-     * @NoAdminRequired
984
-     */
985
-    public function getreceivedtablefordel($userId) {
986
-           return $this->service->getreceivedtablefordel($this->userId);
987
-    }
988
-
989
-    /**
990
-     * @NoAdminRequired
991
-     */
992
-    public function removerecrows($userId, $recmessagedbIDs) {
993
-
994
-           // Get the Display Name of the current user
995
-           $crtuserdel = $this->userManager->get($this->userId);
996
-           $userDelDspName = $crtuserdel->getDisplayName();
997
-
998
-           return $this->service->removerecrows($this->userId, $userDelDspName, $recmessagedbIDs);
999
-    }
1000
-
1001
-    /**
1002
-     * @NoAdminRequired
1003
-     */
1004
-    public function getsenttable($userId) {
1005
-           return $this->service->getsenttable($this->userId);
1006
-    }
1007
-
1008
-    /**
1009
-     * @NoAdminRequired
1010
-     */
1011
-    public function getsenttablefordel($userId) {
1012
-           return $this->service->getsenttablefordel($this->userId);
1013
-    }
1014
-
1015
-    /**
1016
-     * @NoAdminRequired
1017
-     */
1018
-    public function removesentrows($userId, $sentmessagedbIDs) {
1019
-
1020
-           // Get the Display Name of the current user
1021
-           $crtuserstdel = $this->userManager->get($this->userId);
1022
-           $userstDelDspName = $crtuserstdel->getDisplayName();
1023
-
1024
-           return $this->service->removesentrows($this->userId, $userstDelDspName, $sentmessagedbIDs);
1025
-    }
1026
-
1027
-    /**
1028
-     * @NoAdminRequired
1029
-     */
1030
-    public function getconversations($userId) {
1031
-           return $this->service->getconversations($this->userId);
1032
-    }
1033
-
1034
-    /**
1035
-     * @NoAdminRequired
1036
-     */
1037
-    public function archiveconv($userId, $conversationId) {
1038
-
1039
-           // Get the Display Name of the current user
1040
-           $crtusergt = $this->userManager->get($this->userId);
1041
-           $userDspNameArch = $crtusergt->getDisplayName();
1042
-
1043
-           return $this->service->archiveconv($this->userId, $userDspNameArch, $conversationId);
1044
-    }
1045
-
1046
-    /**
1047
-     * @NoAdminRequired
1048
-     */
1049
-    public function unarchiveconv($userId, $conversationId) {
1050
-
1051
-           // Get the Display Name of the current user
1052
-           $crtusergtun = $this->userManager->get($this->userId);
1053
-           $userDspNameUnarch = $crtusergtun->getDisplayName();
1054
-
1055
-           return $this->service->unarchiveconv($this->userId, $userDspNameUnarch, $conversationId);
1056
-    }
1057
-
1058
-    /**
1059
-     * @NoAdminRequired
1060
-     */
1061
-    public function saveconvdescription($userId, $convDescription, $convId) {
1062
-
1063
-           // Get the Display Name of the current user
1064
-           $crtuserdesc = $this->userManager->get($this->userId);
1065
-           $userDspNameDesc = $crtuserdesc->getDisplayName();
1066
-
1067
-           return $this->service->saveconvdescription($this->userId, $userDspNameDesc, $convDescription, $convId);
1068
-    }
1069
-
1070
-    /**
1071
-     * @NoAdminRequired
1072
-     */
1073
-    public function saveconvtag($userId, $convTag, $convId) {
1074
-
1075
-           // Get the Display Name of the current user
1076
-           $crtusertag = $this->userManager->get($this->userId);
1077
-           $userDspNameTag = $crtusertag->getDisplayName();
1078
-
1079
-           return $this->service->saveconvtag($this->userId, $userDspNameTag, $convTag, $convId);
1080
-    }
1081
-
1082
-    /**
1083
-     * @NoAdminRequired
1084
-     */
1085
-    public function saveconvflag($userId, $convFlag, $convId) {
1086
-
1087
-           // Get the Display Name of the current user
1088
-           $crtuserflag = $this->userManager->get($this->userId);
1089
-           $userDspNameFlag = $crtuserflag->getDisplayName();
1090
-
1091
-           return $this->service->saveconvflag($this->userId, $userDspNameFlag, $convFlag, $convId);
1092
-    }
1093
-
1094
-    /**
1095
-     * @NoAdminRequired
1096
-     */
1097
-    public function removeconvmsgs($userId, $conversationId) {
1098
-           return $this->service->removeconvmsgs($this->userId, $conversationId);
1099
-    }
1100
-
1101
-    /**
1102
-     * @NoAdminRequired
1103
-     */
1104
-    public function getgroupedtable($userId) {
1105
-           return $this->service->getgroupedtable($this->userId);
1106
-    }
1107
-
1108
-    /**
1109
-     * @NoAdminRequired
1110
-     */
1111
-    public function savedisplayname($userId, $authorDisplayname, $from) {
1112
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1113
-    }
1114
-
1115
-    /**
1116
-     * @NoAdminRequired
1117
-     */
1118
-    public function getmsgsperpgnewmsgarchnb($userId) {
1119
-           return $this->service->getmsgsperpgnewmsgarchnb($this->userId);
1120
-    }
1121
-
1122
-    /**
1123
-     * @NoAdminRequired
1124
-     */
1125
-    public function getnewmsgindicator($userId) {
1126
-           return $this->service->getnewmsgindicator($this->userId);
1127
-    }
1128
-
1129
-    /**
1130
-     * @NoAdminRequired
1131
-     */
1132
-    public function getdelrecsettings($userId) {
1133
-           return $this->service->getdelrecsettings($this->userId);
1134
-    }
1135
-
1136
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1137
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1138
-    }
1139
-
1140
-    public function updatekeysallowedusers($userId, $groups, $users, $groupsdel, $usersdel, $provider) {
1141
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $groupsdel, $usersdel, $provider);
1142
-    }
1143
-
1144
-    public function removenumberrestrictions($userId, $phoneNumber) {
1145
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1146
-    }
1147
-
1148
-    /**
1149
-     * @NoAdminRequired
1150
-     */
1151
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1152
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1153
-    }
1154
-
1155
-    /**
1156
-     * @NoAdminRequired
1157
-     */
1158
-    public function removeautoreplies($userId, $phoneNumber) {
1159
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1160
-    }
1161
-
1162
-    /**
1163
-     * @NoAdminRequired
1164
-     */
1165
-    public function getsettings($userId) {
1166
-           return $this->service->getsettings($this->userId);
1167
-    }
1168
-
1169
-    public function getadminsettings($userId) {
1170
-           return $this->service->getadminsettings($this->userId);
1171
-    }
1172
-
1173
-    /**
1174
-     * @NoAdminRequired
1175
-     */
1176
-    public function getautoreplyconf($userId) {
1177
-
1178
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1179
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1180
-
1181
-           // Get the display name of the current user
1182
-           $usrid = $this->userId;
1183
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1184
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1185
-	   $getusrdnmdata = $getusrdnmres->fetch();
1186
-	   $userDisplayNm = $getusrdnmdata['value'];
1187
-	   $getusrdnmres->closeCursor();
1188
-
1189
-           // Get the auto-replies for the available phone numbers
1190
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1191
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1192
-	   $getautorplres = $getautorpl->execute();
1193
-           $autorplconf = [];
1194
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1195
-                  $autorplconf[] = $acdatausrdnadm;
1196
-           }
1197
-	   $getautorplres->closeCursor();
1198
-
1199
-           if ($autorplconf) {
1200
-
1201
-               $autoreplyconf = [];
1202
-               foreach ($autorplconf as $arkey => $arvalue) {
1203
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1204
-                            $autoreplyconf[] = $arvalue;
1205
-                        }
1206
-               }
1207
-
1208
-           } else { $autoreplyconf = ''; }
1209
-
1210
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1211
-
1212
-           return $autoreplyfdb;
1213
-    }
1214
-
1215
-    /**
1216
-     * @NoAdminRequired
1217
-     */
1218
-    public function getgroupedpernumber($userId, $phoneNumber) {
1219
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1220
-    }
1221
-
1222
-    /**
1223
-     * @NoAdminRequired
1224
-     */
1225
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1226
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1227
-    }
1228
-
1229
-    /**
1230
-     * @NoAdminRequired
1231
-     */
1232
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1233
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1234
-    }
1235
-
1236
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1237
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1238
-    }
1239
-
1240
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1241
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1242
-    }
1243
-}
Browse code

added appinfo/info.xml appinfo/signature.json CHANGELOG.txt css/style.css js/settings.js js/adminsettings.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/settings/personal.php templates/settings/admin.php lib/Migration/Version135Date20240420221527.php lib/Migration/Version136Date20240502081941.php

DoubleBastionAdmin authored on 02/05/2024 04:12:37
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1243 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\Share\IManager;
49
+use OCP\Constants;
50
+use OCP\IGroupManager;
51
+use OCP\IDBConnection;
52
+use OCP\IUserManager;
53
+use OC\URLGenerator;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $shareManager;
64
+    private $groupManager;
65
+    private $connection;
66
+    private $userManager;
67
+    private $urlGenerator;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->shareManager = $shareManager;
78
+        $this->groupManager = $groupManager;
79
+        $this->connection = $connection;
80
+        $this->userManager = $userManager;
81
+        $this->urlGenerator = $urlGenerator;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getappdirectory($userId) {
120
+        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
+        $apprelpatharr = explode("/", $apprelpath);
122
+        $currentappdir = $apprelpatharr[1];
123
+        return $currentappdir;
124
+    }
125
+
126
+
127
+    /**
128
+     * @NoAdminRequired
129
+     */
130
+    public function createMessageId() {
131
+             // Create a random string to use as message id for messages that don't have it
132
+	     $keypassin = substr(sha1((string) mt_rand()), 0, 32);
133
+	     $keysaltin = openssl_random_pseudo_bytes(24);
134
+	     $keyLengthin = 32;
135
+	     $iterationin = 50;
136
+	     $generated_keyin = openssl_pbkdf2($keypassin, $keysaltin, $keyLengthin, $iterationin, 'sha256');
137
+	     $ctdMessageId = "generated-id-" . bin2hex($generated_keyin);
138
+             return $ctdMessageId;
139
+    }
140
+
141
+
142
+    /**
143
+     * @NoAdminRequired
144
+     */
145
+    public function getbalancetel($userId) {
146
+
147
+        $telsmsapicred = $this->service->getapicredentials($this->userId, 'telnyx');
148
+
149
+        $telapikey = $telsmsapicred[0];
150
+        $ch = curl_init();
151
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
152
+
153
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
154
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
155
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
156
+        $responsetel = curl_exec($ch);
157
+        $recdatatel = json_decode($responsetel, TRUE);
158
+        $telbalresponse = $recdatatel['data']['balance'];
159
+        $currentbalancetel = round(floatval($telbalresponse), 3);
160
+        curl_close($ch);
161
+
162
+        return $currentbalancetel;
163
+    }
164
+
165
+
166
+    /**
167
+     * @NoAdminRequired
168
+     */
169
+    public function getbalancenex($userId) {
170
+
171
+        $smsapicred = $this->service->getapicredentials($this->userId, 'plivo');
172
+        $smsapikey = $smsapicred[5];
173
+        $smsapisecret = $smsapicred[6];
174
+
175
+        if ($smsapikey == '' || $smsapisecret == '') {
176
+            $currentbalancenex = "N/A";
177
+        } else {
178
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
179
+            $mesdata = file_get_contents($getmesdata);
180
+            $datainit = json_decode($mesdata);
181
+            $balancenex = $datainit->cash_credits;
182
+            $currentbalancenex = round(floatval($balancenex), 3);
183
+        }
184
+        return $currentbalancenex;
185
+    }
186
+
187
+
188
+    /**
189
+     * @NoAdminRequired
190
+     */
191
+    public function getbalancetwil($userId) {
192
+
193
+        $smsapicred = $this->service->getapicredentials($this->userId, 'twilio');
194
+        $smsapisid = $smsapicred[15];
195
+        $smsapitoken = $smsapicred[16];
196
+
197
+        if ($smsapisid == '' || $smsapitoken == '') {
198
+            $currentbalancetwil = "N/A";
199
+        } else {
200
+
201
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
202
+            $balancetwil = $twilbalance->balance;
203
+
204
+            $currentbalancetwil = round(floatval($balancetwil), 3);
205
+        }
206
+        return $currentbalancetwil;
207
+    }
208
+
209
+
210
+    /**
211
+     * @NoAdminRequired
212
+     */
213
+    public function getbalanceflow($userId) {
214
+
215
+        $currentbalanceflow = 'n/a';
216
+        return $currentbalanceflow;
217
+    }
218
+
219
+
220
+    /**
221
+     * @NoAdminRequired
222
+     */
223
+    public function getsmsnumbers($userId) {
224
+
225
+        return $this->service->getsmsnumbers($this->userId);
226
+    }
227
+
228
+
229
+    /**
230
+     * @NoAdminRequired
231
+     */
232
+    public function refreshavailablenumbers($userId) {
233
+
234
+        return $this->service->refreshavailablenumbers($this->userId);
235
+    }
236
+
237
+
238
+    /**
239
+     * @NoAdminRequired
240
+     */
241
+    public function cleantempdir($userId) {
242
+
243
+        // Create the temporary folder if it doesn't exist
244
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
245
+            $this->folder->newFolder('SMS_Relentless/temp_files');
246
+        }
247
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
248
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
249
+        $fileSystemIterator = new FilesystemIterator($targetdir);
250
+
251
+        $dirfiles = [];
252
+        foreach ($fileSystemIterator as $fileInfo) {
253
+                 $dirfiles[] = $fileInfo->getFilename();
254
+        }
255
+
256
+        foreach ($dirfiles as $key => $indfile) {
257
+                 $thisuserroot = $this->view->getRoot();
258
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
259
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
260
+        }
261
+     }
262
+
263
+
264
+    /**
265
+     * @NoAdminRequired
266
+     */
267
+    public function cleanmultrecdir($userId) {
268
+
269
+        // Create the temporary folder if it doesn't exist
270
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
271
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
272
+        }
273
+        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
274
+        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
275
+        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
276
+
277
+        $dirfilesmrc = [];
278
+        foreach ($fileSystemIteratormrc as $fileInfomrc){
279
+                 $dirfilesmrc[] = $fileInfomrc->getFilename();
280
+        }
281
+
282
+        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
283
+                 $thisuserrootmrc = $this->view->getRoot();
284
+                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
285
+                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
286
+        }
287
+     }
288
+
289
+
290
+    /**
291
+     * @NoAdminRequired
292
+     */
293
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
294
+
295
+        // Create the temporary folder if it doesn't exist
296
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
297
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
298
+        }
299
+
300
+        // First delete any file that has been previously uploaded
301
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
302
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
303
+        $fileSystemIterator = new FilesystemIterator($targetdir);
304
+
305
+        $dirfiles = [];
306
+        foreach ($fileSystemIterator as $fileInfo){
307
+                 $dirfiles[] = $fileInfo->getFilename();
308
+        }
309
+
310
+        foreach ($dirfiles as $key => $indfile) {
311
+                 $thisuserroot = $this->view->getRoot();
312
+                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
313
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
314
+        }
315
+
316
+        // Upload the new file
317
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
318
+        $fileName = $_FILES['uploadfileforsms']['name'];
319
+
320
+        $userroot = $this->view->getRoot();
321
+        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
322
+
323
+        $target = $this->folder->newFile($targetfile);
324
+        $target->putContent($fileContent);
325
+
326
+        // Extract the phone numbers from the file
327
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
328
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
329
+        $numberarrayfourth = explode(",", $numberarraytert);
330
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
331
+        $numberarray = array_unique($numberarrayfifth);
332
+
333
+        return $numberarray;
334
+    }
335
+
336
+
337
+    /**
338
+     * @NoAdminRequired
339
+     */
340
+    public function uploadfile($uploadfileformms) {
341
+
342
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
343
+           $fileName = $_FILES['uploadfileformms']['name'];
344
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
345
+           $fileSize = $fileSizeinit / 1024;
346
+
347
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
348
+               $this->folder->newFolder('SMS_Relentless/temp_files');
349
+           }
350
+
351
+           $userroot = $this->view->getRoot();
352
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
353
+
354
+           $target = $this->folder->newFile($targetfile);
355
+           $target->putContent($fileContent);
356
+
357
+           // Get the cumulative files size of the uploaded files
358
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
359
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
360
+
361
+           $fileSystemIterator = new FilesystemIterator($targetdir);
362
+
363
+           $dirfiles = [];
364
+           foreach ($fileSystemIterator as $fileInfo){
365
+                    $dirfiles[] = $fileInfo->getFilename();
366
+           }
367
+
368
+           $totalflsizeinit = 0;
369
+           foreach ($dirfiles as $key => $indfile) {
370
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
371
+                    $mbSize = round($fileSizeinit / 1024, 4);
372
+                    $totalflsizeinit += $mbSize;
373
+           }
374
+
375
+           $totalflsize = round($totalflsizeinit, 4);
376
+
377
+           return $totalflsize;
378
+    }
379
+
380
+
381
+    /**
382
+     * @NoAdminRequired
383
+     */
384
+    public function pickfile($path) {
385
+
386
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
387
+               $this->folder->newFolder('SMS_Relentless/temp_files');
388
+           }
389
+
390
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
391
+
392
+           $fltgt = $datadir . $this->userId . "/files" . $path;
393
+
394
+           $fileContent = file_get_contents($fltgt);
395
+
396
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
397
+
398
+           $patharr = explode("/", $path);
399
+
400
+           $revarr = array_reverse($patharr);
401
+
402
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
403
+
404
+           $target = $this->folder->newFile($relflpath);
405
+
406
+           $target->putContent($fileContent);
407
+
408
+           // Get the cumulative files size of the uploaded files
409
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
410
+
411
+           $fileSystemIterator = new FilesystemIterator($targetdir);
412
+
413
+           $dirfiles = [];
414
+           foreach ($fileSystemIterator as $fileInfo) {
415
+                    $dirfiles[] = $fileInfo->getFilename();
416
+           }
417
+
418
+           $totalflsizeinit = 0;
419
+
420
+           foreach ($dirfiles as $key => $indfile) {
421
+
422
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
423
+                    $mbSize = round($fileSizeinit / 1024, 4);
424
+                    $totalflsizeinit += $mbSize;
425
+           }
426
+
427
+           $totalflsize = round($totalflsizeinit, 4);
428
+
429
+           $pickresult = [$totalflsize, $pkfilesize];
430
+
431
+           return $pickresult;
432
+    }
433
+
434
+
435
+    /**
436
+     * @NoAdminRequired
437
+     */
438
+    public function removeupfile($removedfilename) {
439
+
440
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
441
+
442
+           $removefile = $this->view->unlink($tmpfl);
443
+
444
+           // Get the cumulative files size of the uploaded files
445
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
446
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
447
+           $fileSystemIterator = new FilesystemIterator($targetdir);
448
+
449
+           $dirfiles = [];
450
+           foreach ($fileSystemIterator as $fileInfo){
451
+                    $dirfiles[] = $fileInfo->getFilename();
452
+           }
453
+
454
+           $totalflsizeinit = 0;
455
+
456
+           foreach ($dirfiles as $key => $indfile) {
457
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
458
+                    $mbSize = round($fileSizeinit / 1024, 4);
459
+                    $totalflsizeinit += $mbSize;
460
+           }
461
+
462
+           $totalflsize = round($totalflsizeinit, 4);
463
+
464
+           return $totalflsize;
465
+    }
466
+
467
+
468
+    /**
469
+     * @NoAdminRequired
470
+     */
471
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
472
+
473
+         $telsmsapicred = $this->service->getapicredentials($this->userId, 'telnyx');
474
+         $telnyxkey = $telsmsapicred[0];
475
+         $teldelrecurl = $telsmsapicred[3];
476
+         $messagingprofid = $telsmsapicred[4];
477
+         $addDisplName = $telsmsapicred[24];
478
+
479
+         // Get the Display Name of the current user
480
+         $crtuser = $this->userManager->get($this->userId);
481
+         $displayname = $crtuser->getDisplayName();
482
+
483
+         if ($addDisplName == 1) {
484
+             $sentsmstext = $displayname . ": " . $sentsmstext;
485
+         }
486
+
487
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
488
+
489
+         $microinterval = $waitinterval * 1000;
490
+
491
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
492
+
493
+             usleep($microinterval);
494
+
495
+             $messagedate = date("Y-m-d H:i:s");
496
+
497
+             if ($ismms == 0) {
498
+
499
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
500
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
501
+                 } else {
502
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
503
+                 }
504
+
505
+                 $messagetexttel = $sentsmstext;
506
+
507
+             } else {
508
+
509
+                 $mediaURLarr = [];
510
+                 $includedMediaFiles = '';
511
+
512
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
513
+
514
+                      $userroot = $this->view->getRoot();
515
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
516
+
517
+                      $flsharetarget = $this->folder->newFile($filetoshare);
518
+
519
+	              $share = $this->shareManager->newShare();
520
+	              $share->setNode($flsharetarget);
521
+	              $share->setPermissions(Constants::PERMISSION_READ);
522
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
523
+	              $share->setSharedBy($this->userId);
524
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
525
+                      $expirydate->add(new \DateInterval('P1D'));
526
+                      $share->setExpirationDate($expirydate);
527
+                      $shared = $this->shareManager->createShare($share);
528
+                      $shareToken = $shared->getToken();
529
+
530
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
531
+
532
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
533
+
534
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
535
+                 }
536
+
537
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
538
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
539
+                 } else {
540
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
541
+                 }
542
+
543
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
544
+             }
545
+
546
+             if ($message) {
547
+                 if (isset($message['id'])) { $messageid = $message['id']; } else { $messageid = $this->createMessageId(); }
548
+             } else { $messageid = $this->createMessageId(); }
549
+
550
+             $messagefrom = "Telnyx: " . $fromsender;
551
+             $messageto = $tonumber;
552
+             $messagenetwork = null;
553
+             $messageprice = null;
554
+             $messagestatus = $message['to'][0]['status'];
555
+             $messagedelivery = null;
556
+
557
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
558
+
559
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
560
+         }
561
+         return $displayname;
562
+    }
563
+
564
+
565
+    /**
566
+     * @NoAdminRequired
567
+     */
568
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
569
+
570
+         $plsmsapicred = $this->service->getapicredentials($this->userId, 'plivo');
571
+
572
+         $smsapikey = $plsmsapicred[5];
573
+         $smsapisecret = $plsmsapicred[6];
574
+         $smsapideliveryrecurl = $plsmsapicred[8];
575
+         $addDisplName = $plsmsapicred[24];
576
+
577
+         // Get the Display Name of the current user
578
+         $crtuser = $this->userManager->get($this->userId);
579
+         $displayname = $crtuser->getDisplayName();
580
+
581
+         if ($addDisplName == 1) {
582
+             $sentsmstext = $displayname . ": " . $sentsmstext;
583
+         }
584
+
585
+         $microinterval = $waitinterval * 1000;
586
+
587
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
588
+
589
+             usleep($microinterval);
590
+
591
+             $messagedatepl = date("Y-m-d H:i:s");
592
+
593
+             if ($ismms == 0) {
594
+
595
+                 $client = new RestClient($smsapikey, $smsapisecret);
596
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
597
+                 $messagetextpl = $sentsmstext;
598
+	         $messageidinit = $response->getmessageUuid(0);
599
+                 $messageid = $messageidinit[0];
600
+
601
+                 if (property_exists($response, 'error')) { 
602
+                     $messagestatus = "Error: " . $response->error;
603
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
604
+
605
+             } else {
606
+
607
+                 $mediaURLarr = [];
608
+                 $includedMediaFiles = '';
609
+
610
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
611
+
612
+                      $userroot = $this->view->getRoot();
613
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
614
+
615
+                      $flsharetarget = $this->folder->newFile($filetoshare);
616
+
617
+	              $share = $this->shareManager->newShare();
618
+	              $share->setNode($flsharetarget);
619
+	              $share->setPermissions(Constants::PERMISSION_READ);
620
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
621
+	              $share->setSharedBy($this->userId);
622
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
623
+                      $expirydate->add(new \DateInterval('P1D'));
624
+                      $share->setExpirationDate($expirydate);
625
+                      $shared = $this->shareManager->createShare($share);
626
+                      $shareToken = $shared->getToken();
627
+
628
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
629
+
630
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
631
+
632
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
633
+                 }
634
+
635
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
636
+		 $postedparamspl = json_encode($datatosendpl);
637
+
638
+		 $chpl = curl_init();
639
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
640
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
641
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
642
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
643
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
644
+		 curl_setopt($chpl, CURLOPT_POST, 1);
645
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
646
+		 $resultpl = curl_exec ($chpl);
647
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
648
+		 curl_close ($chpl);
649
+
650
+		 $decresultpl = json_decode($resultpl);
651
+
652
+                 if ($decresultpl) {
653
+                     if (property_exists($decresultpl, 'message_uuid')) {
654
+                         $messageidinit = $decresultpl->message_uuid;
655
+                         $messageid = $messageidinit[0];
656
+                     } else { $messageid = $this->createMessageId(); }
657
+                 } else { $messageid = $this->createMessageId(); }
658
+
659
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
660
+
661
+                     if (property_exists($decresultpl, 'error')) {
662
+                         $messagestatus = "Error: " . $decresultpl->error;
663
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
664
+
665
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
666
+
667
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
668
+             }
669
+
670
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
671
+                 $messagefrom = "Plivo: " . $fromsender;
672
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
673
+
674
+             $messageto = $tonumber;
675
+             $messagenetwork = '';
676
+             $messageprice = '';
677
+
678
+             $messagedelivery = '';
679
+
680
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
681
+
682
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
683
+         }
684
+         return $displayname;
685
+    }
686
+
687
+
688
+    /**
689
+     * @NoAdminRequired
690
+     */
691
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
692
+
693
+         $twsmsapicred = $this->service->getapicredentials($this->userId, 'twilio');
694
+
695
+         $sid = $twsmsapicred[15];
696
+         $token = $twsmsapicred[16];
697
+         $smsapirecurltw = $twsmsapicred[18];
698
+         $addDisplName = $twsmsapicred[24];
699
+
700
+         // Get the Display Name of the current user
701
+         $crtuser = $this->userManager->get($this->userId);
702
+         $displayname = $crtuser->getDisplayName();
703
+
704
+         if ($addDisplName == 1) {
705
+             $sentsmstext = $displayname . ": " . $sentsmstext;
706
+         }
707
+
708
+         $microinterval = $waitinterval * 1000;
709
+
710
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
711
+
712
+             usleep($microinterval);
713
+
714
+             $messagedatetw = date("Y-m-d H:i:s");
715
+
716
+             if ($ismms == 0) {
717
+
718
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
719
+                 $sentsmstextfintw = $sentsmstext;
720
+
721
+             } else {
722
+
723
+                 $mediaURLs = [];
724
+                 $includedMediaFiles = '';
725
+
726
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
727
+
728
+                      $userroot = $this->view->getRoot();
729
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
730
+
731
+                      $flsharetarget = $this->folder->newFile($filetoshare);
732
+
733
+	              $share = $this->shareManager->newShare();
734
+	              $share->setNode($flsharetarget);
735
+	              $share->setPermissions(Constants::PERMISSION_READ);
736
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
737
+	              $share->setSharedBy($this->userId);
738
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
739
+                      $expirydate->add(new \DateInterval('P1D'));
740
+                      $share->setExpirationDate($expirydate);
741
+                      $shared = $this->shareManager->createShare($share);
742
+                      $shareToken = $shared->getToken();
743
+
744
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
745
+
746
+                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
747
+
748
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
749
+                 }
750
+
751
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
752
+
753
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
754
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
755
+                 }
756
+
757
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
758
+             }
759
+
760
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
761
+
762
+	     $chtw = curl_init();
763
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
764
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
765
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
766
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
767
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
768
+	     curl_setopt($chtw, CURLOPT_POST, 1);
769
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
770
+
771
+	     $resulttw = curl_exec ($chtw);
772
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
773
+	     curl_close ($chtw);
774
+
775
+             $decresulttw = json_decode($resulttw);
776
+
777
+             if ($decresulttw) {
778
+                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = $this->createMessageId(); }
779
+             } else { $messageidtw = $this->createMessageId(); }
780
+
781
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
782
+                 $messagestatustw = 'The message has been accepted for delivery.';
783
+             } else {
784
+                 $messagestatustw = 'An error occurred while trying to send the message.';
785
+             }
786
+
787
+             $messagefromtw = "Twilio: " . $fromsender;
788
+
789
+             $messagenetworktw = '';
790
+             $messagepricetw = '';
791
+             $messagedeliverytw = '';
792
+
793
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
794
+
795
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
796
+         }
797
+         return $displayname;
798
+    }
799
+
800
+
801
+    /**
802
+     * @NoAdminRequired
803
+     */
804
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
805
+
806
+         $flsmsapicred = $this->service->getapicredentials($this->userId, 'flowroute');
807
+
808
+         $flowapikey = $flsmsapicred[20];
809
+         $flowapisecret = $flsmsapicred[21];
810
+         $flowdelrecurl = $flsmsapicred[23];
811
+         $addDisplName = $flsmsapicred[24];
812
+
813
+         // Get the Display Name of the current user
814
+         $crtuser = $this->userManager->get($this->userId);
815
+         $displayname = $crtuser->getDisplayName();
816
+
817
+         if ($addDisplName == 1) {
818
+             $sentsmstext = $displayname . ": " . $sentsmstext;
819
+         }
820
+
821
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
822
+
823
+         $microinterval = $waitinterval * 1000;
824
+
825
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
826
+
827
+             usleep($microinterval);
828
+
829
+             $messagedatefl = date("Y-m-d H:i:s");
830
+
831
+             if ($ismms == 0) {
832
+
833
+                 $messagetextfinfl = $sentsmstext;
834
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
835
+
836
+             } else {
837
+
838
+		 $mediaurlsarr = [];
839
+		 $includedMediaFiles = '';
840
+
841
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
842
+
843
+		      $userroot = $this->view->getRoot();
844
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
845
+
846
+		      $flsharetarget = $this->folder->newFile($filetoshare);
847
+
848
+		      $share = $this->shareManager->newShare();
849
+		      $share->setNode($flsharetarget);
850
+		      $share->setPermissions(Constants::PERMISSION_READ);
851
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
852
+		      $share->setSharedBy($this->userId);
853
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
854
+                      $expirydate->add(new \DateInterval('P1D'));
855
+                      $share->setExpirationDate($expirydate);
856
+		      $shared = $this->shareManager->createShare($share);
857
+		      $shareToken = $shared->getToken();
858
+
859
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
860
+
861
+		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
862
+
863
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
864
+		 }
865
+
866
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
867
+
868
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
869
+             }
870
+
871
+	     $chfl = curl_init();
872
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
873
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
874
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
875
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
876
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
877
+	     curl_setopt($chfl, CURLOPT_POST, 1);
878
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
879
+	     $resultfl = curl_exec ($chfl);
880
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
881
+	     curl_close ($chfl);
882
+
883
+             $decresultfl = json_decode($resultfl);
884
+
885
+             if ($decresultfl) {
886
+                 if (property_exists($decresultfl, 'data')) { 
887
+                     $messageidfl = $decresultfl->data->id;
888
+                 } else { $messageidfl = $this->createMessageId(); }
889
+             } else { $messageidfl = $this->createMessageId(); }
890
+
891
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
892
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
893
+             } else { 
894
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
895
+             }
896
+
897
+             $messagefromfl = "Flowroute: " . $fromsender;
898
+             $messagetofl = $tonumberfl;
899
+             $messagenetworkfl = '';
900
+             $messagepricefl = '';
901
+             $messagedeliveryfl = '';
902
+
903
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
904
+
905
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
906
+         }
907
+         return $displayname;
908
+    }
909
+
910
+
911
+    /**
912
+     * @NoAdminRequired
913
+     */
914
+    public function saveoldrecrows($userId, $oldrecRows) {
915
+
916
+           // Create the folder for removed messages if it doesn't exist
917
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
918
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
919
+           }
920
+           $savecheck = 0;
921
+
922
+           if (count($oldrecRows) > 1) {
923
+               $msfileContent = implode("", $oldrecRows);
924
+
925
+               $delrowsdate = date("Y-m-d_H-i-s");
926
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
927
+
928
+               $userroot = $this->view->getRoot();
929
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
930
+
931
+               $target = $this->folder->newFile($targetfile);
932
+               $target->putContent($msfileContent);
933
+
934
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
935
+                   $savecheck = 1;
936
+               }
937
+           }
938
+
939
+           return $savecheck;
940
+    }
941
+
942
+
943
+    /**
944
+     * @NoAdminRequired
945
+     */
946
+    public function saveoldsentrows($userId, $oldsentRows) {
947
+
948
+           // Create the folder for removed messages if it doesn't exist
949
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
950
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
951
+           }
952
+           $savesentcheck = 0;
953
+
954
+           if (count($oldsentRows) > 1) {
955
+               $sntfileContent = implode("", $oldsentRows);
956
+
957
+               $delsentrowsdate = date("Y-m-d_H-i-s");
958
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
959
+
960
+               $userroot = $this->view->getRoot();
961
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
962
+
963
+               $snttarget = $this->folder->newFile($snttargetfile);
964
+               $snttarget->putContent($sntfileContent);
965
+
966
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
967
+                   $savesentcheck = 1;
968
+               }
969
+           }
970
+
971
+           return $savesentcheck;
972
+    }
973
+
974
+
975
+    /**
976
+     * @NoAdminRequired
977
+     */
978
+    public function getreceivedtable($userId) {
979
+           return $this->service->getreceivedtable($this->userId);
980
+    }
981
+
982
+    /**
983
+     * @NoAdminRequired
984
+     */
985
+    public function getreceivedtablefordel($userId) {
986
+           return $this->service->getreceivedtablefordel($this->userId);
987
+    }
988
+
989
+    /**
990
+     * @NoAdminRequired
991
+     */
992
+    public function removerecrows($userId, $recmessagedbIDs) {
993
+
994
+           // Get the Display Name of the current user
995
+           $crtuserdel = $this->userManager->get($this->userId);
996
+           $userDelDspName = $crtuserdel->getDisplayName();
997
+
998
+           return $this->service->removerecrows($this->userId, $userDelDspName, $recmessagedbIDs);
999
+    }
1000
+
1001
+    /**
1002
+     * @NoAdminRequired
1003
+     */
1004
+    public function getsenttable($userId) {
1005
+           return $this->service->getsenttable($this->userId);
1006
+    }
1007
+
1008
+    /**
1009
+     * @NoAdminRequired
1010
+     */
1011
+    public function getsenttablefordel($userId) {
1012
+           return $this->service->getsenttablefordel($this->userId);
1013
+    }
1014
+
1015
+    /**
1016
+     * @NoAdminRequired
1017
+     */
1018
+    public function removesentrows($userId, $sentmessagedbIDs) {
1019
+
1020
+           // Get the Display Name of the current user
1021
+           $crtuserstdel = $this->userManager->get($this->userId);
1022
+           $userstDelDspName = $crtuserstdel->getDisplayName();
1023
+
1024
+           return $this->service->removesentrows($this->userId, $userstDelDspName, $sentmessagedbIDs);
1025
+    }
1026
+
1027
+    /**
1028
+     * @NoAdminRequired
1029
+     */
1030
+    public function getconversations($userId) {
1031
+           return $this->service->getconversations($this->userId);
1032
+    }
1033
+
1034
+    /**
1035
+     * @NoAdminRequired
1036
+     */
1037
+    public function archiveconv($userId, $conversationId) {
1038
+
1039
+           // Get the Display Name of the current user
1040
+           $crtusergt = $this->userManager->get($this->userId);
1041
+           $userDspNameArch = $crtusergt->getDisplayName();
1042
+
1043
+           return $this->service->archiveconv($this->userId, $userDspNameArch, $conversationId);
1044
+    }
1045
+
1046
+    /**
1047
+     * @NoAdminRequired
1048
+     */
1049
+    public function unarchiveconv($userId, $conversationId) {
1050
+
1051
+           // Get the Display Name of the current user
1052
+           $crtusergtun = $this->userManager->get($this->userId);
1053
+           $userDspNameUnarch = $crtusergtun->getDisplayName();
1054
+
1055
+           return $this->service->unarchiveconv($this->userId, $userDspNameUnarch, $conversationId);
1056
+    }
1057
+
1058
+    /**
1059
+     * @NoAdminRequired
1060
+     */
1061
+    public function saveconvdescription($userId, $convDescription, $convId) {
1062
+
1063
+           // Get the Display Name of the current user
1064
+           $crtuserdesc = $this->userManager->get($this->userId);
1065
+           $userDspNameDesc = $crtuserdesc->getDisplayName();
1066
+
1067
+           return $this->service->saveconvdescription($this->userId, $userDspNameDesc, $convDescription, $convId);
1068
+    }
1069
+
1070
+    /**
1071
+     * @NoAdminRequired
1072
+     */
1073
+    public function saveconvtag($userId, $convTag, $convId) {
1074
+
1075
+           // Get the Display Name of the current user
1076
+           $crtusertag = $this->userManager->get($this->userId);
1077
+           $userDspNameTag = $crtusertag->getDisplayName();
1078
+
1079
+           return $this->service->saveconvtag($this->userId, $userDspNameTag, $convTag, $convId);
1080
+    }
1081
+
1082
+    /**
1083
+     * @NoAdminRequired
1084
+     */
1085
+    public function saveconvflag($userId, $convFlag, $convId) {
1086
+
1087
+           // Get the Display Name of the current user
1088
+           $crtuserflag = $this->userManager->get($this->userId);
1089
+           $userDspNameFlag = $crtuserflag->getDisplayName();
1090
+
1091
+           return $this->service->saveconvflag($this->userId, $userDspNameFlag, $convFlag, $convId);
1092
+    }
1093
+
1094
+    /**
1095
+     * @NoAdminRequired
1096
+     */
1097
+    public function removeconvmsgs($userId, $conversationId) {
1098
+           return $this->service->removeconvmsgs($this->userId, $conversationId);
1099
+    }
1100
+
1101
+    /**
1102
+     * @NoAdminRequired
1103
+     */
1104
+    public function getgroupedtable($userId) {
1105
+           return $this->service->getgroupedtable($this->userId);
1106
+    }
1107
+
1108
+    /**
1109
+     * @NoAdminRequired
1110
+     */
1111
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1112
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1113
+    }
1114
+
1115
+    /**
1116
+     * @NoAdminRequired
1117
+     */
1118
+    public function getmsgsperpgnewmsgarchnb($userId) {
1119
+           return $this->service->getmsgsperpgnewmsgarchnb($this->userId);
1120
+    }
1121
+
1122
+    /**
1123
+     * @NoAdminRequired
1124
+     */
1125
+    public function getnewmsgindicator($userId) {
1126
+           return $this->service->getnewmsgindicator($this->userId);
1127
+    }
1128
+
1129
+    /**
1130
+     * @NoAdminRequired
1131
+     */
1132
+    public function getdelrecsettings($userId) {
1133
+           return $this->service->getdelrecsettings($this->userId);
1134
+    }
1135
+
1136
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1137
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1138
+    }
1139
+
1140
+    public function updatekeysallowedusers($userId, $groups, $users, $groupsdel, $usersdel, $provider) {
1141
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $groupsdel, $usersdel, $provider);
1142
+    }
1143
+
1144
+    public function removenumberrestrictions($userId, $phoneNumber) {
1145
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1146
+    }
1147
+
1148
+    /**
1149
+     * @NoAdminRequired
1150
+     */
1151
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1152
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1153
+    }
1154
+
1155
+    /**
1156
+     * @NoAdminRequired
1157
+     */
1158
+    public function removeautoreplies($userId, $phoneNumber) {
1159
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1160
+    }
1161
+
1162
+    /**
1163
+     * @NoAdminRequired
1164
+     */
1165
+    public function getsettings($userId) {
1166
+           return $this->service->getsettings($this->userId);
1167
+    }
1168
+
1169
+    public function getadminsettings($userId) {
1170
+           return $this->service->getadminsettings($this->userId);
1171
+    }
1172
+
1173
+    /**
1174
+     * @NoAdminRequired
1175
+     */
1176
+    public function getautoreplyconf($userId) {
1177
+
1178
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1179
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1180
+
1181
+           // Get the display name of the current user
1182
+           $usrid = $this->userId;
1183
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1184
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1185
+	   $getusrdnmdata = $getusrdnmres->fetch();
1186
+	   $userDisplayNm = $getusrdnmdata['value'];
1187
+	   $getusrdnmres->closeCursor();
1188
+
1189
+           // Get the auto-replies for the available phone numbers
1190
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1191
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1192
+	   $getautorplres = $getautorpl->execute();
1193
+           $autorplconf = [];
1194
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1195
+                  $autorplconf[] = $acdatausrdnadm;
1196
+           }
1197
+	   $getautorplres->closeCursor();
1198
+
1199
+           if ($autorplconf) {
1200
+
1201
+               $autoreplyconf = [];
1202
+               foreach ($autorplconf as $arkey => $arvalue) {
1203
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1204
+                            $autoreplyconf[] = $arvalue;
1205
+                        }
1206
+               }
1207
+
1208
+           } else { $autoreplyconf = ''; }
1209
+
1210
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1211
+
1212
+           return $autoreplyfdb;
1213
+    }
1214
+
1215
+    /**
1216
+     * @NoAdminRequired
1217
+     */
1218
+    public function getgroupedpernumber($userId, $phoneNumber) {
1219
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1220
+    }
1221
+
1222
+    /**
1223
+     * @NoAdminRequired
1224
+     */
1225
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1226
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1227
+    }
1228
+
1229
+    /**
1230
+     * @NoAdminRequired
1231
+     */
1232
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1233
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1234
+    }
1235
+
1236
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1237
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1238
+    }
1239
+
1240
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1241
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1242
+    }
1243
+}
Browse code

removed appinfo/info.xml appinfo/signature.json CHANGELOG.txt css/style.css js/settings.js js/adminsettings.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/settings/personal.php templates/settings/admin.php lib/Migration/Version135Date20240420221527.php

DoubleBastionAdmin authored on 02/05/2024 04:04:23
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1249 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\Share\IManager;
49
-use OCP\Constants;
50
-use OCP\IGroupManager;
51
-use OCP\IDBConnection;
52
-use OCP\IUserManager;
53
-use OC\URLGenerator;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $shareManager;
64
-    private $groupManager;
65
-    private $connection;
66
-    private $userManager;
67
-    private $urlGenerator;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->shareManager = $shareManager;
78
-        $this->groupManager = $groupManager;
79
-        $this->connection = $connection;
80
-        $this->userManager = $userManager;
81
-        $this->urlGenerator = $urlGenerator;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getappdirectory($userId) {
120
-        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
-        $apprelpatharr = explode("/", $apprelpath);
122
-        $currentappdir = $apprelpatharr[1];
123
-        return $currentappdir;
124
-    }
125
-
126
-
127
-    /**
128
-     * @NoAdminRequired
129
-     */
130
-    public function createMessageId() {
131
-             // Create a random string to use as message id for messages that don't have it
132
-	     $keypassin = substr(sha1((string) mt_rand()), 0, 32);
133
-	     $keysaltin = openssl_random_pseudo_bytes(24);
134
-	     $keyLengthin = 32;
135
-	     $iterationin = 50;
136
-	     $generated_keyin = openssl_pbkdf2($keypassin, $keysaltin, $keyLengthin, $iterationin, 'sha256');
137
-	     $ctdMessageId = "generated-id-" . bin2hex($generated_keyin);
138
-             return $ctdMessageId;
139
-    }
140
-
141
-
142
-    /**
143
-     * @NoAdminRequired
144
-     */
145
-    public function getbalancetel($userId) {
146
-
147
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
148
-
149
-        $telapikey = $telsmsapicred[0];
150
-        $ch = curl_init();
151
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
152
-
153
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
154
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
155
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
156
-        $responsetel = curl_exec($ch);
157
-        $recdatatel = json_decode($responsetel, TRUE);
158
-        $telbalresponse = $recdatatel['data']['balance'];
159
-        $currentbalancetel = round(floatval($telbalresponse), 3);
160
-        curl_close($ch);
161
-
162
-        return $currentbalancetel;
163
-    }
164
-
165
-
166
-    /**
167
-     * @NoAdminRequired
168
-     */
169
-    public function getbalancenex($userId) {
170
-
171
-        $smsapicred = $this->service->getapicredentials($this->userId);
172
-        $smsapikey = $smsapicred[5];
173
-        $smsapisecret = $smsapicred[6];
174
-
175
-        if ($smsapikey == '' || $smsapisecret == '') {
176
-            $currentbalancenex = "N/A";
177
-        } else {
178
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
179
-            $mesdata = file_get_contents($getmesdata);
180
-            $datainit = json_decode($mesdata);
181
-            $balancenex = $datainit->cash_credits;
182
-            $currentbalancenex = round(floatval($balancenex), 3);
183
-        }
184
-        return $currentbalancenex;
185
-    }
186
-
187
-
188
-    /**
189
-     * @NoAdminRequired
190
-     */
191
-    public function getbalancetwil($userId) {
192
-
193
-        $smsapicred = $this->service->getapicredentials($this->userId);
194
-        $smsapisid = $smsapicred[15];
195
-        $smsapitoken = $smsapicred[16];
196
-
197
-        if ($smsapisid == '' || $smsapitoken == '') {
198
-            $currentbalancetwil = "N/A";
199
-        } else {
200
-
201
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
202
-            $balancetwil = $twilbalance->balance;
203
-
204
-            $currentbalancetwil = round(floatval($balancetwil), 3);
205
-        }
206
-        return $currentbalancetwil;
207
-    }
208
-
209
-
210
-    /**
211
-     * @NoAdminRequired
212
-     */
213
-    public function getbalanceflow($userId) {
214
-
215
-        $currentbalanceflow = 'n/a';
216
-        return $currentbalanceflow;
217
-    }
218
-
219
-
220
-    /**
221
-     * @NoAdminRequired
222
-     */
223
-    public function getsmsnumbers($userId) {
224
-
225
-        return $this->service->getsmsnumbers($this->userId);
226
-    }
227
-
228
-
229
-    /**
230
-     * @NoAdminRequired
231
-     */
232
-    public function refreshavailablenumbers($userId) {
233
-
234
-        return $this->service->refreshavailablenumbers($this->userId);
235
-    }
236
-
237
-
238
-    /**
239
-     * @NoAdminRequired
240
-     */
241
-    public function cleantempdir($userId) {
242
-
243
-        // Create the temporary folder if it doesn't exist
244
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
245
-            $this->folder->newFolder('SMS_Relentless/temp_files');
246
-        }
247
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
248
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
249
-        $fileSystemIterator = new FilesystemIterator($targetdir);
250
-
251
-        $dirfiles = [];
252
-        foreach ($fileSystemIterator as $fileInfo) {
253
-                 $dirfiles[] = $fileInfo->getFilename();
254
-        }
255
-
256
-        foreach ($dirfiles as $key => $indfile) {
257
-                 $thisuserroot = $this->view->getRoot();
258
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
259
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
260
-        }
261
-     }
262
-
263
-
264
-    /**
265
-     * @NoAdminRequired
266
-     */
267
-    public function cleanmultrecdir($userId) {
268
-
269
-        // Create the temporary folder if it doesn't exist
270
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
271
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
272
-        }
273
-        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
274
-        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
275
-        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
276
-
277
-        $dirfilesmrc = [];
278
-        foreach ($fileSystemIteratormrc as $fileInfomrc){
279
-                 $dirfilesmrc[] = $fileInfomrc->getFilename();
280
-        }
281
-
282
-        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
283
-                 $thisuserrootmrc = $this->view->getRoot();
284
-                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
285
-                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
286
-        }
287
-     }
288
-
289
-
290
-    /**
291
-     * @NoAdminRequired
292
-     */
293
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
294
-
295
-        // Create the temporary folder if it doesn't exist
296
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
297
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
298
-        }
299
-
300
-        // First delete any file that has been previously uploaded
301
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
302
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
303
-        $fileSystemIterator = new FilesystemIterator($targetdir);
304
-
305
-        $dirfiles = [];
306
-        foreach ($fileSystemIterator as $fileInfo){
307
-                 $dirfiles[] = $fileInfo->getFilename();
308
-        }
309
-
310
-        foreach ($dirfiles as $key => $indfile) {
311
-                 $thisuserroot = $this->view->getRoot();
312
-                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
313
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
314
-        }
315
-
316
-        // Upload the new file
317
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
318
-        $fileName = $_FILES['uploadfileforsms']['name'];
319
-
320
-        $userroot = $this->view->getRoot();
321
-        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
322
-
323
-        $target = $this->folder->newFile($targetfile);
324
-        $target->putContent($fileContent);
325
-
326
-        // Extract the phone numbers from the file
327
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
328
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
329
-        $numberarrayfourth = explode(",", $numberarraytert);
330
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
331
-        $numberarray = array_unique($numberarrayfifth);
332
-
333
-        return $numberarray;
334
-    }
335
-
336
-
337
-    /**
338
-     * @NoAdminRequired
339
-     */
340
-    public function uploadfile($uploadfileformms) {
341
-
342
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
343
-           $fileName = $_FILES['uploadfileformms']['name'];
344
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
345
-           $fileSize = $fileSizeinit / 1024;
346
-
347
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
348
-               $this->folder->newFolder('SMS_Relentless/temp_files');
349
-           }
350
-
351
-           $userroot = $this->view->getRoot();
352
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
353
-
354
-           $target = $this->folder->newFile($targetfile);
355
-           $target->putContent($fileContent);
356
-
357
-           // Get the cumulative files size of the uploaded files
358
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
359
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
360
-
361
-           $fileSystemIterator = new FilesystemIterator($targetdir);
362
-
363
-           $dirfiles = [];
364
-           foreach ($fileSystemIterator as $fileInfo){
365
-                    $dirfiles[] = $fileInfo->getFilename();
366
-           }
367
-
368
-           $totalflsizeinit = 0;
369
-           foreach ($dirfiles as $key => $indfile) {
370
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
371
-                    $mbSize = round($fileSizeinit / 1024, 4);
372
-                    $totalflsizeinit += $mbSize;
373
-           }
374
-
375
-           $totalflsize = round($totalflsizeinit, 4);
376
-
377
-           return $totalflsize;
378
-    }
379
-
380
-
381
-    /**
382
-     * @NoAdminRequired
383
-     */
384
-    public function pickfile($path) {
385
-
386
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
387
-               $this->folder->newFolder('SMS_Relentless/temp_files');
388
-           }
389
-
390
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
391
-
392
-           $fltgt = $datadir . $this->userId . "/files" . $path;
393
-
394
-           $fileContent = file_get_contents($fltgt);
395
-
396
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
397
-
398
-           $patharr = explode("/", $path);
399
-
400
-           $revarr = array_reverse($patharr);
401
-
402
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
403
-
404
-           $target = $this->folder->newFile($relflpath);
405
-
406
-           $target->putContent($fileContent);
407
-
408
-           // Get the cumulative files size of the uploaded files
409
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
410
-
411
-           $fileSystemIterator = new FilesystemIterator($targetdir);
412
-
413
-           $dirfiles = [];
414
-           foreach ($fileSystemIterator as $fileInfo) {
415
-                    $dirfiles[] = $fileInfo->getFilename();
416
-           }
417
-
418
-           $totalflsizeinit = 0;
419
-
420
-           foreach ($dirfiles as $key => $indfile) {
421
-
422
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
423
-                    $mbSize = round($fileSizeinit / 1024, 4);
424
-                    $totalflsizeinit += $mbSize;
425
-           }
426
-
427
-           $totalflsize = round($totalflsizeinit, 4);
428
-
429
-           $pickresult = [$totalflsize, $pkfilesize];
430
-
431
-           return $pickresult;
432
-    }
433
-
434
-
435
-    /**
436
-     * @NoAdminRequired
437
-     */
438
-    public function removeupfile($removedfilename) {
439
-
440
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
441
-
442
-           $removefile = $this->view->unlink($tmpfl);
443
-
444
-           // Get the cumulative files size of the uploaded files
445
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
446
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
447
-           $fileSystemIterator = new FilesystemIterator($targetdir);
448
-
449
-           $dirfiles = [];
450
-           foreach ($fileSystemIterator as $fileInfo){
451
-                    $dirfiles[] = $fileInfo->getFilename();
452
-           }
453
-
454
-           $totalflsizeinit = 0;
455
-
456
-           foreach ($dirfiles as $key => $indfile) {
457
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
458
-                    $mbSize = round($fileSizeinit / 1024, 4);
459
-                    $totalflsizeinit += $mbSize;
460
-           }
461
-
462
-           $totalflsize = round($totalflsizeinit, 4);
463
-
464
-           return $totalflsize;
465
-    }
466
-
467
-
468
-    /**
469
-     * @NoAdminRequired
470
-     */
471
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
472
-
473
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
474
-         $telnyxkey = $telsmsapicred[0];
475
-         $teldelrecurl = $telsmsapicred[3];
476
-         $messagingprofid = $telsmsapicred[4];
477
-         $addDisplName = $telsmsapicred[24];
478
-
479
-         // Get the Display Name of the current user
480
-         $crtuser = $this->userManager->get($this->userId);
481
-         $displayname = $crtuser->getDisplayName();
482
-
483
-         if ($addDisplName == 1) {
484
-             $sentsmstext = $displayname . ": " . $sentsmstext;
485
-         }
486
-
487
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
488
-
489
-         $microinterval = $waitinterval * 1000;
490
-
491
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
492
-
493
-             usleep($microinterval);
494
-
495
-             $messagedate = date("Y-m-d H:i:s");
496
-
497
-             if ($ismms == 0) {
498
-
499
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
500
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
501
-                 } else {
502
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
503
-                 }
504
-
505
-                 $messagetexttel = $sentsmstext;
506
-
507
-             } else {
508
-
509
-                 $mediaURLarr = [];
510
-                 $includedMediaFiles = '';
511
-
512
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
513
-
514
-                      $userroot = $this->view->getRoot();
515
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
516
-
517
-                      $flsharetarget = $this->folder->newFile($filetoshare);
518
-
519
-	              $share = $this->shareManager->newShare();
520
-	              $share->setNode($flsharetarget);
521
-	              $share->setPermissions(Constants::PERMISSION_READ);
522
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
523
-	              $share->setSharedBy($this->userId);
524
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
525
-                      $expirydate->add(new \DateInterval('P1D'));
526
-                      $share->setExpirationDate($expirydate);
527
-                      $shared = $this->shareManager->createShare($share);
528
-                      $shareToken = $shared->getToken();
529
-
530
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
531
-
532
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
533
-
534
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
535
-                 }
536
-
537
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
538
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
539
-                 } else {
540
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
541
-                 }
542
-
543
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
544
-             }
545
-
546
-             if ($message) {
547
-                 if (isset($message['id'])) { $messageid = $message['id']; } else { $messageid = $this->createMessageId(); }
548
-             } else { $messageid = $this->createMessageId(); }
549
-
550
-//             $messageid = $message['id'];
551
-             $messagefrom = "Telnyx: " . $fromsender;
552
-             $messageto = $tonumber;
553
-             $messagenetwork = null;
554
-             $messageprice = null;
555
-             $messagestatus = $message['to'][0]['status'];
556
-             $messagedelivery = null;
557
-
558
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
559
-
560
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
561
-         }
562
-         return $displayname;
563
-    }
564
-
565
-
566
-    /**
567
-     * @NoAdminRequired
568
-     */
569
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
570
-
571
-         $plsmsapicred = $this->service->getapicredentials($this->userId);
572
-
573
-         $smsapikey = $plsmsapicred[5];
574
-         $smsapisecret = $plsmsapicred[6];
575
-         $smsapideliveryrecurl = $plsmsapicred[8];
576
-         $addDisplName = $plsmsapicred[24];
577
-
578
-         // Get the Display Name of the current user
579
-         $crtuser = $this->userManager->get($this->userId);
580
-         $displayname = $crtuser->getDisplayName();
581
-
582
-         if ($addDisplName == 1) {
583
-             $sentsmstext = $displayname . ": " . $sentsmstext;
584
-         }
585
-
586
-         $microinterval = $waitinterval * 1000;
587
-
588
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
589
-
590
-             usleep($microinterval);
591
-
592
-             $messagedatepl = date("Y-m-d H:i:s");
593
-
594
-             if ($ismms == 0) {
595
-
596
-                 $client = new RestClient($smsapikey, $smsapisecret);
597
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
598
-                 $messagetextpl = $sentsmstext;
599
-	         $messageidinit = $response->getmessageUuid(0);
600
-                 $messageid = $messageidinit[0];
601
-
602
-                 if (property_exists($response, 'error')) { 
603
-                     $messagestatus = "Error: " . $response->error;
604
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
605
-
606
-             } else {
607
-
608
-                 $mediaURLarr = [];
609
-                 $includedMediaFiles = '';
610
-
611
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
612
-
613
-                      $userroot = $this->view->getRoot();
614
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
615
-
616
-                      $flsharetarget = $this->folder->newFile($filetoshare);
617
-
618
-	              $share = $this->shareManager->newShare();
619
-	              $share->setNode($flsharetarget);
620
-	              $share->setPermissions(Constants::PERMISSION_READ);
621
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
622
-	              $share->setSharedBy($this->userId);
623
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
624
-                      $expirydate->add(new \DateInterval('P1D'));
625
-                      $share->setExpirationDate($expirydate);
626
-                      $shared = $this->shareManager->createShare($share);
627
-                      $shareToken = $shared->getToken();
628
-
629
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
630
-
631
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
632
-
633
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
634
-                 }
635
-
636
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
637
-		 $postedparamspl = json_encode($datatosendpl);
638
-
639
-		 $chpl = curl_init();
640
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
641
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
642
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
643
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
644
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
645
-		 curl_setopt($chpl, CURLOPT_POST, 1);
646
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
647
-		 $resultpl = curl_exec ($chpl);
648
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
649
-		 curl_close ($chpl);
650
-
651
-		 $decresultpl = json_decode($resultpl);
652
-
653
-                 if ($decresultpl) {
654
-                     if (property_exists($decresultpl, 'message_uuid')) {
655
-                         $messageidinit = $decresultpl->message_uuid;
656
-                         $messageid = $messageidinit[0];
657
-                     } else { $messageid = $this->createMessageId(); }
658
-                 } else { $messageid = $this->createMessageId(); }
659
-
660
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
661
-
662
-                     if (property_exists($decresultpl, 'error')) {
663
-                         $messagestatus = "Error: " . $decresultpl->error;
664
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
665
-
666
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
667
-
668
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
669
-             }
670
-
671
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
672
-                 $messagefrom = "Plivo: " . $fromsender;
673
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
674
-
675
-             $messageto = $tonumber;
676
-             $messagenetwork = '';
677
-             $messageprice = '';
678
-
679
-             $messagedelivery = '';
680
-
681
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
682
-
683
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
684
-         }
685
-         return $displayname;
686
-    }
687
-
688
-
689
-    /**
690
-     * @NoAdminRequired
691
-     */
692
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
693
-
694
-         $twsmsapicred = $this->service->getapicredentials($this->userId);
695
-
696
-         $sid = $twsmsapicred[15];
697
-         $token = $twsmsapicred[16];
698
-         $smsapirecurltw = $twsmsapicred[18];
699
-         $addDisplName = $twsmsapicred[24];
700
-
701
-         // Get the Display Name of the current user
702
-         $crtuser = $this->userManager->get($this->userId);
703
-         $displayname = $crtuser->getDisplayName();
704
-
705
-         if ($addDisplName == 1) {
706
-             $sentsmstext = $displayname . ": " . $sentsmstext;
707
-         }
708
-
709
-         $microinterval = $waitinterval * 1000;
710
-
711
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
712
-
713
-             usleep($microinterval);
714
-
715
-             $messagedatetw = date("Y-m-d H:i:s");
716
-
717
-             if ($ismms == 0) {
718
-
719
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
720
-                 $sentsmstextfintw = $sentsmstext;
721
-
722
-             } else {
723
-
724
-                 $mediaURLs = [];
725
-                 $includedMediaFiles = '';
726
-
727
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
728
-
729
-                      $userroot = $this->view->getRoot();
730
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
731
-
732
-                      $flsharetarget = $this->folder->newFile($filetoshare);
733
-
734
-	              $share = $this->shareManager->newShare();
735
-	              $share->setNode($flsharetarget);
736
-	              $share->setPermissions(Constants::PERMISSION_READ);
737
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
738
-	              $share->setSharedBy($this->userId);
739
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
740
-                      $expirydate->add(new \DateInterval('P1D'));
741
-                      $share->setExpirationDate($expirydate);
742
-                      $shared = $this->shareManager->createShare($share);
743
-                      $shareToken = $shared->getToken();
744
-
745
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
746
-
747
-                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
748
-
749
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
750
-                 }
751
-
752
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
753
-
754
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
755
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
756
-                 }
757
-
758
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
759
-             }
760
-
761
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
762
-
763
-	     $chtw = curl_init();
764
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
765
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
766
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
767
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
768
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
769
-	     curl_setopt($chtw, CURLOPT_POST, 1);
770
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
771
-
772
-	     $resulttw = curl_exec ($chtw);
773
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
774
-	     curl_close ($chtw);
775
-
776
-             $decresulttw = json_decode($resulttw);
777
-
778
-             if ($decresulttw) {
779
-                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = $this->createMessageId(); }
780
-             } else { $messageidtw = $this->createMessageId(); }
781
-
782
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
783
-                 $messagestatustw = 'The message has been accepted for delivery.';
784
-             } else {
785
-                 $messagestatustw = 'An error occurred while trying to send the message.';
786
-             }
787
-
788
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
789
-                 $messagefromtw = "Twilio: " . $fromsender;
790
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
791
-
792
-             $messagenetworktw = '';
793
-             $messagepricetw = '';
794
-             $messagedeliverytw = '';
795
-
796
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
797
-
798
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
799
-         }
800
-         return $displayname;
801
-    }
802
-
803
-
804
-    /**
805
-     * @NoAdminRequired
806
-     */
807
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
808
-
809
-         $flsmsapicred = $this->service->getapicredentials($this->userId);
810
-
811
-         $flowapikey = $flsmsapicred[20];
812
-         $flowapisecret = $flsmsapicred[21];
813
-         $flowdelrecurl = $flsmsapicred[23];
814
-         $addDisplName = $flsmsapicred[24];
815
-
816
-         // Get the Display Name of the current user
817
-         $crtuser = $this->userManager->get($this->userId);
818
-         $displayname = $crtuser->getDisplayName();
819
-
820
-         if ($addDisplName == 1) {
821
-             $sentsmstext = $displayname . ": " . $sentsmstext;
822
-         }
823
-
824
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
825
-
826
-         $microinterval = $waitinterval * 1000;
827
-
828
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
829
-
830
-             usleep($microinterval);
831
-
832
-             $messagedatefl = date("Y-m-d H:i:s");
833
-
834
-             if ($ismms == 0) {
835
-
836
-                 $messagetextfinfl = $sentsmstext;
837
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
838
-
839
-             } else {
840
-
841
-		 $mediaurlsarr = [];
842
-		 $includedMediaFiles = '';
843
-
844
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
845
-
846
-		      $userroot = $this->view->getRoot();
847
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
848
-
849
-		      $flsharetarget = $this->folder->newFile($filetoshare);
850
-
851
-		      $share = $this->shareManager->newShare();
852
-		      $share->setNode($flsharetarget);
853
-		      $share->setPermissions(Constants::PERMISSION_READ);
854
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
855
-		      $share->setSharedBy($this->userId);
856
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
857
-                      $expirydate->add(new \DateInterval('P1D'));
858
-                      $share->setExpirationDate($expirydate);
859
-		      $shared = $this->shareManager->createShare($share);
860
-		      $shareToken = $shared->getToken();
861
-
862
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
863
-
864
-		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
865
-
866
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
867
-		 }
868
-
869
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
870
-
871
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
872
-             }
873
-
874
-	     $chfl = curl_init();
875
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
876
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
877
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
878
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
879
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
880
-	     curl_setopt($chfl, CURLOPT_POST, 1);
881
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
882
-	     $resultfl = curl_exec ($chfl);
883
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
884
-	     curl_close ($chfl);
885
-
886
-             $decresultfl = json_decode($resultfl);
887
-
888
-             if ($decresultfl) {
889
-                 if (property_exists($decresultfl, 'data')) { 
890
-                     $messageidfl = $decresultfl->data->id;
891
-                 } else { $messageidfl = $this->createMessageId(); }
892
-             } else { $messageidfl = $this->createMessageId(); }
893
-
894
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
895
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
896
-             } else { 
897
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
898
-             }
899
-
900
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
901
-                 $messagefromfl = "Flowroute: " . $fromsender;
902
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
903
-
904
-             $messagetofl = $tonumberfl;
905
-             $messagenetworkfl = '';
906
-             $messagepricefl = '';
907
-             $messagedeliveryfl = '';
908
-
909
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
910
-
911
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
912
-         }
913
-         return $displayname;
914
-    }
915
-
916
-
917
-    /**
918
-     * @NoAdminRequired
919
-     */
920
-    public function saveoldrecrows($userId, $oldrecRows) {
921
-
922
-           // Create the folder for removed messages if it doesn't exist
923
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
924
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
925
-           }
926
-           $savecheck = 0;
927
-
928
-           if (count($oldrecRows) > 1) {
929
-               $msfileContent = implode("", $oldrecRows);
930
-
931
-               $delrowsdate = date("Y-m-d_H-i-s");
932
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
933
-
934
-               $userroot = $this->view->getRoot();
935
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
936
-
937
-               $target = $this->folder->newFile($targetfile);
938
-               $target->putContent($msfileContent);
939
-
940
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
941
-                   $savecheck = 1;
942
-               }
943
-           }
944
-
945
-           return $savecheck;
946
-    }
947
-
948
-
949
-    /**
950
-     * @NoAdminRequired
951
-     */
952
-    public function saveoldsentrows($userId, $oldsentRows) {
953
-
954
-           // Create the folder for removed messages if it doesn't exist
955
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
956
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
957
-           }
958
-           $savesentcheck = 0;
959
-
960
-           if (count($oldsentRows) > 1) {
961
-               $sntfileContent = implode("", $oldsentRows);
962
-
963
-               $delsentrowsdate = date("Y-m-d_H-i-s");
964
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
965
-
966
-               $userroot = $this->view->getRoot();
967
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
968
-
969
-               $snttarget = $this->folder->newFile($snttargetfile);
970
-               $snttarget->putContent($sntfileContent);
971
-
972
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
973
-                   $savesentcheck = 1;
974
-               }
975
-           }
976
-
977
-           return $savesentcheck;
978
-    }
979
-
980
-
981
-    /**
982
-     * @NoAdminRequired
983
-     */
984
-    public function getreceivedtable($userId) {
985
-           return $this->service->getreceivedtable($this->userId);
986
-    }
987
-
988
-    /**
989
-     * @NoAdminRequired
990
-     */
991
-    public function getreceivedtablefordel($userId) {
992
-           return $this->service->getreceivedtablefordel($this->userId);
993
-    }
994
-
995
-    /**
996
-     * @NoAdminRequired
997
-     */
998
-    public function removerecrows($userId, $recmessagedbIDs) {
999
-
1000
-           // Get the Display Name of the current user
1001
-           $crtuserdel = $this->userManager->get($this->userId);
1002
-           $userDelDspName = $crtuserdel->getDisplayName();
1003
-
1004
-           return $this->service->removerecrows($this->userId, $userDelDspName, $recmessagedbIDs);
1005
-    }
1006
-
1007
-    /**
1008
-     * @NoAdminRequired
1009
-     */
1010
-    public function getsenttable($userId) {
1011
-           return $this->service->getsenttable($this->userId);
1012
-    }
1013
-
1014
-    /**
1015
-     * @NoAdminRequired
1016
-     */
1017
-    public function getsenttablefordel($userId) {
1018
-           return $this->service->getsenttablefordel($this->userId);
1019
-    }
1020
-
1021
-    /**
1022
-     * @NoAdminRequired
1023
-     */
1024
-    public function removesentrows($userId, $sentmessagedbIDs) {
1025
-
1026
-           // Get the Display Name of the current user
1027
-           $crtuserstdel = $this->userManager->get($this->userId);
1028
-           $userstDelDspName = $crtuserstdel->getDisplayName();
1029
-
1030
-           return $this->service->removesentrows($this->userId, $userstDelDspName, $sentmessagedbIDs);
1031
-    }
1032
-
1033
-    /**
1034
-     * @NoAdminRequired
1035
-     */
1036
-    public function getconversations($userId) {
1037
-           return $this->service->getconversations($this->userId);
1038
-    }
1039
-
1040
-    /**
1041
-     * @NoAdminRequired
1042
-     */
1043
-    public function archiveconv($userId, $conversationId) {
1044
-
1045
-           // Get the Display Name of the current user
1046
-           $crtusergt = $this->userManager->get($this->userId);
1047
-           $userDspNameArch = $crtusergt->getDisplayName();
1048
-
1049
-           return $this->service->archiveconv($this->userId, $userDspNameArch, $conversationId);
1050
-    }
1051
-
1052
-    /**
1053
-     * @NoAdminRequired
1054
-     */
1055
-    public function unarchiveconv($userId, $conversationId) {
1056
-
1057
-           // Get the Display Name of the current user
1058
-           $crtusergtun = $this->userManager->get($this->userId);
1059
-           $userDspNameUnarch = $crtusergtun->getDisplayName();
1060
-
1061
-           return $this->service->unarchiveconv($this->userId, $userDspNameUnarch, $conversationId);
1062
-    }
1063
-
1064
-    /**
1065
-     * @NoAdminRequired
1066
-     */
1067
-    public function saveconvdescription($userId, $convDescription, $convId) {
1068
-
1069
-           // Get the Display Name of the current user
1070
-           $crtuserdesc = $this->userManager->get($this->userId);
1071
-           $userDspNameDesc = $crtuserdesc->getDisplayName();
1072
-
1073
-           return $this->service->saveconvdescription($this->userId, $userDspNameDesc, $convDescription, $convId);
1074
-    }
1075
-
1076
-    /**
1077
-     * @NoAdminRequired
1078
-     */
1079
-    public function saveconvtag($userId, $convTag, $convId) {
1080
-
1081
-           // Get the Display Name of the current user
1082
-           $crtusertag = $this->userManager->get($this->userId);
1083
-           $userDspNameTag = $crtusertag->getDisplayName();
1084
-
1085
-           return $this->service->saveconvtag($this->userId, $userDspNameTag, $convTag, $convId);
1086
-    }
1087
-
1088
-    /**
1089
-     * @NoAdminRequired
1090
-     */
1091
-    public function saveconvflag($userId, $convFlag, $convId) {
1092
-
1093
-           // Get the Display Name of the current user
1094
-           $crtuserflag = $this->userManager->get($this->userId);
1095
-           $userDspNameFlag = $crtuserflag->getDisplayName();
1096
-
1097
-           return $this->service->saveconvflag($this->userId, $userDspNameFlag, $convFlag, $convId);
1098
-    }
1099
-
1100
-    /**
1101
-     * @NoAdminRequired
1102
-     */
1103
-    public function removeconvmsgs($userId, $conversationId) {
1104
-           return $this->service->removeconvmsgs($this->userId, $conversationId);
1105
-    }
1106
-
1107
-    /**
1108
-     * @NoAdminRequired
1109
-     */
1110
-    public function getgroupedtable($userId) {
1111
-           return $this->service->getgroupedtable($this->userId);
1112
-    }
1113
-
1114
-    /**
1115
-     * @NoAdminRequired
1116
-     */
1117
-    public function savedisplayname($userId, $authorDisplayname, $from) {
1118
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1119
-    }
1120
-
1121
-    /**
1122
-     * @NoAdminRequired
1123
-     */
1124
-    public function getmsgsperpgnewmsgarchnb($userId) {
1125
-           return $this->service->getmsgsperpgnewmsgarchnb($this->userId);
1126
-    }
1127
-
1128
-    /**
1129
-     * @NoAdminRequired
1130
-     */
1131
-    public function getnewmsgindicator($userId) {
1132
-           return $this->service->getnewmsgindicator($this->userId);
1133
-    }
1134
-
1135
-    /**
1136
-     * @NoAdminRequired
1137
-     */
1138
-    public function getdelrecsettings($userId) {
1139
-           return $this->service->getdelrecsettings($this->userId);
1140
-    }
1141
-
1142
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1143
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1144
-    }
1145
-
1146
-    public function updatekeysallowedusers($userId, $groups, $users, $groupsdel, $usersdel, $provider) {
1147
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $groupsdel, $usersdel, $provider);
1148
-    }
1149
-
1150
-    public function removenumberrestrictions($userId, $phoneNumber) {
1151
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1152
-    }
1153
-
1154
-    /**
1155
-     * @NoAdminRequired
1156
-     */
1157
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1158
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1159
-    }
1160
-
1161
-    /**
1162
-     * @NoAdminRequired
1163
-     */
1164
-    public function removeautoreplies($userId, $phoneNumber) {
1165
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1166
-    }
1167
-
1168
-    /**
1169
-     * @NoAdminRequired
1170
-     */
1171
-    public function getsettings($userId) {
1172
-           return $this->service->getsettings($this->userId);
1173
-    }
1174
-
1175
-    public function getadminsettings($userId) {
1176
-           return $this->service->getadminsettings($this->userId);
1177
-    }
1178
-
1179
-    /**
1180
-     * @NoAdminRequired
1181
-     */
1182
-    public function getautoreplyconf($userId) {
1183
-
1184
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1185
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1186
-
1187
-           // Get the display name of the current user
1188
-           $usrid = $this->userId;
1189
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1190
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1191
-	   $getusrdnmdata = $getusrdnmres->fetch();
1192
-	   $userDisplayNm = $getusrdnmdata['value'];
1193
-	   $getusrdnmres->closeCursor();
1194
-
1195
-           // Get the auto-replies for the available phone numbers
1196
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1197
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1198
-	   $getautorplres = $getautorpl->execute();
1199
-           $autorplconf = [];
1200
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1201
-                  $autorplconf[] = $acdatausrdnadm;
1202
-           }
1203
-	   $getautorplres->closeCursor();
1204
-
1205
-           if ($autorplconf) {
1206
-
1207
-               $autoreplyconf = [];
1208
-               foreach ($autorplconf as $arkey => $arvalue) {
1209
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1210
-                            $autoreplyconf[] = $arvalue;
1211
-                        }
1212
-               }
1213
-
1214
-           } else { $autoreplyconf = ''; }
1215
-
1216
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1217
-
1218
-           return $autoreplyfdb;
1219
-    }
1220
-
1221
-    /**
1222
-     * @NoAdminRequired
1223
-     */
1224
-    public function getgroupedpernumber($userId, $phoneNumber) {
1225
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1226
-    }
1227
-
1228
-    /**
1229
-     * @NoAdminRequired
1230
-     */
1231
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1232
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1233
-    }
1234
-
1235
-    /**
1236
-     * @NoAdminRequired
1237
-     */
1238
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1239
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1240
-    }
1241
-
1242
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1243
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1244
-    }
1245
-
1246
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1247
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1248
-    }
1249
-}
Browse code

added appinfo/info.xml appinfo/signature.json CHANGELOG.txt js/showsmstables.js js/adminsettings.js css/style.css lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/settings/admin.php lib/Migration/Version135Date20240420221527.php

DoubleBastionAdmin authored on 20/04/2024 03:36:59
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1249 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\Share\IManager;
49
+use OCP\Constants;
50
+use OCP\IGroupManager;
51
+use OCP\IDBConnection;
52
+use OCP\IUserManager;
53
+use OC\URLGenerator;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $shareManager;
64
+    private $groupManager;
65
+    private $connection;
66
+    private $userManager;
67
+    private $urlGenerator;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->shareManager = $shareManager;
78
+        $this->groupManager = $groupManager;
79
+        $this->connection = $connection;
80
+        $this->userManager = $userManager;
81
+        $this->urlGenerator = $urlGenerator;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getappdirectory($userId) {
120
+        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
+        $apprelpatharr = explode("/", $apprelpath);
122
+        $currentappdir = $apprelpatharr[1];
123
+        return $currentappdir;
124
+    }
125
+
126
+
127
+    /**
128
+     * @NoAdminRequired
129
+     */
130
+    public function createMessageId() {
131
+             // Create a random string to use as message id for messages that don't have it
132
+	     $keypassin = substr(sha1((string) mt_rand()), 0, 32);
133
+	     $keysaltin = openssl_random_pseudo_bytes(24);
134
+	     $keyLengthin = 32;
135
+	     $iterationin = 50;
136
+	     $generated_keyin = openssl_pbkdf2($keypassin, $keysaltin, $keyLengthin, $iterationin, 'sha256');
137
+	     $ctdMessageId = "generated-id-" . bin2hex($generated_keyin);
138
+             return $ctdMessageId;
139
+    }
140
+
141
+
142
+    /**
143
+     * @NoAdminRequired
144
+     */
145
+    public function getbalancetel($userId) {
146
+
147
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
148
+
149
+        $telapikey = $telsmsapicred[0];
150
+        $ch = curl_init();
151
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
152
+
153
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
154
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
155
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
156
+        $responsetel = curl_exec($ch);
157
+        $recdatatel = json_decode($responsetel, TRUE);
158
+        $telbalresponse = $recdatatel['data']['balance'];
159
+        $currentbalancetel = round(floatval($telbalresponse), 3);
160
+        curl_close($ch);
161
+
162
+        return $currentbalancetel;
163
+    }
164
+
165
+
166
+    /**
167
+     * @NoAdminRequired
168
+     */
169
+    public function getbalancenex($userId) {
170
+
171
+        $smsapicred = $this->service->getapicredentials($this->userId);
172
+        $smsapikey = $smsapicred[5];
173
+        $smsapisecret = $smsapicred[6];
174
+
175
+        if ($smsapikey == '' || $smsapisecret == '') {
176
+            $currentbalancenex = "N/A";
177
+        } else {
178
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
179
+            $mesdata = file_get_contents($getmesdata);
180
+            $datainit = json_decode($mesdata);
181
+            $balancenex = $datainit->cash_credits;
182
+            $currentbalancenex = round(floatval($balancenex), 3);
183
+        }
184
+        return $currentbalancenex;
185
+    }
186
+
187
+
188
+    /**
189
+     * @NoAdminRequired
190
+     */
191
+    public function getbalancetwil($userId) {
192
+
193
+        $smsapicred = $this->service->getapicredentials($this->userId);
194
+        $smsapisid = $smsapicred[15];
195
+        $smsapitoken = $smsapicred[16];
196
+
197
+        if ($smsapisid == '' || $smsapitoken == '') {
198
+            $currentbalancetwil = "N/A";
199
+        } else {
200
+
201
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
202
+            $balancetwil = $twilbalance->balance;
203
+
204
+            $currentbalancetwil = round(floatval($balancetwil), 3);
205
+        }
206
+        return $currentbalancetwil;
207
+    }
208
+
209
+
210
+    /**
211
+     * @NoAdminRequired
212
+     */
213
+    public function getbalanceflow($userId) {
214
+
215
+        $currentbalanceflow = 'n/a';
216
+        return $currentbalanceflow;
217
+    }
218
+
219
+
220
+    /**
221
+     * @NoAdminRequired
222
+     */
223
+    public function getsmsnumbers($userId) {
224
+
225
+        return $this->service->getsmsnumbers($this->userId);
226
+    }
227
+
228
+
229
+    /**
230
+     * @NoAdminRequired
231
+     */
232
+    public function refreshavailablenumbers($userId) {
233
+
234
+        return $this->service->refreshavailablenumbers($this->userId);
235
+    }
236
+
237
+
238
+    /**
239
+     * @NoAdminRequired
240
+     */
241
+    public function cleantempdir($userId) {
242
+
243
+        // Create the temporary folder if it doesn't exist
244
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
245
+            $this->folder->newFolder('SMS_Relentless/temp_files');
246
+        }
247
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
248
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
249
+        $fileSystemIterator = new FilesystemIterator($targetdir);
250
+
251
+        $dirfiles = [];
252
+        foreach ($fileSystemIterator as $fileInfo) {
253
+                 $dirfiles[] = $fileInfo->getFilename();
254
+        }
255
+
256
+        foreach ($dirfiles as $key => $indfile) {
257
+                 $thisuserroot = $this->view->getRoot();
258
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
259
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
260
+        }
261
+     }
262
+
263
+
264
+    /**
265
+     * @NoAdminRequired
266
+     */
267
+    public function cleanmultrecdir($userId) {
268
+
269
+        // Create the temporary folder if it doesn't exist
270
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
271
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
272
+        }
273
+        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
274
+        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
275
+        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
276
+
277
+        $dirfilesmrc = [];
278
+        foreach ($fileSystemIteratormrc as $fileInfomrc){
279
+                 $dirfilesmrc[] = $fileInfomrc->getFilename();
280
+        }
281
+
282
+        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
283
+                 $thisuserrootmrc = $this->view->getRoot();
284
+                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
285
+                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
286
+        }
287
+     }
288
+
289
+
290
+    /**
291
+     * @NoAdminRequired
292
+     */
293
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
294
+
295
+        // Create the temporary folder if it doesn't exist
296
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
297
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
298
+        }
299
+
300
+        // First delete any file that has been previously uploaded
301
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
302
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
303
+        $fileSystemIterator = new FilesystemIterator($targetdir);
304
+
305
+        $dirfiles = [];
306
+        foreach ($fileSystemIterator as $fileInfo){
307
+                 $dirfiles[] = $fileInfo->getFilename();
308
+        }
309
+
310
+        foreach ($dirfiles as $key => $indfile) {
311
+                 $thisuserroot = $this->view->getRoot();
312
+                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
313
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
314
+        }
315
+
316
+        // Upload the new file
317
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
318
+        $fileName = $_FILES['uploadfileforsms']['name'];
319
+
320
+        $userroot = $this->view->getRoot();
321
+        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
322
+
323
+        $target = $this->folder->newFile($targetfile);
324
+        $target->putContent($fileContent);
325
+
326
+        // Extract the phone numbers from the file
327
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
328
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
329
+        $numberarrayfourth = explode(",", $numberarraytert);
330
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
331
+        $numberarray = array_unique($numberarrayfifth);
332
+
333
+        return $numberarray;
334
+    }
335
+
336
+
337
+    /**
338
+     * @NoAdminRequired
339
+     */
340
+    public function uploadfile($uploadfileformms) {
341
+
342
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
343
+           $fileName = $_FILES['uploadfileformms']['name'];
344
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
345
+           $fileSize = $fileSizeinit / 1024;
346
+
347
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
348
+               $this->folder->newFolder('SMS_Relentless/temp_files');
349
+           }
350
+
351
+           $userroot = $this->view->getRoot();
352
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
353
+
354
+           $target = $this->folder->newFile($targetfile);
355
+           $target->putContent($fileContent);
356
+
357
+           // Get the cumulative files size of the uploaded files
358
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
359
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
360
+
361
+           $fileSystemIterator = new FilesystemIterator($targetdir);
362
+
363
+           $dirfiles = [];
364
+           foreach ($fileSystemIterator as $fileInfo){
365
+                    $dirfiles[] = $fileInfo->getFilename();
366
+           }
367
+
368
+           $totalflsizeinit = 0;
369
+           foreach ($dirfiles as $key => $indfile) {
370
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
371
+                    $mbSize = round($fileSizeinit / 1024, 4);
372
+                    $totalflsizeinit += $mbSize;
373
+           }
374
+
375
+           $totalflsize = round($totalflsizeinit, 4);
376
+
377
+           return $totalflsize;
378
+    }
379
+
380
+
381
+    /**
382
+     * @NoAdminRequired
383
+     */
384
+    public function pickfile($path) {
385
+
386
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
387
+               $this->folder->newFolder('SMS_Relentless/temp_files');
388
+           }
389
+
390
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
391
+
392
+           $fltgt = $datadir . $this->userId . "/files" . $path;
393
+
394
+           $fileContent = file_get_contents($fltgt);
395
+
396
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
397
+
398
+           $patharr = explode("/", $path);
399
+
400
+           $revarr = array_reverse($patharr);
401
+
402
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
403
+
404
+           $target = $this->folder->newFile($relflpath);
405
+
406
+           $target->putContent($fileContent);
407
+
408
+           // Get the cumulative files size of the uploaded files
409
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
410
+
411
+           $fileSystemIterator = new FilesystemIterator($targetdir);
412
+
413
+           $dirfiles = [];
414
+           foreach ($fileSystemIterator as $fileInfo) {
415
+                    $dirfiles[] = $fileInfo->getFilename();
416
+           }
417
+
418
+           $totalflsizeinit = 0;
419
+
420
+           foreach ($dirfiles as $key => $indfile) {
421
+
422
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
423
+                    $mbSize = round($fileSizeinit / 1024, 4);
424
+                    $totalflsizeinit += $mbSize;
425
+           }
426
+
427
+           $totalflsize = round($totalflsizeinit, 4);
428
+
429
+           $pickresult = [$totalflsize, $pkfilesize];
430
+
431
+           return $pickresult;
432
+    }
433
+
434
+
435
+    /**
436
+     * @NoAdminRequired
437
+     */
438
+    public function removeupfile($removedfilename) {
439
+
440
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
441
+
442
+           $removefile = $this->view->unlink($tmpfl);
443
+
444
+           // Get the cumulative files size of the uploaded files
445
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
446
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
447
+           $fileSystemIterator = new FilesystemIterator($targetdir);
448
+
449
+           $dirfiles = [];
450
+           foreach ($fileSystemIterator as $fileInfo){
451
+                    $dirfiles[] = $fileInfo->getFilename();
452
+           }
453
+
454
+           $totalflsizeinit = 0;
455
+
456
+           foreach ($dirfiles as $key => $indfile) {
457
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
458
+                    $mbSize = round($fileSizeinit / 1024, 4);
459
+                    $totalflsizeinit += $mbSize;
460
+           }
461
+
462
+           $totalflsize = round($totalflsizeinit, 4);
463
+
464
+           return $totalflsize;
465
+    }
466
+
467
+
468
+    /**
469
+     * @NoAdminRequired
470
+     */
471
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
472
+
473
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
474
+         $telnyxkey = $telsmsapicred[0];
475
+         $teldelrecurl = $telsmsapicred[3];
476
+         $messagingprofid = $telsmsapicred[4];
477
+         $addDisplName = $telsmsapicred[24];
478
+
479
+         // Get the Display Name of the current user
480
+         $crtuser = $this->userManager->get($this->userId);
481
+         $displayname = $crtuser->getDisplayName();
482
+
483
+         if ($addDisplName == 1) {
484
+             $sentsmstext = $displayname . ": " . $sentsmstext;
485
+         }
486
+
487
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
488
+
489
+         $microinterval = $waitinterval * 1000;
490
+
491
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
492
+
493
+             usleep($microinterval);
494
+
495
+             $messagedate = date("Y-m-d H:i:s");
496
+
497
+             if ($ismms == 0) {
498
+
499
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
500
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
501
+                 } else {
502
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
503
+                 }
504
+
505
+                 $messagetexttel = $sentsmstext;
506
+
507
+             } else {
508
+
509
+                 $mediaURLarr = [];
510
+                 $includedMediaFiles = '';
511
+
512
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
513
+
514
+                      $userroot = $this->view->getRoot();
515
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
516
+
517
+                      $flsharetarget = $this->folder->newFile($filetoshare);
518
+
519
+	              $share = $this->shareManager->newShare();
520
+	              $share->setNode($flsharetarget);
521
+	              $share->setPermissions(Constants::PERMISSION_READ);
522
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
523
+	              $share->setSharedBy($this->userId);
524
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
525
+                      $expirydate->add(new \DateInterval('P1D'));
526
+                      $share->setExpirationDate($expirydate);
527
+                      $shared = $this->shareManager->createShare($share);
528
+                      $shareToken = $shared->getToken();
529
+
530
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
531
+
532
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
533
+
534
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
535
+                 }
536
+
537
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
538
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
539
+                 } else {
540
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
541
+                 }
542
+
543
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
544
+             }
545
+
546
+             if ($message) {
547
+                 if (isset($message['id'])) { $messageid = $message['id']; } else { $messageid = $this->createMessageId(); }
548
+             } else { $messageid = $this->createMessageId(); }
549
+
550
+//             $messageid = $message['id'];
551
+             $messagefrom = "Telnyx: " . $fromsender;
552
+             $messageto = $tonumber;
553
+             $messagenetwork = null;
554
+             $messageprice = null;
555
+             $messagestatus = $message['to'][0]['status'];
556
+             $messagedelivery = null;
557
+
558
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
559
+
560
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
561
+         }
562
+         return $displayname;
563
+    }
564
+
565
+
566
+    /**
567
+     * @NoAdminRequired
568
+     */
569
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
570
+
571
+         $plsmsapicred = $this->service->getapicredentials($this->userId);
572
+
573
+         $smsapikey = $plsmsapicred[5];
574
+         $smsapisecret = $plsmsapicred[6];
575
+         $smsapideliveryrecurl = $plsmsapicred[8];
576
+         $addDisplName = $plsmsapicred[24];
577
+
578
+         // Get the Display Name of the current user
579
+         $crtuser = $this->userManager->get($this->userId);
580
+         $displayname = $crtuser->getDisplayName();
581
+
582
+         if ($addDisplName == 1) {
583
+             $sentsmstext = $displayname . ": " . $sentsmstext;
584
+         }
585
+
586
+         $microinterval = $waitinterval * 1000;
587
+
588
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
589
+
590
+             usleep($microinterval);
591
+
592
+             $messagedatepl = date("Y-m-d H:i:s");
593
+
594
+             if ($ismms == 0) {
595
+
596
+                 $client = new RestClient($smsapikey, $smsapisecret);
597
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
598
+                 $messagetextpl = $sentsmstext;
599
+	         $messageidinit = $response->getmessageUuid(0);
600
+                 $messageid = $messageidinit[0];
601
+
602
+                 if (property_exists($response, 'error')) { 
603
+                     $messagestatus = "Error: " . $response->error;
604
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
605
+
606
+             } else {
607
+
608
+                 $mediaURLarr = [];
609
+                 $includedMediaFiles = '';
610
+
611
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
612
+
613
+                      $userroot = $this->view->getRoot();
614
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
615
+
616
+                      $flsharetarget = $this->folder->newFile($filetoshare);
617
+
618
+	              $share = $this->shareManager->newShare();
619
+	              $share->setNode($flsharetarget);
620
+	              $share->setPermissions(Constants::PERMISSION_READ);
621
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
622
+	              $share->setSharedBy($this->userId);
623
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
624
+                      $expirydate->add(new \DateInterval('P1D'));
625
+                      $share->setExpirationDate($expirydate);
626
+                      $shared = $this->shareManager->createShare($share);
627
+                      $shareToken = $shared->getToken();
628
+
629
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
630
+
631
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
632
+
633
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
634
+                 }
635
+
636
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
637
+		 $postedparamspl = json_encode($datatosendpl);
638
+
639
+		 $chpl = curl_init();
640
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
641
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
642
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
643
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
644
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
645
+		 curl_setopt($chpl, CURLOPT_POST, 1);
646
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
647
+		 $resultpl = curl_exec ($chpl);
648
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
649
+		 curl_close ($chpl);
650
+
651
+		 $decresultpl = json_decode($resultpl);
652
+
653
+                 if ($decresultpl) {
654
+                     if (property_exists($decresultpl, 'message_uuid')) {
655
+                         $messageidinit = $decresultpl->message_uuid;
656
+                         $messageid = $messageidinit[0];
657
+                     } else { $messageid = $this->createMessageId(); }
658
+                 } else { $messageid = $this->createMessageId(); }
659
+
660
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
661
+
662
+                     if (property_exists($decresultpl, 'error')) {
663
+                         $messagestatus = "Error: " . $decresultpl->error;
664
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
665
+
666
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
667
+
668
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
669
+             }
670
+
671
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
672
+                 $messagefrom = "Plivo: " . $fromsender;
673
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
674
+
675
+             $messageto = $tonumber;
676
+             $messagenetwork = '';
677
+             $messageprice = '';
678
+
679
+             $messagedelivery = '';
680
+
681
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
682
+
683
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
684
+         }
685
+         return $displayname;
686
+    }
687
+
688
+
689
+    /**
690
+     * @NoAdminRequired
691
+     */
692
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
693
+
694
+         $twsmsapicred = $this->service->getapicredentials($this->userId);
695
+
696
+         $sid = $twsmsapicred[15];
697
+         $token = $twsmsapicred[16];
698
+         $smsapirecurltw = $twsmsapicred[18];
699
+         $addDisplName = $twsmsapicred[24];
700
+
701
+         // Get the Display Name of the current user
702
+         $crtuser = $this->userManager->get($this->userId);
703
+         $displayname = $crtuser->getDisplayName();
704
+
705
+         if ($addDisplName == 1) {
706
+             $sentsmstext = $displayname . ": " . $sentsmstext;
707
+         }
708
+
709
+         $microinterval = $waitinterval * 1000;
710
+
711
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
712
+
713
+             usleep($microinterval);
714
+
715
+             $messagedatetw = date("Y-m-d H:i:s");
716
+
717
+             if ($ismms == 0) {
718
+
719
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
720
+                 $sentsmstextfintw = $sentsmstext;
721
+
722
+             } else {
723
+
724
+                 $mediaURLs = [];
725
+                 $includedMediaFiles = '';
726
+
727
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
728
+
729
+                      $userroot = $this->view->getRoot();
730
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
731
+
732
+                      $flsharetarget = $this->folder->newFile($filetoshare);
733
+
734
+	              $share = $this->shareManager->newShare();
735
+	              $share->setNode($flsharetarget);
736
+	              $share->setPermissions(Constants::PERMISSION_READ);
737
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
738
+	              $share->setSharedBy($this->userId);
739
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
740
+                      $expirydate->add(new \DateInterval('P1D'));
741
+                      $share->setExpirationDate($expirydate);
742
+                      $shared = $this->shareManager->createShare($share);
743
+                      $shareToken = $shared->getToken();
744
+
745
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
746
+
747
+                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
748
+
749
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
750
+                 }
751
+
752
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
753
+
754
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
755
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
756
+                 }
757
+
758
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
759
+             }
760
+
761
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
762
+
763
+	     $chtw = curl_init();
764
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
765
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
766
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
767
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
768
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
769
+	     curl_setopt($chtw, CURLOPT_POST, 1);
770
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
771
+
772
+	     $resulttw = curl_exec ($chtw);
773
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
774
+	     curl_close ($chtw);
775
+
776
+             $decresulttw = json_decode($resulttw);
777
+
778
+             if ($decresulttw) {
779
+                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = $this->createMessageId(); }
780
+             } else { $messageidtw = $this->createMessageId(); }
781
+
782
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
783
+                 $messagestatustw = 'The message has been accepted for delivery.';
784
+             } else {
785
+                 $messagestatustw = 'An error occurred while trying to send the message.';
786
+             }
787
+
788
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
789
+                 $messagefromtw = "Twilio: " . $fromsender;
790
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
791
+
792
+             $messagenetworktw = '';
793
+             $messagepricetw = '';
794
+             $messagedeliverytw = '';
795
+
796
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
797
+
798
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
799
+         }
800
+         return $displayname;
801
+    }
802
+
803
+
804
+    /**
805
+     * @NoAdminRequired
806
+     */
807
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
808
+
809
+         $flsmsapicred = $this->service->getapicredentials($this->userId);
810
+
811
+         $flowapikey = $flsmsapicred[20];
812
+         $flowapisecret = $flsmsapicred[21];
813
+         $flowdelrecurl = $flsmsapicred[23];
814
+         $addDisplName = $flsmsapicred[24];
815
+
816
+         // Get the Display Name of the current user
817
+         $crtuser = $this->userManager->get($this->userId);
818
+         $displayname = $crtuser->getDisplayName();
819
+
820
+         if ($addDisplName == 1) {
821
+             $sentsmstext = $displayname . ": " . $sentsmstext;
822
+         }
823
+
824
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
825
+
826
+         $microinterval = $waitinterval * 1000;
827
+
828
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
829
+
830
+             usleep($microinterval);
831
+
832
+             $messagedatefl = date("Y-m-d H:i:s");
833
+
834
+             if ($ismms == 0) {
835
+
836
+                 $messagetextfinfl = $sentsmstext;
837
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
838
+
839
+             } else {
840
+
841
+		 $mediaurlsarr = [];
842
+		 $includedMediaFiles = '';
843
+
844
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
845
+
846
+		      $userroot = $this->view->getRoot();
847
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
848
+
849
+		      $flsharetarget = $this->folder->newFile($filetoshare);
850
+
851
+		      $share = $this->shareManager->newShare();
852
+		      $share->setNode($flsharetarget);
853
+		      $share->setPermissions(Constants::PERMISSION_READ);
854
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
855
+		      $share->setSharedBy($this->userId);
856
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
857
+                      $expirydate->add(new \DateInterval('P1D'));
858
+                      $share->setExpirationDate($expirydate);
859
+		      $shared = $this->shareManager->createShare($share);
860
+		      $shareToken = $shared->getToken();
861
+
862
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
863
+
864
+		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
865
+
866
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
867
+		 }
868
+
869
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
870
+
871
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
872
+             }
873
+
874
+	     $chfl = curl_init();
875
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
876
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
877
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
878
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
879
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
880
+	     curl_setopt($chfl, CURLOPT_POST, 1);
881
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
882
+	     $resultfl = curl_exec ($chfl);
883
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
884
+	     curl_close ($chfl);
885
+
886
+             $decresultfl = json_decode($resultfl);
887
+
888
+             if ($decresultfl) {
889
+                 if (property_exists($decresultfl, 'data')) { 
890
+                     $messageidfl = $decresultfl->data->id;
891
+                 } else { $messageidfl = $this->createMessageId(); }
892
+             } else { $messageidfl = $this->createMessageId(); }
893
+
894
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
895
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
896
+             } else { 
897
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
898
+             }
899
+
900
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
901
+                 $messagefromfl = "Flowroute: " . $fromsender;
902
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
903
+
904
+             $messagetofl = $tonumberfl;
905
+             $messagenetworkfl = '';
906
+             $messagepricefl = '';
907
+             $messagedeliveryfl = '';
908
+
909
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
910
+
911
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
912
+         }
913
+         return $displayname;
914
+    }
915
+
916
+
917
+    /**
918
+     * @NoAdminRequired
919
+     */
920
+    public function saveoldrecrows($userId, $oldrecRows) {
921
+
922
+           // Create the folder for removed messages if it doesn't exist
923
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
924
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
925
+           }
926
+           $savecheck = 0;
927
+
928
+           if (count($oldrecRows) > 1) {
929
+               $msfileContent = implode("", $oldrecRows);
930
+
931
+               $delrowsdate = date("Y-m-d_H-i-s");
932
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
933
+
934
+               $userroot = $this->view->getRoot();
935
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
936
+
937
+               $target = $this->folder->newFile($targetfile);
938
+               $target->putContent($msfileContent);
939
+
940
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
941
+                   $savecheck = 1;
942
+               }
943
+           }
944
+
945
+           return $savecheck;
946
+    }
947
+
948
+
949
+    /**
950
+     * @NoAdminRequired
951
+     */
952
+    public function saveoldsentrows($userId, $oldsentRows) {
953
+
954
+           // Create the folder for removed messages if it doesn't exist
955
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
956
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
957
+           }
958
+           $savesentcheck = 0;
959
+
960
+           if (count($oldsentRows) > 1) {
961
+               $sntfileContent = implode("", $oldsentRows);
962
+
963
+               $delsentrowsdate = date("Y-m-d_H-i-s");
964
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
965
+
966
+               $userroot = $this->view->getRoot();
967
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
968
+
969
+               $snttarget = $this->folder->newFile($snttargetfile);
970
+               $snttarget->putContent($sntfileContent);
971
+
972
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
973
+                   $savesentcheck = 1;
974
+               }
975
+           }
976
+
977
+           return $savesentcheck;
978
+    }
979
+
980
+
981
+    /**
982
+     * @NoAdminRequired
983
+     */
984
+    public function getreceivedtable($userId) {
985
+           return $this->service->getreceivedtable($this->userId);
986
+    }
987
+
988
+    /**
989
+     * @NoAdminRequired
990
+     */
991
+    public function getreceivedtablefordel($userId) {
992
+           return $this->service->getreceivedtablefordel($this->userId);
993
+    }
994
+
995
+    /**
996
+     * @NoAdminRequired
997
+     */
998
+    public function removerecrows($userId, $recmessagedbIDs) {
999
+
1000
+           // Get the Display Name of the current user
1001
+           $crtuserdel = $this->userManager->get($this->userId);
1002
+           $userDelDspName = $crtuserdel->getDisplayName();
1003
+
1004
+           return $this->service->removerecrows($this->userId, $userDelDspName, $recmessagedbIDs);
1005
+    }
1006
+
1007
+    /**
1008
+     * @NoAdminRequired
1009
+     */
1010
+    public function getsenttable($userId) {
1011
+           return $this->service->getsenttable($this->userId);
1012
+    }
1013
+
1014
+    /**
1015
+     * @NoAdminRequired
1016
+     */
1017
+    public function getsenttablefordel($userId) {
1018
+           return $this->service->getsenttablefordel($this->userId);
1019
+    }
1020
+
1021
+    /**
1022
+     * @NoAdminRequired
1023
+     */
1024
+    public function removesentrows($userId, $sentmessagedbIDs) {
1025
+
1026
+           // Get the Display Name of the current user
1027
+           $crtuserstdel = $this->userManager->get($this->userId);
1028
+           $userstDelDspName = $crtuserstdel->getDisplayName();
1029
+
1030
+           return $this->service->removesentrows($this->userId, $userstDelDspName, $sentmessagedbIDs);
1031
+    }
1032
+
1033
+    /**
1034
+     * @NoAdminRequired
1035
+     */
1036
+    public function getconversations($userId) {
1037
+           return $this->service->getconversations($this->userId);
1038
+    }
1039
+
1040
+    /**
1041
+     * @NoAdminRequired
1042
+     */
1043
+    public function archiveconv($userId, $conversationId) {
1044
+
1045
+           // Get the Display Name of the current user
1046
+           $crtusergt = $this->userManager->get($this->userId);
1047
+           $userDspNameArch = $crtusergt->getDisplayName();
1048
+
1049
+           return $this->service->archiveconv($this->userId, $userDspNameArch, $conversationId);
1050
+    }
1051
+
1052
+    /**
1053
+     * @NoAdminRequired
1054
+     */
1055
+    public function unarchiveconv($userId, $conversationId) {
1056
+
1057
+           // Get the Display Name of the current user
1058
+           $crtusergtun = $this->userManager->get($this->userId);
1059
+           $userDspNameUnarch = $crtusergtun->getDisplayName();
1060
+
1061
+           return $this->service->unarchiveconv($this->userId, $userDspNameUnarch, $conversationId);
1062
+    }
1063
+
1064
+    /**
1065
+     * @NoAdminRequired
1066
+     */
1067
+    public function saveconvdescription($userId, $convDescription, $convId) {
1068
+
1069
+           // Get the Display Name of the current user
1070
+           $crtuserdesc = $this->userManager->get($this->userId);
1071
+           $userDspNameDesc = $crtuserdesc->getDisplayName();
1072
+
1073
+           return $this->service->saveconvdescription($this->userId, $userDspNameDesc, $convDescription, $convId);
1074
+    }
1075
+
1076
+    /**
1077
+     * @NoAdminRequired
1078
+     */
1079
+    public function saveconvtag($userId, $convTag, $convId) {
1080
+
1081
+           // Get the Display Name of the current user
1082
+           $crtusertag = $this->userManager->get($this->userId);
1083
+           $userDspNameTag = $crtusertag->getDisplayName();
1084
+
1085
+           return $this->service->saveconvtag($this->userId, $userDspNameTag, $convTag, $convId);
1086
+    }
1087
+
1088
+    /**
1089
+     * @NoAdminRequired
1090
+     */
1091
+    public function saveconvflag($userId, $convFlag, $convId) {
1092
+
1093
+           // Get the Display Name of the current user
1094
+           $crtuserflag = $this->userManager->get($this->userId);
1095
+           $userDspNameFlag = $crtuserflag->getDisplayName();
1096
+
1097
+           return $this->service->saveconvflag($this->userId, $userDspNameFlag, $convFlag, $convId);
1098
+    }
1099
+
1100
+    /**
1101
+     * @NoAdminRequired
1102
+     */
1103
+    public function removeconvmsgs($userId, $conversationId) {
1104
+           return $this->service->removeconvmsgs($this->userId, $conversationId);
1105
+    }
1106
+
1107
+    /**
1108
+     * @NoAdminRequired
1109
+     */
1110
+    public function getgroupedtable($userId) {
1111
+           return $this->service->getgroupedtable($this->userId);
1112
+    }
1113
+
1114
+    /**
1115
+     * @NoAdminRequired
1116
+     */
1117
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1118
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1119
+    }
1120
+
1121
+    /**
1122
+     * @NoAdminRequired
1123
+     */
1124
+    public function getmsgsperpgnewmsgarchnb($userId) {
1125
+           return $this->service->getmsgsperpgnewmsgarchnb($this->userId);
1126
+    }
1127
+
1128
+    /**
1129
+     * @NoAdminRequired
1130
+     */
1131
+    public function getnewmsgindicator($userId) {
1132
+           return $this->service->getnewmsgindicator($this->userId);
1133
+    }
1134
+
1135
+    /**
1136
+     * @NoAdminRequired
1137
+     */
1138
+    public function getdelrecsettings($userId) {
1139
+           return $this->service->getdelrecsettings($this->userId);
1140
+    }
1141
+
1142
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1143
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1144
+    }
1145
+
1146
+    public function updatekeysallowedusers($userId, $groups, $users, $groupsdel, $usersdel, $provider) {
1147
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $groupsdel, $usersdel, $provider);
1148
+    }
1149
+
1150
+    public function removenumberrestrictions($userId, $phoneNumber) {
1151
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1152
+    }
1153
+
1154
+    /**
1155
+     * @NoAdminRequired
1156
+     */
1157
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1158
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1159
+    }
1160
+
1161
+    /**
1162
+     * @NoAdminRequired
1163
+     */
1164
+    public function removeautoreplies($userId, $phoneNumber) {
1165
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1166
+    }
1167
+
1168
+    /**
1169
+     * @NoAdminRequired
1170
+     */
1171
+    public function getsettings($userId) {
1172
+           return $this->service->getsettings($this->userId);
1173
+    }
1174
+
1175
+    public function getadminsettings($userId) {
1176
+           return $this->service->getadminsettings($this->userId);
1177
+    }
1178
+
1179
+    /**
1180
+     * @NoAdminRequired
1181
+     */
1182
+    public function getautoreplyconf($userId) {
1183
+
1184
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1185
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1186
+
1187
+           // Get the display name of the current user
1188
+           $usrid = $this->userId;
1189
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1190
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1191
+	   $getusrdnmdata = $getusrdnmres->fetch();
1192
+	   $userDisplayNm = $getusrdnmdata['value'];
1193
+	   $getusrdnmres->closeCursor();
1194
+
1195
+           // Get the auto-replies for the available phone numbers
1196
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1197
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1198
+	   $getautorplres = $getautorpl->execute();
1199
+           $autorplconf = [];
1200
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1201
+                  $autorplconf[] = $acdatausrdnadm;
1202
+           }
1203
+	   $getautorplres->closeCursor();
1204
+
1205
+           if ($autorplconf) {
1206
+
1207
+               $autoreplyconf = [];
1208
+               foreach ($autorplconf as $arkey => $arvalue) {
1209
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1210
+                            $autoreplyconf[] = $arvalue;
1211
+                        }
1212
+               }
1213
+
1214
+           } else { $autoreplyconf = ''; }
1215
+
1216
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1217
+
1218
+           return $autoreplyfdb;
1219
+    }
1220
+
1221
+    /**
1222
+     * @NoAdminRequired
1223
+     */
1224
+    public function getgroupedpernumber($userId, $phoneNumber) {
1225
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1226
+    }
1227
+
1228
+    /**
1229
+     * @NoAdminRequired
1230
+     */
1231
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1232
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1233
+    }
1234
+
1235
+    /**
1236
+     * @NoAdminRequired
1237
+     */
1238
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1239
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1240
+    }
1241
+
1242
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1243
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1244
+    }
1245
+
1246
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1247
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1248
+    }
1249
+}
Browse code

removed appinfo/info.xml appinfo/signature.json CHANGELOG.txt js/showsmstables.js js/adminsettings.js css/style.css lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/settings/admin.php

DoubleBastionAdmin authored on 20/04/2024 03:30:52
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1220 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\Share\IManager;
49
-use OCP\Constants;
50
-use OCP\IGroupManager;
51
-use OCP\IDBConnection;
52
-use OCP\IUserManager;
53
-use OC\URLGenerator;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $shareManager;
64
-    private $groupManager;
65
-    private $connection;
66
-    private $userManager;
67
-    private $urlGenerator;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->shareManager = $shareManager;
78
-        $this->groupManager = $groupManager;
79
-        $this->connection = $connection;
80
-        $this->userManager = $userManager;
81
-        $this->urlGenerator = $urlGenerator;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getappdirectory($userId) {
120
-        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
-        $apprelpatharr = explode("/", $apprelpath);
122
-        $currentappdir = $apprelpatharr[1];
123
-        return $currentappdir;
124
-    }
125
-
126
-
127
-    /**
128
-     * @NoAdminRequired
129
-     */
130
-    public function getbalancetel($userId) {
131
-
132
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
133
-
134
-        $telapikey = $telsmsapicred[0];
135
-        $ch = curl_init();
136
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
137
-
138
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
139
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
140
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
141
-        $responsetel = curl_exec($ch);
142
-        $recdatatel = json_decode($responsetel, TRUE);
143
-        $telbalresponse = $recdatatel['data']['balance'];
144
-        $currentbalancetel = round(floatval($telbalresponse), 3);
145
-        curl_close($ch);
146
-
147
-        return $currentbalancetel;
148
-    }
149
-
150
-
151
-    /**
152
-     * @NoAdminRequired
153
-     */
154
-    public function getbalancenex($userId) {
155
-
156
-        $smsapicred = $this->service->getapicredentials($this->userId);
157
-        $smsapikey = $smsapicred[5];
158
-        $smsapisecret = $smsapicred[6];
159
-
160
-        if ($smsapikey == '' || $smsapisecret == '') {
161
-            $currentbalancenex = "N/A";
162
-        } else {
163
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
164
-            $mesdata = file_get_contents($getmesdata);
165
-            $datainit = json_decode($mesdata);
166
-            $balancenex = $datainit->cash_credits;
167
-            $currentbalancenex = round(floatval($balancenex), 3);
168
-        }
169
-        return $currentbalancenex;
170
-    }
171
-
172
-
173
-    /**
174
-     * @NoAdminRequired
175
-     */
176
-    public function getbalancetwil($userId) {
177
-
178
-        $smsapicred = $this->service->getapicredentials($this->userId);
179
-        $smsapisid = $smsapicred[15];
180
-        $smsapitoken = $smsapicred[16];
181
-
182
-        if ($smsapisid == '' || $smsapitoken == '') {
183
-            $currentbalancetwil = "N/A";
184
-        } else {
185
-
186
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
187
-            $balancetwil = $twilbalance->balance;
188
-
189
-            $currentbalancetwil = round(floatval($balancetwil), 3);
190
-        }
191
-        return $currentbalancetwil;
192
-    }
193
-
194
-
195
-    /**
196
-     * @NoAdminRequired
197
-     */
198
-    public function getbalanceflow($userId) {
199
-
200
-        $currentbalanceflow = 'n/a';
201
-        return $currentbalanceflow;
202
-    }
203
-
204
-
205
-    /**
206
-     * @NoAdminRequired
207
-     */
208
-    public function getsmsnumbers($userId) {
209
-
210
-        return $this->service->getsmsnumbers($this->userId);
211
-    }
212
-
213
-
214
-    /**
215
-     * @NoAdminRequired
216
-     */
217
-    public function refreshavailablenumbers($userId) {
218
-
219
-        return $this->service->refreshavailablenumbers($this->userId);
220
-    }
221
-
222
-
223
-    /**
224
-     * @NoAdminRequired
225
-     */
226
-    public function cleantempdir($userId) {
227
-
228
-        // Create the temporary folder if it doesn't exist
229
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
230
-            $this->folder->newFolder('SMS_Relentless/temp_files');
231
-        }
232
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
233
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
234
-        $fileSystemIterator = new FilesystemIterator($targetdir);
235
-
236
-        $dirfiles = [];
237
-        foreach ($fileSystemIterator as $fileInfo) {
238
-                 $dirfiles[] = $fileInfo->getFilename();
239
-        }
240
-
241
-        foreach ($dirfiles as $key => $indfile) {
242
-                 $thisuserroot = $this->view->getRoot();
243
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
244
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
245
-        }
246
-     }
247
-
248
-
249
-    /**
250
-     * @NoAdminRequired
251
-     */
252
-    public function cleanmultrecdir($userId) {
253
-
254
-        // Create the temporary folder if it doesn't exist
255
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
256
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
257
-        }
258
-        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
259
-        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
260
-        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
261
-
262
-        $dirfilesmrc = [];
263
-        foreach ($fileSystemIteratormrc as $fileInfomrc){
264
-                 $dirfilesmrc[] = $fileInfomrc->getFilename();
265
-        }
266
-
267
-        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
268
-                 $thisuserrootmrc = $this->view->getRoot();
269
-                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
270
-                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
271
-        }
272
-     }
273
-
274
-
275
-    /**
276
-     * @NoAdminRequired
277
-     */
278
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
279
-
280
-        // Create the temporary folder if it doesn't exist
281
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
282
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
283
-        }
284
-
285
-        // First delete any file that has been previously uploaded
286
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
287
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
288
-        $fileSystemIterator = new FilesystemIterator($targetdir);
289
-
290
-        $dirfiles = [];
291
-        foreach ($fileSystemIterator as $fileInfo){
292
-                 $dirfiles[] = $fileInfo->getFilename();
293
-        }
294
-
295
-        foreach ($dirfiles as $key => $indfile) {
296
-                 $thisuserroot = $this->view->getRoot();
297
-                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
298
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
299
-        }
300
-
301
-        // Upload the new file
302
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
303
-        $fileName = $_FILES['uploadfileforsms']['name'];
304
-
305
-        $userroot = $this->view->getRoot();
306
-        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
307
-
308
-        $target = $this->folder->newFile($targetfile);
309
-        $target->putContent($fileContent);
310
-
311
-        // Extract the phone numbers from the file
312
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
313
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
314
-        $numberarrayfourth = explode(",", $numberarraytert);
315
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
316
-        $numberarray = array_unique($numberarrayfifth);
317
-
318
-        return $numberarray;
319
-    }
320
-
321
-
322
-    /**
323
-     * @NoAdminRequired
324
-     */
325
-    public function uploadfile($uploadfileformms) {
326
-
327
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
328
-           $fileName = $_FILES['uploadfileformms']['name'];
329
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
330
-           $fileSize = $fileSizeinit / 1024;
331
-
332
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
333
-               $this->folder->newFolder('SMS_Relentless/temp_files');
334
-           }
335
-
336
-           $userroot = $this->view->getRoot();
337
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
338
-
339
-           $target = $this->folder->newFile($targetfile);
340
-           $target->putContent($fileContent);
341
-
342
-           // Get the cumulative files size of the uploaded files
343
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
344
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
345
-
346
-           $fileSystemIterator = new FilesystemIterator($targetdir);
347
-
348
-           $dirfiles = [];
349
-           foreach ($fileSystemIterator as $fileInfo){
350
-                    $dirfiles[] = $fileInfo->getFilename();
351
-           }
352
-
353
-           $totalflsizeinit = 0;
354
-           foreach ($dirfiles as $key => $indfile) {
355
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
356
-                    $mbSize = round($fileSizeinit / 1024, 4);
357
-                    $totalflsizeinit += $mbSize;
358
-           }
359
-
360
-           $totalflsize = round($totalflsizeinit, 4);
361
-
362
-           return $totalflsize;
363
-    }
364
-
365
-
366
-    /**
367
-     * @NoAdminRequired
368
-     */
369
-    public function pickfile($path) {
370
-
371
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
372
-               $this->folder->newFolder('SMS_Relentless/temp_files');
373
-           }
374
-
375
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
376
-
377
-           $fltgt = $datadir . $this->userId . "/files" . $path;
378
-
379
-           $fileContent = file_get_contents($fltgt);
380
-
381
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
382
-
383
-           $patharr = explode("/", $path);
384
-
385
-           $revarr = array_reverse($patharr);
386
-
387
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
388
-
389
-           $target = $this->folder->newFile($relflpath);
390
-
391
-           $target->putContent($fileContent);
392
-
393
-           // Get the cumulative files size of the uploaded files
394
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
395
-
396
-           $fileSystemIterator = new FilesystemIterator($targetdir);
397
-
398
-           $dirfiles = [];
399
-           foreach ($fileSystemIterator as $fileInfo) {
400
-                    $dirfiles[] = $fileInfo->getFilename();
401
-           }
402
-
403
-           $totalflsizeinit = 0;
404
-
405
-           foreach ($dirfiles as $key => $indfile) {
406
-
407
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
408
-                    $mbSize = round($fileSizeinit / 1024, 4);
409
-                    $totalflsizeinit += $mbSize;
410
-           }
411
-
412
-           $totalflsize = round($totalflsizeinit, 4);
413
-
414
-           $pickresult = [$totalflsize, $pkfilesize];
415
-
416
-           return $pickresult;
417
-    }
418
-
419
-
420
-    /**
421
-     * @NoAdminRequired
422
-     */
423
-    public function removeupfile($removedfilename) {
424
-
425
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
426
-
427
-           $removefile = $this->view->unlink($tmpfl);
428
-
429
-           // Get the cumulative files size of the uploaded files
430
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
431
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
432
-           $fileSystemIterator = new FilesystemIterator($targetdir);
433
-
434
-           $dirfiles = [];
435
-           foreach ($fileSystemIterator as $fileInfo){
436
-                    $dirfiles[] = $fileInfo->getFilename();
437
-           }
438
-
439
-           $totalflsizeinit = 0;
440
-
441
-           foreach ($dirfiles as $key => $indfile) {
442
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
443
-                    $mbSize = round($fileSizeinit / 1024, 4);
444
-                    $totalflsizeinit += $mbSize;
445
-           }
446
-
447
-           $totalflsize = round($totalflsizeinit, 4);
448
-
449
-           return $totalflsize;
450
-    }
451
-
452
-
453
-    /**
454
-     * @NoAdminRequired
455
-     */
456
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
457
-
458
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
459
-         $telnyxkey = $telsmsapicred[0];
460
-         $teldelrecurl = $telsmsapicred[3];
461
-         $messagingprofid = $telsmsapicred[4];
462
-         $addDisplName = $telsmsapicred[24];
463
-
464
-         // Get the Display Name of the current user
465
-         $crtuser = $this->userManager->get($this->userId);
466
-         $displayname = $crtuser->getDisplayName();
467
-
468
-         if ($addDisplName == 1) {
469
-             $sentsmstext = $displayname . ": " . $sentsmstext;
470
-         }
471
-
472
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
473
-
474
-         $microinterval = $waitinterval * 1000;
475
-
476
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
477
-
478
-             usleep($microinterval);
479
-
480
-             $messagedate = date("Y-m-d H:i:s");
481
-
482
-             if ($ismms == 0) {
483
-
484
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
485
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
486
-                 } else {
487
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
488
-                 }
489
-
490
-                 $messagetexttel = $sentsmstext;
491
-
492
-             } else {
493
-
494
-                 $mediaURLarr = [];
495
-                 $includedMediaFiles = '';
496
-
497
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
498
-
499
-                      $userroot = $this->view->getRoot();
500
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
501
-
502
-                      $flsharetarget = $this->folder->newFile($filetoshare);
503
-
504
-	              $share = $this->shareManager->newShare();
505
-	              $share->setNode($flsharetarget);
506
-	              $share->setPermissions(Constants::PERMISSION_READ);
507
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
508
-	              $share->setSharedBy($this->userId);
509
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
510
-                      $expirydate->add(new \DateInterval('P1D'));
511
-                      $share->setExpirationDate($expirydate);
512
-                      $shared = $this->shareManager->createShare($share);
513
-                      $shareToken = $shared->getToken();
514
-
515
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
516
-
517
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
518
-
519
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
520
-                 }
521
-
522
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
523
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
524
-                 } else {
525
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
526
-                 }
527
-
528
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
529
-             }
530
-
531
-             $messageid = $message['id'];
532
-             $messagefrom = "Telnyx: " . $fromsender;
533
-             $messageto = $tonumber;
534
-             $messagenetwork = null;
535
-             $messageprice = null;
536
-             $messagestatus = $message['to'][0]['status'];
537
-             $messagedelivery = null;
538
-
539
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
540
-
541
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
542
-         }
543
-         return $displayname;
544
-    }
545
-
546
-
547
-    /**
548
-     * @NoAdminRequired
549
-     */
550
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
551
-
552
-         $plsmsapicred = $this->service->getapicredentials($this->userId);
553
-
554
-         $smsapikey = $plsmsapicred[5];
555
-         $smsapisecret = $plsmsapicred[6];
556
-         $smsapideliveryrecurl = $plsmsapicred[8];
557
-         $addDisplName = $plsmsapicred[24];
558
-
559
-         // Get the Display Name of the current user
560
-         $crtuser = $this->userManager->get($this->userId);
561
-         $displayname = $crtuser->getDisplayName();
562
-
563
-         if ($addDisplName == 1) {
564
-             $sentsmstext = $displayname . ": " . $sentsmstext;
565
-         }
566
-
567
-         $microinterval = $waitinterval * 1000;
568
-
569
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
570
-
571
-             usleep($microinterval);
572
-
573
-             $messagedatepl = date("Y-m-d H:i:s");
574
-
575
-             if ($ismms == 0) {
576
-
577
-                 $client = new RestClient($smsapikey, $smsapisecret);
578
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
579
-                 $messagetextpl = $sentsmstext;
580
-	         $messageidinit = $response->getmessageUuid(0);
581
-                 $messageid = $messageidinit[0];
582
-
583
-                 if (property_exists($response, 'error')) { 
584
-                     $messagestatus = "Error: " . $response->error;
585
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
586
-
587
-             } else {
588
-
589
-                 $mediaURLarr = [];
590
-                 $includedMediaFiles = '';
591
-
592
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
593
-
594
-                      $userroot = $this->view->getRoot();
595
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
596
-
597
-                      $flsharetarget = $this->folder->newFile($filetoshare);
598
-
599
-	              $share = $this->shareManager->newShare();
600
-	              $share->setNode($flsharetarget);
601
-	              $share->setPermissions(Constants::PERMISSION_READ);
602
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
603
-	              $share->setSharedBy($this->userId);
604
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
605
-                      $expirydate->add(new \DateInterval('P1D'));
606
-                      $share->setExpirationDate($expirydate);
607
-                      $shared = $this->shareManager->createShare($share);
608
-                      $shareToken = $shared->getToken();
609
-
610
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
611
-
612
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
613
-
614
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
615
-                 }
616
-
617
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
618
-		 $postedparamspl = json_encode($datatosendpl);
619
-
620
-		 $chpl = curl_init();
621
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
622
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
623
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
624
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
625
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
626
-		 curl_setopt($chpl, CURLOPT_POST, 1);
627
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
628
-		 $resultpl = curl_exec ($chpl);
629
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
630
-		 curl_close ($chpl);
631
-
632
-		 $decresultpl = json_decode($resultpl);
633
-
634
-                 if ($decresultpl) {
635
-                     if (property_exists($decresultpl, 'message_uuid')) {
636
-                         $messageidinit = $decresultpl->message_uuid;
637
-                         $messageid = $messageidinit[0];
638
-                     } else { $messageid = 'n/a'; }
639
-                 } else { $messageid = 'n/a'; }
640
-
641
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
642
-
643
-                     if (property_exists($decresultpl, 'error')) {
644
-                         $messagestatus = "Error: " . $decresultpl->error;
645
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
646
-
647
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
648
-
649
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
650
-             }
651
-
652
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
653
-                 $messagefrom = "Plivo: " . $fromsender;
654
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
655
-
656
-             $messageto = $tonumber;
657
-             $messagenetwork = '';
658
-             $messageprice = '';
659
-
660
-             $messagedelivery = '';
661
-
662
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
663
-
664
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
665
-         }
666
-         return $displayname;
667
-    }
668
-
669
-
670
-    /**
671
-     * @NoAdminRequired
672
-     */
673
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
674
-
675
-         $twsmsapicred = $this->service->getapicredentials($this->userId);
676
-
677
-         $sid = $twsmsapicred[15];
678
-         $token = $twsmsapicred[16];
679
-         $smsapirecurltw = $twsmsapicred[18];
680
-         $addDisplName = $twsmsapicred[24];
681
-
682
-         // Get the Display Name of the current user
683
-         $crtuser = $this->userManager->get($this->userId);
684
-         $displayname = $crtuser->getDisplayName();
685
-
686
-         if ($addDisplName == 1) {
687
-             $sentsmstext = $displayname . ": " . $sentsmstext;
688
-         }
689
-
690
-         $microinterval = $waitinterval * 1000;
691
-
692
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
693
-
694
-             usleep($microinterval);
695
-
696
-             $messagedatetw = date("Y-m-d H:i:s");
697
-
698
-             if ($ismms == 0) {
699
-
700
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
701
-                 $sentsmstextfintw = $sentsmstext;
702
-
703
-             } else {
704
-
705
-                 $mediaURLs = [];
706
-                 $includedMediaFiles = '';
707
-
708
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
709
-
710
-                      $userroot = $this->view->getRoot();
711
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
712
-
713
-                      $flsharetarget = $this->folder->newFile($filetoshare);
714
-
715
-	              $share = $this->shareManager->newShare();
716
-	              $share->setNode($flsharetarget);
717
-	              $share->setPermissions(Constants::PERMISSION_READ);
718
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
719
-	              $share->setSharedBy($this->userId);
720
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
721
-                      $expirydate->add(new \DateInterval('P1D'));
722
-                      $share->setExpirationDate($expirydate);
723
-                      $shared = $this->shareManager->createShare($share);
724
-                      $shareToken = $shared->getToken();
725
-
726
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
727
-
728
-                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
729
-
730
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
731
-                 }
732
-
733
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
734
-
735
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
736
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
737
-                 }
738
-
739
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
740
-             }
741
-
742
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
743
-
744
-	     $chtw = curl_init();
745
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
746
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
747
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
748
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
749
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
750
-	     curl_setopt($chtw, CURLOPT_POST, 1);
751
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
752
-
753
-	     $resulttw = curl_exec ($chtw);
754
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
755
-	     curl_close ($chtw);
756
-
757
-             $decresulttw = json_decode($resulttw);
758
-
759
-             if ($decresulttw) {
760
-                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
761
-             } else { $messageidtw = 'n/a'; }
762
-
763
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
764
-                 $messagestatustw = 'The message has been accepted for delivery.';
765
-             } else {
766
-                 $messagestatustw = 'An error occurred while trying to send the message.';
767
-             }
768
-
769
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
770
-                 $messagefromtw = "Twilio: " . $fromsender;
771
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
772
-
773
-             $messagenetworktw = '';
774
-             $messagepricetw = '';
775
-             $messagedeliverytw = '';
776
-
777
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
778
-
779
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
780
-         }
781
-         return $displayname;
782
-    }
783
-
784
-
785
-    /**
786
-     * @NoAdminRequired
787
-     */
788
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
789
-
790
-         $flsmsapicred = $this->service->getapicredentials($this->userId);
791
-
792
-         $flowapikey = $flsmsapicred[20];
793
-         $flowapisecret = $flsmsapicred[21];
794
-         $flowdelrecurl = $flsmsapicred[23];
795
-         $addDisplName = $flsmsapicred[24];
796
-
797
-         // Get the Display Name of the current user
798
-         $crtuser = $this->userManager->get($this->userId);
799
-         $displayname = $crtuser->getDisplayName();
800
-
801
-         if ($addDisplName == 1) {
802
-             $sentsmstext = $displayname . ": " . $sentsmstext;
803
-         }
804
-
805
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
806
-
807
-         $microinterval = $waitinterval * 1000;
808
-
809
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
810
-
811
-             usleep($microinterval);
812
-
813
-             $messagedatefl = date("Y-m-d H:i:s");
814
-
815
-             if ($ismms == 0) {
816
-
817
-                 $messagetextfinfl = $sentsmstext;
818
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
819
-
820
-             } else {
821
-
822
-		 $mediaurlsarr = [];
823
-		 $includedMediaFiles = '';
824
-
825
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
826
-
827
-		      $userroot = $this->view->getRoot();
828
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
829
-
830
-		      $flsharetarget = $this->folder->newFile($filetoshare);
831
-
832
-		      $share = $this->shareManager->newShare();
833
-		      $share->setNode($flsharetarget);
834
-		      $share->setPermissions(Constants::PERMISSION_READ);
835
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
836
-		      $share->setSharedBy($this->userId);
837
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
838
-                      $expirydate->add(new \DateInterval('P1D'));
839
-                      $share->setExpirationDate($expirydate);
840
-		      $shared = $this->shareManager->createShare($share);
841
-		      $shareToken = $shared->getToken();
842
-
843
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
844
-
845
-		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
846
-
847
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
848
-		 }
849
-
850
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
851
-
852
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
853
-             }
854
-
855
-	     $chfl = curl_init();
856
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
857
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
858
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
859
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
860
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
861
-	     curl_setopt($chfl, CURLOPT_POST, 1);
862
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
863
-	     $resultfl = curl_exec ($chfl);
864
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
865
-	     curl_close ($chfl);
866
-
867
-             $decresultfl = json_decode($resultfl);
868
-
869
-             if ($decresultfl) {
870
-                 if (property_exists($decresultfl, 'data')) { 
871
-                     $messageidfl = $decresultfl->data->id;
872
-                 } else { $messageidfl = 'n/a'; }
873
-             } else { $messageidfl = 'n/a'; }
874
-
875
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
876
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
877
-             } else { 
878
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
879
-             }
880
-
881
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
882
-                 $messagefromfl = "Flowroute: " . $fromsender;
883
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
884
-
885
-             $messagetofl = $tonumberfl;
886
-             $messagenetworkfl = '';
887
-             $messagepricefl = '';
888
-             $messagedeliveryfl = '';
889
-
890
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
891
-
892
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
893
-         }
894
-         return $displayname;
895
-    }
896
-
897
-
898
-    /**
899
-     * @NoAdminRequired
900
-     */
901
-    public function saveoldrecrows($userId, $oldrecRows) {
902
-
903
-           // Create the folder for removed messages if it doesn't exist
904
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
905
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
906
-           }
907
-           $savecheck = 0;
908
-
909
-           if (count($oldrecRows) > 1) {
910
-               $msfileContent = implode("", $oldrecRows);
911
-
912
-               $delrowsdate = date("Y-m-d_H-i-s");
913
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
914
-
915
-               $userroot = $this->view->getRoot();
916
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
917
-
918
-               $target = $this->folder->newFile($targetfile);
919
-               $target->putContent($msfileContent);
920
-
921
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
922
-                   $savecheck = 1;
923
-               }
924
-           }
925
-
926
-           return $savecheck;
927
-    }
928
-
929
-
930
-    /**
931
-     * @NoAdminRequired
932
-     */
933
-    public function saveoldsentrows($userId, $oldsentRows) {
934
-
935
-           // Create the folder for removed messages if it doesn't exist
936
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
937
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
938
-           }
939
-           $savesentcheck = 0;
940
-
941
-           if (count($oldsentRows) > 1) {
942
-               $sntfileContent = implode("", $oldsentRows);
943
-
944
-               $delsentrowsdate = date("Y-m-d_H-i-s");
945
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
946
-
947
-               $userroot = $this->view->getRoot();
948
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
949
-
950
-               $snttarget = $this->folder->newFile($snttargetfile);
951
-               $snttarget->putContent($sntfileContent);
952
-
953
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
954
-                   $savesentcheck = 1;
955
-               }
956
-           }
957
-
958
-           return $savesentcheck;
959
-    }
960
-
961
-
962
-    /**
963
-     * @NoAdminRequired
964
-     */
965
-    public function getreceivedtable($userId) {
966
-           return $this->service->getreceivedtable($this->userId);
967
-    }
968
-
969
-    /**
970
-     * @NoAdminRequired
971
-     */
972
-    public function getreceivedtablefordel($userId) {
973
-           return $this->service->getreceivedtablefordel($this->userId);
974
-    }
975
-
976
-    /**
977
-     * @NoAdminRequired
978
-     */
979
-    public function removerecrows($userId, $recmessagedbIDs) {
980
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
981
-    }
982
-
983
-    /**
984
-     * @NoAdminRequired
985
-     */
986
-    public function getsenttable($userId) {
987
-           return $this->service->getsenttable($this->userId);
988
-    }
989
-
990
-    /**
991
-     * @NoAdminRequired
992
-     */
993
-    public function getsenttablefordel($userId) {
994
-           return $this->service->getsenttablefordel($this->userId);
995
-    }
996
-
997
-    /**
998
-     * @NoAdminRequired
999
-     */
1000
-    public function removesentrows($userId, $sentmessagedbIDs) {
1001
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1002
-    }
1003
-
1004
-    /**
1005
-     * @NoAdminRequired
1006
-     */
1007
-    public function getconversations($userId) {
1008
-           return $this->service->getconversations($this->userId);
1009
-    }
1010
-
1011
-    /**
1012
-     * @NoAdminRequired
1013
-     */
1014
-    public function archiveconv($userId, $conversationId) {
1015
-
1016
-           // Get the Display Name of the current user
1017
-           $crtusergt = $this->userManager->get($this->userId);
1018
-           $userDspNameArch = $crtusergt->getDisplayName();
1019
-
1020
-           return $this->service->archiveconv($this->userId, $userDspNameArch, $conversationId);
1021
-    }
1022
-
1023
-    /**
1024
-     * @NoAdminRequired
1025
-     */
1026
-    public function unarchiveconv($userId, $conversationId) {
1027
-
1028
-           // Get the Display Name of the current user
1029
-           $crtusergtun = $this->userManager->get($this->userId);
1030
-           $userDspNameUnarch = $crtusergtun->getDisplayName();
1031
-
1032
-           return $this->service->unarchiveconv($this->userId, $userDspNameUnarch, $conversationId);
1033
-    }
1034
-
1035
-    /**
1036
-     * @NoAdminRequired
1037
-     */
1038
-    public function saveconvdescription($userId, $convDescription, $convId) {
1039
-
1040
-           // Get the Display Name of the current user
1041
-           $crtuserdesc = $this->userManager->get($this->userId);
1042
-           $userDspNameDesc = $crtuserdesc->getDisplayName();
1043
-
1044
-           return $this->service->saveconvdescription($this->userId, $userDspNameDesc, $convDescription, $convId);
1045
-    }
1046
-
1047
-    /**
1048
-     * @NoAdminRequired
1049
-     */
1050
-    public function saveconvtag($userId, $convTag, $convId) {
1051
-
1052
-           // Get the Display Name of the current user
1053
-           $crtusertag = $this->userManager->get($this->userId);
1054
-           $userDspNameTag = $crtusertag->getDisplayName();
1055
-
1056
-           return $this->service->saveconvtag($this->userId, $userDspNameTag, $convTag, $convId);
1057
-    }
1058
-
1059
-    /**
1060
-     * @NoAdminRequired
1061
-     */
1062
-    public function saveconvflag($userId, $convFlag, $convId) {
1063
-
1064
-           // Get the Display Name of the current user
1065
-           $crtuserflag = $this->userManager->get($this->userId);
1066
-           $userDspNameFlag = $crtuserflag->getDisplayName();
1067
-
1068
-           return $this->service->saveconvflag($this->userId, $userDspNameFlag, $convFlag, $convId);
1069
-    }
1070
-
1071
-    /**
1072
-     * @NoAdminRequired
1073
-     */
1074
-    public function removeconvmsgs($userId, $conversationId) {
1075
-           return $this->service->removeconvmsgs($this->userId, $conversationId);
1076
-    }
1077
-
1078
-    /**
1079
-     * @NoAdminRequired
1080
-     */
1081
-    public function getgroupedtable($userId) {
1082
-           return $this->service->getgroupedtable($this->userId);
1083
-    }
1084
-
1085
-    /**
1086
-     * @NoAdminRequired
1087
-     */
1088
-    public function savedisplayname($userId, $authorDisplayname, $from) {
1089
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1090
-    }
1091
-
1092
-    /**
1093
-     * @NoAdminRequired
1094
-     */
1095
-    public function getmsgsperpgnewmsgarchnb($userId) {
1096
-           return $this->service->getmsgsperpgnewmsgarchnb($this->userId);
1097
-    }
1098
-
1099
-    /**
1100
-     * @NoAdminRequired
1101
-     */
1102
-    public function getnewmsgindicator($userId) {
1103
-           return $this->service->getnewmsgindicator($this->userId);
1104
-    }
1105
-
1106
-    /**
1107
-     * @NoAdminRequired
1108
-     */
1109
-    public function getdelrecsettings($userId) {
1110
-           return $this->service->getdelrecsettings($this->userId);
1111
-    }
1112
-
1113
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1114
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1115
-    }
1116
-
1117
-    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1118
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1119
-    }
1120
-
1121
-    public function removenumberrestrictions($userId, $phoneNumber) {
1122
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1123
-    }
1124
-
1125
-    /**
1126
-     * @NoAdminRequired
1127
-     */
1128
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1129
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1130
-    }
1131
-
1132
-    /**
1133
-     * @NoAdminRequired
1134
-     */
1135
-    public function removeautoreplies($userId, $phoneNumber) {
1136
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1137
-    }
1138
-
1139
-    /**
1140
-     * @NoAdminRequired
1141
-     */
1142
-    public function getsettings($userId) {
1143
-           return $this->service->getsettings($this->userId);
1144
-    }
1145
-
1146
-    public function getadminsettings($userId) {
1147
-           return $this->service->getadminsettings($this->userId);
1148
-    }
1149
-
1150
-    /**
1151
-     * @NoAdminRequired
1152
-     */
1153
-    public function getautoreplyconf($userId) {
1154
-
1155
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1156
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1157
-
1158
-           // Get the display name of the current user
1159
-           $usrid = $this->userId;
1160
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1161
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1162
-	   $getusrdnmdata = $getusrdnmres->fetch();
1163
-	   $userDisplayNm = $getusrdnmdata['value'];
1164
-	   $getusrdnmres->closeCursor();
1165
-
1166
-           // Get the auto-replies for the available phone numbers
1167
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1168
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1169
-	   $getautorplres = $getautorpl->execute();
1170
-           $autorplconf = [];
1171
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1172
-                  $autorplconf[] = $acdatausrdnadm;
1173
-           }
1174
-	   $getautorplres->closeCursor();
1175
-
1176
-           if ($autorplconf) {
1177
-
1178
-               $autoreplyconf = [];
1179
-               foreach ($autorplconf as $arkey => $arvalue) {
1180
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1181
-                            $autoreplyconf[] = $arvalue;
1182
-                        }
1183
-               }
1184
-
1185
-           } else { $autoreplyconf = ''; }
1186
-
1187
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1188
-
1189
-           return $autoreplyfdb;
1190
-    }
1191
-
1192
-    /**
1193
-     * @NoAdminRequired
1194
-     */
1195
-    public function getgroupedpernumber($userId, $phoneNumber) {
1196
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1197
-    }
1198
-
1199
-    /**
1200
-     * @NoAdminRequired
1201
-     */
1202
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1203
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1204
-    }
1205
-
1206
-    /**
1207
-     * @NoAdminRequired
1208
-     */
1209
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1210
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1211
-    }
1212
-
1213
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1214
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1215
-    }
1216
-
1217
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1218
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1219
-    }
1220
-}
Browse code

added Conversations page and improved mobile compatibility

DoubleBastionAdmin authored on 02/04/2024 00:47:37
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1220 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\Share\IManager;
49
+use OCP\Constants;
50
+use OCP\IGroupManager;
51
+use OCP\IDBConnection;
52
+use OCP\IUserManager;
53
+use OC\URLGenerator;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $shareManager;
64
+    private $groupManager;
65
+    private $connection;
66
+    private $userManager;
67
+    private $urlGenerator;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->shareManager = $shareManager;
78
+        $this->groupManager = $groupManager;
79
+        $this->connection = $connection;
80
+        $this->userManager = $userManager;
81
+        $this->urlGenerator = $urlGenerator;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getappdirectory($userId) {
120
+        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
+        $apprelpatharr = explode("/", $apprelpath);
122
+        $currentappdir = $apprelpatharr[1];
123
+        return $currentappdir;
124
+    }
125
+
126
+
127
+    /**
128
+     * @NoAdminRequired
129
+     */
130
+    public function getbalancetel($userId) {
131
+
132
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
133
+
134
+        $telapikey = $telsmsapicred[0];
135
+        $ch = curl_init();
136
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
137
+
138
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
139
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
140
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
141
+        $responsetel = curl_exec($ch);
142
+        $recdatatel = json_decode($responsetel, TRUE);
143
+        $telbalresponse = $recdatatel['data']['balance'];
144
+        $currentbalancetel = round(floatval($telbalresponse), 3);
145
+        curl_close($ch);
146
+
147
+        return $currentbalancetel;
148
+    }
149
+
150
+
151
+    /**
152
+     * @NoAdminRequired
153
+     */
154
+    public function getbalancenex($userId) {
155
+
156
+        $smsapicred = $this->service->getapicredentials($this->userId);
157
+        $smsapikey = $smsapicred[5];
158
+        $smsapisecret = $smsapicred[6];
159
+
160
+        if ($smsapikey == '' || $smsapisecret == '') {
161
+            $currentbalancenex = "N/A";
162
+        } else {
163
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
164
+            $mesdata = file_get_contents($getmesdata);
165
+            $datainit = json_decode($mesdata);
166
+            $balancenex = $datainit->cash_credits;
167
+            $currentbalancenex = round(floatval($balancenex), 3);
168
+        }
169
+        return $currentbalancenex;
170
+    }
171
+
172
+
173
+    /**
174
+     * @NoAdminRequired
175
+     */
176
+    public function getbalancetwil($userId) {
177
+
178
+        $smsapicred = $this->service->getapicredentials($this->userId);
179
+        $smsapisid = $smsapicred[15];
180
+        $smsapitoken = $smsapicred[16];
181
+
182
+        if ($smsapisid == '' || $smsapitoken == '') {
183
+            $currentbalancetwil = "N/A";
184
+        } else {
185
+
186
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
187
+            $balancetwil = $twilbalance->balance;
188
+
189
+            $currentbalancetwil = round(floatval($balancetwil), 3);
190
+        }
191
+        return $currentbalancetwil;
192
+    }
193
+
194
+
195
+    /**
196
+     * @NoAdminRequired
197
+     */
198
+    public function getbalanceflow($userId) {
199
+
200
+        $currentbalanceflow = 'n/a';
201
+        return $currentbalanceflow;
202
+    }
203
+
204
+
205
+    /**
206
+     * @NoAdminRequired
207
+     */
208
+    public function getsmsnumbers($userId) {
209
+
210
+        return $this->service->getsmsnumbers($this->userId);
211
+    }
212
+
213
+
214
+    /**
215
+     * @NoAdminRequired
216
+     */
217
+    public function refreshavailablenumbers($userId) {
218
+
219
+        return $this->service->refreshavailablenumbers($this->userId);
220
+    }
221
+
222
+
223
+    /**
224
+     * @NoAdminRequired
225
+     */
226
+    public function cleantempdir($userId) {
227
+
228
+        // Create the temporary folder if it doesn't exist
229
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
230
+            $this->folder->newFolder('SMS_Relentless/temp_files');
231
+        }
232
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
233
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
234
+        $fileSystemIterator = new FilesystemIterator($targetdir);
235
+
236
+        $dirfiles = [];
237
+        foreach ($fileSystemIterator as $fileInfo) {
238
+                 $dirfiles[] = $fileInfo->getFilename();
239
+        }
240
+
241
+        foreach ($dirfiles as $key => $indfile) {
242
+                 $thisuserroot = $this->view->getRoot();
243
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
244
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
245
+        }
246
+     }
247
+
248
+
249
+    /**
250
+     * @NoAdminRequired
251
+     */
252
+    public function cleanmultrecdir($userId) {
253
+
254
+        // Create the temporary folder if it doesn't exist
255
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
256
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
257
+        }
258
+        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
259
+        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
260
+        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
261
+
262
+        $dirfilesmrc = [];
263
+        foreach ($fileSystemIteratormrc as $fileInfomrc){
264
+                 $dirfilesmrc[] = $fileInfomrc->getFilename();
265
+        }
266
+
267
+        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
268
+                 $thisuserrootmrc = $this->view->getRoot();
269
+                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
270
+                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
271
+        }
272
+     }
273
+
274
+
275
+    /**
276
+     * @NoAdminRequired
277
+     */
278
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
279
+
280
+        // Create the temporary folder if it doesn't exist
281
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
282
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
283
+        }
284
+
285
+        // First delete any file that has been previously uploaded
286
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
287
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
288
+        $fileSystemIterator = new FilesystemIterator($targetdir);
289
+
290
+        $dirfiles = [];
291
+        foreach ($fileSystemIterator as $fileInfo){
292
+                 $dirfiles[] = $fileInfo->getFilename();
293
+        }
294
+
295
+        foreach ($dirfiles as $key => $indfile) {
296
+                 $thisuserroot = $this->view->getRoot();
297
+                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
298
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
299
+        }
300
+
301
+        // Upload the new file
302
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
303
+        $fileName = $_FILES['uploadfileforsms']['name'];
304
+
305
+        $userroot = $this->view->getRoot();
306
+        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
307
+
308
+        $target = $this->folder->newFile($targetfile);
309
+        $target->putContent($fileContent);
310
+
311
+        // Extract the phone numbers from the file
312
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
313
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
314
+        $numberarrayfourth = explode(",", $numberarraytert);
315
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
316
+        $numberarray = array_unique($numberarrayfifth);
317
+
318
+        return $numberarray;
319
+    }
320
+
321
+
322
+    /**
323
+     * @NoAdminRequired
324
+     */
325
+    public function uploadfile($uploadfileformms) {
326
+
327
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
328
+           $fileName = $_FILES['uploadfileformms']['name'];
329
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
330
+           $fileSize = $fileSizeinit / 1024;
331
+
332
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
333
+               $this->folder->newFolder('SMS_Relentless/temp_files');
334
+           }
335
+
336
+           $userroot = $this->view->getRoot();
337
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
338
+
339
+           $target = $this->folder->newFile($targetfile);
340
+           $target->putContent($fileContent);
341
+
342
+           // Get the cumulative files size of the uploaded files
343
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
344
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
345
+
346
+           $fileSystemIterator = new FilesystemIterator($targetdir);
347
+
348
+           $dirfiles = [];
349
+           foreach ($fileSystemIterator as $fileInfo){
350
+                    $dirfiles[] = $fileInfo->getFilename();
351
+           }
352
+
353
+           $totalflsizeinit = 0;
354
+           foreach ($dirfiles as $key => $indfile) {
355
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
356
+                    $mbSize = round($fileSizeinit / 1024, 4);
357
+                    $totalflsizeinit += $mbSize;
358
+           }
359
+
360
+           $totalflsize = round($totalflsizeinit, 4);
361
+
362
+           return $totalflsize;
363
+    }
364
+
365
+
366
+    /**
367
+     * @NoAdminRequired
368
+     */
369
+    public function pickfile($path) {
370
+
371
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
372
+               $this->folder->newFolder('SMS_Relentless/temp_files');
373
+           }
374
+
375
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
376
+
377
+           $fltgt = $datadir . $this->userId . "/files" . $path;
378
+
379
+           $fileContent = file_get_contents($fltgt);
380
+
381
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
382
+
383
+           $patharr = explode("/", $path);
384
+
385
+           $revarr = array_reverse($patharr);
386
+
387
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
388
+
389
+           $target = $this->folder->newFile($relflpath);
390
+
391
+           $target->putContent($fileContent);
392
+
393
+           // Get the cumulative files size of the uploaded files
394
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
395
+
396
+           $fileSystemIterator = new FilesystemIterator($targetdir);
397
+
398
+           $dirfiles = [];
399
+           foreach ($fileSystemIterator as $fileInfo) {
400
+                    $dirfiles[] = $fileInfo->getFilename();
401
+           }
402
+
403
+           $totalflsizeinit = 0;
404
+
405
+           foreach ($dirfiles as $key => $indfile) {
406
+
407
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
408
+                    $mbSize = round($fileSizeinit / 1024, 4);
409
+                    $totalflsizeinit += $mbSize;
410
+           }
411
+
412
+           $totalflsize = round($totalflsizeinit, 4);
413
+
414
+           $pickresult = [$totalflsize, $pkfilesize];
415
+
416
+           return $pickresult;
417
+    }
418
+
419
+
420
+    /**
421
+     * @NoAdminRequired
422
+     */
423
+    public function removeupfile($removedfilename) {
424
+
425
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
426
+
427
+           $removefile = $this->view->unlink($tmpfl);
428
+
429
+           // Get the cumulative files size of the uploaded files
430
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
431
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
432
+           $fileSystemIterator = new FilesystemIterator($targetdir);
433
+
434
+           $dirfiles = [];
435
+           foreach ($fileSystemIterator as $fileInfo){
436
+                    $dirfiles[] = $fileInfo->getFilename();
437
+           }
438
+
439
+           $totalflsizeinit = 0;
440
+
441
+           foreach ($dirfiles as $key => $indfile) {
442
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
443
+                    $mbSize = round($fileSizeinit / 1024, 4);
444
+                    $totalflsizeinit += $mbSize;
445
+           }
446
+
447
+           $totalflsize = round($totalflsizeinit, 4);
448
+
449
+           return $totalflsize;
450
+    }
451
+
452
+
453
+    /**
454
+     * @NoAdminRequired
455
+     */
456
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
457
+
458
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
459
+         $telnyxkey = $telsmsapicred[0];
460
+         $teldelrecurl = $telsmsapicred[3];
461
+         $messagingprofid = $telsmsapicred[4];
462
+         $addDisplName = $telsmsapicred[24];
463
+
464
+         // Get the Display Name of the current user
465
+         $crtuser = $this->userManager->get($this->userId);
466
+         $displayname = $crtuser->getDisplayName();
467
+
468
+         if ($addDisplName == 1) {
469
+             $sentsmstext = $displayname . ": " . $sentsmstext;
470
+         }
471
+
472
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
473
+
474
+         $microinterval = $waitinterval * 1000;
475
+
476
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
477
+
478
+             usleep($microinterval);
479
+
480
+             $messagedate = date("Y-m-d H:i:s");
481
+
482
+             if ($ismms == 0) {
483
+
484
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
485
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
486
+                 } else {
487
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
488
+                 }
489
+
490
+                 $messagetexttel = $sentsmstext;
491
+
492
+             } else {
493
+
494
+                 $mediaURLarr = [];
495
+                 $includedMediaFiles = '';
496
+
497
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
498
+
499
+                      $userroot = $this->view->getRoot();
500
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
501
+
502
+                      $flsharetarget = $this->folder->newFile($filetoshare);
503
+
504
+	              $share = $this->shareManager->newShare();
505
+	              $share->setNode($flsharetarget);
506
+	              $share->setPermissions(Constants::PERMISSION_READ);
507
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
508
+	              $share->setSharedBy($this->userId);
509
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
510
+                      $expirydate->add(new \DateInterval('P1D'));
511
+                      $share->setExpirationDate($expirydate);
512
+                      $shared = $this->shareManager->createShare($share);
513
+                      $shareToken = $shared->getToken();
514
+
515
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
516
+
517
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
518
+
519
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
520
+                 }
521
+
522
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
523
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
524
+                 } else {
525
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
526
+                 }
527
+
528
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
529
+             }
530
+
531
+             $messageid = $message['id'];
532
+             $messagefrom = "Telnyx: " . $fromsender;
533
+             $messageto = $tonumber;
534
+             $messagenetwork = null;
535
+             $messageprice = null;
536
+             $messagestatus = $message['to'][0]['status'];
537
+             $messagedelivery = null;
538
+
539
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
540
+
541
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
542
+         }
543
+         return $displayname;
544
+    }
545
+
546
+
547
+    /**
548
+     * @NoAdminRequired
549
+     */
550
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
551
+
552
+         $plsmsapicred = $this->service->getapicredentials($this->userId);
553
+
554
+         $smsapikey = $plsmsapicred[5];
555
+         $smsapisecret = $plsmsapicred[6];
556
+         $smsapideliveryrecurl = $plsmsapicred[8];
557
+         $addDisplName = $plsmsapicred[24];
558
+
559
+         // Get the Display Name of the current user
560
+         $crtuser = $this->userManager->get($this->userId);
561
+         $displayname = $crtuser->getDisplayName();
562
+
563
+         if ($addDisplName == 1) {
564
+             $sentsmstext = $displayname . ": " . $sentsmstext;
565
+         }
566
+
567
+         $microinterval = $waitinterval * 1000;
568
+
569
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
570
+
571
+             usleep($microinterval);
572
+
573
+             $messagedatepl = date("Y-m-d H:i:s");
574
+
575
+             if ($ismms == 0) {
576
+
577
+                 $client = new RestClient($smsapikey, $smsapisecret);
578
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
579
+                 $messagetextpl = $sentsmstext;
580
+	         $messageidinit = $response->getmessageUuid(0);
581
+                 $messageid = $messageidinit[0];
582
+
583
+                 if (property_exists($response, 'error')) { 
584
+                     $messagestatus = "Error: " . $response->error;
585
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
586
+
587
+             } else {
588
+
589
+                 $mediaURLarr = [];
590
+                 $includedMediaFiles = '';
591
+
592
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
593
+
594
+                      $userroot = $this->view->getRoot();
595
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
596
+
597
+                      $flsharetarget = $this->folder->newFile($filetoshare);
598
+
599
+	              $share = $this->shareManager->newShare();
600
+	              $share->setNode($flsharetarget);
601
+	              $share->setPermissions(Constants::PERMISSION_READ);
602
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
603
+	              $share->setSharedBy($this->userId);
604
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
605
+                      $expirydate->add(new \DateInterval('P1D'));
606
+                      $share->setExpirationDate($expirydate);
607
+                      $shared = $this->shareManager->createShare($share);
608
+                      $shareToken = $shared->getToken();
609
+
610
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
611
+
612
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
613
+
614
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
615
+                 }
616
+
617
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
618
+		 $postedparamspl = json_encode($datatosendpl);
619
+
620
+		 $chpl = curl_init();
621
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
622
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
623
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
624
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
625
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
626
+		 curl_setopt($chpl, CURLOPT_POST, 1);
627
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
628
+		 $resultpl = curl_exec ($chpl);
629
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
630
+		 curl_close ($chpl);
631
+
632
+		 $decresultpl = json_decode($resultpl);
633
+
634
+                 if ($decresultpl) {
635
+                     if (property_exists($decresultpl, 'message_uuid')) {
636
+                         $messageidinit = $decresultpl->message_uuid;
637
+                         $messageid = $messageidinit[0];
638
+                     } else { $messageid = 'n/a'; }
639
+                 } else { $messageid = 'n/a'; }
640
+
641
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
642
+
643
+                     if (property_exists($decresultpl, 'error')) {
644
+                         $messagestatus = "Error: " . $decresultpl->error;
645
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
646
+
647
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
648
+
649
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
650
+             }
651
+
652
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
653
+                 $messagefrom = "Plivo: " . $fromsender;
654
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
655
+
656
+             $messageto = $tonumber;
657
+             $messagenetwork = '';
658
+             $messageprice = '';
659
+
660
+             $messagedelivery = '';
661
+
662
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
663
+
664
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
665
+         }
666
+         return $displayname;
667
+    }
668
+
669
+
670
+    /**
671
+     * @NoAdminRequired
672
+     */
673
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
674
+
675
+         $twsmsapicred = $this->service->getapicredentials($this->userId);
676
+
677
+         $sid = $twsmsapicred[15];
678
+         $token = $twsmsapicred[16];
679
+         $smsapirecurltw = $twsmsapicred[18];
680
+         $addDisplName = $twsmsapicred[24];
681
+
682
+         // Get the Display Name of the current user
683
+         $crtuser = $this->userManager->get($this->userId);
684
+         $displayname = $crtuser->getDisplayName();
685
+
686
+         if ($addDisplName == 1) {
687
+             $sentsmstext = $displayname . ": " . $sentsmstext;
688
+         }
689
+
690
+         $microinterval = $waitinterval * 1000;
691
+
692
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
693
+
694
+             usleep($microinterval);
695
+
696
+             $messagedatetw = date("Y-m-d H:i:s");
697
+
698
+             if ($ismms == 0) {
699
+
700
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
701
+                 $sentsmstextfintw = $sentsmstext;
702
+
703
+             } else {
704
+
705
+                 $mediaURLs = [];
706
+                 $includedMediaFiles = '';
707
+
708
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
709
+
710
+                      $userroot = $this->view->getRoot();
711
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
712
+
713
+                      $flsharetarget = $this->folder->newFile($filetoshare);
714
+
715
+	              $share = $this->shareManager->newShare();
716
+	              $share->setNode($flsharetarget);
717
+	              $share->setPermissions(Constants::PERMISSION_READ);
718
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
719
+	              $share->setSharedBy($this->userId);
720
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
721
+                      $expirydate->add(new \DateInterval('P1D'));
722
+                      $share->setExpirationDate($expirydate);
723
+                      $shared = $this->shareManager->createShare($share);
724
+                      $shareToken = $shared->getToken();
725
+
726
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
727
+
728
+                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
729
+
730
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
731
+                 }
732
+
733
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
734
+
735
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
736
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
737
+                 }
738
+
739
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
740
+             }
741
+
742
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
743
+
744
+	     $chtw = curl_init();
745
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
746
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
747
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
748
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
749
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
750
+	     curl_setopt($chtw, CURLOPT_POST, 1);
751
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
752
+
753
+	     $resulttw = curl_exec ($chtw);
754
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
755
+	     curl_close ($chtw);
756
+
757
+             $decresulttw = json_decode($resulttw);
758
+
759
+             if ($decresulttw) {
760
+                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
761
+             } else { $messageidtw = 'n/a'; }
762
+
763
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
764
+                 $messagestatustw = 'The message has been accepted for delivery.';
765
+             } else {
766
+                 $messagestatustw = 'An error occurred while trying to send the message.';
767
+             }
768
+
769
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
770
+                 $messagefromtw = "Twilio: " . $fromsender;
771
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
772
+
773
+             $messagenetworktw = '';
774
+             $messagepricetw = '';
775
+             $messagedeliverytw = '';
776
+
777
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
778
+
779
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
780
+         }
781
+         return $displayname;
782
+    }
783
+
784
+
785
+    /**
786
+     * @NoAdminRequired
787
+     */
788
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
789
+
790
+         $flsmsapicred = $this->service->getapicredentials($this->userId);
791
+
792
+         $flowapikey = $flsmsapicred[20];
793
+         $flowapisecret = $flsmsapicred[21];
794
+         $flowdelrecurl = $flsmsapicred[23];
795
+         $addDisplName = $flsmsapicred[24];
796
+
797
+         // Get the Display Name of the current user
798
+         $crtuser = $this->userManager->get($this->userId);
799
+         $displayname = $crtuser->getDisplayName();
800
+
801
+         if ($addDisplName == 1) {
802
+             $sentsmstext = $displayname . ": " . $sentsmstext;
803
+         }
804
+
805
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
806
+
807
+         $microinterval = $waitinterval * 1000;
808
+
809
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
810
+
811
+             usleep($microinterval);
812
+
813
+             $messagedatefl = date("Y-m-d H:i:s");
814
+
815
+             if ($ismms == 0) {
816
+
817
+                 $messagetextfinfl = $sentsmstext;
818
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
819
+
820
+             } else {
821
+
822
+		 $mediaurlsarr = [];
823
+		 $includedMediaFiles = '';
824
+
825
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
826
+
827
+		      $userroot = $this->view->getRoot();
828
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
829
+
830
+		      $flsharetarget = $this->folder->newFile($filetoshare);
831
+
832
+		      $share = $this->shareManager->newShare();
833
+		      $share->setNode($flsharetarget);
834
+		      $share->setPermissions(Constants::PERMISSION_READ);
835
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
836
+		      $share->setSharedBy($this->userId);
837
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
838
+                      $expirydate->add(new \DateInterval('P1D'));
839
+                      $share->setExpirationDate($expirydate);
840
+		      $shared = $this->shareManager->createShare($share);
841
+		      $shareToken = $shared->getToken();
842
+
843
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
844
+
845
+		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
846
+
847
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
848
+		 }
849
+
850
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
851
+
852
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
853
+             }
854
+
855
+	     $chfl = curl_init();
856
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
857
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
858
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
859
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
860
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
861
+	     curl_setopt($chfl, CURLOPT_POST, 1);
862
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
863
+	     $resultfl = curl_exec ($chfl);
864
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
865
+	     curl_close ($chfl);
866
+
867
+             $decresultfl = json_decode($resultfl);
868
+
869
+             if ($decresultfl) {
870
+                 if (property_exists($decresultfl, 'data')) { 
871
+                     $messageidfl = $decresultfl->data->id;
872
+                 } else { $messageidfl = 'n/a'; }
873
+             } else { $messageidfl = 'n/a'; }
874
+
875
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
876
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
877
+             } else { 
878
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
879
+             }
880
+
881
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
882
+                 $messagefromfl = "Flowroute: " . $fromsender;
883
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
884
+
885
+             $messagetofl = $tonumberfl;
886
+             $messagenetworkfl = '';
887
+             $messagepricefl = '';
888
+             $messagedeliveryfl = '';
889
+
890
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
891
+
892
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
893
+         }
894
+         return $displayname;
895
+    }
896
+
897
+
898
+    /**
899
+     * @NoAdminRequired
900
+     */
901
+    public function saveoldrecrows($userId, $oldrecRows) {
902
+
903
+           // Create the folder for removed messages if it doesn't exist
904
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
905
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
906
+           }
907
+           $savecheck = 0;
908
+
909
+           if (count($oldrecRows) > 1) {
910
+               $msfileContent = implode("", $oldrecRows);
911
+
912
+               $delrowsdate = date("Y-m-d_H-i-s");
913
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
914
+
915
+               $userroot = $this->view->getRoot();
916
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
917
+
918
+               $target = $this->folder->newFile($targetfile);
919
+               $target->putContent($msfileContent);
920
+
921
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
922
+                   $savecheck = 1;
923
+               }
924
+           }
925
+
926
+           return $savecheck;
927
+    }
928
+
929
+
930
+    /**
931
+     * @NoAdminRequired
932
+     */
933
+    public function saveoldsentrows($userId, $oldsentRows) {
934
+
935
+           // Create the folder for removed messages if it doesn't exist
936
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
937
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
938
+           }
939
+           $savesentcheck = 0;
940
+
941
+           if (count($oldsentRows) > 1) {
942
+               $sntfileContent = implode("", $oldsentRows);
943
+
944
+               $delsentrowsdate = date("Y-m-d_H-i-s");
945
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
946
+
947
+               $userroot = $this->view->getRoot();
948
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
949
+
950
+               $snttarget = $this->folder->newFile($snttargetfile);
951
+               $snttarget->putContent($sntfileContent);
952
+
953
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
954
+                   $savesentcheck = 1;
955
+               }
956
+           }
957
+
958
+           return $savesentcheck;
959
+    }
960
+
961
+
962
+    /**
963
+     * @NoAdminRequired
964
+     */
965
+    public function getreceivedtable($userId) {
966
+           return $this->service->getreceivedtable($this->userId);
967
+    }
968
+
969
+    /**
970
+     * @NoAdminRequired
971
+     */
972
+    public function getreceivedtablefordel($userId) {
973
+           return $this->service->getreceivedtablefordel($this->userId);
974
+    }
975
+
976
+    /**
977
+     * @NoAdminRequired
978
+     */
979
+    public function removerecrows($userId, $recmessagedbIDs) {
980
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
981
+    }
982
+
983
+    /**
984
+     * @NoAdminRequired
985
+     */
986
+    public function getsenttable($userId) {
987
+           return $this->service->getsenttable($this->userId);
988
+    }
989
+
990
+    /**
991
+     * @NoAdminRequired
992
+     */
993
+    public function getsenttablefordel($userId) {
994
+           return $this->service->getsenttablefordel($this->userId);
995
+    }
996
+
997
+    /**
998
+     * @NoAdminRequired
999
+     */
1000
+    public function removesentrows($userId, $sentmessagedbIDs) {
1001
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1002
+    }
1003
+
1004
+    /**
1005
+     * @NoAdminRequired
1006
+     */
1007
+    public function getconversations($userId) {
1008
+           return $this->service->getconversations($this->userId);
1009
+    }
1010
+
1011
+    /**
1012
+     * @NoAdminRequired
1013
+     */
1014
+    public function archiveconv($userId, $conversationId) {
1015
+
1016
+           // Get the Display Name of the current user
1017
+           $crtusergt = $this->userManager->get($this->userId);
1018
+           $userDspNameArch = $crtusergt->getDisplayName();
1019
+
1020
+           return $this->service->archiveconv($this->userId, $userDspNameArch, $conversationId);
1021
+    }
1022
+
1023
+    /**
1024
+     * @NoAdminRequired
1025
+     */
1026
+    public function unarchiveconv($userId, $conversationId) {
1027
+
1028
+           // Get the Display Name of the current user
1029
+           $crtusergtun = $this->userManager->get($this->userId);
1030
+           $userDspNameUnarch = $crtusergtun->getDisplayName();
1031
+
1032
+           return $this->service->unarchiveconv($this->userId, $userDspNameUnarch, $conversationId);
1033
+    }
1034
+
1035
+    /**
1036
+     * @NoAdminRequired
1037
+     */
1038
+    public function saveconvdescription($userId, $convDescription, $convId) {
1039
+
1040
+           // Get the Display Name of the current user
1041
+           $crtuserdesc = $this->userManager->get($this->userId);
1042
+           $userDspNameDesc = $crtuserdesc->getDisplayName();
1043
+
1044
+           return $this->service->saveconvdescription($this->userId, $userDspNameDesc, $convDescription, $convId);
1045
+    }
1046
+
1047
+    /**
1048
+     * @NoAdminRequired
1049
+     */
1050
+    public function saveconvtag($userId, $convTag, $convId) {
1051
+
1052
+           // Get the Display Name of the current user
1053
+           $crtusertag = $this->userManager->get($this->userId);
1054
+           $userDspNameTag = $crtusertag->getDisplayName();
1055
+
1056
+           return $this->service->saveconvtag($this->userId, $userDspNameTag, $convTag, $convId);
1057
+    }
1058
+
1059
+    /**
1060
+     * @NoAdminRequired
1061
+     */
1062
+    public function saveconvflag($userId, $convFlag, $convId) {
1063
+
1064
+           // Get the Display Name of the current user
1065
+           $crtuserflag = $this->userManager->get($this->userId);
1066
+           $userDspNameFlag = $crtuserflag->getDisplayName();
1067
+
1068
+           return $this->service->saveconvflag($this->userId, $userDspNameFlag, $convFlag, $convId);
1069
+    }
1070
+
1071
+    /**
1072
+     * @NoAdminRequired
1073
+     */
1074
+    public function removeconvmsgs($userId, $conversationId) {
1075
+           return $this->service->removeconvmsgs($this->userId, $conversationId);
1076
+    }
1077
+
1078
+    /**
1079
+     * @NoAdminRequired
1080
+     */
1081
+    public function getgroupedtable($userId) {
1082
+           return $this->service->getgroupedtable($this->userId);
1083
+    }
1084
+
1085
+    /**
1086
+     * @NoAdminRequired
1087
+     */
1088
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1089
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1090
+    }
1091
+
1092
+    /**
1093
+     * @NoAdminRequired
1094
+     */
1095
+    public function getmsgsperpgnewmsgarchnb($userId) {
1096
+           return $this->service->getmsgsperpgnewmsgarchnb($this->userId);
1097
+    }
1098
+
1099
+    /**
1100
+     * @NoAdminRequired
1101
+     */
1102
+    public function getnewmsgindicator($userId) {
1103
+           return $this->service->getnewmsgindicator($this->userId);
1104
+    }
1105
+
1106
+    /**
1107
+     * @NoAdminRequired
1108
+     */
1109
+    public function getdelrecsettings($userId) {
1110
+           return $this->service->getdelrecsettings($this->userId);
1111
+    }
1112
+
1113
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1114
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1115
+    }
1116
+
1117
+    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1118
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1119
+    }
1120
+
1121
+    public function removenumberrestrictions($userId, $phoneNumber) {
1122
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1123
+    }
1124
+
1125
+    /**
1126
+     * @NoAdminRequired
1127
+     */
1128
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1129
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1130
+    }
1131
+
1132
+    /**
1133
+     * @NoAdminRequired
1134
+     */
1135
+    public function removeautoreplies($userId, $phoneNumber) {
1136
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1137
+    }
1138
+
1139
+    /**
1140
+     * @NoAdminRequired
1141
+     */
1142
+    public function getsettings($userId) {
1143
+           return $this->service->getsettings($this->userId);
1144
+    }
1145
+
1146
+    public function getadminsettings($userId) {
1147
+           return $this->service->getadminsettings($this->userId);
1148
+    }
1149
+
1150
+    /**
1151
+     * @NoAdminRequired
1152
+     */
1153
+    public function getautoreplyconf($userId) {
1154
+
1155
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1156
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1157
+
1158
+           // Get the display name of the current user
1159
+           $usrid = $this->userId;
1160
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1161
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1162
+	   $getusrdnmdata = $getusrdnmres->fetch();
1163
+	   $userDisplayNm = $getusrdnmdata['value'];
1164
+	   $getusrdnmres->closeCursor();
1165
+
1166
+           // Get the auto-replies for the available phone numbers
1167
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1168
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1169
+	   $getautorplres = $getautorpl->execute();
1170
+           $autorplconf = [];
1171
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1172
+                  $autorplconf[] = $acdatausrdnadm;
1173
+           }
1174
+	   $getautorplres->closeCursor();
1175
+
1176
+           if ($autorplconf) {
1177
+
1178
+               $autoreplyconf = [];
1179
+               foreach ($autorplconf as $arkey => $arvalue) {
1180
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1181
+                            $autoreplyconf[] = $arvalue;
1182
+                        }
1183
+               }
1184
+
1185
+           } else { $autoreplyconf = ''; }
1186
+
1187
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1188
+
1189
+           return $autoreplyfdb;
1190
+    }
1191
+
1192
+    /**
1193
+     * @NoAdminRequired
1194
+     */
1195
+    public function getgroupedpernumber($userId, $phoneNumber) {
1196
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1197
+    }
1198
+
1199
+    /**
1200
+     * @NoAdminRequired
1201
+     */
1202
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1203
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1204
+    }
1205
+
1206
+    /**
1207
+     * @NoAdminRequired
1208
+     */
1209
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1210
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1211
+    }
1212
+
1213
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1214
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1215
+    }
1216
+
1217
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr) {
1218
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval, $archivedConvNmbr);
1219
+    }
1220
+}
Browse code

removed appinfo/info.xml appinfo/signature.json appinfo/routes.php CHANGELOG.txt README.md css/style.css js/showsmstables.js js/settings.js js/sendsms.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/navigation/index.php templates/settings/personal.php img/arrow-top.svg

DoubleBastionAdmin authored on 02/04/2024 00:07:07
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1146 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\Share\IManager;
49
-use OCP\Constants;
50
-use OCP\IGroupManager;
51
-use OCP\IDBConnection;
52
-use OCP\IUserManager;
53
-use OC\URLGenerator;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $shareManager;
64
-    private $groupManager;
65
-    private $connection;
66
-    private $userManager;
67
-    private $urlGenerator;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->shareManager = $shareManager;
78
-        $this->groupManager = $groupManager;
79
-        $this->connection = $connection;
80
-        $this->userManager = $userManager;
81
-        $this->urlGenerator = $urlGenerator;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getappdirectory($userId) {
120
-        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
-        $apprelpatharr = explode("/", $apprelpath);
122
-        $currentappdir = $apprelpatharr[1];
123
-        return $currentappdir;
124
-    }
125
-
126
-
127
-    /**
128
-     * @NoAdminRequired
129
-     */
130
-    public function getbalancetel($userId) {
131
-
132
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
133
-
134
-        $telapikey = $telsmsapicred[0];
135
-        $ch = curl_init();
136
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
137
-
138
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
139
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
140
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
141
-        $responsetel = curl_exec($ch);
142
-        $recdatatel = json_decode($responsetel, TRUE);
143
-        $telbalresponse = $recdatatel['data']['balance'];
144
-        $currentbalancetel = round(floatval($telbalresponse), 3);
145
-        curl_close($ch);
146
-
147
-        return $currentbalancetel;
148
-    }
149
-
150
-
151
-    /**
152
-     * @NoAdminRequired
153
-     */
154
-    public function getbalancenex($userId) {
155
-
156
-        $smsapicred = $this->service->getapicredentials($this->userId);
157
-        $smsapikey = $smsapicred[5];
158
-        $smsapisecret = $smsapicred[6];
159
-
160
-        if ($smsapikey == '' || $smsapisecret == '') {
161
-            $currentbalancenex = "N/A";
162
-        } else {
163
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
164
-            $mesdata = file_get_contents($getmesdata);
165
-            $datainit = json_decode($mesdata);
166
-            $balancenex = $datainit->cash_credits;
167
-            $currentbalancenex = round(floatval($balancenex), 3);
168
-        }
169
-        return $currentbalancenex;
170
-    }
171
-
172
-
173
-    /**
174
-     * @NoAdminRequired
175
-     */
176
-    public function getbalancetwil($userId) {
177
-
178
-        $smsapicred = $this->service->getapicredentials($this->userId);
179
-        $smsapisid = $smsapicred[15];
180
-        $smsapitoken = $smsapicred[16];
181
-
182
-        if ($smsapisid == '' || $smsapitoken == '') {
183
-            $currentbalancetwil = "N/A";
184
-        } else {
185
-
186
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
187
-            $balancetwil = $twilbalance->balance;
188
-
189
-            $currentbalancetwil = round(floatval($balancetwil), 3);
190
-        }
191
-        return $currentbalancetwil;
192
-    }
193
-
194
-
195
-    /**
196
-     * @NoAdminRequired
197
-     */
198
-    public function getbalanceflow($userId) {
199
-
200
-        $currentbalanceflow = 'n/a';
201
-        return $currentbalanceflow;
202
-    }
203
-
204
-
205
-    /**
206
-     * @NoAdminRequired
207
-     */
208
-    public function getsmsnumbers($userId) {
209
-
210
-        return $this->service->getsmsnumbers($this->userId);
211
-    }
212
-
213
-
214
-    /**
215
-     * @NoAdminRequired
216
-     */
217
-    public function refreshavailablenumbers($userId) {
218
-
219
-        return $this->service->refreshavailablenumbers($this->userId);
220
-    }
221
-
222
-
223
-    /**
224
-     * @NoAdminRequired
225
-     */
226
-    public function cleantempdir($userId) {
227
-
228
-        // Create the temporary folder if it doesn't exist
229
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
230
-            $this->folder->newFolder('SMS_Relentless/temp_files');
231
-        }
232
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
233
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
234
-        $fileSystemIterator = new FilesystemIterator($targetdir);
235
-
236
-        $dirfiles = [];
237
-        foreach ($fileSystemIterator as $fileInfo) {
238
-                 $dirfiles[] = $fileInfo->getFilename();
239
-        }
240
-
241
-        foreach ($dirfiles as $key => $indfile) {
242
-                 $thisuserroot = $this->view->getRoot();
243
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
244
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
245
-        }
246
-     }
247
-
248
-
249
-    /**
250
-     * @NoAdminRequired
251
-     */
252
-    public function cleanmultrecdir($userId) {
253
-
254
-        // Create the temporary folder if it doesn't exist
255
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
256
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
257
-        }
258
-        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
259
-        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
260
-        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
261
-
262
-        $dirfilesmrc = [];
263
-        foreach ($fileSystemIteratormrc as $fileInfomrc){
264
-                 $dirfilesmrc[] = $fileInfomrc->getFilename();
265
-        }
266
-
267
-        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
268
-                 $thisuserrootmrc = $this->view->getRoot();
269
-                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
270
-                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
271
-        }
272
-     }
273
-
274
-
275
-    /**
276
-     * @NoAdminRequired
277
-     */
278
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
279
-
280
-        // Create the temporary folder if it doesn't exist
281
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
282
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
283
-        }
284
-
285
-        // First delete any file that has been previously uploaded
286
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
287
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
288
-        $fileSystemIterator = new FilesystemIterator($targetdir);
289
-
290
-        $dirfiles = [];
291
-        foreach ($fileSystemIterator as $fileInfo){
292
-                 $dirfiles[] = $fileInfo->getFilename();
293
-        }
294
-
295
-        foreach ($dirfiles as $key => $indfile) {
296
-                 $thisuserroot = $this->view->getRoot();
297
-                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
298
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
299
-        }
300
-
301
-        // Upload the new file
302
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
303
-        $fileName = $_FILES['uploadfileforsms']['name'];
304
-
305
-        $userroot = $this->view->getRoot();
306
-        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
307
-
308
-        $target = $this->folder->newFile($targetfile);
309
-        $target->putContent($fileContent);
310
-
311
-        // Extract the phone numbers from the file
312
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
313
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
314
-        $numberarrayfourth = explode(",", $numberarraytert);
315
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
316
-        $numberarray = array_unique($numberarrayfifth);
317
-
318
-        return $numberarray;
319
-    }
320
-
321
-
322
-    /**
323
-     * @NoAdminRequired
324
-     */
325
-    public function uploadfile($uploadfileformms) {
326
-
327
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
328
-           $fileName = $_FILES['uploadfileformms']['name'];
329
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
330
-           $fileSize = $fileSizeinit / 1024;
331
-
332
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
333
-               $this->folder->newFolder('SMS_Relentless/temp_files');
334
-           }
335
-
336
-           $userroot = $this->view->getRoot();
337
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
338
-
339
-           $target = $this->folder->newFile($targetfile);
340
-           $target->putContent($fileContent);
341
-
342
-           // Get the cumulative files size of the uploaded files
343
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
344
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
345
-
346
-           $fileSystemIterator = new FilesystemIterator($targetdir);
347
-
348
-           $dirfiles = [];
349
-           foreach ($fileSystemIterator as $fileInfo){
350
-                    $dirfiles[] = $fileInfo->getFilename();
351
-           }
352
-
353
-           $totalflsizeinit = 0;
354
-           foreach ($dirfiles as $key => $indfile) {
355
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
356
-                    $mbSize = round($fileSizeinit / 1024, 4);
357
-                    $totalflsizeinit += $mbSize;
358
-           }
359
-
360
-           $totalflsize = round($totalflsizeinit, 4);
361
-
362
-           return $totalflsize;
363
-    }
364
-
365
-
366
-    /**
367
-     * @NoAdminRequired
368
-     */
369
-    public function pickfile($path) {
370
-
371
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
372
-               $this->folder->newFolder('SMS_Relentless/temp_files');
373
-           }
374
-
375
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
376
-
377
-           $fltgt = $datadir . $this->userId . "/files" . $path;
378
-
379
-           $fileContent = file_get_contents($fltgt);
380
-
381
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
382
-
383
-           $patharr = explode("/", $path);
384
-
385
-           $revarr = array_reverse($patharr);
386
-
387
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
388
-
389
-           $target = $this->folder->newFile($relflpath);
390
-
391
-           $target->putContent($fileContent);
392
-
393
-           // Get the cumulative files size of the uploaded files
394
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
395
-
396
-           $fileSystemIterator = new FilesystemIterator($targetdir);
397
-
398
-           $dirfiles = [];
399
-           foreach ($fileSystemIterator as $fileInfo) {
400
-                    $dirfiles[] = $fileInfo->getFilename();
401
-           }
402
-
403
-           $totalflsizeinit = 0;
404
-
405
-           foreach ($dirfiles as $key => $indfile) {
406
-
407
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
408
-                    $mbSize = round($fileSizeinit / 1024, 4);
409
-                    $totalflsizeinit += $mbSize;
410
-           }
411
-
412
-           $totalflsize = round($totalflsizeinit, 4);
413
-
414
-           $pickresult = [$totalflsize, $pkfilesize];
415
-
416
-           return $pickresult;
417
-    }
418
-
419
-
420
-    /**
421
-     * @NoAdminRequired
422
-     */
423
-    public function removeupfile($removedfilename) {
424
-
425
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
426
-
427
-           $removefile = $this->view->unlink($tmpfl);
428
-
429
-           // Get the cumulative files size of the uploaded files
430
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
431
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
432
-           $fileSystemIterator = new FilesystemIterator($targetdir);
433
-
434
-           $dirfiles = [];
435
-           foreach ($fileSystemIterator as $fileInfo){
436
-                    $dirfiles[] = $fileInfo->getFilename();
437
-           }
438
-
439
-           $totalflsizeinit = 0;
440
-
441
-           foreach ($dirfiles as $key => $indfile) {
442
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
443
-                    $mbSize = round($fileSizeinit / 1024, 4);
444
-                    $totalflsizeinit += $mbSize;
445
-           }
446
-
447
-           $totalflsize = round($totalflsizeinit, 4);
448
-
449
-           return $totalflsize;
450
-    }
451
-
452
-
453
-    /**
454
-     * @NoAdminRequired
455
-     */
456
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
457
-
458
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
459
-         $telnyxkey = $telsmsapicred[0];
460
-         $teldelrecurl = $telsmsapicred[3];
461
-         $messagingprofid = $telsmsapicred[4];
462
-         $addDisplName = $telsmsapicred[24];
463
-
464
-         // Get the Display Name of the current user
465
-         $crtuser = $this->userManager->get($this->userId);
466
-         $displayname = $crtuser->getDisplayName();
467
-
468
-         if ($addDisplName == 1) {
469
-             $sentsmstext = $displayname . ": " . $sentsmstext;
470
-         }
471
-
472
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
473
-
474
-         $microinterval = $waitinterval * 1000;
475
-
476
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
477
-
478
-             usleep($microinterval);
479
-
480
-             $messagedate = date("Y-m-d H:i:s");
481
-
482
-             if ($ismms == 0) {
483
-
484
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
485
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
486
-                 } else {
487
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
488
-                 }
489
-
490
-                 $messagetexttel = $sentsmstext;
491
-
492
-             } else {
493
-
494
-                 $mediaURLarr = [];
495
-                 $includedMediaFiles = '';
496
-
497
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
498
-
499
-                      $userroot = $this->view->getRoot();
500
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
501
-
502
-                      $flsharetarget = $this->folder->newFile($filetoshare);
503
-
504
-	              $share = $this->shareManager->newShare();
505
-	              $share->setNode($flsharetarget);
506
-	              $share->setPermissions(Constants::PERMISSION_READ);
507
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
508
-	              $share->setSharedBy($this->userId);
509
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
510
-                      $expirydate->add(new \DateInterval('P1D'));
511
-                      $share->setExpirationDate($expirydate);
512
-                      $shared = $this->shareManager->createShare($share);
513
-                      $shareToken = $shared->getToken();
514
-
515
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
516
-
517
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
518
-
519
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
520
-                 }
521
-
522
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
523
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
524
-                 } else {
525
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
526
-                 }
527
-
528
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
529
-             }
530
-
531
-             $messageid = $message['id'];
532
-             $messagefrom = "Telnyx: " . $fromsender;
533
-             $messageto = $tonumber;
534
-             $messagenetwork = null;
535
-             $messageprice = null;
536
-             $messagestatus = $message['to'][0]['status'];
537
-             $messagedelivery = null;
538
-
539
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
540
-
541
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
542
-         }
543
-         return $displayname;
544
-    }
545
-
546
-
547
-    /**
548
-     * @NoAdminRequired
549
-     */
550
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
551
-
552
-         $plsmsapicred = $this->service->getapicredentials($this->userId);
553
-
554
-         $smsapikey = $plsmsapicred[5];
555
-         $smsapisecret = $plsmsapicred[6];
556
-         $smsapideliveryrecurl = $plsmsapicred[8];
557
-         $addDisplName = $plsmsapicred[24];
558
-
559
-         // Get the Display Name of the current user
560
-         $crtuser = $this->userManager->get($this->userId);
561
-         $displayname = $crtuser->getDisplayName();
562
-
563
-         if ($addDisplName == 1) {
564
-             $sentsmstext = $displayname . ": " . $sentsmstext;
565
-         }
566
-
567
-         $microinterval = $waitinterval * 1000;
568
-
569
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
570
-
571
-             usleep($microinterval);
572
-
573
-             $messagedatepl = date("Y-m-d H:i:s");
574
-
575
-             if ($ismms == 0) {
576
-
577
-                 $client = new RestClient($smsapikey, $smsapisecret);
578
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
579
-                 $messagetextpl = $sentsmstext;
580
-	         $messageidinit = $response->getmessageUuid(0);
581
-                 $messageid = $messageidinit[0];
582
-
583
-                 if (property_exists($response, 'error')) { 
584
-                     $messagestatus = "Error: " . $response->error;
585
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
586
-
587
-             } else {
588
-
589
-                 $mediaURLarr = [];
590
-                 $includedMediaFiles = '';
591
-
592
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
593
-
594
-                      $userroot = $this->view->getRoot();
595
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
596
-
597
-                      $flsharetarget = $this->folder->newFile($filetoshare);
598
-
599
-	              $share = $this->shareManager->newShare();
600
-	              $share->setNode($flsharetarget);
601
-	              $share->setPermissions(Constants::PERMISSION_READ);
602
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
603
-	              $share->setSharedBy($this->userId);
604
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
605
-                      $expirydate->add(new \DateInterval('P1D'));
606
-                      $share->setExpirationDate($expirydate);
607
-                      $shared = $this->shareManager->createShare($share);
608
-                      $shareToken = $shared->getToken();
609
-
610
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
611
-
612
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
613
-
614
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
615
-                 }
616
-
617
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
618
-		 $postedparamspl = json_encode($datatosendpl);
619
-
620
-		 $chpl = curl_init();
621
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
622
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
623
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
624
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
625
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
626
-		 curl_setopt($chpl, CURLOPT_POST, 1);
627
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
628
-		 $resultpl = curl_exec ($chpl);
629
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
630
-		 curl_close ($chpl);
631
-
632
-		 $decresultpl = json_decode($resultpl);
633
-
634
-                 if ($decresultpl) {
635
-                     if (property_exists($decresultpl, 'message_uuid')) {
636
-                         $messageidinit = $decresultpl->message_uuid;
637
-                         $messageid = $messageidinit[0];
638
-                     } else { $messageid = 'n/a'; }
639
-                 } else { $messageid = 'n/a'; }
640
-
641
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
642
-
643
-                     if (property_exists($decresultpl, 'error')) {
644
-                         $messagestatus = "Error: " . $decresultpl->error;
645
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
646
-
647
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
648
-
649
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
650
-             }
651
-
652
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
653
-                 $messagefrom = "Plivo: " . $fromsender;
654
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
655
-
656
-             $messageto = $tonumber;
657
-             $messagenetwork = '';
658
-             $messageprice = '';
659
-
660
-             $messagedelivery = '';
661
-
662
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
663
-
664
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
665
-         }
666
-         return $displayname;
667
-    }
668
-
669
-
670
-    /**
671
-     * @NoAdminRequired
672
-     */
673
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
674
-
675
-         $twsmsapicred = $this->service->getapicredentials($this->userId);
676
-
677
-         $sid = $twsmsapicred[15];
678
-         $token = $twsmsapicred[16];
679
-         $smsapirecurltw = $twsmsapicred[18];
680
-         $addDisplName = $twsmsapicred[24];
681
-
682
-         // Get the Display Name of the current user
683
-         $crtuser = $this->userManager->get($this->userId);
684
-         $displayname = $crtuser->getDisplayName();
685
-
686
-         if ($addDisplName == 1) {
687
-             $sentsmstext = $displayname . ": " . $sentsmstext;
688
-         }
689
-
690
-         $microinterval = $waitinterval * 1000;
691
-
692
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
693
-
694
-             usleep($microinterval);
695
-
696
-             $messagedatetw = date("Y-m-d H:i:s");
697
-
698
-             if ($ismms == 0) {
699
-
700
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
701
-                 $sentsmstextfintw = $sentsmstext;
702
-
703
-             } else {
704
-
705
-                 $mediaURLs = [];
706
-                 $includedMediaFiles = '';
707
-
708
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
709
-
710
-                      $userroot = $this->view->getRoot();
711
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
712
-
713
-                      $flsharetarget = $this->folder->newFile($filetoshare);
714
-
715
-	              $share = $this->shareManager->newShare();
716
-	              $share->setNode($flsharetarget);
717
-	              $share->setPermissions(Constants::PERMISSION_READ);
718
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
719
-	              $share->setSharedBy($this->userId);
720
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
721
-                      $expirydate->add(new \DateInterval('P1D'));
722
-                      $share->setExpirationDate($expirydate);
723
-                      $shared = $this->shareManager->createShare($share);
724
-                      $shareToken = $shared->getToken();
725
-
726
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
727
-
728
-                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
729
-
730
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
731
-                 }
732
-
733
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
734
-
735
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
736
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
737
-                 }
738
-
739
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
740
-             }
741
-
742
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
743
-
744
-	     $chtw = curl_init();
745
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
746
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
747
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
748
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
749
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
750
-	     curl_setopt($chtw, CURLOPT_POST, 1);
751
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
752
-
753
-	     $resulttw = curl_exec ($chtw);
754
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
755
-	     curl_close ($chtw);
756
-
757
-             $decresulttw = json_decode($resulttw);
758
-
759
-             if ($decresulttw) {
760
-                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
761
-             } else { $messageidtw = 'n/a'; }
762
-
763
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
764
-                 $messagestatustw = 'The message has been accepted for delivery.';
765
-             } else {
766
-                 $messagestatustw = 'An error occurred while trying to send the message.';
767
-             }
768
-
769
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
770
-                 $messagefromtw = "Twilio: " . $fromsender;
771
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
772
-
773
-             $messagenetworktw = '';
774
-             $messagepricetw = '';
775
-             $messagedeliverytw = '';
776
-
777
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
778
-
779
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
780
-         }
781
-         return $displayname;
782
-    }
783
-
784
-
785
-    /**
786
-     * @NoAdminRequired
787
-     */
788
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
789
-
790
-         $flsmsapicred = $this->service->getapicredentials($this->userId);
791
-
792
-         $flowapikey = $flsmsapicred[20];
793
-         $flowapisecret = $flsmsapicred[21];
794
-         $flowdelrecurl = $flsmsapicred[23];
795
-         $addDisplName = $flsmsapicred[24];
796
-
797
-         // Get the Display Name of the current user
798
-         $crtuser = $this->userManager->get($this->userId);
799
-         $displayname = $crtuser->getDisplayName();
800
-
801
-         if ($addDisplName == 1) {
802
-             $sentsmstext = $displayname . ": " . $sentsmstext;
803
-         }
804
-
805
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
806
-
807
-         $microinterval = $waitinterval * 1000;
808
-
809
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
810
-
811
-             usleep($microinterval);
812
-
813
-             $messagedatefl = date("Y-m-d H:i:s");
814
-
815
-             if ($ismms == 0) {
816
-
817
-                 $messagetextfinfl = $sentsmstext;
818
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
819
-
820
-             } else {
821
-
822
-		 $mediaurlsarr = [];
823
-		 $includedMediaFiles = '';
824
-
825
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
826
-
827
-		      $userroot = $this->view->getRoot();
828
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
829
-
830
-		      $flsharetarget = $this->folder->newFile($filetoshare);
831
-
832
-		      $share = $this->shareManager->newShare();
833
-		      $share->setNode($flsharetarget);
834
-		      $share->setPermissions(Constants::PERMISSION_READ);
835
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
836
-		      $share->setSharedBy($this->userId);
837
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
838
-                      $expirydate->add(new \DateInterval('P1D'));
839
-                      $share->setExpirationDate($expirydate);
840
-		      $shared = $this->shareManager->createShare($share);
841
-		      $shareToken = $shared->getToken();
842
-
843
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
844
-
845
-		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
846
-
847
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
848
-		 }
849
-
850
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
851
-
852
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
853
-             }
854
-
855
-	     $chfl = curl_init();
856
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
857
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
858
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
859
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
860
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
861
-	     curl_setopt($chfl, CURLOPT_POST, 1);
862
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
863
-	     $resultfl = curl_exec ($chfl);
864
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
865
-	     curl_close ($chfl);
866
-
867
-             $decresultfl = json_decode($resultfl);
868
-
869
-             if ($decresultfl) {
870
-                 if (property_exists($decresultfl, 'data')) { 
871
-                     $messageidfl = $decresultfl->data->id;
872
-                 } else { $messageidfl = 'n/a'; }
873
-             } else { $messageidfl = 'n/a'; }
874
-
875
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
876
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
877
-             } else { 
878
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
879
-             }
880
-
881
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
882
-                 $messagefromfl = "Flowroute: " . $fromsender;
883
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
884
-
885
-             $messagetofl = $tonumberfl;
886
-             $messagenetworkfl = '';
887
-             $messagepricefl = '';
888
-             $messagedeliveryfl = '';
889
-
890
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
891
-
892
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
893
-         }
894
-         return $displayname;
895
-    }
896
-
897
-
898
-    /**
899
-     * @NoAdminRequired
900
-     */
901
-    public function saveoldrecrows($userId, $oldrecRows) {
902
-
903
-           // Create the folder for removed messages if it doesn't exist
904
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
905
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
906
-           }
907
-           $savecheck = 0;
908
-
909
-           if (count($oldrecRows) > 1) {
910
-               $msfileContent = implode("", $oldrecRows);
911
-
912
-               $delrowsdate = date("Y-m-d_H-i-s");
913
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
914
-
915
-               $userroot = $this->view->getRoot();
916
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
917
-
918
-               $target = $this->folder->newFile($targetfile);
919
-               $target->putContent($msfileContent);
920
-
921
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
922
-                   $savecheck = 1;
923
-               }
924
-           }
925
-
926
-           return $savecheck;
927
-    }
928
-
929
-
930
-    /**
931
-     * @NoAdminRequired
932
-     */
933
-    public function saveoldsentrows($userId, $oldsentRows) {
934
-
935
-           // Create the folder for removed messages if it doesn't exist
936
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
937
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
938
-           }
939
-           $savesentcheck = 0;
940
-
941
-           if (count($oldsentRows) > 1) {
942
-               $sntfileContent = implode("", $oldsentRows);
943
-
944
-               $delsentrowsdate = date("Y-m-d_H-i-s");
945
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
946
-
947
-               $userroot = $this->view->getRoot();
948
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
949
-
950
-               $snttarget = $this->folder->newFile($snttargetfile);
951
-               $snttarget->putContent($sntfileContent);
952
-
953
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
954
-                   $savesentcheck = 1;
955
-               }
956
-           }
957
-
958
-           return $savesentcheck;
959
-    }
960
-
961
-
962
-    /**
963
-     * @NoAdminRequired
964
-     */
965
-    public function getreceivedtable($userId) {
966
-           return $this->service->getreceivedtable($this->userId);
967
-    }
968
-
969
-    /**
970
-     * @NoAdminRequired
971
-     */
972
-    public function getreceivedtablefordel($userId) {
973
-           return $this->service->getreceivedtablefordel($this->userId);
974
-    }
975
-
976
-    /**
977
-     * @NoAdminRequired
978
-     */
979
-    public function removerecrows($userId, $recmessagedbIDs) {
980
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
981
-    }
982
-
983
-    /**
984
-     * @NoAdminRequired
985
-     */
986
-    public function getsenttable($userId) {
987
-           return $this->service->getsenttable($this->userId);
988
-    }
989
-
990
-    /**
991
-     * @NoAdminRequired
992
-     */
993
-    public function getsenttablefordel($userId) {
994
-           return $this->service->getsenttablefordel($this->userId);
995
-    }
996
-
997
-    /**
998
-     * @NoAdminRequired
999
-     */
1000
-    public function removesentrows($userId, $sentmessagedbIDs) {
1001
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1002
-    }
1003
-
1004
-    /**
1005
-     * @NoAdminRequired
1006
-     */
1007
-    public function getgroupedtable($userId) {
1008
-           return $this->service->getgroupedtable($this->userId);
1009
-    }
1010
-
1011
-    /**
1012
-     * @NoAdminRequired
1013
-     */
1014
-    public function savedisplayname($userId, $authorDisplayname, $from) {
1015
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1016
-    }
1017
-
1018
-    /**
1019
-     * @NoAdminRequired
1020
-     */
1021
-    public function getmsgsperpagenewmsg($userId) {
1022
-           return $this->service->getmsgsperpagenewmsg($this->userId);
1023
-    }
1024
-
1025
-    /**
1026
-     * @NoAdminRequired
1027
-     */
1028
-    public function getnewmsgindicator($userId) {
1029
-           return $this->service->getnewmsgindicator($this->userId);
1030
-    }
1031
-
1032
-    /**
1033
-     * @NoAdminRequired
1034
-     */
1035
-    public function getdelrecsettings($userId) {
1036
-           return $this->service->getdelrecsettings($this->userId);
1037
-    }
1038
-
1039
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1040
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1041
-    }
1042
-
1043
-    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1044
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1045
-    }
1046
-
1047
-    public function removenumberrestrictions($userId, $phoneNumber) {
1048
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1049
-    }
1050
-
1051
-    /**
1052
-     * @NoAdminRequired
1053
-     */
1054
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1055
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1056
-    }
1057
-
1058
-    /**
1059
-     * @NoAdminRequired
1060
-     */
1061
-    public function removeautoreplies($userId, $phoneNumber) {
1062
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1063
-    }
1064
-
1065
-    /**
1066
-     * @NoAdminRequired
1067
-     */
1068
-    public function getsettings($userId) {
1069
-           return $this->service->getsettings($this->userId);
1070
-    }
1071
-
1072
-    public function getadminsettings($userId) {
1073
-           return $this->service->getadminsettings($this->userId);
1074
-    }
1075
-
1076
-    /**
1077
-     * @NoAdminRequired
1078
-     */
1079
-    public function getautoreplyconf($userId) {
1080
-
1081
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1082
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1083
-
1084
-           // Get the display name of the current user
1085
-           $usrid = $this->userId;
1086
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1087
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1088
-	   $getusrdnmdata = $getusrdnmres->fetch();
1089
-	   $userDisplayNm = $getusrdnmdata['value'];
1090
-	   $getusrdnmres->closeCursor();
1091
-
1092
-           // Get the auto-replies for the available phone numbers
1093
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1094
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1095
-	   $getautorplres = $getautorpl->execute();
1096
-           $autorplconf = [];
1097
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1098
-                  $autorplconf[] = $acdatausrdnadm;
1099
-           }
1100
-	   $getautorplres->closeCursor();
1101
-
1102
-           if ($autorplconf) {
1103
-
1104
-               $autoreplyconf = [];
1105
-               foreach ($autorplconf as $arkey => $arvalue) {
1106
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1107
-                            $autoreplyconf[] = $arvalue;
1108
-                        }
1109
-               }
1110
-
1111
-           } else { $autoreplyconf = ''; }
1112
-
1113
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1114
-
1115
-           return $autoreplyfdb;
1116
-    }
1117
-
1118
-    /**
1119
-     * @NoAdminRequired
1120
-     */
1121
-    public function getgroupedpernumber($userId, $phoneNumber) {
1122
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1123
-    }
1124
-
1125
-    /**
1126
-     * @NoAdminRequired
1127
-     */
1128
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1129
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1130
-    }
1131
-
1132
-    /**
1133
-     * @NoAdminRequired
1134
-     */
1135
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval) {
1136
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval);
1137
-    }
1138
-
1139
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1140
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1141
-    }
1142
-
1143
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval) {
1144
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval);
1145
-    }
1146
-}
Browse code

added appinfo/info.xml appinfo/signature.json appinfo/routes.php CHANGELOG.txt README.md css/style.css js/settings.js js/sendsms.js js/adminsettings.js js/showsmstables.js templates/settings/admin.php templates/settings/personal.php templates/navigation/index.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php l10n/en_GB.js l10n/en_GB.json l10n/en_US.js l10n/en_US.json lib/Migration/Version133Date20240215094712.php

DoubleBastionAdmin authored on 14/02/2024 22:47:20
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1146 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\Share\IManager;
49
+use OCP\Constants;
50
+use OCP\IGroupManager;
51
+use OCP\IDBConnection;
52
+use OCP\IUserManager;
53
+use OC\URLGenerator;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $shareManager;
64
+    private $groupManager;
65
+    private $connection;
66
+    private $userManager;
67
+    private $urlGenerator;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager, URLGenerator $urlGenerator) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->shareManager = $shareManager;
78
+        $this->groupManager = $groupManager;
79
+        $this->connection = $connection;
80
+        $this->userManager = $userManager;
81
+        $this->urlGenerator = $urlGenerator;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getappdirectory($userId) {
120
+        $apprelpath = $this->urlGenerator->linkTo('sms_relentless', 'COPYING.txt');
121
+        $apprelpatharr = explode("/", $apprelpath);
122
+        $currentappdir = $apprelpatharr[1];
123
+        return $currentappdir;
124
+    }
125
+
126
+
127
+    /**
128
+     * @NoAdminRequired
129
+     */
130
+    public function getbalancetel($userId) {
131
+
132
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
133
+
134
+        $telapikey = $telsmsapicred[0];
135
+        $ch = curl_init();
136
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
137
+
138
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
139
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
140
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
141
+        $responsetel = curl_exec($ch);
142
+        $recdatatel = json_decode($responsetel, TRUE);
143
+        $telbalresponse = $recdatatel['data']['balance'];
144
+        $currentbalancetel = round(floatval($telbalresponse), 3);
145
+        curl_close($ch);
146
+
147
+        return $currentbalancetel;
148
+    }
149
+
150
+
151
+    /**
152
+     * @NoAdminRequired
153
+     */
154
+    public function getbalancenex($userId) {
155
+
156
+        $smsapicred = $this->service->getapicredentials($this->userId);
157
+        $smsapikey = $smsapicred[5];
158
+        $smsapisecret = $smsapicred[6];
159
+
160
+        if ($smsapikey == '' || $smsapisecret == '') {
161
+            $currentbalancenex = "N/A";
162
+        } else {
163
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
164
+            $mesdata = file_get_contents($getmesdata);
165
+            $datainit = json_decode($mesdata);
166
+            $balancenex = $datainit->cash_credits;
167
+            $currentbalancenex = round(floatval($balancenex), 3);
168
+        }
169
+        return $currentbalancenex;
170
+    }
171
+
172
+
173
+    /**
174
+     * @NoAdminRequired
175
+     */
176
+    public function getbalancetwil($userId) {
177
+
178
+        $smsapicred = $this->service->getapicredentials($this->userId);
179
+        $smsapisid = $smsapicred[15];
180
+        $smsapitoken = $smsapicred[16];
181
+
182
+        if ($smsapisid == '' || $smsapitoken == '') {
183
+            $currentbalancetwil = "N/A";
184
+        } else {
185
+
186
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
187
+            $balancetwil = $twilbalance->balance;
188
+
189
+            $currentbalancetwil = round(floatval($balancetwil), 3);
190
+        }
191
+        return $currentbalancetwil;
192
+    }
193
+
194
+
195
+    /**
196
+     * @NoAdminRequired
197
+     */
198
+    public function getbalanceflow($userId) {
199
+
200
+        $currentbalanceflow = 'n/a';
201
+        return $currentbalanceflow;
202
+    }
203
+
204
+
205
+    /**
206
+     * @NoAdminRequired
207
+     */
208
+    public function getsmsnumbers($userId) {
209
+
210
+        return $this->service->getsmsnumbers($this->userId);
211
+    }
212
+
213
+
214
+    /**
215
+     * @NoAdminRequired
216
+     */
217
+    public function refreshavailablenumbers($userId) {
218
+
219
+        return $this->service->refreshavailablenumbers($this->userId);
220
+    }
221
+
222
+
223
+    /**
224
+     * @NoAdminRequired
225
+     */
226
+    public function cleantempdir($userId) {
227
+
228
+        // Create the temporary folder if it doesn't exist
229
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
230
+            $this->folder->newFolder('SMS_Relentless/temp_files');
231
+        }
232
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
233
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
234
+        $fileSystemIterator = new FilesystemIterator($targetdir);
235
+
236
+        $dirfiles = [];
237
+        foreach ($fileSystemIterator as $fileInfo) {
238
+                 $dirfiles[] = $fileInfo->getFilename();
239
+        }
240
+
241
+        foreach ($dirfiles as $key => $indfile) {
242
+                 $thisuserroot = $this->view->getRoot();
243
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
244
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
245
+        }
246
+     }
247
+
248
+
249
+    /**
250
+     * @NoAdminRequired
251
+     */
252
+    public function cleanmultrecdir($userId) {
253
+
254
+        // Create the temporary folder if it doesn't exist
255
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
256
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
257
+        }
258
+        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
259
+        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
260
+        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
261
+
262
+        $dirfilesmrc = [];
263
+        foreach ($fileSystemIteratormrc as $fileInfomrc){
264
+                 $dirfilesmrc[] = $fileInfomrc->getFilename();
265
+        }
266
+
267
+        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
268
+                 $thisuserrootmrc = $this->view->getRoot();
269
+                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
270
+                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
271
+        }
272
+     }
273
+
274
+
275
+    /**
276
+     * @NoAdminRequired
277
+     */
278
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
279
+
280
+        // Create the temporary folder if it doesn't exist
281
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
282
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
283
+        }
284
+
285
+        // First delete any file that has been previously uploaded
286
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
287
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
288
+        $fileSystemIterator = new FilesystemIterator($targetdir);
289
+
290
+        $dirfiles = [];
291
+        foreach ($fileSystemIterator as $fileInfo){
292
+                 $dirfiles[] = $fileInfo->getFilename();
293
+        }
294
+
295
+        foreach ($dirfiles as $key => $indfile) {
296
+                 $thisuserroot = $this->view->getRoot();
297
+                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
298
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
299
+        }
300
+
301
+        // Upload the new file
302
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
303
+        $fileName = $_FILES['uploadfileforsms']['name'];
304
+
305
+        $userroot = $this->view->getRoot();
306
+        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
307
+
308
+        $target = $this->folder->newFile($targetfile);
309
+        $target->putContent($fileContent);
310
+
311
+        // Extract the phone numbers from the file
312
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
313
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
314
+        $numberarrayfourth = explode(",", $numberarraytert);
315
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
316
+        $numberarray = array_unique($numberarrayfifth);
317
+
318
+        return $numberarray;
319
+    }
320
+
321
+
322
+    /**
323
+     * @NoAdminRequired
324
+     */
325
+    public function uploadfile($uploadfileformms) {
326
+
327
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
328
+           $fileName = $_FILES['uploadfileformms']['name'];
329
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
330
+           $fileSize = $fileSizeinit / 1024;
331
+
332
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
333
+               $this->folder->newFolder('SMS_Relentless/temp_files');
334
+           }
335
+
336
+           $userroot = $this->view->getRoot();
337
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
338
+
339
+           $target = $this->folder->newFile($targetfile);
340
+           $target->putContent($fileContent);
341
+
342
+           // Get the cumulative files size of the uploaded files
343
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
344
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
345
+
346
+           $fileSystemIterator = new FilesystemIterator($targetdir);
347
+
348
+           $dirfiles = [];
349
+           foreach ($fileSystemIterator as $fileInfo){
350
+                    $dirfiles[] = $fileInfo->getFilename();
351
+           }
352
+
353
+           $totalflsizeinit = 0;
354
+           foreach ($dirfiles as $key => $indfile) {
355
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
356
+                    $mbSize = round($fileSizeinit / 1024, 4);
357
+                    $totalflsizeinit += $mbSize;
358
+           }
359
+
360
+           $totalflsize = round($totalflsizeinit, 4);
361
+
362
+           return $totalflsize;
363
+    }
364
+
365
+
366
+    /**
367
+     * @NoAdminRequired
368
+     */
369
+    public function pickfile($path) {
370
+
371
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
372
+               $this->folder->newFolder('SMS_Relentless/temp_files');
373
+           }
374
+
375
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
376
+
377
+           $fltgt = $datadir . $this->userId . "/files" . $path;
378
+
379
+           $fileContent = file_get_contents($fltgt);
380
+
381
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
382
+
383
+           $patharr = explode("/", $path);
384
+
385
+           $revarr = array_reverse($patharr);
386
+
387
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
388
+
389
+           $target = $this->folder->newFile($relflpath);
390
+
391
+           $target->putContent($fileContent);
392
+
393
+           // Get the cumulative files size of the uploaded files
394
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
395
+
396
+           $fileSystemIterator = new FilesystemIterator($targetdir);
397
+
398
+           $dirfiles = [];
399
+           foreach ($fileSystemIterator as $fileInfo) {
400
+                    $dirfiles[] = $fileInfo->getFilename();
401
+           }
402
+
403
+           $totalflsizeinit = 0;
404
+
405
+           foreach ($dirfiles as $key => $indfile) {
406
+
407
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
408
+                    $mbSize = round($fileSizeinit / 1024, 4);
409
+                    $totalflsizeinit += $mbSize;
410
+           }
411
+
412
+           $totalflsize = round($totalflsizeinit, 4);
413
+
414
+           $pickresult = [$totalflsize, $pkfilesize];
415
+
416
+           return $pickresult;
417
+    }
418
+
419
+
420
+    /**
421
+     * @NoAdminRequired
422
+     */
423
+    public function removeupfile($removedfilename) {
424
+
425
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
426
+
427
+           $removefile = $this->view->unlink($tmpfl);
428
+
429
+           // Get the cumulative files size of the uploaded files
430
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
431
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
432
+           $fileSystemIterator = new FilesystemIterator($targetdir);
433
+
434
+           $dirfiles = [];
435
+           foreach ($fileSystemIterator as $fileInfo){
436
+                    $dirfiles[] = $fileInfo->getFilename();
437
+           }
438
+
439
+           $totalflsizeinit = 0;
440
+
441
+           foreach ($dirfiles as $key => $indfile) {
442
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
443
+                    $mbSize = round($fileSizeinit / 1024, 4);
444
+                    $totalflsizeinit += $mbSize;
445
+           }
446
+
447
+           $totalflsize = round($totalflsizeinit, 4);
448
+
449
+           return $totalflsize;
450
+    }
451
+
452
+
453
+    /**
454
+     * @NoAdminRequired
455
+     */
456
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
457
+
458
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
459
+         $telnyxkey = $telsmsapicred[0];
460
+         $teldelrecurl = $telsmsapicred[3];
461
+         $messagingprofid = $telsmsapicred[4];
462
+         $addDisplName = $telsmsapicred[24];
463
+
464
+         // Get the Display Name of the current user
465
+         $crtuser = $this->userManager->get($this->userId);
466
+         $displayname = $crtuser->getDisplayName();
467
+
468
+         if ($addDisplName == 1) {
469
+             $sentsmstext = $displayname . ": " . $sentsmstext;
470
+         }
471
+
472
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
473
+
474
+         $microinterval = $waitinterval * 1000;
475
+
476
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
477
+
478
+             usleep($microinterval);
479
+
480
+             $messagedate = date("Y-m-d H:i:s");
481
+
482
+             if ($ismms == 0) {
483
+
484
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
485
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
486
+                 } else {
487
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
488
+                 }
489
+
490
+                 $messagetexttel = $sentsmstext;
491
+
492
+             } else {
493
+
494
+                 $mediaURLarr = [];
495
+                 $includedMediaFiles = '';
496
+
497
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
498
+
499
+                      $userroot = $this->view->getRoot();
500
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
501
+
502
+                      $flsharetarget = $this->folder->newFile($filetoshare);
503
+
504
+	              $share = $this->shareManager->newShare();
505
+	              $share->setNode($flsharetarget);
506
+	              $share->setPermissions(Constants::PERMISSION_READ);
507
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
508
+	              $share->setSharedBy($this->userId);
509
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
510
+                      $expirydate->add(new \DateInterval('P1D'));
511
+                      $share->setExpirationDate($expirydate);
512
+                      $shared = $this->shareManager->createShare($share);
513
+                      $shareToken = $shared->getToken();
514
+
515
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
516
+
517
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
518
+
519
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
520
+                 }
521
+
522
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
523
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
524
+                 } else {
525
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
526
+                 }
527
+
528
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
529
+             }
530
+
531
+             $messageid = $message['id'];
532
+             $messagefrom = "Telnyx: " . $fromsender;
533
+             $messageto = $tonumber;
534
+             $messagenetwork = null;
535
+             $messageprice = null;
536
+             $messagestatus = $message['to'][0]['status'];
537
+             $messagedelivery = null;
538
+
539
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
540
+
541
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
542
+         }
543
+         return $displayname;
544
+    }
545
+
546
+
547
+    /**
548
+     * @NoAdminRequired
549
+     */
550
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
551
+
552
+         $plsmsapicred = $this->service->getapicredentials($this->userId);
553
+
554
+         $smsapikey = $plsmsapicred[5];
555
+         $smsapisecret = $plsmsapicred[6];
556
+         $smsapideliveryrecurl = $plsmsapicred[8];
557
+         $addDisplName = $plsmsapicred[24];
558
+
559
+         // Get the Display Name of the current user
560
+         $crtuser = $this->userManager->get($this->userId);
561
+         $displayname = $crtuser->getDisplayName();
562
+
563
+         if ($addDisplName == 1) {
564
+             $sentsmstext = $displayname . ": " . $sentsmstext;
565
+         }
566
+
567
+         $microinterval = $waitinterval * 1000;
568
+
569
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
570
+
571
+             usleep($microinterval);
572
+
573
+             $messagedatepl = date("Y-m-d H:i:s");
574
+
575
+             if ($ismms == 0) {
576
+
577
+                 $client = new RestClient($smsapikey, $smsapisecret);
578
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
579
+                 $messagetextpl = $sentsmstext;
580
+	         $messageidinit = $response->getmessageUuid(0);
581
+                 $messageid = $messageidinit[0];
582
+
583
+                 if (property_exists($response, 'error')) { 
584
+                     $messagestatus = "Error: " . $response->error;
585
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
586
+
587
+             } else {
588
+
589
+                 $mediaURLarr = [];
590
+                 $includedMediaFiles = '';
591
+
592
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
593
+
594
+                      $userroot = $this->view->getRoot();
595
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
596
+
597
+                      $flsharetarget = $this->folder->newFile($filetoshare);
598
+
599
+	              $share = $this->shareManager->newShare();
600
+	              $share->setNode($flsharetarget);
601
+	              $share->setPermissions(Constants::PERMISSION_READ);
602
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
603
+	              $share->setSharedBy($this->userId);
604
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
605
+                      $expirydate->add(new \DateInterval('P1D'));
606
+                      $share->setExpirationDate($expirydate);
607
+                      $shared = $this->shareManager->createShare($share);
608
+                      $shareToken = $shared->getToken();
609
+
610
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
611
+
612
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
613
+
614
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
615
+                 }
616
+
617
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
618
+		 $postedparamspl = json_encode($datatosendpl);
619
+
620
+		 $chpl = curl_init();
621
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
622
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
623
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
624
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
625
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
626
+		 curl_setopt($chpl, CURLOPT_POST, 1);
627
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
628
+		 $resultpl = curl_exec ($chpl);
629
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
630
+		 curl_close ($chpl);
631
+
632
+		 $decresultpl = json_decode($resultpl);
633
+
634
+                 if ($decresultpl) {
635
+                     if (property_exists($decresultpl, 'message_uuid')) {
636
+                         $messageidinit = $decresultpl->message_uuid;
637
+                         $messageid = $messageidinit[0];
638
+                     } else { $messageid = 'n/a'; }
639
+                 } else { $messageid = 'n/a'; }
640
+
641
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
642
+
643
+                     if (property_exists($decresultpl, 'error')) {
644
+                         $messagestatus = "Error: " . $decresultpl->error;
645
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
646
+
647
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
648
+
649
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
650
+             }
651
+
652
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
653
+                 $messagefrom = "Plivo: " . $fromsender;
654
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
655
+
656
+             $messageto = $tonumber;
657
+             $messagenetwork = '';
658
+             $messageprice = '';
659
+
660
+             $messagedelivery = '';
661
+
662
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
663
+
664
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
665
+         }
666
+         return $displayname;
667
+    }
668
+
669
+
670
+    /**
671
+     * @NoAdminRequired
672
+     */
673
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
674
+
675
+         $twsmsapicred = $this->service->getapicredentials($this->userId);
676
+
677
+         $sid = $twsmsapicred[15];
678
+         $token = $twsmsapicred[16];
679
+         $smsapirecurltw = $twsmsapicred[18];
680
+         $addDisplName = $twsmsapicred[24];
681
+
682
+         // Get the Display Name of the current user
683
+         $crtuser = $this->userManager->get($this->userId);
684
+         $displayname = $crtuser->getDisplayName();
685
+
686
+         if ($addDisplName == 1) {
687
+             $sentsmstext = $displayname . ": " . $sentsmstext;
688
+         }
689
+
690
+         $microinterval = $waitinterval * 1000;
691
+
692
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
693
+
694
+             usleep($microinterval);
695
+
696
+             $messagedatetw = date("Y-m-d H:i:s");
697
+
698
+             if ($ismms == 0) {
699
+
700
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
701
+                 $sentsmstextfintw = $sentsmstext;
702
+
703
+             } else {
704
+
705
+                 $mediaURLs = [];
706
+                 $includedMediaFiles = '';
707
+
708
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
709
+
710
+                      $userroot = $this->view->getRoot();
711
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
712
+
713
+                      $flsharetarget = $this->folder->newFile($filetoshare);
714
+
715
+	              $share = $this->shareManager->newShare();
716
+	              $share->setNode($flsharetarget);
717
+	              $share->setPermissions(Constants::PERMISSION_READ);
718
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
719
+	              $share->setSharedBy($this->userId);
720
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
721
+                      $expirydate->add(new \DateInterval('P1D'));
722
+                      $share->setExpirationDate($expirydate);
723
+                      $shared = $this->shareManager->createShare($share);
724
+                      $shareToken = $shared->getToken();
725
+
726
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
727
+
728
+                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
729
+
730
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
731
+                 }
732
+
733
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
734
+
735
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
736
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
737
+                 }
738
+
739
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
740
+             }
741
+
742
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
743
+
744
+	     $chtw = curl_init();
745
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
746
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
747
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
748
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
749
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
750
+	     curl_setopt($chtw, CURLOPT_POST, 1);
751
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
752
+
753
+	     $resulttw = curl_exec ($chtw);
754
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
755
+	     curl_close ($chtw);
756
+
757
+             $decresulttw = json_decode($resulttw);
758
+
759
+             if ($decresulttw) {
760
+                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
761
+             } else { $messageidtw = 'n/a'; }
762
+
763
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
764
+                 $messagestatustw = 'The message has been accepted for delivery.';
765
+             } else {
766
+                 $messagestatustw = 'An error occurred while trying to send the message.';
767
+             }
768
+
769
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
770
+                 $messagefromtw = "Twilio: " . $fromsender;
771
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
772
+
773
+             $messagenetworktw = '';
774
+             $messagepricetw = '';
775
+             $messagedeliverytw = '';
776
+
777
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
778
+
779
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
780
+         }
781
+         return $displayname;
782
+    }
783
+
784
+
785
+    /**
786
+     * @NoAdminRequired
787
+     */
788
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
789
+
790
+         $flsmsapicred = $this->service->getapicredentials($this->userId);
791
+
792
+         $flowapikey = $flsmsapicred[20];
793
+         $flowapisecret = $flsmsapicred[21];
794
+         $flowdelrecurl = $flsmsapicred[23];
795
+         $addDisplName = $flsmsapicred[24];
796
+
797
+         // Get the Display Name of the current user
798
+         $crtuser = $this->userManager->get($this->userId);
799
+         $displayname = $crtuser->getDisplayName();
800
+
801
+         if ($addDisplName == 1) {
802
+             $sentsmstext = $displayname . ": " . $sentsmstext;
803
+         }
804
+
805
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
806
+
807
+         $microinterval = $waitinterval * 1000;
808
+
809
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
810
+
811
+             usleep($microinterval);
812
+
813
+             $messagedatefl = date("Y-m-d H:i:s");
814
+
815
+             if ($ismms == 0) {
816
+
817
+                 $messagetextfinfl = $sentsmstext;
818
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
819
+
820
+             } else {
821
+
822
+		 $mediaurlsarr = [];
823
+		 $includedMediaFiles = '';
824
+
825
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
826
+
827
+		      $userroot = $this->view->getRoot();
828
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
829
+
830
+		      $flsharetarget = $this->folder->newFile($filetoshare);
831
+
832
+		      $share = $this->shareManager->newShare();
833
+		      $share->setNode($flsharetarget);
834
+		      $share->setPermissions(Constants::PERMISSION_READ);
835
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
836
+		      $share->setSharedBy($this->userId);
837
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
838
+                      $expirydate->add(new \DateInterval('P1D'));
839
+                      $share->setExpirationDate($expirydate);
840
+		      $shared = $this->shareManager->createShare($share);
841
+		      $shareToken = $shared->getToken();
842
+
843
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
844
+
845
+		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
846
+
847
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
848
+		 }
849
+
850
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
851
+
852
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
853
+             }
854
+
855
+	     $chfl = curl_init();
856
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
857
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
858
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
859
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
860
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
861
+	     curl_setopt($chfl, CURLOPT_POST, 1);
862
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
863
+	     $resultfl = curl_exec ($chfl);
864
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
865
+	     curl_close ($chfl);
866
+
867
+             $decresultfl = json_decode($resultfl);
868
+
869
+             if ($decresultfl) {
870
+                 if (property_exists($decresultfl, 'data')) { 
871
+                     $messageidfl = $decresultfl->data->id;
872
+                 } else { $messageidfl = 'n/a'; }
873
+             } else { $messageidfl = 'n/a'; }
874
+
875
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
876
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
877
+             } else { 
878
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
879
+             }
880
+
881
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
882
+                 $messagefromfl = "Flowroute: " . $fromsender;
883
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
884
+
885
+             $messagetofl = $tonumberfl;
886
+             $messagenetworkfl = '';
887
+             $messagepricefl = '';
888
+             $messagedeliveryfl = '';
889
+
890
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
891
+
892
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
893
+         }
894
+         return $displayname;
895
+    }
896
+
897
+
898
+    /**
899
+     * @NoAdminRequired
900
+     */
901
+    public function saveoldrecrows($userId, $oldrecRows) {
902
+
903
+           // Create the folder for removed messages if it doesn't exist
904
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
905
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
906
+           }
907
+           $savecheck = 0;
908
+
909
+           if (count($oldrecRows) > 1) {
910
+               $msfileContent = implode("", $oldrecRows);
911
+
912
+               $delrowsdate = date("Y-m-d_H-i-s");
913
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
914
+
915
+               $userroot = $this->view->getRoot();
916
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
917
+
918
+               $target = $this->folder->newFile($targetfile);
919
+               $target->putContent($msfileContent);
920
+
921
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
922
+                   $savecheck = 1;
923
+               }
924
+           }
925
+
926
+           return $savecheck;
927
+    }
928
+
929
+
930
+    /**
931
+     * @NoAdminRequired
932
+     */
933
+    public function saveoldsentrows($userId, $oldsentRows) {
934
+
935
+           // Create the folder for removed messages if it doesn't exist
936
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
937
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
938
+           }
939
+           $savesentcheck = 0;
940
+
941
+           if (count($oldsentRows) > 1) {
942
+               $sntfileContent = implode("", $oldsentRows);
943
+
944
+               $delsentrowsdate = date("Y-m-d_H-i-s");
945
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
946
+
947
+               $userroot = $this->view->getRoot();
948
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
949
+
950
+               $snttarget = $this->folder->newFile($snttargetfile);
951
+               $snttarget->putContent($sntfileContent);
952
+
953
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
954
+                   $savesentcheck = 1;
955
+               }
956
+           }
957
+
958
+           return $savesentcheck;
959
+    }
960
+
961
+
962
+    /**
963
+     * @NoAdminRequired
964
+     */
965
+    public function getreceivedtable($userId) {
966
+           return $this->service->getreceivedtable($this->userId);
967
+    }
968
+
969
+    /**
970
+     * @NoAdminRequired
971
+     */
972
+    public function getreceivedtablefordel($userId) {
973
+           return $this->service->getreceivedtablefordel($this->userId);
974
+    }
975
+
976
+    /**
977
+     * @NoAdminRequired
978
+     */
979
+    public function removerecrows($userId, $recmessagedbIDs) {
980
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
981
+    }
982
+
983
+    /**
984
+     * @NoAdminRequired
985
+     */
986
+    public function getsenttable($userId) {
987
+           return $this->service->getsenttable($this->userId);
988
+    }
989
+
990
+    /**
991
+     * @NoAdminRequired
992
+     */
993
+    public function getsenttablefordel($userId) {
994
+           return $this->service->getsenttablefordel($this->userId);
995
+    }
996
+
997
+    /**
998
+     * @NoAdminRequired
999
+     */
1000
+    public function removesentrows($userId, $sentmessagedbIDs) {
1001
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1002
+    }
1003
+
1004
+    /**
1005
+     * @NoAdminRequired
1006
+     */
1007
+    public function getgroupedtable($userId) {
1008
+           return $this->service->getgroupedtable($this->userId);
1009
+    }
1010
+
1011
+    /**
1012
+     * @NoAdminRequired
1013
+     */
1014
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1015
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1016
+    }
1017
+
1018
+    /**
1019
+     * @NoAdminRequired
1020
+     */
1021
+    public function getmsgsperpagenewmsg($userId) {
1022
+           return $this->service->getmsgsperpagenewmsg($this->userId);
1023
+    }
1024
+
1025
+    /**
1026
+     * @NoAdminRequired
1027
+     */
1028
+    public function getnewmsgindicator($userId) {
1029
+           return $this->service->getnewmsgindicator($this->userId);
1030
+    }
1031
+
1032
+    /**
1033
+     * @NoAdminRequired
1034
+     */
1035
+    public function getdelrecsettings($userId) {
1036
+           return $this->service->getdelrecsettings($this->userId);
1037
+    }
1038
+
1039
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1040
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1041
+    }
1042
+
1043
+    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1044
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1045
+    }
1046
+
1047
+    public function removenumberrestrictions($userId, $phoneNumber) {
1048
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1049
+    }
1050
+
1051
+    /**
1052
+     * @NoAdminRequired
1053
+     */
1054
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1055
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1056
+    }
1057
+
1058
+    /**
1059
+     * @NoAdminRequired
1060
+     */
1061
+    public function removeautoreplies($userId, $phoneNumber) {
1062
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1063
+    }
1064
+
1065
+    /**
1066
+     * @NoAdminRequired
1067
+     */
1068
+    public function getsettings($userId) {
1069
+           return $this->service->getsettings($this->userId);
1070
+    }
1071
+
1072
+    public function getadminsettings($userId) {
1073
+           return $this->service->getadminsettings($this->userId);
1074
+    }
1075
+
1076
+    /**
1077
+     * @NoAdminRequired
1078
+     */
1079
+    public function getautoreplyconf($userId) {
1080
+
1081
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1082
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1083
+
1084
+           // Get the display name of the current user
1085
+           $usrid = $this->userId;
1086
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1087
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1088
+	   $getusrdnmdata = $getusrdnmres->fetch();
1089
+	   $userDisplayNm = $getusrdnmdata['value'];
1090
+	   $getusrdnmres->closeCursor();
1091
+
1092
+           // Get the auto-replies for the available phone numbers
1093
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1094
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1095
+	   $getautorplres = $getautorpl->execute();
1096
+           $autorplconf = [];
1097
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1098
+                  $autorplconf[] = $acdatausrdnadm;
1099
+           }
1100
+	   $getautorplres->closeCursor();
1101
+
1102
+           if ($autorplconf) {
1103
+
1104
+               $autoreplyconf = [];
1105
+               foreach ($autorplconf as $arkey => $arvalue) {
1106
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1107
+                            $autoreplyconf[] = $arvalue;
1108
+                        }
1109
+               }
1110
+
1111
+           } else { $autoreplyconf = ''; }
1112
+
1113
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1114
+
1115
+           return $autoreplyfdb;
1116
+    }
1117
+
1118
+    /**
1119
+     * @NoAdminRequired
1120
+     */
1121
+    public function getgroupedpernumber($userId, $phoneNumber) {
1122
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1123
+    }
1124
+
1125
+    /**
1126
+     * @NoAdminRequired
1127
+     */
1128
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1129
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1130
+    }
1131
+
1132
+    /**
1133
+     * @NoAdminRequired
1134
+     */
1135
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval) {
1136
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval);
1137
+    }
1138
+
1139
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1140
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1141
+    }
1142
+
1143
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval) {
1144
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames, $msgCheckInterval);
1145
+    }
1146
+}
Browse code

removed appinfo/info.xml appinfo/signature.json appinfo/routes.php CHANGELOG.txt README.md css/style.css js/settings.js js/sendsms.js js/adminsettings.js js/showsmstables.js templates/settings/admin.php templates/settings/personal.php templates/navigation/index.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php l10n/en_GB.js l10n/en_GB.json l10n/en_US.js l10n/en_US.json

DoubleBastionAdmin authored on 14/02/2024 22:37:16
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1120 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\IURLGenerator;
49
-use OCP\Share\IManager;
50
-use OCP\Constants;
51
-use OCP\IGroupManager;
52
-use OCP\IDBConnection;
53
-use OCP\IUserManager;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $urlGenerator;
64
-    private $shareManager;
65
-    private $groupManager;
66
-    private $connection;
67
-    private $userManager;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->urlGenerator = $urlGenerator;
78
-	$this->shareManager = $shareManager;
79
-        $this->groupManager = $groupManager;
80
-        $this->connection = $connection;
81
-        $this->userManager = $userManager;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getbalancetel($userId) {
120
-
121
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
-
123
-        $telapikey = $telsmsapicred[0];
124
-        $ch = curl_init();
125
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
-
127
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
-        $responsetel = curl_exec($ch);
131
-        $recdatatel = json_decode($responsetel, TRUE);
132
-        $telbalresponse = $recdatatel['data']['balance'];
133
-        $currentbalancetel = round(floatval($telbalresponse), 3);
134
-        curl_close($ch);
135
-
136
-        return $currentbalancetel;
137
-    }
138
-
139
-
140
-    /**
141
-     * @NoAdminRequired
142
-     */
143
-    public function getbalancenex($userId) {
144
-
145
-        $smsapicred = $this->service->getapicredentials($this->userId);
146
-        $smsapikey = $smsapicred[5];
147
-        $smsapisecret = $smsapicred[6];
148
-
149
-        if ($smsapikey == '' || $smsapisecret == '') {
150
-            $currentbalancenex = "N/A";
151
-        } else {
152
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
-            $mesdata = file_get_contents($getmesdata);
154
-            $datainit = json_decode($mesdata);
155
-            $balancenex = $datainit->cash_credits;
156
-            $currentbalancenex = round(floatval($balancenex), 3);
157
-        }
158
-        return $currentbalancenex;
159
-    }
160
-
161
-
162
-    /**
163
-     * @NoAdminRequired
164
-     */
165
-    public function getbalancetwil($userId) {
166
-
167
-        $smsapicred = $this->service->getapicredentials($this->userId);
168
-        $smsapisid = $smsapicred[15];
169
-        $smsapitoken = $smsapicred[16];
170
-
171
-        if ($smsapisid == '' || $smsapitoken == '') {
172
-            $currentbalancetwil = "N/A";
173
-        } else {
174
-
175
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
-            $balancetwil = $twilbalance->balance;
177
-
178
-            $currentbalancetwil = round(floatval($balancetwil), 3);
179
-        }
180
-        return $currentbalancetwil;
181
-    }
182
-
183
-
184
-    /**
185
-     * @NoAdminRequired
186
-     */
187
-    public function getbalanceflow($userId) {
188
-
189
-        $currentbalanceflow = 'n/a';
190
-
191
-        return $currentbalanceflow;
192
-    }
193
-
194
-
195
-    /**
196
-     * @NoAdminRequired
197
-     */
198
-    public function getsmsnumbers($userId) {
199
-
200
-        return $this->service->getsmsnumbers($this->userId);
201
-    }
202
-
203
-
204
-    /**
205
-     * @NoAdminRequired
206
-     */
207
-    public function cleantempdir($userId) {
208
-
209
-        // Create the temporary folder if it doesn't exist
210
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
211
-            $this->folder->newFolder('SMS_Relentless/temp_files');
212
-        }
213
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
214
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
215
-        $fileSystemIterator = new FilesystemIterator($targetdir);
216
-
217
-        $dirfiles = [];
218
-        foreach ($fileSystemIterator as $fileInfo) {
219
-                 $dirfiles[] = $fileInfo->getFilename();
220
-        }
221
-
222
-        foreach ($dirfiles as $key => $indfile) {
223
-                 $thisuserroot = $this->view->getRoot();
224
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
225
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
226
-        }
227
-     }
228
-
229
-
230
-    /**
231
-     * @NoAdminRequired
232
-     */
233
-    public function cleanmultrecdir($userId) {
234
-
235
-        // Create the temporary folder if it doesn't exist
236
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
237
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
238
-        }
239
-        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
240
-        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
241
-        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
242
-
243
-        $dirfilesmrc = [];
244
-        foreach ($fileSystemIteratormrc as $fileInfomrc){
245
-                 $dirfilesmrc[] = $fileInfomrc->getFilename();
246
-        }
247
-
248
-        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
249
-                 $thisuserrootmrc = $this->view->getRoot();
250
-                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
251
-                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
252
-        }
253
-     }
254
-
255
-
256
-    /**
257
-     * @NoAdminRequired
258
-     */
259
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
260
-
261
-        // Create the temporary folder if it doesn't exist
262
-        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
263
-            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
264
-        }
265
-
266
-        // First delete any file that has been previously uploaded
267
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
268
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
269
-        $fileSystemIterator = new FilesystemIterator($targetdir);
270
-
271
-        $dirfiles = [];
272
-        foreach ($fileSystemIterator as $fileInfo){
273
-                 $dirfiles[] = $fileInfo->getFilename();
274
-        }
275
-
276
-        foreach ($dirfiles as $key => $indfile) {
277
-                 $thisuserroot = $this->view->getRoot();
278
-                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
279
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
280
-        }
281
-
282
-        // Upload the new file
283
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
284
-        $fileName = $_FILES['uploadfileforsms']['name'];
285
-
286
-        $userroot = $this->view->getRoot();
287
-        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
288
-
289
-        $target = $this->folder->newFile($targetfile);
290
-        $target->putContent($fileContent);
291
-
292
-        // Extract the phone numbers from the file
293
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
294
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
295
-        $numberarrayfourth = explode(",", $numberarraytert);
296
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
297
-        $numberarray = array_unique($numberarrayfifth);
298
-
299
-        return $numberarray;
300
-    }
301
-
302
-
303
-    /**
304
-     * @NoAdminRequired
305
-     */
306
-    public function uploadfile($uploadfileformms) {
307
-
308
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
309
-           $fileName = $_FILES['uploadfileformms']['name'];
310
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
311
-           $fileSize = $fileSizeinit / 1024;
312
-
313
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
314
-               $this->folder->newFolder('SMS_Relentless/temp_files');
315
-           }
316
-
317
-           $userroot = $this->view->getRoot();
318
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
319
-
320
-           $target = $this->folder->newFile($targetfile);
321
-           $target->putContent($fileContent);
322
-
323
-           // Get the cumulative files size of the uploaded files
324
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
325
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
326
-
327
-           $fileSystemIterator = new FilesystemIterator($targetdir);
328
-
329
-           $dirfiles = [];
330
-           foreach ($fileSystemIterator as $fileInfo){
331
-                    $dirfiles[] = $fileInfo->getFilename();
332
-           }
333
-
334
-           $totalflsizeinit = 0;
335
-           foreach ($dirfiles as $key => $indfile) {
336
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
337
-                    $mbSize = round($fileSizeinit / 1024, 4);
338
-                    $totalflsizeinit += $mbSize;
339
-           }
340
-
341
-           $totalflsize = round($totalflsizeinit, 4);
342
-
343
-           return $totalflsize;
344
-    }
345
-
346
-
347
-    /**
348
-     * @NoAdminRequired
349
-     */
350
-    public function pickfile($path) {
351
-
352
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
353
-               $this->folder->newFolder('SMS_Relentless/temp_files');
354
-           }
355
-
356
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
357
-
358
-           $fltgt = $datadir . $this->userId . "/files" . $path;
359
-
360
-           $fileContent = file_get_contents($fltgt);
361
-
362
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
363
-
364
-           $patharr = explode("/", $path);
365
-
366
-           $revarr = array_reverse($patharr);
367
-
368
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
369
-
370
-           $target = $this->folder->newFile($relflpath);
371
-
372
-           $target->putContent($fileContent);
373
-
374
-           // Get the cumulative files size of the uploaded files
375
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
376
-
377
-           $fileSystemIterator = new FilesystemIterator($targetdir);
378
-
379
-           $dirfiles = [];
380
-           foreach ($fileSystemIterator as $fileInfo) {
381
-                    $dirfiles[] = $fileInfo->getFilename();
382
-           }
383
-
384
-           $totalflsizeinit = 0;
385
-
386
-           foreach ($dirfiles as $key => $indfile) {
387
-
388
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
389
-                    $mbSize = round($fileSizeinit / 1024, 4);
390
-                    $totalflsizeinit += $mbSize;
391
-           }
392
-
393
-           $totalflsize = round($totalflsizeinit, 4);
394
-
395
-           $pickresult = [$totalflsize, $pkfilesize];
396
-
397
-           return $pickresult;
398
-    }
399
-
400
-
401
-    /**
402
-     * @NoAdminRequired
403
-     */
404
-    public function removeupfile($removedfilename) {
405
-
406
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
407
-
408
-           $removefile = $this->view->unlink($tmpfl);
409
-
410
-           // Get the cumulative files size of the uploaded files
411
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
412
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
413
-           $fileSystemIterator = new FilesystemIterator($targetdir);
414
-
415
-           $dirfiles = [];
416
-           foreach ($fileSystemIterator as $fileInfo){
417
-                    $dirfiles[] = $fileInfo->getFilename();
418
-           }
419
-
420
-           $totalflsizeinit = 0;
421
-
422
-           foreach ($dirfiles as $key => $indfile) {
423
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
424
-                    $mbSize = round($fileSizeinit / 1024, 4);
425
-                    $totalflsizeinit += $mbSize;
426
-           }
427
-
428
-           $totalflsize = round($totalflsizeinit, 4);
429
-
430
-           return $totalflsize;
431
-    }
432
-
433
-
434
-    /**
435
-     * @NoAdminRequired
436
-     */
437
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
438
-
439
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
440
-         $telnyxkey = $telsmsapicred[0];
441
-         $teldelrecurl = $telsmsapicred[3];
442
-         $messagingprofid = $telsmsapicred[4];
443
-         $addDisplName = $telsmsapicred[24];
444
-
445
-         // Get the Display Name of the current user
446
-         $crtuser = $this->userManager->get($this->userId);
447
-         $displayname = $crtuser->getDisplayName();
448
-
449
-         if ($addDisplName == 1) {
450
-             $sentsmstext = $displayname . ": " . $sentsmstext;
451
-         }
452
-
453
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
454
-
455
-         $microinterval = $waitinterval * 1000;
456
-
457
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
458
-
459
-             usleep($microinterval);
460
-
461
-             $messagedate = date("Y-m-d H:i:s");
462
-
463
-             if ($ismms == 0) {
464
-
465
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
466
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
467
-                 } else {
468
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
469
-                 }
470
-
471
-                 $messagetexttel = $sentsmstext;
472
-
473
-             } else {
474
-
475
-                 $mediaURLarr = [];
476
-                 $includedMediaFiles = '';
477
-
478
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
479
-
480
-                      $userroot = $this->view->getRoot();
481
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
482
-
483
-                      $flsharetarget = $this->folder->newFile($filetoshare);
484
-
485
-	              $share = $this->shareManager->newShare();
486
-	              $share->setNode($flsharetarget);
487
-	              $share->setPermissions(Constants::PERMISSION_READ);
488
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
489
-	              $share->setSharedBy($this->userId);
490
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
491
-                      $expirydate->add(new \DateInterval('P1D'));
492
-                      $share->setExpirationDate($expirydate);
493
-                      $shared = $this->shareManager->createShare($share);
494
-                      $shareToken = $shared->getToken();
495
-
496
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
497
-
498
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
499
-
500
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
501
-                 }
502
-
503
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
504
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
505
-                 } else {
506
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
507
-                 }
508
-
509
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
510
-             }
511
-
512
-             $messageid = $message['id'];
513
-             $messagefrom = "Telnyx: " . $fromsender;
514
-             $messageto = $tonumber;
515
-             $messagenetwork = null;
516
-             $messageprice = null;
517
-             $messagestatus = $message['to'][0]['status'];
518
-             $messagedelivery = null;
519
-
520
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
521
-
522
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
523
-         }
524
-         return $displayname;
525
-    }
526
-
527
-
528
-    /**
529
-     * @NoAdminRequired
530
-     */
531
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
532
-
533
-         $plsmsapicred = $this->service->getapicredentials($this->userId);
534
-
535
-         $smsapikey = $plsmsapicred[5];
536
-         $smsapisecret = $plsmsapicred[6];
537
-         $smsapideliveryrecurl = $plsmsapicred[8];
538
-         $addDisplName = $plsmsapicred[24];
539
-
540
-         // Get the Display Name of the current user
541
-         $crtuser = $this->userManager->get($this->userId);
542
-         $displayname = $crtuser->getDisplayName();
543
-
544
-         if ($addDisplName == 1) {
545
-             $sentsmstext = $displayname . ": " . $sentsmstext;
546
-         }
547
-
548
-         $microinterval = $waitinterval * 1000;
549
-
550
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
551
-
552
-             usleep($microinterval);
553
-
554
-             $messagedatepl = date("Y-m-d H:i:s");
555
-
556
-             if ($ismms == 0) {
557
-
558
-                 $client = new RestClient($smsapikey, $smsapisecret);
559
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
560
-                 $messagetextpl = $sentsmstext;
561
-	         $messageidinit = $response->getmessageUuid(0);
562
-                 $messageid = $messageidinit[0];
563
-
564
-                 if (property_exists($response, 'error')) { 
565
-                     $messagestatus = "Error: " . $response->error;
566
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
567
-
568
-             } else {
569
-
570
-                 $mediaURLarr = [];
571
-                 $includedMediaFiles = '';
572
-
573
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
574
-
575
-                      $userroot = $this->view->getRoot();
576
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
577
-
578
-                      $flsharetarget = $this->folder->newFile($filetoshare);
579
-
580
-	              $share = $this->shareManager->newShare();
581
-	              $share->setNode($flsharetarget);
582
-	              $share->setPermissions(Constants::PERMISSION_READ);
583
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
584
-	              $share->setSharedBy($this->userId);
585
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
586
-                      $expirydate->add(new \DateInterval('P1D'));
587
-                      $share->setExpirationDate($expirydate);
588
-                      $shared = $this->shareManager->createShare($share);
589
-                      $shareToken = $shared->getToken();
590
-
591
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
592
-
593
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
594
-
595
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
596
-                 }
597
-
598
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
599
-		 $postedparamspl = json_encode($datatosendpl);
600
-
601
-		 $chpl = curl_init();
602
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
603
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
604
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
605
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
606
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
607
-		 curl_setopt($chpl, CURLOPT_POST, 1);
608
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
609
-		 $resultpl = curl_exec ($chpl);
610
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
611
-		 curl_close ($chpl);
612
-
613
-		 $decresultpl = json_decode($resultpl);
614
-
615
-                 if ($decresultpl) {
616
-                     if (property_exists($decresultpl, 'message_uuid')) {
617
-                         $messageidinit = $decresultpl->message_uuid;
618
-                         $messageid = $messageidinit[0];
619
-                     } else { $messageid = 'n/a'; }
620
-                 } else { $messageid = 'n/a'; }
621
-
622
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
623
-
624
-                     if (property_exists($decresultpl, 'error')) {
625
-                         $messagestatus = "Error: " . $decresultpl->error;
626
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
627
-
628
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
629
-
630
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
631
-             }
632
-
633
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
634
-                 $messagefrom = "Plivo: " . $fromsender;
635
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
636
-
637
-             $messageto = $tonumber;
638
-             $messagenetwork = '';
639
-             $messageprice = '';
640
-
641
-             $messagedelivery = '';
642
-
643
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
644
-
645
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
646
-         }
647
-         return $displayname;
648
-    }
649
-
650
-
651
-    /**
652
-     * @NoAdminRequired
653
-     */
654
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
655
-
656
-         $twsmsapicred = $this->service->getapicredentials($this->userId);
657
-
658
-         $sid = $twsmsapicred[15];
659
-         $token = $twsmsapicred[16];
660
-         $smsapirecurltw = $twsmsapicred[18];
661
-         $addDisplName = $twsmsapicred[24];
662
-
663
-         // Get the Display Name of the current user
664
-         $crtuser = $this->userManager->get($this->userId);
665
-         $displayname = $crtuser->getDisplayName();
666
-
667
-         if ($addDisplName == 1) {
668
-             $sentsmstext = $displayname . ": " . $sentsmstext;
669
-         }
670
-
671
-         $microinterval = $waitinterval * 1000;
672
-
673
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
674
-
675
-             usleep($microinterval);
676
-
677
-             $messagedatetw = date("Y-m-d H:i:s");
678
-
679
-             if ($ismms == 0) {
680
-
681
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
682
-                 $sentsmstextfintw = $sentsmstext;
683
-
684
-             } else {
685
-
686
-                 $mediaURLs = [];
687
-                 $includedMediaFiles = '';
688
-
689
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
690
-
691
-                      $userroot = $this->view->getRoot();
692
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
693
-
694
-                      $flsharetarget = $this->folder->newFile($filetoshare);
695
-
696
-	              $share = $this->shareManager->newShare();
697
-	              $share->setNode($flsharetarget);
698
-	              $share->setPermissions(Constants::PERMISSION_READ);
699
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
700
-	              $share->setSharedBy($this->userId);
701
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
702
-                      $expirydate->add(new \DateInterval('P1D'));
703
-                      $share->setExpirationDate($expirydate);
704
-                      $shared = $this->shareManager->createShare($share);
705
-                      $shareToken = $shared->getToken();
706
-
707
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
708
-
709
-                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
710
-
711
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
712
-                 }
713
-
714
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
715
-
716
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
717
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
718
-                 }
719
-
720
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
721
-             }
722
-
723
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
724
-
725
-	     $chtw = curl_init();
726
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
727
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
728
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
729
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
730
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
731
-	     curl_setopt($chtw, CURLOPT_POST, 1);
732
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
733
-
734
-	     $resulttw = curl_exec ($chtw);
735
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
736
-	     curl_close ($chtw);
737
-
738
-             $decresulttw = json_decode($resulttw);
739
-
740
-             if ($decresulttw) {
741
-                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
742
-             } else { $messageidtw = 'n/a'; }
743
-
744
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
745
-                 $messagestatustw = 'The message has been accepted for delivery.';
746
-             } else {
747
-                 $messagestatustw = 'An error occurred while trying to send the message.';
748
-             }
749
-
750
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
751
-                 $messagefromtw = "Twilio: " . $fromsender;
752
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
753
-
754
-             $messagenetworktw = '';
755
-             $messagepricetw = '';
756
-             $messagedeliverytw = '';
757
-
758
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
759
-
760
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
761
-         }
762
-         return $displayname;
763
-    }
764
-
765
-
766
-    /**
767
-     * @NoAdminRequired
768
-     */
769
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
770
-
771
-         $flsmsapicred = $this->service->getapicredentials($this->userId);
772
-
773
-         $flowapikey = $flsmsapicred[20];
774
-         $flowapisecret = $flsmsapicred[21];
775
-         $flowdelrecurl = $flsmsapicred[23];
776
-         $addDisplName = $flsmsapicred[24];
777
-
778
-         // Get the Display Name of the current user
779
-         $crtuser = $this->userManager->get($this->userId);
780
-         $displayname = $crtuser->getDisplayName();
781
-
782
-         if ($addDisplName == 1) {
783
-             $sentsmstext = $displayname . ": " . $sentsmstext;
784
-         }
785
-
786
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
787
-
788
-         $microinterval = $waitinterval * 1000;
789
-
790
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
791
-
792
-             usleep($microinterval);
793
-
794
-             $messagedatefl = date("Y-m-d H:i:s");
795
-
796
-             if ($ismms == 0) {
797
-
798
-                 $messagetextfinfl = $sentsmstext;
799
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
800
-
801
-             } else {
802
-
803
-		 $mediaurlsarr = [];
804
-		 $includedMediaFiles = '';
805
-
806
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
807
-
808
-		      $userroot = $this->view->getRoot();
809
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
810
-
811
-		      $flsharetarget = $this->folder->newFile($filetoshare);
812
-
813
-		      $share = $this->shareManager->newShare();
814
-		      $share->setNode($flsharetarget);
815
-		      $share->setPermissions(Constants::PERMISSION_READ);
816
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
817
-		      $share->setSharedBy($this->userId);
818
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
819
-                      $expirydate->add(new \DateInterval('P1D'));
820
-                      $share->setExpirationDate($expirydate);
821
-		      $shared = $this->shareManager->createShare($share);
822
-		      $shareToken = $shared->getToken();
823
-
824
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
825
-
826
-		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
827
-
828
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
829
-		 }
830
-
831
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
832
-
833
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
834
-             }
835
-
836
-	     $chfl = curl_init();
837
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
838
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
839
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
840
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
841
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
842
-	     curl_setopt($chfl, CURLOPT_POST, 1);
843
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
844
-	     $resultfl = curl_exec ($chfl);
845
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
846
-	     curl_close ($chfl);
847
-
848
-             $decresultfl = json_decode($resultfl);
849
-
850
-             if ($decresultfl) {
851
-                 if (property_exists($decresultfl, 'data')) { 
852
-                     $messageidfl = $decresultfl->data->id;
853
-                 } else { $messageidfl = 'n/a'; }
854
-             } else { $messageidfl = 'n/a'; }
855
-
856
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
857
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
858
-             } else { 
859
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
860
-             }
861
-
862
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
863
-                 $messagefromfl = "Flowroute: " . $fromsender;
864
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
865
-
866
-             $messagetofl = $tonumberfl;
867
-             $messagenetworkfl = '';
868
-             $messagepricefl = '';
869
-             $messagedeliveryfl = '';
870
-
871
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
872
-
873
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
874
-         }
875
-         return $displayname;
876
-    }
877
-
878
-
879
-    /**
880
-     * @NoAdminRequired
881
-     */
882
-    public function saveoldrecrows($userId, $oldrecRows) {
883
-
884
-           // Create the folder for removed messages if it doesn't exist
885
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
886
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
887
-           }
888
-           $savecheck = 0;
889
-
890
-           if (count($oldrecRows) > 1) {
891
-               $msfileContent = implode("", $oldrecRows);
892
-
893
-               $delrowsdate = date("Y-m-d_H-i-s");
894
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
895
-
896
-               $userroot = $this->view->getRoot();
897
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
898
-
899
-               $target = $this->folder->newFile($targetfile);
900
-               $target->putContent($msfileContent);
901
-
902
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
903
-                   $savecheck = 1;
904
-               }
905
-           }
906
-
907
-           return $savecheck;
908
-    }
909
-
910
-
911
-    /**
912
-     * @NoAdminRequired
913
-     */
914
-    public function saveoldsentrows($userId, $oldsentRows) {
915
-
916
-           // Create the folder for removed messages if it doesn't exist
917
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
918
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
919
-           }
920
-           $savesentcheck = 0;
921
-
922
-           if (count($oldsentRows) > 1) {
923
-               $sntfileContent = implode("", $oldsentRows);
924
-
925
-               $delsentrowsdate = date("Y-m-d_H-i-s");
926
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
927
-
928
-               $userroot = $this->view->getRoot();
929
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
930
-
931
-               $snttarget = $this->folder->newFile($snttargetfile);
932
-               $snttarget->putContent($sntfileContent);
933
-
934
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
935
-                   $savesentcheck = 1;
936
-               }
937
-           }
938
-
939
-           return $savesentcheck;
940
-    }
941
-
942
-
943
-    /**
944
-     * @NoAdminRequired
945
-     */
946
-    public function getreceivedtable($userId) {
947
-           return $this->service->getreceivedtable($this->userId);
948
-    }
949
-
950
-    /**
951
-     * @NoAdminRequired
952
-     */
953
-    public function getreceivedtablefordel($userId) {
954
-           return $this->service->getreceivedtablefordel($this->userId);
955
-    }
956
-
957
-    /**
958
-     * @NoAdminRequired
959
-     */
960
-    public function removerecrows($userId, $recmessagedbIDs) {
961
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
962
-    }
963
-
964
-    /**
965
-     * @NoAdminRequired
966
-     */
967
-    public function getsenttable($userId) {
968
-           return $this->service->getsenttable($this->userId);
969
-    }
970
-
971
-    /**
972
-     * @NoAdminRequired
973
-     */
974
-    public function getsenttablefordel($userId) {
975
-           return $this->service->getsenttablefordel($this->userId);
976
-    }
977
-
978
-    /**
979
-     * @NoAdminRequired
980
-     */
981
-    public function removesentrows($userId, $sentmessagedbIDs) {
982
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
983
-    }
984
-
985
-    /**
986
-     * @NoAdminRequired
987
-     */
988
-    public function getgroupedtable($userId) {
989
-           return $this->service->getgroupedtable($this->userId);
990
-    }
991
-
992
-    /**
993
-     * @NoAdminRequired
994
-     */
995
-    public function savedisplayname($userId, $authorDisplayname, $from) {
996
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
997
-    }
998
-
999
-    /**
1000
-     * @NoAdminRequired
1001
-     */
1002
-    public function getmessagesperpage($userId) {
1003
-           return $this->service->getmessagesperpage($this->userId);
1004
-    }
1005
-
1006
-    /**
1007
-     * @NoAdminRequired
1008
-     */
1009
-    public function getdelrecsettings($userId) {
1010
-           return $this->service->getdelrecsettings($this->userId);
1011
-    }
1012
-
1013
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1014
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1015
-    }
1016
-
1017
-    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1018
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1019
-    }
1020
-
1021
-    public function removenumberrestrictions($userId, $phoneNumber) {
1022
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1023
-    }
1024
-
1025
-    /**
1026
-     * @NoAdminRequired
1027
-     */
1028
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1029
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1030
-    }
1031
-
1032
-    /**
1033
-     * @NoAdminRequired
1034
-     */
1035
-    public function removeautoreplies($userId, $phoneNumber) {
1036
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1037
-    }
1038
-
1039
-    /**
1040
-     * @NoAdminRequired
1041
-     */
1042
-    public function getsettings($userId) {
1043
-           return $this->service->getsettings($this->userId);
1044
-    }
1045
-
1046
-    public function getadminsettings($userId) {
1047
-           return $this->service->getadminsettings($this->userId);
1048
-    }
1049
-
1050
-    /**
1051
-     * @NoAdminRequired
1052
-     */
1053
-    public function getautoreplyconf($userId) {
1054
-
1055
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1056
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1057
-
1058
-           // Get the display name of the current user
1059
-           $usrid = $this->userId;
1060
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1061
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1062
-	   $getusrdnmdata = $getusrdnmres->fetch();
1063
-	   $userDisplayNm = $getusrdnmdata['value'];
1064
-	   $getusrdnmres->closeCursor();
1065
-
1066
-           // Get the auto-replies for the available phone numbers
1067
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1068
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1069
-	   $getautorplres = $getautorpl->execute();
1070
-           $autorplconf = [];
1071
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1072
-                  $autorplconf[] = $acdatausrdnadm;
1073
-           }
1074
-	   $getautorplres->closeCursor();
1075
-
1076
-           if ($autorplconf) {
1077
-
1078
-               $autoreplyconf = [];
1079
-               foreach ($autorplconf as $arkey => $arvalue) {
1080
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1081
-                            $autoreplyconf[] = $arvalue;
1082
-                        }
1083
-               }
1084
-
1085
-           } else { $autoreplyconf = ''; }
1086
-
1087
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1088
-
1089
-           return $autoreplyfdb;
1090
-    }
1091
-
1092
-    /**
1093
-     * @NoAdminRequired
1094
-     */
1095
-    public function getgroupedpernumber($userId, $phoneNumber) {
1096
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1097
-    }
1098
-
1099
-    /**
1100
-     * @NoAdminRequired
1101
-     */
1102
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1103
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1104
-    }
1105
-
1106
-    /**
1107
-     * @NoAdminRequired
1108
-     */
1109
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1110
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1111
-    }
1112
-
1113
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1114
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1115
-    }
1116
-
1117
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1118
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1119
-    }
1120
-}
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json appinfo/routes.php css/style.css js/adminsettings.js js/deleteoldsms.js js/sendsms.js js/settings.js js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php providers/Telnyx/lib/ApiResource.php

DoubleBastionAdmin authored on 15/07/2023 22:05:06
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1120 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\IURLGenerator;
49
+use OCP\Share\IManager;
50
+use OCP\Constants;
51
+use OCP\IGroupManager;
52
+use OCP\IDBConnection;
53
+use OCP\IUserManager;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $urlGenerator;
64
+    private $shareManager;
65
+    private $groupManager;
66
+    private $connection;
67
+    private $userManager;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->urlGenerator = $urlGenerator;
78
+	$this->shareManager = $shareManager;
79
+        $this->groupManager = $groupManager;
80
+        $this->connection = $connection;
81
+        $this->userManager = $userManager;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getbalancetel($userId) {
120
+
121
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
+
123
+        $telapikey = $telsmsapicred[0];
124
+        $ch = curl_init();
125
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
+
127
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
+        $responsetel = curl_exec($ch);
131
+        $recdatatel = json_decode($responsetel, TRUE);
132
+        $telbalresponse = $recdatatel['data']['balance'];
133
+        $currentbalancetel = round(floatval($telbalresponse), 3);
134
+        curl_close($ch);
135
+
136
+        return $currentbalancetel;
137
+    }
138
+
139
+
140
+    /**
141
+     * @NoAdminRequired
142
+     */
143
+    public function getbalancenex($userId) {
144
+
145
+        $smsapicred = $this->service->getapicredentials($this->userId);
146
+        $smsapikey = $smsapicred[5];
147
+        $smsapisecret = $smsapicred[6];
148
+
149
+        if ($smsapikey == '' || $smsapisecret == '') {
150
+            $currentbalancenex = "N/A";
151
+        } else {
152
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
+            $mesdata = file_get_contents($getmesdata);
154
+            $datainit = json_decode($mesdata);
155
+            $balancenex = $datainit->cash_credits;
156
+            $currentbalancenex = round(floatval($balancenex), 3);
157
+        }
158
+        return $currentbalancenex;
159
+    }
160
+
161
+
162
+    /**
163
+     * @NoAdminRequired
164
+     */
165
+    public function getbalancetwil($userId) {
166
+
167
+        $smsapicred = $this->service->getapicredentials($this->userId);
168
+        $smsapisid = $smsapicred[15];
169
+        $smsapitoken = $smsapicred[16];
170
+
171
+        if ($smsapisid == '' || $smsapitoken == '') {
172
+            $currentbalancetwil = "N/A";
173
+        } else {
174
+
175
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
+            $balancetwil = $twilbalance->balance;
177
+
178
+            $currentbalancetwil = round(floatval($balancetwil), 3);
179
+        }
180
+        return $currentbalancetwil;
181
+    }
182
+
183
+
184
+    /**
185
+     * @NoAdminRequired
186
+     */
187
+    public function getbalanceflow($userId) {
188
+
189
+        $currentbalanceflow = 'n/a';
190
+
191
+        return $currentbalanceflow;
192
+    }
193
+
194
+
195
+    /**
196
+     * @NoAdminRequired
197
+     */
198
+    public function getsmsnumbers($userId) {
199
+
200
+        return $this->service->getsmsnumbers($this->userId);
201
+    }
202
+
203
+
204
+    /**
205
+     * @NoAdminRequired
206
+     */
207
+    public function cleantempdir($userId) {
208
+
209
+        // Create the temporary folder if it doesn't exist
210
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
211
+            $this->folder->newFolder('SMS_Relentless/temp_files');
212
+        }
213
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
214
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
215
+        $fileSystemIterator = new FilesystemIterator($targetdir);
216
+
217
+        $dirfiles = [];
218
+        foreach ($fileSystemIterator as $fileInfo) {
219
+                 $dirfiles[] = $fileInfo->getFilename();
220
+        }
221
+
222
+        foreach ($dirfiles as $key => $indfile) {
223
+                 $thisuserroot = $this->view->getRoot();
224
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
225
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
226
+        }
227
+     }
228
+
229
+
230
+    /**
231
+     * @NoAdminRequired
232
+     */
233
+    public function cleanmultrecdir($userId) {
234
+
235
+        // Create the temporary folder if it doesn't exist
236
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
237
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
238
+        }
239
+        $datadirmrc = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
240
+        $targetdirmrc = $datadirmrc . $this->userId . "/files/SMS_Relentless/multiple_recipients";
241
+        $fileSystemIteratormrc = new FilesystemIterator($targetdirmrc);
242
+
243
+        $dirfilesmrc = [];
244
+        foreach ($fileSystemIteratormrc as $fileInfomrc){
245
+                 $dirfilesmrc[] = $fileInfomrc->getFilename();
246
+        }
247
+
248
+        foreach ($dirfilesmrc as $mreckey => $mrecfile) {
249
+                 $thisuserrootmrc = $this->view->getRoot();
250
+                 $mrectempfile = $thisuserrootmrc . "/SMS_Relentless/multiple_recipients/" . $mrecfile;
251
+                 $removemrectmpfile = $this->filesystem->unlink($mrectempfile);
252
+        }
253
+     }
254
+
255
+
256
+    /**
257
+     * @NoAdminRequired
258
+     */
259
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
260
+
261
+        // Create the temporary folder if it doesn't exist
262
+        if ($this->folder->nodeExists('SMS_Relentless/multiple_recipients') == false) {
263
+            $this->folder->newFolder('SMS_Relentless/multiple_recipients');
264
+        }
265
+
266
+        // First delete any file that has been previously uploaded
267
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
268
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/multiple_recipients";
269
+        $fileSystemIterator = new FilesystemIterator($targetdir);
270
+
271
+        $dirfiles = [];
272
+        foreach ($fileSystemIterator as $fileInfo){
273
+                 $dirfiles[] = $fileInfo->getFilename();
274
+        }
275
+
276
+        foreach ($dirfiles as $key => $indfile) {
277
+                 $thisuserroot = $this->view->getRoot();
278
+                 $tempfile = $thisuserroot . "/SMS_Relentless/multiple_recipients/" . $indfile;
279
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
280
+        }
281
+
282
+        // Upload the new file
283
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
284
+        $fileName = $_FILES['uploadfileforsms']['name'];
285
+
286
+        $userroot = $this->view->getRoot();
287
+        $targetfile = $userroot . "/SMS_Relentless/multiple_recipients/" . $fileName;
288
+
289
+        $target = $this->folder->newFile($targetfile);
290
+        $target->putContent($fileContent);
291
+
292
+        // Extract the phone numbers from the file
293
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
294
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
295
+        $numberarrayfourth = explode(",", $numberarraytert);
296
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
297
+        $numberarray = array_unique($numberarrayfifth);
298
+
299
+        return $numberarray;
300
+    }
301
+
302
+
303
+    /**
304
+     * @NoAdminRequired
305
+     */
306
+    public function uploadfile($uploadfileformms) {
307
+
308
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
309
+           $fileName = $_FILES['uploadfileformms']['name'];
310
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
311
+           $fileSize = $fileSizeinit / 1024;
312
+
313
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
314
+               $this->folder->newFolder('SMS_Relentless/temp_files');
315
+           }
316
+
317
+           $userroot = $this->view->getRoot();
318
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
319
+
320
+           $target = $this->folder->newFile($targetfile);
321
+           $target->putContent($fileContent);
322
+
323
+           // Get the cumulative files size of the uploaded files
324
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
325
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
326
+
327
+           $fileSystemIterator = new FilesystemIterator($targetdir);
328
+
329
+           $dirfiles = [];
330
+           foreach ($fileSystemIterator as $fileInfo){
331
+                    $dirfiles[] = $fileInfo->getFilename();
332
+           }
333
+
334
+           $totalflsizeinit = 0;
335
+           foreach ($dirfiles as $key => $indfile) {
336
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
337
+                    $mbSize = round($fileSizeinit / 1024, 4);
338
+                    $totalflsizeinit += $mbSize;
339
+           }
340
+
341
+           $totalflsize = round($totalflsizeinit, 4);
342
+
343
+           return $totalflsize;
344
+    }
345
+
346
+
347
+    /**
348
+     * @NoAdminRequired
349
+     */
350
+    public function pickfile($path) {
351
+
352
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
353
+               $this->folder->newFolder('SMS_Relentless/temp_files');
354
+           }
355
+
356
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
357
+
358
+           $fltgt = $datadir . $this->userId . "/files" . $path;
359
+
360
+           $fileContent = file_get_contents($fltgt);
361
+
362
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
363
+
364
+           $patharr = explode("/", $path);
365
+
366
+           $revarr = array_reverse($patharr);
367
+
368
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
369
+
370
+           $target = $this->folder->newFile($relflpath);
371
+
372
+           $target->putContent($fileContent);
373
+
374
+           // Get the cumulative files size of the uploaded files
375
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
376
+
377
+           $fileSystemIterator = new FilesystemIterator($targetdir);
378
+
379
+           $dirfiles = [];
380
+           foreach ($fileSystemIterator as $fileInfo) {
381
+                    $dirfiles[] = $fileInfo->getFilename();
382
+           }
383
+
384
+           $totalflsizeinit = 0;
385
+
386
+           foreach ($dirfiles as $key => $indfile) {
387
+
388
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
389
+                    $mbSize = round($fileSizeinit / 1024, 4);
390
+                    $totalflsizeinit += $mbSize;
391
+           }
392
+
393
+           $totalflsize = round($totalflsizeinit, 4);
394
+
395
+           $pickresult = [$totalflsize, $pkfilesize];
396
+
397
+           return $pickresult;
398
+    }
399
+
400
+
401
+    /**
402
+     * @NoAdminRequired
403
+     */
404
+    public function removeupfile($removedfilename) {
405
+
406
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
407
+
408
+           $removefile = $this->view->unlink($tmpfl);
409
+
410
+           // Get the cumulative files size of the uploaded files
411
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
412
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
413
+           $fileSystemIterator = new FilesystemIterator($targetdir);
414
+
415
+           $dirfiles = [];
416
+           foreach ($fileSystemIterator as $fileInfo){
417
+                    $dirfiles[] = $fileInfo->getFilename();
418
+           }
419
+
420
+           $totalflsizeinit = 0;
421
+
422
+           foreach ($dirfiles as $key => $indfile) {
423
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
424
+                    $mbSize = round($fileSizeinit / 1024, 4);
425
+                    $totalflsizeinit += $mbSize;
426
+           }
427
+
428
+           $totalflsize = round($totalflsizeinit, 4);
429
+
430
+           return $totalflsize;
431
+    }
432
+
433
+
434
+    /**
435
+     * @NoAdminRequired
436
+     */
437
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
438
+
439
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
440
+         $telnyxkey = $telsmsapicred[0];
441
+         $teldelrecurl = $telsmsapicred[3];
442
+         $messagingprofid = $telsmsapicred[4];
443
+         $addDisplName = $telsmsapicred[24];
444
+
445
+         // Get the Display Name of the current user
446
+         $crtuser = $this->userManager->get($this->userId);
447
+         $displayname = $crtuser->getDisplayName();
448
+
449
+         if ($addDisplName == 1) {
450
+             $sentsmstext = $displayname . ": " . $sentsmstext;
451
+         }
452
+
453
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
454
+
455
+         $microinterval = $waitinterval * 1000;
456
+
457
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
458
+
459
+             usleep($microinterval);
460
+
461
+             $messagedate = date("Y-m-d H:i:s");
462
+
463
+             if ($ismms == 0) {
464
+
465
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
466
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
467
+                 } else {
468
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
469
+                 }
470
+
471
+                 $messagetexttel = $sentsmstext;
472
+
473
+             } else {
474
+
475
+                 $mediaURLarr = [];
476
+                 $includedMediaFiles = '';
477
+
478
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
479
+
480
+                      $userroot = $this->view->getRoot();
481
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
482
+
483
+                      $flsharetarget = $this->folder->newFile($filetoshare);
484
+
485
+	              $share = $this->shareManager->newShare();
486
+	              $share->setNode($flsharetarget);
487
+	              $share->setPermissions(Constants::PERMISSION_READ);
488
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
489
+	              $share->setSharedBy($this->userId);
490
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
491
+                      $expirydate->add(new \DateInterval('P1D'));
492
+                      $share->setExpirationDate($expirydate);
493
+                      $shared = $this->shareManager->createShare($share);
494
+                      $shareToken = $shared->getToken();
495
+
496
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
497
+
498
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
499
+
500
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
501
+                 }
502
+
503
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
504
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
505
+                 } else {
506
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
507
+                 }
508
+
509
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
510
+             }
511
+
512
+             $messageid = $message['id'];
513
+             $messagefrom = "Telnyx: " . $fromsender;
514
+             $messageto = $tonumber;
515
+             $messagenetwork = null;
516
+             $messageprice = null;
517
+             $messagestatus = $message['to'][0]['status'];
518
+             $messagedelivery = null;
519
+
520
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
521
+
522
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
523
+         }
524
+         return $displayname;
525
+    }
526
+
527
+
528
+    /**
529
+     * @NoAdminRequired
530
+     */
531
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
532
+
533
+         $plsmsapicred = $this->service->getapicredentials($this->userId);
534
+
535
+         $smsapikey = $plsmsapicred[5];
536
+         $smsapisecret = $plsmsapicred[6];
537
+         $smsapideliveryrecurl = $plsmsapicred[8];
538
+         $addDisplName = $plsmsapicred[24];
539
+
540
+         // Get the Display Name of the current user
541
+         $crtuser = $this->userManager->get($this->userId);
542
+         $displayname = $crtuser->getDisplayName();
543
+
544
+         if ($addDisplName == 1) {
545
+             $sentsmstext = $displayname . ": " . $sentsmstext;
546
+         }
547
+
548
+         $microinterval = $waitinterval * 1000;
549
+
550
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
551
+
552
+             usleep($microinterval);
553
+
554
+             $messagedatepl = date("Y-m-d H:i:s");
555
+
556
+             if ($ismms == 0) {
557
+
558
+                 $client = new RestClient($smsapikey, $smsapisecret);
559
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
560
+                 $messagetextpl = $sentsmstext;
561
+	         $messageidinit = $response->getmessageUuid(0);
562
+                 $messageid = $messageidinit[0];
563
+
564
+                 if (property_exists($response, 'error')) { 
565
+                     $messagestatus = "Error: " . $response->error;
566
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
567
+
568
+             } else {
569
+
570
+                 $mediaURLarr = [];
571
+                 $includedMediaFiles = '';
572
+
573
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
574
+
575
+                      $userroot = $this->view->getRoot();
576
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
577
+
578
+                      $flsharetarget = $this->folder->newFile($filetoshare);
579
+
580
+	              $share = $this->shareManager->newShare();
581
+	              $share->setNode($flsharetarget);
582
+	              $share->setPermissions(Constants::PERMISSION_READ);
583
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
584
+	              $share->setSharedBy($this->userId);
585
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
586
+                      $expirydate->add(new \DateInterval('P1D'));
587
+                      $share->setExpirationDate($expirydate);
588
+                      $shared = $this->shareManager->createShare($share);
589
+                      $shareToken = $shared->getToken();
590
+
591
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
592
+
593
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
594
+
595
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
596
+                 }
597
+
598
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
599
+		 $postedparamspl = json_encode($datatosendpl);
600
+
601
+		 $chpl = curl_init();
602
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
603
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
604
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
605
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
606
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
607
+		 curl_setopt($chpl, CURLOPT_POST, 1);
608
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
609
+		 $resultpl = curl_exec ($chpl);
610
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
611
+		 curl_close ($chpl);
612
+
613
+		 $decresultpl = json_decode($resultpl);
614
+
615
+                 if ($decresultpl) {
616
+                     if (property_exists($decresultpl, 'message_uuid')) {
617
+                         $messageidinit = $decresultpl->message_uuid;
618
+                         $messageid = $messageidinit[0];
619
+                     } else { $messageid = 'n/a'; }
620
+                 } else { $messageid = 'n/a'; }
621
+
622
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
623
+
624
+                     if (property_exists($decresultpl, 'error')) {
625
+                         $messagestatus = "Error: " . $decresultpl->error;
626
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
627
+
628
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
629
+
630
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
631
+             }
632
+
633
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
634
+                 $messagefrom = "Plivo: " . $fromsender;
635
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
636
+
637
+             $messageto = $tonumber;
638
+             $messagenetwork = '';
639
+             $messageprice = '';
640
+
641
+             $messagedelivery = '';
642
+
643
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
644
+
645
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
646
+         }
647
+         return $displayname;
648
+    }
649
+
650
+
651
+    /**
652
+     * @NoAdminRequired
653
+     */
654
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
655
+
656
+         $twsmsapicred = $this->service->getapicredentials($this->userId);
657
+
658
+         $sid = $twsmsapicred[15];
659
+         $token = $twsmsapicred[16];
660
+         $smsapirecurltw = $twsmsapicred[18];
661
+         $addDisplName = $twsmsapicred[24];
662
+
663
+         // Get the Display Name of the current user
664
+         $crtuser = $this->userManager->get($this->userId);
665
+         $displayname = $crtuser->getDisplayName();
666
+
667
+         if ($addDisplName == 1) {
668
+             $sentsmstext = $displayname . ": " . $sentsmstext;
669
+         }
670
+
671
+         $microinterval = $waitinterval * 1000;
672
+
673
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
674
+
675
+             usleep($microinterval);
676
+
677
+             $messagedatetw = date("Y-m-d H:i:s");
678
+
679
+             if ($ismms == 0) {
680
+
681
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
682
+                 $sentsmstextfintw = $sentsmstext;
683
+
684
+             } else {
685
+
686
+                 $mediaURLs = [];
687
+                 $includedMediaFiles = '';
688
+
689
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
690
+
691
+                      $userroot = $this->view->getRoot();
692
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
693
+
694
+                      $flsharetarget = $this->folder->newFile($filetoshare);
695
+
696
+	              $share = $this->shareManager->newShare();
697
+	              $share->setNode($flsharetarget);
698
+	              $share->setPermissions(Constants::PERMISSION_READ);
699
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
700
+	              $share->setSharedBy($this->userId);
701
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
702
+                      $expirydate->add(new \DateInterval('P1D'));
703
+                      $share->setExpirationDate($expirydate);
704
+                      $shared = $this->shareManager->createShare($share);
705
+                      $shareToken = $shared->getToken();
706
+
707
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
708
+
709
+                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
710
+
711
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
712
+                 }
713
+
714
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
715
+
716
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
717
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
718
+                 }
719
+
720
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
721
+             }
722
+
723
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
724
+
725
+	     $chtw = curl_init();
726
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
727
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
728
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
729
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
730
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
731
+	     curl_setopt($chtw, CURLOPT_POST, 1);
732
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
733
+
734
+	     $resulttw = curl_exec ($chtw);
735
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
736
+	     curl_close ($chtw);
737
+
738
+             $decresulttw = json_decode($resulttw);
739
+
740
+             if ($decresulttw) {
741
+                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
742
+             } else { $messageidtw = 'n/a'; }
743
+
744
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
745
+                 $messagestatustw = 'The message has been accepted for delivery.';
746
+             } else {
747
+                 $messagestatustw = 'An error occurred while trying to send the message.';
748
+             }
749
+
750
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
751
+                 $messagefromtw = "Twilio: " . $fromsender;
752
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
753
+
754
+             $messagenetworktw = '';
755
+             $messagepricetw = '';
756
+             $messagedeliverytw = '';
757
+
758
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
759
+
760
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
761
+         }
762
+         return $displayname;
763
+    }
764
+
765
+
766
+    /**
767
+     * @NoAdminRequired
768
+     */
769
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
770
+
771
+         $flsmsapicred = $this->service->getapicredentials($this->userId);
772
+
773
+         $flowapikey = $flsmsapicred[20];
774
+         $flowapisecret = $flsmsapicred[21];
775
+         $flowdelrecurl = $flsmsapicred[23];
776
+         $addDisplName = $flsmsapicred[24];
777
+
778
+         // Get the Display Name of the current user
779
+         $crtuser = $this->userManager->get($this->userId);
780
+         $displayname = $crtuser->getDisplayName();
781
+
782
+         if ($addDisplName == 1) {
783
+             $sentsmstext = $displayname . ": " . $sentsmstext;
784
+         }
785
+
786
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
787
+
788
+         $microinterval = $waitinterval * 1000;
789
+
790
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
791
+
792
+             usleep($microinterval);
793
+
794
+             $messagedatefl = date("Y-m-d H:i:s");
795
+
796
+             if ($ismms == 0) {
797
+
798
+                 $messagetextfinfl = $sentsmstext;
799
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
800
+
801
+             } else {
802
+
803
+		 $mediaurlsarr = [];
804
+		 $includedMediaFiles = '';
805
+
806
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
807
+
808
+		      $userroot = $this->view->getRoot();
809
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
810
+
811
+		      $flsharetarget = $this->folder->newFile($filetoshare);
812
+
813
+		      $share = $this->shareManager->newShare();
814
+		      $share->setNode($flsharetarget);
815
+		      $share->setPermissions(Constants::PERMISSION_READ);
816
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
817
+		      $share->setSharedBy($this->userId);
818
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
819
+                      $expirydate->add(new \DateInterval('P1D'));
820
+                      $share->setExpirationDate($expirydate);
821
+		      $shared = $this->shareManager->createShare($share);
822
+		      $shareToken = $shared->getToken();
823
+
824
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
825
+
826
+		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
827
+
828
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
829
+		 }
830
+
831
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
832
+
833
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
834
+             }
835
+
836
+	     $chfl = curl_init();
837
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
838
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
839
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
840
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
841
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
842
+	     curl_setopt($chfl, CURLOPT_POST, 1);
843
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
844
+	     $resultfl = curl_exec ($chfl);
845
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
846
+	     curl_close ($chfl);
847
+
848
+             $decresultfl = json_decode($resultfl);
849
+
850
+             if ($decresultfl) {
851
+                 if (property_exists($decresultfl, 'data')) { 
852
+                     $messageidfl = $decresultfl->data->id;
853
+                 } else { $messageidfl = 'n/a'; }
854
+             } else { $messageidfl = 'n/a'; }
855
+
856
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
857
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
858
+             } else { 
859
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
860
+             }
861
+
862
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
863
+                 $messagefromfl = "Flowroute: " . $fromsender;
864
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
865
+
866
+             $messagetofl = $tonumberfl;
867
+             $messagenetworkfl = '';
868
+             $messagepricefl = '';
869
+             $messagedeliveryfl = '';
870
+
871
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
872
+
873
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
874
+         }
875
+         return $displayname;
876
+    }
877
+
878
+
879
+    /**
880
+     * @NoAdminRequired
881
+     */
882
+    public function saveoldrecrows($userId, $oldrecRows) {
883
+
884
+           // Create the folder for removed messages if it doesn't exist
885
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
886
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
887
+           }
888
+           $savecheck = 0;
889
+
890
+           if (count($oldrecRows) > 1) {
891
+               $msfileContent = implode("", $oldrecRows);
892
+
893
+               $delrowsdate = date("Y-m-d_H-i-s");
894
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
895
+
896
+               $userroot = $this->view->getRoot();
897
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
898
+
899
+               $target = $this->folder->newFile($targetfile);
900
+               $target->putContent($msfileContent);
901
+
902
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
903
+                   $savecheck = 1;
904
+               }
905
+           }
906
+
907
+           return $savecheck;
908
+    }
909
+
910
+
911
+    /**
912
+     * @NoAdminRequired
913
+     */
914
+    public function saveoldsentrows($userId, $oldsentRows) {
915
+
916
+           // Create the folder for removed messages if it doesn't exist
917
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
918
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
919
+           }
920
+           $savesentcheck = 0;
921
+
922
+           if (count($oldsentRows) > 1) {
923
+               $sntfileContent = implode("", $oldsentRows);
924
+
925
+               $delsentrowsdate = date("Y-m-d_H-i-s");
926
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
927
+
928
+               $userroot = $this->view->getRoot();
929
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
930
+
931
+               $snttarget = $this->folder->newFile($snttargetfile);
932
+               $snttarget->putContent($sntfileContent);
933
+
934
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
935
+                   $savesentcheck = 1;
936
+               }
937
+           }
938
+
939
+           return $savesentcheck;
940
+    }
941
+
942
+
943
+    /**
944
+     * @NoAdminRequired
945
+     */
946
+    public function getreceivedtable($userId) {
947
+           return $this->service->getreceivedtable($this->userId);
948
+    }
949
+
950
+    /**
951
+     * @NoAdminRequired
952
+     */
953
+    public function getreceivedtablefordel($userId) {
954
+           return $this->service->getreceivedtablefordel($this->userId);
955
+    }
956
+
957
+    /**
958
+     * @NoAdminRequired
959
+     */
960
+    public function removerecrows($userId, $recmessagedbIDs) {
961
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
962
+    }
963
+
964
+    /**
965
+     * @NoAdminRequired
966
+     */
967
+    public function getsenttable($userId) {
968
+           return $this->service->getsenttable($this->userId);
969
+    }
970
+
971
+    /**
972
+     * @NoAdminRequired
973
+     */
974
+    public function getsenttablefordel($userId) {
975
+           return $this->service->getsenttablefordel($this->userId);
976
+    }
977
+
978
+    /**
979
+     * @NoAdminRequired
980
+     */
981
+    public function removesentrows($userId, $sentmessagedbIDs) {
982
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
983
+    }
984
+
985
+    /**
986
+     * @NoAdminRequired
987
+     */
988
+    public function getgroupedtable($userId) {
989
+           return $this->service->getgroupedtable($this->userId);
990
+    }
991
+
992
+    /**
993
+     * @NoAdminRequired
994
+     */
995
+    public function savedisplayname($userId, $authorDisplayname, $from) {
996
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
997
+    }
998
+
999
+    /**
1000
+     * @NoAdminRequired
1001
+     */
1002
+    public function getmessagesperpage($userId) {
1003
+           return $this->service->getmessagesperpage($this->userId);
1004
+    }
1005
+
1006
+    /**
1007
+     * @NoAdminRequired
1008
+     */
1009
+    public function getdelrecsettings($userId) {
1010
+           return $this->service->getdelrecsettings($this->userId);
1011
+    }
1012
+
1013
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1014
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1015
+    }
1016
+
1017
+    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1018
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1019
+    }
1020
+
1021
+    public function removenumberrestrictions($userId, $phoneNumber) {
1022
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1023
+    }
1024
+
1025
+    /**
1026
+     * @NoAdminRequired
1027
+     */
1028
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1029
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1030
+    }
1031
+
1032
+    /**
1033
+     * @NoAdminRequired
1034
+     */
1035
+    public function removeautoreplies($userId, $phoneNumber) {
1036
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1037
+    }
1038
+
1039
+    /**
1040
+     * @NoAdminRequired
1041
+     */
1042
+    public function getsettings($userId) {
1043
+           return $this->service->getsettings($this->userId);
1044
+    }
1045
+
1046
+    public function getadminsettings($userId) {
1047
+           return $this->service->getadminsettings($this->userId);
1048
+    }
1049
+
1050
+    /**
1051
+     * @NoAdminRequired
1052
+     */
1053
+    public function getautoreplyconf($userId) {
1054
+
1055
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1056
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1057
+
1058
+           // Get the display name of the current user
1059
+           $usrid = $this->userId;
1060
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1061
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1062
+	   $getusrdnmdata = $getusrdnmres->fetch();
1063
+	   $userDisplayNm = $getusrdnmdata['value'];
1064
+	   $getusrdnmres->closeCursor();
1065
+
1066
+           // Get the auto-replies for the available phone numbers
1067
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1068
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1069
+	   $getautorplres = $getautorpl->execute();
1070
+           $autorplconf = [];
1071
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1072
+                  $autorplconf[] = $acdatausrdnadm;
1073
+           }
1074
+	   $getautorplres->closeCursor();
1075
+
1076
+           if ($autorplconf) {
1077
+
1078
+               $autoreplyconf = [];
1079
+               foreach ($autorplconf as $arkey => $arvalue) {
1080
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1081
+                            $autoreplyconf[] = $arvalue;
1082
+                        }
1083
+               }
1084
+
1085
+           } else { $autoreplyconf = ''; }
1086
+
1087
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1088
+
1089
+           return $autoreplyfdb;
1090
+    }
1091
+
1092
+    /**
1093
+     * @NoAdminRequired
1094
+     */
1095
+    public function getgroupedpernumber($userId, $phoneNumber) {
1096
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1097
+    }
1098
+
1099
+    /**
1100
+     * @NoAdminRequired
1101
+     */
1102
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1103
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1104
+    }
1105
+
1106
+    /**
1107
+     * @NoAdminRequired
1108
+     */
1109
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1110
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1111
+    }
1112
+
1113
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1114
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1115
+    }
1116
+
1117
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1118
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1119
+    }
1120
+}
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json appinfo/routes.php css/style.css js/adminsettings.js js/deleteoldsms.js js/sendsms.js js/settings.js js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php providers/Telnyx/lib/ApiResource.php

DoubleBastionAdmin authored on 15/07/2023 21:56:42
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1094 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\IURLGenerator;
49
-use OCP\Share\IManager;
50
-use OCP\Constants;
51
-use OCP\IGroupManager;
52
-use OCP\IDBConnection;
53
-use OCP\IUserManager;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $urlGenerator;
64
-    private $shareManager;
65
-    private $groupManager;
66
-    private $connection;
67
-    private $userManager;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->urlGenerator = $urlGenerator;
78
-	$this->shareManager = $shareManager;
79
-        $this->groupManager = $groupManager;
80
-        $this->connection = $connection;
81
-        $this->userManager = $userManager;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getbalancetel($userId) {
120
-
121
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
-
123
-        $telapikey = $telsmsapicred[0];
124
-        $ch = curl_init();
125
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
-
127
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
-        $responsetel = curl_exec($ch);
131
-        $recdatatel = json_decode($responsetel, TRUE);
132
-        $telbalresponse = $recdatatel['data']['balance'];
133
-        $currentbalancetel = round(floatval($telbalresponse), 3);
134
-        curl_close($ch);
135
-
136
-        return $currentbalancetel;
137
-    }
138
-
139
-
140
-    /**
141
-     * @NoAdminRequired
142
-     */
143
-    public function getbalancenex($userId) {
144
-
145
-        $smsapicred = $this->service->getapicredentials($this->userId);
146
-        $smsapikey = $smsapicred[5];
147
-        $smsapisecret = $smsapicred[6];
148
-
149
-        if ($smsapikey == '' || $smsapisecret == '') {
150
-            $currentbalancenex = "N/A";
151
-        } else {
152
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
-            $mesdata = file_get_contents($getmesdata);
154
-            $datainit = json_decode($mesdata);
155
-            $balancenex = $datainit->cash_credits;
156
-            $currentbalancenex = round(floatval($balancenex), 3);
157
-        }
158
-        return $currentbalancenex;
159
-    }
160
-
161
-
162
-    /**
163
-     * @NoAdminRequired
164
-     */
165
-    public function getbalancetwil($userId) {
166
-
167
-        $smsapicred = $this->service->getapicredentials($this->userId);
168
-        $smsapisid = $smsapicred[15];
169
-        $smsapitoken = $smsapicred[16];
170
-
171
-        if ($smsapisid == '' || $smsapitoken == '') {
172
-            $currentbalancetwil = "N/A";
173
-        } else {
174
-
175
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
-            $balancetwil = $twilbalance->balance;
177
-
178
-            $currentbalancetwil = round(floatval($balancetwil), 3);
179
-        }
180
-        return $currentbalancetwil;
181
-    }
182
-
183
-
184
-    /**
185
-     * @NoAdminRequired
186
-     */
187
-    public function getbalanceflow($userId) {
188
-
189
-        $currentbalanceflow = 'n/a';
190
-
191
-        return $currentbalanceflow;
192
-    }
193
-
194
-
195
-    /**
196
-     * @NoAdminRequired
197
-     */
198
-    public function getsmsnumbers($userId) {
199
-
200
-        return $this->service->getsmsnumbers($this->userId);
201
-    }
202
-
203
-
204
-    /**
205
-     * @NoAdminRequired
206
-     */
207
-    public function cleantempdir($userId) {
208
-
209
-        // Create the temporary folder if it doesn't exist
210
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
211
-            $this->folder->newFolder('SMS_Relentless/temp_files');
212
-        }
213
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
214
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
215
-        $fileSystemIterator = new FilesystemIterator($targetdir);
216
-
217
-        $dirfiles = [];
218
-        foreach ($fileSystemIterator as $fileInfo){
219
-                 $dirfiles[] = $fileInfo->getFilename();
220
-        }
221
-
222
-        foreach ($dirfiles as $key => $indfile) {
223
-                 $thisuserroot = $this->view->getRoot();
224
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
225
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
226
-        }
227
-     }
228
-
229
-
230
-    /**
231
-     * @NoAdminRequired
232
-     */
233
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
234
-
235
-        // Create the temporary folder if it doesn't exist
236
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
237
-            $this->folder->newFolder('SMS_Relentless/temp_files');
238
-        }
239
-
240
-        // First delete any file that has been previously uploaded
241
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
242
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
243
-        $fileSystemIterator = new FilesystemIterator($targetdir);
244
-
245
-        $dirfiles = [];
246
-        foreach ($fileSystemIterator as $fileInfo){
247
-                 $dirfiles[] = $fileInfo->getFilename();
248
-        }
249
-
250
-        foreach ($dirfiles as $key => $indfile) {
251
-                 $thisuserroot = $this->view->getRoot();
252
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
253
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
254
-        }
255
-
256
-        // Upload the new file
257
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
258
-        $fileName = $_FILES['uploadfileforsms']['name'];
259
-
260
-        $userroot = $this->view->getRoot();
261
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
262
-
263
-        $target = $this->folder->newFile($targetfile);
264
-        $target->putContent($fileContent);
265
-
266
-        // Extract the phone numbers from the file
267
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
268
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
269
-        $numberarrayfourth = explode(",", $numberarraytert);
270
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
271
-        $numberarray = array_unique($numberarrayfifth);
272
-
273
-        return $numberarray;
274
-    }
275
-
276
-
277
-    /**
278
-     * @NoAdminRequired
279
-     */
280
-    public function uploadfile($uploadfileformms) {
281
-
282
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
283
-           $fileName = $_FILES['uploadfileformms']['name'];
284
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
285
-           $fileSize = $fileSizeinit / 1024;
286
-
287
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
288
-               $this->folder->newFolder('SMS_Relentless/temp_files');
289
-           }
290
-
291
-           $userroot = $this->view->getRoot();
292
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
293
-
294
-           $target = $this->folder->newFile($targetfile);
295
-           $target->putContent($fileContent);
296
-
297
-           // Get the cumulative files size of the uploaded files
298
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
299
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
300
-
301
-           $fileSystemIterator = new FilesystemIterator($targetdir);
302
-
303
-           $dirfiles = [];
304
-           foreach ($fileSystemIterator as $fileInfo){
305
-                    $dirfiles[] = $fileInfo->getFilename();
306
-           }
307
-
308
-           $totalflsizeinit = 0;
309
-           foreach ($dirfiles as $key => $indfile) {
310
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
311
-                    $mbSize = round($fileSizeinit / 1024, 4);
312
-                    $totalflsizeinit += $mbSize;
313
-           }
314
-
315
-           $totalflsize = round($totalflsizeinit, 4);
316
-
317
-           return $totalflsize;
318
-    }
319
-
320
-
321
-    /**
322
-     * @NoAdminRequired
323
-     */
324
-    public function pickfile($path) {
325
-
326
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
327
-               $this->folder->newFolder('SMS_Relentless/temp_files');
328
-           }
329
-
330
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
331
-
332
-           $fltgt = $datadir . $this->userId . "/files" . $path;
333
-
334
-           $fileContent = file_get_contents($fltgt);
335
-
336
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
337
-
338
-           $patharr = explode("/", $path);
339
-
340
-           $revarr = array_reverse($patharr);
341
-
342
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
343
-
344
-           $target = $this->folder->newFile($relflpath);
345
-
346
-           $target->putContent($fileContent);
347
-
348
-           // Get the cumulative files size of the uploaded files
349
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
350
-
351
-           $fileSystemIterator = new FilesystemIterator($targetdir);
352
-
353
-           $dirfiles = [];
354
-           foreach ($fileSystemIterator as $fileInfo) {
355
-                    $dirfiles[] = $fileInfo->getFilename();
356
-           }
357
-
358
-           $totalflsizeinit = 0;
359
-
360
-           foreach ($dirfiles as $key => $indfile) {
361
-
362
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
363
-                    $mbSize = round($fileSizeinit / 1024, 4);
364
-                    $totalflsizeinit += $mbSize;
365
-           }
366
-
367
-           $totalflsize = round($totalflsizeinit, 4);
368
-
369
-           $pickresult = [$totalflsize, $pkfilesize];
370
-
371
-           return $pickresult;
372
-    }
373
-
374
-
375
-    /**
376
-     * @NoAdminRequired
377
-     */
378
-    public function removeupfile($removedfilename) {
379
-
380
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
381
-
382
-           $removefile = $this->view->unlink($tmpfl);
383
-
384
-           // Get the cumulative files size of the uploaded files
385
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
386
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
387
-           $fileSystemIterator = new FilesystemIterator($targetdir);
388
-
389
-           $dirfiles = [];
390
-           foreach ($fileSystemIterator as $fileInfo){
391
-                    $dirfiles[] = $fileInfo->getFilename();
392
-           }
393
-
394
-           $totalflsizeinit = 0;
395
-
396
-           foreach ($dirfiles as $key => $indfile) {
397
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
398
-                    $mbSize = round($fileSizeinit / 1024, 4);
399
-                    $totalflsizeinit += $mbSize;
400
-           }
401
-
402
-           $totalflsize = round($totalflsizeinit, 4);
403
-
404
-           return $totalflsize;
405
-    }
406
-
407
-
408
-    /**
409
-     * @NoAdminRequired
410
-     */
411
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
412
-
413
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
414
-         $telnyxkey = $telsmsapicred[0];
415
-         $teldelrecurl = $telsmsapicred[3];
416
-         $messagingprofid = $telsmsapicred[4];
417
-         $addDisplName = $telsmsapicred[24];
418
-
419
-         // Get the Display Name of the current user
420
-         $crtuser = $this->userManager->get($this->userId);
421
-         $displayname = $crtuser->getDisplayName();
422
-
423
-         if ($addDisplName == 1) {
424
-             $sentsmstext = $displayname . ": " . $sentsmstext;
425
-         }
426
-
427
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
428
-
429
-         $microinterval = $waitinterval * 1000;
430
-
431
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
432
-
433
-             usleep($microinterval);
434
-
435
-             $messagedate = date("Y-m-d H:i:s");
436
-
437
-             if ($ismms == 0) {
438
-
439
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
440
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
441
-                 } else {
442
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
443
-                 }
444
-
445
-                 $messagetexttel = $sentsmstext;
446
-
447
-             } else {
448
-
449
-                 $mediaURLarr = [];
450
-                 $includedMediaFiles = '';
451
-
452
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
453
-
454
-                      $userroot = $this->view->getRoot();
455
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
456
-
457
-                      $flsharetarget = $this->folder->newFile($filetoshare);
458
-
459
-	              $share = $this->shareManager->newShare();
460
-	              $share->setNode($flsharetarget);
461
-	              $share->setPermissions(Constants::PERMISSION_READ);
462
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
463
-	              $share->setSharedBy($this->userId);
464
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
465
-                      $expirydate->add(new \DateInterval('P1D'));
466
-                      $share->setExpirationDate($expirydate);
467
-                      $shared = $this->shareManager->createShare($share);
468
-                      $shareToken = $shared->getToken();
469
-
470
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
471
-
472
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
473
-
474
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
475
-                 }
476
-
477
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
478
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
479
-                 } else {
480
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
481
-                 }
482
-
483
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
484
-             }
485
-
486
-             $messageid = $message['id'];
487
-             $messagefrom = "Telnyx: " . $fromsender;
488
-             $messageto = $tonumber;
489
-             $messagenetwork = null;
490
-             $messageprice = null;
491
-             $messagestatus = $message['to'][0]['status'];
492
-             $messagedelivery = null;
493
-
494
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
495
-
496
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
497
-         }
498
-         return $displayname;
499
-    }
500
-
501
-
502
-    /**
503
-     * @NoAdminRequired
504
-     */
505
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
506
-
507
-         $plsmsapicred = $this->service->getapicredentials($this->userId);
508
-
509
-         $smsapikey = $plsmsapicred[5];
510
-         $smsapisecret = $plsmsapicred[6];
511
-         $smsapideliveryrecurl = $plsmsapicred[8];
512
-         $addDisplName = $plsmsapicred[24];
513
-
514
-         // Get the Display Name of the current user
515
-         $crtuser = $this->userManager->get($this->userId);
516
-         $displayname = $crtuser->getDisplayName();
517
-
518
-         if ($addDisplName == 1) {
519
-             $sentsmstext = $displayname . ": " . $sentsmstext;
520
-         }
521
-
522
-         $microinterval = $waitinterval * 1000;
523
-
524
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
525
-
526
-             usleep($microinterval);
527
-
528
-             $messagedatepl = date("Y-m-d H:i:s");
529
-
530
-             if ($ismms == 0) {
531
-
532
-                 $client = new RestClient($smsapikey, $smsapisecret);
533
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
534
-                 $messagetextpl = $sentsmstext;
535
-	         $messageidinit = $response->getmessageUuid(0);
536
-                 $messageid = $messageidinit[0];
537
-
538
-                 if (property_exists($response, 'error')) { 
539
-                     $messagestatus = "Error: " . $response->error;
540
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
541
-
542
-             } else {
543
-
544
-                 $mediaURLarr = [];
545
-                 $includedMediaFiles = '';
546
-
547
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
548
-
549
-                      $userroot = $this->view->getRoot();
550
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
551
-
552
-                      $flsharetarget = $this->folder->newFile($filetoshare);
553
-
554
-	              $share = $this->shareManager->newShare();
555
-	              $share->setNode($flsharetarget);
556
-	              $share->setPermissions(Constants::PERMISSION_READ);
557
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
558
-	              $share->setSharedBy($this->userId);
559
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
560
-                      $expirydate->add(new \DateInterval('P1D'));
561
-                      $share->setExpirationDate($expirydate);
562
-                      $shared = $this->shareManager->createShare($share);
563
-                      $shareToken = $shared->getToken();
564
-
565
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
566
-
567
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
568
-
569
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
570
-                 }
571
-
572
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
573
-		 $postedparamspl = json_encode($datatosendpl);
574
-
575
-		 $chpl = curl_init();
576
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
577
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
578
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
579
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
580
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
581
-		 curl_setopt($chpl, CURLOPT_POST, 1);
582
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
583
-		 $resultpl = curl_exec ($chpl);
584
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
585
-		 curl_close ($chpl);
586
-
587
-		 $decresultpl = json_decode($resultpl);
588
-
589
-                 if ($decresultpl) {
590
-                     if (property_exists($decresultpl, 'message_uuid')) {
591
-                         $messageidinit = $decresultpl->message_uuid;
592
-                         $messageid = $messageidinit[0];
593
-                     } else { $messageid = 'n/a'; }
594
-                 } else { $messageid = 'n/a'; }
595
-
596
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
597
-
598
-                     if (property_exists($decresultpl, 'error')) {
599
-                         $messagestatus = "Error: " . $decresultpl->error;
600
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
601
-
602
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
603
-
604
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
605
-             }
606
-
607
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
608
-                 $messagefrom = "Plivo: " . $fromsender;
609
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
610
-
611
-             $messageto = $tonumber;
612
-             $messagenetwork = '';
613
-             $messageprice = '';
614
-
615
-             $messagedelivery = '';
616
-
617
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
618
-
619
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
620
-         }
621
-         return $displayname;
622
-    }
623
-
624
-
625
-    /**
626
-     * @NoAdminRequired
627
-     */
628
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
629
-
630
-         $twsmsapicred = $this->service->getapicredentials($this->userId);
631
-
632
-         $sid = $twsmsapicred[15];
633
-         $token = $twsmsapicred[16];
634
-         $smsapirecurltw = $twsmsapicred[18];
635
-         $addDisplName = $twsmsapicred[24];
636
-
637
-         // Get the Display Name of the current user
638
-         $crtuser = $this->userManager->get($this->userId);
639
-         $displayname = $crtuser->getDisplayName();
640
-
641
-         if ($addDisplName == 1) {
642
-             $sentsmstext = $displayname . ": " . $sentsmstext;
643
-         }
644
-
645
-         $microinterval = $waitinterval * 1000;
646
-
647
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
648
-
649
-             usleep($microinterval);
650
-
651
-             $messagedatetw = date("Y-m-d H:i:s");
652
-
653
-             if ($ismms == 0) {
654
-
655
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
656
-                 $sentsmstextfintw = $sentsmstext;
657
-
658
-             } else {
659
-
660
-                 $mediaURLs = [];
661
-                 $includedMediaFiles = '';
662
-
663
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
664
-
665
-                      $userroot = $this->view->getRoot();
666
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
667
-
668
-                      $flsharetarget = $this->folder->newFile($filetoshare);
669
-
670
-	              $share = $this->shareManager->newShare();
671
-	              $share->setNode($flsharetarget);
672
-	              $share->setPermissions(Constants::PERMISSION_READ);
673
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
674
-	              $share->setSharedBy($this->userId);
675
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
676
-                      $expirydate->add(new \DateInterval('P1D'));
677
-                      $share->setExpirationDate($expirydate);
678
-                      $shared = $this->shareManager->createShare($share);
679
-                      $shareToken = $shared->getToken();
680
-
681
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
682
-
683
-                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
684
-
685
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
686
-                 }
687
-
688
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
689
-
690
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
691
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
692
-                 }
693
-
694
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
695
-             }
696
-
697
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
698
-
699
-	     $chtw = curl_init();
700
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
701
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
702
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
703
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
704
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
705
-	     curl_setopt($chtw, CURLOPT_POST, 1);
706
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
707
-
708
-	     $resulttw = curl_exec ($chtw);
709
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
710
-	     curl_close ($chtw);
711
-
712
-             $decresulttw = json_decode($resulttw);
713
-
714
-             if ($decresulttw) {
715
-                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
716
-             } else { $messageidtw = 'n/a'; }
717
-
718
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
719
-                 $messagestatustw = 'The message has been accepted for delivery.';
720
-             } else {
721
-                 $messagestatustw = 'An error occurred while trying to send the message.';
722
-             }
723
-
724
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
725
-                 $messagefromtw = "Twilio: " . $fromsender;
726
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
727
-
728
-             $messagenetworktw = '';
729
-             $messagepricetw = '';
730
-             $messagedeliverytw = '';
731
-
732
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
733
-
734
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
735
-         }
736
-         return $displayname;
737
-    }
738
-
739
-
740
-    /**
741
-     * @NoAdminRequired
742
-     */
743
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
744
-
745
-         $flsmsapicred = $this->service->getapicredentials($this->userId);
746
-
747
-         $flowapikey = $flsmsapicred[20];
748
-         $flowapisecret = $flsmsapicred[21];
749
-         $flowdelrecurl = $flsmsapicred[23];
750
-         $addDisplName = $flsmsapicred[24];
751
-
752
-         // Get the Display Name of the current user
753
-         $crtuser = $this->userManager->get($this->userId);
754
-         $displayname = $crtuser->getDisplayName();
755
-
756
-         if ($addDisplName == 1) {
757
-             $sentsmstext = $displayname . ": " . $sentsmstext;
758
-         }
759
-
760
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
761
-
762
-         $microinterval = $waitinterval * 1000;
763
-
764
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
765
-
766
-             usleep($microinterval);
767
-
768
-             $messagedatefl = date("Y-m-d H:i:s");
769
-
770
-             if ($ismms == 0) {
771
-
772
-                 $messagetextfinfl = $sentsmstext;
773
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
774
-
775
-             } else {
776
-
777
-		 $mediaurlsarr = [];
778
-		 $includedMediaFiles = '';
779
-
780
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
781
-
782
-		      $userroot = $this->view->getRoot();
783
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
784
-
785
-		      $flsharetarget = $this->folder->newFile($filetoshare);
786
-
787
-		      $share = $this->shareManager->newShare();
788
-		      $share->setNode($flsharetarget);
789
-		      $share->setPermissions(Constants::PERMISSION_READ);
790
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
791
-		      $share->setSharedBy($this->userId);
792
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
793
-                      $expirydate->add(new \DateInterval('P1D'));
794
-                      $share->setExpirationDate($expirydate);
795
-		      $shared = $this->shareManager->createShare($share);
796
-		      $shareToken = $shared->getToken();
797
-
798
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
799
-
800
-		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
801
-
802
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
803
-		 }
804
-
805
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
806
-
807
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
808
-             }
809
-
810
-	     $chfl = curl_init();
811
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
812
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
813
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
814
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
815
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
816
-	     curl_setopt($chfl, CURLOPT_POST, 1);
817
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
818
-	     $resultfl = curl_exec ($chfl);
819
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
820
-	     curl_close ($chfl);
821
-
822
-             $decresultfl = json_decode($resultfl);
823
-
824
-             if ($decresultfl) {
825
-                 if (property_exists($decresultfl, 'data')) { 
826
-                     $messageidfl = $decresultfl->data->id;
827
-                 } else { $messageidfl = 'n/a'; }
828
-             } else { $messageidfl = 'n/a'; }
829
-
830
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
831
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
832
-             } else { 
833
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
834
-             }
835
-
836
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
837
-                 $messagefromfl = "Flowroute: " . $fromsender;
838
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
839
-
840
-             $messagetofl = $tonumberfl;
841
-             $messagenetworkfl = '';
842
-             $messagepricefl = '';
843
-             $messagedeliveryfl = '';
844
-
845
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
846
-
847
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
848
-         }
849
-         return $displayname;
850
-    }
851
-
852
-
853
-    /**
854
-     * @NoAdminRequired
855
-     */
856
-    public function saveoldrecrows($userId, $oldrecRows) {
857
-
858
-           // Create the folder for removed messages if it doesn't exist
859
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
860
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
861
-           }
862
-           $savecheck = 0;
863
-
864
-           if (count($oldrecRows) > 1) {
865
-               $msfileContent = implode("", $oldrecRows);
866
-
867
-               $delrowsdate = date("Y-m-d_H-i-s");
868
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
869
-
870
-               $userroot = $this->view->getRoot();
871
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
872
-
873
-               $target = $this->folder->newFile($targetfile);
874
-               $target->putContent($msfileContent);
875
-
876
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
877
-                   $savecheck = 1;
878
-               }
879
-           }
880
-
881
-           return $savecheck;
882
-    }
883
-
884
-
885
-    /**
886
-     * @NoAdminRequired
887
-     */
888
-    public function saveoldsentrows($userId, $oldsentRows) {
889
-
890
-           // Create the folder for removed messages if it doesn't exist
891
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
892
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
893
-           }
894
-           $savesentcheck = 0;
895
-
896
-           if (count($oldsentRows) > 1) {
897
-               $sntfileContent = implode("", $oldsentRows);
898
-
899
-               $delsentrowsdate = date("Y-m-d_H-i-s");
900
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
901
-
902
-               $userroot = $this->view->getRoot();
903
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
904
-
905
-               $snttarget = $this->folder->newFile($snttargetfile);
906
-               $snttarget->putContent($sntfileContent);
907
-
908
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
909
-                   $savesentcheck = 1;
910
-               }
911
-           }
912
-
913
-           return $savesentcheck;
914
-    }
915
-
916
-
917
-    /**
918
-     * @NoAdminRequired
919
-     */
920
-    public function getreceivedtable($userId) {
921
-           return $this->service->getreceivedtable($this->userId);
922
-    }
923
-
924
-    /**
925
-     * @NoAdminRequired
926
-     */
927
-    public function getreceivedtablefordel($userId) {
928
-           return $this->service->getreceivedtablefordel($this->userId);
929
-    }
930
-
931
-    /**
932
-     * @NoAdminRequired
933
-     */
934
-    public function removerecrows($userId, $recmessagedbIDs) {
935
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
936
-    }
937
-
938
-    /**
939
-     * @NoAdminRequired
940
-     */
941
-    public function getsenttable($userId) {
942
-           return $this->service->getsenttable($this->userId);
943
-    }
944
-
945
-    /**
946
-     * @NoAdminRequired
947
-     */
948
-    public function getsenttablefordel($userId) {
949
-           return $this->service->getsenttablefordel($this->userId);
950
-    }
951
-
952
-    /**
953
-     * @NoAdminRequired
954
-     */
955
-    public function removesentrows($userId, $sentmessagedbIDs) {
956
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
957
-    }
958
-
959
-    /**
960
-     * @NoAdminRequired
961
-     */
962
-    public function getgroupedtable($userId) {
963
-           return $this->service->getgroupedtable($this->userId);
964
-    }
965
-
966
-    /**
967
-     * @NoAdminRequired
968
-     */
969
-    public function savedisplayname($userId, $authorDisplayname, $from) {
970
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
971
-    }
972
-
973
-    /**
974
-     * @NoAdminRequired
975
-     */
976
-    public function getmessagesperpage($userId) {
977
-           return $this->service->getmessagesperpage($this->userId);
978
-    }
979
-
980
-    /**
981
-     * @NoAdminRequired
982
-     */
983
-    public function getdelrecsettings($userId) {
984
-           return $this->service->getdelrecsettings($this->userId);
985
-    }
986
-
987
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
988
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
989
-    }
990
-
991
-    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
992
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
993
-    }
994
-
995
-    public function removenumberrestrictions($userId, $phoneNumber) {
996
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
997
-    }
998
-
999
-    /**
1000
-     * @NoAdminRequired
1001
-     */
1002
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1003
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1004
-    }
1005
-
1006
-    /**
1007
-     * @NoAdminRequired
1008
-     */
1009
-    public function removeautoreplies($userId, $phoneNumber) {
1010
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1011
-    }
1012
-
1013
-    /**
1014
-     * @NoAdminRequired
1015
-     */
1016
-    public function getsettings($userId) {
1017
-           return $this->service->getsettings($this->userId);
1018
-    }
1019
-
1020
-    public function getadminsettings($userId) {
1021
-           return $this->service->getadminsettings($this->userId);
1022
-    }
1023
-
1024
-    /**
1025
-     * @NoAdminRequired
1026
-     */
1027
-    public function getautoreplyconf($userId) {
1028
-
1029
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1030
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1031
-
1032
-           // Get the display name of the current user
1033
-           $usrid = $this->userId;
1034
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1035
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1036
-	   $getusrdnmdata = $getusrdnmres->fetch();
1037
-	   $userDisplayNm = $getusrdnmdata['value'];
1038
-	   $getusrdnmres->closeCursor();
1039
-
1040
-           // Get the auto-replies for the available phone numbers
1041
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1042
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1043
-	   $getautorplres = $getautorpl->execute();
1044
-           $autorplconf = [];
1045
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1046
-                  $autorplconf[] = $acdatausrdnadm;
1047
-           }
1048
-	   $getautorplres->closeCursor();
1049
-
1050
-           if ($autorplconf) {
1051
-
1052
-               $autoreplyconf = [];
1053
-               foreach ($autorplconf as $arkey => $arvalue) {
1054
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1055
-                            $autoreplyconf[] = $arvalue;
1056
-                        }
1057
-               }
1058
-
1059
-           } else { $autoreplyconf = ''; }
1060
-
1061
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1062
-
1063
-           return $autoreplyfdb;
1064
-    }
1065
-
1066
-    /**
1067
-     * @NoAdminRequired
1068
-     */
1069
-    public function getgroupedpernumber($userId, $phoneNumber) {
1070
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1071
-    }
1072
-
1073
-    /**
1074
-     * @NoAdminRequired
1075
-     */
1076
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1077
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1078
-    }
1079
-
1080
-    /**
1081
-     * @NoAdminRequired
1082
-     */
1083
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1084
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1085
-    }
1086
-
1087
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1088
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1089
-    }
1090
-
1091
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1092
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1093
-    }
1094
-}
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php

DoubleBastionAdmin authored on 21/06/2023 21:20:39
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1094 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\IURLGenerator;
49
+use OCP\Share\IManager;
50
+use OCP\Constants;
51
+use OCP\IGroupManager;
52
+use OCP\IDBConnection;
53
+use OCP\IUserManager;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $urlGenerator;
64
+    private $shareManager;
65
+    private $groupManager;
66
+    private $connection;
67
+    private $userManager;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->urlGenerator = $urlGenerator;
78
+	$this->shareManager = $shareManager;
79
+        $this->groupManager = $groupManager;
80
+        $this->connection = $connection;
81
+        $this->userManager = $userManager;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getbalancetel($userId) {
120
+
121
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
+
123
+        $telapikey = $telsmsapicred[0];
124
+        $ch = curl_init();
125
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
+
127
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
+        $responsetel = curl_exec($ch);
131
+        $recdatatel = json_decode($responsetel, TRUE);
132
+        $telbalresponse = $recdatatel['data']['balance'];
133
+        $currentbalancetel = round(floatval($telbalresponse), 3);
134
+        curl_close($ch);
135
+
136
+        return $currentbalancetel;
137
+    }
138
+
139
+
140
+    /**
141
+     * @NoAdminRequired
142
+     */
143
+    public function getbalancenex($userId) {
144
+
145
+        $smsapicred = $this->service->getapicredentials($this->userId);
146
+        $smsapikey = $smsapicred[5];
147
+        $smsapisecret = $smsapicred[6];
148
+
149
+        if ($smsapikey == '' || $smsapisecret == '') {
150
+            $currentbalancenex = "N/A";
151
+        } else {
152
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
+            $mesdata = file_get_contents($getmesdata);
154
+            $datainit = json_decode($mesdata);
155
+            $balancenex = $datainit->cash_credits;
156
+            $currentbalancenex = round(floatval($balancenex), 3);
157
+        }
158
+        return $currentbalancenex;
159
+    }
160
+
161
+
162
+    /**
163
+     * @NoAdminRequired
164
+     */
165
+    public function getbalancetwil($userId) {
166
+
167
+        $smsapicred = $this->service->getapicredentials($this->userId);
168
+        $smsapisid = $smsapicred[15];
169
+        $smsapitoken = $smsapicred[16];
170
+
171
+        if ($smsapisid == '' || $smsapitoken == '') {
172
+            $currentbalancetwil = "N/A";
173
+        } else {
174
+
175
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
+            $balancetwil = $twilbalance->balance;
177
+
178
+            $currentbalancetwil = round(floatval($balancetwil), 3);
179
+        }
180
+        return $currentbalancetwil;
181
+    }
182
+
183
+
184
+    /**
185
+     * @NoAdminRequired
186
+     */
187
+    public function getbalanceflow($userId) {
188
+
189
+        $currentbalanceflow = 'n/a';
190
+
191
+        return $currentbalanceflow;
192
+    }
193
+
194
+
195
+    /**
196
+     * @NoAdminRequired
197
+     */
198
+    public function getsmsnumbers($userId) {
199
+
200
+        return $this->service->getsmsnumbers($this->userId);
201
+    }
202
+
203
+
204
+    /**
205
+     * @NoAdminRequired
206
+     */
207
+    public function cleantempdir($userId) {
208
+
209
+        // Create the temporary folder if it doesn't exist
210
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
211
+            $this->folder->newFolder('SMS_Relentless/temp_files');
212
+        }
213
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
214
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
215
+        $fileSystemIterator = new FilesystemIterator($targetdir);
216
+
217
+        $dirfiles = [];
218
+        foreach ($fileSystemIterator as $fileInfo){
219
+                 $dirfiles[] = $fileInfo->getFilename();
220
+        }
221
+
222
+        foreach ($dirfiles as $key => $indfile) {
223
+                 $thisuserroot = $this->view->getRoot();
224
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
225
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
226
+        }
227
+     }
228
+
229
+
230
+    /**
231
+     * @NoAdminRequired
232
+     */
233
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
234
+
235
+        // Create the temporary folder if it doesn't exist
236
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
237
+            $this->folder->newFolder('SMS_Relentless/temp_files');
238
+        }
239
+
240
+        // First delete any file that has been previously uploaded
241
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
242
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
243
+        $fileSystemIterator = new FilesystemIterator($targetdir);
244
+
245
+        $dirfiles = [];
246
+        foreach ($fileSystemIterator as $fileInfo){
247
+                 $dirfiles[] = $fileInfo->getFilename();
248
+        }
249
+
250
+        foreach ($dirfiles as $key => $indfile) {
251
+                 $thisuserroot = $this->view->getRoot();
252
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
253
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
254
+        }
255
+
256
+        // Upload the new file
257
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
258
+        $fileName = $_FILES['uploadfileforsms']['name'];
259
+
260
+        $userroot = $this->view->getRoot();
261
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
262
+
263
+        $target = $this->folder->newFile($targetfile);
264
+        $target->putContent($fileContent);
265
+
266
+        // Extract the phone numbers from the file
267
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
268
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
269
+        $numberarrayfourth = explode(",", $numberarraytert);
270
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
271
+        $numberarray = array_unique($numberarrayfifth);
272
+
273
+        return $numberarray;
274
+    }
275
+
276
+
277
+    /**
278
+     * @NoAdminRequired
279
+     */
280
+    public function uploadfile($uploadfileformms) {
281
+
282
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
283
+           $fileName = $_FILES['uploadfileformms']['name'];
284
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
285
+           $fileSize = $fileSizeinit / 1024;
286
+
287
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
288
+               $this->folder->newFolder('SMS_Relentless/temp_files');
289
+           }
290
+
291
+           $userroot = $this->view->getRoot();
292
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
293
+
294
+           $target = $this->folder->newFile($targetfile);
295
+           $target->putContent($fileContent);
296
+
297
+           // Get the cumulative files size of the uploaded files
298
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
299
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
300
+
301
+           $fileSystemIterator = new FilesystemIterator($targetdir);
302
+
303
+           $dirfiles = [];
304
+           foreach ($fileSystemIterator as $fileInfo){
305
+                    $dirfiles[] = $fileInfo->getFilename();
306
+           }
307
+
308
+           $totalflsizeinit = 0;
309
+           foreach ($dirfiles as $key => $indfile) {
310
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
311
+                    $mbSize = round($fileSizeinit / 1024, 4);
312
+                    $totalflsizeinit += $mbSize;
313
+           }
314
+
315
+           $totalflsize = round($totalflsizeinit, 4);
316
+
317
+           return $totalflsize;
318
+    }
319
+
320
+
321
+    /**
322
+     * @NoAdminRequired
323
+     */
324
+    public function pickfile($path) {
325
+
326
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
327
+               $this->folder->newFolder('SMS_Relentless/temp_files');
328
+           }
329
+
330
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
331
+
332
+           $fltgt = $datadir . $this->userId . "/files" . $path;
333
+
334
+           $fileContent = file_get_contents($fltgt);
335
+
336
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
337
+
338
+           $patharr = explode("/", $path);
339
+
340
+           $revarr = array_reverse($patharr);
341
+
342
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
343
+
344
+           $target = $this->folder->newFile($relflpath);
345
+
346
+           $target->putContent($fileContent);
347
+
348
+           // Get the cumulative files size of the uploaded files
349
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
350
+
351
+           $fileSystemIterator = new FilesystemIterator($targetdir);
352
+
353
+           $dirfiles = [];
354
+           foreach ($fileSystemIterator as $fileInfo) {
355
+                    $dirfiles[] = $fileInfo->getFilename();
356
+           }
357
+
358
+           $totalflsizeinit = 0;
359
+
360
+           foreach ($dirfiles as $key => $indfile) {
361
+
362
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
363
+                    $mbSize = round($fileSizeinit / 1024, 4);
364
+                    $totalflsizeinit += $mbSize;
365
+           }
366
+
367
+           $totalflsize = round($totalflsizeinit, 4);
368
+
369
+           $pickresult = [$totalflsize, $pkfilesize];
370
+
371
+           return $pickresult;
372
+    }
373
+
374
+
375
+    /**
376
+     * @NoAdminRequired
377
+     */
378
+    public function removeupfile($removedfilename) {
379
+
380
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
381
+
382
+           $removefile = $this->view->unlink($tmpfl);
383
+
384
+           // Get the cumulative files size of the uploaded files
385
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
386
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
387
+           $fileSystemIterator = new FilesystemIterator($targetdir);
388
+
389
+           $dirfiles = [];
390
+           foreach ($fileSystemIterator as $fileInfo){
391
+                    $dirfiles[] = $fileInfo->getFilename();
392
+           }
393
+
394
+           $totalflsizeinit = 0;
395
+
396
+           foreach ($dirfiles as $key => $indfile) {
397
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
398
+                    $mbSize = round($fileSizeinit / 1024, 4);
399
+                    $totalflsizeinit += $mbSize;
400
+           }
401
+
402
+           $totalflsize = round($totalflsizeinit, 4);
403
+
404
+           return $totalflsize;
405
+    }
406
+
407
+
408
+    /**
409
+     * @NoAdminRequired
410
+     */
411
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
412
+
413
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
414
+         $telnyxkey = $telsmsapicred[0];
415
+         $teldelrecurl = $telsmsapicred[3];
416
+         $messagingprofid = $telsmsapicred[4];
417
+         $addDisplName = $telsmsapicred[24];
418
+
419
+         // Get the Display Name of the current user
420
+         $crtuser = $this->userManager->get($this->userId);
421
+         $displayname = $crtuser->getDisplayName();
422
+
423
+         if ($addDisplName == 1) {
424
+             $sentsmstext = $displayname . ": " . $sentsmstext;
425
+         }
426
+
427
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
428
+
429
+         $microinterval = $waitinterval * 1000;
430
+
431
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
432
+
433
+             usleep($microinterval);
434
+
435
+             $messagedate = date("Y-m-d H:i:s");
436
+
437
+             if ($ismms == 0) {
438
+
439
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
440
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
441
+                 } else {
442
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
443
+                 }
444
+
445
+                 $messagetexttel = $sentsmstext;
446
+
447
+             } else {
448
+
449
+                 $mediaURLarr = [];
450
+                 $includedMediaFiles = '';
451
+
452
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
453
+
454
+                      $userroot = $this->view->getRoot();
455
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
456
+
457
+                      $flsharetarget = $this->folder->newFile($filetoshare);
458
+
459
+	              $share = $this->shareManager->newShare();
460
+	              $share->setNode($flsharetarget);
461
+	              $share->setPermissions(Constants::PERMISSION_READ);
462
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
463
+	              $share->setSharedBy($this->userId);
464
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
465
+                      $expirydate->add(new \DateInterval('P1D'));
466
+                      $share->setExpirationDate($expirydate);
467
+                      $shared = $this->shareManager->createShare($share);
468
+                      $shareToken = $shared->getToken();
469
+
470
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
471
+
472
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
473
+
474
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
475
+                 }
476
+
477
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
478
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
479
+                 } else {
480
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
481
+                 }
482
+
483
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
484
+             }
485
+
486
+             $messageid = $message['id'];
487
+             $messagefrom = "Telnyx: " . $fromsender;
488
+             $messageto = $tonumber;
489
+             $messagenetwork = null;
490
+             $messageprice = null;
491
+             $messagestatus = $message['to'][0]['status'];
492
+             $messagedelivery = null;
493
+
494
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
495
+
496
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
497
+         }
498
+         return $displayname;
499
+    }
500
+
501
+
502
+    /**
503
+     * @NoAdminRequired
504
+     */
505
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
506
+
507
+         $plsmsapicred = $this->service->getapicredentials($this->userId);
508
+
509
+         $smsapikey = $plsmsapicred[5];
510
+         $smsapisecret = $plsmsapicred[6];
511
+         $smsapideliveryrecurl = $plsmsapicred[8];
512
+         $addDisplName = $plsmsapicred[24];
513
+
514
+         // Get the Display Name of the current user
515
+         $crtuser = $this->userManager->get($this->userId);
516
+         $displayname = $crtuser->getDisplayName();
517
+
518
+         if ($addDisplName == 1) {
519
+             $sentsmstext = $displayname . ": " . $sentsmstext;
520
+         }
521
+
522
+         $microinterval = $waitinterval * 1000;
523
+
524
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
525
+
526
+             usleep($microinterval);
527
+
528
+             $messagedatepl = date("Y-m-d H:i:s");
529
+
530
+             if ($ismms == 0) {
531
+
532
+                 $client = new RestClient($smsapikey, $smsapisecret);
533
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
534
+                 $messagetextpl = $sentsmstext;
535
+	         $messageidinit = $response->getmessageUuid(0);
536
+                 $messageid = $messageidinit[0];
537
+
538
+                 if (property_exists($response, 'error')) { 
539
+                     $messagestatus = "Error: " . $response->error;
540
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
541
+
542
+             } else {
543
+
544
+                 $mediaURLarr = [];
545
+                 $includedMediaFiles = '';
546
+
547
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
548
+
549
+                      $userroot = $this->view->getRoot();
550
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
551
+
552
+                      $flsharetarget = $this->folder->newFile($filetoshare);
553
+
554
+	              $share = $this->shareManager->newShare();
555
+	              $share->setNode($flsharetarget);
556
+	              $share->setPermissions(Constants::PERMISSION_READ);
557
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
558
+	              $share->setSharedBy($this->userId);
559
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
560
+                      $expirydate->add(new \DateInterval('P1D'));
561
+                      $share->setExpirationDate($expirydate);
562
+                      $shared = $this->shareManager->createShare($share);
563
+                      $shareToken = $shared->getToken();
564
+
565
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
566
+
567
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
568
+
569
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
570
+                 }
571
+
572
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
573
+		 $postedparamspl = json_encode($datatosendpl);
574
+
575
+		 $chpl = curl_init();
576
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
577
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
578
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
579
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
580
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
581
+		 curl_setopt($chpl, CURLOPT_POST, 1);
582
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
583
+		 $resultpl = curl_exec ($chpl);
584
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
585
+		 curl_close ($chpl);
586
+
587
+		 $decresultpl = json_decode($resultpl);
588
+
589
+                 if ($decresultpl) {
590
+                     if (property_exists($decresultpl, 'message_uuid')) {
591
+                         $messageidinit = $decresultpl->message_uuid;
592
+                         $messageid = $messageidinit[0];
593
+                     } else { $messageid = 'n/a'; }
594
+                 } else { $messageid = 'n/a'; }
595
+
596
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
597
+
598
+                     if (property_exists($decresultpl, 'error')) {
599
+                         $messagestatus = "Error: " . $decresultpl->error;
600
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
601
+
602
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
603
+
604
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
605
+             }
606
+
607
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
608
+                 $messagefrom = "Plivo: " . $fromsender;
609
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
610
+
611
+             $messageto = $tonumber;
612
+             $messagenetwork = '';
613
+             $messageprice = '';
614
+
615
+             $messagedelivery = '';
616
+
617
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
618
+
619
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
620
+         }
621
+         return $displayname;
622
+    }
623
+
624
+
625
+    /**
626
+     * @NoAdminRequired
627
+     */
628
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
629
+
630
+         $twsmsapicred = $this->service->getapicredentials($this->userId);
631
+
632
+         $sid = $twsmsapicred[15];
633
+         $token = $twsmsapicred[16];
634
+         $smsapirecurltw = $twsmsapicred[18];
635
+         $addDisplName = $twsmsapicred[24];
636
+
637
+         // Get the Display Name of the current user
638
+         $crtuser = $this->userManager->get($this->userId);
639
+         $displayname = $crtuser->getDisplayName();
640
+
641
+         if ($addDisplName == 1) {
642
+             $sentsmstext = $displayname . ": " . $sentsmstext;
643
+         }
644
+
645
+         $microinterval = $waitinterval * 1000;
646
+
647
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
648
+
649
+             usleep($microinterval);
650
+
651
+             $messagedatetw = date("Y-m-d H:i:s");
652
+
653
+             if ($ismms == 0) {
654
+
655
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
656
+                 $sentsmstextfintw = $sentsmstext;
657
+
658
+             } else {
659
+
660
+                 $mediaURLs = [];
661
+                 $includedMediaFiles = '';
662
+
663
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
664
+
665
+                      $userroot = $this->view->getRoot();
666
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
667
+
668
+                      $flsharetarget = $this->folder->newFile($filetoshare);
669
+
670
+	              $share = $this->shareManager->newShare();
671
+	              $share->setNode($flsharetarget);
672
+	              $share->setPermissions(Constants::PERMISSION_READ);
673
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
674
+	              $share->setSharedBy($this->userId);
675
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
676
+                      $expirydate->add(new \DateInterval('P1D'));
677
+                      $share->setExpirationDate($expirydate);
678
+                      $shared = $this->shareManager->createShare($share);
679
+                      $shareToken = $shared->getToken();
680
+
681
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
682
+
683
+                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
684
+
685
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
686
+                 }
687
+
688
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
689
+
690
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
691
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
692
+                 }
693
+
694
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
695
+             }
696
+
697
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
698
+
699
+	     $chtw = curl_init();
700
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
701
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
702
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
703
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
704
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
705
+	     curl_setopt($chtw, CURLOPT_POST, 1);
706
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
707
+
708
+	     $resulttw = curl_exec ($chtw);
709
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
710
+	     curl_close ($chtw);
711
+
712
+             $decresulttw = json_decode($resulttw);
713
+
714
+             if ($decresulttw) {
715
+                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
716
+             } else { $messageidtw = 'n/a'; }
717
+
718
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
719
+                 $messagestatustw = 'The message has been accepted for delivery.';
720
+             } else {
721
+                 $messagestatustw = 'An error occurred while trying to send the message.';
722
+             }
723
+
724
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
725
+                 $messagefromtw = "Twilio: " . $fromsender;
726
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
727
+
728
+             $messagenetworktw = '';
729
+             $messagepricetw = '';
730
+             $messagedeliverytw = '';
731
+
732
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
733
+
734
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
735
+         }
736
+         return $displayname;
737
+    }
738
+
739
+
740
+    /**
741
+     * @NoAdminRequired
742
+     */
743
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
744
+
745
+         $flsmsapicred = $this->service->getapicredentials($this->userId);
746
+
747
+         $flowapikey = $flsmsapicred[20];
748
+         $flowapisecret = $flsmsapicred[21];
749
+         $flowdelrecurl = $flsmsapicred[23];
750
+         $addDisplName = $flsmsapicred[24];
751
+
752
+         // Get the Display Name of the current user
753
+         $crtuser = $this->userManager->get($this->userId);
754
+         $displayname = $crtuser->getDisplayName();
755
+
756
+         if ($addDisplName == 1) {
757
+             $sentsmstext = $displayname . ": " . $sentsmstext;
758
+         }
759
+
760
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
761
+
762
+         $microinterval = $waitinterval * 1000;
763
+
764
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
765
+
766
+             usleep($microinterval);
767
+
768
+             $messagedatefl = date("Y-m-d H:i:s");
769
+
770
+             if ($ismms == 0) {
771
+
772
+                 $messagetextfinfl = $sentsmstext;
773
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
774
+
775
+             } else {
776
+
777
+		 $mediaurlsarr = [];
778
+		 $includedMediaFiles = '';
779
+
780
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
781
+
782
+		      $userroot = $this->view->getRoot();
783
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
784
+
785
+		      $flsharetarget = $this->folder->newFile($filetoshare);
786
+
787
+		      $share = $this->shareManager->newShare();
788
+		      $share->setNode($flsharetarget);
789
+		      $share->setPermissions(Constants::PERMISSION_READ);
790
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
791
+		      $share->setSharedBy($this->userId);
792
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
793
+                      $expirydate->add(new \DateInterval('P1D'));
794
+                      $share->setExpirationDate($expirydate);
795
+		      $shared = $this->shareManager->createShare($share);
796
+		      $shareToken = $shared->getToken();
797
+
798
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
799
+
800
+		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
801
+
802
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
803
+		 }
804
+
805
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
806
+
807
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
808
+             }
809
+
810
+	     $chfl = curl_init();
811
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
812
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
813
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
814
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
815
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
816
+	     curl_setopt($chfl, CURLOPT_POST, 1);
817
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
818
+	     $resultfl = curl_exec ($chfl);
819
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
820
+	     curl_close ($chfl);
821
+
822
+             $decresultfl = json_decode($resultfl);
823
+
824
+             if ($decresultfl) {
825
+                 if (property_exists($decresultfl, 'data')) { 
826
+                     $messageidfl = $decresultfl->data->id;
827
+                 } else { $messageidfl = 'n/a'; }
828
+             } else { $messageidfl = 'n/a'; }
829
+
830
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
831
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
832
+             } else { 
833
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
834
+             }
835
+
836
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
837
+                 $messagefromfl = "Flowroute: " . $fromsender;
838
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
839
+
840
+             $messagetofl = $tonumberfl;
841
+             $messagenetworkfl = '';
842
+             $messagepricefl = '';
843
+             $messagedeliveryfl = '';
844
+
845
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
846
+
847
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
848
+         }
849
+         return $displayname;
850
+    }
851
+
852
+
853
+    /**
854
+     * @NoAdminRequired
855
+     */
856
+    public function saveoldrecrows($userId, $oldrecRows) {
857
+
858
+           // Create the folder for removed messages if it doesn't exist
859
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
860
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
861
+           }
862
+           $savecheck = 0;
863
+
864
+           if (count($oldrecRows) > 1) {
865
+               $msfileContent = implode("", $oldrecRows);
866
+
867
+               $delrowsdate = date("Y-m-d_H-i-s");
868
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
869
+
870
+               $userroot = $this->view->getRoot();
871
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
872
+
873
+               $target = $this->folder->newFile($targetfile);
874
+               $target->putContent($msfileContent);
875
+
876
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
877
+                   $savecheck = 1;
878
+               }
879
+           }
880
+
881
+           return $savecheck;
882
+    }
883
+
884
+
885
+    /**
886
+     * @NoAdminRequired
887
+     */
888
+    public function saveoldsentrows($userId, $oldsentRows) {
889
+
890
+           // Create the folder for removed messages if it doesn't exist
891
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
892
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
893
+           }
894
+           $savesentcheck = 0;
895
+
896
+           if (count($oldsentRows) > 1) {
897
+               $sntfileContent = implode("", $oldsentRows);
898
+
899
+               $delsentrowsdate = date("Y-m-d_H-i-s");
900
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
901
+
902
+               $userroot = $this->view->getRoot();
903
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
904
+
905
+               $snttarget = $this->folder->newFile($snttargetfile);
906
+               $snttarget->putContent($sntfileContent);
907
+
908
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
909
+                   $savesentcheck = 1;
910
+               }
911
+           }
912
+
913
+           return $savesentcheck;
914
+    }
915
+
916
+
917
+    /**
918
+     * @NoAdminRequired
919
+     */
920
+    public function getreceivedtable($userId) {
921
+           return $this->service->getreceivedtable($this->userId);
922
+    }
923
+
924
+    /**
925
+     * @NoAdminRequired
926
+     */
927
+    public function getreceivedtablefordel($userId) {
928
+           return $this->service->getreceivedtablefordel($this->userId);
929
+    }
930
+
931
+    /**
932
+     * @NoAdminRequired
933
+     */
934
+    public function removerecrows($userId, $recmessagedbIDs) {
935
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
936
+    }
937
+
938
+    /**
939
+     * @NoAdminRequired
940
+     */
941
+    public function getsenttable($userId) {
942
+           return $this->service->getsenttable($this->userId);
943
+    }
944
+
945
+    /**
946
+     * @NoAdminRequired
947
+     */
948
+    public function getsenttablefordel($userId) {
949
+           return $this->service->getsenttablefordel($this->userId);
950
+    }
951
+
952
+    /**
953
+     * @NoAdminRequired
954
+     */
955
+    public function removesentrows($userId, $sentmessagedbIDs) {
956
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
957
+    }
958
+
959
+    /**
960
+     * @NoAdminRequired
961
+     */
962
+    public function getgroupedtable($userId) {
963
+           return $this->service->getgroupedtable($this->userId);
964
+    }
965
+
966
+    /**
967
+     * @NoAdminRequired
968
+     */
969
+    public function savedisplayname($userId, $authorDisplayname, $from) {
970
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
971
+    }
972
+
973
+    /**
974
+     * @NoAdminRequired
975
+     */
976
+    public function getmessagesperpage($userId) {
977
+           return $this->service->getmessagesperpage($this->userId);
978
+    }
979
+
980
+    /**
981
+     * @NoAdminRequired
982
+     */
983
+    public function getdelrecsettings($userId) {
984
+           return $this->service->getdelrecsettings($this->userId);
985
+    }
986
+
987
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
988
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
989
+    }
990
+
991
+    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
992
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
993
+    }
994
+
995
+    public function removenumberrestrictions($userId, $phoneNumber) {
996
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
997
+    }
998
+
999
+    /**
1000
+     * @NoAdminRequired
1001
+     */
1002
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1003
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1004
+    }
1005
+
1006
+    /**
1007
+     * @NoAdminRequired
1008
+     */
1009
+    public function removeautoreplies($userId, $phoneNumber) {
1010
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1011
+    }
1012
+
1013
+    /**
1014
+     * @NoAdminRequired
1015
+     */
1016
+    public function getsettings($userId) {
1017
+           return $this->service->getsettings($this->userId);
1018
+    }
1019
+
1020
+    public function getadminsettings($userId) {
1021
+           return $this->service->getadminsettings($this->userId);
1022
+    }
1023
+
1024
+    /**
1025
+     * @NoAdminRequired
1026
+     */
1027
+    public function getautoreplyconf($userId) {
1028
+
1029
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1030
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1031
+
1032
+           // Get the display name of the current user
1033
+           $usrid = $this->userId;
1034
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1035
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1036
+	   $getusrdnmdata = $getusrdnmres->fetch();
1037
+	   $userDisplayNm = $getusrdnmdata['value'];
1038
+	   $getusrdnmres->closeCursor();
1039
+
1040
+           // Get the auto-replies for the available phone numbers
1041
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1042
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1043
+	   $getautorplres = $getautorpl->execute();
1044
+           $autorplconf = [];
1045
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1046
+                  $autorplconf[] = $acdatausrdnadm;
1047
+           }
1048
+	   $getautorplres->closeCursor();
1049
+
1050
+           if ($autorplconf) {
1051
+
1052
+               $autoreplyconf = [];
1053
+               foreach ($autorplconf as $arkey => $arvalue) {
1054
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1055
+                            $autoreplyconf[] = $arvalue;
1056
+                        }
1057
+               }
1058
+
1059
+           } else { $autoreplyconf = ''; }
1060
+
1061
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1062
+
1063
+           return $autoreplyfdb;
1064
+    }
1065
+
1066
+    /**
1067
+     * @NoAdminRequired
1068
+     */
1069
+    public function getgroupedpernumber($userId, $phoneNumber) {
1070
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1071
+    }
1072
+
1073
+    /**
1074
+     * @NoAdminRequired
1075
+     */
1076
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1077
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1078
+    }
1079
+
1080
+    /**
1081
+     * @NoAdminRequired
1082
+     */
1083
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1084
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1085
+    }
1086
+
1087
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1088
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1089
+    }
1090
+
1091
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1092
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1093
+    }
1094
+}
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php

DoubleBastionAdmin authored on 21/06/2023 21:17:24
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1281 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\IURLGenerator;
49
-use OCP\Share\IManager;
50
-use OCP\Constants;
51
-use OCP\IGroupManager;
52
-use OCP\IDBConnection;
53
-use OCP\IUserManager;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $urlGenerator;
64
-    private $shareManager;
65
-    private $groupManager;
66
-    private $connection;
67
-    private $userManager;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->urlGenerator = $urlGenerator;
78
-	$this->shareManager = $shareManager;
79
-        $this->groupManager = $groupManager;
80
-        $this->connection = $connection;
81
-        $this->userManager = $userManager;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getbalancetel($userId) {
120
-
121
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
-
123
-        $telapikey = $telsmsapicred[0];
124
-        $ch = curl_init();
125
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
-
127
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
-        $responsetel = curl_exec($ch);
131
-        $recdatatel = json_decode($responsetel, TRUE);
132
-        $telbalresponse = $recdatatel['data']['balance'];
133
-        $currentbalancetel = round(floatval($telbalresponse), 3);
134
-        curl_close($ch);
135
-
136
-        return $currentbalancetel;
137
-    }
138
-
139
-
140
-    /**
141
-     * @NoAdminRequired
142
-     */
143
-    public function getbalancenex($userId) {
144
-
145
-        $smsapicred = $this->service->getapicredentials($this->userId);
146
-        $smsapikey = $smsapicred[5];
147
-        $smsapisecret = $smsapicred[6];
148
-
149
-        if ($smsapikey == '' || $smsapisecret == '') {
150
-            $currentbalancenex = "N/A";
151
-        } else {
152
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
-            $mesdata = file_get_contents($getmesdata);
154
-            $datainit = json_decode($mesdata);
155
-            $balancenex = $datainit->cash_credits;
156
-            $currentbalancenex = round(floatval($balancenex), 3);
157
-        }
158
-        return $currentbalancenex;
159
-    }
160
-
161
-
162
-    /**
163
-     * @NoAdminRequired
164
-     */
165
-    public function getbalancetwil($userId) {
166
-
167
-        $smsapicred = $this->service->getapicredentials($this->userId);
168
-        $smsapisid = $smsapicred[15];
169
-        $smsapitoken = $smsapicred[16];
170
-
171
-        if ($smsapisid == '' || $smsapitoken == '') {
172
-            $currentbalancetwil = "N/A";
173
-        } else {
174
-
175
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
-            $balancetwil = $twilbalance->balance;
177
-
178
-            $currentbalancetwil = round(floatval($balancetwil), 3);
179
-        }
180
-        return $currentbalancetwil;
181
-    }
182
-
183
-
184
-    /**
185
-     * @NoAdminRequired
186
-     */
187
-    public function getbalanceflow($userId) {
188
-
189
-        $currentbalanceflow = 'n/a';
190
-
191
-        return $currentbalanceflow;
192
-    }
193
-
194
-
195
-    /**
196
-     * @NoAdminRequired
197
-     */
198
-    public function getsmsnumbers($userId) {
199
-
200
-        $smsapicred = $this->service->getapicredentials($this->userId);
201
-
202
-        $telnyxkey = $smsapicred[0];
203
-
204
-        $nexapikey = $smsapicred[5];
205
-        $nexapisecret = $smsapicred[6];
206
-
207
-        $twilapikey = $smsapicred[15];
208
-        $twilapisecret = $smsapicred[16];
209
-
210
-        $flowapikey = $smsapicred[20];
211
-        $flowapisecret = $smsapicred[21];
212
-
213
-        $telsendernameinit = $smsapicred[9];
214
-        $nexsendernameinit = $smsapicred[10];
215
-        $twilsendernameinit = $smsapicred[19];
216
-
217
-        if ($telsendernameinit) {
218
-            $telsendername = "Tx: " . $telsendernameinit;
219
-            $telsenderarr = [0 => $telsendername];
220
-        } else { $telsenderarr = []; }
221
-
222
-        if ($nexsendernameinit) {
223
-            $nexsendername = "Pl: " . $nexsendernameinit;
224
-            $nexsenderarr = [0 => $nexsendername];
225
-        } else { $nexsenderarr = []; }
226
-
227
-        if ($twilsendernameinit) {
228
-            $twilsendername = "Tw: " . $twilsendernameinit;
229
-            $twilsenderarr = [0 => $twilsendername];
230
-        } else { $twilsenderarr = []; }
231
-
232
-        // Get Telnyx phone numbers
233
-        if ($telnyxkey != '') {
234
-
235
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
236
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
237
-
238
-           $telnumbersarr = $this->object_to_array($telnumbers);
239
-           $telnmbrs = [];
240
-
241
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
242
-              if (is_int($nmbkey)) {
243
-                 foreach ($nmbvalue as $nkey => $nvalue) {
244
-                    if ($nkey == 'phone_number' && $nvalue) {
245
-                       $telnmbrs[] = "Tx: " . $nvalue;
246
-                    }
247
-                 }
248
-              }
249
-           }
250
-
251
-        } else { $telnmbrs = []; }
252
-
253
-        // Get Plivo phone numbers
254
-        if ($nexapikey != '' && $nexapisecret != '') {
255
-
256
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
257
-           $acdata = file_get_contents($getacdata);
258
-           $datainit = json_decode($acdata, true);
259
-
260
-           $findata = $this->object_to_array($datainit);
261
-
262
-           $nexcurrentnmbrs = [];
263
-
264
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
265
-                   if (is_array($smsvalue)) {
266
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
267
-                               if ($smskey2 == 'number' && $smsvalue2) {
268
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
269
-                               }
270
-                         }
271
-                   }
272
-           }
273
-
274
-
275
-        } else { $nexcurrentnmbrs = []; }
276
-
277
-        // Get Twilio phone numbers
278
-        if ($twilapikey != '' && $twilapisecret != '') {
279
-
280
-            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
281
-            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
282
-
283
-            $twilcurrentnmbrs = [];
284
-            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
285
-                 if (is_array($twnbvalue)) {
286
-                     foreach ($twnbvalue as $twfkey => $twfvalue) {
287
-                          if ($twfkey == 'phone_number' && $twfvalue) {
288
-                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
289
-                          }
290
-                     }
291
-                 }
292
-            }
293
-
294
-        } else { $twilcurrentnmbrs = []; }
295
-
296
-        // Get Flowroute phone numbers
297
-        if ($flowapikey != '' && $flowapisecret != '') {
298
-
299
-            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
300
-            $flnbrsarr = $flnbrsresult->data;
301
-            $flowcurrentnmbrs = [];
302
-            foreach ($flnbrsarr as $flkey => $flitem) {
303
-                     if ($flitem->id) {
304
-                         $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
305
-                     }
306
-            }
307
-
308
-        } else { $flowcurrentnmbrs = []; }
309
-
310
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
311
-
312
-        if ($this->groupManager->isAdmin($this->userId)) {
313
-
314
-            return $currentnmbrs;
315
-
316
-        } else {
317
-
318
-            // Get the restrictions from the 'sms_relent_restrict' table
319
-            $getrestr = $this->connection->prepare('
320
-		       SELECT `phone_number`, `groups`, `users` FROM `*PREFIX*sms_relent_restrict`');
321
-            $getrestrres = $getrestr->execute();
322
-
323
-            $restrdata = [];
324
-            while ($restrfetched = $getrestrres->fetch()) {
325
-                   $restrdata[] = $restrfetched;
326
-            }
327
-            $getrestrres->closeCursor();
328
-
329
-            if ($restrdata) {
330
-
331
-                // Get the groups to which the current user belongs
332
-                $usrId = $this->userId;
333
-                $getusrgrp = $this->connection->prepare('
334
-		       SELECT `gid`, `uid` FROM `*PREFIX*group_user` WHERE `uid` = ?');
335
-                $getusrgrpres = $getusrgrp->execute([$usrId]);
336
-
337
-                $usergrps = [];
338
-                while ($fetchedgrps = $getusrgrpres->fetch()) {
339
-                       $usergrps[] = $fetchedgrps['gid'];
340
-                }
341
-                $getusrgrpres->closeCursor();
342
-                $ctusergroups = implode("|", $usergrps);
343
-
344
-		// Get the Display Name of the current user
345
-		$getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
346
-		$getacdatadnres = $getacdatadn->execute([$usrId, 'displayname']);
347
-		$acdatausrdnadm = $getacdatadnres->fetch();
348
-		$cruserdname = $acdatausrdnadm['value'];
349
-		$getacdatadnres->closeCursor();
350
-
351
-                // Get the phone numbers that are not allowed for the current user
352
-                $restrPhoneNb = [];
353
-                foreach ($restrdata as $rskey => $rsvalue) {
354
-
355
-                        $chck = 0;
356
-                        if ($rsvalue['groups']) {
357
-                            $restrgrparr = explode("|", $rsvalue['groups']);
358
-
359
-                            foreach ($restrgrparr as $grkey => $grvalue) {
360
-                                     if (str_contains($ctusergroups, $grvalue)) { $chck++; }
361
-                            }
362
-                        }
363
-
364
-                        if ($rsvalue['users']) {
365
-                            $usrnmstr = $rsvalue['users'];
366
-                            if (str_contains($usrnmstr, $cruserdname)) { $chck++; }
367
-                        }
368
-
369
-                        if ($chck == 0) { $restrPhoneNb[] = $rsvalue['phone_number']; }
370
-                }
371
-
372
-                $restrPhoneNmbrs = array_unique($restrPhoneNb);
373
-
374
-                // Assemble the array of phone numbers that the current user is allowed to use
375
-                for ($k = 0; $k < count($currentnmbrs); $k++) {
376
-
377
-                    if (in_array($currentnmbrs[$k], $restrPhoneNmbrs)) {
378
-                        unset($currentnmbrs[$k]);
379
-                    }
380
-                }
381
-
382
-                $currentnmbrsrstr = array_values($currentnmbrs);
383
-
384
-                return $currentnmbrsrstr;
385
-
386
-            } else { return $currentnmbrs; }
387
-        }
388
-    }
389
-
390
-
391
-    /**
392
-     * @NoAdminRequired
393
-     */
394
-    public function cleantempdir($userId) {
395
-
396
-        // Create the temporary folder if it doesn't exist
397
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
398
-            $this->folder->newFolder('SMS_Relentless/temp_files');
399
-        }
400
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
401
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
402
-        $fileSystemIterator = new FilesystemIterator($targetdir);
403
-
404
-        $dirfiles = [];
405
-        foreach ($fileSystemIterator as $fileInfo){
406
-                 $dirfiles[] = $fileInfo->getFilename();
407
-        }
408
-
409
-        foreach ($dirfiles as $key => $indfile) {
410
-                 $thisuserroot = $this->view->getRoot();
411
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
412
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
413
-        }
414
-     }
415
-
416
-
417
-    /**
418
-     * @NoAdminRequired
419
-     */
420
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
421
-
422
-        // Create the temporary folder if it doesn't exist
423
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
424
-            $this->folder->newFolder('SMS_Relentless/temp_files');
425
-        }
426
-
427
-        // First delete any file that has been previously uploaded
428
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
429
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
430
-        $fileSystemIterator = new FilesystemIterator($targetdir);
431
-
432
-        $dirfiles = [];
433
-        foreach ($fileSystemIterator as $fileInfo){
434
-                 $dirfiles[] = $fileInfo->getFilename();
435
-        }
436
-
437
-        foreach ($dirfiles as $key => $indfile) {
438
-                 $thisuserroot = $this->view->getRoot();
439
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
440
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
441
-        }
442
-
443
-        // Upload the new file
444
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
445
-        $fileName = $_FILES['uploadfileforsms']['name'];
446
-
447
-        $userroot = $this->view->getRoot();
448
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
449
-
450
-        $target = $this->folder->newFile($targetfile);
451
-        $target->putContent($fileContent);
452
-
453
-        // Extract the phone numbers from the file
454
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
455
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
456
-        $numberarrayfourth = explode(",", $numberarraytert);
457
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
458
-        $numberarray = array_unique($numberarrayfifth);
459
-
460
-        return $numberarray;
461
-    }
462
-
463
-
464
-    /**
465
-     * @NoAdminRequired
466
-     */
467
-    public function uploadfile($uploadfileformms) {
468
-
469
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
470
-           $fileName = $_FILES['uploadfileformms']['name'];
471
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
472
-           $fileSize = $fileSizeinit / 1024;
473
-
474
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
475
-               $this->folder->newFolder('SMS_Relentless/temp_files');
476
-           }
477
-
478
-           $userroot = $this->view->getRoot();
479
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
480
-
481
-           $target = $this->folder->newFile($targetfile);
482
-           $target->putContent($fileContent);
483
-
484
-           // Get the cumulative files size of the uploaded files
485
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
486
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
487
-
488
-           $fileSystemIterator = new FilesystemIterator($targetdir);
489
-
490
-           $dirfiles = [];
491
-           foreach ($fileSystemIterator as $fileInfo){
492
-                    $dirfiles[] = $fileInfo->getFilename();
493
-           }
494
-
495
-           $totalflsizeinit = 0;
496
-           foreach ($dirfiles as $key => $indfile) {
497
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
498
-                    $mbSize = round($fileSizeinit / 1024, 4);
499
-                    $totalflsizeinit += $mbSize;
500
-           }
501
-
502
-           $totalflsize = round($totalflsizeinit, 4);
503
-
504
-           return $totalflsize;
505
-    }
506
-
507
-
508
-    /**
509
-     * @NoAdminRequired
510
-     */
511
-    public function pickfile($path) {
512
-
513
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
514
-               $this->folder->newFolder('SMS_Relentless/temp_files');
515
-           }
516
-
517
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
518
-
519
-           $fltgt = $datadir . $this->userId . "/files" . $path;
520
-
521
-           $fileContent = file_get_contents($fltgt);
522
-
523
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
524
-
525
-           $patharr = explode("/", $path);
526
-
527
-           $revarr = array_reverse($patharr);
528
-
529
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
530
-
531
-           $target = $this->folder->newFile($relflpath);
532
-
533
-           $target->putContent($fileContent);
534
-
535
-           // Get the cumulative files size of the uploaded files
536
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
537
-
538
-           $fileSystemIterator = new FilesystemIterator($targetdir);
539
-
540
-           $dirfiles = [];
541
-           foreach ($fileSystemIterator as $fileInfo) {
542
-                    $dirfiles[] = $fileInfo->getFilename();
543
-           }
544
-
545
-           $totalflsizeinit = 0;
546
-
547
-           foreach ($dirfiles as $key => $indfile) {
548
-
549
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
550
-                    $mbSize = round($fileSizeinit / 1024, 4);
551
-                    $totalflsizeinit += $mbSize;
552
-           }
553
-
554
-           $totalflsize = round($totalflsizeinit, 4);
555
-
556
-           $pickresult = [$totalflsize, $pkfilesize];
557
-
558
-           return $pickresult;
559
-    }
560
-
561
-
562
-    /**
563
-     * @NoAdminRequired
564
-     */
565
-    public function removeupfile($removedfilename) {
566
-
567
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
568
-
569
-           $removefile = $this->view->unlink($tmpfl);
570
-
571
-           // Get the cumulative files size of the uploaded files
572
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
573
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
574
-           $fileSystemIterator = new FilesystemIterator($targetdir);
575
-
576
-           $dirfiles = [];
577
-           foreach ($fileSystemIterator as $fileInfo){
578
-                    $dirfiles[] = $fileInfo->getFilename();
579
-           }
580
-
581
-           $totalflsizeinit = 0;
582
-
583
-           foreach ($dirfiles as $key => $indfile) {
584
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
585
-                    $mbSize = round($fileSizeinit / 1024, 4);
586
-                    $totalflsizeinit += $mbSize;
587
-           }
588
-
589
-           $totalflsize = round($totalflsizeinit, 4);
590
-
591
-           return $totalflsize;
592
-    }
593
-
594
-
595
-    /**
596
-     * @NoAdminRequired
597
-     */
598
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
599
-
600
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
601
-         $telnyxkey = $telsmsapicred[0];
602
-         $teldelrecurl = $telsmsapicred[3];
603
-         $messagingprofid = $telsmsapicred[4];
604
-         $addDisplName = $telsmsapicred[24];
605
-
606
-         // Get the Display Name of the current user
607
-         $crtuser = $this->userManager->get($this->userId);
608
-         $displayname = $crtuser->getDisplayName();
609
-
610
-         if ($addDisplName == 1) {
611
-             $sentsmstext = $displayname . ": " . $sentsmstext;
612
-         }
613
-
614
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
615
-
616
-         $microinterval = $waitinterval * 1000;
617
-
618
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
619
-
620
-             usleep($microinterval);
621
-
622
-             $messagedate = date("Y-m-d H:i:s");
623
-
624
-             if ($ismms == 0) {
625
-
626
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
627
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
628
-                 } else {
629
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
630
-                 }
631
-
632
-                 $messagetexttel = $sentsmstext;
633
-
634
-             } else {
635
-
636
-                 $mediaURLarr = [];
637
-                 $includedMediaFiles = '';
638
-
639
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
640
-
641
-                      $userroot = $this->view->getRoot();
642
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
643
-
644
-                      $flsharetarget = $this->folder->newFile($filetoshare);
645
-
646
-	              $share = $this->shareManager->newShare();
647
-	              $share->setNode($flsharetarget);
648
-	              $share->setPermissions(Constants::PERMISSION_READ);
649
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
650
-	              $share->setSharedBy($this->userId);
651
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
652
-                      $expirydate->add(new \DateInterval('P1D'));
653
-                      $share->setExpirationDate($expirydate);
654
-                      $shared = $this->shareManager->createShare($share);
655
-                      $shareToken = $shared->getToken();
656
-
657
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
658
-
659
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
660
-
661
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
662
-                 }
663
-
664
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
665
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
666
-                 } else {
667
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
668
-                 }
669
-
670
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
671
-             }
672
-
673
-             $messageid = $message['id'];
674
-             $messagefrom = "Telnyx: " . $fromsender;
675
-             $messageto = $tonumber;
676
-             $messagenetwork = null;
677
-             $messageprice = null;
678
-             $messagestatus = $message['to'][0]['status'];
679
-             $messagedelivery = null;
680
-
681
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
682
-
683
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
684
-         }
685
-         return $displayname;
686
-    }
687
-
688
-
689
-    /**
690
-     * @NoAdminRequired
691
-     */
692
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
693
-
694
-         $plsmsapicred = $this->service->getapicredentials($this->userId);
695
-
696
-         $smsapikey = $plsmsapicred[5];
697
-         $smsapisecret = $plsmsapicred[6];
698
-         $smsapideliveryrecurl = $plsmsapicred[8];
699
-         $addDisplName = $plsmsapicred[24];
700
-
701
-         // Get the Display Name of the current user
702
-         $crtuser = $this->userManager->get($this->userId);
703
-         $displayname = $crtuser->getDisplayName();
704
-
705
-         if ($addDisplName == 1) {
706
-             $sentsmstext = $displayname . ": " . $sentsmstext;
707
-         }
708
-
709
-         $microinterval = $waitinterval * 1000;
710
-
711
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
712
-
713
-             usleep($microinterval);
714
-
715
-             $messagedatepl = date("Y-m-d H:i:s");
716
-
717
-             if ($ismms == 0) {
718
-
719
-                 $client = new RestClient($smsapikey, $smsapisecret);
720
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
721
-                 $messagetextpl = $sentsmstext;
722
-	         $messageidinit = $response->getmessageUuid(0);
723
-                 $messageid = $messageidinit[0];
724
-
725
-                 if (property_exists($response, 'error')) { 
726
-                     $messagestatus = "Error: " . $response->error;
727
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
728
-
729
-             } else {
730
-
731
-                 $mediaURLarr = [];
732
-                 $includedMediaFiles = '';
733
-
734
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
735
-
736
-                      $userroot = $this->view->getRoot();
737
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
738
-
739
-                      $flsharetarget = $this->folder->newFile($filetoshare);
740
-
741
-	              $share = $this->shareManager->newShare();
742
-	              $share->setNode($flsharetarget);
743
-	              $share->setPermissions(Constants::PERMISSION_READ);
744
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
745
-	              $share->setSharedBy($this->userId);
746
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
747
-                      $expirydate->add(new \DateInterval('P1D'));
748
-                      $share->setExpirationDate($expirydate);
749
-                      $shared = $this->shareManager->createShare($share);
750
-                      $shareToken = $shared->getToken();
751
-
752
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
753
-
754
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
755
-
756
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
757
-                 }
758
-
759
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
760
-		 $postedparamspl = json_encode($datatosendpl);
761
-
762
-		 $chpl = curl_init();
763
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
764
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
765
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
766
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
767
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
768
-		 curl_setopt($chpl, CURLOPT_POST, 1);
769
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
770
-		 $resultpl = curl_exec ($chpl);
771
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
772
-		 curl_close ($chpl);
773
-
774
-		 $decresultpl = json_decode($resultpl);
775
-
776
-                 if ($decresultpl) {
777
-                     if (property_exists($decresultpl, 'message_uuid')) {
778
-                         $messageidinit = $decresultpl->message_uuid;
779
-                         $messageid = $messageidinit[0];
780
-                     } else { $messageid = 'n/a'; }
781
-                 } else { $messageid = 'n/a'; }
782
-
783
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
784
-
785
-                     if (property_exists($decresultpl, 'error')) {
786
-                         $messagestatus = "Error: " . $decresultpl->error;
787
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
788
-
789
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
790
-
791
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
792
-             }
793
-
794
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
795
-                 $messagefrom = "Plivo: " . $fromsender;
796
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
797
-
798
-             $messageto = $tonumber;
799
-             $messagenetwork = '';
800
-             $messageprice = '';
801
-
802
-             $messagedelivery = '';
803
-
804
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
805
-
806
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
807
-         }
808
-         return $displayname;
809
-    }
810
-
811
-
812
-    /**
813
-     * @NoAdminRequired
814
-     */
815
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
816
-
817
-         $twsmsapicred = $this->service->getapicredentials($this->userId);
818
-
819
-         $sid = $twsmsapicred[15];
820
-         $token = $twsmsapicred[16];
821
-         $smsapirecurltw = $twsmsapicred[18];
822
-         $addDisplName = $twsmsapicred[24];
823
-
824
-         // Get the Display Name of the current user
825
-         $crtuser = $this->userManager->get($this->userId);
826
-         $displayname = $crtuser->getDisplayName();
827
-
828
-         if ($addDisplName == 1) {
829
-             $sentsmstext = $displayname . ": " . $sentsmstext;
830
-         }
831
-
832
-         $microinterval = $waitinterval * 1000;
833
-
834
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
835
-
836
-             usleep($microinterval);
837
-
838
-             $messagedatetw = date("Y-m-d H:i:s");
839
-
840
-             if ($ismms == 0) {
841
-
842
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
843
-                 $sentsmstextfintw = $sentsmstext;
844
-
845
-             } else {
846
-
847
-                 $mediaURLs = [];
848
-                 $includedMediaFiles = '';
849
-
850
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
851
-
852
-                      $userroot = $this->view->getRoot();
853
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
854
-
855
-                      $flsharetarget = $this->folder->newFile($filetoshare);
856
-
857
-	              $share = $this->shareManager->newShare();
858
-	              $share->setNode($flsharetarget);
859
-	              $share->setPermissions(Constants::PERMISSION_READ);
860
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
861
-	              $share->setSharedBy($this->userId);
862
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
863
-                      $expirydate->add(new \DateInterval('P1D'));
864
-                      $share->setExpirationDate($expirydate);
865
-                      $shared = $this->shareManager->createShare($share);
866
-                      $shareToken = $shared->getToken();
867
-
868
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
869
-
870
-                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
871
-
872
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
873
-                 }
874
-
875
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
876
-
877
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
878
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
879
-                 }
880
-
881
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
882
-             }
883
-
884
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
885
-
886
-	     $chtw = curl_init();
887
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
888
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
889
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
890
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
891
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
892
-	     curl_setopt($chtw, CURLOPT_POST, 1);
893
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
894
-
895
-	     $resulttw = curl_exec ($chtw);
896
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
897
-	     curl_close ($chtw);
898
-
899
-             $decresulttw = json_decode($resulttw);
900
-
901
-             if ($decresulttw) {
902
-                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
903
-             } else { $messageidtw = 'n/a'; }
904
-
905
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
906
-                 $messagestatustw = 'The message has been accepted for delivery.';
907
-             } else {
908
-                 $messagestatustw = 'An error occurred while trying to send the message.';
909
-             }
910
-
911
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
912
-                 $messagefromtw = "Twilio: " . $fromsender;
913
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
914
-
915
-             $messagenetworktw = '';
916
-             $messagepricetw = '';
917
-             $messagedeliverytw = '';
918
-
919
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
920
-
921
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
922
-         }
923
-         return $displayname;
924
-    }
925
-
926
-
927
-    /**
928
-     * @NoAdminRequired
929
-     */
930
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
931
-
932
-         $flsmsapicred = $this->service->getapicredentials($this->userId);
933
-
934
-         $flowapikey = $flsmsapicred[20];
935
-         $flowapisecret = $flsmsapicred[21];
936
-         $flowdelrecurl = $flsmsapicred[23];
937
-         $addDisplName = $flsmsapicred[24];
938
-
939
-         // Get the Display Name of the current user
940
-         $crtuser = $this->userManager->get($this->userId);
941
-         $displayname = $crtuser->getDisplayName();
942
-
943
-         if ($addDisplName == 1) {
944
-             $sentsmstext = $displayname . ": " . $sentsmstext;
945
-         }
946
-
947
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
948
-
949
-         $microinterval = $waitinterval * 1000;
950
-
951
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
952
-
953
-             usleep($microinterval);
954
-
955
-             $messagedatefl = date("Y-m-d H:i:s");
956
-
957
-             if ($ismms == 0) {
958
-
959
-                 $messagetextfinfl = $sentsmstext;
960
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
961
-
962
-             } else {
963
-
964
-		 $mediaurlsarr = [];
965
-		 $includedMediaFiles = '';
966
-
967
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
968
-
969
-		      $userroot = $this->view->getRoot();
970
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
971
-
972
-		      $flsharetarget = $this->folder->newFile($filetoshare);
973
-
974
-		      $share = $this->shareManager->newShare();
975
-		      $share->setNode($flsharetarget);
976
-		      $share->setPermissions(Constants::PERMISSION_READ);
977
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
978
-		      $share->setSharedBy($this->userId);
979
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
980
-                      $expirydate->add(new \DateInterval('P1D'));
981
-                      $share->setExpirationDate($expirydate);
982
-		      $shared = $this->shareManager->createShare($share);
983
-		      $shareToken = $shared->getToken();
984
-
985
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
986
-
987
-		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
988
-
989
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
990
-		 }
991
-
992
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
993
-
994
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
995
-             }
996
-
997
-	     $chfl = curl_init();
998
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
999
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
1000
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
1001
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
1002
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
1003
-	     curl_setopt($chfl, CURLOPT_POST, 1);
1004
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
1005
-	     $resultfl = curl_exec ($chfl);
1006
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
1007
-	     curl_close ($chfl);
1008
-
1009
-             $decresultfl = json_decode($resultfl);
1010
-
1011
-             if ($decresultfl) {
1012
-                 if (property_exists($decresultfl, 'data')) { 
1013
-                     $messageidfl = $decresultfl->data->id;
1014
-                 } else { $messageidfl = 'n/a'; }
1015
-             } else { $messageidfl = 'n/a'; }
1016
-
1017
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
1018
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
1019
-             } else { 
1020
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
1021
-             }
1022
-
1023
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
1024
-                 $messagefromfl = "Flowroute: " . $fromsender;
1025
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
1026
-
1027
-             $messagetofl = $tonumberfl;
1028
-             $messagenetworkfl = '';
1029
-             $messagepricefl = '';
1030
-             $messagedeliveryfl = '';
1031
-
1032
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
1033
-
1034
-             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
1035
-         }
1036
-         return $displayname;
1037
-    }
1038
-
1039
-
1040
-    /**
1041
-     * @NoAdminRequired
1042
-     */
1043
-    public function saveoldrecrows($userId, $oldrecRows) {
1044
-
1045
-           // Create the folder for removed messages if it doesn't exist
1046
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
1047
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
1048
-           }
1049
-           $savecheck = 0;
1050
-
1051
-           if (count($oldrecRows) > 1) {
1052
-               $msfileContent = implode("", $oldrecRows);
1053
-
1054
-               $delrowsdate = date("Y-m-d_H-i-s");
1055
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
1056
-
1057
-               $userroot = $this->view->getRoot();
1058
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
1059
-
1060
-               $target = $this->folder->newFile($targetfile);
1061
-               $target->putContent($msfileContent);
1062
-
1063
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
1064
-                   $savecheck = 1;
1065
-               }
1066
-           }
1067
-
1068
-           return $savecheck;
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * @NoAdminRequired
1074
-     */
1075
-    public function saveoldsentrows($userId, $oldsentRows) {
1076
-
1077
-           // Create the folder for removed messages if it doesn't exist
1078
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
1079
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
1080
-           }
1081
-           $savesentcheck = 0;
1082
-
1083
-           if (count($oldsentRows) > 1) {
1084
-               $sntfileContent = implode("", $oldsentRows);
1085
-
1086
-               $delsentrowsdate = date("Y-m-d_H-i-s");
1087
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
1088
-
1089
-               $userroot = $this->view->getRoot();
1090
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
1091
-
1092
-               $snttarget = $this->folder->newFile($snttargetfile);
1093
-               $snttarget->putContent($sntfileContent);
1094
-
1095
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
1096
-                   $savesentcheck = 1;
1097
-               }
1098
-           }
1099
-
1100
-           return $savesentcheck;
1101
-    }
1102
-
1103
-
1104
-    /**
1105
-     * @NoAdminRequired
1106
-     */
1107
-    public function getreceivedtable($userId) {
1108
-           return $this->service->getreceivedtable($this->userId);
1109
-    }
1110
-
1111
-    /**
1112
-     * @NoAdminRequired
1113
-     */
1114
-    public function getreceivedtablefordel($userId) {
1115
-           return $this->service->getreceivedtablefordel($this->userId);
1116
-    }
1117
-
1118
-    /**
1119
-     * @NoAdminRequired
1120
-     */
1121
-    public function removerecrows($userId, $recmessagedbIDs) {
1122
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
1123
-    }
1124
-
1125
-    /**
1126
-     * @NoAdminRequired
1127
-     */
1128
-    public function getsenttable($userId) {
1129
-           return $this->service->getsenttable($this->userId);
1130
-    }
1131
-
1132
-    /**
1133
-     * @NoAdminRequired
1134
-     */
1135
-    public function getsenttablefordel($userId) {
1136
-           return $this->service->getsenttablefordel($this->userId);
1137
-    }
1138
-
1139
-    /**
1140
-     * @NoAdminRequired
1141
-     */
1142
-    public function removesentrows($userId, $sentmessagedbIDs) {
1143
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1144
-    }
1145
-
1146
-    /**
1147
-     * @NoAdminRequired
1148
-     */
1149
-    public function getgroupedtable($userId) {
1150
-           return $this->service->getgroupedtable($this->userId);
1151
-    }
1152
-
1153
-    /**
1154
-     * @NoAdminRequired
1155
-     */
1156
-    public function savedisplayname($userId, $authorDisplayname, $from) {
1157
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1158
-    }
1159
-
1160
-    /**
1161
-     * @NoAdminRequired
1162
-     */
1163
-    public function getmessagesperpage($userId) {
1164
-           return $this->service->getmessagesperpage($this->userId);
1165
-    }
1166
-
1167
-    /**
1168
-     * @NoAdminRequired
1169
-     */
1170
-    public function getdelrecsettings($userId) {
1171
-           return $this->service->getdelrecsettings($this->userId);
1172
-    }
1173
-
1174
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1175
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1176
-    }
1177
-
1178
-    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1179
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1180
-    }
1181
-
1182
-    public function removenumberrestrictions($userId, $phoneNumber) {
1183
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1184
-    }
1185
-
1186
-    /**
1187
-     * @NoAdminRequired
1188
-     */
1189
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1190
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1191
-    }
1192
-
1193
-    /**
1194
-     * @NoAdminRequired
1195
-     */
1196
-    public function removeautoreplies($userId, $phoneNumber) {
1197
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1198
-    }
1199
-
1200
-    /**
1201
-     * @NoAdminRequired
1202
-     */
1203
-    public function getsettings($userId) {
1204
-           return $this->service->getsettings($this->userId);
1205
-    }
1206
-
1207
-    public function getadminsettings($userId) {
1208
-           return $this->service->getadminsettings($this->userId);
1209
-    }
1210
-
1211
-    /**
1212
-     * @NoAdminRequired
1213
-     */
1214
-    public function getautoreplyconf($userId) {
1215
-
1216
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1217
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1218
-
1219
-           // Get the display name of the current user
1220
-           $usrid = $this->userId;
1221
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1222
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1223
-	   $getusrdnmdata = $getusrdnmres->fetch();
1224
-	   $userDisplayNm = $getusrdnmdata['value'];
1225
-	   $getusrdnmres->closeCursor();
1226
-
1227
-           // Get the auto-replies for the available phone numbers
1228
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1229
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1230
-	   $getautorplres = $getautorpl->execute();
1231
-           $autorplconf = [];
1232
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1233
-                  $autorplconf[] = $acdatausrdnadm;
1234
-           }
1235
-	   $getautorplres->closeCursor();
1236
-
1237
-           if ($autorplconf) {
1238
-
1239
-               $autoreplyconf = [];
1240
-               foreach ($autorplconf as $arkey => $arvalue) {
1241
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1242
-                            $autoreplyconf[] = $arvalue;
1243
-                        }
1244
-               }
1245
-
1246
-           } else { $autoreplyconf = ''; }
1247
-
1248
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1249
-
1250
-           return $autoreplyfdb;
1251
-    }
1252
-
1253
-    /**
1254
-     * @NoAdminRequired
1255
-     */
1256
-    public function getgroupedpernumber($userId, $phoneNumber) {
1257
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1258
-    }
1259
-
1260
-    /**
1261
-     * @NoAdminRequired
1262
-     */
1263
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1264
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1265
-    }
1266
-
1267
-    /**
1268
-     * @NoAdminRequired
1269
-     */
1270
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1271
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1272
-    }
1273
-
1274
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1275
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1276
-    }
1277
-
1278
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1279
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1280
-    }
1281
-}
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/settings.js js/showsmstables.js js/sendsms.js lib/Controller/SmsrelentlessController.php lib/Controller/AuthorApiController.php lib/Service/SmsrelentlessService.php templates/settings/personal.php lib/Migration/Version125Date20230603224815.php

DoubleBastionAdmin authored on 04/06/2023 00:54:42
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1281 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\IURLGenerator;
49
+use OCP\Share\IManager;
50
+use OCP\Constants;
51
+use OCP\IGroupManager;
52
+use OCP\IDBConnection;
53
+use OCP\IUserManager;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $urlGenerator;
64
+    private $shareManager;
65
+    private $groupManager;
66
+    private $connection;
67
+    private $userManager;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->urlGenerator = $urlGenerator;
78
+	$this->shareManager = $shareManager;
79
+        $this->groupManager = $groupManager;
80
+        $this->connection = $connection;
81
+        $this->userManager = $userManager;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getbalancetel($userId) {
120
+
121
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
+
123
+        $telapikey = $telsmsapicred[0];
124
+        $ch = curl_init();
125
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
+
127
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
+        $responsetel = curl_exec($ch);
131
+        $recdatatel = json_decode($responsetel, TRUE);
132
+        $telbalresponse = $recdatatel['data']['balance'];
133
+        $currentbalancetel = round(floatval($telbalresponse), 3);
134
+        curl_close($ch);
135
+
136
+        return $currentbalancetel;
137
+    }
138
+
139
+
140
+    /**
141
+     * @NoAdminRequired
142
+     */
143
+    public function getbalancenex($userId) {
144
+
145
+        $smsapicred = $this->service->getapicredentials($this->userId);
146
+        $smsapikey = $smsapicred[5];
147
+        $smsapisecret = $smsapicred[6];
148
+
149
+        if ($smsapikey == '' || $smsapisecret == '') {
150
+            $currentbalancenex = "N/A";
151
+        } else {
152
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
+            $mesdata = file_get_contents($getmesdata);
154
+            $datainit = json_decode($mesdata);
155
+            $balancenex = $datainit->cash_credits;
156
+            $currentbalancenex = round(floatval($balancenex), 3);
157
+        }
158
+        return $currentbalancenex;
159
+    }
160
+
161
+
162
+    /**
163
+     * @NoAdminRequired
164
+     */
165
+    public function getbalancetwil($userId) {
166
+
167
+        $smsapicred = $this->service->getapicredentials($this->userId);
168
+        $smsapisid = $smsapicred[15];
169
+        $smsapitoken = $smsapicred[16];
170
+
171
+        if ($smsapisid == '' || $smsapitoken == '') {
172
+            $currentbalancetwil = "N/A";
173
+        } else {
174
+
175
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
+            $balancetwil = $twilbalance->balance;
177
+
178
+            $currentbalancetwil = round(floatval($balancetwil), 3);
179
+        }
180
+        return $currentbalancetwil;
181
+    }
182
+
183
+
184
+    /**
185
+     * @NoAdminRequired
186
+     */
187
+    public function getbalanceflow($userId) {
188
+
189
+        $currentbalanceflow = 'n/a';
190
+
191
+        return $currentbalanceflow;
192
+    }
193
+
194
+
195
+    /**
196
+     * @NoAdminRequired
197
+     */
198
+    public function getsmsnumbers($userId) {
199
+
200
+        $smsapicred = $this->service->getapicredentials($this->userId);
201
+
202
+        $telnyxkey = $smsapicred[0];
203
+
204
+        $nexapikey = $smsapicred[5];
205
+        $nexapisecret = $smsapicred[6];
206
+
207
+        $twilapikey = $smsapicred[15];
208
+        $twilapisecret = $smsapicred[16];
209
+
210
+        $flowapikey = $smsapicred[20];
211
+        $flowapisecret = $smsapicred[21];
212
+
213
+        $telsendernameinit = $smsapicred[9];
214
+        $nexsendernameinit = $smsapicred[10];
215
+        $twilsendernameinit = $smsapicred[19];
216
+
217
+        if ($telsendernameinit) {
218
+            $telsendername = "Tx: " . $telsendernameinit;
219
+            $telsenderarr = [0 => $telsendername];
220
+        } else { $telsenderarr = []; }
221
+
222
+        if ($nexsendernameinit) {
223
+            $nexsendername = "Pl: " . $nexsendernameinit;
224
+            $nexsenderarr = [0 => $nexsendername];
225
+        } else { $nexsenderarr = []; }
226
+
227
+        if ($twilsendernameinit) {
228
+            $twilsendername = "Tw: " . $twilsendernameinit;
229
+            $twilsenderarr = [0 => $twilsendername];
230
+        } else { $twilsenderarr = []; }
231
+
232
+        // Get Telnyx phone numbers
233
+        if ($telnyxkey != '') {
234
+
235
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
236
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
237
+
238
+           $telnumbersarr = $this->object_to_array($telnumbers);
239
+           $telnmbrs = [];
240
+
241
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
242
+              if (is_int($nmbkey)) {
243
+                 foreach ($nmbvalue as $nkey => $nvalue) {
244
+                    if ($nkey == 'phone_number' && $nvalue) {
245
+                       $telnmbrs[] = "Tx: " . $nvalue;
246
+                    }
247
+                 }
248
+              }
249
+           }
250
+
251
+        } else { $telnmbrs = []; }
252
+
253
+        // Get Plivo phone numbers
254
+        if ($nexapikey != '' && $nexapisecret != '') {
255
+
256
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
257
+           $acdata = file_get_contents($getacdata);
258
+           $datainit = json_decode($acdata, true);
259
+
260
+           $findata = $this->object_to_array($datainit);
261
+
262
+           $nexcurrentnmbrs = [];
263
+
264
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
265
+                   if (is_array($smsvalue)) {
266
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
267
+                               if ($smskey2 == 'number' && $smsvalue2) {
268
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
269
+                               }
270
+                         }
271
+                   }
272
+           }
273
+
274
+
275
+        } else { $nexcurrentnmbrs = []; }
276
+
277
+        // Get Twilio phone numbers
278
+        if ($twilapikey != '' && $twilapisecret != '') {
279
+
280
+            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
281
+            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
282
+
283
+            $twilcurrentnmbrs = [];
284
+            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
285
+                 if (is_array($twnbvalue)) {
286
+                     foreach ($twnbvalue as $twfkey => $twfvalue) {
287
+                          if ($twfkey == 'phone_number' && $twfvalue) {
288
+                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
289
+                          }
290
+                     }
291
+                 }
292
+            }
293
+
294
+        } else { $twilcurrentnmbrs = []; }
295
+
296
+        // Get Flowroute phone numbers
297
+        if ($flowapikey != '' && $flowapisecret != '') {
298
+
299
+            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
300
+            $flnbrsarr = $flnbrsresult->data;
301
+            $flowcurrentnmbrs = [];
302
+            foreach ($flnbrsarr as $flkey => $flitem) {
303
+                     if ($flitem->id) {
304
+                         $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
305
+                     }
306
+            }
307
+
308
+        } else { $flowcurrentnmbrs = []; }
309
+
310
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
311
+
312
+        if ($this->groupManager->isAdmin($this->userId)) {
313
+
314
+            return $currentnmbrs;
315
+
316
+        } else {
317
+
318
+            // Get the restrictions from the 'sms_relent_restrict' table
319
+            $getrestr = $this->connection->prepare('
320
+		       SELECT `phone_number`, `groups`, `users` FROM `*PREFIX*sms_relent_restrict`');
321
+            $getrestrres = $getrestr->execute();
322
+
323
+            $restrdata = [];
324
+            while ($restrfetched = $getrestrres->fetch()) {
325
+                   $restrdata[] = $restrfetched;
326
+            }
327
+            $getrestrres->closeCursor();
328
+
329
+            if ($restrdata) {
330
+
331
+                // Get the groups to which the current user belongs
332
+                $usrId = $this->userId;
333
+                $getusrgrp = $this->connection->prepare('
334
+		       SELECT `gid`, `uid` FROM `*PREFIX*group_user` WHERE `uid` = ?');
335
+                $getusrgrpres = $getusrgrp->execute([$usrId]);
336
+
337
+                $usergrps = [];
338
+                while ($fetchedgrps = $getusrgrpres->fetch()) {
339
+                       $usergrps[] = $fetchedgrps['gid'];
340
+                }
341
+                $getusrgrpres->closeCursor();
342
+                $ctusergroups = implode("|", $usergrps);
343
+
344
+		// Get the Display Name of the current user
345
+		$getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
346
+		$getacdatadnres = $getacdatadn->execute([$usrId, 'displayname']);
347
+		$acdatausrdnadm = $getacdatadnres->fetch();
348
+		$cruserdname = $acdatausrdnadm['value'];
349
+		$getacdatadnres->closeCursor();
350
+
351
+                // Get the phone numbers that are not allowed for the current user
352
+                $restrPhoneNb = [];
353
+                foreach ($restrdata as $rskey => $rsvalue) {
354
+
355
+                        $chck = 0;
356
+                        if ($rsvalue['groups']) {
357
+                            $restrgrparr = explode("|", $rsvalue['groups']);
358
+
359
+                            foreach ($restrgrparr as $grkey => $grvalue) {
360
+                                     if (str_contains($ctusergroups, $grvalue)) { $chck++; }
361
+                            }
362
+                        }
363
+
364
+                        if ($rsvalue['users']) {
365
+                            $usrnmstr = $rsvalue['users'];
366
+                            if (str_contains($usrnmstr, $cruserdname)) { $chck++; }
367
+                        }
368
+
369
+                        if ($chck == 0) { $restrPhoneNb[] = $rsvalue['phone_number']; }
370
+                }
371
+
372
+                $restrPhoneNmbrs = array_unique($restrPhoneNb);
373
+
374
+                // Assemble the array of phone numbers that the current user is allowed to use
375
+                for ($k = 0; $k < count($currentnmbrs); $k++) {
376
+
377
+                    if (in_array($currentnmbrs[$k], $restrPhoneNmbrs)) {
378
+                        unset($currentnmbrs[$k]);
379
+                    }
380
+                }
381
+
382
+                $currentnmbrsrstr = array_values($currentnmbrs);
383
+
384
+                return $currentnmbrsrstr;
385
+
386
+            } else { return $currentnmbrs; }
387
+        }
388
+    }
389
+
390
+
391
+    /**
392
+     * @NoAdminRequired
393
+     */
394
+    public function cleantempdir($userId) {
395
+
396
+        // Create the temporary folder if it doesn't exist
397
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
398
+            $this->folder->newFolder('SMS_Relentless/temp_files');
399
+        }
400
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
401
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
402
+        $fileSystemIterator = new FilesystemIterator($targetdir);
403
+
404
+        $dirfiles = [];
405
+        foreach ($fileSystemIterator as $fileInfo){
406
+                 $dirfiles[] = $fileInfo->getFilename();
407
+        }
408
+
409
+        foreach ($dirfiles as $key => $indfile) {
410
+                 $thisuserroot = $this->view->getRoot();
411
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
412
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
413
+        }
414
+     }
415
+
416
+
417
+    /**
418
+     * @NoAdminRequired
419
+     */
420
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
421
+
422
+        // Create the temporary folder if it doesn't exist
423
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
424
+            $this->folder->newFolder('SMS_Relentless/temp_files');
425
+        }
426
+
427
+        // First delete any file that has been previously uploaded
428
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
429
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
430
+        $fileSystemIterator = new FilesystemIterator($targetdir);
431
+
432
+        $dirfiles = [];
433
+        foreach ($fileSystemIterator as $fileInfo){
434
+                 $dirfiles[] = $fileInfo->getFilename();
435
+        }
436
+
437
+        foreach ($dirfiles as $key => $indfile) {
438
+                 $thisuserroot = $this->view->getRoot();
439
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
440
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
441
+        }
442
+
443
+        // Upload the new file
444
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
445
+        $fileName = $_FILES['uploadfileforsms']['name'];
446
+
447
+        $userroot = $this->view->getRoot();
448
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
449
+
450
+        $target = $this->folder->newFile($targetfile);
451
+        $target->putContent($fileContent);
452
+
453
+        // Extract the phone numbers from the file
454
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
455
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
456
+        $numberarrayfourth = explode(",", $numberarraytert);
457
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
458
+        $numberarray = array_unique($numberarrayfifth);
459
+
460
+        return $numberarray;
461
+    }
462
+
463
+
464
+    /**
465
+     * @NoAdminRequired
466
+     */
467
+    public function uploadfile($uploadfileformms) {
468
+
469
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
470
+           $fileName = $_FILES['uploadfileformms']['name'];
471
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
472
+           $fileSize = $fileSizeinit / 1024;
473
+
474
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
475
+               $this->folder->newFolder('SMS_Relentless/temp_files');
476
+           }
477
+
478
+           $userroot = $this->view->getRoot();
479
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
480
+
481
+           $target = $this->folder->newFile($targetfile);
482
+           $target->putContent($fileContent);
483
+
484
+           // Get the cumulative files size of the uploaded files
485
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
486
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
487
+
488
+           $fileSystemIterator = new FilesystemIterator($targetdir);
489
+
490
+           $dirfiles = [];
491
+           foreach ($fileSystemIterator as $fileInfo){
492
+                    $dirfiles[] = $fileInfo->getFilename();
493
+           }
494
+
495
+           $totalflsizeinit = 0;
496
+           foreach ($dirfiles as $key => $indfile) {
497
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
498
+                    $mbSize = round($fileSizeinit / 1024, 4);
499
+                    $totalflsizeinit += $mbSize;
500
+           }
501
+
502
+           $totalflsize = round($totalflsizeinit, 4);
503
+
504
+           return $totalflsize;
505
+    }
506
+
507
+
508
+    /**
509
+     * @NoAdminRequired
510
+     */
511
+    public function pickfile($path) {
512
+
513
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
514
+               $this->folder->newFolder('SMS_Relentless/temp_files');
515
+           }
516
+
517
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
518
+
519
+           $fltgt = $datadir . $this->userId . "/files" . $path;
520
+
521
+           $fileContent = file_get_contents($fltgt);
522
+
523
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
524
+
525
+           $patharr = explode("/", $path);
526
+
527
+           $revarr = array_reverse($patharr);
528
+
529
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
530
+
531
+           $target = $this->folder->newFile($relflpath);
532
+
533
+           $target->putContent($fileContent);
534
+
535
+           // Get the cumulative files size of the uploaded files
536
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
537
+
538
+           $fileSystemIterator = new FilesystemIterator($targetdir);
539
+
540
+           $dirfiles = [];
541
+           foreach ($fileSystemIterator as $fileInfo) {
542
+                    $dirfiles[] = $fileInfo->getFilename();
543
+           }
544
+
545
+           $totalflsizeinit = 0;
546
+
547
+           foreach ($dirfiles as $key => $indfile) {
548
+
549
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
550
+                    $mbSize = round($fileSizeinit / 1024, 4);
551
+                    $totalflsizeinit += $mbSize;
552
+           }
553
+
554
+           $totalflsize = round($totalflsizeinit, 4);
555
+
556
+           $pickresult = [$totalflsize, $pkfilesize];
557
+
558
+           return $pickresult;
559
+    }
560
+
561
+
562
+    /**
563
+     * @NoAdminRequired
564
+     */
565
+    public function removeupfile($removedfilename) {
566
+
567
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
568
+
569
+           $removefile = $this->view->unlink($tmpfl);
570
+
571
+           // Get the cumulative files size of the uploaded files
572
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
573
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
574
+           $fileSystemIterator = new FilesystemIterator($targetdir);
575
+
576
+           $dirfiles = [];
577
+           foreach ($fileSystemIterator as $fileInfo){
578
+                    $dirfiles[] = $fileInfo->getFilename();
579
+           }
580
+
581
+           $totalflsizeinit = 0;
582
+
583
+           foreach ($dirfiles as $key => $indfile) {
584
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
585
+                    $mbSize = round($fileSizeinit / 1024, 4);
586
+                    $totalflsizeinit += $mbSize;
587
+           }
588
+
589
+           $totalflsize = round($totalflsizeinit, 4);
590
+
591
+           return $totalflsize;
592
+    }
593
+
594
+
595
+    /**
596
+     * @NoAdminRequired
597
+     */
598
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
599
+
600
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
601
+         $telnyxkey = $telsmsapicred[0];
602
+         $teldelrecurl = $telsmsapicred[3];
603
+         $messagingprofid = $telsmsapicred[4];
604
+         $addDisplName = $telsmsapicred[24];
605
+
606
+         // Get the Display Name of the current user
607
+         $crtuser = $this->userManager->get($this->userId);
608
+         $displayname = $crtuser->getDisplayName();
609
+
610
+         if ($addDisplName == 1) {
611
+             $sentsmstext = $displayname . ": " . $sentsmstext;
612
+         }
613
+
614
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
615
+
616
+         $microinterval = $waitinterval * 1000;
617
+
618
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
619
+
620
+             usleep($microinterval);
621
+
622
+             $messagedate = date("Y-m-d H:i:s");
623
+
624
+             if ($ismms == 0) {
625
+
626
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
627
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
628
+                 } else {
629
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
630
+                 }
631
+
632
+                 $messagetexttel = $sentsmstext;
633
+
634
+             } else {
635
+
636
+                 $mediaURLarr = [];
637
+                 $includedMediaFiles = '';
638
+
639
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
640
+
641
+                      $userroot = $this->view->getRoot();
642
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
643
+
644
+                      $flsharetarget = $this->folder->newFile($filetoshare);
645
+
646
+	              $share = $this->shareManager->newShare();
647
+	              $share->setNode($flsharetarget);
648
+	              $share->setPermissions(Constants::PERMISSION_READ);
649
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
650
+	              $share->setSharedBy($this->userId);
651
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
652
+                      $expirydate->add(new \DateInterval('P1D'));
653
+                      $share->setExpirationDate($expirydate);
654
+                      $shared = $this->shareManager->createShare($share);
655
+                      $shareToken = $shared->getToken();
656
+
657
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
658
+
659
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
660
+
661
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
662
+                 }
663
+
664
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
665
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
666
+                 } else {
667
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
668
+                 }
669
+
670
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
671
+             }
672
+
673
+             $messageid = $message['id'];
674
+             $messagefrom = "Telnyx: " . $fromsender;
675
+             $messageto = $tonumber;
676
+             $messagenetwork = null;
677
+             $messageprice = null;
678
+             $messagestatus = $message['to'][0]['status'];
679
+             $messagedelivery = null;
680
+
681
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
682
+
683
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
684
+         }
685
+         return $displayname;
686
+    }
687
+
688
+
689
+    /**
690
+     * @NoAdminRequired
691
+     */
692
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
693
+
694
+         $plsmsapicred = $this->service->getapicredentials($this->userId);
695
+
696
+         $smsapikey = $plsmsapicred[5];
697
+         $smsapisecret = $plsmsapicred[6];
698
+         $smsapideliveryrecurl = $plsmsapicred[8];
699
+         $addDisplName = $plsmsapicred[24];
700
+
701
+         // Get the Display Name of the current user
702
+         $crtuser = $this->userManager->get($this->userId);
703
+         $displayname = $crtuser->getDisplayName();
704
+
705
+         if ($addDisplName == 1) {
706
+             $sentsmstext = $displayname . ": " . $sentsmstext;
707
+         }
708
+
709
+         $microinterval = $waitinterval * 1000;
710
+
711
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
712
+
713
+             usleep($microinterval);
714
+
715
+             $messagedatepl = date("Y-m-d H:i:s");
716
+
717
+             if ($ismms == 0) {
718
+
719
+                 $client = new RestClient($smsapikey, $smsapisecret);
720
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
721
+                 $messagetextpl = $sentsmstext;
722
+	         $messageidinit = $response->getmessageUuid(0);
723
+                 $messageid = $messageidinit[0];
724
+
725
+                 if (property_exists($response, 'error')) { 
726
+                     $messagestatus = "Error: " . $response->error;
727
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
728
+
729
+             } else {
730
+
731
+                 $mediaURLarr = [];
732
+                 $includedMediaFiles = '';
733
+
734
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
735
+
736
+                      $userroot = $this->view->getRoot();
737
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
738
+
739
+                      $flsharetarget = $this->folder->newFile($filetoshare);
740
+
741
+	              $share = $this->shareManager->newShare();
742
+	              $share->setNode($flsharetarget);
743
+	              $share->setPermissions(Constants::PERMISSION_READ);
744
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
745
+	              $share->setSharedBy($this->userId);
746
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
747
+                      $expirydate->add(new \DateInterval('P1D'));
748
+                      $share->setExpirationDate($expirydate);
749
+                      $shared = $this->shareManager->createShare($share);
750
+                      $shareToken = $shared->getToken();
751
+
752
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
753
+
754
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
755
+
756
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
757
+                 }
758
+
759
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
760
+		 $postedparamspl = json_encode($datatosendpl);
761
+
762
+		 $chpl = curl_init();
763
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
764
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
765
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
766
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
767
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
768
+		 curl_setopt($chpl, CURLOPT_POST, 1);
769
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
770
+		 $resultpl = curl_exec ($chpl);
771
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
772
+		 curl_close ($chpl);
773
+
774
+		 $decresultpl = json_decode($resultpl);
775
+
776
+                 if ($decresultpl) {
777
+                     if (property_exists($decresultpl, 'message_uuid')) {
778
+                         $messageidinit = $decresultpl->message_uuid;
779
+                         $messageid = $messageidinit[0];
780
+                     } else { $messageid = 'n/a'; }
781
+                 } else { $messageid = 'n/a'; }
782
+
783
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
784
+
785
+                     if (property_exists($decresultpl, 'error')) {
786
+                         $messagestatus = "Error: " . $decresultpl->error;
787
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
788
+
789
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
790
+
791
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
792
+             }
793
+
794
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
795
+                 $messagefrom = "Plivo: " . $fromsender;
796
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
797
+
798
+             $messageto = $tonumber;
799
+             $messagenetwork = '';
800
+             $messageprice = '';
801
+
802
+             $messagedelivery = '';
803
+
804
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
805
+
806
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
807
+         }
808
+         return $displayname;
809
+    }
810
+
811
+
812
+    /**
813
+     * @NoAdminRequired
814
+     */
815
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
816
+
817
+         $twsmsapicred = $this->service->getapicredentials($this->userId);
818
+
819
+         $sid = $twsmsapicred[15];
820
+         $token = $twsmsapicred[16];
821
+         $smsapirecurltw = $twsmsapicred[18];
822
+         $addDisplName = $twsmsapicred[24];
823
+
824
+         // Get the Display Name of the current user
825
+         $crtuser = $this->userManager->get($this->userId);
826
+         $displayname = $crtuser->getDisplayName();
827
+
828
+         if ($addDisplName == 1) {
829
+             $sentsmstext = $displayname . ": " . $sentsmstext;
830
+         }
831
+
832
+         $microinterval = $waitinterval * 1000;
833
+
834
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
835
+
836
+             usleep($microinterval);
837
+
838
+             $messagedatetw = date("Y-m-d H:i:s");
839
+
840
+             if ($ismms == 0) {
841
+
842
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
843
+                 $sentsmstextfintw = $sentsmstext;
844
+
845
+             } else {
846
+
847
+                 $mediaURLs = [];
848
+                 $includedMediaFiles = '';
849
+
850
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
851
+
852
+                      $userroot = $this->view->getRoot();
853
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
854
+
855
+                      $flsharetarget = $this->folder->newFile($filetoshare);
856
+
857
+	              $share = $this->shareManager->newShare();
858
+	              $share->setNode($flsharetarget);
859
+	              $share->setPermissions(Constants::PERMISSION_READ);
860
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
861
+	              $share->setSharedBy($this->userId);
862
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
863
+                      $expirydate->add(new \DateInterval('P1D'));
864
+                      $share->setExpirationDate($expirydate);
865
+                      $shared = $this->shareManager->createShare($share);
866
+                      $shareToken = $shared->getToken();
867
+
868
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
869
+
870
+                      $mediaURLs[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
871
+
872
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
873
+                 }
874
+
875
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
876
+
877
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
878
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
879
+                 }
880
+
881
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
882
+             }
883
+
884
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
885
+
886
+	     $chtw = curl_init();
887
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
888
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
889
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
890
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
891
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
892
+	     curl_setopt($chtw, CURLOPT_POST, 1);
893
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
894
+
895
+	     $resulttw = curl_exec ($chtw);
896
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
897
+	     curl_close ($chtw);
898
+
899
+             $decresulttw = json_decode($resulttw);
900
+
901
+             if ($decresulttw) {
902
+                 if (property_exists($decresulttw, 'sid')) { $messageidtw = $decresulttw->sid; } else { $messageidtw = 'n/a'; }
903
+             } else { $messageidtw = 'n/a'; }
904
+
905
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
906
+                 $messagestatustw = 'The message has been accepted for delivery.';
907
+             } else {
908
+                 $messagestatustw = 'An error occurred while trying to send the message.';
909
+             }
910
+
911
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
912
+                 $messagefromtw = "Twilio: " . $fromsender;
913
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
914
+
915
+             $messagenetworktw = '';
916
+             $messagepricetw = '';
917
+             $messagedeliverytw = '';
918
+
919
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
920
+
921
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
922
+         }
923
+         return $displayname;
924
+    }
925
+
926
+
927
+    /**
928
+     * @NoAdminRequired
929
+     */
930
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
931
+
932
+         $flsmsapicred = $this->service->getapicredentials($this->userId);
933
+
934
+         $flowapikey = $flsmsapicred[20];
935
+         $flowapisecret = $flsmsapicred[21];
936
+         $flowdelrecurl = $flsmsapicred[23];
937
+         $addDisplName = $flsmsapicred[24];
938
+
939
+         // Get the Display Name of the current user
940
+         $crtuser = $this->userManager->get($this->userId);
941
+         $displayname = $crtuser->getDisplayName();
942
+
943
+         if ($addDisplName == 1) {
944
+             $sentsmstext = $displayname . ": " . $sentsmstext;
945
+         }
946
+
947
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
948
+
949
+         $microinterval = $waitinterval * 1000;
950
+
951
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
952
+
953
+             usleep($microinterval);
954
+
955
+             $messagedatefl = date("Y-m-d H:i:s");
956
+
957
+             if ($ismms == 0) {
958
+
959
+                 $messagetextfinfl = $sentsmstext;
960
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
961
+
962
+             } else {
963
+
964
+		 $mediaurlsarr = [];
965
+		 $includedMediaFiles = '';
966
+
967
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
968
+
969
+		      $userroot = $this->view->getRoot();
970
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
971
+
972
+		      $flsharetarget = $this->folder->newFile($filetoshare);
973
+
974
+		      $share = $this->shareManager->newShare();
975
+		      $share->setNode($flsharetarget);
976
+		      $share->setPermissions(Constants::PERMISSION_READ);
977
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
978
+		      $share->setSharedBy($this->userId);
979
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
980
+                      $expirydate->add(new \DateInterval('P1D'));
981
+                      $share->setExpirationDate($expirydate);
982
+		      $shared = $this->shareManager->createShare($share);
983
+		      $shareToken = $shared->getToken();
984
+
985
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
986
+
987
+		      $mediaurlsarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p];
988
+
989
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . mt_rand(1, 10000) . "' class='mmstblUrls' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
990
+		 }
991
+
992
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
993
+
994
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
995
+             }
996
+
997
+	     $chfl = curl_init();
998
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
999
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
1000
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
1001
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
1002
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
1003
+	     curl_setopt($chfl, CURLOPT_POST, 1);
1004
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
1005
+	     $resultfl = curl_exec ($chfl);
1006
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
1007
+	     curl_close ($chfl);
1008
+
1009
+             $decresultfl = json_decode($resultfl);
1010
+
1011
+             if ($decresultfl) {
1012
+                 if (property_exists($decresultfl, 'data')) { 
1013
+                     $messageidfl = $decresultfl->data->id;
1014
+                 } else { $messageidfl = 'n/a'; }
1015
+             } else { $messageidfl = 'n/a'; }
1016
+
1017
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
1018
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
1019
+             } else { 
1020
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
1021
+             }
1022
+
1023
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
1024
+                 $messagefromfl = "Flowroute: " . $fromsender;
1025
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
1026
+
1027
+             $messagetofl = $tonumberfl;
1028
+             $messagenetworkfl = '';
1029
+             $messagepricefl = '';
1030
+             $messagedeliveryfl = '';
1031
+
1032
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
1033
+
1034
+             $this->service->insertsentsms($this->userId, $displayname, $sentmessagearr);
1035
+         }
1036
+         return $displayname;
1037
+    }
1038
+
1039
+
1040
+    /**
1041
+     * @NoAdminRequired
1042
+     */
1043
+    public function saveoldrecrows($userId, $oldrecRows) {
1044
+
1045
+           // Create the folder for removed messages if it doesn't exist
1046
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
1047
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
1048
+           }
1049
+           $savecheck = 0;
1050
+
1051
+           if (count($oldrecRows) > 1) {
1052
+               $msfileContent = implode("", $oldrecRows);
1053
+
1054
+               $delrowsdate = date("Y-m-d_H-i-s");
1055
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
1056
+
1057
+               $userroot = $this->view->getRoot();
1058
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
1059
+
1060
+               $target = $this->folder->newFile($targetfile);
1061
+               $target->putContent($msfileContent);
1062
+
1063
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
1064
+                   $savecheck = 1;
1065
+               }
1066
+           }
1067
+
1068
+           return $savecheck;
1069
+    }
1070
+
1071
+
1072
+    /**
1073
+     * @NoAdminRequired
1074
+     */
1075
+    public function saveoldsentrows($userId, $oldsentRows) {
1076
+
1077
+           // Create the folder for removed messages if it doesn't exist
1078
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
1079
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
1080
+           }
1081
+           $savesentcheck = 0;
1082
+
1083
+           if (count($oldsentRows) > 1) {
1084
+               $sntfileContent = implode("", $oldsentRows);
1085
+
1086
+               $delsentrowsdate = date("Y-m-d_H-i-s");
1087
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
1088
+
1089
+               $userroot = $this->view->getRoot();
1090
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
1091
+
1092
+               $snttarget = $this->folder->newFile($snttargetfile);
1093
+               $snttarget->putContent($sntfileContent);
1094
+
1095
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
1096
+                   $savesentcheck = 1;
1097
+               }
1098
+           }
1099
+
1100
+           return $savesentcheck;
1101
+    }
1102
+
1103
+
1104
+    /**
1105
+     * @NoAdminRequired
1106
+     */
1107
+    public function getreceivedtable($userId) {
1108
+           return $this->service->getreceivedtable($this->userId);
1109
+    }
1110
+
1111
+    /**
1112
+     * @NoAdminRequired
1113
+     */
1114
+    public function getreceivedtablefordel($userId) {
1115
+           return $this->service->getreceivedtablefordel($this->userId);
1116
+    }
1117
+
1118
+    /**
1119
+     * @NoAdminRequired
1120
+     */
1121
+    public function removerecrows($userId, $recmessagedbIDs) {
1122
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
1123
+    }
1124
+
1125
+    /**
1126
+     * @NoAdminRequired
1127
+     */
1128
+    public function getsenttable($userId) {
1129
+           return $this->service->getsenttable($this->userId);
1130
+    }
1131
+
1132
+    /**
1133
+     * @NoAdminRequired
1134
+     */
1135
+    public function getsenttablefordel($userId) {
1136
+           return $this->service->getsenttablefordel($this->userId);
1137
+    }
1138
+
1139
+    /**
1140
+     * @NoAdminRequired
1141
+     */
1142
+    public function removesentrows($userId, $sentmessagedbIDs) {
1143
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1144
+    }
1145
+
1146
+    /**
1147
+     * @NoAdminRequired
1148
+     */
1149
+    public function getgroupedtable($userId) {
1150
+           return $this->service->getgroupedtable($this->userId);
1151
+    }
1152
+
1153
+    /**
1154
+     * @NoAdminRequired
1155
+     */
1156
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1157
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1158
+    }
1159
+
1160
+    /**
1161
+     * @NoAdminRequired
1162
+     */
1163
+    public function getmessagesperpage($userId) {
1164
+           return $this->service->getmessagesperpage($this->userId);
1165
+    }
1166
+
1167
+    /**
1168
+     * @NoAdminRequired
1169
+     */
1170
+    public function getdelrecsettings($userId) {
1171
+           return $this->service->getdelrecsettings($this->userId);
1172
+    }
1173
+
1174
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1175
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1176
+    }
1177
+
1178
+    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1179
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1180
+    }
1181
+
1182
+    public function removenumberrestrictions($userId, $phoneNumber) {
1183
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1184
+    }
1185
+
1186
+    /**
1187
+     * @NoAdminRequired
1188
+     */
1189
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1190
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1191
+    }
1192
+
1193
+    /**
1194
+     * @NoAdminRequired
1195
+     */
1196
+    public function removeautoreplies($userId, $phoneNumber) {
1197
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1198
+    }
1199
+
1200
+    /**
1201
+     * @NoAdminRequired
1202
+     */
1203
+    public function getsettings($userId) {
1204
+           return $this->service->getsettings($this->userId);
1205
+    }
1206
+
1207
+    public function getadminsettings($userId) {
1208
+           return $this->service->getadminsettings($this->userId);
1209
+    }
1210
+
1211
+    /**
1212
+     * @NoAdminRequired
1213
+     */
1214
+    public function getautoreplyconf($userId) {
1215
+
1216
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1217
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1218
+
1219
+           // Get the display name of the current user
1220
+           $usrid = $this->userId;
1221
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1222
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1223
+	   $getusrdnmdata = $getusrdnmres->fetch();
1224
+	   $userDisplayNm = $getusrdnmdata['value'];
1225
+	   $getusrdnmres->closeCursor();
1226
+
1227
+           // Get the auto-replies for the available phone numbers
1228
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1229
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1230
+	   $getautorplres = $getautorpl->execute();
1231
+           $autorplconf = [];
1232
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1233
+                  $autorplconf[] = $acdatausrdnadm;
1234
+           }
1235
+	   $getautorplres->closeCursor();
1236
+
1237
+           if ($autorplconf) {
1238
+
1239
+               $autoreplyconf = [];
1240
+               foreach ($autorplconf as $arkey => $arvalue) {
1241
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1242
+                            $autoreplyconf[] = $arvalue;
1243
+                        }
1244
+               }
1245
+
1246
+           } else { $autoreplyconf = ''; }
1247
+
1248
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1249
+
1250
+           return $autoreplyfdb;
1251
+    }
1252
+
1253
+    /**
1254
+     * @NoAdminRequired
1255
+     */
1256
+    public function getgroupedpernumber($userId, $phoneNumber) {
1257
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1258
+    }
1259
+
1260
+    /**
1261
+     * @NoAdminRequired
1262
+     */
1263
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1264
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1265
+    }
1266
+
1267
+    /**
1268
+     * @NoAdminRequired
1269
+     */
1270
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1271
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1272
+    }
1273
+
1274
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1275
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1276
+    }
1277
+
1278
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames) {
1279
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames, $addDisplayNames);
1280
+    }
1281
+}
Browse code

CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/settings.js js/showsmstables.js js/sendsms.js lib/Controller/SmsrelentlessController.php lib/Controller/AuthorApiController.php lib/Service/SmsrelentlessService.php templates/settings/personal.php

DoubleBastionAdmin authored on 04/06/2023 00:49:12
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1260 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\IURLGenerator;
49
-use OCP\Share\IManager;
50
-use OCP\Constants;
51
-use OCP\IGroupManager;
52
-use OCP\IDBConnection;
53
-use OCP\IUserManager;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $urlGenerator;
64
-    private $shareManager;
65
-    private $groupManager;
66
-    private $connection;
67
-    private $userManager;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->urlGenerator = $urlGenerator;
78
-	$this->shareManager = $shareManager;
79
-        $this->groupManager = $groupManager;
80
-        $this->connection = $connection;
81
-        $this->userManager = $userManager;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getbalancetel($userId) {
120
-
121
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
-
123
-        $telapikey = $telsmsapicred[0];
124
-        $ch = curl_init();
125
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
-
127
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
-        $responsetel = curl_exec($ch);
131
-        $recdatatel = json_decode($responsetel, TRUE);
132
-        $telbalresponse = $recdatatel['data']['balance'];
133
-        $currentbalancetel = round(floatval($telbalresponse), 3);
134
-        curl_close($ch);
135
-
136
-        return $currentbalancetel;
137
-    }
138
-
139
-
140
-    /**
141
-     * @NoAdminRequired
142
-     */
143
-    public function getbalancenex($userId) {
144
-
145
-        $smsapicred = $this->service->getapicredentials($this->userId);
146
-        $smsapikey = $smsapicred[5];
147
-        $smsapisecret = $smsapicred[6];
148
-
149
-        if ($smsapikey == '' || $smsapisecret == '') {
150
-            $currentbalancenex = "N/A";
151
-        } else {
152
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
-            $mesdata = file_get_contents($getmesdata);
154
-            $datainit = json_decode($mesdata);
155
-            $balancenex = $datainit->cash_credits;
156
-            $currentbalancenex = round(floatval($balancenex), 3);
157
-        }
158
-        return $currentbalancenex;
159
-    }
160
-
161
-
162
-    /**
163
-     * @NoAdminRequired
164
-     */
165
-    public function getbalancetwil($userId) {
166
-
167
-        $smsapicred = $this->service->getapicredentials($this->userId);
168
-        $smsapisid = $smsapicred[15];
169
-        $smsapitoken = $smsapicred[16];
170
-
171
-        if ($smsapisid == '' || $smsapitoken == '') {
172
-            $currentbalancetwil = "N/A";
173
-        } else {
174
-
175
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
-            $balancetwil = $twilbalance->balance;
177
-
178
-            $currentbalancetwil = round(floatval($balancetwil), 3);
179
-        }
180
-        return $currentbalancetwil;
181
-    }
182
-
183
-
184
-    /**
185
-     * @NoAdminRequired
186
-     */
187
-    public function getbalanceflow($userId) {
188
-
189
-        $currentbalanceflow = 'n/a';
190
-
191
-        return $currentbalanceflow;
192
-    }
193
-
194
-
195
-    /**
196
-     * @NoAdminRequired
197
-     */
198
-    public function getsmsnumbers($userId) {
199
-
200
-        $smsapicred = $this->service->getapicredentials($this->userId);
201
-
202
-        $telnyxkey = $smsapicred[0];
203
-
204
-        $nexapikey = $smsapicred[5];
205
-        $nexapisecret = $smsapicred[6];
206
-
207
-        $twilapikey = $smsapicred[15];
208
-        $twilapisecret = $smsapicred[16];
209
-
210
-        $flowapikey = $smsapicred[20];
211
-        $flowapisecret = $smsapicred[21];
212
-
213
-        $telsendernameinit = $smsapicred[9];
214
-        $nexsendernameinit = $smsapicred[10];
215
-        $twilsendernameinit = $smsapicred[19];
216
-
217
-        if ($telsendernameinit) {
218
-            $telsendername = "Tx: " . $telsendernameinit;
219
-            $telsenderarr = [0 => $telsendername];
220
-        } else { $telsenderarr = []; }
221
-
222
-        if ($nexsendernameinit) {
223
-            $nexsendername = "Pl: " . $nexsendernameinit;
224
-            $nexsenderarr = [0 => $nexsendername];
225
-        } else { $nexsenderarr = []; }
226
-
227
-        if ($twilsendernameinit) {
228
-            $twilsendername = "Tw: " . $twilsendernameinit;
229
-            $twilsenderarr = [0 => $twilsendername];
230
-        } else { $twilsenderarr = []; }
231
-
232
-        // Get Telnyx phone numbers
233
-        if ($telnyxkey != '') {
234
-
235
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
236
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
237
-
238
-           $telnumbersarr = $this->object_to_array($telnumbers);
239
-           $telnmbrs = [];
240
-
241
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
242
-              if (is_int($nmbkey)) {
243
-                 foreach ($nmbvalue as $nkey => $nvalue) {
244
-                    if ($nkey == 'phone_number' && $nvalue) {
245
-                       $telnmbrs[] = "Tx: " . $nvalue;
246
-                    }
247
-                 }
248
-              }
249
-           }
250
-
251
-        } else { $telnmbrs = []; }
252
-
253
-        // Get Plivo phone numbers
254
-        if ($nexapikey != '' && $nexapisecret != '') {
255
-
256
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
257
-           $acdata = file_get_contents($getacdata);
258
-           $datainit = json_decode($acdata, true);
259
-
260
-           $findata = $this->object_to_array($datainit);
261
-
262
-           $nexcurrentnmbrs = [];
263
-
264
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
265
-                   if (is_array($smsvalue)) {
266
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
267
-                               if ($smskey2 == 'number' && $smsvalue2) {
268
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
269
-                               }
270
-                         }
271
-                   }
272
-           }
273
-
274
-
275
-        } else { $nexcurrentnmbrs = []; }
276
-
277
-        // Get Twilio phone numbers
278
-        if ($twilapikey != '' && $twilapisecret != '') {
279
-
280
-            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
281
-            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
282
-
283
-            $twilcurrentnmbrs = [];
284
-            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
285
-                 if (is_array($twnbvalue)) {
286
-                     foreach ($twnbvalue as $twfkey => $twfvalue) {
287
-                          if ($twfkey == 'phone_number' && $twfvalue) {
288
-                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
289
-                          }
290
-                     }
291
-                 }
292
-            }
293
-
294
-        } else { $twilcurrentnmbrs = []; }
295
-
296
-        // Get Flowroute phone numbers
297
-        if ($flowapikey != '' && $flowapisecret != '') {
298
-
299
-            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
300
-            $flnbrsarr = $flnbrsresult->data;
301
-            $flowcurrentnmbrs = [];
302
-            foreach ($flnbrsarr as $flkey => $flitem) {
303
-                     if ($flitem->id) {
304
-                         $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
305
-                     }
306
-            }
307
-
308
-        } else { $flowcurrentnmbrs = []; }
309
-
310
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
311
-
312
-        if ($this->groupManager->isAdmin($this->userId)) {
313
-
314
-            return $currentnmbrs;
315
-
316
-        } else {
317
-
318
-            // Get the restrictions from the 'sms_relent_restrict' table
319
-            $getrestr = $this->connection->prepare('
320
-		       SELECT `phone_number`, `groups`, `users` FROM `*PREFIX*sms_relent_restrict`');
321
-            $getrestrres = $getrestr->execute();
322
-
323
-            $restrdata = [];
324
-            while ($restrfetched = $getrestrres->fetch()) {
325
-                   $restrdata[] = $restrfetched;
326
-            }
327
-            $getrestrres->closeCursor();
328
-
329
-            if ($restrdata) {
330
-
331
-                // Get the groups to which the current user belongs
332
-                $usrId = $this->userId;
333
-                $getusrgrp = $this->connection->prepare('
334
-		       SELECT `gid`, `uid` FROM `*PREFIX*group_user` WHERE `uid` = ?');
335
-                $getusrgrpres = $getusrgrp->execute([$usrId]);
336
-
337
-                $usergrps = [];
338
-                while ($fetchedgrps = $getusrgrpres->fetch()) {
339
-                       $usergrps[] = $fetchedgrps['gid'];
340
-                }
341
-                $getusrgrpres->closeCursor();
342
-                $ctusergroups = implode("|", $usergrps);
343
-
344
-		// Get the Display Name of the current user
345
-		$getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
346
-		$getacdatadnres = $getacdatadn->execute([$usrId, 'displayname']);
347
-		$acdatausrdnadm = $getacdatadnres->fetch();
348
-		$cruserdname = $acdatausrdnadm['value'];
349
-		$getacdatadnres->closeCursor();
350
-
351
-                // Get the phone numbers that are not allowed for the current user
352
-                $restrPhoneNb = [];
353
-                foreach ($restrdata as $rskey => $rsvalue) {
354
-
355
-                        $chck = 0;
356
-                        if ($rsvalue['groups']) {
357
-                            $restrgrparr = explode("|", $rsvalue['groups']);
358
-
359
-                            foreach ($restrgrparr as $grkey => $grvalue) {
360
-                                     if (str_contains($ctusergroups, $grvalue)) { $chck++; }
361
-                            }
362
-                        }
363
-
364
-                        if ($rsvalue['users']) {
365
-                            $usrnmstr = $rsvalue['users'];
366
-                            if (str_contains($usrnmstr, $cruserdname)) { $chck++; }
367
-                        }
368
-
369
-                        if ($chck == 0) { $restrPhoneNb[] = $rsvalue['phone_number']; }
370
-                }
371
-
372
-                $restrPhoneNmbrs = array_unique($restrPhoneNb);
373
-
374
-                // Assemble the array of phone numbers that the current user is allowed to use
375
-                for ($k = 0; $k < count($currentnmbrs); $k++) {
376
-
377
-                    if (in_array($currentnmbrs[$k], $restrPhoneNmbrs)) {
378
-                        unset($currentnmbrs[$k]);
379
-                    }
380
-                }
381
-
382
-                $currentnmbrsrstr = array_values($currentnmbrs);
383
-
384
-                return $currentnmbrsrstr;
385
-
386
-            } else { return $currentnmbrs; }
387
-        }
388
-    }
389
-
390
-
391
-    /**
392
-     * @NoAdminRequired
393
-     */
394
-    public function cleantempdir($userId) {
395
-
396
-        // Create the temporary folder if it doesn't exist
397
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
398
-            $this->folder->newFolder('SMS_Relentless/temp_files');
399
-        }
400
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
401
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
402
-        $fileSystemIterator = new FilesystemIterator($targetdir);
403
-
404
-        $dirfiles = [];
405
-        foreach ($fileSystemIterator as $fileInfo){
406
-                 $dirfiles[] = $fileInfo->getFilename();
407
-        }
408
-
409
-        foreach ($dirfiles as $key => $indfile) {
410
-                 $thisuserroot = $this->view->getRoot();
411
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
412
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
413
-        }
414
-     }
415
-
416
-
417
-    /**
418
-     * @NoAdminRequired
419
-     */
420
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
421
-
422
-        // Create the temporary folder if it doesn't exist
423
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
424
-            $this->folder->newFolder('SMS_Relentless/temp_files');
425
-        }
426
-
427
-        // First delete any file that has been previously uploaded
428
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
429
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
430
-        $fileSystemIterator = new FilesystemIterator($targetdir);
431
-
432
-        $dirfiles = [];
433
-        foreach ($fileSystemIterator as $fileInfo){
434
-                 $dirfiles[] = $fileInfo->getFilename();
435
-        }
436
-
437
-        foreach ($dirfiles as $key => $indfile) {
438
-                 $thisuserroot = $this->view->getRoot();
439
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
440
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
441
-        }
442
-
443
-        // Upload the new file
444
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
445
-        $fileName = $_FILES['uploadfileforsms']['name'];
446
-
447
-        $userroot = $this->view->getRoot();
448
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
449
-
450
-        $target = $this->folder->newFile($targetfile);
451
-        $target->putContent($fileContent);
452
-
453
-        // Extract the phone numbers from the file
454
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
455
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
456
-        $numberarrayfourth = explode(",", $numberarraytert);
457
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
458
-        $numberarray = array_unique($numberarrayfifth);
459
-
460
-        return $numberarray;
461
-    }
462
-
463
-
464
-    /**
465
-     * @NoAdminRequired
466
-     */
467
-    public function uploadfile($uploadfileformms) {
468
-
469
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
470
-           $fileName = $_FILES['uploadfileformms']['name'];
471
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
472
-           $fileSize = $fileSizeinit / 1024;
473
-
474
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
475
-               $this->folder->newFolder('SMS_Relentless/temp_files');
476
-           }
477
-
478
-           $userroot = $this->view->getRoot();
479
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
480
-
481
-           $target = $this->folder->newFile($targetfile);
482
-           $target->putContent($fileContent);
483
-
484
-           // Get the cumulative files size of the uploaded files
485
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
486
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
487
-
488
-           $fileSystemIterator = new FilesystemIterator($targetdir);
489
-
490
-           $dirfiles = [];
491
-           foreach ($fileSystemIterator as $fileInfo){
492
-                    $dirfiles[] = $fileInfo->getFilename();
493
-           }
494
-
495
-           $totalflsizeinit = 0;
496
-           foreach ($dirfiles as $key => $indfile) {
497
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
498
-                    $mbSize = round($fileSizeinit / 1024, 4);
499
-                    $totalflsizeinit += $mbSize;
500
-           }
501
-
502
-           $totalflsize = round($totalflsizeinit, 4);
503
-
504
-           return $totalflsize;
505
-    }
506
-
507
-
508
-    /**
509
-     * @NoAdminRequired
510
-     */
511
-    public function pickfile($path) {
512
-
513
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
514
-               $this->folder->newFolder('SMS_Relentless/temp_files');
515
-           }
516
-
517
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
518
-
519
-           $fltgt = $datadir . $this->userId . "/files" . $path;
520
-
521
-           $fileContent = file_get_contents($fltgt);
522
-
523
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
524
-
525
-           $patharr = explode("/", $path);
526
-
527
-           $revarr = array_reverse($patharr);
528
-
529
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
530
-
531
-           $target = $this->folder->newFile($relflpath);
532
-
533
-           $target->putContent($fileContent);
534
-
535
-           // Get the cumulative files size of the uploaded files
536
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
537
-
538
-           $fileSystemIterator = new FilesystemIterator($targetdir);
539
-
540
-           $dirfiles = [];
541
-           foreach ($fileSystemIterator as $fileInfo) {
542
-                    $dirfiles[] = $fileInfo->getFilename();
543
-           }
544
-
545
-           $totalflsizeinit = 0;
546
-
547
-           foreach ($dirfiles as $key => $indfile) {
548
-
549
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
550
-                    $mbSize = round($fileSizeinit / 1024, 4);
551
-                    $totalflsizeinit += $mbSize;
552
-           }
553
-
554
-           $totalflsize = round($totalflsizeinit, 4);
555
-
556
-           $pickresult = [$totalflsize, $pkfilesize];
557
-
558
-           return $pickresult;
559
-    }
560
-
561
-
562
-    /**
563
-     * @NoAdminRequired
564
-     */
565
-    public function removeupfile($removedfilename) {
566
-
567
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
568
-
569
-           $removefile = $this->view->unlink($tmpfl);
570
-
571
-           // Get the cumulative files size of the uploaded files
572
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
573
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
574
-           $fileSystemIterator = new FilesystemIterator($targetdir);
575
-
576
-           $dirfiles = [];
577
-           foreach ($fileSystemIterator as $fileInfo){
578
-                    $dirfiles[] = $fileInfo->getFilename();
579
-           }
580
-
581
-           $totalflsizeinit = 0;
582
-
583
-           foreach ($dirfiles as $key => $indfile) {
584
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
585
-                    $mbSize = round($fileSizeinit / 1024, 4);
586
-                    $totalflsizeinit += $mbSize;
587
-           }
588
-
589
-           $totalflsize = round($totalflsizeinit, 4);
590
-
591
-           return $totalflsize;
592
-    }
593
-
594
-
595
-    /**
596
-     * @NoAdminRequired
597
-     */
598
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
599
-
600
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
601
-         $telnyxkey = $telsmsapicred[0];
602
-         $teldelrecurl = $telsmsapicred[3];
603
-         $messagingprofid = $telsmsapicred[4];
604
-
605
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
606
-
607
-         $microinterval = $waitinterval * 1000;
608
-
609
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
610
-
611
-             usleep($microinterval);
612
-
613
-             $messagedate = date("Y-m-d H:i:s");
614
-
615
-             if ($ismms == 0) {
616
-
617
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
618
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
619
-                 } else {
620
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
621
-                 }
622
-
623
-                 $messagetexttel = $sentsmstext;
624
-
625
-             } else {
626
-
627
-                 $mediaURLarr = [];
628
-                 $includedMediaFiles = '';
629
-
630
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
631
-
632
-                      $userroot = $this->view->getRoot();
633
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
634
-
635
-                      $flsharetarget = $this->folder->newFile($filetoshare);
636
-
637
-	              $share = $this->shareManager->newShare();
638
-	              $share->setNode($flsharetarget);
639
-	              $share->setPermissions(Constants::PERMISSION_READ);
640
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
641
-	              $share->setSharedBy($this->userId);
642
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
643
-                      $expirydate->add(new \DateInterval('P1D'));
644
-                      $share->setExpirationDate($expirydate);
645
-                      $shared = $this->shareManager->createShare($share);
646
-                      $shareToken = $shared->getToken();
647
-
648
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
649
-
650
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "";
651
-
652
-                      $base64imagetx = base64_encode(file_get_contents($hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p]));
653
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . $p . "' class='mmstblUrls' name='" . $base64imagetx . "' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
654
-                 }
655
-
656
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
657
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
658
-                 } else {
659
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
660
-                 }
661
-
662
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
663
-             }
664
-
665
-             $messageid = $message['id'];
666
-             $messagefrom = "Telnyx: " . $fromsender;
667
-             $messageto = $tonumber;
668
-             $messagenetwork = null;
669
-             $messageprice = null;
670
-             $messagestatus = $message['to'][0]['status'];
671
-             $messagedelivery = null;
672
-
673
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
674
-
675
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
676
-         }
677
-
678
-         $crtuser = $this->userManager->get($this->userId);
679
-         $displayname = $crtuser->getDisplayName();
680
-         return $displayname;
681
-    }
682
-
683
-
684
-    /**
685
-     * @NoAdminRequired
686
-     */
687
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
688
-
689
-         $smsapicred = $this->service->getapicredentials($this->userId);
690
-
691
-         $smsapikey = $smsapicred[5];
692
-         $smsapisecret = $smsapicred[6];
693
-         $smsapideliveryrecurl = $smsapicred[8];
694
-
695
-         $microinterval = $waitinterval * 1000;
696
-
697
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
698
-
699
-             usleep($microinterval);
700
-
701
-             $messagedatepl = date("Y-m-d H:i:s");
702
-
703
-             if ($ismms == 0) {
704
-
705
-                 $client = new RestClient($smsapikey, $smsapisecret);
706
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
707
-                 $messagetextpl = $sentsmstext;
708
-	         $messageidinit = $response->getmessageUuid(0);
709
-                 $messageid = $messageidinit[0];
710
-
711
-                 if (property_exists($response, 'error')) { 
712
-                     $messagestatus = "Error: " . $response->error;
713
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
714
-
715
-             } else {
716
-
717
-                 $mediaURLarr = [];
718
-                 $includedMediaFiles = '';
719
-
720
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
721
-
722
-                      $userroot = $this->view->getRoot();
723
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
724
-
725
-                      $flsharetarget = $this->folder->newFile($filetoshare);
726
-
727
-	              $share = $this->shareManager->newShare();
728
-	              $share->setNode($flsharetarget);
729
-	              $share->setPermissions(Constants::PERMISSION_READ);
730
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
731
-	              $share->setSharedBy($this->userId);
732
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
733
-                      $expirydate->add(new \DateInterval('P1D'));
734
-                      $share->setExpirationDate($expirydate);
735
-                      $shared = $this->shareManager->createShare($share);
736
-                      $shareToken = $shared->getToken();
737
-
738
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
739
-
740
-                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "";
741
-
742
-                      $base64imagepl = base64_encode(file_get_contents($hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p]));
743
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . $p . "' class='mmstblUrls' name='" . $base64imagepl . "' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
744
-                 }
745
-
746
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
747
-		 $postedparamspl = json_encode($datatosendpl);
748
-
749
-		 $chpl = curl_init();
750
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
751
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
752
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
753
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
754
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
755
-		 curl_setopt($chpl, CURLOPT_POST, 1);
756
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
757
-		 $resultpl = curl_exec ($chpl);
758
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
759
-		 curl_close ($chpl);
760
-
761
-		 $decresultpl = json_decode($resultpl);
762
-
763
-                 if (property_exists($decresultpl, 'message_uuid')) {
764
-                     $messageidinit = $decresultpl->message_uuid;
765
-                     $messageid = $messageidinit[0];
766
-                 }
767
-
768
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
769
-
770
-                     if (property_exists($decresultpl, 'error')) {
771
-                         $messagestatus = "Error: " . $decresultpl->error;
772
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
773
-
774
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
775
-
776
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
777
-             }
778
-
779
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
780
-                 $messagefrom = "Plivo: " . $fromsender;
781
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
782
-
783
-             $messageto = $tonumber;
784
-             $messagenetwork = '';
785
-             $messageprice = '';
786
-
787
-             $messagedelivery = '';
788
-
789
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
790
-
791
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
792
-         }
793
-
794
-         $crtuser = $this->userManager->get($this->userId);
795
-         $displayname = $crtuser->getDisplayName();
796
-         return $displayname;
797
-    }
798
-
799
-
800
-    /**
801
-     * @NoAdminRequired
802
-     */
803
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
804
-
805
-         $smsapicred = $this->service->getapicredentials($this->userId);
806
-
807
-         $sid = $smsapicred[15];
808
-         $token = $smsapicred[16];
809
-         $smsapirecurltw = $smsapicred[18];
810
-
811
-         $microinterval = $waitinterval * 1000;
812
-
813
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
814
-
815
-             usleep($microinterval);
816
-
817
-             $messagedatetw = date("Y-m-d H:i:s");
818
-
819
-             if ($ismms == 0) {
820
-
821
-                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
822
-                  $sentsmstextfintw = $sentsmstext;
823
-
824
-             } else {
825
-
826
-                 $mediaURLs = [];
827
-
828
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
829
-
830
-                      $userroot = $this->view->getRoot();
831
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
832
-
833
-                      $flsharetarget = $this->folder->newFile($filetoshare);
834
-
835
-	              $share = $this->shareManager->newShare();
836
-	              $share->setNode($flsharetarget);
837
-	              $share->setPermissions(Constants::PERMISSION_READ);
838
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
839
-	              $share->setSharedBy($this->userId);
840
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
841
-                      $expirydate->add(new \DateInterval('P1D'));
842
-                      $share->setExpirationDate($expirydate);
843
-                      $shared = $this->shareManager->createShare($share);
844
-                      $shareToken = $shared->getToken();
845
-
846
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
847
-
848
-                      $mediaURLs[] = $hostnm . "/s/".$shareToken."/download/".$mmsfiles[$p]."";
849
-
850
-                 }
851
-
852
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
853
-                 $includedMediaFiles = '';
854
-
855
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
856
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
857
-                      $base64imagetw = base64_encode(file_get_contents($mediaURLs[$m]));
858
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . $m . "' class='mmstblUrls' name='" . $base64imagetw . "' title='Download this file only if you trust the sender and the domain of the URL.'>" . $mediaURLs[$m] . "</div><br><br>";
859
-                 }
860
-
861
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
862
-             }
863
-
864
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
865
-
866
-	     $chtw = curl_init();
867
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
868
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
869
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
870
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
871
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
872
-	     curl_setopt($chtw, CURLOPT_POST, 1);
873
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
874
-
875
-	     $resulttw = curl_exec ($chtw);
876
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
877
-	     curl_close ($chtw);
878
-
879
-             $decresulttw = json_decode($resulttw);
880
-
881
-             if ($resulttw) {
882
-                 $messageidtw = $decresulttw->sid;
883
-             } else { $messageidtw = ''; }
884
-
885
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
886
-                 $messagestatustw = 'The message has been accepted for delivery.';
887
-             } else {
888
-                 $messagestatustw = 'An error occurred while trying to send the message.';
889
-             }
890
-
891
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
892
-                 $messagefromtw = "Twilio: " . $fromsender;
893
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
894
-
895
-             $messagenetworktw = '';
896
-             $messagepricetw = '';
897
-             $messagedeliverytw = '';
898
-
899
-
900
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
901
-
902
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
903
-         }
904
-
905
-         $crtuser = $this->userManager->get($this->userId);
906
-         $displayname = $crtuser->getDisplayName();
907
-         return $displayname;
908
-    }
909
-
910
-
911
-    /**
912
-     * @NoAdminRequired
913
-     */
914
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
915
-
916
-         $smsapicredfl = $this->service->getapicredentials($this->userId);
917
-
918
-         $flowapikey = $smsapicredfl[20];
919
-         $flowapisecret = $smsapicredfl[21];
920
-         $flowdelrecurl = $smsapicredfl[23];
921
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
922
-
923
-         $microinterval = $waitinterval * 1000;
924
-
925
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
926
-
927
-             usleep($microinterval);
928
-
929
-             $messagedatefl = date("Y-m-d H:i:s");
930
-
931
-             if ($ismms == 0) {
932
-
933
-                 $messagetextfinfl = $sentsmstext;
934
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
935
-
936
-             } else {
937
-
938
-		 $mediaurlsarr = [];
939
-
940
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
941
-
942
-		      $userroot = $this->view->getRoot();
943
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
944
-
945
-		      $flsharetarget = $this->folder->newFile($filetoshare);
946
-
947
-		      $share = $this->shareManager->newShare();
948
-		      $share->setNode($flsharetarget);
949
-		      $share->setPermissions(Constants::PERMISSION_READ);
950
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
951
-		      $share->setSharedBy($this->userId);
952
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
953
-                      $expirydate->add(new \DateInterval('P1D'));
954
-                      $share->setExpirationDate($expirydate);
955
-		      $shared = $this->shareManager->createShare($share);
956
-		      $shareToken = $shared->getToken();
957
-
958
-                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
959
-
960
-		      $mediaurlsarr[] = $hostnm . "/s/".$shareToken."/download/".$mmsfiles[$p]."";
961
-		 }
962
-
963
-		 $includedMediaFiles = '';
964
-
965
-		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
966
-                      $base64imagefl = base64_encode(file_get_contents($mediaurlsarr[$m]));
967
-                      $includedMediaFiles .= "<div id='mmsTblUrl-" . $m . "' class='mmstblUrls' name='" . $base64imagefl . "' title='Download this file only if you trust the sender and the domain of the URL.'>" . $mediaurlsarr[$m] . "</div><br><br>";
968
-		 }
969
-
970
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
971
-
972
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
973
-             }
974
-
975
-	     $chfl = curl_init();
976
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
977
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
978
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
979
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
980
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
981
-	     curl_setopt($chfl, CURLOPT_POST, 1);
982
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
983
-	     $resultfl = curl_exec ($chfl);
984
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
985
-	     curl_close ($chfl);
986
-
987
-             $decresultfl = json_decode($resultfl);
988
-
989
-             if ($resultfl) {
990
-                 $messageidfl = $decresultfl->data->id;
991
-             } else { $messageidfl = ''; }
992
-
993
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
994
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
995
-             } else { 
996
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
997
-             }
998
-
999
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
1000
-                 $messagefromfl = "Flowroute: " . $fromsender;
1001
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
1002
-
1003
-             $messagetofl = $tonumberfl;
1004
-             $messagenetworkfl = '';
1005
-             $messagepricefl = '';
1006
-             $messagedeliveryfl = '';
1007
-
1008
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
1009
-
1010
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
1011
-         }
1012
-
1013
-         $crtuser = $this->userManager->get($this->userId);
1014
-         $displayname = $crtuser->getDisplayName();
1015
-         return $displayname;
1016
-    }
1017
-
1018
-
1019
-    /**
1020
-     * @NoAdminRequired
1021
-     */
1022
-    public function saveoldrecrows($userId, $oldrecRows) {
1023
-
1024
-           // Create the folder for removed messages if it doesn't exist
1025
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
1026
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
1027
-           }
1028
-           $savecheck = 0;
1029
-
1030
-           if (count($oldrecRows) > 1) {
1031
-               $msfileContent = implode("", $oldrecRows);
1032
-
1033
-               $delrowsdate = date("Y-m-d_H-i-s");
1034
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
1035
-
1036
-               $userroot = $this->view->getRoot();
1037
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
1038
-
1039
-               $target = $this->folder->newFile($targetfile);
1040
-               $target->putContent($msfileContent);
1041
-
1042
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
1043
-                   $savecheck = 1;
1044
-               }
1045
-           }
1046
-
1047
-           return $savecheck;
1048
-    }
1049
-
1050
-
1051
-    /**
1052
-     * @NoAdminRequired
1053
-     */
1054
-    public function saveoldsentrows($userId, $oldsentRows) {
1055
-
1056
-           // Create the folder for removed messages if it doesn't exist
1057
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
1058
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
1059
-           }
1060
-           $savesentcheck = 0;
1061
-
1062
-           if (count($oldsentRows) > 1) {
1063
-               $sntfileContent = implode("", $oldsentRows);
1064
-
1065
-               $delsentrowsdate = date("Y-m-d_H-i-s");
1066
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
1067
-
1068
-               $userroot = $this->view->getRoot();
1069
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
1070
-
1071
-               $snttarget = $this->folder->newFile($snttargetfile);
1072
-               $snttarget->putContent($sntfileContent);
1073
-
1074
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
1075
-                   $savesentcheck = 1;
1076
-               }
1077
-           }
1078
-
1079
-           return $savesentcheck;
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * @NoAdminRequired
1085
-     */
1086
-    public function getreceivedtable($userId) {
1087
-           return $this->service->getreceivedtable($this->userId);
1088
-    }
1089
-
1090
-    /**
1091
-     * @NoAdminRequired
1092
-     */
1093
-    public function getreceivedtablefordel($userId) {
1094
-           return $this->service->getreceivedtablefordel($this->userId);
1095
-    }
1096
-
1097
-    /**
1098
-     * @NoAdminRequired
1099
-     */
1100
-    public function removerecrows($userId, $recmessagedbIDs) {
1101
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
1102
-    }
1103
-
1104
-    /**
1105
-     * @NoAdminRequired
1106
-     */
1107
-    public function getsenttable($userId) {
1108
-           return $this->service->getsenttable($this->userId);
1109
-    }
1110
-
1111
-    /**
1112
-     * @NoAdminRequired
1113
-     */
1114
-    public function getsenttablefordel($userId) {
1115
-           return $this->service->getsenttablefordel($this->userId);
1116
-    }
1117
-
1118
-    /**
1119
-     * @NoAdminRequired
1120
-     */
1121
-    public function removesentrows($userId, $sentmessagedbIDs) {
1122
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1123
-    }
1124
-
1125
-    /**
1126
-     * @NoAdminRequired
1127
-     */
1128
-    public function getgroupedtable($userId) {
1129
-           return $this->service->getgroupedtable($this->userId);
1130
-    }
1131
-
1132
-    /**
1133
-     * @NoAdminRequired
1134
-     */
1135
-    public function savedisplayname($userId, $authorDisplayname, $from) {
1136
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1137
-    }
1138
-
1139
-    /**
1140
-     * @NoAdminRequired
1141
-     */
1142
-    public function getmessagesperpage($userId) {
1143
-           return $this->service->getmessagesperpage($this->userId);
1144
-    }
1145
-
1146
-    /**
1147
-     * @NoAdminRequired
1148
-     */
1149
-    public function getdelrecsettings($userId) {
1150
-           return $this->service->getdelrecsettings($this->userId);
1151
-    }
1152
-
1153
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1154
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1155
-    }
1156
-
1157
-    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1158
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1159
-    }
1160
-
1161
-    public function removenumberrestrictions($userId, $phoneNumber) {
1162
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1163
-    }
1164
-
1165
-    /**
1166
-     * @NoAdminRequired
1167
-     */
1168
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1169
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1170
-    }
1171
-
1172
-    /**
1173
-     * @NoAdminRequired
1174
-     */
1175
-    public function removeautoreplies($userId, $phoneNumber) {
1176
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1177
-    }
1178
-
1179
-    /**
1180
-     * @NoAdminRequired
1181
-     */
1182
-    public function getsettings($userId) {
1183
-           return $this->service->getsettings($this->userId);
1184
-    }
1185
-
1186
-    public function getadminsettings($userId) {
1187
-           return $this->service->getadminsettings($this->userId);
1188
-    }
1189
-
1190
-    /**
1191
-     * @NoAdminRequired
1192
-     */
1193
-    public function getautoreplyconf($userId) {
1194
-
1195
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1196
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1197
-
1198
-           // Get the display name of the current user
1199
-           $usrid = $this->userId;
1200
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1201
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1202
-	   $getusrdnmdata = $getusrdnmres->fetch();
1203
-	   $userDisplayNm = $getusrdnmdata['value'];
1204
-	   $getusrdnmres->closeCursor();
1205
-
1206
-           // Get the auto-replies for the available phone numbers
1207
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1208
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1209
-	   $getautorplres = $getautorpl->execute();
1210
-           $autorplconf = [];
1211
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1212
-                  $autorplconf[] = $acdatausrdnadm;
1213
-           }
1214
-	   $getautorplres->closeCursor();
1215
-
1216
-           if ($autorplconf) {
1217
-
1218
-               $autoreplyconf = [];
1219
-               foreach ($autorplconf as $arkey => $arvalue) {
1220
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1221
-                            $autoreplyconf[] = $arvalue;
1222
-                        }
1223
-               }
1224
-
1225
-           } else { $autoreplyconf = ''; }
1226
-
1227
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1228
-
1229
-           return $autoreplyfdb;
1230
-    }
1231
-
1232
-    /**
1233
-     * @NoAdminRequired
1234
-     */
1235
-    public function getgroupedpernumber($userId, $phoneNumber) {
1236
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1237
-    }
1238
-
1239
-    /**
1240
-     * @NoAdminRequired
1241
-     */
1242
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1243
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1244
-    }
1245
-
1246
-    /**
1247
-     * @NoAdminRequired
1248
-     */
1249
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames) {
1250
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames);
1251
-    }
1252
-
1253
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1254
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1255
-    }
1256
-
1257
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames) {
1258
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames);
1259
-    }
1260
-}
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php js/sendsms.js

DoubleBastionAdmin authored on 30/05/2023 15:51:12
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1260 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\IURLGenerator;
49
+use OCP\Share\IManager;
50
+use OCP\Constants;
51
+use OCP\IGroupManager;
52
+use OCP\IDBConnection;
53
+use OCP\IUserManager;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $urlGenerator;
64
+    private $shareManager;
65
+    private $groupManager;
66
+    private $connection;
67
+    private $userManager;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->urlGenerator = $urlGenerator;
78
+	$this->shareManager = $shareManager;
79
+        $this->groupManager = $groupManager;
80
+        $this->connection = $connection;
81
+        $this->userManager = $userManager;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getbalancetel($userId) {
120
+
121
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
+
123
+        $telapikey = $telsmsapicred[0];
124
+        $ch = curl_init();
125
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
+
127
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
+        $responsetel = curl_exec($ch);
131
+        $recdatatel = json_decode($responsetel, TRUE);
132
+        $telbalresponse = $recdatatel['data']['balance'];
133
+        $currentbalancetel = round(floatval($telbalresponse), 3);
134
+        curl_close($ch);
135
+
136
+        return $currentbalancetel;
137
+    }
138
+
139
+
140
+    /**
141
+     * @NoAdminRequired
142
+     */
143
+    public function getbalancenex($userId) {
144
+
145
+        $smsapicred = $this->service->getapicredentials($this->userId);
146
+        $smsapikey = $smsapicred[5];
147
+        $smsapisecret = $smsapicred[6];
148
+
149
+        if ($smsapikey == '' || $smsapisecret == '') {
150
+            $currentbalancenex = "N/A";
151
+        } else {
152
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
+            $mesdata = file_get_contents($getmesdata);
154
+            $datainit = json_decode($mesdata);
155
+            $balancenex = $datainit->cash_credits;
156
+            $currentbalancenex = round(floatval($balancenex), 3);
157
+        }
158
+        return $currentbalancenex;
159
+    }
160
+
161
+
162
+    /**
163
+     * @NoAdminRequired
164
+     */
165
+    public function getbalancetwil($userId) {
166
+
167
+        $smsapicred = $this->service->getapicredentials($this->userId);
168
+        $smsapisid = $smsapicred[15];
169
+        $smsapitoken = $smsapicred[16];
170
+
171
+        if ($smsapisid == '' || $smsapitoken == '') {
172
+            $currentbalancetwil = "N/A";
173
+        } else {
174
+
175
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
+            $balancetwil = $twilbalance->balance;
177
+
178
+            $currentbalancetwil = round(floatval($balancetwil), 3);
179
+        }
180
+        return $currentbalancetwil;
181
+    }
182
+
183
+
184
+    /**
185
+     * @NoAdminRequired
186
+     */
187
+    public function getbalanceflow($userId) {
188
+
189
+        $currentbalanceflow = 'n/a';
190
+
191
+        return $currentbalanceflow;
192
+    }
193
+
194
+
195
+    /**
196
+     * @NoAdminRequired
197
+     */
198
+    public function getsmsnumbers($userId) {
199
+
200
+        $smsapicred = $this->service->getapicredentials($this->userId);
201
+
202
+        $telnyxkey = $smsapicred[0];
203
+
204
+        $nexapikey = $smsapicred[5];
205
+        $nexapisecret = $smsapicred[6];
206
+
207
+        $twilapikey = $smsapicred[15];
208
+        $twilapisecret = $smsapicred[16];
209
+
210
+        $flowapikey = $smsapicred[20];
211
+        $flowapisecret = $smsapicred[21];
212
+
213
+        $telsendernameinit = $smsapicred[9];
214
+        $nexsendernameinit = $smsapicred[10];
215
+        $twilsendernameinit = $smsapicred[19];
216
+
217
+        if ($telsendernameinit) {
218
+            $telsendername = "Tx: " . $telsendernameinit;
219
+            $telsenderarr = [0 => $telsendername];
220
+        } else { $telsenderarr = []; }
221
+
222
+        if ($nexsendernameinit) {
223
+            $nexsendername = "Pl: " . $nexsendernameinit;
224
+            $nexsenderarr = [0 => $nexsendername];
225
+        } else { $nexsenderarr = []; }
226
+
227
+        if ($twilsendernameinit) {
228
+            $twilsendername = "Tw: " . $twilsendernameinit;
229
+            $twilsenderarr = [0 => $twilsendername];
230
+        } else { $twilsenderarr = []; }
231
+
232
+        // Get Telnyx phone numbers
233
+        if ($telnyxkey != '') {
234
+
235
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
236
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
237
+
238
+           $telnumbersarr = $this->object_to_array($telnumbers);
239
+           $telnmbrs = [];
240
+
241
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
242
+              if (is_int($nmbkey)) {
243
+                 foreach ($nmbvalue as $nkey => $nvalue) {
244
+                    if ($nkey == 'phone_number' && $nvalue) {
245
+                       $telnmbrs[] = "Tx: " . $nvalue;
246
+                    }
247
+                 }
248
+              }
249
+           }
250
+
251
+        } else { $telnmbrs = []; }
252
+
253
+        // Get Plivo phone numbers
254
+        if ($nexapikey != '' && $nexapisecret != '') {
255
+
256
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
257
+           $acdata = file_get_contents($getacdata);
258
+           $datainit = json_decode($acdata, true);
259
+
260
+           $findata = $this->object_to_array($datainit);
261
+
262
+           $nexcurrentnmbrs = [];
263
+
264
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
265
+                   if (is_array($smsvalue)) {
266
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
267
+                               if ($smskey2 == 'number' && $smsvalue2) {
268
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
269
+                               }
270
+                         }
271
+                   }
272
+           }
273
+
274
+
275
+        } else { $nexcurrentnmbrs = []; }
276
+
277
+        // Get Twilio phone numbers
278
+        if ($twilapikey != '' && $twilapisecret != '') {
279
+
280
+            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
281
+            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
282
+
283
+            $twilcurrentnmbrs = [];
284
+            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
285
+                 if (is_array($twnbvalue)) {
286
+                     foreach ($twnbvalue as $twfkey => $twfvalue) {
287
+                          if ($twfkey == 'phone_number' && $twfvalue) {
288
+                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
289
+                          }
290
+                     }
291
+                 }
292
+            }
293
+
294
+        } else { $twilcurrentnmbrs = []; }
295
+
296
+        // Get Flowroute phone numbers
297
+        if ($flowapikey != '' && $flowapisecret != '') {
298
+
299
+            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
300
+            $flnbrsarr = $flnbrsresult->data;
301
+            $flowcurrentnmbrs = [];
302
+            foreach ($flnbrsarr as $flkey => $flitem) {
303
+                     if ($flitem->id) {
304
+                         $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
305
+                     }
306
+            }
307
+
308
+        } else { $flowcurrentnmbrs = []; }
309
+
310
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
311
+
312
+        if ($this->groupManager->isAdmin($this->userId)) {
313
+
314
+            return $currentnmbrs;
315
+
316
+        } else {
317
+
318
+            // Get the restrictions from the 'sms_relent_restrict' table
319
+            $getrestr = $this->connection->prepare('
320
+		       SELECT `phone_number`, `groups`, `users` FROM `*PREFIX*sms_relent_restrict`');
321
+            $getrestrres = $getrestr->execute();
322
+
323
+            $restrdata = [];
324
+            while ($restrfetched = $getrestrres->fetch()) {
325
+                   $restrdata[] = $restrfetched;
326
+            }
327
+            $getrestrres->closeCursor();
328
+
329
+            if ($restrdata) {
330
+
331
+                // Get the groups to which the current user belongs
332
+                $usrId = $this->userId;
333
+                $getusrgrp = $this->connection->prepare('
334
+		       SELECT `gid`, `uid` FROM `*PREFIX*group_user` WHERE `uid` = ?');
335
+                $getusrgrpres = $getusrgrp->execute([$usrId]);
336
+
337
+                $usergrps = [];
338
+                while ($fetchedgrps = $getusrgrpres->fetch()) {
339
+                       $usergrps[] = $fetchedgrps['gid'];
340
+                }
341
+                $getusrgrpres->closeCursor();
342
+                $ctusergroups = implode("|", $usergrps);
343
+
344
+		// Get the Display Name of the current user
345
+		$getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
346
+		$getacdatadnres = $getacdatadn->execute([$usrId, 'displayname']);
347
+		$acdatausrdnadm = $getacdatadnres->fetch();
348
+		$cruserdname = $acdatausrdnadm['value'];
349
+		$getacdatadnres->closeCursor();
350
+
351
+                // Get the phone numbers that are not allowed for the current user
352
+                $restrPhoneNb = [];
353
+                foreach ($restrdata as $rskey => $rsvalue) {
354
+
355
+                        $chck = 0;
356
+                        if ($rsvalue['groups']) {
357
+                            $restrgrparr = explode("|", $rsvalue['groups']);
358
+
359
+                            foreach ($restrgrparr as $grkey => $grvalue) {
360
+                                     if (str_contains($ctusergroups, $grvalue)) { $chck++; }
361
+                            }
362
+                        }
363
+
364
+                        if ($rsvalue['users']) {
365
+                            $usrnmstr = $rsvalue['users'];
366
+                            if (str_contains($usrnmstr, $cruserdname)) { $chck++; }
367
+                        }
368
+
369
+                        if ($chck == 0) { $restrPhoneNb[] = $rsvalue['phone_number']; }
370
+                }
371
+
372
+                $restrPhoneNmbrs = array_unique($restrPhoneNb);
373
+
374
+                // Assemble the array of phone numbers that the current user is allowed to use
375
+                for ($k = 0; $k < count($currentnmbrs); $k++) {
376
+
377
+                    if (in_array($currentnmbrs[$k], $restrPhoneNmbrs)) {
378
+                        unset($currentnmbrs[$k]);
379
+                    }
380
+                }
381
+
382
+                $currentnmbrsrstr = array_values($currentnmbrs);
383
+
384
+                return $currentnmbrsrstr;
385
+
386
+            } else { return $currentnmbrs; }
387
+        }
388
+    }
389
+
390
+
391
+    /**
392
+     * @NoAdminRequired
393
+     */
394
+    public function cleantempdir($userId) {
395
+
396
+        // Create the temporary folder if it doesn't exist
397
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
398
+            $this->folder->newFolder('SMS_Relentless/temp_files');
399
+        }
400
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
401
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
402
+        $fileSystemIterator = new FilesystemIterator($targetdir);
403
+
404
+        $dirfiles = [];
405
+        foreach ($fileSystemIterator as $fileInfo){
406
+                 $dirfiles[] = $fileInfo->getFilename();
407
+        }
408
+
409
+        foreach ($dirfiles as $key => $indfile) {
410
+                 $thisuserroot = $this->view->getRoot();
411
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
412
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
413
+        }
414
+     }
415
+
416
+
417
+    /**
418
+     * @NoAdminRequired
419
+     */
420
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
421
+
422
+        // Create the temporary folder if it doesn't exist
423
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
424
+            $this->folder->newFolder('SMS_Relentless/temp_files');
425
+        }
426
+
427
+        // First delete any file that has been previously uploaded
428
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
429
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
430
+        $fileSystemIterator = new FilesystemIterator($targetdir);
431
+
432
+        $dirfiles = [];
433
+        foreach ($fileSystemIterator as $fileInfo){
434
+                 $dirfiles[] = $fileInfo->getFilename();
435
+        }
436
+
437
+        foreach ($dirfiles as $key => $indfile) {
438
+                 $thisuserroot = $this->view->getRoot();
439
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
440
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
441
+        }
442
+
443
+        // Upload the new file
444
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
445
+        $fileName = $_FILES['uploadfileforsms']['name'];
446
+
447
+        $userroot = $this->view->getRoot();
448
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
449
+
450
+        $target = $this->folder->newFile($targetfile);
451
+        $target->putContent($fileContent);
452
+
453
+        // Extract the phone numbers from the file
454
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
455
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
456
+        $numberarrayfourth = explode(",", $numberarraytert);
457
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
458
+        $numberarray = array_unique($numberarrayfifth);
459
+
460
+        return $numberarray;
461
+    }
462
+
463
+
464
+    /**
465
+     * @NoAdminRequired
466
+     */
467
+    public function uploadfile($uploadfileformms) {
468
+
469
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
470
+           $fileName = $_FILES['uploadfileformms']['name'];
471
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
472
+           $fileSize = $fileSizeinit / 1024;
473
+
474
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
475
+               $this->folder->newFolder('SMS_Relentless/temp_files');
476
+           }
477
+
478
+           $userroot = $this->view->getRoot();
479
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
480
+
481
+           $target = $this->folder->newFile($targetfile);
482
+           $target->putContent($fileContent);
483
+
484
+           // Get the cumulative files size of the uploaded files
485
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
486
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
487
+
488
+           $fileSystemIterator = new FilesystemIterator($targetdir);
489
+
490
+           $dirfiles = [];
491
+           foreach ($fileSystemIterator as $fileInfo){
492
+                    $dirfiles[] = $fileInfo->getFilename();
493
+           }
494
+
495
+           $totalflsizeinit = 0;
496
+           foreach ($dirfiles as $key => $indfile) {
497
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
498
+                    $mbSize = round($fileSizeinit / 1024, 4);
499
+                    $totalflsizeinit += $mbSize;
500
+           }
501
+
502
+           $totalflsize = round($totalflsizeinit, 4);
503
+
504
+           return $totalflsize;
505
+    }
506
+
507
+
508
+    /**
509
+     * @NoAdminRequired
510
+     */
511
+    public function pickfile($path) {
512
+
513
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
514
+               $this->folder->newFolder('SMS_Relentless/temp_files');
515
+           }
516
+
517
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
518
+
519
+           $fltgt = $datadir . $this->userId . "/files" . $path;
520
+
521
+           $fileContent = file_get_contents($fltgt);
522
+
523
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
524
+
525
+           $patharr = explode("/", $path);
526
+
527
+           $revarr = array_reverse($patharr);
528
+
529
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
530
+
531
+           $target = $this->folder->newFile($relflpath);
532
+
533
+           $target->putContent($fileContent);
534
+
535
+           // Get the cumulative files size of the uploaded files
536
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
537
+
538
+           $fileSystemIterator = new FilesystemIterator($targetdir);
539
+
540
+           $dirfiles = [];
541
+           foreach ($fileSystemIterator as $fileInfo) {
542
+                    $dirfiles[] = $fileInfo->getFilename();
543
+           }
544
+
545
+           $totalflsizeinit = 0;
546
+
547
+           foreach ($dirfiles as $key => $indfile) {
548
+
549
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
550
+                    $mbSize = round($fileSizeinit / 1024, 4);
551
+                    $totalflsizeinit += $mbSize;
552
+           }
553
+
554
+           $totalflsize = round($totalflsizeinit, 4);
555
+
556
+           $pickresult = [$totalflsize, $pkfilesize];
557
+
558
+           return $pickresult;
559
+    }
560
+
561
+
562
+    /**
563
+     * @NoAdminRequired
564
+     */
565
+    public function removeupfile($removedfilename) {
566
+
567
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
568
+
569
+           $removefile = $this->view->unlink($tmpfl);
570
+
571
+           // Get the cumulative files size of the uploaded files
572
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
573
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
574
+           $fileSystemIterator = new FilesystemIterator($targetdir);
575
+
576
+           $dirfiles = [];
577
+           foreach ($fileSystemIterator as $fileInfo){
578
+                    $dirfiles[] = $fileInfo->getFilename();
579
+           }
580
+
581
+           $totalflsizeinit = 0;
582
+
583
+           foreach ($dirfiles as $key => $indfile) {
584
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
585
+                    $mbSize = round($fileSizeinit / 1024, 4);
586
+                    $totalflsizeinit += $mbSize;
587
+           }
588
+
589
+           $totalflsize = round($totalflsizeinit, 4);
590
+
591
+           return $totalflsize;
592
+    }
593
+
594
+
595
+    /**
596
+     * @NoAdminRequired
597
+     */
598
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
599
+
600
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
601
+         $telnyxkey = $telsmsapicred[0];
602
+         $teldelrecurl = $telsmsapicred[3];
603
+         $messagingprofid = $telsmsapicred[4];
604
+
605
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
606
+
607
+         $microinterval = $waitinterval * 1000;
608
+
609
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
610
+
611
+             usleep($microinterval);
612
+
613
+             $messagedate = date("Y-m-d H:i:s");
614
+
615
+             if ($ismms == 0) {
616
+
617
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
618
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
619
+                 } else {
620
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
621
+                 }
622
+
623
+                 $messagetexttel = $sentsmstext;
624
+
625
+             } else {
626
+
627
+                 $mediaURLarr = [];
628
+                 $includedMediaFiles = '';
629
+
630
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
631
+
632
+                      $userroot = $this->view->getRoot();
633
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
634
+
635
+                      $flsharetarget = $this->folder->newFile($filetoshare);
636
+
637
+	              $share = $this->shareManager->newShare();
638
+	              $share->setNode($flsharetarget);
639
+	              $share->setPermissions(Constants::PERMISSION_READ);
640
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
641
+	              $share->setSharedBy($this->userId);
642
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
643
+                      $expirydate->add(new \DateInterval('P1D'));
644
+                      $share->setExpirationDate($expirydate);
645
+                      $shared = $this->shareManager->createShare($share);
646
+                      $shareToken = $shared->getToken();
647
+
648
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
649
+
650
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "";
651
+
652
+                      $base64imagetx = base64_encode(file_get_contents($hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p]));
653
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . $p . "' class='mmstblUrls' name='" . $base64imagetx . "' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
654
+                 }
655
+
656
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
657
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
658
+                 } else {
659
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
660
+                 }
661
+
662
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
663
+             }
664
+
665
+             $messageid = $message['id'];
666
+             $messagefrom = "Telnyx: " . $fromsender;
667
+             $messageto = $tonumber;
668
+             $messagenetwork = null;
669
+             $messageprice = null;
670
+             $messagestatus = $message['to'][0]['status'];
671
+             $messagedelivery = null;
672
+
673
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
674
+
675
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
676
+         }
677
+
678
+         $crtuser = $this->userManager->get($this->userId);
679
+         $displayname = $crtuser->getDisplayName();
680
+         return $displayname;
681
+    }
682
+
683
+
684
+    /**
685
+     * @NoAdminRequired
686
+     */
687
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
688
+
689
+         $smsapicred = $this->service->getapicredentials($this->userId);
690
+
691
+         $smsapikey = $smsapicred[5];
692
+         $smsapisecret = $smsapicred[6];
693
+         $smsapideliveryrecurl = $smsapicred[8];
694
+
695
+         $microinterval = $waitinterval * 1000;
696
+
697
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
698
+
699
+             usleep($microinterval);
700
+
701
+             $messagedatepl = date("Y-m-d H:i:s");
702
+
703
+             if ($ismms == 0) {
704
+
705
+                 $client = new RestClient($smsapikey, $smsapisecret);
706
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
707
+                 $messagetextpl = $sentsmstext;
708
+	         $messageidinit = $response->getmessageUuid(0);
709
+                 $messageid = $messageidinit[0];
710
+
711
+                 if (property_exists($response, 'error')) { 
712
+                     $messagestatus = "Error: " . $response->error;
713
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
714
+
715
+             } else {
716
+
717
+                 $mediaURLarr = [];
718
+                 $includedMediaFiles = '';
719
+
720
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
721
+
722
+                      $userroot = $this->view->getRoot();
723
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
724
+
725
+                      $flsharetarget = $this->folder->newFile($filetoshare);
726
+
727
+	              $share = $this->shareManager->newShare();
728
+	              $share->setNode($flsharetarget);
729
+	              $share->setPermissions(Constants::PERMISSION_READ);
730
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
731
+	              $share->setSharedBy($this->userId);
732
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
733
+                      $expirydate->add(new \DateInterval('P1D'));
734
+                      $share->setExpirationDate($expirydate);
735
+                      $shared = $this->shareManager->createShare($share);
736
+                      $shareToken = $shared->getToken();
737
+
738
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
739
+
740
+                      $mediaURLarr[] = $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "";
741
+
742
+                      $base64imagepl = base64_encode(file_get_contents($hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p]));
743
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . $p . "' class='mmstblUrls' name='" . $base64imagepl . "' title='Download this file only if you trust the sender and the domain of the URL.'>" . $hostnm . "/s/" . $shareToken . "/download/" . $mmsfiles[$p] . "</div><br><br>";
744
+                 }
745
+
746
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
747
+		 $postedparamspl = json_encode($datatosendpl);
748
+
749
+		 $chpl = curl_init();
750
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
751
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
752
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
753
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
754
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
755
+		 curl_setopt($chpl, CURLOPT_POST, 1);
756
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
757
+		 $resultpl = curl_exec ($chpl);
758
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
759
+		 curl_close ($chpl);
760
+
761
+		 $decresultpl = json_decode($resultpl);
762
+
763
+                 if (property_exists($decresultpl, 'message_uuid')) {
764
+                     $messageidinit = $decresultpl->message_uuid;
765
+                     $messageid = $messageidinit[0];
766
+                 }
767
+
768
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
769
+
770
+                     if (property_exists($decresultpl, 'error')) {
771
+                         $messagestatus = "Error: " . $decresultpl->error;
772
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
773
+
774
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
775
+
776
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
777
+             }
778
+
779
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
780
+                 $messagefrom = "Plivo: " . $fromsender;
781
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
782
+
783
+             $messageto = $tonumber;
784
+             $messagenetwork = '';
785
+             $messageprice = '';
786
+
787
+             $messagedelivery = '';
788
+
789
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
790
+
791
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
792
+         }
793
+
794
+         $crtuser = $this->userManager->get($this->userId);
795
+         $displayname = $crtuser->getDisplayName();
796
+         return $displayname;
797
+    }
798
+
799
+
800
+    /**
801
+     * @NoAdminRequired
802
+     */
803
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
804
+
805
+         $smsapicred = $this->service->getapicredentials($this->userId);
806
+
807
+         $sid = $smsapicred[15];
808
+         $token = $smsapicred[16];
809
+         $smsapirecurltw = $smsapicred[18];
810
+
811
+         $microinterval = $waitinterval * 1000;
812
+
813
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
814
+
815
+             usleep($microinterval);
816
+
817
+             $messagedatetw = date("Y-m-d H:i:s");
818
+
819
+             if ($ismms == 0) {
820
+
821
+                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
822
+                  $sentsmstextfintw = $sentsmstext;
823
+
824
+             } else {
825
+
826
+                 $mediaURLs = [];
827
+
828
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
829
+
830
+                      $userroot = $this->view->getRoot();
831
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
832
+
833
+                      $flsharetarget = $this->folder->newFile($filetoshare);
834
+
835
+	              $share = $this->shareManager->newShare();
836
+	              $share->setNode($flsharetarget);
837
+	              $share->setPermissions(Constants::PERMISSION_READ);
838
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
839
+	              $share->setSharedBy($this->userId);
840
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
841
+                      $expirydate->add(new \DateInterval('P1D'));
842
+                      $share->setExpirationDate($expirydate);
843
+                      $shared = $this->shareManager->createShare($share);
844
+                      $shareToken = $shared->getToken();
845
+
846
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
847
+
848
+                      $mediaURLs[] = $hostnm . "/s/".$shareToken."/download/".$mmsfiles[$p]."";
849
+
850
+                 }
851
+
852
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
853
+                 $includedMediaFiles = '';
854
+
855
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
856
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
857
+                      $base64imagetw = base64_encode(file_get_contents($mediaURLs[$m]));
858
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . $m . "' class='mmstblUrls' name='" . $base64imagetw . "' title='Download this file only if you trust the sender and the domain of the URL.'>" . $mediaURLs[$m] . "</div><br><br>";
859
+                 }
860
+
861
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
862
+             }
863
+
864
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
865
+
866
+	     $chtw = curl_init();
867
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
868
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
869
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
870
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
871
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
872
+	     curl_setopt($chtw, CURLOPT_POST, 1);
873
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
874
+
875
+	     $resulttw = curl_exec ($chtw);
876
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
877
+	     curl_close ($chtw);
878
+
879
+             $decresulttw = json_decode($resulttw);
880
+
881
+             if ($resulttw) {
882
+                 $messageidtw = $decresulttw->sid;
883
+             } else { $messageidtw = ''; }
884
+
885
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
886
+                 $messagestatustw = 'The message has been accepted for delivery.';
887
+             } else {
888
+                 $messagestatustw = 'An error occurred while trying to send the message.';
889
+             }
890
+
891
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
892
+                 $messagefromtw = "Twilio: " . $fromsender;
893
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
894
+
895
+             $messagenetworktw = '';
896
+             $messagepricetw = '';
897
+             $messagedeliverytw = '';
898
+
899
+
900
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
901
+
902
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
903
+         }
904
+
905
+         $crtuser = $this->userManager->get($this->userId);
906
+         $displayname = $crtuser->getDisplayName();
907
+         return $displayname;
908
+    }
909
+
910
+
911
+    /**
912
+     * @NoAdminRequired
913
+     */
914
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
915
+
916
+         $smsapicredfl = $this->service->getapicredentials($this->userId);
917
+
918
+         $flowapikey = $smsapicredfl[20];
919
+         $flowapisecret = $smsapicredfl[21];
920
+         $flowdelrecurl = $smsapicredfl[23];
921
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
922
+
923
+         $microinterval = $waitinterval * 1000;
924
+
925
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
926
+
927
+             usleep($microinterval);
928
+
929
+             $messagedatefl = date("Y-m-d H:i:s");
930
+
931
+             if ($ismms == 0) {
932
+
933
+                 $messagetextfinfl = $sentsmstext;
934
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
935
+
936
+             } else {
937
+
938
+		 $mediaurlsarr = [];
939
+
940
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
941
+
942
+		      $userroot = $this->view->getRoot();
943
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
944
+
945
+		      $flsharetarget = $this->folder->newFile($filetoshare);
946
+
947
+		      $share = $this->shareManager->newShare();
948
+		      $share->setNode($flsharetarget);
949
+		      $share->setPermissions(Constants::PERMISSION_READ);
950
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
951
+		      $share->setSharedBy($this->userId);
952
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
953
+                      $expirydate->add(new \DateInterval('P1D'));
954
+                      $share->setExpirationDate($expirydate);
955
+		      $shared = $this->shareManager->createShare($share);
956
+		      $shareToken = $shared->getToken();
957
+
958
+                      $hostnm = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'];
959
+
960
+		      $mediaurlsarr[] = $hostnm . "/s/".$shareToken."/download/".$mmsfiles[$p]."";
961
+		 }
962
+
963
+		 $includedMediaFiles = '';
964
+
965
+		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
966
+                      $base64imagefl = base64_encode(file_get_contents($mediaurlsarr[$m]));
967
+                      $includedMediaFiles .= "<div id='mmsTblUrl-" . $m . "' class='mmstblUrls' name='" . $base64imagefl . "' title='Download this file only if you trust the sender and the domain of the URL.'>" . $mediaurlsarr[$m] . "</div><br><br>";
968
+		 }
969
+
970
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
971
+
972
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
973
+             }
974
+
975
+	     $chfl = curl_init();
976
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
977
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
978
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
979
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
980
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
981
+	     curl_setopt($chfl, CURLOPT_POST, 1);
982
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
983
+	     $resultfl = curl_exec ($chfl);
984
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
985
+	     curl_close ($chfl);
986
+
987
+             $decresultfl = json_decode($resultfl);
988
+
989
+             if ($resultfl) {
990
+                 $messageidfl = $decresultfl->data->id;
991
+             } else { $messageidfl = ''; }
992
+
993
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
994
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
995
+             } else { 
996
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
997
+             }
998
+
999
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
1000
+                 $messagefromfl = "Flowroute: " . $fromsender;
1001
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
1002
+
1003
+             $messagetofl = $tonumberfl;
1004
+             $messagenetworkfl = '';
1005
+             $messagepricefl = '';
1006
+             $messagedeliveryfl = '';
1007
+
1008
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
1009
+
1010
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
1011
+         }
1012
+
1013
+         $crtuser = $this->userManager->get($this->userId);
1014
+         $displayname = $crtuser->getDisplayName();
1015
+         return $displayname;
1016
+    }
1017
+
1018
+
1019
+    /**
1020
+     * @NoAdminRequired
1021
+     */
1022
+    public function saveoldrecrows($userId, $oldrecRows) {
1023
+
1024
+           // Create the folder for removed messages if it doesn't exist
1025
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
1026
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
1027
+           }
1028
+           $savecheck = 0;
1029
+
1030
+           if (count($oldrecRows) > 1) {
1031
+               $msfileContent = implode("", $oldrecRows);
1032
+
1033
+               $delrowsdate = date("Y-m-d_H-i-s");
1034
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
1035
+
1036
+               $userroot = $this->view->getRoot();
1037
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
1038
+
1039
+               $target = $this->folder->newFile($targetfile);
1040
+               $target->putContent($msfileContent);
1041
+
1042
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
1043
+                   $savecheck = 1;
1044
+               }
1045
+           }
1046
+
1047
+           return $savecheck;
1048
+    }
1049
+
1050
+
1051
+    /**
1052
+     * @NoAdminRequired
1053
+     */
1054
+    public function saveoldsentrows($userId, $oldsentRows) {
1055
+
1056
+           // Create the folder for removed messages if it doesn't exist
1057
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
1058
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
1059
+           }
1060
+           $savesentcheck = 0;
1061
+
1062
+           if (count($oldsentRows) > 1) {
1063
+               $sntfileContent = implode("", $oldsentRows);
1064
+
1065
+               $delsentrowsdate = date("Y-m-d_H-i-s");
1066
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
1067
+
1068
+               $userroot = $this->view->getRoot();
1069
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
1070
+
1071
+               $snttarget = $this->folder->newFile($snttargetfile);
1072
+               $snttarget->putContent($sntfileContent);
1073
+
1074
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
1075
+                   $savesentcheck = 1;
1076
+               }
1077
+           }
1078
+
1079
+           return $savesentcheck;
1080
+    }
1081
+
1082
+
1083
+    /**
1084
+     * @NoAdminRequired
1085
+     */
1086
+    public function getreceivedtable($userId) {
1087
+           return $this->service->getreceivedtable($this->userId);
1088
+    }
1089
+
1090
+    /**
1091
+     * @NoAdminRequired
1092
+     */
1093
+    public function getreceivedtablefordel($userId) {
1094
+           return $this->service->getreceivedtablefordel($this->userId);
1095
+    }
1096
+
1097
+    /**
1098
+     * @NoAdminRequired
1099
+     */
1100
+    public function removerecrows($userId, $recmessagedbIDs) {
1101
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
1102
+    }
1103
+
1104
+    /**
1105
+     * @NoAdminRequired
1106
+     */
1107
+    public function getsenttable($userId) {
1108
+           return $this->service->getsenttable($this->userId);
1109
+    }
1110
+
1111
+    /**
1112
+     * @NoAdminRequired
1113
+     */
1114
+    public function getsenttablefordel($userId) {
1115
+           return $this->service->getsenttablefordel($this->userId);
1116
+    }
1117
+
1118
+    /**
1119
+     * @NoAdminRequired
1120
+     */
1121
+    public function removesentrows($userId, $sentmessagedbIDs) {
1122
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1123
+    }
1124
+
1125
+    /**
1126
+     * @NoAdminRequired
1127
+     */
1128
+    public function getgroupedtable($userId) {
1129
+           return $this->service->getgroupedtable($this->userId);
1130
+    }
1131
+
1132
+    /**
1133
+     * @NoAdminRequired
1134
+     */
1135
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1136
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1137
+    }
1138
+
1139
+    /**
1140
+     * @NoAdminRequired
1141
+     */
1142
+    public function getmessagesperpage($userId) {
1143
+           return $this->service->getmessagesperpage($this->userId);
1144
+    }
1145
+
1146
+    /**
1147
+     * @NoAdminRequired
1148
+     */
1149
+    public function getdelrecsettings($userId) {
1150
+           return $this->service->getdelrecsettings($this->userId);
1151
+    }
1152
+
1153
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1154
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1155
+    }
1156
+
1157
+    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1158
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1159
+    }
1160
+
1161
+    public function removenumberrestrictions($userId, $phoneNumber) {
1162
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1163
+    }
1164
+
1165
+    /**
1166
+     * @NoAdminRequired
1167
+     */
1168
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1169
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1170
+    }
1171
+
1172
+    /**
1173
+     * @NoAdminRequired
1174
+     */
1175
+    public function removeautoreplies($userId, $phoneNumber) {
1176
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1177
+    }
1178
+
1179
+    /**
1180
+     * @NoAdminRequired
1181
+     */
1182
+    public function getsettings($userId) {
1183
+           return $this->service->getsettings($this->userId);
1184
+    }
1185
+
1186
+    public function getadminsettings($userId) {
1187
+           return $this->service->getadminsettings($this->userId);
1188
+    }
1189
+
1190
+    /**
1191
+     * @NoAdminRequired
1192
+     */
1193
+    public function getautoreplyconf($userId) {
1194
+
1195
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1196
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1197
+
1198
+           // Get the display name of the current user
1199
+           $usrid = $this->userId;
1200
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1201
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1202
+	   $getusrdnmdata = $getusrdnmres->fetch();
1203
+	   $userDisplayNm = $getusrdnmdata['value'];
1204
+	   $getusrdnmres->closeCursor();
1205
+
1206
+           // Get the auto-replies for the available phone numbers
1207
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1208
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1209
+	   $getautorplres = $getautorpl->execute();
1210
+           $autorplconf = [];
1211
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1212
+                  $autorplconf[] = $acdatausrdnadm;
1213
+           }
1214
+	   $getautorplres->closeCursor();
1215
+
1216
+           if ($autorplconf) {
1217
+
1218
+               $autoreplyconf = [];
1219
+               foreach ($autorplconf as $arkey => $arvalue) {
1220
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1221
+                            $autoreplyconf[] = $arvalue;
1222
+                        }
1223
+               }
1224
+
1225
+           } else { $autoreplyconf = ''; }
1226
+
1227
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1228
+
1229
+           return $autoreplyfdb;
1230
+    }
1231
+
1232
+    /**
1233
+     * @NoAdminRequired
1234
+     */
1235
+    public function getgroupedpernumber($userId, $phoneNumber) {
1236
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1237
+    }
1238
+
1239
+    /**
1240
+     * @NoAdminRequired
1241
+     */
1242
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1243
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1244
+    }
1245
+
1246
+    /**
1247
+     * @NoAdminRequired
1248
+     */
1249
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames) {
1250
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames);
1251
+    }
1252
+
1253
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1254
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1255
+    }
1256
+
1257
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames) {
1258
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames);
1259
+    }
1260
+}
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php js/sendsms.js

DoubleBastionAdmin authored on 30/05/2023 15:47:20
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1245 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\IURLGenerator;
49
-use OCP\Share\IManager;
50
-use OCP\Constants;
51
-use OCP\IGroupManager;
52
-use OCP\IDBConnection;
53
-use OCP\IUserManager;
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $urlGenerator;
64
-    private $shareManager;
65
-    private $groupManager;
66
-    private $connection;
67
-    private $userManager;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->urlGenerator = $urlGenerator;
78
-	$this->shareManager = $shareManager;
79
-        $this->groupManager = $groupManager;
80
-        $this->connection = $connection;
81
-        $this->userManager = $userManager;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function object_to_array($obj) {
89
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
-        if (is_array($obj)) {
91
-           $new = array();
92
-           foreach($obj as $key => $val) {
93
-               $new[$key] = $this->object_to_array($val);
94
-           }
95
-        }
96
-        else $new = $obj;
97
-        return $new;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function dismount($object) {
105
-        $reflectionClass = new ReflectionClass(get_class($object));
106
-        $array = array();
107
-        foreach ($reflectionClass->getProperties() as $property) {
108
-           $property->setAccessible(true);
109
-           $array[$property->getName()] = $property->getValue($object);
110
-           $property->setAccessible(false);
111
-        }
112
-        return $array;
113
-    }
114
-
115
-
116
-    /**
117
-     * @NoAdminRequired
118
-     */
119
-    public function getbalancetel($userId) {
120
-
121
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
-
123
-        $telapikey = $telsmsapicred[0];
124
-        $ch = curl_init();
125
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
-
127
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
-        $responsetel = curl_exec($ch);
131
-        $recdatatel = json_decode($responsetel, TRUE);
132
-        $telbalresponse = $recdatatel['data']['balance'];
133
-        $currentbalancetel = round(floatval($telbalresponse), 3);
134
-        curl_close($ch);
135
-
136
-        return $currentbalancetel;
137
-    }
138
-
139
-
140
-    /**
141
-     * @NoAdminRequired
142
-     */
143
-    public function getbalancenex($userId) {
144
-
145
-        $smsapicred = $this->service->getapicredentials($this->userId);
146
-        $smsapikey = $smsapicred[5];
147
-        $smsapisecret = $smsapicred[6];
148
-
149
-        if ($smsapikey == '' || $smsapisecret == '') {
150
-            $currentbalancenex = "N/A";
151
-        } else {
152
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
-            $mesdata = file_get_contents($getmesdata);
154
-            $datainit = json_decode($mesdata);
155
-            $balancenex = $datainit->cash_credits;
156
-            $currentbalancenex = round(floatval($balancenex), 3);
157
-        }
158
-        return $currentbalancenex;
159
-    }
160
-
161
-
162
-    /**
163
-     * @NoAdminRequired
164
-     */
165
-    public function getbalancetwil($userId) {
166
-
167
-        $smsapicred = $this->service->getapicredentials($this->userId);
168
-        $smsapisid = $smsapicred[15];
169
-        $smsapitoken = $smsapicred[16];
170
-
171
-        if ($smsapisid == '' || $smsapitoken == '') {
172
-            $currentbalancetwil = "N/A";
173
-        } else {
174
-
175
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
-            $balancetwil = $twilbalance->balance;
177
-
178
-            $currentbalancetwil = round(floatval($balancetwil), 3);
179
-        }
180
-        return $currentbalancetwil;
181
-    }
182
-
183
-
184
-    /**
185
-     * @NoAdminRequired
186
-     */
187
-    public function getbalanceflow($userId) {
188
-
189
-        $currentbalanceflow = 'n/a';
190
-
191
-        return $currentbalanceflow;
192
-    }
193
-
194
-
195
-    /**
196
-     * @NoAdminRequired
197
-     */
198
-    public function getsmsnumbers($userId) {
199
-
200
-        $smsapicred = $this->service->getapicredentials($this->userId);
201
-
202
-        $telnyxkey = $smsapicred[0];
203
-
204
-        $nexapikey = $smsapicred[5];
205
-        $nexapisecret = $smsapicred[6];
206
-
207
-        $twilapikey = $smsapicred[15];
208
-        $twilapisecret = $smsapicred[16];
209
-
210
-        $flowapikey = $smsapicred[20];
211
-        $flowapisecret = $smsapicred[21];
212
-
213
-        $telsendernameinit = $smsapicred[9];
214
-        $nexsendernameinit = $smsapicred[10];
215
-        $twilsendernameinit = $smsapicred[19];
216
-
217
-        if ($telsendernameinit) {
218
-            $telsendername = "Tx: " . $telsendernameinit;
219
-            $telsenderarr = [0 => $telsendername];
220
-        } else { $telsenderarr = []; }
221
-
222
-        if ($nexsendernameinit) {
223
-            $nexsendername = "Pl: " . $nexsendernameinit;
224
-            $nexsenderarr = [0 => $nexsendername];
225
-        } else { $nexsenderarr = []; }
226
-
227
-        if ($twilsendernameinit) {
228
-            $twilsendername = "Tw: " . $twilsendernameinit;
229
-            $twilsenderarr = [0 => $twilsendername];
230
-        } else { $twilsenderarr = []; }
231
-
232
-        // Get Telnyx phone numbers
233
-        if ($telnyxkey != '') {
234
-
235
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
236
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
237
-
238
-           $telnumbersarr = $this->object_to_array($telnumbers);
239
-           $telnmbrs = [];
240
-
241
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
242
-              if (is_int($nmbkey)) {
243
-                 foreach ($nmbvalue as $nkey => $nvalue) {
244
-                    if ($nkey == 'phone_number' && $nvalue) {
245
-                       $telnmbrs[] = "Tx: " . $nvalue;
246
-                    }
247
-                 }
248
-              }
249
-           }
250
-
251
-        } else { $telnmbrs = []; }
252
-
253
-        // Get Plivo phone numbers
254
-        if ($nexapikey != '' && $nexapisecret != '') {
255
-
256
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
257
-           $acdata = file_get_contents($getacdata);
258
-           $datainit = json_decode($acdata, true);
259
-
260
-           $findata = $this->object_to_array($datainit);
261
-
262
-           $nexcurrentnmbrs = [];
263
-
264
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
265
-                   if (is_array($smsvalue)) {
266
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
267
-                               if ($smskey2 == 'number' && $smsvalue2) {
268
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
269
-                               }
270
-                         }
271
-                   }
272
-           }
273
-
274
-
275
-        } else { $nexcurrentnmbrs = []; }
276
-
277
-        // Get Twilio phone numbers
278
-        if ($twilapikey != '' && $twilapisecret != '') {
279
-
280
-            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
281
-            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
282
-
283
-            $twilcurrentnmbrs = [];
284
-            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
285
-                 if (is_array($twnbvalue)) {
286
-                     foreach ($twnbvalue as $twfkey => $twfvalue) {
287
-                          if ($twfkey == 'phone_number' && $twfvalue) {
288
-                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
289
-                          }
290
-                     }
291
-                 }
292
-            }
293
-
294
-        } else { $twilcurrentnmbrs = []; }
295
-
296
-        // Get Flowroute phone numbers
297
-        if ($flowapikey != '' && $flowapisecret != '') {
298
-
299
-            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
300
-            $flnbrsarr = $flnbrsresult->data;
301
-            $flowcurrentnmbrs = [];
302
-            foreach ($flnbrsarr as $flkey => $flitem) {
303
-                     if ($flitem->id) {
304
-                         $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
305
-                     }
306
-            }
307
-
308
-        } else { $flowcurrentnmbrs = []; }
309
-
310
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
311
-
312
-        if ($this->groupManager->isAdmin($this->userId)) {
313
-
314
-            return $currentnmbrs;
315
-
316
-        } else {
317
-
318
-            // Get the restrictions from the 'sms_relent_restrict' table
319
-            $getrestr = $this->connection->prepare('
320
-		       SELECT `phone_number`, `groups`, `users` FROM `*PREFIX*sms_relent_restrict`');
321
-            $getrestrres = $getrestr->execute();
322
-
323
-            $restrdata = [];
324
-            while ($restrfetched = $getrestrres->fetch()) {
325
-                   $restrdata[] = $restrfetched;
326
-            }
327
-            $getrestrres->closeCursor();
328
-
329
-            if ($restrdata) {
330
-
331
-                // Get the groups to which the current user belongs
332
-                $usrId = $this->userId;
333
-                $getusrgrp = $this->connection->prepare('
334
-		       SELECT `gid`, `uid` FROM `*PREFIX*group_user` WHERE `uid` = ?');
335
-                $getusrgrpres = $getusrgrp->execute([$usrId]);
336
-
337
-                $usergrps = [];
338
-                while ($fetchedgrps = $getusrgrpres->fetch()) {
339
-                       $usergrps[] = $fetchedgrps['gid'];
340
-                }
341
-                $getusrgrpres->closeCursor();
342
-                $ctusergroups = implode("|", $usergrps);
343
-
344
-		// Get the Display Name of the current user
345
-		$getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
346
-		$getacdatadnres = $getacdatadn->execute([$usrId, 'displayname']);
347
-		$acdatausrdnadm = $getacdatadnres->fetch();
348
-		$cruserdname = $acdatausrdnadm['value'];
349
-		$getacdatadnres->closeCursor();
350
-
351
-                // Get the phone numbers that are not allowed for the current user
352
-                $restrPhoneNb = [];
353
-                foreach ($restrdata as $rskey => $rsvalue) {
354
-
355
-                        $chck = 0;
356
-                        if ($rsvalue['groups']) {
357
-                            $restrgrparr = explode("|", $rsvalue['groups']);
358
-
359
-                            foreach ($restrgrparr as $grkey => $grvalue) {
360
-                                     if (str_contains($ctusergroups, $grvalue)) { $chck++; }
361
-                            }
362
-                        }
363
-
364
-                        if ($rsvalue['users']) {
365
-                            $usrnmstr = $rsvalue['users'];
366
-                            if (str_contains($usrnmstr, $cruserdname)) { $chck++; }
367
-                        }
368
-
369
-                        if ($chck == 0) { $restrPhoneNb[] = $rsvalue['phone_number']; }
370
-                }
371
-
372
-                $restrPhoneNmbrs = array_unique($restrPhoneNb);
373
-
374
-                // Assemble the array of phone numbers that the current user is allowed to use
375
-                for ($k = 0; $k < count($currentnmbrs); $k++) {
376
-
377
-                    if (in_array($currentnmbrs[$k], $restrPhoneNmbrs)) {
378
-                        unset($currentnmbrs[$k]);
379
-                    }
380
-                }
381
-
382
-                $currentnmbrsrstr = array_values($currentnmbrs);
383
-
384
-                return $currentnmbrsrstr;
385
-
386
-            } else { return $currentnmbrs; }
387
-        }
388
-    }
389
-
390
-
391
-    /**
392
-     * @NoAdminRequired
393
-     */
394
-    public function cleantempdir($userId) {
395
-
396
-        // Create the temporary folder if it doesn't exist
397
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
398
-            $this->folder->newFolder('SMS_Relentless/temp_files');
399
-        }
400
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
401
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
402
-        $fileSystemIterator = new FilesystemIterator($targetdir);
403
-
404
-        $dirfiles = [];
405
-        foreach ($fileSystemIterator as $fileInfo){
406
-                 $dirfiles[] = $fileInfo->getFilename();
407
-        }
408
-
409
-        foreach ($dirfiles as $key => $indfile) {
410
-                 $thisuserroot = $this->view->getRoot();
411
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
412
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
413
-        }
414
-     }
415
-
416
-
417
-    /**
418
-     * @NoAdminRequired
419
-     */
420
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
421
-
422
-        // Create the temporary folder if it doesn't exist
423
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
424
-            $this->folder->newFolder('SMS_Relentless/temp_files');
425
-        }
426
-
427
-        // First delete any file that has been previously uploaded
428
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
429
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
430
-        $fileSystemIterator = new FilesystemIterator($targetdir);
431
-
432
-        $dirfiles = [];
433
-        foreach ($fileSystemIterator as $fileInfo){
434
-                 $dirfiles[] = $fileInfo->getFilename();
435
-        }
436
-
437
-        foreach ($dirfiles as $key => $indfile) {
438
-                 $thisuserroot = $this->view->getRoot();
439
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
440
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
441
-        }
442
-
443
-        // Upload the new file
444
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
445
-        $fileName = $_FILES['uploadfileforsms']['name'];
446
-
447
-        $userroot = $this->view->getRoot();
448
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
449
-
450
-        $target = $this->folder->newFile($targetfile);
451
-        $target->putContent($fileContent);
452
-
453
-        // Extract the phone numbers from the file
454
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
455
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
456
-        $numberarrayfourth = explode(",", $numberarraytert);
457
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
458
-        $numberarray = array_unique($numberarrayfifth);
459
-
460
-        return $numberarray;
461
-    }
462
-
463
-
464
-    /**
465
-     * @NoAdminRequired
466
-     */
467
-    public function uploadfile($uploadfileformms) {
468
-
469
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
470
-           $fileName = $_FILES['uploadfileformms']['name'];
471
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
472
-           $fileSize = $fileSizeinit / 1024;
473
-
474
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
475
-               $this->folder->newFolder('SMS_Relentless/temp_files');
476
-           }
477
-
478
-           $userroot = $this->view->getRoot();
479
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
480
-
481
-           $target = $this->folder->newFile($targetfile);
482
-           $target->putContent($fileContent);
483
-
484
-           // Get the cumulative files size of the uploaded files
485
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
486
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
487
-
488
-           $fileSystemIterator = new FilesystemIterator($targetdir);
489
-
490
-           $dirfiles = [];
491
-           foreach ($fileSystemIterator as $fileInfo){
492
-                    $dirfiles[] = $fileInfo->getFilename();
493
-           }
494
-
495
-           $totalflsizeinit = 0;
496
-           foreach ($dirfiles as $key => $indfile) {
497
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
498
-                    $mbSize = round($fileSizeinit / 1024, 4);
499
-                    $totalflsizeinit += $mbSize;
500
-           }
501
-
502
-           $totalflsize = round($totalflsizeinit, 4);
503
-
504
-           return $totalflsize;
505
-    }
506
-
507
-
508
-    /**
509
-     * @NoAdminRequired
510
-     */
511
-    public function pickfile($path) {
512
-
513
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
514
-               $this->folder->newFolder('SMS_Relentless/temp_files');
515
-           }
516
-
517
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
518
-
519
-           $fltgt = $datadir . $this->userId . "/files" . $path;
520
-
521
-           $fileContent = file_get_contents($fltgt);
522
-
523
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
524
-
525
-           $patharr = explode("/", $path);
526
-
527
-           $revarr = array_reverse($patharr);
528
-
529
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
530
-
531
-           $target = $this->folder->newFile($relflpath);
532
-
533
-           $target->putContent($fileContent);
534
-
535
-           // Get the cumulative files size of the uploaded files
536
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
537
-
538
-           $fileSystemIterator = new FilesystemIterator($targetdir);
539
-
540
-           $dirfiles = [];
541
-           foreach ($fileSystemIterator as $fileInfo) {
542
-                    $dirfiles[] = $fileInfo->getFilename();
543
-           }
544
-
545
-           $totalflsizeinit = 0;
546
-
547
-           foreach ($dirfiles as $key => $indfile) {
548
-
549
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
550
-                    $mbSize = round($fileSizeinit / 1024, 4);
551
-                    $totalflsizeinit += $mbSize;
552
-           }
553
-
554
-           $totalflsize = round($totalflsizeinit, 4);
555
-
556
-           $pickresult = [$totalflsize, $pkfilesize];
557
-
558
-           return $pickresult;
559
-    }
560
-
561
-
562
-    /**
563
-     * @NoAdminRequired
564
-     */
565
-    public function removeupfile($removedfilename) {
566
-
567
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
568
-
569
-           $removefile = $this->view->unlink($tmpfl);
570
-
571
-           // Get the cumulative files size of the uploaded files
572
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
573
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
574
-           $fileSystemIterator = new FilesystemIterator($targetdir);
575
-
576
-           $dirfiles = [];
577
-           foreach ($fileSystemIterator as $fileInfo){
578
-                    $dirfiles[] = $fileInfo->getFilename();
579
-           }
580
-
581
-           $totalflsizeinit = 0;
582
-
583
-           foreach ($dirfiles as $key => $indfile) {
584
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
585
-                    $mbSize = round($fileSizeinit / 1024, 4);
586
-                    $totalflsizeinit += $mbSize;
587
-           }
588
-
589
-           $totalflsize = round($totalflsizeinit, 4);
590
-
591
-           return $totalflsize;
592
-    }
593
-
594
-
595
-    /**
596
-     * @NoAdminRequired
597
-     */
598
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
599
-
600
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
601
-         $telnyxkey = $telsmsapicred[0];
602
-         $teldelrecurl = $telsmsapicred[3];
603
-         $messagingprofid = $telsmsapicred[4];
604
-
605
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
606
-
607
-         $microinterval = $waitinterval * 1000;
608
-
609
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
610
-
611
-             usleep($microinterval);
612
-
613
-             $messagedate = date("Y-m-d H:i:s");
614
-
615
-             if ($ismms == 0) {
616
-
617
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
618
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
619
-                 } else {
620
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
621
-                 }
622
-
623
-                 $messagetexttel = $sentsmstext;
624
-
625
-             } else {
626
-
627
-                 $mediaURLarr = [];
628
-                 $includedMediaFiles = '';
629
-
630
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
631
-
632
-                      $userroot = $this->view->getRoot();
633
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
634
-
635
-                      $flsharetarget = $this->folder->newFile($filetoshare);
636
-
637
-	              $share = $this->shareManager->newShare();
638
-	              $share->setNode($flsharetarget);
639
-	              $share->setPermissions(Constants::PERMISSION_READ);
640
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
641
-	              $share->setSharedBy($this->userId);
642
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
643
-                      $expirydate->add(new \DateInterval('P1D'));
644
-                      $share->setExpirationDate($expirydate);
645
-                      $shared = $this->shareManager->createShare($share);
646
-                      $shareToken = $shared->getToken();
647
-
648
-                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
649
-                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
650
-                 }
651
-
652
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
653
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
654
-                 } else {
655
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
656
-                 }
657
-
658
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
659
-             }
660
-
661
-             $messageid = $message['id'];
662
-             $messagefrom = "Telnyx: " . $fromsender;
663
-             $messageto = $tonumber;
664
-             $messagenetwork = null;
665
-             $messageprice = null;
666
-             $messagestatus = $message['to'][0]['status'];
667
-             $messagedelivery = null;
668
-
669
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
670
-
671
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
672
-         }
673
-
674
-         $crtuser = $this->userManager->get($this->userId);
675
-         $displayname = $crtuser->getDisplayName();
676
-         return $displayname;
677
-    }
678
-
679
-
680
-    /**
681
-     * @NoAdminRequired
682
-     */
683
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
684
-
685
-         $smsapicred = $this->service->getapicredentials($this->userId);
686
-
687
-         $smsapikey = $smsapicred[5];
688
-         $smsapisecret = $smsapicred[6];
689
-         $smsapideliveryrecurl = $smsapicred[8];
690
-
691
-         $microinterval = $waitinterval * 1000;
692
-
693
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
694
-
695
-             usleep($microinterval);
696
-
697
-             $messagedatepl = date("Y-m-d H:i:s");
698
-
699
-             if ($ismms == 0) {
700
-
701
-                 $client = new RestClient($smsapikey, $smsapisecret);
702
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
703
-                 $messagetextpl = $sentsmstext;
704
-	         $messageidinit = $response->getmessageUuid(0);
705
-                 $messageid = $messageidinit[0];
706
-
707
-                 if (property_exists($response, 'error')) { 
708
-                     $messagestatus = "Error: " . $response->error;
709
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
710
-
711
-             } else {
712
-
713
-                 $mediaURLarr = [];
714
-                 $includedMediaFiles = '';
715
-
716
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
717
-
718
-                      $userroot = $this->view->getRoot();
719
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
720
-
721
-                      $flsharetarget = $this->folder->newFile($filetoshare);
722
-
723
-	              $share = $this->shareManager->newShare();
724
-	              $share->setNode($flsharetarget);
725
-	              $share->setPermissions(Constants::PERMISSION_READ);
726
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
727
-	              $share->setSharedBy($this->userId);
728
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
729
-                      $expirydate->add(new \DateInterval('P1D'));
730
-                      $share->setExpirationDate($expirydate);
731
-                      $shared = $this->shareManager->createShare($share);
732
-                      $shareToken = $shared->getToken();
733
-
734
-                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
735
-                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
736
-                 }
737
-
738
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
739
-		 $postedparamspl = json_encode($datatosendpl);
740
-
741
-		 $chpl = curl_init();
742
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
743
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
744
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
745
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
746
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
747
-		 curl_setopt($chpl, CURLOPT_POST, 1);
748
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
749
-		 $resultpl = curl_exec ($chpl);
750
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
751
-		 curl_close ($chpl);
752
-
753
-		 $decresultpl = json_decode($resultpl);
754
-
755
-                 if (property_exists($decresultpl, 'message_uuid')) {
756
-                     $messageidinit = $decresultpl->message_uuid;
757
-                     $messageid = $messageidinit[0];
758
-                 }
759
-
760
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
761
-
762
-                     if (property_exists($decresultpl, 'error')) {
763
-                         $messagestatus = "Error: " . $decresultpl->error;
764
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
765
-
766
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
767
-
768
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
769
-             }
770
-
771
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
772
-                 $messagefrom = "Plivo: " . $fromsender;
773
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
774
-
775
-             $messageto = $tonumber;
776
-             $messagenetwork = '';
777
-             $messageprice = '';
778
-
779
-             $messagedelivery = '';
780
-
781
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
782
-
783
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
784
-         }
785
-
786
-         $crtuser = $this->userManager->get($this->userId);
787
-         $displayname = $crtuser->getDisplayName();
788
-         return $displayname;
789
-    }
790
-
791
-
792
-    /**
793
-     * @NoAdminRequired
794
-     */
795
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
796
-
797
-         $smsapicred = $this->service->getapicredentials($this->userId);
798
-
799
-         $sid = $smsapicred[15];
800
-         $token = $smsapicred[16];
801
-         $smsapirecurltw = $smsapicred[18];
802
-
803
-         $microinterval = $waitinterval * 1000;
804
-
805
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
806
-
807
-             usleep($microinterval);
808
-
809
-             $messagedatetw = date("Y-m-d H:i:s");
810
-
811
-             if ($ismms == 0) {
812
-
813
-                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
814
-                  $sentsmstextfintw = $sentsmstext;
815
-
816
-             } else {
817
-
818
-                 $mediaURLs = [];
819
-
820
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
821
-
822
-                      $userroot = $this->view->getRoot();
823
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
824
-
825
-                      $flsharetarget = $this->folder->newFile($filetoshare);
826
-
827
-	              $share = $this->shareManager->newShare();
828
-	              $share->setNode($flsharetarget);
829
-	              $share->setPermissions(Constants::PERMISSION_READ);
830
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
831
-	              $share->setSharedBy($this->userId);
832
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
833
-                      $expirydate->add(new \DateInterval('P1D'));
834
-                      $share->setExpirationDate($expirydate);
835
-                      $shared = $this->shareManager->createShare($share);
836
-                      $shareToken = $shared->getToken();
837
-
838
-                      $mediaURLs[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
839
-                 }
840
-
841
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
842
-                 $includedMediaFiles = '';
843
-
844
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
845
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
846
-                      $includedMediaFiles .= $mediaURLs[$m] . "<br><br>";
847
-                 }
848
-
849
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
850
-             }
851
-
852
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
853
-
854
-	     $chtw = curl_init();
855
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
856
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
857
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
858
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
859
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
860
-	     curl_setopt($chtw, CURLOPT_POST, 1);
861
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
862
-
863
-	     $resulttw = curl_exec ($chtw);
864
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
865
-	     curl_close ($chtw);
866
-
867
-             $decresulttw = json_decode($resulttw);
868
-
869
-             if ($resulttw) {
870
-                 $messageidtw = $decresulttw->sid;
871
-             } else { $messageidtw = ''; }
872
-
873
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
874
-                 $messagestatustw = 'The message has been accepted for delivery.';
875
-             } else {
876
-                 $messagestatustw = 'An error occurred while trying to send the message.';
877
-             }
878
-
879
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
880
-                 $messagefromtw = "Twilio: " . $fromsender;
881
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
882
-
883
-             $messagenetworktw = '';
884
-             $messagepricetw = '';
885
-             $messagedeliverytw = '';
886
-
887
-
888
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
889
-
890
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
891
-         }
892
-
893
-         $crtuser = $this->userManager->get($this->userId);
894
-         $displayname = $crtuser->getDisplayName();
895
-         return $displayname;
896
-    }
897
-
898
-
899
-    /**
900
-     * @NoAdminRequired
901
-     */
902
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
903
-
904
-         $smsapicredfl = $this->service->getapicredentials($this->userId);
905
-
906
-         $flowapikey = $smsapicredfl[20];
907
-         $flowapisecret = $smsapicredfl[21];
908
-         $flowdelrecurl = $smsapicredfl[23];
909
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
910
-
911
-         $microinterval = $waitinterval * 1000;
912
-
913
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
914
-
915
-             usleep($microinterval);
916
-
917
-             $messagedatefl = date("Y-m-d H:i:s");
918
-
919
-             if ($ismms == 0) {
920
-
921
-                 $messagetextfinfl = $sentsmstext;
922
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
923
-
924
-             } else {
925
-
926
-		 $mediaurlsarr = [];
927
-
928
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
929
-
930
-		      $userroot = $this->view->getRoot();
931
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
932
-
933
-		      $flsharetarget = $this->folder->newFile($filetoshare);
934
-
935
-		      $share = $this->shareManager->newShare();
936
-		      $share->setNode($flsharetarget);
937
-		      $share->setPermissions(Constants::PERMISSION_READ);
938
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
939
-		      $share->setSharedBy($this->userId);
940
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
941
-                      $expirydate->add(new \DateInterval('P1D'));
942
-                      $share->setExpirationDate($expirydate);
943
-		      $shared = $this->shareManager->createShare($share);
944
-		      $shareToken = $shared->getToken();
945
-
946
-		      $mediaurlsarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
947
-		 }
948
-
949
-		 $includedMediaFiles = '';
950
-
951
-		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
952
-		      $includedMediaFiles .= $mediaurlsarr[$m] . "<br><br>";
953
-		 }
954
-
955
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
956
-
957
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
958
-             }
959
-
960
-	     $chfl = curl_init();
961
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
962
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
963
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
964
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
965
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
966
-	     curl_setopt($chfl, CURLOPT_POST, 1);
967
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
968
-	     $resultfl = curl_exec ($chfl);
969
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
970
-	     curl_close ($chfl);
971
-
972
-             $decresultfl = json_decode($resultfl);
973
-
974
-             if ($resultfl) {
975
-                 $messageidfl = $decresultfl->data->id;
976
-             } else { $messageidfl = ''; }
977
-
978
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
979
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
980
-             } else { 
981
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
982
-             }
983
-
984
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
985
-                 $messagefromfl = "Flowroute: " . $fromsender;
986
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
987
-
988
-             $messagetofl = $tonumberfl;
989
-             $messagenetworkfl = '';
990
-             $messagepricefl = '';
991
-             $messagedeliveryfl = '';
992
-
993
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
994
-
995
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
996
-         }
997
-
998
-         $crtuser = $this->userManager->get($this->userId);
999
-         $displayname = $crtuser->getDisplayName();
1000
-         return $displayname;
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * @NoAdminRequired
1006
-     */
1007
-    public function saveoldrecrows($userId, $oldrecRows) {
1008
-
1009
-           // Create the folder for removed messages if it doesn't exist
1010
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
1011
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
1012
-           }
1013
-           $savecheck = 0;
1014
-
1015
-           if (count($oldrecRows) > 1) {
1016
-               $msfileContent = implode("", $oldrecRows);
1017
-
1018
-               $delrowsdate = date("Y-m-d_H-i-s");
1019
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
1020
-
1021
-               $userroot = $this->view->getRoot();
1022
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
1023
-
1024
-               $target = $this->folder->newFile($targetfile);
1025
-               $target->putContent($msfileContent);
1026
-
1027
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
1028
-                   $savecheck = 1;
1029
-               }
1030
-           }
1031
-
1032
-           return $savecheck;
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * @NoAdminRequired
1038
-     */
1039
-    public function saveoldsentrows($userId, $oldsentRows) {
1040
-
1041
-           // Create the folder for removed messages if it doesn't exist
1042
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
1043
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
1044
-           }
1045
-           $savesentcheck = 0;
1046
-
1047
-           if (count($oldsentRows) > 1) {
1048
-               $sntfileContent = implode("", $oldsentRows);
1049
-
1050
-               $delsentrowsdate = date("Y-m-d_H-i-s");
1051
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
1052
-
1053
-               $userroot = $this->view->getRoot();
1054
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
1055
-
1056
-               $snttarget = $this->folder->newFile($snttargetfile);
1057
-               $snttarget->putContent($sntfileContent);
1058
-
1059
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
1060
-                   $savesentcheck = 1;
1061
-               }
1062
-           }
1063
-
1064
-           return $savesentcheck;
1065
-    }
1066
-
1067
-
1068
-    /**
1069
-     * @NoAdminRequired
1070
-     */
1071
-    public function getreceivedtable($userId) {
1072
-           return $this->service->getreceivedtable($this->userId);
1073
-    }
1074
-
1075
-    /**
1076
-     * @NoAdminRequired
1077
-     */
1078
-    public function getreceivedtablefordel($userId) {
1079
-           return $this->service->getreceivedtablefordel($this->userId);
1080
-    }
1081
-
1082
-    /**
1083
-     * @NoAdminRequired
1084
-     */
1085
-    public function removerecrows($userId, $recmessagedbIDs) {
1086
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
1087
-    }
1088
-
1089
-    /**
1090
-     * @NoAdminRequired
1091
-     */
1092
-    public function getsenttable($userId) {
1093
-           return $this->service->getsenttable($this->userId);
1094
-    }
1095
-
1096
-    /**
1097
-     * @NoAdminRequired
1098
-     */
1099
-    public function getsenttablefordel($userId) {
1100
-           return $this->service->getsenttablefordel($this->userId);
1101
-    }
1102
-
1103
-    /**
1104
-     * @NoAdminRequired
1105
-     */
1106
-    public function removesentrows($userId, $sentmessagedbIDs) {
1107
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1108
-    }
1109
-
1110
-    /**
1111
-     * @NoAdminRequired
1112
-     */
1113
-    public function getgroupedtable($userId) {
1114
-           return $this->service->getgroupedtable($this->userId);
1115
-    }
1116
-
1117
-    /**
1118
-     * @NoAdminRequired
1119
-     */
1120
-    public function savedisplayname($userId, $authorDisplayname, $from) {
1121
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1122
-    }
1123
-
1124
-    /**
1125
-     * @NoAdminRequired
1126
-     */
1127
-    public function getmessagesperpage($userId) {
1128
-           return $this->service->getmessagesperpage($this->userId);
1129
-    }
1130
-
1131
-    /**
1132
-     * @NoAdminRequired
1133
-     */
1134
-    public function getdelrecsettings($userId) {
1135
-           return $this->service->getdelrecsettings($this->userId);
1136
-    }
1137
-
1138
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1139
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1140
-    }
1141
-
1142
-    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1143
-           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1144
-    }
1145
-
1146
-    public function removenumberrestrictions($userId, $phoneNumber) {
1147
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1148
-    }
1149
-
1150
-    /**
1151
-     * @NoAdminRequired
1152
-     */
1153
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1154
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1155
-    }
1156
-
1157
-    /**
1158
-     * @NoAdminRequired
1159
-     */
1160
-    public function removeautoreplies($userId, $phoneNumber) {
1161
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1162
-    }
1163
-
1164
-    /**
1165
-     * @NoAdminRequired
1166
-     */
1167
-    public function getsettings($userId) {
1168
-           return $this->service->getsettings($this->userId);
1169
-    }
1170
-
1171
-    public function getadminsettings($userId) {
1172
-           return $this->service->getadminsettings($this->userId);
1173
-    }
1174
-
1175
-    /**
1176
-     * @NoAdminRequired
1177
-     */
1178
-    public function getautoreplyconf($userId) {
1179
-
1180
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1181
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1182
-
1183
-           // Get the display name of the current user
1184
-           $usrid = $this->userId;
1185
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1186
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1187
-	   $getusrdnmdata = $getusrdnmres->fetch();
1188
-	   $userDisplayNm = $getusrdnmdata['value'];
1189
-	   $getusrdnmres->closeCursor();
1190
-
1191
-           // Get the auto-replies for the available phone numbers
1192
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1193
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1194
-	   $getautorplres = $getautorpl->execute();
1195
-           $autorplconf = [];
1196
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1197
-                  $autorplconf[] = $acdatausrdnadm;
1198
-           }
1199
-	   $getautorplres->closeCursor();
1200
-
1201
-           if ($autorplconf) {
1202
-
1203
-               $autoreplyconf = [];
1204
-               foreach ($autorplconf as $arkey => $arvalue) {
1205
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1206
-                            $autoreplyconf[] = $arvalue;
1207
-                        }
1208
-               }
1209
-
1210
-           } else { $autoreplyconf = ''; }
1211
-
1212
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1213
-
1214
-           return $autoreplyfdb;
1215
-    }
1216
-
1217
-    /**
1218
-     * @NoAdminRequired
1219
-     */
1220
-    public function getgroupedpernumber($userId, $phoneNumber) {
1221
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1222
-    }
1223
-
1224
-    /**
1225
-     * @NoAdminRequired
1226
-     */
1227
-    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1228
-           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1229
-    }
1230
-
1231
-    /**
1232
-     * @NoAdminRequired
1233
-     */
1234
-    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames) {
1235
-           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames);
1236
-    }
1237
-
1238
-    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1239
-           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1240
-    }
1241
-
1242
-    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames) {
1243
-           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames);
1244
-    }
1245
-}
Browse code

added files to implement pop-up windows, etc.

DoubleBastionAdmin authored on 20/05/2023 01:06:57
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1245 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\IURLGenerator;
49
+use OCP\Share\IManager;
50
+use OCP\Constants;
51
+use OCP\IGroupManager;
52
+use OCP\IDBConnection;
53
+use OCP\IUserManager;
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $urlGenerator;
64
+    private $shareManager;
65
+    private $groupManager;
66
+    private $connection;
67
+    private $userManager;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection, IUserManager $userManager) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->urlGenerator = $urlGenerator;
78
+	$this->shareManager = $shareManager;
79
+        $this->groupManager = $groupManager;
80
+        $this->connection = $connection;
81
+        $this->userManager = $userManager;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function object_to_array($obj) {
89
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
90
+        if (is_array($obj)) {
91
+           $new = array();
92
+           foreach($obj as $key => $val) {
93
+               $new[$key] = $this->object_to_array($val);
94
+           }
95
+        }
96
+        else $new = $obj;
97
+        return $new;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function dismount($object) {
105
+        $reflectionClass = new ReflectionClass(get_class($object));
106
+        $array = array();
107
+        foreach ($reflectionClass->getProperties() as $property) {
108
+           $property->setAccessible(true);
109
+           $array[$property->getName()] = $property->getValue($object);
110
+           $property->setAccessible(false);
111
+        }
112
+        return $array;
113
+    }
114
+
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     */
119
+    public function getbalancetel($userId) {
120
+
121
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
122
+
123
+        $telapikey = $telsmsapicred[0];
124
+        $ch = curl_init();
125
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
126
+
127
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
128
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
130
+        $responsetel = curl_exec($ch);
131
+        $recdatatel = json_decode($responsetel, TRUE);
132
+        $telbalresponse = $recdatatel['data']['balance'];
133
+        $currentbalancetel = round(floatval($telbalresponse), 3);
134
+        curl_close($ch);
135
+
136
+        return $currentbalancetel;
137
+    }
138
+
139
+
140
+    /**
141
+     * @NoAdminRequired
142
+     */
143
+    public function getbalancenex($userId) {
144
+
145
+        $smsapicred = $this->service->getapicredentials($this->userId);
146
+        $smsapikey = $smsapicred[5];
147
+        $smsapisecret = $smsapicred[6];
148
+
149
+        if ($smsapikey == '' || $smsapisecret == '') {
150
+            $currentbalancenex = "N/A";
151
+        } else {
152
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
153
+            $mesdata = file_get_contents($getmesdata);
154
+            $datainit = json_decode($mesdata);
155
+            $balancenex = $datainit->cash_credits;
156
+            $currentbalancenex = round(floatval($balancenex), 3);
157
+        }
158
+        return $currentbalancenex;
159
+    }
160
+
161
+
162
+    /**
163
+     * @NoAdminRequired
164
+     */
165
+    public function getbalancetwil($userId) {
166
+
167
+        $smsapicred = $this->service->getapicredentials($this->userId);
168
+        $smsapisid = $smsapicred[15];
169
+        $smsapitoken = $smsapicred[16];
170
+
171
+        if ($smsapisid == '' || $smsapitoken == '') {
172
+            $currentbalancetwil = "N/A";
173
+        } else {
174
+
175
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
176
+            $balancetwil = $twilbalance->balance;
177
+
178
+            $currentbalancetwil = round(floatval($balancetwil), 3);
179
+        }
180
+        return $currentbalancetwil;
181
+    }
182
+
183
+
184
+    /**
185
+     * @NoAdminRequired
186
+     */
187
+    public function getbalanceflow($userId) {
188
+
189
+        $currentbalanceflow = 'n/a';
190
+
191
+        return $currentbalanceflow;
192
+    }
193
+
194
+
195
+    /**
196
+     * @NoAdminRequired
197
+     */
198
+    public function getsmsnumbers($userId) {
199
+
200
+        $smsapicred = $this->service->getapicredentials($this->userId);
201
+
202
+        $telnyxkey = $smsapicred[0];
203
+
204
+        $nexapikey = $smsapicred[5];
205
+        $nexapisecret = $smsapicred[6];
206
+
207
+        $twilapikey = $smsapicred[15];
208
+        $twilapisecret = $smsapicred[16];
209
+
210
+        $flowapikey = $smsapicred[20];
211
+        $flowapisecret = $smsapicred[21];
212
+
213
+        $telsendernameinit = $smsapicred[9];
214
+        $nexsendernameinit = $smsapicred[10];
215
+        $twilsendernameinit = $smsapicred[19];
216
+
217
+        if ($telsendernameinit) {
218
+            $telsendername = "Tx: " . $telsendernameinit;
219
+            $telsenderarr = [0 => $telsendername];
220
+        } else { $telsenderarr = []; }
221
+
222
+        if ($nexsendernameinit) {
223
+            $nexsendername = "Pl: " . $nexsendernameinit;
224
+            $nexsenderarr = [0 => $nexsendername];
225
+        } else { $nexsenderarr = []; }
226
+
227
+        if ($twilsendernameinit) {
228
+            $twilsendername = "Tw: " . $twilsendernameinit;
229
+            $twilsenderarr = [0 => $twilsendername];
230
+        } else { $twilsenderarr = []; }
231
+
232
+        // Get Telnyx phone numbers
233
+        if ($telnyxkey != '') {
234
+
235
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
236
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
237
+
238
+           $telnumbersarr = $this->object_to_array($telnumbers);
239
+           $telnmbrs = [];
240
+
241
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
242
+              if (is_int($nmbkey)) {
243
+                 foreach ($nmbvalue as $nkey => $nvalue) {
244
+                    if ($nkey == 'phone_number' && $nvalue) {
245
+                       $telnmbrs[] = "Tx: " . $nvalue;
246
+                    }
247
+                 }
248
+              }
249
+           }
250
+
251
+        } else { $telnmbrs = []; }
252
+
253
+        // Get Plivo phone numbers
254
+        if ($nexapikey != '' && $nexapisecret != '') {
255
+
256
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
257
+           $acdata = file_get_contents($getacdata);
258
+           $datainit = json_decode($acdata, true);
259
+
260
+           $findata = $this->object_to_array($datainit);
261
+
262
+           $nexcurrentnmbrs = [];
263
+
264
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
265
+                   if (is_array($smsvalue)) {
266
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
267
+                               if ($smskey2 == 'number' && $smsvalue2) {
268
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
269
+                               }
270
+                         }
271
+                   }
272
+           }
273
+
274
+
275
+        } else { $nexcurrentnmbrs = []; }
276
+
277
+        // Get Twilio phone numbers
278
+        if ($twilapikey != '' && $twilapisecret != '') {
279
+
280
+            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
281
+            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
282
+
283
+            $twilcurrentnmbrs = [];
284
+            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
285
+                 if (is_array($twnbvalue)) {
286
+                     foreach ($twnbvalue as $twfkey => $twfvalue) {
287
+                          if ($twfkey == 'phone_number' && $twfvalue) {
288
+                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
289
+                          }
290
+                     }
291
+                 }
292
+            }
293
+
294
+        } else { $twilcurrentnmbrs = []; }
295
+
296
+        // Get Flowroute phone numbers
297
+        if ($flowapikey != '' && $flowapisecret != '') {
298
+
299
+            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
300
+            $flnbrsarr = $flnbrsresult->data;
301
+            $flowcurrentnmbrs = [];
302
+            foreach ($flnbrsarr as $flkey => $flitem) {
303
+                     if ($flitem->id) {
304
+                         $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
305
+                     }
306
+            }
307
+
308
+        } else { $flowcurrentnmbrs = []; }
309
+
310
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
311
+
312
+        if ($this->groupManager->isAdmin($this->userId)) {
313
+
314
+            return $currentnmbrs;
315
+
316
+        } else {
317
+
318
+            // Get the restrictions from the 'sms_relent_restrict' table
319
+            $getrestr = $this->connection->prepare('
320
+		       SELECT `phone_number`, `groups`, `users` FROM `*PREFIX*sms_relent_restrict`');
321
+            $getrestrres = $getrestr->execute();
322
+
323
+            $restrdata = [];
324
+            while ($restrfetched = $getrestrres->fetch()) {
325
+                   $restrdata[] = $restrfetched;
326
+            }
327
+            $getrestrres->closeCursor();
328
+
329
+            if ($restrdata) {
330
+
331
+                // Get the groups to which the current user belongs
332
+                $usrId = $this->userId;
333
+                $getusrgrp = $this->connection->prepare('
334
+		       SELECT `gid`, `uid` FROM `*PREFIX*group_user` WHERE `uid` = ?');
335
+                $getusrgrpres = $getusrgrp->execute([$usrId]);
336
+
337
+                $usergrps = [];
338
+                while ($fetchedgrps = $getusrgrpres->fetch()) {
339
+                       $usergrps[] = $fetchedgrps['gid'];
340
+                }
341
+                $getusrgrpres->closeCursor();
342
+                $ctusergroups = implode("|", $usergrps);
343
+
344
+		// Get the Display Name of the current user
345
+		$getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
346
+		$getacdatadnres = $getacdatadn->execute([$usrId, 'displayname']);
347
+		$acdatausrdnadm = $getacdatadnres->fetch();
348
+		$cruserdname = $acdatausrdnadm['value'];
349
+		$getacdatadnres->closeCursor();
350
+
351
+                // Get the phone numbers that are not allowed for the current user
352
+                $restrPhoneNb = [];
353
+                foreach ($restrdata as $rskey => $rsvalue) {
354
+
355
+                        $chck = 0;
356
+                        if ($rsvalue['groups']) {
357
+                            $restrgrparr = explode("|", $rsvalue['groups']);
358
+
359
+                            foreach ($restrgrparr as $grkey => $grvalue) {
360
+                                     if (str_contains($ctusergroups, $grvalue)) { $chck++; }
361
+                            }
362
+                        }
363
+
364
+                        if ($rsvalue['users']) {
365
+                            $usrnmstr = $rsvalue['users'];
366
+                            if (str_contains($usrnmstr, $cruserdname)) { $chck++; }
367
+                        }
368
+
369
+                        if ($chck == 0) { $restrPhoneNb[] = $rsvalue['phone_number']; }
370
+                }
371
+
372
+                $restrPhoneNmbrs = array_unique($restrPhoneNb);
373
+
374
+                // Assemble the array of phone numbers that the current user is allowed to use
375
+                for ($k = 0; $k < count($currentnmbrs); $k++) {
376
+
377
+                    if (in_array($currentnmbrs[$k], $restrPhoneNmbrs)) {
378
+                        unset($currentnmbrs[$k]);
379
+                    }
380
+                }
381
+
382
+                $currentnmbrsrstr = array_values($currentnmbrs);
383
+
384
+                return $currentnmbrsrstr;
385
+
386
+            } else { return $currentnmbrs; }
387
+        }
388
+    }
389
+
390
+
391
+    /**
392
+     * @NoAdminRequired
393
+     */
394
+    public function cleantempdir($userId) {
395
+
396
+        // Create the temporary folder if it doesn't exist
397
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
398
+            $this->folder->newFolder('SMS_Relentless/temp_files');
399
+        }
400
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
401
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
402
+        $fileSystemIterator = new FilesystemIterator($targetdir);
403
+
404
+        $dirfiles = [];
405
+        foreach ($fileSystemIterator as $fileInfo){
406
+                 $dirfiles[] = $fileInfo->getFilename();
407
+        }
408
+
409
+        foreach ($dirfiles as $key => $indfile) {
410
+                 $thisuserroot = $this->view->getRoot();
411
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
412
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
413
+        }
414
+     }
415
+
416
+
417
+    /**
418
+     * @NoAdminRequired
419
+     */
420
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
421
+
422
+        // Create the temporary folder if it doesn't exist
423
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
424
+            $this->folder->newFolder('SMS_Relentless/temp_files');
425
+        }
426
+
427
+        // First delete any file that has been previously uploaded
428
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
429
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
430
+        $fileSystemIterator = new FilesystemIterator($targetdir);
431
+
432
+        $dirfiles = [];
433
+        foreach ($fileSystemIterator as $fileInfo){
434
+                 $dirfiles[] = $fileInfo->getFilename();
435
+        }
436
+
437
+        foreach ($dirfiles as $key => $indfile) {
438
+                 $thisuserroot = $this->view->getRoot();
439
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
440
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
441
+        }
442
+
443
+        // Upload the new file
444
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
445
+        $fileName = $_FILES['uploadfileforsms']['name'];
446
+
447
+        $userroot = $this->view->getRoot();
448
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
449
+
450
+        $target = $this->folder->newFile($targetfile);
451
+        $target->putContent($fileContent);
452
+
453
+        // Extract the phone numbers from the file
454
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
455
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
456
+        $numberarrayfourth = explode(",", $numberarraytert);
457
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
458
+        $numberarray = array_unique($numberarrayfifth);
459
+
460
+        return $numberarray;
461
+    }
462
+
463
+
464
+    /**
465
+     * @NoAdminRequired
466
+     */
467
+    public function uploadfile($uploadfileformms) {
468
+
469
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
470
+           $fileName = $_FILES['uploadfileformms']['name'];
471
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
472
+           $fileSize = $fileSizeinit / 1024;
473
+
474
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
475
+               $this->folder->newFolder('SMS_Relentless/temp_files');
476
+           }
477
+
478
+           $userroot = $this->view->getRoot();
479
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
480
+
481
+           $target = $this->folder->newFile($targetfile);
482
+           $target->putContent($fileContent);
483
+
484
+           // Get the cumulative files size of the uploaded files
485
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
486
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
487
+
488
+           $fileSystemIterator = new FilesystemIterator($targetdir);
489
+
490
+           $dirfiles = [];
491
+           foreach ($fileSystemIterator as $fileInfo){
492
+                    $dirfiles[] = $fileInfo->getFilename();
493
+           }
494
+
495
+           $totalflsizeinit = 0;
496
+           foreach ($dirfiles as $key => $indfile) {
497
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
498
+                    $mbSize = round($fileSizeinit / 1024, 4);
499
+                    $totalflsizeinit += $mbSize;
500
+           }
501
+
502
+           $totalflsize = round($totalflsizeinit, 4);
503
+
504
+           return $totalflsize;
505
+    }
506
+
507
+
508
+    /**
509
+     * @NoAdminRequired
510
+     */
511
+    public function pickfile($path) {
512
+
513
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
514
+               $this->folder->newFolder('SMS_Relentless/temp_files');
515
+           }
516
+
517
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
518
+
519
+           $fltgt = $datadir . $this->userId . "/files" . $path;
520
+
521
+           $fileContent = file_get_contents($fltgt);
522
+
523
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
524
+
525
+           $patharr = explode("/", $path);
526
+
527
+           $revarr = array_reverse($patharr);
528
+
529
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
530
+
531
+           $target = $this->folder->newFile($relflpath);
532
+
533
+           $target->putContent($fileContent);
534
+
535
+           // Get the cumulative files size of the uploaded files
536
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
537
+
538
+           $fileSystemIterator = new FilesystemIterator($targetdir);
539
+
540
+           $dirfiles = [];
541
+           foreach ($fileSystemIterator as $fileInfo) {
542
+                    $dirfiles[] = $fileInfo->getFilename();
543
+           }
544
+
545
+           $totalflsizeinit = 0;
546
+
547
+           foreach ($dirfiles as $key => $indfile) {
548
+
549
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
550
+                    $mbSize = round($fileSizeinit / 1024, 4);
551
+                    $totalflsizeinit += $mbSize;
552
+           }
553
+
554
+           $totalflsize = round($totalflsizeinit, 4);
555
+
556
+           $pickresult = [$totalflsize, $pkfilesize];
557
+
558
+           return $pickresult;
559
+    }
560
+
561
+
562
+    /**
563
+     * @NoAdminRequired
564
+     */
565
+    public function removeupfile($removedfilename) {
566
+
567
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
568
+
569
+           $removefile = $this->view->unlink($tmpfl);
570
+
571
+           // Get the cumulative files size of the uploaded files
572
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
573
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
574
+           $fileSystemIterator = new FilesystemIterator($targetdir);
575
+
576
+           $dirfiles = [];
577
+           foreach ($fileSystemIterator as $fileInfo){
578
+                    $dirfiles[] = $fileInfo->getFilename();
579
+           }
580
+
581
+           $totalflsizeinit = 0;
582
+
583
+           foreach ($dirfiles as $key => $indfile) {
584
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
585
+                    $mbSize = round($fileSizeinit / 1024, 4);
586
+                    $totalflsizeinit += $mbSize;
587
+           }
588
+
589
+           $totalflsize = round($totalflsizeinit, 4);
590
+
591
+           return $totalflsize;
592
+    }
593
+
594
+
595
+    /**
596
+     * @NoAdminRequired
597
+     */
598
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
599
+
600
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
601
+         $telnyxkey = $telsmsapicred[0];
602
+         $teldelrecurl = $telsmsapicred[3];
603
+         $messagingprofid = $telsmsapicred[4];
604
+
605
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
606
+
607
+         $microinterval = $waitinterval * 1000;
608
+
609
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
610
+
611
+             usleep($microinterval);
612
+
613
+             $messagedate = date("Y-m-d H:i:s");
614
+
615
+             if ($ismms == 0) {
616
+
617
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
618
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
619
+                 } else {
620
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
621
+                 }
622
+
623
+                 $messagetexttel = $sentsmstext;
624
+
625
+             } else {
626
+
627
+                 $mediaURLarr = [];
628
+                 $includedMediaFiles = '';
629
+
630
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
631
+
632
+                      $userroot = $this->view->getRoot();
633
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
634
+
635
+                      $flsharetarget = $this->folder->newFile($filetoshare);
636
+
637
+	              $share = $this->shareManager->newShare();
638
+	              $share->setNode($flsharetarget);
639
+	              $share->setPermissions(Constants::PERMISSION_READ);
640
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
641
+	              $share->setSharedBy($this->userId);
642
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
643
+                      $expirydate->add(new \DateInterval('P1D'));
644
+                      $share->setExpirationDate($expirydate);
645
+                      $shared = $this->shareManager->createShare($share);
646
+                      $shareToken = $shared->getToken();
647
+
648
+                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
649
+                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
650
+                 }
651
+
652
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
653
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
654
+                 } else {
655
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
656
+                 }
657
+
658
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
659
+             }
660
+
661
+             $messageid = $message['id'];
662
+             $messagefrom = "Telnyx: " . $fromsender;
663
+             $messageto = $tonumber;
664
+             $messagenetwork = null;
665
+             $messageprice = null;
666
+             $messagestatus = $message['to'][0]['status'];
667
+             $messagedelivery = null;
668
+
669
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
670
+
671
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
672
+         }
673
+
674
+         $crtuser = $this->userManager->get($this->userId);
675
+         $displayname = $crtuser->getDisplayName();
676
+         return $displayname;
677
+    }
678
+
679
+
680
+    /**
681
+     * @NoAdminRequired
682
+     */
683
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
684
+
685
+         $smsapicred = $this->service->getapicredentials($this->userId);
686
+
687
+         $smsapikey = $smsapicred[5];
688
+         $smsapisecret = $smsapicred[6];
689
+         $smsapideliveryrecurl = $smsapicred[8];
690
+
691
+         $microinterval = $waitinterval * 1000;
692
+
693
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
694
+
695
+             usleep($microinterval);
696
+
697
+             $messagedatepl = date("Y-m-d H:i:s");
698
+
699
+             if ($ismms == 0) {
700
+
701
+                 $client = new RestClient($smsapikey, $smsapisecret);
702
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
703
+                 $messagetextpl = $sentsmstext;
704
+	         $messageidinit = $response->getmessageUuid(0);
705
+                 $messageid = $messageidinit[0];
706
+
707
+                 if (property_exists($response, 'error')) { 
708
+                     $messagestatus = "Error: " . $response->error;
709
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
710
+
711
+             } else {
712
+
713
+                 $mediaURLarr = [];
714
+                 $includedMediaFiles = '';
715
+
716
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
717
+
718
+                      $userroot = $this->view->getRoot();
719
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
720
+
721
+                      $flsharetarget = $this->folder->newFile($filetoshare);
722
+
723
+	              $share = $this->shareManager->newShare();
724
+	              $share->setNode($flsharetarget);
725
+	              $share->setPermissions(Constants::PERMISSION_READ);
726
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
727
+	              $share->setSharedBy($this->userId);
728
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
729
+                      $expirydate->add(new \DateInterval('P1D'));
730
+                      $share->setExpirationDate($expirydate);
731
+                      $shared = $this->shareManager->createShare($share);
732
+                      $shareToken = $shared->getToken();
733
+
734
+                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
735
+                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
736
+                 }
737
+
738
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
739
+		 $postedparamspl = json_encode($datatosendpl);
740
+
741
+		 $chpl = curl_init();
742
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
743
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
744
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
745
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
746
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
747
+		 curl_setopt($chpl, CURLOPT_POST, 1);
748
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
749
+		 $resultpl = curl_exec ($chpl);
750
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
751
+		 curl_close ($chpl);
752
+
753
+		 $decresultpl = json_decode($resultpl);
754
+
755
+                 if (property_exists($decresultpl, 'message_uuid')) {
756
+                     $messageidinit = $decresultpl->message_uuid;
757
+                     $messageid = $messageidinit[0];
758
+                 }
759
+
760
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
761
+
762
+                     if (property_exists($decresultpl, 'error')) {
763
+                         $messagestatus = "Error: " . $decresultpl->error;
764
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
765
+
766
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
767
+
768
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
769
+             }
770
+
771
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
772
+                 $messagefrom = "Plivo: " . $fromsender;
773
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
774
+
775
+             $messageto = $tonumber;
776
+             $messagenetwork = '';
777
+             $messageprice = '';
778
+
779
+             $messagedelivery = '';
780
+
781
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
782
+
783
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
784
+         }
785
+
786
+         $crtuser = $this->userManager->get($this->userId);
787
+         $displayname = $crtuser->getDisplayName();
788
+         return $displayname;
789
+    }
790
+
791
+
792
+    /**
793
+     * @NoAdminRequired
794
+     */
795
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
796
+
797
+         $smsapicred = $this->service->getapicredentials($this->userId);
798
+
799
+         $sid = $smsapicred[15];
800
+         $token = $smsapicred[16];
801
+         $smsapirecurltw = $smsapicred[18];
802
+
803
+         $microinterval = $waitinterval * 1000;
804
+
805
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
806
+
807
+             usleep($microinterval);
808
+
809
+             $messagedatetw = date("Y-m-d H:i:s");
810
+
811
+             if ($ismms == 0) {
812
+
813
+                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
814
+                  $sentsmstextfintw = $sentsmstext;
815
+
816
+             } else {
817
+
818
+                 $mediaURLs = [];
819
+
820
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
821
+
822
+                      $userroot = $this->view->getRoot();
823
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
824
+
825
+                      $flsharetarget = $this->folder->newFile($filetoshare);
826
+
827
+	              $share = $this->shareManager->newShare();
828
+	              $share->setNode($flsharetarget);
829
+	              $share->setPermissions(Constants::PERMISSION_READ);
830
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
831
+	              $share->setSharedBy($this->userId);
832
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
833
+                      $expirydate->add(new \DateInterval('P1D'));
834
+                      $share->setExpirationDate($expirydate);
835
+                      $shared = $this->shareManager->createShare($share);
836
+                      $shareToken = $shared->getToken();
837
+
838
+                      $mediaURLs[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
839
+                 }
840
+
841
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
842
+                 $includedMediaFiles = '';
843
+
844
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
845
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
846
+                      $includedMediaFiles .= $mediaURLs[$m] . "<br><br>";
847
+                 }
848
+
849
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
850
+             }
851
+
852
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
853
+
854
+	     $chtw = curl_init();
855
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
856
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
857
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
858
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
859
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
860
+	     curl_setopt($chtw, CURLOPT_POST, 1);
861
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
862
+
863
+	     $resulttw = curl_exec ($chtw);
864
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
865
+	     curl_close ($chtw);
866
+
867
+             $decresulttw = json_decode($resulttw);
868
+
869
+             if ($resulttw) {
870
+                 $messageidtw = $decresulttw->sid;
871
+             } else { $messageidtw = ''; }
872
+
873
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
874
+                 $messagestatustw = 'The message has been accepted for delivery.';
875
+             } else {
876
+                 $messagestatustw = 'An error occurred while trying to send the message.';
877
+             }
878
+
879
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
880
+                 $messagefromtw = "Twilio: " . $fromsender;
881
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
882
+
883
+             $messagenetworktw = '';
884
+             $messagepricetw = '';
885
+             $messagedeliverytw = '';
886
+
887
+
888
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
889
+
890
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
891
+         }
892
+
893
+         $crtuser = $this->userManager->get($this->userId);
894
+         $displayname = $crtuser->getDisplayName();
895
+         return $displayname;
896
+    }
897
+
898
+
899
+    /**
900
+     * @NoAdminRequired
901
+     */
902
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
903
+
904
+         $smsapicredfl = $this->service->getapicredentials($this->userId);
905
+
906
+         $flowapikey = $smsapicredfl[20];
907
+         $flowapisecret = $smsapicredfl[21];
908
+         $flowdelrecurl = $smsapicredfl[23];
909
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
910
+
911
+         $microinterval = $waitinterval * 1000;
912
+
913
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
914
+
915
+             usleep($microinterval);
916
+
917
+             $messagedatefl = date("Y-m-d H:i:s");
918
+
919
+             if ($ismms == 0) {
920
+
921
+                 $messagetextfinfl = $sentsmstext;
922
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
923
+
924
+             } else {
925
+
926
+		 $mediaurlsarr = [];
927
+
928
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
929
+
930
+		      $userroot = $this->view->getRoot();
931
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
932
+
933
+		      $flsharetarget = $this->folder->newFile($filetoshare);
934
+
935
+		      $share = $this->shareManager->newShare();
936
+		      $share->setNode($flsharetarget);
937
+		      $share->setPermissions(Constants::PERMISSION_READ);
938
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
939
+		      $share->setSharedBy($this->userId);
940
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
941
+                      $expirydate->add(new \DateInterval('P1D'));
942
+                      $share->setExpirationDate($expirydate);
943
+		      $shared = $this->shareManager->createShare($share);
944
+		      $shareToken = $shared->getToken();
945
+
946
+		      $mediaurlsarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
947
+		 }
948
+
949
+		 $includedMediaFiles = '';
950
+
951
+		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
952
+		      $includedMediaFiles .= $mediaurlsarr[$m] . "<br><br>";
953
+		 }
954
+
955
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
956
+
957
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
958
+             }
959
+
960
+	     $chfl = curl_init();
961
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
962
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
963
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
964
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
965
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
966
+	     curl_setopt($chfl, CURLOPT_POST, 1);
967
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
968
+	     $resultfl = curl_exec ($chfl);
969
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
970
+	     curl_close ($chfl);
971
+
972
+             $decresultfl = json_decode($resultfl);
973
+
974
+             if ($resultfl) {
975
+                 $messageidfl = $decresultfl->data->id;
976
+             } else { $messageidfl = ''; }
977
+
978
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
979
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
980
+             } else { 
981
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
982
+             }
983
+
984
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
985
+                 $messagefromfl = "Flowroute: " . $fromsender;
986
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
987
+
988
+             $messagetofl = $tonumberfl;
989
+             $messagenetworkfl = '';
990
+             $messagepricefl = '';
991
+             $messagedeliveryfl = '';
992
+
993
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
994
+
995
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
996
+         }
997
+
998
+         $crtuser = $this->userManager->get($this->userId);
999
+         $displayname = $crtuser->getDisplayName();
1000
+         return $displayname;
1001
+    }
1002
+
1003
+
1004
+    /**
1005
+     * @NoAdminRequired
1006
+     */
1007
+    public function saveoldrecrows($userId, $oldrecRows) {
1008
+
1009
+           // Create the folder for removed messages if it doesn't exist
1010
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
1011
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
1012
+           }
1013
+           $savecheck = 0;
1014
+
1015
+           if (count($oldrecRows) > 1) {
1016
+               $msfileContent = implode("", $oldrecRows);
1017
+
1018
+               $delrowsdate = date("Y-m-d_H-i-s");
1019
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
1020
+
1021
+               $userroot = $this->view->getRoot();
1022
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
1023
+
1024
+               $target = $this->folder->newFile($targetfile);
1025
+               $target->putContent($msfileContent);
1026
+
1027
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
1028
+                   $savecheck = 1;
1029
+               }
1030
+           }
1031
+
1032
+           return $savecheck;
1033
+    }
1034
+
1035
+
1036
+    /**
1037
+     * @NoAdminRequired
1038
+     */
1039
+    public function saveoldsentrows($userId, $oldsentRows) {
1040
+
1041
+           // Create the folder for removed messages if it doesn't exist
1042
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
1043
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
1044
+           }
1045
+           $savesentcheck = 0;
1046
+
1047
+           if (count($oldsentRows) > 1) {
1048
+               $sntfileContent = implode("", $oldsentRows);
1049
+
1050
+               $delsentrowsdate = date("Y-m-d_H-i-s");
1051
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
1052
+
1053
+               $userroot = $this->view->getRoot();
1054
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
1055
+
1056
+               $snttarget = $this->folder->newFile($snttargetfile);
1057
+               $snttarget->putContent($sntfileContent);
1058
+
1059
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
1060
+                   $savesentcheck = 1;
1061
+               }
1062
+           }
1063
+
1064
+           return $savesentcheck;
1065
+    }
1066
+
1067
+
1068
+    /**
1069
+     * @NoAdminRequired
1070
+     */
1071
+    public function getreceivedtable($userId) {
1072
+           return $this->service->getreceivedtable($this->userId);
1073
+    }
1074
+
1075
+    /**
1076
+     * @NoAdminRequired
1077
+     */
1078
+    public function getreceivedtablefordel($userId) {
1079
+           return $this->service->getreceivedtablefordel($this->userId);
1080
+    }
1081
+
1082
+    /**
1083
+     * @NoAdminRequired
1084
+     */
1085
+    public function removerecrows($userId, $recmessagedbIDs) {
1086
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
1087
+    }
1088
+
1089
+    /**
1090
+     * @NoAdminRequired
1091
+     */
1092
+    public function getsenttable($userId) {
1093
+           return $this->service->getsenttable($this->userId);
1094
+    }
1095
+
1096
+    /**
1097
+     * @NoAdminRequired
1098
+     */
1099
+    public function getsenttablefordel($userId) {
1100
+           return $this->service->getsenttablefordel($this->userId);
1101
+    }
1102
+
1103
+    /**
1104
+     * @NoAdminRequired
1105
+     */
1106
+    public function removesentrows($userId, $sentmessagedbIDs) {
1107
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1108
+    }
1109
+
1110
+    /**
1111
+     * @NoAdminRequired
1112
+     */
1113
+    public function getgroupedtable($userId) {
1114
+           return $this->service->getgroupedtable($this->userId);
1115
+    }
1116
+
1117
+    /**
1118
+     * @NoAdminRequired
1119
+     */
1120
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1121
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1122
+    }
1123
+
1124
+    /**
1125
+     * @NoAdminRequired
1126
+     */
1127
+    public function getmessagesperpage($userId) {
1128
+           return $this->service->getmessagesperpage($this->userId);
1129
+    }
1130
+
1131
+    /**
1132
+     * @NoAdminRequired
1133
+     */
1134
+    public function getdelrecsettings($userId) {
1135
+           return $this->service->getdelrecsettings($this->userId);
1136
+    }
1137
+
1138
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1139
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1140
+    }
1141
+
1142
+    public function updatekeysallowedusers($userId, $groups, $users, $provider) {
1143
+           return $this->service->updatekeysallowedusers($this->userId, $groups, $users, $provider);
1144
+    }
1145
+
1146
+    public function removenumberrestrictions($userId, $phoneNumber) {
1147
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1148
+    }
1149
+
1150
+    /**
1151
+     * @NoAdminRequired
1152
+     */
1153
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1154
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1155
+    }
1156
+
1157
+    /**
1158
+     * @NoAdminRequired
1159
+     */
1160
+    public function removeautoreplies($userId, $phoneNumber) {
1161
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1162
+    }
1163
+
1164
+    /**
1165
+     * @NoAdminRequired
1166
+     */
1167
+    public function getsettings($userId) {
1168
+           return $this->service->getsettings($this->userId);
1169
+    }
1170
+
1171
+    public function getadminsettings($userId) {
1172
+           return $this->service->getadminsettings($this->userId);
1173
+    }
1174
+
1175
+    /**
1176
+     * @NoAdminRequired
1177
+     */
1178
+    public function getautoreplyconf($userId) {
1179
+
1180
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1181
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1182
+
1183
+           // Get the display name of the current user
1184
+           $usrid = $this->userId;
1185
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1186
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1187
+	   $getusrdnmdata = $getusrdnmres->fetch();
1188
+	   $userDisplayNm = $getusrdnmdata['value'];
1189
+	   $getusrdnmres->closeCursor();
1190
+
1191
+           // Get the auto-replies for the available phone numbers
1192
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1193
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1194
+	   $getautorplres = $getautorpl->execute();
1195
+           $autorplconf = [];
1196
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1197
+                  $autorplconf[] = $acdatausrdnadm;
1198
+           }
1199
+	   $getautorplres->closeCursor();
1200
+
1201
+           if ($autorplconf) {
1202
+
1203
+               $autoreplyconf = [];
1204
+               foreach ($autorplconf as $arkey => $arvalue) {
1205
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1206
+                            $autoreplyconf[] = $arvalue;
1207
+                        }
1208
+               }
1209
+
1210
+           } else { $autoreplyconf = ''; }
1211
+
1212
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1213
+
1214
+           return $autoreplyfdb;
1215
+    }
1216
+
1217
+    /**
1218
+     * @NoAdminRequired
1219
+     */
1220
+    public function getgroupedpernumber($userId, $phoneNumber) {
1221
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1222
+    }
1223
+
1224
+    /**
1225
+     * @NoAdminRequired
1226
+     */
1227
+    public function getgroupedforreply($userId, $phoneNmbrFrom, $phoneNmbrTo) {
1228
+           return $this->service->getgroupedforreply($this->userId, $phoneNmbrFrom, $phoneNmbrTo);
1229
+    }
1230
+
1231
+    /**
1232
+     * @NoAdminRequired
1233
+     */
1234
+    public function updatesettings($userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames) {
1235
+           return $this->service->updatesettings($this->userId, $telapiUrlRec, $telapiUrl, $nexapiUrlRec, $nexapiUrl, $twilapiUrlRec, $twilapiUrl, $flowapiUrlRec, $flowapiUrl, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames);
1236
+    }
1237
+
1238
+    public function updateadminsettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages) {
1239
+           return $this->service->updateadminsettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showAllMessages);
1240
+    }
1241
+
1242
+    public function updatepersadmnsettings($userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames) {
1243
+           return $this->service->updatepersadmnsettings($this->userId, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $showDisplayNames);
1244
+    }
1245
+}
Browse code

removed files to implement auto-reply fix, etc.

DoubleBastionAdmin authored on 20/05/2023 00:46:30
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1210 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\IURLGenerator;
49
-use OCP\Share\IManager;
50
-use OCP\Constants;
51
-use OCP\IGroupManager;
52
-use OCP\IDBConnection;
53
-
54
-
55
-class SmsrelentlessController extends Controller {
56
-
57
-    private $service;
58
-    private $config;
59
-    private $userId;
60
-    private $folder;
61
-    private $filesystem;
62
-    private $view;
63
-    private $urlGenerator;
64
-    private $shareManager;
65
-
66
-    private $groupManager;
67
-    private $connection;
68
-
69
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection) {
70
-        parent::__construct($appName, $request);
71
-        $this->service = $service;
72
-        $this->config = $config;
73
-        $this->userId = $userId;
74
-        $this->folder = $folder;
75
-        $this->filesystem = $filesystem;
76
-        $this->view = $view;
77
-	$this->urlGenerator = $urlGenerator;
78
-	$this->shareManager = $shareManager;
79
-        $this->groupManager = $groupManager;
80
-        $this->connection = $connection;
81
-    }
82
-
83
-
84
-    /**
85
-     * @NoAdminRequired
86
-     */
87
-    public function object_to_array($obj) {
88
-        if (is_object($obj)) $obj = (array)$this->dismount($obj);
89
-        if (is_array($obj)) {
90
-           $new = array();
91
-           foreach($obj as $key => $val) {
92
-               $new[$key] = $this->object_to_array($val);
93
-           }
94
-        }
95
-        else $new = $obj;
96
-        return $new;
97
-    }
98
-
99
-
100
-    /**
101
-     * @NoAdminRequired
102
-     */
103
-    public function dismount($object) {
104
-        $reflectionClass = new ReflectionClass(get_class($object));
105
-        $array = array();
106
-        foreach ($reflectionClass->getProperties() as $property) {
107
-           $property->setAccessible(true);
108
-           $array[$property->getName()] = $property->getValue($object);
109
-           $property->setAccessible(false);
110
-        }
111
-        return $array;
112
-    }
113
-
114
-
115
-    /**
116
-     * @NoAdminRequired
117
-     */
118
-    public function getbalancetel($userId) {
119
-
120
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
121
-
122
-        $telapikey = $telsmsapicred[0];
123
-        $ch = curl_init();
124
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
125
-
126
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
127
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
128
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
129
-        $responsetel = curl_exec($ch);
130
-        $recdatatel = json_decode($responsetel, TRUE);
131
-        $telbalresponse = $recdatatel['data']['balance'];
132
-        $currentbalancetel = round(floatval($telbalresponse), 3);
133
-        curl_close($ch);
134
-
135
-        return $currentbalancetel;
136
-    }
137
-
138
-
139
-    /**
140
-     * @NoAdminRequired
141
-     */
142
-    public function getbalancenex($userId) {
143
-
144
-        $smsapicred = $this->service->getapicredentials($this->userId);
145
-        $smsapikey = $smsapicred[5];
146
-        $smsapisecret = $smsapicred[6];
147
-
148
-        if ($smsapikey == '' || $smsapisecret == '') {
149
-            $currentbalancenex = "N/A";
150
-        } else {
151
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
152
-            $mesdata = file_get_contents($getmesdata);
153
-            $datainit = json_decode($mesdata);
154
-            $balancenex = $datainit->cash_credits;
155
-            $currentbalancenex = round(floatval($balancenex), 3);
156
-        }
157
-        return $currentbalancenex;
158
-    }
159
-
160
-
161
-    /**
162
-     * @NoAdminRequired
163
-     */
164
-    public function getbalancetwil($userId) {
165
-
166
-        $smsapicred = $this->service->getapicredentials($this->userId);
167
-        $smsapisid = $smsapicred[15];
168
-        $smsapitoken = $smsapicred[16];
169
-
170
-        if ($smsapisid == '' || $smsapitoken == '') {
171
-            $currentbalancetwil = "N/A";
172
-        } else {
173
-
174
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
175
-            $balancetwil = $twilbalance->balance;
176
-
177
-            $currentbalancetwil = round(floatval($balancetwil), 3);
178
-        }
179
-        return $currentbalancetwil;
180
-    }
181
-
182
-
183
-    /**
184
-     * @NoAdminRequired
185
-     */
186
-    public function getbalanceflow($userId) {
187
-
188
-        $currentbalanceflow = 'n/a';
189
-
190
-        return $currentbalanceflow;
191
-    }
192
-
193
-
194
-    /**
195
-     * @NoAdminRequired
196
-     */
197
-    public function getsmsnumbers($userId) {
198
-
199
-        $smsapicred = $this->service->getapicredentials($this->userId);
200
-
201
-        $telnyxkey = $smsapicred[0];
202
-
203
-        $nexapikey = $smsapicred[5];
204
-        $nexapisecret = $smsapicred[6];
205
-
206
-        $twilapikey = $smsapicred[15];
207
-        $twilapisecret = $smsapicred[16];
208
-
209
-        $flowapikey = $smsapicred[20];
210
-        $flowapisecret = $smsapicred[21];
211
-
212
-        $telsendernameinit = $smsapicred[9];
213
-        $nexsendernameinit = $smsapicred[10];
214
-        $twilsendernameinit = $smsapicred[19];
215
-
216
-        $telsendername = "Tx: " . $telsendernameinit;
217
-        $nexsendername = "Pl: " . $nexsendernameinit;
218
-        $twilsendername = "Tw: " . $twilsendernameinit;
219
-
220
-        // Get Telnyx phone numbers
221
-        if ($telnyxkey != '') {
222
-
223
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
224
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
225
-
226
-           $telnumbersarr = $this->object_to_array($telnumbers);
227
-           $telnmbrs = [];
228
-
229
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
230
-              if (is_int($nmbkey)) {
231
-                 foreach ($nmbvalue as $nkey => $nvalue) {
232
-                    if ($nkey == 'phone_number') {
233
-                       $telnmbrs[] = "Tx: " . $nvalue;
234
-                    }
235
-                 }
236
-              }
237
-           }
238
-
239
-        } else { $telnmbrs = []; }
240
-
241
-        // Get Plivo phone numbers
242
-        if ($nexapikey != '' && $nexapisecret != '') {
243
-
244
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
245
-           $acdata = file_get_contents($getacdata);
246
-           $datainit = json_decode($acdata, true);
247
-
248
-           $findata = $this->object_to_array($datainit);
249
-
250
-           $nexcurrentnmbrs = [];
251
-
252
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
253
-                   if (is_array($smsvalue)) {
254
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
255
-                               if ($smskey2 == 'number') {
256
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
257
-                               }
258
-                         }
259
-                   }
260
-           }
261
-
262
-
263
-        } else { $nexcurrentnmbrs = []; }
264
-
265
-        // Get Twilio phone numbers
266
-        if ($twilapikey != '' && $twilapisecret != '') {
267
-
268
-            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
269
-            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
270
-
271
-            $twilcurrentnmbrs = [];
272
-            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
273
-                 if (is_array($twnbvalue)) {
274
-                     foreach ($twnbvalue as $twfkey => $twfvalue) {
275
-                          if ($twfkey == 'phone_number') {
276
-                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
277
-                          }
278
-                     }
279
-                 }
280
-            }
281
-
282
-        } else { $twilcurrentnmbrs = []; }
283
-
284
-        // Get Flowroute phone numbers
285
-        if ($flowapikey != '' && $flowapisecret != '') {
286
-
287
-            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
288
-            $flnbrsarr = $flnbrsresult->data;
289
-            $flowcurrentnmbrs = [];
290
-            foreach ($flnbrsarr as $flkey => $flitem) {
291
-                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
292
-            }
293
-
294
-        } else { $flowcurrentnmbrs = []; }
295
-
296
-
297
-        $telsenderarr = [0 => $telsendername];
298
-        $nexsenderarr = [0 => $nexsendername];
299
-        $twilsenderarr = [0 => $twilsendername];
300
-
301
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
302
-
303
-        if ($this->groupManager->isAdmin($this->userId)) {
304
-
305
-            return $currentnmbrs;
306
-
307
-        } else {
308
-
309
-            // Get the restrictions from the 'sms_relent_restrict' table
310
-            $getrestr = $this->connection->prepare('
311
-		       SELECT `phone_number`, `groups`, `users` FROM `*PREFIX*sms_relent_restrict`');
312
-            $getrestrres = $getrestr->execute();
313
-
314
-            $restrdata = [];
315
-            while ($restrfetched = $getrestrres->fetch()) {
316
-                   $restrdata[] = $restrfetched;
317
-            }
318
-            $getrestrres->closeCursor();
319
-
320
-            if ($restrdata) {
321
-
322
-                // Get the groups to which the current user belongs
323
-                $usrId = $this->userId;
324
-                $getusrgrp = $this->connection->prepare('
325
-		       SELECT `gid`, `uid` FROM `*PREFIX*group_user` WHERE `uid` = ?');
326
-                $getusrgrpres = $getusrgrp->execute([$usrId]);
327
-
328
-                $usergrps = [];
329
-                while ($fetchedgrps = $getusrgrpres->fetch()) {
330
-                       $usergrps[] = $fetchedgrps['gid'];
331
-                }
332
-                $getusrgrpres->closeCursor();
333
-
334
-		// Get the Display Name of the current user
335
-		$getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
336
-		$getacdatadnres = $getacdatadn->execute([$usrId, 'displayname']);
337
-		$acdatausrdnadm = $getacdatadnres->fetch();
338
-		$cruserdname = $acdatausrdnadm['value'];
339
-		$getacdatadnres->closeCursor();
340
-
341
-                // Get the phone numbers that are not allowed for the current user
342
-                $restrPhoneNb = [];
343
-                foreach ($restrdata as $rskey => $rsvalue) {
344
-
345
-                       $restrgrparr = explode("|", $rsvalue['groups']);
346
-                       $chck = 0;
347
-                       foreach ($restrgrparr as $rkey => $rvalue) {
348
-                                if (str_contains(implode("|", $usergrps), $rvalue)) { $chck++; }
349
-                       }
350
-                       if (str_contains($rsvalue['users'], $cruserdname)) { $chck++; }
351
-
352
-                       if ($chck == 0) { $restrPhoneNb[] = $rsvalue['phone_number']; }
353
-                }
354
-
355
-                $restrPhoneNmbrs = array_unique($restrPhoneNb);
356
-
357
-                // Clean the restricted phone numbers from tags
358
-                $restrPhfin = [];
359
-                foreach ($restrPhoneNmbrs as $phkey => $phvalue) {
360
-
361
-                    $restrpharr = explode(": ", $phvalue);
362
-                    $restrPhfin[] = $restrpharr[1];
363
-                }
364
-
365
-                // Assemble the array of phone numbers that the current user is allowed to use
366
-                for ($k = 0; $k < count($currentnmbrs); $k++) {
367
-
368
-                    $availnmbrarr = explode(": ", $currentnmbrs[$k]);
369
-                    $availphnmbr = $availnmbrarr[1];
370
-
371
-                    if (in_array($availphnmbr, $restrPhfin)) {
372
-                        unset($currentnmbrs[$k]);
373
-                    }
374
-                }
375
-
376
-                $currentnmbrsrstr = array_values($currentnmbrs);
377
-
378
-                return $currentnmbrsrstr;
379
-
380
-            } else { return $currentnmbrs; }
381
-        }
382
-    }
383
-
384
-
385
-    /**
386
-     * @NoAdminRequired
387
-     */
388
-    public function cleantempdir($userId) {
389
-
390
-        // Create the temporary folder if it doesn't exist
391
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
392
-            $this->folder->newFolder('SMS_Relentless/temp_files');
393
-        }
394
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
395
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
396
-        $fileSystemIterator = new FilesystemIterator($targetdir);
397
-
398
-        $dirfiles = [];
399
-        foreach ($fileSystemIterator as $fileInfo){
400
-                 $dirfiles[] = $fileInfo->getFilename();
401
-        }
402
-
403
-        foreach ($dirfiles as $key => $indfile) {
404
-                 $thisuserroot = $this->view->getRoot();
405
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
406
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
407
-        }
408
-     }
409
-
410
-
411
-    /**
412
-     * @NoAdminRequired
413
-     */
414
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
415
-
416
-        // Create the temporary folder if it doesn't exist
417
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
418
-            $this->folder->newFolder('SMS_Relentless/temp_files');
419
-        }
420
-
421
-        // First delete any file that has been previously uploaded
422
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
423
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
424
-        $fileSystemIterator = new FilesystemIterator($targetdir);
425
-
426
-        $dirfiles = [];
427
-        foreach ($fileSystemIterator as $fileInfo){
428
-                 $dirfiles[] = $fileInfo->getFilename();
429
-        }
430
-
431
-        foreach ($dirfiles as $key => $indfile) {
432
-                 $thisuserroot = $this->view->getRoot();
433
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
434
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
435
-        }
436
-
437
-        // Upload the new file
438
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
439
-        $fileName = $_FILES['uploadfileforsms']['name'];
440
-
441
-        $userroot = $this->view->getRoot();
442
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
443
-
444
-        $target = $this->folder->newFile($targetfile);
445
-        $target->putContent($fileContent);
446
-
447
-        // Extract the phone numbers from the file
448
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
449
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
450
-        $numberarrayfourth = explode(",", $numberarraytert);
451
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
452
-        $numberarray = array_unique($numberarrayfifth);
453
-
454
-        return $numberarray;
455
-    }
456
-
457
-
458
-    /**
459
-     * @NoAdminRequired
460
-     */
461
-    public function uploadfile($uploadfileformms) {
462
-
463
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
464
-           $fileName = $_FILES['uploadfileformms']['name'];
465
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
466
-           $fileSize = $fileSizeinit / 1024;
467
-
468
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
469
-               $this->folder->newFolder('SMS_Relentless/temp_files');
470
-           }
471
-
472
-           $userroot = $this->view->getRoot();
473
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
474
-
475
-           $target = $this->folder->newFile($targetfile);
476
-           $target->putContent($fileContent);
477
-
478
-           // Get the cumulative files size of the uploaded files
479
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
480
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
481
-
482
-           $fileSystemIterator = new FilesystemIterator($targetdir);
483
-
484
-           $dirfiles = [];
485
-           foreach ($fileSystemIterator as $fileInfo){
486
-                    $dirfiles[] = $fileInfo->getFilename();
487
-           }
488
-
489
-           $totalflsizeinit = 0;
490
-           foreach ($dirfiles as $key => $indfile) {
491
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
492
-                    $mbSize = round($fileSizeinit / 1024, 4);
493
-                    $totalflsizeinit += $mbSize;
494
-           }
495
-
496
-           $totalflsize = round($totalflsizeinit, 4);
497
-
498
-           return $totalflsize;
499
-    }
500
-
501
-
502
-    /**
503
-     * @NoAdminRequired
504
-     */
505
-    public function pickfile($path) {
506
-
507
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
508
-               $this->folder->newFolder('SMS_Relentless/temp_files');
509
-           }
510
-
511
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
512
-
513
-           $fltgt = $datadir . $this->userId . "/files" . $path;
514
-
515
-           $fileContent = file_get_contents($fltgt);
516
-
517
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
518
-
519
-           $patharr = explode("/", $path);
520
-
521
-           $revarr = array_reverse($patharr);
522
-
523
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
524
-
525
-           $target = $this->folder->newFile($relflpath);
526
-
527
-           $target->putContent($fileContent);
528
-
529
-           // Get the cumulative files size of the uploaded files
530
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
531
-
532
-           $fileSystemIterator = new FilesystemIterator($targetdir);
533
-
534
-           $dirfiles = [];
535
-           foreach ($fileSystemIterator as $fileInfo) {
536
-                    $dirfiles[] = $fileInfo->getFilename();
537
-           }
538
-
539
-           $totalflsizeinit = 0;
540
-
541
-           foreach ($dirfiles as $key => $indfile) {
542
-
543
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
544
-                    $mbSize = round($fileSizeinit / 1024, 4);
545
-                    $totalflsizeinit += $mbSize;
546
-           }
547
-
548
-           $totalflsize = round($totalflsizeinit, 4);
549
-
550
-           $pickresult = [$totalflsize, $pkfilesize];
551
-
552
-           return $pickresult;
553
-    }
554
-
555
-
556
-    /**
557
-     * @NoAdminRequired
558
-     */
559
-    public function removeupfile($removedfilename) {
560
-
561
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
562
-
563
-           $removefile = $this->view->unlink($tmpfl);
564
-
565
-           // Get the cumulative files size of the uploaded files
566
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
567
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
568
-           $fileSystemIterator = new FilesystemIterator($targetdir);
569
-
570
-           $dirfiles = [];
571
-           foreach ($fileSystemIterator as $fileInfo){
572
-                    $dirfiles[] = $fileInfo->getFilename();
573
-           }
574
-
575
-           $totalflsizeinit = 0;
576
-
577
-           foreach ($dirfiles as $key => $indfile) {
578
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
579
-                    $mbSize = round($fileSizeinit / 1024, 4);
580
-                    $totalflsizeinit += $mbSize;
581
-           }
582
-
583
-           $totalflsize = round($totalflsizeinit, 4);
584
-
585
-           return $totalflsize;
586
-    }
587
-
588
-
589
-    /**
590
-     * @NoAdminRequired
591
-     */
592
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
593
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
594
-         $telnyxkey = $telsmsapicred[0];
595
-         $teldelrecurl = $telsmsapicred[3];
596
-         $messagingprofid = $telsmsapicred[4];
597
-
598
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
599
-
600
-         $microinterval = $waitinterval * 1000;
601
-
602
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
603
-
604
-             usleep($microinterval);
605
-
606
-             $messagedate = date("Y-m-d H:i:s");
607
-
608
-             if ($ismms == 0) {
609
-
610
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
611
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
612
-                 } else {
613
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
614
-                 }
615
-
616
-                 $messagetexttel = $sentsmstext;
617
-
618
-             } else {
619
-
620
-                 $mediaURLarr = [];
621
-                 $includedMediaFiles = '';
622
-
623
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
624
-
625
-                      $userroot = $this->view->getRoot();
626
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
627
-
628
-                      $flsharetarget = $this->folder->newFile($filetoshare);
629
-
630
-	              $share = $this->shareManager->newShare();
631
-	              $share->setNode($flsharetarget);
632
-	              $share->setPermissions(Constants::PERMISSION_READ);
633
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
634
-	              $share->setSharedBy($this->userId);
635
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
636
-                      $expirydate->add(new \DateInterval('P1D'));
637
-                      $share->setExpirationDate($expirydate);
638
-                      $shared = $this->shareManager->createShare($share);
639
-                      $shareToken = $shared->getToken();
640
-
641
-                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
642
-                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
643
-                 }
644
-
645
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
646
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
647
-                 } else {
648
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
649
-                 }
650
-
651
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
652
-             }
653
-
654
-             $messageid = $message['id'];
655
-             $messagefrom = "Telnyx: " . $fromsender;
656
-             $messageto = $tonumber;
657
-             $messagenetwork = null;
658
-             $messageprice = null;
659
-             $messagestatus = $message['to'][0]['status'];
660
-             $messagedelivery = null;
661
-
662
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
663
-
664
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
665
-         }
666
-    }
667
-
668
-
669
-    /**
670
-     * @NoAdminRequired
671
-     */
672
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
673
-
674
-         $smsapicred = $this->service->getapicredentials($this->userId);
675
-
676
-         $smsapikey = $smsapicred[5];
677
-         $smsapisecret = $smsapicred[6];
678
-         $smsapideliveryrecurl = $smsapicred[8];
679
-
680
-         $microinterval = $waitinterval * 1000;
681
-
682
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
683
-
684
-             usleep($microinterval);
685
-
686
-             $messagedatepl = date("Y-m-d H:i:s");
687
-
688
-             if ($ismms == 0) {
689
-
690
-                 $client = new RestClient($smsapikey, $smsapisecret);
691
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
692
-                 $messagetextpl = $sentsmstext;
693
-	         $messageidinit = $response->getmessageUuid(0);
694
-                 $messageid = $messageidinit[0];
695
-
696
-                 if (property_exists($response, 'error')) { 
697
-                     $messagestatus = "Error: " . $response->error;
698
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
699
-
700
-             } else {
701
-
702
-                 $mediaURLarr = [];
703
-                 $includedMediaFiles = '';
704
-
705
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
706
-
707
-                      $userroot = $this->view->getRoot();
708
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
709
-
710
-                      $flsharetarget = $this->folder->newFile($filetoshare);
711
-
712
-	              $share = $this->shareManager->newShare();
713
-	              $share->setNode($flsharetarget);
714
-	              $share->setPermissions(Constants::PERMISSION_READ);
715
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
716
-	              $share->setSharedBy($this->userId);
717
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
718
-                      $expirydate->add(new \DateInterval('P1D'));
719
-                      $share->setExpirationDate($expirydate);
720
-                      $shared = $this->shareManager->createShare($share);
721
-                      $shareToken = $shared->getToken();
722
-
723
-                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
724
-                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
725
-                 }
726
-
727
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
728
-		 $postedparamspl = json_encode($datatosendpl);
729
-
730
-		 $chpl = curl_init();
731
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
732
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
733
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
734
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
735
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
736
-		 curl_setopt($chpl, CURLOPT_POST, 1);
737
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
738
-		 $resultpl = curl_exec ($chpl);
739
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
740
-		 curl_close ($chpl);
741
-
742
-		 $decresultpl = json_decode($resultpl);
743
-
744
-                 if (property_exists($decresultpl, 'message_uuid')) {
745
-                     $messageidinit = $decresultpl->message_uuid;
746
-                     $messageid = $messageidinit[0];
747
-                 }
748
-
749
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
750
-
751
-                     if (property_exists($decresultpl, 'error')) {
752
-                         $messagestatus = "Error: " . $decresultpl->error;
753
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
754
-
755
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
756
-
757
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
758
-             }
759
-
760
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
761
-                 $messagefrom = "Plivo: " . $fromsender;
762
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
763
-
764
-             $messageto = $tonumber;
765
-             $messagenetwork = '';
766
-             $messageprice = '';
767
-
768
-             $messagedelivery = '';
769
-
770
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
771
-
772
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
773
-         }
774
-    }
775
-
776
-
777
-    /**
778
-     * @NoAdminRequired
779
-     */
780
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
781
-
782
-         $smsapicred = $this->service->getapicredentials($this->userId);
783
-
784
-         $sid = $smsapicred[15];
785
-         $token = $smsapicred[16];
786
-         $smsapirecurltw = $smsapicred[18];
787
-
788
-         $microinterval = $waitinterval * 1000;
789
-
790
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
791
-
792
-             usleep($microinterval);
793
-
794
-             $messagedatetw = date("Y-m-d H:i:s");
795
-
796
-             if ($ismms == 0) {
797
-
798
-                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
799
-                  $sentsmstextfintw = $sentsmstext;
800
-
801
-             } else {
802
-
803
-                 $mediaURLs = [];
804
-
805
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
806
-
807
-                      $userroot = $this->view->getRoot();
808
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
809
-
810
-                      $flsharetarget = $this->folder->newFile($filetoshare);
811
-
812
-	              $share = $this->shareManager->newShare();
813
-	              $share->setNode($flsharetarget);
814
-	              $share->setPermissions(Constants::PERMISSION_READ);
815
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
816
-	              $share->setSharedBy($this->userId);
817
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
818
-                      $expirydate->add(new \DateInterval('P1D'));
819
-                      $share->setExpirationDate($expirydate);
820
-                      $shared = $this->shareManager->createShare($share);
821
-                      $shareToken = $shared->getToken();
822
-
823
-                      $mediaURLs[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
824
-                 }
825
-
826
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
827
-                 $includedMediaFiles = '';
828
-
829
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
830
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
831
-                      $includedMediaFiles .= $mediaURLs[$m] . "<br><br>";
832
-                 }
833
-
834
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
835
-             }
836
-
837
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
838
-
839
-	     $chtw = curl_init();
840
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
841
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
842
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
843
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
844
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
845
-	     curl_setopt($chtw, CURLOPT_POST, 1);
846
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
847
-
848
-	     $resulttw = curl_exec ($chtw);
849
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
850
-	     curl_close ($chtw);
851
-
852
-             $decresulttw = json_decode($resulttw);
853
-
854
-             if ($resulttw) {
855
-                 $messageidtw = $decresulttw->sid;
856
-             } else { $messageidtw = ''; }
857
-
858
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
859
-                 $messagestatustw = 'The message has been accepted for delivery.';
860
-             } else {
861
-                 $messagestatustw = 'An error occurred while trying to send the message.';
862
-             }
863
-
864
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
865
-                 $messagefromtw = "Twilio: " . $fromsender;
866
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
867
-
868
-             $messagenetworktw = '';
869
-             $messagepricetw = '';
870
-             $messagedeliverytw = '';
871
-
872
-
873
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
874
-
875
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
876
-         }
877
-
878
-    }
879
-
880
-
881
-    /**
882
-     * @NoAdminRequired
883
-     */
884
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
885
-
886
-         $smsapicredfl = $this->service->getapicredentials($this->userId);
887
-
888
-         $flowapikey = $smsapicredfl[20];
889
-         $flowapisecret = $smsapicredfl[21];
890
-         $flowdelrecurl = $smsapicredfl[23];
891
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
892
-
893
-         $microinterval = $waitinterval * 1000;
894
-
895
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
896
-
897
-             usleep($microinterval);
898
-
899
-             $messagedatefl = date("Y-m-d H:i:s");
900
-
901
-             if ($ismms == 0) {
902
-
903
-                 $messagetextfinfl = $sentsmstext;
904
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
905
-
906
-             } else {
907
-
908
-		 $mediaurlsarr = [];
909
-
910
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
911
-
912
-		      $userroot = $this->view->getRoot();
913
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
914
-
915
-		      $flsharetarget = $this->folder->newFile($filetoshare);
916
-
917
-		      $share = $this->shareManager->newShare();
918
-		      $share->setNode($flsharetarget);
919
-		      $share->setPermissions(Constants::PERMISSION_READ);
920
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
921
-		      $share->setSharedBy($this->userId);
922
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
923
-                      $expirydate->add(new \DateInterval('P1D'));
924
-                      $share->setExpirationDate($expirydate);
925
-		      $shared = $this->shareManager->createShare($share);
926
-		      $shareToken = $shared->getToken();
927
-
928
-		      $mediaurlsarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
929
-		 }
930
-
931
-		 $includedMediaFiles = '';
932
-
933
-		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
934
-		      $includedMediaFiles .= $mediaurlsarr[$m] . "<br><br>";
935
-		 }
936
-
937
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
938
-
939
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
940
-             }
941
-
942
-
943
-	     $chfl = curl_init();
944
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
945
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
946
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
947
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
948
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
949
-	     curl_setopt($chfl, CURLOPT_POST, 1);
950
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
951
-	     $resultfl = curl_exec ($chfl);
952
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
953
-	     curl_close ($chfl);
954
-
955
-             $decresultfl = json_decode($resultfl);
956
-
957
-             if ($resultfl) {
958
-                 $messageidfl = $decresultfl->data->id;
959
-             } else { $messageidfl = ''; }
960
-
961
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
962
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
963
-             } else { 
964
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
965
-             }
966
-
967
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
968
-                 $messagefromfl = "Flowroute: " . $fromsender;
969
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
970
-
971
-             $messagetofl = $tonumberfl;
972
-             $messagenetworkfl = '';
973
-             $messagepricefl = '';
974
-             $messagedeliveryfl = '';
975
-
976
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
977
-
978
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
979
-         }
980
-
981
-    }
982
-
983
-
984
-    /**
985
-     * @NoAdminRequired
986
-     */
987
-    public function saveoldrecrows($userId, $oldrecRows) {
988
-
989
-           // Create the folder for removed messages if it doesn't exist
990
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
991
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
992
-           }
993
-           $savecheck = 0;
994
-
995
-           if (count($oldrecRows) > 1) {
996
-               $msfileContent = implode("", $oldrecRows);
997
-
998
-               $delrowsdate = date("Y-m-d_H-i-s");
999
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
1000
-
1001
-               $userroot = $this->view->getRoot();
1002
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
1003
-
1004
-               $target = $this->folder->newFile($targetfile);
1005
-               $target->putContent($msfileContent);
1006
-
1007
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
1008
-                   $savecheck = 1;
1009
-               }
1010
-           }
1011
-
1012
-           return $savecheck;
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * @NoAdminRequired
1018
-     */
1019
-    public function saveoldsentrows($userId, $oldsentRows) {
1020
-
1021
-           // Create the folder for removed messages if it doesn't exist
1022
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
1023
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
1024
-           }
1025
-           $savesentcheck = 0;
1026
-
1027
-           if (count($oldsentRows) > 1) {
1028
-               $sntfileContent = implode("", $oldsentRows);
1029
-
1030
-               $delsentrowsdate = date("Y-m-d_H-i-s");
1031
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
1032
-
1033
-               $userroot = $this->view->getRoot();
1034
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
1035
-
1036
-               $snttarget = $this->folder->newFile($snttargetfile);
1037
-               $snttarget->putContent($sntfileContent);
1038
-
1039
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
1040
-                   $savesentcheck = 1;
1041
-               }
1042
-           }
1043
-
1044
-           return $savesentcheck;
1045
-    }
1046
-
1047
-
1048
-    /**
1049
-     * @NoAdminRequired
1050
-     */
1051
-    public function getreceivedtable($userId) {
1052
-           return $this->service->getreceivedtable($this->userId);
1053
-    }
1054
-
1055
-    /**
1056
-     * @NoAdminRequired
1057
-     */
1058
-    public function getreceivedtablefordel($userId) {
1059
-           return $this->service->getreceivedtablefordel($this->userId);
1060
-    }
1061
-
1062
-    /**
1063
-     * @NoAdminRequired
1064
-     */
1065
-    public function removerecrows($userId, $recmessagedbIDs) {
1066
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
1067
-    }
1068
-
1069
-    /**
1070
-     * @NoAdminRequired
1071
-     */
1072
-    public function getsenttable($userId) {
1073
-           return $this->service->getsenttable($this->userId);
1074
-    }
1075
-
1076
-    /**
1077
-     * @NoAdminRequired
1078
-     */
1079
-    public function getsenttablefordel($userId) {
1080
-           return $this->service->getsenttablefordel($this->userId);
1081
-    }
1082
-
1083
-    /**
1084
-     * @NoAdminRequired
1085
-     */
1086
-    public function removesentrows($userId, $sentmessagedbIDs) {
1087
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1088
-    }
1089
-
1090
-    /**
1091
-     * @NoAdminRequired
1092
-     */
1093
-    public function getgroupedtable($userId) {
1094
-           return $this->service->getgroupedtable($this->userId);
1095
-    }
1096
-
1097
-    /**
1098
-     * @NoAdminRequired
1099
-     */
1100
-    public function savedisplayname($userId, $authorDisplayname, $from) {
1101
-           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1102
-    }
1103
-
1104
-    /**
1105
-     * @NoAdminRequired
1106
-     */
1107
-    public function getmessagesperpage($userId) {
1108
-           return $this->service->getmessagesperpage($this->userId);
1109
-    }
1110
-
1111
-    /**
1112
-     * @NoAdminRequired
1113
-     */
1114
-    public function getdelrecsettings($userId) {
1115
-           return $this->service->getdelrecsettings($this->userId);
1116
-    }
1117
-
1118
-    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1119
-           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1120
-    }
1121
-
1122
-    public function removenumberrestrictions($userId, $phoneNumber) {
1123
-           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1124
-    }
1125
-
1126
-    /**
1127
-     * @NoAdminRequired
1128
-     */
1129
-    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1130
-           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1131
-    }
1132
-
1133
-    /**
1134
-     * @NoAdminRequired
1135
-     */
1136
-    public function removeautoreplies($userId, $phoneNumber) {
1137
-           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1138
-    }
1139
-
1140
-    /**
1141
-     * @NoAdminRequired
1142
-     */
1143
-    public function getsettings($userId) {
1144
-           return $this->service->getsettings($this->userId);
1145
-    }
1146
-
1147
-    public function getadminsettings($userId) {
1148
-           return $this->service->getadminsettings($this->userId);
1149
-    }
1150
-
1151
-    /**
1152
-     * @NoAdminRequired
1153
-     */
1154
-    public function getautoreplyconf($userId) {
1155
-
1156
-           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1157
-           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1158
-
1159
-           // Get the display name of the current user
1160
-           $usrid = $this->userId;
1161
-           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1162
-	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1163
-	   $getusrdnmdata = $getusrdnmres->fetch();
1164
-	   $userDisplayNm = $getusrdnmdata['value'];
1165
-	   $getusrdnmres->closeCursor();
1166
-
1167
-           // Get the auto-replies for the available phone numbers
1168
-           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1169
-                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1170
-	   $getautorplres = $getautorpl->execute();
1171
-           $autorplconf = [];
1172
-	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1173
-                  $autorplconf[] = $acdatausrdnadm;
1174
-           }
1175
-	   $getautorplres->closeCursor();
1176
-
1177
-           if ($autorplconf) {
1178
-
1179
-               $autoreplyconf = [];
1180
-               foreach ($autorplconf as $arkey => $arvalue) {
1181
-                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1182
-                            $autoreplyconf[] = $arvalue;
1183
-                        }
1184
-               }
1185
-
1186
-           } else { $autoreplyconf = ''; }
1187
-
1188
-           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1189
-
1190
-           return $autoreplyfdb;
1191
-    }
1192
-
1193
-    /**
1194
-     * @NoAdminRequired
1195
-     */
1196
-    public function getgroupedpernumber($userId, $phoneNumber) {
1197
-           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1198
-    }
1199
-
1200
-    /**
1201
-     * @NoAdminRequired
1202
-     */
1203
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showDisplayNames) {
1204
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showDisplayNames);
1205
-    }
1206
-
1207
-    public function updateadminsettings($userId, $showAllMessages) {
1208
-           return $this->service->updateadminsettings($this->userId, $showAllMessages);
1209
-    }
1210
-}
Browse code

added changes for origination, auto-reply, etc.

DoubleBastionAdmin authored on 08/05/2023 20:50:18
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1210 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\IURLGenerator;
49
+use OCP\Share\IManager;
50
+use OCP\Constants;
51
+use OCP\IGroupManager;
52
+use OCP\IDBConnection;
53
+
54
+
55
+class SmsrelentlessController extends Controller {
56
+
57
+    private $service;
58
+    private $config;
59
+    private $userId;
60
+    private $folder;
61
+    private $filesystem;
62
+    private $view;
63
+    private $urlGenerator;
64
+    private $shareManager;
65
+
66
+    private $groupManager;
67
+    private $connection;
68
+
69
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager, IGroupManager $groupManager, IDBConnection $connection) {
70
+        parent::__construct($appName, $request);
71
+        $this->service = $service;
72
+        $this->config = $config;
73
+        $this->userId = $userId;
74
+        $this->folder = $folder;
75
+        $this->filesystem = $filesystem;
76
+        $this->view = $view;
77
+	$this->urlGenerator = $urlGenerator;
78
+	$this->shareManager = $shareManager;
79
+        $this->groupManager = $groupManager;
80
+        $this->connection = $connection;
81
+    }
82
+
83
+
84
+    /**
85
+     * @NoAdminRequired
86
+     */
87
+    public function object_to_array($obj) {
88
+        if (is_object($obj)) $obj = (array)$this->dismount($obj);
89
+        if (is_array($obj)) {
90
+           $new = array();
91
+           foreach($obj as $key => $val) {
92
+               $new[$key] = $this->object_to_array($val);
93
+           }
94
+        }
95
+        else $new = $obj;
96
+        return $new;
97
+    }
98
+
99
+
100
+    /**
101
+     * @NoAdminRequired
102
+     */
103
+    public function dismount($object) {
104
+        $reflectionClass = new ReflectionClass(get_class($object));
105
+        $array = array();
106
+        foreach ($reflectionClass->getProperties() as $property) {
107
+           $property->setAccessible(true);
108
+           $array[$property->getName()] = $property->getValue($object);
109
+           $property->setAccessible(false);
110
+        }
111
+        return $array;
112
+    }
113
+
114
+
115
+    /**
116
+     * @NoAdminRequired
117
+     */
118
+    public function getbalancetel($userId) {
119
+
120
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
121
+
122
+        $telapikey = $telsmsapicred[0];
123
+        $ch = curl_init();
124
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
125
+
126
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
127
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
128
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
129
+        $responsetel = curl_exec($ch);
130
+        $recdatatel = json_decode($responsetel, TRUE);
131
+        $telbalresponse = $recdatatel['data']['balance'];
132
+        $currentbalancetel = round(floatval($telbalresponse), 3);
133
+        curl_close($ch);
134
+
135
+        return $currentbalancetel;
136
+    }
137
+
138
+
139
+    /**
140
+     * @NoAdminRequired
141
+     */
142
+    public function getbalancenex($userId) {
143
+
144
+        $smsapicred = $this->service->getapicredentials($this->userId);
145
+        $smsapikey = $smsapicred[5];
146
+        $smsapisecret = $smsapicred[6];
147
+
148
+        if ($smsapikey == '' || $smsapisecret == '') {
149
+            $currentbalancenex = "N/A";
150
+        } else {
151
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
152
+            $mesdata = file_get_contents($getmesdata);
153
+            $datainit = json_decode($mesdata);
154
+            $balancenex = $datainit->cash_credits;
155
+            $currentbalancenex = round(floatval($balancenex), 3);
156
+        }
157
+        return $currentbalancenex;
158
+    }
159
+
160
+
161
+    /**
162
+     * @NoAdminRequired
163
+     */
164
+    public function getbalancetwil($userId) {
165
+
166
+        $smsapicred = $this->service->getapicredentials($this->userId);
167
+        $smsapisid = $smsapicred[15];
168
+        $smsapitoken = $smsapicred[16];
169
+
170
+        if ($smsapisid == '' || $smsapitoken == '') {
171
+            $currentbalancetwil = "N/A";
172
+        } else {
173
+
174
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
175
+            $balancetwil = $twilbalance->balance;
176
+
177
+            $currentbalancetwil = round(floatval($balancetwil), 3);
178
+        }
179
+        return $currentbalancetwil;
180
+    }
181
+
182
+
183
+    /**
184
+     * @NoAdminRequired
185
+     */
186
+    public function getbalanceflow($userId) {
187
+
188
+        $currentbalanceflow = 'n/a';
189
+
190
+        return $currentbalanceflow;
191
+    }
192
+
193
+
194
+    /**
195
+     * @NoAdminRequired
196
+     */
197
+    public function getsmsnumbers($userId) {
198
+
199
+        $smsapicred = $this->service->getapicredentials($this->userId);
200
+
201
+        $telnyxkey = $smsapicred[0];
202
+
203
+        $nexapikey = $smsapicred[5];
204
+        $nexapisecret = $smsapicred[6];
205
+
206
+        $twilapikey = $smsapicred[15];
207
+        $twilapisecret = $smsapicred[16];
208
+
209
+        $flowapikey = $smsapicred[20];
210
+        $flowapisecret = $smsapicred[21];
211
+
212
+        $telsendernameinit = $smsapicred[9];
213
+        $nexsendernameinit = $smsapicred[10];
214
+        $twilsendernameinit = $smsapicred[19];
215
+
216
+        $telsendername = "Tx: " . $telsendernameinit;
217
+        $nexsendername = "Pl: " . $nexsendernameinit;
218
+        $twilsendername = "Tw: " . $twilsendernameinit;
219
+
220
+        // Get Telnyx phone numbers
221
+        if ($telnyxkey != '') {
222
+
223
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
224
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
225
+
226
+           $telnumbersarr = $this->object_to_array($telnumbers);
227
+           $telnmbrs = [];
228
+
229
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
230
+              if (is_int($nmbkey)) {
231
+                 foreach ($nmbvalue as $nkey => $nvalue) {
232
+                    if ($nkey == 'phone_number') {
233
+                       $telnmbrs[] = "Tx: " . $nvalue;
234
+                    }
235
+                 }
236
+              }
237
+           }
238
+
239
+        } else { $telnmbrs = []; }
240
+
241
+        // Get Plivo phone numbers
242
+        if ($nexapikey != '' && $nexapisecret != '') {
243
+
244
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
245
+           $acdata = file_get_contents($getacdata);
246
+           $datainit = json_decode($acdata, true);
247
+
248
+           $findata = $this->object_to_array($datainit);
249
+
250
+           $nexcurrentnmbrs = [];
251
+
252
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
253
+                   if (is_array($smsvalue)) {
254
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
255
+                               if ($smskey2 == 'number') {
256
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
257
+                               }
258
+                         }
259
+                   }
260
+           }
261
+
262
+
263
+        } else { $nexcurrentnmbrs = []; }
264
+
265
+        // Get Twilio phone numbers
266
+        if ($twilapikey != '' && $twilapisecret != '') {
267
+
268
+            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
269
+            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
270
+
271
+            $twilcurrentnmbrs = [];
272
+            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
273
+                 if (is_array($twnbvalue)) {
274
+                     foreach ($twnbvalue as $twfkey => $twfvalue) {
275
+                          if ($twfkey == 'phone_number') {
276
+                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
277
+                          }
278
+                     }
279
+                 }
280
+            }
281
+
282
+        } else { $twilcurrentnmbrs = []; }
283
+
284
+        // Get Flowroute phone numbers
285
+        if ($flowapikey != '' && $flowapisecret != '') {
286
+
287
+            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
288
+            $flnbrsarr = $flnbrsresult->data;
289
+            $flowcurrentnmbrs = [];
290
+            foreach ($flnbrsarr as $flkey => $flitem) {
291
+                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
292
+            }
293
+
294
+        } else { $flowcurrentnmbrs = []; }
295
+
296
+
297
+        $telsenderarr = [0 => $telsendername];
298
+        $nexsenderarr = [0 => $nexsendername];
299
+        $twilsenderarr = [0 => $twilsendername];
300
+
301
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
302
+
303
+        if ($this->groupManager->isAdmin($this->userId)) {
304
+
305
+            return $currentnmbrs;
306
+
307
+        } else {
308
+
309
+            // Get the restrictions from the 'sms_relent_restrict' table
310
+            $getrestr = $this->connection->prepare('
311
+		       SELECT `phone_number`, `groups`, `users` FROM `*PREFIX*sms_relent_restrict`');
312
+            $getrestrres = $getrestr->execute();
313
+
314
+            $restrdata = [];
315
+            while ($restrfetched = $getrestrres->fetch()) {
316
+                   $restrdata[] = $restrfetched;
317
+            }
318
+            $getrestrres->closeCursor();
319
+
320
+            if ($restrdata) {
321
+
322
+                // Get the groups to which the current user belongs
323
+                $usrId = $this->userId;
324
+                $getusrgrp = $this->connection->prepare('
325
+		       SELECT `gid`, `uid` FROM `*PREFIX*group_user` WHERE `uid` = ?');
326
+                $getusrgrpres = $getusrgrp->execute([$usrId]);
327
+
328
+                $usergrps = [];
329
+                while ($fetchedgrps = $getusrgrpres->fetch()) {
330
+                       $usergrps[] = $fetchedgrps['gid'];
331
+                }
332
+                $getusrgrpres->closeCursor();
333
+
334
+		// Get the Display Name of the current user
335
+		$getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
336
+		$getacdatadnres = $getacdatadn->execute([$usrId, 'displayname']);
337
+		$acdatausrdnadm = $getacdatadnres->fetch();
338
+		$cruserdname = $acdatausrdnadm['value'];
339
+		$getacdatadnres->closeCursor();
340
+
341
+                // Get the phone numbers that are not allowed for the current user
342
+                $restrPhoneNb = [];
343
+                foreach ($restrdata as $rskey => $rsvalue) {
344
+
345
+                       $restrgrparr = explode("|", $rsvalue['groups']);
346
+                       $chck = 0;
347
+                       foreach ($restrgrparr as $rkey => $rvalue) {
348
+                                if (str_contains(implode("|", $usergrps), $rvalue)) { $chck++; }
349
+                       }
350
+                       if (str_contains($rsvalue['users'], $cruserdname)) { $chck++; }
351
+
352
+                       if ($chck == 0) { $restrPhoneNb[] = $rsvalue['phone_number']; }
353
+                }
354
+
355
+                $restrPhoneNmbrs = array_unique($restrPhoneNb);
356
+
357
+                // Clean the restricted phone numbers from tags
358
+                $restrPhfin = [];
359
+                foreach ($restrPhoneNmbrs as $phkey => $phvalue) {
360
+
361
+                    $restrpharr = explode(": ", $phvalue);
362
+                    $restrPhfin[] = $restrpharr[1];
363
+                }
364
+
365
+                // Assemble the array of phone numbers that the current user is allowed to use
366
+                for ($k = 0; $k < count($currentnmbrs); $k++) {
367
+
368
+                    $availnmbrarr = explode(": ", $currentnmbrs[$k]);
369
+                    $availphnmbr = $availnmbrarr[1];
370
+
371
+                    if (in_array($availphnmbr, $restrPhfin)) {
372
+                        unset($currentnmbrs[$k]);
373
+                    }
374
+                }
375
+
376
+                $currentnmbrsrstr = array_values($currentnmbrs);
377
+
378
+                return $currentnmbrsrstr;
379
+
380
+            } else { return $currentnmbrs; }
381
+        }
382
+    }
383
+
384
+
385
+    /**
386
+     * @NoAdminRequired
387
+     */
388
+    public function cleantempdir($userId) {
389
+
390
+        // Create the temporary folder if it doesn't exist
391
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
392
+            $this->folder->newFolder('SMS_Relentless/temp_files');
393
+        }
394
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
395
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
396
+        $fileSystemIterator = new FilesystemIterator($targetdir);
397
+
398
+        $dirfiles = [];
399
+        foreach ($fileSystemIterator as $fileInfo){
400
+                 $dirfiles[] = $fileInfo->getFilename();
401
+        }
402
+
403
+        foreach ($dirfiles as $key => $indfile) {
404
+                 $thisuserroot = $this->view->getRoot();
405
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
406
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
407
+        }
408
+     }
409
+
410
+
411
+    /**
412
+     * @NoAdminRequired
413
+     */
414
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
415
+
416
+        // Create the temporary folder if it doesn't exist
417
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
418
+            $this->folder->newFolder('SMS_Relentless/temp_files');
419
+        }
420
+
421
+        // First delete any file that has been previously uploaded
422
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
423
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
424
+        $fileSystemIterator = new FilesystemIterator($targetdir);
425
+
426
+        $dirfiles = [];
427
+        foreach ($fileSystemIterator as $fileInfo){
428
+                 $dirfiles[] = $fileInfo->getFilename();
429
+        }
430
+
431
+        foreach ($dirfiles as $key => $indfile) {
432
+                 $thisuserroot = $this->view->getRoot();
433
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
434
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
435
+        }
436
+
437
+        // Upload the new file
438
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
439
+        $fileName = $_FILES['uploadfileforsms']['name'];
440
+
441
+        $userroot = $this->view->getRoot();
442
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
443
+
444
+        $target = $this->folder->newFile($targetfile);
445
+        $target->putContent($fileContent);
446
+
447
+        // Extract the phone numbers from the file
448
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
449
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
450
+        $numberarrayfourth = explode(",", $numberarraytert);
451
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
452
+        $numberarray = array_unique($numberarrayfifth);
453
+
454
+        return $numberarray;
455
+    }
456
+
457
+
458
+    /**
459
+     * @NoAdminRequired
460
+     */
461
+    public function uploadfile($uploadfileformms) {
462
+
463
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
464
+           $fileName = $_FILES['uploadfileformms']['name'];
465
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
466
+           $fileSize = $fileSizeinit / 1024;
467
+
468
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
469
+               $this->folder->newFolder('SMS_Relentless/temp_files');
470
+           }
471
+
472
+           $userroot = $this->view->getRoot();
473
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
474
+
475
+           $target = $this->folder->newFile($targetfile);
476
+           $target->putContent($fileContent);
477
+
478
+           // Get the cumulative files size of the uploaded files
479
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
480
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
481
+
482
+           $fileSystemIterator = new FilesystemIterator($targetdir);
483
+
484
+           $dirfiles = [];
485
+           foreach ($fileSystemIterator as $fileInfo){
486
+                    $dirfiles[] = $fileInfo->getFilename();
487
+           }
488
+
489
+           $totalflsizeinit = 0;
490
+           foreach ($dirfiles as $key => $indfile) {
491
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
492
+                    $mbSize = round($fileSizeinit / 1024, 4);
493
+                    $totalflsizeinit += $mbSize;
494
+           }
495
+
496
+           $totalflsize = round($totalflsizeinit, 4);
497
+
498
+           return $totalflsize;
499
+    }
500
+
501
+
502
+    /**
503
+     * @NoAdminRequired
504
+     */
505
+    public function pickfile($path) {
506
+
507
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
508
+               $this->folder->newFolder('SMS_Relentless/temp_files');
509
+           }
510
+
511
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
512
+
513
+           $fltgt = $datadir . $this->userId . "/files" . $path;
514
+
515
+           $fileContent = file_get_contents($fltgt);
516
+
517
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
518
+
519
+           $patharr = explode("/", $path);
520
+
521
+           $revarr = array_reverse($patharr);
522
+
523
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
524
+
525
+           $target = $this->folder->newFile($relflpath);
526
+
527
+           $target->putContent($fileContent);
528
+
529
+           // Get the cumulative files size of the uploaded files
530
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
531
+
532
+           $fileSystemIterator = new FilesystemIterator($targetdir);
533
+
534
+           $dirfiles = [];
535
+           foreach ($fileSystemIterator as $fileInfo) {
536
+                    $dirfiles[] = $fileInfo->getFilename();
537
+           }
538
+
539
+           $totalflsizeinit = 0;
540
+
541
+           foreach ($dirfiles as $key => $indfile) {
542
+
543
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
544
+                    $mbSize = round($fileSizeinit / 1024, 4);
545
+                    $totalflsizeinit += $mbSize;
546
+           }
547
+
548
+           $totalflsize = round($totalflsizeinit, 4);
549
+
550
+           $pickresult = [$totalflsize, $pkfilesize];
551
+
552
+           return $pickresult;
553
+    }
554
+
555
+
556
+    /**
557
+     * @NoAdminRequired
558
+     */
559
+    public function removeupfile($removedfilename) {
560
+
561
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
562
+
563
+           $removefile = $this->view->unlink($tmpfl);
564
+
565
+           // Get the cumulative files size of the uploaded files
566
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
567
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
568
+           $fileSystemIterator = new FilesystemIterator($targetdir);
569
+
570
+           $dirfiles = [];
571
+           foreach ($fileSystemIterator as $fileInfo){
572
+                    $dirfiles[] = $fileInfo->getFilename();
573
+           }
574
+
575
+           $totalflsizeinit = 0;
576
+
577
+           foreach ($dirfiles as $key => $indfile) {
578
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
579
+                    $mbSize = round($fileSizeinit / 1024, 4);
580
+                    $totalflsizeinit += $mbSize;
581
+           }
582
+
583
+           $totalflsize = round($totalflsizeinit, 4);
584
+
585
+           return $totalflsize;
586
+    }
587
+
588
+
589
+    /**
590
+     * @NoAdminRequired
591
+     */
592
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
593
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
594
+         $telnyxkey = $telsmsapicred[0];
595
+         $teldelrecurl = $telsmsapicred[3];
596
+         $messagingprofid = $telsmsapicred[4];
597
+
598
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
599
+
600
+         $microinterval = $waitinterval * 1000;
601
+
602
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
603
+
604
+             usleep($microinterval);
605
+
606
+             $messagedate = date("Y-m-d H:i:s");
607
+
608
+             if ($ismms == 0) {
609
+
610
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
611
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
612
+                 } else {
613
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
614
+                 }
615
+
616
+                 $messagetexttel = $sentsmstext;
617
+
618
+             } else {
619
+
620
+                 $mediaURLarr = [];
621
+                 $includedMediaFiles = '';
622
+
623
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
624
+
625
+                      $userroot = $this->view->getRoot();
626
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
627
+
628
+                      $flsharetarget = $this->folder->newFile($filetoshare);
629
+
630
+	              $share = $this->shareManager->newShare();
631
+	              $share->setNode($flsharetarget);
632
+	              $share->setPermissions(Constants::PERMISSION_READ);
633
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
634
+	              $share->setSharedBy($this->userId);
635
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
636
+                      $expirydate->add(new \DateInterval('P1D'));
637
+                      $share->setExpirationDate($expirydate);
638
+                      $shared = $this->shareManager->createShare($share);
639
+                      $shareToken = $shared->getToken();
640
+
641
+                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
642
+                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
643
+                 }
644
+
645
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
646
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
647
+                 } else {
648
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
649
+                 }
650
+
651
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
652
+             }
653
+
654
+             $messageid = $message['id'];
655
+             $messagefrom = "Telnyx: " . $fromsender;
656
+             $messageto = $tonumber;
657
+             $messagenetwork = null;
658
+             $messageprice = null;
659
+             $messagestatus = $message['to'][0]['status'];
660
+             $messagedelivery = null;
661
+
662
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
663
+
664
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
665
+         }
666
+    }
667
+
668
+
669
+    /**
670
+     * @NoAdminRequired
671
+     */
672
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
673
+
674
+         $smsapicred = $this->service->getapicredentials($this->userId);
675
+
676
+         $smsapikey = $smsapicred[5];
677
+         $smsapisecret = $smsapicred[6];
678
+         $smsapideliveryrecurl = $smsapicred[8];
679
+
680
+         $microinterval = $waitinterval * 1000;
681
+
682
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
683
+
684
+             usleep($microinterval);
685
+
686
+             $messagedatepl = date("Y-m-d H:i:s");
687
+
688
+             if ($ismms == 0) {
689
+
690
+                 $client = new RestClient($smsapikey, $smsapisecret);
691
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
692
+                 $messagetextpl = $sentsmstext;
693
+	         $messageidinit = $response->getmessageUuid(0);
694
+                 $messageid = $messageidinit[0];
695
+
696
+                 if (property_exists($response, 'error')) { 
697
+                     $messagestatus = "Error: " . $response->error;
698
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
699
+
700
+             } else {
701
+
702
+                 $mediaURLarr = [];
703
+                 $includedMediaFiles = '';
704
+
705
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
706
+
707
+                      $userroot = $this->view->getRoot();
708
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
709
+
710
+                      $flsharetarget = $this->folder->newFile($filetoshare);
711
+
712
+	              $share = $this->shareManager->newShare();
713
+	              $share->setNode($flsharetarget);
714
+	              $share->setPermissions(Constants::PERMISSION_READ);
715
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
716
+	              $share->setSharedBy($this->userId);
717
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
718
+                      $expirydate->add(new \DateInterval('P1D'));
719
+                      $share->setExpirationDate($expirydate);
720
+                      $shared = $this->shareManager->createShare($share);
721
+                      $shareToken = $shared->getToken();
722
+
723
+                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
724
+                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
725
+                 }
726
+
727
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
728
+		 $postedparamspl = json_encode($datatosendpl);
729
+
730
+		 $chpl = curl_init();
731
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
732
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
733
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
734
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
735
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
736
+		 curl_setopt($chpl, CURLOPT_POST, 1);
737
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
738
+		 $resultpl = curl_exec ($chpl);
739
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
740
+		 curl_close ($chpl);
741
+
742
+		 $decresultpl = json_decode($resultpl);
743
+
744
+                 if (property_exists($decresultpl, 'message_uuid')) {
745
+                     $messageidinit = $decresultpl->message_uuid;
746
+                     $messageid = $messageidinit[0];
747
+                 }
748
+
749
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
750
+
751
+                     if (property_exists($decresultpl, 'error')) {
752
+                         $messagestatus = "Error: " . $decresultpl->error;
753
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
754
+
755
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
756
+
757
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
758
+             }
759
+
760
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
761
+                 $messagefrom = "Plivo: " . $fromsender;
762
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
763
+
764
+             $messageto = $tonumber;
765
+             $messagenetwork = '';
766
+             $messageprice = '';
767
+
768
+             $messagedelivery = '';
769
+
770
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
771
+
772
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
773
+         }
774
+    }
775
+
776
+
777
+    /**
778
+     * @NoAdminRequired
779
+     */
780
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
781
+
782
+         $smsapicred = $this->service->getapicredentials($this->userId);
783
+
784
+         $sid = $smsapicred[15];
785
+         $token = $smsapicred[16];
786
+         $smsapirecurltw = $smsapicred[18];
787
+
788
+         $microinterval = $waitinterval * 1000;
789
+
790
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
791
+
792
+             usleep($microinterval);
793
+
794
+             $messagedatetw = date("Y-m-d H:i:s");
795
+
796
+             if ($ismms == 0) {
797
+
798
+                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
799
+                  $sentsmstextfintw = $sentsmstext;
800
+
801
+             } else {
802
+
803
+                 $mediaURLs = [];
804
+
805
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
806
+
807
+                      $userroot = $this->view->getRoot();
808
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
809
+
810
+                      $flsharetarget = $this->folder->newFile($filetoshare);
811
+
812
+	              $share = $this->shareManager->newShare();
813
+	              $share->setNode($flsharetarget);
814
+	              $share->setPermissions(Constants::PERMISSION_READ);
815
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
816
+	              $share->setSharedBy($this->userId);
817
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
818
+                      $expirydate->add(new \DateInterval('P1D'));
819
+                      $share->setExpirationDate($expirydate);
820
+                      $shared = $this->shareManager->createShare($share);
821
+                      $shareToken = $shared->getToken();
822
+
823
+                      $mediaURLs[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
824
+                 }
825
+
826
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
827
+                 $includedMediaFiles = '';
828
+
829
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
830
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
831
+                      $includedMediaFiles .= $mediaURLs[$m] . "<br><br>";
832
+                 }
833
+
834
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
835
+             }
836
+
837
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
838
+
839
+	     $chtw = curl_init();
840
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
841
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
842
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
843
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
844
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
845
+	     curl_setopt($chtw, CURLOPT_POST, 1);
846
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
847
+
848
+	     $resulttw = curl_exec ($chtw);
849
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
850
+	     curl_close ($chtw);
851
+
852
+             $decresulttw = json_decode($resulttw);
853
+
854
+             if ($resulttw) {
855
+                 $messageidtw = $decresulttw->sid;
856
+             } else { $messageidtw = ''; }
857
+
858
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
859
+                 $messagestatustw = 'The message has been accepted for delivery.';
860
+             } else {
861
+                 $messagestatustw = 'An error occurred while trying to send the message.';
862
+             }
863
+
864
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
865
+                 $messagefromtw = "Twilio: " . $fromsender;
866
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
867
+
868
+             $messagenetworktw = '';
869
+             $messagepricetw = '';
870
+             $messagedeliverytw = '';
871
+
872
+
873
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
874
+
875
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
876
+         }
877
+
878
+    }
879
+
880
+
881
+    /**
882
+     * @NoAdminRequired
883
+     */
884
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
885
+
886
+         $smsapicredfl = $this->service->getapicredentials($this->userId);
887
+
888
+         $flowapikey = $smsapicredfl[20];
889
+         $flowapisecret = $smsapicredfl[21];
890
+         $flowdelrecurl = $smsapicredfl[23];
891
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
892
+
893
+         $microinterval = $waitinterval * 1000;
894
+
895
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
896
+
897
+             usleep($microinterval);
898
+
899
+             $messagedatefl = date("Y-m-d H:i:s");
900
+
901
+             if ($ismms == 0) {
902
+
903
+                 $messagetextfinfl = $sentsmstext;
904
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
905
+
906
+             } else {
907
+
908
+		 $mediaurlsarr = [];
909
+
910
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
911
+
912
+		      $userroot = $this->view->getRoot();
913
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
914
+
915
+		      $flsharetarget = $this->folder->newFile($filetoshare);
916
+
917
+		      $share = $this->shareManager->newShare();
918
+		      $share->setNode($flsharetarget);
919
+		      $share->setPermissions(Constants::PERMISSION_READ);
920
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
921
+		      $share->setSharedBy($this->userId);
922
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
923
+                      $expirydate->add(new \DateInterval('P1D'));
924
+                      $share->setExpirationDate($expirydate);
925
+		      $shared = $this->shareManager->createShare($share);
926
+		      $shareToken = $shared->getToken();
927
+
928
+		      $mediaurlsarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
929
+		 }
930
+
931
+		 $includedMediaFiles = '';
932
+
933
+		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
934
+		      $includedMediaFiles .= $mediaurlsarr[$m] . "<br><br>";
935
+		 }
936
+
937
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
938
+
939
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
940
+             }
941
+
942
+
943
+	     $chfl = curl_init();
944
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
945
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
946
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
947
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
948
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
949
+	     curl_setopt($chfl, CURLOPT_POST, 1);
950
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
951
+	     $resultfl = curl_exec ($chfl);
952
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
953
+	     curl_close ($chfl);
954
+
955
+             $decresultfl = json_decode($resultfl);
956
+
957
+             if ($resultfl) {
958
+                 $messageidfl = $decresultfl->data->id;
959
+             } else { $messageidfl = ''; }
960
+
961
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
962
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
963
+             } else { 
964
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
965
+             }
966
+
967
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
968
+                 $messagefromfl = "Flowroute: " . $fromsender;
969
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
970
+
971
+             $messagetofl = $tonumberfl;
972
+             $messagenetworkfl = '';
973
+             $messagepricefl = '';
974
+             $messagedeliveryfl = '';
975
+
976
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
977
+
978
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
979
+         }
980
+
981
+    }
982
+
983
+
984
+    /**
985
+     * @NoAdminRequired
986
+     */
987
+    public function saveoldrecrows($userId, $oldrecRows) {
988
+
989
+           // Create the folder for removed messages if it doesn't exist
990
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
991
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
992
+           }
993
+           $savecheck = 0;
994
+
995
+           if (count($oldrecRows) > 1) {
996
+               $msfileContent = implode("", $oldrecRows);
997
+
998
+               $delrowsdate = date("Y-m-d_H-i-s");
999
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
1000
+
1001
+               $userroot = $this->view->getRoot();
1002
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
1003
+
1004
+               $target = $this->folder->newFile($targetfile);
1005
+               $target->putContent($msfileContent);
1006
+
1007
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
1008
+                   $savecheck = 1;
1009
+               }
1010
+           }
1011
+
1012
+           return $savecheck;
1013
+    }
1014
+
1015
+
1016
+    /**
1017
+     * @NoAdminRequired
1018
+     */
1019
+    public function saveoldsentrows($userId, $oldsentRows) {
1020
+
1021
+           // Create the folder for removed messages if it doesn't exist
1022
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
1023
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
1024
+           }
1025
+           $savesentcheck = 0;
1026
+
1027
+           if (count($oldsentRows) > 1) {
1028
+               $sntfileContent = implode("", $oldsentRows);
1029
+
1030
+               $delsentrowsdate = date("Y-m-d_H-i-s");
1031
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
1032
+
1033
+               $userroot = $this->view->getRoot();
1034
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
1035
+
1036
+               $snttarget = $this->folder->newFile($snttargetfile);
1037
+               $snttarget->putContent($sntfileContent);
1038
+
1039
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
1040
+                   $savesentcheck = 1;
1041
+               }
1042
+           }
1043
+
1044
+           return $savesentcheck;
1045
+    }
1046
+
1047
+
1048
+    /**
1049
+     * @NoAdminRequired
1050
+     */
1051
+    public function getreceivedtable($userId) {
1052
+           return $this->service->getreceivedtable($this->userId);
1053
+    }
1054
+
1055
+    /**
1056
+     * @NoAdminRequired
1057
+     */
1058
+    public function getreceivedtablefordel($userId) {
1059
+           return $this->service->getreceivedtablefordel($this->userId);
1060
+    }
1061
+
1062
+    /**
1063
+     * @NoAdminRequired
1064
+     */
1065
+    public function removerecrows($userId, $recmessagedbIDs) {
1066
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
1067
+    }
1068
+
1069
+    /**
1070
+     * @NoAdminRequired
1071
+     */
1072
+    public function getsenttable($userId) {
1073
+           return $this->service->getsenttable($this->userId);
1074
+    }
1075
+
1076
+    /**
1077
+     * @NoAdminRequired
1078
+     */
1079
+    public function getsenttablefordel($userId) {
1080
+           return $this->service->getsenttablefordel($this->userId);
1081
+    }
1082
+
1083
+    /**
1084
+     * @NoAdminRequired
1085
+     */
1086
+    public function removesentrows($userId, $sentmessagedbIDs) {
1087
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1088
+    }
1089
+
1090
+    /**
1091
+     * @NoAdminRequired
1092
+     */
1093
+    public function getgroupedtable($userId) {
1094
+           return $this->service->getgroupedtable($this->userId);
1095
+    }
1096
+
1097
+    /**
1098
+     * @NoAdminRequired
1099
+     */
1100
+    public function savedisplayname($userId, $authorDisplayname, $from) {
1101
+           return $this->service->savedisplayname($this->userId, $authorDisplayname, $from);
1102
+    }
1103
+
1104
+    /**
1105
+     * @NoAdminRequired
1106
+     */
1107
+    public function getmessagesperpage($userId) {
1108
+           return $this->service->getmessagesperpage($this->userId);
1109
+    }
1110
+
1111
+    /**
1112
+     * @NoAdminRequired
1113
+     */
1114
+    public function getdelrecsettings($userId) {
1115
+           return $this->service->getdelrecsettings($this->userId);
1116
+    }
1117
+
1118
+    public function updatenumberrestrictions($userId, $savedByDsplname, $phoneNumber, $groups, $users) {
1119
+           return $this->service->updatenumberrestrictions($this->userId, $savedByDsplname, $phoneNumber, $groups, $users);
1120
+    }
1121
+
1122
+    public function removenumberrestrictions($userId, $phoneNumber) {
1123
+           return $this->service->removenumberrestrictions($this->userId, $phoneNumber);
1124
+    }
1125
+
1126
+    /**
1127
+     * @NoAdminRequired
1128
+     */
1129
+    public function updateautoreplies($userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText) {
1130
+           return $this->service->updateautoreplies($this->userId, $savedByDsplname, $phoneNumber, $daysOfWeek, $dailyStart, $dailyEnd, $vacationStart, $vacationEnd, $messageText);
1131
+    }
1132
+
1133
+    /**
1134
+     * @NoAdminRequired
1135
+     */
1136
+    public function removeautoreplies($userId, $phoneNumber) {
1137
+           return $this->service->removeautoreplies($this->userId, $phoneNumber);
1138
+    }
1139
+
1140
+    /**
1141
+     * @NoAdminRequired
1142
+     */
1143
+    public function getsettings($userId) {
1144
+           return $this->service->getsettings($this->userId);
1145
+    }
1146
+
1147
+    public function getadminsettings($userId) {
1148
+           return $this->service->getadminsettings($this->userId);
1149
+    }
1150
+
1151
+    /**
1152
+     * @NoAdminRequired
1153
+     */
1154
+    public function getautoreplyconf($userId) {
1155
+
1156
+           // Get the available phone numbers for the current user (the restricted phone numbers are excluded)
1157
+           $availphonenmbrs = $this->getsmsnumbers($this->userId);
1158
+
1159
+           // Get the display name of the current user
1160
+           $usrid = $this->userId;
1161
+           $getusrdnm = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
1162
+	   $getusrdnmres = $getusrdnm->execute([$usrid, 'displayname']);
1163
+	   $getusrdnmdata = $getusrdnmres->fetch();
1164
+	   $userDisplayNm = $getusrdnmdata['value'];
1165
+	   $getusrdnmres->closeCursor();
1166
+
1167
+           // Get the auto-replies for the available phone numbers
1168
+           $getautorpl = $this->connection->prepare('SELECT `saved_by_dsplname`, `phone_number`, `days_of_week`, `daily_start`, `daily_end`, `vacation_start`, `vacation_end`, 
1169
+                                                    `message_text` FROM `*PREFIX*sms_relent_autorply`');
1170
+	   $getautorplres = $getautorpl->execute();
1171
+           $autorplconf = [];
1172
+	   while ($acdatausrdnadm = $getautorplres->fetch()) {
1173
+                  $autorplconf[] = $acdatausrdnadm;
1174
+           }
1175
+	   $getautorplres->closeCursor();
1176
+
1177
+           if ($autorplconf) {
1178
+
1179
+               $autoreplyconf = [];
1180
+               foreach ($autorplconf as $arkey => $arvalue) {
1181
+                        if (in_array($arvalue['phone_number'], $availphonenmbrs)) {
1182
+                            $autoreplyconf[] = $arvalue;
1183
+                        }
1184
+               }
1185
+
1186
+           } else { $autoreplyconf = ''; }
1187
+
1188
+           $autoreplyfdb = ['userdisplayname' => $userDisplayNm, 'phonenumbers' => $availphonenmbrs, 'autoreplies' => $autoreplyconf];
1189
+
1190
+           return $autoreplyfdb;
1191
+    }
1192
+
1193
+    /**
1194
+     * @NoAdminRequired
1195
+     */
1196
+    public function getgroupedpernumber($userId, $phoneNumber) {
1197
+           return $this->service->getgroupedpernumber($this->userId, $phoneNumber);
1198
+    }
1199
+
1200
+    /**
1201
+     * @NoAdminRequired
1202
+     */
1203
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showDisplayNames) {
1204
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $showDisplayNames);
1205
+    }
1206
+
1207
+    public function updateadminsettings($userId, $showAllMessages) {
1208
+           return $this->service->updateadminsettings($this->userId, $showAllMessages);
1209
+    }
1210
+}
Browse code

removed a substantial number of files

DoubleBastionAdmin authored on 08/05/2023 20:27:04
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1035 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\IURLGenerator;
49
-use OCP\Share\IManager;
50
-use OCP\Constants;
51
-
52
-
53
-
54
-class SmsrelentlessController extends Controller {
55
-
56
-    private $service;
57
-    private $config;
58
-    private $userId;
59
-    private $folder;
60
-    private $filesystem;
61
-    private $view;
62
-    private $urlGenerator;
63
-    private $shareManager;
64
-
65
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager) {
66
-        parent::__construct($appName, $request);
67
-        $this->service = $service;
68
-        $this->config = $config;
69
-        $this->userId = $userId;
70
-        $this->folder = $folder;
71
-        $this->filesystem = $filesystem;
72
-        $this->view = $view;
73
-	$this->urlGenerator = $urlGenerator;
74
-	$this->shareManager = $shareManager;
75
-    }
76
-
77
-
78
-    /**
79
-     * @NoAdminRequired
80
-     */
81
-    public function object_to_array($obj) {
82
-        if(is_object($obj)) $obj = (array)$this->dismount($obj);
83
-        if(is_array($obj)) {
84
-           $new = array();
85
-           foreach($obj as $key => $val) {
86
-               $new[$key] = $this->object_to_array($val);
87
-           }
88
-        }
89
-        else $new = $obj;
90
-        return $new;
91
-    }
92
-
93
-
94
-    /**
95
-     * @NoAdminRequired
96
-     */
97
-    public function dismount($object) {
98
-        $reflectionClass = new ReflectionClass(get_class($object));
99
-        $array = array();
100
-        foreach ($reflectionClass->getProperties() as $property) {
101
-           $property->setAccessible(true);
102
-           $array[$property->getName()] = $property->getValue($object);
103
-           $property->setAccessible(false);
104
-        }
105
-        return $array;
106
-    }
107
-
108
-
109
-    /**
110
-     * @NoAdminRequired
111
-     */
112
-    public function getbalancetel($userId) {
113
-
114
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
115
-
116
-        $telapikey = $telsmsapicred[0];
117
-        $ch = curl_init();
118
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
119
-
120
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
121
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
122
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
123
-        $responsetel = curl_exec($ch);
124
-        $recdatatel = json_decode($responsetel, TRUE);
125
-        $telbalresponse = $recdatatel['data']['balance'];
126
-        $currentbalancetel = round(floatval($telbalresponse), 3);
127
-        curl_close($ch);
128
-
129
-        return $currentbalancetel;
130
-    }
131
-
132
-
133
-    /**
134
-     * @NoAdminRequired
135
-     */
136
-    public function getbalancenex($userId) {
137
-
138
-        $smsapicred = $this->service->getapicredentials($this->userId);
139
-        $smsapikey = $smsapicred[5];
140
-        $smsapisecret = $smsapicred[6];
141
-
142
-        if ($smsapikey == '' || $smsapisecret == '') {
143
-            $currentbalancenex = "N/A";
144
-        } else {
145
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
146
-            $mesdata = file_get_contents($getmesdata);
147
-            $datainit = json_decode($mesdata);
148
-            $balancenex = $datainit->cash_credits;
149
-            $currentbalancenex = round(floatval($balancenex), 3);
150
-        }
151
-        return $currentbalancenex;
152
-    }
153
-
154
-
155
-    /**
156
-     * @NoAdminRequired
157
-     */
158
-    public function getbalancetwil($userId) {
159
-
160
-        $smsapicred = $this->service->getapicredentials($this->userId);
161
-        $smsapisid = $smsapicred[15];
162
-        $smsapitoken = $smsapicred[16];
163
-
164
-        if ($smsapisid == '' || $smsapitoken == '') {
165
-            $currentbalancetwil = "N/A";
166
-        } else {
167
-
168
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
169
-            $balancetwil = $twilbalance->balance;
170
-
171
-            $currentbalancetwil = round(floatval($balancetwil), 3);
172
-        }
173
-        return $currentbalancetwil;
174
-    }
175
-
176
-
177
-    /**
178
-     * @NoAdminRequired
179
-     */
180
-    public function getbalanceflow($userId) {
181
-
182
-        $currentbalanceflow = 'n/a';
183
-
184
-        return $currentbalanceflow;
185
-    }
186
-
187
-
188
-    /**
189
-     * @NoAdminRequired
190
-     */
191
-    public function getsmsnumbers($userId) {
192
-
193
-        $smsapicred = $this->service->getapicredentials($this->userId);
194
-
195
-        $telnyxkey = $smsapicred[0];
196
-
197
-        $nexapikey = $smsapicred[5];
198
-        $nexapisecret = $smsapicred[6];
199
-
200
-        $twilapikey = $smsapicred[15];
201
-        $twilapisecret = $smsapicred[16];
202
-
203
-        $flowapikey = $smsapicred[20];
204
-        $flowapisecret = $smsapicred[21];
205
-
206
-        $telsendernameinit = $smsapicred[9];
207
-        $nexsendernameinit = $smsapicred[10];
208
-        $twilsendernameinit = $smsapicred[19];
209
-
210
-        $telsendername = "Tx: " . $telsendernameinit;
211
-        $nexsendername = "Pl: " . $nexsendernameinit;
212
-        $twilsendername = "Tw: " . $twilsendernameinit;
213
-
214
-        // Get Telnyx phone numbers
215
-        if ($telnyxkey != '') {
216
-
217
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
218
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
219
-
220
-           $telnumbersarr = $this->object_to_array($telnumbers);
221
-           $telnmbrs = [];
222
-
223
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
224
-              if (is_int($nmbkey)) {
225
-                 foreach ($nmbvalue as $nkey => $nvalue) {
226
-                    if ($nkey == 'phone_number') {
227
-                       $telnmbrs[] = "Tx: " . $nvalue;
228
-                    }
229
-                 }
230
-              }
231
-           }
232
-
233
-        } else { $telnmbrs = []; }
234
-
235
-        // Get Plivo phone numbers
236
-        if ($nexapikey != '' && $nexapisecret != '') {
237
-
238
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
239
-           $acdata = file_get_contents($getacdata);
240
-           $datainit = json_decode($acdata, true);
241
-
242
-           $findata = $this->object_to_array($datainit);
243
-
244
-           $nexcurrentnmbrs = [];
245
-
246
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
247
-                   if (is_array($smsvalue)) {
248
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
249
-                               if ($smskey2 == 'number') {
250
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
251
-                               }
252
-                         }
253
-                   }
254
-           }
255
-
256
-
257
-        } else { $nexcurrentnmbrs = []; }
258
-
259
-        // Get Twilio phone numbers
260
-        if ($twilapikey != '' && $twilapisecret != '') {
261
-
262
-            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
263
-            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
264
-
265
-            $twilcurrentnmbrs = [];
266
-            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
267
-                 if (is_array($twnbvalue)) {
268
-                     foreach ($twnbvalue as $twfkey => $twfvalue) {
269
-                          if ($twfkey == 'phone_number') {
270
-                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
271
-                          }
272
-                     }
273
-                 }
274
-            }
275
-
276
-        } else { $twilcurrentnmbrs = []; }
277
-
278
-        // Get Flowroute phone numbers
279
-        if ($flowapikey != '' && $flowapisecret != '') {
280
-
281
-            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
282
-            $flnbrsarr = $flnbrsresult->data;
283
-            $flowcurrentnmbrs = [];
284
-            foreach ($flnbrsarr as $flkey => $flitem) {
285
-                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
286
-            }
287
-
288
-        } else { $flowcurrentnmbrs = []; }
289
-
290
-
291
-        $telsenderarr = [0 => $telsendername];
292
-        $nexsenderarr = [0 => $nexsendername];
293
-        $twilsenderarr = [0 => $twilsendername];
294
-
295
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
296
-
297
-        return $currentnmbrs;
298
-    }
299
-
300
-
301
-    /**
302
-     * @NoAdminRequired
303
-     */
304
-    public function cleantempdir($userId) {
305
-
306
-        // Create the temporary folder if it doesn't exist
307
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
308
-            $this->folder->newFolder('SMS_Relentless/temp_files');
309
-        }
310
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
311
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
312
-        $fileSystemIterator = new FilesystemIterator($targetdir);
313
-
314
-        $dirfiles = [];
315
-        foreach ($fileSystemIterator as $fileInfo){
316
-                 $dirfiles[] = $fileInfo->getFilename();
317
-        }
318
-
319
-        foreach ($dirfiles as $key => $indfile) {
320
-                 $thisuserroot = $this->view->getRoot();
321
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
322
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
323
-        }
324
-     }
325
-
326
-
327
-    /**
328
-     * @NoAdminRequired
329
-     */
330
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
331
-
332
-        // Create the temporary folder if it doesn't exist
333
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
334
-            $this->folder->newFolder('SMS_Relentless/temp_files');
335
-        }
336
-
337
-        // First delete any file that has been previously uploaded
338
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
339
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
340
-        $fileSystemIterator = new FilesystemIterator($targetdir);
341
-
342
-        $dirfiles = [];
343
-        foreach ($fileSystemIterator as $fileInfo){
344
-                 $dirfiles[] = $fileInfo->getFilename();
345
-        }
346
-
347
-        foreach ($dirfiles as $key => $indfile) {
348
-                 $thisuserroot = $this->view->getRoot();
349
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
350
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
351
-        }
352
-
353
-        // Upload the new file
354
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
355
-        $fileName = $_FILES['uploadfileforsms']['name'];
356
-
357
-        $userroot = $this->view->getRoot();
358
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
359
-
360
-        $target = $this->folder->newFile($targetfile);
361
-        $target->putContent($fileContent);
362
-
363
-        // Extract the phone numbers from the file
364
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
365
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
366
-        $numberarrayfourth = explode(",", $numberarraytert);
367
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
368
-        $numberarray = array_unique($numberarrayfifth);
369
-
370
-        return $numberarray;
371
-    }
372
-
373
-
374
-    /**
375
-     * @NoAdminRequired
376
-     */
377
-    public function uploadfile($uploadfileformms) {
378
-
379
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
380
-           $fileName = $_FILES['uploadfileformms']['name'];
381
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
382
-           $fileSize = $fileSizeinit / 1024;
383
-
384
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
385
-               $this->folder->newFolder('SMS_Relentless/temp_files');
386
-           }
387
-
388
-           $userroot = $this->view->getRoot();
389
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
390
-
391
-           $target = $this->folder->newFile($targetfile);
392
-           $target->putContent($fileContent);
393
-
394
-           // Get the cumulative files size of the uploaded files
395
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
396
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
397
-
398
-           $fileSystemIterator = new FilesystemIterator($targetdir);
399
-
400
-           $dirfiles = [];
401
-           foreach ($fileSystemIterator as $fileInfo){
402
-                    $dirfiles[] = $fileInfo->getFilename();
403
-           }
404
-
405
-           $totalflsizeinit = 0;
406
-           foreach ($dirfiles as $key => $indfile) {
407
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
408
-                    $mbSize = round($fileSizeinit / 1024, 4);
409
-                    $totalflsizeinit += $mbSize;
410
-           }
411
-
412
-           $totalflsize = round($totalflsizeinit, 4);
413
-
414
-           return $totalflsize;
415
-    }
416
-
417
-
418
-    /**
419
-     * @NoAdminRequired
420
-     */
421
-    public function pickfile($path) {
422
-
423
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
424
-               $this->folder->newFolder('SMS_Relentless/temp_files');
425
-           }
426
-
427
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
428
-
429
-           $fltgt = $datadir . $this->userId . "/files" . $path;
430
-
431
-           $fileContent = file_get_contents($fltgt);
432
-
433
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
434
-
435
-           $patharr = explode("/", $path);
436
-
437
-           $revarr = array_reverse($patharr);
438
-
439
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
440
-
441
-           $target = $this->folder->newFile($relflpath);
442
-
443
-           $target->putContent($fileContent);
444
-
445
-           // Get the cumulative files size of the uploaded files
446
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
447
-
448
-           $fileSystemIterator = new FilesystemIterator($targetdir);
449
-
450
-           $dirfiles = [];
451
-           foreach ($fileSystemIterator as $fileInfo) {
452
-                    $dirfiles[] = $fileInfo->getFilename();
453
-           }
454
-
455
-           $totalflsizeinit = 0;
456
-
457
-           foreach ($dirfiles as $key => $indfile) {
458
-
459
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
460
-                    $mbSize = round($fileSizeinit / 1024, 4);
461
-                    $totalflsizeinit += $mbSize;
462
-           }
463
-
464
-           $totalflsize = round($totalflsizeinit, 4);
465
-
466
-           $pickresult = [$totalflsize, $pkfilesize];
467
-
468
-           return $pickresult;
469
-    }
470
-
471
-
472
-    /**
473
-     * @NoAdminRequired
474
-     */
475
-    public function removeupfile($removedfilename) {
476
-
477
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
478
-
479
-           $removefile = $this->view->unlink($tmpfl);
480
-
481
-           // Get the cumulative files size of the uploaded files
482
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
483
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
484
-           $fileSystemIterator = new FilesystemIterator($targetdir);
485
-
486
-           $dirfiles = [];
487
-           foreach ($fileSystemIterator as $fileInfo){
488
-                    $dirfiles[] = $fileInfo->getFilename();
489
-           }
490
-
491
-           $totalflsizeinit = 0;
492
-
493
-           foreach ($dirfiles as $key => $indfile) {
494
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
495
-                    $mbSize = round($fileSizeinit / 1024, 4);
496
-                    $totalflsizeinit += $mbSize;
497
-           }
498
-
499
-           $totalflsize = round($totalflsizeinit, 4);
500
-
501
-           return $totalflsize;
502
-    }
503
-
504
-
505
-    /**
506
-     * @NoAdminRequired
507
-     */
508
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
509
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
510
-         $telnyxkey = $telsmsapicred[0];
511
-         $teldelrecurl = $telsmsapicred[3];
512
-         $messagingprofid = $telsmsapicred[4];
513
-
514
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
515
-
516
-         $microinterval = $waitinterval * 1000;
517
-
518
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
519
-
520
-             usleep($microinterval);
521
-
522
-             $messagedate = date("Y-m-d H:i:s");
523
-
524
-             if ($ismms == 0) {
525
-
526
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
527
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
528
-                 } else {
529
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
530
-                 }
531
-
532
-                 $messagetexttel = $sentsmstext;
533
-
534
-             } else {
535
-
536
-                 $mediaURLarr = [];
537
-                 $includedMediaFiles = '';
538
-
539
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
540
-
541
-                      $userroot = $this->view->getRoot();
542
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
543
-
544
-                      $flsharetarget = $this->folder->newFile($filetoshare);
545
-
546
-	              $share = $this->shareManager->newShare();
547
-	              $share->setNode($flsharetarget);
548
-	              $share->setPermissions(Constants::PERMISSION_READ);
549
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
550
-	              $share->setSharedBy($this->userId);
551
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
552
-                      $expirydate->add(new \DateInterval('P1D'));
553
-                      $share->setExpirationDate($expirydate);
554
-                      $shared = $this->shareManager->createShare($share);
555
-                      $shareToken = $shared->getToken();
556
-
557
-                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
558
-                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
559
-                 }
560
-
561
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
562
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
563
-                 } else {
564
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
565
-                 }
566
-
567
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
568
-             }
569
-
570
-             $messageid = $message['id'];
571
-             $messagefrom = "Telnyx: " . $fromsender;
572
-             $messageto = $tonumber;
573
-             $messagenetwork = null;
574
-             $messageprice = null;
575
-             $messagestatus = $message['to'][0]['status'];
576
-             $messagedelivery = null;
577
-
578
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
579
-
580
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
581
-
582
-         }
583
-    }
584
-
585
-
586
-    /**
587
-     * @NoAdminRequired
588
-     */
589
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
590
-
591
-         $smsapicred = $this->service->getapicredentials($this->userId);
592
-
593
-         $smsapikey = $smsapicred[5];
594
-         $smsapisecret = $smsapicred[6];
595
-         $smsapideliveryrecurl = $smsapicred[8];
596
-
597
-         $microinterval = $waitinterval * 1000;
598
-
599
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
600
-
601
-             usleep($microinterval);
602
-
603
-             $messagedatepl = date("Y-m-d H:i:s");
604
-
605
-             if ($ismms == 0) {
606
-
607
-                 $client = new RestClient($smsapikey, $smsapisecret);
608
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
609
-                 $messagetextpl = $sentsmstext;
610
-	         $messageidinit = $response->getmessageUuid(0);
611
-                 $messageid = $messageidinit[0];
612
-
613
-                 if (property_exists($response, 'error')) { 
614
-                     $messagestatus = "Error: " . $response->error;
615
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
616
-
617
-             } else {
618
-
619
-                 $mediaURLarr = [];
620
-                 $includedMediaFiles = '';
621
-
622
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
623
-
624
-                      $userroot = $this->view->getRoot();
625
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
626
-
627
-                      $flsharetarget = $this->folder->newFile($filetoshare);
628
-
629
-	              $share = $this->shareManager->newShare();
630
-	              $share->setNode($flsharetarget);
631
-	              $share->setPermissions(Constants::PERMISSION_READ);
632
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
633
-	              $share->setSharedBy($this->userId);
634
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
635
-                      $expirydate->add(new \DateInterval('P1D'));
636
-                      $share->setExpirationDate($expirydate);
637
-                      $shared = $this->shareManager->createShare($share);
638
-                      $shareToken = $shared->getToken();
639
-
640
-                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
641
-                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
642
-                 }
643
-
644
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
645
-		 $postedparamspl = json_encode($datatosendpl);
646
-
647
-		 $chpl = curl_init();
648
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
649
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
650
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
651
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
652
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
653
-		 curl_setopt($chpl, CURLOPT_POST, 1);
654
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
655
-		 $resultpl = curl_exec ($chpl);
656
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
657
-		 curl_close ($chpl);
658
-
659
-		 $decresultpl = json_decode($resultpl);
660
-
661
-                 if (property_exists($decresultpl, 'message_uuid')) {
662
-                     $messageidinit = $decresultpl->message_uuid;
663
-                     $messageid = $messageidinit[0];
664
-                 }
665
-
666
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
667
-
668
-                     if (property_exists($decresultpl, 'error')) {
669
-                         $messagestatus = "Error: " . $decresultpl->error;
670
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
671
-
672
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
673
-
674
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
675
-             }
676
-
677
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
678
-                 $messagefrom = "Plivo: " . $fromsender;
679
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
680
-
681
-             $messageto = $tonumber;
682
-             $messagenetwork = '';
683
-             $messageprice = '';
684
-
685
-             $messagedelivery = '';
686
-
687
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
688
-
689
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
690
-         }
691
-    }
692
-
693
-
694
-    /**
695
-     * @NoAdminRequired
696
-     */
697
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
698
-
699
-         $smsapicred = $this->service->getapicredentials($this->userId);
700
-
701
-         $sid = $smsapicred[15];
702
-         $token = $smsapicred[16];
703
-         $smsapirecurltw = $smsapicred[18];
704
-
705
-         $microinterval = $waitinterval * 1000;
706
-
707
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
708
-
709
-             usleep($microinterval);
710
-
711
-             $messagedatetw = date("Y-m-d H:i:s");
712
-
713
-             if ($ismms == 0) {
714
-
715
-                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
716
-                  $sentsmstextfintw = $sentsmstext;
717
-
718
-             } else {
719
-
720
-                 $mediaURLs = [];
721
-
722
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
723
-
724
-                      $userroot = $this->view->getRoot();
725
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
726
-
727
-                      $flsharetarget = $this->folder->newFile($filetoshare);
728
-
729
-	              $share = $this->shareManager->newShare();
730
-	              $share->setNode($flsharetarget);
731
-	              $share->setPermissions(Constants::PERMISSION_READ);
732
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
733
-	              $share->setSharedBy($this->userId);
734
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
735
-                      $expirydate->add(new \DateInterval('P1D'));
736
-                      $share->setExpirationDate($expirydate);
737
-                      $shared = $this->shareManager->createShare($share);
738
-                      $shareToken = $shared->getToken();
739
-
740
-                      $mediaURLs[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
741
-                 }
742
-
743
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
744
-                 $includedMediaFiles = '';
745
-
746
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
747
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
748
-                      $includedMediaFiles .= $mediaURLs[$m] . "<br><br>";
749
-                 }
750
-
751
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
752
-             }
753
-
754
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
755
-
756
-	     $chtw = curl_init();
757
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
758
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
759
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
760
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
761
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
762
-	     curl_setopt($chtw, CURLOPT_POST, 1);
763
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
764
-
765
-	     $resulttw = curl_exec ($chtw);
766
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
767
-	     curl_close ($chtw);
768
-
769
-             $decresulttw = json_decode($resulttw);
770
-
771
-             if ($resulttw) {
772
-                 $messageidtw = $decresulttw->sid;
773
-             } else { $messageidtw = ''; }
774
-
775
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
776
-                 $messagestatustw = 'The message has been accepted for delivery.';
777
-             } else {
778
-                 $messagestatustw = 'An error occurred while trying to send the message.';
779
-             }
780
-
781
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
782
-                 $messagefromtw = "Twilio: " . $fromsender;
783
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
784
-
785
-             $messagenetworktw = '';
786
-             $messagepricetw = '';
787
-             $messagedeliverytw = '';
788
-
789
-
790
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
791
-
792
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
793
-         }
794
-
795
-    }
796
-
797
-
798
-    /**
799
-     * @NoAdminRequired
800
-     */
801
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
802
-
803
-         $smsapicredfl = $this->service->getapicredentials($this->userId);
804
-
805
-         $flowapikey = $smsapicredfl[20];
806
-         $flowapisecret = $smsapicredfl[21];
807
-         $flowdelrecurl = $smsapicredfl[23];
808
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
809
-
810
-         $microinterval = $waitinterval * 1000;
811
-
812
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
813
-
814
-             usleep($microinterval);
815
-
816
-             $messagedatefl = date("Y-m-d H:i:s");
817
-
818
-             if ($ismms == 0) {
819
-
820
-                 $messagetextfinfl = $sentsmstext;
821
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
822
-
823
-             } else {
824
-
825
-		 $mediaurlsarr = [];
826
-
827
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
828
-
829
-		      $userroot = $this->view->getRoot();
830
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
831
-
832
-		      $flsharetarget = $this->folder->newFile($filetoshare);
833
-
834
-		      $share = $this->shareManager->newShare();
835
-		      $share->setNode($flsharetarget);
836
-		      $share->setPermissions(Constants::PERMISSION_READ);
837
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
838
-		      $share->setSharedBy($this->userId);
839
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
840
-                      $expirydate->add(new \DateInterval('P1D'));
841
-                      $share->setExpirationDate($expirydate);
842
-		      $shared = $this->shareManager->createShare($share);
843
-		      $shareToken = $shared->getToken();
844
-
845
-		      $mediaurlsarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
846
-		 }
847
-
848
-		 $includedMediaFiles = '';
849
-
850
-		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
851
-		      $includedMediaFiles .= $mediaurlsarr[$m] . "<br><br>";
852
-		 }
853
-
854
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
855
-
856
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
857
-             }
858
-
859
-
860
-	     $chfl = curl_init();
861
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
862
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
863
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
864
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
865
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
866
-	     curl_setopt($chfl, CURLOPT_POST, 1);
867
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
868
-	     $resultfl = curl_exec ($chfl);
869
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
870
-	     curl_close ($chfl);
871
-
872
-             $decresultfl = json_decode($resultfl);
873
-
874
-             if ($resultfl) {
875
-                 $messageidfl = $decresultfl->data->id;
876
-             } else { $messageidfl = ''; }
877
-
878
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
879
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
880
-             } else { 
881
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
882
-             }
883
-
884
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
885
-                 $messagefromfl = "Flowroute: " . $fromsender;
886
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
887
-
888
-             $messagetofl = $tonumberfl;
889
-             $messagenetworkfl = '';
890
-             $messagepricefl = '';
891
-             $messagedeliveryfl = '';
892
-
893
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
894
-
895
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
896
-         }
897
-
898
-    }
899
-
900
-
901
-    /**
902
-     * @NoAdminRequired
903
-     */
904
-    public function saveoldrecrows($userId, $oldrecRows) {
905
-
906
-           // Create the folder for removed messages if it doesn't exist
907
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
908
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
909
-           }
910
-           $savecheck = 0;
911
-
912
-           if (count($oldrecRows) > 1) {
913
-               $msfileContent = implode("", $oldrecRows);
914
-
915
-               $delrowsdate = date("Y-m-d_H-i-s");
916
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
917
-
918
-               $userroot = $this->view->getRoot();
919
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
920
-
921
-               $target = $this->folder->newFile($targetfile);
922
-               $target->putContent($msfileContent);
923
-
924
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
925
-                   $savecheck = 1;
926
-               }
927
-           }
928
-
929
-           return $savecheck;
930
-    }
931
-
932
-
933
-    /**
934
-     * @NoAdminRequired
935
-     */
936
-    public function saveoldsentrows($userId, $oldsentRows) {
937
-
938
-           // Create the folder for removed messages if it doesn't exist
939
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
940
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
941
-           }
942
-           $savesentcheck = 0;
943
-
944
-           if (count($oldsentRows) > 1) {
945
-               $sntfileContent = implode("", $oldsentRows);
946
-
947
-               $delsentrowsdate = date("Y-m-d_H-i-s");
948
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
949
-
950
-               $userroot = $this->view->getRoot();
951
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
952
-
953
-               $snttarget = $this->folder->newFile($snttargetfile);
954
-               $snttarget->putContent($sntfileContent);
955
-
956
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
957
-                   $savesentcheck = 1;
958
-               }
959
-           }
960
-
961
-           return $savesentcheck;
962
-    }
963
-
964
-
965
-    /**
966
-     * @NoAdminRequired
967
-     */
968
-    public function getreceivedtable($userId) {
969
-           return $this->service->getreceivedtable($this->userId);
970
-    }
971
-
972
-    /**
973
-     * @NoAdminRequired
974
-     */
975
-    public function getreceivedtablefordel($userId) {
976
-           return $this->service->getreceivedtablefordel($this->userId);
977
-    }
978
-
979
-    /**
980
-     * @NoAdminRequired
981
-     */
982
-    public function removerecrows($userId, $recmessagedbIDs) {
983
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
984
-    }
985
-
986
-    /**
987
-     * @NoAdminRequired
988
-     */
989
-    public function getsenttable($userId) {
990
-           return $this->service->getsenttable($this->userId);
991
-    }
992
-
993
-    /**
994
-     * @NoAdminRequired
995
-     */
996
-    public function getsenttablefordel($userId) {
997
-           return $this->service->getsenttablefordel($this->userId);
998
-    }
999
-
1000
-    /**
1001
-     * @NoAdminRequired
1002
-     */
1003
-    public function removesentrows($userId, $sentmessagedbIDs) {
1004
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1005
-    }
1006
-
1007
-    /**
1008
-     * @NoAdminRequired
1009
-     */
1010
-    public function getmessagesperpage($userId) {
1011
-           return $this->service->getmessagesperpage($this->userId);
1012
-    }
1013
-
1014
-    /**
1015
-     * @NoAdminRequired
1016
-     */
1017
-    public function getdelrecsettings($userId) {
1018
-           return $this->service->getdelrecsettings($this->userId);
1019
-    }
1020
-
1021
-    /**
1022
-     * @NoAdminRequired
1023
-     */
1024
-    public function getsettings($userId) {
1025
-           return $this->service->getsettings($this->userId);
1026
-    }
1027
-
1028
-    /**
1029
-     * @NoAdminRequired
1030
-     */
1031
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl) {
1032
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl);
1033
-    }
1034
-
1035
-}
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/settings.js templates/settings.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php

DoubleBastionAdmin authored on 08/09/2022 21:56:39
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1035 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\IURLGenerator;
49
+use OCP\Share\IManager;
50
+use OCP\Constants;
51
+
52
+
53
+
54
+class SmsrelentlessController extends Controller {
55
+
56
+    private $service;
57
+    private $config;
58
+    private $userId;
59
+    private $folder;
60
+    private $filesystem;
61
+    private $view;
62
+    private $urlGenerator;
63
+    private $shareManager;
64
+
65
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager) {
66
+        parent::__construct($appName, $request);
67
+        $this->service = $service;
68
+        $this->config = $config;
69
+        $this->userId = $userId;
70
+        $this->folder = $folder;
71
+        $this->filesystem = $filesystem;
72
+        $this->view = $view;
73
+	$this->urlGenerator = $urlGenerator;
74
+	$this->shareManager = $shareManager;
75
+    }
76
+
77
+
78
+    /**
79
+     * @NoAdminRequired
80
+     */
81
+    public function object_to_array($obj) {
82
+        if(is_object($obj)) $obj = (array)$this->dismount($obj);
83
+        if(is_array($obj)) {
84
+           $new = array();
85
+           foreach($obj as $key => $val) {
86
+               $new[$key] = $this->object_to_array($val);
87
+           }
88
+        }
89
+        else $new = $obj;
90
+        return $new;
91
+    }
92
+
93
+
94
+    /**
95
+     * @NoAdminRequired
96
+     */
97
+    public function dismount($object) {
98
+        $reflectionClass = new ReflectionClass(get_class($object));
99
+        $array = array();
100
+        foreach ($reflectionClass->getProperties() as $property) {
101
+           $property->setAccessible(true);
102
+           $array[$property->getName()] = $property->getValue($object);
103
+           $property->setAccessible(false);
104
+        }
105
+        return $array;
106
+    }
107
+
108
+
109
+    /**
110
+     * @NoAdminRequired
111
+     */
112
+    public function getbalancetel($userId) {
113
+
114
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
115
+
116
+        $telapikey = $telsmsapicred[0];
117
+        $ch = curl_init();
118
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
119
+
120
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
121
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
122
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
123
+        $responsetel = curl_exec($ch);
124
+        $recdatatel = json_decode($responsetel, TRUE);
125
+        $telbalresponse = $recdatatel['data']['balance'];
126
+        $currentbalancetel = round(floatval($telbalresponse), 3);
127
+        curl_close($ch);
128
+
129
+        return $currentbalancetel;
130
+    }
131
+
132
+
133
+    /**
134
+     * @NoAdminRequired
135
+     */
136
+    public function getbalancenex($userId) {
137
+
138
+        $smsapicred = $this->service->getapicredentials($this->userId);
139
+        $smsapikey = $smsapicred[5];
140
+        $smsapisecret = $smsapicred[6];
141
+
142
+        if ($smsapikey == '' || $smsapisecret == '') {
143
+            $currentbalancenex = "N/A";
144
+        } else {
145
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
146
+            $mesdata = file_get_contents($getmesdata);
147
+            $datainit = json_decode($mesdata);
148
+            $balancenex = $datainit->cash_credits;
149
+            $currentbalancenex = round(floatval($balancenex), 3);
150
+        }
151
+        return $currentbalancenex;
152
+    }
153
+
154
+
155
+    /**
156
+     * @NoAdminRequired
157
+     */
158
+    public function getbalancetwil($userId) {
159
+
160
+        $smsapicred = $this->service->getapicredentials($this->userId);
161
+        $smsapisid = $smsapicred[15];
162
+        $smsapitoken = $smsapicred[16];
163
+
164
+        if ($smsapisid == '' || $smsapitoken == '') {
165
+            $currentbalancetwil = "N/A";
166
+        } else {
167
+
168
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
169
+            $balancetwil = $twilbalance->balance;
170
+
171
+            $currentbalancetwil = round(floatval($balancetwil), 3);
172
+        }
173
+        return $currentbalancetwil;
174
+    }
175
+
176
+
177
+    /**
178
+     * @NoAdminRequired
179
+     */
180
+    public function getbalanceflow($userId) {
181
+
182
+        $currentbalanceflow = 'n/a';
183
+
184
+        return $currentbalanceflow;
185
+    }
186
+
187
+
188
+    /**
189
+     * @NoAdminRequired
190
+     */
191
+    public function getsmsnumbers($userId) {
192
+
193
+        $smsapicred = $this->service->getapicredentials($this->userId);
194
+
195
+        $telnyxkey = $smsapicred[0];
196
+
197
+        $nexapikey = $smsapicred[5];
198
+        $nexapisecret = $smsapicred[6];
199
+
200
+        $twilapikey = $smsapicred[15];
201
+        $twilapisecret = $smsapicred[16];
202
+
203
+        $flowapikey = $smsapicred[20];
204
+        $flowapisecret = $smsapicred[21];
205
+
206
+        $telsendernameinit = $smsapicred[9];
207
+        $nexsendernameinit = $smsapicred[10];
208
+        $twilsendernameinit = $smsapicred[19];
209
+
210
+        $telsendername = "Tx: " . $telsendernameinit;
211
+        $nexsendername = "Pl: " . $nexsendernameinit;
212
+        $twilsendername = "Tw: " . $twilsendernameinit;
213
+
214
+        // Get Telnyx phone numbers
215
+        if ($telnyxkey != '') {
216
+
217
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
218
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
219
+
220
+           $telnumbersarr = $this->object_to_array($telnumbers);
221
+           $telnmbrs = [];
222
+
223
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
224
+              if (is_int($nmbkey)) {
225
+                 foreach ($nmbvalue as $nkey => $nvalue) {
226
+                    if ($nkey == 'phone_number') {
227
+                       $telnmbrs[] = "Tx: " . $nvalue;
228
+                    }
229
+                 }
230
+              }
231
+           }
232
+
233
+        } else { $telnmbrs = []; }
234
+
235
+        // Get Plivo phone numbers
236
+        if ($nexapikey != '' && $nexapisecret != '') {
237
+
238
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
239
+           $acdata = file_get_contents($getacdata);
240
+           $datainit = json_decode($acdata, true);
241
+
242
+           $findata = $this->object_to_array($datainit);
243
+
244
+           $nexcurrentnmbrs = [];
245
+
246
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
247
+                   if (is_array($smsvalue)) {
248
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
249
+                               if ($smskey2 == 'number') {
250
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
251
+                               }
252
+                         }
253
+                   }
254
+           }
255
+
256
+
257
+        } else { $nexcurrentnmbrs = []; }
258
+
259
+        // Get Twilio phone numbers
260
+        if ($twilapikey != '' && $twilapisecret != '') {
261
+
262
+            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
263
+            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
264
+
265
+            $twilcurrentnmbrs = [];
266
+            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
267
+                 if (is_array($twnbvalue)) {
268
+                     foreach ($twnbvalue as $twfkey => $twfvalue) {
269
+                          if ($twfkey == 'phone_number') {
270
+                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
271
+                          }
272
+                     }
273
+                 }
274
+            }
275
+
276
+        } else { $twilcurrentnmbrs = []; }
277
+
278
+        // Get Flowroute phone numbers
279
+        if ($flowapikey != '' && $flowapisecret != '') {
280
+
281
+            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
282
+            $flnbrsarr = $flnbrsresult->data;
283
+            $flowcurrentnmbrs = [];
284
+            foreach ($flnbrsarr as $flkey => $flitem) {
285
+                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
286
+            }
287
+
288
+        } else { $flowcurrentnmbrs = []; }
289
+
290
+
291
+        $telsenderarr = [0 => $telsendername];
292
+        $nexsenderarr = [0 => $nexsendername];
293
+        $twilsenderarr = [0 => $twilsendername];
294
+
295
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
296
+
297
+        return $currentnmbrs;
298
+    }
299
+
300
+
301
+    /**
302
+     * @NoAdminRequired
303
+     */
304
+    public function cleantempdir($userId) {
305
+
306
+        // Create the temporary folder if it doesn't exist
307
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
308
+            $this->folder->newFolder('SMS_Relentless/temp_files');
309
+        }
310
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
311
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
312
+        $fileSystemIterator = new FilesystemIterator($targetdir);
313
+
314
+        $dirfiles = [];
315
+        foreach ($fileSystemIterator as $fileInfo){
316
+                 $dirfiles[] = $fileInfo->getFilename();
317
+        }
318
+
319
+        foreach ($dirfiles as $key => $indfile) {
320
+                 $thisuserroot = $this->view->getRoot();
321
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
322
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
323
+        }
324
+     }
325
+
326
+
327
+    /**
328
+     * @NoAdminRequired
329
+     */
330
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
331
+
332
+        // Create the temporary folder if it doesn't exist
333
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
334
+            $this->folder->newFolder('SMS_Relentless/temp_files');
335
+        }
336
+
337
+        // First delete any file that has been previously uploaded
338
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
339
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
340
+        $fileSystemIterator = new FilesystemIterator($targetdir);
341
+
342
+        $dirfiles = [];
343
+        foreach ($fileSystemIterator as $fileInfo){
344
+                 $dirfiles[] = $fileInfo->getFilename();
345
+        }
346
+
347
+        foreach ($dirfiles as $key => $indfile) {
348
+                 $thisuserroot = $this->view->getRoot();
349
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
350
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
351
+        }
352
+
353
+        // Upload the new file
354
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
355
+        $fileName = $_FILES['uploadfileforsms']['name'];
356
+
357
+        $userroot = $this->view->getRoot();
358
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
359
+
360
+        $target = $this->folder->newFile($targetfile);
361
+        $target->putContent($fileContent);
362
+
363
+        // Extract the phone numbers from the file
364
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
365
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
366
+        $numberarrayfourth = explode(",", $numberarraytert);
367
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
368
+        $numberarray = array_unique($numberarrayfifth);
369
+
370
+        return $numberarray;
371
+    }
372
+
373
+
374
+    /**
375
+     * @NoAdminRequired
376
+     */
377
+    public function uploadfile($uploadfileformms) {
378
+
379
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
380
+           $fileName = $_FILES['uploadfileformms']['name'];
381
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
382
+           $fileSize = $fileSizeinit / 1024;
383
+
384
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
385
+               $this->folder->newFolder('SMS_Relentless/temp_files');
386
+           }
387
+
388
+           $userroot = $this->view->getRoot();
389
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
390
+
391
+           $target = $this->folder->newFile($targetfile);
392
+           $target->putContent($fileContent);
393
+
394
+           // Get the cumulative files size of the uploaded files
395
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
396
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
397
+
398
+           $fileSystemIterator = new FilesystemIterator($targetdir);
399
+
400
+           $dirfiles = [];
401
+           foreach ($fileSystemIterator as $fileInfo){
402
+                    $dirfiles[] = $fileInfo->getFilename();
403
+           }
404
+
405
+           $totalflsizeinit = 0;
406
+           foreach ($dirfiles as $key => $indfile) {
407
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
408
+                    $mbSize = round($fileSizeinit / 1024, 4);
409
+                    $totalflsizeinit += $mbSize;
410
+           }
411
+
412
+           $totalflsize = round($totalflsizeinit, 4);
413
+
414
+           return $totalflsize;
415
+    }
416
+
417
+
418
+    /**
419
+     * @NoAdminRequired
420
+     */
421
+    public function pickfile($path) {
422
+
423
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
424
+               $this->folder->newFolder('SMS_Relentless/temp_files');
425
+           }
426
+
427
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
428
+
429
+           $fltgt = $datadir . $this->userId . "/files" . $path;
430
+
431
+           $fileContent = file_get_contents($fltgt);
432
+
433
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
434
+
435
+           $patharr = explode("/", $path);
436
+
437
+           $revarr = array_reverse($patharr);
438
+
439
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
440
+
441
+           $target = $this->folder->newFile($relflpath);
442
+
443
+           $target->putContent($fileContent);
444
+
445
+           // Get the cumulative files size of the uploaded files
446
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
447
+
448
+           $fileSystemIterator = new FilesystemIterator($targetdir);
449
+
450
+           $dirfiles = [];
451
+           foreach ($fileSystemIterator as $fileInfo) {
452
+                    $dirfiles[] = $fileInfo->getFilename();
453
+           }
454
+
455
+           $totalflsizeinit = 0;
456
+
457
+           foreach ($dirfiles as $key => $indfile) {
458
+
459
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
460
+                    $mbSize = round($fileSizeinit / 1024, 4);
461
+                    $totalflsizeinit += $mbSize;
462
+           }
463
+
464
+           $totalflsize = round($totalflsizeinit, 4);
465
+
466
+           $pickresult = [$totalflsize, $pkfilesize];
467
+
468
+           return $pickresult;
469
+    }
470
+
471
+
472
+    /**
473
+     * @NoAdminRequired
474
+     */
475
+    public function removeupfile($removedfilename) {
476
+
477
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
478
+
479
+           $removefile = $this->view->unlink($tmpfl);
480
+
481
+           // Get the cumulative files size of the uploaded files
482
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
483
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
484
+           $fileSystemIterator = new FilesystemIterator($targetdir);
485
+
486
+           $dirfiles = [];
487
+           foreach ($fileSystemIterator as $fileInfo){
488
+                    $dirfiles[] = $fileInfo->getFilename();
489
+           }
490
+
491
+           $totalflsizeinit = 0;
492
+
493
+           foreach ($dirfiles as $key => $indfile) {
494
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
495
+                    $mbSize = round($fileSizeinit / 1024, 4);
496
+                    $totalflsizeinit += $mbSize;
497
+           }
498
+
499
+           $totalflsize = round($totalflsizeinit, 4);
500
+
501
+           return $totalflsize;
502
+    }
503
+
504
+
505
+    /**
506
+     * @NoAdminRequired
507
+     */
508
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
509
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
510
+         $telnyxkey = $telsmsapicred[0];
511
+         $teldelrecurl = $telsmsapicred[3];
512
+         $messagingprofid = $telsmsapicred[4];
513
+
514
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
515
+
516
+         $microinterval = $waitinterval * 1000;
517
+
518
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
519
+
520
+             usleep($microinterval);
521
+
522
+             $messagedate = date("Y-m-d H:i:s");
523
+
524
+             if ($ismms == 0) {
525
+
526
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
527
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
528
+                 } else {
529
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
530
+                 }
531
+
532
+                 $messagetexttel = $sentsmstext;
533
+
534
+             } else {
535
+
536
+                 $mediaURLarr = [];
537
+                 $includedMediaFiles = '';
538
+
539
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
540
+
541
+                      $userroot = $this->view->getRoot();
542
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
543
+
544
+                      $flsharetarget = $this->folder->newFile($filetoshare);
545
+
546
+	              $share = $this->shareManager->newShare();
547
+	              $share->setNode($flsharetarget);
548
+	              $share->setPermissions(Constants::PERMISSION_READ);
549
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
550
+	              $share->setSharedBy($this->userId);
551
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
552
+                      $expirydate->add(new \DateInterval('P1D'));
553
+                      $share->setExpirationDate($expirydate);
554
+                      $shared = $this->shareManager->createShare($share);
555
+                      $shareToken = $shared->getToken();
556
+
557
+                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
558
+                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
559
+                 }
560
+
561
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
562
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
563
+                 } else {
564
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
565
+                 }
566
+
567
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
568
+             }
569
+
570
+             $messageid = $message['id'];
571
+             $messagefrom = "Telnyx: " . $fromsender;
572
+             $messageto = $tonumber;
573
+             $messagenetwork = null;
574
+             $messageprice = null;
575
+             $messagestatus = $message['to'][0]['status'];
576
+             $messagedelivery = null;
577
+
578
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
579
+
580
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
581
+
582
+         }
583
+    }
584
+
585
+
586
+    /**
587
+     * @NoAdminRequired
588
+     */
589
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
590
+
591
+         $smsapicred = $this->service->getapicredentials($this->userId);
592
+
593
+         $smsapikey = $smsapicred[5];
594
+         $smsapisecret = $smsapicred[6];
595
+         $smsapideliveryrecurl = $smsapicred[8];
596
+
597
+         $microinterval = $waitinterval * 1000;
598
+
599
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
600
+
601
+             usleep($microinterval);
602
+
603
+             $messagedatepl = date("Y-m-d H:i:s");
604
+
605
+             if ($ismms == 0) {
606
+
607
+                 $client = new RestClient($smsapikey, $smsapisecret);
608
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
609
+                 $messagetextpl = $sentsmstext;
610
+	         $messageidinit = $response->getmessageUuid(0);
611
+                 $messageid = $messageidinit[0];
612
+
613
+                 if (property_exists($response, 'error')) { 
614
+                     $messagestatus = "Error: " . $response->error;
615
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
616
+
617
+             } else {
618
+
619
+                 $mediaURLarr = [];
620
+                 $includedMediaFiles = '';
621
+
622
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
623
+
624
+                      $userroot = $this->view->getRoot();
625
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
626
+
627
+                      $flsharetarget = $this->folder->newFile($filetoshare);
628
+
629
+	              $share = $this->shareManager->newShare();
630
+	              $share->setNode($flsharetarget);
631
+	              $share->setPermissions(Constants::PERMISSION_READ);
632
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
633
+	              $share->setSharedBy($this->userId);
634
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
635
+                      $expirydate->add(new \DateInterval('P1D'));
636
+                      $share->setExpirationDate($expirydate);
637
+                      $shared = $this->shareManager->createShare($share);
638
+                      $shareToken = $shared->getToken();
639
+
640
+                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
641
+                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
642
+                 }
643
+
644
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
645
+		 $postedparamspl = json_encode($datatosendpl);
646
+
647
+		 $chpl = curl_init();
648
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
649
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
650
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
651
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
652
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
653
+		 curl_setopt($chpl, CURLOPT_POST, 1);
654
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
655
+		 $resultpl = curl_exec ($chpl);
656
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
657
+		 curl_close ($chpl);
658
+
659
+		 $decresultpl = json_decode($resultpl);
660
+
661
+                 if (property_exists($decresultpl, 'message_uuid')) {
662
+                     $messageidinit = $decresultpl->message_uuid;
663
+                     $messageid = $messageidinit[0];
664
+                 }
665
+
666
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
667
+
668
+                     if (property_exists($decresultpl, 'error')) {
669
+                         $messagestatus = "Error: " . $decresultpl->error;
670
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
671
+
672
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
673
+
674
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
675
+             }
676
+
677
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
678
+                 $messagefrom = "Plivo: " . $fromsender;
679
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
680
+
681
+             $messageto = $tonumber;
682
+             $messagenetwork = '';
683
+             $messageprice = '';
684
+
685
+             $messagedelivery = '';
686
+
687
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
688
+
689
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
690
+         }
691
+    }
692
+
693
+
694
+    /**
695
+     * @NoAdminRequired
696
+     */
697
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
698
+
699
+         $smsapicred = $this->service->getapicredentials($this->userId);
700
+
701
+         $sid = $smsapicred[15];
702
+         $token = $smsapicred[16];
703
+         $smsapirecurltw = $smsapicred[18];
704
+
705
+         $microinterval = $waitinterval * 1000;
706
+
707
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
708
+
709
+             usleep($microinterval);
710
+
711
+             $messagedatetw = date("Y-m-d H:i:s");
712
+
713
+             if ($ismms == 0) {
714
+
715
+                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
716
+                  $sentsmstextfintw = $sentsmstext;
717
+
718
+             } else {
719
+
720
+                 $mediaURLs = [];
721
+
722
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
723
+
724
+                      $userroot = $this->view->getRoot();
725
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
726
+
727
+                      $flsharetarget = $this->folder->newFile($filetoshare);
728
+
729
+	              $share = $this->shareManager->newShare();
730
+	              $share->setNode($flsharetarget);
731
+	              $share->setPermissions(Constants::PERMISSION_READ);
732
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
733
+	              $share->setSharedBy($this->userId);
734
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
735
+                      $expirydate->add(new \DateInterval('P1D'));
736
+                      $share->setExpirationDate($expirydate);
737
+                      $shared = $this->shareManager->createShare($share);
738
+                      $shareToken = $shared->getToken();
739
+
740
+                      $mediaURLs[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
741
+                 }
742
+
743
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
744
+                 $includedMediaFiles = '';
745
+
746
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
747
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
748
+                      $includedMediaFiles .= $mediaURLs[$m] . "<br><br>";
749
+                 }
750
+
751
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
752
+             }
753
+
754
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
755
+
756
+	     $chtw = curl_init();
757
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
758
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
759
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
760
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
761
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
762
+	     curl_setopt($chtw, CURLOPT_POST, 1);
763
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
764
+
765
+	     $resulttw = curl_exec ($chtw);
766
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
767
+	     curl_close ($chtw);
768
+
769
+             $decresulttw = json_decode($resulttw);
770
+
771
+             if ($resulttw) {
772
+                 $messageidtw = $decresulttw->sid;
773
+             } else { $messageidtw = ''; }
774
+
775
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
776
+                 $messagestatustw = 'The message has been accepted for delivery.';
777
+             } else {
778
+                 $messagestatustw = 'An error occurred while trying to send the message.';
779
+             }
780
+
781
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
782
+                 $messagefromtw = "Twilio: " . $fromsender;
783
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
784
+
785
+             $messagenetworktw = '';
786
+             $messagepricetw = '';
787
+             $messagedeliverytw = '';
788
+
789
+
790
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
791
+
792
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
793
+         }
794
+
795
+    }
796
+
797
+
798
+    /**
799
+     * @NoAdminRequired
800
+     */
801
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
802
+
803
+         $smsapicredfl = $this->service->getapicredentials($this->userId);
804
+
805
+         $flowapikey = $smsapicredfl[20];
806
+         $flowapisecret = $smsapicredfl[21];
807
+         $flowdelrecurl = $smsapicredfl[23];
808
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
809
+
810
+         $microinterval = $waitinterval * 1000;
811
+
812
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
813
+
814
+             usleep($microinterval);
815
+
816
+             $messagedatefl = date("Y-m-d H:i:s");
817
+
818
+             if ($ismms == 0) {
819
+
820
+                 $messagetextfinfl = $sentsmstext;
821
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
822
+
823
+             } else {
824
+
825
+		 $mediaurlsarr = [];
826
+
827
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
828
+
829
+		      $userroot = $this->view->getRoot();
830
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
831
+
832
+		      $flsharetarget = $this->folder->newFile($filetoshare);
833
+
834
+		      $share = $this->shareManager->newShare();
835
+		      $share->setNode($flsharetarget);
836
+		      $share->setPermissions(Constants::PERMISSION_READ);
837
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
838
+		      $share->setSharedBy($this->userId);
839
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
840
+                      $expirydate->add(new \DateInterval('P1D'));
841
+                      $share->setExpirationDate($expirydate);
842
+		      $shared = $this->shareManager->createShare($share);
843
+		      $shareToken = $shared->getToken();
844
+
845
+		      $mediaurlsarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
846
+		 }
847
+
848
+		 $includedMediaFiles = '';
849
+
850
+		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
851
+		      $includedMediaFiles .= $mediaurlsarr[$m] . "<br><br>";
852
+		 }
853
+
854
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
855
+
856
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
857
+             }
858
+
859
+
860
+	     $chfl = curl_init();
861
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
862
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
863
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
864
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
865
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
866
+	     curl_setopt($chfl, CURLOPT_POST, 1);
867
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
868
+	     $resultfl = curl_exec ($chfl);
869
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
870
+	     curl_close ($chfl);
871
+
872
+             $decresultfl = json_decode($resultfl);
873
+
874
+             if ($resultfl) {
875
+                 $messageidfl = $decresultfl->data->id;
876
+             } else { $messageidfl = ''; }
877
+
878
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
879
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
880
+             } else { 
881
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
882
+             }
883
+
884
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
885
+                 $messagefromfl = "Flowroute: " . $fromsender;
886
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
887
+
888
+             $messagetofl = $tonumberfl;
889
+             $messagenetworkfl = '';
890
+             $messagepricefl = '';
891
+             $messagedeliveryfl = '';
892
+
893
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
894
+
895
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
896
+         }
897
+
898
+    }
899
+
900
+
901
+    /**
902
+     * @NoAdminRequired
903
+     */
904
+    public function saveoldrecrows($userId, $oldrecRows) {
905
+
906
+           // Create the folder for removed messages if it doesn't exist
907
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
908
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
909
+           }
910
+           $savecheck = 0;
911
+
912
+           if (count($oldrecRows) > 1) {
913
+               $msfileContent = implode("", $oldrecRows);
914
+
915
+               $delrowsdate = date("Y-m-d_H-i-s");
916
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
917
+
918
+               $userroot = $this->view->getRoot();
919
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
920
+
921
+               $target = $this->folder->newFile($targetfile);
922
+               $target->putContent($msfileContent);
923
+
924
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
925
+                   $savecheck = 1;
926
+               }
927
+           }
928
+
929
+           return $savecheck;
930
+    }
931
+
932
+
933
+    /**
934
+     * @NoAdminRequired
935
+     */
936
+    public function saveoldsentrows($userId, $oldsentRows) {
937
+
938
+           // Create the folder for removed messages if it doesn't exist
939
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
940
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
941
+           }
942
+           $savesentcheck = 0;
943
+
944
+           if (count($oldsentRows) > 1) {
945
+               $sntfileContent = implode("", $oldsentRows);
946
+
947
+               $delsentrowsdate = date("Y-m-d_H-i-s");
948
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
949
+
950
+               $userroot = $this->view->getRoot();
951
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
952
+
953
+               $snttarget = $this->folder->newFile($snttargetfile);
954
+               $snttarget->putContent($sntfileContent);
955
+
956
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
957
+                   $savesentcheck = 1;
958
+               }
959
+           }
960
+
961
+           return $savesentcheck;
962
+    }
963
+
964
+
965
+    /**
966
+     * @NoAdminRequired
967
+     */
968
+    public function getreceivedtable($userId) {
969
+           return $this->service->getreceivedtable($this->userId);
970
+    }
971
+
972
+    /**
973
+     * @NoAdminRequired
974
+     */
975
+    public function getreceivedtablefordel($userId) {
976
+           return $this->service->getreceivedtablefordel($this->userId);
977
+    }
978
+
979
+    /**
980
+     * @NoAdminRequired
981
+     */
982
+    public function removerecrows($userId, $recmessagedbIDs) {
983
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
984
+    }
985
+
986
+    /**
987
+     * @NoAdminRequired
988
+     */
989
+    public function getsenttable($userId) {
990
+           return $this->service->getsenttable($this->userId);
991
+    }
992
+
993
+    /**
994
+     * @NoAdminRequired
995
+     */
996
+    public function getsenttablefordel($userId) {
997
+           return $this->service->getsenttablefordel($this->userId);
998
+    }
999
+
1000
+    /**
1001
+     * @NoAdminRequired
1002
+     */
1003
+    public function removesentrows($userId, $sentmessagedbIDs) {
1004
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1005
+    }
1006
+
1007
+    /**
1008
+     * @NoAdminRequired
1009
+     */
1010
+    public function getmessagesperpage($userId) {
1011
+           return $this->service->getmessagesperpage($this->userId);
1012
+    }
1013
+
1014
+    /**
1015
+     * @NoAdminRequired
1016
+     */
1017
+    public function getdelrecsettings($userId) {
1018
+           return $this->service->getdelrecsettings($this->userId);
1019
+    }
1020
+
1021
+    /**
1022
+     * @NoAdminRequired
1023
+     */
1024
+    public function getsettings($userId) {
1025
+           return $this->service->getsettings($this->userId);
1026
+    }
1027
+
1028
+    /**
1029
+     * @NoAdminRequired
1030
+     */
1031
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl) {
1032
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl);
1033
+    }
1034
+
1035
+}
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/settings.js templates/settings.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php

DoubleBastionAdmin authored on 08/09/2022 21:52:34
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1038 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use \DateInterval;
44
-use OCP\AppFramework\Http\DataResponse;
45
-use OCP\Files\NotFoundException;
46
-use OCP\Files\NotPermittedException;
47
-use Plivo\RestClient;
48
-use OCP\IURLGenerator;
49
-use OCP\Share\IManager;
50
-use OCP\Constants;
51
-
52
-
53
-
54
-class SmsrelentlessController extends Controller {
55
-
56
-    private $service;
57
-    private $config;
58
-    private $userId;
59
-    private $folder;
60
-    private $filesystem;
61
-    private $view;
62
-    private $urlGenerator;
63
-    private $shareManager;
64
-
65
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager) {
66
-        parent::__construct($appName, $request);
67
-        $this->service = $service;
68
-        $this->config = $config;
69
-        $this->userId = $userId;
70
-        $this->folder = $folder;
71
-        $this->filesystem = $filesystem;
72
-        $this->view = $view;
73
-	$this->urlGenerator = $urlGenerator;
74
-	$this->shareManager = $shareManager;
75
-    }
76
-
77
-
78
-    /**
79
-     * @NoAdminRequired
80
-     */
81
-    public function object_to_array($obj) {
82
-        if(is_object($obj)) $obj = (array)$this->dismount($obj);
83
-        if(is_array($obj)) {
84
-           $new = array();
85
-           foreach($obj as $key => $val) {
86
-               $new[$key] = $this->object_to_array($val);
87
-           }
88
-        }
89
-        else $new = $obj;
90
-        return $new;
91
-    }
92
-
93
-
94
-    /**
95
-     * @NoAdminRequired
96
-     */
97
-    public function dismount($object) {
98
-        $reflectionClass = new ReflectionClass(get_class($object));
99
-        $array = array();
100
-        foreach ($reflectionClass->getProperties() as $property) {
101
-           $property->setAccessible(true);
102
-           $array[$property->getName()] = $property->getValue($object);
103
-           $property->setAccessible(false);
104
-        }
105
-        return $array;
106
-    }
107
-
108
-
109
-    /**
110
-     * @NoAdminRequired
111
-     */
112
-    public function getbalancetel($userId) {
113
-
114
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
115
-
116
-        $telapikey = $telsmsapicred[0];
117
-        $ch = curl_init();
118
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
119
-
120
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
121
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
122
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
123
-        $responsetel = curl_exec($ch);
124
-        $recdatatel = json_decode($responsetel, TRUE);
125
-        $telbalresponse = $recdatatel['data']['balance'];
126
-        $currentbalancetel = round(floatval($telbalresponse), 3);
127
-        curl_close($ch);
128
-
129
-        return $currentbalancetel;
130
-    }
131
-
132
-
133
-    /**
134
-     * @NoAdminRequired
135
-     */
136
-    public function getbalancenex($userId) {
137
-
138
-        $smsapicred = $this->service->getapicredentials($this->userId);
139
-        $smsapikey = $smsapicred[5];
140
-        $smsapisecret = $smsapicred[6];
141
-
142
-        if ($smsapikey == '' || $smsapisecret == '') {
143
-            $currentbalancenex = "N/A";
144
-        } else {
145
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
146
-            $mesdata = file_get_contents($getmesdata);
147
-            $datainit = json_decode($mesdata);
148
-            $balancenex = $datainit->cash_credits;
149
-            $currentbalancenex = round(floatval($balancenex), 3);
150
-        }
151
-        return $currentbalancenex;
152
-    }
153
-
154
-
155
-    /**
156
-     * @NoAdminRequired
157
-     */
158
-    public function getbalancetwil($userId) {
159
-
160
-        $smsapicred = $this->service->getapicredentials($this->userId);
161
-        $smsapisid = $smsapicred[15];
162
-        $smsapitoken = $smsapicred[16];
163
-
164
-        if ($smsapisid == '' || $smsapitoken == '') {
165
-            $currentbalancetwil = "N/A";
166
-        } else {
167
-
168
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
169
-            $balancetwil = $twilbalance->balance;
170
-
171
-            $currentbalancetwil = round(floatval($balancetwil), 3);
172
-        }
173
-        return $currentbalancetwil;
174
-    }
175
-
176
-
177
-    /**
178
-     * @NoAdminRequired
179
-     */
180
-    public function getbalanceflow($userId) {
181
-
182
-        $currentbalanceflow = 'n/a';
183
-
184
-        return $currentbalanceflow;
185
-    }
186
-
187
-
188
-    /**
189
-     * @NoAdminRequired
190
-     */
191
-    public function getsmsnumbers($userId) {
192
-
193
-        $smsapicred = $this->service->getapicredentials($this->userId);
194
-
195
-        $telnyxkey = $smsapicred[0];
196
-
197
-        $nexapikey = $smsapicred[5];
198
-        $nexapisecret = $smsapicred[6];
199
-
200
-        $twilapikey = $smsapicred[15];
201
-        $twilapisecret = $smsapicred[16];
202
-
203
-        $flowapikey = $smsapicred[20];
204
-        $flowapisecret = $smsapicred[21];
205
-
206
-        $telsendernameinit = $smsapicred[9];
207
-        $nexsendernameinit = $smsapicred[10];
208
-        $twilsendernameinit = $smsapicred[19];
209
-        $flowsendernameinit = $smsapicred[24];
210
-
211
-        $telsendername = "Tx: " . $telsendernameinit;
212
-        $nexsendername = "Pl: " . $nexsendernameinit;
213
-        $twilsendername = "Tw: " . $twilsendernameinit;
214
-        $flowsendername = "Fl: " . $flowsendernameinit;
215
-
216
-        // Get Telnyx phone numbers
217
-        if ($telnyxkey != '') {
218
-
219
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
220
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
221
-
222
-           $telnumbersarr = $this->object_to_array($telnumbers);
223
-           $telnmbrs = [];
224
-
225
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
226
-              if (is_int($nmbkey)) {
227
-                 foreach ($nmbvalue as $nkey => $nvalue) {
228
-                    if ($nkey == 'phone_number') {
229
-                       $telnmbrs[] = "Tx: " . $nvalue;
230
-                    }
231
-                 }
232
-              }
233
-           }
234
-
235
-        } else { $telnmbrs = []; }
236
-
237
-        // Get Plivo phone numbers
238
-        if ($nexapikey != '' && $nexapisecret != '') {
239
-
240
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
241
-           $acdata = file_get_contents($getacdata);
242
-           $datainit = json_decode($acdata, true);
243
-
244
-           $findata = $this->object_to_array($datainit);
245
-
246
-           $nexcurrentnmbrs = [];
247
-
248
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
249
-                   if (is_array($smsvalue)) {
250
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
251
-                               if ($smskey2 == 'number') {
252
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
253
-                               }
254
-                         }
255
-                   }
256
-           }
257
-
258
-
259
-        } else { $nexcurrentnmbrs = []; }
260
-
261
-        // Get Twilio phone numbers
262
-        if ($twilapikey != '' && $twilapisecret != '') {
263
-
264
-            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
265
-            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
266
-
267
-            $twilcurrentnmbrs = [];
268
-            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
269
-                 if (is_array($twnbvalue)) {
270
-                     foreach ($twnbvalue as $twfkey => $twfvalue) {
271
-                          if ($twfkey == 'phone_number') {
272
-                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
273
-                          }
274
-                     }
275
-                 }
276
-            }
277
-
278
-        } else { $twilcurrentnmbrs = []; }
279
-
280
-        // Get Flowroute phone numbers
281
-        if ($flowapikey != '' && $flowapisecret != '') {
282
-
283
-            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
284
-            $flnbrsarr = $flnbrsresult->data;
285
-            $flowcurrentnmbrs = [];
286
-            foreach ($flnbrsarr as $flkey => $flitem) {
287
-                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
288
-            }
289
-
290
-        } else { $flowcurrentnmbrs = []; }
291
-
292
-
293
-        $telsenderarr = [0 => $telsendername];
294
-        $nexsenderarr = [0 => $nexsendername];
295
-        $twilsenderarr = [0 => $twilsendername];
296
-        $flowsenderarr = [0 => $flowsendername];
297
-
298
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr, $flowsenderarr);
299
-
300
-        return $currentnmbrs;
301
-    }
302
-
303
-
304
-    /**
305
-     * @NoAdminRequired
306
-     */
307
-    public function cleantempdir($userId) {
308
-
309
-        // Create the temporary folder if it doesn't exist
310
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
311
-            $this->folder->newFolder('SMS_Relentless/temp_files');
312
-        }
313
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
314
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
315
-        $fileSystemIterator = new FilesystemIterator($targetdir);
316
-
317
-        $dirfiles = [];
318
-        foreach ($fileSystemIterator as $fileInfo){
319
-                 $dirfiles[] = $fileInfo->getFilename();
320
-        }
321
-
322
-        foreach ($dirfiles as $key => $indfile) {
323
-                 $thisuserroot = $this->view->getRoot();
324
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
325
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
326
-        }
327
-     }
328
-
329
-
330
-    /**
331
-     * @NoAdminRequired
332
-     */
333
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
334
-
335
-        // Create the temporary folder if it doesn't exist
336
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
337
-            $this->folder->newFolder('SMS_Relentless/temp_files');
338
-        }
339
-
340
-        // First delete any file that has been previously uploaded
341
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
342
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
343
-        $fileSystemIterator = new FilesystemIterator($targetdir);
344
-
345
-        $dirfiles = [];
346
-        foreach ($fileSystemIterator as $fileInfo){
347
-                 $dirfiles[] = $fileInfo->getFilename();
348
-        }
349
-
350
-        foreach ($dirfiles as $key => $indfile) {
351
-                 $thisuserroot = $this->view->getRoot();
352
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
353
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
354
-        }
355
-
356
-        // Upload the new file
357
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
358
-        $fileName = $_FILES['uploadfileforsms']['name'];
359
-
360
-        $userroot = $this->view->getRoot();
361
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
362
-
363
-        $target = $this->folder->newFile($targetfile);
364
-        $target->putContent($fileContent);
365
-
366
-        // Extract the phone numbers from the file
367
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
368
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
369
-        $numberarrayfourth = explode(",", $numberarraytert);
370
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
371
-        $numberarray = array_unique($numberarrayfifth);
372
-
373
-        return $numberarray;
374
-    }
375
-
376
-
377
-    /**
378
-     * @NoAdminRequired
379
-     */
380
-    public function uploadfile($uploadfileformms) {
381
-
382
-           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
383
-           $fileName = $_FILES['uploadfileformms']['name'];
384
-           $fileSizeinit = $_FILES['uploadfileformms']['size'];
385
-           $fileSize = $fileSizeinit / 1024;
386
-
387
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
388
-               $this->folder->newFolder('SMS_Relentless/temp_files');
389
-           }
390
-
391
-           $userroot = $this->view->getRoot();
392
-           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
393
-
394
-           $target = $this->folder->newFile($targetfile);
395
-           $target->putContent($fileContent);
396
-
397
-           // Get the cumulative files size of the uploaded files
398
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
399
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
400
-
401
-           $fileSystemIterator = new FilesystemIterator($targetdir);
402
-
403
-           $dirfiles = [];
404
-           foreach ($fileSystemIterator as $fileInfo){
405
-                    $dirfiles[] = $fileInfo->getFilename();
406
-           }
407
-
408
-           $totalflsizeinit = 0;
409
-           foreach ($dirfiles as $key => $indfile) {
410
-                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
411
-                    $mbSize = round($fileSizeinit / 1024, 4);
412
-                    $totalflsizeinit += $mbSize;
413
-           }
414
-
415
-           $totalflsize = round($totalflsizeinit, 4);
416
-
417
-           return $totalflsize;
418
-    }
419
-
420
-
421
-    /**
422
-     * @NoAdminRequired
423
-     */
424
-    public function pickfile($path) {
425
-
426
-           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
427
-               $this->folder->newFolder('SMS_Relentless/temp_files');
428
-           }
429
-
430
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
431
-
432
-           $fltgt = $datadir . $this->userId . "/files" . $path;
433
-
434
-           $fileContent = file_get_contents($fltgt);
435
-
436
-           $pkfilesize = round(filesize($fltgt) / 1024, 4);
437
-
438
-           $patharr = explode("/", $path);
439
-
440
-           $revarr = array_reverse($patharr);
441
-
442
-           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
443
-
444
-           $target = $this->folder->newFile($relflpath);
445
-
446
-           $target->putContent($fileContent);
447
-
448
-           // Get the cumulative files size of the uploaded files
449
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
450
-
451
-           $fileSystemIterator = new FilesystemIterator($targetdir);
452
-
453
-           $dirfiles = [];
454
-           foreach ($fileSystemIterator as $fileInfo) {
455
-                    $dirfiles[] = $fileInfo->getFilename();
456
-           }
457
-
458
-           $totalflsizeinit = 0;
459
-
460
-           foreach ($dirfiles as $key => $indfile) {
461
-
462
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
463
-                    $mbSize = round($fileSizeinit / 1024, 4);
464
-                    $totalflsizeinit += $mbSize;
465
-           }
466
-
467
-           $totalflsize = round($totalflsizeinit, 4);
468
-
469
-           $pickresult = [$totalflsize, $pkfilesize];
470
-
471
-           return $pickresult;
472
-    }
473
-
474
-
475
-    /**
476
-     * @NoAdminRequired
477
-     */
478
-    public function removeupfile($removedfilename) {
479
-
480
-           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
481
-
482
-           $removefile = $this->view->unlink($tmpfl);
483
-
484
-           // Get the cumulative files size of the uploaded files
485
-           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
486
-           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
487
-           $fileSystemIterator = new FilesystemIterator($targetdir);
488
-
489
-           $dirfiles = [];
490
-           foreach ($fileSystemIterator as $fileInfo){
491
-                    $dirfiles[] = $fileInfo->getFilename();
492
-           }
493
-
494
-           $totalflsizeinit = 0;
495
-
496
-           foreach ($dirfiles as $key => $indfile) {
497
-                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
498
-                    $mbSize = round($fileSizeinit / 1024, 4);
499
-                    $totalflsizeinit += $mbSize;
500
-           }
501
-
502
-           $totalflsize = round($totalflsizeinit, 4);
503
-
504
-           return $totalflsize;
505
-    }
506
-
507
-
508
-    /**
509
-     * @NoAdminRequired
510
-     */
511
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
512
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
513
-         $telnyxkey = $telsmsapicred[0];
514
-         $teldelrecurl = $telsmsapicred[3];
515
-         $messagingprofid = $telsmsapicred[4];
516
-
517
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
518
-
519
-         $microinterval = $waitinterval * 1000;
520
-
521
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
522
-
523
-             usleep($microinterval);
524
-
525
-             $messagedate = date("Y-m-d H:i:s");
526
-
527
-             if ($ismms == 0) {
528
-
529
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
530
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
531
-                 } else {
532
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
533
-                 }
534
-
535
-                 $messagetexttel = $sentsmstext;
536
-
537
-             } else {
538
-
539
-                 $mediaURLarr = [];
540
-                 $includedMediaFiles = '';
541
-
542
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
543
-
544
-                      $userroot = $this->view->getRoot();
545
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
546
-
547
-                      $flsharetarget = $this->folder->newFile($filetoshare);
548
-
549
-	              $share = $this->shareManager->newShare();
550
-	              $share->setNode($flsharetarget);
551
-	              $share->setPermissions(Constants::PERMISSION_READ);
552
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
553
-	              $share->setSharedBy($this->userId);
554
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
555
-                      $expirydate->add(new \DateInterval('P1D'));
556
-                      $share->setExpirationDate($expirydate);
557
-                      $shared = $this->shareManager->createShare($share);
558
-                      $shareToken = $shared->getToken();
559
-
560
-                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
561
-                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
562
-                 }
563
-
564
-                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
565
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
566
-                 } else {
567
-                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
568
-                 }
569
-
570
-                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
571
-             }
572
-
573
-             $messageid = $message['id'];
574
-             $messagefrom = "Telnyx: " . $fromsender;
575
-             $messageto = $tonumber;
576
-             $messagenetwork = null;
577
-             $messageprice = null;
578
-             $messagestatus = $message['to'][0]['status'];
579
-             $messagedelivery = null;
580
-
581
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
582
-
583
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
584
-
585
-         }
586
-    }
587
-
588
-
589
-    /**
590
-     * @NoAdminRequired
591
-     */
592
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
593
-
594
-         $smsapicred = $this->service->getapicredentials($this->userId);
595
-
596
-         $smsapikey = $smsapicred[5];
597
-         $smsapisecret = $smsapicred[6];
598
-         $smsapideliveryrecurl = $smsapicred[8];
599
-
600
-         $microinterval = $waitinterval * 1000;
601
-
602
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
603
-
604
-             usleep($microinterval);
605
-
606
-             $messagedatepl = date("Y-m-d H:i:s");
607
-
608
-             if ($ismms == 0) {
609
-
610
-                 $client = new RestClient($smsapikey, $smsapisecret);
611
-                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
612
-                 $messagetextpl = $sentsmstext;
613
-	         $messageidinit = $response->getmessageUuid(0);
614
-                 $messageid = $messageidinit[0];
615
-
616
-                 if (property_exists($response, 'error')) { 
617
-                     $messagestatus = "Error: " . $response->error;
618
-                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
619
-
620
-             } else {
621
-
622
-                 $mediaURLarr = [];
623
-                 $includedMediaFiles = '';
624
-
625
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
626
-
627
-                      $userroot = $this->view->getRoot();
628
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
629
-
630
-                      $flsharetarget = $this->folder->newFile($filetoshare);
631
-
632
-	              $share = $this->shareManager->newShare();
633
-	              $share->setNode($flsharetarget);
634
-	              $share->setPermissions(Constants::PERMISSION_READ);
635
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
636
-	              $share->setSharedBy($this->userId);
637
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
638
-                      $expirydate->add(new \DateInterval('P1D'));
639
-                      $share->setExpirationDate($expirydate);
640
-                      $shared = $this->shareManager->createShare($share);
641
-                      $shareToken = $shared->getToken();
642
-
643
-                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
644
-                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
645
-                 }
646
-
647
-		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
648
-		 $postedparamspl = json_encode($datatosendpl);
649
-
650
-		 $chpl = curl_init();
651
-		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
652
-		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
653
-		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
654
-		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
655
-		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
656
-		 curl_setopt($chpl, CURLOPT_POST, 1);
657
-		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
658
-		 $resultpl = curl_exec ($chpl);
659
-		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
660
-		 curl_close ($chpl);
661
-
662
-		 $decresultpl = json_decode($resultpl);
663
-
664
-                 if (property_exists($decresultpl, 'message_uuid')) {
665
-                     $messageidinit = $decresultpl->message_uuid;
666
-                     $messageid = $messageidinit[0];
667
-                 }
668
-
669
-	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
670
-
671
-                     if (property_exists($decresultpl, 'error')) {
672
-                         $messagestatus = "Error: " . $decresultpl->error;
673
-                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
674
-
675
-                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
676
-
677
-                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
678
-             }
679
-
680
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
681
-                 $messagefrom = "Plivo: " . $fromsender;
682
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
683
-
684
-             $messageto = $tonumber;
685
-             $messagenetwork = '';
686
-             $messageprice = '';
687
-
688
-             $messagedelivery = '';
689
-
690
-             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
691
-
692
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
693
-         }
694
-    }
695
-
696
-
697
-    /**
698
-     * @NoAdminRequired
699
-     */
700
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
701
-
702
-         $smsapicred = $this->service->getapicredentials($this->userId);
703
-
704
-         $sid = $smsapicred[15];
705
-         $token = $smsapicred[16];
706
-         $smsapirecurltw = $smsapicred[18];
707
-
708
-         $microinterval = $waitinterval * 1000;
709
-
710
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
711
-
712
-             usleep($microinterval);
713
-
714
-             $messagedatetw = date("Y-m-d H:i:s");
715
-
716
-             if ($ismms == 0) {
717
-
718
-                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
719
-                  $sentsmstextfintw = $sentsmstext;
720
-
721
-             } else {
722
-
723
-                 $mediaURLs = [];
724
-
725
-                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
726
-
727
-                      $userroot = $this->view->getRoot();
728
-                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
729
-
730
-                      $flsharetarget = $this->folder->newFile($filetoshare);
731
-
732
-	              $share = $this->shareManager->newShare();
733
-	              $share->setNode($flsharetarget);
734
-	              $share->setPermissions(Constants::PERMISSION_READ);
735
-	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
736
-	              $share->setSharedBy($this->userId);
737
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
738
-                      $expirydate->add(new \DateInterval('P1D'));
739
-                      $share->setExpirationDate($expirydate);
740
-                      $shared = $this->shareManager->createShare($share);
741
-                      $shareToken = $shared->getToken();
742
-
743
-                      $mediaURLs[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
744
-                 }
745
-
746
-                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
747
-                 $includedMediaFiles = '';
748
-
749
-                 for ($m = 0; $m < count($mediaURLs); $m++) {
750
-                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
751
-                      $includedMediaFiles .= $mediaURLs[$m] . "<br><br>";
752
-                 }
753
-
754
-                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
755
-             }
756
-
757
-             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
758
-
759
-	     $chtw = curl_init();
760
-	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
761
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
762
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
763
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
764
-             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
765
-	     curl_setopt($chtw, CURLOPT_POST, 1);
766
-             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
767
-
768
-	     $resulttw = curl_exec ($chtw);
769
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
770
-	     curl_close ($chtw);
771
-
772
-             $decresulttw = json_decode($resulttw);
773
-
774
-             if ($resulttw) {
775
-                 $messageidtw = $decresulttw->sid;
776
-             } else { $messageidtw = ''; }
777
-
778
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
779
-                 $messagestatustw = 'The message has been accepted for delivery.';
780
-             } else {
781
-                 $messagestatustw = 'An error occurred while trying to send the message.';
782
-             }
783
-
784
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
785
-                 $messagefromtw = "Twilio: " . $fromsender;
786
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
787
-
788
-             $messagenetworktw = '';
789
-             $messagepricetw = '';
790
-             $messagedeliverytw = '';
791
-
792
-
793
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
794
-
795
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
796
-         }
797
-
798
-    }
799
-
800
-
801
-    /**
802
-     * @NoAdminRequired
803
-     */
804
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
805
-
806
-         $smsapicredfl = $this->service->getapicredentials($this->userId);
807
-
808
-         $flowapikey = $smsapicredfl[20];
809
-         $flowapisecret = $smsapicredfl[21];
810
-         $flowdelrecurl = $smsapicredfl[23];
811
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
812
-
813
-         $microinterval = $waitinterval * 1000;
814
-
815
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
816
-
817
-             usleep($microinterval);
818
-
819
-             $messagedatefl = date("Y-m-d H:i:s");
820
-
821
-             if ($ismms == 0) {
822
-
823
-                 $messagetextfinfl = $sentsmstext;
824
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
825
-
826
-             } else {
827
-
828
-		 $mediaurlsarr = [];
829
-
830
-		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
831
-
832
-		      $userroot = $this->view->getRoot();
833
-		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
834
-
835
-		      $flsharetarget = $this->folder->newFile($filetoshare);
836
-
837
-		      $share = $this->shareManager->newShare();
838
-		      $share->setNode($flsharetarget);
839
-		      $share->setPermissions(Constants::PERMISSION_READ);
840
-		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
841
-		      $share->setSharedBy($this->userId);
842
-                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
843
-                      $expirydate->add(new \DateInterval('P1D'));
844
-                      $share->setExpirationDate($expirydate);
845
-		      $shared = $this->shareManager->createShare($share);
846
-		      $shareToken = $shared->getToken();
847
-
848
-		      $mediaurlsarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
849
-		 }
850
-
851
-		 $includedMediaFiles = '';
852
-
853
-		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
854
-		      $includedMediaFiles .= $mediaurlsarr[$m] . "<br><br>";
855
-		 }
856
-
857
-                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
858
-
859
-                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
860
-             }
861
-
862
-
863
-	     $chfl = curl_init();
864
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
865
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
866
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
867
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
868
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
869
-	     curl_setopt($chfl, CURLOPT_POST, 1);
870
-             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
871
-	     $resultfl = curl_exec ($chfl);
872
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
873
-	     curl_close ($chfl);
874
-
875
-             $decresultfl = json_decode($resultfl);
876
-
877
-             if ($resultfl) {
878
-                 $messageidfl = $decresultfl->data->id;
879
-             } else { $messageidfl = ''; }
880
-
881
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
882
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
883
-             } else { 
884
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
885
-             }
886
-
887
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
888
-                 $messagefromfl = "Flowroute: " . $fromsender;
889
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
890
-
891
-             $messagetofl = $tonumberfl;
892
-             $messagenetworkfl = '';
893
-             $messagepricefl = '';
894
-             $messagedeliveryfl = '';
895
-
896
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
897
-
898
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
899
-         }
900
-
901
-    }
902
-
903
-
904
-    /**
905
-     * @NoAdminRequired
906
-     */
907
-    public function saveoldrecrows($userId, $oldrecRows) {
908
-
909
-           // Create the folder for removed messages if it doesn't exist
910
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
911
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
912
-           }
913
-           $savecheck = 0;
914
-
915
-           if (count($oldrecRows) > 1) {
916
-               $msfileContent = implode("", $oldrecRows);
917
-
918
-               $delrowsdate = date("Y-m-d_H-i-s");
919
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
920
-
921
-               $userroot = $this->view->getRoot();
922
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
923
-
924
-               $target = $this->folder->newFile($targetfile);
925
-               $target->putContent($msfileContent);
926
-
927
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
928
-                   $savecheck = 1;
929
-               }
930
-           }
931
-
932
-           return $savecheck;
933
-    }
934
-
935
-
936
-    /**
937
-     * @NoAdminRequired
938
-     */
939
-    public function saveoldsentrows($userId, $oldsentRows) {
940
-
941
-           // Create the folder for removed messages if it doesn't exist
942
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
943
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
944
-           }
945
-           $savesentcheck = 0;
946
-
947
-           if (count($oldsentRows) > 1) {
948
-               $sntfileContent = implode("", $oldsentRows);
949
-
950
-               $delsentrowsdate = date("Y-m-d_H-i-s");
951
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
952
-
953
-               $userroot = $this->view->getRoot();
954
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
955
-
956
-               $snttarget = $this->folder->newFile($snttargetfile);
957
-               $snttarget->putContent($sntfileContent);
958
-
959
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
960
-                   $savesentcheck = 1;
961
-               }
962
-           }
963
-
964
-           return $savesentcheck;
965
-    }
966
-
967
-
968
-    /**
969
-     * @NoAdminRequired
970
-     */
971
-    public function getreceivedtable($userId) {
972
-           return $this->service->getreceivedtable($this->userId);
973
-    }
974
-
975
-    /**
976
-     * @NoAdminRequired
977
-     */
978
-    public function getreceivedtablefordel($userId) {
979
-           return $this->service->getreceivedtablefordel($this->userId);
980
-    }
981
-
982
-    /**
983
-     * @NoAdminRequired
984
-     */
985
-    public function removerecrows($userId, $recmessagedbIDs) {
986
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
987
-    }
988
-
989
-    /**
990
-     * @NoAdminRequired
991
-     */
992
-    public function getsenttable($userId) {
993
-           return $this->service->getsenttable($this->userId);
994
-    }
995
-
996
-    /**
997
-     * @NoAdminRequired
998
-     */
999
-    public function getsenttablefordel($userId) {
1000
-           return $this->service->getsenttablefordel($this->userId);
1001
-    }
1002
-
1003
-    /**
1004
-     * @NoAdminRequired
1005
-     */
1006
-    public function removesentrows($userId, $sentmessagedbIDs) {
1007
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1008
-    }
1009
-
1010
-    /**
1011
-     * @NoAdminRequired
1012
-     */
1013
-    public function getmessagesperpage($userId) {
1014
-           return $this->service->getmessagesperpage($this->userId);
1015
-    }
1016
-
1017
-    /**
1018
-     * @NoAdminRequired
1019
-     */
1020
-    public function getdelrecsettings($userId) {
1021
-           return $this->service->getdelrecsettings($this->userId);
1022
-    }
1023
-
1024
-    /**
1025
-     * @NoAdminRequired
1026
-     */
1027
-    public function getsettings($userId) {
1028
-           return $this->service->getsettings($this->userId);
1029
-    }
1030
-
1031
-    /**
1032
-     * @NoAdminRequired
1033
-     */
1034
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName) {
1035
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName);
1036
-    }
1037
-
1038
-}
Browse code

added README.md CHANGELOG.txt appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/settings.js js/sendsms.js js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php templates/navigation/index.php templates/content/index.php templates/settings.php js/tiff.min.js img/nextcloud_logo.svg img/nextcloud_logo_bright.svg img/sms_relentless_mms_sending.png

DoubleBastionAdmin authored on 02/09/2022 23:19:37
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1038 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use \DateInterval;
44
+use OCP\AppFramework\Http\DataResponse;
45
+use OCP\Files\NotFoundException;
46
+use OCP\Files\NotPermittedException;
47
+use Plivo\RestClient;
48
+use OCP\IURLGenerator;
49
+use OCP\Share\IManager;
50
+use OCP\Constants;
51
+
52
+
53
+
54
+class SmsrelentlessController extends Controller {
55
+
56
+    private $service;
57
+    private $config;
58
+    private $userId;
59
+    private $folder;
60
+    private $filesystem;
61
+    private $view;
62
+    private $urlGenerator;
63
+    private $shareManager;
64
+
65
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view, IURLGenerator $urlGenerator, IManager $shareManager) {
66
+        parent::__construct($appName, $request);
67
+        $this->service = $service;
68
+        $this->config = $config;
69
+        $this->userId = $userId;
70
+        $this->folder = $folder;
71
+        $this->filesystem = $filesystem;
72
+        $this->view = $view;
73
+	$this->urlGenerator = $urlGenerator;
74
+	$this->shareManager = $shareManager;
75
+    }
76
+
77
+
78
+    /**
79
+     * @NoAdminRequired
80
+     */
81
+    public function object_to_array($obj) {
82
+        if(is_object($obj)) $obj = (array)$this->dismount($obj);
83
+        if(is_array($obj)) {
84
+           $new = array();
85
+           foreach($obj as $key => $val) {
86
+               $new[$key] = $this->object_to_array($val);
87
+           }
88
+        }
89
+        else $new = $obj;
90
+        return $new;
91
+    }
92
+
93
+
94
+    /**
95
+     * @NoAdminRequired
96
+     */
97
+    public function dismount($object) {
98
+        $reflectionClass = new ReflectionClass(get_class($object));
99
+        $array = array();
100
+        foreach ($reflectionClass->getProperties() as $property) {
101
+           $property->setAccessible(true);
102
+           $array[$property->getName()] = $property->getValue($object);
103
+           $property->setAccessible(false);
104
+        }
105
+        return $array;
106
+    }
107
+
108
+
109
+    /**
110
+     * @NoAdminRequired
111
+     */
112
+    public function getbalancetel($userId) {
113
+
114
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
115
+
116
+        $telapikey = $telsmsapicred[0];
117
+        $ch = curl_init();
118
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
119
+
120
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
121
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
122
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
123
+        $responsetel = curl_exec($ch);
124
+        $recdatatel = json_decode($responsetel, TRUE);
125
+        $telbalresponse = $recdatatel['data']['balance'];
126
+        $currentbalancetel = round(floatval($telbalresponse), 3);
127
+        curl_close($ch);
128
+
129
+        return $currentbalancetel;
130
+    }
131
+
132
+
133
+    /**
134
+     * @NoAdminRequired
135
+     */
136
+    public function getbalancenex($userId) {
137
+
138
+        $smsapicred = $this->service->getapicredentials($this->userId);
139
+        $smsapikey = $smsapicred[5];
140
+        $smsapisecret = $smsapicred[6];
141
+
142
+        if ($smsapikey == '' || $smsapisecret == '') {
143
+            $currentbalancenex = "N/A";
144
+        } else {
145
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
146
+            $mesdata = file_get_contents($getmesdata);
147
+            $datainit = json_decode($mesdata);
148
+            $balancenex = $datainit->cash_credits;
149
+            $currentbalancenex = round(floatval($balancenex), 3);
150
+        }
151
+        return $currentbalancenex;
152
+    }
153
+
154
+
155
+    /**
156
+     * @NoAdminRequired
157
+     */
158
+    public function getbalancetwil($userId) {
159
+
160
+        $smsapicred = $this->service->getapicredentials($this->userId);
161
+        $smsapisid = $smsapicred[15];
162
+        $smsapitoken = $smsapicred[16];
163
+
164
+        if ($smsapisid == '' || $smsapitoken == '') {
165
+            $currentbalancetwil = "N/A";
166
+        } else {
167
+
168
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
169
+            $balancetwil = $twilbalance->balance;
170
+
171
+            $currentbalancetwil = round(floatval($balancetwil), 3);
172
+        }
173
+        return $currentbalancetwil;
174
+    }
175
+
176
+
177
+    /**
178
+     * @NoAdminRequired
179
+     */
180
+    public function getbalanceflow($userId) {
181
+
182
+        $currentbalanceflow = 'n/a';
183
+
184
+        return $currentbalanceflow;
185
+    }
186
+
187
+
188
+    /**
189
+     * @NoAdminRequired
190
+     */
191
+    public function getsmsnumbers($userId) {
192
+
193
+        $smsapicred = $this->service->getapicredentials($this->userId);
194
+
195
+        $telnyxkey = $smsapicred[0];
196
+
197
+        $nexapikey = $smsapicred[5];
198
+        $nexapisecret = $smsapicred[6];
199
+
200
+        $twilapikey = $smsapicred[15];
201
+        $twilapisecret = $smsapicred[16];
202
+
203
+        $flowapikey = $smsapicred[20];
204
+        $flowapisecret = $smsapicred[21];
205
+
206
+        $telsendernameinit = $smsapicred[9];
207
+        $nexsendernameinit = $smsapicred[10];
208
+        $twilsendernameinit = $smsapicred[19];
209
+        $flowsendernameinit = $smsapicred[24];
210
+
211
+        $telsendername = "Tx: " . $telsendernameinit;
212
+        $nexsendername = "Pl: " . $nexsendernameinit;
213
+        $twilsendername = "Tw: " . $twilsendernameinit;
214
+        $flowsendername = "Fl: " . $flowsendernameinit;
215
+
216
+        // Get Telnyx phone numbers
217
+        if ($telnyxkey != '') {
218
+
219
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
220
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
221
+
222
+           $telnumbersarr = $this->object_to_array($telnumbers);
223
+           $telnmbrs = [];
224
+
225
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
226
+              if (is_int($nmbkey)) {
227
+                 foreach ($nmbvalue as $nkey => $nvalue) {
228
+                    if ($nkey == 'phone_number') {
229
+                       $telnmbrs[] = "Tx: " . $nvalue;
230
+                    }
231
+                 }
232
+              }
233
+           }
234
+
235
+        } else { $telnmbrs = []; }
236
+
237
+        // Get Plivo phone numbers
238
+        if ($nexapikey != '' && $nexapisecret != '') {
239
+
240
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
241
+           $acdata = file_get_contents($getacdata);
242
+           $datainit = json_decode($acdata, true);
243
+
244
+           $findata = $this->object_to_array($datainit);
245
+
246
+           $nexcurrentnmbrs = [];
247
+
248
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
249
+                   if (is_array($smsvalue)) {
250
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
251
+                               if ($smskey2 == 'number') {
252
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
253
+                               }
254
+                         }
255
+                   }
256
+           }
257
+
258
+
259
+        } else { $nexcurrentnmbrs = []; }
260
+
261
+        // Get Twilio phone numbers
262
+        if ($twilapikey != '' && $twilapisecret != '') {
263
+
264
+            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
265
+            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
266
+
267
+            $twilcurrentnmbrs = [];
268
+            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
269
+                 if (is_array($twnbvalue)) {
270
+                     foreach ($twnbvalue as $twfkey => $twfvalue) {
271
+                          if ($twfkey == 'phone_number') {
272
+                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
273
+                          }
274
+                     }
275
+                 }
276
+            }
277
+
278
+        } else { $twilcurrentnmbrs = []; }
279
+
280
+        // Get Flowroute phone numbers
281
+        if ($flowapikey != '' && $flowapisecret != '') {
282
+
283
+            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
284
+            $flnbrsarr = $flnbrsresult->data;
285
+            $flowcurrentnmbrs = [];
286
+            foreach ($flnbrsarr as $flkey => $flitem) {
287
+                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
288
+            }
289
+
290
+        } else { $flowcurrentnmbrs = []; }
291
+
292
+
293
+        $telsenderarr = [0 => $telsendername];
294
+        $nexsenderarr = [0 => $nexsendername];
295
+        $twilsenderarr = [0 => $twilsendername];
296
+        $flowsenderarr = [0 => $flowsendername];
297
+
298
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr, $flowsenderarr);
299
+
300
+        return $currentnmbrs;
301
+    }
302
+
303
+
304
+    /**
305
+     * @NoAdminRequired
306
+     */
307
+    public function cleantempdir($userId) {
308
+
309
+        // Create the temporary folder if it doesn't exist
310
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
311
+            $this->folder->newFolder('SMS_Relentless/temp_files');
312
+        }
313
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
314
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
315
+        $fileSystemIterator = new FilesystemIterator($targetdir);
316
+
317
+        $dirfiles = [];
318
+        foreach ($fileSystemIterator as $fileInfo){
319
+                 $dirfiles[] = $fileInfo->getFilename();
320
+        }
321
+
322
+        foreach ($dirfiles as $key => $indfile) {
323
+                 $thisuserroot = $this->view->getRoot();
324
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
325
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
326
+        }
327
+     }
328
+
329
+
330
+    /**
331
+     * @NoAdminRequired
332
+     */
333
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
334
+
335
+        // Create the temporary folder if it doesn't exist
336
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
337
+            $this->folder->newFolder('SMS_Relentless/temp_files');
338
+        }
339
+
340
+        // First delete any file that has been previously uploaded
341
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
342
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
343
+        $fileSystemIterator = new FilesystemIterator($targetdir);
344
+
345
+        $dirfiles = [];
346
+        foreach ($fileSystemIterator as $fileInfo){
347
+                 $dirfiles[] = $fileInfo->getFilename();
348
+        }
349
+
350
+        foreach ($dirfiles as $key => $indfile) {
351
+                 $thisuserroot = $this->view->getRoot();
352
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
353
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
354
+        }
355
+
356
+        // Upload the new file
357
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
358
+        $fileName = $_FILES['uploadfileforsms']['name'];
359
+
360
+        $userroot = $this->view->getRoot();
361
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
362
+
363
+        $target = $this->folder->newFile($targetfile);
364
+        $target->putContent($fileContent);
365
+
366
+        // Extract the phone numbers from the file
367
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
368
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
369
+        $numberarrayfourth = explode(",", $numberarraytert);
370
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
371
+        $numberarray = array_unique($numberarrayfifth);
372
+
373
+        return $numberarray;
374
+    }
375
+
376
+
377
+    /**
378
+     * @NoAdminRequired
379
+     */
380
+    public function uploadfile($uploadfileformms) {
381
+
382
+           $fileContent = file_get_contents($_FILES['uploadfileformms']['tmp_name']);
383
+           $fileName = $_FILES['uploadfileformms']['name'];
384
+           $fileSizeinit = $_FILES['uploadfileformms']['size'];
385
+           $fileSize = $fileSizeinit / 1024;
386
+
387
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
388
+               $this->folder->newFolder('SMS_Relentless/temp_files');
389
+           }
390
+
391
+           $userroot = $this->view->getRoot();
392
+           $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
393
+
394
+           $target = $this->folder->newFile($targetfile);
395
+           $target->putContent($fileContent);
396
+
397
+           // Get the cumulative files size of the uploaded files
398
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
399
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
400
+
401
+           $fileSystemIterator = new FilesystemIterator($targetdir);
402
+
403
+           $dirfiles = [];
404
+           foreach ($fileSystemIterator as $fileInfo){
405
+                    $dirfiles[] = $fileInfo->getFilename();
406
+           }
407
+
408
+           $totalflsizeinit = 0;
409
+           foreach ($dirfiles as $key => $indfile) {
410
+                    $fileSizeinit = $this->filesystem->filesize($userroot . "/SMS_Relentless/temp_files/" . $indfile);
411
+                    $mbSize = round($fileSizeinit / 1024, 4);
412
+                    $totalflsizeinit += $mbSize;
413
+           }
414
+
415
+           $totalflsize = round($totalflsizeinit, 4);
416
+
417
+           return $totalflsize;
418
+    }
419
+
420
+
421
+    /**
422
+     * @NoAdminRequired
423
+     */
424
+    public function pickfile($path) {
425
+
426
+           if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
427
+               $this->folder->newFolder('SMS_Relentless/temp_files');
428
+           }
429
+
430
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
431
+
432
+           $fltgt = $datadir . $this->userId . "/files" . $path;
433
+
434
+           $fileContent = file_get_contents($fltgt);
435
+
436
+           $pkfilesize = round(filesize($fltgt) / 1024, 4);
437
+
438
+           $patharr = explode("/", $path);
439
+
440
+           $revarr = array_reverse($patharr);
441
+
442
+           $relflpath = "/SMS_Relentless/temp_files/" . $revarr[0]; 
443
+
444
+           $target = $this->folder->newFile($relflpath);
445
+
446
+           $target->putContent($fileContent);
447
+
448
+           // Get the cumulative files size of the uploaded files
449
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
450
+
451
+           $fileSystemIterator = new FilesystemIterator($targetdir);
452
+
453
+           $dirfiles = [];
454
+           foreach ($fileSystemIterator as $fileInfo) {
455
+                    $dirfiles[] = $fileInfo->getFilename();
456
+           }
457
+
458
+           $totalflsizeinit = 0;
459
+
460
+           foreach ($dirfiles as $key => $indfile) {
461
+
462
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
463
+                    $mbSize = round($fileSizeinit / 1024, 4);
464
+                    $totalflsizeinit += $mbSize;
465
+           }
466
+
467
+           $totalflsize = round($totalflsizeinit, 4);
468
+
469
+           $pickresult = [$totalflsize, $pkfilesize];
470
+
471
+           return $pickresult;
472
+    }
473
+
474
+
475
+    /**
476
+     * @NoAdminRequired
477
+     */
478
+    public function removeupfile($removedfilename) {
479
+
480
+           $tmpfl = "/" . $this->userId . "/files/SMS_Relentless/temp_files/" . $removedfilename;
481
+
482
+           $removefile = $this->view->unlink($tmpfl);
483
+
484
+           // Get the cumulative files size of the uploaded files
485
+           $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
486
+           $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
487
+           $fileSystemIterator = new FilesystemIterator($targetdir);
488
+
489
+           $dirfiles = [];
490
+           foreach ($fileSystemIterator as $fileInfo){
491
+                    $dirfiles[] = $fileInfo->getFilename();
492
+           }
493
+
494
+           $totalflsizeinit = 0;
495
+
496
+           foreach ($dirfiles as $key => $indfile) {
497
+                    $fileSizeinit = $this->filesystem->filesize("/SMS_Relentless/temp_files/" . $indfile);
498
+                    $mbSize = round($fileSizeinit / 1024, 4);
499
+                    $totalflsizeinit += $mbSize;
500
+           }
501
+
502
+           $totalflsize = round($totalflsizeinit, 4);
503
+
504
+           return $totalflsize;
505
+    }
506
+
507
+
508
+    /**
509
+     * @NoAdminRequired
510
+     */
511
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
512
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
513
+         $telnyxkey = $telsmsapicred[0];
514
+         $teldelrecurl = $telsmsapicred[3];
515
+         $messagingprofid = $telsmsapicred[4];
516
+
517
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
518
+
519
+         $microinterval = $waitinterval * 1000;
520
+
521
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
522
+
523
+             usleep($microinterval);
524
+
525
+             $messagedate = date("Y-m-d H:i:s");
526
+
527
+             if ($ismms == 0) {
528
+
529
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
530
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
531
+                 } else {
532
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
533
+                 }
534
+
535
+                 $messagetexttel = $sentsmstext;
536
+
537
+             } else {
538
+
539
+                 $mediaURLarr = [];
540
+                 $includedMediaFiles = '';
541
+
542
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
543
+
544
+                      $userroot = $this->view->getRoot();
545
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
546
+
547
+                      $flsharetarget = $this->folder->newFile($filetoshare);
548
+
549
+	              $share = $this->shareManager->newShare();
550
+	              $share->setNode($flsharetarget);
551
+	              $share->setPermissions(Constants::PERMISSION_READ);
552
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
553
+	              $share->setSharedBy($this->userId);
554
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedate);
555
+                      $expirydate->add(new \DateInterval('P1D'));
556
+                      $share->setExpirationDate($expirydate);
557
+                      $shared = $this->shareManager->createShare($share);
558
+                      $shareToken = $shared->getToken();
559
+
560
+                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
561
+                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
562
+                 }
563
+
564
+                 if (preg_match('/[A-Za-z]+/', $fromsender)) {
565
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid, "subject" => "MMS", "media_urls" => $mediaURLarr]);
566
+                 } else {
567
+                     $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "subject" => "MMS", "media_urls" => $mediaURLarr]);
568
+                 }
569
+
570
+                 $messagetexttel = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
571
+             }
572
+
573
+             $messageid = $message['id'];
574
+             $messagefrom = "Telnyx: " . $fromsender;
575
+             $messageto = $tonumber;
576
+             $messagenetwork = null;
577
+             $messageprice = null;
578
+             $messagestatus = $message['to'][0]['status'];
579
+             $messagedelivery = null;
580
+
581
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetexttel];
582
+
583
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
584
+
585
+         }
586
+    }
587
+
588
+
589
+    /**
590
+     * @NoAdminRequired
591
+     */
592
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
593
+
594
+         $smsapicred = $this->service->getapicredentials($this->userId);
595
+
596
+         $smsapikey = $smsapicred[5];
597
+         $smsapisecret = $smsapicred[6];
598
+         $smsapideliveryrecurl = $smsapicred[8];
599
+
600
+         $microinterval = $waitinterval * 1000;
601
+
602
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
603
+
604
+             usleep($microinterval);
605
+
606
+             $messagedatepl = date("Y-m-d H:i:s");
607
+
608
+             if ($ismms == 0) {
609
+
610
+                 $client = new RestClient($smsapikey, $smsapisecret);
611
+                 $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl]);
612
+                 $messagetextpl = $sentsmstext;
613
+	         $messageidinit = $response->getmessageUuid(0);
614
+                 $messageid = $messageidinit[0];
615
+
616
+                 if (property_exists($response, 'error')) { 
617
+                     $messagestatus = "Error: " . $response->error;
618
+                 } else { $messagestatus = 'The message has been accepted for delivery.'; }
619
+
620
+             } else {
621
+
622
+                 $mediaURLarr = [];
623
+                 $includedMediaFiles = '';
624
+
625
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
626
+
627
+                      $userroot = $this->view->getRoot();
628
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
629
+
630
+                      $flsharetarget = $this->folder->newFile($filetoshare);
631
+
632
+	              $share = $this->shareManager->newShare();
633
+	              $share->setNode($flsharetarget);
634
+	              $share->setPermissions(Constants::PERMISSION_READ);
635
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
636
+	              $share->setSharedBy($this->userId);
637
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatepl);
638
+                      $expirydate->add(new \DateInterval('P1D'));
639
+                      $share->setExpirationDate($expirydate);
640
+                      $shared = $this->shareManager->createShare($share);
641
+                      $shareToken = $shared->getToken();
642
+
643
+                      $mediaURLarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
644
+                      $includedMediaFiles .= "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p] . "<br><br>";
645
+                 }
646
+
647
+		 $datatosendpl = ["src" => $fromsender, "dst" => $tonumber, "text" => $sentsmstext, "url" => $smsapideliveryrecurl, "type" => "mms", "media_urls" => $mediaURLarr];
648
+		 $postedparamspl = json_encode($datatosendpl);
649
+
650
+		 $chpl = curl_init();
651
+		 curl_setopt($chpl, CURLOPT_URL, 'https://'.$smsapikey.':'.$smsapisecret.'@api.plivo.com/v1/Account/'.$smsapikey.'/Message/');
652
+		 curl_setopt($chpl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
653
+		 curl_setopt($chpl, CURLOPT_TIMEOUT, 300);
654
+		 curl_setopt($chpl, CURLOPT_RETURNTRANSFER, 1);
655
+		 curl_setopt($chpl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
656
+		 curl_setopt($chpl, CURLOPT_POST, 1);
657
+		 curl_setopt($chpl, CURLOPT_POSTFIELDS, $postedparamspl);
658
+		 $resultpl = curl_exec ($chpl);
659
+		 $statusCodepl = curl_getinfo($chpl, CURLINFO_HTTP_CODE);
660
+		 curl_close ($chpl);
661
+
662
+		 $decresultpl = json_decode($resultpl);
663
+
664
+                 if (property_exists($decresultpl, 'message_uuid')) {
665
+                     $messageidinit = $decresultpl->message_uuid;
666
+                     $messageid = $messageidinit[0];
667
+                 }
668
+
669
+	         if (in_array($statusCodepl, [200, 201, 202, 203, 204, 205, 206])) {
670
+
671
+                     if (property_exists($decresultpl, 'error')) {
672
+                         $messagestatus = "Error: " . $decresultpl->error;
673
+                     } else { $messagestatus = 'The message has been accepted for delivery.'; }
674
+
675
+                 } else { $messagestatus = 'An error occurred while trying to send the message.'; }
676
+
677
+                 $messagetextpl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
678
+             }
679
+
680
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
681
+                 $messagefrom = "Plivo: " . $fromsender;
682
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
683
+
684
+             $messageto = $tonumber;
685
+             $messagenetwork = '';
686
+             $messageprice = '';
687
+
688
+             $messagedelivery = '';
689
+
690
+             $sentmessagearr = [$messageid, $messagedatepl, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetextpl];
691
+
692
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
693
+         }
694
+    }
695
+
696
+
697
+    /**
698
+     * @NoAdminRequired
699
+     */
700
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
701
+
702
+         $smsapicred = $this->service->getapicredentials($this->userId);
703
+
704
+         $sid = $smsapicred[15];
705
+         $token = $smsapicred[16];
706
+         $smsapirecurltw = $smsapicred[18];
707
+
708
+         $microinterval = $waitinterval * 1000;
709
+
710
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
711
+
712
+             usleep($microinterval);
713
+
714
+             $messagedatetw = date("Y-m-d H:i:s");
715
+
716
+             if ($ismms == 0) {
717
+
718
+                  $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
719
+                  $sentsmstextfintw = $sentsmstext;
720
+
721
+             } else {
722
+
723
+                 $mediaURLs = [];
724
+
725
+                 for ($p = 0; $p < count($mmsfiles); $p++ ) {
726
+
727
+                      $userroot = $this->view->getRoot();
728
+                      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
729
+
730
+                      $flsharetarget = $this->folder->newFile($filetoshare);
731
+
732
+	              $share = $this->shareManager->newShare();
733
+	              $share->setNode($flsharetarget);
734
+	              $share->setPermissions(Constants::PERMISSION_READ);
735
+	              $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
736
+	              $share->setSharedBy($this->userId);
737
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatetw);
738
+                      $expirydate->add(new \DateInterval('P1D'));
739
+                      $share->setExpirationDate($expirydate);
740
+                      $shared = $this->shareManager->createShare($share);
741
+                      $shareToken = $shared->getToken();
742
+
743
+                      $mediaURLs[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
744
+                 }
745
+
746
+                 $datatoposttw = [["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]];
747
+                 $includedMediaFiles = '';
748
+
749
+                 for ($m = 0; $m < count($mediaURLs); $m++) {
750
+                      array_push($datatoposttw, ["MediaUrl" => $mediaURLs[$m]]);
751
+                      $includedMediaFiles .= $mediaURLs[$m] . "<br><br>";
752
+                 }
753
+
754
+                 $sentsmstextfintw = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
755
+             }
756
+
757
+             $postedsendingfl = implode('&', array_map('http_build_query', $datatoposttw));
758
+
759
+	     $chtw = curl_init();
760
+	     curl_setopt($chtw, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
761
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
762
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
763
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
764
+             curl_setopt($chtw, CURLOPT_USERPWD, "$sid:$token");
765
+	     curl_setopt($chtw, CURLOPT_POST, 1);
766
+             curl_setopt($chtw, CURLOPT_POSTFIELDS, $postedsendingfl);
767
+
768
+	     $resulttw = curl_exec ($chtw);
769
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
770
+	     curl_close ($chtw);
771
+
772
+             $decresulttw = json_decode($resulttw);
773
+
774
+             if ($resulttw) {
775
+                 $messageidtw = $decresulttw->sid;
776
+             } else { $messageidtw = ''; }
777
+
778
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) {
779
+                 $messagestatustw = 'The message has been accepted for delivery.';
780
+             } else {
781
+                 $messagestatustw = 'An error occurred while trying to send the message.';
782
+             }
783
+
784
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
785
+                 $messagefromtw = "Twilio: " . $fromsender;
786
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
787
+
788
+             $messagenetworktw = '';
789
+             $messagepricetw = '';
790
+             $messagedeliverytw = '';
791
+
792
+
793
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstextfintw];
794
+
795
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
796
+         }
797
+
798
+    }
799
+
800
+
801
+    /**
802
+     * @NoAdminRequired
803
+     */
804
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext, $ismms, $mmsfiles) {
805
+
806
+         $smsapicredfl = $this->service->getapicredentials($this->userId);
807
+
808
+         $flowapikey = $smsapicredfl[20];
809
+         $flowapisecret = $smsapicredfl[21];
810
+         $flowdelrecurl = $smsapicredfl[23];
811
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
812
+
813
+         $microinterval = $waitinterval * 1000;
814
+
815
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
816
+
817
+             usleep($microinterval);
818
+
819
+             $messagedatefl = date("Y-m-d H:i:s");
820
+
821
+             if ($ismms == 0) {
822
+
823
+                 $messagetextfinfl = $sentsmstext;
824
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl]);
825
+
826
+             } else {
827
+
828
+		 $mediaurlsarr = [];
829
+
830
+		 for ($p = 0; $p < count($mmsfiles); $p++ ) {
831
+
832
+		      $userroot = $this->view->getRoot();
833
+		      $filetoshare = $userroot . "/SMS_Relentless/temp_files/".$mmsfiles[$p]."";
834
+
835
+		      $flsharetarget = $this->folder->newFile($filetoshare);
836
+
837
+		      $share = $this->shareManager->newShare();
838
+		      $share->setNode($flsharetarget);
839
+		      $share->setPermissions(Constants::PERMISSION_READ);
840
+		      $share->setShareType(\OC\Share\Constants::SHARE_TYPE_LINK);
841
+		      $share->setSharedBy($this->userId);
842
+                      $expirydate = DateTime::createFromFormat('Y-m-d H:i:s', $messagedatefl);
843
+                      $expirydate->add(new \DateInterval('P1D'));
844
+                      $share->setExpirationDate($expirydate);
845
+		      $shared = $this->shareManager->createShare($share);
846
+		      $shareToken = $shared->getToken();
847
+
848
+		      $mediaurlsarr[] = "https://cloud.webpublicist.net/s/".$shareToken."/download/".$mmsfiles[$p]."";
849
+		 }
850
+
851
+		 $includedMediaFiles = '';
852
+
853
+		 for ($m = 0; $m < count($mediaurlsarr); $m++) {
854
+		      $includedMediaFiles .= $mediaurlsarr[$m] . "<br><br>";
855
+		 }
856
+
857
+                 $messagetextfinfl = $sentsmstext . "<br><br><br>--- File(s) included in MMS ---<br><br>" . $includedMediaFiles;
858
+
859
+                 $postedparamsfl = json_encode(["to" => $tonumberfl, "from" => $fromsender, "body" => $sentsmstextproc, "dlr_callback" => $flowdelrecurl, "media_urls" => $mediaurlsarr]);
860
+             }
861
+
862
+
863
+	     $chfl = curl_init();
864
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
865
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
866
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
867
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
868
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
869
+	     curl_setopt($chfl, CURLOPT_POST, 1);
870
+             curl_setopt($chfl, CURLOPT_POSTFIELDS, $postedparamsfl);
871
+	     $resultfl = curl_exec ($chfl);
872
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
873
+	     curl_close ($chfl);
874
+
875
+             $decresultfl = json_decode($resultfl);
876
+
877
+             if ($resultfl) {
878
+                 $messageidfl = $decresultfl->data->id;
879
+             } else { $messageidfl = ''; }
880
+
881
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
882
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
883
+             } else { 
884
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
885
+             }
886
+
887
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
888
+                 $messagefromfl = "Flowroute: " . $fromsender;
889
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
890
+
891
+             $messagetofl = $tonumberfl;
892
+             $messagenetworkfl = '';
893
+             $messagepricefl = '';
894
+             $messagedeliveryfl = '';
895
+
896
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfinfl];
897
+
898
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
899
+         }
900
+
901
+    }
902
+
903
+
904
+    /**
905
+     * @NoAdminRequired
906
+     */
907
+    public function saveoldrecrows($userId, $oldrecRows) {
908
+
909
+           // Create the folder for removed messages if it doesn't exist
910
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
911
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
912
+           }
913
+           $savecheck = 0;
914
+
915
+           if (count($oldrecRows) > 1) {
916
+               $msfileContent = implode("", $oldrecRows);
917
+
918
+               $delrowsdate = date("Y-m-d_H-i-s");
919
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
920
+
921
+               $userroot = $this->view->getRoot();
922
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
923
+
924
+               $target = $this->folder->newFile($targetfile);
925
+               $target->putContent($msfileContent);
926
+
927
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
928
+                   $savecheck = 1;
929
+               }
930
+           }
931
+
932
+           return $savecheck;
933
+    }
934
+
935
+
936
+    /**
937
+     * @NoAdminRequired
938
+     */
939
+    public function saveoldsentrows($userId, $oldsentRows) {
940
+
941
+           // Create the folder for removed messages if it doesn't exist
942
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
943
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
944
+           }
945
+           $savesentcheck = 0;
946
+
947
+           if (count($oldsentRows) > 1) {
948
+               $sntfileContent = implode("", $oldsentRows);
949
+
950
+               $delsentrowsdate = date("Y-m-d_H-i-s");
951
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
952
+
953
+               $userroot = $this->view->getRoot();
954
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
955
+
956
+               $snttarget = $this->folder->newFile($snttargetfile);
957
+               $snttarget->putContent($sntfileContent);
958
+
959
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
960
+                   $savesentcheck = 1;
961
+               }
962
+           }
963
+
964
+           return $savesentcheck;
965
+    }
966
+
967
+
968
+    /**
969
+     * @NoAdminRequired
970
+     */
971
+    public function getreceivedtable($userId) {
972
+           return $this->service->getreceivedtable($this->userId);
973
+    }
974
+
975
+    /**
976
+     * @NoAdminRequired
977
+     */
978
+    public function getreceivedtablefordel($userId) {
979
+           return $this->service->getreceivedtablefordel($this->userId);
980
+    }
981
+
982
+    /**
983
+     * @NoAdminRequired
984
+     */
985
+    public function removerecrows($userId, $recmessagedbIDs) {
986
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
987
+    }
988
+
989
+    /**
990
+     * @NoAdminRequired
991
+     */
992
+    public function getsenttable($userId) {
993
+           return $this->service->getsenttable($this->userId);
994
+    }
995
+
996
+    /**
997
+     * @NoAdminRequired
998
+     */
999
+    public function getsenttablefordel($userId) {
1000
+           return $this->service->getsenttablefordel($this->userId);
1001
+    }
1002
+
1003
+    /**
1004
+     * @NoAdminRequired
1005
+     */
1006
+    public function removesentrows($userId, $sentmessagedbIDs) {
1007
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
1008
+    }
1009
+
1010
+    /**
1011
+     * @NoAdminRequired
1012
+     */
1013
+    public function getmessagesperpage($userId) {
1014
+           return $this->service->getmessagesperpage($this->userId);
1015
+    }
1016
+
1017
+    /**
1018
+     * @NoAdminRequired
1019
+     */
1020
+    public function getdelrecsettings($userId) {
1021
+           return $this->service->getdelrecsettings($this->userId);
1022
+    }
1023
+
1024
+    /**
1025
+     * @NoAdminRequired
1026
+     */
1027
+    public function getsettings($userId) {
1028
+           return $this->service->getsettings($this->userId);
1029
+    }
1030
+
1031
+    /**
1032
+     * @NoAdminRequired
1033
+     */
1034
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName) {
1035
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName);
1036
+    }
1037
+
1038
+}
Browse code

removed README.md CHANGELOG.txt appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/settings.js js/sendsms.js js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php templates/navigation/index.php templates/content/index.php templates/settings.php

DoubleBastionAdmin authored on 02/09/2022 23:09:46
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,706 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use OCP\AppFramework\Http\DataResponse;
44
-use OCP\Files\NotFoundException;
45
-use OCP\Files\NotPermittedException;
46
-use Plivo\RestClient;
47
-
48
-
49
-class SmsrelentlessController extends Controller {
50
-
51
-    private $service;
52
-    private $config;
53
-    private $userId;
54
-    private $folder;
55
-    private $filesystem;
56
-    private $view;
57
-
58
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
59
-        parent::__construct($appName, $request);
60
-        $this->service = $service;
61
-        $this->config = $config;
62
-        $this->userId = $userId;
63
-        $this->folder = $folder;
64
-        $this->filesystem = $filesystem;
65
-        $this->view = $view;
66
-    }
67
-
68
-
69
-    /**
70
-     * @NoAdminRequired
71
-     */
72
-    public function object_to_array($obj) {
73
-        if(is_object($obj)) $obj = (array)$this->dismount($obj);
74
-        if(is_array($obj)) {
75
-           $new = array();
76
-           foreach($obj as $key => $val) {
77
-               $new[$key] = $this->object_to_array($val);
78
-           }
79
-        }
80
-        else $new = $obj;
81
-        return $new;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function dismount($object) {
89
-        $reflectionClass = new ReflectionClass(get_class($object));
90
-        $array = array();
91
-        foreach ($reflectionClass->getProperties() as $property) {
92
-           $property->setAccessible(true);
93
-           $array[$property->getName()] = $property->getValue($object);
94
-           $property->setAccessible(false);
95
-        }
96
-        return $array;
97
-    }
98
-
99
-
100
-    /**
101
-     * @NoAdminRequired
102
-     */
103
-    public function getbalancetel($userId) {
104
-
105
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
106
-
107
-        $telapikey = $telsmsapicred[0];
108
-        $ch = curl_init();
109
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
110
-
111
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
112
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
113
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
114
-        $responsetel = curl_exec($ch);
115
-        $recdatatel = json_decode($responsetel, TRUE);
116
-        $telbalresponse = $recdatatel['data']['balance'];
117
-        $currentbalancetel = round(floatval($telbalresponse), 3);
118
-        curl_close($ch);
119
-
120
-        return $currentbalancetel;
121
-    }
122
-
123
-
124
-    /**
125
-     * @NoAdminRequired
126
-     */
127
-    public function getbalancenex($userId) {
128
-
129
-        $smsapicred = $this->service->getapicredentials($this->userId);
130
-        $smsapikey = $smsapicred[5];
131
-        $smsapisecret = $smsapicred[6];
132
-
133
-        if ($smsapikey == '' || $smsapisecret == '') {
134
-            $currentbalancenex = "N/A";
135
-        } else {
136
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
137
-            $mesdata = file_get_contents($getmesdata);
138
-            $datainit = json_decode($mesdata);
139
-            $balancenex = $datainit->cash_credits;
140
-            $currentbalancenex = round(floatval($balancenex), 3);
141
-        }
142
-        return $currentbalancenex;
143
-    }
144
-
145
-
146
-    /**
147
-     * @NoAdminRequired
148
-     */
149
-    public function getbalancetwil($userId) {
150
-
151
-        $smsapicred = $this->service->getapicredentials($this->userId);
152
-        $smsapisid = $smsapicred[15];
153
-        $smsapitoken = $smsapicred[16];
154
-
155
-        if ($smsapisid == '' || $smsapitoken == '') {
156
-            $currentbalancetwil = "N/A";
157
-        } else {
158
-
159
-            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
160
-            $balancetwil = $twilbalance->balance;
161
-
162
-            $currentbalancetwil = round(floatval($balancetwil), 3);
163
-        }
164
-        return $currentbalancetwil;
165
-    }
166
-
167
-
168
-    /**
169
-     * @NoAdminRequired
170
-     */
171
-    public function getbalanceflow($userId) {
172
-
173
-        $currentbalanceflow = 'n/a';
174
-
175
-        return $currentbalanceflow;
176
-    }
177
-
178
-
179
-    /**
180
-     * @NoAdminRequired
181
-     */
182
-    public function getsmsnumbers($userId) {
183
-
184
-        $smsapicred = $this->service->getapicredentials($this->userId);
185
-
186
-        $telnyxkey = $smsapicred[0];
187
-
188
-        $nexapikey = $smsapicred[5];
189
-        $nexapisecret = $smsapicred[6];
190
-
191
-        $twilapikey = $smsapicred[15];
192
-        $twilapisecret = $smsapicred[16];
193
-
194
-        $flowapikey = $smsapicred[20];
195
-        $flowapisecret = $smsapicred[21];
196
-
197
-        $telsendernameinit = $smsapicred[9];
198
-        $nexsendernameinit = $smsapicred[10];
199
-        $twilsendernameinit = $smsapicred[19];
200
-        $flowsendernameinit = $smsapicred[24];
201
-
202
-        $telsendername = "Tx: " . $telsendernameinit;
203
-        $nexsendername = "Pl: " . $nexsendernameinit;
204
-        $twilsendername = "Tw: " . $twilsendernameinit;
205
-        $flowsendername = "Fl: " . $flowsendernameinit;
206
-
207
-        // Get Telnyx phone numbers
208
-        if ($telnyxkey != '') {
209
-
210
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
211
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
212
-
213
-           $telnumbersarr = $this->object_to_array($telnumbers);
214
-           $telnmbrs = [];
215
-
216
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
217
-              if (is_int($nmbkey)) {
218
-                 foreach ($nmbvalue as $nkey => $nvalue) {
219
-                    if ($nkey == 'phone_number') {
220
-                       $telnmbrs[] = "Tx: " . $nvalue;
221
-                    }
222
-                 }
223
-              }
224
-           }
225
-
226
-        } else { $telnmbrs = []; }
227
-
228
-        // Get Plivo phone numbers
229
-        if ($nexapikey != '' && $nexapisecret != '') {
230
-
231
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
232
-           $acdata = file_get_contents($getacdata);
233
-           $datainit = json_decode($acdata, true);
234
-
235
-           $findata = $this->object_to_array($datainit);
236
-
237
-           $nexcurrentnmbrs = [];
238
-
239
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
240
-                   if (is_array($smsvalue)) {
241
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
242
-                               if ($smskey2 == 'number') {
243
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
244
-                               }
245
-                         }
246
-                   }
247
-           }
248
-
249
-
250
-        } else { $nexcurrentnmbrs = []; }
251
-
252
-        // Get Twilio phone numbers
253
-        if ($twilapikey != '' && $twilapisecret != '') {
254
-
255
-            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
256
-            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
257
-
258
-            $twilcurrentnmbrs = [];
259
-            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
260
-                 if (is_array($twnbvalue)) {
261
-                     foreach ($twnbvalue as $twfkey => $twfvalue) {
262
-                          if ($twfkey == 'phone_number') {
263
-                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
264
-                          }
265
-                     }
266
-                 }
267
-            }
268
-
269
-        } else { $twilcurrentnmbrs = []; }
270
-
271
-        // Get Flowroute phone numbers
272
-        if ($flowapikey != '' && $flowapisecret != '') {
273
-
274
-            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
275
-            $flnbrsarr = $flnbrsresult->data;
276
-            $flowcurrentnmbrs = [];
277
-            foreach ($flnbrsarr as $flkey => $flitem) {
278
-                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
279
-            }
280
-
281
-        } else { $flowcurrentnmbrs = []; }
282
-
283
-
284
-        $telsenderarr = [0 => $telsendername];
285
-        $nexsenderarr = [0 => $nexsendername];
286
-        $twilsenderarr = [0 => $twilsendername];
287
-        $flowsenderarr = [0 => $flowsendername];
288
-
289
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr, $flowsenderarr);
290
-
291
-        return $currentnmbrs;
292
-    }
293
-
294
-
295
-    /**
296
-     * @NoAdminRequired
297
-     */
298
-    public function cleantempdir($userId) {
299
-
300
-        // Create the temporary folder if it doesn't exist
301
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
302
-            $this->folder->newFolder('SMS_Relentless/temp_files');
303
-        }
304
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
305
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
306
-        $fileSystemIterator = new FilesystemIterator($targetdir);
307
-
308
-        $dirfiles = [];
309
-        foreach ($fileSystemIterator as $fileInfo){
310
-                 $dirfiles[] = $fileInfo->getFilename();
311
-        }
312
-
313
-        foreach ($dirfiles as $key => $indfile) {
314
-                 $thisuserroot = $this->view->getRoot();
315
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
316
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
317
-        }
318
-     }
319
-
320
-
321
-    /**
322
-     * @NoAdminRequired
323
-     */
324
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
325
-
326
-        // Create the temporary folder if it doesn't exist
327
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
328
-            $this->folder->newFolder('SMS_Relentless/temp_files');
329
-        }
330
-
331
-        // First delete any file that has been previously uploaded
332
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
333
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
334
-        $fileSystemIterator = new FilesystemIterator($targetdir);
335
-
336
-        $dirfiles = [];
337
-        foreach ($fileSystemIterator as $fileInfo){
338
-                 $dirfiles[] = $fileInfo->getFilename();
339
-        }
340
-
341
-        foreach ($dirfiles as $key => $indfile) {
342
-                 $thisuserroot = $this->view->getRoot();
343
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
344
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
345
-        }
346
-
347
-        // Upload the new file
348
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
349
-        $fileName = $_FILES['uploadfileforsms']['name'];
350
-
351
-        $userroot = $this->view->getRoot();
352
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
353
-
354
-        $target = $this->folder->newFile($targetfile);
355
-        $target->putContent($fileContent);
356
-
357
-        // Extract the phone numbers from the file
358
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
359
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
360
-        $numberarrayfourth = explode(",", $numberarraytert);
361
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
362
-        $numberarray = array_unique($numberarrayfifth);
363
-
364
-        return $numberarray;
365
-    }
366
-
367
-
368
-    /**
369
-     * @NoAdminRequired
370
-     */
371
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
372
-
373
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
374
-         $telnyxkey = $telsmsapicred[0];
375
-         $teldelrecurl = $telsmsapicred[3];
376
-         $messagingprofid = $telsmsapicred[4];
377
-
378
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
379
-
380
-         $microinterval = $waitinterval * 1000;
381
-
382
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
383
-
384
-             usleep($microinterval);
385
-
386
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
387
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
388
-             } else {
389
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
390
-             }
391
-
392
-             $messageid = $message['id'];
393
-             $messagedate = date("Y-m-d H:i:s");
394
-             $messagefrom = "Telnyx: " . $fromsender;
395
-             $messageto = $tonumber;
396
-             $messagenetwork = null;
397
-             $messageprice = null;
398
-             $messagestatus = $message['to'][0]['status'];
399
-             $messagedelivery = null;
400
-             $messagetext = $sentsmstext;
401
-
402
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
403
-
404
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
405
-
406
-         }
407
-    }
408
-
409
-
410
-    /**
411
-     * @NoAdminRequired
412
-     */
413
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
414
-
415
-         $smsapicred = $this->service->getapicredentials($this->userId);
416
-
417
-         $smsapikey = $smsapicred[5];
418
-         $smsapisecret = $smsapicred[6];
419
-         $smsapideliveryrecurl = $smsapicred[8];
420
-
421
-         $microinterval = $waitinterval * 1000;
422
-
423
-         $client = new RestClient($smsapikey, $smsapisecret);
424
-
425
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
426
-
427
-             usleep($microinterval);
428
-
429
-             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
430
-
431
-	     $messageidinit = $response->getmessageUuid(0);
432
-             $messageid = $messageidinit[0];
433
-
434
-             $messagedate = date("Y-m-d H:i:s");
435
-
436
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
437
-                 $messagefrom = "Plivo: " . $fromsender;
438
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
439
-
440
-             $messageto = $tonumber;
441
-             $messagenetwork = null;
442
-             $messageprice = null;
443
-             $messagestatus = "The message has been accepted for delivery.";
444
-             $messagedelivery = null;
445
-             $messagetext = $sentsmstext;
446
-
447
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
448
-
449
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
450
-         }
451
-    }
452
-
453
-
454
-    /**
455
-     * @NoAdminRequired
456
-     */
457
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
458
-
459
-         $smsapicred = $this->service->getapicredentials($this->userId);
460
-
461
-         $sid = $smsapicred[15];
462
-         $token = $smsapicred[16];
463
-         $smsapirecurltw = $smsapicred[18];
464
-
465
-         $microinterval = $waitinterval * 1000;
466
-
467
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
468
-
469
-             usleep($microinterval);
470
-
471
-	     $chtw = curl_init();
472
-	     curl_setopt($chtw, CURLOPT_URL, 'https://'.$sid.':'.$token.'@api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
473
-	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
474
-	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
475
-	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
476
-	     curl_setopt($chtw, CURLOPT_POST, 1);
477
-	     curl_setopt($chtw, CURLOPT_POSTFIELDS, ["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]);
478
-	     $resulttw = curl_exec ($chtw);
479
-	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
480
-	     curl_close ($chtw);
481
-
482
-             $decresulttw = json_decode($resulttw);
483
-             if (is_object($decresulttw)) {
484
-                 $messageidtw = $decresulttw->sid;
485
-             } else { $messageidtw = ''; }
486
-
487
-	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) { 
488
-                 $messagestatustw = 'The message has been accepted for delivery.'; 
489
-             } else { 
490
-                 $messagestatustw = 'An error occurred while trying to send the message.'; 
491
-             }
492
-
493
-             $messagedatetw = date("Y-m-d H:i:s");
494
-
495
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
496
-                 $messagefromtw = "Twilio: " . $fromsender;
497
-             } else { $messagefromtw = "Twilio: " . $fromsender; }
498
-
499
-             $messagenetworktw = '';
500
-             $messagepricetw = '';
501
-             $messagedeliverytw = '';
502
-
503
-             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstext];
504
-
505
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
506
-         }
507
-
508
-    }
509
-
510
-
511
-    /**
512
-     * @NoAdminRequired
513
-     */
514
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
515
-
516
-         $smsapicredfl = $this->service->getapicredentials($this->userId);
517
-
518
-         $flowapikey = $smsapicredfl[20];
519
-         $flowapisecret = $smsapicredfl[21];
520
-         $flowdelrecurl = $smsapicredfl[23];
521
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
522
-
523
-         $microinterval = $waitinterval * 1000;
524
-
525
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
526
-
527
-             usleep($microinterval);
528
-
529
-	     $chfl = curl_init();
530
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
531
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
532
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
533
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
534
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
535
-	     curl_setopt($chfl, CURLOPT_POST, 1);
536
-	     curl_setopt($chfl, CURLOPT_POSTFIELDS, '{"to": "'. $tonumberfl .'", "from": "'. $fromsender .'", "body": "'. $sentsmstextproc .'", "dlr_callback": "'. $flowdelrecurl .'"}');
537
-	     $resultfl = curl_exec ($chfl);
538
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
539
-	     curl_close ($chfl);
540
-
541
-             $decresultfl = json_decode($resultfl);
542
-             if (is_object($decresultfl)) {
543
-                 $messageidfl = $decresultfl->data->id;
544
-             } else { $messageidfl = ''; }
545
-
546
-	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
547
-                 $messagestatusfl = 'The message has been accepted for delivery.'; 
548
-             } else { 
549
-                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
550
-             }
551
-
552
-             $messagedatefl = date("Y-m-d H:i:s");
553
-
554
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
555
-                 $messagefromfl = "Flowroute: " . $fromsender;
556
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
557
-
558
-             $messagetofl = $tonumberfl;
559
-             $messagenetworkfl = '';
560
-             $messagepricefl = '';
561
-             $messagedeliveryfl = '';
562
-             $messagetextfl = $sentsmstext;
563
-
564
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfl];
565
-
566
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
567
-         }
568
-
569
-    }
570
-
571
-
572
-    /**
573
-     * @NoAdminRequired
574
-     */
575
-    public function saveoldrecrows($userId, $oldrecRows) {
576
-
577
-           // Create the folder for removed messages if it doesn't exist
578
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
579
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
580
-           }
581
-           $savecheck = 0;
582
-
583
-           if (count($oldrecRows) > 1) {
584
-               $msfileContent = implode("", $oldrecRows);
585
-
586
-               $delrowsdate = date("Y-m-d_H-i-s");
587
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
588
-
589
-               $userroot = $this->view->getRoot();
590
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
591
-
592
-               $target = $this->folder->newFile($targetfile);
593
-               $target->putContent($msfileContent);
594
-
595
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
596
-                   $savecheck = 1;
597
-               }
598
-           }
599
-
600
-           return $savecheck;
601
-    }
602
-
603
-
604
-    /**
605
-     * @NoAdminRequired
606
-     */
607
-    public function saveoldsentrows($userId, $oldsentRows) {
608
-
609
-           // Create the folder for removed messages if it doesn't exist
610
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
611
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
612
-           }
613
-           $savesentcheck = 0;
614
-
615
-           if (count($oldsentRows) > 1) {
616
-               $sntfileContent = implode("", $oldsentRows);
617
-
618
-               $delsentrowsdate = date("Y-m-d_H-i-s");
619
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
620
-
621
-               $userroot = $this->view->getRoot();
622
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
623
-
624
-               $snttarget = $this->folder->newFile($snttargetfile);
625
-               $snttarget->putContent($sntfileContent);
626
-
627
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
628
-                   $savesentcheck = 1;
629
-               }
630
-           }
631
-
632
-           return $savesentcheck;
633
-    }
634
-
635
-
636
-    /**
637
-     * @NoAdminRequired
638
-     */
639
-    public function getreceivedtable($userId) {
640
-           return $this->service->getreceivedtable($this->userId);
641
-    }
642
-
643
-    /**
644
-     * @NoAdminRequired
645
-     */
646
-    public function getreceivedtablefordel($userId) {
647
-           return $this->service->getreceivedtablefordel($this->userId);
648
-    }
649
-
650
-    /**
651
-     * @NoAdminRequired
652
-     */
653
-    public function removerecrows($userId, $recmessagedbIDs) {
654
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
655
-    }
656
-
657
-    /**
658
-     * @NoAdminRequired
659
-     */
660
-    public function getsenttable($userId) {
661
-           return $this->service->getsenttable($this->userId);
662
-    }
663
-
664
-    /**
665
-     * @NoAdminRequired
666
-     */
667
-    public function getsenttablefordel($userId) {
668
-           return $this->service->getsenttablefordel($this->userId);
669
-    }
670
-
671
-    /**
672
-     * @NoAdminRequired
673
-     */
674
-    public function removesentrows($userId, $sentmessagedbIDs) {
675
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
676
-    }
677
-
678
-    /**
679
-     * @NoAdminRequired
680
-     */
681
-    public function getmessagesperpage($userId) {
682
-           return $this->service->getmessagesperpage($this->userId);
683
-    }
684
-
685
-    /**
686
-     * @NoAdminRequired
687
-     */
688
-    public function getdelrecsettings($userId) {
689
-           return $this->service->getdelrecsettings($this->userId);
690
-    }
691
-
692
-    /**
693
-     * @NoAdminRequired
694
-     */
695
-    public function getsettings($userId) {
696
-           return $this->service->getsettings($this->userId);
697
-    }
698
-
699
-    /**
700
-     * @NoAdminRequired
701
-     */
702
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName) {
703
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName);
704
-    }
705
-
706
-}
Browse code

added README.md CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/settings.js lib/AppInfo/Application.php lib/Controller/SmsrelentlessController.php lib/Controller/AuthorApiController.php lib/Migration/Version108Date20220823132408.php providers/Twilio

DoubleBastionAdmin authored on 23/08/2022 10:48:04
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,706 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use OCP\AppFramework\Http\DataResponse;
44
+use OCP\Files\NotFoundException;
45
+use OCP\Files\NotPermittedException;
46
+use Plivo\RestClient;
47
+
48
+
49
+class SmsrelentlessController extends Controller {
50
+
51
+    private $service;
52
+    private $config;
53
+    private $userId;
54
+    private $folder;
55
+    private $filesystem;
56
+    private $view;
57
+
58
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
59
+        parent::__construct($appName, $request);
60
+        $this->service = $service;
61
+        $this->config = $config;
62
+        $this->userId = $userId;
63
+        $this->folder = $folder;
64
+        $this->filesystem = $filesystem;
65
+        $this->view = $view;
66
+    }
67
+
68
+
69
+    /**
70
+     * @NoAdminRequired
71
+     */
72
+    public function object_to_array($obj) {
73
+        if(is_object($obj)) $obj = (array)$this->dismount($obj);
74
+        if(is_array($obj)) {
75
+           $new = array();
76
+           foreach($obj as $key => $val) {
77
+               $new[$key] = $this->object_to_array($val);
78
+           }
79
+        }
80
+        else $new = $obj;
81
+        return $new;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function dismount($object) {
89
+        $reflectionClass = new ReflectionClass(get_class($object));
90
+        $array = array();
91
+        foreach ($reflectionClass->getProperties() as $property) {
92
+           $property->setAccessible(true);
93
+           $array[$property->getName()] = $property->getValue($object);
94
+           $property->setAccessible(false);
95
+        }
96
+        return $array;
97
+    }
98
+
99
+
100
+    /**
101
+     * @NoAdminRequired
102
+     */
103
+    public function getbalancetel($userId) {
104
+
105
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
106
+
107
+        $telapikey = $telsmsapicred[0];
108
+        $ch = curl_init();
109
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
110
+
111
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
112
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
113
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
114
+        $responsetel = curl_exec($ch);
115
+        $recdatatel = json_decode($responsetel, TRUE);
116
+        $telbalresponse = $recdatatel['data']['balance'];
117
+        $currentbalancetel = round(floatval($telbalresponse), 3);
118
+        curl_close($ch);
119
+
120
+        return $currentbalancetel;
121
+    }
122
+
123
+
124
+    /**
125
+     * @NoAdminRequired
126
+     */
127
+    public function getbalancenex($userId) {
128
+
129
+        $smsapicred = $this->service->getapicredentials($this->userId);
130
+        $smsapikey = $smsapicred[5];
131
+        $smsapisecret = $smsapicred[6];
132
+
133
+        if ($smsapikey == '' || $smsapisecret == '') {
134
+            $currentbalancenex = "N/A";
135
+        } else {
136
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
137
+            $mesdata = file_get_contents($getmesdata);
138
+            $datainit = json_decode($mesdata);
139
+            $balancenex = $datainit->cash_credits;
140
+            $currentbalancenex = round(floatval($balancenex), 3);
141
+        }
142
+        return $currentbalancenex;
143
+    }
144
+
145
+
146
+    /**
147
+     * @NoAdminRequired
148
+     */
149
+    public function getbalancetwil($userId) {
150
+
151
+        $smsapicred = $this->service->getapicredentials($this->userId);
152
+        $smsapisid = $smsapicred[15];
153
+        $smsapitoken = $smsapicred[16];
154
+
155
+        if ($smsapisid == '' || $smsapitoken == '') {
156
+            $currentbalancetwil = "N/A";
157
+        } else {
158
+
159
+            $twilbalance = json_decode(file_get_contents("https://".$smsapisid.":".$smsapitoken."@api.twilio.com/2010-04-01/Accounts/".$smsapisid."/Balance.json"));
160
+            $balancetwil = $twilbalance->balance;
161
+
162
+            $currentbalancetwil = round(floatval($balancetwil), 3);
163
+        }
164
+        return $currentbalancetwil;
165
+    }
166
+
167
+
168
+    /**
169
+     * @NoAdminRequired
170
+     */
171
+    public function getbalanceflow($userId) {
172
+
173
+        $currentbalanceflow = 'n/a';
174
+
175
+        return $currentbalanceflow;
176
+    }
177
+
178
+
179
+    /**
180
+     * @NoAdminRequired
181
+     */
182
+    public function getsmsnumbers($userId) {
183
+
184
+        $smsapicred = $this->service->getapicredentials($this->userId);
185
+
186
+        $telnyxkey = $smsapicred[0];
187
+
188
+        $nexapikey = $smsapicred[5];
189
+        $nexapisecret = $smsapicred[6];
190
+
191
+        $twilapikey = $smsapicred[15];
192
+        $twilapisecret = $smsapicred[16];
193
+
194
+        $flowapikey = $smsapicred[20];
195
+        $flowapisecret = $smsapicred[21];
196
+
197
+        $telsendernameinit = $smsapicred[9];
198
+        $nexsendernameinit = $smsapicred[10];
199
+        $twilsendernameinit = $smsapicred[19];
200
+        $flowsendernameinit = $smsapicred[24];
201
+
202
+        $telsendername = "Tx: " . $telsendernameinit;
203
+        $nexsendername = "Pl: " . $nexsendernameinit;
204
+        $twilsendername = "Tw: " . $twilsendernameinit;
205
+        $flowsendername = "Fl: " . $flowsendernameinit;
206
+
207
+        // Get Telnyx phone numbers
208
+        if ($telnyxkey != '') {
209
+
210
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
211
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
212
+
213
+           $telnumbersarr = $this->object_to_array($telnumbers);
214
+           $telnmbrs = [];
215
+
216
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
217
+              if (is_int($nmbkey)) {
218
+                 foreach ($nmbvalue as $nkey => $nvalue) {
219
+                    if ($nkey == 'phone_number') {
220
+                       $telnmbrs[] = "Tx: " . $nvalue;
221
+                    }
222
+                 }
223
+              }
224
+           }
225
+
226
+        } else { $telnmbrs = []; }
227
+
228
+        // Get Plivo phone numbers
229
+        if ($nexapikey != '' && $nexapisecret != '') {
230
+
231
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
232
+           $acdata = file_get_contents($getacdata);
233
+           $datainit = json_decode($acdata, true);
234
+
235
+           $findata = $this->object_to_array($datainit);
236
+
237
+           $nexcurrentnmbrs = [];
238
+
239
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
240
+                   if (is_array($smsvalue)) {
241
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
242
+                               if ($smskey2 == 'number') {
243
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
244
+                               }
245
+                         }
246
+                   }
247
+           }
248
+
249
+
250
+        } else { $nexcurrentnmbrs = []; }
251
+
252
+        // Get Twilio phone numbers
253
+        if ($twilapikey != '' && $twilapisecret != '') {
254
+
255
+            $twilnumbers = json_decode(file_get_contents("https://".$twilapikey.":".$twilapisecret."@api.twilio.com/2010-04-01/Accounts/".$twilapikey."/IncomingPhoneNumbers.json"), true);
256
+            $twilactivenmbrs = $twilnumbers['incoming_phone_numbers'];
257
+
258
+            $twilcurrentnmbrs = [];
259
+            foreach ($twilactivenmbrs as $twnbkey => $twnbvalue) {
260
+                 if (is_array($twnbvalue)) {
261
+                     foreach ($twnbvalue as $twfkey => $twfvalue) {
262
+                          if ($twfkey == 'phone_number') {
263
+                              $twilcurrentnmbrs[] = "Tw: " . $twfvalue;
264
+                          }
265
+                     }
266
+                 }
267
+            }
268
+
269
+        } else { $twilcurrentnmbrs = []; }
270
+
271
+        // Get Flowroute phone numbers
272
+        if ($flowapikey != '' && $flowapisecret != '') {
273
+
274
+            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
275
+            $flnbrsarr = $flnbrsresult->data;
276
+            $flowcurrentnmbrs = [];
277
+            foreach ($flnbrsarr as $flkey => $flitem) {
278
+                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
279
+            }
280
+
281
+        } else { $flowcurrentnmbrs = []; }
282
+
283
+
284
+        $telsenderarr = [0 => $telsendername];
285
+        $nexsenderarr = [0 => $nexsendername];
286
+        $twilsenderarr = [0 => $twilsendername];
287
+        $flowsenderarr = [0 => $flowsendername];
288
+
289
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr, $flowsenderarr);
290
+
291
+        return $currentnmbrs;
292
+    }
293
+
294
+
295
+    /**
296
+     * @NoAdminRequired
297
+     */
298
+    public function cleantempdir($userId) {
299
+
300
+        // Create the temporary folder if it doesn't exist
301
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
302
+            $this->folder->newFolder('SMS_Relentless/temp_files');
303
+        }
304
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
305
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
306
+        $fileSystemIterator = new FilesystemIterator($targetdir);
307
+
308
+        $dirfiles = [];
309
+        foreach ($fileSystemIterator as $fileInfo){
310
+                 $dirfiles[] = $fileInfo->getFilename();
311
+        }
312
+
313
+        foreach ($dirfiles as $key => $indfile) {
314
+                 $thisuserroot = $this->view->getRoot();
315
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
316
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
317
+        }
318
+     }
319
+
320
+
321
+    /**
322
+     * @NoAdminRequired
323
+     */
324
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
325
+
326
+        // Create the temporary folder if it doesn't exist
327
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
328
+            $this->folder->newFolder('SMS_Relentless/temp_files');
329
+        }
330
+
331
+        // First delete any file that has been previously uploaded
332
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
333
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
334
+        $fileSystemIterator = new FilesystemIterator($targetdir);
335
+
336
+        $dirfiles = [];
337
+        foreach ($fileSystemIterator as $fileInfo){
338
+                 $dirfiles[] = $fileInfo->getFilename();
339
+        }
340
+
341
+        foreach ($dirfiles as $key => $indfile) {
342
+                 $thisuserroot = $this->view->getRoot();
343
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
344
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
345
+        }
346
+
347
+        // Upload the new file
348
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
349
+        $fileName = $_FILES['uploadfileforsms']['name'];
350
+
351
+        $userroot = $this->view->getRoot();
352
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
353
+
354
+        $target = $this->folder->newFile($targetfile);
355
+        $target->putContent($fileContent);
356
+
357
+        // Extract the phone numbers from the file
358
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
359
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
360
+        $numberarrayfourth = explode(",", $numberarraytert);
361
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
362
+        $numberarray = array_unique($numberarrayfifth);
363
+
364
+        return $numberarray;
365
+    }
366
+
367
+
368
+    /**
369
+     * @NoAdminRequired
370
+     */
371
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
372
+
373
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
374
+         $telnyxkey = $telsmsapicred[0];
375
+         $teldelrecurl = $telsmsapicred[3];
376
+         $messagingprofid = $telsmsapicred[4];
377
+
378
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
379
+
380
+         $microinterval = $waitinterval * 1000;
381
+
382
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
383
+
384
+             usleep($microinterval);
385
+
386
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
387
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
388
+             } else {
389
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
390
+             }
391
+
392
+             $messageid = $message['id'];
393
+             $messagedate = date("Y-m-d H:i:s");
394
+             $messagefrom = "Telnyx: " . $fromsender;
395
+             $messageto = $tonumber;
396
+             $messagenetwork = null;
397
+             $messageprice = null;
398
+             $messagestatus = $message['to'][0]['status'];
399
+             $messagedelivery = null;
400
+             $messagetext = $sentsmstext;
401
+
402
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
403
+
404
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
405
+
406
+         }
407
+    }
408
+
409
+
410
+    /**
411
+     * @NoAdminRequired
412
+     */
413
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
414
+
415
+         $smsapicred = $this->service->getapicredentials($this->userId);
416
+
417
+         $smsapikey = $smsapicred[5];
418
+         $smsapisecret = $smsapicred[6];
419
+         $smsapideliveryrecurl = $smsapicred[8];
420
+
421
+         $microinterval = $waitinterval * 1000;
422
+
423
+         $client = new RestClient($smsapikey, $smsapisecret);
424
+
425
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
426
+
427
+             usleep($microinterval);
428
+
429
+             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
430
+
431
+	     $messageidinit = $response->getmessageUuid(0);
432
+             $messageid = $messageidinit[0];
433
+
434
+             $messagedate = date("Y-m-d H:i:s");
435
+
436
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
437
+                 $messagefrom = "Plivo: " . $fromsender;
438
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
439
+
440
+             $messageto = $tonumber;
441
+             $messagenetwork = null;
442
+             $messageprice = null;
443
+             $messagestatus = "The message has been accepted for delivery.";
444
+             $messagedelivery = null;
445
+             $messagetext = $sentsmstext;
446
+
447
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
448
+
449
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
450
+         }
451
+    }
452
+
453
+
454
+    /**
455
+     * @NoAdminRequired
456
+     */
457
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
458
+
459
+         $smsapicred = $this->service->getapicredentials($this->userId);
460
+
461
+         $sid = $smsapicred[15];
462
+         $token = $smsapicred[16];
463
+         $smsapirecurltw = $smsapicred[18];
464
+
465
+         $microinterval = $waitinterval * 1000;
466
+
467
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
468
+
469
+             usleep($microinterval);
470
+
471
+	     $chtw = curl_init();
472
+	     curl_setopt($chtw, CURLOPT_URL, 'https://'.$sid.':'.$token.'@api.twilio.com/2010-04-01/Accounts/'.$sid.'/Messages.json');
473
+	     curl_setopt($chtw, CURLOPT_TIMEOUT, 300);
474
+	     curl_setopt($chtw, CURLOPT_RETURNTRANSFER, 1);
475
+	     curl_setopt($chtw, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
476
+	     curl_setopt($chtw, CURLOPT_POST, 1);
477
+	     curl_setopt($chtw, CURLOPT_POSTFIELDS, ["To" => $tonumbertw, "From" => $fromsender, "Body" => $sentsmstext, "StatusCallback" => $smsapirecurltw]);
478
+	     $resulttw = curl_exec ($chtw);
479
+	     $statusCodetw = curl_getinfo($chtw, CURLINFO_HTTP_CODE);
480
+	     curl_close ($chtw);
481
+
482
+             $decresulttw = json_decode($resulttw);
483
+             if (is_object($decresulttw)) {
484
+                 $messageidtw = $decresulttw->sid;
485
+             } else { $messageidtw = ''; }
486
+
487
+	     if (in_array($statusCodetw, [200, 201, 202, 203, 204, 205, 206])) { 
488
+                 $messagestatustw = 'The message has been accepted for delivery.'; 
489
+             } else { 
490
+                 $messagestatustw = 'An error occurred while trying to send the message.'; 
491
+             }
492
+
493
+             $messagedatetw = date("Y-m-d H:i:s");
494
+
495
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
496
+                 $messagefromtw = "Twilio: " . $fromsender;
497
+             } else { $messagefromtw = "Twilio: " . $fromsender; }
498
+
499
+             $messagenetworktw = '';
500
+             $messagepricetw = '';
501
+             $messagedeliverytw = '';
502
+
503
+             $sentmessagearr = [$messageidtw, $messagedatetw, $messagefromtw, $tonumbertw, $messagenetworktw, $messagepricetw, $messagestatustw, $messagedeliverytw, $sentsmstext];
504
+
505
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
506
+         }
507
+
508
+    }
509
+
510
+
511
+    /**
512
+     * @NoAdminRequired
513
+     */
514
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
515
+
516
+         $smsapicredfl = $this->service->getapicredentials($this->userId);
517
+
518
+         $flowapikey = $smsapicredfl[20];
519
+         $flowapisecret = $smsapicredfl[21];
520
+         $flowdelrecurl = $smsapicredfl[23];
521
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
522
+
523
+         $microinterval = $waitinterval * 1000;
524
+
525
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
526
+
527
+             usleep($microinterval);
528
+
529
+	     $chfl = curl_init();
530
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
531
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
532
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
533
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
534
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
535
+	     curl_setopt($chfl, CURLOPT_POST, 1);
536
+	     curl_setopt($chfl, CURLOPT_POSTFIELDS, '{"to": "'. $tonumberfl .'", "from": "'. $fromsender .'", "body": "'. $sentsmstextproc .'", "dlr_callback": "'. $flowdelrecurl .'"}');
537
+	     $resultfl = curl_exec ($chfl);
538
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
539
+	     curl_close ($chfl);
540
+
541
+             $decresultfl = json_decode($resultfl);
542
+             if (is_object($decresultfl)) {
543
+                 $messageidfl = $decresultfl->data->id;
544
+             } else { $messageidfl = ''; }
545
+
546
+	     if (in_array($statusCode, [200, 201, 202, 203, 204, 205, 206])) {
547
+                 $messagestatusfl = 'The message has been accepted for delivery.'; 
548
+             } else { 
549
+                 $messagestatusfl = 'An error occurred while trying to send the message.'; 
550
+             }
551
+
552
+             $messagedatefl = date("Y-m-d H:i:s");
553
+
554
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
555
+                 $messagefromfl = "Flowroute: " . $fromsender;
556
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
557
+
558
+             $messagetofl = $tonumberfl;
559
+             $messagenetworkfl = '';
560
+             $messagepricefl = '';
561
+             $messagedeliveryfl = '';
562
+             $messagetextfl = $sentsmstext;
563
+
564
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfl];
565
+
566
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
567
+         }
568
+
569
+    }
570
+
571
+
572
+    /**
573
+     * @NoAdminRequired
574
+     */
575
+    public function saveoldrecrows($userId, $oldrecRows) {
576
+
577
+           // Create the folder for removed messages if it doesn't exist
578
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
579
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
580
+           }
581
+           $savecheck = 0;
582
+
583
+           if (count($oldrecRows) > 1) {
584
+               $msfileContent = implode("", $oldrecRows);
585
+
586
+               $delrowsdate = date("Y-m-d_H-i-s");
587
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
588
+
589
+               $userroot = $this->view->getRoot();
590
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
591
+
592
+               $target = $this->folder->newFile($targetfile);
593
+               $target->putContent($msfileContent);
594
+
595
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
596
+                   $savecheck = 1;
597
+               }
598
+           }
599
+
600
+           return $savecheck;
601
+    }
602
+
603
+
604
+    /**
605
+     * @NoAdminRequired
606
+     */
607
+    public function saveoldsentrows($userId, $oldsentRows) {
608
+
609
+           // Create the folder for removed messages if it doesn't exist
610
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
611
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
612
+           }
613
+           $savesentcheck = 0;
614
+
615
+           if (count($oldsentRows) > 1) {
616
+               $sntfileContent = implode("", $oldsentRows);
617
+
618
+               $delsentrowsdate = date("Y-m-d_H-i-s");
619
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
620
+
621
+               $userroot = $this->view->getRoot();
622
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
623
+
624
+               $snttarget = $this->folder->newFile($snttargetfile);
625
+               $snttarget->putContent($sntfileContent);
626
+
627
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
628
+                   $savesentcheck = 1;
629
+               }
630
+           }
631
+
632
+           return $savesentcheck;
633
+    }
634
+
635
+
636
+    /**
637
+     * @NoAdminRequired
638
+     */
639
+    public function getreceivedtable($userId) {
640
+           return $this->service->getreceivedtable($this->userId);
641
+    }
642
+
643
+    /**
644
+     * @NoAdminRequired
645
+     */
646
+    public function getreceivedtablefordel($userId) {
647
+           return $this->service->getreceivedtablefordel($this->userId);
648
+    }
649
+
650
+    /**
651
+     * @NoAdminRequired
652
+     */
653
+    public function removerecrows($userId, $recmessagedbIDs) {
654
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
655
+    }
656
+
657
+    /**
658
+     * @NoAdminRequired
659
+     */
660
+    public function getsenttable($userId) {
661
+           return $this->service->getsenttable($this->userId);
662
+    }
663
+
664
+    /**
665
+     * @NoAdminRequired
666
+     */
667
+    public function getsenttablefordel($userId) {
668
+           return $this->service->getsenttablefordel($this->userId);
669
+    }
670
+
671
+    /**
672
+     * @NoAdminRequired
673
+     */
674
+    public function removesentrows($userId, $sentmessagedbIDs) {
675
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
676
+    }
677
+
678
+    /**
679
+     * @NoAdminRequired
680
+     */
681
+    public function getmessagesperpage($userId) {
682
+           return $this->service->getmessagesperpage($this->userId);
683
+    }
684
+
685
+    /**
686
+     * @NoAdminRequired
687
+     */
688
+    public function getdelrecsettings($userId) {
689
+           return $this->service->getdelrecsettings($this->userId);
690
+    }
691
+
692
+    /**
693
+     * @NoAdminRequired
694
+     */
695
+    public function getsettings($userId) {
696
+           return $this->service->getsettings($this->userId);
697
+    }
698
+
699
+    /**
700
+     * @NoAdminRequired
701
+     */
702
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName) {
703
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName);
704
+    }
705
+
706
+}
Browse code

removed README.md CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/settings.js lib/AppInfo/Application.php lib/Controller/SmsrelentlessController.php lib/Controller/AuthorApiController.php lib/Migration/Version108Date20220820204512.php providers/Twilio

DoubleBastionAdmin authored on 23/08/2022 10:40:23
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,683 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use OCP\AppFramework\Http\DataResponse;
44
-use OCP\Files\NotFoundException;
45
-use OCP\Files\NotPermittedException;
46
-use Plivo\RestClient;
47
-use Twilio\Rest\TwilioClient;
48
-
49
-
50
-class SmsrelentlessController extends Controller {
51
-
52
-    private $service;
53
-    private $config;
54
-    private $userId;
55
-    private $folder;
56
-    private $filesystem;
57
-    private $view;
58
-
59
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
60
-        parent::__construct($appName, $request);
61
-        $this->service = $service;
62
-        $this->config = $config;
63
-        $this->userId = $userId;
64
-        $this->folder = $folder;
65
-        $this->filesystem = $filesystem;
66
-        $this->view = $view;
67
-    }
68
-
69
-
70
-    /**
71
-     * @NoAdminRequired
72
-     */
73
-    public function object_to_array($obj) {
74
-        if(is_object($obj)) $obj = (array)$this->dismount($obj);
75
-        if(is_array($obj)) {
76
-           $new = array();
77
-           foreach($obj as $key => $val) {
78
-               $new[$key] = $this->object_to_array($val);
79
-           }
80
-        }
81
-        else $new = $obj;
82
-        return $new;
83
-    }
84
-
85
-
86
-    /**
87
-     * @NoAdminRequired
88
-     */
89
-    public function dismount($object) {
90
-        $reflectionClass = new ReflectionClass(get_class($object));
91
-        $array = array();
92
-        foreach ($reflectionClass->getProperties() as $property) {
93
-           $property->setAccessible(true);
94
-           $array[$property->getName()] = $property->getValue($object);
95
-           $property->setAccessible(false);
96
-        }
97
-        return $array;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function getbalancetel($userId) {
105
-
106
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
107
-
108
-        $telapikey = $telsmsapicred[0];
109
-        $ch = curl_init();
110
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
111
-
112
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
113
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
115
-        $responsetel = curl_exec($ch);
116
-        $recdatatel = json_decode($responsetel, TRUE);
117
-        $telbalresponse = $recdatatel['data']['balance'];
118
-        $currentbalancetel = round(floatval($telbalresponse), 3);
119
-        curl_close($ch);
120
-
121
-        return $currentbalancetel;
122
-    }
123
-
124
-
125
-    /**
126
-     * @NoAdminRequired
127
-     */
128
-    public function getbalancenex($userId) {
129
-
130
-        $smsapicred = $this->service->getapicredentials($this->userId);
131
-        $smsapikey = $smsapicred[5];
132
-        $smsapisecret = $smsapicred[6];
133
-
134
-        if ($smsapikey == '' || $smsapisecret == '') {
135
-            $currentbalancenex = "N/A";
136
-        } else {
137
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
138
-            $mesdata = file_get_contents($getmesdata);
139
-            $datainit = json_decode($mesdata);
140
-            $balancenex = $datainit->cash_credits;
141
-            $currentbalancenex = round(floatval($balancenex), 3);
142
-        }
143
-        return $currentbalancenex;
144
-    }
145
-
146
-
147
-    /**
148
-     * @NoAdminRequired
149
-     */
150
-    public function getbalancetwil($userId) {
151
-
152
-        $smsapicred = $this->service->getapicredentials($this->userId);
153
-        $smsapisid = $smsapicred[15];
154
-        $smsapitoken = $smsapicred[16];
155
-
156
-        if ($smsapisid == '' || $smsapitoken == '') {
157
-            $currentbalancetwil = "N/A";
158
-        } else {
159
-            $client = new TwilioClient($smsapisid, $smsapitoken);
160
-            $balancetwil = $client->balance->fetch()->balance;
161
-            $currentbalancetwil = round(floatval($balancetwil), 3);
162
-        }
163
-        return $currentbalancetwil;
164
-    }
165
-
166
-
167
-    /**
168
-     * @NoAdminRequired
169
-     */
170
-    public function getbalanceflow($userId) {
171
-
172
-        $currentbalanceflow = 'n/a';
173
-
174
-        return $currentbalanceflow;
175
-    }
176
-
177
-
178
-    /**
179
-     * @NoAdminRequired
180
-     */
181
-    public function getsmsnumbers($userId) {
182
-
183
-        $smsapicred = $this->service->getapicredentials($this->userId);
184
-
185
-        $telnyxkey = $smsapicred[0];
186
-
187
-        $nexapikey = $smsapicred[5];
188
-        $nexapisecret = $smsapicred[6];
189
-
190
-        $twilapikey = $smsapicred[15];
191
-        $twilapisecret = $smsapicred[16];
192
-
193
-        $flowapikey = $smsapicred[20];
194
-        $flowapisecret = $smsapicred[21];
195
-
196
-        $telsendernameinit = $smsapicred[9];
197
-        $nexsendernameinit = $smsapicred[10];
198
-        $twilsendernameinit = $smsapicred[19];
199
-        $flowsendernameinit = $smsapicred[24];
200
-
201
-        $telsendername = "Tx: " . $telsendernameinit;
202
-        $nexsendername = "Pl: " . $nexsendernameinit;
203
-        $twilsendername = "Tw: " . $twilsendernameinit;
204
-        $flowsendername = "Fl: " . $flowsendernameinit;
205
-
206
-        // Get Telnyx phone numbers
207
-        if ($telnyxkey != '') {
208
-
209
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
210
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
211
-
212
-           $telnumbersarr = $this->object_to_array($telnumbers);
213
-           $telnmbrs = [];
214
-
215
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
216
-              if (is_int($nmbkey)) {
217
-                 foreach ($nmbvalue as $nkey => $nvalue) {
218
-                    if ($nkey == 'phone_number') {
219
-                       $telnmbrs[] = "Tx: " . $nvalue;
220
-                    }
221
-                 }
222
-              }
223
-           }
224
-
225
-        } else { $telnmbrs = []; }
226
-
227
-        // Get Plivo phone numbers
228
-        if ($nexapikey != '' && $nexapisecret != '') {
229
-
230
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
231
-           $acdata = file_get_contents($getacdata);
232
-           $datainit = json_decode($acdata, true);
233
-
234
-           $findata = $this->object_to_array($datainit);
235
-
236
-           $nexcurrentnmbrs = [];
237
-
238
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
239
-                   if (is_array($smsvalue)) {
240
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
241
-                               if ($smskey2 == 'number') {
242
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
243
-                               }
244
-                         }
245
-                   }
246
-           }
247
-
248
-
249
-        } else { $nexcurrentnmbrs = []; }
250
-
251
-        // Get Twilio phone numbers
252
-        if ($twilapikey != '' && $twilapisecret != '') {
253
-
254
-            $clienttw = new TwilioClient($twilapikey, $twilapisecret);
255
-            $accdata = $clienttw->getAccount();
256
-            $activeNumbers = $accdata->incomingPhoneNumbers;
257
-            $activeNumbersArr = $activeNumbers->read();
258
-            $twilcurrentnmbrs = [];
259
-
260
-            foreach ($activeNumbersArr as $activeNmbr) {
261
-                     $twilcurrentnmbrs[] = "Tw: " . $activeNmbr->phoneNumber;
262
-            }
263
-
264
-        } else { $twilcurrentnmbrs = []; }
265
-
266
-        // Get Flowroute phone numbers
267
-        if ($flowapikey != '' && $flowapisecret != '') {
268
-
269
-            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
270
-            $flnbrsarr = $flnbrsresult->data;
271
-            $flowcurrentnmbrs = [];
272
-            foreach ($flnbrsarr as $flkey => $flitem) {
273
-                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
274
-            }
275
-
276
-        } else { $flowcurrentnmbrs = []; }
277
-
278
-
279
-        $telsenderarr = [0 => $telsendername];
280
-        $nexsenderarr = [0 => $nexsendername];
281
-        $twilsenderarr = [0 => $twilsendername];
282
-        $flowsenderarr = [0 => $flowsendername];
283
-
284
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr, $flowsenderarr);
285
-
286
-        return $currentnmbrs;
287
-    }
288
-
289
-
290
-    /**
291
-     * @NoAdminRequired
292
-     */
293
-    public function cleantempdir($userId) {
294
-
295
-        // Create the temporary folder if it doesn't exist
296
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
297
-            $this->folder->newFolder('SMS_Relentless/temp_files');
298
-        }
299
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
300
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
301
-        $fileSystemIterator = new FilesystemIterator($targetdir);
302
-
303
-        $dirfiles = [];
304
-        foreach ($fileSystemIterator as $fileInfo){
305
-                 $dirfiles[] = $fileInfo->getFilename();
306
-        }
307
-
308
-        foreach ($dirfiles as $key => $indfile) {
309
-                 $thisuserroot = $this->view->getRoot();
310
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
311
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
312
-        }
313
-     }
314
-
315
-
316
-    /**
317
-     * @NoAdminRequired
318
-     */
319
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
320
-
321
-        // Create the temporary folder if it doesn't exist
322
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
323
-            $this->folder->newFolder('SMS_Relentless/temp_files');
324
-        }
325
-
326
-        // First delete any file that has been previously uploaded
327
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
328
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
329
-        $fileSystemIterator = new FilesystemIterator($targetdir);
330
-
331
-        $dirfiles = [];
332
-        foreach ($fileSystemIterator as $fileInfo){
333
-                 $dirfiles[] = $fileInfo->getFilename();
334
-        }
335
-
336
-        foreach ($dirfiles as $key => $indfile) {
337
-                 $thisuserroot = $this->view->getRoot();
338
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
339
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
340
-        }
341
-
342
-        // Upload the new file
343
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
344
-        $fileName = $_FILES['uploadfileforsms']['name'];
345
-
346
-        $userroot = $this->view->getRoot();
347
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
348
-
349
-        $target = $this->folder->newFile($targetfile);
350
-        $target->putContent($fileContent);
351
-
352
-        // Extract the phone numbers from the file
353
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
354
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
355
-        $numberarrayfourth = explode(",", $numberarraytert);
356
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
357
-        $numberarray = array_unique($numberarrayfifth);
358
-
359
-        return $numberarray;
360
-    }
361
-
362
-
363
-    /**
364
-     * @NoAdminRequired
365
-     */
366
-//    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
367
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
368
-
369
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
370
-         $telnyxkey = $telsmsapicred[0];
371
-         $teldelrecurl = $telsmsapicred[3];
372
-         $messagingprofid = $telsmsapicred[4];
373
-
374
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
375
-
376
-         $microinterval = $waitinterval * 1000;
377
-
378
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
379
-
380
-             usleep($microinterval);
381
-
382
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
383
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
384
-             } else {
385
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
386
-             }
387
-
388
-             $messageid = $message['id'];
389
-             $messagedate = date("Y-m-d H:i:s");
390
-             $messagefrom = "Telnyx: " . $fromsender;
391
-             $messageto = $tonumber;
392
-             $messagenetwork = null;
393
-             $messageprice = null;
394
-             $messagestatus = $message['to'][0]['status'];
395
-             $messagedelivery = null;
396
-             $messagetext = $sentsmstext;
397
-
398
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
399
-
400
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
401
-
402
-         }
403
-    }
404
-
405
-
406
-    /**
407
-     * @NoAdminRequired
408
-     */
409
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
410
-
411
-         $smsapicred = $this->service->getapicredentials($this->userId);
412
-
413
-         $smsapikey = $smsapicred[5];
414
-         $smsapisecret = $smsapicred[6];
415
-         $smsapideliveryrecurl = $smsapicred[8];
416
-
417
-         $microinterval = $waitinterval * 1000;
418
-
419
-         $client = new RestClient($smsapikey, $smsapisecret);
420
-
421
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
422
-
423
-             usleep($microinterval);
424
-
425
-             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
426
-
427
-	     $messageidinit = $response->getmessageUuid(0);
428
-             $messageid = $messageidinit[0];
429
-
430
-             $messagedate = date("Y-m-d H:i:s");
431
-
432
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
433
-                 $messagefrom = "Plivo: " . $fromsender;
434
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
435
-
436
-             $messageto = $tonumber;
437
-             $messagenetwork = null;
438
-             $messageprice = null;
439
-             $messagestatus = "The message has been accepted for delivery.";
440
-             $messagedelivery = null;
441
-             $messagetext = $sentsmstext;
442
-
443
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
444
-
445
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
446
-         }
447
-    }
448
-
449
-
450
-    /**
451
-     * @NoAdminRequired
452
-     */
453
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
454
-
455
-
456
-         $smsapicred = $this->service->getapicredentials($this->userId);
457
-
458
-         $sid = $smsapicred[15];
459
-         $token = $smsapicred[16];
460
-         $smsapideliveryrecurl = $smsapicred[18];
461
-
462
-         $microinterval = $waitinterval * 1000;
463
-
464
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
465
-
466
-             usleep($microinterval);
467
-
468
-	     $client = new TwilioClient($sid, $token);
469
-
470
-	     $message = $client->messages->create($tonumbertw, ['from' => $fromsender, 'body' => $sentsmstext, 'statusCallback' => $smsapideliveryrecurl]);
471
-
472
-             $messagedate = date("Y-m-d H:i:s");
473
-
474
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
475
-                 $messagefrom = "Twilio: " . $fromsender;
476
-             } else { $messagefrom = "Twilio: " . $fromsender; }
477
-
478
-             $messageid = $message->sid;
479
-             $messageto = $tonumbertw;
480
-             $messagenetwork = '';
481
-             $messageprice = '';
482
-             $messagestatus = $message->status;
483
-             $messagedelivery = '';
484
-             $messagetext = $sentsmstext;
485
-
486
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
487
-
488
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
489
-         }
490
-
491
-    }
492
-
493
-
494
-    /**
495
-     * @NoAdminRequired
496
-     */
497
-    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
498
-
499
-         $smsapicredfl = $this->service->getapicredentials($this->userId);
500
-
501
-         $flowapikey = $smsapicredfl[20];
502
-         $flowapisecret = $smsapicredfl[21];
503
-         $flowdelrecurl = $smsapicredfl[23];
504
-         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
505
-
506
-         $microinterval = $waitinterval * 1000;
507
-
508
-         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
509
-
510
-             usleep($microinterval);
511
-
512
-	     $chfl = curl_init();
513
-	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
514
-	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
515
-	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
516
-	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
517
-	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
518
-	     curl_setopt($chfl, CURLOPT_POST, 1);
519
-	     curl_setopt($chfl, CURLOPT_POSTFIELDS, '{"to": "'. $tonumberfl .'", "from": "'. $fromsender .'", "body": "'. $sentsmstextproc .'", "dlr_callback": "'. $flowdelrecurl .'"}');
520
-	     $resultfl = curl_exec ($chfl);
521
-	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
522
-	     curl_close ($chfl);
523
-
524
-             $decresultfl = json_decode($resultfl);
525
-             $messageidfl = $decresultfl->data->id;
526
-
527
-	     if ($statusCode == 202) { $messagestatusfl = 'The message has been accepted for delivery.'; } else { $messagestatusfl = 'An error occurred while trying to send the message.'; }
528
-
529
-             $messagedatefl = date("Y-m-d H:i:s");
530
-
531
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
532
-                 $messagefromfl = "Flowroute: " . $fromsender;
533
-             } else { $messagefromfl = "Flowroute: " . $fromsender; }
534
-
535
-             $messagetofl = $tonumberfl;
536
-             $messagenetworkfl = '';
537
-             $messagepricefl = '';
538
-             $messagedeliveryfl = '';
539
-             $messagetextfl = $sentsmstext;
540
-
541
-             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfl];
542
-
543
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
544
-         }
545
-
546
-    }
547
-
548
-
549
-    /**
550
-     * @NoAdminRequired
551
-     */
552
-    public function saveoldrecrows($userId, $oldrecRows) {
553
-
554
-           // Create the folder for removed messages if it doesn't exist
555
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
556
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
557
-           }
558
-           $savecheck = 0;
559
-
560
-           if (count($oldrecRows) > 1) {
561
-               $msfileContent = implode("", $oldrecRows);
562
-
563
-               $delrowsdate = date("Y-m-d_H-i-s");
564
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
565
-
566
-               $userroot = $this->view->getRoot();
567
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
568
-
569
-               $target = $this->folder->newFile($targetfile);
570
-               $target->putContent($msfileContent);
571
-
572
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
573
-                   $savecheck = 1;
574
-               }
575
-           }
576
-
577
-           return $savecheck;
578
-    }
579
-
580
-
581
-    /**
582
-     * @NoAdminRequired
583
-     */
584
-    public function saveoldsentrows($userId, $oldsentRows) {
585
-
586
-           // Create the folder for removed messages if it doesn't exist
587
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
588
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
589
-           }
590
-           $savesentcheck = 0;
591
-
592
-           if (count($oldsentRows) > 1) {
593
-               $sntfileContent = implode("", $oldsentRows);
594
-
595
-               $delsentrowsdate = date("Y-m-d_H-i-s");
596
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
597
-
598
-               $userroot = $this->view->getRoot();
599
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
600
-
601
-               $snttarget = $this->folder->newFile($snttargetfile);
602
-               $snttarget->putContent($sntfileContent);
603
-
604
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
605
-                   $savesentcheck = 1;
606
-               }
607
-           }
608
-
609
-           return $savesentcheck;
610
-    }
611
-
612
-
613
-    /**
614
-     * @NoAdminRequired
615
-     */
616
-    public function getreceivedtable($userId) {
617
-           return $this->service->getreceivedtable($this->userId);
618
-    }
619
-
620
-    /**
621
-     * @NoAdminRequired
622
-     */
623
-    public function getreceivedtablefordel($userId) {
624
-           return $this->service->getreceivedtablefordel($this->userId);
625
-    }
626
-
627
-    /**
628
-     * @NoAdminRequired
629
-     */
630
-    public function removerecrows($userId, $recmessagedbIDs) {
631
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
632
-    }
633
-
634
-    /**
635
-     * @NoAdminRequired
636
-     */
637
-    public function getsenttable($userId) {
638
-           return $this->service->getsenttable($this->userId);
639
-    }
640
-
641
-    /**
642
-     * @NoAdminRequired
643
-     */
644
-    public function getsenttablefordel($userId) {
645
-           return $this->service->getsenttablefordel($this->userId);
646
-    }
647
-
648
-    /**
649
-     * @NoAdminRequired
650
-     */
651
-    public function removesentrows($userId, $sentmessagedbIDs) {
652
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
653
-    }
654
-
655
-    /**
656
-     * @NoAdminRequired
657
-     */
658
-    public function getmessagesperpage($userId) {
659
-           return $this->service->getmessagesperpage($this->userId);
660
-    }
661
-
662
-    /**
663
-     * @NoAdminRequired
664
-     */
665
-    public function getdelrecsettings($userId) {
666
-           return $this->service->getdelrecsettings($this->userId);
667
-    }
668
-
669
-    /**
670
-     * @NoAdminRequired
671
-     */
672
-    public function getsettings($userId) {
673
-           return $this->service->getsettings($this->userId);
674
-    }
675
-
676
-    /**
677
-     * @NoAdminRequired
678
-     */
679
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName) {
680
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName);
681
-    }
682
-
683
-}
Browse code

added CHANGELOG.txt README.md appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/sendsms.js js/settings.js lib/AppInfo/Application.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/navigation/index.php templates/settings.php lib/Migration/Version108Date20220818235106.php

DoubleBastionAdmin authored on 18/08/2022 21:30:17
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,683 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use OCP\AppFramework\Http\DataResponse;
44
+use OCP\Files\NotFoundException;
45
+use OCP\Files\NotPermittedException;
46
+use Plivo\RestClient;
47
+use Twilio\Rest\TwilioClient;
48
+
49
+
50
+class SmsrelentlessController extends Controller {
51
+
52
+    private $service;
53
+    private $config;
54
+    private $userId;
55
+    private $folder;
56
+    private $filesystem;
57
+    private $view;
58
+
59
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
60
+        parent::__construct($appName, $request);
61
+        $this->service = $service;
62
+        $this->config = $config;
63
+        $this->userId = $userId;
64
+        $this->folder = $folder;
65
+        $this->filesystem = $filesystem;
66
+        $this->view = $view;
67
+    }
68
+
69
+
70
+    /**
71
+     * @NoAdminRequired
72
+     */
73
+    public function object_to_array($obj) {
74
+        if(is_object($obj)) $obj = (array)$this->dismount($obj);
75
+        if(is_array($obj)) {
76
+           $new = array();
77
+           foreach($obj as $key => $val) {
78
+               $new[$key] = $this->object_to_array($val);
79
+           }
80
+        }
81
+        else $new = $obj;
82
+        return $new;
83
+    }
84
+
85
+
86
+    /**
87
+     * @NoAdminRequired
88
+     */
89
+    public function dismount($object) {
90
+        $reflectionClass = new ReflectionClass(get_class($object));
91
+        $array = array();
92
+        foreach ($reflectionClass->getProperties() as $property) {
93
+           $property->setAccessible(true);
94
+           $array[$property->getName()] = $property->getValue($object);
95
+           $property->setAccessible(false);
96
+        }
97
+        return $array;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function getbalancetel($userId) {
105
+
106
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
107
+
108
+        $telapikey = $telsmsapicred[0];
109
+        $ch = curl_init();
110
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
111
+
112
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
113
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
115
+        $responsetel = curl_exec($ch);
116
+        $recdatatel = json_decode($responsetel, TRUE);
117
+        $telbalresponse = $recdatatel['data']['balance'];
118
+        $currentbalancetel = round(floatval($telbalresponse), 3);
119
+        curl_close($ch);
120
+
121
+        return $currentbalancetel;
122
+    }
123
+
124
+
125
+    /**
126
+     * @NoAdminRequired
127
+     */
128
+    public function getbalancenex($userId) {
129
+
130
+        $smsapicred = $this->service->getapicredentials($this->userId);
131
+        $smsapikey = $smsapicred[5];
132
+        $smsapisecret = $smsapicred[6];
133
+
134
+        if ($smsapikey == '' || $smsapisecret == '') {
135
+            $currentbalancenex = "N/A";
136
+        } else {
137
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
138
+            $mesdata = file_get_contents($getmesdata);
139
+            $datainit = json_decode($mesdata);
140
+            $balancenex = $datainit->cash_credits;
141
+            $currentbalancenex = round(floatval($balancenex), 3);
142
+        }
143
+        return $currentbalancenex;
144
+    }
145
+
146
+
147
+    /**
148
+     * @NoAdminRequired
149
+     */
150
+    public function getbalancetwil($userId) {
151
+
152
+        $smsapicred = $this->service->getapicredentials($this->userId);
153
+        $smsapisid = $smsapicred[15];
154
+        $smsapitoken = $smsapicred[16];
155
+
156
+        if ($smsapisid == '' || $smsapitoken == '') {
157
+            $currentbalancetwil = "N/A";
158
+        } else {
159
+            $client = new TwilioClient($smsapisid, $smsapitoken);
160
+            $balancetwil = $client->balance->fetch()->balance;
161
+            $currentbalancetwil = round(floatval($balancetwil), 3);
162
+        }
163
+        return $currentbalancetwil;
164
+    }
165
+
166
+
167
+    /**
168
+     * @NoAdminRequired
169
+     */
170
+    public function getbalanceflow($userId) {
171
+
172
+        $currentbalanceflow = 'n/a';
173
+
174
+        return $currentbalanceflow;
175
+    }
176
+
177
+
178
+    /**
179
+     * @NoAdminRequired
180
+     */
181
+    public function getsmsnumbers($userId) {
182
+
183
+        $smsapicred = $this->service->getapicredentials($this->userId);
184
+
185
+        $telnyxkey = $smsapicred[0];
186
+
187
+        $nexapikey = $smsapicred[5];
188
+        $nexapisecret = $smsapicred[6];
189
+
190
+        $twilapikey = $smsapicred[15];
191
+        $twilapisecret = $smsapicred[16];
192
+
193
+        $flowapikey = $smsapicred[20];
194
+        $flowapisecret = $smsapicred[21];
195
+
196
+        $telsendernameinit = $smsapicred[9];
197
+        $nexsendernameinit = $smsapicred[10];
198
+        $twilsendernameinit = $smsapicred[19];
199
+        $flowsendernameinit = $smsapicred[24];
200
+
201
+        $telsendername = "Tx: " . $telsendernameinit;
202
+        $nexsendername = "Pl: " . $nexsendernameinit;
203
+        $twilsendername = "Tw: " . $twilsendernameinit;
204
+        $flowsendername = "Fl: " . $flowsendernameinit;
205
+
206
+        // Get Telnyx phone numbers
207
+        if ($telnyxkey != '') {
208
+
209
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
210
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
211
+
212
+           $telnumbersarr = $this->object_to_array($telnumbers);
213
+           $telnmbrs = [];
214
+
215
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
216
+              if (is_int($nmbkey)) {
217
+                 foreach ($nmbvalue as $nkey => $nvalue) {
218
+                    if ($nkey == 'phone_number') {
219
+                       $telnmbrs[] = "Tx: " . $nvalue;
220
+                    }
221
+                 }
222
+              }
223
+           }
224
+
225
+        } else { $telnmbrs = []; }
226
+
227
+        // Get Plivo phone numbers
228
+        if ($nexapikey != '' && $nexapisecret != '') {
229
+
230
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
231
+           $acdata = file_get_contents($getacdata);
232
+           $datainit = json_decode($acdata, true);
233
+
234
+           $findata = $this->object_to_array($datainit);
235
+
236
+           $nexcurrentnmbrs = [];
237
+
238
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
239
+                   if (is_array($smsvalue)) {
240
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
241
+                               if ($smskey2 == 'number') {
242
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
243
+                               }
244
+                         }
245
+                   }
246
+           }
247
+
248
+
249
+        } else { $nexcurrentnmbrs = []; }
250
+
251
+        // Get Twilio phone numbers
252
+        if ($twilapikey != '' && $twilapisecret != '') {
253
+
254
+            $clienttw = new TwilioClient($twilapikey, $twilapisecret);
255
+            $accdata = $clienttw->getAccount();
256
+            $activeNumbers = $accdata->incomingPhoneNumbers;
257
+            $activeNumbersArr = $activeNumbers->read();
258
+            $twilcurrentnmbrs = [];
259
+
260
+            foreach ($activeNumbersArr as $activeNmbr) {
261
+                     $twilcurrentnmbrs[] = "Tw: " . $activeNmbr->phoneNumber;
262
+            }
263
+
264
+        } else { $twilcurrentnmbrs = []; }
265
+
266
+        // Get Flowroute phone numbers
267
+        if ($flowapikey != '' && $flowapisecret != '') {
268
+
269
+            $flnbrsresult = json_decode(file_get_contents("https://".$flowapikey.":".$flowapisecret."@api.flowroute.com/v2/numbers"));
270
+            $flnbrsarr = $flnbrsresult->data;
271
+            $flowcurrentnmbrs = [];
272
+            foreach ($flnbrsarr as $flkey => $flitem) {
273
+                     $flowcurrentnmbrs[] = "Fl: +" . $flitem->id;
274
+            }
275
+
276
+        } else { $flowcurrentnmbrs = []; }
277
+
278
+
279
+        $telsenderarr = [0 => $telsendername];
280
+        $nexsenderarr = [0 => $nexsendername];
281
+        $twilsenderarr = [0 => $twilsendername];
282
+        $flowsenderarr = [0 => $flowsendername];
283
+
284
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $flowcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr, $flowsenderarr);
285
+
286
+        return $currentnmbrs;
287
+    }
288
+
289
+
290
+    /**
291
+     * @NoAdminRequired
292
+     */
293
+    public function cleantempdir($userId) {
294
+
295
+        // Create the temporary folder if it doesn't exist
296
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
297
+            $this->folder->newFolder('SMS_Relentless/temp_files');
298
+        }
299
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
300
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
301
+        $fileSystemIterator = new FilesystemIterator($targetdir);
302
+
303
+        $dirfiles = [];
304
+        foreach ($fileSystemIterator as $fileInfo){
305
+                 $dirfiles[] = $fileInfo->getFilename();
306
+        }
307
+
308
+        foreach ($dirfiles as $key => $indfile) {
309
+                 $thisuserroot = $this->view->getRoot();
310
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
311
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
312
+        }
313
+     }
314
+
315
+
316
+    /**
317
+     * @NoAdminRequired
318
+     */
319
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
320
+
321
+        // Create the temporary folder if it doesn't exist
322
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
323
+            $this->folder->newFolder('SMS_Relentless/temp_files');
324
+        }
325
+
326
+        // First delete any file that has been previously uploaded
327
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
328
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
329
+        $fileSystemIterator = new FilesystemIterator($targetdir);
330
+
331
+        $dirfiles = [];
332
+        foreach ($fileSystemIterator as $fileInfo){
333
+                 $dirfiles[] = $fileInfo->getFilename();
334
+        }
335
+
336
+        foreach ($dirfiles as $key => $indfile) {
337
+                 $thisuserroot = $this->view->getRoot();
338
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
339
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
340
+        }
341
+
342
+        // Upload the new file
343
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
344
+        $fileName = $_FILES['uploadfileforsms']['name'];
345
+
346
+        $userroot = $this->view->getRoot();
347
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
348
+
349
+        $target = $this->folder->newFile($targetfile);
350
+        $target->putContent($fileContent);
351
+
352
+        // Extract the phone numbers from the file
353
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
354
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
355
+        $numberarrayfourth = explode(",", $numberarraytert);
356
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
357
+        $numberarray = array_unique($numberarrayfifth);
358
+
359
+        return $numberarray;
360
+    }
361
+
362
+
363
+    /**
364
+     * @NoAdminRequired
365
+     */
366
+//    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
367
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
368
+
369
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
370
+         $telnyxkey = $telsmsapicred[0];
371
+         $teldelrecurl = $telsmsapicred[3];
372
+         $messagingprofid = $telsmsapicred[4];
373
+
374
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
375
+
376
+         $microinterval = $waitinterval * 1000;
377
+
378
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
379
+
380
+             usleep($microinterval);
381
+
382
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
383
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "messaging_profile_id" => $messagingprofid]);
384
+             } else {
385
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl]);
386
+             }
387
+
388
+             $messageid = $message['id'];
389
+             $messagedate = date("Y-m-d H:i:s");
390
+             $messagefrom = "Telnyx: " . $fromsender;
391
+             $messageto = $tonumber;
392
+             $messagenetwork = null;
393
+             $messageprice = null;
394
+             $messagestatus = $message['to'][0]['status'];
395
+             $messagedelivery = null;
396
+             $messagetext = $sentsmstext;
397
+
398
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
399
+
400
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
401
+
402
+         }
403
+    }
404
+
405
+
406
+    /**
407
+     * @NoAdminRequired
408
+     */
409
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
410
+
411
+         $smsapicred = $this->service->getapicredentials($this->userId);
412
+
413
+         $smsapikey = $smsapicred[5];
414
+         $smsapisecret = $smsapicred[6];
415
+         $smsapideliveryrecurl = $smsapicred[8];
416
+
417
+         $microinterval = $waitinterval * 1000;
418
+
419
+         $client = new RestClient($smsapikey, $smsapisecret);
420
+
421
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
422
+
423
+             usleep($microinterval);
424
+
425
+             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
426
+
427
+	     $messageidinit = $response->getmessageUuid(0);
428
+             $messageid = $messageidinit[0];
429
+
430
+             $messagedate = date("Y-m-d H:i:s");
431
+
432
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
433
+                 $messagefrom = "Plivo: " . $fromsender;
434
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
435
+
436
+             $messageto = $tonumber;
437
+             $messagenetwork = null;
438
+             $messageprice = null;
439
+             $messagestatus = "The message has been accepted for delivery.";
440
+             $messagedelivery = null;
441
+             $messagetext = $sentsmstext;
442
+
443
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
444
+
445
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
446
+         }
447
+    }
448
+
449
+
450
+    /**
451
+     * @NoAdminRequired
452
+     */
453
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
454
+
455
+
456
+         $smsapicred = $this->service->getapicredentials($this->userId);
457
+
458
+         $sid = $smsapicred[15];
459
+         $token = $smsapicred[16];
460
+         $smsapideliveryrecurl = $smsapicred[18];
461
+
462
+         $microinterval = $waitinterval * 1000;
463
+
464
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
465
+
466
+             usleep($microinterval);
467
+
468
+	     $client = new TwilioClient($sid, $token);
469
+
470
+	     $message = $client->messages->create($tonumbertw, ['from' => $fromsender, 'body' => $sentsmstext, 'statusCallback' => $smsapideliveryrecurl]);
471
+
472
+             $messagedate = date("Y-m-d H:i:s");
473
+
474
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
475
+                 $messagefrom = "Twilio: " . $fromsender;
476
+             } else { $messagefrom = "Twilio: " . $fromsender; }
477
+
478
+             $messageid = $message->sid;
479
+             $messageto = $tonumbertw;
480
+             $messagenetwork = '';
481
+             $messageprice = '';
482
+             $messagestatus = $message->status;
483
+             $messagedelivery = '';
484
+             $messagetext = $sentsmstext;
485
+
486
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
487
+
488
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
489
+         }
490
+
491
+    }
492
+
493
+
494
+    /**
495
+     * @NoAdminRequired
496
+     */
497
+    public function sendsmsflow($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $sentsmstext) {
498
+
499
+         $smsapicredfl = $this->service->getapicredentials($this->userId);
500
+
501
+         $flowapikey = $smsapicredfl[20];
502
+         $flowapisecret = $smsapicredfl[21];
503
+         $flowdelrecurl = $smsapicredfl[23];
504
+         $sentsmstextproc = str_replace('"','\\"', $sentsmstext);
505
+
506
+         $microinterval = $waitinterval * 1000;
507
+
508
+         foreach ($receiversPhoneNbs as $keyflow => $tonumberfl) {
509
+
510
+             usleep($microinterval);
511
+
512
+	     $chfl = curl_init();
513
+	     curl_setopt($chfl, CURLOPT_URL, 'https://'.$flowapikey.':'.$flowapisecret.'@api.flowroute.com/v2.1/messages');
514
+	     curl_setopt($chfl, CURLOPT_HTTPHEADER, array("Content-Type: application/vnd.api+json"));
515
+	     curl_setopt($chfl, CURLOPT_TIMEOUT, 300);
516
+	     curl_setopt($chfl, CURLOPT_RETURNTRANSFER, 1);
517
+	     curl_setopt($chfl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
518
+	     curl_setopt($chfl, CURLOPT_POST, 1);
519
+	     curl_setopt($chfl, CURLOPT_POSTFIELDS, '{"to": "'. $tonumberfl .'", "from": "'. $fromsender .'", "body": "'. $sentsmstextproc .'", "dlr_callback": "'. $flowdelrecurl .'"}');
520
+	     $resultfl = curl_exec ($chfl);
521
+	     $statusCode = curl_getinfo($chfl, CURLINFO_HTTP_CODE);
522
+	     curl_close ($chfl);
523
+
524
+             $decresultfl = json_decode($resultfl);
525
+             $messageidfl = $decresultfl->data->id;
526
+
527
+	     if ($statusCode == 202) { $messagestatusfl = 'The message has been accepted for delivery.'; } else { $messagestatusfl = 'An error occurred while trying to send the message.'; }
528
+
529
+             $messagedatefl = date("Y-m-d H:i:s");
530
+
531
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
532
+                 $messagefromfl = "Flowroute: " . $fromsender;
533
+             } else { $messagefromfl = "Flowroute: " . $fromsender; }
534
+
535
+             $messagetofl = $tonumberfl;
536
+             $messagenetworkfl = '';
537
+             $messagepricefl = '';
538
+             $messagedeliveryfl = '';
539
+             $messagetextfl = $sentsmstext;
540
+
541
+             $sentmessagearr = [$messageidfl, $messagedatefl, $messagefromfl, $messagetofl, $messagenetworkfl, $messagepricefl, $messagestatusfl, $messagedeliveryfl, $messagetextfl];
542
+
543
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
544
+         }
545
+
546
+    }
547
+
548
+
549
+    /**
550
+     * @NoAdminRequired
551
+     */
552
+    public function saveoldrecrows($userId, $oldrecRows) {
553
+
554
+           // Create the folder for removed messages if it doesn't exist
555
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
556
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
557
+           }
558
+           $savecheck = 0;
559
+
560
+           if (count($oldrecRows) > 1) {
561
+               $msfileContent = implode("", $oldrecRows);
562
+
563
+               $delrowsdate = date("Y-m-d_H-i-s");
564
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
565
+
566
+               $userroot = $this->view->getRoot();
567
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
568
+
569
+               $target = $this->folder->newFile($targetfile);
570
+               $target->putContent($msfileContent);
571
+
572
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
573
+                   $savecheck = 1;
574
+               }
575
+           }
576
+
577
+           return $savecheck;
578
+    }
579
+
580
+
581
+    /**
582
+     * @NoAdminRequired
583
+     */
584
+    public function saveoldsentrows($userId, $oldsentRows) {
585
+
586
+           // Create the folder for removed messages if it doesn't exist
587
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
588
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
589
+           }
590
+           $savesentcheck = 0;
591
+
592
+           if (count($oldsentRows) > 1) {
593
+               $sntfileContent = implode("", $oldsentRows);
594
+
595
+               $delsentrowsdate = date("Y-m-d_H-i-s");
596
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
597
+
598
+               $userroot = $this->view->getRoot();
599
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
600
+
601
+               $snttarget = $this->folder->newFile($snttargetfile);
602
+               $snttarget->putContent($sntfileContent);
603
+
604
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
605
+                   $savesentcheck = 1;
606
+               }
607
+           }
608
+
609
+           return $savesentcheck;
610
+    }
611
+
612
+
613
+    /**
614
+     * @NoAdminRequired
615
+     */
616
+    public function getreceivedtable($userId) {
617
+           return $this->service->getreceivedtable($this->userId);
618
+    }
619
+
620
+    /**
621
+     * @NoAdminRequired
622
+     */
623
+    public function getreceivedtablefordel($userId) {
624
+           return $this->service->getreceivedtablefordel($this->userId);
625
+    }
626
+
627
+    /**
628
+     * @NoAdminRequired
629
+     */
630
+    public function removerecrows($userId, $recmessagedbIDs) {
631
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
632
+    }
633
+
634
+    /**
635
+     * @NoAdminRequired
636
+     */
637
+    public function getsenttable($userId) {
638
+           return $this->service->getsenttable($this->userId);
639
+    }
640
+
641
+    /**
642
+     * @NoAdminRequired
643
+     */
644
+    public function getsenttablefordel($userId) {
645
+           return $this->service->getsenttablefordel($this->userId);
646
+    }
647
+
648
+    /**
649
+     * @NoAdminRequired
650
+     */
651
+    public function removesentrows($userId, $sentmessagedbIDs) {
652
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
653
+    }
654
+
655
+    /**
656
+     * @NoAdminRequired
657
+     */
658
+    public function getmessagesperpage($userId) {
659
+           return $this->service->getmessagesperpage($this->userId);
660
+    }
661
+
662
+    /**
663
+     * @NoAdminRequired
664
+     */
665
+    public function getdelrecsettings($userId) {
666
+           return $this->service->getdelrecsettings($this->userId);
667
+    }
668
+
669
+    /**
670
+     * @NoAdminRequired
671
+     */
672
+    public function getsettings($userId) {
673
+           return $this->service->getsettings($this->userId);
674
+    }
675
+
676
+    /**
677
+     * @NoAdminRequired
678
+     */
679
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName) {
680
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName, $flowapiKey, $flowapiSecret, $flowapiUrlRec, $flowapiUrl, $flowSenderName);
681
+    }
682
+
683
+}
Browse code

deleted CHANGELOG.txt README.md appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/sendsms.js js/settings.js lib/AppInfo/Application.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/navigation/index.php templates/settings.php

DoubleBastionAdmin authored on 18/08/2022 21:08:00
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,599 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use OCP\AppFramework\Http\DataResponse;
44
-use OCP\Files\NotFoundException;
45
-use OCP\Files\NotPermittedException;
46
-use Plivo\RestClient;
47
-use Twilio\Rest\TwilioClient;
48
-
49
-
50
-class SmsrelentlessController extends Controller {
51
-
52
-    private $service;
53
-    private $config;
54
-    private $userId;
55
-    private $folder;
56
-    private $filesystem;
57
-    private $view;
58
-
59
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
60
-        parent::__construct($appName, $request);
61
-        $this->service = $service;
62
-        $this->config = $config;
63
-        $this->userId = $userId;
64
-        $this->folder = $folder;
65
-        $this->filesystem = $filesystem;
66
-        $this->view = $view;
67
-    }
68
-
69
-
70
-    /**
71
-     * @NoAdminRequired
72
-     */
73
-    public function object_to_array($obj) {
74
-        if(is_object($obj)) $obj = (array)$this->dismount($obj);
75
-        if(is_array($obj)) {
76
-           $new = array();
77
-           foreach($obj as $key => $val) {
78
-               $new[$key] = $this->object_to_array($val);
79
-           }
80
-        }
81
-        else $new = $obj;
82
-        return $new;
83
-    }
84
-
85
-
86
-    /**
87
-     * @NoAdminRequired
88
-     */
89
-    public function dismount($object) {
90
-        $reflectionClass = new ReflectionClass(get_class($object));
91
-        $array = array();
92
-        foreach ($reflectionClass->getProperties() as $property) {
93
-           $property->setAccessible(true);
94
-           $array[$property->getName()] = $property->getValue($object);
95
-           $property->setAccessible(false);
96
-        }
97
-        return $array;
98
-    }
99
-
100
-
101
-    /**
102
-     * @NoAdminRequired
103
-     */
104
-    public function getbalancetel($userId) {
105
-
106
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
107
-
108
-        $telapikey = $telsmsapicred[0];
109
-        $ch = curl_init();
110
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
111
-
112
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
113
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
115
-        $responsetel = curl_exec($ch);
116
-        $recdatatel = json_decode($responsetel, TRUE);
117
-        $telbalresponse = $recdatatel['data']['balance'];
118
-        $currentbalancetel = round(floatval($telbalresponse), 3);
119
-        curl_close($ch);
120
-
121
-        return $currentbalancetel;
122
-    }
123
-
124
-
125
-    /**
126
-     * @NoAdminRequired
127
-     */
128
-    public function getbalancenex($userId) {
129
-
130
-        $smsapicred = $this->service->getapicredentials($this->userId);
131
-        $smsapikey = $smsapicred[5];
132
-        $smsapisecret = $smsapicred[6];
133
-
134
-        if ($smsapikey == '' || $smsapisecret == '') {
135
-            $currentbalancenex = "N/A";
136
-        } else {
137
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
138
-            $mesdata = file_get_contents($getmesdata);
139
-            $datainit = json_decode($mesdata);
140
-            $balancenex = $datainit->cash_credits;
141
-            $currentbalancenex = round(floatval($balancenex), 3);
142
-        }
143
-        return $currentbalancenex;
144
-    }
145
-
146
-
147
-    /**
148
-     * @NoAdminRequired
149
-     */
150
-    public function getbalancetwil($userId) {
151
-
152
-        $smsapicred = $this->service->getapicredentials($this->userId);
153
-        $smsapisid = $smsapicred[15];
154
-        $smsapitoken = $smsapicred[16];
155
-
156
-        if ($smsapisid == '' || $smsapitoken == '') {
157
-            $currentbalancetwil = "N/A";
158
-        } else {
159
-            $client = new TwilioClient($smsapisid, $smsapitoken);
160
-            $balancetwil = $client->balance->fetch()->balance;
161
-            // $currencytwil = $client->balance->fetch()->currency;
162
-            $currentbalancetwil = round(floatval($balancetwil), 3);
163
-        }
164
-        return $currentbalancetwil;
165
-    }
166
-
167
-
168
-    /**
169
-     * @NoAdminRequired
170
-     */
171
-    public function getsmsnumbers($userId) {
172
-
173
-        $smsapicred = $this->service->getapicredentials($this->userId);
174
-
175
-        $telnyxkey = $smsapicred[0];
176
-
177
-        $nexapikey = $smsapicred[5];
178
-        $nexapisecret = $smsapicred[6];
179
-
180
-        $twilapikey = $smsapicred[15];
181
-        $twilapisecret = $smsapicred[16];
182
-
183
-        $telsendernameinit = $smsapicred[9];
184
-        $nexsendernameinit = $smsapicred[10];
185
-        $twilsendernameinit = $smsapicred[19];
186
-
187
-        $telsendername = "Tx: " . $telsendernameinit;
188
-        $nexsendername = "Pl: " . $nexsendernameinit;
189
-        $twilsendername = "Tw: " . $twilsendernameinit;
190
-
191
-        // Get Telnyx phone numbers
192
-        if ($telnyxkey != '') {
193
-
194
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
195
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
196
-
197
-           $telnumbersarr = $this->object_to_array($telnumbers);
198
-           $telnmbrs = [];
199
-
200
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
201
-              if (is_int($nmbkey)) {
202
-                 foreach ($nmbvalue as $nkey => $nvalue) {
203
-                    if ($nkey == 'phone_number') {
204
-                       $telnmbrs[] = "Tx: " . $nvalue;
205
-                    }
206
-                 }
207
-              }
208
-           }
209
-
210
-        } else { $telnmbrs = []; }
211
-
212
-        // Get Plivo phone numbers
213
-        if ($nexapikey != '' && $nexapisecret != '') {
214
-
215
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
216
-           $acdata = file_get_contents($getacdata);
217
-           $datainit = json_decode($acdata, true);
218
-
219
-           $findata = $this->object_to_array($datainit);
220
-
221
-           $nexcurrentnmbrs = [];
222
-
223
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
224
-                   if (is_array($smsvalue)) {
225
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
226
-                               if ($smskey2 == 'number') {
227
-                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
228
-                               }
229
-                         }
230
-                   }
231
-           }
232
-
233
-
234
-        } else { $nexcurrentnmbrs = []; }
235
-
236
-        // Get Twilio phone numbers
237
-        if ($twilapikey != '' && $twilapisecret != '') {
238
-
239
-            $clienttw = new TwilioClient($twilapikey, $twilapisecret);
240
-            $accdata = $clienttw->getAccount();
241
-            $activeNumbers = $accdata->incomingPhoneNumbers;
242
-            $activeNumbersArr = $activeNumbers->read();
243
-            $twilcurrentnmbrs = [];
244
-
245
-            foreach ($activeNumbersArr as $activeNmbr) {
246
-                     $twilcurrentnmbrs[] = "Tw: " . $activeNmbr->phoneNumber;
247
-            }
248
-
249
-        } else { $twilcurrentnmbrs = []; }
250
-
251
-
252
-        $telsenderarr = [0 => $telsendername];
253
-        $nexsenderarr = [0 => $nexsendername];
254
-        $twilsenderarr = [0 => $twilsendername];
255
-
256
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
257
-
258
-        return $currentnmbrs;
259
-    }
260
-
261
-
262
-    /**
263
-     * @NoAdminRequired
264
-     */
265
-    public function cleantempdir($userId) {
266
-
267
-        // Create the temporary folder if it doesn't exist
268
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
269
-            $this->folder->newFolder('SMS_Relentless/temp_files');
270
-        }
271
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
272
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
273
-        $fileSystemIterator = new FilesystemIterator($targetdir);
274
-
275
-        $dirfiles = [];
276
-        foreach ($fileSystemIterator as $fileInfo){
277
-                 $dirfiles[] = $fileInfo->getFilename();
278
-        }
279
-
280
-        foreach ($dirfiles as $key => $indfile) {
281
-                 $thisuserroot = $this->view->getRoot();
282
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
283
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
284
-        }
285
-     }
286
-
287
-
288
-    /**
289
-     * @NoAdminRequired
290
-     */
291
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
292
-
293
-        // Create the temporary folder if it doesn't exist
294
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
295
-            $this->folder->newFolder('SMS_Relentless/temp_files');
296
-        }
297
-
298
-        // First delete any file that has been previously uploaded
299
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
300
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
301
-        $fileSystemIterator = new FilesystemIterator($targetdir);
302
-
303
-        $dirfiles = [];
304
-        foreach ($fileSystemIterator as $fileInfo){
305
-                 $dirfiles[] = $fileInfo->getFilename();
306
-        }
307
-
308
-        foreach ($dirfiles as $key => $indfile) {
309
-                 $thisuserroot = $this->view->getRoot();
310
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
311
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
312
-        }
313
-
314
-        // Upload the new file
315
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
316
-        $fileName = $_FILES['uploadfileforsms']['name'];
317
-
318
-        $userroot = $this->view->getRoot();
319
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
320
-
321
-        $target = $this->folder->newFile($targetfile);
322
-        $target->putContent($fileContent);
323
-
324
-        // Extract the phone numbers from the file
325
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
326
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
327
-        $numberarrayfourth = explode(",", $numberarraytert);
328
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
329
-        $numberarray = array_unique($numberarrayfifth);
330
-
331
-        return $numberarray;
332
-    }
333
-
334
-
335
-    /**
336
-     * @NoAdminRequired
337
-     */
338
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
339
-
340
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
341
-         $telnyxkey = $telsmsapicred[0];
342
-         $teldelrecurl = $telsmsapicred[3];
343
-         $messagingprofid = $telsmsapicred[4];
344
-
345
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
346
-
347
-         $microinterval = $waitinterval * 1000;
348
-
349
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
350
-
351
-             usleep($microinterval);
352
-
353
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
354
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding, "messaging_profile_id" => $messagingprofid]);
355
-             } else {
356
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding]);
357
-             }
358
-
359
-             $messageid = $message['id'];
360
-             $messagedate = date("Y-m-d H:i:s");
361
-             $messagefrom = "Telnyx: " . $fromsender;
362
-             $messageto = $tonumber;
363
-             $messagenetwork = null;
364
-             $messageprice = null;
365
-             $messagestatus = $message['to'][0]['status'];
366
-             $messagedelivery = null;
367
-             $messagetext = $sentsmstext;
368
-
369
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
370
-
371
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
372
-
373
-         }
374
-    }
375
-
376
-
377
-    /**
378
-     * @NoAdminRequired
379
-     */
380
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
381
-
382
-         $smsapicred = $this->service->getapicredentials($this->userId);
383
-
384
-         $smsapikey = $smsapicred[5];
385
-         $smsapisecret = $smsapicred[6];
386
-         $smsapideliveryrecurl = $smsapicred[8];
387
-
388
-         $microinterval = $waitinterval * 1000;
389
-
390
-         $client = new RestClient($smsapikey, $smsapisecret);
391
-
392
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
393
-
394
-             usleep($microinterval);
395
-
396
-             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
397
-
398
-	     $messageidinit = $response->getmessageUuid(0);
399
-             $messageid = $messageidinit[0];
400
-
401
-             $messagedate = date("Y-m-d H:i:s");
402
-
403
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
404
-                 $messagefrom = "Plivo: " . $fromsender;
405
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
406
-
407
-             $messageto = $tonumber;
408
-             $messagenetwork = null;
409
-             $messageprice = null;
410
-             $messagestatus = "The message has been accepted for delivery.";
411
-             $messagedelivery = null;
412
-             $messagetext = $sentsmstext;
413
-
414
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
415
-
416
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
417
-         }
418
-    }
419
-
420
-
421
-    /**
422
-     * @NoAdminRequired
423
-     */
424
-    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
425
-
426
-
427
-         $smsapicred = $this->service->getapicredentials($this->userId);
428
-
429
-         $sid = $smsapicred[15];
430
-         $token = $smsapicred[16];
431
-         $smsapideliveryrecurl = $smsapicred[18];
432
-
433
-         $microinterval = $waitinterval * 1000;
434
-
435
-         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
436
-
437
-             usleep($microinterval);
438
-
439
-	     $client = new TwilioClient($sid, $token);
440
-
441
-	     $message = $client->messages->create($tonumbertw, ['from' => $fromsender, 'body' => $sentsmstext, 'statusCallback' => $smsapideliveryrecurl]);
442
-
443
-             $messagedate = date("Y-m-d H:i:s");
444
-
445
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
446
-                 $messagefrom = "Twilio: " . $fromsender;
447
-             } else { $messagefrom = "Twilio: " . $fromsender; }
448
-
449
-             $messageid = $message->sid;
450
-             $messageto = $tonumbertw;
451
-             $messagenetwork = '';
452
-             $messageprice = '';
453
-             $messagestatus = $message->status;
454
-             $messagedelivery = '';
455
-             $messagetext = $sentsmstext;
456
-
457
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
458
-
459
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
460
-         }
461
-
462
-    }
463
-
464
-
465
-    /**
466
-     * @NoAdminRequired
467
-     */
468
-    public function saveoldrecrows($userId, $oldrecRows) {
469
-
470
-           // Create the folder for removed messages if it doesn't exist
471
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
472
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
473
-           }
474
-           $savecheck = 0;
475
-
476
-           if (count($oldrecRows) > 1) {
477
-               $msfileContent = implode("", $oldrecRows);
478
-
479
-               $delrowsdate = date("Y-m-d_H-i-s");
480
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
481
-
482
-               $userroot = $this->view->getRoot();
483
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
484
-
485
-               $target = $this->folder->newFile($targetfile);
486
-               $target->putContent($msfileContent);
487
-
488
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
489
-                   $savecheck = 1;
490
-               }
491
-           }
492
-
493
-           return $savecheck;
494
-    }
495
-
496
-
497
-    /**
498
-     * @NoAdminRequired
499
-     */
500
-    public function saveoldsentrows($userId, $oldsentRows) {
501
-
502
-           // Create the folder for removed messages if it doesn't exist
503
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
504
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
505
-           }
506
-           $savesentcheck = 0;
507
-
508
-           if (count($oldsentRows) > 1) {
509
-               $sntfileContent = implode("", $oldsentRows);
510
-
511
-               $delsentrowsdate = date("Y-m-d_H-i-s");
512
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
513
-
514
-               $userroot = $this->view->getRoot();
515
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
516
-
517
-               $snttarget = $this->folder->newFile($snttargetfile);
518
-               $snttarget->putContent($sntfileContent);
519
-
520
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
521
-                   $savesentcheck = 1;
522
-               }
523
-           }
524
-
525
-           return $savesentcheck;
526
-    }
527
-
528
-
529
-    /**
530
-     * @NoAdminRequired
531
-     */
532
-    public function getreceivedtable($userId) {
533
-           return $this->service->getreceivedtable($this->userId);
534
-    }
535
-
536
-    /**
537
-     * @NoAdminRequired
538
-     */
539
-    public function getreceivedtablefordel($userId) {
540
-           return $this->service->getreceivedtablefordel($this->userId);
541
-    }
542
-
543
-    /**
544
-     * @NoAdminRequired
545
-     */
546
-    public function removerecrows($userId, $recmessagedbIDs) {
547
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
548
-    }
549
-
550
-    /**
551
-     * @NoAdminRequired
552
-     */
553
-    public function getsenttable($userId) {
554
-           return $this->service->getsenttable($this->userId);
555
-    }
556
-
557
-    /**
558
-     * @NoAdminRequired
559
-     */
560
-    public function getsenttablefordel($userId) {
561
-           return $this->service->getsenttablefordel($this->userId);
562
-    }
563
-
564
-    /**
565
-     * @NoAdminRequired
566
-     */
567
-    public function removesentrows($userId, $sentmessagedbIDs) {
568
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
569
-    }
570
-
571
-    /**
572
-     * @NoAdminRequired
573
-     */
574
-    public function getmessagesperpage($userId) {
575
-           return $this->service->getmessagesperpage($this->userId);
576
-    }
577
-
578
-    /**
579
-     * @NoAdminRequired
580
-     */
581
-    public function getdelrecsettings($userId) {
582
-           return $this->service->getdelrecsettings($this->userId);
583
-    }
584
-
585
-    /**
586
-     * @NoAdminRequired
587
-     */
588
-    public function getsettings($userId) {
589
-           return $this->service->getsettings($this->userId);
590
-    }
591
-
592
-    /**
593
-     * @NoAdminRequired
594
-     */
595
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName) {
596
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName);
597
-    }
598
-
599
-}
Browse code

added CHANGELOG.txt README.md appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/sendsms.js js/settings.js lib/AppInfo/Application.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php img/sms_relentless_screenshot.png lib/Migration/Version106Date20220813144231.php

DoubleBastionAdmin authored on 13/08/2022 12:43:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,599 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use OCP\AppFramework\Http\DataResponse;
44
+use OCP\Files\NotFoundException;
45
+use OCP\Files\NotPermittedException;
46
+use Plivo\RestClient;
47
+use Twilio\Rest\TwilioClient;
48
+
49
+
50
+class SmsrelentlessController extends Controller {
51
+
52
+    private $service;
53
+    private $config;
54
+    private $userId;
55
+    private $folder;
56
+    private $filesystem;
57
+    private $view;
58
+
59
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
60
+        parent::__construct($appName, $request);
61
+        $this->service = $service;
62
+        $this->config = $config;
63
+        $this->userId = $userId;
64
+        $this->folder = $folder;
65
+        $this->filesystem = $filesystem;
66
+        $this->view = $view;
67
+    }
68
+
69
+
70
+    /**
71
+     * @NoAdminRequired
72
+     */
73
+    public function object_to_array($obj) {
74
+        if(is_object($obj)) $obj = (array)$this->dismount($obj);
75
+        if(is_array($obj)) {
76
+           $new = array();
77
+           foreach($obj as $key => $val) {
78
+               $new[$key] = $this->object_to_array($val);
79
+           }
80
+        }
81
+        else $new = $obj;
82
+        return $new;
83
+    }
84
+
85
+
86
+    /**
87
+     * @NoAdminRequired
88
+     */
89
+    public function dismount($object) {
90
+        $reflectionClass = new ReflectionClass(get_class($object));
91
+        $array = array();
92
+        foreach ($reflectionClass->getProperties() as $property) {
93
+           $property->setAccessible(true);
94
+           $array[$property->getName()] = $property->getValue($object);
95
+           $property->setAccessible(false);
96
+        }
97
+        return $array;
98
+    }
99
+
100
+
101
+    /**
102
+     * @NoAdminRequired
103
+     */
104
+    public function getbalancetel($userId) {
105
+
106
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
107
+
108
+        $telapikey = $telsmsapicred[0];
109
+        $ch = curl_init();
110
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
111
+
112
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
113
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
115
+        $responsetel = curl_exec($ch);
116
+        $recdatatel = json_decode($responsetel, TRUE);
117
+        $telbalresponse = $recdatatel['data']['balance'];
118
+        $currentbalancetel = round(floatval($telbalresponse), 3);
119
+        curl_close($ch);
120
+
121
+        return $currentbalancetel;
122
+    }
123
+
124
+
125
+    /**
126
+     * @NoAdminRequired
127
+     */
128
+    public function getbalancenex($userId) {
129
+
130
+        $smsapicred = $this->service->getapicredentials($this->userId);
131
+        $smsapikey = $smsapicred[5];
132
+        $smsapisecret = $smsapicred[6];
133
+
134
+        if ($smsapikey == '' || $smsapisecret == '') {
135
+            $currentbalancenex = "N/A";
136
+        } else {
137
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
138
+            $mesdata = file_get_contents($getmesdata);
139
+            $datainit = json_decode($mesdata);
140
+            $balancenex = $datainit->cash_credits;
141
+            $currentbalancenex = round(floatval($balancenex), 3);
142
+        }
143
+        return $currentbalancenex;
144
+    }
145
+
146
+
147
+    /**
148
+     * @NoAdminRequired
149
+     */
150
+    public function getbalancetwil($userId) {
151
+
152
+        $smsapicred = $this->service->getapicredentials($this->userId);
153
+        $smsapisid = $smsapicred[15];
154
+        $smsapitoken = $smsapicred[16];
155
+
156
+        if ($smsapisid == '' || $smsapitoken == '') {
157
+            $currentbalancetwil = "N/A";
158
+        } else {
159
+            $client = new TwilioClient($smsapisid, $smsapitoken);
160
+            $balancetwil = $client->balance->fetch()->balance;
161
+            // $currencytwil = $client->balance->fetch()->currency;
162
+            $currentbalancetwil = round(floatval($balancetwil), 3);
163
+        }
164
+        return $currentbalancetwil;
165
+    }
166
+
167
+
168
+    /**
169
+     * @NoAdminRequired
170
+     */
171
+    public function getsmsnumbers($userId) {
172
+
173
+        $smsapicred = $this->service->getapicredentials($this->userId);
174
+
175
+        $telnyxkey = $smsapicred[0];
176
+
177
+        $nexapikey = $smsapicred[5];
178
+        $nexapisecret = $smsapicred[6];
179
+
180
+        $twilapikey = $smsapicred[15];
181
+        $twilapisecret = $smsapicred[16];
182
+
183
+        $telsendernameinit = $smsapicred[9];
184
+        $nexsendernameinit = $smsapicred[10];
185
+        $twilsendernameinit = $smsapicred[19];
186
+
187
+        $telsendername = "Tx: " . $telsendernameinit;
188
+        $nexsendername = "Pl: " . $nexsendernameinit;
189
+        $twilsendername = "Tw: " . $twilsendernameinit;
190
+
191
+        // Get Telnyx phone numbers
192
+        if ($telnyxkey != '') {
193
+
194
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
195
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
196
+
197
+           $telnumbersarr = $this->object_to_array($telnumbers);
198
+           $telnmbrs = [];
199
+
200
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
201
+              if (is_int($nmbkey)) {
202
+                 foreach ($nmbvalue as $nkey => $nvalue) {
203
+                    if ($nkey == 'phone_number') {
204
+                       $telnmbrs[] = "Tx: " . $nvalue;
205
+                    }
206
+                 }
207
+              }
208
+           }
209
+
210
+        } else { $telnmbrs = []; }
211
+
212
+        // Get Plivo phone numbers
213
+        if ($nexapikey != '' && $nexapisecret != '') {
214
+
215
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
216
+           $acdata = file_get_contents($getacdata);
217
+           $datainit = json_decode($acdata, true);
218
+
219
+           $findata = $this->object_to_array($datainit);
220
+
221
+           $nexcurrentnmbrs = [];
222
+
223
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
224
+                   if (is_array($smsvalue)) {
225
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
226
+                               if ($smskey2 == 'number') {
227
+                                   $nexcurrentnmbrs[] = "Pl: +" . $smsvalue2;
228
+                               }
229
+                         }
230
+                   }
231
+           }
232
+
233
+
234
+        } else { $nexcurrentnmbrs = []; }
235
+
236
+        // Get Twilio phone numbers
237
+        if ($twilapikey != '' && $twilapisecret != '') {
238
+
239
+            $clienttw = new TwilioClient($twilapikey, $twilapisecret);
240
+            $accdata = $clienttw->getAccount();
241
+            $activeNumbers = $accdata->incomingPhoneNumbers;
242
+            $activeNumbersArr = $activeNumbers->read();
243
+            $twilcurrentnmbrs = [];
244
+
245
+            foreach ($activeNumbersArr as $activeNmbr) {
246
+                     $twilcurrentnmbrs[] = "Tw: " . $activeNmbr->phoneNumber;
247
+            }
248
+
249
+        } else { $twilcurrentnmbrs = []; }
250
+
251
+
252
+        $telsenderarr = [0 => $telsendername];
253
+        $nexsenderarr = [0 => $nexsendername];
254
+        $twilsenderarr = [0 => $twilsendername];
255
+
256
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $twilcurrentnmbrs, $telsenderarr, $nexsenderarr, $twilsenderarr);
257
+
258
+        return $currentnmbrs;
259
+    }
260
+
261
+
262
+    /**
263
+     * @NoAdminRequired
264
+     */
265
+    public function cleantempdir($userId) {
266
+
267
+        // Create the temporary folder if it doesn't exist
268
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
269
+            $this->folder->newFolder('SMS_Relentless/temp_files');
270
+        }
271
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
272
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
273
+        $fileSystemIterator = new FilesystemIterator($targetdir);
274
+
275
+        $dirfiles = [];
276
+        foreach ($fileSystemIterator as $fileInfo){
277
+                 $dirfiles[] = $fileInfo->getFilename();
278
+        }
279
+
280
+        foreach ($dirfiles as $key => $indfile) {
281
+                 $thisuserroot = $this->view->getRoot();
282
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
283
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
284
+        }
285
+     }
286
+
287
+
288
+    /**
289
+     * @NoAdminRequired
290
+     */
291
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
292
+
293
+        // Create the temporary folder if it doesn't exist
294
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
295
+            $this->folder->newFolder('SMS_Relentless/temp_files');
296
+        }
297
+
298
+        // First delete any file that has been previously uploaded
299
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
300
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
301
+        $fileSystemIterator = new FilesystemIterator($targetdir);
302
+
303
+        $dirfiles = [];
304
+        foreach ($fileSystemIterator as $fileInfo){
305
+                 $dirfiles[] = $fileInfo->getFilename();
306
+        }
307
+
308
+        foreach ($dirfiles as $key => $indfile) {
309
+                 $thisuserroot = $this->view->getRoot();
310
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
311
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
312
+        }
313
+
314
+        // Upload the new file
315
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
316
+        $fileName = $_FILES['uploadfileforsms']['name'];
317
+
318
+        $userroot = $this->view->getRoot();
319
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
320
+
321
+        $target = $this->folder->newFile($targetfile);
322
+        $target->putContent($fileContent);
323
+
324
+        // Extract the phone numbers from the file
325
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
326
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
327
+        $numberarrayfourth = explode(",", $numberarraytert);
328
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
329
+        $numberarray = array_unique($numberarrayfifth);
330
+
331
+        return $numberarray;
332
+    }
333
+
334
+
335
+    /**
336
+     * @NoAdminRequired
337
+     */
338
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
339
+
340
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
341
+         $telnyxkey = $telsmsapicred[0];
342
+         $teldelrecurl = $telsmsapicred[3];
343
+         $messagingprofid = $telsmsapicred[4];
344
+
345
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
346
+
347
+         $microinterval = $waitinterval * 1000;
348
+
349
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
350
+
351
+             usleep($microinterval);
352
+
353
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
354
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding, "messaging_profile_id" => $messagingprofid]);
355
+             } else {
356
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding]);
357
+             }
358
+
359
+             $messageid = $message['id'];
360
+             $messagedate = date("Y-m-d H:i:s");
361
+             $messagefrom = "Telnyx: " . $fromsender;
362
+             $messageto = $tonumber;
363
+             $messagenetwork = null;
364
+             $messageprice = null;
365
+             $messagestatus = $message['to'][0]['status'];
366
+             $messagedelivery = null;
367
+             $messagetext = $sentsmstext;
368
+
369
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
370
+
371
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
372
+
373
+         }
374
+    }
375
+
376
+
377
+    /**
378
+     * @NoAdminRequired
379
+     */
380
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
381
+
382
+         $smsapicred = $this->service->getapicredentials($this->userId);
383
+
384
+         $smsapikey = $smsapicred[5];
385
+         $smsapisecret = $smsapicred[6];
386
+         $smsapideliveryrecurl = $smsapicred[8];
387
+
388
+         $microinterval = $waitinterval * 1000;
389
+
390
+         $client = new RestClient($smsapikey, $smsapisecret);
391
+
392
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
393
+
394
+             usleep($microinterval);
395
+
396
+             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
397
+
398
+	     $messageidinit = $response->getmessageUuid(0);
399
+             $messageid = $messageidinit[0];
400
+
401
+             $messagedate = date("Y-m-d H:i:s");
402
+
403
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
404
+                 $messagefrom = "Plivo: " . $fromsender;
405
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
406
+
407
+             $messageto = $tonumber;
408
+             $messagenetwork = null;
409
+             $messageprice = null;
410
+             $messagestatus = "The message has been accepted for delivery.";
411
+             $messagedelivery = null;
412
+             $messagetext = $sentsmstext;
413
+
414
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
415
+
416
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
417
+         }
418
+    }
419
+
420
+
421
+    /**
422
+     * @NoAdminRequired
423
+     */
424
+    public function sendsmstwil($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
425
+
426
+
427
+         $smsapicred = $this->service->getapicredentials($this->userId);
428
+
429
+         $sid = $smsapicred[15];
430
+         $token = $smsapicred[16];
431
+         $smsapideliveryrecurl = $smsapicred[18];
432
+
433
+         $microinterval = $waitinterval * 1000;
434
+
435
+         foreach ($receiversPhoneNbs as $keytwil => $tonumbertw) {
436
+
437
+             usleep($microinterval);
438
+
439
+	     $client = new TwilioClient($sid, $token);
440
+
441
+	     $message = $client->messages->create($tonumbertw, ['from' => $fromsender, 'body' => $sentsmstext, 'statusCallback' => $smsapideliveryrecurl]);
442
+
443
+             $messagedate = date("Y-m-d H:i:s");
444
+
445
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
446
+                 $messagefrom = "Twilio: " . $fromsender;
447
+             } else { $messagefrom = "Twilio: " . $fromsender; }
448
+
449
+             $messageid = $message->sid;
450
+             $messageto = $tonumbertw;
451
+             $messagenetwork = '';
452
+             $messageprice = '';
453
+             $messagestatus = $message->status;
454
+             $messagedelivery = '';
455
+             $messagetext = $sentsmstext;
456
+
457
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
458
+
459
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
460
+         }
461
+
462
+    }
463
+
464
+
465
+    /**
466
+     * @NoAdminRequired
467
+     */
468
+    public function saveoldrecrows($userId, $oldrecRows) {
469
+
470
+           // Create the folder for removed messages if it doesn't exist
471
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
472
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
473
+           }
474
+           $savecheck = 0;
475
+
476
+           if (count($oldrecRows) > 1) {
477
+               $msfileContent = implode("", $oldrecRows);
478
+
479
+               $delrowsdate = date("Y-m-d_H-i-s");
480
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
481
+
482
+               $userroot = $this->view->getRoot();
483
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
484
+
485
+               $target = $this->folder->newFile($targetfile);
486
+               $target->putContent($msfileContent);
487
+
488
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
489
+                   $savecheck = 1;
490
+               }
491
+           }
492
+
493
+           return $savecheck;
494
+    }
495
+
496
+
497
+    /**
498
+     * @NoAdminRequired
499
+     */
500
+    public function saveoldsentrows($userId, $oldsentRows) {
501
+
502
+           // Create the folder for removed messages if it doesn't exist
503
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
504
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
505
+           }
506
+           $savesentcheck = 0;
507
+
508
+           if (count($oldsentRows) > 1) {
509
+               $sntfileContent = implode("", $oldsentRows);
510
+
511
+               $delsentrowsdate = date("Y-m-d_H-i-s");
512
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
513
+
514
+               $userroot = $this->view->getRoot();
515
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
516
+
517
+               $snttarget = $this->folder->newFile($snttargetfile);
518
+               $snttarget->putContent($sntfileContent);
519
+
520
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
521
+                   $savesentcheck = 1;
522
+               }
523
+           }
524
+
525
+           return $savesentcheck;
526
+    }
527
+
528
+
529
+    /**
530
+     * @NoAdminRequired
531
+     */
532
+    public function getreceivedtable($userId) {
533
+           return $this->service->getreceivedtable($this->userId);
534
+    }
535
+
536
+    /**
537
+     * @NoAdminRequired
538
+     */
539
+    public function getreceivedtablefordel($userId) {
540
+           return $this->service->getreceivedtablefordel($this->userId);
541
+    }
542
+
543
+    /**
544
+     * @NoAdminRequired
545
+     */
546
+    public function removerecrows($userId, $recmessagedbIDs) {
547
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
548
+    }
549
+
550
+    /**
551
+     * @NoAdminRequired
552
+     */
553
+    public function getsenttable($userId) {
554
+           return $this->service->getsenttable($this->userId);
555
+    }
556
+
557
+    /**
558
+     * @NoAdminRequired
559
+     */
560
+    public function getsenttablefordel($userId) {
561
+           return $this->service->getsenttablefordel($this->userId);
562
+    }
563
+
564
+    /**
565
+     * @NoAdminRequired
566
+     */
567
+    public function removesentrows($userId, $sentmessagedbIDs) {
568
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
569
+    }
570
+
571
+    /**
572
+     * @NoAdminRequired
573
+     */
574
+    public function getmessagesperpage($userId) {
575
+           return $this->service->getmessagesperpage($this->userId);
576
+    }
577
+
578
+    /**
579
+     * @NoAdminRequired
580
+     */
581
+    public function getdelrecsettings($userId) {
582
+           return $this->service->getdelrecsettings($this->userId);
583
+    }
584
+
585
+    /**
586
+     * @NoAdminRequired
587
+     */
588
+    public function getsettings($userId) {
589
+           return $this->service->getsettings($this->userId);
590
+    }
591
+
592
+    /**
593
+     * @NoAdminRequired
594
+     */
595
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName) {
596
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail, $twilapiKey, $twilapiSecret, $twilapiUrlRec, $twilapiUrl, $twilSenderName);
597
+    }
598
+
599
+}
Browse code

removed CHANGELOG.txt README.md appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css lib/js/sendsms.js lib/js/settings.js lib/AppInfo/Application.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php img/sms_relentless_screenshot.png

DoubleBastionAdmin authored on 13/08/2022 12:33:36
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,507 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use OCP\AppFramework\Http\DataResponse;
44
-use OCP\Files\NotFoundException;
45
-use OCP\Files\NotPermittedException;
46
-use Plivo\RestClient;
47
-
48
-
49
-class SmsrelentlessController extends Controller {
50
-
51
-    private $service;
52
-    private $config;
53
-    private $userId;
54
-    private $folder;
55
-    private $filesystem;
56
-    private $view;
57
-
58
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
59
-        parent::__construct($appName, $request);
60
-        $this->service = $service;
61
-        $this->config = $config;
62
-        $this->userId = $userId;
63
-        $this->folder = $folder;
64
-        $this->filesystem = $filesystem;
65
-        $this->view = $view;
66
-    }
67
-
68
-
69
-    /**
70
-     * @NoAdminRequired
71
-     */
72
-    public function object_to_array($obj) {
73
-        if(is_object($obj)) $obj = (array)$this->dismount($obj);
74
-        if(is_array($obj)) {
75
-           $new = array();
76
-           foreach($obj as $key => $val) {
77
-               $new[$key] = $this->object_to_array($val);
78
-           }
79
-        }
80
-        else $new = $obj;
81
-        return $new;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function dismount($object) {
89
-        $reflectionClass = new ReflectionClass(get_class($object));
90
-        $array = array();
91
-        foreach ($reflectionClass->getProperties() as $property) {
92
-           $property->setAccessible(true);
93
-           $array[$property->getName()] = $property->getValue($object);
94
-           $property->setAccessible(false);
95
-        }
96
-        return $array;
97
-    }
98
-
99
-
100
-    /**
101
-     * @NoAdminRequired
102
-     */
103
-    public function getbalancetel($userId) {
104
-
105
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
106
-
107
-        $telapikey = $telsmsapicred[0];
108
-        $ch = curl_init();
109
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
110
-
111
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
112
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
113
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
114
-        $responsetel = curl_exec($ch);
115
-        $recdatatel = json_decode($responsetel, TRUE);
116
-        $telbalresponse = $recdatatel['data']['balance'];
117
-        $currentbalancetel = round(floatval($telbalresponse), 3);
118
-        curl_close($ch);
119
-
120
-        return $currentbalancetel;
121
-    }
122
-
123
-
124
-    /**
125
-     * @NoAdminRequired
126
-     */
127
-    public function getbalancenex($userId) {
128
-
129
-        $smsapicred = $this->service->getapicredentials($this->userId);
130
-        $smsapikey = $smsapicred[5];
131
-        $smsapisecret = $smsapicred[6];
132
-
133
-        if ($smsapikey == '' || $smsapisecret == '') {
134
-            $currentbalancenex = "N/A";
135
-        } else {
136
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
137
-            $mesdata = file_get_contents($getmesdata);
138
-            $datainit = json_decode($mesdata);
139
-            $balancenex = $datainit->cash_credits;
140
-            $currentbalancenex = round(floatval($balancenex), 3);
141
-        }
142
-        return $currentbalancenex;
143
-    }
144
-
145
-
146
-    /**
147
-     * @NoAdminRequired
148
-     */
149
-    public function getsmsnumbers($userId) {
150
-
151
-        $smsapicred = $this->service->getapicredentials($this->userId);
152
-
153
-        $telnyxkey = $smsapicred[0];
154
-
155
-        $nexapikey = $smsapicred[5];
156
-        $nexapisecret = $smsapicred[6];
157
-
158
-        $telsendernameinit = $smsapicred[9];
159
-        $nexsendernameinit = $smsapicred[10];
160
-        $telsendername = "T: " . $telsendernameinit;
161
-        $nexsendername = "P: " . $nexsendernameinit;
162
-
163
-        if ($telnyxkey != '') {
164
-
165
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
166
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
167
-
168
-           $telnumbersarr = $this->object_to_array($telnumbers);
169
-           $telnmbrs = [];
170
-
171
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
172
-              if (is_int($nmbkey)) {
173
-                 foreach ($nmbvalue as $nkey => $nvalue) {
174
-                    if ($nkey == 'phone_number') {
175
-                       $telnmbrs[] = "T: " . $nvalue;
176
-                    }
177
-                 }
178
-              }
179
-           }
180
-
181
-        } else { $telnmbrs = []; }
182
-
183
-        if ($nexapikey != '' && $nexapisecret != '') {
184
-
185
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
186
-           $acdata = file_get_contents($getacdata);
187
-           $datainit = json_decode($acdata, true);
188
-
189
-           $findata = $this->object_to_array($datainit);
190
-
191
-           $nexcurrentnmbrs = [];
192
-
193
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
194
-                   if (is_array($smsvalue)) {
195
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
196
-                               if ($smskey2 == 'number') {
197
-                                   $nexcurrentnmbrs[] = "P: +" . $smsvalue2;
198
-                               }
199
-                         }
200
-                   }
201
-           }
202
-
203
-
204
-        } else { $nexcurrentnmbrs = []; }
205
-
206
-        $telsenderarr = [0 => $telsendername];
207
-        $nexsenderarr = [0 => $nexsendername];
208
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $telsenderarr, $nexsenderarr);
209
-
210
-        return $currentnmbrs;
211
-    }
212
-
213
-
214
-    /**
215
-     * @NoAdminRequired
216
-     */
217
-    public function cleantempdir($userId) {
218
-
219
-        // Create the temporary folder if it doesn't exist
220
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
221
-            $this->folder->newFolder('SMS_Relentless/temp_files');
222
-        }
223
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
224
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
225
-        $fileSystemIterator = new FilesystemIterator($targetdir);
226
-
227
-        $dirfiles = [];
228
-        foreach ($fileSystemIterator as $fileInfo){
229
-                 $dirfiles[] = $fileInfo->getFilename();
230
-        }
231
-
232
-        foreach ($dirfiles as $key => $indfile) {
233
-                 $thisuserroot = $this->view->getRoot();
234
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
235
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
236
-        }
237
-     }
238
-
239
-
240
-    /**
241
-     * @NoAdminRequired
242
-     */
243
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
244
-
245
-        // Create the temporary folder if it doesn't exist
246
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
247
-            $this->folder->newFolder('SMS_Relentless/temp_files');
248
-        }
249
-
250
-        // First delete any file that has been previously uploaded
251
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
252
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
253
-        $fileSystemIterator = new FilesystemIterator($targetdir);
254
-
255
-        $dirfiles = [];
256
-        foreach ($fileSystemIterator as $fileInfo){
257
-                 $dirfiles[] = $fileInfo->getFilename();
258
-        }
259
-
260
-        foreach ($dirfiles as $key => $indfile) {
261
-                 $thisuserroot = $this->view->getRoot();
262
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
263
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
264
-        }
265
-
266
-        // Upload the new file
267
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
268
-        $fileName = $_FILES['uploadfileforsms']['name'];
269
-
270
-        $userroot = $this->view->getRoot();
271
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
272
-
273
-        $target = $this->folder->newFile($targetfile);
274
-        $target->putContent($fileContent);
275
-
276
-        // Extract the phone numbers from the file
277
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
278
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
279
-        $numberarrayfourth = explode(",", $numberarraytert);
280
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
281
-        $numberarray = array_unique($numberarrayfifth);
282
-
283
-        return $numberarray;
284
-    }
285
-
286
-
287
-    /**
288
-     * @NoAdminRequired
289
-     */
290
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
291
-
292
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
293
-         $telnyxkey = $telsmsapicred[0];
294
-         $teldelrecurl = $telsmsapicred[3];
295
-         $messagingprofid = $telsmsapicred[4];
296
-
297
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
298
-
299
-         $microinterval = $waitinterval * 1000;
300
-
301
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
302
-
303
-             usleep($microinterval);
304
-
305
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
306
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding, "messaging_profile_id" => $messagingprofid]);
307
-             } else {
308
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding]);
309
-             }
310
-
311
-             $messageid = $message['id'];
312
-             $messagedate = date("Y-m-d H:i:s");
313
-             $messagefrom = "Telnyx: " . $fromsender;
314
-             $messageto = $tonumber;
315
-             $messagenetwork = null;
316
-             $messageprice = null;
317
-             $messagestatus = $message['to'][0]['status'];
318
-             $messagedelivery = null;
319
-             $messagetext = $sentsmstext;
320
-
321
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
322
-
323
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
324
-
325
-         }
326
-    }
327
-
328
-
329
-    /**
330
-     * @NoAdminRequired
331
-     */
332
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
333
-
334
-         $smsapicred = $this->service->getapicredentials($this->userId);
335
-
336
-         $smsapikey = $smsapicred[5];
337
-         $smsapisecret = $smsapicred[6];
338
-         $smsapideliveryrecurl = $smsapicred[8];
339
-
340
-         $microinterval = $waitinterval * 1000;
341
-
342
-         $client = new RestClient($smsapikey, $smsapisecret);
343
-
344
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
345
-
346
-             usleep($microinterval);
347
-
348
-             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
349
-
350
-	     $messageidinit = $response->getmessageUuid(0);
351
-             $messageid = $messageidinit[0];
352
-
353
-             $messagedate = date("Y-m-d H:i:s");
354
-
355
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
356
-                 $messagefrom = "Plivo: " . $fromsender;
357
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
358
-
359
-             $messageto = $tonumber;
360
-             $messagenetwork = null;
361
-             $messageprice = null;
362
-             $messagestatus = "The message has been accepted for delivery.";
363
-             $messagedelivery = null;
364
-             $messagetext = $sentsmstext;
365
-
366
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
367
-
368
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
369
-         }
370
-    }
371
-
372
-
373
-    /**
374
-     * @NoAdminRequired
375
-     */
376
-    public function saveoldrecrows($userId, $oldrecRows) {
377
-
378
-           // Create the folder for removed messages if it doesn't exist
379
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
380
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
381
-           }
382
-           $savecheck = 0;
383
-
384
-           if (count($oldrecRows) > 1) {
385
-               $msfileContent = implode("", $oldrecRows);
386
-
387
-               $delrowsdate = date("Y-m-d_H-i-s");
388
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
389
-
390
-               $userroot = $this->view->getRoot();
391
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
392
-
393
-               $target = $this->folder->newFile($targetfile);
394
-               $target->putContent($msfileContent);
395
-
396
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
397
-                   $savecheck = 1;
398
-               }
399
-           }
400
-
401
-           return $savecheck;
402
-    }
403
-
404
-
405
-    /**
406
-     * @NoAdminRequired
407
-     */
408
-    public function saveoldsentrows($userId, $oldsentRows) {
409
-
410
-           // Create the folder for removed messages if it doesn't exist
411
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
412
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
413
-           }
414
-           $savesentcheck = 0;
415
-
416
-           if (count($oldsentRows) > 1) {
417
-               $sntfileContent = implode("", $oldsentRows);
418
-
419
-               $delsentrowsdate = date("Y-m-d_H-i-s");
420
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
421
-
422
-               $userroot = $this->view->getRoot();
423
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
424
-
425
-               $snttarget = $this->folder->newFile($snttargetfile);
426
-               $snttarget->putContent($sntfileContent);
427
-
428
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
429
-                   $savesentcheck = 1;
430
-               }
431
-           }
432
-
433
-           return $savesentcheck;
434
-    }
435
-
436
-
437
-    /**
438
-     * @NoAdminRequired
439
-     */
440
-    public function getreceivedtable($userId) {
441
-           return $this->service->getreceivedtable($this->userId);
442
-    }
443
-
444
-    /**
445
-     * @NoAdminRequired
446
-     */
447
-    public function getreceivedtablefordel($userId) {
448
-           return $this->service->getreceivedtablefordel($this->userId);
449
-    }
450
-
451
-    /**
452
-     * @NoAdminRequired
453
-     */
454
-    public function removerecrows($userId, $recmessagedbIDs) {
455
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
456
-    }
457
-
458
-    /**
459
-     * @NoAdminRequired
460
-     */
461
-    public function getsenttable($userId) {
462
-           return $this->service->getsenttable($this->userId);
463
-    }
464
-
465
-    /**
466
-     * @NoAdminRequired
467
-     */
468
-    public function getsenttablefordel($userId) {
469
-           return $this->service->getsenttablefordel($this->userId);
470
-    }
471
-
472
-    /**
473
-     * @NoAdminRequired
474
-     */
475
-    public function removesentrows($userId, $sentmessagedbIDs) {
476
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
477
-    }
478
-
479
-    /**
480
-     * @NoAdminRequired
481
-     */
482
-    public function getmessagesperpage($userId) {
483
-           return $this->service->getmessagesperpage($this->userId);
484
-    }
485
-
486
-    /**
487
-     * @NoAdminRequired
488
-     */
489
-    public function getdelrecsettings($userId) {
490
-           return $this->service->getdelrecsettings($this->userId);
491
-    }
492
-
493
-    /**
494
-     * @NoAdminRequired
495
-     */
496
-    public function getsettings($userId) {
497
-           return $this->service->getsettings($this->userId);
498
-    }
499
-
500
-    /**
501
-     * @NoAdminRequired
502
-     */
503
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail) {
504
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail);
505
-    }
506
-
507
-}
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json lib/Migration/Version105Date20220509201842.php lib/Service/SmsrelentlessService.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php js/settings.js

DoubleBastionAdmin authored on 09/05/2022 15:12:45
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,507 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use OCP\AppFramework\Http\DataResponse;
44
+use OCP\Files\NotFoundException;
45
+use OCP\Files\NotPermittedException;
46
+use Plivo\RestClient;
47
+
48
+
49
+class SmsrelentlessController extends Controller {
50
+
51
+    private $service;
52
+    private $config;
53
+    private $userId;
54
+    private $folder;
55
+    private $filesystem;
56
+    private $view;
57
+
58
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
59
+        parent::__construct($appName, $request);
60
+        $this->service = $service;
61
+        $this->config = $config;
62
+        $this->userId = $userId;
63
+        $this->folder = $folder;
64
+        $this->filesystem = $filesystem;
65
+        $this->view = $view;
66
+    }
67
+
68
+
69
+    /**
70
+     * @NoAdminRequired
71
+     */
72
+    public function object_to_array($obj) {
73
+        if(is_object($obj)) $obj = (array)$this->dismount($obj);
74
+        if(is_array($obj)) {
75
+           $new = array();
76
+           foreach($obj as $key => $val) {
77
+               $new[$key] = $this->object_to_array($val);
78
+           }
79
+        }
80
+        else $new = $obj;
81
+        return $new;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function dismount($object) {
89
+        $reflectionClass = new ReflectionClass(get_class($object));
90
+        $array = array();
91
+        foreach ($reflectionClass->getProperties() as $property) {
92
+           $property->setAccessible(true);
93
+           $array[$property->getName()] = $property->getValue($object);
94
+           $property->setAccessible(false);
95
+        }
96
+        return $array;
97
+    }
98
+
99
+
100
+    /**
101
+     * @NoAdminRequired
102
+     */
103
+    public function getbalancetel($userId) {
104
+
105
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
106
+
107
+        $telapikey = $telsmsapicred[0];
108
+        $ch = curl_init();
109
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
110
+
111
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
112
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
113
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
114
+        $responsetel = curl_exec($ch);
115
+        $recdatatel = json_decode($responsetel, TRUE);
116
+        $telbalresponse = $recdatatel['data']['balance'];
117
+        $currentbalancetel = round(floatval($telbalresponse), 3);
118
+        curl_close($ch);
119
+
120
+        return $currentbalancetel;
121
+    }
122
+
123
+
124
+    /**
125
+     * @NoAdminRequired
126
+     */
127
+    public function getbalancenex($userId) {
128
+
129
+        $smsapicred = $this->service->getapicredentials($this->userId);
130
+        $smsapikey = $smsapicred[5];
131
+        $smsapisecret = $smsapicred[6];
132
+
133
+        if ($smsapikey == '' || $smsapisecret == '') {
134
+            $currentbalancenex = "N/A";
135
+        } else {
136
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
137
+            $mesdata = file_get_contents($getmesdata);
138
+            $datainit = json_decode($mesdata);
139
+            $balancenex = $datainit->cash_credits;
140
+            $currentbalancenex = round(floatval($balancenex), 3);
141
+        }
142
+        return $currentbalancenex;
143
+    }
144
+
145
+
146
+    /**
147
+     * @NoAdminRequired
148
+     */
149
+    public function getsmsnumbers($userId) {
150
+
151
+        $smsapicred = $this->service->getapicredentials($this->userId);
152
+
153
+        $telnyxkey = $smsapicred[0];
154
+
155
+        $nexapikey = $smsapicred[5];
156
+        $nexapisecret = $smsapicred[6];
157
+
158
+        $telsendernameinit = $smsapicred[9];
159
+        $nexsendernameinit = $smsapicred[10];
160
+        $telsendername = "T: " . $telsendernameinit;
161
+        $nexsendername = "P: " . $nexsendernameinit;
162
+
163
+        if ($telnyxkey != '') {
164
+
165
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
166
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
167
+
168
+           $telnumbersarr = $this->object_to_array($telnumbers);
169
+           $telnmbrs = [];
170
+
171
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
172
+              if (is_int($nmbkey)) {
173
+                 foreach ($nmbvalue as $nkey => $nvalue) {
174
+                    if ($nkey == 'phone_number') {
175
+                       $telnmbrs[] = "T: " . $nvalue;
176
+                    }
177
+                 }
178
+              }
179
+           }
180
+
181
+        } else { $telnmbrs = []; }
182
+
183
+        if ($nexapikey != '' && $nexapisecret != '') {
184
+
185
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
186
+           $acdata = file_get_contents($getacdata);
187
+           $datainit = json_decode($acdata, true);
188
+
189
+           $findata = $this->object_to_array($datainit);
190
+
191
+           $nexcurrentnmbrs = [];
192
+
193
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
194
+                   if (is_array($smsvalue)) {
195
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
196
+                               if ($smskey2 == 'number') {
197
+                                   $nexcurrentnmbrs[] = "P: +" . $smsvalue2;
198
+                               }
199
+                         }
200
+                   }
201
+           }
202
+
203
+
204
+        } else { $nexcurrentnmbrs = []; }
205
+
206
+        $telsenderarr = [0 => $telsendername];
207
+        $nexsenderarr = [0 => $nexsendername];
208
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $telsenderarr, $nexsenderarr);
209
+
210
+        return $currentnmbrs;
211
+    }
212
+
213
+
214
+    /**
215
+     * @NoAdminRequired
216
+     */
217
+    public function cleantempdir($userId) {
218
+
219
+        // Create the temporary folder if it doesn't exist
220
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
221
+            $this->folder->newFolder('SMS_Relentless/temp_files');
222
+        }
223
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
224
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
225
+        $fileSystemIterator = new FilesystemIterator($targetdir);
226
+
227
+        $dirfiles = [];
228
+        foreach ($fileSystemIterator as $fileInfo){
229
+                 $dirfiles[] = $fileInfo->getFilename();
230
+        }
231
+
232
+        foreach ($dirfiles as $key => $indfile) {
233
+                 $thisuserroot = $this->view->getRoot();
234
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
235
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
236
+        }
237
+     }
238
+
239
+
240
+    /**
241
+     * @NoAdminRequired
242
+     */
243
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
244
+
245
+        // Create the temporary folder if it doesn't exist
246
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
247
+            $this->folder->newFolder('SMS_Relentless/temp_files');
248
+        }
249
+
250
+        // First delete any file that has been previously uploaded
251
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
252
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
253
+        $fileSystemIterator = new FilesystemIterator($targetdir);
254
+
255
+        $dirfiles = [];
256
+        foreach ($fileSystemIterator as $fileInfo){
257
+                 $dirfiles[] = $fileInfo->getFilename();
258
+        }
259
+
260
+        foreach ($dirfiles as $key => $indfile) {
261
+                 $thisuserroot = $this->view->getRoot();
262
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
263
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
264
+        }
265
+
266
+        // Upload the new file
267
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
268
+        $fileName = $_FILES['uploadfileforsms']['name'];
269
+
270
+        $userroot = $this->view->getRoot();
271
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
272
+
273
+        $target = $this->folder->newFile($targetfile);
274
+        $target->putContent($fileContent);
275
+
276
+        // Extract the phone numbers from the file
277
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
278
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
279
+        $numberarrayfourth = explode(",", $numberarraytert);
280
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
281
+        $numberarray = array_unique($numberarrayfifth);
282
+
283
+        return $numberarray;
284
+    }
285
+
286
+
287
+    /**
288
+     * @NoAdminRequired
289
+     */
290
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
291
+
292
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
293
+         $telnyxkey = $telsmsapicred[0];
294
+         $teldelrecurl = $telsmsapicred[3];
295
+         $messagingprofid = $telsmsapicred[4];
296
+
297
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
298
+
299
+         $microinterval = $waitinterval * 1000;
300
+
301
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
302
+
303
+             usleep($microinterval);
304
+
305
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
306
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding, "messaging_profile_id" => $messagingprofid]);
307
+             } else {
308
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding]);
309
+             }
310
+
311
+             $messageid = $message['id'];
312
+             $messagedate = date("Y-m-d H:i:s");
313
+             $messagefrom = "Telnyx: " . $fromsender;
314
+             $messageto = $tonumber;
315
+             $messagenetwork = null;
316
+             $messageprice = null;
317
+             $messagestatus = $message['to'][0]['status'];
318
+             $messagedelivery = null;
319
+             $messagetext = $sentsmstext;
320
+
321
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
322
+
323
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
324
+
325
+         }
326
+    }
327
+
328
+
329
+    /**
330
+     * @NoAdminRequired
331
+     */
332
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
333
+
334
+         $smsapicred = $this->service->getapicredentials($this->userId);
335
+
336
+         $smsapikey = $smsapicred[5];
337
+         $smsapisecret = $smsapicred[6];
338
+         $smsapideliveryrecurl = $smsapicred[8];
339
+
340
+         $microinterval = $waitinterval * 1000;
341
+
342
+         $client = new RestClient($smsapikey, $smsapisecret);
343
+
344
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
345
+
346
+             usleep($microinterval);
347
+
348
+             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
349
+
350
+	     $messageidinit = $response->getmessageUuid(0);
351
+             $messageid = $messageidinit[0];
352
+
353
+             $messagedate = date("Y-m-d H:i:s");
354
+
355
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
356
+                 $messagefrom = "Plivo: " . $fromsender;
357
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
358
+
359
+             $messageto = $tonumber;
360
+             $messagenetwork = null;
361
+             $messageprice = null;
362
+             $messagestatus = "The message has been accepted for delivery.";
363
+             $messagedelivery = null;
364
+             $messagetext = $sentsmstext;
365
+
366
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
367
+
368
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
369
+         }
370
+    }
371
+
372
+
373
+    /**
374
+     * @NoAdminRequired
375
+     */
376
+    public function saveoldrecrows($userId, $oldrecRows) {
377
+
378
+           // Create the folder for removed messages if it doesn't exist
379
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
380
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
381
+           }
382
+           $savecheck = 0;
383
+
384
+           if (count($oldrecRows) > 1) {
385
+               $msfileContent = implode("", $oldrecRows);
386
+
387
+               $delrowsdate = date("Y-m-d_H-i-s");
388
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
389
+
390
+               $userroot = $this->view->getRoot();
391
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
392
+
393
+               $target = $this->folder->newFile($targetfile);
394
+               $target->putContent($msfileContent);
395
+
396
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
397
+                   $savecheck = 1;
398
+               }
399
+           }
400
+
401
+           return $savecheck;
402
+    }
403
+
404
+
405
+    /**
406
+     * @NoAdminRequired
407
+     */
408
+    public function saveoldsentrows($userId, $oldsentRows) {
409
+
410
+           // Create the folder for removed messages if it doesn't exist
411
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
412
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
413
+           }
414
+           $savesentcheck = 0;
415
+
416
+           if (count($oldsentRows) > 1) {
417
+               $sntfileContent = implode("", $oldsentRows);
418
+
419
+               $delsentrowsdate = date("Y-m-d_H-i-s");
420
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
421
+
422
+               $userroot = $this->view->getRoot();
423
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
424
+
425
+               $snttarget = $this->folder->newFile($snttargetfile);
426
+               $snttarget->putContent($sntfileContent);
427
+
428
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
429
+                   $savesentcheck = 1;
430
+               }
431
+           }
432
+
433
+           return $savesentcheck;
434
+    }
435
+
436
+
437
+    /**
438
+     * @NoAdminRequired
439
+     */
440
+    public function getreceivedtable($userId) {
441
+           return $this->service->getreceivedtable($this->userId);
442
+    }
443
+
444
+    /**
445
+     * @NoAdminRequired
446
+     */
447
+    public function getreceivedtablefordel($userId) {
448
+           return $this->service->getreceivedtablefordel($this->userId);
449
+    }
450
+
451
+    /**
452
+     * @NoAdminRequired
453
+     */
454
+    public function removerecrows($userId, $recmessagedbIDs) {
455
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
456
+    }
457
+
458
+    /**
459
+     * @NoAdminRequired
460
+     */
461
+    public function getsenttable($userId) {
462
+           return $this->service->getsenttable($this->userId);
463
+    }
464
+
465
+    /**
466
+     * @NoAdminRequired
467
+     */
468
+    public function getsenttablefordel($userId) {
469
+           return $this->service->getsenttablefordel($this->userId);
470
+    }
471
+
472
+    /**
473
+     * @NoAdminRequired
474
+     */
475
+    public function removesentrows($userId, $sentmessagedbIDs) {
476
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
477
+    }
478
+
479
+    /**
480
+     * @NoAdminRequired
481
+     */
482
+    public function getmessagesperpage($userId) {
483
+           return $this->service->getmessagesperpage($this->userId);
484
+    }
485
+
486
+    /**
487
+     * @NoAdminRequired
488
+     */
489
+    public function getdelrecsettings($userId) {
490
+           return $this->service->getdelrecsettings($this->userId);
491
+    }
492
+
493
+    /**
494
+     * @NoAdminRequired
495
+     */
496
+    public function getsettings($userId) {
497
+           return $this->service->getsettings($this->userId);
498
+    }
499
+
500
+    /**
501
+     * @NoAdminRequired
502
+     */
503
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail) {
504
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail);
505
+    }
506
+
507
+}
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json lib/Migration/Version104Date20220507234521.php lib/Service/SmsrelentlessService.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php js/settings.js

DoubleBastionAdmin authored on 09/05/2022 15:03:46
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,508 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OCP\IConfig;
38
-use OC\Files\Filesystem;
39
-use OC\Files\View;
40
-use \ReflectionClass;
41
-use \FilesystemIterator;
42
-use \DateTime;
43
-use OCP\AppFramework\Http\DataResponse;
44
-use OCP\Files\NotFoundException;
45
-use OCP\Files\NotPermittedException;
46
-use Plivo\RestClient;
47
-
48
-
49
-class SmsrelentlessController extends Controller {
50
-
51
-    private $service;
52
-    private $config;
53
-    private $userId;
54
-    private $folder;
55
-    private $filesystem;
56
-    private $view;
57
-
58
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
59
-        parent::__construct($appName, $request);
60
-        $this->service = $service;
61
-        $this->config = $config;
62
-        $this->userId = $userId;
63
-        $this->folder = $folder;
64
-        $this->filesystem = $filesystem;
65
-        $this->view = $view;
66
-    }
67
-
68
-
69
-    /**
70
-     * @NoAdminRequired
71
-     */
72
-    public function object_to_array($obj) {
73
-        if(is_object($obj)) $obj = (array)$this->dismount($obj);
74
-        if(is_array($obj)) {
75
-           $new = array();
76
-           foreach($obj as $key => $val) {
77
-               $new[$key] = $this->object_to_array($val);
78
-           }
79
-        }
80
-        else $new = $obj;
81
-        return $new;
82
-    }
83
-
84
-
85
-    /**
86
-     * @NoAdminRequired
87
-     */
88
-    public function dismount($object) {
89
-        $reflectionClass = new ReflectionClass(get_class($object));
90
-        $array = array();
91
-        foreach ($reflectionClass->getProperties() as $property) {
92
-           $property->setAccessible(true);
93
-           $array[$property->getName()] = $property->getValue($object);
94
-           $property->setAccessible(false);
95
-        }
96
-        return $array;
97
-    }
98
-
99
-
100
-    /**
101
-     * @NoAdminRequired
102
-     */
103
-    public function getbalancetel($userId) {
104
-
105
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
106
-
107
-        $telapikey = $telsmsapicred[0];
108
-        $ch = curl_init();
109
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
110
-
111
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
112
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
113
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
114
-        $responsetel = curl_exec($ch);
115
-        $recdatatel = json_decode($responsetel, TRUE);
116
-        $telbalresponse = $recdatatel['data']['balance'];
117
-        $currentbalancetel = round(floatval($telbalresponse), 3);
118
-        curl_close($ch);
119
-
120
-        return $currentbalancetel;
121
-    }
122
-
123
-
124
-    /**
125
-     * @NoAdminRequired
126
-     */
127
-    public function getbalancenex($userId) {
128
-
129
-        $smsapicred = $this->service->getapicredentials($this->userId);
130
-        $smsapikey = $smsapicred[5];
131
-        $smsapisecret = $smsapicred[6];
132
-
133
-        if ($smsapikey == '' || $smsapisecret == '') {
134
-            $currentbalancenex = "N/A";
135
-        } else {
136
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
137
-            $mesdata = file_get_contents($getmesdata);
138
-            $datainit = json_decode($mesdata);
139
-            $balancenex = $datainit->cash_credits;
140
-            $currentbalancenex = round(floatval($balancenex), 3);
141
-        }
142
-        return $currentbalancenex;
143
-    }
144
-
145
-
146
-    /**
147
-     * @NoAdminRequired
148
-     */
149
-    public function getsmsnumbers($userId) {
150
-
151
-        $smsapicred = $this->service->getapicredentials($this->userId);
152
-
153
-        $telnyxkey = $smsapicred[0];
154
-
155
-        $nexapikey = $smsapicred[5];
156
-        $nexapisecret = $smsapicred[6];
157
-
158
-        $telsendernameinit = $smsapicred[9];
159
-        $nexsendernameinit = $smsapicred[10];
160
-        $telsendername = "T: " . $telsendernameinit;
161
-        $nexsendername = "P: " . $nexsendernameinit;
162
-
163
-        if ($telnyxkey != '') {
164
-
165
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
166
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
167
-
168
-           $telnumbersarr = $this->object_to_array($telnumbers);
169
-           $telnmbrs = [];
170
-
171
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
172
-              if (is_int($nmbkey)) {
173
-                 foreach ($nmbvalue as $nkey => $nvalue) {
174
-                    if ($nkey == 'phone_number') {
175
-                       $telnmbrs[] = "T: " . $nvalue;
176
-                    }
177
-                 }
178
-              }
179
-           }
180
-
181
-        } else { $telnmbrs = []; }
182
-
183
-        if ($nexapikey != '' && $nexapisecret != '') {
184
-
185
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
186
-           $acdata = file_get_contents($getacdata);
187
-           $datainit = json_decode($acdata, true);
188
-
189
-           $findata = $this->object_to_array($datainit);
190
-
191
-           $nexcurrentnmbrs = [];
192
-
193
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
194
-                   if (is_array($smsvalue)) {
195
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
196
-                               if ($smskey2 == 'number') {
197
-                                   $nexcurrentnmbrs[] = "P: +" . $smsvalue2;
198
-                               }
199
-                         }
200
-                   }
201
-           }
202
-
203
-
204
-        } else { $nexcurrentnmbrs = []; }
205
-
206
-        $telsenderarr = [0 => $telsendername];
207
-        $nexsenderarr = [0 => $nexsendername];
208
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $telsenderarr, $nexsenderarr);
209
-
210
-        return $currentnmbrs;
211
-    }
212
-
213
-
214
-    /**
215
-     * @NoAdminRequired
216
-     */
217
-    public function cleantempdir($userId) {
218
-
219
-        // Create the temporary folder if it doesn't exist
220
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
221
-            $this->folder->newFolder('SMS_Relentless/temp_files');
222
-        }
223
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
224
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
225
-        $fileSystemIterator = new FilesystemIterator($targetdir);
226
-
227
-        $dirfiles = [];
228
-        foreach ($fileSystemIterator as $fileInfo){
229
-                 $dirfiles[] = $fileInfo->getFilename();
230
-        }
231
-
232
-        foreach ($dirfiles as $key => $indfile) {
233
-                 $thisuserroot = $this->view->getRoot();
234
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
235
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
236
-        }
237
-     }
238
-
239
-
240
-    /**
241
-     * @NoAdminRequired
242
-     */
243
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
244
-
245
-        // Create the temporary folder if it doesn't exist
246
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
247
-            $this->folder->newFolder('SMS_Relentless/temp_files');
248
-        }
249
-
250
-        // First delete any file that has been previously uploaded
251
-        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
252
-        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
253
-        $fileSystemIterator = new FilesystemIterator($targetdir);
254
-
255
-        $dirfiles = [];
256
-        foreach ($fileSystemIterator as $fileInfo){
257
-                 $dirfiles[] = $fileInfo->getFilename();
258
-        }
259
-
260
-        foreach ($dirfiles as $key => $indfile) {
261
-                 $thisuserroot = $this->view->getRoot();
262
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
263
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
264
-        }
265
-
266
-        // Upload the new file
267
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
268
-        $fileName = $_FILES['uploadfileforsms']['name'];
269
-
270
-        $userroot = $this->view->getRoot();
271
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
272
-
273
-        $target = $this->folder->newFile($targetfile);
274
-        $target->putContent($fileContent);
275
-
276
-        // Extract the phone numbers from the file
277
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
278
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
279
-        $numberarrayfourth = explode(",", $numberarraytert);
280
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
281
-        $numberarray = array_unique($numberarrayfifth);
282
-
283
-        return $numberarray;
284
-
285
-    }
286
-
287
-
288
-    /**
289
-     * @NoAdminRequired
290
-     */
291
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
292
-
293
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
294
-         $telnyxkey = $telsmsapicred[0];
295
-         $teldelrecurl = $telsmsapicred[3];
296
-         $messagingprofid = $telsmsapicred[4];
297
-
298
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
299
-
300
-         $microinterval = $waitinterval * 1000;
301
-
302
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
303
-
304
-             usleep($microinterval);
305
-
306
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
307
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding, "messaging_profile_id" => $messagingprofid]);
308
-             } else {
309
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding]);
310
-             }
311
-
312
-             $messageid = $message['id'];
313
-             $messagedate = date("Y-m-d H:i:s");
314
-             $messagefrom = "Telnyx: " . $fromsender;
315
-             $messageto = $tonumber;
316
-             $messagenetwork = null;
317
-             $messageprice = null;
318
-             $messagestatus = $message['to'][0]['status'];
319
-             $messagedelivery = null;
320
-             $messagetext = str_replace("'", "\'", $sentsmstext);
321
-
322
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
323
-
324
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
325
-
326
-         }
327
-    }
328
-
329
-
330
-    /**
331
-     * @NoAdminRequired
332
-     */
333
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
334
-
335
-         $smsapicred = $this->service->getapicredentials($this->userId);
336
-
337
-         $smsapikey = $smsapicred[5];
338
-         $smsapisecret = $smsapicred[6];
339
-         $smsapideliveryrecurl = $smsapicred[8];
340
-
341
-         $microinterval = $waitinterval * 1000;
342
-
343
-         $client = new RestClient($smsapikey, $smsapisecret);
344
-
345
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
346
-
347
-             usleep($microinterval);
348
-
349
-             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
350
-
351
-	     $messageidinit = $response->getmessageUuid(0);
352
-             $messageid = $messageidinit[0];
353
-
354
-             $messagedate = date("Y-m-d H:i:s");
355
-
356
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
357
-                 $messagefrom = "Plivo: " . $fromsender;
358
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
359
-
360
-             $messageto = $tonumber;
361
-             $messagenetwork = null;
362
-             $messageprice = null;
363
-             $messagestatus = "The message has been accepted for delivery.";
364
-             $messagedelivery = null;
365
-             $messagetext = str_replace("'", "\'", $sentsmstext);
366
-
367
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
368
-
369
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
370
-         }
371
-    }
372
-
373
-
374
-    /**
375
-     * @NoAdminRequired
376
-     */
377
-    public function saveoldrecrows($userId, $oldrecRows) {
378
-
379
-           // Create the folder for removed messages if it doesn't exist
380
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
381
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
382
-           }
383
-           $savecheck = 0;
384
-
385
-           if (count($oldrecRows) > 1) {
386
-               $msfileContent = implode("", $oldrecRows);
387
-
388
-               $delrowsdate = date("Y-m-d_H-i-s");
389
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
390
-
391
-               $userroot = $this->view->getRoot();
392
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
393
-
394
-               $target = $this->folder->newFile($targetfile);
395
-               $target->putContent($msfileContent);
396
-
397
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
398
-                   $savecheck = 1;
399
-               }
400
-           }
401
-
402
-           return $savecheck;
403
-    }
404
-
405
-
406
-    /**
407
-     * @NoAdminRequired
408
-     */
409
-    public function saveoldsentrows($userId, $oldsentRows) {
410
-
411
-           // Create the folder for removed messages if it doesn't exist
412
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
413
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
414
-           }
415
-           $savesentcheck = 0;
416
-
417
-           if (count($oldsentRows) > 1) {
418
-               $sntfileContent = implode("", $oldsentRows);
419
-
420
-               $delsentrowsdate = date("Y-m-d_H-i-s");
421
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
422
-
423
-               $userroot = $this->view->getRoot();
424
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
425
-
426
-               $snttarget = $this->folder->newFile($snttargetfile);
427
-               $snttarget->putContent($sntfileContent);
428
-
429
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
430
-                   $savesentcheck = 1;
431
-               }
432
-           }
433
-
434
-           return $savesentcheck;
435
-    }
436
-
437
-
438
-    /**
439
-     * @NoAdminRequired
440
-     */
441
-    public function getreceivedtable($userId) {
442
-           return $this->service->getreceivedtable($this->userId);
443
-    }
444
-
445
-    /**
446
-     * @NoAdminRequired
447
-     */
448
-    public function getreceivedtablefordel($userId) {
449
-           return $this->service->getreceivedtablefordel($this->userId);
450
-    }
451
-
452
-    /**
453
-     * @NoAdminRequired
454
-     */
455
-    public function removerecrows($userId, $recmessagedbIDs) {
456
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
457
-    }
458
-
459
-    /**
460
-     * @NoAdminRequired
461
-     */
462
-    public function getsenttable($userId) {
463
-           return $this->service->getsenttable($this->userId);
464
-    }
465
-
466
-    /**
467
-     * @NoAdminRequired
468
-     */
469
-    public function getsenttablefordel($userId) {
470
-           return $this->service->getsenttablefordel($this->userId);
471
-    }
472
-
473
-    /**
474
-     * @NoAdminRequired
475
-     */
476
-    public function removesentrows($userId, $sentmessagedbIDs) {
477
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
478
-    }
479
-
480
-    /**
481
-     * @NoAdminRequired
482
-     */
483
-    public function getmessagesperpage($userId) {
484
-           return $this->service->getmessagesperpage($this->userId);
485
-    }
486
-
487
-    /**
488
-     * @NoAdminRequired
489
-     */
490
-    public function getdelrecsettings($userId) {
491
-           return $this->service->getdelrecsettings($this->userId);
492
-    }
493
-
494
-    /**
495
-     * @NoAdminRequired
496
-     */
497
-    public function getsettings($userId) {
498
-           return $this->service->getsettings($this->userId);
499
-    }
500
-
501
-    /**
502
-     * @NoAdminRequired
503
-     */
504
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail) {
505
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail);
506
-    }
507
-
508
-}
Browse code

added appinfo/info.xml appinfo/signature.json css/style.css js/showsmstables.js lib/Controller/SmsrelentlessController.php CHANGELOG.txt Contributors.txt

DoubleBastionAdmin authored on 12/04/2022 22:24:09
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,508 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OCP\IConfig;
38
+use OC\Files\Filesystem;
39
+use OC\Files\View;
40
+use \ReflectionClass;
41
+use \FilesystemIterator;
42
+use \DateTime;
43
+use OCP\AppFramework\Http\DataResponse;
44
+use OCP\Files\NotFoundException;
45
+use OCP\Files\NotPermittedException;
46
+use Plivo\RestClient;
47
+
48
+
49
+class SmsrelentlessController extends Controller {
50
+
51
+    private $service;
52
+    private $config;
53
+    private $userId;
54
+    private $folder;
55
+    private $filesystem;
56
+    private $view;
57
+
58
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, IConfig $config, $userId, Folder $folder, Filesystem $filesystem, View $view) {
59
+        parent::__construct($appName, $request);
60
+        $this->service = $service;
61
+        $this->config = $config;
62
+        $this->userId = $userId;
63
+        $this->folder = $folder;
64
+        $this->filesystem = $filesystem;
65
+        $this->view = $view;
66
+    }
67
+
68
+
69
+    /**
70
+     * @NoAdminRequired
71
+     */
72
+    public function object_to_array($obj) {
73
+        if(is_object($obj)) $obj = (array)$this->dismount($obj);
74
+        if(is_array($obj)) {
75
+           $new = array();
76
+           foreach($obj as $key => $val) {
77
+               $new[$key] = $this->object_to_array($val);
78
+           }
79
+        }
80
+        else $new = $obj;
81
+        return $new;
82
+    }
83
+
84
+
85
+    /**
86
+     * @NoAdminRequired
87
+     */
88
+    public function dismount($object) {
89
+        $reflectionClass = new ReflectionClass(get_class($object));
90
+        $array = array();
91
+        foreach ($reflectionClass->getProperties() as $property) {
92
+           $property->setAccessible(true);
93
+           $array[$property->getName()] = $property->getValue($object);
94
+           $property->setAccessible(false);
95
+        }
96
+        return $array;
97
+    }
98
+
99
+
100
+    /**
101
+     * @NoAdminRequired
102
+     */
103
+    public function getbalancetel($userId) {
104
+
105
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
106
+
107
+        $telapikey = $telsmsapicred[0];
108
+        $ch = curl_init();
109
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
110
+
111
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
112
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
113
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
114
+        $responsetel = curl_exec($ch);
115
+        $recdatatel = json_decode($responsetel, TRUE);
116
+        $telbalresponse = $recdatatel['data']['balance'];
117
+        $currentbalancetel = round(floatval($telbalresponse), 3);
118
+        curl_close($ch);
119
+
120
+        return $currentbalancetel;
121
+    }
122
+
123
+
124
+    /**
125
+     * @NoAdminRequired
126
+     */
127
+    public function getbalancenex($userId) {
128
+
129
+        $smsapicred = $this->service->getapicredentials($this->userId);
130
+        $smsapikey = $smsapicred[5];
131
+        $smsapisecret = $smsapicred[6];
132
+
133
+        if ($smsapikey == '' || $smsapisecret == '') {
134
+            $currentbalancenex = "N/A";
135
+        } else {
136
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
137
+            $mesdata = file_get_contents($getmesdata);
138
+            $datainit = json_decode($mesdata);
139
+            $balancenex = $datainit->cash_credits;
140
+            $currentbalancenex = round(floatval($balancenex), 3);
141
+        }
142
+        return $currentbalancenex;
143
+    }
144
+
145
+
146
+    /**
147
+     * @NoAdminRequired
148
+     */
149
+    public function getsmsnumbers($userId) {
150
+
151
+        $smsapicred = $this->service->getapicredentials($this->userId);
152
+
153
+        $telnyxkey = $smsapicred[0];
154
+
155
+        $nexapikey = $smsapicred[5];
156
+        $nexapisecret = $smsapicred[6];
157
+
158
+        $telsendernameinit = $smsapicred[9];
159
+        $nexsendernameinit = $smsapicred[10];
160
+        $telsendername = "T: " . $telsendernameinit;
161
+        $nexsendername = "P: " . $nexsendernameinit;
162
+
163
+        if ($telnyxkey != '') {
164
+
165
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
166
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
167
+
168
+           $telnumbersarr = $this->object_to_array($telnumbers);
169
+           $telnmbrs = [];
170
+
171
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
172
+              if (is_int($nmbkey)) {
173
+                 foreach ($nmbvalue as $nkey => $nvalue) {
174
+                    if ($nkey == 'phone_number') {
175
+                       $telnmbrs[] = "T: " . $nvalue;
176
+                    }
177
+                 }
178
+              }
179
+           }
180
+
181
+        } else { $telnmbrs = []; }
182
+
183
+        if ($nexapikey != '' && $nexapisecret != '') {
184
+
185
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
186
+           $acdata = file_get_contents($getacdata);
187
+           $datainit = json_decode($acdata, true);
188
+
189
+           $findata = $this->object_to_array($datainit);
190
+
191
+           $nexcurrentnmbrs = [];
192
+
193
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
194
+                   if (is_array($smsvalue)) {
195
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
196
+                               if ($smskey2 == 'number') {
197
+                                   $nexcurrentnmbrs[] = "P: +" . $smsvalue2;
198
+                               }
199
+                         }
200
+                   }
201
+           }
202
+
203
+
204
+        } else { $nexcurrentnmbrs = []; }
205
+
206
+        $telsenderarr = [0 => $telsendername];
207
+        $nexsenderarr = [0 => $nexsendername];
208
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $telsenderarr, $nexsenderarr);
209
+
210
+        return $currentnmbrs;
211
+    }
212
+
213
+
214
+    /**
215
+     * @NoAdminRequired
216
+     */
217
+    public function cleantempdir($userId) {
218
+
219
+        // Create the temporary folder if it doesn't exist
220
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
221
+            $this->folder->newFolder('SMS_Relentless/temp_files');
222
+        }
223
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
224
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
225
+        $fileSystemIterator = new FilesystemIterator($targetdir);
226
+
227
+        $dirfiles = [];
228
+        foreach ($fileSystemIterator as $fileInfo){
229
+                 $dirfiles[] = $fileInfo->getFilename();
230
+        }
231
+
232
+        foreach ($dirfiles as $key => $indfile) {
233
+                 $thisuserroot = $this->view->getRoot();
234
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
235
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
236
+        }
237
+     }
238
+
239
+
240
+    /**
241
+     * @NoAdminRequired
242
+     */
243
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
244
+
245
+        // Create the temporary folder if it doesn't exist
246
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
247
+            $this->folder->newFolder('SMS_Relentless/temp_files');
248
+        }
249
+
250
+        // First delete any file that has been previously uploaded
251
+        $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/';
252
+        $targetdir = $datadir . $this->userId . "/files/SMS_Relentless/temp_files";
253
+        $fileSystemIterator = new FilesystemIterator($targetdir);
254
+
255
+        $dirfiles = [];
256
+        foreach ($fileSystemIterator as $fileInfo){
257
+                 $dirfiles[] = $fileInfo->getFilename();
258
+        }
259
+
260
+        foreach ($dirfiles as $key => $indfile) {
261
+                 $thisuserroot = $this->view->getRoot();
262
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
263
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
264
+        }
265
+
266
+        // Upload the new file
267
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
268
+        $fileName = $_FILES['uploadfileforsms']['name'];
269
+
270
+        $userroot = $this->view->getRoot();
271
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
272
+
273
+        $target = $this->folder->newFile($targetfile);
274
+        $target->putContent($fileContent);
275
+
276
+        // Extract the phone numbers from the file
277
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
278
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
279
+        $numberarrayfourth = explode(",", $numberarraytert);
280
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
281
+        $numberarray = array_unique($numberarrayfifth);
282
+
283
+        return $numberarray;
284
+
285
+    }
286
+
287
+
288
+    /**
289
+     * @NoAdminRequired
290
+     */
291
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
292
+
293
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
294
+         $telnyxkey = $telsmsapicred[0];
295
+         $teldelrecurl = $telsmsapicred[3];
296
+         $messagingprofid = $telsmsapicred[4];
297
+
298
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
299
+
300
+         $microinterval = $waitinterval * 1000;
301
+
302
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
303
+
304
+             usleep($microinterval);
305
+
306
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
307
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding, "messaging_profile_id" => $messagingprofid]);
308
+             } else {
309
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding]);
310
+             }
311
+
312
+             $messageid = $message['id'];
313
+             $messagedate = date("Y-m-d H:i:s");
314
+             $messagefrom = "Telnyx: " . $fromsender;
315
+             $messageto = $tonumber;
316
+             $messagenetwork = null;
317
+             $messageprice = null;
318
+             $messagestatus = $message['to'][0]['status'];
319
+             $messagedelivery = null;
320
+             $messagetext = str_replace("'", "\'", $sentsmstext);
321
+
322
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
323
+
324
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
325
+
326
+         }
327
+    }
328
+
329
+
330
+    /**
331
+     * @NoAdminRequired
332
+     */
333
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
334
+
335
+         $smsapicred = $this->service->getapicredentials($this->userId);
336
+
337
+         $smsapikey = $smsapicred[5];
338
+         $smsapisecret = $smsapicred[6];
339
+         $smsapideliveryrecurl = $smsapicred[8];
340
+
341
+         $microinterval = $waitinterval * 1000;
342
+
343
+         $client = new RestClient($smsapikey, $smsapisecret);
344
+
345
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
346
+
347
+             usleep($microinterval);
348
+
349
+             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
350
+
351
+	     $messageidinit = $response->getmessageUuid(0);
352
+             $messageid = $messageidinit[0];
353
+
354
+             $messagedate = date("Y-m-d H:i:s");
355
+
356
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
357
+                 $messagefrom = "Plivo: " . $fromsender;
358
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
359
+
360
+             $messageto = $tonumber;
361
+             $messagenetwork = null;
362
+             $messageprice = null;
363
+             $messagestatus = "The message has been accepted for delivery.";
364
+             $messagedelivery = null;
365
+             $messagetext = str_replace("'", "\'", $sentsmstext);
366
+
367
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
368
+
369
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
370
+         }
371
+    }
372
+
373
+
374
+    /**
375
+     * @NoAdminRequired
376
+     */
377
+    public function saveoldrecrows($userId, $oldrecRows) {
378
+
379
+           // Create the folder for removed messages if it doesn't exist
380
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
381
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
382
+           }
383
+           $savecheck = 0;
384
+
385
+           if (count($oldrecRows) > 1) {
386
+               $msfileContent = implode("", $oldrecRows);
387
+
388
+               $delrowsdate = date("Y-m-d_H-i-s");
389
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
390
+
391
+               $userroot = $this->view->getRoot();
392
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
393
+
394
+               $target = $this->folder->newFile($targetfile);
395
+               $target->putContent($msfileContent);
396
+
397
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
398
+                   $savecheck = 1;
399
+               }
400
+           }
401
+
402
+           return $savecheck;
403
+    }
404
+
405
+
406
+    /**
407
+     * @NoAdminRequired
408
+     */
409
+    public function saveoldsentrows($userId, $oldsentRows) {
410
+
411
+           // Create the folder for removed messages if it doesn't exist
412
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
413
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
414
+           }
415
+           $savesentcheck = 0;
416
+
417
+           if (count($oldsentRows) > 1) {
418
+               $sntfileContent = implode("", $oldsentRows);
419
+
420
+               $delsentrowsdate = date("Y-m-d_H-i-s");
421
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
422
+
423
+               $userroot = $this->view->getRoot();
424
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
425
+
426
+               $snttarget = $this->folder->newFile($snttargetfile);
427
+               $snttarget->putContent($sntfileContent);
428
+
429
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
430
+                   $savesentcheck = 1;
431
+               }
432
+           }
433
+
434
+           return $savesentcheck;
435
+    }
436
+
437
+
438
+    /**
439
+     * @NoAdminRequired
440
+     */
441
+    public function getreceivedtable($userId) {
442
+           return $this->service->getreceivedtable($this->userId);
443
+    }
444
+
445
+    /**
446
+     * @NoAdminRequired
447
+     */
448
+    public function getreceivedtablefordel($userId) {
449
+           return $this->service->getreceivedtablefordel($this->userId);
450
+    }
451
+
452
+    /**
453
+     * @NoAdminRequired
454
+     */
455
+    public function removerecrows($userId, $recmessagedbIDs) {
456
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
457
+    }
458
+
459
+    /**
460
+     * @NoAdminRequired
461
+     */
462
+    public function getsenttable($userId) {
463
+           return $this->service->getsenttable($this->userId);
464
+    }
465
+
466
+    /**
467
+     * @NoAdminRequired
468
+     */
469
+    public function getsenttablefordel($userId) {
470
+           return $this->service->getsenttablefordel($this->userId);
471
+    }
472
+
473
+    /**
474
+     * @NoAdminRequired
475
+     */
476
+    public function removesentrows($userId, $sentmessagedbIDs) {
477
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
478
+    }
479
+
480
+    /**
481
+     * @NoAdminRequired
482
+     */
483
+    public function getmessagesperpage($userId) {
484
+           return $this->service->getmessagesperpage($this->userId);
485
+    }
486
+
487
+    /**
488
+     * @NoAdminRequired
489
+     */
490
+    public function getdelrecsettings($userId) {
491
+           return $this->service->getdelrecsettings($this->userId);
492
+    }
493
+
494
+    /**
495
+     * @NoAdminRequired
496
+     */
497
+    public function getsettings($userId) {
498
+           return $this->service->getsettings($this->userId);
499
+    }
500
+
501
+    /**
502
+     * @NoAdminRequired
503
+     */
504
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail) {
505
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail);
506
+    }
507
+
508
+}
Browse code

removed appinfo/info.xml appinfo/signature.json css/style.css js/showsmstables.js lib/Controller/SmsrelentlessController.php CHANGELOG.txt

DoubleBastionAdmin authored on 12/04/2022 22:15:59
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,503 +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\SMSRelentless\Controller;
27
-
28
-use OCP\IRequest;
29
-use OCP\AppFramework\Controller;
30
-use OCA\SMSRelentless\Service\SmsrelentlessService;
31
-use OCP\AppFramework\App;
32
-use OC\Http\Client\Client;
33
-use OCP\Files\SimpleFS\ISimpleFile;
34
-use OCP\Files\SimpleFS\ISimpleFolder;
35
-use OCP\IL10N;
36
-use OCP\Files\Folder;
37
-use OC\Files\Filesystem;
38
-use OC\Files\View;
39
-use \ReflectionClass;
40
-use \FilesystemIterator;
41
-use \DateTime;
42
-use OCP\AppFramework\Http\DataResponse;
43
-use OCP\Files\NotFoundException;
44
-use OCP\Files\NotPermittedException;
45
-use Plivo\RestClient;
46
-
47
-
48
-class SmsrelentlessController extends Controller {
49
-
50
-    private $service;
51
-    private $userId;
52
-    private $folder;
53
-    private $filesystem;
54
-    private $view;
55
-
56
-    public function __construct($appName, IRequest $request, SmsrelentlessService $service, Folder $folder, Filesystem $filesystem, $userId, View $view) {
57
-        parent::__construct($appName, $request);
58
-        $this->service = $service;
59
-        $this->userId = $userId;
60
-        $this->folder = $folder;
61
-        $this->filesystem = $filesystem;
62
-        $this->view = $view;
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
-    public function getbalancetel($userId) {
101
-
102
-        $telsmsapicred = $this->service->getapicredentials($this->userId);
103
-
104
-        $telapikey = $telsmsapicred[0];
105
-        $ch = curl_init();
106
-        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
107
-
108
-        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
109
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
110
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
111
-        $responsetel = curl_exec($ch);
112
-        $recdatatel = json_decode($responsetel, TRUE);
113
-        $telbalresponse = $recdatatel['data']['balance'];
114
-        $currentbalancetel = round(floatval($telbalresponse), 3);
115
-        curl_close($ch);
116
-
117
-        return $currentbalancetel;
118
-    }
119
-
120
-
121
-    /**
122
-     * @NoAdminRequired
123
-     */
124
-    public function getbalancenex($userId) {
125
-
126
-        $smsapicred = $this->service->getapicredentials($this->userId);
127
-        $smsapikey = $smsapicred[5];
128
-        $smsapisecret = $smsapicred[6];
129
-
130
-        if ($smsapikey == '' || $smsapisecret == '') {
131
-            $currentbalancenex = "N/A";
132
-        } else {
133
-            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
134
-            $mesdata = file_get_contents($getmesdata);
135
-            $datainit = json_decode($mesdata);
136
-            $balancenex = $datainit->cash_credits;
137
-            $currentbalancenex = round(floatval($balancenex), 3);
138
-        }
139
-        return $currentbalancenex;
140
-    }
141
-
142
-
143
-    /**
144
-     * @NoAdminRequired
145
-     */
146
-    public function getsmsnumbers($userId) {
147
-
148
-        $smsapicred = $this->service->getapicredentials($this->userId);
149
-
150
-        $telnyxkey = $smsapicred[0];
151
-
152
-        $nexapikey = $smsapicred[5];
153
-        $nexapisecret = $smsapicred[6];
154
-
155
-        $telsendernameinit = $smsapicred[9];
156
-        $nexsendernameinit = $smsapicred[10];
157
-        $telsendername = "T: " . $telsendernameinit;
158
-        $nexsendername = "P: " . $nexsendernameinit;
159
-
160
-        if ($telnyxkey != '') {
161
-
162
-           \Telnyx\Telnyx::setApiKey($telnyxkey);
163
-           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
164
-
165
-           $telnumbersarr = $this->object_to_array($telnumbers);
166
-           $telnmbrs = [];
167
-
168
-           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
169
-              if (is_int($nmbkey)) {
170
-                 foreach ($nmbvalue as $nkey => $nvalue) {
171
-                    if ($nkey == 'phone_number') {
172
-                       $telnmbrs[] = "T: " . $nvalue;
173
-                    }
174
-                 }
175
-              }
176
-           }
177
-
178
-        } else { $telnmbrs = []; }
179
-
180
-        if ($nexapikey != '' && $nexapisecret != '') {
181
-
182
-           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
183
-           $acdata = file_get_contents($getacdata);
184
-           $datainit = json_decode($acdata, true);
185
-
186
-           $findata = $this->object_to_array($datainit);
187
-
188
-           $nexcurrentnmbrs = [];
189
-
190
-           foreach ($findata['objects'] as $smskey => $smsvalue) {
191
-                   if (is_array($smsvalue)) {
192
-                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
193
-                               if ($smskey2 == 'number') {
194
-                                   $nexcurrentnmbrs[] = "P: +" . $smsvalue2;
195
-                               }
196
-                         }
197
-                   }
198
-           }
199
-
200
-
201
-        } else { $nexcurrentnmbrs = []; }
202
-
203
-        $telsenderarr = [0 => $telsendername];
204
-        $nexsenderarr = [0 => $nexsendername];
205
-        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $telsenderarr, $nexsenderarr);
206
-
207
-        return $currentnmbrs;
208
-    }
209
-
210
-
211
-    /**
212
-     * @NoAdminRequired
213
-     */
214
-    public function cleantempdir($userId) {
215
-
216
-        // Create the temporary folder if it doesn't exist
217
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
218
-            $this->folder->newFolder('SMS_Relentless/temp_files');
219
-        }
220
-        $targetdir = "data/" . $this->userId . "/files/SMS_Relentless/temp_files";
221
-        $fileSystemIterator = new FilesystemIterator($targetdir);
222
-
223
-        $dirfiles = [];
224
-        foreach ($fileSystemIterator as $fileInfo){
225
-                 $dirfiles[] = $fileInfo->getFilename();
226
-        }
227
-
228
-        foreach ($dirfiles as $key => $indfile) {
229
-                 $thisuserroot = $this->view->getRoot();
230
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
231
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
232
-        }
233
-     }
234
-
235
-
236
-    /**
237
-     * @NoAdminRequired
238
-     */
239
-    public function uploadNumbersFile($userId, $uploadfileforsms) {
240
-
241
-        // Create the temporary folder if it doesn't exist
242
-        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
243
-            $this->folder->newFolder('SMS_Relentless/temp_files');
244
-        }
245
-
246
-        // First delete any file that has been previously uploaded
247
-        $targetdir = "data/" . $this->userId . "/files/SMS_Relentless/temp_files";
248
-        $fileSystemIterator = new FilesystemIterator($targetdir);
249
-
250
-        $dirfiles = [];
251
-        foreach ($fileSystemIterator as $fileInfo){
252
-                 $dirfiles[] = $fileInfo->getFilename();
253
-        }
254
-
255
-        foreach ($dirfiles as $key => $indfile) {
256
-                 $thisuserroot = $this->view->getRoot();
257
-                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
258
-                 $removetmpfile = $this->filesystem->unlink($tempfile);
259
-        }
260
-
261
-        // Upload the new file
262
-        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
263
-        $fileName = $_FILES['uploadfileforsms']['name'];
264
-
265
-        $userroot = $this->view->getRoot();
266
-        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
267
-
268
-        $target = $this->folder->newFile($targetfile);
269
-        $target->putContent($fileContent);
270
-
271
-        // Extract the phone numbers from the file
272
-        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
273
-        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
274
-        $numberarrayfourth = explode(",", $numberarraytert);
275
-        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
276
-        $numberarray = array_unique($numberarrayfifth);
277
-
278
-        return $numberarray;
279
-
280
-    }
281
-
282
-
283
-    /**
284
-     * @NoAdminRequired
285
-     */
286
-    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
287
-
288
-         $telsmsapicred = $this->service->getapicredentials($this->userId);
289
-         $telnyxkey = $telsmsapicred[0];
290
-         $teldelrecurl = $telsmsapicred[3];
291
-         $messagingprofid = $telsmsapicred[4];
292
-
293
-         \Telnyx\Telnyx::setApiKey($telnyxkey);
294
-
295
-         $microinterval = $waitinterval * 1000;
296
-
297
-         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
298
-
299
-             usleep($microinterval);
300
-
301
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
302
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding, "messaging_profile_id" => $messagingprofid]);
303
-             } else {
304
-                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding]);
305
-             }
306
-
307
-             $messageid = $message['id'];
308
-             $messagedate = date("Y-m-d H:i:s");
309
-             $messagefrom = "Telnyx: " . $fromsender;
310
-             $messageto = $tonumber;
311
-             $messagenetwork = null;
312
-             $messageprice = null;
313
-             $messagestatus = $message['to'][0]['status'];
314
-             $messagedelivery = null;
315
-             $messagetext = str_replace("'", "\'", $sentsmstext);
316
-
317
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
318
-
319
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
320
-
321
-         }
322
-    }
323
-
324
-
325
-    /**
326
-     * @NoAdminRequired
327
-     */
328
-    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
329
-
330
-         $smsapicred = $this->service->getapicredentials($this->userId);
331
-
332
-         $smsapikey = $smsapicred[5];
333
-         $smsapisecret = $smsapicred[6];
334
-         $smsapideliveryrecurl = $smsapicred[8];
335
-
336
-         $microinterval = $waitinterval * 1000;
337
-
338
-         $client = new RestClient($smsapikey, $smsapisecret);
339
-
340
-         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
341
-
342
-             usleep($microinterval);
343
-
344
-             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
345
-
346
-	     $messageidinit = $response->getmessageUuid(0);
347
-             $messageid = $messageidinit[0];
348
-
349
-             $messagedate = date("Y-m-d H:i:s");
350
-
351
-             if (preg_match('/[A-Za-z]+/', $fromsender)) {
352
-                 $messagefrom = "Plivo: " . $fromsender;
353
-             } else { $messagefrom = "Plivo: +" . $fromsender; }
354
-
355
-             $messageto = $tonumber;
356
-             $messagenetwork = null;
357
-             $messageprice = null;
358
-             $messagestatus = "The message has been accepted for delivery.";
359
-             $messagedelivery = null;
360
-             $messagetext = str_replace("'", "\'", $sentsmstext);
361
-
362
-             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
363
-
364
-             $this->service->insertsentsms($this->userId, $sentmessagearr);
365
-         }
366
-    }
367
-
368
-
369
-    /**
370
-     * @NoAdminRequired
371
-     */
372
-    public function saveoldrecrows($userId, $oldrecRows) {
373
-
374
-           // Create the folder for removed messages if it doesn't exist
375
-           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
376
-               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
377
-           }
378
-           $savecheck = 0;
379
-
380
-           if (count($oldrecRows) > 1) {
381
-               $msfileContent = implode("", $oldrecRows);
382
-
383
-               $delrowsdate = date("Y-m-d_H-i-s");
384
-               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
385
-
386
-               $userroot = $this->view->getRoot();
387
-               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
388
-
389
-               $target = $this->folder->newFile($targetfile);
390
-               $target->putContent($msfileContent);
391
-
392
-               if ($this->filesystem->file_get_contents($targetfile) != '') {
393
-                   $savecheck = 1;
394
-               }
395
-           }
396
-
397
-           return $savecheck;
398
-    }
399
-
400
-
401
-    /**
402
-     * @NoAdminRequired
403
-     */
404
-    public function saveoldsentrows($userId, $oldsentRows) {
405
-
406
-           // Create the folder for removed messages if it doesn't exist
407
-           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
408
-               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
409
-           }
410
-           $savesentcheck = 0;
411
-
412
-           if (count($oldsentRows) > 1) {
413
-               $sntfileContent = implode("", $oldsentRows);
414
-
415
-               $delsentrowsdate = date("Y-m-d_H-i-s");
416
-               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
417
-
418
-               $userroot = $this->view->getRoot();
419
-               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
420
-
421
-               $snttarget = $this->folder->newFile($snttargetfile);
422
-               $snttarget->putContent($sntfileContent);
423
-
424
-               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
425
-                   $savesentcheck = 1;
426
-               }
427
-           }
428
-
429
-           return $savesentcheck;
430
-    }
431
-
432
-
433
-    /**
434
-     * @NoAdminRequired
435
-     */
436
-    public function getreceivedtable($userId) {
437
-           return $this->service->getreceivedtable($this->userId);
438
-    }
439
-
440
-    /**
441
-     * @NoAdminRequired
442
-     */
443
-    public function getreceivedtablefordel($userId) {
444
-           return $this->service->getreceivedtablefordel($this->userId);
445
-    }
446
-
447
-    /**
448
-     * @NoAdminRequired
449
-     */
450
-    public function removerecrows($userId, $recmessagedbIDs) {
451
-           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
452
-    }
453
-
454
-    /**
455
-     * @NoAdminRequired
456
-     */
457
-    public function getsenttable($userId) {
458
-           return $this->service->getsenttable($this->userId);
459
-    }
460
-
461
-    /**
462
-     * @NoAdminRequired
463
-     */
464
-    public function getsenttablefordel($userId) {
465
-           return $this->service->getsenttablefordel($this->userId);
466
-    }
467
-
468
-    /**
469
-     * @NoAdminRequired
470
-     */
471
-    public function removesentrows($userId, $sentmessagedbIDs) {
472
-           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
473
-    }
474
-
475
-    /**
476
-     * @NoAdminRequired
477
-     */
478
-    public function getmessagesperpage($userId) {
479
-           return $this->service->getmessagesperpage($this->userId);
480
-    }
481
-
482
-    /**
483
-     * @NoAdminRequired
484
-     */
485
-    public function getdelrecsettings($userId) {
486
-           return $this->service->getdelrecsettings($this->userId);
487
-    }
488
-
489
-    /**
490
-     * @NoAdminRequired
491
-     */
492
-    public function getsettings($userId) {
493
-           return $this->service->getsettings($this->userId);
494
-    }
495
-
496
-    /**
497
-     * @NoAdminRequired
498
-     */
499
-    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail) {
500
-           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail);
501
-    }
502
-
503
-}
Browse code

Created repository.

DoubleBastionAdmin authored on 01/03/2022 23:47:00
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,503 @@
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\SMSRelentless\Controller;
27
+
28
+use OCP\IRequest;
29
+use OCP\AppFramework\Controller;
30
+use OCA\SMSRelentless\Service\SmsrelentlessService;
31
+use OCP\AppFramework\App;
32
+use OC\Http\Client\Client;
33
+use OCP\Files\SimpleFS\ISimpleFile;
34
+use OCP\Files\SimpleFS\ISimpleFolder;
35
+use OCP\IL10N;
36
+use OCP\Files\Folder;
37
+use OC\Files\Filesystem;
38
+use OC\Files\View;
39
+use \ReflectionClass;
40
+use \FilesystemIterator;
41
+use \DateTime;
42
+use OCP\AppFramework\Http\DataResponse;
43
+use OCP\Files\NotFoundException;
44
+use OCP\Files\NotPermittedException;
45
+use Plivo\RestClient;
46
+
47
+
48
+class SmsrelentlessController extends Controller {
49
+
50
+    private $service;
51
+    private $userId;
52
+    private $folder;
53
+    private $filesystem;
54
+    private $view;
55
+
56
+    public function __construct($appName, IRequest $request, SmsrelentlessService $service, Folder $folder, Filesystem $filesystem, $userId, View $view) {
57
+        parent::__construct($appName, $request);
58
+        $this->service = $service;
59
+        $this->userId = $userId;
60
+        $this->folder = $folder;
61
+        $this->filesystem = $filesystem;
62
+        $this->view = $view;
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
+    public function getbalancetel($userId) {
101
+
102
+        $telsmsapicred = $this->service->getapicredentials($this->userId);
103
+
104
+        $telapikey = $telsmsapicred[0];
105
+        $ch = curl_init();
106
+        $headerstel = array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer ".$telapikey);
107
+
108
+        curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
109
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
110
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerstel);
111
+        $responsetel = curl_exec($ch);
112
+        $recdatatel = json_decode($responsetel, TRUE);
113
+        $telbalresponse = $recdatatel['data']['balance'];
114
+        $currentbalancetel = round(floatval($telbalresponse), 3);
115
+        curl_close($ch);
116
+
117
+        return $currentbalancetel;
118
+    }
119
+
120
+
121
+    /**
122
+     * @NoAdminRequired
123
+     */
124
+    public function getbalancenex($userId) {
125
+
126
+        $smsapicred = $this->service->getapicredentials($this->userId);
127
+        $smsapikey = $smsapicred[5];
128
+        $smsapisecret = $smsapicred[6];
129
+
130
+        if ($smsapikey == '' || $smsapisecret == '') {
131
+            $currentbalancenex = "N/A";
132
+        } else {
133
+            $getmesdata = "https://".$smsapikey.":".$smsapisecret."@api.plivo.com/v1/Account/".$smsapikey."/";
134
+            $mesdata = file_get_contents($getmesdata);
135
+            $datainit = json_decode($mesdata);
136
+            $balancenex = $datainit->cash_credits;
137
+            $currentbalancenex = round(floatval($balancenex), 3);
138
+        }
139
+        return $currentbalancenex;
140
+    }
141
+
142
+
143
+    /**
144
+     * @NoAdminRequired
145
+     */
146
+    public function getsmsnumbers($userId) {
147
+
148
+        $smsapicred = $this->service->getapicredentials($this->userId);
149
+
150
+        $telnyxkey = $smsapicred[0];
151
+
152
+        $nexapikey = $smsapicred[5];
153
+        $nexapisecret = $smsapicred[6];
154
+
155
+        $telsendernameinit = $smsapicred[9];
156
+        $nexsendernameinit = $smsapicred[10];
157
+        $telsendername = "T: " . $telsendernameinit;
158
+        $nexsendername = "P: " . $nexsendernameinit;
159
+
160
+        if ($telnyxkey != '') {
161
+
162
+           \Telnyx\Telnyx::setApiKey($telnyxkey);
163
+           $telnumbers = \Telnyx\MessagingPhoneNumber::All();
164
+
165
+           $telnumbersarr = $this->object_to_array($telnumbers);
166
+           $telnmbrs = [];
167
+
168
+           foreach ($telnumbersarr['_originalValues'] as $nmbkey => $nmbvalue) {
169
+              if (is_int($nmbkey)) {
170
+                 foreach ($nmbvalue as $nkey => $nvalue) {
171
+                    if ($nkey == 'phone_number') {
172
+                       $telnmbrs[] = "T: " . $nvalue;
173
+                    }
174
+                 }
175
+              }
176
+           }
177
+
178
+        } else { $telnmbrs = []; }
179
+
180
+        if ($nexapikey != '' && $nexapisecret != '') {
181
+
182
+           $getacdata = "https://".$nexapikey.":".$nexapisecret."@api.plivo.com/v1/Account/".$nexapikey."/Number/";
183
+           $acdata = file_get_contents($getacdata);
184
+           $datainit = json_decode($acdata, true);
185
+
186
+           $findata = $this->object_to_array($datainit);
187
+
188
+           $nexcurrentnmbrs = [];
189
+
190
+           foreach ($findata['objects'] as $smskey => $smsvalue) {
191
+                   if (is_array($smsvalue)) {
192
+                         foreach ($smsvalue as $smskey2 => $smsvalue2) {
193
+                               if ($smskey2 == 'number') {
194
+                                   $nexcurrentnmbrs[] = "P: +" . $smsvalue2;
195
+                               }
196
+                         }
197
+                   }
198
+           }
199
+
200
+
201
+        } else { $nexcurrentnmbrs = []; }
202
+
203
+        $telsenderarr = [0 => $telsendername];
204
+        $nexsenderarr = [0 => $nexsendername];
205
+        $currentnmbrs = array_merge($telnmbrs, $nexcurrentnmbrs, $telsenderarr, $nexsenderarr);
206
+
207
+        return $currentnmbrs;
208
+    }
209
+
210
+
211
+    /**
212
+     * @NoAdminRequired
213
+     */
214
+    public function cleantempdir($userId) {
215
+
216
+        // Create the temporary folder if it doesn't exist
217
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
218
+            $this->folder->newFolder('SMS_Relentless/temp_files');
219
+        }
220
+        $targetdir = "data/" . $this->userId . "/files/SMS_Relentless/temp_files";
221
+        $fileSystemIterator = new FilesystemIterator($targetdir);
222
+
223
+        $dirfiles = [];
224
+        foreach ($fileSystemIterator as $fileInfo){
225
+                 $dirfiles[] = $fileInfo->getFilename();
226
+        }
227
+
228
+        foreach ($dirfiles as $key => $indfile) {
229
+                 $thisuserroot = $this->view->getRoot();
230
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
231
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
232
+        }
233
+     }
234
+
235
+
236
+    /**
237
+     * @NoAdminRequired
238
+     */
239
+    public function uploadNumbersFile($userId, $uploadfileforsms) {
240
+
241
+        // Create the temporary folder if it doesn't exist
242
+        if ($this->folder->nodeExists('SMS_Relentless/temp_files') == false) {
243
+            $this->folder->newFolder('SMS_Relentless/temp_files');
244
+        }
245
+
246
+        // First delete any file that has been previously uploaded
247
+        $targetdir = "data/" . $this->userId . "/files/SMS_Relentless/temp_files";
248
+        $fileSystemIterator = new FilesystemIterator($targetdir);
249
+
250
+        $dirfiles = [];
251
+        foreach ($fileSystemIterator as $fileInfo){
252
+                 $dirfiles[] = $fileInfo->getFilename();
253
+        }
254
+
255
+        foreach ($dirfiles as $key => $indfile) {
256
+                 $thisuserroot = $this->view->getRoot();
257
+                 $tempfile = $thisuserroot . "/SMS_Relentless/temp_files/" . $indfile;
258
+                 $removetmpfile = $this->filesystem->unlink($tempfile);
259
+        }
260
+
261
+        // Upload the new file
262
+        $fileContent = file_get_contents($_FILES['uploadfileforsms']['tmp_name']);
263
+        $fileName = $_FILES['uploadfileforsms']['name'];
264
+
265
+        $userroot = $this->view->getRoot();
266
+        $targetfile = $userroot . "/SMS_Relentless/temp_files/" . $fileName;
267
+
268
+        $target = $this->folder->newFile($targetfile);
269
+        $target->putContent($fileContent);
270
+
271
+        // Extract the phone numbers from the file
272
+        $numberarraysec = str_replace(array(";", "|", "\r\n", "\r", "\n", "\t"), ",", $fileContent);
273
+        $numberarraytert = preg_replace("/[^0-9,]/", "", $numberarraysec);
274
+        $numberarrayfourth = explode(",", $numberarraytert);
275
+        $numberarrayfifth = array_filter(array_map('trim', $numberarrayfourth));
276
+        $numberarray = array_unique($numberarrayfifth);
277
+
278
+        return $numberarray;
279
+
280
+    }
281
+
282
+
283
+    /**
284
+     * @NoAdminRequired
285
+     */
286
+    public function sendsmstel($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
287
+
288
+         $telsmsapicred = $this->service->getapicredentials($this->userId);
289
+         $telnyxkey = $telsmsapicred[0];
290
+         $teldelrecurl = $telsmsapicred[3];
291
+         $messagingprofid = $telsmsapicred[4];
292
+
293
+         \Telnyx\Telnyx::setApiKey($telnyxkey);
294
+
295
+         $microinterval = $waitinterval * 1000;
296
+
297
+         foreach ($receiversPhoneNbs as $keytel => $tonumber) {
298
+
299
+             usleep($microinterval);
300
+
301
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
302
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding, "messaging_profile_id" => $messagingprofid]);
303
+             } else {
304
+                 $message = \Telnyx\Message::Create(["from" => $fromsender, "to" => $tonumber, "text" => $sentsmstext, "webhook_url" => $teldelrecurl, "encoding" => $encoding]);
305
+             }
306
+
307
+             $messageid = $message['id'];
308
+             $messagedate = date("Y-m-d H:i:s");
309
+             $messagefrom = "Telnyx: " . $fromsender;
310
+             $messageto = $tonumber;
311
+             $messagenetwork = null;
312
+             $messageprice = null;
313
+             $messagestatus = $message['to'][0]['status'];
314
+             $messagedelivery = null;
315
+             $messagetext = str_replace("'", "\'", $sentsmstext);
316
+
317
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
318
+
319
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
320
+
321
+         }
322
+    }
323
+
324
+
325
+    /**
326
+     * @NoAdminRequired
327
+     */
328
+    public function sendsmsnex($userId, $receiversPhoneNbs, $fromsender, $waitinterval, $encoding, $sentsmstext) {
329
+
330
+         $smsapicred = $this->service->getapicredentials($this->userId);
331
+
332
+         $smsapikey = $smsapicred[5];
333
+         $smsapisecret = $smsapicred[6];
334
+         $smsapideliveryrecurl = $smsapicred[8];
335
+
336
+         $microinterval = $waitinterval * 1000;
337
+
338
+         $client = new RestClient($smsapikey, $smsapisecret);
339
+
340
+         foreach ($receiversPhoneNbs as $keynex => $tonumber) {
341
+
342
+             usleep($microinterval);
343
+
344
+             $response = $client->messages->create($fromsender,[$tonumber],$sentsmstext,["url" => $smsapideliveryrecurl],);
345
+
346
+	     $messageidinit = $response->getmessageUuid(0);
347
+             $messageid = $messageidinit[0];
348
+
349
+             $messagedate = date("Y-m-d H:i:s");
350
+
351
+             if (preg_match('/[A-Za-z]+/', $fromsender)) {
352
+                 $messagefrom = "Plivo: " . $fromsender;
353
+             } else { $messagefrom = "Plivo: +" . $fromsender; }
354
+
355
+             $messageto = $tonumber;
356
+             $messagenetwork = null;
357
+             $messageprice = null;
358
+             $messagestatus = "The message has been accepted for delivery.";
359
+             $messagedelivery = null;
360
+             $messagetext = str_replace("'", "\'", $sentsmstext);
361
+
362
+             $sentmessagearr = [$messageid, $messagedate, $messagefrom, $messageto, $messagenetwork, $messageprice, $messagestatus, $messagedelivery, $messagetext];
363
+
364
+             $this->service->insertsentsms($this->userId, $sentmessagearr);
365
+         }
366
+    }
367
+
368
+
369
+    /**
370
+     * @NoAdminRequired
371
+     */
372
+    public function saveoldrecrows($userId, $oldrecRows) {
373
+
374
+           // Create the folder for removed messages if it doesn't exist
375
+           if ($this->folder->nodeExists('SMS_Relentless/removed_received_messages') == false) {
376
+               $this->folder->newFolder('SMS_Relentless/removed_received_messages');
377
+           }
378
+           $savecheck = 0;
379
+
380
+           if (count($oldrecRows) > 1) {
381
+               $msfileContent = implode("", $oldrecRows);
382
+
383
+               $delrowsdate = date("Y-m-d_H-i-s");
384
+               $msfileName = "Received_Messages_Deleted_On_" . $delrowsdate . ".csv";
385
+
386
+               $userroot = $this->view->getRoot();
387
+               $targetfile = $userroot . "/SMS_Relentless/removed_received_messages/" . $msfileName;
388
+
389
+               $target = $this->folder->newFile($targetfile);
390
+               $target->putContent($msfileContent);
391
+
392
+               if ($this->filesystem->file_get_contents($targetfile) != '') {
393
+                   $savecheck = 1;
394
+               }
395
+           }
396
+
397
+           return $savecheck;
398
+    }
399
+
400
+
401
+    /**
402
+     * @NoAdminRequired
403
+     */
404
+    public function saveoldsentrows($userId, $oldsentRows) {
405
+
406
+           // Create the folder for removed messages if it doesn't exist
407
+           if ($this->folder->nodeExists('SMS_Relentless/removed_sent_messages') == false) {
408
+               $this->folder->newFolder('SMS_Relentless/removed_sent_messages');
409
+           }
410
+           $savesentcheck = 0;
411
+
412
+           if (count($oldsentRows) > 1) {
413
+               $sntfileContent = implode("", $oldsentRows);
414
+
415
+               $delsentrowsdate = date("Y-m-d_H-i-s");
416
+               $sntfileName = "Sent_Messages_Deleted_On_" . $delsentrowsdate . ".csv";
417
+
418
+               $userroot = $this->view->getRoot();
419
+               $snttargetfile = $userroot . "/SMS_Relentless/removed_sent_messages/" . $sntfileName;
420
+
421
+               $snttarget = $this->folder->newFile($snttargetfile);
422
+               $snttarget->putContent($sntfileContent);
423
+
424
+               if ($this->filesystem->file_get_contents($snttargetfile) != '') {
425
+                   $savesentcheck = 1;
426
+               }
427
+           }
428
+
429
+           return $savesentcheck;
430
+    }
431
+
432
+
433
+    /**
434
+     * @NoAdminRequired
435
+     */
436
+    public function getreceivedtable($userId) {
437
+           return $this->service->getreceivedtable($this->userId);
438
+    }
439
+
440
+    /**
441
+     * @NoAdminRequired
442
+     */
443
+    public function getreceivedtablefordel($userId) {
444
+           return $this->service->getreceivedtablefordel($this->userId);
445
+    }
446
+
447
+    /**
448
+     * @NoAdminRequired
449
+     */
450
+    public function removerecrows($userId, $recmessagedbIDs) {
451
+           return $this->service->removerecrows($this->userId, $recmessagedbIDs);
452
+    }
453
+
454
+    /**
455
+     * @NoAdminRequired
456
+     */
457
+    public function getsenttable($userId) {
458
+           return $this->service->getsenttable($this->userId);
459
+    }
460
+
461
+    /**
462
+     * @NoAdminRequired
463
+     */
464
+    public function getsenttablefordel($userId) {
465
+           return $this->service->getsenttablefordel($this->userId);
466
+    }
467
+
468
+    /**
469
+     * @NoAdminRequired
470
+     */
471
+    public function removesentrows($userId, $sentmessagedbIDs) {
472
+           return $this->service->removesentrows($this->userId, $sentmessagedbIDs);
473
+    }
474
+
475
+    /**
476
+     * @NoAdminRequired
477
+     */
478
+    public function getmessagesperpage($userId) {
479
+           return $this->service->getmessagesperpage($this->userId);
480
+    }
481
+
482
+    /**
483
+     * @NoAdminRequired
484
+     */
485
+    public function getdelrecsettings($userId) {
486
+           return $this->service->getdelrecsettings($this->userId);
487
+    }
488
+
489
+    /**
490
+     * @NoAdminRequired
491
+     */
492
+    public function getsettings($userId) {
493
+           return $this->service->getsettings($this->userId);
494
+    }
495
+
496
+    /**
497
+     * @NoAdminRequired
498
+     */
499
+    public function updatesettings($userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail) {
500
+           return $this->service->updatesettings($this->userId, $telapiKey, $telPubKey, $telapiUrlRec, $telapiUrl, $messagingProfileId, $nexapiKey, $nexapiSecret, $nexapiUrlRec, $nexapiUrl, $telSenderName, $nexSenderName, $messagesperpage, $getNotify, $notificationEmail, $getsmsinemail);
501
+    }
502
+
503
+}