Code

65f61d7579f57555be5543a86164617f7e4fbadc
[gosa.git] / gosa-plugins / dhcp / admin / systems / services / dhcp / class_servDHCP.inc
1 <?php
3 class servdhcp extends goService
4 {
5     /* attribute list for save action */
6     var $attributes= array("dhcpServiceDN");
7     var $objectclasses= array("dhcpServer");
8     var $conflicts        = array("servdhcp");
9     var $dhcpServiceDN= "";
11     /* Section storage */
12     var $dhcpSections= array();
13     var $dhcpObjectCache= array();
15     var $dhcpDNtoID = array();
17     var $current_object= "";
18     var $types= array();
19     var $serviceDN= "";
21     var $quote_option = array("domain-name");
23     var $orig_dn = "";
25     var $dhcp_server_list   = array("ENTRIES"=> array(),"FOR_LIST"=> array());
26     var $take_over_id       = -1;
27     var $display_warning  = TRUE;
29     function servdhcp (&$config, $dn= NULL, $parent= NULL)
30     {
31         plugin::plugin ($config, $dn, $parent);
33         $this->serviceDN = "cn=dhcp,".$dn;
34         $this->orig_dn = $dn;
36         $this->DisplayName = _("DHCP service");
38         $this->types= array(  "dhcpLog" => _("Logging"),
39                 "dhcpService" => _("Global options"),
40                 "dhcpClass" => _("Class"),
41                 "dhcpSubClass" => _("Subclass"),
42                 "dhcpHost" => _("Host"),
43                 "dhcpGroup" => _("Group"),
44                 "dhcpPool" => _("Pool"),
45                 "dhcpSubnet" => _("Subnet"),
46                 "dhcpFailOverPeer" => _("Fail-over peer"),
47                 "dhcpSharedNetwork" => _("Shared network"),
48                 "dhcpTSigKey" => _("DNS update key"),
49                 "dhcpDnsZone" => _("DNS update zone") );
52         /* Backport: PHP4 compatibility  */
53         foreach($this->types as $type => $translation){
54             $this->types[strtolower($type)] = $translation;
55         }
57         /* Load information about available services */
58         $this->reload(); 
59         if (!count($this->dhcpSections)){
60             $this->is_account= FALSE;
61             $this->dhcp_server_list = $this->get_list_of_dhcp_servers();
62         }
64         // Prepare lists
65         $this->entryList = new sortableListing();
66         $this->entryList->setDeleteable(false);
67         $this->entryList->setEditable(false);
68         $this->entryList->setWidth("100%");
69         $this->entryList->setHeight("400px");
70         $this->entryList->setHeader(array(_("Type"),_("Option"),_("Address")));
71         $this->entryList->setColspecs(array('*','*','*', '80px'));
73     }
76     function execute()
77     {
78         /* Call parent execute */
79         plugin::execute();
81         /* Fill templating stuff */
82         $smarty= get_smarty();
83         $smarty->assign("dns_take_over",FALSE);
84         $display= "";
87         /*****************/
88         /* Handle Take Over Actions 
89         /*****************/
91         /* Give smarty the required informations */
92         $smarty->assign("dhcp_server_list", $this->dhcp_server_list['FOR_LIST']);
93         $smarty->assign("dhcp_server_list_cnt", count($this->dhcp_server_list['FOR_LIST']));
95         /* Take over requested, save id */
96         if(isset($_POST['take_over_src']) && isset($_POST['take_over'])){
97             $id = get_post('take_over_src');
98             if(isset($this->dhcp_server_list['ENTRIES'][$id])){
99                 $this->take_over_id = $id;      
100             }
101         }
103         /* Abort take over action */ 
104         if(isset($_POST['cancel_take_over'])){
105             $this->dialog =false;
106             $this->take_over_id = -1;
107             $this->dhcp_server_list = $this->get_list_of_dhcp_servers();
108         }
110         /* Display informartion about take over that will be started when saving this server 
111          *  and hide default dhcp output
112          */
113         if($this->take_over_id != -1){
115             $this->dialog = FALSE;
116             $id = $this->take_over_id;
117             $smarty->assign("dns_take_over",TRUE);
118             $warning = sprintf(_("You have requested a migration of the DHCP setup from server '%s' to the current one."),
119                     $this->dhcp_server_list['ENTRIES'][$id]['cn'][0]);
120             $warning.= "&nbsp;"._("The migration will be started when you save this system.");
122             if($this->display_warning){
123                 msg_dialog::display(_("Warning"), $warning, WARNING_DIALOG);
124                 $this->display_warning = FALSE;
125             }
126             return($smarty->fetch(get_template_path('servdhcp.tpl', TRUE, dirname(__FILE__))));
127         }
130         /*****************/
131         /* List handling  
132         /*****************/
134         /* Section Creation? */
135         if (isset($_POST['create_section']) && isset($_POST['section'])){
136             $section= get_post('section');
137             $tmp = new dhcpNewSectionDialog(NULL);
138             if (isset($tmp->sectionMap[$section])){
139                 $this->dialog= new $section($this,$this->current_object);
140                 $this->current_object= "";
141             } else {
142                 $this->dialog= FALSE;
143             }
144         }
146         /* Cancel section creation? */
147         if (isset($_POST['cancel_section']) || isset($_POST['cancel_dhcp'])){
148             $this->dialog= FALSE;
149         }
151         /* Save changes */
152         if (isset($_POST['save_dhcp'])){
153             $this->dialog->save_object();
154             $messages= $this->dialog->check();
155             if (count($messages)){
156                 msg_dialog::displayChecks($messages);
157             } else {
158                 $dn= $this->dialog->dn;
159                 $class= get_class($this->dialog);
160                 $type= $this->types[$class];
161                 if(empty($this->serviceDN)){
162                     $indent= substr_count(preg_replace("/".$this->dn."/", '', $dn), ",") -1;
163                 }else{
164                     $indent= substr_count(preg_replace("/".$this->serviceDN."/", '', $dn), ",");
165                 }
166                 $spaces= "";
167                 for ($i= 0; $i<$indent; $i++){
168                     $spaces.= "&nbsp;&nbsp;&nbsp;&nbsp;";
169                 }
170                 $data= $this->dialog->save();
171                 if ($this->current_object == ""){
173                     /* New object */
174                     $newsects= array();
175                     foreach ($this->dhcpSections as $key => $dsc){
176                         $newsects[$key]= $dsc;
177                         if ($key == $dn){
178                             $spaces.= "&nbsp;&nbsp;&nbsp;&nbsp;";
179                             $newsects[$data['dn']]= "$spaces$type '".preg_replace('/^[^=]+=([^,]+),.*$/', '\1', $data['dn'])."'";
180                         }
181                     }
182                     $this->dhcpObjectCache[$data['dn']]= $data;
183                     $this->dhcpSections= $newsects;
184                 } else {
185                     if ($dn != $data['dn']){
186                         /* Old object, new name */
187                         $this->dhcpObjectCache[$dn]= array();
188                         $this->dhcpObjectCache[$data['dn']]= $data;
190                         /* If we renamed a section, we've to rename a couple of objects, too */
191                         foreach ($this->dhcpObjectCache as $key => $dsc){
192                             if (preg_match("/,$dn$/", $key)){
193                                 $new_dn= preg_replace("/,$dn$/", ",".$data['dn'], $key);
194                                 $dsc['MODIFIED']= TRUE;
195                                 $this->dhcpObjectCache[$new_dn]= $dsc;
196                                 unset($this->dhcpObjectCache[$key]);
197                             }
198                         }
199                         $newsects= array();
200                         foreach ($this->dhcpSections as $key => $dsc){
201                             if ($key == $dn){
202                                 $newsects[$data['dn']]= "$spaces$type '".preg_replace('/^[^=]+=([^,]+),.*$/', '\1', $data['dn'])."'";
203                                 continue;
204                             }
205                             if (preg_match("/,$dn$/", $key)){
206                                 $new_dn= preg_replace("/,$dn$/", ",".$data['dn'], $key);
207                                 $newsects[$new_dn]= $dsc;
208                             } else {
209                                 $newsects[$key]= $dsc;
210                             }
211                         }
212                         $this->dhcpSections= $newsects;
214                     } else {
215                         /* Old object, old name */
216                         $this->dhcpObjectCache[$data['dn']]= $data;
217                     }
218                 }
219                 $this->dialog= FALSE;
220             }
221         }
223         /* Remove section? */
224         if (isset($_POST['delete_dhcp_confirm'])){
225             if ($this->acl_is_removeable()){
226                 unset($this->dhcpSections[$this->current_object]);
227                 unset($this->dhcpObjectCache[$this->current_object]);
228                 $this->dhcpObjectCache[$this->current_object]= array();
229                 foreach ($this->dhcpSections as $key => $value){
230                     if (preg_match("/".$this->current_object."$/", $key)){
231                         unset($this->dhcpSections[$key]);
232                         unset($this->dhcpObjectCache[$key]);
233                         $this->dhcpObjectCache[$key]= array();
234                     }
235                 }
236             } else {
237                 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
238             }
239             $this->dialog= FALSE;
240         }
242         /* Look for post entries */
243         foreach($_POST as $name => $value){
245             /* Insert new section? */
246             if (preg_match('/^insertDhcp_.*/', $name)){
247                 $id= preg_replace('/^insertDhcp_(.*)$/', '\1', $name);
248                 $dn = $this->dhcpDNtoID[$id];
249                 if (isset($this->dhcpObjectCache[$dn])){
250                     $this->dialog= new dhcpNewSectionDialog($this->objectType($dn));
251                     $this->current_object= $dn;
252                     $this->dialog->acl= $this->acl;
253                 }
254             }
256             /* Edit section? */
257             if (preg_match('/^editDhcp_.*$/', $name)){
258                 $id= preg_replace('/^editDhcp_(.*)$/', '\1', $name);
259                 $dn = $this->dhcpDNtoID[$id];
260                 if (isset($this->dhcpObjectCache[$dn])){
261                     $section= $this->objectType($dn);
262                     $this->current_object= $dn;
263                     $this->dialog= new $section($this,$this->dhcpObjectCache[$dn]);
264                 }
265             }
267             /* Remove section? */
268             if (preg_match('/^delDhcp_.*$/', $name)){
269                 $id= preg_replace('/^delDhcp_(.*)$/', '\1', $name);
270                 $dn = $this->dhcpDNtoID[$id];
271                 if (isset($this->dhcpObjectCache[$dn])){
272                     $this->current_object= $dn;
273                     $this->dialog= 1;
274                     $smarty->assign("warning", msgPool::deleteInfo(LDAP::fix($dn),_("DHCP section")));
275                     return($smarty->fetch(get_template_path('remove_dhcp.tpl', TRUE, dirname(__FILE__))));
276                 }
277             }
279         }
281         if(isset($_GET['act']) && $_GET['act']=="edit" && isset($_GET['id'])){
282             $id = $_GET['id'];      
283             $dn = $this->dhcpDNtoID[$id];
284             if (isset($this->dhcpObjectCache[$dn])){
285                 $section= $this->objectType($dn);
286                 $this->current_object= $dn;
287                 $this->dialog= new $section($this,$this->dhcpObjectCache[$dn]);
288             }
289         }
292         if(isset($_GET['act']) && $_GET['act']=="edit" && isset($_GET['id'])){
293             $id = $_GET['id'];
294             $dn = $this->dhcpDNtoID[$id];
295             if (isset($this->dhcpObjectCache[$dn])){
296                 $section= $this->objectType($dn);
297                 $this->current_object= $dn;
298                 $this->dialog= new $section($this,$this->dhcpObjectCache[$dn]);
299             }
300         }
303         /* Do we need to flip is_account state? */
304         if (isset($_POST['modify_state'])){
305             $this->is_account= !$this->is_account;
306         }
308         /* Show tab dialog headers */
309         if ($this->is_account){
310             if (!count($this->dhcpObjectCache)){
311                 $attrs= array();
312                 $attrs['dn']= 'cn=dhcp,'.$this->dn;
313                 $attrs['cn']= array('dhcp');
314                 $attrs['objectClass']= array('top', 'dhcpService');
315                 $attrs['dhcpPrimaryDN']= array($this->dn);
316                 $attrs['dhcpStatements']= array("default-lease-time 600",
317                         "max-lease-time 1200",
318                         "authoritative",
319                         "ddns-update-style none");
320                 $attrs['MODIFIED']= TRUE;
321                 $this->dhcpSections['cn=dhcp,'.$this->dn]= _("Global options");
322                 $this->dhcpObjectCache['cn=dhcp,'.$this->dn]= $attrs;
323             }
325         } else {
326             return ($display);
327         }
330         /* Show dialog
331          */
332         if(isset($this->dialog) && is_object($this->dialog)){
333             $this->dialog->save_object();
334             $this->dialog->parent = $this;
335             return($this->dialog->execute());
336         }
338         $editImgIns = image('images/lists/element.png[new]', 'insertDhcp_%s', _("Insert new DHCP section"));
339         $editImgIns.= image('images/lists/edit.png', 'editDhcp_%s', _("Edit DHCP section"));
340         $editImgIns.= image('images/lists/trash.png', 'delDhcp_%s', _("Remove DHCP section"));
342         $editImgInsNoDel = image('images/lists/element.png[new]', 'insertDhcp_%s', _("Insert new DHCP section"));
343         $editImgInsNoDel.= image('images/lists/edit.png', 'editDhcp_%s', _("Edit DHCP section"));
345         $editImg = image('images/lists/edit.png', 'editDhcp_%s', _("Edit DHCP section"));
346         $editImg.= image('images/lists/trash.png', 'delDhcp_%s', _("Remove DHCP section"));
348         $this->entryList->setAcl('rwcdm');
349         $lData = $data = array();
350         $tmp = new dhcpNewSectionDialog(NULL);
351         foreach($this->dhcpSections as $section => $values ){
353             // Ensure that we've a valid id for this section.
354             if(!in_array($section,$this->dhcpDNtoID)){
355                 $this->dhcpDNtoID[] = $section;
356             }
358             // Get entry ID  
359             $id = array_search($section,$this->dhcpDNtoID);
360             $data[$id] = $values;
362             $values = "<a href='?plug=".$_GET['plug']."&amp;act=edit&amp;id=".$id."'>".$values."</a>";
364             $objtype = $this->objectType($section);
365             $dhcpObject = new $objtype($this,$this->dhcpObjectCache[$section]);
366             if (count($tmp->sectionMap[$objtype])){
367                 if ($objtype == "dhcpService"){
368                     $lData[$id] = array('data' => array($values,'','',str_replace("%s",$id,$editImgInsNoDel)));
369                 } else {
370                     $lData[$id] = array('data' => array($values,$dhcpObject->options->get('routers'),'',str_replace("%s",$id,$editImgIns)));
371                 }
372             } else {
373                 $lData[$id] = array('data' => array($values,
374                             $dhcpObject->statements->get('fixed-address'),
375                             preg_replace('/^[^ ]+ /', '', isset($dhcpObject->dhcpHWAddress)?$dhcpObject->dhcpHWAddress:""),
376                             str_replace("%s",$id,$editImg)));
377             }
378         }
379         $this->entryList->setListData($this->dhcpSections, $lData);
380         $this->entryList->update();
382         /* Display tempalte */
383         $smarty->assign("DhcpList",$this->entryList->render());
384         $display.= $smarty->fetch(get_template_path('servdhcp.tpl', TRUE, dirname(__FILE__)));
385         return($display);
386     }
389     function remove_from_parent()
390     {
391         /* Cancel if there's nothing to do here */
392         if (!$this->initially_was_account){
393             return;
394         }
396         /* Remove subtrees */
397         $ldap= $this->config->get_ldap_link();
398         foreach ($this->dhcpObjectCache as $dn => $content){
399             if ($this->objectType($dn) == 'dhcpService'){
400                 $ldap->rmdir_recursive($dn);
401                 if (!$ldap->success()){
402                     msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
403                 }
404             }
405         }
407         /* Remove from self */
408         $ldap= $this->config->get_ldap_link();
410         /* Remove and write to LDAP */
411         plugin::remove_from_parent();
413         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->attributes, "Save");
414         $ldap->cd($this->dn);
415         $this->cleanup();
416         $ldap->modify ($this->attrs);
418         if (!$ldap->success()){
419             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
420         }
422         /* Optionally execute a command after we're done */
423         $this->handle_post_events("remove");
424     }
427     /* Save data to object */
428     function save_object()
429     {
430         plugin::save_object();
431     }
434     /* Check supplied data */
435     function check()
436     {
437         /* Call common method to give check the hook */
438         $message= plugin::check();
440         return ($message);
441     }
444     /* Save to LDAP */
445     function save()
446     {
447         /* Take over handling 
448          * - Load servdhcp class and dhcpObjectCache for the source dhcp setup.
449          * - Assign dhcpObjectCache to this configuration. 
450          * - Save this setup and remove source setup from ldap.
451          */
452         if($this->take_over_id != -1){
453             $id = $this->take_over_id;
454             $src = preg_replace("/cn=dhcp,/","",$this->dhcp_server_list['ENTRIES'][$id]['dn']);
455             $tmp = new servdhcp ($this->config, $src);
456             $this->orig_dn = $src;
457             $this->dhcpObjectCache =  $tmp->dhcpObjectCache;
458         }
460         /* Save dhcp setttings */
461         $ldap= $this->config->get_ldap_link();
462         foreach ($this->dhcpObjectCache as $dn => $data){
464             if($this->dn != $this->orig_dn){
465                 $dn = preg_replace("/".preg_quote($this->orig_dn, '/')."$/i",$this->dn,$dn);
466             }
468             /* Remove entry? */
469             if (count($data) == 0){
470                 /* Check if exists, then remove... */
471                 if($ldap->cat($dn)){
472                     $ldap->rmdir_recursive($dn);
473                     if (!$ldap->success()){
474                         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
475                     }
476                 }
477                 continue;
478             }
480             /* Update dhcp option 'server-name' to actual server name */
481             if($this->dn != $this->orig_dn){
482                 $fixed = FALSE;
483                 foreach(array("dhcpHost","dhcpSubnet","dhcpGroup","dhcpSharedNetwork") as $object){
484                     if(in_array($object,$data['objectClass']) && isset($data['dhcpOption'])){
485                         foreach($data['dhcpOption'] as $key => $option){
486                             if(preg_match("/^server-name /",$option)){
487                                 $data['dhcpOption'][$key] = "server-name ".$this->cn;
488                                 $data['MODIFIED'] = TRUE; 
489                                 break;
490                             }
491                         }
492                     }
494                     /* Skip next loops if entry is updated */
495                     if($fixed){
496                         break;
497                     }
498                 }
499             }
501             /* Modify existing entry? */
502             if (isset($data['MODIFIED']) || $this->orig_dn != $this->dn){
504                 if($ldap->cat($dn)){
505                     $modify= TRUE;
506                 } else {
507                     $modify= FALSE;
508                 }
510                 /* Build new entry */
511                 $attrs= array();
512                 foreach ($data as $attribute => $values){
513                     if ($attribute == "MODIFIED" || $attribute == "dn"){
514                         continue;
515                     }
517                     if(in_array($attribute,array("dhcpPrimaryDN","dhcpSecondaryDN","dhcpServerDN","dhcpFailOverPeerDN"))){
518                         foreach($values as $v_key => $value){
519                             $values[$v_key] = preg_replace("/".preg_quote($this->orig_dn, '/')."$/i",$this->dn,$value);
520                         }
521                     }
523                     if (count($values)){
525                         if($attribute == "dhcpOption"){
526                             foreach($values as $key => $value){
527                                 $option_name = trim(preg_replace("/[^ ]*$/","",$value));
528                                 $option_value= trim(preg_replace("/^[^ ]*/","",$value));
529                                 if(in_array($option_name,$this->quote_option)){
530                                     $values[$key] = $option_name." \"".$option_value."\"";
531                                 }
532                             }
533                         }
534                         if (count($values) == 1){
535                             $attrs[$attribute]= $values[0];
536                         } else {
537                             $attrs[$attribute]= $values;
538                         }
539                     } else {
540                         if ($modify){
541                             $attrs[$attribute]= array();
542                         }
543                     }
544                 }
546                 $ldap->cd($dn);
547                 if ($modify){
548                     $ldap->modify($attrs);
549                     if (!$ldap->success()){
550                         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
551                     }
553                     /* Optionally execute a command after we're done */
554                     $this->handle_post_events("modify");
555                 } else {
556                     $ldap->add($attrs);
557                     if (!$ldap->success()){
558                         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_ADD, get_class()));
559                     }
561                     /* Optionally execute a command after we're done */
562                     $this->handle_post_events("add");
563                 }
564             }
565         }
567         $this->dhcpServiceDN= $this->serviceDN;
568         if($this->dn != $this->orig_dn){
569             $this->dhcpServiceDN= preg_replace("/".preg_quote($this->orig_dn, '/')."$/i",$this->dn,$this->dhcpServiceDN);
570         }
572         /* Replace 'new' dn */ 
573         if(preg_match("/new$/",$this->dhcpServiceDN)){
574             $this->dhcpServiceDN = preg_replace("/new$/",$this->dn,$this->dhcpServiceDN);
575         }
577         plugin::save();
579         /* Save data to LDAP */
580         $ldap->cd($this->dn);
581         $this->cleanup();
582         $ldap->modify ($this->attrs);
584         if (!$ldap->success()){
585             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
586         }
588         /* Optionally execute a command after we're done */
589         if ($this->initially_was_account == $this->is_account){
590             if ($this->is_modified){
591                 $this->handle_post_events("modify");
592             }
593         } else {
594             $this->handle_post_events("add");
595         }
597         /* Take over handling
598          * - Remove old dhcp config from source server 
599          */
600         if($this->take_over_id != -1){
601             $id = $this->take_over_id;
602             $src = $this->dhcp_server_list['ENTRIES'][$id]['dn'];
603             $tmp = new servdhcp ($this->config, $src);
604             $tmp->remove_from_parent();
605         }
606     }
609     function reload()
610     {
611         /* Init LDAP and load list */
612         $ldap= $this->config->get_ldap_link();
613         $ui= get_userinfo();
614         $me= $this->dn;
616         $filter = "(&(objectClass=dhcpService)(|(dhcpPrimaryDN=$me)(dhcpSecondaryDN=$me)(dhcpServerDN=$me)(dhcpFailOverPeerDN=$me)))";
618         $list= get_list($filter, array("server"), $this->config->current['BASE'], array("cn"),GL_SIZELIMIT | GL_SUBSEARCH);
619         $final= array();
621         foreach ($list as $value){
623             /* Set header */
624             $sortpart= explode(",", $value['dn']);
625             $sortpart= array_reverse($sortpart);
626             $tmp= implode(",", $sortpart);
628             $final[$value['dn']]= $tmp."!"._("Global options");
630             /* Read all sub entries to place here */
631             $ldap->cd($value['dn']);
632             $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpLog)(objectClass=dhcpClass)(objectClass=dhcpSubClass)(objectClass=dhcpHost)(objectClass=dhcpGroup)(objectClass=dhcpPool)(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork)(objectClass=dhcpOptions)(objectClass=dhcpTSigKey)(objectClass=dhcpDnsZone)(objectClass=dhcpFailOverPeer))", array());
633             $this->serviceDN= $value['dn'];
635             while ($attrs= $ldap->fetch()){
636                 $sattrs= array();
637                 for ($i= 0; $i<$attrs['count']; $i++){
638                     $sattrs[$attrs[$i]]= $attrs[$attrs[$i]];
639                     unset($sattrs[$attrs[$i]]['count']);
640                 }
641                 $sattrs['dn']= $ldap->getDN();
643                 foreach($sattrs as $name => $values){
644                     if($name == "dhcpOption"){
645                         foreach($values as $key => $value){
646                             $value_name = trim(preg_replace("/[^ ]*$/","",$value));
647                             $value_value= trim(preg_replace("/^[^ ]*/","",$value));
648                             if(in_array($value_name,$this->quote_option)){
649                                 $value_value = preg_replace("/^\"/","",$value_value);
650                                 $value_value = preg_replace("/\"$/","",$value_value);
651                                 $sattrs[$name][$key] = $value_name." ".$value_value;
652                             }
653                         }
654                     }
655                 }
657                 $this->dhcpObjectCache[$ldap->getDN()]= $sattrs;
658                 $tmp= preg_replace("/".$this->serviceDN."/", "", $ldap->getDN());
659                 $indent= substr_count($tmp, ",");
660                 $spaces= "";
661                 for ($i= 0; $i<$indent; $i++){
662                     $spaces.= "&nbsp;&nbsp;&nbsp;&nbsp;";
663                 }
665                 foreach ($this->types as $key => $val){
666                     if (in_array("$key", $attrs['objectClass'])){
667                         $type= $val;
668                         break;
669                     }
670                 }
672                 /* Prepare for sorting... */
673                 $sortpart= explode(",", $ldap->getDN());
674                 $sortpart= array_reverse($sortpart);
675                 $tmp= implode(",", $sortpart);
676                 $final[$ldap->getDN()]= $tmp."!".$spaces.$type." '".$attrs['cn'][0]."'";
677             }
678         }
680         /* Sort it... */
681         natsort($final);
682         $this->dhcpSections= array();
683         foreach ($final as $key => $val){
684             $this->dhcpSections[$key]= preg_replace('/^[^!]+!(.*)$/', '\\1', $val);
685         }
687         $this->dhcpDNtoID = array();
688         $this->dhcpDNtoID = array_merge(array_keys($this->dhcpSections),array_keys($this->dhcpObjectCache));
689         $this->dhcpDNtoID = array_unique($this->dhcpDNtoID);
690     }
693     function objectType($dn)
694     {
695         $type= "";
696         $types= array("dhcpService", "dhcpClass", "dhcpSubClass", "dhcpHost",
697                 "dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork",
698                 "dhcpTSigKey", "dhcpDnsZone");
700         foreach ($this->dhcpObjectCache[$dn]['objectClass'] as $oc){
701             if (in_array($oc, $types)){
702                 $type= $oc;
703                 break;
704             }
705         }
707         /* That should not happen... */
708         if ($type == ""){
709             msg_dialog::display(_("Error"), _("The DHCP configuration set is unknown. Please contact your system administrator."), ERROR_DIALOG);
710         }
712         return ($type);
713     }
716     /* Return plugin informations for acl handling */
717     static function plInfo()
718     {
719         return (array(
720                     "plShortName"   => _("DHCP service"),
721                     "plDescription" => _("DHCP service")." ("._("Services").")",
722                     "plSelfModify"  => FALSE,
723                     "plDepends"     => array(),
724                     "plPriority"    => 84,
725                     "plSection"     => array("administration"),
726                     "plCategory"    => array("server"),
728                     "plProvidedAcls"=> array(
729                         "dhcpServiceDN" => _("DHCP entries"),  // Remove this to hide the start button at all.
730                         "start"         => _("Start service"),  // Remove this to hide the start button at all.
731                         "stop"          => _("Stop service"),   // Remove this to hide the stop button at all.
732                         "restart"       => _("Restart service"))// Remove this to hide the restart button at all.
733                     ));
734     }
737     function take_over_service()
738     {
740     }
743     function get_list_of_dhcp_servers()
744     {
745         $ret = array("ENTRIES"=> array(),"FOR_LIST"=> array());
746         $ldap = $this->config->get_ldap_link();
747         $ldap->cd($this->config->current['BASE']);
748         $ldap->search("(&(objectClass=goServer)(dhcpServiceDN=*))",array("dn","cn","dhcpServiceDN"));
749         while($attrs = $ldap->fetch()){
751             /* Skip own config */
752             if($this->dn != "new" && preg_match("/".preg_quote($this->dn, '/')."$/",$attrs['dn'])){
753                 continue;
754             }
756             $ret['ENTRIES'][] = $attrs;
757         }
758         foreach($ret['ENTRIES'] as $key => $data){
759             $ret['FOR_LIST'][$key] = $data['cn'][0];
760         }
761         return($ret);
762     }
765     function getListEntry()
766     {
767         $fields               = goService::getListEntry();
768         $fields['Message']    = _("DHCP service");
769 #$fields['AllowEdit']  = true;
770         return($fields);
771     }
775 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
776 ?>