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)
49 {
50 plugin::plugin ($config, $dn);
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 ("/^[^,]+,[^,]+,[^,]+,/", "", $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> <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("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 $smarty->assign("base_select", $this->base);
91 /* Show main page */
92 $smarty->assign("netconfig", $this->netConfigDNS->execute());
93 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
94 }
96 function remove_from_parent()
97 {
98 $ldap= $this->config->get_ldap_link();
99 $ldap->rmdir($this->dn);
100 show_ldap_error($ldap->get_error());
101 $this->handle_post_events("remove");
103 /* Delete references to object groups */
104 $ldap->cd ($this->config->current['BASE']);
105 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
106 while ($ldap->fetch()){
107 $og= new ogroup($this->config, $ldap->getDN());
108 unset($og->member[$this->dn]);
109 $og->save ();
110 }
111 $this->netConfigDNS->remove_from_parent();
112 }
115 /* Save data to object */
116 function save_object()
117 {
118 plugin::save_object();
119 $this->netConfigDNS->save_object();
120 /* Save base, since this is no LDAP attribute */
121 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
122 $this->base= $_POST['base'];
123 }
124 }
127 /* Check supplied data */
128 function check()
129 {
130 $message=$this->netConfigDNS->check();
131 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
133 $ui= get_userinfo();
134 $acl= get_permissions ($this->dn, $ui->subtreeACL);
135 $acl= get_module_permission($acl, "component", $this->dn);
136 if (chkacl($acl, "create") != ""){
137 $message[]= _("You have no permissions to create a component on this 'Base'.");
138 }
140 if ($this->orig_dn != $this->dn){
141 $ldap= $this->config->get_ldap_link();
142 $ldap->cd ($this->base);
143 $ldap->search ("(cn=".$this->cn.")", array("cn"));
144 if ($ldap->count() != 0){
145 while ($attrs= $ldap->fetch()){
146 if ($attrs['dn'] != $this->orig_dn){
147 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
148 break;
149 }
150 }
151 }
152 }
154 return ($message);
155 }
158 /* Save to LDAP */
159 function save()
160 {
161 plugin::save();
163 /* Remove all empty values */
164 if ($this->orig_dn == 'new'){
165 $attrs= array();
166 foreach ($this->attrs as $key => $val){
167 if (is_array($val) && count($val) == 0){
168 continue;
169 }
170 $attrs[$key]= $val;
171 }
172 $this->attrs= $attrs;
173 }
175 /* Write back to ldap */
176 $ldap= $this->config->get_ldap_link();
177 if ($this->orig_dn == 'new'){
178 $ldap->cd($this->config->current['BASE']);
179 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
180 $ldap->cd($this->dn);
181 $ldap->add($this->attrs);
182 $this->handle_post_events("add");
183 } else {
184 if ($this->orig_dn != $this->dn){
185 $this->move($this->orig_dn, $this->dn);
186 }
188 $ldap->cd($this->dn);
189 $ldap->modify($this->attrs);
190 $this->handle_post_events("modify");
191 }
192 $this->netConfigDNS->save($this->dn);
193 show_ldap_error($ldap->get_error());
195 /* Optionally execute a command after we're done */
196 $this->postcreate();
197 }
199 }
201 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
202 ?>