-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBCon.php
executable file
·254 lines (239 loc) · 7.29 KB
/
DBCon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
/*
Copyright © 2009,2015,2022 Siggi Bjarnason.
Licensed under GNU GPL v3 and later. Check out LICENSE.TXT for details
or see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>
Main connection file, handles DB connections and other initialization
*/
require_once("functions.php");
// default_charset = "utf-8";
ini_set( "default_charset", "UTF-8" );
set_time_limit(30);
$DevEnvironment = getenv("DEVENV");
$ROOTPATH = "/";
$HeadImg ="img/apisim.png";
$CSSName = "SiteStyle.css";
$ErrMsg = "We seem to be experiencing some technical difficulties, " .
"hopefully we'll have it resolved shortly.<br>" .
"If you have any questions please contact us at [email protected].";
# All Environment and secret vars are specified in ExtVars.php
# Follow instruction there on how to adjust.
require("ExtVars.php");
if($DBServerName == "" or $UID == "" or $PWD == "" or $MailUser == ""
or $MailPWD == "" or $MailHost == "" or $MailHostPort == ""
or $UseSSL == "" or $UseStartTLS == "")
{
error_log("One or more of the required email and DB creds variable are blank");
error_log("Make sure database connections and email server conf in DBCon.php are correct.");
ShowErrHead();
}
date_default_timezone_set("UTC");
$strRemoteIP = $_SERVER["REMOTE_ADDR"];
$Priv = 0; // Default Privledge level is public or 0
$strHost = $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] != 80 and $_SERVER["SERVER_PORT"] != 443)
{
$strHost .= ":".$_SERVER["SERVER_PORT"];
}
$strScriptName = $_SERVER["SCRIPT_NAME"];
$gFileName = __FILE__;
$strURI = $_SERVER["REQUEST_URI"];
$HeadAdd = "";
$strSiteLabel = "";
$DBError = "false";
$strHostNameParts = explode(".",$strHost);
$HostnamePartCount = count($strHostNameParts);
$OSEnv = "not used";
if($HostnamePartCount == 1)
{
$SiteType = "a";
}
else
{
$SiteType = $strHostNameParts[0];
}
$strURL = "Localhost/";
try
{
$dbh = new mysqli($DBServerName, $UID, $PWD, $DefaultDB);
}
catch(Exception $e)
{
error_log("Error while attempting to create a new mysqli client to $DBServerName.$DefaultDB using $UID and password that starts with "
. substr($PWD,0,3) . " " . $e->getMessage());
error_log("Make sure database connections in DBCon.php are correct.");
ShowErrHead();
}
$dbh->set_charset("utf8");
if($dbh->connect_errno)
{
error_log( "Failed to connect to $DBServerName.$DefaultDB using $UID and password that starts with " . substr($PWD,0,3) . " Error(" . $dbh->connect_errno . ") " . $dbh->connect_error);
error_log("Make sure database connections in DBCon.php are correct.");
$DBError = "true";
}
else
{
$strQuery = "SELECT * FROM tblconf";
$QueryData = QuerySQL($strQuery);
if($QueryData[0] > 0)
{
foreach($QueryData[1] as $Row)
{
$ConfArray[$Row["vcValueName"]] = $Row["vcValue"];
switch($Row["vcValueName"])
{
case "SupportEmail":
$SupportEmail = $Row["vcValue"];
break;
case "HeadKeyLen":
$HKeyLen = $Row["vcValue"];
break;
case "FootKeyLen":
$FKeyLen = $Row["vcValue"];
break;
case "ImgHeight":
$ImgHeight = $Row["vcValue"];
break;
case "Owner":
$Owner = $Row["vcValue"];
break;
case "Address1":
$Address1 = $Row["vcValue"];
break;
case "Address2":
$Address2 = $Row["vcValue"];
break;
case "Phone":
$Phone = $Row["vcValue"];
break;
case "ProfileNotify":
$ProfileNotify = $Row["vcValue"];
break;
case "Copyright":
$Copyright = $Row["vcValue"];
break;
case "Maintenance":
$Maintenance = $Row["vcValue"];
break;
case "EmailFromAddr":
$eFromAddr = $Row["vcValue"];
break;
case "EmailFromName":
$eFromName = $Row["vcValue"];
break;
case "ShowLinkURL":
$ShowLinkURL = $Row["vcValue"];
break;
case "SiteMessage":
$strSiteLabel = $Row["vcValue"];
break;
case "HeadAdd":
$HeadAdd = $Row["vcValue"];
break;
case "DefNumWeeks":
$DefNumWeeks = $Row["vcValue"];
break;
case "DefClassLen":
$DefClassLen = $Row["vcValue"];
break;
case "defClassPrice":
$DefClassPrice = $Row["vcValue"];
break;
case "ShowLast":
$ShowLastClass = $Row["vcValue"];
break;
case "ClassDur":
$ClassDuration = $Row["vcValue"];
break;
case "CTUnit":
$CTUnit = $Row["vcValue"];
break;
case "TimeFormat":
$strTimeFormat = $Row["vcValue"];
break;
case "DateFormat":
$strDateFormat = $Row["vcValue"];
break;
case "PDFBase":
$strPDFBaseName = $Row["vcValue"];
break;
case "DefMaxStudent":
$DefMaxStudent = $Row["vcValue"];
break;
case "minRegLevel":
$minRegLevel = $Row["vcValue"];
break;
case "SecureOpt":
$strSecOpt = $Row["vcValue"];
break;
case "NumAdminCol":
$iNumCol = $Row["vcValue"];
break;
case "ShowAdminSub":
$ShowAdminSub = $Row["vcValue"];
break;
case "UserTimeout":
$Timeout = $Row["vcValue"] * 60;
break;
case "NewPWDLen":
$PWDLength = $Row["vcValue"];
break;
case "MinPWDLen":
$MinPWDLen = $Row["vcValue"];
break;
case "ProductName":
$ProdName = $Row["vcValue"];
break;
case "USOnly":
$bUSOnly = $Row["vcValue"];
break;
}
}
}
else
{
$strMsg = Array2String($QueryData[1]);
error_log("Query of $strQuery did not return data. Rowcount: $QueryData[0] Msg:$strMsg");
printPg($ErrMsg,"error");
}
}
$FromEmail = "From:$eFromName <$eFromAddr>";
if(!isset($_SESSION))
{
session_start();
}
if(isset($_SERVER["HTTP_REFERER"]))
{
$strReferer = $_SERVER["HTTP_REFERER"];
}
else
{
$strReferer = "";
}
if(isset($_SERVER["HTTPS"]))
{
$strProto = "https://";
}
else
{
$strProto = "http://";
}
$strPageURL = $strProto . $strHost . $strURI;
$PostVarCount = count($_POST);
$dtNow = date('Y-m-d H:i:s');
$strQuery = "SELECT vcTextName, tPageTexts FROM tblPageTexts;";
$QueryData = QuerySQL($strQuery);
if($QueryData[0] > 0)
{
foreach($QueryData[1] as $Row)
{
$TextArray[$Row["vcTextName"]] = str_replace("\n","<br>\n",$Row["tPageTexts"]);
}
}
else
{
$strMsg = Array2String($QueryData[1]);
error_log("Query of $strQuery did not return data. Rowcount: $QueryData[0] Msg:$strMsg");
printPg($ErrMsg,"error");
}
?>