Browse code

Changed majority of files.

DoubleBastionAdmin authored on 30/11/2024 06:56:40
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,584 @@
1
+<?php
2
+/**
3
+ *  Copyright (C) 2021  Double Bastion LLC
4
+ *
5
+ *  This file is part of Roundpin, which is licensed under the
6
+ *  GNU Affero General Public License Version 3.0. The license terms
7
+ *  are detailed in the "LICENSE.txt" file located in the root directory.
8
+ */
9
+
10
+session_start();
11
+
12
+ // header('Set-Cookie: PHPSESSID= ' . session_id() . '; SameSite=strict; Secure=true; HttpOnly=true;');
13
+
14
+if (isset($_POST['s_ajax_call']) && ($_POST['s_ajax_call'] == $_SESSION['validate_s_access'])) {
15
+
16
+
17
+    define('ACCESSCONST', TRUE);
18
+
19
+    require('db-connect.php');
20
+
21
+    $username = $_POST['username'];
22
+    $wssServer = $_POST['wss_server'];
23
+    $webSocketPort = $_POST['web_socket_port'];
24
+    $serverPath = $_POST['server_path'];
25
+    $profileName = $_POST['profile_name'];
26
+    $sipUsername = $_POST['sip_username'];
27
+    $sipPasswordPre = $_POST['sip_password'];
28
+    $stunServer = $_POST['stun_server'];
29
+    $audioOutputId = $_POST['audio_output_id'];
30
+    $videoSrcId = $_POST['video_src_id'];
31
+    $videoHeight = $_POST['video_height'];
32
+    $frameRate = $_POST['frame_rate'];
33
+    $aspectRatio = $_POST['aspect_ratio'];
34
+    $videoOrientation = $_POST['video_orientation'];
35
+    $ringTone = $_POST['ringtone'];
36
+    $audioSrcId = $_POST['audio_src_id'];
37
+    $autoGainControl = $_POST['auto_gain_control'];
38
+    $echoCancellation = $_POST['echo_cancellation'];
39
+    $noiseSuppression = $_POST['noise_suppression'];
40
+    $ringOutputId = $_POST['ring_output_id'];
41
+    $videoConfWindowWidth = $_POST['video_conf_window_width'];
42
+    $profilePicture = $_POST['profile_picture'];
43
+    $language = $_POST['language'];
44
+    $notifications = $_POST['notifications'];
45
+    $showVconfNames = $_POST['show_vconf_usernames'];
46
+    $displayVconfUser = $_POST['display_vconf_user'];
47
+    $useEmail = $_POST['use_email'];
48
+    $rcDomain = $_POST['rcdomain'];
49
+    $rcBasicAuthUser = $_POST['rcbasicauthuser'];
50
+    $rcBasicAuthPass = $_POST['rcbasicauthpass'];
51
+    $rcUser = $_POST['rcuser'];
52
+    $rcPassword = $_POST['rcpassword'];
53
+    $loadGroups = $_POST['load_groups'];
54
+    $voicenmb = $_POST['voicenmb'];
55
+    $voicedefnmb = $_POST['voicedefnmb'];
56
+    $smsnmb = $_POST['smsnmb'];
57
+    $smsdefnmb = $_POST['smsdefnmb'];
58
+    $telsecretkey = $_POST['telsecretkey'];
59
+    $telfaxappid = $_POST['telfaxappid'];
60
+    $telrecwhurl = $_POST['telrecwhurl'];
61
+    $phaxapikey = $_POST['phaxapikey'];
62
+    $phaxapisecret = $_POST['phaxapisecret'];
63
+    $phaxwebhooktoken = $_POST['phaxwebhooktoken'];
64
+    $phaxreceiveurl = $_POST['phaxreceiveurl'];
65
+    $faxnotification = $_POST['faxnotification'];
66
+    $faxnotifyemail = $_POST['faxnotifyemail'];
67
+    $faxnmb = $_POST['faxnmb'];
68
+    $faxdefnmb = $_POST['faxdefnmb'];
69
+
70
+    $messageupdata5 = 'success';
71
+    $messageupdata6 = 'success';
72
+    $messageupdata7 = 'success';
73
+    $messageupdata8 = 'success';
74
+    $messageupdata9 = 'success';
75
+    $messageupdata10 = 'success';
76
+    $messageupdata11 = 'success';
77
+    $messageupdata12 = 'success';
78
+
79
+
80
+    // Get the id of the current user from the 'app_users' table
81
+    $queryselid = $mysqli->prepare("SELECT id, username FROM app_users WHERE BINARY username = ?");
82
+    $queryselid->bind_param("s", $username);
83
+    $queryselid->execute(); 
84
+    $queryselid = $queryselid->get_result()->fetch_assoc();
85
+    $userid = $queryselid['id'];
86
+
87
+
88
+    // Remove the directories for temporary files from the 'src/email-to-fax/tmp' folder, for the current user, if any
89
+    $queryfaxwhurl = $mysqli->prepare("SELECT userid, tel_recwh_url, phax_receive_url FROM fax_settings WHERE userid = ?");
90
+    $queryfaxwhurl->bind_param("i", $userid);
91
+    $queryfaxwhurl->execute(); 
92
+    $queryfxurlres = $queryfaxwhurl->get_result()->fetch_assoc();
93
+    $telnyxurl = $queryfxurlres['tel_recwh_url'];
94
+    $phaxiourl = $queryfxurlres['phax_receive_url'];
95
+
96
+    if ($queryfxurlres) {
97
+
98
+        if ($telnyxurl) {
99
+
100
+            // Remove the directory for temporary files from the 'src/email-to-fax/tmp' folder, for the current user, for Telnyx, if any
101
+            $usertmpdirtxarr = explode("/", $telnyxurl);
102
+            $usertmpdirtxpre = array_reverse($usertmpdirtxarr);
103
+            $usertmpdirtx = substr($usertmpdirtxpre[0], 8, 20);
104
+            if (is_dir(dirname(__FILE__) . '/email-to-fax/tmp/' . $usertmpdirtx)) {
105
+                array_map('unlink', glob(dirname(__FILE__) . '/email-to-fax/tmp/' . $usertmpdirtx . "/*"));
106
+                rmdir(dirname(__FILE__) . '/email-to-fax/tmp/' . $usertmpdirtx);
107
+            }
108
+
109
+
110
+            if ($telrecwhurl) {
111
+
112
+                // Remove the files with random alphanumeric strings as names, that were previously created to receive webhook requests from Telnyx
113
+                foreach (glob(dirname(__FILE__) . "/telnyxfaxwh-*.php") as $flnametx) { unlink($flnametx); }
114
+
115
+                // Create a new file having a random alphanumeric string as name, to prevent unwanted access, since its name will be part of the webhook URL for Telnyx
116
+                $telrecwhurlarr = explode("/", $telrecwhurl);
117
+                $telrecwhfile = end($telrecwhurlarr);
118
+                // The atypical indentation that follows is intentional
119
+                $texttosavetx = "<?php
120
+/**
121
+ *  Copyright (C) 2021  Double Bastion LLC
122
+ *
123
+ *  This file is part of Roundpin, which is licensed under the
124
+ *  GNU Affero General Public License Version 3.0. The license terms
125
+ *  are detailed in the 'LICENSE.txt' file located in the root directory.
126
+ */
127
+
128
+include(dirname(__FILE__) . '/receive-telnyx-fax-webhooks.php');
129
+?>";
130
+                file_put_contents(dirname(__FILE__) . "/" . $telrecwhfile, $texttosavetx);
131
+            }   
132
+        }
133
+
134
+        if ($phaxiourl) {
135
+
136
+            // Remove the directory for temporary files from the 'src/email-to-fax/tmp' folder, for the current user, for Phaxio, if any
137
+            $usertmpdirpharr = explode("/", $phaxiourl);
138
+            $usertmpdirphpre = array_reverse($usertmpdirpharr);
139
+            $usertmpdirph = substr($usertmpdirphpre[0], 9, 20);
140
+            if (is_dir(dirname(__FILE__) . '/email-to-fax/tmp/' . $usertmpdirph)) {
141
+                array_map('unlink', glob(dirname(__FILE__) . '/email-to-fax/tmp/' . $usertmpdirph . "/*"));
142
+                rmdir(dirname(__FILE__) . '/email-to-fax/tmp/' . $usertmpdirph);
143
+            }
144
+
145
+
146
+            if ($phaxreceiveurl) {
147
+
148
+                // Remove the files with random alphanumeric strings as names, that were previously created to receive webhook requests from Phaxio
149
+                foreach (glob(dirname(__FILE__) . "/phaxiofaxwh-*.php") as $flnameph) { unlink($flnameph); }
150
+
151
+                // Create a new file having a random alphanumeric string as name, to prevent unwanted access, since its name will be part of the webhook URL for Phaxio
152
+                $phaxrecwhurlarr = explode("/", $phaxreceiveurl);
153
+                $phaxrecwhfile = end($phaxrecwhurlarr);
154
+                // The atypical indentation that follows is intentional
155
+                $texttosaveph = "<?php
156
+/**
157
+ *  Copyright (C) 2021  Double Bastion LLC
158
+ *
159
+ *  This file is part of Roundpin, which is licensed under the
160
+ *  GNU Affero General Public License Version 3.0. The license terms
161
+ *  are detailed in the 'LICENSE.txt' file located in the root directory.
162
+ */
163
+
164
+include(dirname(__FILE__) . '/receive-phaxio-fax-webhooks.php');
165
+?>";
166
+                file_put_contents(dirname(__FILE__) . "/" . $phaxrecwhfile, $texttosaveph);
167
+            }
168
+        }
169
+    }
170
+
171
+
172
+    // Encrypt the SIP password, the keys from the Fax and SMS sections (if any), Roundcube password (if any) and Roundcube basic auth password (if any), before inserting them into the database
173
+
174
+    if ($sipPasswordPre != '' && $sipPasswordPre != "%20%20%20%20%20%20%20") {
175
+
176
+        $keypass = substr(sha1((string) mt_rand()), 0, 32);
177
+        $keysalt = openssl_random_pseudo_bytes(12);
178
+        $generated_key = openssl_pbkdf2($keypass, $keysalt, 40, 100, 'sha256');
179
+        $psswdadded = bin2hex($generated_key);
180
+
181
+        if (!is_dir('../restr')) {
182
+            mkdir('../restr', 0700);
183
+        }
184
+
185
+        if (!is_dir('../restr/' . $username . '')) {
186
+            mkdir('../restr/' . $username . '', 0700);
187
+        }
188
+
189
+        if (file_put_contents('../restr/' . $username . '/pwdkey', $psswdadded)) { $messageupdatasippwd1 = 'success'; } else { $messageupdatasippwd1 = 'failure'; }
190
+        if (chmod('../restr/' . $username . '/pwdkey', 0600)) { $messageupdatasippwd2 = 'success'; } else { $messageupdatasippwd2 = 'failure'; }
191
+        if ($messageupdatasippwd1 == 'success' && $messageupdatasippwd2 == 'success') { $messageupdata5 = 'success'; } else { $messageupdata5 = 'failure'; }
192
+
193
+        $iv = substr(sha1((string) mt_rand()), 0, 16);
194
+        $encpwdin = openssl_encrypt($sipPasswordPre, 'AES-256-CBC', $psswdadded, false, $iv);
195
+        $sipPasswordEnc = $encpwdin.':'.$iv;
196
+
197
+    } elseif ($sipPasswordPre == "%20%20%20%20%20%20%20") {
198
+
199
+              $queryselsippass = $mysqli->prepare("SELECT username, sip_password FROM app_users WHERE BINARY username = ?");
200
+              $queryselsippass->bind_param("s", $username);
201
+              $queryselsippass->execute();
202
+              $sippassarr = $queryselsippass->get_result()->fetch_assoc();
203
+              $sipPasswordEnc = $sippassarr['sip_password'];
204
+
205
+    } elseif ($sipPasswordPre == '') {
206
+              $sipPasswordEnc = '';
207
+
208
+    } else { $sipPasswordEnc = ''; }
209
+
210
+
211
+    if ($telsecretkey != '' && $telsecretkey != "%20%20%20%20%20%20%20") {
212
+
213
+        $keypasstelkey = substr(sha1((string) mt_rand()), 0, 32);
214
+        $keysalttelkey = openssl_random_pseudo_bytes(12);
215
+        $generated_keytelkey = openssl_pbkdf2($keypasstelkey, $keysalttelkey, 40, 100, 'sha256');
216
+        $psswdaddedtelkey = bin2hex($generated_keytelkey);
217
+
218
+        if (!is_dir('../restr')) {
219
+            mkdir('../restr', 0700);
220
+        }
221
+
222
+        if (!is_dir('../restr/' . $username . '')) {
223
+            mkdir('../restr/' . $username . '', 0700);
224
+        }
225
+
226
+        if (file_put_contents('../restr/' . $username . '/pwdtelnyxkey', $psswdaddedtelkey)) { $messageupdatatelkey1 = 'success'; } else { $messageupdatatelkey1 = 'failure'; }
227
+        if (chmod('../restr/' . $username . '/pwdtelnyxkey', 0600)) { $messageupdatatelkey2 = 'success'; } else { $messageupdatatelkey2 = 'failure'; }
228
+        if ($messageupdatatelkey1 == 'success' && $messageupdatatelkey2 == 'success') { $messageupdata11 = 'success'; } else { $messageupdata11 = 'failure'; }
229
+
230
+        $iv8 = substr(sha1((string) mt_rand()), 0, 16);
231
+        $enctelkey = openssl_encrypt($telsecretkey, 'AES-256-CBC', $psswdaddedtelkey, false, $iv8);
232
+        $telsecretkeyEnc = $enctelkey.':'.$iv8;
233
+
234
+    } elseif ($telsecretkey == "%20%20%20%20%20%20%20") {
235
+              $queryseltelkeypass = $mysqli->prepare("SELECT userid, tel_secret_key FROM fax_settings WHERE userid = ?");
236
+              $queryseltelkeypass->bind_param("i", $userid);
237
+              $queryseltelkeypass->execute();
238
+              $telkeypassarr = $queryseltelkeypass->get_result()->fetch_assoc();
239
+              $telsecretkeyEnc = $telkeypassarr['tel_secret_key'];
240
+
241
+    } elseif ($telsecretkey == '') {
242
+              $telsecretkeyEnc = '';
243
+
244
+    } else { $telsecretkeyEnc = ''; }
245
+
246
+
247
+    if ($telfaxappid != '' && $telfaxappid != "%20%20%20%20%20%20%20") {
248
+
249
+        $keypasstelappid = substr(sha1((string) mt_rand()), 0, 32);
250
+        $keysalttelappid = openssl_random_pseudo_bytes(12);
251
+        $generated_keytelappid = openssl_pbkdf2($keypasstelappid, $keysalttelappid, 40, 100, 'sha256');
252
+        $psswdaddedtelappid = bin2hex($generated_keytelappid);
253
+
254
+        if (!is_dir('../restr')) {
255
+            mkdir('../restr', 0700);
256
+        }
257
+
258
+        if (!is_dir('../restr/' . $username . '')) {
259
+            mkdir('../restr/' . $username . '', 0700);
260
+        }
261
+
262
+        if (file_put_contents('../restr/' . $username . '/pwdtelnyxappid', $psswdaddedtelappid)) { $messageupdatatelappid1 = 'success'; } else { $messageupdatatelappid1 = 'failure'; }
263
+        if (chmod('../restr/' . $username . '/pwdtelnyxappid', 0600)) { $messageupdatatelappid2 = 'success'; } else { $messageupdatatelappid2 = 'failure'; }
264
+        if ($messageupdatatelappid1 == 'success' && $messageupdatatelappid2 == 'success') { $messageupdata12 = 'success'; } else { $messageupdata12 = 'failure'; }
265
+
266
+        $iv9 = substr(sha1((string) mt_rand()), 0, 16);
267
+        $enctelappid = openssl_encrypt($telfaxappid, 'AES-256-CBC', $psswdaddedtelappid, false, $iv9);
268
+        $telfaxappidEnc = $enctelappid.':'.$iv9;
269
+
270
+    } elseif ($telfaxappid == "%20%20%20%20%20%20%20") {
271
+              $queryseltelappidpass = $mysqli->prepare("SELECT userid, tel_fax_app_id FROM fax_settings WHERE userid = ?");
272
+              $queryseltelappidpass->bind_param("i", $userid);
273
+              $queryseltelappidpass->execute();
274
+              $telappidpassarr = $queryseltelappidpass->get_result()->fetch_assoc();
275
+              $telfaxappidEnc = $telappidpassarr['tel_fax_app_id'];
276
+
277
+    } elseif ($telfaxappid == '') {
278
+              $telfaxappidEnc = '';
279
+
280
+    } else { $telfaxappidEnc = ''; }
281
+
282
+
283
+    if ($phaxapikey != '' && $phaxapikey != "%20%20%20%20%20%20%20") {
284
+
285
+        $keypassphkey = substr(sha1((string) mt_rand()), 0, 32);
286
+        $keysaltphkey = openssl_random_pseudo_bytes(12);
287
+        $generated_keyphkey = openssl_pbkdf2($keypassphkey, $keysaltphkey, 40, 100, 'sha256');
288
+        $psswdaddedphkey = bin2hex($generated_keyphkey);
289
+
290
+        if (!is_dir('../restr')) {
291
+            mkdir('../restr', 0700);
292
+        }
293
+
294
+        if (!is_dir('../restr/' . $username . '')) {
295
+            mkdir('../restr/' . $username . '', 0700);
296
+        }
297
+
298
+        if (file_put_contents('../restr/' . $username . '/pwdphaxiokey', $psswdaddedphkey)) { $messageupdataphkey1 = 'success'; } else { $messageupdataphkey1 = 'failure'; }
299
+        if (chmod('../restr/' . $username . '/pwdphaxiokey', 0600)) { $messageupdataphkey2 = 'success'; } else { $messageupdataphkey2 = 'failure'; }
300
+        if ($messageupdataphkey1 == 'success' && $messageupdataphkey2 == 'success') { $messageupdata6 = 'success'; } else { $messageupdata6 = 'failure'; }
301
+
302
+        $iv2 = substr(sha1((string) mt_rand()), 0, 16);
303
+        $encphkey = openssl_encrypt($phaxapikey, 'AES-256-CBC', $psswdaddedphkey, false, $iv2);
304
+        $phaxapikeyEnc = $encphkey.':'.$iv2;
305
+
306
+    } elseif ($phaxapikey == "%20%20%20%20%20%20%20") {
307
+              $queryselphkeypass = $mysqli->prepare("SELECT userid, phax_api_key FROM fax_settings WHERE userid = ?");
308
+              $queryselphkeypass->bind_param("i", $userid);
309
+              $queryselphkeypass->execute();
310
+              $phkeypassarr = $queryselphkeypass->get_result()->fetch_assoc();
311
+              $phaxapikeyEnc = $phkeypassarr['phax_api_key'];
312
+
313
+    } elseif ($phaxapikey == '') {
314
+              $phaxapikeyEnc = '';
315
+
316
+    } else { $phaxapikeyEnc = ''; }
317
+
318
+
319
+    if ($phaxapisecret != '' && $phaxapisecret != "%20%20%20%20%20%20%20") {
320
+
321
+        $keypassphsecret = substr(sha1(string) (mt_rand()), 0, 32);
322
+        $keysaltphsecret = openssl_random_pseudo_bytes(12);
323
+        $generated_keyphsecret = openssl_pbkdf2($keypassphsecret, $keysaltphsecret, 40, 100, 'sha256');
324
+        $psswdaddedphsecret = bin2hex($generated_keyphsecret);
325
+
326
+        if (!is_dir('../restr')) {
327
+            mkdir('../restr', 0700);
328
+        }
329
+
330
+        if (!is_dir('../restr/' . $username . '')) {
331
+            mkdir('../restr/' . $username . '', 0700);
332
+        }
333
+
334
+        if (file_put_contents('../restr/' . $username . '/pwdphaxiosecret', $psswdaddedphsecret)) { $messageupdataphsec1 = 'success'; } else { $messageupdataphsec1 = 'failure'; }
335
+        if (chmod('../restr/' . $username . '/pwdphaxiosecret', 0600)) { $messageupdataphsec2 = 'success'; } else { $messageupdataphsec2 = 'failure'; }
336
+        if ($messageupdataphsec1 == 'success' && $messageupdataphsec2 == 'success') { $messageupdata7 = 'success'; } else { $messageupdata7 = 'failure'; }
337
+
338
+        $iv3 = substr(sha1((string) mt_rand()), 0, 16);
339
+        $encphsecret = openssl_encrypt($phaxapisecret, 'AES-256-CBC', $psswdaddedphsecret, false, $iv3);
340
+        $phaxapisecretEnc = $encphsecret.':'.$iv3;
341
+
342
+    } elseif ($phaxapisecret == "%20%20%20%20%20%20%20") {
343
+              $queryselphsecretpass = $mysqli->prepare("SELECT userid, phax_api_secret FROM fax_settings WHERE userid = ?");
344
+              $queryselphsecretpass->bind_param("i", $userid);
345
+              $queryselphsecretpass->execute();
346
+              $phsecretpassarr = $queryselphsecretpass->get_result()->fetch_assoc();
347
+              $phaxapisecretEnc = $phsecretpassarr['phax_api_secret'];
348
+
349
+    } elseif ($phaxapisecret == '') {
350
+              $phaxapisecretEnc = '';
351
+
352
+    } else { $phaxapisecretEnc = ''; }
353
+
354
+
355
+    if ($phaxwebhooktoken != '' && $phaxwebhooktoken != "%20%20%20%20%20%20%20") {
356
+
357
+        $keypassphwhtoken = substr(sha1((string) mt_rand()), 0, 32);
358
+        $keysaltphwhtoken = openssl_random_pseudo_bytes(12);
359
+        $generated_keyphwhtoken = openssl_pbkdf2($keypassphwhtoken, $keysaltphwhtoken, 40, 100, 'sha256');
360
+        $psswdaddedphwhtoken = bin2hex($generated_keyphwhtoken);
361
+
362
+        if (!is_dir('../restr')) {
363
+            mkdir('../restr', 0700);
364
+        }
365
+
366
+        if (!is_dir('../restr/' . $username . '')) {
367
+            mkdir('../restr/' . $username . '', 0700);
368
+        }
369
+
370
+        if (file_put_contents('../restr/' . $username . '/pwdphaxiowhtoken', $psswdaddedphwhtoken)) { $messageupdataphwht1 = 'success'; } else { $messageupdataphwht1 = 'failure'; }
371
+        if (chmod('../restr/' . $username . '/pwdphaxiowhtoken', 0600)) { $messageupdataphwht2 = 'success'; } else { $messageupdataphwht2 = 'failure'; }
372
+        if ($messageupdataphwht1 == 'success' && $messageupdataphwht2 == 'success') { $messageupdata8 = 'success'; } else { $messageupdata8 = 'failure'; }
373
+
374
+        $iv4 = substr(sha1((string) mt_rand()), 0, 16);
375
+        $encphwhtoken = openssl_encrypt($phaxwebhooktoken, 'AES-256-CBC', $psswdaddedphwhtoken, false, $iv4);
376
+        $phaxapiwhtokenEnc = $encphwhtoken.':'.$iv4;
377
+
378
+    } elseif ($phaxwebhooktoken == "%20%20%20%20%20%20%20") {
379
+              $queryselphwhtpass = $mysqli->prepare("SELECT userid, phax_webhook_token FROM fax_settings WHERE userid = ?");
380
+              $queryselphwhtpass->bind_param("i", $userid);
381
+              $queryselphwhtpass->execute();
382
+              $phwhtpassarr = $queryselphwhtpass->get_result()->fetch_assoc();
383
+              $phaxapiwhtokenEnc = $phwhtpassarr['phax_webhook_token'];
384
+
385
+    } elseif ($phaxwebhooktoken == '') {
386
+              $phaxapiwhtokenEnc = '';
387
+
388
+    } else { $phaxapiwhtokenEnc = ''; }
389
+
390
+
391
+    if ($rcBasicAuthPass != '' && $rcBasicAuthPass != "%20%20%20%20%20%20%20") {
392
+
393
+        $keypassrcba = substr(sha1((string) mt_rand()), 0, 32);
394
+        $keysaltrcba = openssl_random_pseudo_bytes(12);
395
+        $generated_keyrcba = openssl_pbkdf2($keypassrcba, $keysaltrcba, 40, 100, 'sha256');
396
+        $psswdaddedrcba = bin2hex($generated_keyrcba);
397
+
398
+        if (!is_dir('../restr')) {
399
+            mkdir('../restr', 0700);
400
+        }
401
+
402
+        if (!is_dir('../restr/' . $username . '')) {
403
+            mkdir('../restr/' . $username . '', 0700);
404
+        }
405
+
406
+        if (file_put_contents('../restr/' . $username . '/pwdkeyrcba', $psswdaddedrcba)) { $messageupdatarcba1 = 'success'; } else { $messageupdatarcba1 = 'failure'; }
407
+        if (chmod('../restr/' . $username . '/pwdkeyrcba', 0600)) { $messageupdatarcba2 = 'success'; } else { $messageupdatarcba2 = 'failure'; }
408
+        if ($messageupdatarcba1 == 'success' && $messageupdatarcba2 == 'success') { $messageupdata9 = 'success'; } else { $messageupdata9 = 'failure'; }
409
+
410
+        $iv6 = substr(sha1((string) mt_rand()), 0, 16);
411
+        $encRcBasicAuthPass = openssl_encrypt($rcBasicAuthPass, 'AES-256-CBC', $psswdaddedrcba, false, $iv6);
412
+        $rcBasicAuthPassEnc = $encRcBasicAuthPass.':'.$iv6;
413
+
414
+    } elseif ($rcBasicAuthPass == "%20%20%20%20%20%20%20") {
415
+              $queryselrcbapass = $mysqli->prepare("SELECT userid, rcbasicauthpass FROM email_conf WHERE userid = ?");
416
+              $queryselrcbapass->bind_param("i", $userid);
417
+              $queryselrcbapass->execute();
418
+              $rcbapassarr = $queryselrcbapass->get_result()->fetch_assoc();
419
+              $rcBasicAuthPassEnc = $rcbapassarr['rcbasicauthpass'];
420
+
421
+    } elseif ($rcBasicAuthPass == '') {
422
+              $rcBasicAuthPassEnc = '';
423
+
424
+    } else { $rcBasicAuthPassEnc = ''; }
425
+
426
+
427
+    if ($rcPassword != '' && $rcPassword != "%20%20%20%20%20%20%20") {
428
+
429
+        $keypassrc = substr(sha1((string) mt_rand()), 0, 32);
430
+        $keysaltrc = openssl_random_pseudo_bytes(12);
431
+        $generated_keyrc = openssl_pbkdf2($keypassrc, $keysaltrc, 40, 100, 'sha256');
432
+        $psswdaddedrc = bin2hex($generated_keyrc);
433
+
434
+        if (!is_dir('../restr')) {
435
+            mkdir('../restr', 0700);
436
+        }
437
+
438
+        if (!is_dir('../restr/' . $username . '')) {
439
+            mkdir('../restr/' . $username . '', 0700);
440
+        }
441
+
442
+        if (file_put_contents('../restr/' . $username . '/pwdkeyrc', $psswdaddedrc)) { $messageupdatarcp1 = 'success'; } else { $messageupdatarcp1 = 'failure'; }
443
+        if (chmod('../restr/' . $username . '/pwdkeyrc', 0600)) { $messageupdatarcp2 = 'success'; } else { $messageupdatarcp2 = 'failure'; }
444
+        if ($messageupdatarcp1 == 'success' && $messageupdatarcp2 == 'success') { $messageupdata10 = 'success'; } else { $messageupdata10 = 'failure'; }
445
+
446
+        $iv7 = substr(sha1((string) mt_rand()), 0, 16);
447
+        $encRcPassword = openssl_encrypt($rcPassword, 'AES-256-CBC', $psswdaddedrc, false, $iv7);
448
+        $rcPasswordEnc = $encRcPassword.':'.$iv7;
449
+
450
+    } elseif ($rcPassword == "%20%20%20%20%20%20%20") {
451
+              $queryselrcpass = $mysqli->prepare("SELECT userid, rcpassword FROM email_conf WHERE userid = ?");
452
+              $queryselrcpass->bind_param("i", $userid);
453
+              $queryselrcpass->execute(); 
454
+              $queryselres = $queryselrcpass->get_result()->fetch_assoc();
455
+              $rcPasswordEnc = $queryselres['rcpassword'];
456
+
457
+    } elseif ($rcPassword == '') { 
458
+              $rcPasswordEnc = '';
459
+
460
+    } else { $rcPasswordEnc = ''; }
461
+
462
+
463
+    // Insert account data for the current user in the 'app_users' table
464
+    $crrntTime = date("Y-m-d H:i:s");
465
+
466
+    $query1 = $mysqli->prepare("UPDATE `app_users` SET `wss_server`=?, `web_socket_port`=?, `server_path`=?, `profile_name`=?, `sip_username`=?, `sip_password`=?, `stun_server`=?,
467
+                               `audio_output_id`=?, `video_src_id`=?, `video_height`=?, `frame_rate`=?, `aspect_ratio`=?, `video_orientation`=?, `ringtone`=?, `audio_src_id`=?, 
468
+                               `auto_gain_control`=?, `echo_cancellation`=?, `noise_suppression`=?, `ring_output_id`=?, `video_conf_window_width`=?, `profile_picture`=?, 
469
+                               `language`=?, `notifications`=?, `show_vconf_usernames`=?, `display_vconf_user`=?, `use_email`=?, `load_groups`=?, `date_modified`=? 
470
+                                WHERE BINARY `username`=?");
471
+    $query1->bind_param("sissssssssisssssssssssiiiisss", $wssServer, $webSocketPort, $serverPath, $profileName, $sipUsername, $sipPasswordEnc, $stunServer, $audioOutputId,
472
+                         $videoSrcId, $videoHeight, $frameRate, $aspectRatio, $videoOrientation, $ringTone, $audioSrcId, $autoGainControl, $echoCancellation, $noiseSuppression,
473
+                         $ringOutputId, $videoConfWindowWidth, $profilePicture, $language, $notifications, $showVconfNames, $displayVconfUser, $useEmail, $loadGroups, 
474
+                         $crrntTime, $username);
475
+    if ($query1->execute()) { $messageupdata1 = 'success'; } else { $messageupdata1 = 'failure'; }
476
+
477
+
478
+    // Check if the fax settings for the current user are already in the `fax_settings` table
479
+    $queryfaxck = $mysqli->prepare("SELECT id, userid FROM fax_settings WHERE userid = ?");
480
+    $queryfaxck->bind_param("i", $userid);
481
+    $queryfaxck->execute(); 
482
+    $queryfaxckres = $queryfaxck->get_result()->fetch_assoc();
483
+
484
+    if ($queryfaxckres) {
485
+
486
+        // Update the fax settings for the current user in the `fax_settings` table
487
+        $queryupfax = $mysqli->prepare("UPDATE `fax_settings` SET `tel_secret_key`=?, `tel_fax_app_id`=?, `tel_recwh_url`=?, `phax_api_key`=?, `phax_api_secret`=?, 
488
+                                       `phax_webhook_token`=?, `phax_receive_url`=?, `get_notification`=?, `notification_email`=? WHERE `userid`=?");
489
+        $queryupfax->bind_param("sssssssisi", $telsecretkeyEnc, $telfaxappidEnc, $telrecwhurl, $phaxapikeyEnc, $phaxapisecretEnc, $phaxapiwhtokenEnc, $phaxreceiveurl, 
490
+                                 $faxnotification, $faxnotifyemail, $userid);
491
+        if ($queryupfax->execute()) { $messageupdata2 = 'success'; } else { $messageupdata2 = 'failure'; }
492
+
493
+    } else {
494
+
495
+        // Insert the fax settings for the current user in the `fax_settings` table
496
+        $queryinsfax = $mysqli->prepare("INSERT INTO `fax_settings` (userid, tel_secret_key, tel_fax_app_id, tel_recwh_url, phax_api_key, phax_api_secret, phax_webhook_token, 
497
+                                         phax_receive_url, get_notification, notification_email) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
498
+        $queryinsfax->bind_param("isssssssis", $userid, $telsecretkeyEnc, $telfaxappidEnc, $telrecwhurl, $phaxapikeyEnc, $phaxapisecretEnc, $phaxapiwhtokenEnc, $phaxreceiveurl, 
499
+                                  $faxnotification, $faxnotifyemail);
500
+        if ($queryinsfax->execute()) { $messageupdata2 = 'success'; } else { $messageupdata2 = 'failure'; }
501
+    }
502
+
503
+
504
+    // Check if the voice/sms/fax numbers for the current user are already in the `phone_numbers` table
505
+    $queryphck = $mysqli->prepare("SELECT id, userid FROM phone_numbers WHERE userid = ?");
506
+    $queryphck->bind_param("i", $userid);
507
+    $queryphck->execute(); 
508
+    $queryphckres = $queryphck->get_result()->fetch_assoc();
509
+
510
+    if ($queryphckres) {
511
+
512
+        // Update voice/sms/fax numbers for the current user in the `phone_numbers` table
513
+        $queryuphnb = $mysqli->prepare("UPDATE `phone_numbers` SET `voice_numbers`=?, `default_voice_number`=?, `sms_numbers`=?, `default_sms_number`=?, `fax_numbers`=?, 
514
+                                       `default_fax_number`=? WHERE `userid`=?");
515
+        $queryuphnb->bind_param("ssssssi", $voicenmb, $voicedefnmb, $smsnmb, $smsdefnmb, $faxnmb, $faxdefnmb, $userid);
516
+        if ($queryuphnb->execute()) { $messageupdata3 = 'success'; } else { $messageupdata3 = 'failure'; }
517
+
518
+    } else {
519
+
520
+        // Insert voice/sms/fax numbers for the current user in the `phone_numbers` table
521
+        $queryinsnb = $mysqli->prepare("INSERT INTO `phone_numbers` (userid, voice_numbers, default_voice_number, sms_numbers, default_sms_number, fax_numbers, default_fax_number) 
522
+                                        VALUES (?, ?, ?, ?, ?, ?, ?)");
523
+        $queryinsnb->bind_param("issssss", $userid, $voicenmb, $voicedefnmb, $smsnmb, $smsdefnmb, $faxnmb, $faxdefnmb);
524
+        if ($queryinsnb->execute()) { $messageupdata3 = 'success'; } else { $messageupdata3 = 'failure'; }
525
+    }
526
+
527
+
528
+    // Check if the email configuration data is already in the `email_conf` table
529
+    $query2 = $mysqli->prepare("SELECT id, userid FROM email_conf WHERE userid = ?");
530
+    $query2->bind_param("s", $userid);
531
+    $query2->execute(); 
532
+    $querychck = $query2->get_result()->fetch_assoc();
533
+
534
+    if ($querychck) {
535
+
536
+        // Update email configuration data in the 'email_conf' table
537
+        $query3 = $mysqli->prepare("UPDATE `email_conf` SET `rcdomain`=?, `rcuser`=?, `rcpassword`=?, `rcbasicauthuser`=?, `rcbasicauthpass`=? WHERE `userid`=?");
538
+        $query3->bind_param("sssssi", $rcDomain, $rcUser, $rcPasswordEnc, $rcBasicAuthUser, $rcBasicAuthPassEnc, $userid);
539
+        if ($query3->execute()) { $messageupdata4 = 'success'; } else { $messageupdata4 = 'failure'; }
540
+
541
+    } else {
542
+
543
+        // Insert email configuration data in the 'email_conf' table
544
+        $query4 = $mysqli->prepare("INSERT INTO `email_conf` (userid, rcdomain, rcuser, rcpassword, rcbasicauthuser, rcbasicauthpass) VALUES (?, ?, ?, ?, ?, ?)");
545
+        $query4->bind_param("isssss", $userid, $rcDomain, $rcUser, $rcPasswordEnc, $rcBasicAuthUser, $rcBasicAuthPassEnc);
546
+        if ($query4->execute()) { $messageupdata4 = 'success'; } else { $messageupdata4 = 'failure'; }
547
+    }
548
+
549
+
550
+    // Update profile picture in the 'contacts' table
551
+    if ($profilePicture != '') {
552
+
553
+              $queryselextno = $mysqli->prepare("SELECT id, extension_number FROM contacts WHERE extension_number = ?");
554
+              $queryselextno->bind_param("s", $sipUsername);
555
+              $queryselextno->execute(); 
556
+              $totextensions = $queryselextno->get_result();
557
+              $errchck = 0;
558
+              while ($foundextensions = $totextensions->fetch_assoc()) {
559
+                     $querypics = $mysqli->prepare("UPDATE `contacts` SET `profile_picture_c`=? WHERE `extension_number`=?");
560
+                     $querypics->bind_param("ss", $profilePicture, $sipUsername);
561
+                     if (!$querypics->execute()) { ++$errchck; }
562
+              }
563
+              if ($errchck == 0) { $messageuppicture = 'success'; } else { $messageuppicture = 'failure'; }
564
+
565
+    } else { $messageuppicture = 'success'; }
566
+
567
+
568
+    if ($messageupdata1 == 'success' && $messageupdata2 == 'success' && $messageupdata3 == 'success' && $messageupdata4 == 'success' &&
569
+        $messageupdata5 == 'success' && $messageupdata6 == 'success' && $messageupdata7 == 'success' && $messageupdata8 == 'success' &&
570
+        $messageupdata9 == 'success' && $messageupdata10 == 'success' && $messageupdata11 == 'success' && $messageupdata12 == 'success') {
571
+        $messageupdata = 'success';
572
+    } else { 
573
+        $messageupdata = 'failure';
574
+    }
575
+
576
+    $response = array('resultupdata' => $messageupdata, 'resultuppicture' => $messageuppicture, 'indivresults' => [$messageupdata1, $messageupdata2, $messageupdata3,
577
+                       $messageupdata4, $messageupdata5, $messageupdata6, $messageupdata7, $messageupdata8, $messageupdata9, $messageupdata10, $messageupdata11, $messageupdata12]);
578
+    echo json_encode($response);
579
+
580
+} else {
581
+    header("Location: ../login.php");
582
+}
583
+
584
+?>