File: Printers.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,424 kB
  • sloc: perl: 26,492; xml: 773; objc: 528; sh: 386; ansic: 333; makefile: 12
file content (56 lines) | stat: -rw-r--r-- 1,850 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Ocsinventory::Agent::Backend::OS::MacOS::Printers;
use strict;

sub check {
    my $params = shift;
    my $common = $params->{common};
    return(undef) unless -r '/usr/sbin/system_profiler';
    return(undef) unless $common->can_load("Mac::SysProfile");
    return 1;
}

sub run {
    my $params = shift;
    my $common = $params->{common};

    my $profile = Mac::SysProfile->new();
    my $data = $profile->gettype('SPPrintersDataType');
    return(undef) unless(ref($data) eq 'ARRAY');

    my $status = "";
    my $description = "";
    my $shared = "";
    my @shared = "";
    my $oslevel = `sw_vers -productVersion`;
    if ($oslevel =~ /10\.[3-6]\./) {
        $shared = `awk \'/Info / {gsub("Info ",""); printf \$0">"}; /Shared/ {print \$NF}\' /etc/cups/printers.conf 2>/dev/null | grep -i yes`;
        @shared = split(/\n/,$shared);
    }

    foreach my $printer (@$data){
        next if ($printer->{'_name'} =~ /^The\sprinters\slist\sis\sempty\.(.*)$/);
        $description = "Status: $printer->{'status'}";
        next if ($description =~ /^Status:\s$/);
        next if ($description =~ /^Status:\sno_info_found$/);
      
        if ($printer->{'default'} eq "Yes") { $description .= " - Default printer"; }

        if ($oslevel =~ /10\.[3-6]\./) {
           foreach my $printShared (@shared) {
               my ($thisPrinter,$isShared) = split(/>/,$printShared);
               if ($printer->{'_name'} eq $thisPrinter) { $description .= " - Shared: yes"; }
           }
        } else {
           if ($printer->{'shared'} eq "Yes") { $description .= " - Shared: yes"; }
        }

        $common->addPrinter({
            NAME        => $printer->{'_name'},
            DRIVER      => $printer->{'ppd'},
            PORT        => $printer->{'uri'},
            DESCRIPTION => $description,
        });
    }

}
1;