#!/usr/bin/perl # Drakwizard # Copyright (C) 2002 MandrakeSoft Mael Dodin (mdodin@mandrakesoft.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use lib qw(/usr/lib/libDrakX); use strict; use vars qw($Wizard_title $Wizard_pix_up $lib_script $perl_module %variable $in $rpm %chooser_hash $welcome $perl_module_name $verbose %description); use XML::Parser; use standalone; use interactive; use MDK::Common::Func; use common; use POSIX; use Locale::gettext(); #- I18N. setlocale(LC_ALL, ""); Locale::gettext::textdomain("drakwizard"); my $in = 'interactive'->vnew('su', 'default'); $::direct = /-direct/; $::Wizard_no_previous = 1; $::Wizard_title = "Drakwizard"; $::isWizard = 1; my $standalone = 1; if (!defined($ARGV[0])) { my $prefix = "/usr/share/wizards/"; my %wiz = ( 1 => [$prefix."web_wizard/web.wiz", "Apache"], 2 => [$prefix."dhcp_wizard/dhcp.wiz", "Dhcp"], 3 => [$prefix."dns_wizard/dns.wiz", "Dns"], 4 => [$prefix."news_wizard/news.wiz", "News"], 5 => [$prefix."postfix_wizard/postfix.wiz", "Postfix"], 6 => [$prefix."ftp_wizard/ftp.wiz", "Proftpd"], 7 => [$prefix."samba_wizard/samba.wiz", "Samba"], 8 => [$prefix."proxy_wizard/proxy.wiz", "Squid"], 9 => [$prefix."time_wizard/time.wiz", "Time"] ); $in->ask_from( _("Drakwizard wizard selection"), _("Please select a wizard"), [{ val => \$ARGV[0], list => [sort keys %wiz], format => sub { $wiz{$_}[1] }}] ); $ARGV[0] = $wiz{$ARGV[0]}[0]; } my $o = []; my $xmltree = XML::Parser->new(Style => 'Tree')->parsefile($ARGV[0]); get_parameter($o, $xmltree); if (("@ARGV" =~ /--debug/)) { $::verbose = 1; navigation($o, $o->[0]); } else { no warnings; $::verbose = 0; eval { navigation($o, $o->[0]) }; } $in->exit; sub translate { my ($format, @params) = @_; !$format and return; sprintf(Locale::gettext::gettext($format), @params); } sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 } sub get_parameter { my ($o, $tree, $tag ,$page) = @_; foreach my $leaf (@$tree) { if (ref($leaf) eq 'ARRAY') { $page = get_parameter($o, $leaf, $tag, $page); } elsif (ref($leaf) eq 'HASH') { my $common_freetext_chooser; my %actions = ( Wizard => sub { ($Wizard_title, $lib_script, $perl_module, $rpm, $Wizard_pix_up) = @{$leaf}{qw(wizardTitle libScript perlModule rpm defaultImage)}; if ($perl_module) { ($::perl_module_name) = ($perl_module =~ /.*\/(.*)\.pm/); require $perl_module; } if ($rpm) { if (!$in->do_pkgs->is_installed($rpm)) { $in->ask_okcancel("error", "$rpm is not installed\nClick \"Ok\" to install or \"Cancel\" to quit") and $in->do_pkgs->install($rpm) or $in->exit; } } }, Variable => sub { $variable{$leaf->{name}} = $leaf->{shellVariable}; $ENV{$leaf->{shellVariable}} = $leaf->{defaultValue}; }, Page => sub { !$welcome and $welcome = $page; my $old_page = $page; push @$o, $page = { %$leaf }; $old_page->{next_page} = $page; if ($leaf->{canBack} =~ /.*false.*/) { $page->{no_prev} = 1} if ($leaf->{canCancel} =~ /.*false.*/) { $page->{no_cancel} = 1} if ($leaf->{nextFinish} =~ /.*true.*/) { $page->{finish} = 1} }, Target => sub { $page->{Target}->{jumpIndex}->{$leaf->{jumpIndex}} = $leaf->{targetName}; }, Info => sub { # This is to avoid monospaced text to be interpolated $leaf->{helpText} = translate($leaf->{helpText}); if ($leaf->{fontName} eq "Monospaced") { chomp($leaf->{helpText}); $leaf->{helpText} = $leaf->{helpText} ? "$leaf->{helpText}\n$leaf->{helpText}" : "$leaf->{helpText}\n"; } $page->{info} = $leaf->{helpText} ? "$page->{info}\n$leaf->{helpText}" : "$page->{info}\n"; if ($leaf->{fillScript}) { $page->{info} .= `source $lib_script; $leaf->{fillScript}`; } # XML compatibility $page->{info} =~ s/\\\'/\'/g; $page->{info} =~ s/\\q/\"/g; $page->{info} =~ s/\\a/\&/g; $page->{info} =~ s/\\n/\n/g; }, Freetext => $common_freetext_chooser = sub { push @{$page->{freetext}}, { %$leaf, main_order => (($tag eq 'Chooser') ? 'combo' : ($tag eq 'Boolean') ? 'bool' : ($leaf->{editable} eq 'true') ? 'entry' : 'field')}; $leaf->{fillScript} =~ s/\\q/\"/g; }, Chooser => \&$common_freetext_chooser, Boolean => \&$common_freetext_chooser, Option => sub { push @{${$page->{freetext}}[-1]->{Option}}, $leaf->{description}; $chooser_hash{$leaf->{description}} = $leaf->{value}; $description{$leaf->{value}} = $leaf->{description}; }); $actions{$tag} and &{$actions{$tag}}; }elsif($leaf=~ /\w\D/){ $tag = $leaf; } } $page; } sub find_page { my ($o, $name) = @_; $_->{name} eq $name and return $_ foreach @$o; } sub display { my ($o, $page) = @_; if ($page->{no_prev} || $page->{name} eq $welcome->{name}) { $::Wizard_no_previous = 1; } if ($page->{finish}) { $::Wizard_finished = 1; $::Wizard_no_cancel = 1; } if ($page->{nextFinish} eq 'true') { $::Wizard_no_previous = 1; $in->ask_okcancel(translate($page->{name}), translate($page->{info})) or quit_global($in, 0); die; } elsif (!$page->{freetext}) { $in->ask_okcancel(translate($page->{name}), translate($page->{info})) or navigation($o, $page->{old_page}); } else { my $valeur; my @liste; my @data = map { if ($_->{main_order} eq 'combo') { if($_->{fillScript}){ @liste = (); $valeur = `. $lib_script && $_->{fillScript}`; while( $valeur =~ /(.+)\n/g){ push @liste, $1; $chooser_hash{$1} = $1; } } else { @liste = @{$_->{Option}}; } } if ($_->{main_order} eq 'entry' and $_->{fillScript}) { $ENV{$variable{$_->{variableName}}} = `. $lib_script && $_->{fillScript}`; } elsif (!$ENV{$variable{$_->{variableName}}} && $_->{main_order} eq 'entry' && $_->{fillfunc}) { $ENV{$variable{$_->{variableName}}} = $::{$perl_module_name."::"}{"$_->{fillfunc}"}->(); } chomp($ENV{$variable{$_->{variableName}}}); ($_->{main_order} eq 'entry') ? { label => translate($_->{helpText}), val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order} } : ($_->{main_order} eq 'bool') ? { val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order}, text => translate($_->{helpText}, advanced => 1) } : ($_->{main_order} eq 'field') ? { val => $description{$ENV{$variable{$_->{variableName}}}}? $description{$ENV{$variable{$_->{variableName}}}} : $ENV{$variable{$_->{variableName}}}, label => $_->{helpText} } : { label => $_->{helpText}, val => \$ENV{$variable{$_->{variableName}}}, list => [@liste], type => $_->{main_order} }; } @{$page->{freetext}}; if($page->{executionLevel} eq 'NORMAL') { $in->ask_from(translate($page->{name}), translate($page->{info}), \@data) or navigation($o, $page->{old_page}); foreach(@{$page->{freetext}}) { if($_->{main_order} eq 'bool') { $ENV{$variable{$_->{variableName}}} = $ENV{$variable{$_->{variableName}}} ? 1 : 0; $description{$ENV{$variable{$_->{variableName}}}} = $ENV{$variable{$_->{variableName}}} ? __("enabled") : __("disabled"); } elsif ($_->{main_order} eq 'combo') { $ENV{$variable{$_->{variableName}}} = $chooser_hash{$ENV{$variable{$_->{variableName}}}}; } } } } undef $::Wizard_no_previous; } sub navigation { my ($o, $page, $previous_page) = @_; $page->{old_page} ||= $previous_page; display($o, $page); my ($next, $prev) = do { if (defined $perl_module_name && $page->{func}) { my @func_arg = split(/\s/, $page->{func}); my $modStatus = $::{$perl_module_name."::"}{"$func_arg[0]"}->(); if ($page->{Target}->{jumpIndex}) { find_page($o, $page->{Target}->{jumpIndex}->{int($modStatus)}), $page; } else { $page->{next_page}, $page->{old_page}; } } elsif ($page->{jumpScript}) { system("source $lib_script ; $page->{jumpScript}"); if ($page->{Target}->{jumpIndex}) { $? = $? >> 8; find_page($o, $page->{Target}->{jumpIndex}->{$?}), $page; } else { $page->{next_page}, $page; } } elsif ($page->{subWizard}) { my $sub_o = []; my $sub_xmltree = XML::Parser->new(Style => 'Tree')->parsefile($page->{subWizard}); get_parameter($sub_o, $sub_xmltree); eval {navigation($sub_o, $sub_o->[0]); }; $in->exit if $@ =~ /^wizcancel/; $page->{old_page}->{no_prev} = 1; $o->[0], $page, undef; } elsif ($page->{jumpPage}) { find_page($o, $page->{jumpPage}), $page; } else { $page->{next_page}, $page; } }; navigation($o, $next, $prev); } 3' href='#n113'>113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
package printer;

use diagnostics;
use strict;

use vars qw(%thedb %printer_type %printer_type_inv @papersize_type);

########################################################################################
# misc imports
########################################################################################
use Data::Dumper;
use commands;
########################################################################################
# pixel imports
########################################################################################
#
########################################################################################
# EXAMPLES AND TYPES
########################################################################################

# An entry in the 'printerdb' file, which describes each type of 
# supported printer                                              

#ex:
#StartEntry: DeskJet550
#  GSDriver: cdj550 
#  Description: {HP DeskJet 550C/560C/6xxC series}
#  About: { \
#	    This driver supports the HP inkjet printers which have \
#	    color capability using both black and color cartridges \
#	    simultaneously. Known to work with the 682C and the 694C. \
#	    Other 600 and 800 series printers may work \
#	    if they have this feature. \
#	    If your printer seems to be saturating the paper with ink, \
#	    try added an extra GS option of '-dDepletion=2'. \
#	    Ghostscript supports several optional parameters for \
#	    this driver: see the document 'devices.doc' \
#	    in the ghostscript directory under /usr/doc. \
#	  }
#  Resolution: {300} {300} {}
#  BitsPerPixel:  {3} {Normal color printing with color cartridge}
#  BitsPerPixel:  {8} {Floyd-Steinberg B&W printing for better greys}
#  BitsPerPixel: {24} {Floyd-Steinberg Color printing (best, but slow)}
#  BitsPerPixel: {32} {Sometimes provides better output than 24}
#EndEntry

my %ex_printerdb_entry = 
  (
   ENTRY    => "DeskJet550",                               #Human-readable name of the entry
   GSDRIVER => "cdj550",                                   #gs driver used by this printer
   DESCR    => "HP DeskJet 550C/560C/6xxC series",         #Single line description of printer
   ABOUT    => "
   This driver supports the HP inkjet printers which have 
   color capability using both black and color cartridges 
        ...",                                             #Lengthy description of printer
   RESOLUTION   => [                                       #List of resolutions supported
		    {
		     XDPI    => 300,
		     YDPI    => 300,
		     DESCR   => "commentaire",
		    },
		   ],
   BITSPERPIXEL => [                                       #List of color depths supported
		    {
		     DEPTH => 3,
		     DESCR => "Normal color printing with color cartridge",
		    },
		   ],
  )
;
  


# A printcap entry 
# Only represents a subset of possible options available 
# Sufficient for the simple configuration we are interested in 

# there is also some text in the template (.in) file in the spooldir

#ex:
## /etc/printcap
##
## Please don't edit this file directly unless you know what you are doing!
## Be warned that the control-panel printtool requires a very strict format!
## Look at the printcap(5) man page for more info.
##
## This file can be edited with the printtool in the control-panel.
#
###PRINTTOOL3## LOCAL uniprint NAxNA letter {} U_NECPrinwriter2X necp2x6 1
#lpname:\
#	 :sd=/var/spool/lpd/lpnamespool:\
#	 :mx#45:\
#	 :sh:\
#	 :lp=/dev/device:\
#	 :if=/var/spool/lpd/lpnamespool/filter:
###PRINTTOOL3## REMOTE st800 360x180 a4 {} EpsonStylus800 Default 1
#remote:\
#	 :sd=/var/spool/lpd/remotespool:\
#	 :mx#47:\
#	 :sh:\
#	 :rm=remotehost:\
#	 :rp=remotequeue:\
#	 :if=/var/spool/lpd/remotespool/filter:
###PRINTTOOL3## SMB la75plus 180x180 letter {} DECLA75P Default {}
#smb:\
#	 :sd=/var/spool/lpd/smbspool:\
#	 :mx#46:\
#	 :sh:\
#	 :if=/var/spool/lpd/smbspool/filter:\
#	 :af=/var/spool/lpd/smbspool/acct:\
#	 :lp=/dev/null:
###PRINTTOOL3## NCP ap3250 180x180 letter {} EpsonAP3250 Default {}
#ncp:\
#	 :sd=/var/spool/lpd/ncpspool:\
#	 :mx#46:\
#	 :sh:\
#	 :if=/var/spool/lpd/ncpspool/filter:\
#	 :af=/var/spool/lpd/ncpspool/acct:\
#	 :lp=/dev/null:


my %ex_printcap_entry = 
  (
   QUEUE    => "lpname",                            #Queue name, can have multi separated by '|'

   #if you want something different from the default
   SPOOLDIR => "/var/spool/lpd/lpnamespool/",        #Spool directory
   IF       => "/var/spool/lpd/lpnamespool/filter", #input filter
   
   # commentaire inserer dans le printcap pour que printtool retrouve ses petits
   DBENTRY      => "DeskJet670",                    #entry in printer database for this printer  

   RESOLUTION   => "NAxNA",                         #ghostscript resolution to use
   PAPERSIZE    => "letter",                        #Papersize
   BITSPERPIXEL => "necp2x6",                       #ghostscript color option                    
   CRLF         => 1 ,                            #Whether or not to do CR/LF xlation         

   TYPE         => "LOCAL",

   # LOCAL
   DEVICE   => "/dev/device",                       #Print device
   
   # REMOTE (lpd) printers only 
   REMOTEHOST   => "remotehost",                     #Remote host (not used for all entries)
   REMOTEQUEUE  => "remotequeue",                    #Queue on the remote machine                


   #SMB (LAN Manager) only 
   # in spooldir/.config
   #share='\\hostname\printername'
   #hostip=1.2.3.4
   #user='user'
   #password='passowrd'
   #workgroup='AS3'
   SMBHOST   => "hostname",                              #Server name (NMB name, can have spaces)
   SMBHOSTIP => "1.2.3.4",                               #Can optional specify and IP address for host
   SMBSHARE  => "printername",                           #Name of share on the SMB server             
   SMBUSER   => "user",                                  #User to log in as on SMB server             
   SMBPASSWD => "passowrd",                              #Corresponding password                      
   SMBWORKGROUP => "AS3",                                #SMB workgroup name                          
   AF        => "/var/spool/lpd/smbspool/acct",           #accounting filter (needed for smbprint)

   # NCP (NetWare) only 
   # in spooldir/.config
   #server=printerservername
   #queue=queuename
   #user=user
   #password=pass
   NCPHOST   => "printerservername",            #Server name (NCP name)                      
   NCPQUEUE  => "queuename",                    #Queue on server                             
   NCPUSER   => "user",                         #User to log in as on NCP server             
   NCPPASSWD => "pass",                         #Corresponding password                      
		
  )
;

########################################################################################
# INTERN CONSTANT
########################################################################################
my $PRINTER_NONE   = "NONE";
my $PRINTER_LOCAL  = "LOCAL";
my $PRINTER_LPRREM = "REMOTE";
my $PRINTER_SMB    = "SMB";
my $PRINTER_NCP    = "NCP";   

########################################################################################
# EXPORTED CONSTANT
########################################################################################


%printer_type = ("local"             => $PRINTER_LOCAL,
		    "Remote lpd"        => $PRINTER_LPRREM,
		    "SMB/Windows 95/NT" => $PRINTER_SMB,
		    "NetWare"           => $PRINTER_NCP,   
		   );                                 

%printer_type_inv = reverse %printer_type;

@papersize_type = qw(letter legal ledger a3 a4);


########################################################################################
# GLOBALS
########################################################################################

#db of all entries in the printerdb file

#if we are in an panoramix config
my $prefix = "";

# location of the printer database in an installed system
my $PRINTER_DB_FILE    = "/usr/lib/rhs/rhs-printfilters/printerdb";
my $PRINTER_FILTER_DIR = "/usr/lib/rhs/rhs-printfilters/";
my $SPOOLDIR           = "/var/spool/lpd/";

########################################################################################
# FUNCTIONS
########################################################################################

sub set_prefix($) {
    $prefix = shift;
}
#******************************************************************************
# read function
#******************************************************************************
#------------------------------------------------------------------------------
#Read the printer database from dbpath into memory
#------------------------------------------------------------------------------
sub read_printer_db(;$) {
    my ($dbpath) = @_;
    
    #$dbpath = $dbpath ? $dbpath : $DB_PRINTER_FILTER;
    $dbpath ||= $PRINTER_DB_FILE;
    $dbpath = "${prefix}$dbpath";
      

    %thedb and return;

    local *DBPATH;		#don't have to do close
    open DBPATH, "<$dbpath" or die "An error has occurred on $dbpath : $!";
      
    while (<DBPATH>) {
	if (/^StartEntry:\s(\w*)/) {
	    my $entryname = $1;
	    my $entry = {};
	      
	    $entry->{ENTRY} = $entryname;
	      
	  WHILE : 
	      while (<DBPATH>) {
		SWITCH: {
		      /GSDriver:\s*(\w*)/      and do { $entry->{GSDRIVER} = $1; last SWITCH};
		      /Description:\s*{(.*)}/  and do { $entry->{DESCR}    = $1; last SWITCH};
		      /About:\s*{(.*)}/        and do { $entry->{ABOUT}    = $1; last SWITCH};
		      /About:\s*{(.*)/ 
			and do 
			  {
			      my $string = "$1\n";
			      while (<DBPATH>) {
				  /(.*)}/ and do { $entry->{ABOUT} = $string; last SWITCH};
				  $string .= $_;
			      }
			  };
		      /Resolution:\s*{(.*)}\s*{(.*)}\s*{(.*)}/ 
			and do { push @{$entry->{RESOLUTION}}, {XDPI => $1, YDPI => $2, DESCR => $3}; last SWITCH};
		      /BitsPerPixel:\s*{(.*)}\s*{(.*)}/ 
			and do { push @{$entry->{BITSPERPIXEL}}, {DEPTH => $1, DESCR => $2};last SWITCH;};
		      /EndEntry/          and do { last WHILE;};
		  }
	      }
	    $thedb{$entryname} = $entry;
	}
    }
}


#******************************************************************************
# write functions 
#******************************************************************************

#------------------------------------------------------------------------------
# given the path queue_path, we create all the required spool directory
#------------------------------------------------------------------------------
sub create_spool_dir($) {
    my ($queue_path) = @_;
    my $complete_path = "${prefix}$queue_path";

    unless ($::testing) {
	mkdir "$complete_path", 0755
	  or die "An error has occurred - can't create $complete_path : $!";
	
	#redhat want that "drwxr-xr-x root lp"
	my $gid_lp = (getpwnam("lp"))[3];
	chown 0, $gid_lp, $complete_path 
	  or die "An error has occurred - can't chgrp $complete_path to lp $!";
    }
}

#------------------------------------------------------------------------------
#given the input spec file 'input', and the target output file 'output'
#we set the fields specified by fieldname to the values in fieldval    
#nval  is the number of fields to set                                  
#Doesnt currently catch error exec'ing sed yet                         
#------------------------------------------------------------------------------
sub create_config_file($$%) {
    my ($inputfile, $outpufile, %toreplace) = @_;
    my ($in, $out) = ("${prefix}$inputfile", "${prefix}$outpufile");
    local *OUT;
    local *IN;
    
    #TODO my $oldmask = umask 0755;

    open IN , "<$in"  or die "Can't open $in $!";
    if ($::testing) {
	open OUT, ">$out" or die "Can't open $out $!";
    } else {
	*OUT = *STDOUT
    }
    
    while ((<IN>)) {
	if (/@@@(.*)@@@/) {
	    my $chaine = $1;
	    if (!defined($toreplace{$chaine})) {
		die "I can't replace $chaine";
	    }
	    s/@@@(.*)@@@/$toreplace{$1}/g;
	}
	print OUT;
    }
   
    
}


#------------------------------------------------------------------------------
#copy master filter to the spool dir
#------------------------------------------------------------------------------
sub copy_master_filter($) {
    my ($queue_path) = @_;
    my $complete_path = "${prefix}${queue_path}filter";
    my $master_filter = "${prefix}${PRINTER_FILTER_DIR}master-filter";


    unless ($::testing) {
	commands::cp($master_filter, $complete_path) or die "Can't copy $master_filter to $complete_path $!";
    } 
    
    
}

#------------------------------------------------------------------------------
# given a PrintCap Entry, create the spool dir and special 
# rhs-printfilters related config files which are required
#------------------------------------------------------------------------------
my $intro_printcap_test="
#
# Please don't edit this file directly unless you know what you are doing!
# Look at the printcap(5) man page for more info.
# Be warned that the control-panel printtool requires a very strict format!
# Look at the printcap(5) man page for more info.
#
# This file can be edited with the printtool in the control-panel.
#

";


sub configure_queue($) {
    my ($entry) = @_;

    $entry->{SPOOLDIR} ||= "$SPOOLDIR";
    $entry->{IF}       ||= "$SPOOLDIR$entry->{QUEUE}/filter";
    $entry->{AF}       ||= "$SPOOLDIR$entry->{QUEUE}/acct";
    
    my $queue_path      = "$entry->{SPOOLDIR}";
    create_spool_dir($queue_path);

    my $get_name_file = sub { 
	my ($name) = @_; 
	("${PRINTER_FILTER_DIR}$name.in)", "$entry->{SPOOLDIR}$name")
    };
    my ($filein, $file);
    my %fieldname = ();
    my $dbentry = $thedb{($entry->{DBENTRY})} or die "no dbentry";


    ($filein, $file) = &$get_name_file("general.cfg");
    $fieldname{desiredto}   = ($entry->{GSDRIVER} eq "TEXT") ? "ps" : "asc";
    $fieldname{papersize}   = ($entry->{PAPERSIZES}) ? $entry->{PAPERSIZES} : "letter";
    $fieldname{printertype} = ($entry)->{TYPE};
    $fieldname{ascps_trans} = ($dbentry->{GSDRIVER} eq "POSTSCRIPT") ? 
      "NO" : "YES";
    create_config_file($filein,$file, %fieldname);

    # successfully created general.cfg, now do postscript.cfg 
    ($filein, $file) = &$get_name_file("postscript.cfg");
    %fieldname = ();
    $fieldname{gsdevice}       = $dbentry->{GSDRIVER};
    $fieldname{papersize}      = ($entry->{PAPERSIZES}) ? $entry->{PAPERSIZES} : "letter";
    $fieldname{resolution}     = ($entry->{RESOLUTION} eq "Default") ? "Default" : "";
    $fieldname{color}          = 
      do {
	  if ($dbentry->{GSDRIVER} eq "uniprint") {
	      ($entry->{BITSPERPIXEL} eq "Default") ? "-dBitsPerPixel=Default" : "";
	  } else {
	      $entry->{BITSPERPIXEL};
	  }
      };
    $fieldname{reversepages}   = "NO";
    $fieldname{extragsoptions} = "";
    $fieldname{pssendeof}      = ($dbentry->{GSDRIVER} eq "POSTSCRIPT") ?
      "NO" : "YES";
    $fieldname{nup}            = "1";
    $fieldname{rtlftmar}       = "18";
    $fieldname{topbotmar}      = "18";
    create_config_file($filein, $file, %fieldname);
	
    # finally, make textonly.cfg
    ($filein, $file) = &$get_name_file("textonly.cfg");
    %fieldname = ();
    $fieldname{textonlyoptions} = "";
    $fieldname{crlftrans}       = $entry->{CRLF} ? "YES" : "";
    $fieldname{textsendeof}     = "1";
    create_config_file($filein, $file, %fieldname);

	
    unless ($::testing) {
	if ($entry->{TYPE} eq $PRINTER_SMB) {
	    # simple config file required if SMB printer
	    my $config_file = "${prefix}${queue_path}.config";
	    local *CONFFILE;
	    open CONFFILE, ">$config_file" or die "Can't create $config_file $!";
	    print CONFFILE "share='\\\\$entry->{SMBHOST}\\$entry->{SMBSHARE}'\n";
	    print CONFFILE "hostip='$entry->{SMBHOSTIP}'\n";
	    print CONFFILE "user='$entry->{SMBUSER}'\n";
	    print CONFFILE "password='$entry->{SMBPASSWD}'\n";
	    print CONFFILE "workgroup='$entry->{SMBWORKGROUP}'\n";
	} elsif ($entry->{TYPE} eq $PRINTER_NCP) {
	    # same for NCP printer
	    my $config_file = "${prefix}${queue_path}.config";
	    local *CONFFILE;
	    open CONFFILE, ">$config_file" or die "Can't create $config_file $!";
	    print CONFFILE "server=$entry->{NCPHOST}\n";
	    print CONFFILE "queue=$entry->{NCPQUEUE}\n";
	    print CONFFILE "user=$entry->{NCPUSER}\n";
	    print CONFFILE "password=$entry->{NCPPASSWD}\n";
	}
    }

    copy_master_filter($queue_path);

    #now the printcap file
    local *PRINTCAP;
    if ($::testing) {
	open PRINTCAP, ">${prefix}etc/printcap" or die "Can't open printcap file $!";
    } else {
	*PRINTCAP = *STDOUT;
    }
    
    print PRINTCAP $intro_printcap_test;
    printf PRINTCAP "##PRINTTOOL3##  %s %s %s %s %s %s %s \n",
      $entry->{TYPE},
	$dbentry->{GSDRIVER},
	  $entry->{RESOLUTION},
	    $entry->{PAPERSIZE},
	      "{}",
		$dbentry->{ENTRY},
		  $entry->{BITSPERPIXEL},
		    $entry->{CRLF} ? "1" : "";

	
    print PRINTCAP "$entry->{QUEUE}:\\\n";
    print PRINTCAP "\t:sd=$entry->{SPOOLDIR}:\\\n";
    print PRINTCAP "\t:mx#0:\\\n\t:sh:\\\n";
	   
    if ($entry->{TYPE} eq $PRINTER_LOCAL) {
	print PRINTCAP "\t:lp=$entry->{DEVICE}:\\\n";
    } elsif ($entry->{TYPE} eq $PRINTER_LPRREM) { 
	print PRINTCAP "\t:rm=$entry->{REMOTEHOST}:\\\n";
	print PRINTCAP "\t:rp=$entry->{REMOTEQUEUE}:\\\n";
    } else {
	# (pcentry->Type == (PRINTER_SMB | PRINTER_NCP))
	print PRINTCAP "\t:lp=/dev/null:\\\n";
	print PRINTCAP "\t:af=$entry->{SPOOLDIR}acct\\\n";
    }

    # cheating to get the input filter!
    print PRINTCAP "\t:if=$entry->{SPOOLDIR}filter:\n";
	
}


#------------------------------------------------------------------------------
#interface function 
#------------------------------------------------------------------------------

sub 
#pixel stuff
my ($o, $in);
    

#------------------------------------------------------------------------------
#fonction de test
#------------------------------------------------------------------------------
sub test {
    $::testing = 1;
    $printer::prefix="";

    read_printer_db();

    print "the dump\n";
    print Dumper(%thedb);


    #
    #eval { printer::create_spool_dir("/tmp/titi/", ".") };
    #print $@;