Code

- Added ssh plugin
[gosa.git] / plugins / admin / systems / class_servDHCP.inc
1 <?php
3 class servdhcp extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= TRUE;
7   var $attributes= array();
8   var $objectclasses= array();
10   /* Section storage */
11   var $dhcpSections= array();
12   var $dhcpObjectCache= array();
13   var $current_object= "";
15   function servdhcp ($config, $dn= NULL, $parent= NULL)
16   {
17     plugin::plugin ($config, $dn, $parent);
19     /* Load information about available services */
20     $this->reload(); 
21   }
24   function execute()
25   {
26     /* Call parent execute */
27     plugin::execute();
29     /* Fill templating stuff */
30     $smarty= get_smarty();
31     $display= "";
33     /* Section Creation? */
34     if (isset($_POST['create_section']) && isset($_POST['section'])){
35       $section= $_POST['section'];
36       if (isset(dhcpNewSectionDialog::$sectionMap[$section])){
37         $this->dialog= new $section(NULL);
38       } else {
39         $this->dialog= NULL;
40       }
41     }
43     /* Cancel section creation? */
44     if (isset($_POST['cancel_section'])){
45       $this->dialog= NULL;
46     }
48     /* Remove section? */
49     if (isset($_POST['delete_dhcp_confirm'])){
50       if (chkacl($this->acl, "delete") == ""){
51         unset($this->dhcpSections[$this->current_object]);
52         unset($this->dhcpObjectCache[$this->current_object]);
53         $this->dhcpObjectCache[$this->current_object]= array();
54         foreach ($this->dhcpSections as $key => $value){
55           if (preg_match("/".$this->current_object."$/", $key)){
56             unset($this->dhcpSections[$key]);
57             unset($this->dhcpObjectCache[$key]);
58             $this->dhcpObjectCache[$key]= array();
59           }
60         }
61       } else {
62         print_red(_("You're not allowed to remove DHCP sections!"));
63       }
64       $this->dialog= NULL;
65     }
67     /* Look for post entries */
68     foreach($_POST as $name => $value){
69       
70       /* Insert new section? */
71       if (preg_match('/^insertDhcp_.*_x$/', $name)){
72         $dn= base64_decode(preg_replace('/^insertDhcp_([^_]+)_x$/', '\1', $name));
73         if (isset($this->dhcpObjectCache[$dn])){
74           $this->dialog= new dhcpNewSectionDialog($this->objectType($dn));
75           $this->current_object= $dn;
76           $this->dialog->acl= $this->acl;
77         }
78       }
80       /* Edit section? */
81       if (preg_match('/^editDhcp_.*_x$/', $name)){
82         $dn= base64_decode(preg_replace('/^editDhcp_([^_]+)_x$/', '\1', $name));
83         if (isset($this->dhcpObjectCache[$dn])){
84           $section= $this->objectType($dn);
85           $this->dialog= new $section($this->dhcpObjectCache[$dn]);
86         }
87       }
89       /* Remove section? */
90       if (preg_match('/^delDhcp_.*_x$/', $name)){
91         $dn= base64_decode(preg_replace('/^delDhcp_([^_]+)_x$/', '\1', $name));
92         if (isset($this->dhcpObjectCache[$dn])){
93           $this->current_object= $dn;
94           $this->dialog= 1;
95           $smarty->assign("warning", sprintf(_("You're about to delete the DHCP section '%s'."), $dn));
96           return($smarty->fetch(get_template_path('remove_dhcp.tpl', TRUE)));
97         }
98       }
100     }
102     /* Do we need to flip is_account state? */
103     if (isset($_POST['modify_state'])){
104       $this->is_account= !$this->is_account;
105     }
107     /* Show tab dialog headers */
108     if ($this->is_account){
109       $display= $this->show_header(_("Remove DHCP service"),
110           _("This server has DHCP features enabled. You can disable them by clicking below."));
111     } else {
112       $display= $this->show_header(_("Add DHCP service"),
113           _("This server has DHCP features disabled. You can enable them by clicking below."));
114       return ($display);
115     }
118     /* Show dialog
119      */
120     if($this->dialog != NULL && !is_int($this->dialog)){
121       $this->dialog->save_object();
122       $this->dialog->parent = $this;
123       return($this->dialog->execute());
124     }
126     /* Create Listbox with existing Zones
127      */
128     $DhcpList = new divSelectBox("dhcpSections");
129     $DhcpList->SetHeight(300);
131     /* Add entries to divlist
132      */
133     $editImgIns = "<input type='image' src='images/list_new.png' name='insertDhcp_%s' title='"._("Insert new DHCP section")."'>".
134       "<input type='image' src='images/edit.png' name='editDhcp_%s' title='"._("Edit DHCP section")."'>".
135       "<input type='image' src='images/edittrash.png' name='delDhcp_%s' title='"._("Remove DHCP section")."'>";
136     $editImg = "<input type='image' src='images/edit.png' name='editDhcp_%s' title='"._("Edit DHCP section")."'>".
137       "<input type='image' src='images/edittrash.png' name='delDhcp_%s' title='"._("Remove DHCP section")."'>";
138     foreach($this->dhcpSections as $section => $values ){
139       if (count(dhcpNewSectionDialog::$sectionMap[$this->objectType($section)])){
140         $DhcpList->AddEntry(array(
141               array("string" => $values),
142               array("string" => str_replace("%s",base64_encode($section),$editImgIns), "attach" => "style='text-align:right;'")
143               ));
144       } else {
145         $DhcpList->AddEntry(array(
146               array("string" => $values),
147               array("string" => str_replace("%s",base64_encode($section),$editImg), "attach" => "style='text-align:right;'")
148               ));
149       }
150     }
152     $smarty->assign("dhcpACL",chkacl($this->acl,"servdhcp"));
154     /* Display tempalte */
155     $smarty->assign("DhcpList",$DhcpList->DrawList());
156     $display.= $smarty->fetch(get_template_path('servdhcp.tpl', TRUE));
157     return($display);
158   }
160   function remove_from_parent()
161   {
162     /* This cannot be removed... */
163   }
166   /* Save data to object */
167   function save_object()
168   {
169     plugin::save_object();
170   }
173   /* Check supplied data */
174   function check()
175   {
176     /* Call common method to give check the hook */
177     $message= plugin::check();
178     
179     return ($message);
180   }
183   /* Save to LDAP */
184   function save()
185   {
186     plugin::save();
188     /* Optionally execute a command after we're done */
189     #$this->handle_post_events($mode);
190   }
193   function reload()
194   {
195     /* Init LDAP and load list */
196     $ldap= $this->config->get_ldap_link();
197     $ui= get_userinfo();
198     $me= $this->dn;
200     $list= get_list("(&(objectClass=dhcpService)(|(dhcpPrimaryDN=$me)(dhcpSecondaryDN=$me)(dhcpServerDN=$me)(dhcpFailOverPeerDN=$me)))", $ui->subtreeACL, $this->config->current['BASE'], array("cn"));
201     $final= array();
202     foreach ($list as $value){
204       /* Set header */
205       $sortpart= split(",", $value['dn']);
206       $sortpart= array_reverse($sortpart);
207       $tmp= implode(",", $sortpart);
209       $final[$value['dn']]= $tmp."!"._("Global options");
211       /* Read all sub entries to place here */
212       $ldap->cd($value['dn']);
213       $ldap->search("(|(objectClass=dhcpLog)(objectClass=dhcpClass)(objectClass=dhcpSubClass)(objectClass=dhcpLeases)(objectClass=dhcpHost)(objectClass=dhcpGroup)(objectClass=dhcpPool)(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork)(objectClass=dhcpOptions)(objectClass=dhcpTSigKey)(objectClass=dhcpDnsZone)(objectClass=dhcpFailOverPeer))", array());
215       while ($attrs= $ldap->fetch()){
216         $this->dhcpObjectCache[$ldap->getDN()]= $attrs;
217         $tmp= preg_replace("/".$value['dn']."/", "", $ldap->getDN());
218         $indent= substr_count($tmp, ",");
219         $spaces= "";
220         for ($i= 0; $i<$indent; $i++){
221           $spaces.= "&nbsp;&nbsp;&nbsp;&nbsp;";
222         }
223         $types= array(  "dhcpLog" => _("Logging"),
224             "dhcpService" => _("Global options"),
225             "dhcpClass" => _("Class"),
226             "dhcpSubClass" => _("Subclass"),
227             "dhcpLeases" => _("Lease"),
228             "dhcpHost" => _("Host"),
229             "dhcpGroup" => _("Group"),
230             "dhcpPool" => _("Pool"),
231             "dhcpSubnet" => _("Subnet"),
232             "dhcpFailOverPeer" => _("Failover peer"),
233             "dhcpSharedNetwork" => _("Shared network"));
235         foreach ($types as $key => $val){
236           if (in_array("$key", $attrs['objectClass'])){
237             $type= $val;
238             break;
239           }
240         }
242         /* Prepare for sorting... */
243         $sortpart= split(",", $ldap->getDN());
244         $sortpart= array_reverse($sortpart);
245         $tmp= implode(",", $sortpart);
246         $final[$ldap->getDN()]= $tmp."!".$spaces.$type." '".$attrs['cn'][0]."'";
247       }
248     }
250     /* Sort it... */
251     natsort($final);
252     $this->dhcpSections= array();
253     foreach ($final as $key => $val){
254       $this->dhcpSections[$key]= preg_replace('/^[^!]+!(.*)$/', '\\1', $val);
255     }
257   }
260   function objectType($dn)
261   {
262     $type= "";
263     $types= array("dhcpService", "dhcpClass", "dhcpSubClass", "dhcpHost",
264                   "dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork");
266     foreach ($this->dhcpObjectCache[$dn]['objectClass'] as $oc){
267       if (in_array($oc, $types)){
268         $type= $oc;
269         break;
270       }
271     }
273     /* That should not happen... */
274     if ($type == ""){
275       print_red(_("DHCP configuration set is unknown. Please contact your system administrator."));
276     }
277     
278     return ($type);
279   }
283 //vim:tabstop=2:expandtab:softtab=2:shiftwidth=2:filetype=php:syntax:ruler:
284 ?>