| 1 | package SNMP::NPAdmin; | ||
| 2 | # | ||
| 3 | # prerequisites: | ||
| 4 | # UCD SNMP v4.2.0 | ||
| 5 | # SNMP module v4.2.0 | ||
| 6 | # Printer MIB and HP MIB (provided) | ||
| 7 | # | ||
| 8 | # assumptions | ||
| 9 | # 1. only SNMPv1 will be supported initially | ||
| 10 | # 2. only mib-2 and printmib will be supported initially | ||
| 11 | # 3. SNMPv2 support will be added later | ||
| 12 | # 4. private mib support will be added after printmib support is complete | ||
| 13 | # | ||
| 14 | # a. incorporated an HP JETDIRECT MIB that I found | ||
| 15 | # | ||
| 16 | # types of queries | ||
| 17 | # boolean | ||
| 18 | # max/min | ||
| 19 | # data, list format, i.e. a hash | ||
| 20 | # data, table format, i.e. a list of hashes | ||
| 21 | |||
| 22 | require 5.005_03; | ||
| 23 | |||
| 24 | use strict; | ||
| 25 | use vars qw/ $VERSION $CVSver @ISA $AUTOLOAD | ||
| 26 | $DEBUG | ||
| 27 | $VERBOSE | ||
| 28 | %vendors | ||
| 29 | %language_map | ||
| 30 | $language_code | ||
| 31 | %filter_map | ||
| 32 | $filter_code | ||
| 33 | %answer_map | ||
| 34 | @paper_sizes | ||
| 35 | $paper_sizes_indexed | ||
| 36 | $answer_code | ||
| 37 | /; | ||
| 38 | |||
| 39 | $VERSION = '1.0'; | ||
| 40 | $CVSver= '$Id: NPAdmin.pm,v 1.23 2002/11/15 03:57:23 bozzio Exp $'; | ||
| 41 | |||
| 42 | use SNMP::NPAdmin::Neon; | ||
| 43 | |||
| 44 | ##################################### PODs | ||
| 45 | |||
| 46 | =pod | ||
| 47 | |||
| 48 | =head1 NAME | ||
| 49 | |||
| 50 | SNMP::NPAdmin - high-level API to query printers via SNMP | ||
| 51 | |||
| 52 | =head1 SYNOPSIS | ||
| 53 | |||
| 54 | # object-oriented | ||
| 55 | $p= SNMP::NPAdmin->new( | ||
| 56 | printer => 'porky', | ||
| 57 | community => 'corpslp' | ||
| 58 | ); | ||
| 59 | printf "Your printer, %s, does%s support PCL.\n", | ||
| 60 | $printer, ( $p->pcl() ? "" : " not"); | ||
| 61 | |||
| 62 | # procedural | ||
| 63 | $p= npa_connect( | ||
| 64 | printer => 'porky', | ||
| 65 | community => 'corpslp' | ||
| 66 | ); | ||
| 67 | printf "Your printer, %s, does%s support PCL.\n", | ||
| 68 | $printer, ( npa_pcl( $p) ? "" : " not"); | ||
| 69 | |||
| 70 | =head1 DESCRIPTION | ||
| 71 | |||
| 72 | The C<SNMP::NPAdmin> package is a complete port of a SNMP/printer utility called C<npadmin> that provides a high-level interface to query printers via SNMP | ||
| 73 | without specific knowledge of SNMP MIBs or the printer's vendor-specific configuration. | ||
| 74 | |||
| 75 | The original C<npadmin> was written in C++ by Ben Woodard who continues to maintain it on SourceForge. | ||
| 76 | |||
| 77 | The primary objective in this port is to have a B<maintainable> and B<extensible> version of the same functionality that the original C<npadmin> provides. | ||
| 78 | |||
| 79 | It is B<not> optimized for performance at all; it is optimized for B<extensibility> and B<maintainability>. | ||
| 80 | The original C<npadmin> is very much extremely performance, the idea being to query many printers very quickly, especially since SNMP can be quite slow. | ||
| 81 | |||
| 82 | To be fair, C<SNMP::NPAdmin> might even be slow by Perl standards due to the extensive use of run-time compilation through the AUTOLOAD subroutine. | ||
| 83 | I don't necessarily believe this since a programmer/sys-admin frequently will not use all of the available methods/subroutines which would typically | ||
| 84 | be compiled during startup; given that only a few methods/subroutines will be called, then only a few will be compiled during the process's lifetime. | ||
| 85 | Probably the difference in speed due to this will be insignificant either way. | ||
| 86 | |||
| 87 | The design was chosen in order to get as much information into a maintainable table format and make the logic as generic as possible; not for speed. | ||
| 88 | |||
| 89 | So this is your choice. If you have some unsupported printers and you want to be able to modify the code to support them then use C<SNMP::NPAdmin>. | ||
| 90 | If you need to support B<a lot> of printers continuously with this kind of utility then you should use Ben Woodard's C<npadmin>. | ||
| 91 | |||
| 92 | =head1 THE PACKAGE | ||
| 93 | |||
| 94 | The C<SNMP::NPAdmin> package is composed of a module, C<SNMP::NPAdmin>, and a script, C<npadmin.pl>. | ||
| 95 | The heart of this package is the C<SNMP::NPAdmin> module. | ||
| 96 | Everything happens in the module. | ||
| 97 | All that the script does is parse command-line arguments, call the C<SNMP::NPAdmin> module and report the results. | ||
| 98 | Actually, two modules are provided; but only one is publicly available. | ||
| 99 | I will not even tell you its name; you can find it yourself if you're so curious. | ||
| 100 | |||
| 101 | The script is provide for two reasons. | ||
| 102 | The first is to fulfill the original objective of writing a Perl-version of C<npadmin> which is a command-line utility. | ||
| 103 | The second is to provide an example script. | ||
| 104 | |||
| 105 | =head1 THE INTERFACE: OBJECT-ORIENTED OR PROCEDURAL? BOTH! | ||
| 106 | |||
| 107 | While writing this module, I received a lot a negative feedback about using OO techniques. | ||
| 108 | Therefore I decided to ensure that it could be used by using both OO and procedural techniques. | ||
| 109 | |||
| 110 | It is probably true that most modules/classes are similarly Janus-faced since Perl always passes the object-reference (or class name) as the first argument. | ||
| 111 | That is not so different from the way many procedural libraries work, particularly those that establish some kind of state such as network connections: | ||
| 112 | initiate a connection and pass the returned struct to future library calls as the first argument. | ||
| 113 | |||
| 114 | B<NOTE!> B<NOTE!> B<NOTE!> B<NOTE!> B<NOTE!> | ||
| 115 | |||
| 116 | The procedural API is not been fully implemented yet. But it is the current task and should be complete soon. | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | ##################################### class method POD: new | ||
| 121 | |||
| 122 | =pod | ||
| 123 | |||
| 124 | =head1 CLASS METHODS | ||
| 125 | |||
| 126 | =head2 THE CONSTRUCTOR | ||
| 127 | |||
| 128 | =over 4 | ||
| 129 | |||
| 130 | =item B<C<SNMP::NPAdmin-E<gt>new()>> | ||
| 131 | |||
| 132 | This is the constructor (duh!). It returns an C<SNMP::NPAdmin> object which can then be queried with the object methods that are described below. | ||
| 133 | For arguments, a hash is used which can include values for five keys: C<printer>, C<community>, C<port>, C<timeout> and C<retries>. The C<printer> | ||
| 134 | key is required; the constructor B<will> fail without it. | ||
| 135 | |||
| 136 | $P= SNMP::NPAdmin->new( | ||
| 137 | printer => 'mega-print', | ||
| 138 | community => 'myhouse', | ||
| 139 | ); | ||
| 140 | |||
| 141 | =item B<C<npa_connect()>> | ||
| 142 | |||
| 143 | This is the procedural call to start a C<SNMP::NPAdmin> session for a specific printer. It accepts the same arguments and returns the same results as | ||
| 144 | the constructor. I didn't bother B<not> blessing the reference just for a procedural call. It will still work when it is passed to the query subroutines. | ||
| 145 | |||
| 146 | $P= npa_connect( | ||
| 147 | printer => 'mega-print', | ||
| 148 | community => 'myhouse', | ||
| 149 | ); | ||
| 150 | |||
| 151 | =back | ||
| 152 | |||
| 153 | =cut | ||
| 154 | |||
| 155 | ##################################### new | ||
| 156 | |||
| 157 | sub new | ||
| 158 | { | ||
| 159 | #warn "new"; | ||
| 160 | my $class= shift; | ||
| 161 | my %options= @_; | ||
| 162 | my $self; | ||
| 163 | |||
| 164 | $self->{boolean}= $options{boolean} | ||
| 165 | ? delete $options{boolean} | ||
| 166 | : [ qw/ 0 1 / ] | ||
| 167 | ; | ||
| 168 | |||
| 169 | $self->{Neon}= SNMP::NPAdmin::Neon->new( @_); | ||
| 170 | |||
| 171 | return undef if ! $self->{Neon}; | ||
| 172 | |||
| 173 | bless $self, $class; | ||
| 174 | return $self; | ||
| 175 | } | ||
| 176 | |||
| 177 | ##################################### class method POD: version | ||
| 178 | |||
| 179 | =pod | ||
| 180 | |||
| 181 | =over 4 | ||
| 182 | |||
| 183 | =item B<C<SNMP::NPAdmin-E<gt>version()>> or B<C<npa_version()>> | ||
| 184 | |||
| 185 | This method returns the version of SNMP::NPAdmin that is being used. | ||
| 186 | |||
| 187 | =back | ||
| 188 | |||
| 189 | =cut | ||
| 190 | |||
| 191 | ##################################### version | ||
| 192 | |||
| 193 | sub version | ||
| 194 | { | ||
| 195 | #warn "version"; | ||
| 196 | return $VERSION; | ||
| 197 | } | ||
| 198 | |||
| 199 | ##################################### class method POD: verbose | ||
| 200 | |||
| 201 | =pod | ||
| 202 | |||
| 203 | =over 4 | ||
| 204 | |||
| 205 | =item B<C<SNMP::NPAdmin-E<gt>verbose()>> or B<C<npa_verbose()>> | ||
| 206 | |||
| 207 | This method toggles the 'verbose' flag for the entire class. | ||
| 208 | All objects will verbosely report its progress during execution of any methods. | ||
| 209 | The previous value of the 'verbose' flag is returned. | ||
| 210 | Currently, the 'verbose' flag is ineffectual. | ||
| 211 | |||
| 212 | =back | ||
| 213 | |||
| 214 | =cut | ||
| 215 | |||
| 216 | ##################################### verbose | ||
| 217 | |||
| 218 | sub verbose | ||
| 219 | { | ||
| 220 | #warn "verbose"; | ||
| 221 | my $class= shift; | ||
| 222 | my $value= shift; | ||
| 223 | |||
| 224 | if ( defined $value ) | ||
| 225 | { | ||
| 226 | $VERBOSE= $value; | ||
| 227 | } | ||
| 228 | else | ||
| 229 | { | ||
| 230 | $VERBOSE |= 1; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | ##################################### class method POD: debug | ||
| 235 | |||
| 236 | =pod | ||
| 237 | |||
| 238 | =over 4 | ||
| 239 | |||
| 240 | =item B<C<SNMP::NPAdmin-E<gt>debug()>> or B<C<npa_debug()>> | ||
| 241 | |||
| 242 | This method toggles the 'debug' flag for the entire class. | ||
| 243 | All objects will report in painful detail everything that is happening during a SNMP::NPAdmin method call. | ||
| 244 | The previous value of the 'debug' flag is returned. | ||
| 245 | Currently, the 'debug' flag is ineffectual. | ||
| 246 | |||
| 247 | =back | ||
| 248 | |||
| 249 | =cut | ||
| 250 | |||
| 251 | ##################################### debug | ||
| 252 | |||
| 253 | sub debug | ||
| 254 | { | ||
| 255 | #warn "debug"; | ||
| 256 | my $class= shift; | ||
| 257 | my $value= shift; | ||
| 258 | |||
| 259 | if ( defined $value ) | ||
| 260 | { | ||
| 261 | $DEBUG= $value; | ||
| 262 | } | ||
| 263 | else | ||
| 264 | { | ||
| 265 | $DEBUG |= 1; | ||
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 269 | ##################################### class method POD: debugsnmp | ||
| 270 | |||
| 271 | =pod | ||
| 272 | |||
| 273 | =over 4 | ||
| 274 | |||
| 275 | =item B<C<SNMP::NPAdmin-E<gt>debugsnmp()>> or B<C<npa_debugsnmp()>> | ||
| 276 | |||
| 277 | This method toggles the 'debugsnmp' flag for all objects/sessions. | ||
| 278 | All objects will report in excruciating detail everything that happens during all actual SNMP transactions. | ||
| 279 | This flag is actually used by the underlying SNMP module. It does work and very well. | ||
| 280 | |||
| 281 | =back | ||
| 282 | |||
| 283 | =cut | ||
| 284 | |||
| 285 | ##################################### debugsnmp | ||
| 286 | |||
| 287 | *debugsnmp= *SNMP::NPAdmin::Neon::debugsnmp; | ||
| 288 | |||
| 289 | ##################################### DESTROY | ||
| 290 | |||
| 291 | sub DESTROY {}; | ||
| 292 | |||
| 293 | ##################################### object PODs | ||
| 294 | |||
| 295 | =pod | ||
| 296 | |||
| 297 | =head1 OBJECT METHODS | ||
| 298 | |||
| 299 | =head2 MIB queries | ||
| 300 | |||
| 301 | The MIB queries determine whether or not the queried printer supports the MIB in question. | ||
| 302 | Currently, SNMP::NPAdmin only asks about the Printer-MIB and the Host-Resources-MIB. | ||
| 303 | |||
| 304 | =over 4 | ||
| 305 | |||
| 306 | =item B<C<$P-E<gt>printmib()>> or B<C<npa_printmib( $P)>> | ||
| 307 | |||
| 308 | Answers the question, "Does the printer support the Printer-MIB?" | ||
| 309 | |||
| 310 | =item B<C<$P-E<gt>hostmib()>> or B<C<npa_hostmib( $P)>> | ||
| 311 | |||
| 312 | Answers the question, "Does the printer support the Host-Resources-MIB?" | ||
| 313 | |||
| 314 | =back | ||
| 315 | |||
| 316 | =over 4 | ||
| 317 | |||
| 318 | =head2 Information queries | ||
| 319 | |||
| 320 | The information queries provide information that requires additional processing in addition to merely querying the printer for data. | ||
| 321 | For most of these, this does involve simply querying the printer and reporting the results. | ||
| 322 | The ones that do require this kind of heuristics are C<vendor()>, C<model()>, C<netconfig()>, C<enginespeed()>, C<maxpapersize()>, C<minpapersize()>. | ||
| 323 | |||
| 324 | =item B<C<$P-E<gt>contact()>> or B<C<npa_contact( $P)>> | ||
| 325 | |||
| 326 | Retrieves contact and location information as contained in C<system.sysDescr> and C<system.sysLocation>. | ||
| 327 | |||
| 328 | =item B<C<$P-E<gt>vendor()>> or B<C<npa_vendor( $P)>> | ||
| 329 | |||
| 330 | Attempts to determine the vendor/manufacturer of the printer. | ||
| 331 | Currently, only a few vendors can be reliably detected: HP, Tektronix, Lexmark, IBM, Xerox, EFI, Fuji and QMS. | ||
| 332 | If a device can be determined to not be a printer then 'not_a_printer' is returned. | ||
| 333 | If the vendor cannot be determined then 'unknown is returned. | ||
| 334 | If you are able to determine an unsupported vendor then please send the information to me (see below). | ||
| 335 | |||
| 336 | =item B<C<$P-E<gt>model()>> or B<C<npa_model( $P)>> | ||
| 337 | |||
| 338 | Attempts to determine the model of the printer. | ||
| 339 | The vendor is determined as the first step. So, this will only work for printers that are supported | ||
| 340 | by the vendor() method. Even then, the module only guarantees its best-effort. | ||
| 341 | If you are able to determine an unsupported model then please send the information to me (see below). | ||
| 342 | |||
| 343 | =item B<C<$P-E<gt>cfgsrc()>> or B<C<npa_cfgsrc( $P)>> | ||
| 344 | |||
| 345 | The configuration source or method is determined as given by the HP private MIB OID | ||
| 346 | C<.iso.org.dod.internet.private.enterprises.hp.nm.interface.npCard.npCfg.npCfgSource>. | ||
| 347 | |||
| 348 | =item B<C<$P-E<gt>status()>> or B<C<npa_status( $P)>> | ||
| 349 | |||
| 350 | Attempts to determine the status of the printer from the Host-Resources-MID OID C<hrPrinterStatus>. | ||
| 351 | |||
| 352 | =item B<C<$P-E<gt>memory()>> or B<C<npa_memory( $P)>> | ||
| 353 | |||
| 354 | Attempts to determine the amount memory in the printer from the Host-Resources-MID OID C<hrMemorySize>. | ||
| 355 | |||
| 356 | =item B<C<$P-E<gt>netconfig()>> or B<C<npa_netconfig( $P)>> | ||
| 357 | |||
| 358 | Attempts to determine the network configuration of the printer from these MIB-2 OIDs: C<ipPhysAddress>, C<ipAdEntAddr>, C<ipAdEntNetMask>, C<ipRouteNextHop>. | ||
| 359 | |||
| 360 | =item B<C<$P-E<gt>pagecount()>> or B<C<npa_pagecount( $P)>> | ||
| 361 | |||
| 362 | Attempts to number of pages printed by the printer from the Printer-MIB OIDs C<prtMarkerLifeCount> and C<prtMarkerCounterUnit>. | ||
| 363 | |||
| 364 | =item B<C<$P-E<gt>colors()>> or B<C<npa_colors( $P)>> | ||
| 365 | |||
| 366 | Attempts to determine the number of colors supported by the printer from the Printer-MIB OID C<prtMarkerProcessColorants>. | ||
| 367 | |||
| 368 | =item B<C<$P-E<gt>resolution()>> or B<C<npa_resolution( $P)>> | ||
| 369 | |||
| 370 | This returns the values for the Printer-MIB OIDs C<prtMarkerAddressabilityFeedDir> and C<prtMarkerAddressabilityXFeedDir>. | ||
| 371 | |||
| 372 | ??? I am not sure what they mean. | ||
| 373 | |||
| 374 | =item B<C<$P-E<gt>minmargin()>> or B<C<npa_minmargin( $P)>> | ||
| 375 | |||
| 376 | This really should be just C<margin> since it is determined from the C<prtMarkerTable> and most printers in use only have one marker. | ||
| 377 | Nonetheless, this merely returns the margins for all of the markers in the printer from the Printer-MIB OIDs C<prtMarkerNorthMargin>, | ||
| 378 | C<prtMarkerSouthMargin>, C<prtMarkerEastMargin> and C<prtMarkerWestMargin>. | ||
| 379 | |||
| 380 | =item B<C<$P-E<gt>enginespeed()>> or B<C<npa_enginespeed( $P)>> | ||
| 381 | |||
| 382 | Determines the maximum speed that one of the media-paths provides from the Printer-MIB OID C<prtMediaPathSpeed>. | ||
| 383 | |||
| 384 | =item B<C<$P-E<gt>maxpapersize()>> or B<C<npa_maxpapersize( $P)>> | ||
| 385 | |||
| 386 | Determines the largest paper-size that is supported by the printer. | ||
| 387 | This does not reflect the largest size paper that is actually in the printer. | ||
| 388 | By "largest" and "max", we mean the paper-size with the most area, as determined from the Printer-MIB OIDs C<prtMediaPathMaxMediaFeedDir> and | ||
| 389 | C<prtMediaPathMaxMediaXFeedDir>. | ||
| 390 | |||
| 391 | =item B<C<$P-E<gt>minpapersize()>> or B<C<npa_minpapersize( $P)>> | ||
| 392 | |||
| 393 | Determines the smallest paper-size that is supported by the printer. | ||
| 394 | This does not reflect the smallest size paper that is actually in the printer. | ||
| 395 | By "smallest" and "min", we mean the paper-size with the least area, as determined from the Printer-MIB OIDs C<prtMediaPathMinMediaFeedDir> and | ||
| 396 | C<prtMediaPathMinMediaXFeedDir>. | ||
| 397 | |||
| 398 | |||
| 399 | =back | ||
| 400 | |||
| 401 | =over 4 | ||
| 402 | |||
| 403 | =head2 SNMP table queries | ||
| 404 | |||
| 405 | The next set of queries merely return the contents of the Printer-MIB tables. | ||
| 406 | Just for brevity, I will only list the method/subroutine names and the respective table OIDs. | ||
| 407 | |||
| 408 | =item B<C<$P-E<gt>display()>> or B<C<npa_display( $P)>> | ||
| 409 | |||
| 410 | printmib.prtConsoleDisplayBuffer.prtConsoleDisplayBufferTable | ||
| 411 | |||
| 412 | =item B<C<$P-E<gt>languages()>> or B<C<npa_languages( $P)>> | ||
| 413 | |||
| 414 | printmib.prtInterpreter.prtInterpreterTable | ||
| 415 | |||
| 416 | =item B<C<$P-E<gt>covers()>> or B<C<npa_covers( $P)>> | ||
| 417 | |||
| 418 | printmib.prtCover.prtCoverTable | ||
| 419 | |||
| 420 | =item B<C<$P-E<gt>inputtray()>> or B<C<npa_inputtray( $P)>> | ||
| 421 | |||
| 422 | printmib.prtInput.prtInputTable | ||
| 423 | |||
| 424 | =item B<C<$P-E<gt>marker()>> or B<C<npa_marker( $P)>> | ||
| 425 | |||
| 426 | printmib.prtMarker.prtMarkerTable | ||
| 427 | |||
| 428 | =item B<C<$P-E<gt>protocol()>> or B<C<npa_protocol( $P)>> | ||
| 429 | |||
| 430 | printmib.prtChannel.prtChannelTable | ||
| 431 | |||
| 432 | =item B<C<$P-E<gt>supplies()>> or B<C<npa_supplies( $P)>> | ||
| 433 | |||
| 434 | printmib.prtMarkerSupplies.prtMarkerSuppliesTable | ||
| 435 | |||
| 436 | =item B<C<$P-E<gt>mediapath()>> or B<C<npa_mediapath( $P)>> | ||
| 437 | |||
| 438 | printmib.prtMediaPath.prtMediaPathTable | ||
| 439 | |||
| 440 | =item B<C<$P-E<gt>alerts()>> or B<C<npa_alerts( $P)>> | ||
| 441 | |||
| 442 | printmib.prtAlert.prtAlertTable | ||
| 443 | |||
| 444 | |||
| 445 | =back | ||
| 446 | |||
| 447 | =over 4 | ||
| 448 | |||
| 449 | =head2 Truth queries | ||
| 450 | |||
| 451 | The truth queries answer a "Yes or No" question about the capabilities of the printer. | ||
| 452 | The questions fall into one of several categories: languages (prtInterpreter), paper-size (prtMediaPath) or protocol (prtChannel). | ||
| 453 | |||
| 454 | =item B<C<$P-E<gt>pjl()>> or B<C<npa_pjl( $P)>> | ||
| 455 | |||
| 456 | supports PJL printer language? | ||
| 457 | |||
| 458 | =item B<C<$P-E<gt>pcl()>> or B<C<npa_pcl( $P)>> | ||
| 459 | |||
| 460 | supports PCL printer language? | ||
| 461 | |||
| 462 | =item B<C<$P-E<gt>hpgl()>> or B<C<npa_hpgl( $P)>> | ||
| 463 | |||
| 464 | supports HPGL printer language? | ||
| 465 | |||
| 466 | =item B<C<$P-E<gt>psprint()>> or B<C<npa_psprint( $P)>> | ||
| 467 | |||
| 468 | supports PSPRINT printer language? | ||
| 469 | |||
| 470 | =item B<C<$P-E<gt>postscript()>> or B<C<npa_postscript( $P)>> | ||
| 471 | |||
| 472 | supports Postscript printer language? | ||
| 473 | |||
| 474 | =item B<C<$P-E<gt>autolang()>> or B<C<npa_autolang( $P)>> | ||
| 475 | |||
| 476 | automatically selects the appropriate language? | ||
| 477 | |||
| 478 | =item B<C<$P-E<gt>duplex()>> or B<C<npa_duplex( $P)>> | ||
| 479 | |||
| 480 | supports duplex printing? | ||
| 481 | |||
| 482 | =item B<C<$P-E<gt>letter()>> or B<C<npa_letter( $P)>> | ||
| 483 | |||
| 484 | supports letter papersize? | ||
| 485 | |||
| 486 | =item B<C<$P-E<gt>legal()>> or B<C<npa_legal( $P)>> | ||
| 487 | |||
| 488 | supports legal papersize? | ||
| 489 | |||
| 490 | =item B<C<$P-E<gt>executive()>> or B<C<npa_executive( $P)>> | ||
| 491 | |||
| 492 | supports executive papersize? | ||
| 493 | |||
| 494 | =item B<C<$P-E<gt>tabloid()>> or B<C<npa_tabloid( $P)>> | ||
| 495 | |||
| 496 | supports tabloid papersize? | ||
| 497 | |||
| 498 | =item B<C<$P-E<gt>a3()>> or B<C<npa_a3( $P)>> | ||
| 499 | |||
| 500 | supports a3 papersize? | ||
| 501 | |||
| 502 | =item B<C<$P-E<gt>a4()>> or B<C<npa_a4( $P)>> | ||
| 503 | |||
| 504 | supports a4 papersize? | ||
| 505 | |||
| 506 | =item B<C<$P-E<gt>b3()>> or B<C<npa_b3( $P)>> | ||
| 507 | |||
| 508 | supports b4 papersize? | ||
| 509 | |||
| 510 | =item B<C<$P-E<gt>b5()>> or B<C<npa_alerts( $P)>> | ||
| 511 | |||
| 512 | supports b5 papersize? | ||
| 513 | |||
| 514 | =item B<C<$P-E<gt>appletalk()>> or B<C<npa_appletalk( $P)>> | ||
| 515 | |||
| 516 | supports Appletalk protocol? | ||
| 517 | |||
| 518 | =item B<C<$P-E<gt>lpd()>> or B<C<npa_lpd( $P)>> | ||
| 519 | |||
| 520 | supports LPD protocol? | ||
| 521 | |||
| 522 | =item B<C<$P-E<gt>netware()>> or B<C<npa_netware( $P)>> | ||
| 523 | |||
| 524 | supports Netware protocol? | ||
| 525 | |||
| 526 | =item B<C<$P-E<gt>port9100()>> or B<C<npa_port9100( $P)>> | ||
| 527 | |||
| 528 | supports port 9100 bidirectional connections? | ||
| 529 | |||
| 530 | =over | ||
| 531 | |||
| 532 | =cut | ||
| 533 | |||
| 534 | ##################################### vendor | ||
| 535 | |||
| 536 | use constant Xerox230_1 => '131;C1H011131;'; | ||
| 537 | use constant Xerox230_2 => ';C1H017730;'; | ||
| 538 | use constant Xerox265 => '3UP060485'; | ||
| 539 | |||
| 540 | %vendors= ( | ||
| 541 | HP => qr/JETDIRECT/o, | ||
| 542 | Lexmark => qr/Lexmark/o, | ||
| 543 | Tektronix => qr/Tektronix/o, | ||
| 544 | Xerox => qr/ Xerox | @{[Xerox230_1]} | @{[Xerox230_2]} | @{[Xerox265]} /ox, | ||
| 545 | QMS => qr/qms/o, | ||
| 546 | IBM => qr/IBM/o, | ||
| 547 | EFI => qr/EFI FieryColor Printer Server|EFI Fiery Server ZX/o, | ||
| 548 | Fuji => qr/Able Model-PRII/o, | ||
| 549 | not_a_printer => qr/HP-UX|HPUX|Windows NT|Sun SNMP Agent|SunOS|Macintosh|UNIX/o, | ||
| 550 | ); | ||
| 551 | |||
| 552 | sub vendor | ||
| 553 | { | ||
| 554 | #warn "vendor"; | ||
| 555 | my $self= shift; | ||
| 556 | |||
| 557 | my $x; | ||
| 558 | $x= $self->{Neon}->mib2_system(); | ||
| 559 | |||
| 560 | while ( my( $k, $v)= each %vendors ) | ||
| 561 | { | ||
| 562 | if ( $x->{sysDescr} =~ $v ) | ||
| 563 | { | ||
| 564 | $self->{vendor}= $k; | ||
| 565 | last; | ||
| 566 | } | ||
| 567 | $self->{vendor} |= 'unknown'; | ||
| 568 | } | ||
| 569 | |||
| 570 | return { vendor => $self->{vendor} }; | ||
| 571 | } | ||
| 572 | |||
| 573 | ##################################### model | ||
| 574 | |||
| 575 | sub model | ||
| 576 | { | ||
| 577 | #warn "model"; | ||
| 578 | my $self= shift; | ||
| 579 | |||
| 580 | for ( $self->vendor()->{vendor} ) | ||
| 581 | { | ||
| 582 | /^EFI$/ && do { | ||
| 583 | last; | ||
| 584 | }; | ||
| 585 | |||
| 586 | /^Fuji$/ && do { | ||
| 587 | $self->{model}= 'Able PRII'; | ||
| 588 | last; | ||
| 589 | }; | ||
| 590 | |||
| 591 | /^HP$/ && do { | ||
| 592 | my $str= $self->{Neon}->hp_gdStatusId()->{gdStatusId}; | ||
| 593 | $self->{model}= ( $str =~ /;(?:MODEL|MDL):\s*(.+?)\s*;/ )[0]; | ||
| 594 | last; | ||
| 595 | }; | ||
| 596 | |||
| 597 | /^Lexmark$/ && do { | ||
| 598 | my $x; | ||
| 599 | $x= $self->{Neon}->mib2_system()->{sysDescr}; | ||
| 600 | $self->{model}= ( $x =~ /Lexmark\s+(.+?) / )[0]; | ||
| 601 | last; | ||
| 602 | }; | ||
| 603 | |||
| 604 | /^Xerox$/ && do { | ||
| 605 | my( $x, $y); | ||
| 606 | $x= $self->{Neon}->mib2_system()->{sysDescr}; | ||
| 607 | if ( $x =~ /[?]{3}/ ) | ||
| 608 | { | ||
| 609 | ; | ||
| 610 | } | ||
| 611 | elsif ( $x =~ / @{[Xerox230_1]} | @{[Xerox230_2]} /ox ) | ||
| 612 | { | ||
| 613 | $self->{model}= 'Document Centre 230ST'; | ||
| 614 | } | ||
| 615 | elsif ( $x =~ / @{[Xerox265]} /ox ) | ||
| 616 | { | ||
| 617 | $self->{model}= 'Document Centre 265'; | ||
| 618 | } | ||
| 619 | else | ||
| 620 | { | ||
| 621 | $x =~ /\s*(?:(.+?),|(.+))/; | ||
| 622 | $self->{model}= $1 || $2; | ||
| 623 | } | ||
| 624 | last; | ||
| 625 | } | ||
| 626 | |||
| 627 | # /^IBM$/ && do { }; | ||
| 628 | |||
| 629 | # /^QMS$/ && do { }; | ||
| 630 | |||
| 631 | # /^Tektronix$/ && do { }; | ||
| 632 | } | ||
| 633 | |||
| 634 | return { model => $self->{model} }; | ||
| 635 | } | ||
| 636 | |||
| 637 | ##################################### final PODs | ||
| 638 | |||
| 639 | =pod | ||
| 640 | |||
| 641 | =head1 AUTHOR | ||
| 642 | |||
| 643 | Robert Lehr, bozzio@the-lehrs.com | ||
| 644 | |||
| 645 | I certainly would appreciate any feedback from people that use it, including complaints, suggestions or patches. | ||
| 646 | Even people that don't use it are welcome to send comments. | ||
| 647 | |||
| 648 | =head1 COPYRIGHT | ||
| 649 | |||
| 650 | Copyright (c) 2001 Robert Lehr. All rights reserved. This program is free software; you can redistribute it and/or | ||
| 651 | modify it under the same terms as Perl itself. | ||
| 652 | |||
| 653 | Caveat emptor. Use this module at your own risk. I will accept no responsibility for any loss of any kind | ||
| 654 | that is the direct or indirect result of the use of this module. | ||
| 655 | |||
| 656 | =head1 SEE ALSO | ||
| 657 | |||
| 658 | the SNMP module v3.1.0; the UCD SNMP library v4.2.0 at http://www.net-snmp.org/; RFC 1759 - The Printer MIB | ||
| 659 | |||
| 660 | =cut | ||
| 661 | |||
| 662 | ##################################### _check_paper_size | ||
| 663 | |||
| 664 | use constant Name => 0; | ||
| 665 | use constant Units => 1; | ||
| 666 | use constant DimA => 2; | ||
| 667 | use constant DimB => 3; | ||
| 668 | |||
| 669 | use constant null => 'null'; | ||
| 670 | use constant tenThousandthsOfInches => 'tenThousandthsOfInches'; | ||
| 671 | use constant micrometers => 'micrometers'; | ||
| 672 | |||
| 673 | @paper_sizes= ( | ||
| 674 | [ 'other', null, -1, -1 ], | ||
| 675 | [ 'unknown', null, -2, -2 ], | ||
| 676 | [ 'letter', tenThousandthsOfInches, 85000, 110000 ], | ||
| 677 | [ 'letter', micrometers, 215900, 279400 ], #bw# | ||
| 678 | [ 'legal', tenThousandthsOfInches, 85000, 140000 ], | ||
| 679 | [ 'legal', micrometers, 215900, 355600 ], #bw# | ||
| 680 | [ 'tabloid', tenThousandthsOfInches, 110000, 170000 ], #bw# | ||
| 681 | [ 'tabloid', micrometers, 279400, 431800 ], #bw# | ||
| 682 | [ 'executive', tenThousandthsOfInches, 75000, 105000 ], #bw# | ||
| 683 | [ 'executive', micrometers, 190500, 266700 ], #bw# | ||
| 684 | [ 'a3', tenThousandthsOfInches, 109842, 165354 ], #bw# | ||
| 685 | [ 'a3', micrometers, 297000, 420000 ], | ||
| 686 | [ 'a4', tenThousandthsOfInches, 82677, 116929 ], #bw# | ||
| 687 | [ 'a4', micrometers, 210000, 297000 ], | ||
| 688 | [ 'b3', micrometers, 353000, 500000 ], | ||
| 689 | [ 'b3', tenThousandthsOfInches, -1, -1 ], | ||
| 690 | [ 'b5', micrometers, 176000, 250000 ], | ||
| 691 | [ 'b5', tenThousandthsOfInches, -1, -1 ], | ||
| 692 | ); | ||
| 693 | #bw# == Ben Woodard, extracted from npadmin, file=npaconsts.h | ||
| 694 | |||
| 695 | map { | ||
| 696 | $paper_sizes_indexed->{$_->[Name]}->{$_->[Units]}= [ undef, undef, $_->[DimA], $_->[DimB] ] | ||
| 697 | } @paper_sizes; | ||
| 698 | |||
| 699 | ##################################### language_code (this points the question at the answer) | ||
| 700 | |||
| 701 | use constant check_language => '_check_language'; | ||
| 702 | use constant check_paper_size => '_check_paper_size'; | ||
| 703 | use constant check_protocol => '_check_protocol'; | ||
| 704 | |||
| 705 | %language_map= ( | ||
| 706 | pcl => check_language, | ||
| 707 | postscript => check_language, | ||
| 708 | psprint => check_language, | ||
| 709 | pjl => check_language, | ||
| 710 | hpgl => check_language, | ||
| 711 | autolang => check_language, | ||
| 712 | legal => check_paper_size, | ||
| 713 | letter => check_paper_size, | ||
| 714 | b5 => check_paper_size, | ||
| 715 | a3 => check_paper_size, | ||
| 716 | executive => check_paper_size, | ||
| 717 | b4 => check_paper_size, | ||
| 718 | a4 => check_paper_size, | ||
| 719 | tabloid => check_paper_size, | ||
| 720 | port9100 => check_protocol, | ||
| 721 | netware => check_protocol, | ||
| 722 | lpd => check_protocol, | ||
| 723 | appletalk => check_protocol, | ||
| 724 | ); | ||
| 725 | |||
| 726 | $language_code= q[ | ||
| 727 | sub ##SUBNAME## | ||
| 728 | { | ||
| 729 | #warn '##SUBNAME##'; | ||
| 730 | my $self= shift; | ||
| 731 | |||
| 732 | return $self->##HANDLER##( '##SUBNAME##'); | ||
| 733 | } | ||
| 734 | ]; | ||
| 735 | |||
| 736 | ##################################### filter_code (this fetches data and translates field names) | ||
| 737 | |||
| 738 | %filter_map= ( | ||
| 739 | status => [ | ||
| 740 | 'hrPrinterStatus', | ||
| 741 | { | ||
| 742 | "hrPrinterStatus" => 'status', | ||
| 743 | }], | ||
| 744 | memory => [ | ||
| 745 | 'hrMemorySize', | ||
| 746 | { | ||
| 747 | 'hrMemorySize' => 'memsize', | ||
| 748 | }], | ||
| 749 | netconfig => [ | ||
| 750 | 'netconfig', | ||
| 751 | { | ||
| 752 | 'ipAdEntAddr' => 'ipaddr', | ||
| 753 | 'ifPhysAddress' => 'hwaddr', | ||
| 754 | 'ipRouteNextHop' => 'gateway', | ||
| 755 | 'ipAdEntNetMask' => 'netmask', | ||
| 756 | }], | ||
| 757 | cfgsrc => [ | ||
| 758 | 'hp_npCfgSource', | ||
| 759 | { | ||
| 760 | 'npCfgSource' => 'cfgsrc', | ||
| 761 | }], | ||
| 762 | storage => [ | ||
| 763 | 'hrStorage', | ||
| 764 | { | ||
| 765 | 'hrStorageDescr' => 'descr', | ||
| 766 | 'hrStorageSize' => 'size', | ||
| 767 | 'hrStorageUsed' => 'used', | ||
| 768 | 'hrStorageAllocationUnits' => 'allocunits', | ||
| 769 | 'hrStorageAllocationFailures' => 'allocfail', | ||
| 770 | }], | ||
| 771 | display => [ | ||
| 772 | 'prtConsoleDisplayBuffer', | ||
| 773 | { | ||
| 774 | 'prtConsoleDisplayBufferText' => 'displayBufferText', | ||
| 775 | }], | ||
| 776 | languages => [ | ||
| 777 | 'prtInterpreter', | ||
| 778 | { | ||
| 779 | 'prtInterpreterLangFamily' => 'langFamily', | ||
| 780 | 'prtInterpreterLangLevel' => 'langLevel', | ||
| 781 | 'prtInterpreterLangVersion' => 'langVersion', | ||
| 782 | 'prtInterpreterDescription' => 'description', | ||
| 783 | 'prtInterpreterVersion' => 'version', | ||
| 784 | 'prtInterpreterDefaultOrientation' => 'orientation', | ||
| 785 | 'prtInterpreterFeedAddressability' => 'feedAddressability', | ||
| 786 | 'prtInterpreterXFeedAddressability' => 'xFeedAddressability', | ||
| 787 | 'prtInterpreterTwoWay' => 'twoWay', | ||
| 788 | }], | ||
| 789 | protocol => [ | ||
| 790 | 'prtChannel', | ||
| 791 | { | ||
| 792 | 'prtChannelType' => 'type', | ||
| 793 | 'prtChannelProtocolVersion' => 'version', | ||
| 794 | 'prtChannelState' => 'state', | ||
| 795 | 'prtChannelStatus' => 'status', | ||
| 796 | 'prtChannelDefaultPageDescLangIndex' => 'defaultPageDescLang', | ||
| 797 | 'prtChannelCurrentJobCntlDescLangIndex' => 'currentJobControlLang', | ||
| 798 | }], | ||
| 799 | covers => [ | ||
| 800 | 'prtCover', | ||
| 801 | { | ||
| 802 | 'prtCoverDescription' => 'description', | ||
| 803 | 'prtCoverStatus' => 'status', | ||
| 804 | }], | ||
| 805 | mediapath => [ | ||
| 806 | 'prtMediaPath', | ||
| 807 | { | ||
| 808 | 'prtMediaPathType' => 'type', | ||
| 809 | 'prtMediaPathDescription' => 'description', | ||
| 810 | 'prtMediaPathStatus' => 'status', | ||
| 811 | 'prtMediaPathMediaSizeUnit' => 'mediaSizeunit', | ||
| 812 | 'prtMediaPathMaxMediaFeedDir' => 'maxMediaFeedDir', | ||
| 813 | 'prtMediaPathMaxMediaXFeedDir' => 'maxMediaXFeedDir', | ||
| 814 | 'prtMediaPathMinMediaFeedDir' => 'minMediaFeedDir', | ||
| 815 | 'prtMediaPathMinMediaXFeedDir' => 'minMediaXFeedDir', | ||
| 816 | 'prtMediaPathMaxSpeed' => 'maxSpeed', | ||
| 817 | 'prtMediaPathMaxSpeedPrintUnit' => 'maxSpeedPrintUnit', | ||
| 818 | }], | ||
| 819 | alerts => [ | ||
| 820 | 'prtAlert', | ||
| 821 | { | ||
| 822 | 'prtAlertTrainingLevel' => 'trainingLevel', | ||
| 823 | 'prtAlertGroup' => 'group', | ||
| 824 | 'prtAlertGroupIndex' => 'groupIndex', | ||
| 825 | 'prtAlertLocation' => 'location', | ||
| 826 | 'prtAlertCode' => 'code', | ||
| 827 | 'prtAlertDescription' => 'description', | ||
| 828 | 'prtAlertTime' => 'time', | ||
| 829 | }], | ||
| 830 | supplies => [ | ||
| 831 | 'prtMarkerSupplies', | ||
| 832 | { | ||
| 833 | 'prtMarkerSuppliesType' => 'type', | ||
| 834 | 'prtMarkerSuppliesSupplyUnit' => 'supplyunit', | ||
| 835 | 'prtMarkerSuppliesClass' => 'class', | ||
| 836 | 'prtMarkerSuppliesDescription' => 'desc', | ||
| 837 | 'prtMarkerSuppliesMaxCapacity' => 'maxcap', | ||
| 838 | 'prtMarkerSuppliesLevel' => 'level', | ||
| 839 | }], | ||
| 840 | marker => [ | ||
| 841 | 'prtMarker', | ||
| 842 | { | ||
| 843 | 'prtMarkerMarkTech' => 'markerTechnology', | ||
| 844 | 'prtMarkerCounterUnit' => 'counterUnits', | ||
| 845 | 'prtMarkerLifeCount' => 'lifeCount', | ||
| 846 | 'prtMarkerProcessColorants' => 'processColorants', | ||
| 847 | 'prtMarkerAddressabilityUnit' => 'addressabilityUnit', | ||
| 848 | 'prtMarkerAddressabilityFeedDir' => 'addressabilityFeedDir', | ||
| 849 | 'prtMarkerAddressabilityXFeedDir' => 'addressabilityXFeedDir', | ||
| 850 | 'prtMarkerNorthMargin' => 'northMargin', | ||
| 851 | 'prtMarkerSouthMargin' => 'southMargin', | ||
| 852 | 'prtMarkerEastMargin' => 'eastMargin', | ||
| 853 | 'prtMarkerWestMargin' => 'westMargin', | ||
| 854 | 'prtMarkerStatus' => 'status', | ||
| 855 | }], | ||
| 856 | inputtray => [ | ||
| 857 | 'prtInput', | ||
| 858 | { | ||
| 859 | 'prtInputType' => 'type', | ||
| 860 | 'prtInputDimUnit' => 'dimUnit', | ||
| 861 | 'prtInputMediaDimFeedDirChosen' => 'dimFeedDir', | ||
| 862 | 'prtInputMediaDimXFeedDirChosen' => 'dimXFeedDir', | ||
| 863 | 'prtInputCapacityUnit' => 'capUnit', | ||
| 864 | 'prtInputMaxCapacity' => 'maxCap', | ||
| 865 | 'prtInputCurrentLevel' => 'curLevel', | ||
| 866 | 'prtInputMediaName' => 'mediaName', | ||
| 867 | 'prtInputName' => 'name', | ||
| 868 | 'prtInputDescription' => 'description', | ||
| 869 | 'prtInputStatus' => 'status', | ||
| 870 | }], | ||
| 871 | contact => [ | ||
| 872 | 'mib2_system', | ||
| 873 | { | ||
| 874 | "sysContact" => 'contact', | ||
| 875 | "sysLocation" => 'location', | ||
| 876 | }], | ||
| 877 | pagecount => [ | ||
| 878 | 'prtMarker', | ||
| 879 | { | ||
| 880 | "prtMarkerLifeCount" => 'pagecount', | ||
| 881 | "prtMarkerCounterUnit" => 'countUnits', | ||
| 882 | }], | ||
| 883 | colors => [ | ||
| 884 | 'prtMarker', | ||
| 885 | { | ||
| 886 | "prtMarkerProcessColorants" => 'processColorants', | ||
| 887 | }], | ||
| 888 | resolution => [ | ||
| 889 | 'prtMarker', | ||
| 890 | { | ||
| 891 | "prtMarkerAddressabilityUnit" => 'addressabilityUnit', | ||
| 892 | "prtMarkerAddressabilityFeedDir" => 'addressabilityFeedDir', | ||
| 893 | "prtMarkerAddressabilityXFeedDir" => 'addressabilityXFeedDir', | ||
| 894 | }], | ||
| 895 | minmargin => [ | ||
| 896 | 'prtMarker', | ||
| 897 | { | ||
| 898 | "prtMarkerAddressabilityUnit" => 'addressabilityUnit', | ||
| 899 | "prtMarkerNorthMargin" => 'northMargin', | ||
| 900 | "prtMarkerSouthMargin" => 'southMargin', | ||
| 901 | "prtMarkerEastMargin" => 'eastMargin', | ||
| 902 | "prtMarkerWestMargin" => 'westMargin', | ||
| 903 | }], | ||
| 904 | minpapersize => [ | ||
| 905 | 'prtMediaPath', | ||
| 906 | { | ||
| 907 | "prtMediaPathMediaSizeUnit" => 'minMediaUnit', | ||
| 908 | "prtMediaPathMinMediaFeedDir" => 'minMediaFeedDir', | ||
| 909 | "prtMediaPathMinMediaXFeedDir" => 'minMediaXFeedDir', | ||
| 910 | }, | ||
| 911 | [ | ||
| 912 | sub { my $x= shift; $x->{prtMediaPathMinMediaFeedDir} * $x->{prtMediaPathMinMediaXFeedDir} }, | ||
| 913 | sub { my @x= @_; $x[0] < ( $x[1] || 1e99 ) }, | ||
| 914 | ], | ||
| 915 | ], | ||
| 916 | maxpapersize => [ | ||
| 917 | 'prtMediaPath', | ||
| 918 | { | ||
| 919 | "prtMediaPathMediaSizeUnit" => 'maxMediaUnit', | ||
| 920 | "prtMediaPathMaxMediaFeedDir" => 'maxMediaFeedDir', | ||
| 921 | "prtMediaPathMaxMediaXFeedDir" => 'maxMediaXFeedDir', | ||
| 922 | }, | ||
| 923 | [ | ||
| 924 | sub { my $x= shift; $x->{prtMediaPathMaxMediaFeedDir} * $x->{prtMediaPathMaxMediaXFeedDir} }, | ||
| 925 | sub { my @x= @_; ( $x[0] > $x[1]) }, | ||
| 926 | ], | ||
| 927 | ], | ||
| 928 | enginespeed => [ | ||
| 929 | 'prtMediaPath', | ||
| 930 | { | ||
| 931 | "prtMediaPathMaxSpeedPrintUnit" => 'maxSpeedUnit', | ||
| 932 | "prtMediaPathMaxSpeed" => 'maxSpeed', | ||
| 933 | }, | ||
| 934 | [ | ||
| 935 | sub { my $x= shift; $x->{prtMediaPathMaxSpeed} }, | ||
| 936 | sub { my @x= @_; ( $x[0] > $x[1] ) }, | ||
| 937 | ], | ||
| 938 | ], | ||
| 939 | ); | ||
| 940 | |||
| 941 | $filter_code= q{ | ||
| 942 | sub ##SUBNAME## | ||
| 943 | { | ||
| 944 | #warn '##SUBNAME##'; | ||
| 945 | my $self= shift; | ||
| 946 | my( $x, $y, $z); | ||
| 947 | |||
| 948 | $x= $self->{Neon}->##SNMPTABLE##(); | ||
| 949 | $x= $self->_munge_it( $x, $filter_map{##SUBNAME##}->[2]) if $filter_map{##SUBNAME##}->[2]; | ||
| 950 | |||
| 951 | $z= $filter_map{##SUBNAME##}->[1]; | ||
| 952 | |||
| 953 | if ( ref $x eq 'ARRAY' ) | ||
| 954 | { | ||
| 955 | foreach my $var (( ref $x eq 'ARRAY' ) ? @$x : $x ) | ||
| 956 | { | ||
| 957 | my %M; | ||
| 958 | %M= map { ( $z->{$_}, $var->{$_}) } ( grep { my $a= $_; grep { $a eq $_ } keys %$z } keys %$var ); | ||
| 959 | push @$y, \%M if %M; | ||
| 960 | } | ||
| 961 | } | ||
| 962 | else | ||
| 963 | { | ||
| 964 | $y= { map { ( $z->{$_}, $x->{$_}) } ( grep { my $a= $_; grep { $a eq $_ } keys %$z } keys %$x ) }; | ||
| 965 | } | ||
| 966 | |||
| 967 | return $y; | ||
| 968 | } | ||
| 969 | }; | ||
| 970 | |||
| 971 | ##################################### answer_code (this answers boolean questions) | ||
| 972 | |||
| 973 | %answer_map= ( | ||
| 974 | duplex => [ | ||
| 975 | 'prtMediaPath', | ||
| 976 | [ 'longEdgeBindingDuplex', 'shortEdgeBindingDuplex'], | ||
| 977 | sub { my @x= @_; grep { $x[0]->{prtMediaPathType} eq $_ } @{$x[1]} }, | ||
| 978 | ], | ||
| 979 | _check_language => [ | ||
| 980 | 'prtInterpreter', | ||
| 981 | { pcl => 'langPCL', | ||
| 982 | postscript => 'langPS', | ||
| 983 | psprint => 'langPSPrinter', | ||
| 984 | pjl => 'langPCL', | ||
| 985 | hpgl => 'langHPGL', | ||
| 986 | autolang => 'langAutomatic', | ||
| 987 | }, | ||
| 988 | sub { my @x= @_; $x[0]->{prtInterpreterLangFamily} eq $x[1]->{$x[2]} }, | ||
| 989 | ], | ||
| 990 | _check_protocol => [ | ||
| 991 | 'prtChannel', | ||
| 992 | { appletalk => [ qw/ chAppleTalkPAP / ], | ||
| 993 | lpd => [ qw/ chLPDServer / ], | ||
| 994 | port9100 => [ qw/ chPort9100 chAppSocket chBidirPortTCP / ], | ||
| 995 | }, | ||
| 996 | sub { my @x= @_; grep { $x[0]->{prtChannelType} eq $_ } @{$x[1]->{$x[2]}} }, | ||
| 997 | ], | ||
| 998 | _check_paper_size => [ | ||
| 999 | 'prtInput', | ||
| 1000 | {}, | ||
| 1001 | sub { my @x= @_; | ||
| 1002 | my $a= $x[0]->{prtInputMediaDimFeedDirChosen}; | ||
| 1003 | my $b= $x[0]->{prtInputMediaDimXFeedDirChosen}; | ||
| 1004 | my $c= $x[0]->{prtInputDimUnit}; | ||
| 1005 | my $y= $paper_sizes_indexed->{$x[2]}->{$c}->[DimA]; | ||
| 1006 | my $z= $paper_sizes_indexed->{$x[2]}->{$c}->[DimB]; | ||
| 1007 | |||
| 1008 | (( $a == $y ) && ( $b == $z )) | ||
| 1009 | || | ||
| 1010 | (( $a == $z ) && ( $b == $y )) | ||
| 1011 | }, | ||
| 1012 | ], | ||
| 1013 | printmib => [ | ||
| 1014 | 'printmib', | ||
| 1015 | undef, | ||
| 1016 | sub { shift()->{printmib} }, | ||
| 1017 | ], | ||
| 1018 | hostmib => [ | ||
| 1019 | 'hostmib', | ||
| 1020 | undef, | ||
| 1021 | sub { shift()->{hostmib} }, | ||
| 1022 | ], | ||
| 1023 | ); | ||
| 1024 | |||
| 1025 | $answer_code= q{ | ||
| 1026 | sub ##SUBNAME## | ||
| 1027 | { | ||
| 1028 | #warn "##SUBNAME##"; | ||
| 1029 | my( $self, $a)= @_; | ||
| 1030 | my $answer= 0; | ||
| 1031 | my( $x, $y, $z); | ||
| 1032 | |||
| 1033 | $x= $self->{Neon}->##SNMPTABLE##(); | ||
| 1034 | $y= $answer_map{##SUBNAME##}->[2]; | ||
| 1035 | $z= $answer_map{##SUBNAME##}->[1]; | ||
| 1036 | |||
| 1037 | if( ref $y =~ '^CODE(.+)' ) | ||
| 1038 | { | ||
| 1039 | foreach my $var ( @$x ) | ||
| 1040 | { | ||
| 1041 | $answer++ if $y->( $var, $z, $a); | ||
| 1042 | } | ||
| 1043 | } | ||
| 1044 | else | ||
| 1045 | { | ||
| 1046 | $answer= $x; | ||
| 1047 | } | ||
| 1048 | |||
| 1049 | return { ##VALNAME## => $self->{boolean}->[$answer?1:0] }; | ||
| 1050 | } | ||
| 1051 | }; | ||
| 1052 | |||
| 1053 | ##################################### AUTOLOAD | ||
| 1054 | |||
| 1055 | sub AUTOLOAD | ||
| 1056 | { | ||
| 1057 | #warn "AUTOLOAD"; | ||
| 1058 | my $autoload= ( $AUTOLOAD =~ /.*::(\w+)/ )[0]; | ||
| 1059 | |||
| 1060 | my( $sub, %tags); | ||
| 1061 | if ( defined $language_map{$autoload} ) | ||
| 1062 | { | ||
| 1063 | $sub= $language_code; | ||
| 1064 | %tags= ( | ||
| 1065 | '##SUBNAME##' => $autoload, | ||
| 1066 | '##HANDLER##' => $language_map{$autoload}, | ||
| 1067 | ); | ||
| 1068 | } | ||
| 1069 | elsif ( defined $filter_map{$autoload} ) | ||
| 1070 | { | ||
| 1071 | $sub= $filter_code; | ||
| 1072 | %tags= ( | ||
| 1073 | '##SUBNAME##' => $autoload, | ||
| 1074 | '##SNMPTABLE##' => $filter_map{$autoload}->[0], | ||
| 1075 | '##MUNGE_FILTER##' => $filter_map{$autoload}->[1], | ||
| 1076 | ); | ||
| 1077 | } | ||
| 1078 | elsif ( defined $answer_map{$autoload} ) | ||
| 1079 | { | ||
| 1080 | $sub= $answer_code; | ||
| 1081 | %tags= ( | ||
| 1082 | '##SUBNAME##' => $autoload, | ||
| 1083 | '##SNMPTABLE##' => $answer_map{$autoload}->[0], | ||
| 1084 | '##VALNAME##' => ( ref $answer_map{$autoload}->[1] eq 'HASH' ) ? '$a' : $autoload, | ||
| 1085 | ); | ||
| 1086 | } | ||
| 1087 | |||
| 1088 | if ( $sub ) | ||
| 1089 | { | ||
| 1090 | map { $sub=~ s/\Q$_/$tags{$_}/g } keys %tags; | ||
| 1091 | eval $sub; | ||
| 1092 | die $@ if $@; | ||
| 1093 | goto &$autoload; | ||
| 1094 | } | ||
| 1095 | |||
| 1096 | printf STDERR "Unimplemented method:\t'%s()'\n", $autoload; | ||
| 1097 | return undef; | ||
| 1098 | } | ||
| 1099 | |||
| 1100 | ##################################### _munge_it | ||
| 1101 | |||
| 1102 | sub _munge_it | ||
| 1103 | { | ||
| 1104 | #warn '_munge_it'; | ||
| 1105 | my( $self, $x, $F)= @_; | ||
| 1106 | |||
| 1107 | my( $M, $m); | ||
| 1108 | foreach my $var ( @$x ) | ||
| 1109 | { | ||
| 1110 | my $a= $F->[0]->( $var); | ||
| 1111 | |||
| 1112 | if (( ! $m ) || ( $F->[1]->( $a, $m) )) | ||
| 1113 | { | ||
| 1114 | $M= $var; | ||
| 1115 | $m= $a; | ||
| 1116 | } | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | return $M; | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | ##################################### the end | ||
| 1123 | # | ||
| 1124 | # $Id: NPAdmin.pm,v 1.23 2002/11/15 03:57:23 bozzio Exp $ | ||
| 1125 | # | ||
| 1126 | |||
| 1127 | 1; |