Code

dde10dd674408b997be11ca2c82fe93fb8ffbc2f
[gosa.git] / gosa-core / plugins / admin / systems / samba / 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");
47   var $view_logged = FALSE;
49   function wingeneric (&$config, $dn= NULL, $parent= NULL)
50   {
51     plugin::plugin ($config, $dn, $parent);
52     $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
53     /* Set base */
54     if ($this->dn == "new"){
55       $ui= get_userinfo();
56       $this->base= dn2base($ui->dn);
57       $this->cn= "";
58     } else {
59       $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
60     }
62     /* Save dn for later references */
63     $this->orig_dn= $this->dn;
65     $this->cn= preg_replace("/\\\$\$/","",$this->cn);
66   }
69   function set_acl_base($base)
70   {
71     plugin::set_acl_base($base);
72     $this->netConfigDNS->set_acl_base($base);
73   }
75   function set_acl_category($cat)
76   {
77     plugin::set_acl_category($cat);
78     $this->netConfigDNS->set_acl_category($cat);
79   }
82   function execute()
83   {
84     /* Call parent execute */
85     plugin::execute();
87     if($this->is_account && !$this->view_logged){
88       $this->view_logged = TRUE;
89       new log("view","winworkstation/".get_class($this),$this->dn);
90     }
93     /* Do we represent a valid phone? */
94     if (!$this->is_account && $this->parent === NULL){
95       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
96         _("This 'dn' has no network features.")."</b>";
97       return($display);
98     }
100     /* Base select dialog */
101     $once = true;
102     foreach($_POST as $name => $value){
103       if(preg_match("/^chooseBase/",$name) && $once){
104         $once = false;
105         $this->dialog = new baseSelectDialog($this->config,$this);
106         $this->dialog->setCurrentBase($this->base);
107       }
108     }
110     /* Dialog handling */
111     if(is_object($this->dialog)){
112       /* Must be called before save_object */
113       $this->dialog->save_object();
115       if($this->dialog->isClosed()){
116         $this->dialog = false;
117       }elseif($this->dialog->isSelected()){
119         /* A new base was selected, check if it is a valid one */
120         $tmp = $this->get_allowed_bases();
121         if(isset($tmp[$this->dialog->isSelected()])){
122           $this->base = $this->dialog->isSelected();
123         }
125         $this->dialog= false;
126       }else{
127         return($this->dialog->execute());
128       }
129     }
131     /* Fill templating stuff */
132     $smarty= get_smarty();
133     $smarty->assign("bases", $this->config->idepartments);
135     /* Assign attributes */
136     foreach ($this->attributes as $attr){
137       $smarty->assign("$attr", $this->$attr);
138     }
139     
140     $smarty->assign("base_select", $this->base);
142     /* Show main page */
143     $str = $this->netConfigDNS->execute();
144     if(is_object($this->netConfigDNS->dialog)){
145       return($str);
146     }
147     $smarty->assign("netconfig", $str);
148     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE,dirname(__FILE__))));
149   }
151   function remove_from_parent()
152   {
153     $this->netConfigDNS->remove_from_parent();
154     $ldap= $this->config->get_ldap_link();
155     $ldap->rmdir($this->dn);
156     new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
157     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
158     $this->handle_post_events("remove");
160     /* Delete references to object groups */
161     $ldap->cd ($this->config->current['BASE']);
162     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
163     while ($ldap->fetch()){
164       $og= new ogroup($this->config, $ldap->getDN());
165       unset($og->member[$this->dn]);
166       $og->save ();
167     }
168   }
171   /* Save data to object */
172   function save_object()
173   {
174     /* Create a base backup and reset the
175        base directly after calling plugin::save_object();
176        Base will be set seperatly a few lines below */
177     $base_tmp = $this->base;
178     plugin::save_object();
179     $this->base = $base_tmp;
181     $this->netConfigDNS->save_object();
183     /* Set new base if allowed */
184     $tmp = $this->get_allowed_bases();
185     if(isset($_POST['base'])){
186       if(isset($tmp[$_POST['base']])){
187         $this->base= $_POST['base'];
188       }
189     }
190   }
193   /* Check supplied data */
194   function check()
195   {
196     /* Call common method to give check the hook */
197     $message= plugin::check();
198     $message= array_merge($message, $this->netConfigDNS->check());
199     $this->dn= "cn=".$this->cn.",".get_ou('componentou').$this->base;
200     
201     /* Set new acl base */
202     if($this->dn == "new") {
203       $this->set_acl_base($this->base);
204     }
206     if(!$this->acl_is_createable() && $this->dn == "new"){
207       $message[]= _("You have no permissions to create a component on this 'Base'.");
208     }
210     if ($this->orig_dn != $this->dn){
211       $ldap= $this->config->get_ldap_link();
212       $ldap->cd ($this->base);
213       $ldap->search ("(cn=".$this->cn.")", array("cn"));
214       if ($ldap->count() != 0){
215         while ($attrs= $ldap->fetch()){
216           if(preg_match("/cn=dhcp,/",$attrs['dn'])){
217             continue;
218           }
219           if ($attrs['dn'] != $this->orig_dn){
220             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
221             break;
222           }
223         }
224       }
225     }
227     return ($message);
228   }
231   /* Save to LDAP */
232   function save()
233   {
234     plugin::save();
236     /* Remove all empty values */
237     if ($this->orig_dn == 'new'){
238       $attrs= array();
239       foreach ($this->attrs as $key => $val){
240         if (is_array($val) && count($val) == 0){
241           continue;
242         }
243         $attrs[$key]= $val;
244       }
245       $this->attrs= $attrs;
246     }
248     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
249       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
250     }
252     /* Write back to ldap */
253     $ldap= $this->config->get_ldap_link();
254     if ($this->orig_dn == 'new'){
255       $ldap->cd($this->config->current['BASE']);
256       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
257       $ldap->cd($this->dn);
258       $ldap->add($this->attrs);
259       new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
260       $this->handle_post_events("add");
261     } else {
262       if ($this->orig_dn != $this->dn){
263         $this->move($this->orig_dn, $this->dn);
264       }
266       $ldap->cd($this->dn);
267       $this->cleanup();
268       $ldap->modify ($this->attrs); 
269       new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
270       $this->handle_post_events("modify");
271     }
273     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->cn);
274     $this->netConfigDNS->save();
275     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
277     /* Optionally execute a command after we're done */
278     $this->postcreate();
279   }
281   /* Return plugin informations for acl handling
282   #FIXME FAIscript seams to ununsed within this class... */
283   static function plInfo()
284   {
285     return (array(
286           "plShortName"   => _("Win generic"),
287           "plDescription" => _("Windows workstation generic"),
288           "plSelfModify"  => FALSE,
289           "plDepends"     => array(),
290           "plPriority"    => 0,
291           "plSection"     => array("administration"),
292           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
293                                                           "objectClass"  => "gotoWorkstation")),
294           "plProvidedAcls"=> array(
295             "cn"                  => _("Workstation name"),
296             "description"         => _("Description"))
297           ));
298   }
303 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
304 ?>