mirror of
https://github.com/moodle/moodle.git
synced 2025-03-31 05:52:51 +02:00
MDL-46269 tool_httpsreplace: Add tool_httpsreplace to core
This commit is contained in:
parent
9a316f3367
commit
eca2b34cb0
8
admin/tool/httpsreplace/README.md
Normal file
8
admin/tool/httpsreplace/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
This plugin was contributed by the Moodlerooms Product Development team. Moodlerooms is an education technology company
|
||||
dedicated to bringing excellent online teaching to institutions across the globe. We serve colleges and universities,
|
||||
schools and organizations by supporting the software that educators use to manage and deliver instructional content to
|
||||
learners in virtual classrooms. Moodlerooms is headquartered in Baltimore, MD. We are proud to be a Moodle Partner company.
|
||||
|
||||
For more information about installation, configuration and usage, please see [the wiki page]
|
||||
|
||||
[the wiki page]: <https://docs.moodle.org/30/en/admin/tool/httpsreplace/index>
|
47
admin/tool/httpsreplace/classes/form.php
Normal file
47
admin/tool/httpsreplace/classes/form.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Site wide http -> https search-replace form.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
namespace tool_httpsreplace;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/formslib.php");
|
||||
|
||||
/**
|
||||
* Site wide http -> https search-replace form.
|
||||
*/
|
||||
class form extends \moodleform {
|
||||
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'confirmhdr', get_string('confirm'));
|
||||
$mform->setExpanded('confirmhdr', true);
|
||||
$mform->addElement('checkbox', 'sure', get_string('disclaimer', 'tool_httpsreplace'));
|
||||
$mform->addRule('sure', get_string('required'), 'required', null, 'client');
|
||||
|
||||
$this->add_action_buttons(false, get_string('doit', 'tool_httpsreplace'));
|
||||
}
|
||||
|
||||
}
|
227
admin/tool/httpsreplace/classes/url_finder.php
Normal file
227
admin/tool/httpsreplace/classes/url_finder.php
Normal file
@ -0,0 +1,227 @@
|
||||
<?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/>.
|
||||
|
||||
namespace tool_httpsreplace;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Examines DB for non-https src or data links that will cause trouble
|
||||
* when embedded in HTTPS sites.
|
||||
*
|
||||
* @package tool_httpsreplace
|
||||
* @copyright Copyright (c) 2016 Blackboard Inc. (http://www.blackboard.com)
|
||||
*/
|
||||
class url_finder {
|
||||
|
||||
/**
|
||||
* Domains that need replaced when using https links.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private $exceptions = [
|
||||
'cdnapi.kaltura.com' => 'cdnapisec.kaltura.com',
|
||||
];
|
||||
|
||||
public function http_link_stats() {
|
||||
return $this->process(false);
|
||||
}
|
||||
|
||||
public function upgrade_http_links() {
|
||||
return $this->process(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace http domains with https equivalent, with two types of exceptions
|
||||
* for less straightforward swaps.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @param string $domain
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function domain_swap($table, $column, $domain) {
|
||||
global $DB;
|
||||
|
||||
$search = "http://$domain";
|
||||
$replace = "https://$domain";
|
||||
if (isset($this->exceptions[$domain])) {
|
||||
$replace = 'https://' . $this->exceptions[$domain];
|
||||
}
|
||||
if (preg_match('/rackcdn.com$/', $domain)) {
|
||||
// Regexes adapted from
|
||||
// https://www.eff.org/https-everywhere/atlas/domains/rackcdn.com.html ruleset.
|
||||
$pattern = '/^([\w-]+)\.(?:r\d+|ssl)\.cf(\d)\.rackcdn\.com$/';
|
||||
$replacement = 'https://$1.ssl.cf$2.rackcdn.com';
|
||||
$replace = preg_replace($pattern, $replacement, $domain);
|
||||
}
|
||||
$DB->set_debug(true);
|
||||
// Note, this search is case sensitive.
|
||||
$DB->replace_all_text($table, $column, $search, $replace);
|
||||
$DB->set_debug(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Originally forked from core function db_search().
|
||||
*/
|
||||
private function process($replacing = false) {
|
||||
global $DB, $CFG;
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
$httpurls = "(src|data)\ *=\ *[\\\"\']http://";
|
||||
|
||||
// TODO: block_instances have HTML content as base64, need to decode then
|
||||
// search, currently just skipped.
|
||||
$skiptables = array(
|
||||
'block_instances',
|
||||
'config',
|
||||
'config_log',
|
||||
'config_plugins',
|
||||
'events_queue',
|
||||
'files',
|
||||
'filter_config',
|
||||
'grade_grades_history',
|
||||
'grade_items_history',
|
||||
'log',
|
||||
'logstore_standard_log',
|
||||
'repository_instance_config',
|
||||
'sessions',
|
||||
'upgrade_log',
|
||||
'grade_categories_history',
|
||||
'',
|
||||
);
|
||||
|
||||
// Turn off time limits.
|
||||
\core_php_time_limit::raise();
|
||||
if (!$tables = $DB->get_tables() ) { // No tables yet at all.
|
||||
return false;
|
||||
}
|
||||
|
||||
$urls = array();
|
||||
$texttypes = array (
|
||||
'text',
|
||||
'mediumtext',
|
||||
'longtext',
|
||||
'varchar',
|
||||
);
|
||||
|
||||
foreach ($tables as $table) {
|
||||
if (in_array($table, $skiptables)) {
|
||||
continue;
|
||||
}
|
||||
if ($columns = $DB->get_columns($table)) {
|
||||
$regexp = $DB->sql_regex();
|
||||
foreach ($columns as $column) {
|
||||
|
||||
if (in_array($column->type, $texttypes)) {
|
||||
$columnname = $column->name;
|
||||
$select = "$columnname $regexp ?";
|
||||
$rs = $DB->get_recordset_select($table, $select, [$httpurls]);
|
||||
|
||||
$found = array();
|
||||
foreach ($rs as $record) {
|
||||
// Regex to match src=http://etc. and data=http://etc.urls.
|
||||
// Standard warning on expecting regex to perfectly parse HTML
|
||||
// read http://stackoverflow.com/a/1732454 for more info.
|
||||
$regex = '#(src|data)\ *=\ *[\'\"]http://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))[\'\"]#';
|
||||
preg_match_all($regex, $record->$columnname, $match);
|
||||
foreach ($match[0] as $url) {
|
||||
if (strpos($url, $CFG->wwwroot) !== false) {
|
||||
continue;
|
||||
}
|
||||
if ($replacing) {
|
||||
$url = substr($url, strpos($url, 'http'), -1);
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
$found[] = $host;
|
||||
} else {
|
||||
$entry["table"] = $table;
|
||||
$entry["columnname"] = $columnname;
|
||||
$entry["url"] = str_replace(array("'", '"'), "", substr($url, ((int) strpos($url, "=") + 1) ));
|
||||
$entry["host"] = parse_url($entry["url"], PHP_URL_HOST);
|
||||
$entry["raw"] = $record->$columnname;
|
||||
$entry["ssl"] = '';
|
||||
$urls[] = $entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
if ($replacing) {
|
||||
$found = array_unique($found);
|
||||
foreach ($found as $domain) {
|
||||
$this->domain_swap($table, $column, $domain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($replacing) {
|
||||
rebuild_course_cache(0, true);
|
||||
purge_all_caches();
|
||||
return true;
|
||||
}
|
||||
|
||||
$domains = array_map(function ($i) {
|
||||
return $i['host'];
|
||||
}, $urls);
|
||||
|
||||
$uniquedomains = array_unique($domains);
|
||||
|
||||
$sslfailures = array();
|
||||
$knownsupported = array(
|
||||
'amazon.com',
|
||||
'www.amazon.com',
|
||||
'dropbox.com',
|
||||
'www.dropbox.com',
|
||||
'cdnapi.kaltura.com',
|
||||
'fe8be92ac963979368eca.r38.cf1.rackcdn.com', // Not actually a real domain, but used for testing.
|
||||
);
|
||||
|
||||
foreach ($uniquedomains as $domain) {
|
||||
if (in_array($domain, $knownsupported)) {
|
||||
continue;
|
||||
}
|
||||
$url = "https://$domain/";
|
||||
$curl = new \curl();
|
||||
$curl->head($url);
|
||||
$info = $curl->get_info();
|
||||
if (empty($info['http_code']) or ($info['http_code'] >= 400)) {
|
||||
$sslfailures[] = $domain;
|
||||
}
|
||||
}
|
||||
|
||||
$results = array();
|
||||
foreach ($urls as $url) {
|
||||
$host = $url['host'];
|
||||
foreach ($sslfailures as $badhost) {
|
||||
if ($host == $badhost) {
|
||||
if (!isset($results[$host])) {
|
||||
$results[$host] = 1;
|
||||
} else {
|
||||
$results[$host]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
43
admin/tool/httpsreplace/cli/url_finder.php
Normal file
43
admin/tool/httpsreplace/cli/url_finder.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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/>.
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require(__DIR__ . '/../../../../config.php');
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
|
||||
list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help'));
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
cli_error(get_string('cliunknowoption', 'admin', $unrecognized), 2);
|
||||
}
|
||||
if ($options['help']) {
|
||||
$help = "List of http (not https) urls on a site in the DB
|
||||
Options:
|
||||
-h, --help Print out this help
|
||||
Example:
|
||||
\$sudo -u www-data /usr/bin/php admin/tool/httpsreplace/cli/url_finder.php \n";
|
||||
echo $help;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$urlfinder = new \tool_httpsreplace\url_finder();
|
||||
$results = $urlfinder->http_link_stats();
|
||||
$fp = fopen('php://stdout', 'w');
|
||||
fputcsv($fp, ['clientsite', 'httpdomain', 'urlcount']);
|
||||
foreach ($results as $domain => $count) {
|
||||
fputcsv($fp, [$SITE->shortname, $domain, $count]);
|
||||
}
|
||||
fclose($fp);
|
37
admin/tool/httpsreplace/cli/url_replace.php
Normal file
37
admin/tool/httpsreplace/cli/url_replace.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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/>.
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require(__DIR__ . '/../../../../config.php');
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
|
||||
list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help'));
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
cli_error(get_string('cliunknowoption', 'admin', $unrecognized), 2);
|
||||
}
|
||||
if ($options['help']) {
|
||||
$help = "Replaces http urls with https across a site's content
|
||||
Options:
|
||||
-h, --help Print out this help
|
||||
Example:
|
||||
\$sudo -u www-data /usr/bin/php admin/tool/httpsreplace/cli/url_replace.php \n";
|
||||
echo $help;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$urlfinder = new \tool_httpsreplace\url_finder();
|
||||
$urlfinder->upgrade_http_links();
|
89
admin/tool/httpsreplace/index.php
Normal file
89
admin/tool/httpsreplace/index.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?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('../../../config.php');
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
admin_externalpage_setup('toolhttpsreplace');
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
echo $OUTPUT->box_start();
|
||||
echo $OUTPUT->notification(get_string('takeabackupwarning', 'tool_httpsreplace'));
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
|
||||
$form = new \tool_httpsreplace\form();
|
||||
|
||||
$finder = new \tool_httpsreplace\url_finder();
|
||||
if (!$data = $form->get_data()) {
|
||||
|
||||
$results = $finder->http_link_stats();
|
||||
|
||||
echo '<p>'.get_string('domainexplain', 'tool_httpsreplace').'</p>';
|
||||
echo '<p>'.page_doc_link(get_string('doclink', 'tool_httpsreplace')).'</p>';
|
||||
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);
|
||||
}
|
||||
$form->display();
|
||||
} else {
|
||||
// Scroll to the end when finished.
|
||||
$PAGE->requires->js_init_code("window.scrollTo(0, 5000000);");
|
||||
|
||||
echo '<p>'.get_string('replacing', 'tool_httpsreplace').'</p>';
|
||||
|
||||
echo $OUTPUT->box_start();
|
||||
$finder->upgrade_http_links();
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
echo $OUTPUT->continue_button(new moodle_url('/admin/index.php'));
|
||||
|
||||
}
|
||||
echo $OUTPUT->footer();
|
41
admin/tool/httpsreplace/lang/en/tool_httpsreplace.php
Normal file
41
admin/tool/httpsreplace/lang/en/tool_httpsreplace.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'tool_httpsreplace'
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage httpsreplace
|
||||
* @copyright Copyright (c) 2016 Blackboard Inc. (http://www.blackboard.com)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['count'] = 'Number of links';
|
||||
$string['disclaimer'] = 'I understand the risks of this operation';
|
||||
$string['doclink'] = 'Read more documentation on the wiki';
|
||||
$string['doit'] = 'Yes, do it!';
|
||||
$string['domain'] = 'Problematic domain';
|
||||
$string['domainexplain'] = 'This tool locates embedded content that may not work when upgrading a site to use https. It also allows you to fix the problems automatically.';
|
||||
$string['domainexplainhelp'] = 'These domains are found in your content, but do not appear to support https links. 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['invalidcharacter'] = 'Invalid characters were found in the search or replace text.';
|
||||
$string['notifyfinished'] = '...finished';
|
||||
$string['notifyrebuilding'] = 'Rebuilding course cache...';
|
||||
$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 links to use https.';
|
||||
$string['pageheader'] = 'Upgrade externally hosted content urls to https';
|
||||
$string['pluginname'] = 'HTTPS Replace';
|
||||
$string['replacing'] = 'Replacing http links with https...';
|
||||
$string['takeabackupwarning'] = 'Changes made can\'t be reverted. A complete backup should be made before running this script!';
|
32
admin/tool/httpsreplace/settings.php
Normal file
32
admin/tool/httpsreplace/settings.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Link to http -> https replace script.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
if ($hassiteconfig) {
|
||||
|
||||
$pluginname = get_string('pluginname', 'tool_httpsreplace');
|
||||
$url = $CFG->wwwroot.'/'.$CFG->admin.'/tool/httpsreplace/index.php';
|
||||
$ADMIN->add('unsupported', new admin_externalpage('toolhttpsreplace', $pluginname, $url, 'moodle/site:config', true));
|
||||
}
|
116
admin/tool/httpsreplace/tests/httpsreplace_test.php
Normal file
116
admin/tool/httpsreplace/tests/httpsreplace_test.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* HTTPS find and replace Tests
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
namespace tool_httpsreplace\tests;
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
class httpsreplace_test extends \advanced_testcase {
|
||||
|
||||
public function test_find_and_replace() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->expectOutputRegex("/UPDATE/");
|
||||
|
||||
$finder = new \tool_httpsreplace\url_finder();
|
||||
$results = $finder->http_link_stats();
|
||||
$this->assertEmpty($results);
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
$imglink1 = '<img src="http://intentionally.unavailable/link1.jpg">';
|
||||
$course1 = $generator->create_course((object) [
|
||||
'summary' => $imglink1,
|
||||
]);
|
||||
|
||||
$imglink2 = '<img src="http://intentionally.unavailable/link2.gif">';
|
||||
$course2 = $generator->create_course((object) [
|
||||
'summary' => $imglink2,
|
||||
]);
|
||||
|
||||
$imglink3 = '<img src="http://other.unavailable/link3.svg">';
|
||||
$course3 = $generator->create_course((object) [
|
||||
'summary' => $imglink1.$imglink2.$imglink3,
|
||||
]);
|
||||
|
||||
$kaltura = '<script src="http://cdnapi.kaltura.com/p/730212/sp/73021200/embedIframeJs">';
|
||||
$course4 = $generator->create_course((object) [
|
||||
'summary' => $kaltura,
|
||||
]);
|
||||
|
||||
$rackcdn = '<iframe src="http://fe8be92ac963979368eca.r38.cf1.rackcdn.com/Helpful_ET_Websites_Apps_Resources.pdf">';
|
||||
$course5 = $generator->create_course((object) [
|
||||
'summary' => $rackcdn,
|
||||
]);
|
||||
|
||||
$results = $finder->http_link_stats();
|
||||
$this->assertCount(2, $results);
|
||||
$this->assertEquals(4, $results['intentionally.unavailable']);
|
||||
$this->assertEquals(1, $results['other.unavailable']);
|
||||
|
||||
$finder->upgrade_http_links();
|
||||
|
||||
$results = $finder->http_link_stats();
|
||||
$this->assertEmpty($results);
|
||||
|
||||
$summary1 = $DB->get_field('course', 'summary', ['id' => $course1->id]);
|
||||
$this->assertContains('https://intentionally.unavailable', $summary1);
|
||||
$this->assertNotContains('http://intentionally.unavailable', $summary1);
|
||||
|
||||
$summary2 = $DB->get_field('course', 'summary', ['id' => $course2->id]);
|
||||
$this->assertContains('https://intentionally.unavailable', $summary2);
|
||||
$this->assertNotContains('http://intentionally.unavailable', $summary2);
|
||||
|
||||
$summary3 = $DB->get_field('course', 'summary', ['id' => $course3->id]);
|
||||
$this->assertContains('https://other.unavailable', $summary3);
|
||||
$this->assertContains('https://intentionally.unavailable', $summary3);
|
||||
$this->assertNotContains('http://intentionally.unavailable', $summary3);
|
||||
|
||||
$summary4 = $DB->get_field('course', 'summary', ['id' => $course4->id]);
|
||||
$this->assertContains('https://cdnapisec.kaltura.com', $summary4);
|
||||
|
||||
$summary5 = $DB->get_field('course', 'summary', ['id' => $course5->id]);
|
||||
$expected = "https://fe8be92ac963979368eca.ssl.cf1.rackcdn.com/Helpful_ET_Websites_Apps_Resources.pdf";
|
||||
$this->assertContains($expected, $summary5);
|
||||
}
|
||||
|
||||
public function test_upgrade_http_links_excluded_tables() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
set_config('test_upgrade_http_links', '<img src="http://somesite/someimage.png" />');
|
||||
|
||||
$finder = new \tool_httpsreplace\url_finder();
|
||||
ob_start();
|
||||
$results = $finder->upgrade_http_links();
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertTrue($results);
|
||||
$this->assertNotContains('https://somesite', $output);
|
||||
$testconf = get_config('core', 'test_upgrade_http_links');
|
||||
$this->assertContains('http://somesite', $testconf);
|
||||
$this->assertNotContains('https://somesite', $testconf);
|
||||
}
|
||||
|
||||
}
|
32
admin/tool/httpsreplace/version.php
Normal file
32
admin/tool/httpsreplace/version.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Version details.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2017063000; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2016120500; // Requires this Moodle version.
|
||||
$plugin->release = '3.2.3';
|
||||
$plugin->component = 'tool_httpsreplace'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
$plugin->maturity = MATURITY_STABLE; // This version's maturity level.
|
Loading…
x
Reference in New Issue
Block a user