Adding printers in Solaris 9 or 10
Below is a perl script which adds/creates printers using lp to two print servers with a web browser.
The script uses perl + CGI.
#!/usr/local/bin/perl use CGI::Ajax; use CGI qw(:standard); use Net::LDAP; use Expect; use Switch; $debug = 1; sub debug { print STDERR "@_" if $debug; } #$site_url = '/cgi-bin/add_printer.cgi'; $site_url = '/cgi-bin/ap.cgi'; $site_name = 'Add a new printer'; # Create the CGI object my $query = new CGI; $ajax_called = $query->param("fname"); $submit_called = $query->param("submit"); ####################################################################################################################################################### # ## User inputs # $printer_name = param('printer_name'); $printer_type = param('printer_type'); $printer_ip = param('printer_ip'); $user = param('user'); $password = param('password'); $chkbox_print1 = $query->param('chkbox_print1'); $chkbox_print2 = $query->param('chkbox_print2'); debug "Executing add_printer.cgi as $ENV{REMOTE_USER}\n"; ####################################################################################################################################################### # ## Process form if submitted; execute ajax as needed or simply display the form # if ( $submit_called ) { my $form_is_valid = &validate_form(); if ( $form_is_valid ) { debug "validated - now starting ajax for the first time\n"; &do_ajax(); exit 0; } else { debug "Form not validated - re-displaying\n"; my $error_message = '*** Please fill in all fields ***'; ## the extra ,1 below is a flag which clears the password field &display_form($error_message,1); } } elsif ( $ajax_called ) { debug "Running ajax function: $ajax_called\n"; &do_ajax(); exit 0; } else { # Output the HTTP header for NON-Ajax operations print $query->header(); &display_form(); } exit 0; ####################################################################################################################################################### # ## start of AJAX subs # ####################################################################################################################################################### sub do_ajax { my $pjx = CGI::Ajax->new( 'spinner' => \&spinner, 'addprintertoserver' => \&addprintertoserver, 'addprintertoldap' => \&addprintertoldap); print $pjx->build_html($query,\&Show_HTML); } sub spinner { my($printer,$server) = @_; debug "spinner - printer: $printer, server: $server\n"; return($server,qq~ Adding $printer to $server...~); } sub Show_HTML { my $html = ''; $html .= <Eric's CGI::Ajax Example