Code

Fixed creation if departments (organizationalUnit)
[gosa.git] / gosa-core / include / class_userinfo.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class userinfo
24 {
25   var $dn;
26   var $ip;
27   var $username;
28   var $cn;
29   var $uid;
30   var $restrictions= array();
31   var $gidNumber= -1;
32   var $language= "";
33   var $config;
34   var $gosaUnitTag= "";
35   var $subtreeACL= array();
36   var $ACL= array();
37   var $ocMapping= array();
38   var $groups= array();
39   var $result_cache =array();
40   var $ignoreACL = FALSE;
41   var $ACLperPath = array();
42   var $ACLperPath_usesFilter = array();
44   /* get acl's an put them into the userinfo object
45      attr subtreeACL (userdn:components, userdn:component1#sub1#sub2,component2,...) */
46   function userinfo(&$config, $userdn){
47     $this->config= &$config;
48     $ldap= $this->config->get_ldap_link();
49     $ldap->cat($userdn,array('sn', 'givenName', 'uid', 'gidNumber', 'preferredLanguage', 'gosaUnitTag', 'gosaLoginRestriction'));
50     $attrs= $ldap->fetch();
52     if (isset($attrs['givenName'][0]) && isset($attrs['sn'][0])){
53       $this->cn= $attrs['givenName'][0]." ".$attrs['sn'][0];
54     } else {
55       $this->cn= $attrs['uid'][0];
56     }
57     if (isset($attrs['gidNumber'][0])){
58       $this->gidNumber= $attrs['gidNumber'][0];
59     }
61     /* Restrictions? */
62     if (isset($attrs['gosaLoginRestriction'])){
63       $this->restrictions= $attrs['gosaLoginRestriction'];
64       unset($this->restrictions['count']);
65     }
67     /* Assign user language */
68     if (isset($attrs['preferredLanguage'][0])){
69       $this->language= $attrs['preferredLanguage'][0];
70     }
72     if (isset($attrs['gosaUnitTag'][0])){
73       $this->gosaUnitTag= $attrs['gosaUnitTag'][0];
74     }
76     $this->dn= $userdn;
77     $this->uid= $attrs['uid'][0];
78     $this->ip= $_SERVER['REMOTE_ADDR'];
80     $this->ignoreACL = ($this->config->get_cfg_value("ignoreAcl") == $this->dn);
82     /* Initialize ACL_CACHE */
83     $this->reset_acl_cache();
84   }
87   public function reset_acl_cache()
88   {
89     /* Initialize ACL_CACHE */
90     session::global_set('ACL_CACHE',array());
91   }
93   function loadACL()
94   {
95     $this->ACL= array();    
96     $this->groups= array();    
97     $this->result_cache =array();
98     $this->reset_acl_cache();
99     $ldap= $this->config->get_ldap_link();
100     $ldap->cd($this->config->current['BASE']);
102     /* Get member groups... */
103     $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array('dn'));
104     while ($attrs= $ldap->fetch()){
105       $this->groups[$attrs['dn']]= $attrs['dn'];
106     }
108     /* Crawl through ACLs and move relevant to the tree */
109     $ldap->search("(objectClass=gosaACL)", array('dn', 'gosaAclEntry'));
110     $aclp= array();
111     $aclc= array();
112     while ($attrs= $ldap->fetch()){
114       /* Insert links in ACL array */
115       $aclp[$attrs['dn']]= substr_count($attrs['dn'], ',');
116       $aclc[$attrs['dn']]= array();
117       $ol= array();
118       for($i= 0; $i<$attrs['gosaAclEntry']['count']; $i++){
119         $ol= array_merge($ol, @acl::explodeAcl($attrs['gosaAclEntry'][$i]));
120       }
121       $aclc[$attrs['dn']]= $ol;
122     }
124     /* Resolve roles here. 
125      */
126     foreach($aclc as $dn => $data){
127       foreach($data as $prio => $aclc_value)  {
128         if($aclc_value['type'] == "role"){
130           unset($aclc[$dn][$prio]);
132           $ldap->cat($aclc_value['acl'],array("gosaAclTemplate"));
133           $attrs = $ldap->fetch();
135           if(isset($attrs['gosaAclTemplate'])){
136             for($i= 0; $i<$attrs['gosaAclTemplate']['count']; $i++){
137               $tmp = @acl::explodeAcl($attrs['gosaAclTemplate'][$i]);  
139               foreach($tmp as $new_acl){
141                 /* Keep non role attributes here! */
142                 $new_acl['filter'] = $aclc_value['filter'];
143                 $new_acl['members'] = $aclc_value['members'];
144                 $aclc[$dn][] =$new_acl;
145               }
146             }      
147           }
148         }
149       }
150     }
152     /* ACL's read, sort for tree depth */
153     asort($aclp);
155     /* Sort in tree order */
156     foreach ($aclp as $dn => $acl){
157       /* Check if we need to keep this ACL */
158       foreach($aclc[$dn] as $idx => $type){
159         $interresting= FALSE;
160         
161         /* No members? This ACL rule is deactivated ... */
162         if (!count($type['members'])){
163           $interresting= FALSE; 
164         } else {
166           /* Inspect members... */
167           foreach ($type['members'] as $grp => $grpdsc){
169             /* Some group inside the members that is relevant for us? */
170             if (in_array_ics(@LDAP::convert(preg_replace('/^G:/', '', $grp)), $this->groups)){
171               $interresting= TRUE;
172             }
174             /* User inside the members? */
175             if (preg_replace('/^U:/', '', $grp) == $this->dn){
176               $interresting= TRUE;
177             }
178           }
179         }
181         if ($interresting){
182           if (!isset($this->ACL[$dn])){
183             $this->ACL[$dn]= array();
184           }
185           $this->ACL[$dn][$idx]= $type;
186         }
187       }
188     }
190     /* Create an array which represenet all relevant permissions settings 
191         per dn.
193       The array will look like this:
194       
195       .     ['ou=base']        ['ou=base']          = array(ACLs);
196       .     
197       .     ['ou=dep1,ou=base']['ou=dep1,ou=base']  = array(ACLs);
198       .                        ['ou=base']          = array(ACLs);
201       For object located in 'ou=dep1,ou=base' we have to both ACLs,
202        for objects in 'ou=base' we only have to apply on ACL.
203      */
204     $without_self_acl = $all_acl = array();
205     foreach($this->ACL as $dn => $acl){
206       $sdn =$dn;
207       $first= TRUE; // Run at least once 
208       while(strpos($dn,",") !== FALSE || $first){
209         $first = FALSE;
210         if(isset($this->ACL[$dn])){
211           $all_acl[$sdn][$dn] = $this->ACL[$dn];
212           $without_self_acl[$sdn][$dn] = $this->ACL[$dn]; 
213           foreach($without_self_acl[$sdn][$dn] as $acl_id => $acl_set){
214   
215             /* Remember which ACL set has speicial user filter 
216              */
217             if(isset($acl_set['filter']{1})){
218               $this->ACLperPath_usesFilter[$sdn] = TRUE;
219             }
220           
221             /* Remove all acl entries which are especially for the current user (self acl)
222              */
223             foreach($acl_set['acl'] as $object => $object_acls){
224               if(isset($object_acls[0]) && strpos($object_acls[0],"s")){
225                 unset($without_self_acl[$sdn][$dn][$acl_id]['acl'][$object]);
226               }
227             }
228           }
229         }
230         $dn = preg_replace("/^[^,]*+,/","",$dn);
231       }
232     } 
233     $this->ACLperPath =$without_self_acl;
235     /* Append Self entry */
236     $dn = $this->dn;
237     while(strpos($dn,",") && !isset($all_acl[$dn])){
238       $dn = preg_replace("/^[^,]*+,/","",$dn);
239     }
240     if(isset($all_acl[$dn])){
241       $this->ACLperPath[$this->dn] = $all_acl[$dn];
242     }
243   }
246   /* Returns an array containing all target objects we've permssions on.
247    */
248   function get_acl_target_objects()
249   {
250     return(array_keys($this->ACLperPath));
251   }
252   
254   function get_category_permissions($dn, $category, $any_acl = FALSE)
255   {
256     return(@$this->get_permissions($dn,$category.'/0',""));
257   }
259   
260   /*! \brief Check if the given object (dn) is copyable
261       @param  String The object dn 
262       @param  String The acl  category (e.g. users) 
263       @param  String The acl  class (e.g. user) 
264       @return Boolean   TRUE if the given object is copyable else FALSE 
265   */
266   function is_copyable($dn, $object, $class)
267   {
268     return(preg_match("/r/",$this->has_complete_category_acls($dn, $object)));
269   }
272   /*! \brief Check if the given object (dn) is cutable
273       @param  String The object dn 
274       @param  String The acl  category (e.g. users) 
275       @param  String The acl  class (e.g. user) 
276       @return Boolean   TRUE if the given object is cutable else FALSE 
277   */
278   function is_cutable($dn, $object, $class)
279   {
280     $remove = preg_match("/d/",$this->get_permissions($dn,$object."/".$class));
281     $read   = preg_match("/r/",$this->has_complete_category_acls($dn, $object));
282     return($remove && $read);
283   }
286   /*! \brief  Checks if we are allowed to paste an object to the given destination ($dn)
287       @param  String The destination dn 
288       @param  String The acl  category (e.g. users) 
289       @param  String The acl  class (e.g. user) 
290       @return Boolean   TRUE if we are allowed to paste an object.
291   */
292   function is_pasteable($dn, $object)
293   {
294     return(preg_match("/w/",$this->has_complete_category_acls($dn, $object)));
295   }
298   /*! \brief  Checks if we are allowed to restore a snapshot for the given dn.
299       @param  String The destination dn 
300       @param  String The acl  category (e.g. users) 
301       @return Boolean   TRUE if we are allowed to restore a snapshot.
302   */
303   function allow_snapshot_restore($dn, $object)
304   {
305     if(!is_array($object)){
306       $object = array($object);
307     }
308     $r = $w = TRUE;
309     foreach($object as $category){
310       $w &= preg_match("/w/",$this->has_complete_category_acls($dn, $category));
311       $r &= preg_match("/r/",$this->has_complete_category_acls($dn, $category));
312     }
313     return($r && $w ); 
314   }  
317   /*! \brief  Checks if we are allowed to create a snapshot of the given dn.
318       @param  String The source dn 
319       @param  String The acl category (e.g. users) 
320       @return Boolean   TRUE if we are allowed to restore a snapshot.
321   */
322   function allow_snapshot_create($dn, $object)
323   {
324     if(!is_array($object)){
325       $object = array($object);
326     }
327     $r = TRUE;
328     foreach($object as $category){
329       $r &= preg_match("/r/",$this->has_complete_category_acls($dn, $category));
330     }
331     return($r) ; 
332   }  
335   function get_permissions($dn, $object, $attribute= "", $skip_write= FALSE)
336   {
337     /* If we are forced to skip ACLs checks for the current user 
338         then return all permissions.
339      */
340     if($this->ignore_acl_for_current_user()){
341       if($skip_write){
342         return("rcdm");
343       }
344       return("rwcdm");
345     }
347     /* Push cache answer? */
348     $ACL_CACHE = &session::global_get('ACL_CACHE');
349     if (isset($ACL_CACHE["$dn+$object+$attribute"])){
350       $ret = $ACL_CACHE["$dn+$object+$attribute"];
351       if($skip_write){
352         $ret = str_replace(array('w','c','d','m'), '',$ret);
353       }
354       return($ret);
355     }
357     /* Detect the set of ACLs we have to check for this object 
358      */
359     $adn = $dn;
360     while(!isset($this->ACLperPath[$adn]) && strpos($adn,",") !== FALSE){
361       $adn = preg_replace("/^[^,]*+,/","",$adn);
362     }
363     if(isset($this->ACLperPath[$adn])){
364       $ACL = $this->ACLperPath[$adn];
365     }else{
366       $ACL_CACHE["$dn+$object+$attribute"] = "";
367       return("");
368     }
369  
370     /* If we do not need to respect any user-filter settings 
371         we can skip the per object ACL checks.
372      */
373     $orig_dn= $dn;
374     if(!isset($this->ACLperPath_usesFilter[$adn])){
375       $dn = $adn;
376       if (isset($ACL_CACHE["$dn+$object+$attribute"])){
377         $ret = $ACL_CACHE["$dn+$object+$attribute"];
378         if(!isset($ACL_CACHE["$orig_dn+$object+$attribute"])){
379           $ACL_CACHE["$orig_dn+$object+$attribute"] = $ACL_CACHE["$dn+$object+$attribute"];
380         }
381         if($skip_write){
382           $ret = str_replace('w','',$ret);
383         }
384         return($ret);
385       }
386     }
387  
388     /* Get ldap object, for later filter checks 
389      */
390     $ldap = $this->config->get_ldap_link();
392     $acl= array("r" => "", "w" => "", "c" => "", "d" => "", "m" => "", "a" => "");
394     /* Build dn array */
395     $path= split(',', $dn);
396     $path= array_reverse($path);
398     /* Walk along the path to evaluate the acl */
399     $cpath= "";
400     foreach ($path as $element){
402       /* Clean potential ACLs for each level */
403                         if(isset($this->config->idepartments[$cpath])){
404         $acl= $this->cleanACL($acl);
405       }
407       if ($cpath == ""){
408         $cpath= $element;
409       } else {
410         $cpath= $element.','.$cpath;
411       }
413       if (isset($ACL[$cpath])){
415         /* Inspect this ACL, place the result into ACL */
416         foreach ($ACL[$cpath] as $subacl){
418           /* Reset? Just clean the ACL and turn over to the next one... */
419           if ($subacl['type'] == 'reset'){
420             $acl= $this->cleanACL($acl, TRUE);
421             continue;
422           }
424           if($subacl['type'] == "role") {
425             echo "role skipped";
426             continue;
427           }
429           /* With user filter */
430           if (isset($subacl['filter']) && !empty($subacl['filter'])){
431             $id = $dn."-".$subacl['filter'];
432             if(!isset($ACL_CACHE['FILTER'][$id])){
433               $ACL_CACHE['FILTER'][$id] = $ldap->object_match_filter($dn,$subacl['filter']);
434             }
435             if(!$ACL_CACHE['FILTER'][$id]){
436               continue;
437             }
438           }
440           /* Self ACLs? 
441            */
442           if($dn != $this->dn && isset($subacl['acl'][$object][0]) && (strpos($subacl['acl'][$object][0],"s") !== FALSE)){
443             continue;
444           }
446           /* If attribute is "", we want to know, if we've *any* permissions here... 
447               Merge global class ACLs [0] with attributes specific ACLs [attribute].
448            */
449           if ($attribute == "" && isset($subacl['acl'][$object])){
450             foreach($subacl['acl'][$object] as $attr => $dummy){
451               $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attr]);
452             }
453             continue;
454           }
456           /* Per attribute ACL? */
457           if (isset($subacl['acl'][$object][$attribute])){
458             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attribute]);
459             continue;
460           }
462           /* Per object ACL? */
463           if (isset($subacl['acl'][$object][0])){
464             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][0]);
465             continue;
466           }
468           /* Global ACL? */
469           if (isset($subacl['acl']['all'][0])){
470             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all'][0]);
471             continue;
472           }
474           /* Category ACLs    (e.g. $object = "user/0")
475            */
476           if(strstr($object,"/0")){
477             $ocs = preg_replace("/\/0$/","",$object);
478             if(isset($this->ocMapping[$ocs])){
480               /* if $attribute is "", then check every single attribute for this object.
481                  if it is 0, then just check the object category ACL.
482                */
483               if($attribute == ""){    
484                 foreach($this->ocMapping[$ocs] as $oc){
485                   if (isset($subacl['acl'][$ocs.'/'.$oc])){
487                     if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
489                     foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
490                       $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
491                     }
492                     continue;
493                   }
494                 }
495               }else{
496                 if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
497                   if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
498                   $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
499                 }
500               }
501             }
502             continue;
503           }
504         }
505       }
506     }
508     /* If the requested ACL is for a container object, then alter 
509         ACLs by applying cleanACL a last time.
510      */
511     if(isset($this->config->idepartments[$dn])){
512       $acl = $this->cleanACL($acl);
513     }
515     /* Assemble string */
516     $ret= "";
517     foreach ($acl as $key => $value){
518       if ($value !== ""){
519         $ret.= $key;
520       }
521     }
523     $ACL_CACHE["$dn+$object+$attribute"]= $ret;
524     $ACL_CACHE["$orig_dn+$object+$attribute"]= $ret;
526     /* Remove write if needed */
527     if ($skip_write){
528       $ret = str_replace(array('w','c','d','m'), '',$ret);
529     }
530     return ($ret);
531   }
534   /* Extract all departments that are accessible (direct or 'on the way' to an
535      accessible department) */
536   function get_module_departments($module, $skip_self_acls = FALSE )
537   {
538     /* If we are forced to skip ACLs checks for the current user 
539         then return all departments as valid.
540      */
541     if($this->ignore_acl_for_current_user()){
542       return(array_keys($this->config->idepartments));
543     }
545     /* Use cached results if possilbe */
546     $ACL_CACHE = &session::global_get('ACL_CACHE');
548     if(!is_array($module)){
549       $module = array($module);
550     }
552     global $plist;
553     $res = array();
554     foreach($module as $mod){
555       if(isset($ACL_CACHE['MODULE_DEPARTMENTS'][$mod])){
556         $res = array_merge($res,$ACL_CACHE['MODULE_DEPARTMENTS'][$mod]);
557         continue;
558       }
560       $deps = array();
562       /* Search for per object ACLs */
563       foreach($this->ACL as $dn => $infos){
564         foreach($infos as $info){
565           $found = FALSE;
566           foreach($info['acl'] as $cat => $data){
568             /* Skip self acls? */
569             if($skip_self_acls && isset($data['0']) && (strpos($data['0'], "s") !== FALSE)) continue;
570             if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
571               $found =TRUE;
572               break;
573             }
574           } 
576           if($found && !isset($this->config->idepartments[$dn])){
577             while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
578               $dn = preg_replace("/^[^,]+,/","",$dn);
579             }
580             if(isset($this->config->idepartments[$dn])){
581               $deps[$dn] = $dn;
582             }
583           }
584         }
585       }
587       /* For all gosaDepartments */
588       foreach ($this->config->departments as $dn){
589         if(isset($deps[$dn])) continue;
590         $acl = "";
591         if(strpos($mod, '/')){
592           $acl.=  $this->get_permissions($dn,$mod);
593         }else{
594           $acl.=  $this->get_category_permissions($dn,$mod,TRUE);
595         }
596         if(!empty($acl)) {
597           $deps[$dn] = $dn;
598         }
599       }
601       $ACL_CACHE['MODULE_DEPARTMENTS'][$mod] = $deps;
602       $res = array_merge($res,$deps);
603     }
605     return (array_values($res));
606   }
609   function mergeACL($acl, $type, $newACL)
610   {
611                 $at= array("psub" => "p", "sub" => "s", "one" => "1");
613     if (strpos($newACL, 'w') !== FALSE && strpos($newACL, 'r') === FALSE){
614       $newACL .= "r";
615     }
617                 /* Ignore invalid characters */
618                 $newACL= preg_replace('/[^rwcdm]/', '', $newACL);
620     foreach(str_split($newACL) as $char){
622       /* Skip "self" ACLs without combination of rwcdm, they have no effect.
623          -self flag without read/write/create/...
624        */
625       if(empty($char)) continue;
627       /* Skip permanent and subtree entries */
628       if (preg_match('/[sp]/', $acl[$char])){
629         continue;
630       }
632                         if ($type == "base" && $acl[$char] != 1) {
633                                 $acl[$char]= 0;
634                         } else {
635         $acl[$char]= $at[$type];
636                         }
637     }
639     return ($acl);
640   }
643   function cleanACL($acl, $reset= FALSE)
644   {
645     foreach ($acl as $key => $value){
647       /* Continue, if value is empty or permanent */
648       if ($value == "" || $value == "p") {
649             continue;
650       }
652       /* Reset removes everything but 'p' */
653       if ($reset && $value != 'p'){
654         $acl[$key]= "";
655         continue;
656       }
658       /* Decrease tree level */
659       if (is_int($value)){
660         if ($value){
661           $acl[$key]--;
662         } else {
663           $acl[$key]= "";
664         }
665       }
666     }
668     return ($acl);
669   }
672   /* #FIXME This could be logical wrong or could be optimized in the future
673      Return combined acls for a given category. 
674      All acls will be combined like boolean AND 
675       As example ('rwcdm' + 'rcd' + 'wrm'= 'r') 
676     
677      Results will be cached in $this->result_cache.
678       $this->result_cache will be resetted if load_acls is called.
679   */
680   function has_complete_category_acls($dn,$category)
681   {
682     $acl    = "rwcdm";
683     $types  = "rwcdm";
685     if(!is_string($category)){
686       trigger_error("category must be string");   
687       $acl = "";
688     }else{
689       if(!isset($this->result_cache['has_complete_category_acls'][$dn][$category]))   {
690         if (isset($this->ocMapping[$category])){
691           foreach($this->ocMapping[$category] as $oc){
693             /* Skip objectClass '0' (e.g. users/0) get_permissions will ever return '' ??  */
694             if($oc == "0") continue;
695             $tmp =  $this->get_permissions($dn, $category."/".$oc);
696             for($i = 0, $l= strlen($types); $i < $l; $i++) {
697               if(!preg_match("/".$types[$i]."/",$tmp)){ 
698                 $acl = preg_replace("/".$types[$i]."/","",$acl);
699               }
700             }
701           }
702         }else{
703           trigger_error("Invalid type of category ".$category);
704           $acl = "";
705         }
706         $this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
707       }else{
708         $acl = $this->result_cache['has_complete_category_acls'][$dn][$category];
709       }
710     }
711     return($acl);
712   }
714  
715   /*! \brief  Returns TRUE if the current user is configured in IGNORE_ACL=".." in your gosa.conf 
716       @param  Return Boolean TRUE if we have to skip ACL checks else FALSE.
717    */ 
718   function ignore_acl_for_current_user()
719   {
720     return($this->ignoreACL);
721   }
724   function loginAllowed()
725   {
726     // Need to check restrictions?
727     if (count($this->restrictions)){
729       // We have restrictions but cannot check them
730       if (!isset($_SERVER['REMOTE_ADDR'])){
731         return false;
732       }
734       // Move to binary...
735       $source= $_SERVER['REMOTE_ADDR'];
736       foreach ($this->restrictions as $restriction) {
738         // Single IP
739         if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $restriction)) {
740            if ($source == $restriction){
741              return true;
742            }
743         }
745         // Match with short netmask
746         if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $restriction, $matches)) {
747           if (isIpInNet($source, $matches[1], long2ip(~(pow(2, (32-$matches[2]))-1)))) {
748             return true;
749           }
750         }
752         // Match with long netmask
753         if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $restriction, $matches)) {
754           if (isIpInNet($source, $matches[1], $matches[2])) {
755             return true;
756           }
757         }
759       }
761       return false;
762     }
764     return true;
765   }
770 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
771 ?>