1 <?php
3 class printgeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage terminal 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();
12 var $ignore_account = FALSE;
14 /* Needed values and lists */
15 var $base = "";
16 var $cn = "";
17 var $l = "";
18 var $description = "";
19 var $labeledURI = "";
20 var $gotoPrinterPPD = "";
21 var $initial_PPD = "";
22 var $orig_dn = "";
24 var $UserMember ="";
25 var $UserMembers =array();
26 var $UserMemberKeys =array();
28 var $AdminMember ="";
29 var $AdminMembers =array();
30 var $AdminMemberKeys =array();
32 var $PPDdialogToSave = NULL;
33 var $BelongsTo = "unknown"; // Specifies if this is a standalone printer, or belongs to a terminal / WS
35 var $member =array();
36 var $strings = "";
37 var $dialog =NULL;
39 var $netConfigDNS;
40 var $baseSelection = false;
41 var $macAddress = "";
43 var $gotoUserAdminPrinter;
44 var $gotoGroupAdminPrinter ;
45 var $gotoGroupPrinter;
46 var $gotoUserPrinter ;
48 /* attribute list for save action */
49 var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
50 "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
51 var $objectclasses = array("top", "gotoPrinter");
53 var $parent;
55 function printgeneric ($config, $dn,$parent_init,$parent)
56 {
57 $this->config = $config;
58 $this->dn = $dn;
60 /* If parent was posted(the tabs object) we can detect the printer type. */
61 if($parent){
62 $this->parent = $parent;
63 $this->getTypeOfPrinter();
64 }else{
65 $this->BelongsTo = "unknown";
66 return;
67 }
69 /* Update dn, to ensure storing as printer instead of WS / terminal */
70 if(preg_match("/Terminal/i",$this->BelongsTo) || preg_match("/TerminalTemplate/i",$this->BelongsTo)){
71 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
72 }
74 if(preg_match("/Workstation/i",$this->BelongsTo) || preg_match("/WorkstationTemplate/i",$this->BelongsTo)){
75 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
76 }
78 $this->orig_dn = $this->dn;
80 /* Get printer settings, possibly dn has changed */
81 plugin::plugin ($config, $this->dn);
83 /* Get is_account initially_was_account status */
84 $this->getTypeOfPrinter(true);
86 /* set orig dn to new if object is new */
87 $ldap= $this->config->get_ldap_link();
88 $ldap->cat($this->dn, array('dn'));
89 if(!$ldap->count()){
90 $this->orig_dn = "new";
91 }
93 /* create dns object */
94 $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
96 /* Set base */
97 if ($this->dn == "new"){
98 $ui= get_userinfo();
99 $this->base= dn2base($ui->dn);
100 $this->cn= "";
101 } else {
103 /* Set base and check if the extracted base exists */
104 if(preg_match("/ou=incoming,/",$this->dn)){
105 $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
106 }else{
107 $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
108 }
110 if(!isset($this->config->idepartments[$this->base])){
111 print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
112 $this->base = $_SESSION['CurrentMainBase'];
113 }
114 }
116 /* Extract selected ppd */
117 if(isset($this->gotoPrinterPPD)){
118 $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
119 }
121 $this->initial_PPD = $this->gotoPrinterPPD;
123 /* Prepare different member types */
124 foreach(array("AddUser" =>"gotoUserPrinter",
125 "AddGroup" =>"gotoGroupPrinter",
126 "AddAdminUser" =>"gotoUserAdminPrinter",
127 "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
129 /* $this->members contains all members */
130 $this->member[$type]=array();
132 if (isset($this->attrs[$attr]['count'])) {
133 unset($this->attrs[$attr]['count']);
134 }
136 if(isset($this->attrs[$attr])){
137 foreach($this->attrs[$attr] as $mem){
138 if(preg_match("/Group/",$type)){
139 $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
140 if($ldap->count()){
141 $entry = $ldap->fetch();
142 $this->member[$type][$entry['cn'][0]]=$entry;
143 }
144 }else{
145 $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
146 if($ldap->count()){
147 $entry = $ldap->fetch();
148 $this->member[$type][$entry['uid'][0]]=$entry;
149 }
150 }
151 }
152 }
153 }
155 if($this->is_account){
156 @log::log("view","printer/".get_class($this),$this->dn);
157 }
158 }
160 function set_acl_base($base)
161 {
162 plugin::set_acl_base($base);
163 if(is_object($this->netConfigDNS)){
164 $this->netConfigDNS->set_acl_base($base);
165 }
166 }
168 function set_acl_category($cat)
169 {
170 plugin::set_acl_category($cat);
171 if(is_object($this->netConfigDNS)){
172 $this->netConfigDNS->set_acl_category($cat);
173 }
174 }
176 /* Detect type of printer.
177 * Printer can be stand alone, belong to a workstation or belong to a terminal.
178 * We can detect the type printer type when comparing the tabs objects
179 */
180 function getTypeOfPrinter($UpdateAccountStatus = false)
181 {
182 /* Disable account as default
183 */
184 $this->is_account = $this->initially_was_account = false;
186 /* Detect type of printer via parent tabs.
187 */
189 $class = get_class($this->parent);
190 if(isset($this->parent->by_object['workgeneric'])){
192 /* Exclude templates
193 */
194 $this->cn = $this->parent->by_object['workgeneric']->cn;
195 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
196 $this->BelongsTo = "WorkstationTemplate";
197 }else{
198 $this->BelongsTo = "Workstation";
199 }
200 }elseif(isset($this->parent->by_object['termgeneric'])){
202 /* Exclude templates
203 */
204 $this->cn = $this->parent->by_object['termgeneric']->cn;
205 if($this->parent->by_object['termgeneric']->cn == "default"){
206 $this->BelongsTo = "TerminalTemplate";
207 }else{
208 $this->BelongsTo = "Terminal";
209 }
210 }elseif(isset($this->parent->by_name['printgeneric'])){
211 $this->BelongsTo = "Printer";
212 }
214 if($UpdateAccountStatus){
216 /* Set is_account / was account
217 */
218 if($this->dn == "new"){
219 $this->initially_was_account = false;
220 }
222 /* If is printer it must be a true account.
223 */
224 if(preg_match("/printer/i",$this->BelongsTo)){
225 $this->is_account = true;
226 }
228 /* Update dn, to ensure storing as printer instead of WS / terminal
229 */
230 if(preg_match("/terminal/i",$this->BelongsTo)){
231 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
232 }
234 if(preg_match("/workstation/i",$this->BelongsTo)){
235 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
236 }
238 /* Detect if this is a valid printer account;
239 */
240 $ldap = $this->config->get_ldap_link();
241 $ldap->cat($this->dn, array('objectClass'));
243 if($ldap->count()){
244 $attrs = $ldap->fetch();
245 if(in_array("gotoPrinter",$attrs['objectClass'])){
246 $this->initially_was_account = true;
247 $this->is_account = true;
248 }else{
249 $this->is_account = false;
250 }
251 }
252 }
253 }
255 function execute()
256 {
257 /* Call parent execute */
258 plugin::execute();
260 /* If type of printer couldn't be detected (because of missing parent object in construction)
261 * hide this tab.
262 */
263 if(preg_match("/unknown/i",$this->BelongsTo)){
264 $display= $this->show_enable_header(_("Add printer extension"),
265 _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
266 return($display);
267 }
269 /* Templates can't have printer extensions
270 */
271 if(preg_match("/WorkstationTemplate/i",$this->BelongsTo)){
272 $display= $this->show_enable_header(_("Add printer extension"),
273 _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
274 return($display);
275 }
276 if(preg_match("/TerminalTemplate/i",$this->BelongsTo)){
277 $display= $this->show_enable_header(_("Add printer extension"),
278 _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
279 return($display);
280 }
282 /* Get cn from base object */
283 if(preg_match("/^Workstation$/i",$this->BelongsTo)){
284 $this->cn = $this->parent->by_object['workgeneric']->cn;
285 }
286 if(preg_match("/^Terminal$/i",$this->BelongsTo)){
287 $this->cn = $this->parent->by_object['termgeneric']->cn;
288 }
290 $smarty= get_smarty();
292 /* Assign acls */
293 $tmp = $this->plInfo();
294 foreach($tmp['plProvidedAcls'] as $name => $translation){
295 $smarty->assign($name."ACL", $this->getacl($name));
296 }
298 $display="";
300 /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
301 if(preg_match("/^Printer$/i",$this->BelongsTo)){
302 $smarty->assign("StandAlone",true);
303 }else{
304 $smarty->assign("StandAlone",false);
305 }
307 /* Do we need to flip is_account state? */
308 if(isset($_POST['modify_state'])){
309 if($this->is_account && $this->acl_is_removeable()){
310 $this->is_account= FALSE;
311 }elseif(!$this->is_account && $this->acl_is_createable()){
312 $this->is_account= TRUE;
313 }
314 }
316 /* Do we represent a valid printer? */
317 if (!$this->is_account && $this->parent == NULL){
318 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
319 _("This 'dn' has no printer features.")."</b>";
320 return($display);
321 }
323 /* If this is a WS / Terminal depending printer, display account state button */
324 if(!preg_match("/^Printer$/i",$this->BelongsTo)){
325 if((empty($this->cn)) && ($this->dn != "new")){
326 $display= $this->show_enable_header(_("Add printer extension"),
327 _("This object has printer extension disabled. You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template"),TRUE,TRUE);
328 $this->is_account= false;
329 return $display;
330 }
332 if (($this->is_account)){
333 if(preg_match("/^Workstation$/i",$this->BelongsTo)){
334 $display= $this->show_disable_header(_("Remove printer extension"),
335 _("This workstation has printer extension enabled.You can disable it by clicking below."));
336 }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){
337 $display= $this->show_disable_header(_("Remove printer extension"),
338 _("This terminal has printer extension enabled. You can disable it by clicking below."));
339 }
340 }else{
341 if(preg_match("/^Workstation$/i",$this->BelongsTo)){
342 $display= $this->show_disable_header(_("Add printer extension"),
343 _("This workstation has printer extension disabled. You can enable it by clicking below."));
344 }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){
345 $display= $this->show_enable_header(_("Add printer extension"),
346 _("This terminal has printer extension disabled. You can enable it by clicking below."));
347 }
348 return ($display);
349 }
350 }
352 /* Base select dialog */
353 $once = true;
354 foreach($_POST as $name => $value){
355 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
356 $once = false;
357 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
358 $this->dialog->setCurrentBase($this->base);
359 $this->baseSelection = true;
360 }
361 }
363 /* Dialog handling for base select dialog
364 * Check if base was selected, dialog aborted etc */
365 if(is_object($this->dialog)){
367 $this->dialog->save_object();
368 if($this->baseSelection){
369 if($this->dialog->isClosed()){
370 $this->dialog = false;
371 $this->baseSelection = false;
372 }elseif($this->dialog->isSelected()){
374 /* A new base was selected, check if it is a valid one */
375 $tmp = $this->get_allowed_bases();
376 if(isset($tmp[$this->dialog->isSelected()])){
377 $this->base = $this->dialog->isSelected();
378 }
380 $this->dialog= false;
381 $this->baseSelection = false;
382 }else{
383 return($this->dialog->execute());
384 }
385 }
386 }
388 /* Fill templating stuff */
389 $smarty->assign("bases", $this->get_allowed_bases());
390 $smarty->assign("base_select", $this->base);
392 /* Assign attributes */
393 foreach ($this->attributes as $attr){
394 $smarty->assign("$attr", $this->$attr);
395 }
397 if(isset($_POST['AddUser'])){
398 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
399 }
400 if(isset($_POST['AddGroup'])){
401 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
402 }
403 if(isset($_POST['AddAdminUser'])){
404 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
405 }
406 if(isset($_POST['AddAdminGroup'])){
407 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
408 }
410 /* Display ppd configure/select dialog */
411 if(isset($_POST['EditDriver'])){
412 if($this->PPDdialogToSave){
413 $this->dialog = $this->PPDdialogToSave;
414 }else{
415 $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
416 $this->dialog->cn= $this->cn;
417 }
418 }
420 /* remove ppd */
421 if(isset($_POST['RemoveDriver'])){
422 $this->gotoPrinterPPD = array();
423 $this->PPDdialogToSave = NULL;
424 }
426 /* Close ppd dialog */
427 if(isset($_POST['ClosePPD'])){
428 unset($this->dialog);
429 $this->dialog=NULL;
430 }
432 /* Save selected ppd */
433 if(isset($_POST['SavePPD'])){
434 $this->dialog->save_object();
435 if(count($this->dialog->check())){
436 foreach($this->dialog->check() as $msg){
437 print_red($msg);
438 }
439 }else{
440 $this->gotoPrinterPPD = array();
441 $this->gotoPrinterPPD = $this->dialog->save();
442 $this->PPDdialogToSave = $this->dialog;
443 unset($this->dialog);
444 $this->dialog=NULL;
445 }
446 }
448 /* Member management, delete user / group / admin ..*/
449 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
450 foreach($_POST['UserMember'] as $mem){
451 $this->DelMember('AddUser',$mem);
452 }
453 }
455 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
456 foreach($_POST['UserMember'] as $mem){
457 $this->DelMember('AddGroup',$mem);
458 }
459 }
461 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
462 foreach($_POST['AdminMember'] as $mem){
463 $this->DelMember('AddAdminUser',$mem);
464 }
465 }
467 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
468 foreach($_POST['AdminMember'] as $mem){
469 $this->DelMember('AddAdminGroup',$mem);
470 }
471 }
473 /* Abort user / group adding dialog */
474 if(isset($_POST['PrinterCancel'])){
475 unset($this->dialog);
476 $this->dialog= NULL;
477 }
479 /* Save selected users / groups */
480 if(isset($_POST['PrinterSave'])){
481 $this->dialog->save_object();
482 if(count($this->dialog->check())){
483 foreach($this->dialog->check() as $msg){
484 print_red($msg);
485 }
486 }else{
487 $data= $new = $this->dialog->save();
488 unset($data['type']);
489 foreach($data as $mem){
490 $this->AddMember($new['type'], $mem['dn']);
491 }
492 unset($this->dialog);
493 $this->dialog=NULL;
494 }
495 }
497 /* Display dialog, if there is currently one open*/
498 if($this->dialog != NULL){
499 $this->dialog->save_object();
500 $display = $this->dialog->execute();
501 return $display;
502 }
504 /* Parse selected ppd file */
505 require_once ("class_ppdManager.inc");
506 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
508 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
509 if(!preg_match("/\/$/",$path)){
510 $path = $path."/";
511 }
513 $ppdManager= new ppdManager($path);
514 if(!empty($this->gotoPrinterPPD)){
515 if((!file_exists($path.$this->gotoPrinterPPD))){
516 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD)."</b>");
517 }else{
518 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
519 }
520 }else{
521 $smarty->assign("driverInfo", _("not defined"));
522 }
523 }else{
524 $smarty->assign("driverInfo",_("can't get ppd informations."));
525 }
527 /* Create user & admin user list */
528 $list=$this->generateList();
529 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
530 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
532 asort($userlist);
533 asort($adminlist);
535 if(!preg_match("/Printer/i",$this->BelongsTo)){
536 if(preg_match("/Terminal/i",$this->BelongsTo)){
537 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
538 }else{
539 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
540 }
541 $smarty->assign("cnACL" , $this->getacl("cn",true));
542 }else{
543 $smarty->assign("desc" ,"");
544 }
545 $smarty->assign("UserMember" ,$this->UserMember);
546 $smarty->assign("UserMembers" ,$userlist);
547 $smarty->assign("UserMemberKeys",array_flip($userlist));
549 $smarty->assign("AdminMember" ,$this->AdminMember);
550 $smarty->assign("AdminMembers" ,$adminlist);
551 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
552 if(preg_match("/Printer/i",$this->BelongsTo)){
553 $smarty->assign("netconfig", $this->netConfigDNS->execute());
554 } else {
555 $smarty->assign("netconfig", "");
556 }
558 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
559 }
561 function remove_from_parent()
562 {
563 /* Only remove if there was initially an account */
564 if($this->initially_was_account){
566 /* Update dn, to ensure storing as printer instead of WS / terminal
567 */
568 if(preg_match("/terminal/i",$this->BelongsTo)){
569 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
570 }
572 if(preg_match("/workstation/i",$this->BelongsTo)){
573 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
574 }
576 /* Check if this dn points to a printer, to avoid deleting something else */
577 $ldap= $this->config->get_ldap_link();
578 $ldap->cat($this->dn, array('dn',"objectClass"));
579 if(!$ldap->count()){
580 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
581 return;
582 }
584 /* Check if obejct is a printer */
585 $CheckPrinter = $ldap->fetch();
586 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
587 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
588 return;
589 }
591 /* Remove account & dns extension */
592 $this->netConfigDNS->remove_from_parent();
593 $ldap->rmdir($this->dn);
595 @log::log("remove","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
597 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
598 $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
600 /* Delete references to object groups */
601 $ldap->cd ($this->config->current['BASE']);
602 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
603 while ($ldap->fetch()){
604 $og= new ogroup($this->config, $ldap->getDN());
605 unset($og->member[$this->dn]);
606 $og->save ();
607 }
609 /* Remove previously selected ppd file.*/
610 if(!empty($this->initial_PPD)){
611 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
612 $tmp->removeModifiedPPD();
613 }
614 }
615 }
618 /* Save data to object */
619 function save_object()
620 {
621 /* Create a base backup and reset the
622 base directly after calling plugin::save_object();
623 Base will be set seperatly a few lines below */
624 $base_tmp = $this->base;
625 plugin::save_object();
626 $this->base = $base_tmp;
628 if(is_object($this->netConfigDNS)){
629 $this->netConfigDNS->save_object();
630 }
632 /* Set new base if allowed */
633 $tmp = $this->get_allowed_bases();
634 if(isset($_POST['base'])){
635 if(isset($tmp[$_POST['base']])){
636 $this->base= $_POST['base'];
637 }
638 }
639 }
641 /* Check supplied data */
642 function check()
643 {
644 /* Call common method to give check the hook */
645 $message= plugin::check();
646 if (preg_match("/printer/i",$this->BelongsTo)){
647 $message= array_merge($message, $this->netConfigDNS->check());
648 }
650 /* Don't display check messages if this is a template object */
651 if(isset($this->parent->by_object['workgeneric'])){
652 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
653 return $message;
654 }
655 }elseif(isset($this->parent->by_object['termgeneric'])){
656 if($this->parent->by_object['termgeneric']->cn == "default"){
657 return $message;
658 }
659 }
661 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
663 /* must: cn */
664 if(preg_match("/printer/i",$this->BelongsTo) && (empty($this->cn))){
665 $message[]= "The required field 'Printer name' is not set.";
666 }
668 /* must: labeledURI */
669 if(empty($this->labeledURI)){
670 $message[]= "The required field 'Printer URL' is not set.";
671 }
673 /* Check if there is already an entry with this cn*/
674 if (($this->orig_dn != $dn)&&( preg_match("/printer/i",$this->BelongsTo))){
675 $ldap= $this->config->get_ldap_link();
676 $ldap->cd ($this->base);
677 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
678 if ($ldap->count() != 0){
679 while ($attrs= $ldap->fetch()){
680 if ($attrs['dn'] != $this->orig_dn){
681 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
682 break;
683 }
684 }
685 }
686 }
688 return ($message);
689 }
692 /* Save to LDAP */
693 function save()
694 {
695 /* Update dn, to ensure storing as printer instead of WS / terminal
696 */
697 if(preg_match("/terminal/i",$this->BelongsTo)){
698 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
699 }
701 if(preg_match("/workstation/i",$this->BelongsTo)){
702 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
703 }
705 if(!$this->is_account) return;
706 if(isset($this->parent->by_object['workgeneric'])){
707 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
708 return;
709 }
710 }elseif(isset($this->parent->by_object['termgeneric'])){
711 if($this->parent->by_object['termgeneric']->cn == "default"){
712 return;
713 }
714 }
716 /* If type is still unknown, the initialisation of this printer failed, abort. */
717 if(preg_match("/unknown/i",$this->BelongsTo)){
718 return;
719 }
721 /* save ppd configuration */
722 if($this->PPDdialogToSave){
723 $this->PPDdialogToSave->save_ppd();
724 }
726 /* Remove previously selected ppd file.*/
727 if($this->initial_PPD != $this->gotoPrinterPPD){
728 if(!empty($this->initial_PPD)){
729 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
730 $tmp->removeModifiedPPD();
731 }
732 }
734 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
735 $method="https://";
736 }else{
737 $method="http://";
738 }
740 /* If no ppd is selected, remove this attribute */
741 if(!empty($this->gotoPrinterPPD)) {
742 $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
743 }else{
744 $this->gotoPrinterPPD = array();
745 }
747 $dn= $this->dn;
748 plugin::save();
749 $ldap= $this->config->get_ldap_link();
751 /* reduce objectClasses to minimun */
752 $this->attrs['objectClass']= $this->objectclasses;
754 /* Remove all empty values */
755 if ($this->orig_dn == 'new'){
756 $attrs= array();
757 foreach ($this->attrs as $key => $val){
758 if (is_array($val) && count($val) == 0){
759 continue;
760 }
761 $attrs[$key]= $val;
762 }
763 $this->attrs= $attrs;
764 }
766 /* Append printer user
767 */
768 $this->attrs['gotoUserPrinter']=array();
769 foreach($this->member['AddUser'] as $mem){
770 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
771 }
773 /* Append printer group
774 */
775 $this->attrs['gotoGroupPrinter'] = array();
776 foreach($this->member['AddGroup'] as $mem){
777 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
778 }
780 /* Append printer admin user
781 */
782 $this->attrs['gotoUserAdminPrinter'] = array();
783 foreach($this->member['AddAdminUser'] as $mem){
784 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
785 }
787 /* Append printer admin group
788 */
789 $this->attrs['gotoGroupAdminPrinter']= array();
790 foreach($this->member['AddAdminGroup'] as $mem){
791 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
792 }
794 if($this->orig_dn == 'new'){
795 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
796 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
797 unset($this->attrs[$checkVar]);
798 }
799 }
800 }else{
801 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
802 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
803 }
804 }
806 /* Ensure to create a new object */
807 if(preg_match("/ou=incoming,/",$this->orig_dn)){
808 $this->orig_dn = "new";
809 }
811 /* Move object in necessary*/
812 if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
813 $this->move($this->orig_dn, $this->dn);
814 }
816 /* Write back to ldap */
817 $ldap= $this->config->get_ldap_link();
818 $ldap->cat($this->dn);
819 if(!$ldap->count()){
820 $ldap->cd($this->config->current['BASE']);
821 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
822 $ldap->cd($this->dn);
824 /* Remove empty values */
825 foreach($this->attrs as $name => $value){
826 if(empty($value)){
827 unset($this->attrs[$name]);
828 }
829 }
831 $ldap->add($this->attrs);
832 $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
833 @log::log("create","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
834 } else {
835 $ldap->cd($this->dn);
836 $this->cleanup();
837 $ldap->modify ($this->attrs);
838 $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
839 @log::log("modify","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
840 }
841 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
843 if(preg_match("/printer/i",$this->BelongsTo)){
844 $this->netConfigDNS->cn = $this->cn;
845 $this->netConfigDNS->dn = $this->dn;
846 $this->netConfigDNS->save($this->dn);
847 }
849 /* This is a multi object. Handle tagging here... */
850 $this->handle_object_tagging();
851 }
853 function generateList(){
854 $a_return=array();
856 foreach($this->member as $type => $values){
857 $a_return[$type]=array();
858 foreach($values as $value){
859 if((preg_match("/Group/i",$type))){
860 if(!isset($value['description'])){
861 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
862 }else{
863 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
864 }
865 }else{
866 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
867 }
868 }
869 }
870 return($a_return);
871 }
873 /* Return plugin informations for acl handling
874 #FIXME FAIscript seams to ununsed within this class... */
875 function plInfo()
876 {
877 return (array(
878 "plShortName" => _("Generic"),
879 "plDescription" => _("Print generic"),
880 "plSelfModify" => FALSE,
881 "plDepends" => array(),
882 "plPriority" => 4,
883 "plSection" => array("administration"),
884 "plCategory" => array("printer" => array("description" => _("Printer"),
885 "objectClass" => "gotoPrinter"),"workstation","terminal"),
886 "plProvidedAcls"=> array(
887 "cn" => _("Name"),
888 "base" => _("Base") ,
889 "description" => _("Description"),
890 "l" => _("Location"),
891 "labeledURI" => _("LabeledURL"),
892 "gotoPrinterPPD" => _("Printer PPD"),
893 "gotoUserPrinter" => _("Permissions"))
894 ));
895 }
898 /* Delete member */
899 function DelMember($type,$id)
900 {
901 /* Check if there was a printer "dn" given, or the "cn" */
902 foreach($this->member[$type] as $key => $printer){
903 if($printer['dn'] == $id) {
904 $id = $key;
905 }
906 }
908 if(!$this->acl_is_writeable("gotoUserPrinter")){
909 print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
910 return(FALSE);
911 }
913 if(isset($this->member[$type][$id])){
914 unset($this->member[$type][$id]);
915 return(TRUE);
916 }
917 return(FALSE);
918 }
921 /* Add given obejct to members */
922 function AddMember($type,$dn)
923 {
924 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
925 if(!in_array_ics($type, $types)){
926 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
927 return(FALSE);
928 }
930 if(!$this->acl_is_writeable("gotoUserPrinter")){
931 print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
932 return(FALSE);
933 }
935 /* Get name of index attributes */
936 if(preg_match("/user/i",$type)){
937 $var = "uid";
938 }else{
939 $var = "cn";
940 }
942 $ldap = $this->config->get_ldap_link();
943 $ldap->cd($dn);
944 $ldap->cat($dn,array($var,"cn"));
945 if($ldap->count()){
947 $attrs = $ldap->fetch();
949 if(isset($attrs[$var][0])){
950 $name = $attrs[$var][0];
952 /* Check if this uid/cn is already assigned to any permission */
953 foreach($types as $ctype){
955 /* If we want to add a user, only check user/userAdmin members */
956 if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
957 continue;
958 }
960 /* If we want to add a group, only check groups/adminGroups .. */
961 if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
962 continue;
963 }
965 if(isset( $this->member[$ctype][$name])){
966 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
967 return(FALSE);
968 }
969 }
971 /* Everything is fine. So add the given object to members */
972 $this->member[$type][$attrs[$var][0]] = $attrs ;
973 }else{
974 print_a($attrs);
975 }
976 }else{
977 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
978 return(FALSE);
979 }
980 return(TRUE);
981 }
982 }
986 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
987 ?>