Code

db058f5810d43d95df54a6be18a7458893e90c1e
[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 ("/^[^,]+,[^,]+,[^,]+,/", "", $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()){
109         $this->base = $this->dialog->isSelected();
110         $this->dialog= false;
111       }else{
112         return($this->dialog->execute());
113       }
114     }
116     /* Fill templating stuff */
117     $smarty= get_smarty();
119     // Undefined index in wingeneric.tpl ... 
120     $smarty->assign("bases", $this->config->idepartments);
122     /* Assign attributes */
123     foreach ($this->attributes as $attr){
124       $smarty->assign("$attr", $this->$attr);
125     }
126     
127     $smarty->assign("base_select", $this->base);
129     /* Show main page */
130     $smarty->assign("netconfig", $this->netConfigDNS->execute());
131     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
132   }
134   function remove_from_parent()
135   {
136     $this->netConfigDNS->remove_from_parent();
137     $ldap= $this->config->get_ldap_link();
138     $ldap->rmdir($this->dn);
139     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
140     $this->handle_post_events("remove");
142     /* Delete references to object groups */
143     $ldap->cd ($this->config->current['BASE']);
144     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
145     while ($ldap->fetch()){
146       $og= new ogroup($this->config, $ldap->getDN());
147       unset($og->member[$this->dn]);
148       $og->save ();
149     }
150   }
153   /* Save data to object */
154   function save_object()
155   {
156     plugin::save_object();
157     $this->netConfigDNS->save_object();
158     /* Save base, since this is no LDAP attribute */
159     if (isset($_POST['base']) && $this->acl_is_moveable()){
160       $this->base= $_POST['base'];
161     }
162   }
165   /* Check supplied data */
166   function check()
167   {
168     /* Call common method to give check the hook */
169     $message= plugin::check();
170     $message= array_merge($message, $this->netConfigDNS->check());
171     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
173     if(!$this->acl_is_createable() && $this->dn == "new"){
174       $message[]= _("You have no permissions to create a component on this 'Base'.");
175     }
177     if ($this->orig_dn != $this->dn){
178       $ldap= $this->config->get_ldap_link();
179       $ldap->cd ($this->base);
180       $ldap->search ("(cn=".$this->cn.")", array("cn"));
181       if ($ldap->count() != 0){
182         while ($attrs= $ldap->fetch()){
183           if ($attrs['dn'] != $this->orig_dn){
184             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
185             break;
186           }
187         }
188       }
189     }
191     return ($message);
192   }
195   /* Save to LDAP */
196   function save()
197   {
198     plugin::save();
200     /* Remove all empty values */
201     if ($this->orig_dn == 'new'){
202       $attrs= array();
203       foreach ($this->attrs as $key => $val){
204         if (is_array($val) && count($val) == 0){
205           continue;
206         }
207         $attrs[$key]= $val;
208       }
209       $this->attrs= $attrs;
210     }
212     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
213       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
214     }
216     /* Write back to ldap */
217     $ldap= $this->config->get_ldap_link();
218     if ($this->orig_dn == 'new'){
219       $ldap->cd($this->config->current['BASE']);
220       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
221       $ldap->cd($this->dn);
222       $ldap->add($this->attrs);
223       $this->handle_post_events("add");
224     } else {
225       if ($this->orig_dn != $this->dn){
226         $this->move($this->orig_dn, $this->dn);
227       }
229       $ldap->cd($this->dn);
230       $this->cleanup();
231       $ldap->modify ($this->attrs); 
233       $this->handle_post_events("modify");
234     }
236     # FIXME can't save mac address
237     #$this->netConfigDNS->cn = $this->cn;
238     #$this->netConfigDNS->save($this->dn);
239     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
241     /* Optionally execute a command after we're done */
242     $this->postcreate();
243   }
245   /* Return plugin informations for acl handling
246   #FIXME FAIscript seams to ununsed within this class... */
247   function plInfo()
248   {
249     return (array(
250           "plShortName"   => _("Win generic"),
251           "plDescription" => _("Windows workstation generic"),
252           "plSelfModify"  => FALSE,
253           "plDepends"     => array(),
254           "plPriority"    => 0,
255           "plSection"     => array("administration"),
256           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
257                                                           "objectClass"  => "gotoWorkstation")),
258           "plProvidedAcls"=> array(
259             "cn"                  => _("Workstation name"),
260             "description"         => _("Description"))
261           ));
262   }
267 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
268 ?>