Subversion Repositories vgwhois

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
#!/usr/bin/php
2
<?php
3
 
4
#
11 daniel-mar 5
#  VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois)
5 daniel-mar 6
#  Maintenance / Developer utilities
2 daniel-mar 7
#
5 daniel-mar 8
#  (c) 2012-2019 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
2 daniel-mar 9
#
5 daniel-mar 10
#  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
2 daniel-mar 11
#
12
 
13
error_reporting(E_ALL | E_NOTICE | E_STRICT | E_DEPRECATED);
14
 
15
$silent = ($argc >= 2) && ($argv[1] == '--silent');
16
 
17
$files = array();
18
 
19
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(dirname(dirname(__DIR__)))));
20
foreach ($rii as $file) {
21
	$filename = $file->getPathname();
22
	if (strpos($filename, '/.') !== false) continue; # also hide ".dir" and ".file"
23
	if (!file_exists($filename)) continue;
24
	$files[] = $filename;
25
}
26
 
27
$baddest = 0;
28
 
29
foreach ($files as $filename) {
30
	$h = fopen($filename, 'r');
31
	$headline = fgets($h);
32
	fclose($h);
33
 
34
	$scripttype = 'n/a';
35
 
36
	if (preg_match('@#!(.+)\s@U', $headline, $m)) {
37
		$interpreter = $m[1];
38
 
39
		switch ($interpreter) {
40
			case '/usr/bin/php':
41
				$scripttype = 'PHP';
42
				break;
43
			case '/usr/bin/perl':
44
				$scripttype = 'Perl';
45
				break;
46
		}
47
	} else if (strpos($filename, '.php') !== false) {
48
		$scripttype = 'PHP';
49
	} else if ((strpos($filename, '.pl') !== false) || (strpos($filename, '.pm') !== false)) {
50
		$scripttype = 'Perl';
51
	}
52
 
53
	$cmd = '';
54
	switch ($scripttype) {
55
		case 'PHP':
56
			$cmd = 'php -l '.escapeshellarg($filename);
57
			break;
58
		case 'Perl':
59
			$cmd = 'perl -Mstrict -Mdiagnostics -cw '.escapeshellarg($filename);
60
			break;
61
	}
62
 
63
	if ($cmd) {
64
		$out = array();
65
		exec($cmd." 2>&1", $out, $code);
66
 
67
		if ($code > $baddest) $baddest = $code;
68
 
69
		if ($code != 0) {
70
			echo "($code) $filename: ".trim(implode("\n    ", $out))."\n";
71
		} else {
72
			if (!$silent) echo "OK: $filename\n";
73
		}
74
	}
75
}
76
 
77
exit($baddest);