On Wed 08 Mar 2006 at 11:42AM, Dan Price wrote:
> On Wed 08 Mar 2006 at 10:49AM, Karyn Ritter wrote:
> > I'll figure out where to put the definitions. This the real status that
> > is in Bugster, so we need to document it anyway....
> So, I wonder if we could use Perl's WWW::Mechanize [1] or something
> equivalent to automate the updating of pages.  Then, Karyn, we could
> write you something which would gather up this info and post it
> every 2 hours, or whatever.
> Maybe we could have a Java package [2] (as well as any other languages
> [3]) that manipulates the website as well-- I personally don't like the
> endless CPAN machinations one must go through to get a useful perl.
> So this is a fun and challenging project for someone.  Any takers?

Nobody ever takes my challenges :(

Anyway, I've completed a prototype of a tool which can do this; for
those interested, it is attached below.  You'll need WWW::Mechanize and
either IO::Socket::SSL or Crypt::SSLeay installed, available from

Here's how to use it:

    $ cat > ~/.osauth
    my_opensolaris_username my_opensolaris_password
    $ chmod 600 ~/.osauth

    $ ./bender.pl
    ./bender.pl: you must specify -u <url>
    Usage: ./bender.pl [-v] -u <url> -f <filename> -x <authfile>
            - Authfile should contain one line with your
              OpenSolaris.org username and password.
            - Note that you must have permission to edit
              the page you are updating, and it must exist already.

    $ date | ./bender.pl -u community/zones/moop -f - -x ~/.osauth -v
    Get file contents...ok
    Get authentication info...ok
    Visit http://www.opensolaris.org/os/...ok
    Click 'Sign in'...ok
    Click 'Login'...ok
    Visit http://www.opensolaris.org/os/community/zones/moop ...ok
    Open edit...ok
    Complete edit...Done.

n.b., for those at Sun, I can't get this to work through the corporate
web proxies (and would love help to do so).  You can use a machine with a
transparent proxy, though, and it'll work fine.  'webhop.sfbay' is available
for this purpose upon request (to me).  Note also that the script tries
to respect the $http_proxy, etc. environment variables, so you may
need to clear those.

Happy cronjob-ing.



# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]

# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#ident  "%Z%%M% %I%     %E% SMI"

use LWP::UserAgent;
#use LWP::Debug qw(+);
use WWW::Mechanize;
use Getopt::Std;

my $verbose;

$| = 1;

sub vprint(@) {
        my (@msg) = @_;
        return if (!$verbose);
        print "@msg" if (@msg);

sub usage(@) {
        my (@msg) = @_;
        print "$0: @msg\n" if (@msg);
        print "Usage: $0 [-v] -u <url> -f <filename> -x <authfile>\n";
        print "\t- Authfile should contain one line with your\n";
        print "\t  OpenSolaris.org username and password.\n";
        print "\t- Note that you must have permission to edit\n";
        print "\t  the page you are updating, and it must exist already.\n";
        exit 2;

$starturl = 'http://www.opensolaris.org/os/';


usage("you must specify -u <url>") unless defined($opt_u);
usage("you must specify -f <filename>") unless defined($opt_f);
usage("you must specify -x <authfile>") unless defined($opt_x);

$myurl = $opt_u;
$myfile = $opt_f;
$myauth = $opt_x;
if (defined($opt_v)) { $verbose = "1"; }

vprint("Get file contents...");
$buffer = "";
open CONTENTS, "$myfile" or die "could not open $myfile";
while (<CONTENTS>) {
        $buffer .= $_;

vprint("Get authentication info...");
$username = "";
$passwd = "";
open CONTENTS, "$myauth" or die "could not open $myauth";
($username, $passwd) = split(" ", <CONTENTS>);

# Log ourselves in.
$mech = WWW::Mechanize->new();

vprint("Visit $starturl...");

die "Can't get $starturl: ", $mech->response->status_line
        unless $mech->success;

vprint("Click 'Sign in'...");
$mech->follow_link(text => "Sign in");

die "Can't follow sign in link: ", $mech->response->status_line
        unless $mech->success;

vprint("Click 'Login'...");
        form_name => "Login",
        fields      => { username => "$username", password => "$passwd" },

die "Can't Sign in: ", $mech->response->status_line
        unless $mech->success;

vprint("Visit " . $myurl . " ...");

die "Can't get page: ", $mech->response->status_line
        unless $mech->success;

vprint("Open edit...");
$mech->follow_link(text => "Edit this page");

die "Can't open edit: ", $mech->response->status_line
        unless $mech->success;

vprint("Complete edit...");
        form_name => "EditPage",
        fields      => { "page.content" => "$buffer" },
        button => "saveButtonPressed"
exit 0;


Daniel Price - Solaris Kernel Engineering - dp at eng.sun.com - blogs.sun.com/dp

Reply via email to