Code

Updated system tabs
[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)
26   {
27     plugin::plugin ($config, $dn);
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     /* Assign attributes */
84     foreach ($this->attributes as $attr){
85       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
86       $smarty->assign("$attr", $this->$attr);
87     }
88     $smarty->assign("base_select", $this->base);
89     $smarty->assign("baseACL", chkacl($this->acl,"base"));
91     /* Show main page */
92     $smarty->assign("netconfig", $this->netConfigDNS->execute());
93     return($smarty->fetch (get_template_path('component.tpl', TRUE)));
94   }
96   function remove_from_parent()
97   {
98     $ldap= $this->config->get_ldap_link();
99     $this->netConfigDNS->remove_from_parent();
100     $ldap->rmdir($this->dn);
101     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system component/generic with dn '%s' failed."),$this->dn));
102     $this->handle_post_events("remove");
104     /* Delete references to object groups */
105     $ldap->cd ($this->config->current['BASE']);
106     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
107     while ($ldap->fetch()){
108       $og= new ogroup($this->config, $ldap->getDN());
109       unset($og->member[$this->dn]);
110       $og->save ();
111     }
112   }
115   /* Save data to object */
116   function save_object()
117   {
118     plugin::save_object();
120     $this->netConfigDNS->save_object();
122     /* Save base, since this is no LDAP attribute */
123     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
124       $this->base= $_POST['base'];
125     }
126   }
129   /* Check supplied data */
130   function check()
131   {
132     /* Call common method to give check the hook */
133     $message= plugin::check();
134     $message= array_merge($message,$this->netConfigDNS->check());
136     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
138     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
139       $message[]= _("The required field 'Component name' is not set.");
140     }
142     /* To check for valid ip*/
143     if($this->netConfigDNS->ipHostNumber == ""){
144        $message[]= _("The required field IP address is empty.");
145     } else {
146       if (!is_ip($this->netConfigDNS->ipHostNumber)){
147         $message[]= _("The field IP address contains an invalid address.");
148       }
149     }
151     $ui= get_userinfo();
152     $acl= get_permissions ($this->dn, $ui->subtreeACL);
153     $acl= get_module_permission($acl, "component", $this->dn);
154     if (chkacl($acl, "create") != ""){
155       $message[]= _("You have no permissions to create a component on this 'Base'.");
156     }
158     if ($this->orig_dn != $this->dn){
159       $ldap= $this->config->get_ldap_link();
160       $ldap->cd ($this->base);
161       $ldap->search ("(cn=".$this->cn.")", array("cn"));
162       if ($ldap->count() != 0){
163         while ($attrs= $ldap->fetch()){
164           if ($attrs['dn'] != $this->orig_dn){
165             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
166             break;
167           }
168         }
169       }
170     }
172     return ($message);
173   }
176   /* Save to LDAP */
177   function save()
178   {
179     plugin::save();
181     /* Remove all empty values */
182     if ($this->orig_dn == 'new'){
183       $attrs= array();
184       foreach ($this->attrs as $key => $val){
185         if (is_array($val) && count($val) == 0){
186           continue;
187         }
188         $attrs[$key]= $val;
189       }
190       $this->attrs= $attrs;
191     }
193     /* If this is a new Object IP & Mac aren't set.
194          IP & Mac are msut attributes, so we set this values by here. */
195     if($this->orig_dn == 'new'){
196       $this->attrs['ipHostNumber'] = $this->netConfigDNS->ipHostNumber;
197       $this->attrs['macAddress']  = $this->netConfigDNS->macAddress;
198     }
200     /* Write back to ldap */
201     $ldap= $this->config->get_ldap_link();
202     if ($this->orig_dn == 'new'){
203       $ldap->cd($this->config->current['BASE']);
204       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
205       $ldap->cd($this->dn);
206       $ldap->add($this->attrs);
207       $this->handle_post_events("add");
208     } else {
209       if ($this->orig_dn != $this->dn){
210         $this->move($this->orig_dn, $this->dn);
211       }
213       $ldap->cd($this->dn);
214       $this->cleanup();
215       $ldap->modify ($this->attrs); 
217       $this->handle_post_events("modify");
218     }
220     $this->netConfigDNS->cn = $this->cn;
221     $this->netConfigDNS->save($this->dn);
223     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system component/generic with dn '%s' failed."),$this->dn));
225     /* Optionally execute a command after we're done */
226     $this->postcreate();
227   }
229   /* Return plugin informations for acl handling */
230   function plInfo()
231   {
232     return (array(
233           "plShortName"   => _("Generic"),
234           "plDescription" => _("Component generic"),
235           "plSelfModify"  => FALSE,
236           "plDepends"     => array(),
237           "plPriority"    => 0,
238           "plSection"     => array("administration"),
239           "plCategory"    => array("component" => array("description"  => _("Network device"),
240                                                         "objectClass"  => array("device", "ipHost", "ieee802Device"))),
241           "plProvidedAcls"=> array(
242             "cn"                  => _("Name"),
243             "description"         => _("Description"))
244           ));
245   }
250 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
251 ?>