File: checkent.php

package info (click to toggle)
phpdoc 20020310-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 35,272 kB
  • ctags: 354
  • sloc: xml: 799,767; php: 1,395; cpp: 500; makefile: 200; sh: 140; awk: 51
file content (121 lines) | stat: -rw-r--r-- 3,581 bytes parent folder | download
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
#!/usr/bin/php -q
<?php

if ($argc > 1 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>

Check entities in entities/global.ent (HTTP and FTP schemes)

  Usage:
  <?=$argv[0]?>

  This script checks FTP and HTTP URLs listed
  in entities/global.ent. Grab the output, to put it in
  a text file.
  
  Written by Georg Richter <georg@php.net>
  Adapted to phpdoc by Gabor Hojtsy <goba@php.net>

<?php
  exit;
}

// CONFIG SECTION
$docdir = "../"; // Main directory of the PHP documentation (one dir up in cvs)

/*********************************************************************/
/* 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 dir
$filename = "../entities/global.ent";

// Read in the file, or die
$file_array = file ($filename);
if (!$file_array) { die ("Cannot open entity file ($filename)."); }

// Put the whole file in a string
$file_string = preg_replace("/[\r\n]/", "", join ("", $file_array));

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($link, "r")) {
                    fclose ($fpurl);
                }
                else {
                    errormsg ($entity, "Could not open document: " . $link);
                }
            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 (!count($flist)) {
                            errormsg($entity, "unknown path: " . $url["path"]);
                        }
                    } else {
                        errormsg ($entity, "could not login as anonymous to " . $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);
}

?>