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