1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#!/usr/bin/php -q
<?php
/*
+----------------------------------------------------------------------+
| Copyright (c) 1997-2023 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net, so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Georg Richter <georg@php.net> |
| Gabor Hojtsy <goba@php.net> |
+----------------------------------------------------------------------+
$Id$
*/
if ($argc > 1 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
Check entities in entities/global.ent (HTTP and FTP schemes)
Usage:
<?php echo $argv[0];?>
This script checks FTP and HTTP URLs listed
in entities/global.ent. Grab the output, to put it in
a text file.
<?php
exit;
}
/*********************************************************************/
/* Nothing to modify below this line */
/*********************************************************************/
// Like a good wine, this script needs some time
set_time_limit(0);
// Schemes we had to check
$schemes = array("http", "ftp");
// Start this script only from the scripts/qa dir
$filename = dirname(__DIR__, 2) . "/entities/global.ent";
// Read in the file, or die
$file_string = file_get_contents($filename);
if (!$file_string) { die ("Cannot open entity file ($filename)."); }
$array = explode('<!-- Obsoletes -->', $file_string);
$file_string = $array[0];
echo "ENTITY CHECK
=========================================================
In the table below you can find the validity check
errors of entites in $filename. Use this list to correct
errors in $filename.
=========================================================
";
// Find entity names and URLs
$schemes_preg = "(" . join("|", $schemes) . ")";
preg_match_all("/<!ENTITY\s+(\S+)\s+([\"'])(({$schemes_preg})[^\\2]+)\\2\s*>/U",
$file_string, $entities_found);
// These are the useful parts
$entity_names = $entities_found[1];
$entity_urls = $entities_found[3];
// Walk through entities found
foreach ($entity_urls as $num => $entity_url) {
// Get the parts of the URL
$url = parse_url($entity_url);
$entity = $entity_names[$num];
// Try to find host
$ip = gethostbyname($url["host"]);
if ($ip == $url["host"]) {
errormsg ($entity, "unknown host: " . $url["host"]);
// Host found, check path
} else {
// Depending on URL scheme
switch ($url["scheme"]) {
// Use URL fopen wrapper
case "http":
if ($fpurl = @fopen($entity_url, "r")) {
fclose ($fpurl);
}
else {
errormsg ($entity, "Could not open document: " . $entity_url);
}
break;
// Use FTP functions
case "ftp":
if ($ftp = @ftp_connect($url["host"])) {
if (@ftp_login($ftp, "anonymous", "georg@php.net")) {
$flist = ftp_nlist($ftp, $url["path"]);
if ($flist === false || !count($flist)) {
errormsg($entity, "unknown path: " . $url["path"] . " for ftp host: " . $url['host']);
}
} else {
errormsg ($entity, "could not login as anonymous to FTP host: " . $url["host"]);
}
ftp_quit($ftp);
} else {
errormsg ($entity, "could not connect to " . $url["host"]);
}
break;
}
}
}
/*********************************************************************/
/* Here starts the functions part */
/*********************************************************************/
function errormsg ($entity, $desc)
{
printf ("%30s: %s\n", $entity, $desc);
}
?>
|