diff options
author | Antoine Ginies <aginies@mandriva.com> | 2005-06-01 08:56:18 +0000 |
---|---|---|
committer | Antoine Ginies <aginies@mandriva.com> | 2005-06-01 08:56:18 +0000 |
commit | 50bf3c96e7972a2cb288ae5722dd8e6fcd1e6e61 (patch) | |
tree | 84485f3930d984db4b3b805dc77016d732c1afb4 | |
parent | 60d6ec8ab2f428a431ab47646f04d1ddceb12a0a (diff) | |
download | drakwizard-50bf3c96e7972a2cb288ae5722dd8e6fcd1e6e61.tar drakwizard-50bf3c96e7972a2cb288ae5722dd8e6fcd1e6e61.tar.gz drakwizard-50bf3c96e7972a2cb288ae5722dd8e6fcd1e6e61.tar.bz2 drakwizard-50bf3c96e7972a2cb288ae5722dd8e6fcd1e6e61.tar.xz drakwizard-50bf3c96e7972a2cb288ae5722dd8e6fcd1e6e61.zip |
Samba wizard to manage printers
-rwxr-xr-x | samba_wizard/Sambaprint.pm | 306 |
1 files changed, 306 insertions, 0 deletions
diff --git a/samba_wizard/Sambaprint.pm b/samba_wizard/Sambaprint.pm new file mode 100755 index 00000000..2e2cfa38 --- /dev/null +++ b/samba_wizard/Sambaprint.pm @@ -0,0 +1,306 @@ +#!/usr/bin/perl + +# Drakwizard +# Copyright (C) 2005 Mandriva +# +# Authors: antoine Ginies <aginies -@- mandriva> +# +# 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. + +package MDK::Wizard::Sambaprint; +use strict; + +use common; +use services; +use MDK::Wizard::Wizcommon; + +use Libconf::Templates; +use Libconf::Glueconf::Samba::Smb_conf; + +my $wiz = new MDK::Wizard::Wizcommon; + +my $wiz_samba_etc = "/etc/sysconfig/wizard_samba"; +my @listshare; +my @listprinters; + +my $o = { + name => 'Samba wizard', + var => { + wiz_all_printers => '', + wiz_printers => '', wiz_do_printer_sharing => '', wiz_printers_comment => '', + wiz_printers_browseable => '', wiz_printers_guestok => '', wiz_printers_createmode => '', + list_printers => '', + }, + defaultimage => "/usr/share/wizards/samba_wizard/images/samba.png" + }; + +# we ask glueconf to give us the structure representing /etc/samba/smb.conf +my $samba = new Libconf::Glueconf::Samba::Smb_conf({ filename => '/etc/samba/smb.conf', show_commented_info => 1 }); + +#debug +use Data::Dumper; +print Dumper($samba); + +my %cprint = ( + 1 => N('Printers - configure your printers'), + 2 => N('Print - printers drivers'), + ); + +my @yesorno = qw(yes no); push @yesorno, ""; + +$o->{pages} = { + welcome => { + name => N('Samba printers Wizard') . "\n\n" . N(''), + no_back => 1, + pre => sub { + if (-f $wiz_samba_etc) { + $::in->ask_warn(N("Information"), N("It seems you previously setup a Samba server. This wizard will re-read your old configuration, and show you the Samba server type you choose")); + my $data = cat_($wiz_samba_etc); + # detect old Samba type + my ($old_type) = $data =~ /type=(\d)/; + $o->{var}{wiz_type} = chomp_($old_type); + } else { $o->{var}{wiz_type} = 2 } + }, + next => 'ask_type', + post => sub { + if ($o->{var}{wiz_type} == 2) { + return 'pdc' } + elsif ($o->{var}{wiz_type} == 1) { + return 'bdc' } + elsif ($o->{var}{wiz_type} == 3) { + return 'ask_workgroup' } + elsif ($o->{var}{wiz_type} == 4) { + return 'member' } + }, + data => [ + { label => N("Wich type of Samba server do you you want:"), val => \$o->{var}{wiz_type}, list => [ keys %type ], format => sub { $type{$_[0]} } }, + ], + }, + ask_printers => { + name => N('Select which printers you want to be accessible from known users'), + pre => sub { + $o->{var}{list_printers} ||= [ list_printers() ]; + $o->{var}{wiz_box_list} ||= []; + }, + data => [ + { text => N('Enable all printers'), type => 'bool', val => \$o->{var}{wiz_all_printers} }, + { val => \$o->{var}{wiz_box_list}, boolean_list => \$o->{var}{list_printers}, disabled => sub { $o->{var}{wiz_all_printers} and return 1; 0 } }, + ], + next => 'ask_printers_options', + }, + ask_printers_options => { + name => N('Now you can configure your printers service. Change value only if you know what your are doing.'), + pre => sub { + if ($samba->{printers}{comment}) { + $o->{var}{wiz_printers_comment} ||= $samba->{printers}{comment} + } else { + $o->{var}{wiz_printers_comment} = "All Printers"; + } + $o->{var}{wiz_printers_browseable} ||= $samba->{printers}{browseable}; + $o->{var}{wiz_printers_guestok} ||= $samba->{printers}{'guest ok'}; + if ($samba->{printers}{'create mode'}) { + $o->{var}{wiz_printers_createmode} ||= $samba->{printers}{'create mode'} + } else { + $o->{var}{wiz_printers_createmode} = "0700"; + } + }, + post => sub { + if ($o->{var}{wiz_do_homes} == 1) { + return 'ask_homes'; + } + }, + data => [ + { label => N('Comment:'), val => \$o->{var}{wiz_printers_comment} }, + { label => N('Create mode:'), val => \$o->{var}{wiz_printers_createmode} }, + { label => N('Browseable:'), val => \$o->{var}{wiz_printers_browseable}, fixed_list => \@yesorno }, + { label => N('Guest ok:'), val => \$o->{var}{wiz_printers_guestok}, fixed_list => \@yesorno }, + ], + next => 'summary', + }, + summary => { + name => N('Configuring Samba priniters'), + pre => sub { + $o->{var}{wiz_sambatype} = $type{$o->{var}{wiz_type}}; + }, + data => [ + { label => N('Samba type:'), fixed_val => \$o->{var}{wiz_sambatype} }, + { label => N('Workgroup:'), fixed_val => \$o->{var}{wiz_workgroup} }, + { label => N('Server banner:'), fixed_val => \$o->{var}{wiz_banner} }, + { label => N('Log file:'), fixed_val => \$o->{var}{wiz_log_file} }, + ], + post => \&do_it, + next => 'end' + }, + end => { + name => N('Congratulations') . "\n\n" . N('The wizard successfully configured your Samba server.'), + post => sub { + store_samba_type($o->{var}{wiz_type}); + }, + no_back => 1, + end => 1, + next => 0 + }, + error_end => { + name => N("Failed"), + data => [ { label => N("Please relaunch drakwizard, and try to change some parameters.") } ], + no_back => 1, + end => 1, + next => 0, + }, + }; + +sub new { + my ($class, $conf) = @_; + bless { + o => $o, + }, $class; +} + +sub check() { + $> and return 1; + $wiz->{net}->is_dhcp() and return 2; + 0; +} + +#section has the name of the printer +sub add_printer { + my ($printer) = @_; + $samba->{$printer}{printer} = $printer; + $samba->{$printer}{printable} = 'yes'; +} + +sub remove_printer { + my ($printer) = @_; + delete $samba->{$printer}; +} + +sub list_printers_smbconf() { + undef @listprinters; + foreach my $clef (keys %$samba) { + if ($samba->{$clef}{printable} =~ /yes/i) { + print "$clef is a printer\n"; + push @listprinters, $clef; + } + } + return @listprinters; +} + +sub list_printers() { + my @list if 0; + return @list if @list; + @list = sort grep /^(?!\#).+/, map { + my ($printer) = split(':', $_); + } cat_("/etc/printcap"); + if (@list) { + @list + } else { () } +} + + +sub printer_sharing() { + # create default sedction for printers with default value + $samba->{global}{'printer adm'} = "\@adm"; + $samba->{printers}; + $samba->{printers}{comment} = $o->{var}{wiz_printers_comment}; + $samba->{printers}{browseable} = $o->{var}{wiz_printers_browseable}; + $samba->{printers}{'guest ok'} = $o->{var}{wiz_printers_guestok}; + $samba->{printers}{'create mode'} = $o->{var}{wiz_printers_createmode}; + # dont want user to change those value... + $samba->{printers}{path} = "/var/spool/samba"; + $samba->{printers}{writable} = "no"; + $samba->{printers}{printable} = "yes"; + $samba->{printers}{'print command'} = "lpr-cups -P %p -o raw %s -r"; + $samba->{printers}{'use client driver'} = "yes"; + for (my $i; $i < @{$o->{var}{wiz_box_list}}; $i++) { + my $printer = $o->{var}{list_printers}[$i]; + if ($o->{var}{wiz_box_list}[$i]) { + add_printer($printer); + } else { + remove_printer($printer); + } + } +} + +sub priner_section() { + $samba->{'pdf-gen'}; + $samba->{path} = "/var/tmp"; + $samba->{'guest ok'} = "no"; + $samba->{printable} = "yes"; + $samba->{comment} = "PDF Generator (only valid users)"; + $samba->{printing} = "bsd"; + $samba->{'print command'} = "/usr/share/samba/scripts/print-pdf \"%s\" \"%H\" \"//%L/%u\" \"%m\" \"%I\" \"%J\" &"; + $samba->{'lpq command'} = "/bin/true"; +} + +sub printdollar_section() { + $samba->{'print$'}; + $samba->{path} = "/var/lib/samba/printers"; + $samba->{browseable} = "yes"; + $samba->{'write list'} = "\@adm root"; + $samba->{'guest ok'} = "yes"; + $samba->{inherit permissions} = "yes"; +} + +sub get_printers() { + if ($o->{var}{wiz_do_printer_sharing}) { + my $string; + $o->{var}{wiz_all_printers} and return "all printers"; + for (my $i; $i < @{$o->{var}{wiz_box_list}}; $i++) { + $string .= "$o->{var}{list_printers}[$i]\n" if $o->{var}{wiz_box_list}[$i] + } + $string; + } + else { + 'disabled'; + } +} + +sub write_conf_restart_smb { + $samba->write_conf("/etc/samba/smb.conf"); + if (services::is_service_running('smb')) { + services::restart('smb') + } else { services::start('smb') } +} + +# remember one variable cannot be commented and not in the same file. +sub do_it { + $::testing and return; + # display a wait dialog box + my $in = 'interactive'->vnew('su', 'Samba'); + my $w = $in->wait_message(N("Samba server"), N("Configuring your Samba server...")); + + # share printers + if ($o->{var}{wiz_do_printer_sharing}) { + printer_sharing(); + printer_section(); + printdollar_section(); + } else { + if ($o->{var}{wiz_box_list}) { + for(my $i; $i < @{$o->{var}{wiz_box_list}}; $i++) { + $o->{var}{list_printers}[$i] and remove_printer($o->{var}{list_printers}[$i]); + } + } + delete $samba->{global}{'printer adm'}; + delete $samba->{printers}; + delete $samba->{'print$'}; + delete $samba->{'pdf-gen'}; + } + + write_conf_restart_smb(); + # remove wait message + undef $w; + check_started('smbd'); + } +1; |