Code

3b72c17a635919456d798e81ef6ed88b1c8dec63
[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="";
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)
49   {
50     plugin::plugin ($config, $dn);
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   }
65   function execute()
66   {
67         /* Call parent execute */
68         plugin::execute();
69     /* Do we represent a valid phone? */
70     if (!$this->is_account && $this->parent == NULL){
71       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
72         _("This 'dn' has no network features.")."</b>";
73       return($display);
74     }
76     /* Fill templating stuff */
77     $smarty= get_smarty();
79     // Undefined index in wingeneric.tpl ... 
80     $smarty->assign("macAddress","");
81     $smarty->assign("ipHostNumber","");
83     $smarty->assign("bases", $this->config->idepartments);
85     /* Assign attributes */
86     foreach ($this->attributes as $attr){
87       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
88       $smarty->assign("$attr", $this->$attr);
89     }
90     
91     /* Show Asterisk for required attribute ipHostNumber and macAddress */
92     $smarty->assign("staticAddress", "<font class=\"must\">*</font>");
93     
94     $smarty->assign("base_select", $this->base);
96     /* Show main page */
97     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
98     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
99   }
101   function remove_from_parent()
102   {
103     $ldap= $this->config->get_ldap_link();
104     $ldap->rmdir($this->dn);
105     show_ldap_error($ldap->get_error());
106     $this->handle_post_events("remove");
108     /* Delete references to object groups */
109     $ldap->cd ($this->config->current['BASE']);
110     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
111     while ($ldap->fetch()){
112       $og= new ogroup($this->config, $ldap->getDN());
113       unset($og->member[$this->dn]);
114       $og->save ();
115     }
117   }
120   /* Save data to object */
121   function save_object()
122   {
123     plugin::save_object();
125     /* Save base, since this is no LDAP attribute */
126     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
127       $this->base= $_POST['base'];
128     }
129   }
132   /* Check supplied data */
133   function check()
134   {
135     $message= array();
136     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
139     /* must: cn, macAddress */
140     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
141       $message[]= _("The required field 'Component name' is not set.");
142     }
144 /*    if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
145       $message[]= _("The required field 'MAC-address' is not set.");
146     }
147     if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
148       $message[]= _("The required field 'IP-address' is not set.");
149     }
150 */
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     /* Write back to ldap */
194     $ldap= $this->config->get_ldap_link();
195     if ($this->orig_dn == 'new'){
196       $ldap->cd($this->config->current['BASE']);
197       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
198       $ldap->cd($this->dn);
199       $ldap->add($this->attrs);
200       $this->handle_post_events("add");
201     } else {
202       if ($this->orig_dn != $this->dn){
203         $this->move($this->orig_dn, $this->dn);
204       }
206       $ldap->cd($this->dn);
207       $ldap->modify($this->attrs);
208       $this->handle_post_events("modify");
209     }
210     show_ldap_error($ldap->get_error());
212     /* Optionally execute a command after we're done */
213     $this->postcreate();
214   }
218 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
219 ?>