From de653fce9b7af80f80daae995aa9ad776525d30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ma=C5=82ek?= Date: Mon, 18 May 2020 19:55:05 +0200 Subject: [PATCH] Set custom user agent (#924) --- docs/faq.rst | 2 +- src/includes/functions.inc.php | 4 ++-- src/lang/en_US.lang.php | 2 ++ src/lang/nl_NL.lang.php | 3 +++ src/lang/pl_PL.lang.php | 2 ++ src/psm/Module/Config/Controller/ConfigController.php | 7 +++++++ src/templates/default/module/config/config.tpl.html | 2 ++ 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/faq.rst b/docs/faq.rst index 19a0db2b..04f6e05a 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -51,7 +51,7 @@ The other way is to parse the access logs created by your webserver software, wh When using tools such as Google Analytics, the monitor requests will not show up in your statistics, because the monitor does not execute any Javascript. Tools that parse your raw access logs like Awstats, will include the requests made by the monitor. -To make sure these requests can be identified, the monitor uses a custom user agent, which you can usually filter out. The user agent of the monitor looks like:: +To make sure these requests can be identified, the monitor uses a custom user agent, which you can usually filter out. The user agent can be modified in the config section, but bij default looks like:: Mozilla/5.0 (compatible; phpservermon/3.0.1; +http://www.phpservermonitor.org) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 01305853..db077969 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -452,8 +452,8 @@ namespace { } if ($add_agent) { - curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; phpservermon/' . - PSM_VERSION . '; +https://github.com/phpservermon/phpservermon)'); + curl_setopt($ch, CURLOPT_USERAGENT, psm_get_conf('user_agent', 'Mozilla/5.0 (compatible; phpservermon/' . + PSM_VERSION . '; +https://github.com/phpservermon/phpservermon)')); } $result['exec'] = curl_exec($ch); diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 8ef4791a..1542b63f 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -415,6 +415,8 @@ $sm_lang = array( 'log_retention_period_description' => 'Number of days to keep logs of notifications and archives of server uptime. Enter 0 to disable log cleanup.', 'log_retention_days' => 'days', + 'user_agent' => 'User Agent', + 'user_agent_key_note' => 'Custom user agent used by monitor within communication with external services.', ), 'notifications' => array( 'off_sms' => 'Server \'%LABEL%\' is DOWN: ip=%IP%, port=%PORT%. Error=%ERROR%', diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php index 7edae458..3c749338 100644 --- a/src/lang/nl_NL.lang.php +++ b/src/lang/nl_NL.lang.php @@ -337,6 +337,9 @@ $sm_lang = array( 'log_retention_period_description' => 'Aantal dagen dat logs van notificaties en archieven van server uptime worden bewaard. Vul 0 in om log opruiming uit te zetten.', 'log_retention_days' => 'dagen', + 'user_agent' => 'User Agent', + 'user_agent_key_note' => 'Aangepaste user agent wordt door de monitor gebruikt bij de communicatie met externe + services.', ), 'notifications' => array( 'off_sms' => 'Server %LABEL% is DOWN: ip=%IP%, poort=%PORT%. Fout=%ERROR%', diff --git a/src/lang/pl_PL.lang.php b/src/lang/pl_PL.lang.php index d2366321..e7d1688c 100644 --- a/src/lang/pl_PL.lang.php +++ b/src/lang/pl_PL.lang.php @@ -273,6 +273,8 @@ $sm_lang = array( archiwizować uptime serwera. Wpisz 0 aby wyłączyć czyszczenie logów.', 'log_retention_days' => 'dni', + 'user_agent' => 'User Agent', + 'user_agent_key_note' => 'Nazwa używana przez monitoring do identyfikacji ze sprawdzaną usługą.', ), 'notifications' => array( 'off_sms' => 'Serwer \'%LABEL%\' przestał odpowiadać: ip=%IP%, port=%PORT%. Błąd=%ERROR%', diff --git a/src/psm/Module/Config/Controller/ConfigController.php b/src/psm/Module/Config/Controller/ConfigController.php index 373a45de..f26b1ff0 100644 --- a/src/psm/Module/Config/Controller/ConfigController.php +++ b/src/psm/Module/Config/Controller/ConfigController.php @@ -78,6 +78,7 @@ class ConfigController extends AbstractController 'jabber_port', 'jabber_username', 'jabber_domain', + 'user_agent', 'site_title' ); @@ -193,6 +194,10 @@ class ConfigController extends AbstractController $tpl_data[$input_key] = (isset($config[$input_key])) ? $config[$input_key] : ''; } + $tpl_data['user_agent'] = empty($tpl_data['user_agent']) ? + 'Mozilla/5.0 (compatible; phpservermon/' . + PSM_VERSION . '; +https://github.com/phpservermon/phpservermon)' : $tpl_data['user_agent']; + $tpl_data['site_title'] = empty($tpl_data['site_title']) ? strtoupper(psm_get_lang('system', 'title')) : $tpl_data['site_title']; @@ -522,6 +527,8 @@ class ConfigController extends AbstractController 'label_log_retention_days' => psm_get_lang('config', 'log_retention_days'), 'label_days' => psm_get_lang('config', 'log_retention_days'), 'label_leave_blank' => psm_get_lang('users', 'password_leave_blank'), + 'label_user_agent' => psm_get_lang('config', 'user_agent'), + 'label_user_agent_key_note' => psm_get_lang('config', 'user_agent_key_note'), 'label_site_title' => psm_get_lang('config', 'site_title'), ); } diff --git a/src/templates/default/module/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html index 79b73c6c..1472bc61 100644 --- a/src/templates/default/module/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -50,6 +50,8 @@ {{ macro.input_field("text", "password_encrypt_key", null, "password_encrypt_key", label_password_encrypt_key, password_encrypt_key, "cab03a766...", "40", "password_encrypt_key_help", label_password_encrypt_key_note) }} + + {{ macro.input_field("text", "user_agent", null, "user_agent", label_user_agent, user_agent, "Mozilla/5.0...", "255", "user_agent_key_help", label_user_agent_key_note) }}