Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

LWP UserAgent

by Andrew Precht (Initiate)
on Oct 10, 2012 at 19:59 UTC ( [id://998306]=perlquestion: print w/replies, xml ) Need Help??

Andrew Precht has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have no knowledge of perl, so please forgive... I've been asked to rebuild a RADIUS server. The guys at FreeRadius.org have really helped me get it up and running. However, my next issue is getting this perl script to run. Where do I start in tracking down this error: Can't locate object method "new" via package "LWP::UserAgent" (perhaps you forgot to load "LWP::UserAgent"?) at /etc/raddb/sjpl.pl line 94.

here is the offending code in line 94

my $ua = LWP::UserAgent->new;

here is all the code added to the default Radius script

sub authenticate { # my $logfile = "/var/log/patron/sign-on.log"; my $logfile = "/dev/null"; my $testfile = "/etc/raddb/test.text"; my $date = `/bin/date`; chomp $date; my $url = "https://10.151.4.3:54620/PATRONAPI/" . $RAD_REQUEST{'User-N +ame'} . "/" . $RAD_REQUEST{'User-Password'} . "/pintest"; my $ua = LWP::UserAgent->new; my $output1 = $ua->get($url); my $output = $output1->as_string; # For debugging purposes only # &log_request_attributes; if ($output =~ /RETCOD=0/) { `echo "$date : SUCCESS via SSL $RAD_REQUEST{'User-Name +'} - $RAD_REQUEST{'User-Password'}" >> $logfile`; $RAD_REPLY{'Reply-Message'} = "Success"; return RLM_MODULE_OK; } else { `echo "$date : FAIL via SSL $RAD_REQUEST{'User-Name'} +- $RAD_REQUEST{'User-Password'}" >> $logfile`; $RAD_REPLY{'Reply-Message'} = "Denied access by RADIUS +"; return RLM_MODULE_REJECT; } }

Thanks for any help.

Replies are listed 'Best First'.
Re: LWP UserAgent
by blue_cowdawg (Monsignor) on Oct 10, 2012 at 20:10 UTC
        Hi Monks, I have no knowledge of perl, so please forgive.

    My heartfelt advice to you is to fix that problem before going any further. Just as I'd not get into a car and drive cross country before I learned a) how to drive and b) how to navigate I don't suggest trying to do something as sophisticated as you're attempting without learning the basics first.

    That said, let me lay out a foundation for you.

    #!/usr/bin/perl -w ################################################ # First line is called a "shebang" and on a *nix or Cygwin environment + loads the # interpreter use strict; # keep an eye on our code looking for major faults use LWP::UserAgent; my $res=authenticate(); # Call your sub. You might want to # decide what to do with the return cod +e. # more code goes here exit(0); #the code you posted goes here

    Find your self a book such as Learning Perl to get a handle on things. I wouldn't attempt to build a house without some basic construction technique knowledge.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: LWP UserAgent
by toolic (Bishop) on Oct 10, 2012 at 20:01 UTC
    Add this line near the top of your /etc/raddb/sjpl.pl file:
    use LWP::UserAgent;
Re: LWP UserAgent
by Andrew Precht (Initiate) on Oct 10, 2012 at 20:52 UTC

    Thanks toolic, use LWP::UserAgent; worked:)

    Thanks Blue Cowdawg, I am in agreement with you... Unfortunately, time does not allow.

      Unfortunately, time does not allow.

      To carry on with blue_cowdawg's apt analogy, you've basically asked "I have no knowledge of driving, so please forgive ... I need to get across the country, and was given this car. How do I start it?" Once someone has pointed out how to put the key in the ignition, turn it, and press the gas pedal, you've ignored the advice to learn how to drive and navigate, and just stuck a brick on the accelerator while you hop into the back seat to connect to the office on your 3G-enabled laptop.

      As you might be able to guess, this does not bode well.

      Sometimes....

      you don't have time NOT to learn.

      Make sure your management is aware of that before they give you instructions that will result not only in a crash down the line, but with even less time to adapt and learn things to resolve it.

      Sigh. There is never time enough to do it right, but that is always enough time to do it over.

      ----
      I Go Back to Sleep, Now.

      OGB

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://998306]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-23 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found