5f250619cd9212478bb2eca9c44325eef0574dc6
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 /* Base select dialog */
78 $once = true;
79 foreach($_POST as $name => $value){
80 if(preg_match("/^chooseBase/",$name) && $once){
81 $once = false;
82 $this->dialog = new baseSelectDialog($this->config);
83 $this->dialog->setCurrentBase($this->base);
84 }
85 }
87 /* Dialog handling */
88 if(is_object($this->dialog)){
89 /* Must be called before save_object */
90 $this->dialog->save_object();
92 if($this->dialog->isClosed()){
93 $this->dialog = false;
94 }elseif($this->dialog->isSelected()){
95 $this->base = $this->dialog->isSelected();
96 $this->dialog= false;
97 }else{
98 return($this->dialog->execute());
99 }
100 }
102 /* Fill templating stuff */
103 $smarty= get_smarty();
105 // Undefined index in wingeneric.tpl ...
106 $smarty->assign("bases", $this->config->idepartments);
108 /* Assign attributes */
109 foreach ($this->attributes as $attr){
110 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
111 $smarty->assign("$attr", $this->$attr);
112 }
114 $smarty->assign("base_select", $this->base);
116 /* Show main page */
117 $smarty->assign("netconfig", $this->netConfigDNS->execute());
118 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
119 }
121 function remove_from_parent()
122 {
123 $this->netConfigDNS->remove_from_parent();
124 $ldap= $this->config->get_ldap_link();
125 $ldap->rmdir($this->dn);
126 show_ldap_error($ldap->get_error());
127 $this->handle_post_events("remove");
129 /* Delete references to object groups */
130 $ldap->cd ($this->config->current['BASE']);
131 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
132 while ($ldap->fetch()){
133 $og= new ogroup($this->config, $ldap->getDN());
134 unset($og->member[$this->dn]);
135 $og->save ();
136 }
137 }
140 /* Save data to object */
141 function save_object()
142 {
143 plugin::save_object();
144 $this->netConfigDNS->save_object();
145 /* Save base, since this is no LDAP attribute */
146 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
147 $this->base= $_POST['base'];
148 }
149 }
152 /* Check supplied data */
153 function check()
154 {
155 $message=$this->netConfigDNS->check();
156 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
158 $ui= get_userinfo();
159 $acl= get_permissions ($this->dn, $ui->subtreeACL);
160 $acl= get_module_permission($acl, "component", $this->dn);
161 if (chkacl($acl, "create") != ""){
162 $message[]= _("You have no permissions to create a component on this 'Base'.");
163 }
165 if ($this->orig_dn != $this->dn){
166 $ldap= $this->config->get_ldap_link();
167 $ldap->cd ($this->base);
168 $ldap->search ("(cn=".$this->cn.")", array("cn"));
169 if ($ldap->count() != 0){
170 while ($attrs= $ldap->fetch()){
171 if ($attrs['dn'] != $this->orig_dn){
172 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
173 break;
174 }
175 }
176 }
177 }
179 return ($message);
180 }
183 /* Save to LDAP */
184 function save()
185 {
186 plugin::save();
188 /* Remove all empty values */
189 if ($this->orig_dn == 'new'){
190 $attrs= array();
191 foreach ($this->attrs as $key => $val){
192 if (is_array($val) && count($val) == 0){
193 continue;
194 }
195 $attrs[$key]= $val;
196 }
197 $this->attrs= $attrs;
198 }
200 /* Write back to ldap */
201 $ldap= $this->config->get_ldap_link();
202 if ($this->orig_dn == 'new'){
203 $ldap->cd($this->config->current['BASE']);
204 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
205 $ldap->cd($this->dn);
206 $ldap->add($this->attrs);
207 $this->handle_post_events("add");
208 } else {
209 if ($this->orig_dn != $this->dn){
210 $this->move($this->orig_dn, $this->dn);
211 }
213 $ldap->cd($this->dn);
214 $this->cleanup();
215 $ldap->modify ($this->attrs);
217 $this->handle_post_events("modify");
218 }
220 $this->netConfigDNS->cn = $this->cn;
221 $this->netConfigDNS->save($this->dn);
222 show_ldap_error($ldap->get_error());
224 /* Optionally execute a command after we're done */
225 $this->postcreate();
226 }
228 }
230 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
231 ?>