aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/config/development/container
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2016-02-18 18:38:43 +0100
committerJoas Schilling <nickvergessen@gmx.de>2016-02-18 18:38:43 +0100
commitfc66f00236230d41362dd63286641e8faffd0f99 (patch)
treebdefdc37112be44eb36edc69e6d5d8cd7fc05f9c /phpBB/config/development/container
parent17e21d5140ccb99363a32bd64c32af6012c1ce97 (diff)
parent9745d8d80e05f755bb8188077d042a2a69e8c21f (diff)
downloadforums-fc66f00236230d41362dd63286641e8faffd0f99.tar
forums-fc66f00236230d41362dd63286641e8faffd0f99.tar.gz
forums-fc66f00236230d41362dd63286641e8faffd0f99.tar.bz2
forums-fc66f00236230d41362dd63286641e8faffd0f99.tar.xz
forums-fc66f00236230d41362dd63286641e8faffd0f99.zip
Merge branch 'prep-release-3.1.8' into 3.1.x
Conflicts: build/build.xml phpBB/includes/constants.php phpBB/install/schemas/schema_data.sql
Diffstat (limited to 'phpBB/config/development/container')
0 files changed, 0 insertions, 0 deletions
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 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
package printer::cups;

use strict;

use printer::data;
use run_program;
use common;


#------------------------------------------------------------------------------

sub lpstat_lpv() {

    # Get a list of remotely defined print queues, with "Description" and
    # "Location"

    # Info to return
    my @items;

    # Hash to simplify the adding of the URIs
    my $itemshash;

    # Run the "lpstat" command in a mode to give as much info about the
    # print queues as possible
    my @lpstat = run_program::rooted_get_stdout
	($::prefix, 'lpstat', '-l', '-p', '-v');
    
    my $currentitem = -1;
    for my $line (@lpstat) {
	chomp ($line);
	if (!($line =~ m!^\s*$!)) {
	    if ($line =~ m!^printer\s+(\S+)\s+(\S.*)$!) {
		# Beginning of new printer's entry
		my $name = $1;
		push(@items, {});
		$currentitem = $#items;
		$itemshash->{$name} = $currentitem;
		$items[$currentitem]{queuename} ||= $name;
	    } elsif ($line =~ m!^\s+Description:\s+(\S.*)$!) {
		# Description field
		if ($currentitem != -1) {
		    $items[$currentitem]{description} ||= $1;
		}
	    } elsif ($line =~ m!^\s+Location:\s+(\S.*)$!) {
		# Location field
		if ($currentitem != -1) {
		    $items[$currentitem]{location} ||= $1;
		}
	    } elsif ($line =~ m!^device\s+for\s+(\S+):\s+(\S.*)$!) {
		# "device for ..." line, extract URI
		my $name = $1;
		my $uri = $2;
		if (defined($itemshash->{$name})) {
		    if ($uri !~ /:/) {$uri = "file:" . $uri};
		    $currentitem = $itemshash->{$name};
		    if (($currentitem <= $#items) &&
			($items[$currentitem]{queuename} eq $name)) {
			$items[$currentitem]{uri} ||= $uri;
			if ($uri =~ m!^ipp://([^/:]+)[:/]!) {
			    $items[$currentitem]{ipp} = $1;
			}
		    }
		}
	    }
	}
    }
    return @items;
}

sub lpstat_v() {
    map {
	if (my ($queuename, $uri) = m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) {
	    +{ queuename => $queuename, uri => $uri, if_($uri =~ m!^ipp://([^/:]+)[:/]!, ipp => $1) };
	} else {
	    ();
	}
    } run_program::rooted_get_stdout($::prefix, 'lpstat', '-v');
}

sub lpinfo_v() {
    map {
	if (my ($type, $uri) = m/^\s*(\S+)\s+(\S+)\b/) {
	    if ($uri =~ m!:/!) {
		$uri;
	    } elsif ($type =~ m/network/i) {
		"$uri://";
	    } else {
		"$uri:/";
	    }
	} else {
	    ();
	}
    } run_program::rooted_get_stdout($::prefix, 'lpinfo', '-v');
}

sub read_printer_list {
    my ($printer) = @_;
    # This function reads in a list of all printers which the local CUPS
    # daemon currently knows, including remote ones.
    map {
	my $comment = 
	  $_->{ipp} && !$printer->{configured}{$_->{queuename}} ?
	    N("(on %s)", $_->{ipp}) : N("(on this machine)");
	"$_->{queuename} $comment";
    } lpstat_v();
}

sub get_formatted_remote_queues {
    my ($printer) = @_;

    # This function reads in a list of all remote printers which the local 
    # CUPS daemon knows due to broadcasting of remote servers or 
    # "BrowsePoll" entries in the local /etc/cups/cupsd.conf/
    map {
	join('!', if_($printer->{expert}, N("CUPS")), N("Configured on other machines"), $_);
    } map {
	my $comment = N("On CUPS server \"%s\"", ($_->{ipp} ? $_->{ipp} : $printer->{remote_cups_server})) . ($_->{queuename} eq $printer->{DEFAULT} ? N(" (Default)") : "");
	"$_->{queuename}: $comment";
    } grep { 
	!$printer->{configured}{$_->{queuename}};
    } lpstat_v();
}

sub get_remote_queues {
    my ($printer) = @_;
    # The following code reads in a list of all remote printers which the
    # local CUPS daemon knows due to broadcasting of remote servers or 
    # "BrowsePoll" entries in the local /etc/cups/cupsd.conf
    map {
	"$_->{queuename}|$_->{ipp}";
    } grep { 
	$_->{ipp} && !$printer->{configured}{$_->{queuename}};
    } lpstat_v();
}

sub queue_enabled {
    my ($queue) = @_;
    0 != grep {
	/\b$queue\b.*\benabled\b/i
    } run_program::rooted_get_stdout($::prefix, 'lpstat', '-p', $queue);
}



1;