Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-36641 Missing HTTP check when using an external resource

  • Loading branch information...
commit f833171fd1461164c6f97d0e2c2bc5597dd677d9 1 parent f42c34a
Matteo Scaramuccia scara authored
1  mod/scorm/lang/en/scorm.php
View
@@ -180,6 +180,7 @@
$string['interactionslearnerresponse'] = 'Learner\'s Response';
$string['invalidactivity'] = 'Scorm activity is incorrect';
$string['invalidurl'] = 'Invalid URL specified';
+$string['invalidurlhttpcheck'] = 'Invalid URL specified. Debug message:<pre>{$a->cmsg}</pre>';
$string['invalidhacpsession'] = 'Invalid HACP Session';
$string['invalidmanifestresource'] = 'WARNING: The following resources were referenced in your manifest but couldn\'t be found:';
$string['last'] = 'Last accessed on';
24 mod/scorm/locallib.php
View
@@ -1864,3 +1864,27 @@ function scorm_get_adlnav_json ($scoes, &$adlnav = array(), $parentscoid = null)
}
return json_encode($adlnav);
}
+
+/**
+ * Check for the availability of a resource by URL.
+ *
+ * Check is performed using an HTTP HEAD call.
+ *
+ * @param $url string A valid URL
+ * @return bool|string True if no issue is found. The error string message, otherwise
+ */
+function scorm_check_url($url) {
+ $curl = new curl;
+
+ if (!ini_get('open_basedir') and !ini_get('safe_mode')) {
+ // Same options as in {@link download_file_content()}, used in {@link scorm_parse_scorm()}.
+ $curl->setopt(array('CURLOPT_FOLLOWLOCATION' => true, 'CURLOPT_MAXREDIRS' => 5));
+ }
+ $cmsg = $curl->head($url);
+ $info = $curl->get_info();
+ if (empty($info['http_code']) || $info['http_code'] != 200) {
+ return get_string('invalidurlhttpcheck', 'scorm', array('cmsg' => $cmsg));
+ }
+
+ return true;
+}
23 mod/scorm/mod_form.php
View
@@ -393,14 +393,28 @@ function validation($data, $files) {
} else if ($type === SCORM_TYPE_EXTERNAL) {
$reference = $data['packageurl'];
+ // Syntax check.
if (!preg_match('/(http:\/\/|https:\/\/|www).*\/imsmanifest.xml$/i', $reference)) {
$errors['packageurl'] = get_string('invalidurl', 'scorm');
+ } else {
+ // Availability check.
+ $result = scorm_check_url($reference);
+ if (is_string($result)) {
+ $errors['packageurl'] = $result;
+ }
}
} else if ($type === 'packageurl') {
$reference = $data['reference'];
+ // Syntax check.
if (!preg_match('/(http:\/\/|https:\/\/|www).*(\.zip|\.pif)$/i', $reference)) {
$errors['packageurl'] = get_string('invalidurl', 'scorm');
+ } else {
+ // Availability check.
+ $result = scorm_check_url($reference);
+ if (is_string($result)) {
+ $errors['packageurl'] = $result;
+ }
}
} else if ($type === SCORM_TYPE_IMSREPOSITORY) {
@@ -408,11 +422,20 @@ function validation($data, $files) {
if (stripos($reference, '#') !== 0) {
$errors['packageurl'] = get_string('invalidurl', 'scorm');
}
+
} else if ($type === SCORM_TYPE_AICCURL) {
$reference = $data['packageurl'];
+ // Syntax check.
if (!preg_match('/(http:\/\/|https:\/\/|www).*/', $reference)) {
$errors['packageurl'] = get_string('invalidurl', 'scorm');
+ } else {
+ // Availability check.
+ $result = scorm_check_url($reference);
+ if (is_string($result)) {
+ $errors['packageurl'] = $result;
+ }
}
+
}
return $errors;
Please sign in to comment.
Something went wrong with that request. Please try again.