RE: Environment Variables..

2001-12-12 Thread Lorne Easton

As in the attached code: The variables do not "unlink" when the program
exits or when I specify to unlink.

I.E: If I run this program once, then run it again with incorrect domain
specified it gives the same information.

Is there any way of gracefully "exiting" and removing all the variables from
memory.

Thanks in advance for you help.

--SNIP--

#Get list of Domain Users

use Win32::NetAdmin;

$domain = @ARGV[0];

Win32::NetAdmin::GetAnyDomainController("",$domain, $dc);
print "$dc\t$domain\n";
Win32::NetAdmin::GroupGetMembers($dc, "Domain Users", \@machines);

foreach $item (@machines) {
print "$item\n";
}

exit (0);




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Shift and "=>"

2001-12-17 Thread Lorne Easton

Hi,

Below is some example code that I have butchered to
it's simplest impelmentation.

I don't understand this line..

$session = Net::SNMP->session(-hostname => "10.0.0.100", -community =>
"public");

Particularly, the way data is presented to the function..

I.E : -data => "text"

Is this some special type of data type?? What does the "=>" signify.

Also, why the use of the "shift" as in:
(from the original example)

   ($session, $error) = Net::SNMP->session(
  -hostname  => shift || '10.0.0.100',
  -community => shift || 'public',
  -port  => shift || 161
   );

and how can you use
"||" with it. I thought it was used like.

open(INPUT,"<$file") ||
die "Error";

being equivalent of:

if !(open(INPUT,"<$file") {
die "Error; }

I apologise for the newbie questions, I am just unable to
find info on this in the beginner docs and the like..

Thanks in advance for your assistance

Cheers,
Lorne

--- SNIP ---

  use Net::SNMP;

  $session = Net::SNMP->session(
  -hostname  => "10.0.0.100",
  -community => "public",);


  my $sysUpTime = '1.3.6.1.2.1.1.3.0';

  $response = $session->get_request($sysUpTime);

  print ($response->{$sysUpTime});

  $session->close();
  exit 0;




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Post does not allow script to execute completely.

2001-12-18 Thread Lorne Easton

I am trying to adapt my commandline script to work from
a web page. The HTML code is this:

--SNIP--



http://adminweb.stage.mas.com.au/cgi-bin/find_user_web.pl";>






--SNIP--

The script is like this

--SNIP--

use Win32::NetAdmin;
use Win32::TieRegistry(Delimiter => "/");
use strict;
use CGI;


my $post = new CGI;

my $search_user = $post->param('user');

my $domain = Win32::DomainName;
my $error;
my $found_user_number = 0;
my $remotekey;
my $server;
my $username;
my @servers;

print $post->header;

if ($search_user eq ""){
print "\n Usage:\t \"perl find_user.pl username\" (Print location of
\"username\")\n";
print " \"perl find_user.pl all\"  (Print location of all
users)";
exit(1);
}

print "For Domain: ",$domain,"\n\n";

 Win32::NetAdmin::GetServers( '', $domain, SV_TYPE_ALL, \@servers);

 foreach $server (@servers) {

 $remotekey = $Registry->Open("//$server/LMachine/SOFTWARE/Microsoft/Windows
NT/CurrentVersion/Winlogon", {Access => "KEY_READ"});
 ($username, $error) = $remotekey->GetValue('DefaultUserName');

 if (($search_user eq $username) or ($search_user eq "all")){
 print $domain,"\\",$username," is located on:","\t",$server,"\n";
 $found_user_number ++;
 }

 if ($error eq "0"){
 print "Could not read key value from server: ",$server,"\n";
 unlink $error;
 }

 }

 print "\nFound: ",$found_user_number," user(s).";
 exit(0);

--SNIP--

The output I get is like this:

--SNIP--

For Domain: MAS

--SNIP--

And then execution stops. Am I missing something?
The vars are passed correctly,
but it does not seem to hit the foreach..

Oh, and permissions for the IIS user are ok as well..

Regards,
Lorne



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: WWW:Robot speed..

2002-01-08 Thread Lorne Easton

Hi there..

I am using the WWW:Robot module to iterate over some internal sites, so
complying with the guidelines for robots is not really an issue.

Anyone have any experience modifying the module so that the delay between
requests is less?

Regards,
Lorne



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




extracting links from HTML data

2002-01-14 Thread Lorne Easton

I need to write some code that extracts that extracts hyperlinks from a
scalar ($data) and puts them into an array.

I imagine that grep can do this, but my mastery of it and
reqular expressions are not brilliant.

Can you please provide some example code, or at least point me in the right
direction?

Cheers,
Lorne



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: extracting links.. continued..

2002-01-16 Thread Lorne Easton

Hi there,

Thanks for the advice. I looked at using HTML::LinkExtor but decided against
it.

I am using code like the following:


sub get_urls {

my @url_array;
my ($data) = @_;

print $data;

#Put all ")|gi) {

 my  $temp_tag = $1;
#Strip out tags
#Insert code here..

push @url_array,$temp_tag;

}
#Temporary to print out all URLS. Testing purposes only.
foreach my $temp (@url_array){
print $temp,"\n";
}
print "\n\n",$#url_array," URLs found.\n";
#

return(@url_array);
}

Which is cool, but it extracts the entire TEXT text. Is
there a way to modify this regexp to strip out this data as well. Obviously
match (m/) is inclusive if the matched data. Is there any way of modifying
this? Or perhaps writing a regexp to do this??

The problem is that data could be




Re: Cgi on IIS

2002-01-16 Thread Lorne Easton

Hi Robert,

Right click on the servername and choose "Properties".
Choose "Home Directory" and choose "Configuration"
under "Application Settings".

You can edit your application mappings from the "App
Mappings" tab.

These should have been set up for you if you installed
perl after IIS, but you will need to add either "perlis.dll"
or "perl %s %s" as a mapping to the .pl extension ( and
or .cgi if you require).

Cheers,
Lorne



"Robert Hanson" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> It's been a long time since I worked on IIS, but I believe the "Method not
> allowed" error refers to GET, POST, PUT, and HEAD.  In IIS you can
> allow/deny each of these, but I forget exactly where in the MMC that this
> was located, it was with the file types.
>
> So maybe ".cgi" doesn't have GET access (or whatever you are trying to
do).
> It could also be a permissions problem.  Make sure that the group
"Everyone"
> can write to the file (or at least the username that the web server uses
> would need to)
>
> Rob
>
> -Original Message-
> From: maureen [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 16, 2002 4:19 PM
> To: Beginners CGI List; [EMAIL PROTECTED]
> Subject: Cgi on IIS
>
>
>
> I hope someone can help me out.
>
> I set up this cgi file and html form on a Unix server. The script
> changes a user's password in a text file.
>
> This works correctly on a Unix Server. However, I need to move these
> files to an IIS server.
> In testing on the IIS server,  I get an HTTP Error 405- Method not
> allowed when the form is submitted.
>
> I did some research, but was unable to determine how to correct the
> error.
>
> If anyone could help me out, I'd really appreciate it.
>
> Thanks, Maureen
>
> #!/usr/bin/perl
> require "cgi-lib.pl";
> #process incoming form data
> &ReadParse;
> #set content type
> print &PrintHeader;
> #initialize variables
> $pwfile =
> "/data1/hypermart.net/worldwidewebstrategies/datafile/pwdata.txt";
> $tmpfile =
> "/data1/hypermart.net/worldwidewebstrategies/datafile/pwdata.tmp";
> $lokfile =
> "/data1/hypermart.net/worldwidewebstrategies/datafile/pwlock.fil";
> #Print initial tags for web page
> print "\n";
> #check for existence of password file
> unless (-e $pwfile)
> {
> #password file doesn't exist!
> #print message & shut down
> print <<"PrintTag";
> Sorry!
> $pwfile has't been uploaded to the
> proper directory. Please contact the webmaster.
> 
> 
> PrintTag
> exit(0);
> }
> #check for blank form fields
> if ($in{'oldname'}eq"" || $in{'oldpw'}eq"")
> {
> #re-create form and shut down program
> print <<"PrintTag";
> ERROR: Please type your current username and
> password in the spaces provided.
> 
ACTION="http://server37.hypermart.net/worldwidewebstrategies/cgi-bin/changep
> w.cgi"
> METHOD="post">
> Your current username:
> 
> Your current password:
> 
> Your new password:
> 
> Type your new password again:
> 
> 
> PrintTag
> if ($in{'delete'} eq "yes")
> {
> print " NAME=\"delete\" VALUE=\"yes\" CHECKED>\n";
> }
> else
> {
> print "\n";
> }
> print <<"PrintTag";
> 
> 
> 
> 
> 
> PrintTag
> exit(0);
> }
> #make sure new passwords match
> if ($in{'newpw1'} ne $in{'newpw2'})
> {
> #re-create form and shut down program
> print <<"PrintTag";
> ERROR: Your new passwords didn't match.
> You must type your new password exactly the same way twice.
> Please try again.
> 
ACTION="http://server37.hypermart.net/worldwidewebstrategies/cgi-bin/changep
> w.cgi"
> METHOD="post">
> Your current username:
> 
> Your current password:
> 
> Your new password:
> 
> Type your new password again:
> 
> 
> 
> 
> 
> PrintTag
> exit(0);
> }
> #check for existence of lock file
> if (-e $lokfile)
> {
> #lock file exists! print message & shut down
> print <<"PrintTag";
> Try again!
> The database is in use. Please try again later.
> 
> 
> PrintTag
> exit(0);
> }
> #everything is okay. Create lock file.
> open(LOCK_FILE, ">$lokfile") ||
> die "Couldn't create $lokfile\n";
> #open password file in read-only mode
> open(FILE,"$pwfile") ||
> die "Can't find $pwfile.\n";
> #store database contents in an array and close file
> @indata = ;
> close(FILE);
> #open temp file in overwrite mode
> open(TEMP,">$tmpfile") ||
> die "Can't create $tmpfile.\n";
> #copy password file contents to temp file
> #use a foreach loop to process each record in the array
> foreach $i (@indata)
> {
> #remove hard return character from each record
> chomp($i);
> #split fields on pipe character
> #assign a variable name to each of the fields
> ($username,$password) = split(/\|/,$i);
> if ($username eq $in{'oldname'} &&
> $password eq $in{'oldpw'} &&
> $in{'delete'} ne "yes")
> {
> print TEMP "$in{'oldname'}|$in{'newpw1'}\n";
> print " Success!Your password has been changed.\n";
> }
> elsif ($username eq $in{'oldname'} &&
> $in{'delete'} eq "yes")
> {
> print "Your password has been deleted.\n";
> }
> else
> {
> print TEMP "$i\n";
> }
> }
> #close temp file
> close(TEMP);
> #change file names
> ren

RE: HTTP Links..

2002-01-24 Thread Lorne Easton

I am trying to get a mechaism that does the following..

With relative urls:

I.E: At 
the url <../../page.htm> refers to


so my URL, after:

--SNIP--

#Get page
 my $res = $ua->request(HTTP::Request->new(GET => $starting_url), sub
{$link_extor->parse($_[0])});

#Note that pages are put in @links by callback function by HTML::LinkExtor

  # Expand all image URLs to absolute ones
  my $base = $res->base;
@links = map { $_ = url($_, $base)->abs; } @links;

--SNIP--

Looks like ../../page.htm. Like


The code:

$element =~ s|\.\./||;

Will remove all the "../". I just need to trim the extra page3/ rubbish
depending on the amount of ../s.
Could you point me in the direction of something that will do this. Perhaps
a regexp, though if you
are including one, could you please provide a description of what it does
for me..

Cheers,
Lorne



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Matching text, e.t.c.

2002-01-29 Thread Lorne Easton

The following code:

 SNIP 

sub return_internal_links
{

 foreach my $element (@links) {


my $all_internal = join("\n",@internal),"\n";

if (($element =~ m/$startingurl/i) && ($all_internal !~ m/$element/gi)) {

  print $element,"\n";
  push (@internal, $element);
  }
 }



}

 SNIP 

Still adds the value to the array whether the value is in
internal or not. I am missing something stupid here I know. Could someone
please enlighten me..

I want the value matched if not in @internal and if
it contains $startingurl..

:o)

Cheers,
Lorne



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Matching text.. Question

2002-01-29 Thread Lorne Easton

The following code:

 SNIP 

sub return_internal_links
{

 foreach my $element (@links) {


my $all_internal = join("\n",@internal),"\n";

if (($element =~ m/$startingurl/i) && ($all_internal !~ m/$element/gi)) {

  print $element,"\n";
  push (@internal, $element);
  }
 }



}

 SNIP 

Still adds the value to the array whether the value is in
internal or not. I am missing something stupid here I know. Could someone
please enlighten me..

I want the value matched if not in @internal and if
it contains $startingurl..

Oh, probably works best if I don't post questions RE:,
huh?

:o)

Cheers,
Lorne





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Evaluating case..

2002-02-03 Thread Lorne Easton

Here is some code that I have written. I know that there is a better way of
writing this. As it stands the
code between the "#Evaluation code" does not work as desired. I cannot seem
to get these if ((case1) and (case2))
type statements to work. How would I and what am I doing wrong? Also, is
there a better way of doing this?

Any pointers for a more perlish way of writing this?? Thanks in advance for
your help.


Regards,
Lorne


 SNIP 

use strict;
use Net::Ping;
use Net::SMTP;

my $host_number = 0;
my @host;
my @failed_pings;

#Constant type values
our $smtp_server = "mail.server.com";
our $timeout = 200;
our $max_failed = 4;

#Read in values from configuration file
open(CONFFILE, "$ARGV[0]") or die "$0: error during open(): $!\n";
while ()
{

my ($field_1, $field_2) = split(/:/, $_);
push (@host, $field_1);
print "Host: $field_1\n";
push (@failed_pings, $field_2);
print "Failed Pings: $field_2\n";


}
close(CONFFILE);

#Iterate through hosts and update failed pings accordingly
foreach my $hostname (@host)
{
my $host_state = ping_host($hostname, $timeout);

print "Host Number: $host_number\n";
print "$hostname\t$host_state\n";

#Evaluation code

#Host was down and is now back up
if (($host_state eq 1) and ($failed_pings[$host_number] ge $max_failed))
{
print "Host: $hostname is up.\n";
#$failed_pings[$host_number] = 0;
}

#No errors at all
if (($host_state eq 1) and ($failed_pings[$host_number] lt $max_failed))
{
print "Host: $hostname has no errors.\n";
#$failed_pings[$host_number] = 0;
}

#Failure for one ping
if (($host_state eq 0) and ($failed_pings[$host_number] lt $max_failed))
{
print "Host: $hostname failed for one ping.\n";
#$failed_pings[$host_number]++;
}

#Hostname is completely down
if (($host_state eq 0) and ($failed_pings[$host_number] ge $max_failed))
{
print "Host: $hostname is down.\n";
#$failed_pings[$host_number]++;
}

#Evaluation code

#Now update indices so as not to trip my poorly written if statements
if ($host_state eq 0) {$failed_pings[$host_number]++}
else {$failed_pings[$host_number] = 0}


#Index for failed pings
$host_number++;
}


#Reset index and open conf file for input.
$host_number = 0;
open (RESULTSFILE, ">$ARGV[0]");

#Add new values to conf file
foreach my $hostname (@host)
{

#Be sure of no trailing \n
if ($host_number lt $#host)
{
print RESULTSFILE "$hostname:$failed_pings[$host_number]\n";
print "Inserting Data\n";
}
else
{
 print RESULTSFILE "$hostname:$failed_pings[$host_number]";
 print "Inserting Data\n";
 }

$host_number ++;
}
#End iterate through hosts

close(CONFFILE);

# Functions 

# Ping Host 
sub ping_host
{
my ($hostname, $timeout) = @_;

my $ping_pointer = Net::Ping->new("icmp");
if (!$ping_pointer->ping($hostname, $timeout))
{
 return(0)
 }

return (1);
}


# Send SMTP mail based on input 
sub send_mail
{

my ($smtp_to, $smtp_from, $smtp_subject, $message_body) = @_;

# Testing Output 
print "Sending mail..";
print "\nTo: $smtp_to\n";
print "From: $smtp_from\n";
print "Subject: $smtp_subject\n";
print "Data: $message_body";


# Create SMTP Object
my $smtp = Net::SMTP->new($smtp_server);

print "Your Domain is: ", $smtp->domain;
print "\n",$smtp->banner,"\n";

# Send Mail
$smtp->mail();
$smtp->to($smtp_to);
$smtp->data();
$smtp->datasend("To: $smtp_to\n");
$smtp->datasend("From: $smtp_from\n");
$smtp->datasend("Subject: $smtp_subject\n");
$smtp->datasend("\n");
$smtp->datasend($message_body);
$smtp->dataend();

$smtp->quit();

}

 SNIP 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Multidimensional hashes..

2002-02-05 Thread Lorne Easton

Hopefully an easy one for you guys.

Let's say that you want to have a hash that has a descriptive name (say of a
PC)
and some other inportant imformation.  This information I want to be
associated
with the PC in that it is a second dimension to the hash value "Name" being
it's name..

Is there an easy way of iterating through the hash based on the
computername..
I.E: I want to have the first computername returned, the get the values for
it
and so on, the same way you could do with foreach and an array..

Could you please provide a simple example that you could use to do this??

I hope that this makes sense.. Cheers..

Lorne





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Hashes of hashes..

2002-02-10 Thread Lorne Easton

Hi all,

Another simple one, I hope. I have data like this.

Computername:Description:Failed Pings

At present I am putting this data into seperate arrays
and using an index to get it out in order. Not an
extremely efficient way to do this and I will need to
add more fields later and the like.

I have considered using a hash, but if I,  say use the
keys function, and am using a multidimensional hash
(i.e $hash => computername => description => failed pings) it will, I
assume, return all the values as keys, whereas I only want the first layer
(I.E Computername)
then I can use it to referance the data with known keynames.

How would I do this? Could you please provide some
example code for me? Thanks a lot in advance..

Regards,
Lorne



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Does anyone know anything about this..?

2002-02-12 Thread Lorne Easton

I have data like this.

Computername:Description:Failed Pings

At present I am putting this data into seperate arrays
and using an index to get it out in order. Not an
extremely efficient way to do this and I will need to
add more fields later and the like.

I have considered using a hash, but if I,  say use the
keys function, and am using a multidimensional hash
(i.e $hash => computername => description => failed pings) it will, I
assume, return all the values as keys, whereas I only want the first layer
(I.E Computername)
then I can use it to referance the data with known keynames.

How would I do this? Could you please provide some
example code for me? Thanks a lot in advance..

Regards,
Lorne




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]