Revision 87f0be87
Added by Chris Buechler over 16 years ago
etc/inc/util.inc | ||
---|---|---|
27 | 27 |
POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
*/ |
29 | 29 |
|
30 |
require_once 'IPv6.inc'; |
|
31 |
|
|
32 | 30 |
/* kill a process by pid file */ |
33 | 31 |
function killbypid($pidfile) { |
34 | 32 |
sigkillbypid($pidfile, "TERM"); |
... | ... | |
122 | 120 |
return false; |
123 | 121 |
} |
124 | 122 |
|
125 |
/* returns true if $ipaddr is a valid IPv4/IPv6 address or an alias thereof */
|
|
123 |
/* returns true if $ipaddr is a valid dotted IPv4 address or an alias thereof */
|
|
126 | 124 |
function is_ipaddroralias($ipaddr) { |
125 |
|
|
127 | 126 |
global $aliastable, $config; |
128 | 127 |
|
129 | 128 |
if(is_array($config['aliases']['alias'])) { |
... | ... | |
133 | 132 |
} |
134 | 133 |
} |
135 | 134 |
|
136 |
if (isset($aliastable[$ipaddr]) && (is_ipaddr($aliastable[$ipaddr]) || Net_IPv6::checkIPv6($aliastable[$ipaddr]))) {
|
|
135 |
if (isset($aliastable[$ipaddr]) && is_ipaddr($aliastable[$ipaddr]))
|
|
137 | 136 |
return true; |
138 |
} else {
|
|
139 |
return (is_ipaddr($ipaddr) || Net_IPv6::checkIPv6($ipaddr));
|
|
140 |
} |
|
137 |
else
|
|
138 |
return is_ipaddr($ipaddr);
|
|
139 |
|
|
141 | 140 |
} |
142 | 141 |
|
143 | 142 |
/* returns true if $ipaddr is a valid dotted IPv4 address or any alias */ |
144 | 143 |
function is_ipaddroranyalias($ipaddr) { |
144 |
|
|
145 | 145 |
global $aliastable; |
146 | 146 |
|
147 |
if (isset($aliastable[$ipaddr])) {
|
|
147 |
if (isset($aliastable[$ipaddr])) |
|
148 | 148 |
return true; |
149 |
} else { |
|
150 |
return (is_ipaddr($ipaddr) || Net_IPv6::checkIPv6($ipaddr)); |
|
151 |
} |
|
149 |
else |
|
150 |
return is_ipaddr($ipaddr); |
|
152 | 151 |
} |
153 | 152 |
|
154 | 153 |
/* returns true if $subnet is a valid subnet in CIDR format */ |
... | ... | |
167 | 166 |
return true; |
168 | 167 |
} |
169 | 168 |
|
170 |
/* returns true if $subnet is a valid IPv6 network address */ |
|
171 |
function is_subnet_ipv6($subnet, $max = 64) { |
|
172 |
if (!is_string($subnet)) { |
|
173 |
return false; |
|
174 |
} |
|
175 |
|
|
176 |
list ($hp, $np) = explode('/', $subnet); |
|
177 |
|
|
178 |
if (!Net_IPv6::checkIPv6($hp)) { |
|
179 |
return false; |
|
180 |
} |
|
181 |
|
|
182 |
if (!is_numeric($np) || ($np < 1) || ($np > $max)) { |
|
183 |
return false; |
|
184 |
} |
|
185 |
|
|
186 |
return true; |
|
187 |
} |
|
188 |
|
|
189 |
|
|
190 | 169 |
/* returns true if $subnet is a valid subnet in CIDR format or an alias thereof */ |
191 | 170 |
function is_subnetoralias($subnet) { |
192 | 171 |
|
... | ... | |
524 | 503 |
|
525 | 504 |
/* expand a host or network alias, if necessary */ |
526 | 505 |
function alias_expand($name) { |
506 |
|
|
527 | 507 |
global $aliastable; |
528 | 508 |
|
529 |
if (isset($aliastable[$name])) {
|
|
509 |
if (isset($aliastable[$name])) |
|
530 | 510 |
return "\${$name}"; |
531 |
} else if (is_ipaddr($name) || is_subnet($name) || Net_IPv6::checkIPv6($name) || is_subnet_ipv6($name)) {
|
|
511 |
else if (is_ipaddr($name) || is_subnet($name))
|
|
532 | 512 |
return "{$name}"; |
533 |
} else {
|
|
513 |
else
|
|
534 | 514 |
return null; |
535 |
} |
|
536 | 515 |
} |
537 | 516 |
|
538 | 517 |
/* expand a host alias, if necessary */ |
... | ... | |
542 | 521 |
if (isset($aliastable[$name])) { |
543 | 522 |
$ip_arr = explode(" ", $aliastable[$name]); |
544 | 523 |
foreach($ip_arr as $ip) { |
545 |
if (!is_ipaddr($ip) || Net_IPv6::checkIPv6($ip)) {
|
|
524 |
if (!is_ipaddr($ip))
|
|
546 | 525 |
return null; |
547 |
} |
|
548 | 526 |
} |
549 | 527 |
return $aliastable[$name]; |
550 |
} else if (is_ipaddr($name) || Net_IPv6::checkIPv6($name)) {
|
|
528 |
} else if (is_ipaddr($name))
|
|
551 | 529 |
return $name; |
552 |
} else {
|
|
530 |
else
|
|
553 | 531 |
return null; |
554 |
} |
|
555 | 532 |
} |
556 | 533 |
|
557 | 534 |
/* expand a network alias, if necessary */ |
... | ... | |
635 | 612 |
|
636 | 613 |
/* return a fieldname that is safe for xml usage */ |
637 | 614 |
function xml_safe_fieldname($fieldname) { |
638 |
$replace = array('/', ' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', |
|
639 |
'+', '=', '{', '}', '[', ']', '|', '/', '<', '>', '?', |
|
615 |
$replace = array('/', '-', ' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
|
|
616 |
'_', '+', '=', '{', '}', '[', ']', '|', '/', '<', '>', '?',
|
|
640 | 617 |
':', ',', '.', '\'', '\\' |
641 | 618 |
); |
642 | 619 |
return strtolower(str_replace($replace, "", $fieldname)); |
... | ... | |
670 | 647 |
|
671 | 648 |
function resolve_retry($hostname, $retries = 5) { |
672 | 649 |
|
673 |
if (is_ipaddr($hostname) || Net_IPv6::checkIPv6($hostname)) {
|
|
650 |
if (is_ipaddr($hostname))
|
|
674 | 651 |
return $hostname; |
675 |
} |
|
676 | 652 |
|
677 | 653 |
for ($i = 0; $i < $retries; $i++) { |
678 | 654 |
$ip = gethostbyname($hostname); |
Also available in: Unified diff
Revert "Merge IPv6 changes"
This reverts commit f193cf92b2c925a2f3f71a713d766efd1e4d81e0.