1 <?php
3 class wingeneric extends plugin
4 {
5 /* Generic terminal attributes */
6 var $interfaces= array();
8 /* Needed values and lists */
9 var $base= "";
10 var $cn= "";
11 var $description= "";
12 var $orig_dn= "";
13 var $shadowLastChange="";
14 var $uidNumber="";
15 var $gidNumber="";
16 var $loginShell="";
17 var $gecos="";
18 var $shadowMin="";
19 var $shadowWarning="";
20 var $shadowInactive="";
21 var $uid="";
22 var $sn="";
23 var $givenName="";
24 var $homeDirectory="";
25 var $sambaSID="";
26 var $sambaPrimaryGroupSID="";
27 var $displayName="";
28 var $sambaPwdMustChange="";
29 var $sambaNTPassword="";
30 var $sambaPwdLastSet="";
31 var $sambaAcctFlags="";
32 var $netConfigDNS;
34 var $orig_cn;
35 var $orig_base;
36 var $baseSelector;
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");
47 var $view_logged = FALSE;
49 function wingeneric (&$config, $dn= NULL, $parent= NULL)
50 {
51 plugin::plugin ($config, $dn, $parent);
52 $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses,FALSE,"uid");
53 $this->netConfigDNS->cn = preg_replace("/\\\$\$/","",$this->uid);
54 $this->netConfigDNS->objectclasses=array("ipHost","ieee802Device");
55 $this->netConfigDNS->MACisMust = FALSE;
56 $this->netConfigDNS->IPisMust = FALSE;
58 /* Set base */
59 if ($this->dn == "new"){
60 $ui = get_userinfo();
61 $this->base= dn2base(session::global_is_set("CurrentMainBase")?session::global_get("CurrentMainBase"):$ui->dn);
62 $this->cn= "";
63 } else {
64 $this->base= preg_replace ("/^[^,]+,".preg_quote(get_winstations_ou(), '/')."/i", "", $this->dn);
65 }
67 $this->cn= preg_replace("/\\\$\$/","",$this->cn);
69 /* Save dn for later references */
70 $this->orig_dn= $this->dn;
71 $this->orig_base= $this->base;
72 $this->orig_cn= $this->cn;
74 /* Instanciate base selector */
75 $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
76 $this->baseSelector->setSubmitButton(false);
77 $this->baseSelector->setHeight(300);
78 $this->baseSelector->update(true);
79 }
82 function set_acl_base($base)
83 {
84 plugin::set_acl_base($base);
85 $this->netConfigDNS->set_acl_base($base);
86 }
89 function set_acl_category($cat)
90 {
91 plugin::set_acl_category($cat);
92 $this->netConfigDNS->set_acl_category($cat);
93 }
96 function execute()
97 {
98 /* Call parent execute */
99 plugin::execute();
101 if($this->is_account && !$this->view_logged){
102 $this->view_logged = TRUE;
103 new log("view","winworkstation/".get_class($this),$this->dn);
104 }
107 /* Do we represent a valid phone? */
108 if (!$this->is_account && $this->parent === NULL){
109 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
110 msgPool::noValidExtension(_("network"))."</b>";
111 return($display);
112 }
114 /* Fill templating stuff */
115 $smarty= get_smarty();
116 $smarty->assign("usePrototype", "true");
118 $tmp = $this->plInfo();
119 foreach($tmp['plProvidedAcls'] as $name => $translated){
120 $smarty->assign($name."ACL",$this->getacl($name));
121 }
123 /* Assign attributes */
124 foreach ($this->attributes as $attr){
125 $smarty->assign("$attr", $this->$attr);
126 }
128 $smarty->assign("base", $this->baseSelector->render());
130 /* Show main page */
131 $str = $this->netConfigDNS->execute();
132 if(is_object($this->netConfigDNS->dialog)){
133 return($str);
134 }
135 $smarty->assign("netconfig", $str);
136 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE,dirname(__FILE__))));
137 }
139 function remove_from_parent()
140 {
141 $this->netConfigDNS->remove_from_parent();
142 $ldap= $this->config->get_ldap_link();
143 $ldap->rmdir($this->dn);
144 new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
145 if (!$ldap->success()){
146 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
147 }
148 $this->handle_post_events("remove");
150 /* Delete references to object groups */
151 $ldap->cd ($this->config->current['BASE']);
152 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
153 while ($ldap->fetch()){
154 $og= new ogroup($this->config, $ldap->getDN());
155 unset($og->member[$this->dn]);
156 $og->save ();
157 }
158 }
161 /* Save data to object */
162 function save_object()
163 {
164 /* Create a base backup and reset the
165 base directly after calling plugin::save_object();
166 Base will be set seperatly a few lines below */
167 $base_tmp = $this->base;
168 plugin::save_object();
169 $this->base = $base_tmp;
171 $this->netConfigDNS->save_object();
173 /* Refresh base */
174 if ($this->acl_is_moveable($this->base)){
175 if (!$this->baseSelector->update()) {
176 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
177 }
178 if ($this->base != $this->baseSelector->getBase()) {
179 $this->base= $this->baseSelector->getBase();
180 $this->is_modified= TRUE;
181 }
182 }
184 }
187 /* Check supplied data */
188 function check()
189 {
190 /* Call common method to give check the hook */
191 $message= plugin::check();
192 $message= array_merge($message, $this->netConfigDNS->check());
193 $this->dn= "cn=".$this->uid.",".get_ou('sambaMachineAccountRDN').$this->base;
195 if(!$this->acl_is_createable()){
196 $message[]= msgPool::permCreate();
197 }
199 if ($this->orig_dn != $this->dn){
200 $ldap= $this->config->get_ldap_link();
201 $ldap->cd ($this->base);
202 $ldap->search ("(cn=".$this->cn.")", array("cn"));
203 if ($ldap->count() != 0){
204 while ($attrs= $ldap->fetch()){
205 if(preg_match("/cn=dhcp,/",$attrs['dn'])){
206 continue;
207 }
208 if ($attrs['dn'] != $this->orig_dn){
209 $message[]= msgPool::duplicated(_("Name"));
210 break;
211 }
212 }
213 }
214 }
216 // Check if a wrong base was supplied
217 if(!$this->baseSelector->checkLastBaseUpdate()){
218 $message[]= msgPool::check_base();;
219 }
221 /* Check if we are allowed to create or move this object
222 */
223 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
224 $message[] = msgPool::permCreate();
225 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
226 $message[] = msgPool::permMove();
227 }
229 return ($message);
230 }
233 /* Save to LDAP */
234 function save()
235 {
236 plugin::save();
238 /* Remove all empty values */
239 if ($this->orig_dn == 'new'){
240 $attrs= array();
241 foreach ($this->attrs as $key => $val){
242 if (is_array($val) && count($val) == 0){
243 continue;
244 }
245 $attrs[$key]= $val;
246 }
247 $this->attrs= $attrs;
248 }
250 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
251 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
252 }
254 /* Write back to ldap */
255 $ldap= $this->config->get_ldap_link();
256 if ($this->orig_dn == 'new'){
257 $ldap->cd($this->config->current['BASE']);
258 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
259 $ldap->cd($this->dn);
260 $ldap->add($this->attrs);
261 new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
262 $this->handle_post_events("add");
263 } else {
264 if ($this->orig_dn != $this->dn){
265 $this->move($this->orig_dn, $this->dn);
266 }
268 $ldap->cd($this->dn);
269 $this->cleanup();
270 $ldap->modify ($this->attrs);
271 new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
272 $this->handle_post_events("modify");
273 }
275 $this->netConfigDNS->cn = preg_replace("/\\\$\$/","",$this->uid);
276 $this->netConfigDNS->save();
277 if (!$ldap->success()){
278 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
279 }
281 /* Optionally execute a command after we're done */
282 $this->postcreate();
283 }
285 /* Return plugin informations for acl handling
286 #FIXME FAIscript seams to ununsed within this class... */
287 static function plInfo()
288 {
289 return (array(
290 "plShortName" => _("Win generic"),
291 "plDescription" => _("Windows workstation generic"),
292 "plSelfModify" => FALSE,
293 "plDepends" => array(),
294 "plPriority" => 0,
295 "plSection" => array("administration"),
296 "plCategory" => array("winworkstation" => array("description" => _("Win workstation"),
297 "objectClass" => "gotoWorkstation")),
298 "plProvidedAcls"=> array(
299 "cn" => _("Name"),
300 "base" => _("Base"),
301 "description" => _("Description"))
302 ));
303 }
306 }
308 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
309 ?>