Skip to content

Commit

Permalink
MDL-46269 tool_httpsreplace: Add multiple steps
Browse files Browse the repository at this point in the history
  • Loading branch information
xow authored and marinaglancy committed Oct 16, 2017
1 parent 4b86dd7 commit 55b1d23
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 63 deletions.
1 change: 0 additions & 1 deletion admin/tool/httpsreplace/classes/form.php
Expand Up @@ -49,5 +49,4 @@ public function definition() {

$this->add_action_buttons(false, get_string('doit', 'tool_httpsreplace'));
}

}
2 changes: 0 additions & 2 deletions admin/tool/httpsreplace/classes/url_finder.php
Expand Up @@ -35,7 +35,6 @@
*/
class url_finder {


/**
* Returns a hash of what hosts are referred to over http and would need to be changed.
*
Expand Down Expand Up @@ -234,5 +233,4 @@ private function process($replacing = false, $progress = null) {
}
return $results;
}

}
60 changes: 3 additions & 57 deletions admin/tool/httpsreplace/index.php
Expand Up @@ -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');
Expand Down Expand Up @@ -54,60 +51,9 @@
echo $OUTPUT->notification(get_string('httpwarning', 'tool_httpsreplace'), 'warning');
}

echo '<p>'.get_string('domainexplain', 'tool_httpsreplace').'</p>';
echo '<p>'.page_doc_link(get_string('doclink', 'tool_httpsreplace')).'</p>';

$form = new \tool_httpsreplace\form();

$finder = new \tool_httpsreplace\url_finder();
if (!$data = $form->get_data()) {

echo '<p>'.get_string('domainexplain', 'tool_httpsreplace').'</p>';
echo '<p>'.page_doc_link(get_string('doclink', 'tool_httpsreplace')).'</p>';

$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 '<p>'.get_string('oktoprocede', 'tool_httpsreplace').'</p>';
} 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 $OUTPUT->continue_button(new moodle_url('/admin/tool/httpsreplace/tool.php'));

echo '<p>'.get_string('replacing', 'tool_httpsreplace').'</p>';

$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();
4 changes: 2 additions & 2 deletions admin/tool/httpsreplace/lang/en/tool_httpsreplace.php
Expand Up @@ -28,8 +28,8 @@
$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.';
Expand Down
1 change: 0 additions & 1 deletion admin/tool/httpsreplace/settings.php
Expand Up @@ -38,5 +38,4 @@
new lang_string('toolintro', 'tool_httpsreplace', $httpsreplaceurl)
)
);

}
2 changes: 2 additions & 0 deletions admin/tool/httpsreplace/tests/behat/httpsreplace.feature
Expand Up @@ -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"
Expand Down
109 changes: 109 additions & 0 deletions admin/tool/httpsreplace/tool.php
@@ -0,0 +1,109 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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 '<p>'.get_string('oktoprocede', 'tool_httpsreplace').'</p>';
} 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();

0 comments on commit 55b1d23

Please sign in to comment.