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,61 @@
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
+    define('ACCESSCONST', TRUE);
17
+
18
+    require('db-connect.php');
19
+
20
+    $username = $_POST['username'];
21
+
22
+    // Get the id of the user who asks for their Telnyx balance
23
+    $query1 = $mysqli->prepare("SELECT id, username FROM app_users WHERE BINARY username = ?");
24
+    $query1->bind_param("s", $username);
25
+    $query1->execute();
26
+    $queryres = $query1->get_result()->fetch_assoc();
27
+    $userID = $queryres['id'];
28
+
29
+    // Get the encrypted Telnyx key from the 'fax_settings' table
30
+    $query2 = $mysqli->prepare("SELECT userid, tel_secret_key FROM fax_settings WHERE userid = ?");
31
+    $query2->bind_param("i", $userID);
32
+    $query2->execute();
33
+    $fetchInfo = $query2->get_result()->fetch_assoc();
34
+    $telnyxKeyEnc = $fetchInfo['tel_secret_key'];
35
+
36
+    // Decrypt the key obtained from the 'fax_settings' table
37
+    $psswdaddedkey = file_get_contents('../restr/' . $username . '/pwdtelnyxkey');
38
+    $componentsippsswd = explode(':', $telnyxKeyEnc);
39
+    $encpwdin = $componentsippsswd[0];
40
+    $ivkey = $componentsippsswd[1];
41
+    $telnyxKey = openssl_decrypt($encpwdin, 'AES-256-CBC', $psswdaddedkey, false, $ivkey);
42
+
43
+    // Get the Telnyx balance
44
+    $ch = curl_init();
45
+    curl_setopt($ch, CURLOPT_URL, "https://api.telnyx.com/v2/balance");
46
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
47
+    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Accept: application/json", "Authorization: Bearer " . $telnyxKey));
48
+    $responsetel = curl_exec($ch);
49
+    if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200) { $messagetosend = 'success'; } else { $messagetosend = 'failure'; }
50
+    $recdatatel = json_decode($responsetel, TRUE);
51
+    $telbalresponse = $recdatatel['data']['balance'];
52
+    $telnyxBalance = round(floatval($telbalresponse), 3);
53
+    curl_close($ch);
54
+
55
+    $respdata = ['messagetosend' => $messagetosend, 'telnyxbalance' => $telnyxBalance];
56
+
57
+    echo json_encode($respdata);
58
+
59
+} else { header("Location: ../login.php"); }
60
+
61
+?>