1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,83 @@ |
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 |
+if (!defined('ACCESSCONST')) { |
|
11 |
+ die(); |
|
12 |
+} |
|
13 |
+ |
|
14 |
+if (is_file(dirname(__FILE__) . '/roundpin-config.php')) { |
|
15 |
+ |
|
16 |
+ // Read the configuration file and extract the database credentials |
|
17 |
+ $configfilestring = file_get_contents(dirname(__FILE__) . '/roundpin-config.php'); |
|
18 |
+ |
|
19 |
+ if (preg_match_all('[include|include_once|require|require_once]', $configfilestring) != 0) { |
|
20 |
+ |
|
21 |
+ if (strpos($configfilestring, "'") !== false) { |
|
22 |
+ $continit = explode("'", $configfilestring); |
|
23 |
+ $configfilepath = $continit[1]; |
|
24 |
+ } elseif (strpos($configfilestring, "\"") !== false) { |
|
25 |
+ $continit = explode("\"", $configfilestring); |
|
26 |
+ $configfilepath = $continit[1]; |
|
27 |
+ } |
|
28 |
+ |
|
29 |
+ $configfilelines = file($configfilepath); |
|
30 |
+ |
|
31 |
+ if (count($configfilelines) != 0) { |
|
32 |
+ |
|
33 |
+ foreach ($configfilelines as $keyfile => $valuefile) { |
|
34 |
+ |
|
35 |
+ if (strpos($valuefile, "\$databasename") !== false) { |
|
36 |
+ $dbname_init = explode("'", $valuefile); |
|
37 |
+ $dbname = $dbname_init[1]; |
|
38 |
+ } elseif (strpos($valuefile, "\$username") !== false) { |
|
39 |
+ $dbusername_init = explode("'", $valuefile); |
|
40 |
+ $dbusername = $dbusername_init[1]; |
|
41 |
+ } elseif (strpos($valuefile, "\$password") !== false) { |
|
42 |
+ $dbuserpass_init = explode("'", $valuefile); |
|
43 |
+ $dbuserpass = $dbuserpass_init[1]; |
|
44 |
+ } |
|
45 |
+ } |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ } else { |
|
49 |
+ |
|
50 |
+ $configfilelines = file(dirname(__FILE__) . '/roundpin-config.php'); |
|
51 |
+ |
|
52 |
+ if (count($configfilelines) != 0) { |
|
53 |
+ |
|
54 |
+ foreach ($configfilelines as $keyfile => $valuefile) { |
|
55 |
+ |
|
56 |
+ if (strpos($valuefile, "\$databasename") !== false) { |
|
57 |
+ $dbname_init = explode("'", $valuefile); |
|
58 |
+ $dbname = $dbname_init[1]; |
|
59 |
+ } elseif (strpos($valuefile, "\$username") !== false) { |
|
60 |
+ $dbusername_init = explode("'", $valuefile); |
|
61 |
+ $dbusername = $dbusername_init[1]; |
|
62 |
+ } elseif (strpos($valuefile, "\$password") !== false) { |
|
63 |
+ $dbuserpass_init = explode("'", $valuefile); |
|
64 |
+ $dbuserpass = $dbuserpass_init[1]; |
|
65 |
+ } |
|
66 |
+ } |
|
67 |
+ } |
|
68 |
+ } |
|
69 |
+ |
|
70 |
+ mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); |
|
71 |
+ |
|
72 |
+ // Connect to the database |
|
73 |
+ $mysqli = new mysqli('localhost', $dbusername, $dbuserpass, $dbname); |
|
74 |
+ |
|
75 |
+ if ($mysqli->connect_error) { |
|
76 |
+ exit('Error connecting to the database !'); |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ $mysqli->set_charset("utf8mb4"); |
|
80 |
+ |
|
81 |
+} |
|
82 |
+ |
|
83 |
+?> |
|
0 | 84 |
\ No newline at end of file |