aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/Updater.php26
-rw-r--r--index.php9
-rw-r--r--tests/Updater/UpdaterTest.php64
3 files changed, 96 insertions, 3 deletions
diff --git a/application/Updater.php b/application/Updater.php
index f07e7697..dece2c02 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -457,6 +457,32 @@ class Updater
457 } 457 }
458 return true; 458 return true;
459 } 459 }
460
461 /**
462 * Add download size and timeout to the configuration file
463 *
464 * @return bool true if the update is successful, false otherwise.
465 */
466 public function updateMethodDownloadSizeAndTimeoutConf()
467 {
468 if ($this->conf->exists('general.download_max_size')
469 && $this->conf->exists('general.download_timeout')
470 ) {
471 return true;
472 }
473
474 if (! $this->conf->exists('general.download_max_size')) {
475 $this->conf->set('general.download_max_size', 1024*1024*4);
476 }
477
478 if (! $this->conf->exists('general.download_timeout')) {
479 $this->conf->set('general.download_timeout', 30);
480 }
481
482 $this->conf->write($this->isLoggedIn);
483
484 return true;
485 }
460} 486}
461 487
462/** 488/**
diff --git a/index.php b/index.php
index 3b8b52a7..dbc2bb3b 100644
--- a/index.php
+++ b/index.php
@@ -1093,7 +1093,6 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1093 $conf->set('general.title', escape($_POST['title'])); 1093 $conf->set('general.title', escape($_POST['title']));
1094 $conf->set('general.header_link', escape($_POST['titleLink'])); 1094 $conf->set('general.header_link', escape($_POST['titleLink']));
1095 $conf->set('resource.theme', escape($_POST['theme'])); 1095 $conf->set('resource.theme', escape($_POST['theme']));
1096 $conf->set('redirector.url', escape($_POST['redirector']));
1097 $conf->set('security.session_protection_disabled', !empty($_POST['disablesessionprotection'])); 1096 $conf->set('security.session_protection_disabled', !empty($_POST['disablesessionprotection']));
1098 $conf->set('privacy.default_private_links', !empty($_POST['privateLinkByDefault'])); 1097 $conf->set('privacy.default_private_links', !empty($_POST['privateLinkByDefault']));
1099 $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks'])); 1098 $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks']));
@@ -1126,7 +1125,6 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1126 $PAGE->assign('title', $conf->get('general.title')); 1125 $PAGE->assign('title', $conf->get('general.title'));
1127 $PAGE->assign('theme', $conf->get('resource.theme')); 1126 $PAGE->assign('theme', $conf->get('resource.theme'));
1128 $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl'))); 1127 $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl')));
1129 $PAGE->assign('redirector', $conf->get('redirector.url'));
1130 list($continents, $cities) = generateTimeZoneData( 1128 list($continents, $cities) = generateTimeZoneData(
1131 timezone_identifiers_list(), 1129 timezone_identifiers_list(),
1132 $conf->get('general.timezone') 1130 $conf->get('general.timezone')
@@ -1376,7 +1374,12 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1376 if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) { 1374 if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) {
1377 // Short timeout to keep the application responsive 1375 // Short timeout to keep the application responsive
1378 // The callback will fill $charset and $title with data from the downloaded page. 1376 // The callback will fill $charset and $title with data from the downloaded page.
1379 get_http_response($url, 25, 4194304, get_curl_download_callback($charset, $title)); 1377 get_http_response(
1378 $url,
1379 $conf->get('general.download_max_size', 4194304),
1380 $conf->get('general.download_timeout', 30),
1381 get_curl_download_callback($charset, $title)
1382 );
1380 if (! empty($title) && strtolower($charset) != 'utf-8') { 1383 if (! empty($title) && strtolower($charset) != 'utf-8') {
1381 $title = mb_convert_encoding($title, 'utf-8', $charset); 1384 $title = mb_convert_encoding($title, 'utf-8', $charset);
1382 } 1385 }
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php
index fed175df..94e3c7d3 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/Updater/UpdaterTest.php
@@ -620,4 +620,68 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
620 $this->assertTrue($updater->updateMethodAtomDefault()); 620 $this->assertTrue($updater->updateMethodAtomDefault());
621 $this->assertTrue($this->conf->get('feed.show_atom')); 621 $this->assertTrue($this->conf->get('feed.show_atom'));
622 } 622 }
623
624 /**
625 * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined.
626 */
627 public function testUpdateMethodDownloadSizeAndTimeoutConf()
628 {
629 $sandboxConf = 'sandbox/config';
630 copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
631 $this->conf = new ConfigManager($sandboxConf);
632 $updater = new Updater([], [], $this->conf, true);
633 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
634 $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
635 $this->assertEquals(30, $this->conf->get('general.download_timeout'));
636
637 $this->conf = new ConfigManager($sandboxConf);
638 $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
639 $this->assertEquals(30, $this->conf->get('general.download_timeout'));
640 }
641
642 /**
643 * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined.
644 */
645 public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore()
646 {
647 $sandboxConf = 'sandbox/config';
648 copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
649 $this->conf = new ConfigManager($sandboxConf);
650 $this->conf->set('general.download_max_size', 38);
651 $this->conf->set('general.download_timeout', 70);
652 $updater = new Updater([], [], $this->conf, true);
653 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
654 $this->assertEquals(38, $this->conf->get('general.download_max_size'));
655 $this->assertEquals(70, $this->conf->get('general.download_timeout'));
656 }
657
658 /**
659 * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here.
660 */
661 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize()
662 {
663 $sandboxConf = 'sandbox/config';
664 copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
665 $this->conf = new ConfigManager($sandboxConf);
666 $this->conf->set('general.download_max_size', 38);
667 $updater = new Updater([], [], $this->conf, true);
668 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
669 $this->assertEquals(38, $this->conf->get('general.download_max_size'));
670 $this->assertEquals(30, $this->conf->get('general.download_timeout'));
671 }
672
673 /**
674 * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here.
675 */
676 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout()
677 {
678 $sandboxConf = 'sandbox/config';
679 copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
680 $this->conf = new ConfigManager($sandboxConf);
681 $this->conf->set('general.download_timeout', 3);
682 $updater = new Updater([], [], $this->conf, true);
683 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
684 $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
685 $this->assertEquals(3, $this->conf->get('general.download_timeout'));
686 }
623} 687}