cvs: docweb /scripts checkent.php
| From: | Mehdi Achour | Date: | Wed, 19 Jan 2005 15:30:38 +0000 |
| Subject: | cvs: docweb /scripts checkent.php | ||
| Groups: | php.doc.web | ||
| Request: | Send a blank email to doc-web+get-492@lists.php.net to get a copy of this message | ||
didou Wed Jan 19 10:30:38 2005 EDT
Modified files:
/docweb/scripts checkent.php
Log:
WS and CS (also remove error_reporting(E_ALL))
http://cvs.php.net/diff.php/docweb/scripts/checkent.php?r1=1.2&r2=1.3&ty=u Index: docweb/scripts/checkent.php diff -u docweb/scripts/checkent.php:1.2 docweb/scripts/checkent.php:1.3 --- docweb/scripts/checkent.php:1.2 Wed Jan 19 10:27:23 2005 +++ docweb/scripts/checkent.php Wed Jan 19 10:30:37 2005 @@ -18,19 +18,9 @@ * | Docweb port: Nuno Lopes <nlopess@php.net> | * | Mehdi Achour <didou@php.net> | * +----------------------------------------------------------------------+ - * - * $Id: checkent.php,v 1.2 2005/01/19 15:27:23 didou Exp $ + * $Id: checkent.php,v 1.3 2005/01/19 15:30:37 didou Exp $ */ - -/* - * checks for errors in URL entities. Currently supports FTP and HTTP. - * - * Based on phpdoc/scripts/checkent.php by Georg Richter and Gabor Hojtsy. - */ - -error_reporting(E_ALL); - set_time_limit(0); $inCli = true; include '../include/init.inc.php'; @@ -75,100 +65,98 @@ // 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 if (gethostbyname($url['host']) == $url['host']) { $errors[UNKNOWN_HOST][] = array($num); continue; } - - switch($url['scheme']) { - + case 'http': - $url['path'] = isset($url['path']) ? $url['path'] : '/'; + $url['path'] = isset($url['path']) ? $url['path'] : '/'; - if (!$fp = @fsockopen($url['host'], 80, $errno, $errstr, 30)) { - $errors[HTTP_CONNECT][] = array($num); + if (!$fp = @fsockopen($url['host'], 80, $errno, $errstr, 30)) { + $errors[HTTP_CONNECT][] = array($num); - } else { - fputs($fp, "HEAD {$url['path']} HTTP/1.0\r\nHost: {$url['host']}\r\nConnection: close\r\n\r\n"); + } else { + fputs($fp, "HEAD {$url['path']} HTTP/1.0\r\nHost: {$url['host']}\r\nConnection: close\r\n\r\n"); - $str = ''; - while (!feof($fp)) { - $str .= fgets($fp, 2048); - } - fclose ($fp); + $str = ''; + while (!feof($fp)) { + $str .= fgets($fp, 2048); + } + fclose ($fp); - if (preg_match('@HTTP/1.\d (\d+)(?: .+)?@S', $str, $match)) { + if (preg_match('@HTTP/1.\d (\d+)(?: .+)?@S', $str, $match)) { - if ($match[1] != '200') { + if ($match[1] != '200') { - switch ($match[1]) - { - case '500' : - case '501' : - $errors[HTTP_INTERNAL_ERROR][] = array($num); - fputs($o, $str); - break; - - case '404' : - $errors[HTTP_NOT_FOUND][] = array($num); - break; - - case '301' : - case '302' : - if (preg_match('/Location: (.+)/', $str, $redir)) { - $errors[HTTP_MOVED][] = array($num, $redir[1]); - } else { - $errors[HTTP_WRONG_HEADER][] = array($num, $str); - } - break; - - default : + switch ($match[1]) + { + case '500' : + case '501' : + $errors[HTTP_INTERNAL_ERROR][] = array($num); + fputs($o, $str); + break; + + case '404' : + $errors[HTTP_NOT_FOUND][] = array($num); + break; + + case '301' : + case '302' : + if (preg_match('/Location: (.+)/', $str, $redir)) { + $errors[HTTP_MOVED][] = array($num, $redir[1]); + } else { $errors[HTTP_WRONG_HEADER][] = array($num, $str); } - } // error != 200 - } else { - $errors[HTTP_WRONG_HEADER][] = array($num, $str); - } + break; + + default : + $errors[HTTP_WRONG_HEADER][] = array($num, $str); + } + } // error != 200 + } else { + $errors[HTTP_WRONG_HEADER][] = array($num, $str); } + } break; - + case 'ftp': - if ($ftp = @ftp_connect($url['host'])) { - - if (@ftp_login($ftp, 'anonymous', 'IEUser@')) { - $flist = ftp_nlist($ftp, $url['path']); - if (!count($flist)) { - $errors[FTP_NO_FILE][] = array($num); - } - } else { - $errors[FTP_LOGIN][] = array($num); + if ($ftp = @ftp_connect($url['host'])) { + + if (@ftp_login($ftp, 'anonymous', 'IEUser@')) { + $flist = ftp_nlist($ftp, $url['path']); + if (!count($flist)) { + $errors[FTP_NO_FILE][] = array($num); } - @ftp_quit($ftp); } else { - $errors[FTP_CONNECT][] = array($num); + $errors[FTP_LOGIN][] = array($num); } + @ftp_quit($ftp); + } else { + $errors[FTP_CONNECT][] = array($num); + } break; } } // ouput the html -echo "<?php include_once '../include/init.inc.php'; +echo "<?php include_once '../include/init.inc.php'; echo site_header('docweb.common.header.checkent'); ?><p>Last check: " . date('r') . "</p>"; if (isset($errors[UNKNOWN_HOST])) { echo '<h2>Unknown host (' . count($errors[UNKNOWN_HOST]) . ')</h2>' . -'<table > + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -181,13 +169,13 @@ .'<td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_CONNECT])) { echo '<h2>HTTP Failed to connect (' . count($errors[HTTP_CONNECT]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -199,13 +187,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[FTP_CONNECT])) { echo '<h2>FTP Failed to connect (' . count($errors[FTP_CONNECT]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -217,13 +205,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[FTP_LOGIN])) { echo '<h2>FTP Cannot login (' . count($errors[FTP_LOGIN]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -236,13 +224,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[FTP_NO_FILE])) { echo '<h2>FTP File not found (' . count($errors[FTP_NO_FILE]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -255,14 +243,14 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_INTERNAL_ERROR])) { echo '<h2>HTTP Internal error (' . count($errors[HTTP_INTERNAL_ERROR]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -274,13 +262,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_NOT_FOUND])) { echo '<h2>HTTP 404 Not Found (' . count($errors[HTTP_NOT_FOUND]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -292,13 +280,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_MOVED])) { echo '<h2>HTTP Moved files (' . count($errors[HTTP_MOVED]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>Redirected to</th> @@ -310,13 +298,13 @@ <td><a href="' . $infos[1] . '">' . $infos[1] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_WRONG_HEADER])) { echo '<h2>HTTP Error (' . count($errors[HTTP_WRONG_HEADER]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>Unreconized header</th>
http://cvs.php.net/diff.php/docweb/scripts/checkent.php?r1=1.2&r2=1.3&ty=u Index: docweb/scripts/checkent.php diff -u docweb/scripts/checkent.php:1.2 docweb/scripts/checkent.php:1.3 --- docweb/scripts/checkent.php:1.2 Wed Jan 19 10:27:23 2005 +++ docweb/scripts/checkent.php Wed Jan 19 10:30:37 2005 @@ -18,19 +18,9 @@ * | Docweb port: Nuno Lopes <nlopess@php.net> | * | Mehdi Achour <didou@php.net> | * +----------------------------------------------------------------------+ - * - * $Id: checkent.php,v 1.2 2005/01/19 15:27:23 didou Exp $ + * $Id: checkent.php,v 1.3 2005/01/19 15:30:37 didou Exp $ */ - -/* - * checks for errors in URL entities. Currently supports FTP and HTTP. - * - * Based on phpdoc/scripts/checkent.php by Georg Richter and Gabor Hojtsy. - */ - -error_reporting(E_ALL); - set_time_limit(0); $inCli = true; include '../include/init.inc.php'; @@ -75,100 +65,98 @@ // 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 if (gethostbyname($url['host']) == $url['host']) { $errors[UNKNOWN_HOST][] = array($num); continue; } - - switch($url['scheme']) { - + case 'http': - $url['path'] = isset($url['path']) ? $url['path'] : '/'; + $url['path'] = isset($url['path']) ? $url['path'] : '/'; - if (!$fp = @fsockopen($url['host'], 80, $errno, $errstr, 30)) { - $errors[HTTP_CONNECT][] = array($num); + if (!$fp = @fsockopen($url['host'], 80, $errno, $errstr, 30)) { + $errors[HTTP_CONNECT][] = array($num); - } else { - fputs($fp, "HEAD {$url['path']} HTTP/1.0\r\nHost: {$url['host']}\r\nConnection: close\r\n\r\n"); + } else { + fputs($fp, "HEAD {$url['path']} HTTP/1.0\r\nHost: {$url['host']}\r\nConnection: close\r\n\r\n"); - $str = ''; - while (!feof($fp)) { - $str .= fgets($fp, 2048); - } - fclose ($fp); + $str = ''; + while (!feof($fp)) { + $str .= fgets($fp, 2048); + } + fclose ($fp); - if (preg_match('@HTTP/1.\d (\d+)(?: .+)?@S', $str, $match)) { + if (preg_match('@HTTP/1.\d (\d+)(?: .+)?@S', $str, $match)) { - if ($match[1] != '200') { + if ($match[1] != '200') { - switch ($match[1]) - { - case '500' : - case '501' : - $errors[HTTP_INTERNAL_ERROR][] = array($num); - fputs($o, $str); - break; - - case '404' : - $errors[HTTP_NOT_FOUND][] = array($num); - break; - - case '301' : - case '302' : - if (preg_match('/Location: (.+)/', $str, $redir)) { - $errors[HTTP_MOVED][] = array($num, $redir[1]); - } else { - $errors[HTTP_WRONG_HEADER][] = array($num, $str); - } - break; - - default : + switch ($match[1]) + { + case '500' : + case '501' : + $errors[HTTP_INTERNAL_ERROR][] = array($num); + fputs($o, $str); + break; + + case '404' : + $errors[HTTP_NOT_FOUND][] = array($num); + break; + + case '301' : + case '302' : + if (preg_match('/Location: (.+)/', $str, $redir)) { + $errors[HTTP_MOVED][] = array($num, $redir[1]); + } else { $errors[HTTP_WRONG_HEADER][] = array($num, $str); } - } // error != 200 - } else { - $errors[HTTP_WRONG_HEADER][] = array($num, $str); - } + break; + + default : + $errors[HTTP_WRONG_HEADER][] = array($num, $str); + } + } // error != 200 + } else { + $errors[HTTP_WRONG_HEADER][] = array($num, $str); } + } break; - + case 'ftp': - if ($ftp = @ftp_connect($url['host'])) { - - if (@ftp_login($ftp, 'anonymous', 'IEUser@')) { - $flist = ftp_nlist($ftp, $url['path']); - if (!count($flist)) { - $errors[FTP_NO_FILE][] = array($num); - } - } else { - $errors[FTP_LOGIN][] = array($num); + if ($ftp = @ftp_connect($url['host'])) { + + if (@ftp_login($ftp, 'anonymous', 'IEUser@')) { + $flist = ftp_nlist($ftp, $url['path']); + if (!count($flist)) { + $errors[FTP_NO_FILE][] = array($num); } - @ftp_quit($ftp); } else { - $errors[FTP_CONNECT][] = array($num); + $errors[FTP_LOGIN][] = array($num); } + @ftp_quit($ftp); + } else { + $errors[FTP_CONNECT][] = array($num); + } break; } } // ouput the html -echo "<?php include_once '../include/init.inc.php'; +echo "<?php include_once '../include/init.inc.php'; echo site_header('docweb.common.header.checkent'); ?><p>Last check: " . date('r') . "</p>"; if (isset($errors[UNKNOWN_HOST])) { echo '<h2>Unknown host (' . count($errors[UNKNOWN_HOST]) . ')</h2>' . -'<table > + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -181,13 +169,13 @@ .'<td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_CONNECT])) { echo '<h2>HTTP Failed to connect (' . count($errors[HTTP_CONNECT]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -199,13 +187,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[FTP_CONNECT])) { echo '<h2>FTP Failed to connect (' . count($errors[FTP_CONNECT]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -217,13 +205,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[FTP_LOGIN])) { echo '<h2>FTP Cannot login (' . count($errors[FTP_LOGIN]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -236,13 +224,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[FTP_NO_FILE])) { echo '<h2>FTP File not found (' . count($errors[FTP_NO_FILE]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -255,14 +243,14 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_INTERNAL_ERROR])) { echo '<h2>HTTP Internal error (' . count($errors[HTTP_INTERNAL_ERROR]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -274,13 +262,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_NOT_FOUND])) { echo '<h2>HTTP 404 Not Found (' . count($errors[HTTP_NOT_FOUND]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>URL</th> @@ -292,13 +280,13 @@ <td><a href="' . $entity_urls[$infos[0]] . '">' . $entity_urls[$infos[0]] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_MOVED])) { echo '<h2>HTTP Moved files (' . count($errors[HTTP_MOVED]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>Redirected to</th> @@ -310,13 +298,13 @@ <td><a href="' . $infos[1] . '">' . $infos[1] . '</a></td> </tr>'; } - + echo '</table>'; } if (isset($errors[HTTP_WRONG_HEADER])) { echo '<h2>HTTP Error (' . count($errors[HTTP_WRONG_HEADER]) . ')</h2>' . -'<table> + '<table> <tr class="blue"> <th>Entity Name</th> <th>Unreconized header</th>