Browse code

Created repository.

DoubleBastionAdmin authored on 29/11/2024 03:10:08
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,97 @@
1
+<?php
2
+/**
3
+ * @copyright 2024 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
+if (!defined('ACCESSCONST')) {
25
+    exit();
26
+}
27
+
28
+if (is_file(dirname(__FILE__) . '/panel-config.php')) {
29
+
30
+ // Read the configuration file and extract the database credentials
31
+ $configfilestring = file_get_contents(dirname(__FILE__) . '/panel-config.php');
32
+
33
+ if (preg_match_all('[include|include_once|require|require_once]', $configfilestring) != 0) {
34
+
35
+     if (strpos($configfilestring, "'") !== false) {
36
+             $continit = explode("'", $configfilestring);
37
+             $configfilepath = $continit[1];
38
+     } elseif (strpos($configfilestring, "\"") !== false) {
39
+             $continit = explode("\"", $configfilestring);
40
+             $configfilepath = $continit[1];
41
+       }
42
+
43
+     $configfilelines = file($configfilepath);
44
+
45
+     if (count($configfilelines) != 0) {
46
+
47
+        foreach ($configfilelines as $keyfile => $valuefile) {
48
+
49
+           if (strpos($valuefile, "\$databasename") !== false) {
50
+                 $dbname_init = explode("'", $valuefile);
51
+                 $dbname = $dbname_init[1];
52
+           } elseif (strpos($valuefile, "\$username") !== false) {
53
+                 $dbusername_init = explode("'", $valuefile);
54
+                 $dbusername = $dbusername_init[1];
55
+           } elseif (strpos($valuefile, "\$password") !== false) {
56
+                 $dbuserpass_init = explode("'", $valuefile);
57
+                 $dbuserpass = $dbuserpass_init[1];
58
+             }
59
+        }
60
+     }
61
+
62
+ } else {
63
+
64
+     $configfilelines = file(dirname(__FILE__) . '/panel-config.php');
65
+
66
+     if (count($configfilelines) != 0) {
67
+
68
+        foreach ($configfilelines as $keyfile => $valuefile) {
69
+
70
+           if (strpos($valuefile, "\$databasename") !== false) {
71
+                 $dbname_init = explode("'", $valuefile);
72
+                 $dbname = $dbname_init[1];
73
+           } elseif (strpos($valuefile, "\$username") !== false) {
74
+                 $dbusername_init = explode("'", $valuefile);
75
+                 $dbusername = $dbusername_init[1];
76
+           } elseif (strpos($valuefile, "\$password") !== false) {
77
+                 $dbuserpass_init = explode("'", $valuefile);
78
+                 $dbuserpass = $dbuserpass_init[1];
79
+             }
80
+        }
81
+     }
82
+   }
83
+
84
+ mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
85
+
86
+ // Connect to the database
87
+ $mysqli = new mysqli('localhost', $dbusername, $dbuserpass, $dbname);
88
+
89
+ if ($mysqli->connect_error) {
90
+     exit('Error connecting to the database !');
91
+ }
92
+
93
+ $mysqli->set_charset("utf8mb4");
94
+
95
+}
96
+
97
+?>