From bed20e9f2813c55388ed611d302e44eb0b97d7ef Mon Sep 17 00:00:00 2001 From: dag Date: Sun, 3 Apr 2022 09:37:39 +0200 Subject: [PATCH] feat: extract curl ua to config value (#2568) * exclude config.default.ini.php from phpcs --- bridges/FB2Bridge.php | 4 ++-- bridges/MixCloudBridge.php | 2 -- bridges/VkBridge.php | 2 -- bridges/WebfailBridge.php | 3 --- bridges/ZoneTelechargementBridge.php | 3 ++- config.default.ini.php | 3 +++ index.php | 10 ---------- lib/contents.php | 2 +- phpcs.xml | 1 + 9 files changed, 9 insertions(+), 21 deletions(-) diff --git a/bridges/FB2Bridge.php b/bridges/FB2Bridge.php index 77ae271e..46a92c56 100644 --- a/bridges/FB2Bridge.php +++ b/bridges/FB2Bridge.php @@ -229,7 +229,7 @@ EOD $ctx = stream_context_create(array( 'http' => array( - 'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0', + 'user_agent' => Configuration::getConfig('http', 'useragent'), 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' ) ) @@ -254,7 +254,7 @@ EOD $context = stream_context_create(array( 'http' => array( - 'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0', + 'user_agent' => Configuration::getConfig('http', 'useragent'), 'header' => 'Cookie: ' . $cookies ) ) diff --git a/bridges/MixCloudBridge.php b/bridges/MixCloudBridge.php index fb38ab5e..c1534ec9 100644 --- a/bridges/MixCloudBridge.php +++ b/bridges/MixCloudBridge.php @@ -25,8 +25,6 @@ class MixCloudBridge extends BridgeAbstract { } public function collectData(){ - ini_set('user_agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0'); - $html = getSimpleHTMLDOM(self::URI . '/' . $this->getInput('u')); foreach($html->find('section.card') as $element) { diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php index 162dd6c5..1d0f65b0 100644 --- a/bridges/VkBridge.php +++ b/bridges/VkBridge.php @@ -409,8 +409,6 @@ class VkBridge extends BridgeAbstract private function getContents() { - ini_set('user-agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0'); - $header = array('Accept-language: en', 'Cookie: remixlang=3'); return getContents($this->getURI(), $header); diff --git a/bridges/WebfailBridge.php b/bridges/WebfailBridge.php index f7cdecb2..fefd539a 100644 --- a/bridges/WebfailBridge.php +++ b/bridges/WebfailBridge.php @@ -41,9 +41,6 @@ class WebfailBridge extends BridgeAbstract { } public function collectData(){ - - ini_set('user_agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0'); - $html = getSimpleHTMLDOM($this->getURI() . $this->getInput('type')); $type = array_search($this->getInput('type'), diff --git a/bridges/ZoneTelechargementBridge.php b/bridges/ZoneTelechargementBridge.php index c534f575..b33b6da8 100644 --- a/bridges/ZoneTelechargementBridge.php +++ b/bridges/ZoneTelechargementBridge.php @@ -47,7 +47,8 @@ class ZoneTelechargementBridge extends BridgeAbstract { $header = array(); // Parse the URL to extract the hostname $parse = parse_url($url); - $opts = array(CURLOPT_USERAGENT => 'curl/7.64.0', + $opts = array( + CURLOPT_USERAGENT => Configuration::getConfig('http', 'useragent'), CURLOPT_RESOLVE => $this->getResolve($parse['host']) ); diff --git a/config.default.ini.php b/config.default.ini.php index 06600892..147a0ca4 100644 --- a/config.default.ini.php +++ b/config.default.ini.php @@ -12,6 +12,9 @@ ; timezone = "UTC" (default) timezone = "UTC" +[http] +useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" + [cache] ; Defines the cache type used by RSS-Bridge diff --git a/index.php b/index.php index ee37b223..dc6b8938 100644 --- a/index.php +++ b/index.php @@ -17,16 +17,6 @@ if (isset($argv)) { $params = $_GET; } -define('USER_AGENT', - 'Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0(rss-bridge/' - . Configuration::$VERSION - . ';+' - . REPOSITORY - . ')' -); - -ini_set('user_agent', USER_AGENT); - try { $actionFac = new \ActionFactory(); diff --git a/lib/contents.php b/lib/contents.php index ce7d335a..a5591c33 100644 --- a/lib/contents.php +++ b/lib/contents.php @@ -168,7 +168,7 @@ function getContents($url, $header = array(), $opts = array(), $returnHeader = f } - curl_setopt($ch, CURLOPT_USERAGENT, ini_get('user_agent')); + curl_setopt($ch, CURLOPT_USERAGENT, Configuration::getConfig('http', 'useragent')); curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); diff --git a/phpcs.xml b/phpcs.xml index 74c7a020..f10e3839 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -3,6 +3,7 @@ Created with the PHP Coding Standard Generator. http://edorian.github.com/php-coding-standard-generator/ ./static ./vendor + ./config.default.ini.php