initial commit of file from CVS for e-smith-LPRng on Wed 12 Jul 08:48:21 BST 2023
This commit is contained in:
1
root/etc/e-smith/db/configuration/defaults/lpd/status
Normal file
1
root/etc/e-smith/db/configuration/defaults/lpd/status
Normal file
@@ -0,0 +1 @@
|
||||
enabled
|
1
root/etc/e-smith/db/configuration/defaults/lpd/type
Normal file
1
root/etc/e-smith/db/configuration/defaults/lpd/type
Normal file
@@ -0,0 +1 @@
|
||||
service
|
65
root/etc/e-smith/events/actions/printer-create
Executable file
65
root/etc/e-smith/events/actions/printer-create
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# copyright (C) 1999 Ip, Tak Hong
|
||||
# copyright (C) 2000-2006 Mitel Networks Corporation
|
||||
#
|
||||
# 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
|
||||
#
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
package esmith;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Errno;
|
||||
use esmith::util;
|
||||
|
||||
use esmith::AccountsDB;
|
||||
my $adb = esmith::AccountsDB->open_ro();
|
||||
|
||||
my $event = $ARGV [0];
|
||||
my $printerName = $ARGV [1];
|
||||
my @printers;
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Create the printer
|
||||
#------------------------------------------------------------
|
||||
|
||||
if ($printerName)
|
||||
{
|
||||
my $p = $adb->get($printerName);
|
||||
die "Invalid printer $printerName; create printer failed.\n"
|
||||
unless ($p and $p->prop('type') eq 'printer');
|
||||
@printers = ($p);
|
||||
}
|
||||
else
|
||||
{
|
||||
@printers = $adb->printers;
|
||||
}
|
||||
|
||||
foreach (@printers)
|
||||
{
|
||||
$printerName = $_->key;
|
||||
unless (-d "/var/spool/lpd/$printerName")
|
||||
{
|
||||
mkdir ("/var/spool/lpd/$printerName", 0700)
|
||||
or die "Could not create spool directory " .
|
||||
"'/var/spool/lpd/$printerName'; $! : create printer failed.\n";
|
||||
esmith::util::chownFile ("lp", "lp", "/var/spool/lpd/$printerName");
|
||||
}
|
||||
}
|
||||
|
||||
exit (0);
|
48
root/etc/e-smith/events/actions/printer-delete
Executable file
48
root/etc/e-smith/events/actions/printer-delete
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# copyright (C) 1999 Ip, Tak Hong
|
||||
# copyright (C) 2000-2005 Mitel Networks Corporation
|
||||
#
|
||||
# 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
|
||||
#
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
package esmith;
|
||||
|
||||
use strict;
|
||||
use Errno;
|
||||
|
||||
use esmith::AccountsDB;
|
||||
my $adb = esmith::AccountsDB->open_ro();
|
||||
|
||||
my $event = $ARGV [0];
|
||||
my $printerName = $ARGV [1];
|
||||
|
||||
#------------------------------------------------------------
|
||||
# delete the printer
|
||||
#------------------------------------------------------------
|
||||
|
||||
die "printerName argument missing." unless defined ($printerName);
|
||||
|
||||
my $p = $adb->get($printerName);
|
||||
die "Invalid printer $printerName; delete printer failed.\n" unless
|
||||
(defined $p && $p->prop('type') eq 'printer-deleted');
|
||||
|
||||
system("/bin/rm", "-rf", "/var/spool/lpd/$printerName") == 0
|
||||
or die "Could not delete spool directory '/var/spool/lpd/$printerName';" .
|
||||
"delete printer failed.\n";
|
||||
|
||||
exit (0);
|
177
root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/printers
Executable file
177
root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/printers
Executable file
@@ -0,0 +1,177 @@
|
||||
<lexicon lang="en-us">
|
||||
<entry>
|
||||
<base>FORM_TITLE</base>
|
||||
<trans>Add or remove printers</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>INITIAL_DESC</base>
|
||||
<trans>
|
||||
<![CDATA[
|
||||
<P><A class="button-like" HREF="printers?page=0&Next=Add">Add printer</A></P>
|
||||
]]>
|
||||
</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>NO_PRINTERS</base>
|
||||
<trans>There are no printers in the system.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CURRENT_LIST</base>
|
||||
<trans>Current List of printers</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>REMOTE_ADDRESS</base>
|
||||
<trans>Remote address</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>REMOTE_NAME</base>
|
||||
<trans>Remote name</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CREATE_NEW_PRINTER</base>
|
||||
<trans>Create a new printer</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CREATE_NEW_DESC</base>
|
||||
<trans>
|
||||
Please choose a unique name for the printer and enter a brief
|
||||
description. The printer name should contain only lower-case
|
||||
letters and numbers, and should start with a lower-case
|
||||
letter. For example "hplaser", "epsonlp", and
|
||||
"canonbj" are valid choices, but "HP Laser Jet",
|
||||
"Canon BubbleJet", and
|
||||
"HP JetDirect Printer" are not.
|
||||
Avoid names and descriptions that contain these terms,
|
||||
"offline", "disabled", "down", "off", "waiting", "jam",
|
||||
"paper", "error" and "responding".
|
||||
</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>PRINTER_NAME</base>
|
||||
<trans>Printer name</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>LOCAL_PRINTER_0</base>
|
||||
<trans>Local printer port 0 (LPT1)</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>LOCAL_PRINTER_1</base>
|
||||
<trans>Local printer port 1 (LPT2)</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>LOCAL_PRINTER_2</base>
|
||||
<trans>Local printer port 2 (LPT3)</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>NET_PRINTER</base>
|
||||
<trans>Network printer ...</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>FIRST_USB_PRINTER</base>
|
||||
<trans>First USB attached printer</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>SECOND_USB_PRINTER</base>
|
||||
<trans>Second USB attached printer</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_UNEXPECTED_NAME</base>
|
||||
<trans>
|
||||
<![CDATA[
|
||||
<P>Error: unexpected characters in printer name.</P>
|
||||
<P>The printer name should contain only lower-case
|
||||
letters and numbers, and should start with a lower-case
|
||||
letter. For example "hplaser", "epsonlp", and
|
||||
"canonbj" are valid names.</P>
|
||||
]]>
|
||||
</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_UNEXPECTED_DESC</base>
|
||||
<trans>
|
||||
Error: unexpected or missing characters in description.
|
||||
Did not create new printer.
|
||||
</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_EXISTS</base>
|
||||
<trans>Error: An account with the same name exists with type: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_INVALID_ADDRESS</base>
|
||||
<trans>Error: invalid network address. Did not create new printer.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_INVALID_REMOTE_NAME</base>
|
||||
<trans>Error: invalid network printer name. Did not create new printer.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_CREATING</base>
|
||||
<trans>Error occurred while creating printer.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CREATED_SUCCESSFULLY</base>
|
||||
<trans>Successfully created printer: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CREATE_NETWORK_PRINTER</base>
|
||||
<trans>Create a new network printer</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_OPENING_DB</base>
|
||||
<trans>Error occurred while opening accounts database.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CREATE_NETWORK_DESC</base>
|
||||
<trans>Please enter the address and name of the network printer</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>HOSTNAME_OR_IP</base>
|
||||
<trans>Hostname or IP address of the network printer</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>REMOTE_NAME_DESC</base>
|
||||
<trans>
|
||||
<![CDATA[
|
||||
Network printer name (enter raw if not sure)
|
||||
]]>
|
||||
</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>REMOVE_PRINTER</base>
|
||||
<trans>Remove printer</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ABOUT_TO_REMOVE</base>
|
||||
<trans>You are about to remove the printer: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>SPOOL_FILE_WARNING</base>
|
||||
<trans>All the spool files for this printer will be deleted.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ARE_YOU_SURE</base>
|
||||
<trans>Are you sure you wish to remove this printer?</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_INTERNAL_FAILURE</base>
|
||||
<trans>Error: internal failure while removing printer: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_DELETING</base>
|
||||
<trans>Error occurred while deleting printer.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>DELETED_SUCCESSFULLY</base>
|
||||
<trans>Successfully deleted printer: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>MUST_BE_VALID_HOSTNAME_OR_IP</base>
|
||||
<trans>Must be a valid hostname or IP number</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>Printers</base>
|
||||
<trans>Printers</trans>
|
||||
</entry>
|
||||
|
||||
</lexicon>
|
1
root/etc/e-smith/templates.metadata/etc/lpd/lpd.perms
Normal file
1
root/etc/e-smith/templates.metadata/etc/lpd/lpd.perms
Normal file
@@ -0,0 +1 @@
|
||||
TEMPLATE_PATH="/etc/lpd.perms"
|
9
root/etc/e-smith/templates/etc/lpd.perms/10printing
Normal file
9
root/etc/e-smith/templates/etc/lpd.perms/10printing
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Printing (ie unspooling) requests
|
||||
#
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
# Accept all requests
|
||||
ACCEPT SERVICE=P
|
9
root/etc/e-smith/templates/etc/lpd.perms/20spooling
Normal file
9
root/etc/e-smith/templates/etc/lpd.perms/20spooling
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Spooling (ie lpr) requests
|
||||
#
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
# Accept all requests
|
||||
ACCEPT SERVICE=R
|
15
root/etc/e-smith/templates/etc/lpd.perms/30control
Normal file
15
root/etc/e-smith/templates/etc/lpd.perms/30control
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Control (ie lpc) requests
|
||||
#
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
# Allow root on the server to control jobs
|
||||
ACCEPT SERVICE=C SERVER REMOTEUSER=root
|
||||
|
||||
# Allow all others access only to server, status and printcap
|
||||
ACCEPT SERVICE=C LPC=lpd,status,printcap
|
||||
|
||||
# Reject all other requests
|
||||
REJECT SERVICE=C
|
15
root/etc/e-smith/templates/etc/lpd.perms/40removal
Normal file
15
root/etc/e-smith/templates/etc/lpd.perms/40removal
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Removal (ie lprm) requests
|
||||
#
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
# Allow same user on originating host to remove a job
|
||||
ACCEPT SERVICE=M SAMEHOST SAMEUSER
|
||||
|
||||
# Allow root on the server to remove a job
|
||||
ACCEPT SERVICE=M SERVER REMOTEUSER=root
|
||||
|
||||
# Reject all other requests
|
||||
REJECT SERVICE=M
|
9
root/etc/e-smith/templates/etc/lpd.perms/50information
Normal file
9
root/etc/e-smith/templates/etc/lpd.perms/50information
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Information (ie lpq) requests
|
||||
#
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
# Allow all requests
|
||||
ACCEPT SERVICE=Q
|
37
root/etc/e-smith/templates/etc/lpd.perms/60access
Normal file
37
root/etc/e-smith/templates/etc/lpd.perms/60access
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Connection access. This controls access to ALL the request types. If
|
||||
# a host does not match one of these rules it will be denied access,
|
||||
# regardless of ANY of the other rules above.
|
||||
#
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
# Allow connections from the localhost
|
||||
ACCEPT SERVICE=X REMOTEIP=127.0.0.1
|
||||
|
||||
# Allow connections from subnets in our control
|
||||
{
|
||||
use esmith::NetworksDB;
|
||||
|
||||
my $ndb = esmith::NetworksDB->open_ro();
|
||||
|
||||
my $prefix = "ACCEPT SERVICE=X REMOTEIP=";
|
||||
|
||||
my ($network, undef) =
|
||||
esmith::util::computeNetworkAndBroadcast($LocalIP, $LocalNetmask);
|
||||
|
||||
my $result = $prefix . "${network}/${LocalNetmask}";
|
||||
|
||||
foreach my $net ($ndb->get_all_by_prop(type=>'network'))
|
||||
{
|
||||
my $key = $net->key;
|
||||
my %properties = $net->props;
|
||||
$result .= "\n" . $prefix . "${key}/$properties{'Mask'}";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
# Reject all other connections
|
||||
REJECT SERVICE=X
|
9
root/etc/e-smith/templates/etc/lpd.perms/70default
Normal file
9
root/etc/e-smith/templates/etc/lpd.perms/70default
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Default action
|
||||
#
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
# Reject anything which has not been explicitly allowed
|
||||
DEFAULT=REJECT
|
13
root/etc/e-smith/templates/etc/printcap/00example
Normal file
13
root/etc/e-smith/templates/etc/printcap/00example
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#--------------------------------------------------
|
||||
# Example printcap entry:
|
||||
#
|
||||
# hplaser|HP Laser 5:\
|
||||
# :server:\
|
||||
# :mx#0:\
|
||||
# :sh:\
|
||||
# :ff_separator=false:\
|
||||
# :sd=/var/spool/lpd/hplaser:\
|
||||
# :lp=/dev/lp0:
|
||||
#--------------------------------------------------
|
||||
|
42
root/etc/e-smith/templates/etc/printcap/05printer
Normal file
42
root/etc/e-smith/templates/etc/printcap/05printer
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
# process all accounts
|
||||
|
||||
use esmith::AccountsDB;
|
||||
my $adb = esmith::AccountsDB->open_ro();
|
||||
|
||||
$OUT = "";
|
||||
|
||||
foreach my $printer ( $adb->printers )
|
||||
{
|
||||
$OUT .= "\n";
|
||||
$OUT .= $printer->key;
|
||||
$OUT .= "|" . $printer->prop('Description') . ":\\\n";
|
||||
$OUT .= "\t:server:\\\n";
|
||||
$OUT .= "\t:mx#0:\\\n";
|
||||
$OUT .= "\t:sh:\\\n";
|
||||
$OUT .= "\t:ff_separator=false:\\\n";
|
||||
$OUT .= "\t:sd=/var/spool/lpd/" . $printer->key . ":\\\n";
|
||||
|
||||
if ($printer->prop('Location') eq 'remote')
|
||||
{
|
||||
$OUT .= "\t:rm=" . $printer->prop('Address') . ":\\\n";
|
||||
|
||||
# no trailing backslash for last entry
|
||||
|
||||
if (defined $printer->prop('RemoteName'))
|
||||
{
|
||||
$OUT .= "\t:rp=" . $printer->prop('RemoteName') . ":\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "\t:rp=raw:\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# no trailing backslash for last entry
|
||||
$OUT .= "\t:lp=/dev/" . $printer->prop('Location') . ":\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
14
root/etc/e-smith/templates/etc/smb.conf/20printing
Normal file
14
root/etc/e-smith/templates/etc/smb.conf/20printing
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
# if you want to automatically load your printer list rather
|
||||
# than setting them up individually then you'll need this
|
||||
# It should not be necessary to spell out the print system type unless
|
||||
# yours is non-standard. Currently supported print systems include:
|
||||
# bsd, sysv, plp, lprng, aix, hpux, qnx
|
||||
|
||||
$OUT .= <<HERE;
|
||||
printcap name = /etc/printcap
|
||||
load printers = yes
|
||||
printing = lprng
|
||||
print command = /usr/bin/lpr -b -h -r -P%p %s
|
||||
HERE
|
||||
}
|
16
root/etc/e-smith/templates/etc/smb.conf/50printers
Normal file
16
root/etc/e-smith/templates/etc/smb.conf/50printers
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
# NOTE: If you have a BSD-style print system there is no need to
|
||||
# specifically define each individual printer
|
||||
# Set public = yes to allow user 'guest account' to print
|
||||
$OUT = <<HERE;
|
||||
[printers]
|
||||
comment = All Printers
|
||||
path = /var/spool/samba
|
||||
browseable = no
|
||||
guest ok = no
|
||||
writable = no
|
||||
printable = yes
|
||||
HERE
|
||||
$OUT .= "use client driver = ";
|
||||
$OUT .= $smb{UseClientDriver} || "yes";
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
# lpd specific service (lpd in init.d)
|
||||
{
|
||||
$status = $lpd{status} || 'disabled';
|
||||
$status = ($status eq "enabled") ? "enable" : "disable";
|
||||
$OUT .= "$status lpd.service\n";
|
||||
}
|
||||
|
6
root/etc/e-smith/tests/30e-smith-LPRng/accounts
Normal file
6
root/etc/e-smith/tests/30e-smith-LPRng/accounts
Normal file
@@ -0,0 +1,6 @@
|
||||
# DO NOT MODIFY THIS FILE.
|
||||
# This file is automatically maintained by the Mitel Networks SME Server
|
||||
# configuration software. Manually editing this file may put your
|
||||
# system in an unknown state.
|
||||
#
|
||||
# updated: Tue May 28 15:10:57 2002
|
83
root/etc/e-smith/web/functions/printers
Executable file
83
root/etc/e-smith/web/functions/printers
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/perl -wT
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# heading : Configuration
|
||||
# description : Printers
|
||||
# navigation : 6000 6400
|
||||
#
|
||||
# copyright (C) 2002 Mitel Networks Corp.
|
||||
#
|
||||
# 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;
|
||||
use esmith::FormMagick::Panel::printers;
|
||||
|
||||
my $fm = esmith::FormMagick::Panel::printers->new();
|
||||
$fm->display();
|
||||
|
||||
__DATA__
|
||||
<form title="FORM_TITLE" header="/etc/e-smith/web/common/head.tmpl"
|
||||
footer="/etc/e-smith/web/common/foot.tmpl">
|
||||
<page name="First" pre-event="print_status_message">
|
||||
<description>INITIAL_DESC</description>
|
||||
<subroutine src="show_printers()"/>
|
||||
</page>
|
||||
|
||||
<page name="Add" pre-event="print_status_message"
|
||||
post-event="create_printer">
|
||||
<title>CREATE_NEW_PRINTER</title>
|
||||
<description>CREATE_NEW_DESC</description>
|
||||
<field id="name" type="text" validation="nonblank, maxlength(32)">
|
||||
<label>PRINTER_NAME</label>
|
||||
</field>
|
||||
<field id="description" type="text" validation="nonblank, maxlength(32)">
|
||||
<label>DESCRIPTION_BRIEF</label>
|
||||
</field>
|
||||
<field id="location" type="select" options="'lp0'=>'LOCAL_PRINTER_0',
|
||||
'lp1'=>'LOCAL_PRINTER_1','lp2'=>'LOCAL_PRINTER_2','remote'=>'NET_PRINTER',
|
||||
'usb/lp0'=>'FIRST_USB_PRINTER','usb/lp1'=>'SECOND_USB_PRINTER'"
|
||||
value="remote" validation="nonblank">
|
||||
<label>LOCATION</label>
|
||||
</field>
|
||||
<subroutine src="print_button('ADD')"/>
|
||||
</page>
|
||||
|
||||
<page name="AddNetwork" pre-event="turn_off_buttons"
|
||||
post-event="create_printer">
|
||||
<title>CREATE_NETWORK_PRINTER</title>
|
||||
<description>CREATE_NETWORK_DESC</description>
|
||||
<field id="address" type="text" validation="hostname_or_ip">
|
||||
<label>HOSTNAME_OR_IP</label>
|
||||
</field>
|
||||
<field id="remoteName" type="text" value="raw" validation="nonblank">
|
||||
<label>REMOTE_NAME_DESC</label>
|
||||
</field>
|
||||
<subroutine src="print_hidden_fields()"/>
|
||||
<subroutine src="print_button('ADD')"/>
|
||||
</page>
|
||||
|
||||
<page name="Delete" pre-event="turn_off_buttons">
|
||||
</page>
|
||||
|
||||
<page name="ConfirmDelete" pre-event="turn_off_buttons"
|
||||
post-event="delete_printer">
|
||||
<title>REMOVE_PRINTER</title>
|
||||
<subroutine src="show_delete_confirmation()"/>
|
||||
<subroutine src="print_button('REMOVE')"/>
|
||||
</page>
|
||||
|
||||
</form>
|
15
root/usr/lib/systemd/system/lpd.service
Normal file
15
root/usr/lib/systemd/system/lpd.service
Normal file
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=lpd, LPRng print spool
|
||||
After=network.target
|
||||
Requires=runit.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStartPre=/sbin/e-smith/service-status lpd
|
||||
ExecStart=/usr/bin/sv u /service/lpd
|
||||
ExecStop=/usr/bin/sv stop /service/lpd
|
||||
ExecReload=/usr/bin/sv t /service/lpd
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=sme-server.target
|
@@ -0,0 +1,486 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Copyright (C) 2002 Mitel Networks Corporation
|
||||
#
|
||||
# $Id: printers.pm,v 1.9 2004/01/07 01:43:22 msoulier Exp $
|
||||
#
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
package esmith::FormMagick::Panel::printers;
|
||||
|
||||
use esmith::FormMagick;
|
||||
use esmith::AccountsDB;
|
||||
use esmith::cgi;
|
||||
use Exporter;
|
||||
|
||||
our @ISA = qw(esmith::FormMagick Exporter);
|
||||
our @EXPORT = qw(
|
||||
show_printers create_printer print_hidden_fields
|
||||
show_delete_confirmation delete_printer
|
||||
hostname_or_ip
|
||||
);
|
||||
our @VERSION = sprintf '%d.%03d', q$Revision: 1.9 $ =~ /: (\d+).(\d+)/;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
esmith::FormMagick::Panel::printers - useful panel functions
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use esmith::FormMagick::Panel::printers;
|
||||
my $panel = esmith::FormMagick::Panel::printers->new();
|
||||
$panel->display();
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
=head2 new
|
||||
|
||||
Exactly as for esmith::FormMagick.
|
||||
|
||||
=begin testing
|
||||
use_ok('esmith::FormMagick::Panel::printers');
|
||||
$FM = esmith::FormMagick::Panel::printers->new();
|
||||
isa_ok($FM, 'esmith::FormMagick::Panel::printers');
|
||||
$FM->{testing} = 1; # set test mode
|
||||
$FM->{cgi} = CGI->new();
|
||||
truncate("30e-smith-LPRng/accounts",0);
|
||||
|
||||
=end testing
|
||||
|
||||
=cut
|
||||
|
||||
sub new
|
||||
{
|
||||
shift;
|
||||
my $self = esmith::FormMagick->new();
|
||||
$self->{calling_package} = (caller)[0];
|
||||
bless $self;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
=head2 hostname_or_ip
|
||||
|
||||
Validation routine for the remote address field for network printers.
|
||||
|
||||
=for testing
|
||||
my $fm = esmith::FormMagick::Panel::printers->new();
|
||||
can_ok('main', 'hostname_or_ip');
|
||||
can_ok('CGI::FormMagick::Validator', 'ip_number');
|
||||
isnt(CGI::FormMagick::Validator::ip_number($fm, '1.2.3'), "OK", "ip_number works OK");
|
||||
like(CGI::FormMagick::Validator::ip_number($fm, '1.2.3'), qr(enough octets), "ip_number works OK");
|
||||
foreach ("1.2.3.4", "255.255.255.255", "foo.com", "foo.bar.com", "123.foo.xxx"){
|
||||
is(hostname_or_ip($fm, $_), "OK", "$_ should be OK");
|
||||
}
|
||||
foreach ("1.2.3", "foo bar", "foo;bar;com", " ", undef) {
|
||||
isnt(hostname_or_ip($fm, $_), "OK", "$_ should not be OK");
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub hostname_or_ip
|
||||
{
|
||||
my ($fm, $data) = @_;
|
||||
if ($data =~ /^[\d\.]+$/) {
|
||||
if (CGI::FormMagick::Validator::ip_number($fm, $data) eq "OK")
|
||||
{
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "MUST_BE_VALID_HOSTNAME_OR_IP";
|
||||
}
|
||||
}
|
||||
elsif ($data =~ /^([a-zA-Z0-9\.\-]+)$/ )
|
||||
{
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "MUST_BE_VALID_HOSTNAME_OR_IP";
|
||||
}
|
||||
}
|
||||
|
||||
=pod
|
||||
|
||||
=head2 show_printers
|
||||
|
||||
Reads the list of printers from accounts database and shows it as a table.
|
||||
|
||||
=begin testing
|
||||
|
||||
$FM->show_printers();
|
||||
like($_STDOUT_, qr/NO_PRINTERS/, 'show_printers');
|
||||
|
||||
=end testing
|
||||
|
||||
=cut
|
||||
|
||||
sub show_printers
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
my $adb;
|
||||
if ($self->{testing})
|
||||
{
|
||||
$adb = esmith::AccountsDB->open('30e-smith-LPRng/accounts');
|
||||
}
|
||||
else
|
||||
{
|
||||
$adb = esmith::AccountsDB->open();
|
||||
}
|
||||
|
||||
my @printerDrivers;
|
||||
if ($adb)
|
||||
{
|
||||
@printerDrivers = $adb->printers();
|
||||
}
|
||||
|
||||
print '<tr><td colspan="2">';
|
||||
my $numPrinters = @printerDrivers;
|
||||
if ($numPrinters == 0)
|
||||
{
|
||||
print $q->p($self->localise('NO_PRINTERS'));
|
||||
}
|
||||
else
|
||||
{
|
||||
print $q->h3($self->localise('CURRENT_LIST'));
|
||||
|
||||
print $q->start_table ({-CLASS => "sme-border"});
|
||||
|
||||
print $q->Tr (esmith::cgi::genSmallCell($q, $self->localise('NAME'),"header"),
|
||||
esmith::cgi::genSmallCell($q, $self->localise('DESCRIPTION'),"header"),
|
||||
esmith::cgi::genSmallCell($q, $self->localise('LOCATION'),"header"),
|
||||
esmith::cgi::genSmallCell($q, $self->localise('REMOTE_ADDRESS'),"header"),
|
||||
esmith::cgi::genSmallCell($q, $self->localise('REMOTE_NAME'),"header"),
|
||||
esmith::cgi::genSmallCell($q, $self->localise('ACTION'),"header"));
|
||||
|
||||
my $printer;
|
||||
foreach $printer (sort @printerDrivers)
|
||||
{
|
||||
my $address = ($printer->prop('Location') eq 'remote')
|
||||
? $printer->prop('Address') : 'N/A';
|
||||
my $remoteName = ($printer->prop('Location') eq 'remote')
|
||||
? $printer->prop('RemoteName') : 'N/A';
|
||||
unless ($remoteName)
|
||||
{
|
||||
$remoteName = 'raw';
|
||||
}
|
||||
|
||||
print $q->Tr (esmith::cgi::genSmallCell ($q, $printer->key, "normal"),
|
||||
esmith::cgi::genSmallCell ($q, $printer->prop('Description'), "normal"),
|
||||
esmith::cgi::genSmallCell ($q, $printer->prop('Location'), "normal"),
|
||||
esmith::cgi::genSmallCell ($q, $address, "normal"),
|
||||
esmith::cgi::genSmallCell ($q, $remoteName, "normal"),
|
||||
esmith::cgi::genSmallCell ($q,
|
||||
$q->a ({href => $q->url (-absolute => 1)
|
||||
."?page=".$self->get_page_by_name('Delete')
|
||||
."&Next=Delete&printer=". $printer->key},
|
||||
$self->localise('REMOVE')), "normal"));
|
||||
}
|
||||
|
||||
print $q->end_table,"\n";
|
||||
}
|
||||
print '</td></tr>';
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
=pod
|
||||
|
||||
=head2 create_printer
|
||||
|
||||
Process the output of the Add page, validate the data and create the printer
|
||||
if all is well.
|
||||
|
||||
=begin testing
|
||||
|
||||
$FM->{cgi}->param(-name=>'name', -value=>'testprn');
|
||||
$FM->{cgi}->param(-name=>'description', -value=>'A test printer');
|
||||
$FM->{cgi}->param(-name=>'location', -value=>'lp0');
|
||||
$FM->create_printer();
|
||||
like($FM->{cgi}->param('status_message'), qr/SUCCESS/, 'create_printer');
|
||||
|
||||
=end testing
|
||||
|
||||
=cut
|
||||
|
||||
sub create_printer
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Validate parameters and untaint them
|
||||
#------------------------------------------------------------
|
||||
|
||||
my $name = $q->param ('name');
|
||||
if ($name =~ /^([a-z][a-z0-9]*)$/)
|
||||
{
|
||||
$name = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $self->error('ERR_UNEXPECTED_NAME', 'Add');
|
||||
}
|
||||
|
||||
my $description = $q->param ('description');
|
||||
if ($description =~ /^([\'\w\s]+)$/)
|
||||
{
|
||||
$description = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $self->error('ERR_UNEXPECTED_DESC', 'Add');
|
||||
}
|
||||
|
||||
my $location = $q->param ('location');
|
||||
if ($location =~ /^(lp[0-9]+|remote|usb\/lp0|usb\/lp[0-9]+)$/)
|
||||
{
|
||||
$location = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$location = "lp0";
|
||||
}
|
||||
|
||||
my $remoteName = $q->param ('remoteName');
|
||||
my $address = $q->param ('address');
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Looks good. Find out if this printer has been taken
|
||||
#------------------------------------------------------------
|
||||
|
||||
my $adb;
|
||||
if ($self->{testing})
|
||||
{
|
||||
$adb = esmith::AccountsDB->open('30e-smith-LPRng/accounts')
|
||||
|| return $self->error('ERR_OPENING_DB');
|
||||
}
|
||||
else
|
||||
{
|
||||
$adb = esmith::AccountsDB->open()
|
||||
|| return $self->error('ERR_OPENING_DB');
|
||||
}
|
||||
my $rec = $adb->get($name);
|
||||
my $type;
|
||||
if ($rec and ($type = $rec->prop('type')))
|
||||
{
|
||||
return $self->error('ERR_EXISTS', 'Add');
|
||||
}
|
||||
|
||||
if ($location eq 'remote')
|
||||
{
|
||||
unless (defined $address)
|
||||
{
|
||||
$q->param(-name=>'wherenext', -value=>'AddNetwork');
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($address =~ /^([a-zA-Z0-9\.\-]+)$/)
|
||||
{
|
||||
$address = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $self->error('ERR_INVALID_ADDRESS', 'Add');
|
||||
}
|
||||
|
||||
if ($remoteName =~ /^([^\|]*)$/)
|
||||
{
|
||||
$remoteName = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $self->error('ERR_INVALID_REMOTE_NAME', 'Add');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$address = "";
|
||||
$remoteName = "";
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Printer name is available! Update printers database and
|
||||
# singal the create-printer event.
|
||||
#------------------------------------------------------------
|
||||
|
||||
$rec = $adb->new_record($name,
|
||||
{type=>'printer',
|
||||
Description => $description,
|
||||
Address => $address,
|
||||
RemoteName => $remoteName,
|
||||
Location => $location});
|
||||
|
||||
unless ($self->{testing})
|
||||
{
|
||||
system ("/sbin/e-smith/signal-event printer-create $name") == 0
|
||||
or return $self->error('ERR_CREATING');
|
||||
}
|
||||
|
||||
$self->success('CREATED_SUCCESSFULLY');
|
||||
}
|
||||
|
||||
|
||||
=pod
|
||||
|
||||
=head2 print_hidden_fields
|
||||
|
||||
Print hidden fields needed by the AddNetwork page.
|
||||
|
||||
=begin testing
|
||||
|
||||
$FM->print_hidden_fields();
|
||||
like($_STDOUT_, qr/name/, 'hidden name field');
|
||||
like($_STDOUT_, qr/description/, 'hidden description field');
|
||||
like($_STDOUT_, qr/location/, 'hidden location field');
|
||||
|
||||
=end testing
|
||||
|
||||
=cut
|
||||
|
||||
sub print_hidden_fields
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
my $name = $q->param('name');
|
||||
my $description = $q->param('description');
|
||||
my $location = $q->param('location');
|
||||
|
||||
print $q->hidden (-name => 'name',
|
||||
-override => 1, -default => $name);
|
||||
print $q->hidden (-name => 'description',
|
||||
-override => 1, -default => $description);
|
||||
print $q->hidden (-name => 'location',
|
||||
-override => 1, -default => $location);
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
=pod
|
||||
|
||||
=head2 show_delete_confirmation
|
||||
|
||||
Display the delete printer confirmation page contents.
|
||||
|
||||
=begin testing
|
||||
|
||||
$FM->{cgi}->param(-name=>'printer', -value=>'testprn');
|
||||
$FM->show_delete_confirmation();
|
||||
like($_STDOUT_, qr/ABOUT_TO_REMOVE/, 'show_delete_confirmation');
|
||||
|
||||
=end testing
|
||||
|
||||
=cut
|
||||
|
||||
sub show_delete_confirmation
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
my $printer = $q->param ('printer');
|
||||
unless ($printer)
|
||||
{
|
||||
$q->param(-name=>'wherenext', -value=>'First');
|
||||
return '';
|
||||
}
|
||||
|
||||
my $adb;
|
||||
if ($self->{testing})
|
||||
{
|
||||
$adb = esmith::AccountsDB->open('30e-smith-LPRng/accounts')
|
||||
|| return $self->error('ERR_OPENING_DB');
|
||||
}
|
||||
else
|
||||
{
|
||||
$adb = esmith::AccountsDB->open()
|
||||
|| return $self->error('ERR_OPENING_DB');
|
||||
}
|
||||
|
||||
my $rec = $adb->get($printer);
|
||||
if ($rec and $rec->prop('type') eq 'printer')
|
||||
{
|
||||
my $description = $rec->prop('Description');
|
||||
|
||||
print '<tr><td>';
|
||||
print $q->p($self->localise('ABOUT_TO_REMOVE').
|
||||
"$printer ($description)");
|
||||
print $q->p($self->localise('SPOOL_FILE_WARNING'));
|
||||
print $q->p($q->b($self->localise('ARE_YOU_SURE')));
|
||||
print '</td></tr>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
=pod
|
||||
|
||||
=head2 delete_printer
|
||||
|
||||
Remove a printer from the accounts database
|
||||
|
||||
=begin testing
|
||||
|
||||
$FM->{cgi}->param(-name=>'printer', -value=>'testprn');
|
||||
$FM->delete_printer();
|
||||
like($FM->{cgi}->param('status_message'), qr/DELETED_SUCCESSFULLY/,
|
||||
'delete_printer');
|
||||
|
||||
=end testing
|
||||
|
||||
=cut
|
||||
|
||||
sub delete_printer
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Attempt to delete printer
|
||||
#------------------------------------------------------------
|
||||
|
||||
my $printer = $q->param ('printer');
|
||||
|
||||
if ($printer =~ /^([a-z][a-z0-9]*)$/)
|
||||
{
|
||||
$printer = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $self->error('ERR_INTERNAL_FAILURE');
|
||||
}
|
||||
|
||||
my $adb;
|
||||
if ($self->{testing})
|
||||
{
|
||||
$adb = esmith::AccountsDB->open('30e-smith-LPRng/accounts')
|
||||
|| return $self->error('ERR_OPENING_DB');
|
||||
}
|
||||
else
|
||||
{
|
||||
$adb = esmith::AccountsDB->open()
|
||||
|| return $self->error('ERR_OPENING_DB');
|
||||
}
|
||||
|
||||
my $rec = $adb->get($printer);
|
||||
unless ($rec)
|
||||
{
|
||||
return $self->error('ERR_INTERNAL_FAILURE');
|
||||
}
|
||||
|
||||
$rec->set_prop('type', 'printer-deleted');
|
||||
unless ($self->{testing})
|
||||
{
|
||||
system ("/sbin/e-smith/signal-event printer-delete $printer") == 0
|
||||
or return $self->error('ERR_DELETING');
|
||||
}
|
||||
$rec->delete();
|
||||
|
||||
$self->success('DELETED_SUCCESSFULLY');
|
||||
}
|
||||
|
||||
1;
|
0
root/var/service/lpd/down
Normal file
0
root/var/service/lpd/down
Normal file
2
root/var/service/lpd/run
Normal file
2
root/var/service/lpd/run
Normal file
@@ -0,0 +1,2 @@
|
||||
#! /bin/sh
|
||||
exec /usr/sbin/lpd -F
|
Reference in New Issue
Block a user