Code

Added WS Startup fix.
[gosa.git] / plugins / admin / systems / class_componentGeneric.inc
1 <?php
3 class componentGeneric extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage component base objects";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* Generic terminal attributes */
11   var $interfaces= array();
12   var $ignore_account= TRUE;
14   /* Needed values and lists */
15   var $base= "";
16   var $cn= "";
17   var $description= "";
18   var $orig_dn= "";
20   /* attribute list for save action */
21   var $attributes= array("cn", "description");
22   var $objectclasses= array("top", "device", "ipHost", "ieee802Device");
23   var $netConfigDNS;
25   function componentgeneric ($config, $dn= NULL, $parent= NULL)
26   {
27     plugin::plugin ($config, $dn, $parent);
29     /* Set base */
30     if ($this->dn == "new"){
31       $ui= get_userinfo();
32       $this->base= dn2base($ui->dn);
33       $this->cn= "";
34     } else {
35       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
36     }
37     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses, true);
38     /* Save dn for later references */
39     $this->orig_dn= $this->dn;
40   }
42   function execute()
43   {
44         /* Call parent execute */
45         plugin::execute();
47     /* Do we represent a valid phone? */
48     if (!$this->is_account && $this->parent == NULL){
49       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
50         _("This 'dn' has no network features.")."</b>";
51       return($display);
52     }
54     /* Base select dialog */
55     $once = true;
56     foreach($_POST as $name => $value){
57       if(preg_match("/^chooseBase/",$name) && $once){
58         $once = false;
59         $this->dialog = new baseSelectDialog($this->config,$this);
60         $this->dialog->setCurrentBase($this->base);
61       }
62     }
64     /* Dialog handling */
65     if(is_object($this->dialog)){
66       /* Must be called before save_object */
67       $this->dialog->save_object();
69       if($this->dialog->isClosed()){
70         $this->dialog = false;
71       }elseif($this->dialog->isSelected()){
72         $this->base = $this->dialog->isSelected();
73         $this->dialog= false;
74       }else{
75         return($this->dialog->execute());
76       }
77     }
79     /* Fill templating stuff */
80     $smarty= get_smarty();
81     $smarty->assign("bases", $this->config->idepartments);
83     /* Create base acls */
84     $baseACL = $this->getacl("base");
85     if(!$this->acl_is_moveable()) {
86       $baseACL = preg_replace("/w/","",$baseACL);
87     }
88     $smarty->assign("baseACL",          $baseACL);
90     /* Set acls */
91     $tmp = $this->plInfo();
92     foreach($tmp['plProvidedAcls'] as $name => $translation){
93       $smarty->assign($name."ACL",$this->getacl($name));
94     }
96     $smarty->assign("bases", $this->get_allowed_bases());
99     /* Assign attributes */
100     foreach ($this->attributes as $attr){
101       $smarty->assign("$attr", $this->$attr);
102     }
103     $smarty->assign("base_select", $this->base);
105     /* Show main page */
106     $smarty->assign("netconfig", $this->netConfigDNS->execute());
107     return($smarty->fetch (get_template_path('component.tpl', TRUE)));
108   }
110   function set_acl_base($base)
111   {
112     plugin::set_acl_base($base);
113     $this->netConfigDNS->set_acl_base($base);
114   }
116   function set_acl_category($cat)
117   {
118     plugin::set_acl_category($cat);
119     $this->netConfigDNS->set_acl_category($cat);
120   }
122   function remove_from_parent()
123   {
124     $ldap= $this->config->get_ldap_link();
125     $this->netConfigDNS->remove_from_parent();
126     $ldap->rmdir($this->dn);
127     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system component/generic with dn '%s' failed."),$this->dn));
128     $this->handle_post_events("remove");
130     /* Delete references to object groups */
131     $ldap->cd ($this->config->current['BASE']);
132     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
133     while ($ldap->fetch()){
134       $og= new ogroup($this->config, $ldap->getDN());
135       unset($og->member[$this->dn]);
136       $og->save ();
137     }
138   }
141   /* Save data to object */
142   function save_object()
143   {
144     plugin::save_object();
146     $this->netConfigDNS->save_object();
148     /* Save base, since this is no LDAP attribute */
149     if (isset($_POST['base']) && $this->acl_is_moveable()){
150       $this->base= $_POST['base'];
151     }
152   }
155   /* Check supplied data */
156   function check()
157   {
158     /* Call common method to give check the hook */
159     $message= plugin::check();
160     $message= array_merge($message,$this->netConfigDNS->check());
162     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
164     if ($this->cn == "" ){
165       $message[]= _("The required field 'Component name' is not set.");
166     }
168     /* To check for valid ip*/
169     if($this->netConfigDNS->ipHostNumber == ""){
170        $message[]= _("The required field IP address is empty.");
171     } else {
172       if (!is_ip($this->netConfigDNS->ipHostNumber)){
173         $message[]= _("The field IP address contains an invalid address.");
174       }
175     }
177     $ui= get_userinfo();
178     if ($this->dn == "new" && !$this->acl_is_createable()){
179       $message[]= _("You have no permissions to create a component on this 'Base'.");
180     }
182     if ($this->orig_dn != $this->dn){
183       $ldap= $this->config->get_ldap_link();
184       $ldap->cd ($this->base);
185       $ldap->search ("(cn=".$this->cn.")", array("cn"));
186       if ($ldap->count() != 0){
187         while ($attrs= $ldap->fetch()){
188           if ($attrs['dn'] != $this->orig_dn){
189             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
190             break;
191           }
192         }
193       }
194     }
196     return ($message);
197   }
200   /* Save to LDAP */
201   function save()
202   {
203     plugin::save();
205     /* Remove all empty values */
206     if ($this->orig_dn == 'new'){
207       $attrs= array();
208       foreach ($this->attrs as $key => $val){
209         if (is_array($val) && count($val) == 0){
210           continue;
211         }
212         $attrs[$key]= $val;
213       }
214       $this->attrs= $attrs;
215     }
217     /* If this is a new Object IP & Mac aren't set.
218          IP & Mac are msut attributes, so we set this values by here. */
219     if($this->orig_dn == 'new'){
220       $this->attrs['ipHostNumber'] = $this->netConfigDNS->ipHostNumber;
221       $this->attrs['macAddress']  = $this->netConfigDNS->macAddress;
222     }
224     /* Write back to ldap */
225     $ldap= $this->config->get_ldap_link();
226     if ($this->orig_dn == 'new'){
227       $ldap->cd($this->config->current['BASE']);
228       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
229       $ldap->cd($this->dn);
230       $ldap->add($this->attrs);
231       $this->handle_post_events("add");
232     } else {
233       if ($this->orig_dn != $this->dn){
234         $this->move($this->orig_dn, $this->dn);
235       }
237       $ldap->cd($this->dn);
238       $this->cleanup();
239       $ldap->modify ($this->attrs); 
241       $this->handle_post_events("modify");
242     }
244     $this->netConfigDNS->cn = $this->cn;
245     $this->netConfigDNS->save($this->dn);
247     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system component/generic with dn '%s' failed."),$this->dn));
249     /* Optionally execute a command after we're done */
250     $this->postcreate();
251   }
253   /* Return plugin informations for acl handling */
254   function plInfo()
255   {
256     return (array(
257           "plShortName"   => _("Generic"),
258           "plDescription" => _("Component generic"),
259           "plSelfModify"  => FALSE,
260           "plDepends"     => array(),
261           "plPriority"    => 0,
262           "plSection"     => array("administration"),
263           "plCategory"    => array("component" => array("description"  => _("Network device"),
264                                                         "objectClass"  => array("device", "ipHost", "ieee802Device"))),
265           "plProvidedAcls"=> array(
266             "cn"                  => _("Name"),
267             "base"                => _("Base"),
268             "description"         => _("Description"))
269           ));
270   }
275 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
276 ?>