Code

Added multiple remove to group list
[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;
64     $this->cn= preg_replace("/\\\$\$/","",$this->cn);
65   }
68   function set_acl_base($base)
69   {
70     plugin::set_acl_base($base);
71     $this->netConfigDNS->set_acl_base($base);
72   }
74   function set_acl_category($cat)
75   {
76     plugin::set_acl_category($cat);
77     $this->netConfigDNS->set_acl_category($cat);
78   }
81   function execute()
82   {
83         /* Call parent execute */
84         plugin::execute();
86     /* Do we represent a valid phone? */
87     if (!$this->is_account && $this->parent == NULL){
88       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
89         _("This 'dn' has no network features.")."</b>";
90       return($display);
91     }
93     /* Base select dialog */
94     $once = true;
95     foreach($_POST as $name => $value){
96       if(preg_match("/^chooseBase/",$name) && $once){
97         $once = false;
98         $this->dialog = new baseSelectDialog($this->config,$this);
99         $this->dialog->setCurrentBase($this->base);
100       }
101     }
103     /* Dialog handling */
104     if(is_object($this->dialog)){
105       /* Must be called before save_object */
106       $this->dialog->save_object();
108       if($this->dialog->isClosed()){
109         $this->dialog = false;
110       }elseif($this->dialog->isSelected()){
112         /* A new base was selected, check if it is a valid one */
113         $tmp = $this->get_allowed_bases();
114         if(isset($tmp[$this->dialog->isSelected()])){
115           $this->base = $this->dialog->isSelected();
116         }
118         $this->dialog= false;
119       }else{
120         return($this->dialog->execute());
121       }
122     }
124     /* Fill templating stuff */
125     $smarty= get_smarty();
127     // Undefined index in wingeneric.tpl ... 
128     $smarty->assign("bases", $this->config->idepartments);
130     /* Assign attributes */
131     foreach ($this->attributes as $attr){
132       $smarty->assign("$attr", $this->$attr);
133     }
134     
135     $smarty->assign("base_select", $this->base);
137     /* Show main page */
138     $smarty->assign("netconfig", $this->netConfigDNS->execute());
139     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
140   }
142   function remove_from_parent()
143   {
144     $this->netConfigDNS->remove_from_parent();
145     $ldap= $this->config->get_ldap_link();
146     $ldap->rmdir($this->dn);
147     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
148     $this->handle_post_events("remove");
150     /* Delete references to object groups */
151     $ldap->cd ($this->config->current['BASE']);
152     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
153     while ($ldap->fetch()){
154       $og= new ogroup($this->config, $ldap->getDN());
155       unset($og->member[$this->dn]);
156       $og->save ();
157     }
158   }
161   /* Save data to object */
162   function save_object()
163   {
164     /* Create a base backup and reset the
165        base directly after calling plugin::save_object();
166        Base will be set seperatly a few lines below */
167     $base_tmp = $this->base;
168     plugin::save_object();
169     $this->base = $base_tmp;
171     $this->netConfigDNS->save_object();
173     /* Set new base if allowed */
174     $tmp = $this->get_allowed_bases();
175     if(isset($_POST['base'])){
176       if(isset($tmp[$_POST['base']])){
177         $this->base= $_POST['base'];
178       }
179     }
180   }
183   /* Check supplied data */
184   function check()
185   {
186     /* Call common method to give check the hook */
187     $message= plugin::check();
188     $message= array_merge($message, $this->netConfigDNS->check());
189     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
190     
191     /* Set new acl base */
192     if($this->dn == "new") {
193       $this->set_acl_base($this->base);
194     }
196     if(!$this->acl_is_createable() && $this->dn == "new"){
197       $message[]= _("You have no permissions to create a component on this 'Base'.");
198     }
200     if ($this->orig_dn != $this->dn){
201       $ldap= $this->config->get_ldap_link();
202       $ldap->cd ($this->base);
203       $ldap->search ("(cn=".$this->cn.")", array("cn"));
204       if ($ldap->count() != 0){
205         while ($attrs= $ldap->fetch()){
206           if ($attrs['dn'] != $this->orig_dn){
207             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
208             break;
209           }
210         }
211       }
212     }
214     return ($message);
215   }
218   /* Save to LDAP */
219   function save()
220   {
221     plugin::save();
223     /* Remove all empty values */
224     if ($this->orig_dn == 'new'){
225       $attrs= array();
226       foreach ($this->attrs as $key => $val){
227         if (is_array($val) && count($val) == 0){
228           continue;
229         }
230         $attrs[$key]= $val;
231       }
232       $this->attrs= $attrs;
233     }
235     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
236       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
237     }
239     /* Write back to ldap */
240     $ldap= $this->config->get_ldap_link();
241     if ($this->orig_dn == 'new'){
242       $ldap->cd($this->config->current['BASE']);
243       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
244       $ldap->cd($this->dn);
245       $ldap->add($this->attrs);
246       $this->handle_post_events("add");
247     } else {
248       if ($this->orig_dn != $this->dn){
249         $this->move($this->orig_dn, $this->dn);
250       }
252       $ldap->cd($this->dn);
253       $this->cleanup();
254       $ldap->modify ($this->attrs); 
256       $this->handle_post_events("modify");
257     }
259     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->cn);
260     $this->netConfigDNS->save($this->dn);
261     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
263     /* Optionally execute a command after we're done */
264     $this->postcreate();
265   }
267   /* Return plugin informations for acl handling
268   #FIXME FAIscript seams to ununsed within this class... */
269   function plInfo()
270   {
271     return (array(
272           "plShortName"   => _("Win generic"),
273           "plDescription" => _("Windows workstation generic"),
274           "plSelfModify"  => FALSE,
275           "plDepends"     => array(),
276           "plPriority"    => 0,
277           "plSection"     => array("administration"),
278           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
279                                                           "objectClass"  => "gotoWorkstation")),
280           "plProvidedAcls"=> array(
281             "cn"                  => _("Workstation name"),
282             "description"         => _("Description"))
283           ));
284   }
289 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
290 ?>