1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,148 @@ |
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\SIPTripPhone\Service; |
|
27 |
+ |
|
28 |
+use OCP\DB\QueryBuilder\IQueryBuilder; |
|
29 |
+use OCP\IDBConnection; |
|
30 |
+use OCP\Security\ICrypto; |
|
31 |
+use function OCP\Log\logger; |
|
32 |
+ |
|
33 |
+class SphoneService { |
|
34 |
+ |
|
35 |
+ private $connection; |
|
36 |
+ private $crypto; |
|
37 |
+ |
|
38 |
+ public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
39 |
+ $this->connection = $connection; |
|
40 |
+ $this->crypto = $crypto; |
|
41 |
+ } |
|
42 |
+ |
|
43 |
+ /** |
|
44 |
+ * @NoAdminRequired |
|
45 |
+ * |
|
46 |
+ */ |
|
47 |
+ public function getsettings($userId) { |
|
48 |
+ |
|
49 |
+ $sql = $this->connection->prepare(' |
|
50 |
+ SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`, `tracesipmsg`, `voicenumbers`, `defaultvoicenumber` |
|
51 |
+ FROM `*PREFIX*sip_trip_phone` |
|
52 |
+ WHERE `user_id` = ?'); |
|
53 |
+ $result = $sql->execute([$userId]); |
|
54 |
+ $settingsdb = $result->fetch(); |
|
55 |
+ $result->closeCursor(); |
|
56 |
+ |
|
57 |
+ if ($settingsdb) { |
|
58 |
+ if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
59 |
+ $settingsdb['sipuserpassword'] = "%20%20%20%20%20%20%20"; |
|
60 |
+ } else { $settingsdb['sipuserpassword'] = ''; } |
|
61 |
+ |
|
62 |
+ return $settingsdb; |
|
63 |
+ } |
|
64 |
+ } |
|
65 |
+ |
|
66 |
+ /** |
|
67 |
+ * @NoAdminRequired |
|
68 |
+ * |
|
69 |
+ */ |
|
70 |
+ public function getsippass($userId) { |
|
71 |
+ |
|
72 |
+ $sqlps = $this->connection->prepare(' |
|
73 |
+ SELECT `id`, `user_id`, `sipuserpassword` |
|
74 |
+ FROM `*PREFIX*sip_trip_phone` |
|
75 |
+ WHERE `user_id` = ?'); |
|
76 |
+ $resultps = $sqlps->execute([$userId]); |
|
77 |
+ $settingsdb = $resultps->fetch(); |
|
78 |
+ $resultps->closeCursor(); |
|
79 |
+ |
|
80 |
+ if ($settingsdb) { |
|
81 |
+ if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
82 |
+ $sipuserpassworddecr = $this->crypto->decrypt($settingsdb['sipuserpassword']); |
|
83 |
+ $sippassword = $sipuserpassworddecr; |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ return $sippassword; |
|
87 |
+ } |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ /** |
|
91 |
+ * @NoAdminRequired |
|
92 |
+ * |
|
93 |
+ */ |
|
94 |
+ public function updatesettings($userId, $pdisplayname, $sipusername, $sipuserpassword, $stphwssurl, $siprealm, $stunserver, $tracesipmsg, $voicenumbers, $defaultvoicenumber) { |
|
95 |
+ |
|
96 |
+ // Validate the data entered in the fields on the settings page |
|
97 |
+ if (mb_strlen($pdisplayname) > 128) { logger('sip_trip_phone')->error("The 'Display Name' cannot exceed 128 characters!"); exit(); } |
|
98 |
+ if (!preg_match('/^[a-zA-Z0-9\*\#]+$/', $sipusername)) { logger('sip_trip_phone')->error("The 'SIP User' that you entered is not valid. The 'SIP User' must contain only alphanumeric characters, asterisks (*) and number signs (#).)"); exit(); } |
|
99 |
+ if (mb_strlen($sipuserpassword) > 300) { logger('sip_trip_phone')->error("The 'SIP User Password' cannot exceed 300 characters!"); exit(); } |
|
100 |
+ if (filter_var($stphwssurl, FILTER_VALIDATE_URL) == false) { logger('sip_trip_phone')->error("The 'WSS URL' that you entered is not valid."); exit(); } |
|
101 |
+ if (filter_var($siprealm, FILTER_VALIDATE_IP) == false && filter_var($siprealm, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) == false) { logger('sip_trip_phone')->error("The 'SIP Realm' that you entered is not valid."); exit(); } |
|
102 |
+ if ($stunserver != '') { |
|
103 |
+ $stunIpDom = explode(":", $stunserver); |
|
104 |
+ if ((filter_var($stunIpDom[0], FILTER_VALIDATE_IP) == false && filter_var($stunIpDom[0], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) == false) || !preg_match('/^[0-9]+$/', $stunIpDom[1])) { logger('sip_trip_phone')->error("The 'STUN Server' that you entered is not valid."); exit(); } |
|
105 |
+ } |
|
106 |
+ if (!preg_match('/^[a-zA-Z0-9\040\+\,\:]*$/', $voicenumbers)) { logger('sip_trip_phone')->error("The 'Available phone numbers' that you entered are not valid. The 'Available phone numbers' must contain only alphanumeric characters, colons (:), spaces, plus signs (+), digits (0-9) and commas (,)."); exit(); } |
|
107 |
+ if (!preg_match('/^[a-zA-Z0-9\040\+\:]*$/', $defaultvoicenumber)) { logger('sip_trip_phone')->error("The 'Default phone number for outgoing calls' that you entered is not valid. The 'Default phone number for outgoing calls' must contain only alphanumeric characters, a colon (:), a space, a plus sign (+) and digits (0-9)."); exit(); } |
|
108 |
+ |
|
109 |
+ $sqlup = $this->connection->prepare(' |
|
110 |
+ SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`, `tracesipmsg`, `voicenumbers`, `defaultvoicenumber` |
|
111 |
+ FROM `*PREFIX*sip_trip_phone` |
|
112 |
+ WHERE `user_id` = ?'); |
|
113 |
+ $resultup = $sqlup->execute([$userId]); |
|
114 |
+ $row = $resultup->fetch(); |
|
115 |
+ $resultup->closeCursor(); |
|
116 |
+ |
|
117 |
+ if ($resultup && !$row) { |
|
118 |
+ |
|
119 |
+ if ($sipuserpassword != '') { |
|
120 |
+ $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
121 |
+ } else { $sipuserpasswordenc = ''; } |
|
122 |
+ |
|
123 |
+ $sqlins = $this->connection->prepare(' |
|
124 |
+ INSERT INTO `*PREFIX*sip_trip_phone` |
|
125 |
+ (`user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`, `tracesipmsg`, `voicenumbers`, `defaultvoicenumber`) |
|
126 |
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); |
|
127 |
+ $sqlins->execute([$userId, $pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver, $tracesipmsg, $voicenumbers, $defaultvoicenumber]); |
|
128 |
+ |
|
129 |
+ } elseif ($resultup && $row) { |
|
130 |
+ |
|
131 |
+ if ($sipuserpassword != '' && $sipuserpassword != "%20%20%20%20%20%20%20") { |
|
132 |
+ $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
133 |
+ } elseif ($sipuserpassword == "%20%20%20%20%20%20%20") { |
|
134 |
+ $sipuserpasswordenc = $row['sipuserpassword']; |
|
135 |
+ } elseif ($sipuserpassword == '') { |
|
136 |
+ $sipuserpasswordenc = ''; |
|
137 |
+ } |
|
138 |
+ |
|
139 |
+ $sqlup = $this->connection->prepare(' |
|
140 |
+ UPDATE `*PREFIX*sip_trip_phone` |
|
141 |
+ SET `pdisplayname` = ?, `sipusername` = ?, `sipuserpassword` = ?, `stphwssurl` = ?, `siprealm` = ?, `stunserver` = ?, `tracesipmsg` = ?, `voicenumbers` = ?, `defaultvoicenumber` = ? |
|
142 |
+ WHERE `user_id` = ?'); |
|
143 |
+ $updateRes = $sqlup->execute([$pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver, $tracesipmsg, $voicenumbers, $defaultvoicenumber, $userId]); |
|
144 |
+ $updateRes->closeCursor(); |
|
145 |
+ |
|
146 |
+ } |
|
147 |
+ } |
|
148 |
+} |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,135 +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\SIPTripPhone\Service; |
|
27 |
- |
|
28 |
-use OCP\DB\QueryBuilder\IQueryBuilder; |
|
29 |
-use OCP\IDBConnection; |
|
30 |
-use OCP\Security\ICrypto; |
|
31 |
- |
|
32 |
- |
|
33 |
-class SphoneService { |
|
34 |
- |
|
35 |
- private $connection; |
|
36 |
- private $crypto; |
|
37 |
- |
|
38 |
- public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
39 |
- $this->connection = $connection; |
|
40 |
- $this->crypto = $crypto; |
|
41 |
- } |
|
42 |
- |
|
43 |
- /** |
|
44 |
- * @NoAdminRequired |
|
45 |
- * |
|
46 |
- */ |
|
47 |
- public function getsettings($userId) { |
|
48 |
- |
|
49 |
- $sql = $this->connection->prepare(' |
|
50 |
- SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver` |
|
51 |
- FROM `*PREFIX*sip_trip_phone` |
|
52 |
- WHERE `user_id` = ?'); |
|
53 |
- $result = $sql->execute([$userId]); |
|
54 |
- $settingsdb = $result->fetch(); |
|
55 |
- $result->closeCursor(); |
|
56 |
- |
|
57 |
- if ($settingsdb) { |
|
58 |
- if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
59 |
- $settingsdb['sipuserpassword'] = "%20%20%20%20%20%20%20"; |
|
60 |
- } else { $settingsdb['sipuserpassword'] = ''; } |
|
61 |
- |
|
62 |
- return $settingsdb; |
|
63 |
- } |
|
64 |
- } |
|
65 |
- |
|
66 |
- /** |
|
67 |
- * @NoAdminRequired |
|
68 |
- * |
|
69 |
- */ |
|
70 |
- public function getsippass($userId) { |
|
71 |
- |
|
72 |
- $sqlps = $this->connection->prepare(' |
|
73 |
- SELECT `id`, `user_id`, `sipuserpassword` |
|
74 |
- FROM `*PREFIX*sip_trip_phone` |
|
75 |
- WHERE `user_id` = ?'); |
|
76 |
- $resultps = $sqlps->execute([$userId]); |
|
77 |
- $settingsdb = $resultps->fetch(); |
|
78 |
- $resultps->closeCursor(); |
|
79 |
- |
|
80 |
- if ($settingsdb) { |
|
81 |
- if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
82 |
- $sipuserpassworddecr = $this->crypto->decrypt($settingsdb['sipuserpassword']); |
|
83 |
- $sippassword = $sipuserpassworddecr; |
|
84 |
- } |
|
85 |
- |
|
86 |
- return $sippassword; |
|
87 |
- } |
|
88 |
- } |
|
89 |
- |
|
90 |
- /** |
|
91 |
- * @NoAdminRequired |
|
92 |
- * |
|
93 |
- */ |
|
94 |
- public function updatesettings($userId, $pdisplayname, $sipusername, $sipuserpassword, $stphwssurl, $siprealm, $stunserver) { |
|
95 |
- |
|
96 |
- $sqlup = $this->connection->prepare(' |
|
97 |
- SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver` |
|
98 |
- FROM `*PREFIX*sip_trip_phone` |
|
99 |
- WHERE `user_id` = ?'); |
|
100 |
- $resultup = $sqlup->execute([$userId]); |
|
101 |
- $row = $resultup->fetch(); |
|
102 |
- $resultup->closeCursor(); |
|
103 |
- |
|
104 |
- if ($resultup && !$row) { |
|
105 |
- |
|
106 |
- if ($sipuserpassword != '') { |
|
107 |
- $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
108 |
- } else { $sipuserpasswordenc = ''; } |
|
109 |
- |
|
110 |
- $sqlins = $this->connection->prepare(' |
|
111 |
- INSERT INTO `*PREFIX*sip_trip_phone` |
|
112 |
- (`user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`) |
|
113 |
- VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
114 |
- $sqlins->execute([$userId, $pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver]); |
|
115 |
- |
|
116 |
- } elseif ($resultup && $row) { |
|
117 |
- |
|
118 |
- if ($sipuserpassword != '' && $sipuserpassword != "%20%20%20%20%20%20%20") { |
|
119 |
- $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
120 |
- } elseif ($sipuserpassword == "%20%20%20%20%20%20%20") { |
|
121 |
- $sipuserpasswordenc = $row['sipuserpassword']; |
|
122 |
- } elseif ($sipuserpassword == '') { |
|
123 |
- $sipuserpasswordenc = ''; |
|
124 |
- } |
|
125 |
- |
|
126 |
- $sqlup = $this->connection->prepare(' |
|
127 |
- UPDATE `*PREFIX*sip_trip_phone` |
|
128 |
- SET `pdisplayname` = ?, `sipusername` = ?, `sipuserpassword` = ?, `stphwssurl` = ?, `siprealm` = ?, `stunserver` = ? |
|
129 |
- WHERE `user_id` = ?'); |
|
130 |
- $updateRes = $sqlup->execute([$pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver, $userId]); |
|
131 |
- $updateRes->closeCursor(); |
|
132 |
- |
|
133 |
- } |
|
134 |
- } |
|
135 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,135 @@ |
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\SIPTripPhone\Service; |
|
27 |
+ |
|
28 |
+use OCP\DB\QueryBuilder\IQueryBuilder; |
|
29 |
+use OCP\IDBConnection; |
|
30 |
+use OCP\Security\ICrypto; |
|
31 |
+ |
|
32 |
+ |
|
33 |
+class SphoneService { |
|
34 |
+ |
|
35 |
+ private $connection; |
|
36 |
+ private $crypto; |
|
37 |
+ |
|
38 |
+ public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
39 |
+ $this->connection = $connection; |
|
40 |
+ $this->crypto = $crypto; |
|
41 |
+ } |
|
42 |
+ |
|
43 |
+ /** |
|
44 |
+ * @NoAdminRequired |
|
45 |
+ * |
|
46 |
+ */ |
|
47 |
+ public function getsettings($userId) { |
|
48 |
+ |
|
49 |
+ $sql = $this->connection->prepare(' |
|
50 |
+ SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver` |
|
51 |
+ FROM `*PREFIX*sip_trip_phone` |
|
52 |
+ WHERE `user_id` = ?'); |
|
53 |
+ $result = $sql->execute([$userId]); |
|
54 |
+ $settingsdb = $result->fetch(); |
|
55 |
+ $result->closeCursor(); |
|
56 |
+ |
|
57 |
+ if ($settingsdb) { |
|
58 |
+ if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
59 |
+ $settingsdb['sipuserpassword'] = "%20%20%20%20%20%20%20"; |
|
60 |
+ } else { $settingsdb['sipuserpassword'] = ''; } |
|
61 |
+ |
|
62 |
+ return $settingsdb; |
|
63 |
+ } |
|
64 |
+ } |
|
65 |
+ |
|
66 |
+ /** |
|
67 |
+ * @NoAdminRequired |
|
68 |
+ * |
|
69 |
+ */ |
|
70 |
+ public function getsippass($userId) { |
|
71 |
+ |
|
72 |
+ $sqlps = $this->connection->prepare(' |
|
73 |
+ SELECT `id`, `user_id`, `sipuserpassword` |
|
74 |
+ FROM `*PREFIX*sip_trip_phone` |
|
75 |
+ WHERE `user_id` = ?'); |
|
76 |
+ $resultps = $sqlps->execute([$userId]); |
|
77 |
+ $settingsdb = $resultps->fetch(); |
|
78 |
+ $resultps->closeCursor(); |
|
79 |
+ |
|
80 |
+ if ($settingsdb) { |
|
81 |
+ if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
82 |
+ $sipuserpassworddecr = $this->crypto->decrypt($settingsdb['sipuserpassword']); |
|
83 |
+ $sippassword = $sipuserpassworddecr; |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ return $sippassword; |
|
87 |
+ } |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ /** |
|
91 |
+ * @NoAdminRequired |
|
92 |
+ * |
|
93 |
+ */ |
|
94 |
+ public function updatesettings($userId, $pdisplayname, $sipusername, $sipuserpassword, $stphwssurl, $siprealm, $stunserver) { |
|
95 |
+ |
|
96 |
+ $sqlup = $this->connection->prepare(' |
|
97 |
+ SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver` |
|
98 |
+ FROM `*PREFIX*sip_trip_phone` |
|
99 |
+ WHERE `user_id` = ?'); |
|
100 |
+ $resultup = $sqlup->execute([$userId]); |
|
101 |
+ $row = $resultup->fetch(); |
|
102 |
+ $resultup->closeCursor(); |
|
103 |
+ |
|
104 |
+ if ($resultup && !$row) { |
|
105 |
+ |
|
106 |
+ if ($sipuserpassword != '') { |
|
107 |
+ $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
108 |
+ } else { $sipuserpasswordenc = ''; } |
|
109 |
+ |
|
110 |
+ $sqlins = $this->connection->prepare(' |
|
111 |
+ INSERT INTO `*PREFIX*sip_trip_phone` |
|
112 |
+ (`user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`) |
|
113 |
+ VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
114 |
+ $sqlins->execute([$userId, $pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver]); |
|
115 |
+ |
|
116 |
+ } elseif ($resultup && $row) { |
|
117 |
+ |
|
118 |
+ if ($sipuserpassword != '' && $sipuserpassword != "%20%20%20%20%20%20%20") { |
|
119 |
+ $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
120 |
+ } elseif ($sipuserpassword == "%20%20%20%20%20%20%20") { |
|
121 |
+ $sipuserpasswordenc = $row['sipuserpassword']; |
|
122 |
+ } elseif ($sipuserpassword == '') { |
|
123 |
+ $sipuserpasswordenc = ''; |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ $sqlup = $this->connection->prepare(' |
|
127 |
+ UPDATE `*PREFIX*sip_trip_phone` |
|
128 |
+ SET `pdisplayname` = ?, `sipusername` = ?, `sipuserpassword` = ?, `stphwssurl` = ?, `siprealm` = ?, `stunserver` = ? |
|
129 |
+ WHERE `user_id` = ?'); |
|
130 |
+ $updateRes = $sqlup->execute([$pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver, $userId]); |
|
131 |
+ $updateRes->closeCursor(); |
|
132 |
+ |
|
133 |
+ } |
|
134 |
+ } |
|
135 |
+} |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,131 +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\SIPTripPhone\Service; |
|
27 |
- |
|
28 |
-use OCP\DB\QueryBuilder\IQueryBuilder; |
|
29 |
-use OCP\IDBConnection; |
|
30 |
-use OCP\Security\ICrypto; |
|
31 |
- |
|
32 |
- |
|
33 |
-class SphoneService { |
|
34 |
- |
|
35 |
- private $connection; |
|
36 |
- private $crypto; |
|
37 |
- |
|
38 |
- public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
39 |
- $this->connection = $connection; |
|
40 |
- $this->crypto = $crypto; |
|
41 |
- } |
|
42 |
- |
|
43 |
- /** |
|
44 |
- * @NoAdminRequired |
|
45 |
- * |
|
46 |
- */ |
|
47 |
- public function getsettings($userId) { |
|
48 |
- |
|
49 |
- $sql = $this->connection->prepare(' |
|
50 |
- SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver` |
|
51 |
- FROM `*PREFIX*sip_trip_phone` |
|
52 |
- WHERE `user_id` = ?'); |
|
53 |
- $result = $sql->execute([$userId]); |
|
54 |
- $settingsdb = $result->fetch(); |
|
55 |
- $result->closeCursor(); |
|
56 |
- |
|
57 |
- if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
58 |
- $settingsdb['sipuserpassword'] = "%20%20%20%20%20%20%20"; |
|
59 |
- } else { $settingsdb['sipuserpassword'] = ''; } |
|
60 |
- |
|
61 |
- return $settingsdb; |
|
62 |
- } |
|
63 |
- |
|
64 |
- /** |
|
65 |
- * @NoAdminRequired |
|
66 |
- * |
|
67 |
- */ |
|
68 |
- public function getsippass($userId) { |
|
69 |
- |
|
70 |
- $sqlps = $this->connection->prepare(' |
|
71 |
- SELECT `id`, `user_id`, `sipuserpassword` |
|
72 |
- FROM `*PREFIX*sip_trip_phone` |
|
73 |
- WHERE `user_id` = ?'); |
|
74 |
- $resultps = $sqlps->execute([$userId]); |
|
75 |
- $settingsdb = $resultps->fetch(); |
|
76 |
- $resultps->closeCursor(); |
|
77 |
- |
|
78 |
- if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
79 |
- $sipuserpassworddecr = $this->crypto->decrypt($settingsdb['sipuserpassword']); |
|
80 |
- $sippassword = $sipuserpassworddecr; |
|
81 |
- } |
|
82 |
- |
|
83 |
- return $sippassword; |
|
84 |
- } |
|
85 |
- |
|
86 |
- /** |
|
87 |
- * @NoAdminRequired |
|
88 |
- * |
|
89 |
- */ |
|
90 |
- public function updatesettings($userId, $pdisplayname, $sipusername, $sipuserpassword, $stphwssurl, $siprealm, $stunserver) { |
|
91 |
- |
|
92 |
- $sqlup = $this->connection->prepare(' |
|
93 |
- SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver` |
|
94 |
- FROM `*PREFIX*sip_trip_phone` |
|
95 |
- WHERE `user_id` = ?'); |
|
96 |
- $resultup = $sqlup->execute([$userId]); |
|
97 |
- $row = $resultup->fetch(); |
|
98 |
- $resultup->closeCursor(); |
|
99 |
- |
|
100 |
- if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) { |
|
101 |
- |
|
102 |
- if ($sipuserpassword != '') { |
|
103 |
- $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
104 |
- } else { $sipuserpasswordenc = ''; } |
|
105 |
- |
|
106 |
- $sqlins = $this->connection->prepare(' |
|
107 |
- INSERT INTO `*PREFIX*sip_trip_phone` |
|
108 |
- (`user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`) |
|
109 |
- VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
110 |
- $sqlins->execute([$userId, $pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver]); |
|
111 |
- |
|
112 |
- } else { |
|
113 |
- |
|
114 |
- if ($sipuserpassword != '' && $sipuserpassword != "%20%20%20%20%20%20%20") { |
|
115 |
- $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
116 |
- } elseif ($sipuserpassword == "%20%20%20%20%20%20%20") { |
|
117 |
- $sipuserpasswordenc = $row['sipuserpassword']; |
|
118 |
- } elseif ($sipuserpassword == '') { |
|
119 |
- $sipuserpasswordenc = ''; |
|
120 |
- } |
|
121 |
- |
|
122 |
- $sqlup = $this->connection->prepare(' |
|
123 |
- UPDATE `*PREFIX*sip_trip_phone` |
|
124 |
- SET `pdisplayname` = ?, `sipusername` = ?, `sipuserpassword` = ?, `stphwssurl` = ?, `siprealm` = ?, `stunserver` = ? |
|
125 |
- WHERE `user_id` = ?'); |
|
126 |
- $updateRes = $sqlup->execute([$pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver, $userId]); |
|
127 |
- $updateRes->closeCursor(); |
|
128 |
- |
|
129 |
- } |
|
130 |
- } |
|
131 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,131 @@ |
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\SIPTripPhone\Service; |
|
27 |
+ |
|
28 |
+use OCP\DB\QueryBuilder\IQueryBuilder; |
|
29 |
+use OCP\IDBConnection; |
|
30 |
+use OCP\Security\ICrypto; |
|
31 |
+ |
|
32 |
+ |
|
33 |
+class SphoneService { |
|
34 |
+ |
|
35 |
+ private $connection; |
|
36 |
+ private $crypto; |
|
37 |
+ |
|
38 |
+ public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
39 |
+ $this->connection = $connection; |
|
40 |
+ $this->crypto = $crypto; |
|
41 |
+ } |
|
42 |
+ |
|
43 |
+ /** |
|
44 |
+ * @NoAdminRequired |
|
45 |
+ * |
|
46 |
+ */ |
|
47 |
+ public function getsettings($userId) { |
|
48 |
+ |
|
49 |
+ $sql = $this->connection->prepare(' |
|
50 |
+ SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver` |
|
51 |
+ FROM `*PREFIX*sip_trip_phone` |
|
52 |
+ WHERE `user_id` = ?'); |
|
53 |
+ $result = $sql->execute([$userId]); |
|
54 |
+ $settingsdb = $result->fetch(); |
|
55 |
+ $result->closeCursor(); |
|
56 |
+ |
|
57 |
+ if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
58 |
+ $settingsdb['sipuserpassword'] = "%20%20%20%20%20%20%20"; |
|
59 |
+ } else { $settingsdb['sipuserpassword'] = ''; } |
|
60 |
+ |
|
61 |
+ return $settingsdb; |
|
62 |
+ } |
|
63 |
+ |
|
64 |
+ /** |
|
65 |
+ * @NoAdminRequired |
|
66 |
+ * |
|
67 |
+ */ |
|
68 |
+ public function getsippass($userId) { |
|
69 |
+ |
|
70 |
+ $sqlps = $this->connection->prepare(' |
|
71 |
+ SELECT `id`, `user_id`, `sipuserpassword` |
|
72 |
+ FROM `*PREFIX*sip_trip_phone` |
|
73 |
+ WHERE `user_id` = ?'); |
|
74 |
+ $resultps = $sqlps->execute([$userId]); |
|
75 |
+ $settingsdb = $resultps->fetch(); |
|
76 |
+ $resultps->closeCursor(); |
|
77 |
+ |
|
78 |
+ if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
79 |
+ $sipuserpassworddecr = $this->crypto->decrypt($settingsdb['sipuserpassword']); |
|
80 |
+ $sippassword = $sipuserpassworddecr; |
|
81 |
+ } |
|
82 |
+ |
|
83 |
+ return $sippassword; |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ /** |
|
87 |
+ * @NoAdminRequired |
|
88 |
+ * |
|
89 |
+ */ |
|
90 |
+ public function updatesettings($userId, $pdisplayname, $sipusername, $sipuserpassword, $stphwssurl, $siprealm, $stunserver) { |
|
91 |
+ |
|
92 |
+ $sqlup = $this->connection->prepare(' |
|
93 |
+ SELECT `id`, `user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver` |
|
94 |
+ FROM `*PREFIX*sip_trip_phone` |
|
95 |
+ WHERE `user_id` = ?'); |
|
96 |
+ $resultup = $sqlup->execute([$userId]); |
|
97 |
+ $row = $resultup->fetch(); |
|
98 |
+ $resultup->closeCursor(); |
|
99 |
+ |
|
100 |
+ if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) { |
|
101 |
+ |
|
102 |
+ if ($sipuserpassword != '') { |
|
103 |
+ $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
104 |
+ } else { $sipuserpasswordenc = ''; } |
|
105 |
+ |
|
106 |
+ $sqlins = $this->connection->prepare(' |
|
107 |
+ INSERT INTO `*PREFIX*sip_trip_phone` |
|
108 |
+ (`user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`) |
|
109 |
+ VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
110 |
+ $sqlins->execute([$userId, $pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver]); |
|
111 |
+ |
|
112 |
+ } else { |
|
113 |
+ |
|
114 |
+ if ($sipuserpassword != '' && $sipuserpassword != "%20%20%20%20%20%20%20") { |
|
115 |
+ $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword); |
|
116 |
+ } elseif ($sipuserpassword == "%20%20%20%20%20%20%20") { |
|
117 |
+ $sipuserpasswordenc = $row['sipuserpassword']; |
|
118 |
+ } elseif ($sipuserpassword == '') { |
|
119 |
+ $sipuserpasswordenc = ''; |
|
120 |
+ } |
|
121 |
+ |
|
122 |
+ $sqlup = $this->connection->prepare(' |
|
123 |
+ UPDATE `*PREFIX*sip_trip_phone` |
|
124 |
+ SET `pdisplayname` = ?, `sipusername` = ?, `sipuserpassword` = ?, `stphwssurl` = ?, `siprealm` = ?, `stunserver` = ? |
|
125 |
+ WHERE `user_id` = ?'); |
|
126 |
+ $updateRes = $sqlup->execute([$pdisplayname, $sipusername, $sipuserpasswordenc, $stphwssurl, $siprealm, $stunserver, $userId]); |
|
127 |
+ $updateRes->closeCursor(); |
|
128 |
+ |
|
129 |
+ } |
|
130 |
+ } |
|
131 |
+} |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,126 +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\SIPTripPhone\Service; |
|
27 |
- |
|
28 |
-use OCP\DB\QueryBuilder\IQueryBuilder; |
|
29 |
-use OCP\IDBConnection; |
|
30 |
-use OCP\Security\ICrypto; |
|
31 |
- |
|
32 |
- |
|
33 |
-class SphoneService { |
|
34 |
- |
|
35 |
- private $connection; |
|
36 |
- private $crypto; |
|
37 |
- |
|
38 |
- public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
39 |
- $this->connection = $connection; |
|
40 |
- $this->crypto = $crypto; |
|
41 |
- } |
|
42 |
- |
|
43 |
- /** |
|
44 |
- * @NoAdminRequired |
|
45 |
- * |
|
46 |
- */ |
|
47 |
- public function getsettings($userId) { |
|
48 |
- |
|
49 |
- $sql0 = "SELECT * FROM `*PREFIX*sip_trip_phone` WHERE `user_id` = '$userId'"; |
|
50 |
- |
|
51 |
- $res0 = $this->connection->prepare($sql0); |
|
52 |
- $res0->execute(); |
|
53 |
- |
|
54 |
- $settingsdb = $res0->fetch(); |
|
55 |
- |
|
56 |
- if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
57 |
- $settingsdb['sipuserpassword'] = "%20%20%20%20%20%20%20"; |
|
58 |
- } else { $settingsdb['sipuserpassword'] = ''; } |
|
59 |
- |
|
60 |
- $res0->closeCursor(); |
|
61 |
- |
|
62 |
- return $settingsdb; |
|
63 |
- } |
|
64 |
- |
|
65 |
- /** |
|
66 |
- * @NoAdminRequired |
|
67 |
- * |
|
68 |
- */ |
|
69 |
- public function getsippass($userId) { |
|
70 |
- |
|
71 |
- $sql0 = "SELECT `id`, `user_id`, `sipuserpassword` FROM `*PREFIX*sip_trip_phone` WHERE `user_id` = '$userId'"; |
|
72 |
- |
|
73 |
- $res0 = $this->connection->prepare($sql0); |
|
74 |
- $res0->execute(); |
|
75 |
- |
|
76 |
- $settingsdb = $res0->fetch(); |
|
77 |
- if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
78 |
- $sipuserpassworddecr = $this->crypto->decrypt($settingsdb['sipuserpassword'], $password = ''); |
|
79 |
- $sippassword = $sipuserpassworddecr; |
|
80 |
- } |
|
81 |
- $res0->closeCursor(); |
|
82 |
- |
|
83 |
- return $sippassword; |
|
84 |
- } |
|
85 |
- |
|
86 |
- /** |
|
87 |
- * @NoAdminRequired |
|
88 |
- * |
|
89 |
- */ |
|
90 |
- public function updatesettings($userId, $pdisplayname, $sipusername, $sipuserpassword, $stphwssurl, $siprealm, $stunserver) { |
|
91 |
- |
|
92 |
- $sql1 = "SELECT * FROM `*PREFIX*sip_trip_phone` WHERE `user_id` = '$userId'"; |
|
93 |
- $res1 = $this->connection->prepare($sql1); |
|
94 |
- $res1->execute(); |
|
95 |
- |
|
96 |
- $row = $res1->fetch(); |
|
97 |
- $res1->closeCursor(); |
|
98 |
- |
|
99 |
- if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) { |
|
100 |
- |
|
101 |
- if ($sipuserpassword != '') { |
|
102 |
- $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword, $password = ''); |
|
103 |
- } else { $sipuserpasswordenc = ''; } |
|
104 |
- |
|
105 |
- $sql2 = "INSERT INTO `*PREFIX*sip_trip_phone` (`user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`) |
|
106 |
- VALUES ('$userId', '$pdisplayname', '$sipusername', '$sipuserpasswordenc', '$stphwssurl', '$siprealm', '$stunserver')"; |
|
107 |
- $res2 = $this->connection->prepare($sql2); |
|
108 |
- $res2->execute(); |
|
109 |
- |
|
110 |
- } else { |
|
111 |
- |
|
112 |
- if ($sipuserpassword != '' && $sipuserpassword != "%20%20%20%20%20%20%20") { |
|
113 |
- $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword, $password = ''); |
|
114 |
- } elseif ($sipuserpassword == "%20%20%20%20%20%20%20") { |
|
115 |
- $sipuserpasswordenc = $row['sipuserpassword']; |
|
116 |
- } elseif ($sipuserpassword == '') { |
|
117 |
- $sipuserpasswordenc = ''; |
|
118 |
- } |
|
119 |
- |
|
120 |
- $sql3 = "UPDATE `*PREFIX*sip_trip_phone` SET `pdisplayname` = '$pdisplayname', `sipusername` = '$sipusername', `sipuserpassword` = '$sipuserpasswordenc', |
|
121 |
- `stphwssurl` = '$stphwssurl', `siprealm` = '$siprealm', `stunserver` = '$stunserver' WHERE `user_id` = '$userId'"; |
|
122 |
- $res3 = $this->connection->prepare($sql3); |
|
123 |
- $res3->execute(); |
|
124 |
- } |
|
125 |
- } |
|
126 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,126 @@ |
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\SIPTripPhone\Service; |
|
27 |
+ |
|
28 |
+use OCP\DB\QueryBuilder\IQueryBuilder; |
|
29 |
+use OCP\IDBConnection; |
|
30 |
+use OCP\Security\ICrypto; |
|
31 |
+ |
|
32 |
+ |
|
33 |
+class SphoneService { |
|
34 |
+ |
|
35 |
+ private $connection; |
|
36 |
+ private $crypto; |
|
37 |
+ |
|
38 |
+ public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
39 |
+ $this->connection = $connection; |
|
40 |
+ $this->crypto = $crypto; |
|
41 |
+ } |
|
42 |
+ |
|
43 |
+ /** |
|
44 |
+ * @NoAdminRequired |
|
45 |
+ * |
|
46 |
+ */ |
|
47 |
+ public function getsettings($userId) { |
|
48 |
+ |
|
49 |
+ $sql0 = "SELECT * FROM `*PREFIX*sip_trip_phone` WHERE `user_id` = '$userId'"; |
|
50 |
+ |
|
51 |
+ $res0 = $this->connection->prepare($sql0); |
|
52 |
+ $res0->execute(); |
|
53 |
+ |
|
54 |
+ $settingsdb = $res0->fetch(); |
|
55 |
+ |
|
56 |
+ if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
57 |
+ $settingsdb['sipuserpassword'] = "%20%20%20%20%20%20%20"; |
|
58 |
+ } else { $settingsdb['sipuserpassword'] = ''; } |
|
59 |
+ |
|
60 |
+ $res0->closeCursor(); |
|
61 |
+ |
|
62 |
+ return $settingsdb; |
|
63 |
+ } |
|
64 |
+ |
|
65 |
+ /** |
|
66 |
+ * @NoAdminRequired |
|
67 |
+ * |
|
68 |
+ */ |
|
69 |
+ public function getsippass($userId) { |
|
70 |
+ |
|
71 |
+ $sql0 = "SELECT `id`, `user_id`, `sipuserpassword` FROM `*PREFIX*sip_trip_phone` WHERE `user_id` = '$userId'"; |
|
72 |
+ |
|
73 |
+ $res0 = $this->connection->prepare($sql0); |
|
74 |
+ $res0->execute(); |
|
75 |
+ |
|
76 |
+ $settingsdb = $res0->fetch(); |
|
77 |
+ if ($settingsdb['sipuserpassword'] != '' && $settingsdb['sipuserpassword'] != null && $settingsdb['sipuserpassword'] != 'undefined') { |
|
78 |
+ $sipuserpassworddecr = $this->crypto->decrypt($settingsdb['sipuserpassword'], $password = ''); |
|
79 |
+ $sippassword = $sipuserpassworddecr; |
|
80 |
+ } |
|
81 |
+ $res0->closeCursor(); |
|
82 |
+ |
|
83 |
+ return $sippassword; |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ /** |
|
87 |
+ * @NoAdminRequired |
|
88 |
+ * |
|
89 |
+ */ |
|
90 |
+ public function updatesettings($userId, $pdisplayname, $sipusername, $sipuserpassword, $stphwssurl, $siprealm, $stunserver) { |
|
91 |
+ |
|
92 |
+ $sql1 = "SELECT * FROM `*PREFIX*sip_trip_phone` WHERE `user_id` = '$userId'"; |
|
93 |
+ $res1 = $this->connection->prepare($sql1); |
|
94 |
+ $res1->execute(); |
|
95 |
+ |
|
96 |
+ $row = $res1->fetch(); |
|
97 |
+ $res1->closeCursor(); |
|
98 |
+ |
|
99 |
+ if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) { |
|
100 |
+ |
|
101 |
+ if ($sipuserpassword != '') { |
|
102 |
+ $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword, $password = ''); |
|
103 |
+ } else { $sipuserpasswordenc = ''; } |
|
104 |
+ |
|
105 |
+ $sql2 = "INSERT INTO `*PREFIX*sip_trip_phone` (`user_id`, `pdisplayname`, `sipusername`, `sipuserpassword`, `stphwssurl`, `siprealm`, `stunserver`) |
|
106 |
+ VALUES ('$userId', '$pdisplayname', '$sipusername', '$sipuserpasswordenc', '$stphwssurl', '$siprealm', '$stunserver')"; |
|
107 |
+ $res2 = $this->connection->prepare($sql2); |
|
108 |
+ $res2->execute(); |
|
109 |
+ |
|
110 |
+ } else { |
|
111 |
+ |
|
112 |
+ if ($sipuserpassword != '' && $sipuserpassword != "%20%20%20%20%20%20%20") { |
|
113 |
+ $sipuserpasswordenc = $this->crypto->encrypt($sipuserpassword, $password = ''); |
|
114 |
+ } elseif ($sipuserpassword == "%20%20%20%20%20%20%20") { |
|
115 |
+ $sipuserpasswordenc = $row['sipuserpassword']; |
|
116 |
+ } elseif ($sipuserpassword == '') { |
|
117 |
+ $sipuserpasswordenc = ''; |
|
118 |
+ } |
|
119 |
+ |
|
120 |
+ $sql3 = "UPDATE `*PREFIX*sip_trip_phone` SET `pdisplayname` = '$pdisplayname', `sipusername` = '$sipusername', `sipuserpassword` = '$sipuserpasswordenc', |
|
121 |
+ `stphwssurl` = '$stphwssurl', `siprealm` = '$siprealm', `stunserver` = '$stunserver' WHERE `user_id` = '$userId'"; |
|
122 |
+ $res3 = $this->connection->prepare($sql3); |
|
123 |
+ $res3->execute(); |
|
124 |
+ } |
|
125 |
+ } |
|
126 |
+} |