“UbuntuHelp:NetwarePrintingFromUbuntu”的版本间的差异
来自Ubuntu中文
小 |
小 |
||
第31行: | 第31行: | ||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
# | # | ||
+ | |||
use strict; | use strict; | ||
+ | |||
# Configurable parameters | # Configurable parameters | ||
+ | |||
# nprint program name (you may want to put the full pathname here) | # nprint program name (you may want to put the full pathname here) | ||
my $NPRINT = "nprint"; | my $NPRINT = "nprint"; | ||
+ | |||
# Home directory (the .nwclient file will be searched there) | # Home directory (the .nwclient file will be searched there) | ||
my $NCP_HOME = "/root"; | my $NCP_HOME = "/root"; | ||
+ | |||
# End of configurable parameters | # End of configurable parameters | ||
+ | |||
+ | |||
+ | |||
# No arguments means show available devices | # No arguments means show available devices | ||
if (scalar(@ARGV) == 0) { | if (scalar(@ARGV) == 0) { | ||
− | print "network ncp \"Unknown\" \"NetWare Printer via NCP\"\n"; | + | print "network ncp \"Unknown\" \"NetWare Printer via NCP\"\n"; |
− | exit 0; | + | exit 0; |
} | } | ||
+ | |||
# Check number of arguments | # Check number of arguments | ||
if (scalar(@ARGV) < 5 || scalar(@ARGV) > 6) { | if (scalar(@ARGV) < 5 || scalar(@ARGV) > 6) { | ||
− | print STDERR "ERROR: ncp job user title copies options [filename]\n"; | + | print STDERR "ERROR: ncp job user title copies options [filename]\n"; |
− | exit 1; | + | exit 1; |
} | } | ||
+ | |||
my ($job, $user, $title, $copies, $options, $file) = @ARGV; | my ($job, $user, $title, $copies, $options, $file) = @ARGV; | ||
my $printer = $ENV{"DEVICE_URI"}; | my $printer = $ENV{"DEVICE_URI"}; | ||
+ | |||
# These variables will hold the URI parts | # These variables will hold the URI parts | ||
my ($server, $queue, $nwuser, $nwpass); | my ($server, $queue, $nwuser, $nwpass); | ||
+ | |||
# Parse the printer URI into parts | # Parse the printer URI into parts | ||
for ($printer) { | for ($printer) { | ||
− | # ncp://USERNAME:PASSWORD@SERVER/QUEUE | + | |
− | m|^ncp://(.+):(.*)@(.+)/(.+)| && do { | + | # ncp://USERNAME:PASSWORD@SERVER/QUEUE |
+ | m|^ncp://(.+):(.*)@(.+)/(.+)| && do { | ||
$nwuser = $1; | $nwuser = $1; | ||
$nwpass = $2; | $nwpass = $2; | ||
第61行: | 第74行: | ||
$queue = $4; | $queue = $4; | ||
last; | last; | ||
− | }; | + | }; |
− | # ncp://USERNAME@SERVER/QUEUE | + | |
− | m|^ncp://(.+)@(.+)/(.+)| && do { | + | # ncp://USERNAME@SERVER/QUEUE |
+ | m|^ncp://(.+)@(.+)/(.+)| && do { | ||
$nwuser = $1; | $nwuser = $1; | ||
$server = $2; | $server = $2; | ||
$queue = $3; | $queue = $3; | ||
last; | last; | ||
− | }; | + | }; |
− | # ncp://SERVER/QUEUE | + | |
− | m|^ncp://(.+)/(.+)| && do { | + | # ncp://SERVER/QUEUE |
+ | m|^ncp://(.+)/(.+)| && do { | ||
$server = $1; | $server = $1; | ||
$queue = $2; | $queue = $2; | ||
last; | last; | ||
− | }; | + | }; |
} | } | ||
+ | |||
# Check if the URI was parsed correctly | # Check if the URI was parsed correctly | ||
if (not defined $server or not defined $queue) { | if (not defined $server or not defined $queue) { | ||
− | print STDERR "ERROR: malformed printer URI\n"; | + | print STDERR "ERROR: malformed printer URI\n"; |
− | exit 1; | + | exit 1; |
} | } | ||
+ | |||
# Unquote the URI parts (must be done after splitting) | # Unquote the URI parts (must be done after splitting) | ||
$nwuser =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $nwuser; | $nwuser =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $nwuser; | ||
第86行: | 第103行: | ||
$server =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $server; | $server =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $server; | ||
$queue =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $queue; | $queue =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $queue; | ||
+ | |||
# Fixed part of the nprint command | # Fixed part of the nprint command | ||
my @command = ($NPRINT, "-S", $server, "-q", $queue, "-N"); | my @command = ($NPRINT, "-S", $server, "-q", $queue, "-N"); | ||
+ | |||
# Add "-U USERNAME" if specified | # Add "-U USERNAME" if specified | ||
if (defined $nwuser) { | if (defined $nwuser) { | ||
− | push @command, "-U"; | + | push @command, "-U"; |
− | push @command, $nwuser; | + | push @command, $nwuser; |
} | } | ||
+ | |||
# Add "-P PASSWORD" if specified | # Add "-P PASSWORD" if specified | ||
if (defined $nwpass) { | if (defined $nwpass) { | ||
− | push @command, "-P"; | + | push @command, "-P"; |
− | push @command, $nwpass; | + | push @command, $nwpass; |
} | } | ||
+ | |||
# Append the print file name or "-" to read from stdin | # Append the print file name or "-" to read from stdin | ||
if (defined $file) { | if (defined $file) { | ||
− | if ($file =~ /^-/) { | + | if ($file =~ /^-/) { |
# Avoid file names which look like switches | # Avoid file names which look like switches | ||
$file = "./$file"; | $file = "./$file"; | ||
− | } | + | } |
− | push @command, $file; | + | push @command, $file; |
} else { | } else { | ||
− | push @command, "-"; | + | push @command, "-"; |
} | } | ||
+ | |||
# nprint will read $HOME/.nwclient, so need to set it | # nprint will read $HOME/.nwclient, so need to set it | ||
$ENV{"HOME"} = $NCP_HOME; | $ENV{"HOME"} = $NCP_HOME; | ||
+ | |||
# all is ready, run nprint (directly, without using shell) | # all is ready, run nprint (directly, without using shell) | ||
my $result = system { $command[0] } @command; | my $result = system { $command[0] } @command; | ||
+ | |||
# if not ok, print the error message in the format required by CUPS | # if not ok, print the error message in the format required by CUPS | ||
if ($result != 0) { | if ($result != 0) { | ||
− | print STDERR "ERROR: nprint exited with status $result\n"; | + | print STDERR "ERROR: nprint exited with status $result\n"; |
− | exit 1; | + | exit 1; |
} | } | ||
+ | |||
# normal exit | # normal exit | ||
exit 0; | exit 0; | ||
− | </nowiki></pre> | + | </nowiki></pre> |
'''Restart CUPS''' | '''Restart CUPS''' | ||
After changing this file, restart CUPS by running ... | After changing this file, restart CUPS by running ... | ||
第143行: | 第168行: | ||
# - no need for security within the machine, ie a personal workstation | # - no need for security within the machine, ie a personal workstation | ||
# - a network connection to a local network, where it will find CUPS-controlled printer servers | # - a network connection to a local network, where it will find CUPS-controlled printer servers | ||
+ | |||
# Log general information in error_log - change "info" to "debug" for | # Log general information in error_log - change "info" to "debug" for | ||
# troubleshooting... | # troubleshooting... | ||
LogLevel warning | LogLevel warning | ||
+ | |||
# Administrator user group... | # Administrator user group... | ||
SystemGroup lpadmin | SystemGroup lpadmin | ||
+ | |||
# Only listen for connections from the local machine. | # Only listen for connections from the local machine. | ||
# These settings are configured in /etc/cups/cups.d/ports.conf so that | # These settings are configured in /etc/cups/cups.d/ports.conf so that | ||
第153行: | 第181行: | ||
# Listen localhost:631 | # Listen localhost:631 | ||
# Listen /var/run/cups/cups.sock | # Listen /var/run/cups/cups.sock | ||
+ | |||
# This setup also allows access to the "Administrative tasks" system at | # This setup also allows access to the "Administrative tasks" system at | ||
# http://localhost:631 | # http://localhost:631 | ||
# File based on Ubuntu 5.10 (Breezy Badger) (Linux version 2.6.12-10-386) | # File based on Ubuntu 5.10 (Breezy Badger) (Linux version 2.6.12-10-386) | ||
# Server Directives are explained in http://localhost:631/sam.html | # Server Directives are explained in http://localhost:631/sam.html | ||
+ | |||
# 25/04/2006 | # 25/04/2006 | ||
+ | |||
ConfigFilePerm 0600 | ConfigFilePerm 0600 | ||
LogLevel info | LogLevel info | ||
第168行: | 第199行: | ||
#Listen 192.168.0.0/24:631 | #Listen 192.168.0.0/24:631 | ||
Port 631 | Port 631 | ||
+ | |||
# Show shared printers on the local network. | # Show shared printers on the local network. | ||
# The 'Browsing' setting is configured in /etc/cups/cups.d/browse.conf | # The 'Browsing' setting is configured in /etc/cups/cups.d/browse.conf | ||
第175行: | 第207行: | ||
BrowseAllow @LOCAL | BrowseAllow @LOCAL | ||
BrowseAddress @LOCAL | BrowseAddress @LOCAL | ||
+ | |||
# Restrict access to the server... | # Restrict access to the server... | ||
# <Location /> | # <Location /> | ||
第187行: | 第220行: | ||
Allow From @LOCAL | Allow From @LOCAL | ||
</Location> | </Location> | ||
+ | |||
<Location /jobs> | <Location /jobs> | ||
AuthType None | AuthType None | ||
第193行: | 第227行: | ||
Allow From @LOCAL | Allow From @LOCAL | ||
</Location> | </Location> | ||
+ | |||
<Location /printers> | <Location /printers> | ||
AuthType None | AuthType None | ||
第199行: | 第234行: | ||
Allow From @LOCAL | Allow From @LOCAL | ||
</Location> | </Location> | ||
+ | |||
# Restrict access to the admin pages... | # Restrict access to the admin pages... | ||
#<Location /admin> | #<Location /admin> | ||
第210行: | 第246行: | ||
Allow From @LOCAL | Allow From @LOCAL | ||
</Location> | </Location> | ||
+ | |||
# Default authentication type, when authentication is required... | # Default authentication type, when authentication is required... | ||
DefaultAuthType Basic | DefaultAuthType Basic | ||
+ | |||
# Restrict access to configuration files... | # Restrict access to configuration files... | ||
<Location /admin/conf> | <Location /admin/conf> | ||
− | AuthType Basic | + | AuthType Basic |
− | Require user @SYSTEM | + | Require user @SYSTEM |
− | Order allow,deny | + | Order allow,deny |
− | Allow localhost | + | Allow localhost |
</Location> | </Location> | ||
+ | |||
# Set the default printer/job policies... | # Set the default printer/job policies... | ||
<Policy default> | <Policy default> | ||
− | # Job-related operations must be done by the owner or an adminstrator... | + | # Job-related operations must be done by the owner or an adminstrator... |
− | <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job> | + | <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job> |
− | Require user @OWNER @SYSTEM | + | Require user @OWNER @SYSTEM |
− | Order deny,allow | + | Order deny,allow |
− | </Limit> | + | </Limit> |
− | # All administration operations require an adminstrator to authenticate... | + | |
− | <Limit Pause-Printer Resume-Printer Set-Printer-Attributes Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Add-Printer CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default> | + | # All administration operations require an adminstrator to authenticate... |
− | AuthType Basic | + | <Limit Pause-Printer Resume-Printer Set-Printer-Attributes Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Add-Printer CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default> |
− | Require user @SYSTEM | + | AuthType Basic |
− | Order deny,allow | + | Require user @SYSTEM |
− | </Limit> | + | Order deny,allow |
− | # Only the owner or an administrator can cancel or authenticate a job... | + | </Limit> |
− | <Limit Cancel-Job CUPS-Authenticate-Job> | + | |
− | Require user @OWNER @SYSTEM | + | # Only the owner or an administrator can cancel or authenticate a job... |
− | Order deny,allow | + | <Limit Cancel-Job CUPS-Authenticate-Job> |
− | </Limit> | + | Require user @OWNER @SYSTEM |
− | <Limit All> | + | Order deny,allow |
− | Order deny,allow | + | </Limit> |
− | </Limit> | + | |
+ | <Limit All> | ||
+ | Order deny,allow | ||
+ | </Limit> | ||
</Policy> | </Policy> | ||
+ | |||
# Include files in /etc/cups/conf.d | # Include files in /etc/cups/conf.d | ||
Include /etc/cups/cups.d/ports.conf | Include /etc/cups/cups.d/ports.conf | ||
Include /etc/cups/cups.d/browse.conf | Include /etc/cups/cups.d/browse.conf | ||
− | </nowiki></pre> | + | </nowiki></pre> |
To access the Cups Web Interface goto http://localhost:631/ | To access the Cups Web Interface goto http://localhost:631/ | ||
---- | ---- |
2007年12月6日 (四) 10:47的版本
点击翻译: |
English |
请不要直接编辑翻译本页,本页将定期与来源同步。 |
目录
Introduction
This page covers only how to install a Netware Printer Queue in Ubuntu.
What is Needed
perl - Larry Wall's Practical Extraction and Report Language, needed for ncp script. ipx - utilities to configure the kernel ipx interface. ncpfs - a set of utilities to use resources from NetWare servers, in particular nprint to print to a netware printer queue. kdeprint - print system for KDE, this is a very nice tool.
NCP script
Create the script /usr/lib/cups/backend/ncp
#! /usr/bin/perl -w # # NCP backend for CUPS # # Copyright (C) 2001 Sergey Vlasov <[email protected]> # # 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 of the License, 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 strict; # Configurable parameters # nprint program name (you may want to put the full pathname here) my $NPRINT = "nprint"; # Home directory (the .nwclient file will be searched there) my $NCP_HOME = "/root"; # End of configurable parameters # No arguments means show available devices if (scalar(@ARGV) == 0) { print "network ncp \"Unknown\" \"NetWare Printer via NCP\"\n"; exit 0; } # Check number of arguments if (scalar(@ARGV) < 5 || scalar(@ARGV) > 6) { print STDERR "ERROR: ncp job user title copies options [filename]\n"; exit 1; } my ($job, $user, $title, $copies, $options, $file) = @ARGV; my $printer = $ENV{"DEVICE_URI"}; # These variables will hold the URI parts my ($server, $queue, $nwuser, $nwpass); # Parse the printer URI into parts for ($printer) { # ncp://USERNAME:PASSWORD@SERVER/QUEUE m|^ncp://(.+):(.*)@(.+)/(.+)| && do { $nwuser = $1; $nwpass = $2; $server = $3; $queue = $4; last; }; # ncp://USERNAME@SERVER/QUEUE m|^ncp://(.+)@(.+)/(.+)| && do { $nwuser = $1; $server = $2; $queue = $3; last; }; # ncp://SERVER/QUEUE m|^ncp://(.+)/(.+)| && do { $server = $1; $queue = $2; last; }; } # Check if the URI was parsed correctly if (not defined $server or not defined $queue) { print STDERR "ERROR: malformed printer URI\n"; exit 1; } # Unquote the URI parts (must be done after splitting) $nwuser =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $nwuser; $nwpass =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $nwpass; $server =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $server; $queue =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if defined $queue; # Fixed part of the nprint command my @command = ($NPRINT, "-S", $server, "-q", $queue, "-N"); # Add "-U USERNAME" if specified if (defined $nwuser) { push @command, "-U"; push @command, $nwuser; } # Add "-P PASSWORD" if specified if (defined $nwpass) { push @command, "-P"; push @command, $nwpass; } # Append the print file name or "-" to read from stdin if (defined $file) { if ($file =~ /^-/) { # Avoid file names which look like switches $file = "./$file"; } push @command, $file; } else { push @command, "-"; } # nprint will read $HOME/.nwclient, so need to set it $ENV{"HOME"} = $NCP_HOME; # all is ready, run nprint (directly, without using shell) my $result = system { $command[0] } @command; # if not ok, print the error message in the format required by CUPS if ($result != 0) { print STDERR "ERROR: nprint exited with status $result\n"; exit 1; } # normal exit exit 0;
Restart CUPS After changing this file, restart CUPS by running ...
sudo /etc/init.d/cupsys restart
or use the Services tool under Gnome menu System -> Administration.
1. Add a printer definition, using kdeprint (Gnome menu System -> Preferences -> Printers). Select Other printer type. In the URl: type
ncp://COMPANY_FS/PRINTER_Q
If at this point you don't see 'Netware Printer via ncp' then refer to 'NCP Script' above. Select the relevent printer etc. and you should have a working Netware Printer.
Add a Netware Printer with Cups Web Interface
This needs an Administrator account. Please refer to NetworkPrintingWithUbuntu -> Ubuntu Client Machine for more info.
# /etc/cups/cupsd.conf # Simple CUPS configuration file for a pure client machine: # which has: # - printers of its own, (and any local printers will be shared?) # - no need for security within the machine, ie a personal workstation # - a network connection to a local network, where it will find CUPS-controlled printer servers # Log general information in error_log - change "info" to "debug" for # troubleshooting... LogLevel warning # Administrator user group... SystemGroup lpadmin # Only listen for connections from the local machine. # These settings are configured in /etc/cups/cups.d/ports.conf so that # changing them does not require to change this file. # Listen localhost:631 # Listen /var/run/cups/cups.sock # This setup also allows access to the "Administrative tasks" system at # http://localhost:631 # File based on Ubuntu 5.10 (Breezy Badger) (Linux version 2.6.12-10-386) # Server Directives are explained in http://localhost:631/sam.html # 25/04/2006 # [email protected] ConfigFilePerm 0600 LogLevel info Printcap /var/run/cups/printcap RunAsUser Yes #Listen 127.0.0.1:631 #Listen 10.0.0.0/8:631 #Listen 128.0.0.0/16:631 #Listen 192.168.0.0/24:631 Port 631 # Show shared printers on the local network. # The 'Browsing' setting is configured in /etc/cups/cups.d/browse.conf # so that changing it does not require to change this file. # Browsing Off BrowseOrder allow,deny BrowseAllow @LOCAL BrowseAddress @LOCAL # Restrict access to the server... # <Location /> # Order allow,deny # Allow localhost # Allow @LOCAL #</Location> <Location /> AuthType None Order Deny,Allow Deny From All Allow From @LOCAL </Location> <Location /jobs> AuthType None Order Deny,Allow Deny From All Allow From @LOCAL </Location> <Location /printers> AuthType None Order Deny,Allow Deny From All Allow From @LOCAL </Location> # Restrict access to the admin pages... #<Location /admin> # Order allow,deny # Allow localhost # </Location> <Location /admin> AuthType None Order Deny,Allow Deny From All Allow From @LOCAL </Location> # Default authentication type, when authentication is required... DefaultAuthType Basic # Restrict access to configuration files... <Location /admin/conf> AuthType Basic Require user @SYSTEM Order allow,deny Allow localhost </Location> # Set the default printer/job policies... <Policy default> # Job-related operations must be done by the owner or an adminstrator... <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job> Require user @OWNER @SYSTEM Order deny,allow </Limit> # All administration operations require an adminstrator to authenticate... <Limit Pause-Printer Resume-Printer Set-Printer-Attributes Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Add-Printer CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default> AuthType Basic Require user @SYSTEM Order deny,allow </Limit> # Only the owner or an administrator can cancel or authenticate a job... <Limit Cancel-Job CUPS-Authenticate-Job> Require user @OWNER @SYSTEM Order deny,allow </Limit> <Limit All> Order deny,allow </Limit> </Policy> # Include files in /etc/cups/conf.d Include /etc/cups/cups.d/ports.conf Include /etc/cups/cups.d/browse.conf
To access the Cups Web Interface goto http://localhost:631/