Add an option to set a custom user agent to retrieve individual feeds (#3494)

* Add an option to set a custom user agent to retrieve individual feeds

This allows retrieving the original RSS feed when websites use services like FeedBurner.

* Use !== instead of != in subscriptionController.php

* Add proxy and user-agent to subscription/add

Co-authored-by: Georgelemental <georgelemental@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
This commit is contained in:
Jules-Bertholet
2021-03-09 14:51:09 -05:00
committed by GitHub
parent 09b7e87532
commit 800a42172d
22 changed files with 122 additions and 27 deletions

View File

@@ -165,9 +165,25 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$http_auth = $user . ':' . $pass;
}
$useragent = Minz_Request::param('curl_params_useragent', '');
$proxy_address = Minz_Request::param('curl_params', '');
$proxy_type = Minz_Request::param('proxy_type', '');
$opts = [];
if ($proxy_address !== '' && $proxy_type !== '' && in_array($proxy_type, [0, 2, 4, 5, 6, 7])) {
$opts[CURLOPT_PROXY] = $proxy_address;
$opts[CURLOPT_PROXYTYPE] = intval($proxy_type);
}
if ($cookie !== '') {
$opts[CURLOPT_COOKIE] = $cookie;
}
if ($useragent !== '') {
$opts[CURLOPT_USERAGENT] = $useragent;
}
$attributes = array(
'ssl_verify' => null,
'timeout' => null,
'curl_params' => empty($opts) ? null : $opts,
);
if (FreshRSS_Auth::hasAccess('admin')) {
$attributes['ssl_verify'] = Minz_Request::paramTernary('ssl_verify');

View File

@@ -96,7 +96,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
$pass = trim(Minz_Request::param('http_pass_feed' . $id, ''));
$httpAuth = '';
if ($user != '' && $pass != '') { //TODO: Sanitize
if ($user !== '' && $pass !== '') { //TODO: Sanitize
$httpAuth = $user . ':' . $pass;
}
@@ -113,16 +113,20 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
$feed->_attributes('clear_cache', Minz_Request::paramTernary('clear_cache'));
$cookie = Minz_Request::param('curl_params_cookie', '');
$useragent = Minz_Request::param('curl_params_useragent', '');
$proxy_address = Minz_Request::param('curl_params', '');
$proxy_type = Minz_Request::param('proxy_type', '');
$opts = [];
if ($proxy_address != '' && $proxy_type != '' && in_array($proxy_type, [0, 2, 4, 5, 6, 7])) {
if ($proxy_address !== '' && $proxy_type !== '' && in_array($proxy_type, [0, 2, 4, 5, 6, 7])) {
$opts[CURLOPT_PROXY] = $proxy_address;
$opts[CURLOPT_PROXYTYPE] = intval($proxy_type);
}
if ($cookie != '') {
if ($cookie !== '') {
$opts[CURLOPT_COOKIE] = $cookie;
}
if ($useragent !== '') {
$opts[CURLOPT_USERAGENT] = $useragent;
}
$feed->_attributes('curl_params', empty($opts) ? null : $opts);
$feed->_attributes('content_action', Minz_Request::param('content_action', 'replace'));

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Přidat RSS kanál',
'ttl' => 'Neobnovovat častěji než',
'url' => 'URL kanálu',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Zkontrolovat platnost kanálu',
'website' => 'URL webové stránky',
'websub' => 'Okamžité oznámení s WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Einen RSS-Feed hinzufügen',
'ttl' => 'Aktualisiere automatisch nicht öfter als',
'url' => 'Feed-URL',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Überprüfen Sie die Gültigkeit des Feeds',
'website' => 'Webseiten-URL',
'websub' => 'Sofortbenachrichtigung mit WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Add an RSS feed',
'ttl' => 'Do not automatically refresh more often than',
'url' => 'Feed URL',
'useragent' => 'Set the user agent for fetching this feed',
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>',
'validator' => 'Check the validity of the feed',
'website' => 'Website URL',
'websub' => 'Instant notification with WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Add an RSS feed',
'ttl' => 'Do not automatically refresh more often than',
'url' => 'Feed URL',
'useragent' => 'Set the user agent for fetching this feed',
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>',
'validator' => 'Check the validity of the feed',
'website' => 'Website URL',
'websub' => 'Instant notification with WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Añadir fuente RSS',
'ttl' => 'No actualizar de forma automática con una frecuencia mayor a',
'url' => 'URL de la fuente',
'useragent' => 'Selecciona el agente de usario por recuperar la fuente',
'useragent_help' => 'Ejemplo: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>',
'validator' => 'Verifica la validez de la fuente',
'website' => 'Web de la URL',
'websub' => 'Notificación inmedaiata con WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Ajouter un flux RSS',
'ttl' => 'Ne pas automatiquement rafraîchir plus souvent que',
'url' => 'URL du flux',
'useragent' => 'Sélectionner lagent utilisateur pour télécharger ce flux',
'useragent_help' => 'Exemple: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>',
'validator' => 'Vérifier la validité du flux',
'website' => 'URL du site',
'websub' => 'Notification instantanée par WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'הוספת הזנה',
'ttl' => 'אין לרענן אוטומטית יותר מ',
'url' => 'הזנה URL',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'בדיקות תקינות ההזנה',
'website' => 'אתר URL',
'websub' => 'Instant notification with WebSub', // TODO - Translation

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Aggiungi RSS feed',
'ttl' => 'Non aggiornare automaticamente piu di',
'url' => 'Feed URL', // TODO - Translation
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Controlla la validita del feed ',
'website' => 'URL del sito',
'websub' => 'Notifica istantanea con WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'RSS 피드 추가',
'ttl' => '다음 시간이 지나기 전에 새로고침 금지',
'url' => '피드 URL',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => '피드 유효성 검사',
'website' => '웹사이트 URL',
'websub' => 'WebSub을 사용한 즉시 알림',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Voeg een RSS-feed toe',
'ttl' => 'Vernieuw automatisch niet vaker dan',
'url' => 'Feed-url',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Controleer de geldigheid van de feed',
'website' => 'Website-url',
'websub' => 'Directe notificaties met WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Ajustar un flux RSS',
'ttl' => 'Actualizar pas automaticament mai sovent que',
'url' => 'Flux URL',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Verificar la validitat del flux',
'website' => 'URL del site',
'websub' => 'Notificaciones instantáneas amb WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Dodaj kanał',
'ttl' => 'Nie odświeżaj automatycznie częściej niż',
'url' => 'Adres kanału',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Sprawdź poprawność kanału',
'website' => 'Adres strony',
'websub' => 'Instant notification with WebSub', // TODO - Translation

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Adicionar o RSS feed',
'ttl' => 'Não atualize automaticamente mais que',
'url' => 'URL do Feed',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Verifique a validade do feed',
'website' => 'URL do site',
'websub' => 'Notificação instantânea com WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Add an RSS feed', // TODO - Translation
'ttl' => 'Do not automatically refresh more often than', // TODO - Translation
'url' => 'Feed URL', // TODO - Translation
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Check the validity of the feed', // TODO - Translation
'website' => 'Website URL', // TODO - Translation
'websub' => 'Instant notification with WebSub', // TODO - Translation

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'Pridať kanál RSS',
'ttl' => 'Automaticky neaktualizovať častejšie ako',
'url' => 'Odkaz kanála',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Skontrolovať platnosť kanála',
'website' => 'Odkaz webovej stránky',
'websub' => 'Okamžité oznámenia cez WebSub',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => 'RSS akışı ekle',
'ttl' => 'Şu kadar süreden fazla otomatik yenileme yapma',
'url' => 'Akış URL',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => 'Akış geçerliliğini kontrol edin',
'website' => 'Site URL',
'websub' => 'WebSub ile anlık bildirim',

View File

@@ -90,6 +90,8 @@ return array(
'title_add' => '添加订阅源',
'ttl' => '最小自动更新间隔',
'url' => '源地址',
'useragent' => 'Set the user agent for fetching this feed', // TODO - Translation
'useragent_help' => 'Example: <kbd>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0)</kbd>', // TODO - Translation
'validator' => '检查订阅源有效性',
'website' => '网站地址',
'websub' => 'WebSub 即时通知',

View File

@@ -327,29 +327,6 @@
</div>
</div>
<div class="form-group">
<label class="group-name" for="path_entries"><?= _t('sub.feed.proxy') ?></label>
<div class="group-controls">
<select class="number" name="proxy_type" id="proxy_type"><?php
$type = '';
if (is_array($this->feed->attributes('curl_params')) && isset($this->feed->attributes('curl_params')[CURLOPT_PROXYTYPE])) {
$type = $this->feed->attributes('curl_params')[CURLOPT_PROXYTYPE];
}
foreach(['' => '', 3 => 'NONE', 0 => 'HTTP', 2 => 'HTTPS', 4 => 'SOCKS4', 6 => 'SOCKS4A', 5 => 'SOCKS5', 7 => 'SOCKS5H'] as $k => $v) {
echo '<option value="' . $k . ($type === $k ? '" selected="selected' : '' ) . '">' . $v . '</option>';
}
?>
</select>
<div class="stick">
<input type="text" name="curl_params" id="curl_params" class="extend" value="<?=
is_array($this->feed->attributes('curl_params')) && !empty($this->feed->attributes('curl_params')[CURLOPT_PROXY]) ?
$this->feed->attributes('curl_params')[CURLOPT_PROXY] : ''
?>" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
</div>
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.proxy_help') ?></p>
</div>
</div>
<div class="form-group">
<label class="group-name" for="mark_updated_article_unread"><?= _t('conf.reading.mark_updated_article_unread') ?></label>
<div class="group-controls">
@@ -386,6 +363,42 @@
</div>
</div>
<div class="form-group">
<label class="group-name" for="path_entries"><?= _t('sub.feed.useragent') ?></label>
<div class="group-controls">
<div class="stick">
<input type="text" name="curl_params_useragent" id="curl_params_useragent" class="extend" value="<?=
is_array($this->feed->attributes('curl_params')) && !empty($this->feed->attributes('curl_params')[CURLOPT_USERAGENT]) ?
$this->feed->attributes('curl_params')[CURLOPT_USERAGENT] : ''
?>" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
</div>
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.useragent_help') ?></p>
</div>
</div>
<div class="form-group">
<label class="group-name" for="path_entries"><?= _t('sub.feed.proxy') ?></label>
<div class="group-controls">
<select class="number" name="proxy_type" id="proxy_type"><?php
$type = '';
if (is_array($this->feed->attributes('curl_params')) && isset($this->feed->attributes('curl_params')[CURLOPT_PROXYTYPE])) {
$type = $this->feed->attributes('curl_params')[CURLOPT_PROXYTYPE];
}
foreach(['' => '', 3 => 'NONE', 0 => 'HTTP', 2 => 'HTTPS', 4 => 'SOCKS4', 6 => 'SOCKS4A', 5 => 'SOCKS5', 7 => 'SOCKS5H'] as $k => $v) {
echo '<option value="' . $k . ($type === $k ? '" selected="selected' : '' ) . '">' . $v . '</option>';
}
?>
</select>
<div class="stick">
<input type="text" name="curl_params" id="curl_params" class="extend" value="<?=
is_array($this->feed->attributes('curl_params')) && !empty($this->feed->attributes('curl_params')[CURLOPT_PROXY]) ?
$this->feed->attributes('curl_params')[CURLOPT_PROXY] : ''
?>" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
</div>
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.proxy_help') ?></p>
</div>
</div>
<?php if (FreshRSS_Auth::hasAccess('admin')) { ?>
<div class="form-group">
<label class="group-name" for="timeout"><?= _t('sub.feed.timeout') ?></label>

View File

@@ -59,8 +59,34 @@
</div>
</div>
<?php if (FreshRSS_Auth::hasAccess('admin')) { ?>
<legend><?= _t('sub.feed.advanced') ?></legend>
<div class="form-group">
<label class="group-name" for="path_entries"><?= _t('sub.feed.useragent') ?></label>
<div class="group-controls">
<div class="stick">
<input type="text" name="curl_params_useragent" id="curl_params_useragent" class="extend" value="" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
</div>
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.useragent_help') ?></p>
</div>
</div>
<div class="form-group">
<label class="group-name" for="path_entries"><?= _t('sub.feed.proxy') ?></label>
<div class="group-controls">
<select class="number" name="proxy_type" id="proxy_type"><?php
foreach(['' => '', 3 => 'NONE', 0 => 'HTTP', 2 => 'HTTPS', 4 => 'SOCKS4', 6 => 'SOCKS4A', 5 => 'SOCKS5', 7 => 'SOCKS5H'] as $k => $v) {
echo '<option value="' . $k . '">' . $v . '</option>';
}
?>
</select>
<div class="stick">
<input type="text" name="curl_params" id="curl_params" class="extend" value="" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
</div>
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.proxy_help') ?></p>
</div>
</div>
<?php if (FreshRSS_Auth::hasAccess('admin')) { ?>
<div class="form-group">
<label class="group-name" for="timeout"><?= _t('sub.feed.timeout') ?></label>
<div class="group-controls">

View File

@@ -756,6 +756,8 @@ return array(
'sub.feed.title_add',
'sub.feed.ttl',
'sub.feed.url',
'sub.feed.useragent',
'sub.feed.useragent_help',
'sub.feed.validator',
'sub.feed.website',
'sub.feed.websub',