&lock_file($drv);
if ($gconfig{'os_version'} >= 2.4) {
# Create the 2.4 driver program
- system("cp $base_driver $drv");
+ ©_source_dest($base_driver, $drv);
}
else {
# Create the 2.3 driver program
}
&remote_error_setup(\&add_error);
-# Make sure each host is set up for firewalling
+# Make sure each host is set up for printer administration
foreach $s (@add) {
$add_error_msg = undef;
local $host = { 'id' => $s->{'id'} };
next;
}
- @printers = &remote_foreign_call($s->{'host'}, "lpadmin", "list_printers");
+ @printers = &remote_foreign_call($s->{'host'}, "lpadmin",
+ "list_printers");
print &text('add_ok', $s->{'host'}, scalar(@printers)),"<p>\n";
&add_cluster_server($s);
}
printf "<tr> <td valign=top><input type=radio name=mode value=1 %s> %s</td>\n",
$_[1]->{'mode'} == 1 ? 'checked' : '', $text{'cups_driver'};
local (@ppds, $d, $f, $ppd, %cache, $outofdate, @files, %donefile);
-local $findver = `find --version 2>&1`;
-local $flag = $findver =~ /GNU\s+find\s+version\s+4\.2/i ? "-L" : "";
-open(FIND, "find $flag ".quotemeta($config{'model_path'})." -type f -print |");
+local $findver = &backquote_command("find --version 2>&1", 1);
+local $flag = $findver =~ /GNU\s+find\s+version\s+([0-9\.]+)/i && $1 >= 4.2 ?
+ "-L" : "";
+&open_execute_command(FIND, "find $flag ".quotemeta($config{'model_path'}).
+ " -type f -print", 1, 1);
while(<FIND>) {
chop;
/([^\/]+)$/;
{
local($stat, @rv, $body, $avl, $con, $sys, %prn, $_, $out);
local $esc = quotemeta($_[0]);
-$out = `$lpstat -l -p $esc`;
+$out = &backquote_command("$lpstat -l -p $esc", 1);
return undef if ($out =~ /non-existent\s+printer/);
if ($out =~ /^printer\s+(\S+)\s+(\S+).*\n([\000-\377]*)$/) {
# printer exists..
if (!$_[1]) {
# request availability
- $avl = `$lpstat -a $prn{'name'} 2>&1`;
+ $avl = &backquote_command("$lpstat -a $prn{'name'} 2>&1", 1);
if ($avl =~ /^\S+\s+not accepting.*\n\s*(.*)/) {
$prn{'accepting'} = 0;
$prn{'accepting_why'} = lc($1) eq "reason unknown" ? "" : $1;
}
}
if (!$uri) {
- $con = `$lpstat -v $prn{'name'} 2>&1`;
+ $con = &backquote_command("$lpstat -v $prn{'name'} 2>&1", 1);
if ($con =~ /^device for \S+:\s+(\S+)/) {
$uri = $1;
}
}
# Check if this is the default printer
-`$lpstat -d 2>&1` =~ /destination: (\S+)/;
-if ($1 eq $prn{'name'}) { $prn{'default'} = 1; }
+if (&backquote_command("$lpstat -d 2>&1", 1) =~ /destination:\s+(\S+)/ &&
+ $1 eq $prn{'name'}) {
+ $prn{'default'} = 1;
+ }
return \%prn;
}
sub list_classes
{
local($stat, %rv);
-$stat = `$lpstat -c 2>&1`;
+$stat = &backquote_command("$lpstat -c 2>&1", 1);
while($stat =~ /^members of class (\S+):\n((\s+\S+\n)+)([\000-\377]*)$/) {
$stat = $4;
$rv{$1} = [ grep { $_ ne "" } split(/\s+/, $2) ];
if (!$_[1]) {
# call lpc to get status
local $esc = quotemeta($prn{'name'});
- $out = `lpc status $esc 2>&1`;
+ $out = &backquote_command("lpc status $esc 2>&1", 1);
$prn{'accepting'} = ($out =~ /queuing is enabled/);
$prn{'enabled'} = ($out =~ /printing is enabled/);
}
{
local($out);
local $esc = quotemeta($_[0]->{'name'});
-$out = `lpc status $esc 2>&1`;
+$out = &backquote_command("lpc status $esc 2>&1", 1);
if ($_[0]->{'enabled'} && $out !~ /printing is enabled/)
{ &backquote_logged("lpc up $esc"); }
elsif (!$_[0]->{'enabled'} && $out =~ /printing is enabled/)
print "</select></td> </tr>\n";
if (&has_ghostscript()) {
- local $out = `$config{'gs_path'} -help 2>&1`;
+ local $out = &backquote_command("$config{'gs_path'} -help 2>&1", 1);
if ($out =~ /Available devices:\n((\s+.*\n)+)/) {
print "<tr> <td valign=top>\n";
printf "<input type=radio name=drv value=1 %s>\n",
close(STAT);
# make models executable
-`chmod 755 $config{'model_path'}/*`;
+&system_logged("chmod 755 $config{'model_path'}/* >/dev/null 2>&1");
return &unique(@rv);
}
{
local($stat, @rv, $body1, $body2, $avl, $con, $sys, %prn, $_, $out);
local $esc = quotemeta($_[0]);
-$out = `lpstat -p$esc`;
+$out = &backquote_command("lpstat -p$esc", 1);
if ($out =~ /^printer\s+(\S+)\s+(.*)\n(.*)\n(.*)$/) {
# printer exists
$prn{'name'} = $1;
if (!$_[1]) {
# request availability
- $avl = `lpstat -a$esc 2>&1`;
+ $avl = &backquote_command("lpstat -a$esc 2>&1", 1);
if ($avl =~ /^\S+\s+not accepting.*\n\s+(.*)/) {
$prn{'accepting'} = 0;
$prn{'accepting_why'} = $1;
}
# request connection
-$con = `lpstat -v$esc 2>&1`;
+$con = &backquote_command("lpstat -v$esc 2>&1", 1);
if ($con =~ /^device for \S+:\s+(\S+)\n\s+(remote to:)\s+(\S+)\s+(on)\s+(\S+)/) {
$prn{'rhost'} = $5;
$prn{'rqueue'} = $3;
elsif ($con =~ /^device for \S+:\s+(\S+)/) { $prn{'dev'} = $1; }
# Check if this is the default printer
-`lpstat -d 2>&1` =~ /destination: (\S+)/;
-if ($1 eq $prn{'name'}) { $prn{'default'} = 1; }
+if (&backquote_command("$lpstat -d 2>&1", 1) =~ /destination:\s+(\S+)/ &&
+ $1 eq $prn{'name'}) {
+ $prn{'default'} = 1;
+ }
return \%prn;
}
$desc = $drv->{'desc'};
}
elsif ($drv->{'mode'} == 2) {
- $out = `head $drv->{'prog'} | grep -e interface -e Printer -e /model/`;
+ $out = &backquote_command("head $drv->{'prog'} | grep -e interface -e Printer -e /model/", 1);
if ($out =~ /interface for\s+(.*)/) { $desc = $1; }
elsif ($out =~ /\s+(\S.*)interface/) { $desc = $1; }
elsif ($out =~ /Printer Command Language level\s+(\S+)/) { $desc = "PCL$1"; }
sub list_classes
{
local($stat, %rv);
-$stat = `lpstat -c 2>&1`;
+$stat = &backquote_command("lpstat -c 2>&1", 1);
while($stat =~ /^members of class (\S+):\n((\s+\S+\n)+)([\000-\377]*)$/) {
$stat = $4;
$rv{$1} = [ grep { $_ ne "" } split(/\s+/, $2) ];
local $wdrv = &is_windows_driver($prn{'iface'});
local $hdrv = &is_hpnp_driver($prn{'iface'});
$scheduler = &sched_running();
-$dummy = "webmin.tmp"; `touch $config{'model_path'}/$dummy`;
+$dummy = "webmin.tmp";
+&system_logged("touch $config{'model_path'}/$dummy");
# create lpadmin command
local $esc = quotemeta($prn{'name'});
## Link to windows webmin driver
&lock_file("$hpux_iface_path/$prn{'name'}");
if ($wdrv) {
- `rm $hpux_iface_path/$esc`;
- `ln -s $drivers_directory/$esc.smb $hpux_iface_path/$esc`;
+ &unlink_file("$hpux_iface_path/$prn{'name'}");
+ &symlink_file("$drivers_directory/$prn{'name'}.smb",
+ "$hpux_iface_path/$prn{'name'}");
}
## Link to webmin hpnp driver
if ($hdrv) {
- `rm $hpux_iface_path/$esc`;
- `ln -s $drivers_directory/$esc.hpnp $hpux_iface_path/$esc`;
+ &unlink_file("$hpux_iface_path/$prn{'name'}");
+ &symlink_file("$drivers_directory/$prn{'name'}.hpnp",
+ "$hpux_iface_path/$prn{'name'}");
}
## Link to webmin driver
if ($prn{'iface'} eq "$drivers_directory/$prn{'name'}" && !$wdrv) {
- `rm $hpux_iface_path/$esc`;
- `ln -s $drivers_directory/$esc $hpux_iface_path/$esc`;
+ &unlink_file("$hpux_iface_path/$prn{'name'}");
+ &symlink_file("$drivers_directory/$prn{'name'}",
+ "$hpux_iface_path/$prn{'name'}");
}
&unlock_file("$hpux_iface_path/$prn{'name'}");
+
&lock_file("$config{'model_path'}/$dummy");
-`rm $config{'model_path'}/$dummy`;
+&unlink_file("$config{'model_path'}/$dummy");
&unlock_file("$config{'model_path'}/$dummy");
# start scheduler
# Returns 1 if running and 0 if not running
sub sched_running
{
-local $out = `lpstat -r 2>&1`;
+local $out = &backquote_command("lpstat -r 2>&1", 1);
if ($out =~ /not/) { return 0; }
else { return 1; }
}
}
if ($access{'cluster'} && @allservers) {
print &ui_buttons_row("cluster.cgi",
- $text{'index_cluster'}, $text{'index_clusterdesc'});
+ $text{'index_cluster'}, $text{'index_clusterdesc'});
}
print &ui_buttons_end();
print "</select></td> </tr>\n";
if (&has_ghostscript()) {
- local $out = `$config{'gs_path'} -help 2>&1`;
+ local $out = &backquote_command("$config{'gs_path'} -help 2>&1", 1);
if ($out =~ /Available devices:\n((\s+.*\n)+)/) {
print "<tr> <td valign=top>\n";
printf "<input type=radio name=drv value=1 %s>\n",
{
local($stat, @rv, $body, $body, $avl, $con, $sys, %prn, $_, $out);
local $esc = quotemeta($_[0]);
-$out = `/usr/bin/lpstat -p$esc`;
+$out = &backquote_command("/usr/bin/lpstat -p$esc", 1);
if ($out =~ /^printer\s+(\S+)\s*(.*)\s+(enabled|disabled)\s+since\s+(.+?)\n?(.*)?$/) {
# printer exists
$prn{'name'} = $1;
if (!$_[1]) {
# request availability
- $avl = `/usr/bin/lpstat -a$esc 2>&1`;
+ $avl = &backquote_command("/usr/bin/lpstat -a$esc 2>&1", 1);
if ($avl =~ /^\S+\s+not accepting.*\n\s+(.*)/) {
$prn{'accepting'} = 0;
$prn{'accepting_why'} = $1;
}
# request connection
-$con = `/usr/bin/lpstat -v$esc 2>&1`;
+$con = &backquote_command("/usr/bin/lpstat -v$esc 2>&1", 1);
if ($con =~ /^device for \S+:\s+(\S+)\n\s+(remote to:)\s+(\S+)\s+(on)\s+(\S+)/) {
$prn{'rhost'} = $5;
$prn{'rqueue'} = $3;
elsif ($con =~ /^device for \S+:\s+(\S+)/) { $prn{'dev'} = $1; }
# Check if this is the default printer
-`/usr/bin/lpstat -d 2>&1` =~ /destination: (\S+)/;
-if ($1 eq $prn{'name'}) { $prn{'default'} = 1; }
+if (&backquote_command("$lpstat -d 2>&1", 1) =~ /destination:\s+(\S+)/ &&
+ $1 eq $prn{'name'}) {
+ $prn{'default'} = 1;
+ }
return \%prn;
}
$desc = $drv->{'desc'};
}
elsif ($drv->{'mode'} == 2) {
- $out = `head $drv->{'prog'} | grep -e interface -e Printer -e /model/`;
+ $out = &backquote_command("head $drv->{'prog'} | grep -e interface -e Printer -e /model/", 1);
if ($out =~ /interface for\s+(.*)/) { $desc = $1; }
elsif ($out =~ /\s+(\S.*)interface/) { $desc = $1; }
elsif ($out =~ /Printer Command Language level\s+(\S+)/) { $desc = "PCL$1"; }
sub list_classes
{
local($stat, %rv);
-$stat = `/usr/bin/lpstat -c 2>&1`;
+$stat = &backquote_command("/usr/bin/lpstat -c 2>&1", 1);
while($stat =~ /^members of class (\S+):\n((\s+\S+\n)+)([\000-\377]*)$/) {
$stat = $4;
$rv{$1} = [ grep { $_ ne "" } split(/\s+/, $2) ];
if ($?) { &error("lpadmin failed : <pre>$out</pre>"); }
if ($prn{'rhost'}) {
- `rm $irix_iface_path/$esc.tmp`;
+ &unlink_file("$irix_iface_path/$prn{'name'}.tmp");
}
## Link to windows webmin driver
# Returns 1 if running and 0 if not running
sub sched_running
{
-local $out = `lpstat -r 2>&1`;
+local $out = &backquote_command("lpstat -r 2>&1", 1);
if ($out =~ /not/) { return 0; }
else { return 1; }
}
jobs_test=Print Test Page
jobs_cancelsel=Cancel Selected Jobs
jobs_on=On printer $1
+jobs_return=list of print jobs
cancel_ecannot=You are not allowed to cancel print jobs
cancel_err=Failed to cancel print job
if (!$_[1]) {
# call lpc to get status
local $esc = quotemeta($prn{'name'});
- $out = `lpc status $esc 2>&1`;
+ $out = &backquote_command("lpc status $esc 2>&1", 1);
$prn{'accepting'} = ($out =~ /queuing is enabled/);
$prn{'enabled'} = ($out =~ /printing is enabled/);
}
{
local($out);
local $esc = quotemeta($_[0]->{'name'});
-$out = `lpc status $esc 2>&1`;
+$out = &backquote_command("lpc status $esc 2>&1", 1);
if ($_[0]->{'enabled'} && $out !~ /printing is enabled/)
{ &backquote_logged("lpc up $esc"); }
elsif (!$_[0]->{'enabled'} && $out =~ /printing is enabled/)
$drv->{'mode'} == 2 ? $drv->{'prog'} : "";
if (&has_ghostscript()) {
- local $out = `$config{'gs_path'} -help 2>&1`;
+ local $out = &backquote_command("$config{'gs_path'} -help 2>&1", 1);
if ($out =~ /Available devices:\n((\s+.*\n)+)/i) {
print "<tr> <td valign=top>\n";
printf "<input type=radio name=drv value=1 %s>\n",
sub list_uniprint
{
local (@rv, $f, $d);
-local $out = `$config{'gs_path'} -help 2>&1`;
+local $out = &backquote_command("$config{'gs_path'} -help 2>&1", 1);
if ($out =~ /Search path:\n((\s+.*\n)+)/i) {
foreach $d (split(/\s+/, $1)) {
next if ($d !~ /^\//);
sub save_on_cluster
{
return ( ) if (!$config{'servers'});
+return ( ) if (&is_readonly_mode());
local ($new, $prn, $drv, $conn, $webmin, $mode) = @_;
&remote_error_setup(\&slave_error_handler);
local $slave;
sub delete_on_cluster
{
return ( ) if (!$config{'servers'});
+return ( ) if (&is_readonly_mode());
local ($prn) = @_;
&remote_error_setup(\&slave_error_handler);
local $slave;
if (!$_[1]) {
# call lpc to get status
local $esc = quotemeta($prn{'name'});
- $out = `lpc -P$esc status 2>&1`;
+ $out = &backquote_command("lpc -P$esc status 2>&1", 1);
if ($out =~ /\n(\S+)\s+(\S+)\s+(\S+)/) {
$prn{'accepting'} = $3 eq 'enabled';
$prn{'enabled'} = $2 eq 'enabled';
# Returns the pid if lpsched is running, 0 if not, -1 if cannot be stopped
sub sched_running
{
-local $out = `lpc lpd all 2>&1`;
+local $out = &backquote_command("lpc lpd all 2>&1", 1);
return $out =~ /pid\s+(\d+)/ ? $1 : 0;
}
desc_zh_CN.UTF-8=打印机管理
desc_ja_JP.UTF-8=プリンタ管理
desc_ko_KR.UTF-8=프린터 관리
+readonly=1
# copy the standard filter into place
&lock_file("$sd/filter");
unlink("$sd/filter");
- system("cp $base_driver $sd/filter");
+ ©_source_dest("$base_driver", "$sd/filter");
&unlock_file("$sd/filter");
return "$sd/filter";
}
{
local($stat, @rv, $body, $avl, $con, $sys, %prn, $_, $out);
local $esc = quotemeta($_[0]);
-$out = `lpstat -l -p $esc`;
+$out = &backquote_command("lpstat -l -p $esc", 1);
if ($out =~ /^printer\s+(\S+)\s*(.*)\s+(enabled|disabled)\s+since\s+([^\.]*)\.\s+(.*)\.\n([\000-\377]*)$/) {
# printer exists
$prn{'name'} = $1;
if (!$_[1]) {
# request availability
- $avl = `lpstat -a $esc 2>&1`;
+ $avl = &backquote_command("lpstat -a $esc 2>&1", 1);
if ($avl =~ /^\S+\s+not accepting.*\n\s+(.*)/) {
$prn{'accepting'} = 0;
$prn{'accepting_why'} = $1;
}
# request connection
-$con = `lpstat -v $esc 2>&1`;
+$con = &backquote_command("lpstat -v $esc 2>&1", 1);
if ($con =~ /^device for \S+:\s+(\S+)/) {
# Prints to a local file
$prn{'dev'} = $1;
# Prints to a remote server
$prn{'rhost'} = $1;
$prn{'rqueue'} = $2 || $prn{'name'};
- $sys = `lpsystem -l $prn{'rhost'} 2>&1`;
+ $sys = &backquote_command("lpsystem -l $prn{'rhost'} 2>&1", 1);
$sys =~ /Type:\s+(\S+)/; $prn{'rtype'} = $1;
}
# Check if this is the default printer
if (!defined($default_printer)) {
- `lpstat -d 2>&1` =~ /destination: (\S+)/;
- $default_printer = $1;
+ if (&backquote_command("lpstat -d 2>&1", 1) =~ /destination:\s+(\S+)/) {
+ $default_printer = $1;
+ }
}
if ($default_printer eq $prn{'name'}) { $prn{'default'} = 1; }
sub list_classes
{
local($stat, %rv);
-$stat = `lpstat -c 2>&1`;
+$stat = &backquote_command("lpstat -c 2>&1", 1);
while($stat =~ /^members of class (\S+):\n((\s+\S+\n)+)([\000-\377]*)$/) {
$stat = $4;
$rv{$1} = [ grep { $_ ne "" } split(/\s+/, $2) ];
}
# Build filter table
-open(STAT, "/usr/bin/ls -1 /etc/lp/fd/*.fd |");
+&open_execute_command(STAT, "/usr/bin/ls -1 /etc/lp/fd/*.fd", 1, 1);
while(<STAT>) {
$file = substr($_, rindex($_, "/") +1, -4 );
- `/usr/sbin/lpfilter -f $file -F /etc/lp/fd/$file.fd`;
+ &system_logged("/usr/sbin/lpfilter -f $file -F /etc/lp/fd/$file.fd");
}
close(STAT);
&unlock_file($aps);
if (!-r "$apsfilter_base.$device") {
&lock_file("$apsfilter_base.$device");
- local $conf = `cat $apsfilter_config`;
+ local $conf = &read_file_contents($apsfilter_config);
$conf =~ s/<gs_device_name>/$device/g;
&open_tempfile(CONF, ">$apsfilter_base.$device");
&print_tempfile(CONF, $conf);
$u, $drv->{'device'} eq $u ? 'selected' : '', $d->[1];
$found++ if ($drv->{'device'} eq $u);
}
- local $out = `$config{'gs_path'} -help 2>&1`;
+ local $out = &backquote_command("$config{'gs_path'} -help 2>&1", 1);
$out =~ /Available devices:\n((\s+.*\n)+)/i;
foreach $d (split(/\s+/, $1)) {
if ($driver{$d}) {
printf "<option value=ps %s>Postscript\n",
$drv->{'device'} eq 'PS' ? 'selected' : '';
$found++ if ($drv->{'device'} eq 'PS');
- local $out = `$config{'gs_path'} -help 2>&1`;
+ local $out = &backquote_command("$config{'gs_path'} -help 2>&1", 1);
$out =~ /Available devices:\n((\s+.*\n)+)/i;
foreach $d (split(/\s+/, $1)) {
if ($d ne 'stp' && $driver{$d}) {
}
else {
$file = &transname();
- open(FILE, ">$file");
- print FILE $in{'file'};
- close(FILE);
+ &open_tempfile(FILE, ">$file", 0, 1);
+ &print_tempfile(FILE, $in{'file'});
+ &close_tempfile(FILE);
}
$cmd = &print_command($in{'name'}, $file);
-print &text('test_exec', "<tt>$cmd</tt>"),"<br>\n";
-print "<pre>";
if ($access{'user'} eq '*') {
- open(CMD, "$cmd 2>&1 |");
+ # Run as root
}
elsif ($access{'user'}) {
- open(CMD, "su '$access{'user'}' -c '$cmd' 2>&1 |");
+ $cmd = &command_as_user($access{'user'}, 0, $cmd);
}
else {
- open(CMD, "su '$remote_user' -c '$cmd' 2>&1 |");
+ $cmd = &command_as_user($remote_user, 0, $cmd);
}
+
+print &text('test_exec', "<tt>$cmd</tt>"),"<br>\n";
+print "<pre>";
+&open_execute_command(CMD, $cmd, 1);
while(<CMD>) {
print;
}
else { print "$text{'test_ok'} <p>\n"; }
unlink($file) if ($in{'mode'} == 3);
-&ui_print_footer("", $text{'index_return'});
+&ui_print_footer("list_jobs.cgi?name=".&urlize($in{'name'}),
+ $text{'jobs_return'},
+ "", $text{'index_return'});
if ($prn{'allow_all'}) { $cmd .= " -u allow:all"; }
elsif ($prn{'deny_all'}) { $cmd .= " -u deny:all"; }
elsif ($prn{'allow'}) {
- system("lpadmin -p $esc -u deny:all >/dev/null 2>&1");
+ &system_logged("lpadmin -p $esc -u deny:all >/dev/null 2>&1");
$cmd .= " -u allow:".join(',', map { quotemeta($_) } @{$prn{'allow'}});
}
elsif ($prn{'deny'}) {
- system("lpadmin -p $esc -u allow:all >/dev/null 2>&1");
+ &system_logged("lpadmin -p $esc -u allow:all >/dev/null 2>&1");
$cmd .= " -u deny:".join(',', map { quotemeta($_) } @{$prn{'deny'}});
}
if ($prn{'dev'}) {
if ($job) {
# print job exists.. dump it
@pf = @{$job->{'printfile'}};
- $type = `file $pf[0]`;
+ $type = &backquote_command("file ".quotemeta($pf[0]), 1);
if ($type =~ /postscript/i) {
print "Content-type: application/postscript\n";
}