1
|
|
|
<?php |
2
|
|
|
/**************************************************************************** |
3
|
|
|
* ./lib/clicompatbase.inc.php |
4
|
|
|
* -------------------- |
5
|
|
|
* begin : Fri September 16 2005 |
6
|
|
|
* For license information see LICENSE.md |
7
|
|
|
****************************************************************************/ |
8
|
|
|
|
9
|
|
|
use Oc\Util\CBench; |
10
|
|
|
|
11
|
|
|
/**************************************************************************** |
12
|
|
|
* contains functions that are compatible with the php-CLI-scripts under util. |
13
|
|
|
* Can be included without including common.inc.php, but will be included from |
14
|
|
|
* common.inc.php. |
15
|
|
|
* Global variables that need to be set up when including without common.inc.php: |
16
|
|
|
* $dblink |
17
|
|
|
****************************************************************************/ |
18
|
|
|
|
19
|
|
|
require_once __DIR__ . '/../vendor/autoload.php'; |
20
|
|
|
|
21
|
|
|
global $interface_output, $dblink_slave; |
22
|
|
|
if (!isset($interface_output)) { |
23
|
|
|
$interface_output = 'plain'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
if (isset($opt['rootpath'])) { |
27
|
|
|
$rootpath = $opt['rootpath']; |
28
|
|
|
} elseif (isset($rootpath)) { |
29
|
|
|
$opt['rootpath'] = $rootpath; |
30
|
|
|
} else { |
31
|
|
|
$rootpath = __DIR__ . '/../'; |
32
|
|
|
$opt['rootpath'] = $rootpath; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// yepp, we will use UTF-8 |
36
|
|
|
mb_internal_encoding('UTF-8'); |
37
|
|
|
mb_regex_encoding('UTF-8'); |
38
|
|
|
mb_language('uni'); |
39
|
|
|
|
40
|
|
|
//load default webserver-settings and common includes |
41
|
|
|
require_once __DIR__ . '/consts.inc.php'; |
42
|
|
|
require_once __DIR__ . '/settings.inc.php'; |
43
|
|
|
require_once __DIR__ . '/../lib2/errorhandler.inc.php'; |
44
|
|
|
|
45
|
|
|
// check for banned UAs |
46
|
|
|
$useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
47
|
|
View Code Duplication |
foreach ($opt['page']['banned_user_agents'] as $ua) { |
48
|
|
|
if (strpos($useragent, $ua) !== false) { |
49
|
|
|
die(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// basic PHP settings |
54
|
|
|
date_default_timezone_set($timezone); |
55
|
|
|
register_errorhandlers(); |
56
|
|
|
|
57
|
|
|
if (isset($debug_page) && $debug_page) { |
58
|
|
|
ini_set('display_errors', true); |
59
|
|
|
ini_set('error_reporting', E_ALL); |
60
|
|
|
} else { |
61
|
|
|
ini_set('display_errors', false); |
62
|
|
|
ini_set('error_reporting', E_ALL & ~E_NOTICE); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$dblink_slave = false; |
66
|
|
|
$db_error = 0; |
67
|
|
|
|
68
|
|
|
// prepare EMail-From |
69
|
|
|
$emailheaders = 'From: "' . $emailaddr . '" <' . $emailaddr . '>'; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $module |
73
|
|
|
* @param int $eventId |
74
|
|
|
* @param $userId |
75
|
|
|
* @param $objectid1 |
76
|
|
|
* @param int $objectid2 |
77
|
|
|
* @param string $logtext |
78
|
|
|
* @param $details |
79
|
|
|
*/ |
80
|
|
|
function logentry($module, $eventId, $userId, $objectid1, $objectid2, $logtext, $details): void |
81
|
|
|
{ |
82
|
|
|
sql( |
|
|
|
|
83
|
|
|
"INSERT INTO logentries (`module`, `eventid`, `userid`, `objectid1`, `objectid2`, `logtext`, `details`) |
84
|
|
|
VALUES ('&1', '&2', '&3', '&4', '&5', '&6', '&7')", |
85
|
|
|
$module, |
86
|
|
|
$eventId, |
87
|
|
|
$userId, |
88
|
|
|
$objectid1, |
89
|
|
|
$objectid2, |
90
|
|
|
$logtext, |
91
|
|
|
serialize($details) |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// read a file and return it as a string |
96
|
|
|
// WARNING: no huge files! |
97
|
|
View Code Duplication |
function read_file($file = '') |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$content = false; |
100
|
|
|
$fh = fopen($file, 'r'); |
101
|
|
|
if ($fh) { |
102
|
|
|
$content = fread($fh, filesize($file)); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
fclose($fh); |
106
|
|
|
|
107
|
|
|
return $content; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
function escape_javascript($text) |
111
|
|
|
{ |
112
|
|
|
return str_replace('\'', '\\\'', str_replace('"', '"', $text)); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
// called if mysqli_query failed, sends email to sysadmin |
116
|
|
|
/** |
117
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
118
|
|
|
*/ |
119
|
|
|
function sql_failed(): void |
120
|
|
|
{ |
121
|
|
|
sql_error(); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
126
|
|
|
* @param string $sql |
127
|
|
|
* @param mixed $default |
128
|
|
|
*/ |
129
|
|
View Code Duplication |
function sqlValue($sql, $default) |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$rs = sql($sql); |
|
|
|
|
132
|
|
|
if ($r = sql_fetch_row($rs)) { |
|
|
|
|
133
|
|
|
if ($r[0] == null) { |
134
|
|
|
return $default; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $r[0]; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return $default; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
145
|
|
|
* @param $sql |
146
|
|
|
* @param $default |
147
|
|
|
* @return mixed |
148
|
|
|
*/ |
149
|
|
View Code Duplication |
function sql_value_slave($sql, $default) |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
$rs = sql_slave($sql); |
|
|
|
|
152
|
|
|
if ($r = sql_fetch_row($rs)) { |
|
|
|
|
153
|
|
|
if ($r[0] == null) { |
154
|
|
|
return $default; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
return $r[0]; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $default; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
165
|
|
|
* @param string $name |
166
|
|
|
* @param string $default |
167
|
|
|
* @return string |
168
|
|
|
*/ |
169
|
|
|
function getSysConfig($name, $default) |
170
|
|
|
{ |
171
|
|
|
return sqlValue('SELECT `value` FROM `sysconfig` WHERE `name`=\'' . sql_escape($name) . '\'', $default); |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
176
|
|
|
* @param string $name |
177
|
|
|
* @param string $value |
178
|
|
|
*/ |
179
|
|
|
function setSysConfig($name, $value): void |
180
|
|
|
{ |
181
|
|
|
if (sqlValue('SELECT COUNT(*) FROM sysconfig WHERE name=\'' . sql_escape($name) . '\'', 0) == 1) { |
|
|
|
|
182
|
|
|
sql( |
|
|
|
|
183
|
|
|
"UPDATE `sysconfig` SET `value`='&1' WHERE `name`='&2' LIMIT 1", |
184
|
|
|
$value, |
185
|
|
|
$name |
186
|
|
|
); |
187
|
|
|
} else { |
188
|
|
|
sql( |
|
|
|
|
189
|
|
|
"INSERT INTO `sysconfig` (`name`, `value`) VALUES ('&1', '&2')", |
190
|
|
|
$name, |
191
|
|
|
$value |
192
|
|
|
); |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
198
|
|
|
* @param $sql |
199
|
|
|
* @return mysqli_result |
200
|
|
|
*/ |
201
|
|
|
function sql($sql) |
202
|
|
|
{ |
203
|
|
|
global $dblink; |
204
|
|
|
|
205
|
|
|
// prepare args |
206
|
|
|
$args = func_get_args(); |
207
|
|
|
unset($args[0]); |
208
|
|
|
|
209
|
|
|
if (isset($args[1]) && is_array($args[1])) { |
210
|
|
|
$tmp_args = $args[1]; |
211
|
|
|
unset($args); |
212
|
|
|
|
213
|
|
|
// correct indizes |
214
|
|
|
$args = array_merge([0], $tmp_args); |
215
|
|
|
unset($tmp_args); |
216
|
|
|
unset($args[0]); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
return sql_internal($dblink, $sql, false, $args); |
|
|
|
|
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
224
|
|
|
* @param $sql |
225
|
|
|
* @return mysqli_result |
226
|
|
|
*/ |
227
|
|
|
function sql_slave($sql) |
|
|
|
|
228
|
|
|
{ |
229
|
|
|
throw new InvalidArgumentException('sql slave support was removed!'); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
234
|
|
|
* @param $_dblink |
235
|
|
|
* @param $sql |
236
|
|
|
* @return mysqli_result |
237
|
|
|
*/ |
238
|
|
|
function sql_internal($_dblink, $sql) |
239
|
|
|
{ |
240
|
|
|
global $sql_warntime; |
241
|
|
|
global $sql_replacements; |
242
|
|
|
|
243
|
|
|
$args = func_get_args(); |
244
|
|
|
unset($args[0], $args[1], $args[2]); |
245
|
|
|
|
246
|
|
|
/* as an option, you can give as second parameter an array |
247
|
|
|
* with all values for the placeholder. The array has to be |
248
|
|
|
* with numeric indices. |
249
|
|
|
*/ |
250
|
|
|
if (isset($args[3]) && is_array($args[3])) { |
251
|
|
|
$tmp_args = $args[3]; |
252
|
|
|
unset($args); |
253
|
|
|
|
254
|
|
|
// correct indices |
255
|
|
|
$args = array_merge([0], $tmp_args); |
256
|
|
|
unset($tmp_args); |
257
|
|
|
unset($args[0]); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
$sqlpos = 0; |
261
|
|
|
$filtered_sql = ''; |
262
|
|
|
|
263
|
|
|
// $sql von vorne bis hinten durchlaufen und alle &x ersetzen |
264
|
|
|
$nextarg = mb_strpos($sql, '&'); |
265
|
|
|
while ($nextarg !== false) { |
266
|
|
|
// muss dieses & ersetzt werden, oder ist es escaped? |
267
|
|
|
$escapesCount = 0; |
268
|
|
|
while ((($nextarg - $escapesCount - 1) > 0) && (mb_substr($sql, $nextarg - $escapesCount - 1, 1) == '\\')) { |
269
|
|
|
$escapesCount++; |
270
|
|
|
} |
271
|
|
|
if (($escapesCount % 2) == 1) { |
272
|
|
|
$nextarg++; |
273
|
|
|
} else { |
274
|
|
|
$nextchar = mb_substr($sql, $nextarg + 1, 1); |
275
|
|
|
if (is_numeric($nextchar)) { |
276
|
|
|
$arglength = 0; |
277
|
|
|
$arg = ''; |
278
|
|
|
|
279
|
|
|
// nächstes Zeichen das keine Zahl ist herausfinden |
280
|
|
View Code Duplication |
while (mb_ereg_match('^[0-9]{1}', $nextchar) == 1) { |
281
|
|
|
$arg .= $nextchar; |
282
|
|
|
|
283
|
|
|
$arglength++; |
284
|
|
|
$nextchar = mb_substr($sql, $nextarg + $arglength + 1, 1); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
// ok ... ersetzen |
288
|
|
|
$filtered_sql .= mb_substr($sql, $sqlpos, $nextarg - $sqlpos); |
289
|
|
|
$sqlpos = $nextarg + $arglength; |
290
|
|
|
|
291
|
|
View Code Duplication |
if (isset($args[$arg])) { |
292
|
|
|
if (is_numeric($args[$arg])) { |
293
|
|
|
$filtered_sql .= $args[$arg]; |
294
|
|
|
} else { |
295
|
|
|
if ((mb_substr($sql, $sqlpos - $arglength - 1, 1) == '\'') && |
296
|
|
|
(mb_substr($sql, $sqlpos + 1, 1) == '\'') |
297
|
|
|
) { |
298
|
|
|
$filtered_sql .= sql_escape($args[$arg]); |
|
|
|
|
299
|
|
|
} elseif ((mb_substr($sql, $sqlpos - $arglength - 1, 1) == '`') && |
300
|
|
|
(mb_substr($sql, $sqlpos + 1, 1) == '`') |
301
|
|
|
) { |
302
|
|
|
$filtered_sql .= sql_escape($args[$arg]); |
|
|
|
|
303
|
|
|
} else { |
304
|
|
|
sql_error(); |
|
|
|
|
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
} else { |
308
|
|
|
// NULL |
309
|
|
|
if ((mb_substr($sql, $sqlpos - $arglength - 1, 1) == '\'') && |
310
|
|
|
(mb_substr($sql, $sqlpos + 1, 1) == '\'') |
311
|
|
|
) { |
312
|
|
|
// Anführungszeichen weg machen und NULL einsetzen |
313
|
|
|
$filtered_sql = mb_substr($filtered_sql, 0, mb_strlen($filtered_sql) - 1); |
314
|
|
|
$filtered_sql .= 'NULL'; |
315
|
|
|
$sqlpos++; |
316
|
|
|
} else { |
317
|
|
|
$filtered_sql .= 'NULL'; |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
$sqlpos++; |
322
|
|
|
} else { |
323
|
|
|
$arglength = 0; |
324
|
|
|
$arg = ''; |
325
|
|
|
|
326
|
|
|
// nächstes Zeichen das kein Buchstabe/Zahl ist herausfinden |
327
|
|
View Code Duplication |
while (mb_ereg_match('^[a-zA-Z0-9]{1}', $nextchar) == 1) { |
328
|
|
|
$arg .= $nextchar; |
329
|
|
|
|
330
|
|
|
$arglength++; |
331
|
|
|
$nextchar = mb_substr($sql, $nextarg + $arglength + 1, 1); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
// ok ... ersetzen |
335
|
|
|
$filtered_sql .= mb_substr($sql, $sqlpos, $nextarg - $sqlpos); |
336
|
|
|
|
337
|
|
|
if (isset($sql_replacements[$arg])) { |
338
|
|
|
$filtered_sql .= $sql_replacements[$arg]; |
339
|
|
|
} else { |
340
|
|
|
sql_error(); |
|
|
|
|
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
$sqlpos = $nextarg + $arglength + 1; |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
$nextarg = mb_strpos($sql, '&', $nextarg + 1); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
// rest anhängen |
351
|
|
|
$filtered_sql .= mb_substr($sql, $sqlpos); |
352
|
|
|
|
353
|
|
|
// \& durch & ersetzen |
354
|
|
|
$nextarg = mb_strpos($filtered_sql, '\&'); |
355
|
|
View Code Duplication |
while ($nextarg !== false) { |
356
|
|
|
$escapesCount = 0; |
357
|
|
|
while ((($nextarg - $escapesCount - 1) > 0) && |
358
|
|
|
(mb_substr($filtered_sql, $nextarg - $escapesCount - 1, 1) == '\\')) { |
359
|
|
|
$escapesCount++; |
360
|
|
|
} |
361
|
|
|
if (($escapesCount % 2) == 0) { |
362
|
|
|
// \& ersetzen durch & |
363
|
|
|
$filtered_sql = mb_substr($filtered_sql, 0, $nextarg) . '&' . mb_substr($filtered_sql, $nextarg + 2); |
364
|
|
|
$nextarg--; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
$nextarg = mb_strpos($filtered_sql, '\&', $nextarg + 2); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
// |
371
|
|
|
// ok ... hier ist filtered_sql fertig |
372
|
|
|
// |
373
|
|
|
|
374
|
|
|
/* todo: |
375
|
|
|
- errorlogging |
376
|
|
|
- LIMIT |
377
|
|
|
- DROP/DELETE ggf. blocken |
378
|
|
|
*/ |
379
|
|
|
|
380
|
|
|
// Zeitmessung für die Ausführung |
381
|
|
|
$cSqlExecution = new CBench; |
382
|
|
|
$cSqlExecution->start(); |
383
|
|
|
|
384
|
|
|
$result = mysqli_query($_dblink, $filtered_sql); |
|
|
|
|
385
|
|
|
if ($result === false) { |
386
|
|
|
sql_error(); |
|
|
|
|
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
$cSqlExecution->stop(); |
390
|
|
|
|
391
|
|
|
if ($sql_warntime > 0 && $cSqlExecution->diff() > $sql_warntime) { |
392
|
|
|
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? "\r\n" . $_SERVER['HTTP_USER_AGENT'] : ''; |
393
|
|
|
sql_warn('execution took ' . $cSqlExecution->diff() . ' seconds' . $ua); |
|
|
|
|
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
return $result; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
401
|
|
|
* @param $value |
402
|
|
|
* @return false|string |
403
|
|
|
*/ |
404
|
|
|
function sql_escape($value) |
405
|
|
|
{ |
406
|
|
|
global $dblink; |
407
|
|
|
$value = mysqli_real_escape_string($dblink, $value); |
408
|
|
|
$value = mb_ereg_replace('&', '\&', $value); |
409
|
|
|
|
410
|
|
|
return $value; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
415
|
|
|
* @param $value |
416
|
|
|
* @return false|mixed|string |
417
|
|
|
*/ |
418
|
|
|
function sql_escape_backtick($value) |
419
|
|
|
{ |
420
|
|
|
$value = sql_escape($value); |
|
|
|
|
421
|
|
|
$value = str_replace('`', '``', $value); |
422
|
|
|
|
423
|
|
|
return $value; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
428
|
|
|
*/ |
429
|
|
|
function sql_error(): void |
430
|
|
|
{ |
431
|
|
|
global $debug_page; |
432
|
|
|
global $sql_errormail; |
433
|
|
|
global $emailheaders; |
434
|
|
|
global $absolute_server_URI; |
435
|
|
|
global $interface_output; |
436
|
|
|
global $dberrormsg; |
437
|
|
|
global $db_error; |
438
|
|
|
global $dblink; |
439
|
|
|
|
440
|
|
|
$db_error += 1; |
441
|
|
|
$msql_error = mysqli_connect_error() . ': ' . mysqli_error($dblink); |
442
|
|
|
if ($db_error > 1) { |
443
|
|
|
$msql_error .= "\n(** error recursion **)"; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
if ($sql_errormail != '') { |
447
|
|
|
// sendout email |
448
|
|
|
$email_content = $msql_error; |
449
|
|
|
$email_content .= "\n--------------------\n"; |
450
|
|
|
$email_content .= print_r(debug_backtrace(), true); |
451
|
|
|
if (admin_errormail($sql_errormail, 'sql_error', $email_content, $emailheaders)) { |
452
|
|
|
mb_send_mail($sql_errormail, 'sql_error: ' . $absolute_server_URI, $email_content, $emailheaders); |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
if ($interface_output == 'html') { |
457
|
|
|
// display errorpage |
458
|
|
|
$errmsg = $dberrormsg . ($debug_page ? '<br />' . $msql_error : ''); |
459
|
|
|
if ($db_error <= 1) { |
460
|
|
|
tpl_errorMsg('sql_error', $errmsg); |
461
|
|
|
} else { |
462
|
|
|
// database error recursion, because another error occurred while trying to |
463
|
|
|
// build the error template (e.g. because connection was lost, or an error mail |
464
|
|
|
// could not load translations from database) |
465
|
|
|
|
466
|
|
|
$errtitle = 'Datenbankfehler'; |
467
|
|
|
require __DIR__ . '/../html/error.php'; |
468
|
|
|
} |
469
|
|
|
exit; |
470
|
|
|
} elseif ($interface_output == 'plain') { |
471
|
|
|
echo "\n"; |
472
|
|
|
echo 'sql_error' . "\n"; |
473
|
|
|
if ($debug_page) { |
474
|
|
|
echo $msql_error . "\n"; |
475
|
|
|
} |
476
|
|
|
echo '---------' . "\n"; |
477
|
|
|
echo print_r(debug_backtrace(), true) . "\n"; |
478
|
|
|
exit; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
die('sql_error'); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
486
|
|
|
* @param string $warnmessage |
487
|
|
|
*/ |
488
|
|
|
function sql_warn($warnmessage): void |
489
|
|
|
{ |
490
|
|
|
global $sql_errormail; |
491
|
|
|
global $emailheaders; |
492
|
|
|
global $absolute_server_URI; |
493
|
|
|
|
494
|
|
|
$email_content = $warnmessage; |
495
|
|
|
$email_content .= "\n--------------------\n"; |
496
|
|
|
$email_content .= print_r(debug_backtrace(), true); |
497
|
|
|
|
498
|
|
|
if (admin_errormail($sql_errormail, 'sql_warn', $email_content, $emailheaders)) { |
499
|
|
|
@mb_send_mail($sql_errormail, 'sql_warn: ' . $absolute_server_URI, $email_content, $emailheaders); |
|
|
|
|
500
|
|
|
} |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/* |
504
|
|
|
Ersatz für die in Mysql eingebauten Funktionen |
505
|
|
|
*/ |
506
|
|
|
/** |
507
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
508
|
|
|
* @param resource $rs |
509
|
|
|
* @return array |
510
|
|
|
*/ |
511
|
|
|
function sql_fetch_array($rs) |
512
|
|
|
{ |
513
|
|
|
return mysqli_fetch_array($rs); |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
518
|
|
|
* @param $rs |
519
|
|
|
* @return array |
520
|
|
|
*/ |
521
|
|
|
function sql_fetch_assoc($rs) |
522
|
|
|
{ |
523
|
|
|
return mysqli_fetch_assoc($rs); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
528
|
|
|
* @param $rs |
529
|
|
|
* @return array |
530
|
|
|
*/ |
531
|
|
|
function sql_fetch_row($rs) |
532
|
|
|
{ |
533
|
|
|
return mysqli_fetch_row($rs); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/** |
537
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
538
|
|
|
* @param resource $rs |
539
|
|
|
* @return array|null |
540
|
|
|
*/ |
541
|
|
View Code Duplication |
function sql_fetch_column($rs) |
|
|
|
|
542
|
|
|
{ |
543
|
|
|
$col = []; |
544
|
|
|
while ($r = sql_fetch_row($rs)) { |
|
|
|
|
545
|
|
|
if (count($r) != 1) { |
546
|
|
|
return null; |
547
|
|
|
} |
548
|
|
|
$col[] = $r[0]; |
549
|
|
|
} |
550
|
|
|
sql_free_result($rs); |
|
|
|
|
551
|
|
|
|
552
|
|
|
return $col; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
557
|
|
|
* @param $rs |
558
|
|
|
* @return bool |
559
|
|
|
*/ |
560
|
|
|
function sql_free_result($rs) |
561
|
|
|
{ |
562
|
|
|
return mysqli_free_result($rs); |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
function mb_trim($str) |
566
|
|
|
{ |
567
|
|
|
$bLoop = true; |
568
|
|
View Code Duplication |
while ($bLoop == true) { |
|
|
|
|
569
|
|
|
$sPos = mb_substr($str, 0, 1); |
570
|
|
|
|
571
|
|
|
if ($sPos == ' ' || $sPos == "\r" || $sPos == "\n" || $sPos == "\t" || $sPos == "\x0B" || $sPos == "\0") { |
572
|
|
|
$str = mb_substr($str, 1, mb_strlen($str) - 1); |
573
|
|
|
} else { |
574
|
|
|
$bLoop = false; |
575
|
|
|
} |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
$bLoop = true; |
579
|
|
View Code Duplication |
while ($bLoop == true) { |
|
|
|
|
580
|
|
|
$sPos = mb_substr($str, -1, 1); |
581
|
|
|
|
582
|
|
|
if ($sPos == ' ' || $sPos == "\r" || $sPos == "\n" || $sPos == "\t" || $sPos == "\x0B" || $sPos == "\0") { |
583
|
|
|
$str = mb_substr($str, 0, mb_strlen($str) - 1); |
584
|
|
|
} else { |
585
|
|
|
$bLoop = false; |
586
|
|
|
} |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
return $str; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
594
|
|
|
* disconnect the database |
595
|
|
|
*/ |
596
|
|
|
function db_disconnect(): void |
597
|
|
|
{ |
598
|
|
|
global $dbpconnect, $dblink; |
599
|
|
|
|
600
|
|
|
//is connected and no persistent connect used? |
601
|
|
|
if (($dbpconnect == false) && ($dblink !== false)) { |
602
|
|
|
@mysqli_close($dblink); |
|
|
|
|
603
|
|
|
$dblink = false; |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* @deprecated use DBAL Conenction instead. See adminreports.php for an example implementation |
609
|
|
|
* database handling |
610
|
|
|
*/ |
611
|
|
|
function db_connect(): void |
612
|
|
|
{ |
613
|
|
|
global $dblink, $dbusername, $dbname, $dbserver, $dbpasswd; |
614
|
|
|
|
615
|
|
|
//connect to the database by the given method - no php error reporting! |
616
|
|
|
$dblink = mysqli_connect($dbserver, $dbusername, $dbpasswd, $dbname); |
617
|
|
|
|
618
|
|
|
if (!$dblink instanceof mysqli) { |
619
|
|
|
throw new InvalidArgumentException('cannot connect to database'); |
620
|
|
|
} |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
function get_site_urls($domain) |
624
|
|
|
{ |
625
|
|
|
global $opt; |
626
|
|
|
|
627
|
|
|
if (!$domain) { |
628
|
|
|
$domain = parse_url($opt['page']['default_primary_url'], PHP_URL_HOST); |
629
|
|
|
} |
630
|
|
|
if ($domain == parse_url($opt['page']['default_primary_url'], PHP_URL_HOST) || |
631
|
|
|
!isset($opt['domain'][$domain]['url']) |
632
|
|
|
) { |
633
|
|
|
$site_url = $opt['page']['default_primary_url']; |
634
|
|
|
$shortlink_url = $opt['page']['default_primary_shortlink_url']; |
635
|
|
|
} else { |
636
|
|
|
$protocol = 'http'; |
637
|
|
|
if (isset($opt['domain'][$domain]['https']['is_default']) && $opt['domain'][$domain]['https']['is_default']) { |
638
|
|
|
$protocol = 'https'; |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
$site_url = $protocol . strstr($opt['domain'][$domain]['url'], '://'); |
642
|
|
|
if (isset($opt['domain'][$domain]['shortlink_domain']) && $opt['domain'][$domain]['shortlink_domain']) { |
643
|
|
|
$shortlink_url = $protocol . '://' . $opt['domain'][$domain]['shortlink_domain'] . '/'; |
644
|
|
|
} else { |
645
|
|
|
$shortlink_url = false; |
646
|
|
|
} |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
return [ |
650
|
|
|
'site_url' => $site_url, |
651
|
|
|
'shortlink_url' => $shortlink_url, |
652
|
|
|
]; |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* @param string $filename |
657
|
|
|
* @param mixed $language |
658
|
|
|
* @param mixed $domain |
659
|
|
|
* @return bool|string |
660
|
|
|
*/ |
661
|
|
|
function fetch_email_template($filename, $language, $domain) |
662
|
|
|
{ |
663
|
|
|
global $opt, $rootpath; |
664
|
|
|
|
665
|
|
|
if (!$language) { |
666
|
|
|
$language = $opt['template']['default']['locale']; |
667
|
|
|
} |
668
|
|
|
$language = strtolower($language); |
669
|
|
|
if (!file_exists(__DIR__ . '/../lang/de/ocstyle/email/' . $language . '/' . $filename . '.email')) { |
670
|
|
|
$language = 'en'; |
671
|
|
|
} |
672
|
|
|
$mailtext = read_file(__DIR__ . '/../lang/de/ocstyle/email/' . $language . '/' . $filename . '.email'); |
673
|
|
|
|
674
|
|
|
$urls = get_site_urls($domain); |
675
|
|
|
$mailtext = mb_ereg_replace('{site_url}', $urls['site_url'], $mailtext); |
676
|
|
View Code Duplication |
if ($urls['shortlink_url']) { |
677
|
|
|
$mailtext = mb_ereg_replace('{shortlink_url}', $urls['shortlink_url'], $mailtext); |
678
|
|
|
} else { |
679
|
|
|
$mailtext = mb_ereg_replace('{shortlink_url}', $urls['site_url'], $mailtext); |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
$mailtext = mb_ereg_replace('{email_contact}', $opt['mail']['contact'], $mailtext); |
683
|
|
|
|
684
|
|
|
return $mailtext; |
685
|
|
|
} |
686
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.