Code

Several winstation fixes from 2.5
[gosa.git] / plugins / admin / systems / class_winGeneric.inc
1 <?php
3 class wingeneric 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();
13   /* Needed values and lists */
14   var $base= "";
15   var $cn= "";
16   var $description= "";
17   var $orig_dn= "";
18   var $shadowLastChange="";
19   var $uidNumber="";
20   var $gidNumber="";
21   var $loginShell="";
22   var $gecos="";
23   var $shadowMin="";
24   var $shadowWarning="";
25   var $shadowInactive="";
26   var $uid="";
27   var $sn="";
28   var $givenName="";
29   var $homeDirectory="";
30   var $sambaSID="";
31   var $sambaPrimaryGroupSID="";
32   var $displayName="";
33   var $sambaPwdMustChange="";
34   var $sambaNTPassword="";
35   var $sambaPwdLastSet="";
36   var $sambaAcctFlags="";
37   var $netConfigDNS;
38   /* attribute list for save action */
39   var $ignore_account= TRUE;
40   var $attributes   = array("cn", "description","shadowLastChange",
41                             "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
42                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
43                             "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
44                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
45   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
48   function wingeneric ($config, $dn= NULL, $parent= NULL)
49   {
50     plugin::plugin ($config, $dn, $parent);
51     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
52     /* Set base */
53     if ($this->dn == "new"){
54       $ui= get_userinfo();
55       $this->base= dn2base($ui->dn);
56       $this->cn= "";
57     } else {
58       $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
59     }
61     /* Save dn for later references */
62     $this->orig_dn= $this->dn;
63   }
66   function set_acl_base($base)
67   {
68     plugin::set_acl_base($base);
69     $this->netConfigDNS->set_acl_base($base);
70   }
72   function set_acl_category($cat)
73   {
74     plugin::set_acl_category($cat);
75     $this->netConfigDNS->set_acl_category($cat);
76   }
79   function execute()
80   {
81         /* Call parent execute */
82         plugin::execute();
84     /* Do we represent a valid phone? */
85     if (!$this->is_account && $this->parent == NULL){
86       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
87         _("This 'dn' has no network features.")."</b>";
88       return($display);
89     }
91     /* Base select dialog */
92     $once = true;
93     foreach($_POST as $name => $value){
94       if(preg_match("/^chooseBase/",$name) && $once){
95         $once = false;
96         $this->dialog = new baseSelectDialog($this->config,$this);
97         $this->dialog->setCurrentBase($this->base);
98       }
99     }
101     /* Dialog handling */
102     if(is_object($this->dialog)){
103       /* Must be called before save_object */
104       $this->dialog->save_object();
106       if($this->dialog->isClosed()){
107         $this->dialog = false;
108       }elseif($this->dialog->isSelected()){
110         /* A new base was selected, check if it is a valid one */
111         $tmp = $this->get_allowed_bases();
112         if(isset($tmp[$this->dialog->isSelected()])){
113           $this->base = $this->dialog->isSelected();
114         }
116         $this->dialog= false;
117       }else{
118         return($this->dialog->execute());
119       }
120     }
122     /* Fill templating stuff */
123     $smarty= get_smarty();
125     // Undefined index in wingeneric.tpl ... 
126     $smarty->assign("bases", $this->config->idepartments);
128     /* Assign attributes */
129     foreach ($this->attributes as $attr){
130       $smarty->assign("$attr", $this->$attr);
131     }
132     
133     $smarty->assign("base_select", $this->base);
135     /* Show main page */
136     $smarty->assign("netconfig", $this->netConfigDNS->execute());
137     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
138   }
140   function remove_from_parent()
141   {
142     $this->netConfigDNS->remove_from_parent();
143     $ldap= $this->config->get_ldap_link();
144     $ldap->rmdir($this->dn);
145     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
146     $this->handle_post_events("remove");
148     /* Delete references to object groups */
149     $ldap->cd ($this->config->current['BASE']);
150     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
151     while ($ldap->fetch()){
152       $og= new ogroup($this->config, $ldap->getDN());
153       unset($og->member[$this->dn]);
154       $og->save ();
155     }
156   }
159   /* Save data to object */
160   function save_object()
161   {
162     /* Create a base backup and reset the
163        base directly after calling plugin::save_object();
164        Base will be set seperatly a few lines below */
165     $base_tmp = $this->base;
166     plugin::save_object();
167     $this->base = $base_tmp;
169     $this->netConfigDNS->save_object();
171     /* Set new base if allowed */
172     $tmp = $this->get_allowed_bases();
173     if(isset($_POST['base'])){
174       if(isset($tmp[$_POST['base']])){
175         $this->base= $_POST['base'];
176       }
177     }
178   }
181   /* Check supplied data */
182   function check()
183   {
184     /* Call common method to give check the hook */
185     $message= plugin::check();
186     $message= array_merge($message, $this->netConfigDNS->check());
187     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
188     
189     /* Set new acl base */
190     if($this->dn == "new") {
191       $this->set_acl_base($this->base);
192     }
194     if(!$this->acl_is_createable() && $this->dn == "new"){
195       $message[]= _("You have no permissions to create a component on this 'Base'.");
196     }
198     if ($this->orig_dn != $this->dn){
199       $ldap= $this->config->get_ldap_link();
200       $ldap->cd ($this->base);
201       $ldap->search ("(cn=".$this->cn.")", array("cn"));
202       if ($ldap->count() != 0){
203         while ($attrs= $ldap->fetch()){
204           if ($attrs['dn'] != $this->orig_dn){
205             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
206             break;
207           }
208         }
209       }
210     }
212     return ($message);
213   }
216   /* Save to LDAP */
217   function save()
218   {
219     plugin::save();
221     /* Remove all empty values */
222     if ($this->orig_dn == 'new'){
223       $attrs= array();
224       foreach ($this->attrs as $key => $val){
225         if (is_array($val) && count($val) == 0){
226           continue;
227         }
228         $attrs[$key]= $val;
229       }
230       $this->attrs= $attrs;
231     }
233     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
234       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
235     }
237     /* Write back to ldap */
238     $ldap= $this->config->get_ldap_link();
239     if ($this->orig_dn == 'new'){
240       $ldap->cd($this->config->current['BASE']);
241       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
242       $ldap->cd($this->dn);
243       $ldap->add($this->attrs);
244       $this->handle_post_events("add");
245     } else {
246       if ($this->orig_dn != $this->dn){
247         $this->move($this->orig_dn, $this->dn);
248       }
250       $ldap->cd($this->dn);
251       $this->cleanup();
252       $ldap->modify ($this->attrs); 
254       $this->handle_post_events("modify");
255     }
257     # FIXME can't save mac address
258     #$this->netConfigDNS->cn = $this->cn;
259     #$this->netConfigDNS->save($this->dn);
260     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
262     /* Optionally execute a command after we're done */
263     $this->postcreate();
264   }
266   /* Return plugin informations for acl handling
267   #FIXME FAIscript seams to ununsed within this class... */
268   function plInfo()
269   {
270     return (array(
271           "plShortName"   => _("Win generic"),
272           "plDescription" => _("Windows workstation generic"),
273           "plSelfModify"  => FALSE,
274           "plDepends"     => array(),
275           "plPriority"    => 0,
276           "plSection"     => array("administration"),
277           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
278                                                           "objectClass"  => "gotoWorkstation")),
279           "plProvidedAcls"=> array(
280             "cn"                  => _("Workstation name"),
281             "description"         => _("Description"))
282           ));
283   }
288 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
289 ?>