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,558 @@
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\Migration;
27
+
28
+use Closure;
29
+use OCP\DB\Types;
30
+use OCP\DB\ISchemaWrapper;
31
+use OCP\IDBConnection;
32
+use OCP\Migration\IOutput;
33
+use OCP\Migration\SimpleMigrationStep;
34
+
35
+
36
+class Version125Date20230603224815 extends SimpleMigrationStep {
37
+
38
+        /** @var IDBConnection */
39
+        private $connection;
40
+
41
+        /**
42
+         * @param IDBConnection $connection
43
+         */
44
+        public function __construct(IDBConnection $connection) {
45
+                $this->connection = $connection;
46
+        }
47
+
48
+	/**
49
+	 * @param IOutput $output
50
+	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
51
+	 * @param array $options
52
+	 * @return null|ISchemaWrapper
53
+	 */
54
+	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
55
+		/** @var ISchemaWrapper $schema */
56
+		$schema = $schemaClosure();
57
+
58
+		if (!$schema->hasTable('sms_relent_settings')) {
59
+			$table = $schema->createTable('sms_relent_settings');
60
+			$table->addColumn('id', Types::BIGINT, [
61
+				'autoincrement' => true,
62
+				'notnull' => true,
63
+                                'length' => 11,
64
+                                'unsigned' => true,
65
+			]);
66
+			$table->addColumn('user_id', Types::STRING, [
67
+				'notnull' => true,
68
+				'length' => 128,
69
+			]);
70
+			$table->addColumn('telapi_key', Types::STRING, [
71
+				'notnull' => true,
72
+				'length' => 512,
73
+			]);
74
+			$table->addColumn('tel_pub_key', Types::STRING, [
75
+				'notnull' => true,
76
+				'length' => 512,
77
+			]);
78
+			$table->addColumn('telapi_url_rec', Types::STRING, [
79
+				'notnull' => true,
80
+				'length' => 512,
81
+			]);
82
+			$table->addColumn('telapi_url', Types::STRING, [
83
+				'notnull' => true,
84
+				'length' => 512,
85
+			]);
86
+			$table->addColumn('messaging_profile_id', Types::STRING, [
87
+				'notnull' => true,
88
+				'length' => 512,
89
+			]);
90
+			$table->addColumn('nexapi_key', Types::STRING, [
91
+				'notnull' => true,
92
+				'length' => 512,
93
+			]);
94
+			$table->addColumn('nexapi_secret', Types::STRING, [
95
+				'notnull' => true,
96
+				'length' => 512,
97
+			]);
98
+			$table->addColumn('nexapi_url_rec', Types::STRING, [
99
+				'notnull' => true,
100
+				'length' => 512,
101
+			]);
102
+			$table->addColumn('nexapi_url', Types::STRING, [
103
+				'notnull' => true,
104
+				'length' => 512,
105
+			]);
106
+			$table->addColumn('twilapi_key', Types::STRING, [
107
+				'notnull' => true,
108
+				'length' => 512,
109
+			]);
110
+			$table->addColumn('twilapi_secret', Types::STRING, [
111
+				'notnull' => true,
112
+				'length' => 512,
113
+			]);
114
+			$table->addColumn('twilapi_url_rec', Types::STRING, [
115
+				'notnull' => true,
116
+				'length' => 512,
117
+			]);
118
+			$table->addColumn('twilapi_url', Types::STRING, [
119
+				'notnull' => true,
120
+				'length' => 512,
121
+			]);
122
+			$table->addColumn('flowapi_key', Types::STRING, [
123
+				'notnull' => true,
124
+				'length' => 512,
125
+			]);
126
+			$table->addColumn('flowapi_secret', Types::STRING, [
127
+				'notnull' => true,
128
+				'length' => 512,
129
+			]);
130
+			$table->addColumn('flowapi_url_rec', Types::STRING, [
131
+				'notnull' => true,
132
+				'length' => 512,
133
+			]);
134
+			$table->addColumn('flowapi_url', Types::STRING, [
135
+				'notnull' => true,
136
+				'length' => 512,
137
+			]);
138
+			$table->addColumn('tel_sender_name', Types::STRING, [
139
+				'notnull' => false,
140
+				'length' => 48,
141
+				'default' => '',
142
+			]);
143
+			$table->addColumn('nex_sender_name', Types::STRING, [
144
+				'notnull' => false,
145
+				'length' => 48,
146
+				'default' => '',
147
+			]);
148
+			$table->addColumn('twil_sender_name', Types::STRING, [
149
+				'notnull' => false,
150
+				'length' => 48,
151
+				'default' => '',
152
+			]);
153
+			$table->addColumn('flow_sender_name', Types::STRING, [
154
+				'notnull' => false,
155
+				'length' => 48,
156
+				'default' => '',
157
+			]);
158
+			$table->addColumn('messagesperpage', Types::INTEGER, [
159
+				'notnull' => false,
160
+				'length' => 11,
161
+                                'unsigned' => true,
162
+			]);
163
+			$table->addColumn('get_notify', Types::SMALLINT, [
164
+				'notnull' => false,
165
+				'length' => 1,
166
+			]);
167
+			$table->addColumn('notification_email', Types::STRING, [
168
+				'notnull' => false,
169
+				'length' => 512,
170
+				'default' => '',
171
+			]);
172
+			$table->addColumn('getsmsinemail', Types::SMALLINT, [
173
+				'notnull' => false,
174
+				'length' => 1,
175
+			]);
176
+			$table->addColumn('show_all_messages', Types::SMALLINT, [
177
+				'notnull' => false,
178
+				'length' => 1,
179
+			]);
180
+			$table->addColumn('show_display_names', Types::SMALLINT, [
181
+				'notnull' => false,
182
+				'length' => 1,
183
+			]);
184
+			$table->addColumn('add_display_names', Types::SMALLINT, [
185
+				'notnull' => false,
186
+				'length' => 1,
187
+			]);
188
+                        $table->setPrimaryKey(['id']);
189
+                        $table->addUniqueIndex(['id']);
190
+
191
+		} else {
192
+
193
+                        $table = $schema->getTable('sms_relent_settings');
194
+
195
+			$table->addColumn('add_display_names', Types::SMALLINT, [
196
+				'notnull' => false,
197
+				'length' => 1,
198
+			]);
199
+                }
200
+
201
+
202
+		if (!$schema->hasTable('sms_relent_received')) {
203
+			$table = $schema->createTable('sms_relent_received');
204
+			$table->addColumn('id', Types::BIGINT, [
205
+				'autoincrement' => true,
206
+				'notnull' => true,
207
+                                'length' => 11,
208
+                                'unsigned' => true,
209
+			]);
210
+			$table->addColumn('user_id', Types::STRING, [
211
+				'notnull' => true,
212
+				'length' => 64,
213
+			]);
214
+			$table->addColumn('message_id', Types::STRING, [
215
+				'notnull' => true,
216
+				'length' => 512,
217
+			]);
218
+			$table->addColumn('date', Types::DATETIME, [
219
+				'notnull' => true,
220
+			]);
221
+			$table->addColumn('from', Types::STRING, [
222
+				'notnull' => true,
223
+				'length' => 128,
224
+			]);
225
+			$table->addColumn('to', Types::STRING, [
226
+				'notnull' => true,
227
+				'length' => 128,
228
+			]);
229
+			$table->addColumn('message', Types::TEXT, [
230
+				'notnull' => false,
231
+				'default' => '',
232
+			]);
233
+			$table->addColumn('author_displayname', Types::STRING, [
234
+				'notnull' => true,
235
+				'length' => 255,
236
+			]);
237
+			$table->addColumn('internal_sender', Types::SMALLINT, [
238
+				'notnull' => false,
239
+				'length' => 1,
240
+			]);
241
+                        $table->setPrimaryKey(['id']);
242
+                        $table->addUniqueIndex(['id']);
243
+
244
+		}
245
+
246
+
247
+		if (!$schema->hasTable('sms_relent_sent')) {
248
+			$table = $schema->createTable('sms_relent_sent');
249
+			$table->addColumn('id', Types::BIGINT, [
250
+				'autoincrement' => true,
251
+				'notnull' => true,
252
+                                'length' => 11,
253
+                                'unsigned' => true,
254
+			]);
255
+			$table->addColumn('user_id', Types::STRING, [
256
+				'notnull' => true,
257
+				'length' => 64,
258
+			]);
259
+			$table->addColumn('message_id', Types::STRING, [
260
+				'notnull' => true,
261
+				'length' => 512,
262
+			]);
263
+			$table->addColumn('date', Types::DATETIME, [
264
+				'notnull' => true,
265
+			]);
266
+			$table->addColumn('from', Types::STRING, [
267
+				'notnull' => true,
268
+				'length' => 128,
269
+			]);
270
+			$table->addColumn('to', Types::STRING, [
271
+				'notnull' => true,
272
+				'length' => 128,
273
+			]);
274
+			$table->addColumn('network ', Types::STRING, [
275
+				'notnull' => false,
276
+				'length' => 64,
277
+				'default' => '',
278
+			]);
279
+			$table->addColumn('price', Types::STRING, [
280
+				'notnull' => false,
281
+				'length' => 64,
282
+				'default' => '',
283
+			]);
284
+			$table->addColumn('status', Types::STRING, [
285
+				'notnull' => false,
286
+				'length' => 512,
287
+				'default' => '',
288
+			]);
289
+			$table->addColumn('deliveryreceipt', Types::STRING, [
290
+				'notnull' => false,
291
+				'length' => 64,
292
+				'default' => '',
293
+			]);
294
+			$table->addColumn('message', Types::TEXT, [
295
+				'notnull' => false,
296
+                                'default' => '',
297
+			]);
298
+			$table->addColumn('author_displayname', Types::STRING, [
299
+				'notnull' => true,
300
+				'length' => 255,
301
+			]);
302
+                        $table->setPrimaryKey(['id']);
303
+                        $table->addUniqueIndex(['id']);
304
+
305
+		}
306
+
307
+
308
+		if (!$schema->hasTable('sms_relent_autorply')) {
309
+			$table = $schema->createTable('sms_relent_autorply');
310
+			$table->addColumn('id', Types::BIGINT, [
311
+				'autoincrement' => true,
312
+				'notnull' => true,
313
+                                'length' => 11,
314
+                                'unsigned' => true,
315
+			]);
316
+			$table->addColumn('user_id', Types::STRING, [
317
+				'notnull' => true,
318
+				'length' => 128,
319
+			]);
320
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
321
+				'notnull' => true,
322
+				'length' => 255,
323
+			]);
324
+			$table->addColumn('phone_number', Types::STRING, [
325
+				'notnull' => true,
326
+				'length' => 128,
327
+			]);
328
+			$table->addColumn('days_of_week', Types::STRING, [
329
+				'notnull' => false,
330
+				'length' => 64,
331
+                                'default' => '',
332
+			]);
333
+			$table->addColumn('daily_start', Types::STRING, [
334
+				'notnull' => false,
335
+				'length' => 8,
336
+                                'default' => '',
337
+			]);
338
+			$table->addColumn('daily_end', Types::STRING, [
339
+				'notnull' => false,
340
+				'length' => 8,
341
+                                'default' => '',
342
+			]);
343
+			$table->addColumn('vacation_start', Types::DATETIME, [
344
+				'notnull' => false,
345
+			]);
346
+			$table->addColumn('vacation_end', Types::DATETIME, [
347
+				'notnull' => false,
348
+			]);
349
+			$table->addColumn('message_text', Types::TEXT, [
350
+				'notnull' => false,
351
+                                'default' => '',
352
+			]);
353
+                        $table->setPrimaryKey(['id']);
354
+                        $table->addUniqueIndex(['id']);
355
+
356
+		}
357
+
358
+
359
+		if (!$schema->hasTable('sms_relent_restrict')) {
360
+			$table = $schema->createTable('sms_relent_restrict');
361
+			$table->addColumn('id', Types::BIGINT, [
362
+				'autoincrement' => true,
363
+				'notnull' => true,
364
+                                'length' => 11,
365
+                                'unsigned' => true,
366
+			]);
367
+			$table->addColumn('user_id', Types::STRING, [
368
+				'notnull' => true,
369
+				'length' => 128,
370
+			]);
371
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
372
+				'notnull' => true,
373
+				'length' => 255,
374
+			]);
375
+			$table->addColumn('phone_number', Types::STRING, [
376
+				'notnull' => true,
377
+				'length' => 128,
378
+			]);
379
+			$table->addColumn('groups', Types::STRING, [
380
+				'notnull' => true,
381
+				'length' => 2048,
382
+			]);
383
+			$table->addColumn('users', Types::STRING, [
384
+				'notnull' => true,
385
+				'length' => 2048,
386
+			]);
387
+                        $table->setPrimaryKey(['id']);
388
+                        $table->addUniqueIndex(['id']);
389
+
390
+		}
391
+
392
+		if (!$schema->hasTable('sms_relent_subac')) {
393
+			$table = $schema->createTable('sms_relent_subac');
394
+			$table->addColumn('id', Types::BIGINT, [
395
+				'autoincrement' => true,
396
+				'notnull' => true,
397
+                                'length' => 11,
398
+                                'unsigned' => true,
399
+			]);
400
+			$table->addColumn('user_id', Types::STRING, [
401
+				'notnull' => true,
402
+				'length' => 128,
403
+			]);
404
+			$table->addColumn('tnx_groups_allowed', Types::TEXT, [
405
+				'notnull' => false,
406
+                                'default' => '',
407
+			]);
408
+			$table->addColumn('tnx_users_allowed', Types::TEXT, [
409
+				'notnull' => false,
410
+                                'default' => '',
411
+			]);
412
+			$table->addColumn('plv_groups_allowed', Types::TEXT, [
413
+				'notnull' => false,
414
+                                'default' => '',
415
+			]);
416
+			$table->addColumn('plv_users_allowed', Types::TEXT, [
417
+				'notnull' => false,
418
+                                'default' => '',
419
+			]);
420
+			$table->addColumn('twl_groups_allowed', Types::TEXT, [
421
+				'notnull' => false,
422
+                                'default' => '',
423
+			]);
424
+			$table->addColumn('twl_users_allowed', Types::TEXT, [
425
+				'notnull' => false,
426
+                                'default' => '',
427
+			]);
428
+			$table->addColumn('flr_groups_allowed', Types::TEXT, [
429
+				'notnull' => false,
430
+                                'default' => '',
431
+			]);
432
+			$table->addColumn('flr_users_allowed', Types::TEXT, [
433
+				'notnull' => false,
434
+                                'default' => '',
435
+			]);
436
+                        $table->setPrimaryKey(['id']);
437
+                        $table->addUniqueIndex(['id']);
438
+		}
439
+
440
+
441
+		return $schema;
442
+	}
443
+
444
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
445
+
446
+
447
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
448
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`');
449
+	        $getrecfromnbres = $getrecfromnb->execute();
450
+
451
+                $recdatauids = [];
452
+                $idsent = [];
453
+                while ($rowfetched = $getrecfromnbres->fetch()) {
454
+                       $recdatauids[] = $rowfetched['user_id'];
455
+                       $idsent[] = $rowfetched['id'];
456
+                }
457
+                $getrecfromnbres->closeCursor();
458
+
459
+                if ($recdatauids) {
460
+
461
+                    $recuids = array_values(array_unique($recdatauids));
462
+                    $acdatausrdn = [];
463
+
464
+                    foreach ($recuids as $dnkey => $dnvalue) {
465
+		             $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
466
+			     $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
467
+
468
+			     while ($acusrdnfetched = $getacdatadnres->fetch()) {
469
+				    $acdatausrdn[$dnvalue] = $acusrdnfetched['value'];
470
+			     }
471
+			     $getacdatadnres->closeCursor();
472
+                    }
473
+
474
+                    foreach ($recdatauids as $pdpkey => $pdpvalue) {
475
+
476
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?');
477
+			     $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]);
478
+			     $updaterecmsres->closeCursor();
479
+                    }
480
+                }
481
+
482
+
483
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
484
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`');
485
+	        $getrecfromnbres = $getrecfromnb->execute();
486
+
487
+                $recdatanmbrs = [];
488
+                $idsrc = [];
489
+                $daterec = [];
490
+                while ($rowfetched = $getrecfromnbres->fetch()) {
491
+                       $recdatanmbrs[] = $rowfetched['from'];
492
+                       $idsrc[] = $rowfetched['id'];
493
+                       $daterecarr = explode(":", $rowfetched['date']);
494
+                       $daterec[] = $daterecarr[0];
495
+                }
496
+                $getrecfromnbres->closeCursor();
497
+
498
+                if ($recdatanmbrs) {
499
+
500
+                    foreach ($recdatanmbrs as $rckey => $rcvalue) {
501
+
502
+			     // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table
503
+			     $recmsgfromprc = '%' . $rcvalue;
504
+                             $recdataprc = $daterec[$rckey] . '%';
505
+			     $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?');
506
+			     $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]);
507
+
508
+			     $dispnamearr = [];
509
+			     while ($dspnmstfetched = $getdspnmstres->fetch()) {
510
+				    $dispnamearr[] = $dspnmstfetched['author_displayname'];
511
+			     }
512
+			     $getdspnmstres->closeCursor();
513
+
514
+			     if ($dispnamearr) {
515
+				 $descdspnmarr = array_reverse($dispnamearr);
516
+				 $authorDisplayNm = $descdspnmarr[0];
517
+				 $internalSender = 1;
518
+
519
+			     } else {
520
+
521
+                                 $authorDisplayNm = '';
522
+
523
+			         $getfrom = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? LIMIT 1');
524
+			         $getfromres = $getfrom->execute([$recmsgfromprc]);
525
+                                 $fromfetched = $getfromres->fetch();
526
+
527
+                                 if ($fromfetched) { $internalSender = 1; } else { $internalSender = 0; }
528
+
529
+
530
+				 // Search for the associated Display Name in the previous messages coming from the same phone number, in the 'sms_relent_received' table
531
+				 $getdspnm = $this->connection->prepare('SELECT `from`, `author_displayname` FROM `*PREFIX*sms_relent_received` WHERE `from` = ?');
532
+				 $getdspnmres = $getdspnm->execute([$rcvalue]);
533
+
534
+				 $dspnmearr = [];
535
+				 while ($dspnmfetched = $getdspnmres->fetch()) {
536
+				        if ($dspnmfetched['author_displayname']) {
537
+				            $dspnmearr[] = $dspnmfetched['author_displayname'];
538
+				        }
539
+				 }
540
+				 $getdspnmres->closeCursor();
541
+
542
+				 if ($dspnmearr) {
543
+				     $descdisplaynmarr = array_reverse($dspnmearr);
544
+				     $authorDisplayNm = $descdisplaynmarr[0];
545
+				 } else { $authorDisplayNm = ''; }
546
+			     }
547
+
548
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ?
549
+                                                                        WHERE `from` LIKE ? AND `id` = ?');
550
+			     $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $recmsgfromprc, $idsrc[$rckey]]);
551
+			     $updaterecmsres->closeCursor();
552
+                    }
553
+                }
554
+
555
+                return null;
556
+        }
557
+
558
+}