yf_logs_redirect class| File | plugins/logs/classes/logs/yf_logs_redirect.class.php |
|---|---|
| Use | _class('logs_redirect', 'classes/logs/') |
A site sets them in its config with $PROJECT_CONF['logs_redirect']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$EXCLUDE_IPSarray |
['127.0.0.1'] |
|
$EXCLUDE_URL_FROMarray |
['object=(aff|dynamic).*'] |
Stop-list for logging (REGEXPs allowed here) |
$EXCLUDE_USER_AGENTSarray |
['zabbix', 'acceptance_tests'] |
|
$LOG_REDIRECTSbool |
true |
|
$checks |
null |
|
$log_denied_because |
null |
None without a leading underscore.
_ hooks and helpers; not routable as page actionspublic function _save_log($params = [])
public function _save_log($params = [])
{
if ( ! $this->LOG_REDIRECTS) {
return false;
}
$checks = null;
if ($this->EXCLUDE_URL_FROM) {
foreach ((array) $this->EXCLUDE_URL_FROM as $pattern) {
if (preg_match('~' . $pattern . '~i', $_SERVER['QUERY_STRING'])) {
$checks['exclude_url_from'] = true;
break;
}
}
}
$ip = common()->get_ip();
if ($this->EXCLUDE_IPS) {
if ($ip && (isset($this->EXCLUDE_IPS[$ip]) || in_array($ip, $this->EXCLUDE_IPS))) {
$checks['exclude_ip'] = true;
}
}
if ($this->EXCLUDE_USER_AGENTS) {
$ua = ($_SERVER['HTTP_USER_AGENT'] ?? null);
foreach ((array) $this->EXCLUDE_USER_AGENTS as $pattern) {
if (preg_match('~' . $pattern . '~i', $ua)) {
$checks['exclude_ua'] = true;
}
}
}
$this->checks = $checks;
foreach ((array) $checks as $name => $is_denied) {
if ($is_denied) {
$this->log_denied_because = $name;
return false;
}
}
// slice 2 first elements (__FUNCTION__ and $this->_go) and leave only 5 more trace elements to save space
$trace = implode(PHP_EOL, array_slice(explode(PHP_EOL, main()->trace_string()), 2, 7));
$is_https = (($_SERVER['HTTPS'] ?? null) || ($_SERVER['SSL_PROTOCOL'] ?? null));
return db()->insert_safe('log_redirects', [
'url_from' => ($is_https ? 'https' : 'http') . '://' . ($_SERVER['HTTP_HOST'] ?? null) . ($_SERVER['REQUEST_URI'] ?? null),
'url_to' => $params['url_to'],
'reason' => $params['reason'],
'use_rewrite' => (int) $params['rewrite'],
'redirect_type' => $params['type'],
'date' => gmdate('Y-m-d H:i:s'),
'ip' => $ip,
'query_string' => ($_SERVER['QUERY_STRING'] ?? null),
'user_agent' => ($_SERVER['HTTP_USER_AGENT'] ?? null),
'referer' => ($_SERVER['HTTP_REFERER'] ?? null),
'object' => ($_GET['object'] ?? null),
'action' => ($_GET['action'] ?? null),
'user_id' => MAIN_TYPE_ADMIN ? main()->ADMIN_ID : main()->USER_ID,
'user_group' => MAIN_TYPE_ADMIN ? main()->ADMIN_GROUP : main()->USER_GROUP,
'site_id' => (int) main()->SITE_ID,
'server_id' => (int) main()->SERVER_ID,
'locale' => conf('language'),
'is_admin' => MAIN_TYPE_ADMIN ? 1 : 0,
'rewrite_mode' => (int) tpl()->REWRITE_MODE,
'debug_mode' => DEBUG_MODE ? 1 : 0,
'exec_time' => str_replace(',', '.', round(microtime(true) - main()->_time_start, 4)),
'trace' => $trace,
]);
}