[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-WebCGI] LWP Example -- kill WebSTAR 2.0 suffix maps



Hi All.

I learned a lot this weekend.  There's a rather substantial
problem with the script I posted earlier -- the realm
authentication doesn't work:

At 8:36 PM -0600 6/4/99, Eric Dobbs wrote:
[snip]
>            #   This is where all the magic happens.  LWP is cool.
>            #   Here we POST the necessary arguments to the server.
>            #   You could also modify this code to add a suffix map.
>            #   One thing -- the $ua object must be remembering the
>            #   authentication information from the last request,
>            #   because none of that is specified here.
>            $response = $ua->request(POST $url,[
>                service => qq(suffix_mappings),
>                last_locked => $last_locked,
>                list_count => $list_count,
>                selection => qq($selection),
>                button => qq(Delete Selection)
>            ]);
[snip]

In this bit, the $ua object was *not* remembering the
authentication information -- rather, the realms on
our servers were not configured properly!  Yikes.


Here's another example where I have the realm
authentication working properly.  The concept is similar:
using LWP to automate some changes to the web server's
configuration through WebSTAR's web-based interface.  In
this case we're configuring the misc. settings.

-Eric


#   misc_WWW‡_settings.pl
#   by Eric Dobbs <dobbs@dobbse.net>

#   a script to set various misc. settings
#   for a collection of WebSTAR 2.0 servers

use LWP::UserAgent;
use HTTP::Request::Common;

# We make our own specialization of LWP::UserAgent
# with methods to set the login and password
# this is critical for the realm authentication to
# work.
{
    package RequestAgent;
    @ISA = qw(LWP::UserAgent);

    my ($user,$password);
    
    sub user {
        my $self = shift;
        my $temp = shift;
        if ($temp) {
            $user = $temp;
            return;
        } else {
            return $user;
        }
    }
    sub password {
        my $self = shift;
        my $temp = shift;
        if ($temp) {
            $password = $temp;
            return;
        } else {
            return $password;
        }
    }
    sub get_basic_credentials {return ($user,$password);}
}


#   need to do this for about 20 servers
#   each element in this array contains a reference to an anonymous array
#   each anonymous array contains the following info:
#       nickname    domain or ip    realm login     realm password
my @servers = (
    [qw(server1     one.somewhere.com       pi_admin    password)],
    [qw(server2     two.somewhere.com       pi_admin    password)],
    [qw(server3     three.somewhere.com     pi_admin    password)],
    [qw(server4     four.somewhere.com      pi_admin    password)]
);

#   these are the fields in WebSTARs misc settings.
my $webstar_service                 = qq(misc_settings);
my $webstar_maxconnections          = qq(28);
my $webstar_port                    = qq(80);
my $webstar_timeout                 = qq(240);
my $webstar_reportdelay             = qq(15);
my $webstar_fileinfocachesize       = qq(400);
my $webstar_buffersize              = qq(8000);
my $webstar_keepaliveconnections    = qq(10);
my $webstar_keepaliveduration       = qq(20);
my $webstar_usedns                  = qq();
my $webstar_cgibin                  = qq();
my $webstar_index                   = qq(default.DIR);
my $webstar_error                   = qq(:error.html);
my $webstar_noaccess                = qq(:noaccess.html);
my $webstar_logfile                 = qq(:Logs:WebSTAR.log);
my $webstar_preprocess              = qq();
my $webstar_postprocess             = qq();
my $webstar_defaultmime             = qq(text/html);
my $webstar_servername              = qq(SomeServer);
my $webstar_button                  = qq(Save);

foreach (@servers) {
    my ($name,$ip,$user,$password) = @$_;
    #   this is the WebSTAR 2.0 url for text-only modification of misc. settings
    my $url = qq(http://$ip/pi_admin_ssi.admin\$adm_miscsettingstext.ssi);
    my $ua = new RequestAgent;

    $ua->user($user);
    $ua->password($password);

    my $response = $ua->request(POST $url,[
        service                 => $webstar_service,
        maxconnections          => $webstar_maxconnections,
        port                    => $webstar_port,
        timeout                 => $webstar_timeout,
        reportdelay             => $webstar_reportdelay,
        fileinfocachesize       => $webstar_fileinfocachesize,
        buffersize              => $webstar_buffersize,
        keepaliveconnections    => $webstar_keepaliveconnections,
        keepaliveduration       => $webstar_keepaliveduration,
        usedns                  => $webstar_usedns,
        cgibin                  => $webstar_cgibin,
        index                   => $webstar_index,
        error                   => $webstar_error,
        noaccess                => $webstar_noaccess,
        logfile                 => $webstar_logfile,
        preprocess              => $webstar_preprocess,
        postprocess             => $webstar_postprocess,
        defaultmime             => $webstar_defaultmime,
        servername              => $webstar_servername,
        button                  => $webstar_button
    ]);
    
    if ($response->is_error()) {
        print qq(\n) . $response->status_line . qq(\n);
    } else {
        print $response->as_string .qq(\n);
    }
}


__END__



==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org