yf_logs_exec_admin classSave execution info log for admin section.
| File | plugins/logs/classes/logs/yf_logs_exec_admin.class.php |
|---|---|
| Use | _class('logs_exec_admin', 'classes/logs/') |
A site sets them in its config with $PROJECT_CONF['logs_exec_admin']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$EXCLUDE_IPSarray |
['127.0.0.1'] |
|
$EXCLUDE_USER_AGENTSarray |
['zabbix', 'acceptance_tests'] |
|
$FILTER_BOTSbool |
false |
|
$LOGGINGbool |
true |
|
$LOG_DIR_NAME |
'logs/log_admin_exec/' |
|
$LOG_DRIVERenum('db','file') |
'db' |
|
$LOG_NOT_FOUND_PAGESbool |
true |
|
$LOG_NO_GRAPHICS_PAGESbool |
true |
|
$STOP_LISTarray |
[] |
Stop-list for logging (REGEXPs allowed here) |
$USE_STOP_LISTbool |
true |
|
$checks |
null |
|
$log_denied_because |
null |
public function go()
Do save.
public function go()
{
if ( ! $this->LOGGING || MAIN_TYPE_USER) {
return false;
}
if (main()->NO_GRAPHICS && ! $this->LOG_NO_GRAPHICS_PAGES) {
return false;
}
if (($GLOBALS['task_not_found'] ?? false) && ! $this->LOG_NOT_FOUND_PAGES) {
return false;
}
if ($this->USE_STOP_LIST) {
foreach ((array) $this->STOP_LIST as $_cur_pattern) {
if (preg_match('/' . $_cur_pattern . '/i', $_SERVER['QUERY_STRING'])) {
return false;
}
}
}
if ($this->FILTER_BOTS && ! main()->USER_ID) {
$SPIDER_NAME = common()->_is_spider(($_SERVER['REMOTE_ADDR'] ?? null), ($_SERVER['HTTP_USER_AGENT'] ?? null));
if ($SPIDER_NAME) {
return false;
}
}
$checks = null;
if ($this->EXCLUDE_IPS) {
$ip = common()->get_ip();
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 ($ua && 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;
}
}
$time_end = $GLOBALS['time_end'] ?? microtime(true);
$exec_time = str_replace(',', '.', common()->_format_time_value($time_end - main()->_time_start));
$query_string = ($_SERVER['QUERY_STRING'] ?? null);
// TODO: use parse_url here
if (main()->is_console()) {
$query_string = http_build_query($_GET);
}
$data = [
'admin_id' => (int) main()->ADMIN_ID,
'admin_group' => (int) main()->ADMIN_GROUP,
'date' => time(),
'ip' => common()->get_ip(),
'user_agent' => (string) ($_SERVER['HTTP_USER_AGENT'] ?? null),
'referer' => (string) ($_SERVER['HTTP_REFERER'] ?? null),
'query_string' => (string) $query_string,
'request_uri' => ($_SERVER['HTTP_HOST'] ?? null) . ($_SERVER['REQUEST_URI'] ?? null),
'exec_time' => $exec_time,
'num_dbq' => (int) db()->NUM_QUERIES,
'page_size' => (int) tpl()->_output_body_length,
'site_id' => (int) conf('SITE_ID'),
'server_id' => (int) conf('SERVER_ID'),
];
if ($this->LOG_DRIVER == 'db') {
$sql = db()->insert_safe('log_admin_exec', $data, $as_sql = true);
db()->_add_shutdown_query($sql);
} elseif ($this->LOG_DRIVER == 'file') {
$data['output_cache'] = '0'; // mean: exec full mode (not from output cache)
$log_file_path = INCLUDE_PATH . $this->LOG_DIR_NAME . gmdate('Y-m-d') . '.log';
$log_dir_path = dirname($log_file_path);
if ( ! file_exists($log_dir_path)) {
_mkdir_m($log_dir_path);
}
file_put_contents($log_file_path, implode('#@#', $data) . PHP_EOL, FILE_APPEND);
}
}
_ hooks and helpers; not routable as page actionspublic function _init()
public function _init()
{
if ( ! $this->LOG_DRIVER || ! in_array($this->LOG_DRIVER, ['db', 'file'])) {
$this->LOG_DRIVER = 'file';
}
}