Code

Fixed headpage
[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();
70     /* Do we represent a valid phone? */
71     if (!$this->is_account && $this->parent == NULL){
72       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
73         _("This 'dn' has no network features.")."</b>";
74       return($display);
75     }
77     /* Fill templating stuff */
78     $smarty= get_smarty();
80     // Undefined index in wingeneric.tpl ... 
81     $smarty->assign("macAddress","");
82     $smarty->assign("ipHostNumber","");
84     $smarty->assign("bases", $this->config->idepartments);
86     /* Assign attributes */
87     foreach ($this->attributes as $attr){
88       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
89       $smarty->assign("$attr", $this->$attr);
90     }
91     
92     /* Show Asterisk for required attribute ipHostNumber and macAddress */
93     $smarty->assign("staticAddress", "<font class=\"must\">*</font>");
94     
95     $smarty->assign("base_select", $this->base);
97     /* Show main page */
98     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
99     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
100   }
102   function remove_from_parent()
103   {
104     $ldap= $this->config->get_ldap_link();
105     $ldap->rmdir($this->dn);
106     show_ldap_error($ldap->get_error());
107     $this->handle_post_events("remove");
109     /* Delete references to object groups */
110     $ldap->cd ($this->config->current['BASE']);
111     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
112     while ($ldap->fetch()){
113       $og= new ogroup($this->config, $ldap->getDN());
114       unset($og->member[$this->dn]);
115       $og->save ();
116     }
118   }
121   /* Save data to object */
122   function save_object()
123   {
124     plugin::save_object();
126     /* Save base, since this is no LDAP attribute */
127     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
128       $this->base= $_POST['base'];
129     }
130   }
133   /* Check supplied data */
134   function check()
135   {
136     $message= array();
137     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
140     /* must: cn, macAddress */
141     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
142       $message[]= _("The required field 'Component name' is not set.");
143     }
145 /*    if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
146       $message[]= _("The required field 'MAC-address' is not set.");
147     }
148     if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
149       $message[]= _("The required field 'IP-address' is not set.");
150     }
151 */
152     $ui= get_userinfo();
153     $acl= get_permissions ($this->dn, $ui->subtreeACL);
154     $acl= get_module_permission($acl, "component", $this->dn);
155     if (chkacl($acl, "create") != ""){
156       $message[]= _("You have no permissions to create a component on this 'Base'.");
157     }
159     if ($this->orig_dn != $this->dn){
160       $ldap= $this->config->get_ldap_link();
161       $ldap->cd ($this->base);
162       $ldap->search ("(cn=".$this->cn.")", array("cn"));
163       if ($ldap->count() != 0){
164         while ($attrs= $ldap->fetch()){
165           if ($attrs['dn'] != $this->orig_dn){
166             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
167             break;
168           }
169         }
170       }
171     }
173     return ($message);
174   }
177   /* Save to LDAP */
178   function save()
179   {
180     plugin::save();
182     /* Remove all empty values */
183     if ($this->orig_dn == 'new'){
184       $attrs= array();
185       foreach ($this->attrs as $key => $val){
186         if (is_array($val) && count($val) == 0){
187           continue;
188         }
189         $attrs[$key]= $val;
190       }
191       $this->attrs= $attrs;
192     }
194     /* Write back to ldap */
195     $ldap= $this->config->get_ldap_link();
196     if ($this->orig_dn == 'new'){
197       $ldap->cd($this->config->current['BASE']);
198       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
199       $ldap->cd($this->dn);
200       $ldap->add($this->attrs);
201       $this->handle_post_events("add");
202     } else {
203       if ($this->orig_dn != $this->dn){
204         $this->move($this->orig_dn, $this->dn);
205       }
207       $ldap->cd($this->dn);
208       $ldap->modify($this->attrs);
209       $this->handle_post_events("modify");
210     }
211     show_ldap_error($ldap->get_error());
213     /* Optionally execute a command after we're done */
214     $this->postcreate();
215   }
219 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
220 ?>