includes/functions.php
changeset 270 5bcdee999015
parent 256 62ee6685ad18
child 271 f088805540ae
child 272 e0ec986c0af3
equal deleted inserted replaced
269:06db76725891 270:5bcdee999015
  2725   {
  2725   {
  2726     if ( is_string($val) )
  2726     if ( is_string($val) )
  2727     {
  2727     {
  2728       $array[$i] = decode_unicode_url($val);
  2728       $array[$i] = decode_unicode_url($val);
  2729     }
  2729     }
  2730     else
  2730     else if ( is_array($val) )
  2731     {
  2731     {
  2732       $array[$i] = decode_unicode_array($val);
  2732       $array[$i] = decode_unicode_array($val);
  2733     }
  2733     }
  2734   }
  2734   }
  2735   return $array;
  2735   return $array;
  2989           $ips[] = "$oc1.$oc2.$oc3.$oc4";
  2989           $ips[] = "$oc1.$oc2.$oc3.$oc4";
  2990         
  2990         
  2991   return $ips;
  2991   return $ips;
  2992 }
  2992 }
  2993 
  2993 
       
  2994 /**
       
  2995  * Parses a valid IP address range into a regular expression.
       
  2996  * @param string IP range string
       
  2997  * @return string
       
  2998  */
       
  2999 
       
  3000 function parse_ip_range_regex($range)
       
  3001 {
       
  3002   // Regular expression to test the range string for validity
       
  3003   $regex = '/^(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
       
  3004            . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
       
  3005            . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
       
  3006            . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)$/';
       
  3007   if ( !preg_match($regex, $range) )
       
  3008   {
       
  3009     return false;
       
  3010   }
       
  3011   $octets = array(0 => array(), 1 => array(), 2 => array(), 3 => array());
       
  3012   list($octets[0], $octets[1], $octets[2], $octets[3]) = explode('.', $range);
       
  3013   $return = '^';
       
  3014   foreach ( $octets as $octet )
       
  3015   {
       
  3016     // alternatives array
       
  3017     $alts = array();
       
  3018     if ( strpos($octet, '|') )
       
  3019     {
       
  3020       $particles = explode('|', $octet);
       
  3021     }
       
  3022     else
       
  3023     {
       
  3024       $particles = array($octet);
       
  3025     }
       
  3026     foreach ( $particles as $atom )
       
  3027     {
       
  3028       // each $atom will be either
       
  3029       if ( strval(intval($atom)) == $atom )
       
  3030       {
       
  3031         $alts[] = $atom;
       
  3032         continue;
       
  3033       }
       
  3034       else
       
  3035       {
       
  3036         // it's a range - parse it out
       
  3037         $alt2 = int_range($atom);
       
  3038         if ( !$alt2 )
       
  3039           return false;
       
  3040         foreach ( $alt2 as $neutrino )
       
  3041           $alts[] = $neutrino;
       
  3042       }
       
  3043     }
       
  3044     $alts = array_unique($alts);
       
  3045     $alts = '|' . implode('|', $alts) . '|';
       
  3046     // we can further optimize/compress this by weaseling our way into using some character ranges
       
  3047     for ( $i = 1; $i <= 25; $i++ )
       
  3048     {
       
  3049       $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);
       
  3050     }
       
  3051     $alts = str_replace("|1|2|3|4|5|6|7|8|9|", "|[1-9]|", $alts);
       
  3052     $alts = '(' . substr($alts, 1, -1) . ')';
       
  3053     $return .= $alts . '\.';
       
  3054   }
       
  3055   $return = substr($return, 0, -2);
       
  3056   $return .= '$';
       
  3057   return $return;
       
  3058 }
       
  3059 
  2994 function password_score_len($password)
  3060 function password_score_len($password)
  2995 {
  3061 {
  2996   if ( !is_string($password) )
  3062   if ( !is_string($password) )
  2997   {
  3063   {
  2998     return -10;
  3064     return -10;