From 55b1d231edbae479019a14bfef3aa4b50220bb67 Mon Sep 17 00:00:00 2001 From: John Okely Date: Mon, 18 Sep 2017 11:18:18 +0800 Subject: [PATCH] MDL-46269 tool_httpsreplace: Add multiple steps --- admin/tool/httpsreplace/classes/form.php | 1 - .../tool/httpsreplace/classes/url_finder.php | 2 - admin/tool/httpsreplace/index.php | 60 +--------- .../lang/en/tool_httpsreplace.php | 4 +- admin/tool/httpsreplace/settings.php | 1 - .../tests/behat/httpsreplace.feature | 2 + admin/tool/httpsreplace/tool.php | 109 ++++++++++++++++++ 7 files changed, 116 insertions(+), 63 deletions(-) create mode 100644 admin/tool/httpsreplace/tool.php diff --git a/admin/tool/httpsreplace/classes/form.php b/admin/tool/httpsreplace/classes/form.php index f8e11a9fb2d..cd834736404 100644 --- a/admin/tool/httpsreplace/classes/form.php +++ b/admin/tool/httpsreplace/classes/form.php @@ -49,5 +49,4 @@ class form extends \moodleform { $this->add_action_buttons(false, get_string('doit', 'tool_httpsreplace')); } - } diff --git a/admin/tool/httpsreplace/classes/url_finder.php b/admin/tool/httpsreplace/classes/url_finder.php index 152827ed96e..bd45ce1bcae 100644 --- a/admin/tool/httpsreplace/classes/url_finder.php +++ b/admin/tool/httpsreplace/classes/url_finder.php @@ -35,7 +35,6 @@ defined('MOODLE_INTERNAL') || die(); */ class url_finder { - /** * Returns a hash of what hosts are referred to over http and would need to be changed. * @@ -234,5 +233,4 @@ class url_finder { } return $results; } - } diff --git a/admin/tool/httpsreplace/index.php b/admin/tool/httpsreplace/index.php index 8f3974aa175..a3cec32cda5 100644 --- a/admin/tool/httpsreplace/index.php +++ b/admin/tool/httpsreplace/index.php @@ -22,10 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define('NO_OUTPUT_BUFFERING', true); - require_once(__DIR__ . '/../../../config.php'); -require_once($CFG->dirroot . '/course/lib.php'); require_once($CFG->libdir . '/adminlib.php'); admin_externalpage_setup('toolhttpsreplace'); @@ -54,60 +51,9 @@ if (!is_https()) { echo $OUTPUT->notification(get_string('httpwarning', 'tool_httpsreplace'), 'warning'); } +echo '

'.get_string('domainexplain', 'tool_httpsreplace').'

'; +echo '

'.page_doc_link(get_string('doclink', 'tool_httpsreplace')).'

'; -$form = new \tool_httpsreplace\form(); +echo $OUTPUT->continue_button(new moodle_url('/admin/tool/httpsreplace/tool.php')); -$finder = new \tool_httpsreplace\url_finder(); -if (!$data = $form->get_data()) { - - echo '

'.get_string('domainexplain', 'tool_httpsreplace').'

'; - echo '

'.page_doc_link(get_string('doclink', 'tool_httpsreplace')).'

'; - - $PAGE->set_cacheable(false); - $progressbar = new progress_bar(); - echo $progressbar->create(); - - $results = $finder->http_link_stats($progressbar); - - $progressbar->update_full(100, get_string('complete', 'tool_httpsreplace')); - - if (empty($results)) { - echo '

'.get_string('oktoprocede', 'tool_httpsreplace').'

'; - } else { - arsort($results); - $table = new html_table(); - $table->id = 'plugins-check'; - $table->head = array( - get_string('domain', 'tool_httpsreplace'), - get_string('count', 'tool_httpsreplace'), - ); - $data = array(); - foreach ($results as $domain => $count) { - $cleandomain = format_text($domain, FORMAT_PLAIN); - $data[] = [$cleandomain, $count]; - } - $table->data = $data; - echo html_writer::table($table); - } - echo $OUTPUT->notification(get_string('takeabackupwarning', 'tool_httpsreplace'), 'warning'); - $form->display(); -} else { - // Scroll to the end when finished. - $PAGE->requires->js_init_code("window.scrollTo(0, 5000000);"); - - echo '

'.get_string('replacing', 'tool_httpsreplace').'

'; - - $PAGE->set_cacheable(false); - $progressbar = new progress_bar(); - echo $progressbar->create(); - - echo $OUTPUT->box_start(); - $finder->upgrade_http_links($progressbar); - echo $OUTPUT->box_end(); - - $progressbar->update_full(100, get_string('complete', 'tool_httpsreplace')); - - echo $OUTPUT->continue_button(new moodle_url('/admin/settings.php', ['section' => 'httpsecurity'])); - -} echo $OUTPUT->footer(); diff --git a/admin/tool/httpsreplace/lang/en/tool_httpsreplace.php b/admin/tool/httpsreplace/lang/en/tool_httpsreplace.php index 55c80365c86..956687450ab 100644 --- a/admin/tool/httpsreplace/lang/en/tool_httpsreplace.php +++ b/admin/tool/httpsreplace/lang/en/tool_httpsreplace.php @@ -28,8 +28,8 @@ $string['disclaimer'] = 'I understand the risks of this operation'; $string['doclink'] = 'Read more documentation on the wiki'; $string['doit'] = 'Perform replacement'; $string['domain'] = 'Problematic domain'; -$string['domainexplain'] = 'When an instance is moved from HTTP to HTTPS, all embeded HTTP content will stop working. This tool always you to automatically convert the HTTP content to HTTPS. Below is a report of content that may not work once you run this script. You may want to check each one has HTTPS available or find alternative resources.'; -$string['domainexplainhelp'] = 'These domains are found in your content, but do not appear to support HTTPS content. After switching to HTTPS, the content included from these sites will no longer display within Moodle for users with secure modern browsers. It is possible that these sites are temporarily or permanently unavailable and will not work with either security setting. Proceed only after reviewing these results and determining if this externally hosted content is non-essential.'; +$string['domainexplain'] = 'When an instance is moved from HTTP to HTTPS, all embeded HTTP content will stop working. This tool allows you to automatically convert the HTTP content to HTTPS. Below you can run a report of content that may not work once you run this script. You may want to check each one has HTTPS available or find alternative resources.'; +$string['domainexplainhelp'] = 'These domains are found in your content, but do not appear to support HTTPS content. After switching to HTTPS, the content included from these sites will no longer display within Moodle for users with secure modern browsers. It is possible that these sites are temporarily or permanently unavailable and will not work with either security setting. Proceed only after reviewing these results and determining if this externally hosted content is non-essential. Note: This content would no longer work upon switching to HTTPS anyway.'; $string['httpwarning'] = 'This instance is still running on HTTP. You can still run this tool and external content will be changed to HTTPS, but internal content will remain on HTTP. You will need to run this script again after switching to HTTPS to convert internal content.'; $string['notimplemented'] = 'Sorry, this feature is not implemented in your database driver.'; $string['oktoprocede'] = 'The scan finds no issues with your content. You can proceed to upgrade any HTTP content to use HTTPS.'; diff --git a/admin/tool/httpsreplace/settings.php b/admin/tool/httpsreplace/settings.php index df9a024cc0e..bf5c259580c 100644 --- a/admin/tool/httpsreplace/settings.php +++ b/admin/tool/httpsreplace/settings.php @@ -38,5 +38,4 @@ if ($hassiteconfig) { new lang_string('toolintro', 'tool_httpsreplace', $httpsreplaceurl) ) ); - } diff --git a/admin/tool/httpsreplace/tests/behat/httpsreplace.feature b/admin/tool/httpsreplace/tests/behat/httpsreplace.feature index 9f6052eb7bb..82bbf590151 100644 --- a/admin/tool/httpsreplace/tests/behat/httpsreplace.feature +++ b/admin/tool/httpsreplace/tests/behat/httpsreplace.feature @@ -15,12 +15,14 @@ Feature: View the httpsreplace report Scenario: Go to the HTTPS replace report screen. Make sure broken domains are reported. When I navigate to "HTTP security" node in "Site administration > Security" And I follow "HTTPS conversion tool" + And I press "Continue" Then I should see "intentionally.unavailable" @javascript Scenario: Use the find and replace tool. When I navigate to "HTTP security" node in "Site administration > Security" And I follow "HTTPS conversion tool" + And I press "Continue" And I set the field "I understand the risks of this operation" to "1" And I press "Perform replacement" Then I should see "intentionally.unavailable" diff --git a/admin/tool/httpsreplace/tool.php b/admin/tool/httpsreplace/tool.php new file mode 100644 index 00000000000..12d5acb2430 --- /dev/null +++ b/admin/tool/httpsreplace/tool.php @@ -0,0 +1,109 @@ +. + +/** + * Search and replace http -> https throughout all texts in the whole database + * + * @package tool_httpsreplace + * @copyright Copyright (c) 2016 Blackboard Inc. (http://www.blackboard.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define('NO_OUTPUT_BUFFERING', true); + +require_once(__DIR__ . '/../../../config.php'); +require_once($CFG->dirroot . '/course/lib.php'); +require_once($CFG->libdir . '/adminlib.php'); + +admin_externalpage_setup('toolhttpsreplace'); + +$context = context_system::instance(); + +require_login(); +require_capability('moodle/site:config', $context); + +$PAGE->set_context($context); +$PAGE->set_url(new moodle_url('/admin/tool/httpsreplace/index.php')); +$PAGE->set_title(get_string('pageheader', 'tool_httpsreplace')); +$PAGE->set_pagelayout('admin'); + +echo $OUTPUT->header(); + +echo $OUTPUT->heading(get_string('pageheader', 'tool_httpsreplace')); + +if (!$DB->replace_all_text_supported()) { + echo $OUTPUT->notification(get_string('notimplemented', 'tool_httpsreplace')); + echo $OUTPUT->footer(); + die; +} + +if (!is_https()) { + echo $OUTPUT->notification(get_string('httpwarning', 'tool_httpsreplace'), 'warning'); +} + +$form = new \tool_httpsreplace\form(); + +$finder = new \tool_httpsreplace\url_finder(); + +$PAGE->set_cacheable(false); +$progressbar = new progress_bar(); + +if (!$data = $form->get_data()) { + + echo $progressbar->create(); + + $results = $finder->http_link_stats($progressbar); + + $progressbar->update_full(100, get_string('complete', 'tool_httpsreplace')); + + if (empty($results)) { + echo '

'.get_string('oktoprocede', 'tool_httpsreplace').'

'; + } else { + arsort($results); + $table = new html_table(); + $table->id = 'plugins-check'; + $table->head = array( + get_string('domain', 'tool_httpsreplace'), + get_string('count', 'tool_httpsreplace'), + ); + $data = array(); + foreach ($results as $domain => $count) { + $cleandomain = format_text($domain, FORMAT_PLAIN); + $data[] = [$cleandomain, $count]; + } + $table->data = $data; + echo html_writer::table($table); + echo get_string('domainexplainhelp', 'tool_httpsreplace'); + } + echo $OUTPUT->notification(get_string('takeabackupwarning', 'tool_httpsreplace'), 'warning'); + $form->display(); +} else { + // Scroll to the end when finished. + $PAGE->requires->js_init_code("window.scrollTo(0, document.body.scrollHeight);"); + + echo html_writer::tag('p', get_string('replacing', 'tool_httpsreplace')); + + echo $progressbar->create(); + + echo $OUTPUT->box_start(); + $finder->upgrade_http_links($progressbar); + echo $OUTPUT->box_end(); + + $progressbar->update_full(100, get_string('complete', 'tool_httpsreplace')); + + echo $OUTPUT->continue_button(new moodle_url('/admin/settings.php', ['section' => 'httpsecurity'])); +} +echo $OUTPUT->footer();