#!/usr/bin/php -q | | Gabor Hojtsy | +----------------------------------------------------------------------+ $Id$ */ if ($argc > 1 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) { ?> Check entities in entities/global.ent (HTTP and FTP schemes) Usage: This script checks FTP and HTTP URLs listed in entities/global.ent. Grab the output, to put it in a text file. ', $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("//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); } ?>