Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css lib/Service/PaxfaxService.php lib/Migration/Version100Date20211106170854.php

DoubleBastionAdmin authored on 02/12/2022 23:47:12
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,248 @@
1
+<?php
2
+/**
3
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
4
+ *
5
+ * @author Double Bastion LLC
6
+ *
7
+ * @license GNU AGPL version 3 or any later version
8
+ *
9
+ * This program is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3 of the License, or any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
+ *
19
+ * You should have received a copy of the GNU Affero General Public
20
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+
24
+declare(strict_types=1);
25
+
26
+namespace OCA\PaxFax\Service;
27
+
28
+use OCP\DB\QueryBuilder\IQueryBuilder;
29
+use OCP\IDBConnection;
30
+use OCP\Security\ICrypto;
31
+use OCP\AppFramework\ApiController;
32
+use OCP\IRequest;
33
+use OCP\AppFramework\Controller;
34
+use OCP\Files\IAppData;
35
+use OCP\AppFramework\App;
36
+use OCP\Files\NotPermittedException;
37
+use OCP\Files\Folder;
38
+use OC\Files\Filesystem;
39
+use \ReflectionClass;
40
+
41
+use Phaxio;
42
+use Phaxio\OperationResult;
43
+use Phaxio\Error\AuthenticationException;
44
+use Phaxio\Error\NotFoundException;
45
+use Phaxio\Error\InvalidRequestException;
46
+use Phaxio\Error\RateLimitException;
47
+use Phaxio\Error\APIConnectionException;
48
+use Phaxio\Error\GeneralException;
49
+
50
+
51
+class PaxfaxService {
52
+
53
+      private $connection;
54
+
55
+      private $crypto;
56
+
57
+      public function __construct(IDBConnection $connection, ICrypto $crypto) {
58
+
59
+              $this->connection = $connection;
60
+
61
+              $this->crypto = $crypto;
62
+      }
63
+
64
+
65
+      /**
66
+       * @NoAdminRequired
67
+       */
68
+      public function object_to_array($obj) {
69
+         if(is_object($obj)) $obj = (array)$this->dismount($obj);
70
+         if(is_array($obj)) {
71
+            $new = array();
72
+            foreach($obj as $key => $val) {
73
+                $new[$key] = $this->object_to_array($val);
74
+            }
75
+         }
76
+         else $new = $obj;
77
+         return $new;
78
+      }
79
+
80
+
81
+      /**
82
+       * @NoAdminRequired
83
+       */
84
+      public function dismount($object) {
85
+         $reflectionClass = new ReflectionClass(get_class($object));
86
+         $array = array();
87
+         foreach ($reflectionClass->getProperties() as $property) {
88
+            $property->setAccessible(true);
89
+            $array[$property->getName()] = $property->getValue($object);
90
+            $property->setAccessible(false);
91
+         }
92
+         return $array;
93
+      }
94
+
95
+
96
+      /**
97
+       * @NoAdminRequired
98
+       *
99
+       */
100
+      public function getsettings($userId) {
101
+
102
+          $sql = $this->connection->prepare('
103
+	           SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
104
+                   FROM `*PREFIX*pax_fax`
105
+                   WHERE `user_id` = ?');
106
+	  $result = $sql->execute([$userId]);
107
+          $settingsfromdb = $result->fetch();
108
+          $result->closeCursor();
109
+
110
+          if ($settingsfromdb) {
111
+
112
+              if ($settingsfromdb['api_key'] != '') {
113
+
114
+                  // Send a placeholder to the browser, instead of the real data
115
+                  $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
116
+              }
117
+              if ($settingsfromdb['api_secret'] != '') {
118
+                  $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
119
+              }
120
+              if ($settingsfromdb['webhook_token'] != '') {
121
+                  $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20";
122
+              }
123
+              if ($settingsfromdb['receive_url'] != '') {
124
+                  $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
125
+              }
126
+
127
+              return $settingsfromdb;
128
+          }
129
+      }
130
+
131
+
132
+      /**
133
+       * @NoAdminRequired
134
+       *
135
+       */
136
+      public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
137
+
138
+          $sqlsel = $this->connection->prepare('
139
+	             SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
140
+                     FROM `*PREFIX*pax_fax`
141
+                     WHERE `user_id` = ?');
142
+	  $resultsel = $sqlsel->execute([$userId]);
143
+          $row = $resultsel->fetch();
144
+          $resultsel->closeCursor();
145
+
146
+          if ($resultsel && !$row) {
147
+
148
+              if ($apiKey != '') {
149
+                  $apikeystrenc = $this->crypto->encrypt($apiKey);                
150
+              } else { $apikeystrenc = ''; }
151
+
152
+              if ($apiSecret != '') {
153
+                  $apisecretstrenc = $this->crypto->encrypt($apiSecret);                
154
+              } else { $apisecretstrenc = ''; }
155
+
156
+              if ($webhookToken != '') {
157
+                  $webhookTokenenc = $this->crypto->encrypt($webhookToken);               
158
+              } else { $webhookTokenenc = ''; }
159
+
160
+              if ($receiveUrl != '') {
161
+                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl);                
162
+              } else { $receiveUrlenc = ''; }
163
+
164
+              $sqlns = $this->connection->prepare('
165
+				INSERT INTO `*PREFIX*pax_fax`
166
+					(`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`)
167
+				VALUES (?, ?, ?, ?, ?, ?, ?)');
168
+	      $sqlns->execute([$userId, $apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail]);
169
+
170
+          } elseif ($resultsel && $row) {  
171
+
172
+              if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
173
+                  $apikeystrenc = $this->crypto->encrypt($apiKey);                
174
+              } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
175
+                  $apikeystrenc = $row['api_key'];
176
+              } elseif ($apiKey == '') {
177
+                  $apikeystrenc = '';
178
+              }
179
+
180
+              if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
181
+                  $apisecretstrenc = $this->crypto->encrypt($apiSecret);                
182
+              } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
183
+                  $apisecretstrenc = $row['api_secret'];
184
+              } elseif ($apiSecret == '') {
185
+                  $apisecretstrenc = '';
186
+              }
187
+
188
+              if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
189
+                  $webhookTokenenc = $this->crypto->encrypt($webhookToken);                
190
+              } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
191
+                  $webhookTokenenc = $row['webhook_token'];
192
+              } elseif ($webhookToken == '') {
193
+                  $webhookTokenenc = '';
194
+              }
195
+
196
+              if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
197
+                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl);                
198
+              } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
199
+                  $receiveUrlenc = $row['receive_url'];
200
+              } elseif ($receiveUrl == '') {
201
+                  $receiveUrlenc = '';
202
+              }
203
+
204
+	      $sqlup = $this->connection->prepare('
205
+			UPDATE `*PREFIX*pax_fax`
206
+			SET `api_key` = ?, `api_secret` = ?, `webhook_token` = ?, `receive_url` = ?, `get_notification` = ?, `notification_email` = ?
207
+                        WHERE `user_id` = ?');
208
+	      $updateRes = $sqlup->execute([$apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail, $userId]);
209
+	      $updateRes->closeCursor();
210
+          }
211
+      }
212
+
213
+      /**
214
+       * @NoAdminRequired
215
+       */
216
+      public function getapicredentials($userId) {
217
+
218
+              $sqlselcr = $this->connection->prepare('
219
+	                    SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
220
+                            FROM `*PREFIX*pax_fax`
221
+                            WHERE `user_id` = ?');
222
+	      $resultselcr = $sqlselcr->execute([$userId]);
223
+              $settingsfrdb = $resultselcr->fetch();
224
+              $resultselcr->closeCursor();
225
+
226
+              if (($settingsfrdb['api_key'] != '') && ($settingsfrdb['api_key'] != 'undefined') && ($settingsfrdb['api_key'] != null)) {
227
+                   $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key']);
228
+              } else { $apikeystr = ''; }
229
+
230
+              if (($settingsfrdb['api_secret'] != '') && ($settingsfrdb['api_secret'] != 'undefined') && ($settingsfrdb['api_secret'] != null)) {              
231
+                   $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret']);
232
+              } else { $apisecretstr = ''; }
233
+
234
+              if (($settingsfrdb['webhook_token'] != '') && ($settingsfrdb['webhook_token'] != 'undefined') && ($settingsfrdb['webhook_token'] != null)) {            
235
+                   $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token']);
236
+              } else { $webhookToken = ''; }
237
+
238
+              if (($settingsfrdb['receive_url'] != '') && ($settingsfrdb['receive_url'] != 'undefined') && ($settingsfrdb['receive_url'] != null)) {
239
+                   $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url']);
240
+              } else { $receiveUrl = ''; }
241
+
242
+              $getnotification = $settingsfrdb['get_notification'];
243
+              $notifyemail = $settingsfrdb['notification_email'];
244
+
245
+              return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail];
246
+      }
247
+
248
+}
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css lib/Service/PaxfaxService.php lib/Migration/Version100Date20211106170854.php

DoubleBastionAdmin authored on 02/12/2022 23:42:41
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,245 +0,0 @@
1
-<?php
2
-/**
3
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
4
- *
5
- * @author Double Bastion LLC
6
- *
7
- * @license GNU AGPL version 3 or any later version
8
- *
9
- * This program is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
- * License as published by the Free Software Foundation; either
12
- * version 3 of the License, or any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
- *
19
- * You should have received a copy of the GNU Affero General Public
20
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
- *
22
- */
23
-
24
-declare(strict_types=1);
25
-
26
-namespace OCA\PaxFax\Service;
27
-
28
-use OCP\DB\QueryBuilder\IQueryBuilder;
29
-use OCP\IDBConnection;
30
-use OCP\Security\ICrypto;
31
-use OCP\AppFramework\ApiController;
32
-use OCP\IRequest;
33
-use OCP\AppFramework\Controller;
34
-use OCP\Files\IAppData;
35
-use OCP\AppFramework\App;
36
-use OCP\Files\NotPermittedException;
37
-use OCP\Files\Folder;
38
-use OC\Files\Filesystem;
39
-use \ReflectionClass;
40
-
41
-use Phaxio;
42
-use Phaxio\OperationResult;
43
-use Phaxio\Error\AuthenticationException;
44
-use Phaxio\Error\NotFoundException;
45
-use Phaxio\Error\InvalidRequestException;
46
-use Phaxio\Error\RateLimitException;
47
-use Phaxio\Error\APIConnectionException;
48
-use Phaxio\Error\GeneralException;
49
-
50
-
51
-class PaxfaxService {
52
-
53
-      private $connection;
54
-
55
-      private $crypto;
56
-
57
-      public function __construct(IDBConnection $connection, ICrypto $crypto) {
58
-
59
-              $this->connection = $connection;
60
-
61
-              $this->crypto = $crypto;
62
-      }
63
-
64
-
65
-      /**
66
-       * @NoAdminRequired
67
-       */
68
-      public function object_to_array($obj) {
69
-         if(is_object($obj)) $obj = (array)$this->dismount($obj);
70
-         if(is_array($obj)) {
71
-            $new = array();
72
-            foreach($obj as $key => $val) {
73
-                $new[$key] = $this->object_to_array($val);
74
-            }
75
-         }
76
-         else $new = $obj;
77
-         return $new;
78
-      }
79
-
80
-
81
-      /**
82
-       * @NoAdminRequired
83
-       */
84
-      public function dismount($object) {
85
-         $reflectionClass = new ReflectionClass(get_class($object));
86
-         $array = array();
87
-         foreach ($reflectionClass->getProperties() as $property) {
88
-            $property->setAccessible(true);
89
-            $array[$property->getName()] = $property->getValue($object);
90
-            $property->setAccessible(false);
91
-         }
92
-         return $array;
93
-      }
94
-
95
-
96
-      /**
97
-       * @NoAdminRequired
98
-       *
99
-       */
100
-      public function getsettings($userId) {
101
-
102
-          $sql = $this->connection->prepare('
103
-	           SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
104
-                   FROM `*PREFIX*pax_fax`
105
-                   WHERE `user_id` = ?');
106
-	  $result = $sql->execute([$userId]);
107
-          $settingsfromdb = $result->fetch();
108
-          $result->closeCursor();
109
-
110
-          if ($settingsfromdb['api_key'] != '') {
111
-
112
-              // Send a placeholder to the browser, instead of the real data
113
-              $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
114
-          }
115
-          if ($settingsfromdb['api_secret'] != '') {
116
-              $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
117
-          }
118
-          if ($settingsfromdb['webhook_token'] != '') {
119
-              $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20";
120
-          }
121
-          if ($settingsfromdb['receive_url'] != '') {
122
-              $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
123
-          }
124
-
125
-          return $settingsfromdb;
126
-      }
127
-
128
-
129
-      /**
130
-       * @NoAdminRequired
131
-       *
132
-       */
133
-      public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
134
-
135
-          $sqlsel = $this->connection->prepare('
136
-	             SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
137
-                     FROM `*PREFIX*pax_fax`
138
-                     WHERE `user_id` = ?');
139
-	  $resultsel = $sqlsel->execute([$userId]);
140
-          $row = $resultsel->fetch();
141
-          $resultsel->closeCursor();
142
-
143
-          if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) {
144
-
145
-              if ($apiKey != '') {
146
-                  $apikeystrenc = $this->crypto->encrypt($apiKey);                
147
-              } else { $apikeystrenc = ''; }
148
-
149
-              if ($apiSecret != '') {
150
-                  $apisecretstrenc = $this->crypto->encrypt($apiSecret);                
151
-              } else { $apisecretstrenc = ''; }
152
-
153
-              if ($webhookToken != '') {
154
-                  $webhookTokenenc = $this->crypto->encrypt($webhookToken);               
155
-              } else { $webhookTokenenc = ''; }
156
-
157
-              if ($receiveUrl != '') {
158
-                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl);                
159
-              } else { $receiveUrlenc = ''; }
160
-
161
-              $sqlns = $this->connection->prepare('
162
-				INSERT INTO `*PREFIX*pax_fax`
163
-					(`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`)
164
-				VALUES (?, ?, ?, ?, ?, ?, ?)');
165
-	      $sqlns->execute([$userId, $apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail]);
166
-
167
-          } else {
168
-
169
-              if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
170
-                  $apikeystrenc = $this->crypto->encrypt($apiKey);                
171
-              } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
172
-                  $apikeystrenc = $row['api_key'];
173
-              } elseif ($apiKey == '') {
174
-                  $apikeystrenc = '';
175
-              }
176
-
177
-              if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
178
-                  $apisecretstrenc = $this->crypto->encrypt($apiSecret);                
179
-              } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
180
-                  $apisecretstrenc = $row['api_secret'];
181
-              } elseif ($apiSecret == '') {
182
-                  $apisecretstrenc = '';
183
-              }
184
-
185
-              if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
186
-                  $webhookTokenenc = $this->crypto->encrypt($webhookToken);                
187
-              } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
188
-                  $webhookTokenenc = $row['webhook_token'];
189
-              } elseif ($webhookToken == '') {
190
-                  $webhookTokenenc = '';
191
-              }
192
-
193
-              if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
194
-                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl);                
195
-              } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
196
-                  $receiveUrlenc = $row['receive_url'];
197
-              } elseif ($receiveUrl == '') {
198
-                  $receiveUrlenc = '';
199
-              }
200
-
201
-	      $sqlup = $this->connection->prepare('
202
-			UPDATE `*PREFIX*pax_fax`
203
-			SET `api_key` = ?, `api_secret` = ?, `webhook_token` = ?, `receive_url` = ?, `get_notification` = ?, `notification_email` = ?
204
-                        WHERE `user_id` = ?');
205
-	      $updateRes = $sqlup->execute([$apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail, $userId]);
206
-	      $updateRes->closeCursor();
207
-          }
208
-      }
209
-
210
-      /**
211
-       * @NoAdminRequired
212
-       */
213
-      public function getapicredentials($userId) {
214
-
215
-              $sqlselcr = $this->connection->prepare('
216
-	                    SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
217
-                            FROM `*PREFIX*pax_fax`
218
-                            WHERE `user_id` = ?');
219
-	      $resultselcr = $sqlselcr->execute([$userId]);
220
-              $settingsfrdb = $resultselcr->fetch();
221
-              $resultselcr->closeCursor();
222
-
223
-              if (($settingsfrdb['api_key'] != '') && ($settingsfrdb['api_key'] != 'undefined') && ($settingsfrdb['api_key'] != null)) {
224
-                   $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key']);
225
-              } else { $apikeystr = ''; }
226
-
227
-              if (($settingsfrdb['api_secret'] != '') && ($settingsfrdb['api_secret'] != 'undefined') && ($settingsfrdb['api_secret'] != null)) {              
228
-                   $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret']);
229
-              } else { $apisecretstr = ''; }
230
-
231
-              if (($settingsfrdb['webhook_token'] != '') && ($settingsfrdb['webhook_token'] != 'undefined') && ($settingsfrdb['webhook_token'] != null)) {            
232
-                   $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token']);
233
-              } else { $webhookToken = ''; }
234
-
235
-              if (($settingsfrdb['receive_url'] != '') && ($settingsfrdb['receive_url'] != 'undefined') && ($settingsfrdb['receive_url'] != null)) {
236
-                   $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url']);
237
-              } else { $receiveUrl = ''; }
238
-
239
-              $getnotification = $settingsfrdb['get_notification'];
240
-              $notifyemail = $settingsfrdb['notification_email'];
241
-
242
-              return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail];
243
-      }
244
-
245
-}
Browse code

added CHANGELOG.txt Contributors.txt README.md templates/settings.php appinfo/info.xml appinfo/signature.json lib/Service/PaxfaxService.php lib/Controller/AuthorApiController.php lib/Controller/PaxfaxController.php

DoubleBastionAdmin authored on 10/05/2022 18:04:58
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,245 @@
1
+<?php
2
+/**
3
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
4
+ *
5
+ * @author Double Bastion LLC
6
+ *
7
+ * @license GNU AGPL version 3 or any later version
8
+ *
9
+ * This program is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3 of the License, or any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
+ *
19
+ * You should have received a copy of the GNU Affero General Public
20
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+
24
+declare(strict_types=1);
25
+
26
+namespace OCA\PaxFax\Service;
27
+
28
+use OCP\DB\QueryBuilder\IQueryBuilder;
29
+use OCP\IDBConnection;
30
+use OCP\Security\ICrypto;
31
+use OCP\AppFramework\ApiController;
32
+use OCP\IRequest;
33
+use OCP\AppFramework\Controller;
34
+use OCP\Files\IAppData;
35
+use OCP\AppFramework\App;
36
+use OCP\Files\NotPermittedException;
37
+use OCP\Files\Folder;
38
+use OC\Files\Filesystem;
39
+use \ReflectionClass;
40
+
41
+use Phaxio;
42
+use Phaxio\OperationResult;
43
+use Phaxio\Error\AuthenticationException;
44
+use Phaxio\Error\NotFoundException;
45
+use Phaxio\Error\InvalidRequestException;
46
+use Phaxio\Error\RateLimitException;
47
+use Phaxio\Error\APIConnectionException;
48
+use Phaxio\Error\GeneralException;
49
+
50
+
51
+class PaxfaxService {
52
+
53
+      private $connection;
54
+
55
+      private $crypto;
56
+
57
+      public function __construct(IDBConnection $connection, ICrypto $crypto) {
58
+
59
+              $this->connection = $connection;
60
+
61
+              $this->crypto = $crypto;
62
+      }
63
+
64
+
65
+      /**
66
+       * @NoAdminRequired
67
+       */
68
+      public function object_to_array($obj) {
69
+         if(is_object($obj)) $obj = (array)$this->dismount($obj);
70
+         if(is_array($obj)) {
71
+            $new = array();
72
+            foreach($obj as $key => $val) {
73
+                $new[$key] = $this->object_to_array($val);
74
+            }
75
+         }
76
+         else $new = $obj;
77
+         return $new;
78
+      }
79
+
80
+
81
+      /**
82
+       * @NoAdminRequired
83
+       */
84
+      public function dismount($object) {
85
+         $reflectionClass = new ReflectionClass(get_class($object));
86
+         $array = array();
87
+         foreach ($reflectionClass->getProperties() as $property) {
88
+            $property->setAccessible(true);
89
+            $array[$property->getName()] = $property->getValue($object);
90
+            $property->setAccessible(false);
91
+         }
92
+         return $array;
93
+      }
94
+
95
+
96
+      /**
97
+       * @NoAdminRequired
98
+       *
99
+       */
100
+      public function getsettings($userId) {
101
+
102
+          $sql = $this->connection->prepare('
103
+	           SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
104
+                   FROM `*PREFIX*pax_fax`
105
+                   WHERE `user_id` = ?');
106
+	  $result = $sql->execute([$userId]);
107
+          $settingsfromdb = $result->fetch();
108
+          $result->closeCursor();
109
+
110
+          if ($settingsfromdb['api_key'] != '') {
111
+
112
+              // Send a placeholder to the browser, instead of the real data
113
+              $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
114
+          }
115
+          if ($settingsfromdb['api_secret'] != '') {
116
+              $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
117
+          }
118
+          if ($settingsfromdb['webhook_token'] != '') {
119
+              $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20";
120
+          }
121
+          if ($settingsfromdb['receive_url'] != '') {
122
+              $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
123
+          }
124
+
125
+          return $settingsfromdb;
126
+      }
127
+
128
+
129
+      /**
130
+       * @NoAdminRequired
131
+       *
132
+       */
133
+      public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
134
+
135
+          $sqlsel = $this->connection->prepare('
136
+	             SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
137
+                     FROM `*PREFIX*pax_fax`
138
+                     WHERE `user_id` = ?');
139
+	  $resultsel = $sqlsel->execute([$userId]);
140
+          $row = $resultsel->fetch();
141
+          $resultsel->closeCursor();
142
+
143
+          if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) {
144
+
145
+              if ($apiKey != '') {
146
+                  $apikeystrenc = $this->crypto->encrypt($apiKey);                
147
+              } else { $apikeystrenc = ''; }
148
+
149
+              if ($apiSecret != '') {
150
+                  $apisecretstrenc = $this->crypto->encrypt($apiSecret);                
151
+              } else { $apisecretstrenc = ''; }
152
+
153
+              if ($webhookToken != '') {
154
+                  $webhookTokenenc = $this->crypto->encrypt($webhookToken);               
155
+              } else { $webhookTokenenc = ''; }
156
+
157
+              if ($receiveUrl != '') {
158
+                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl);                
159
+              } else { $receiveUrlenc = ''; }
160
+
161
+              $sqlns = $this->connection->prepare('
162
+				INSERT INTO `*PREFIX*pax_fax`
163
+					(`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`)
164
+				VALUES (?, ?, ?, ?, ?, ?, ?)');
165
+	      $sqlns->execute([$userId, $apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail]);
166
+
167
+          } else {
168
+
169
+              if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
170
+                  $apikeystrenc = $this->crypto->encrypt($apiKey);                
171
+              } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
172
+                  $apikeystrenc = $row['api_key'];
173
+              } elseif ($apiKey == '') {
174
+                  $apikeystrenc = '';
175
+              }
176
+
177
+              if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
178
+                  $apisecretstrenc = $this->crypto->encrypt($apiSecret);                
179
+              } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
180
+                  $apisecretstrenc = $row['api_secret'];
181
+              } elseif ($apiSecret == '') {
182
+                  $apisecretstrenc = '';
183
+              }
184
+
185
+              if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
186
+                  $webhookTokenenc = $this->crypto->encrypt($webhookToken);                
187
+              } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
188
+                  $webhookTokenenc = $row['webhook_token'];
189
+              } elseif ($webhookToken == '') {
190
+                  $webhookTokenenc = '';
191
+              }
192
+
193
+              if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
194
+                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl);                
195
+              } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
196
+                  $receiveUrlenc = $row['receive_url'];
197
+              } elseif ($receiveUrl == '') {
198
+                  $receiveUrlenc = '';
199
+              }
200
+
201
+	      $sqlup = $this->connection->prepare('
202
+			UPDATE `*PREFIX*pax_fax`
203
+			SET `api_key` = ?, `api_secret` = ?, `webhook_token` = ?, `receive_url` = ?, `get_notification` = ?, `notification_email` = ?
204
+                        WHERE `user_id` = ?');
205
+	      $updateRes = $sqlup->execute([$apikeystrenc, $apisecretstrenc, $webhookTokenenc, $receiveUrlenc, $getNotification, $notificationEmail, $userId]);
206
+	      $updateRes->closeCursor();
207
+          }
208
+      }
209
+
210
+      /**
211
+       * @NoAdminRequired
212
+       */
213
+      public function getapicredentials($userId) {
214
+
215
+              $sqlselcr = $this->connection->prepare('
216
+	                    SELECT `id`, `user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email` 
217
+                            FROM `*PREFIX*pax_fax`
218
+                            WHERE `user_id` = ?');
219
+	      $resultselcr = $sqlselcr->execute([$userId]);
220
+              $settingsfrdb = $resultselcr->fetch();
221
+              $resultselcr->closeCursor();
222
+
223
+              if (($settingsfrdb['api_key'] != '') && ($settingsfrdb['api_key'] != 'undefined') && ($settingsfrdb['api_key'] != null)) {
224
+                   $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key']);
225
+              } else { $apikeystr = ''; }
226
+
227
+              if (($settingsfrdb['api_secret'] != '') && ($settingsfrdb['api_secret'] != 'undefined') && ($settingsfrdb['api_secret'] != null)) {              
228
+                   $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret']);
229
+              } else { $apisecretstr = ''; }
230
+
231
+              if (($settingsfrdb['webhook_token'] != '') && ($settingsfrdb['webhook_token'] != 'undefined') && ($settingsfrdb['webhook_token'] != null)) {            
232
+                   $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token']);
233
+              } else { $webhookToken = ''; }
234
+
235
+              if (($settingsfrdb['receive_url'] != '') && ($settingsfrdb['receive_url'] != 'undefined') && ($settingsfrdb['receive_url'] != null)) {
236
+                   $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url']);
237
+              } else { $receiveUrl = ''; }
238
+
239
+              $getnotification = $settingsfrdb['get_notification'];
240
+              $notifyemail = $settingsfrdb['notification_email'];
241
+
242
+              return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail];
243
+      }
244
+
245
+}
Browse code

removed CHANGELOG.txt Contributors.txt README.md templates/settings.php appinfo/info.xml appinfo/signature.json lib/Service/PaxfaxService.php lib/Controller/AuthorApiController.php lib/Controller/PaxfaxController.php

DoubleBastionAdmin authored on 10/05/2022 18:00:53
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,226 +0,0 @@
1
-<?php
2
-/**
3
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
4
- *
5
- * @author Double Bastion LLC
6
- *
7
- * @license GNU AGPL version 3 or any later version
8
- *
9
- * This program is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
- * License as published by the Free Software Foundation; either
12
- * version 3 of the License, or any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
- *
19
- * You should have received a copy of the GNU Affero General Public
20
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
- *
22
- */
23
-
24
-declare(strict_types=1);
25
-
26
-namespace OCA\PaxFax\Service;
27
-
28
-use OCP\DB\QueryBuilder\IQueryBuilder;
29
-use OCP\IDBConnection;
30
-use OCP\Security\ICrypto;
31
-
32
-use OCP\AppFramework\ApiController;
33
-use OCP\IRequest;
34
-use OCP\AppFramework\Controller;
35
-use OCP\Files\IAppData;
36
-use OCP\AppFramework\App;
37
-use OCP\Files\NotPermittedException;
38
-use OCP\Files\Folder;
39
-use OC\Files\Filesystem;
40
-use \ReflectionClass;
41
-
42
-use Phaxio;
43
-use Phaxio\OperationResult;
44
-use Phaxio\Error\AuthenticationException;
45
-use Phaxio\Error\NotFoundException;
46
-use Phaxio\Error\InvalidRequestException;
47
-use Phaxio\Error\RateLimitException;
48
-use Phaxio\Error\APIConnectionException;
49
-use Phaxio\Error\GeneralException;
50
-
51
-
52
-class PaxfaxService {
53
-
54
-      private $connection;
55
-
56
-      private $crypto;
57
-
58
-      public function __construct(IDBConnection $connection, ICrypto $crypto) {
59
-
60
-              $this->connection = $connection;
61
-
62
-              $this->crypto = $crypto;
63
-      }
64
-
65
-
66
-      /**
67
-       * @NoAdminRequired
68
-       */
69
-      public function object_to_array($obj) {
70
-         if(is_object($obj)) $obj = (array)$this->dismount($obj);
71
-         if(is_array($obj)) {
72
-            $new = array();
73
-            foreach($obj as $key => $val) {
74
-                $new[$key] = $this->object_to_array($val);
75
-            }
76
-         }
77
-         else $new = $obj;
78
-         return $new;
79
-      }
80
-
81
-
82
-      /**
83
-       * @NoAdminRequired
84
-       */
85
-      public function dismount($object) {
86
-         $reflectionClass = new ReflectionClass(get_class($object));
87
-         $array = array();
88
-         foreach ($reflectionClass->getProperties() as $property) {
89
-            $property->setAccessible(true);
90
-            $array[$property->getName()] = $property->getValue($object);
91
-            $property->setAccessible(false);
92
-         }
93
-         return $array;
94
-      }
95
-
96
-
97
-      /**
98
-       * @NoAdminRequired
99
-       *
100
-       */
101
-      public function getsettings($userId) {
102
-
103
-          $sql0 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'";
104
-
105
-          $res0 = $this->connection->prepare($sql0);
106
-          $res0->execute();
107
-
108
-          $settingsfromdb = $res0->fetch();
109
-          if ($settingsfromdb['api_key'] != '') {
110
-
111
-              // Send a placeholder to the browser, instead of the real API key
112
-              $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
113
-          }
114
-          if ($settingsfromdb['api_secret'] != '') {
115
-              $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
116
-          }
117
-          if ($settingsfromdb['webhook_token'] != '') {
118
-              $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20";
119
-          }
120
-          if ($settingsfromdb['receive_url'] != '') {
121
-              $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
122
-          }
123
-          $res0->closeCursor();
124
-
125
-          return $settingsfromdb;
126
-      }
127
-
128
-
129
-      /**
130
-       * @NoAdminRequired
131
-       *
132
-       */
133
-      public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
134
-
135
-          $sql1 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'";
136
-          $res1 = $this->connection->prepare($sql1);
137
-          $res1->execute();
138
-
139
-          $row = $res1->fetch();
140
-          $res1->closeCursor();
141
-
142
-          if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) {
143
-
144
-              if ($apiKey != '') {
145
-                  $apikeystrenc = $this->crypto->encrypt($apiKey, $password = '');                
146
-              } else { $apikeystrenc = ''; }
147
-
148
-              if ($apiSecret != '') {
149
-                  $apisecretstrenc = $this->crypto->encrypt($apiSecret, $password = '');                
150
-              } else { $apisecretstrenc = ''; }
151
-
152
-              if ($webhookToken != '') {
153
-                  $webhookTokenenc = $this->crypto->encrypt($webhookToken, $password = '');               
154
-              } else { $webhookTokenenc = ''; }
155
-
156
-              if ($receiveUrl != '') {
157
-                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl, $password = '');                
158
-              } else { $receiveUrlenc = ''; }
159
-
160
-              $sql2 = "INSERT INTO `*PREFIX*pax_fax` (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`) VALUES ('$userId', '$apikeystrenc', '$apisecretstrenc', '$webhookTokenenc', '$receiveUrlenc', '$getNotification', '$notificationEmail')";
161
-              $res2 = $this->connection->prepare($sql2);
162
-              $res2->execute();
163
-
164
-          } else {
165
-
166
-              if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
167
-                  $apikeystrenc = $this->crypto->encrypt($apiKey, $password = '');                
168
-              } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
169
-                  $apikeystrenc = $row['api_key'];
170
-              } elseif ($apiKey == '') {
171
-                  $apikeystrenc = '';
172
-              }
173
-
174
-              if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
175
-                  $apisecretstrenc = $this->crypto->encrypt($apiSecret, $password = '');                
176
-              } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
177
-                  $apisecretstrenc = $row['api_secret'];
178
-              } elseif ($apiSecret == '') {
179
-                  $apisecretstrenc = '';
180
-              }
181
-
182
-              if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
183
-                  $webhookTokenenc = $this->crypto->encrypt($webhookToken, $password = '');                
184
-              } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
185
-                  $webhookTokenenc = $row['webhook_token'];
186
-              } elseif ($webhookToken == '') {
187
-                  $webhookTokenenc = '';
188
-              }
189
-
190
-              if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
191
-                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl, $password = '');                
192
-              } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
193
-                  $receiveUrlenc = $row['receive_url'];
194
-              } elseif ($receiveUrl == '') {
195
-                  $receiveUrlenc = '';
196
-              }
197
-
198
-              $sql3 = "UPDATE `*PREFIX*pax_fax` SET `api_key` = '$apikeystrenc', `api_secret` = '$apisecretstrenc', `webhook_token` = '$webhookTokenenc', `receive_url` = '$receiveUrlenc', `get_notification` = '$getNotification', `notification_email` = '$notificationEmail' WHERE `user_id` = '$userId'";
199
-              $res3 = $this->connection->prepare($sql3);
200
-              $res3->execute();
201
-          }
202
-      }
203
-
204
-      /**
205
-       * @NoAdminRequired
206
-       */
207
-      public function getapicredentials($userId) {
208
-
209
-              $sql7 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'";
210
-              $res7 = $this->connection->prepare($sql7);
211
-              $res7->execute();
212
-              $settingsfrdb = $res7->fetch();
213
-              $res7->closeCursor();
214
-
215
-              $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key'], $password = '');
216
-              $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret'], $password = '');
217
-              $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token'], $password = '');
218
-              $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url'], $password = '');
219
-              $getnotification = $settingsfrdb['get_notification'];
220
-              $notifyemail = $settingsfrdb['notification_email'];
221
-
222
-              return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail];
223
-
224
-      }
225
-
226
-}
Browse code

Created repository.

DoubleBastionAdmin authored on 01/03/2022 23:31:10
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,226 @@
1
+<?php
2
+/**
3
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
4
+ *
5
+ * @author Double Bastion LLC
6
+ *
7
+ * @license GNU AGPL version 3 or any later version
8
+ *
9
+ * This program is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3 of the License, or any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
+ *
19
+ * You should have received a copy of the GNU Affero General Public
20
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+
24
+declare(strict_types=1);
25
+
26
+namespace OCA\PaxFax\Service;
27
+
28
+use OCP\DB\QueryBuilder\IQueryBuilder;
29
+use OCP\IDBConnection;
30
+use OCP\Security\ICrypto;
31
+
32
+use OCP\AppFramework\ApiController;
33
+use OCP\IRequest;
34
+use OCP\AppFramework\Controller;
35
+use OCP\Files\IAppData;
36
+use OCP\AppFramework\App;
37
+use OCP\Files\NotPermittedException;
38
+use OCP\Files\Folder;
39
+use OC\Files\Filesystem;
40
+use \ReflectionClass;
41
+
42
+use Phaxio;
43
+use Phaxio\OperationResult;
44
+use Phaxio\Error\AuthenticationException;
45
+use Phaxio\Error\NotFoundException;
46
+use Phaxio\Error\InvalidRequestException;
47
+use Phaxio\Error\RateLimitException;
48
+use Phaxio\Error\APIConnectionException;
49
+use Phaxio\Error\GeneralException;
50
+
51
+
52
+class PaxfaxService {
53
+
54
+      private $connection;
55
+
56
+      private $crypto;
57
+
58
+      public function __construct(IDBConnection $connection, ICrypto $crypto) {
59
+
60
+              $this->connection = $connection;
61
+
62
+              $this->crypto = $crypto;
63
+      }
64
+
65
+
66
+      /**
67
+       * @NoAdminRequired
68
+       */
69
+      public function object_to_array($obj) {
70
+         if(is_object($obj)) $obj = (array)$this->dismount($obj);
71
+         if(is_array($obj)) {
72
+            $new = array();
73
+            foreach($obj as $key => $val) {
74
+                $new[$key] = $this->object_to_array($val);
75
+            }
76
+         }
77
+         else $new = $obj;
78
+         return $new;
79
+      }
80
+
81
+
82
+      /**
83
+       * @NoAdminRequired
84
+       */
85
+      public function dismount($object) {
86
+         $reflectionClass = new ReflectionClass(get_class($object));
87
+         $array = array();
88
+         foreach ($reflectionClass->getProperties() as $property) {
89
+            $property->setAccessible(true);
90
+            $array[$property->getName()] = $property->getValue($object);
91
+            $property->setAccessible(false);
92
+         }
93
+         return $array;
94
+      }
95
+
96
+
97
+      /**
98
+       * @NoAdminRequired
99
+       *
100
+       */
101
+      public function getsettings($userId) {
102
+
103
+          $sql0 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'";
104
+
105
+          $res0 = $this->connection->prepare($sql0);
106
+          $res0->execute();
107
+
108
+          $settingsfromdb = $res0->fetch();
109
+          if ($settingsfromdb['api_key'] != '') {
110
+
111
+              // Send a placeholder to the browser, instead of the real API key
112
+              $settingsfromdb['api_key'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
113
+          }
114
+          if ($settingsfromdb['api_secret'] != '') {
115
+              $settingsfromdb['api_secret'] = "%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
116
+          }
117
+          if ($settingsfromdb['webhook_token'] != '') {
118
+              $settingsfromdb['webhook_token'] = "%20%20%20%20%20%20%20%20%20%20%20";
119
+          }
120
+          if ($settingsfromdb['receive_url'] != '') {
121
+              $settingsfromdb['receive_url']= "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20";
122
+          }
123
+          $res0->closeCursor();
124
+
125
+          return $settingsfromdb;
126
+      }
127
+
128
+
129
+      /**
130
+       * @NoAdminRequired
131
+       *
132
+       */
133
+      public function updatesettings($userId, $apiKey, $apiSecret, $webhookToken, $receiveUrl, $getNotification, $notificationEmail) {
134
+
135
+          $sql1 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'";
136
+          $res1 = $this->connection->prepare($sql1);
137
+          $res1->execute();
138
+
139
+          $row = $res1->fetch();
140
+          $res1->closeCursor();
141
+
142
+          if ($row['user_id'] == '' || $row['user_id'] == 'undefined' || $row['user_id'] == null) {
143
+
144
+              if ($apiKey != '') {
145
+                  $apikeystrenc = $this->crypto->encrypt($apiKey, $password = '');                
146
+              } else { $apikeystrenc = ''; }
147
+
148
+              if ($apiSecret != '') {
149
+                  $apisecretstrenc = $this->crypto->encrypt($apiSecret, $password = '');                
150
+              } else { $apisecretstrenc = ''; }
151
+
152
+              if ($webhookToken != '') {
153
+                  $webhookTokenenc = $this->crypto->encrypt($webhookToken, $password = '');               
154
+              } else { $webhookTokenenc = ''; }
155
+
156
+              if ($receiveUrl != '') {
157
+                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl, $password = '');                
158
+              } else { $receiveUrlenc = ''; }
159
+
160
+              $sql2 = "INSERT INTO `*PREFIX*pax_fax` (`user_id`, `api_key`, `api_secret`, `webhook_token`, `receive_url`, `get_notification`, `notification_email`) VALUES ('$userId', '$apikeystrenc', '$apisecretstrenc', '$webhookTokenenc', '$receiveUrlenc', '$getNotification', '$notificationEmail')";
161
+              $res2 = $this->connection->prepare($sql2);
162
+              $res2->execute();
163
+
164
+          } else {
165
+
166
+              if ($apiKey != '' && $apiKey != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
167
+                  $apikeystrenc = $this->crypto->encrypt($apiKey, $password = '');                
168
+              } elseif ($apiKey == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
169
+                  $apikeystrenc = $row['api_key'];
170
+              } elseif ($apiKey == '') {
171
+                  $apikeystrenc = '';
172
+              }
173
+
174
+              if ($apiSecret != '' && $apiSecret != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
175
+                  $apisecretstrenc = $this->crypto->encrypt($apiSecret, $password = '');                
176
+              } elseif ($apiSecret == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
177
+                  $apisecretstrenc = $row['api_secret'];
178
+              } elseif ($apiSecret == '') {
179
+                  $apisecretstrenc = '';
180
+              }
181
+
182
+              if ($webhookToken != '' && $webhookToken != "%20%20%20%20%20%20%20%20%20%20%20") {
183
+                  $webhookTokenenc = $this->crypto->encrypt($webhookToken, $password = '');                
184
+              } elseif ($webhookToken == "%20%20%20%20%20%20%20%20%20%20%20") {
185
+                  $webhookTokenenc = $row['webhook_token'];
186
+              } elseif ($webhookToken == '') {
187
+                  $webhookTokenenc = '';
188
+              }
189
+
190
+              if ($receiveUrl != '' && $receiveUrl != "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
191
+                  $receiveUrlenc = $this->crypto->encrypt($receiveUrl, $password = '');                
192
+              } elseif ($receiveUrl == "%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {
193
+                  $receiveUrlenc = $row['receive_url'];
194
+              } elseif ($receiveUrl == '') {
195
+                  $receiveUrlenc = '';
196
+              }
197
+
198
+              $sql3 = "UPDATE `*PREFIX*pax_fax` SET `api_key` = '$apikeystrenc', `api_secret` = '$apisecretstrenc', `webhook_token` = '$webhookTokenenc', `receive_url` = '$receiveUrlenc', `get_notification` = '$getNotification', `notification_email` = '$notificationEmail' WHERE `user_id` = '$userId'";
199
+              $res3 = $this->connection->prepare($sql3);
200
+              $res3->execute();
201
+          }
202
+      }
203
+
204
+      /**
205
+       * @NoAdminRequired
206
+       */
207
+      public function getapicredentials($userId) {
208
+
209
+              $sql7 = "SELECT * FROM `*PREFIX*pax_fax` WHERE `user_id` = '$userId'";
210
+              $res7 = $this->connection->prepare($sql7);
211
+              $res7->execute();
212
+              $settingsfrdb = $res7->fetch();
213
+              $res7->closeCursor();
214
+
215
+              $apikeystr = $this->crypto->decrypt($settingsfrdb['api_key'], $password = '');
216
+              $apisecretstr = $this->crypto->decrypt($settingsfrdb['api_secret'], $password = '');
217
+              $webhookToken = $this->crypto->decrypt($settingsfrdb['webhook_token'], $password = '');
218
+              $receiveUrl = $this->crypto->decrypt($settingsfrdb['receive_url'], $password = '');
219
+              $getnotification = $settingsfrdb['get_notification'];
220
+              $notifyemail = $settingsfrdb['notification_email'];
221
+
222
+              return [$apikeystr, $apisecretstr, $webhookToken, $receiveUrl, $getnotification, $notifyemail];
223
+
224
+      }
225
+
226
+}