947c778201c42105379d63306ffede234ee70b77
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 $orig_dn = "";
23 var $UserMember ="";
24 var $UserMembers =array();
25 var $UserMemberKeys =array();
27 var $AdminMember ="";
28 var $AdminMembers =array();
29 var $AdminMemberKeys =array();
31 var $PPDdialogToSave = NULL;
32 var $BelongsTo = "unknown"; // Specifies if this is a standalone printer, or belongs to a terminal / WS
34 var $member =array();
35 var $strings = "";
36 var $dialog =NULL;
38 var $netConfigDNS;
39 var $baseSelection = false;
40 var $macAddress = "";
42 var $gotoUserAdminPrinter;
43 var $gotoGroupAdminPrinter ;
44 var $gotoGroupPrinter;
45 var $gotoUserPrinter ;
47 /* attribute list for save action */
48 var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
49 "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
50 var $objectclasses = array("top", "gotoPrinter");
52 function printgeneric ($config, $dn,$parent)
53 {
54 $this->config = $config;
55 $this->dn = $dn;
57 /* If parent was posted(the tabs object) we can detect the printer type. */
58 if($parent){
59 $this->parent = $parent;
60 $this->getTypeOfPrinter();
61 }else{
62 $this->BelongsTo = "unknown";
63 return;
64 }
66 /* Update dn, to ensure storing as printer instead of WS / terminal */
67 if($this->BelongsTo == "Terminal"){
68 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
69 }
71 if($this->BelongsTo == "Workstation"){
72 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
73 }
75 $this->orig_dn = $this->dn;
77 /* Get printer settings, possibly dn has changed */
78 plugin::plugin ($config, $this->dn);
80 /* Get is_account initially_was_account status */
81 $this->getTypeOfPrinter(true);
83 /* set orig dn to new if object is new */
84 $ldap= $this->config->get_ldap_link();
85 $ldap->cat($this->dn, array('dn'));
86 if(!$ldap->count()){
87 $this->orig_dn = "new";
88 }
90 /* create dns object */
91 $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
93 /* Set base */
94 if ($this->dn == "new"){
95 $ui= get_userinfo();
96 $this->base= dn2base($ui->dn);
97 $this->cn= "";
98 } else {
100 /* Set base and check if the extracted base exists */
101 if(preg_match("/ou=incoming,/",$this->dn)){
102 $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
103 }else{
104 $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
105 }
107 if(!isset($this->config->idepartments[$this->base])){
108 print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
109 $this->base = $_SESSION['CurrentMainBase'];
110 }
111 }
113 /* Extract selected ppd */
114 if(isset($this->gotoPrinterPPD)){
115 $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
116 }
118 /* Prepare different member types */
119 foreach(array("AddUser" =>"gotoUserPrinter",
120 "AddGroup" =>"gotoGroupPrinter",
121 "AddAdminUser" =>"gotoUserAdminPrinter",
122 "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
124 /* $this->members contains all members */
125 $this->member[$type]=array();
127 if (isset($this->attrs[$attr]['count'])) {
128 unset($this->attrs[$attr]['count']);
129 }
131 if(isset($this->attrs[$attr])){
132 foreach($this->attrs[$attr] as $mem){
133 if(preg_match("/Group/",$type)){
134 $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
135 if($ldap->count()){
136 $entry = $ldap->fetch();
137 $this->member[$type][$entry['cn'][0]]=$entry;
138 }
139 }else{
140 $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
141 if($ldap->count()){
142 $entry = $ldap->fetch();
143 $this->member[$type][$entry['uid'][0]]=$entry;
144 }
145 }
146 }
147 }
148 }
149 }
152 /* Detect type of printer.
153 * Printer can be stand alone, belong to a workstation or belong to a terminal.
154 * We can detect the type printer type when comparing the tabs objects
155 */
156 function getTypeOfPrinter($UpdateAccountStatus = false)
157 {
158 /* Disable account as default
159 */
160 $this->is_account = $this->initially_was_account = false;
162 /* Detect type of printer via parent tabs.
163 */
164 if(isset($this->parent->by_object['workgeneric'])){
166 /* Exclude templates
167 */
168 $this->cn = $this->parent->by_object['workgeneric']->cn;
169 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
170 $this->BelongsTo = "WorkstationTemplate";
171 }else{
172 $this->BelongsTo = "Workstation";
173 }
174 }elseif(isset($this->parent->by_object['termgeneric'])){
176 /* Exclude templates
177 */
178 $this->cn = $this->parent->by_object['termgeneric']->cn;
179 if($this->parent->by_object['termgeneric']->cn == "default"){
180 $this->BelongsTo = "TerminalTemplate";
181 }else{
182 $this->BelongsTo = "Terminal";
183 }
184 }elseif(isset($this->parent->by_name['printgeneric'])){
185 $this->BelongsTo = "Printer";
186 }
188 if($UpdateAccountStatus){
190 /* Set is_account / was account
191 */
192 if($this->dn == "new"){
193 $this->initially_was_account = false;
194 }
196 /* If is printer it must be a true account.
197 */
198 if($this->BelongsTo == "Printer"){
199 $this->is_account = true;
200 }
202 /* Update dn, to ensure storing as printer instead of WS / terminal
203 */
204 if($this->BelongsTo == "Terminal"){
205 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
206 }
208 if($this->BelongsTo == "Workstation"){
209 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
210 }
212 /* Detect if this is a valid printer account;
213 */
214 //FIXME: do we need to do this? we've already everything we need in $this->attrs...
215 $ldap = $this->config->get_ldap_link();
216 $ldap->cat($this->dn, array('objectClass'));
218 if($ldap->count()){
219 $attrs = $ldap->fetch();
220 if(in_array("gotoPrinter",$attrs['objectClass'])){
221 $this->initially_was_account = true;
222 $this->is_account = true;
223 }else{
224 $this->is_account = false;
225 }
226 }
227 }
228 }
230 function execute()
231 {
232 /* Call parent execute */
233 plugin::execute();
235 /* If type of printer couldn't be detected (because of missing parent object in construction)
236 * hide this tab.
237 */
238 if($this->BelongsTo == "unknown"){
239 $display= $this->show_enable_header(_("Add printer extension"),
240 _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
241 return($display);
242 }
244 /* Templates can't have printer extensions
245 */
246 if($this->BelongsTo == "WorkstationTemplate"){
247 $display= $this->show_enable_header(_("Add printer extension"),
248 _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
249 return($display);
250 }
251 if($this->BelongsTo == "TerminalTemplate"){
252 $display= $this->show_enable_header(_("Add printer extension"),
253 _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
254 return($display);
255 }
257 /* Get cn from base object */
258 if($this->BelongsTo == "Workstation"){
259 $this->cn = $this->parent->by_object['workgeneric']->cn;
260 }
261 if($this->BelongsTo == "Terminal"){
262 $this->cn = $this->parent->by_object['termgeneric']->cn;
263 }
265 $smarty= get_smarty();
267 /* Assign acls */
268 $tmp = $this->plInfo();
269 foreach($tmp['plProvidedAcls'] as $name => $translation){
270 $smarty->assign($name."ACL", $this->getacl($name));
271 }
273 /* Create base acls */
274 $baseACL = $this->getacl("base");
275 if(!$this->acl_is_moveable()) {
276 $baseACL = preg_replace("/w/","",$baseACL);
277 }
278 $smarty->assign("baseACL", $baseACL);
281 $display="";
283 /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
284 if($this->BelongsTo == "Printer"){
285 $smarty->assign("StandAlone",true);
286 }else{
287 $smarty->assign("StandAlone",false);
288 }
290 /* Do we need to flip is_account state? */
291 if (isset($_POST['modify_state'])){
292 $this->is_modified = true;
293 $this->is_account= !$this->is_account;
294 }
296 /* Do we represent a valid printer? */
297 if (!$this->is_account && $this->parent == NULL){
298 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
299 _("This 'dn' has no printer features.")."</b>";
300 return($display);
301 }
303 /* If this is a WS / Terminal depending printer, display account state button */
304 if($this->BelongsTo != "Printer"){
305 if((empty($this->cn)) && ($this->dn != "new")){
306 $display= $this->show_enable_header(_("Add printer extension"),
307 _("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);
308 $this->is_account= false;
309 return $display;
310 }
312 if (($this->is_account)){
313 if($this->BelongsTo=="Workstation"){
314 $display= $this->show_disable_header(_("Remove printer extension"),
315 _("This workstation has printer extension enabled.You can disable it by clicking below."));
316 }elseif($this->BelongsTo=="Terminal"){
317 $display= $this->show_disable_header(_("Remove printer extension"),
318 _("This terminal has printer extension enabled. You can disable it by clicking below."));
319 }
320 }else{
321 if($this->BelongsTo=="Workstation"){
322 $display= $this->show_disable_header(_("Add printer extension"),
323 _("This workstation has printer extension disabled. You can enable it by clicking below."));
324 }elseif($this->BelongsTo=="Terminal"){
325 $display= $this->show_enable_header(_("Add printer extension"),
326 _("This terminal has printer extension disabled. You can enable it by clicking below."));
327 }
328 return ($display);
329 }
330 }
332 /* Base select dialog */
333 $once = true;
334 foreach($_POST as $name => $value){
335 if(preg_match("/^chooseBase/",$name) && $once){
336 $once = false;
337 $this->dialog = new baseSelectDialog($this->config,$this);
338 $this->dialog->setCurrentBase($this->base);
339 $this->baseSelection = true;
340 }
341 }
343 /* Dialog handling for base select dialog
344 * Check if base was selected, dialog aborted etc */
345 if(is_object($this->dialog)){
347 $this->dialog->save_object();
348 if($this->baseSelection){
349 if($this->dialog->isClosed()){
350 $this->dialog = false;
351 $this->baseSelection = false;
352 }elseif($this->dialog->isSelected()){
353 $this->base = $this->dialog->isSelected();
354 $this->dialog= false;
355 $this->baseSelection = false;
356 }else{
357 return($this->dialog->execute());
358 }
359 }
360 }
362 /* Fill templating stuff */
363 $smarty->assign("bases", $this->config->idepartments);
364 $smarty->assign("base_select", $this->base);
366 /* Assign attributes */
367 foreach ($this->attributes as $attr){
368 $smarty->assign("$attr", $this->$attr);
369 }
371 if(isset($_POST['AddUser'])){
372 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
373 }
374 if(isset($_POST['AddGroup'])){
375 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
376 }
377 if(isset($_POST['AddAdminUser'])){
378 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
379 }
380 if(isset($_POST['AddAdminGroup'])){
381 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
382 }
384 /* Display ppd configure/select dialog */
385 if(isset($_POST['EditDriver'])){
386 if($this->PPDdialogToSave){
387 $this->dialog = $this->PPDdialogToSave;
388 }else{
389 $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
390 }
391 }
393 /* remove ppd */
394 if(isset($_POST['RemoveDriver'])){
395 $this->gotoPrinterPPD = array();
396 $this->PPDdialogToSave = NULL;
397 }
399 /* Close ppd dialog */
400 if(isset($_POST['ClosePPD'])){
401 unset($this->dialog);
402 $this->dialog=NULL;
403 }
405 /* Save selected ppd */
406 if(isset($_POST['SavePPD'])){
407 $this->dialog->save_object();
408 if(count($this->dialog->check())){
409 foreach($this->dialog->check() as $msg){
410 print_red($msg);
411 }
412 }else{
413 $this->gotoPrinterPPD = array();
414 $this->gotoPrinterPPD = $this->dialog->save();
415 $this->PPDdialogToSave = $this->dialog;
416 unset($this->dialog);
417 $this->dialog=NULL;
418 }
419 }
421 /* Member management, delete user / group / admin ..*/
422 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
423 foreach($_POST['UserMember'] as $mem){
424 $this->DelMember('AddUser',$mem);
425 }
426 }
428 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
429 foreach($_POST['UserMember'] as $mem){
430 $this->DelMember('AddGroup',$mem);
431 }
432 }
434 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
435 foreach($_POST['AdminMember'] as $mem){
436 $this->DelMember('AddAdminUser',$mem);
437 }
438 }
440 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
441 foreach($_POST['AdminMember'] as $mem){
442 $this->DelMember('AddAdminGroup',$mem);
443 }
444 }
446 /* Abort user / group adding dialog */
447 if(isset($_POST['PrinterCancel'])){
448 unset($this->dialog);
449 $this->dialog= NULL;
450 }
452 /* Save selected users / groups */
453 if(isset($_POST['PrinterSave'])){
454 $this->dialog->save_object();
455 if(count($this->dialog->check())){
456 foreach($this->dialog->check() as $msg){
457 print_red($msg);
458 }
459 }else{
460 $data= $new = $this->dialog->save();
461 unset($data['type']);
462 foreach($data as $mem){
463 $this->AddMember($new['type'], $mem['dn']);
464 }
465 unset($this->dialog);
466 $this->dialog=NULL;
467 }
468 }
470 /* Display dialog, if there is currently one open*/
471 if($this->dialog != NULL){
472 $this->dialog->save_object();
473 $display = $this->dialog->execute();
474 return $display;
475 }
477 /* Parse selected ppd file */
478 require_once ("class_ppdManager.inc");
479 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
481 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
482 if(!preg_match("/\/$/",$path)){
483 $path = $path."/";
484 }
486 $ppdManager= new ppdManager($path);
487 if(!empty($this->gotoPrinterPPD)){
488 if((!file_exists($path.$this->gotoPrinterPPD))){
489 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
490 }else{
491 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
492 }
493 }else{
494 $smarty->assign("driverInfo", _("not defined"));
495 }
496 }else{
497 $smarty->assign("driverInfo",_("can't get ppd informations."));
498 }
500 /* Create user & admin user list */
501 $list=$this->generateList();
502 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
503 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
505 asort($userlist);
506 asort($adminlist);
508 if($this->BelongsTo != "Printer"){
509 if($this->BelongsTo == "Terminal"){
510 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
511 }else{
512 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
513 }
514 $smarty->assign("cnACL" , $this->getacl("cn",true));
515 }else{
516 $smarty->assign("desc" ,"");
517 }
518 $smarty->assign("UserMember" ,$this->UserMember);
519 $smarty->assign("UserMembers" ,$userlist);
520 $smarty->assign("UserMemberKeys",array_flip($userlist));
522 $smarty->assign("AdminMember" ,$this->AdminMember);
523 $smarty->assign("AdminMembers" ,$adminlist);
524 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
525 if($this->BelongsTo == "Printer"){
526 $smarty->assign("netconfig", $this->netConfigDNS->execute());
527 } else {
528 $smarty->assign("netconfig", "");
529 }
531 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
532 }
534 function remove_from_parent()
535 {
536 /* Only remove if there was initially an account */
537 if($this->initially_was_account){
539 /* Update dn, to ensure storing as printer instead of WS / terminal
540 */
541 if($this->BelongsTo == "Terminal"){
542 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
543 }
545 if($this->BelongsTo == "Workstation"){
546 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
547 }
549 /* Check if this dn points to a printer, to avoid deleting something else */
550 $ldap= $this->config->get_ldap_link();
551 $ldap->cat($this->dn, array('dn',"objectClass"));
552 if(!$ldap->count()){
553 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
554 return;
555 }
557 /* Check if obejct is a printer */
558 $CheckPrinter = $ldap->fetch();
559 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
560 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
561 return;
562 }
564 /* Remove account & dns extension */
565 $this->netConfigDNS->remove_from_parent();
566 $ldap->rmdir($this->dn);
567 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
568 $this->handle_post_events("remove");
570 /* Delete references to object groups */
571 $ldap->cd ($this->config->current['BASE']);
572 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
573 while ($ldap->fetch()){
574 $og= new ogroup($this->config, $ldap->getDN());
575 unset($og->member[$this->dn]);
576 $og->save ();
577 }
578 }
579 }
582 /* Save data to object */
583 function save_object()
584 {
585 plugin::save_object();
586 $this->netConfigDNS->save_object();
588 /* Save base, since this is no LDAP attribute */
589 if(isset($_POST['base'])){
590 $this->set_acl_base('dummy,'.$_POST['base']);
591 if($this->acl_is_moveable()){
593 if(isset($this->config->idepartments[$_POST['base']])){
594 $this->base = $_POST['base'];
595 if ($_POST['base'] != $this->base){
596 $this->is_modified= TRUE;
597 }
598 }
599 }else{
601 print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
602 $this->set_acl_base('dummy,'.$this->base);
603 }
604 }
605 }
607 /* Check supplied data */
608 function check()
609 {
610 /* Call common method to give check the hook */
611 $message= plugin::check();
612 if ($this->BelongsTo == 'printer'){
613 $message= array_merge($message, $this->netConfigDNS->check());
614 }
616 /* Don't display check messages if this is a template object */
617 if(isset($this->parent->by_object['workgeneric'])){
618 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
619 return $message;
620 }
621 }elseif(isset($this->parent->by_object['termgeneric'])){
622 if($this->parent->by_object['termgeneric']->cn == "default"){
623 return $message;
624 }
625 }
627 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
629 /* must: cn */
630 if(($this->BelongsTo == "Printer") && (empty($this->cn))){
631 $message[]= "The required field 'Printer name' is not set.";
632 }
634 if($this->BelongsTo == "Printer"){
635 if($this->acl_is_createable()){
636 $message[]= _("You have no permissions to create a printer on this 'Base'.");
637 }
638 }
641 /* must: labeledURI */
642 if(empty($this->labeledURI)){
643 $message[]= "The required field 'Printer URL' is not set.";
644 }
646 /* Check if there is already an entry with this cn*/
647 if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
648 $ldap= $this->config->get_ldap_link();
649 $ldap->cd ($this->base);
650 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
651 if ($ldap->count() != 0){
652 while ($attrs= $ldap->fetch()){
653 if ($attrs['dn'] != $this->orig_dn){
654 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
655 break;
656 }
657 }
658 }
659 }
661 return ($message);
662 }
665 /* Save to LDAP */
666 function save()
667 {
668 /* Update dn, to ensure storing as printer instead of WS / terminal
669 */
670 if($this->BelongsTo == "Terminal"){
671 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
672 }
674 if($this->BelongsTo == "Workstation"){
675 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
676 }
678 if(!$this->is_account) return;
679 if(isset($this->parent->by_object['workgeneric'])){
680 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
681 return;
682 }
683 }elseif(isset($this->parent->by_object['termgeneric'])){
684 if($this->parent->by_object['termgeneric']->cn == "default"){
685 return;
686 }
687 }
689 /* If type is still unknown, the initialisation of this printer failed, abort. */
690 if($this->BelongsTo == "unknown"){
691 return;
692 }
694 /* save ppd configuration */
695 if($this->PPDdialogToSave){
696 $this->PPDdialogToSave->save_ppd();
697 }
699 $dn= $this->dn;
700 plugin::save();
701 $ldap= $this->config->get_ldap_link();
703 /* reduce objectClasses to minimun */
704 $this->attrs['objectClass']= $this->objectclasses;
706 /* Remove all empty values */
707 if ($this->orig_dn == 'new'){
708 $attrs= array();
709 foreach ($this->attrs as $key => $val){
710 if (is_array($val) && count($val) == 0){
711 continue;
712 }
713 $attrs[$key]= $val;
714 }
715 $this->attrs= $attrs;
716 }
718 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
719 $method="https://";
720 }else{
721 $method="http://";
722 }
724 $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
726 /* Append printer user
727 */
728 $this->attrs['gotoUserPrinter']=array();
729 foreach($this->member['AddUser'] as $mem){
730 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
731 }
733 /* Append printer group
734 */
735 $this->attrs['gotoGroupPrinter'] = array();
736 foreach($this->member['AddGroup'] as $mem){
737 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
738 }
740 /* Append printer admin user
741 */
742 $this->attrs['gotoUserAdminPrinter'] = array();
743 foreach($this->member['AddAdminUser'] as $mem){
744 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
745 }
747 /* Append printer admin group
748 */
749 $this->attrs['gotoGroupAdminPrinter']= array();
750 foreach($this->member['AddAdminGroup'] as $mem){
751 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
752 }
754 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
755 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
756 }
758 if($this->orig_dn == 'new'){
759 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
760 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
761 unset($this->attrs[$checkVar]);
762 }
763 }
764 }
766 /* Move object in necessary*/
767 if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
768 $this->move($this->orig_dn, $this->dn);
769 }
771 /* Write back to ldap */
772 $ldap= $this->config->get_ldap_link();
773 $ldap->cat($this->dn);
774 if(!$ldap->count()){
775 $ldap->cd($this->config->current['BASE']);
776 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
777 $ldap->cd($this->dn);
778 $ldap->add($this->attrs);
779 $this->handle_post_events("add");
780 } else {
781 $ldap->cd($this->dn);
782 $this->cleanup();
783 $ldap->modify ($this->attrs);
784 $this->handle_post_events("modify");
785 }
786 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
788 if($this->BelongsTo == "Printer"){
789 $this->netConfigDNS->cn = $this->cn;
790 $this->netConfigDNS->dn = $this->dn;
791 $this->netConfigDNS->save($this->dn);
792 }
794 /* Optionally execute a command after we're done */
795 $this->postcreate();
797 /* This is a multi object. Handle tagging here... */
798 $this->handle_object_tagging();
799 }
801 function generateList(){
802 $a_return=array();
803 foreach($this->member as $type => $values){
804 $a_return[$type]=array();
805 foreach($values as $value){
806 if((preg_match("/Group/i",$type))){
807 if(!isset($value['description'])){
808 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
809 }else{
810 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
811 }
812 }else{
813 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
814 }
815 }
816 }
817 return($a_return);
818 }
820 /* Return plugin informations for acl handling
821 #FIXME FAIscript seams to ununsed within this class... */
822 function plInfo()
823 {
824 return (array(
825 "plShortName" => _("Generic"),
826 "plDescription" => _("Print generic"),
827 "plSelfModify" => FALSE,
828 "plDepends" => array(),
829 "plPriority" => 0,
830 "plSection" => array("administration"),
831 "plCategory" => array("printer" => array("description" => _("Printer"),
832 "objectClass" => "gotoPrinter")),
833 "plProvidedAcls"=> array(
834 "cn" => _("Name"),
836 "description" => _("Description"),
837 "l" => _("Location"),
838 "labeledURI" => _("LabeledURL"),
839 "gotoPrinterPPD" => _("Printer PPD"),
840 "gotoUserPrinter" => _("Permissions"))
841 ));
842 }
845 /* Delete member */
846 function DelMember($type,$id)
847 {
848 /* Check if there was a printer "dn" given, or the "cn" */
849 foreach($this->member[$type] as $key => $printer){
850 if($printer['dn'] == $id) {
851 $id = $key;
852 }
853 }
855 if(!$this->acl_is_writeable("gotoUserPrinter")){
856 print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
857 return(FALSE);
858 }
860 if(isset($this->member[$type][$id])){
861 unset($this->member[$type][$id]);
862 return(TRUE);
863 }
864 return(FALSE);
865 }
868 /* Add given obejct to members */
869 function AddMember($type,$dn)
870 {
871 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
872 if(!in_array_ics($type, $types)){
873 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
874 return(FALSE);
875 }
877 if(!$this->acl_is_writeable("gotoUserPrinter")){
878 print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
879 return(FALSE);
880 }
882 /* Get name of index attributes */
883 if(preg_match("/user/i",$type)){
884 $var = "uid";
885 }else{
886 $var = "cn";
887 }
889 $ldap = $this->config->get_ldap_link();
890 $ldap->cd($dn);
891 $ldap->cat($dn,array($var));
892 if($ldap->count()){
894 $attrs = $ldap->fetch();
896 if(isset($attrs[$var][0])){
897 $name = $attrs[$var][0];
899 /* Check if this uid/cn is already assigned to any permission */
900 foreach($types as $ctype){
902 /* If we want to add a user, only check user/userAdmin members */
903 if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
904 continue;
905 }
907 /* If we want to add a group, only check groups/adminGroups .. */
908 if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
909 continue;
910 }
912 if(isset( $this->member[$ctype][$name])){
913 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
914 return(FALSE);
915 }
916 }
918 /* Everything is fine. So add the given object to members */
919 $this->member[$type][$attrs[$var][0]] = $attrs ;
920 }else{
921 print_a($attrs);
922 }
923 }else{
924 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
925 return(FALSE);
926 }
927 return(TRUE);
928 }
929 }
933 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
934 ?>