2997 $ips[] = "$oc1.$oc2.$oc3.$oc4"; |
2997 $ips[] = "$oc1.$oc2.$oc3.$oc4"; |
2998 |
2998 |
2999 return $ips; |
2999 return $ips; |
3000 } |
3000 } |
3001 |
3001 |
|
3002 /** |
|
3003 * Parses a valid IP address range into a regular expression. |
|
3004 * @param string IP range string |
|
3005 * @return string |
|
3006 */ |
|
3007 |
|
3008 function parse_ip_range_regex($range) |
|
3009 { |
|
3010 // Regular expression to test the range string for validity |
|
3011 $regex = '/^(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.' |
|
3012 . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.' |
|
3013 . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.' |
|
3014 . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)$/'; |
|
3015 if ( !preg_match($regex, $range) ) |
|
3016 { |
|
3017 return false; |
|
3018 } |
|
3019 $octets = array(0 => array(), 1 => array(), 2 => array(), 3 => array()); |
|
3020 list($octets[0], $octets[1], $octets[2], $octets[3]) = explode('.', $range); |
|
3021 $return = '^'; |
|
3022 foreach ( $octets as $octet ) |
|
3023 { |
|
3024 // alternatives array |
|
3025 $alts = array(); |
|
3026 if ( strpos($octet, '|') ) |
|
3027 { |
|
3028 $particles = explode('|', $octet); |
|
3029 } |
|
3030 else |
|
3031 { |
|
3032 $particles = array($octet); |
|
3033 } |
|
3034 foreach ( $particles as $atom ) |
|
3035 { |
|
3036 // each $atom will be either |
|
3037 if ( strval(intval($atom)) == $atom ) |
|
3038 { |
|
3039 $alts[] = $atom; |
|
3040 continue; |
|
3041 } |
|
3042 else |
|
3043 { |
|
3044 // it's a range - parse it out |
|
3045 $alt2 = int_range($atom); |
|
3046 if ( !$alt2 ) |
|
3047 return false; |
|
3048 foreach ( $alt2 as $neutrino ) |
|
3049 $alts[] = $neutrino; |
|
3050 } |
|
3051 } |
|
3052 $alts = array_unique($alts); |
|
3053 $alts = '|' . implode('|', $alts) . '|'; |
|
3054 // we can further optimize/compress this by weaseling our way into using some character ranges |
|
3055 for ( $i = 1; $i <= 25; $i++ ) |
|
3056 { |
|
3057 $alts = str_replace("|{$i}0|{$i}1|{$i}2|{$i}3|{$i}4|{$i}5|{$i}6|{$i}7|{$i}8|{$i}9|", "|{$i}[0-9]|", $alts); |
|
3058 } |
|
3059 $alts = str_replace("|1|2|3|4|5|6|7|8|9|", "|[1-9]|", $alts); |
|
3060 $alts = '(' . substr($alts, 1, -1) . ')'; |
|
3061 $return .= $alts . '\.'; |
|
3062 } |
|
3063 $return = substr($return, 0, -2); |
|
3064 $return .= '$'; |
|
3065 return $return; |
|
3066 } |
|
3067 |
3002 function password_score_len($password) |
3068 function password_score_len($password) |
3003 { |
3069 { |
3004 if ( !is_string($password) ) |
3070 if ( !is_string($password) ) |
3005 { |
3071 { |
3006 return -10; |
3072 return -10; |