Re: IPv4/IPv6 parsing

2016-07-14 Thread Chris Knipe
Hi,


On Thu, Jul 14, 2016 at 10:28 PM, Илья Рассадин  wrote:

> It's really simple regexp that can handle this, I wrote simple example to
> illustrate the idea.
>
> Of course, this $port_re can match invalid port (all port numbers which
> higher than 65536). If it's critical to your case, you can adjust strip
> port function.
>


Yes, that will work for IPv4, not for IPv6 (Regexp::Common:Net needs a
different pattern for a IPv6 regexp).  It's not as simple as that.

You first need to reliably determine whether it's an IPv4 or IPv6 address
(both contain . and : which is generally used for this test), and whether
it's IPv4 or IPv6, that will determine how to strip off the port (such as
using Regexp::Common for example)...

Once you know for certain that you're dealing with an IPv4 OR an IPv6
address, yes, it's easy to strip the port off.  I guess the question wasn't
clear then.  How would you differentiate between a IPv4:port and IPv6.port,
as both contain the same set of numbers.  Assuming IPv4 is decimal only
also won't work as 1:2:3:4::1 is also a perfectly legitimate IPv6 address.

Would need to be some kind of regexp checking the amount of "." vs. the
amount of ":" characters I guess.  IPv4 = 3 dots + 1 colon, whilst IPv6 =
at least two colons and one dot.  Once you know whether you're dealing with
IPv4 or IPv4, a simple split() would be enough to cut the port... The
question is more towards determining reliably what you're working with.

--
Chris.


IPv4/IPv6 parsing

2016-07-14 Thread Chris Knipe
Hi,

Any modules available that can:
  - Parse IPv4/IPv6 addresses that includes ports (1.1.1.1:80 & ::1.80 for
example)
  - Convert the IPv4 and IPv6 to integers

There's plenty around to convert to integers, validate the address, etc.
Not a lot (that I could find) that can handle an address that includes the
port portion.  Net::IP for example sees the above mentioned two examples as
invalid addresses (and rightfully so I suppose).

Is there perhaps an intelligent way to split() the address from the port
that would work for both IPv4 as well as IPv6?  Should be possible with a
regex I guess, but them regex'es ain't one of my strong points.

-- 

Regards,
Chris Knipe


Cache::*

2016-02-18 Thread Chris Knipe
Hi,

Are there any Cache::* modules that are thread safe and can be used with
Threading?

Using Cache::Memory (even specifying the same NameSpace), two or more
threads can't access the same keys in the cache,

Using Cache::File, there are issues with the indexes (documented too under
Caveats,

Neither can be :shared, Invalid value for shared scalar

I'm basically just looking for a key->value type of way to share data
between the threads, but I would prefer not to use an external resource
such as memcached or redis.

Master thread basically uses Thread::Queues to enqueue work received via an
IO::Socket::INET, slaves process the work (while the client socket waits),
and then the master thread returns the result from the queued work back
over the TCP socket.

With IO::Select and IO::Sockets, this is the rundown of the client loop...

while (1) {
  foreach my $ClientConnection ($Select->can_read(1)) {
if ($ClientConnection == $ServerSocket) {
  $ClientConnection = $ServerSocket->accept();
  $Select->add($ClientConnection);
} else {
  my $Data = $ClientConnection->getline();
  unless (defined($Data) && length($Data)) {
$Select->remove($ClientConnection);
$ClientConnection->shutdown(2);
close $ClientConnection;
next;
  }
  if ($RequestQueue->pending() > $MaxConnections*4) {
$ClientConnection->send("400 Too busy\r\n");
next;
  } else {
$Data =~ s/[^ -~]//g;
$RequestQueue->enqueue($Data);
my $Processed = 0;
my $TimeStamp = time();
if (defined($Data) && length($Data)) {
  do {
# $Cache->set is called in the worker threads
my $Response = $Cache->get($Data);
if ($Response && $Response ne "") {
  $ClientConnection->send($Response);
  $Cache->remove($Data);
  $Processed=1;
}
  } until ($Processed==1 || time() - $TimeStamp >= 2);
}
  }
}
  }
}



-- 

Regards,
Chris Knipe


Re: reading from socket

2015-09-17 Thread Chris Knipe
>
>
> Hello Chris.
>
> Can you provide the yenc files?
> Both the good one and the bad one?
>


http://expirebox.com/download/f7ebd6e37cf576e29df89bb6ae78ded4.html

- Includes the two original files (text document, and binary image)
- Includes the yEnc version of both files, as received by Perl (posted
through another program to the server, it doesn't have a option to save the
files to disk prior to posting to the server)
- Includes the yEnc version of both files, as encoded by the official yEnc
encoder/decoder from http://www.yenc32.com/

--
Chris.


RE: reading from socket

2015-09-17 Thread Chris Knipe
Just an example, and no, the decoder isn't written by me, it's from the 
official yEnc web site (www.yenc.org), so I'm 100% it's right.

Both files are encoded and uploaded by the same piece of software (again, not 
written by me), and again, I'm 100% that software is correct as well, it's used 
by thousands of people on a daily basis... 

Both these messages, are sent through the EXACT code, as it's below... 

This works absolutely fine:
Trigger: =ybegin part=1 line=128 size=76 name=New Text Document.txt
DesFileName = (New Text Document.txt)
yDecoder started...
=ypart-line:  =ypart begin=1 end=76
part-begin: 1
part-end  : 76
Last line.
Endline (76 bytes): =yend size=76 part=1 pcrc32=f00625ae
Included CRC: $f00625ae - calculated CRC: $f00625ae
Write part to target file (start: 0, size: 76)
yDecode successful
AddPart (New Text Document.txt(76).dec) [1 - 76]
Complete multipart --> New Text Document.txt
Decoded multipart --> New Text Document.txt


This fails:
Trigger: =ybegin part=1 line=128 size=77859 name=Capture.PNG
DesFileName = (Capture.PNG)
yDecoder started...
=ypart-line:  =ypart begin=1 end=77859
part-begin: 1
part-end  : 77859
Last line.
Endline (77862 bytes): =yend size=77859 part=1 pcrc32=083aa26d
Partial message corrupt: longer than (end-begin)!
yDecode failed (reason: 11)

Note that the failed file has 3 extra bytes... It should end at 77859, but 
instead, it ends at 77862.  So where does those extra three bytes come from?

*completely, lost*





-----Original Message-
From: Chris Knipe [mailto:sav...@savage.za.org] 
Sent: Thursday, September 17, 2015 10:56 PM
To: 'beginners@perl.org' 
Subject: RE: reading from socket

Hi All,

I'm SERIOUSLY starting to cry here :-(  It's been over a month since I started 
this thread, and it's pretty much been close to a year of me battling to get 
this right with perl, and yes - still not there... 

Running under Net::Server, I have:

sub process_request {
while () {
  $_ =~ s/\r?\n$//; # Remove any instance of \r or \n from the end 
of the received line
  $_ =~ s/\t//; # Remove any instance of \t from the received 
line
  $_ =~ s/[^[:ascii:]]//g;
  my @Command = split(/\ /, $_);
  switch($Command['0']) {

case m/^\bPOST\b/i {
  print $sock "340 Ok, send message\r\n";

my $filename = '/tmp/test.txt';
open(OUTFILE, ">", $filename);
binmode(OUTFILE);
binmode(STDIN);
my $size=0;
  while (read(*STDIN, local $_, 4)) { $self->log(0,Dumper($_)); print 
OUTFILE $_; $size=$size+length($_);
if ($_ =~ /^\.\r\n$/) {
  last;
}
  }
close(OUTFILE);
  print "240 article received\r\n";
$self->log(0,"received: " . $size);
}
  }
}
  }
}


1) From the client, I can confirm via Wireshark, all data has been transmitted 
(correctly, and successfully),
2) On the server, I can confirm via tcpdump, all the data has been received 
(correctly, and successfully),
3) In perl, I can confirm the entire message has been received in sequence 
(whether it's correct or not, I do not know),

Certain messages that are sent, decodes correctly (a manual decode of the file 
that has been written.  Other messages that are sent, does not decode correctly 
(but the data has been transmitted and received correctly).  I am able to 
reproduce, and have data sets of data that works, and data that doesn't work.  
The problem is that after the file is saved to disk, certain files can decode 
successfully, whilst others, does not decode correctly.

Can someone *PLEASE* just help me to get this sorted out?  I am even willing to 
go off list and pay someone to fix this for me.  It's now a serious, serious 
issue that I need to get resolved asap, and more than likely either something 
very trivial that I'm overlooking, or a bug somewhere in perl / Net::Server.

Yes, this is still yEnc related binary data...  And a gazillion things has been 
tried already (a lot coming from this mailing list). 

I fail (really, I do), to see why SOME yEnc messages that is saved decodes 
correctly, and others does not.  It's precisely the same code The only 
thing that I can think of is that there are certain characters in some messages 
that something doesn't like, which IMHO means something is manipulating / 
changing the data is some way or form... The above code really is simple, 
there's no changing of data there 

--
Chris.






-Original Message-
From: Brandon McCaig [mailto:bamcc...@gmail.com]
Sent: Wednesday, August 12, 2015 8:00 PM
To: Chris Knipe 
Cc: beginners@perl.org
Subject: Re: reading from socket

On Wed, Aug 12, 2015 at 12:40:29AM +0200, Chris Knipe wrote:
> On Wed, Aug 12, 2015 at 12:16 AM, Chris Knipe  wrote:
> Looking at Data::Dumper - it actually looks like latin1 to me 
> *se

RE: reading from socket

2015-09-17 Thread Chris Knipe
Hi All,

I'm SERIOUSLY starting to cry here :-(  It's been over a month since I started 
this thread, and it's pretty much been close to a year of me battling to get 
this right with perl, and yes - still not there... 

Running under Net::Server, I have:

sub process_request {
while () {
  $_ =~ s/\r?\n$//; # Remove any instance of \r or \n from the end 
of the received line
  $_ =~ s/\t//; # Remove any instance of \t from the received 
line
  $_ =~ s/[^[:ascii:]]//g;
  my @Command = split(/\ /, $_);
  switch($Command['0']) {

case m/^\bPOST\b/i {
  print $sock "340 Ok, send message\r\n";

my $filename = '/tmp/test.txt';
open(OUTFILE, ">", $filename);
binmode(OUTFILE);
binmode(STDIN);
my $size=0;
  while (read(*STDIN, local $_, 4)) {
$self->log(0,Dumper($_));
print OUTFILE $_;
$size=$size+length($_);
if ($_ =~ /^\.\r\n$/) {
  last;
}
  }
close(OUTFILE);
  print "240 article received\r\n";
$self->log(0,"received: " . $size);
}
  }
}
  }
}


1) From the client, I can confirm via Wireshark, all data has been transmitted 
(correctly, and successfully),
2) On the server, I can confirm via tcpdump, all the data has been received 
(correctly, and successfully),
3) In perl, I can confirm the entire message has been received in sequence 
(whether it's correct or not, I do not know),

Certain messages that are sent, decodes correctly (a manual decode of the file 
that has been written.  Other messages that are sent, does not decode correctly 
(but the data has been transmitted and received correctly).  I am able to 
reproduce, and have data sets of data that works, and data that doesn't work.  
The problem is that after the file is saved to disk, certain files can decode 
successfully, whilst others, does not decode correctly.

Can someone *PLEASE* just help me to get this sorted out?  I am even willing to 
go off list and pay someone to fix this for me.  It's now a serious, serious 
issue that I need to get resolved asap, and more than likely either something 
very trivial that I'm overlooking, or a bug somewhere in perl / Net::Server.

Yes, this is still yEnc related binary data...  And a gazillion things has been 
tried already (a lot coming from this mailing list). 

I fail (really, I do), to see why SOME yEnc messages that is saved decodes 
correctly, and others does not.  It's precisely the same code The only 
thing that I can think of is that there are certain characters in some messages 
that something doesn't like, which IMHO means something is manipulating / 
changing the data is some way or form... The above code really is simple, 
there's no changing of data there 

--
Chris.






-----Original Message-
From: Brandon McCaig [mailto:bamcc...@gmail.com] 
Sent: Wednesday, August 12, 2015 8:00 PM
To: Chris Knipe 
Cc: beginners@perl.org
Subject: Re: reading from socket

On Wed, Aug 12, 2015 at 12:40:29AM +0200, Chris Knipe wrote:
> On Wed, Aug 12, 2015 at 12:16 AM, Chris Knipe  wrote:
> Looking at Data::Dumper - it actually looks like latin1 to me 
> *seriously
> confused*
> 
> $VAR1 =
> "L\\xAF\\xF3\\xDDWJL\\x94\\xEB\\xB2\\xF8\\xE1\\xACZ\\x89Ul;\\xB7\\xD
> E}1
> '\\xCA\\xC2\\xE3uZ\\xFF7\\xD2=}\\xA8q:;\@,%:_\x{286}-\\xD8\\xF8\\xF
> 9E\x{2c1}5\\xD6j+Z?\\xA6\\x9F\\xEC7\\xEC\\xBB4'CNld\\xBE\\xE6=J\
> \xFDL\x{7d4}\\xF9nOz(w\\x83\\xEA\\xD6UHi\\xD5p+\\xBFa\\xADvG\\xD4*a\\
> xEA\\xBBC\\xD0\x{9631}=J\\x96 
> \\xFD&\\xF9MxD\\x89g\\x9EA\\xBD5\\xB4R\\xA0\\xE5sp\\xF3\\xD2x\\x84
> \xEC\\x92y\\x91\\\x{7c1}\\xB1\\xA1\\x9C\\xB73BE\\xA9)\\xCAf\\xC8\\xE
> E+\\xA1b\\x8E\\xFCM!\@\\xBE^\\xB5d";

This snippet of data looks like what I perceive the yEncoding to be. If this is 
the beginning of the message then perhaps the entire stream *is* yEncoded? In 
that case, decoding the yEnc before processing may be helpful. I don't know 
what protocol this is...

I don't see anything in there that could be mistaken for \r or \n, though I'm 
not sure how yEnc works. How did you modify the loop to log this? Can you show 
us the updated program?

> And yes - there's numerous characters in the the above that actually 
> didn't even make it to the email...
> http://www.savage.za.org/webpics/perl-encode.png

I don't remember mention of an E-mail before. What relationship does that 
E-mail message have to this program?

Note also that you appear to be sending HTML E-mails (see the Internet for why 
that's evil), which could also potentially mean that what I'm reading in plain 
text isn't exactly what you intended to send... It all depends on your MUA. You 
may gain some comfort knowing what you send is what you want to send by 
switching to pl

Re: reading from socket

2015-08-11 Thread Chris Knipe
On Wed, Aug 12, 2015 at 12:16 AM, Chris Knipe  wrote:



> Lines *should* be terminated by CRLF (provided the 8-bit encoding doesn't
> mess up the detection), and the entire data stream is then terminated with
> a CRLF.CRLF (similar to a SMTP message for example in terms of protocol).
>

Looking at Data::Dumper - it actually looks like latin1 to me *seriously
confused*

$VAR1 =
"L\\xAF\\xF3\\xDDWJL\\x94\\xEB\\xB2\\xF8\\xE1\\xACZ\\x89Ul;\\xB7\\xDE}1
'\\xCA\\xC2\\xE3uZ\\xFF7\\xD2=}\\xA8q:;\@,%:_\x{286}-\\xD8\\xF8\\xF9E\x{2c1}5\\xD6j+Z?\\xA6\\x9F\\xEC7\\xEC\\xBB4'CNld\\xBE\\xE6=J\\xFDL\x{7d4}\\xF9nOz(w\\x83\\xEA\\xD6UHi\\xD5p+\\xBFa\\xADvG\\xD4*a\\xEA\\xBBC\\xD0\x{9631}=J\\x96
\\xFD&\\xF9MxD\\x89g\\x9EA\\xBD5\\xB4R\\xA0\\xE5sp\\xF3\\xD2x\\x84\xEC\\x92y\\x91\\\x{7c1}\\xB1\\xA1\\x9C\\xB73BE\\xA9)\\xCAf\\xC8\\xEE+\\xA1b\\x8E\\xFCM!\@\\xBE^\\xB5d";

And yes - there's numerous characters in the the above that actually didn't
even make it to the email...
http://www.savage.za.org/webpics/perl-encode.png


-- 

Regards,
Chris Knipe


Re: reading from socket

2015-08-11 Thread Chris Knipe
>
> Firstly, if the handle isn't being read with binmode set then
> perhaps the \r\n are being converted to \n (if this is Windows)?
> How are you creating/initializing the socket?
>


Unfortunately, with or without binmode, there's no difference to the
matching (from what I can tell)

Socket creation:
my $TCPSocket = new IO::Socket::INET (PeerHost => "x.x.x.x",
  PeerPort => "5000",
  Proto=> "tcp",
  Blocking => "1", 
<-- Tried with blocking (0|1) as well.
 ) or die "ERROR in Socket Creation :
$!\n";

# Ensure we get output right away
$TCPSocket->autoflush(1);

binmode $TCPSocket;### Tried with/without binmode



Similarly, the character encoding of the data on the socket could
> matter. You said there are character codes above 127. Does that
> mean the encoding is 8-bit such as [extended] ASCII or latin1, or
> do you mean the character codes are WAY above 127? Character
> encoding could be another culprit if the \r and \n characters are
> encoded differently in the stream than you (and Perl) expects.
> Using the IO layers or the explicit Encode module you should be
> able to decode the stream into a Perl string that Perl
> understands properly.
>

>From the relevant RFCs:

   The terms "NUL", "TAB", "LF", "CR, and "space" refer to the octets
   %x00, %x09, %x0A, %x0D, and %x20, respectively (that is, the octets
   with those codes in US-ASCII [ANSI1986] and thus in UTF-8 [RFC3629]).
   The term "CRLF" or "CRLF pair" means the sequence CR immediately
   followed by LF (that is, %x0D.0A).  A "printable US-ASCII character"
   is an octet in the range %x21-7E.  Quoted characters refer to the
   octets with those codes in US-ASCII (so "." and "<" refer to %x2E and
   %x3C) and will always be printable US-ASCII characters; similarly,
   "digit" refers to the octets %x30-39.

However, the data stream does contain yEnc content, which as far as I know,
is 8-bit encoding.  So whilst the protocol itself may use UTF-8, the data
transmitted in the protocol can either be UTF-8, or 8-bit

Lines *should* be terminated by CRLF (provided the 8-bit encoding doesn't
mess up the detection), and the entire data stream is then terminated with
a CRLF.CRLF (similar to a SMTP message for example in terms of protocol).



> You can attach an IO layer to the file handle by passing an
> additional argument to binmode:
>
> binmode $fh, ':encoding(UTF-8)';
>
>
Loads, and LOADS and *piles* of UTF-8 errors...

utf8 "\xD826" does not map to Unicode at test.pl line 40 (#1)
utf8 "\x1583F9" does not map to Unicode at test.pl line 40 (#1)
etc.

>From personal experience and using other (nasty) methods and components for
doing what I -should- be able to do with native perl, I've learned the hard
way that messing with binmode $fh, ":encoding" generally corrupts the
8-bit (yEnc) data.  Again, I am more than likely doing it incorrectly, but
I'm really trying to understand how to do it correctly though :-)



> Lastly, you're reading from a socket so there's no guarantee that
> the buffer string is going to necessarily end at the termination
> boundary. Perhaps the protocol guarantees that, but the socket
> surely doesn't. You may need to look for that terminating
> sequence in the middle of the buffer.
>
>
But isn't that exactly why we set things like autoflush(1) or $|=1?  After
the data stream has been sent from the server (i.e. CRLF.CRLF) the server
stops transmitting data and waits for the next command, so there's no
chance that a second data stream may be received by the client socket, at
least not until the client socket issues a new command.



> Does any of that help?
>
>
I appreciate it, truly.  But no, not really :-(  I can honestly say, been
there, done that.

I realize my problem here is the really whacky way in which the data stream
is encoded (and that is completely out of my control).  But there must be a
adequate and proper way to handle this data.


-- 

Regards,
Chris Knipe


Re: reading from socket

2015-08-11 Thread Chris Knipe
On Tue, Aug 11, 2015 at 5:28 PM, John SJ Anderson  wrote:

> On Tue, Aug 11, 2015 at 6:58 AM, John SJ Anderson 
> wrote:
>
>> On Tue, Aug 11, 2015 at 5:24 AM, Chris Knipe 
>> wrote:
>>
>>>
>>>
>>> my $numBytesToRead = 512;
>>>
>>> my $buffer;
>>>
>>> while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {
>>>
>>>   if ($buffer =~ m/\r\n\.\r\n$/) {
>>>
>>> print $buffer;
>>>
>>> last;
>>>
>>>   }
>>>
>>> }
>>>
>>>
>>>
>>> I’m obviously doing this wrong :(  Can anyone perhaps show me the light?
>>>
>>>
>> Don't you need to put $bytesRead into $buffer at some point?
>>
>
> Wow, and this is why we don't review the code before the coffee... 8^/
>


Indeed... read() returns the number of bytes read, not the actual stream of
what HAS been read, unless of course I am again missing something...
http://perldoc.perl.org/functions/read.html

For the above, $bytesRead will be 512.  The stream that is read, is pushed
into $buffer

-- 

Regards,
Chris Knipe


reading from socket

2015-08-11 Thread Chris Knipe
Hi All,

 

I'm reading "binary" from a socket, and just like a normal email message on
the SMTP protocol (for example), the data is terminated by \r\n.\r\n

 

I'm saying "binary" because the data stream does include yEnc data (or
character codes > 127)

 

I'm having issues to exit my read loop when I receive the termination
characters... 

 

my $numBytesToRead = 512;

my $buffer;

while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {

  if ($buffer =~ m/\r\n\.\r\n$/) {

print $buffer;

last;

  }

}

 

I'm obviously doing this wrong :(  Can anyone perhaps show me the light?

 

--

Chris.

 



Re: UTF8, UTF-8, utf8, Utf8 encoding blues

2014-11-08 Thread Chris Knipe
Hi Kent,

> Though I haven't fully understood the problem and I'm also tired, so my tip
> could be a red herring.
>
> The good news is if you want to remove only 3 *bytes* from the string
> instead of 3 *characters* then that could be straight forward.
>
> And I believe ".\r\n" might be exactly 3 bytes regardless of unicode magics.
> ( That is, depending on what you're doing you could get away without the
> utf8 transformation, but I really don't know what I'm talking about now )

I agree with you - and it also explains what we are seeing in terms of
that certain data comes through clean, and others doesn't.  I too
expect that the *entire stream* is not encoded with UTF8 (even though
it should be).

In terms of removing the last three characters, that is not what is
causing the issue.  Even if I remove the substr and pass literally
$Body = $Response, the data is still corrupted once it goes out via
STDOUT.

What is also VERY strange to me is that for some reason when I just do
something simple like put a use Encoding into the script, everything
works fine.  Then half an hour later, or a day or two later, and it
stops working and starts becoming corrupt again.  And THIS is what has
my mind completely baffled.  I am the only one with access to the
servers (and code), and I am not even logged in on the machines when
this sudden "change" in behaviour happens.

This is however really urgent to me, and I am not by any means the
"expect" in terms of programming either.  As I've stated in one or two
private emails, I am willing to pay someone to look at the code and
fix this for us.  I'm not asking you to do my homework either - it's a
legitimate issue going on here in a semi big application (and it
worked fine for about a year and a half before all of a sudden just
acting up for some reason).  I won't be surprised if this is a OS
issue even.


-- 

Regards,
Chris Knipe

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




UTF8, UTF-8, utf8, Utf8 encoding blues

2014-11-08 Thread Chris Knipe
Hi All,

I'm reading loads, and loads of very confusing and contradicting information
about UTF8 in Perl.  A lot of posts are also (rightfully IMHO) stating that
UTF8 is an absolute nightmare in Perl. 

Can someone shed some light as to what is going on here please:

use Encoding;

SysLog("debug", "1 - DEBUG LENGTH: " . length($Response));
my $unicode_chars = Encode::decode('utf8', $Response);
SysLog("debug", "** ENCODING: " . find_encoding($Response));
my $newunicode_chars = substr($unicode_chars, 0, -3);
my $Body = $newunicode_chars;

Log:
Nov  8 11:44:59 cache12 perl[44786]: DEBUG: 1 - DEBUG LENGTH: 1001 
Nov  8 11:44:59 cache12 perl[44786]: DEBUG: ** ENCODING:  
Nov  8 11:44:59 cache12 perl[44786]: DEBUG: 2 - DEBUG LENGTH: 998

The idea is to remove the last three characters from the string (.\r\n).
Now whilst it looks like it worked because the length is 3 less, the
encoding is entirely whacked.  The encoding at the beginning and the
encoding at the end are different.  find_encoding() does not state which
encoding is used on the string initially, yet are, apparently, more than
happy to decode it as utf8. When Perl now re-encodes the string as utf8,
it's completely whacked and the string just plain and simply is wrong and
the data does not match CRC checksums.

I know for a FACT that the initial data is encoded using UTF8. When I remove
the code to strip the last 3 characters (.\r\n) from the $Response
everything works absolutely fine.  Unfortunately, I *must* remove these last
three characters.

Can anyone perhaps please shed some light on the subject for me.  



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: async, non blocking tcp server

2014-08-29 Thread Chris Knipe
On Fri, Aug 29, 2014 at 11:20 AM, Carl Inglis  wrote:
> Does your communication protocol not include an option to back off the rate
> of transmission? Or could you do something at a lower level and not ACK the
> packets to force retransmission at the TCP level? (Clutching at straws a
> little here).

Unfortunately not (we are talking NNTP specifically here if it isn't
obvious yet) - and the data rates on the network in terms of the
stream we're looking at over 1Gbps (generated with the TAKETHIS
commands).  The other seemingly obvious problem that I am going to
have by handing the work off to a separate process (or even thread for
that matter) is that I need to inform the remote client on the socket
in real time whether I want / do not want / if an error occurred to
the article in question issued by the command from the client.

It's times like this that I *really* wish I knew how to code in C - no
offence to anyone, again.  Even in .NET doing something like this is
almost trivial by using separate event handlers for receiving data
from the socket - again which is why I firmly believed that something
like this could have been done via POE (yes, this would be handled via
threads - but it's done and managed by the .NET modules, and thus
require -very- little code, or understanding for that matter, from the
programmer's point of view).

Oh well - it's back to the drawing board for this one then.

-- 

Regards,
Chris Knipe

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: async, non blocking tcp server

2014-08-29 Thread Chris Knipe
On Fri, Aug 29, 2014 at 10:43 AM, Carl Inglis  wrote:
> Hi Chris,
>
> The only way this is going to work as far as I can see is some form of
> multi-threading - how about you have a thread which issues the commands, a
> thread which reads from the sockets and shoves the results into a queue, and
> another thread which processes that queue.
>
> I think you're looking for a single threaded solution to an implicitly
> multi-threaded problem. I can't see any way for a single thread to do what
> you want.

Not specifically looking for a single threaded solution - looking for
*any* solution.  This is why I am saying, there really isn't anything
in terms of examples, cookbooks, etc. dealing with something like
this.  This is really simple asynchronous communication at the end of
the day - in my books at least.  Through my searching I've stumbled
onto something on perlmonks (I think) basically where there was a
thread to read from the socket, and a thread to write to the socket,
but it was advised against doing that for some reason or the other -
I'll see whether I can get the link again in the browser history or
something.

At the end of the day I suppose, see this as an opportunity (for the
mainstream developers).  Whilst it will most certainly complicate
things, native support for things like this in POE, or Net::Server, or
Net::IO::Socket would really be appreciated.  We are in the 21st
century afterall.  IMHO the days synchronous communication are long
gone.  And again, I mean this with the utmost respect :-)  In the case
of POE or Any::Event (if my memory serves me correctly), one should
surely be able to "offload" the "work" through an event handler in a
non blocking way, and write back to the socket at any time?  That was
my understanding of it at least - and guess my surprise when that was
not the case.  Who knows, perhaps it is possible and I'm just
overlooking it too.

Multi-Threading and queueing is a option.  The first thing that crops
up in my head again now though is that *IF* you receive data faster
than what you can process it, you're now looking at OOM issues again.
Secondly sitting with say, 1K forks from Net::Server and each fork
sitting with 2 or 3 Threads - the poor server is all that I'm going to
say...

Perhaps the simplest (and what I didn't want to do), is to just dump
it to a spool directory on disk and have a completely separate daemon
pickup and process the files from disk... At least then you can read
the list of files, spawn say 30 or 40 threads, and deal with the files
- quickly - say every minute or two.  The server can also if needs be
I suppose fork through a non blocking sub to write the files to disk,
so the server doesn't even need to wait for the IO operation.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: async, non blocking tcp server

2014-08-29 Thread Chris Knipe
And this is effectively what I WANT to happen...

  [C] TAKETHIS 
  [C] Path: pathost!demo!somewhere!not-for-mail
  [C] From: "Demo User" 
  [C] Newsgroups: misc.test
  [C] Subject: I am just a test article
  [C] Date: 6 Oct 1998 04:38:40 -0500
  [C] Organization: An Example Com, San Jose, CA
  [C] Message-ID: 
  [C]
  [C] This is just a test article.
  [C] .
# . indicates the end of the article.  Perl now starts to do work,
processing the article it received. As this process takes time, the
main while (1) { loop reading from the socket is now blocked, causing
the server not to read any more from the socket until after the
article has been dealt with.
  [C] TAKETHIS 
  [C] Path: pathost!demo!somewhere!not-for-mail
  [C] From: "Demo User" 
  [C] Newsgroups: misc.test
# Perl server only NOW responds with an acceptance code for the first article.
  [S] 239 
  [C] Subject: I am just a test article
  [C] Date: 6 Oct 1998 04:38:40 -0500
  [C] Organization: An Example Com, San Jose, CA
  [C] Message-ID: 
  [C]
  [C] This is just a test article.
  [C] .
# Perl server only NOW responds with an acceptance code for the second article.
  [S] 239 

I am now presuming that we've read both articles completely (all
lines) from the socket.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: async, non blocking tcp server

2014-08-29 Thread Chris Knipe
On Fri, Aug 29, 2014 at 10:10 AM, Carl Inglis  wrote:
> I suspect you're looking for something like this:
> http://www.perlmonks.org/?node_id=66135
>
> In fact, it's specifically mentioned in the Perl Cookbook:
> http://docstore.mik.ua/orelly/perl/cookbook/ch07_15.htm

The comments on the first URL is worrying, but I don't believe that it
would solve my issue.  Lets take the following out of RFC4664 as an
example.  This is an actual example of a communication stream between
a client and the perl server, the socket is already established, and
communication is flowing between the two parties.  [C] indicates what
the client is sending to the server, and [S] indicates the responses
the server sends to the client.  My comments added with # and thus
does not form part of the communication stream.

  [C] TAKETHIS 
  [C] Path: pathost!demo!somewhere!not-for-mail
  [C] From: "Demo User" 
  [C] Newsgroups: misc.test
  [C] Subject: I am just a test article
  [C] Date: 6 Oct 1998 04:38:40 -0500
  [C] Organization: An Example Com, San Jose, CA
  [C] Message-ID: 
  [C]
  [C] This is just a test article.
  [C] .
# . indicates the end of the article.  Perl now starts to do work,
processing the article it received. As this process takes time, the
main while (1) { loop reading from the socket is now blocked, causing
the server not to read any more from the socket until after the
article has been dealt with.
  [C] TAKETHIS 
  [C] Path: pathost!demo!somewhere!not-for-mail
  [C] From: "Demo User" 
  [C] Newsgroups: misc.test
  [C] Subject: I am just a test article
  [C] Date: 6 Oct 1998 04:38:40 -0500
  [C] Organization: An Example Com, San Jose, CA
  [C] Message-ID: 
  [C]
  [C] This is just a test article.
  [C] .
# Perl server only NOW responds with an acceptance code for the first article.
  [S] 239 

We have effectively now COMPLETELY missed the second article in our
while (1) loop, as perl did not read from the socket WHILST processing
the article.

When you multiply the above example and think that you can effectively
be receiving up to 100 (if not more) TAKETHIS commands per second, and
that it takes (on average) say 100ms to "deal" with an article
received... I'm sure you can understand the economics at scale here as
to why this is important, and what I mean by non blocking...

The whole while (1) { read from socket; do work; respond; }; isn't
going to work.  The moment you "do work", you block reading from the
socket until such time that the work has been completed.   I don't
know how to be clearer about this.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: async, non blocking tcp server

2014-08-29 Thread Chris Knipe
On Fri, Aug 29, 2014 at 1:18 AM, Sam  wrote:
> Are you saying the normal 'unix' way won't work? (ie. listen on socket, fork
> on an accepted connection, do the work, close)

Oh - and yes, if that is the 'unix' way, then yes, it's unacceptable.
The socket CANNOT be torn down after each and every single command.
Once the client is connected to the socket, the client can send to the
tune of hundreds of commands per second.  Tearing down and then
re-establishing a TCP session each time, will be just as devastating
(if not more) to performance as dealing with requests synchronously.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: async, non blocking tcp server

2014-08-29 Thread Chris Knipe
On Fri, Aug 29, 2014 at 1:18 AM, Sam  wrote:

> Are you saying the normal 'unix' way won't work? (ie. listen on socket, fork
> on an accepted connection, do the work, close)

Not at all.  My problem is not related to creating, accepting, or
forking at all.

The block / waiting occurs whilst the socket is already connected.  I
think a better way to describe this from terms I've seen whilst
googling... I need to be able to read & write simultaneously on the
socket after the client connected.

Again, as per my example given, that is one single client socket
connected to the server.  The asynchronous part comes in to the effect
that the client must be able to CONTINUOUSLY (non blocking) supply
commands to the server, whilst the server MAY take a large time before
responding to those commands.  Now, every single (almost) perl
application I've looked at, does this to some form of degree in terms
of reading/writing on sockets...

while (1) {
  # read $_ from socket
  # do stuff with $_
  # respond to client with some form of print
}

In that example, whilst you are doing stuff with $_ (the workload,
sleep($randomtime) in my example, the client is blocked and the client
cannot write to the socket (or technically it can, but the server
can't process it rather).  I am thus referring to the communication
stream, needing to be asynchronous.

I don't even know how to accurately present this in text, but I'm
basically after something to the tune of the below.  And the *real*
crux of the matter is going to be that the writing will indeed
sometimes happen at the *same time* as what the reading will happen.
Or at least, it needs to.

while (1) {
  # read $_ from the socket and pass it to some non blocking sub / event handler
}

sub processit {
  # do stuff with $_
  # respond to the client with some form of print
}

SMPP is a protocol which can be seen as a very good example.  Whilst
it CAN work synchronously (receive data, process it, respond), it
operates immensely better when it's written as a asynchronous
application.  THe same with certain aspects of NNTP for example (RFC
4644), and I'm sure that there is allot of other examples I can give
where asynchronous communication is absolutely vital.

I'm most certainly also not saying that it isn't possible with Perl
either.  All that I am saying is that, to date, I have not been able
to find one single example, recipe, or cookbook entry on HOW to do
this.  Not wanting to step on any toes, but I almost get the feeling
that the examples of code being given is rather outdated.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




async, non blocking tcp server

2014-08-28 Thread Chris Knipe
Hi All,

 

I've looked at Net::Server (and have my "new" server with some 20K lines of
code written in it that we're currently finalising), POE, and a few other
things, but I cannot find what I am looking for. I'm hoping for some
assistance / pointers please.  I am looking for the following simple
scenario.

 

On the server side, read data through the socket (for simplicity, let's say
"commands" are terminated by \n)

On the client side, send numerous commands to the server, WITHOUT waiting
for a response - that's simple enough.

 

Now, let's say the server sleep($randomtime) between commands to simulate a
work load.  I effectively want the following

 

C> Do 1

C> Do 2

S> Done 1

C> Do 3

C> Do 4

S> Done 4

S> Done 2

S> Done 3

 

I know this sounds simple, but can anyone give a rough example of the server
code (even if it's just an echo with a random sleep).  For the love of. I
cannot seem to stop the synchronous nature of POE, or Net::Server.  The
whole wait for input, deal with input, write output thing is really blocking
my application's performance, seriously, at this point in time.  I need to
be truly asynchronous.

 

I need to also preferably need to use PreForks.  The application needs to
deal with some 500Mbps in terms of bandwidth on the sockets, and a good
amount of thousands of concurrent connections.  Again, I'm not sure whether
Net::Server will scale (we're developing / debugging currently, whilst in
production we currently use xinetd).

 

Many thanks,

Chris.

 

 

 

 

 



Re: Date::Parse and strange dates

2014-07-25 Thread Chris Knipe
On Fri, Jul 25, 2014 at 7:12 PM, Andy Bach  wrote:
>
> On Fri, Jul 25, 2014 at 11:54 AM, Chris Knipe  wrote:
>>
>> Thu, 23 Oct 2008 12:06:48+0400
>>
>>
>>
>> Note the lack of a space between the seconds and the timezone.
>
>
> Well, depending upon the consistency of your one bad case (presuming the
> date string is in $_ for the moment):
> if ( s/(\w+, \s+ \d+ \s+ \w+ \s+ \d+ \s+ [\d:]+) ([+-]\d+/$1 $2/xms )
>  warn("Fixed bad date str $_\n");
> }
>
> either after Date::Parse has failed (and so retry) or a test before, just in
> case.

Would have to be something generic I suppose.  Will look through
Regex::Common as someone else suggested as well.  Now that +- timezone
is fixed, now the next one just crops up...

Mi, 18 Nov 09 12:39:57 GMT

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Date::Parse and strange dates

2014-07-25 Thread Chris Knipe
Hi All,

 

I have the odd (very rare) case where I am given a date in an incorrect
format.  I already use Date::Parse to convert the dates to a unix timestamp,
and it's working incredibly well.  However, on the rare case that I get
incorrect dates, Date::Parse does not like them either and errors out.  The
formats in question that I can't parse basically looks like

 

Thu, 23 Oct 2008 12:06:48+0400

 

Note the lack of a space between the seconds and the timezone.

 

Is there a simple quick way to fix that by means of a regex?

 

Many thanks,

Chris.

 



Re: question on escaping shell command

2014-05-16 Thread Chris Knipe
Thanks for all the suggestions and replies guys.

After further investigation, it seems the bug is rather in the shell
program itself.  Even if reading the values from a text file instead
of STDIN, it still refuses to parse anything beyond a # character.

I've altered my code to use Authen::Radius instead, and it seems to be
working better.

--
Chris.


On Fri, May 16, 2014 at 10:54 AM, Simon Foutaiz  wrote:
> You can take a look at the IPC::Cmd module that should remove some pain when
> dealing with system commands through Perl.
>
>  https://metacpan.org/pod/IPC::Cmd
>
>
> On Thu, May 15, 2014 at 3:10 PM, Chris Knipe  wrote:
>>
>> Hi All,
>>
>> I'm having a bit of a strange issue executing a system command through
>> perl.
>> The system command reads a bunch of parameters through STDIN, and responds
>> via STDOUT.  The problem is that special commands (notably the "#" and "!"
>> character.  Perl itself, escapes the characters correctly (as indicated
>> through the print $RADCommand code), but the command once executed through
>> the shell, but from there it goes pear shaped once the system executes the
>> command..
>>
>> A quick example:
>> use Data::Dumper;
>> use strict;
>> use warnings;
>> my $AuthName = "user\@domain.com";
>> my $AuthPass = "!\@#bsay0nd";
>> my $ClientIP = "10.0.0.3";
>> my $RADCommand = "/bin/echo -e ";
>> $RADCommand .= "Called-Station-Id = x.x.x.42, ";
>> $RADCommand .= "Calling-Station-Id = " . $ClientIP . ", ";
>> $RADCommand .= "Login-Service = Telnet, ";
>> $RADCommand .= "Login-TCP-Port = 119, ";
>> $RADCommand .= "NAS-IP-Address = 10.255.255.245, ";
>> $RADCommand .= "NAS-Port-Type = Virtual, ";
>> $RADCommand .= "Service-Type = Authenticate-Only, ";
>> $RADCommand .= "User-Name = " . $AuthName . ", ";
>> $RADCommand .= "User-Password = " . $AuthPass . " ";
>> $RADCommand .= "| /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
>> quaap5hooZae4ahNguehusieg0Oiph1u";
>> my @RADResult = qx($RADCommand);
>> print $RADCommand . "\n";
>> print Dumper(@RADResult);
>>
>> The output of the above code is correct:
>> /bin/echo -e Called-Station-Id = 85.12.8.42, Calling-Station-Id =
>> 198.19.255.3, Login-Service = Telnet, Login-TCP-Port = 119, NAS-IP-Address
>> =
>> 10.255.255.245, NAS-Port-Type = Virtual, Service-Type = Authenticate-Only,
>> User-Name = gar...@beyondonline.co.za, User-Password = !@#Bey0nd |
>> /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
>> quaap5hooZae4ahNguehusieg0Oiph1u
>> $VAR1 = 'Received response ID 198, code 3, length = 55
>> ';
>> $VAR2 = '   Reply-Message = "NOK:Authentication failed"
>> ';
>>
>> However, once executing the command, the RADIUS server receives the
>> incorrect string for the password:
>> Thu May 15 09:57:46 2014
>> Packet-Type = Access-Request
>> Called-Station-Id = "x.x.x.42"
>> Calling-Station-Id = "10.0.0.3"
>> Login-Service = Telnet
>> Login-TCP-Port = 119
>> NAS-IP-Address = 10.255.255.245
>> NAS-Port-Type = Virtual
>> Service-Type = Authenticate-Only
>> User-Name = " u...@domain.com"
>> User-Password = "!@"
>> Realm = "DEFAULT"
>>
>> The problem is a shell problem rather than a perl problem, I do know that
>> much.  Nevermind what I do or where I put quotes / escape strings, I
>> cannot
>> get bash to execute the echo statement.
>>
>> Can anyone shed some light on this subject perhaps?  I know it's more than
>> likely a little bit off topic, but I would appreciate the assistance.
>>
>> --
>> Chris.
>>
>>
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>



-- 

Regards,
Chris Knipe

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




question on escaping shell command

2014-05-15 Thread Chris Knipe
Hi All,

I'm having a bit of a strange issue executing a system command through perl.
The system command reads a bunch of parameters through STDIN, and responds
via STDOUT.  The problem is that special commands (notably the "#" and "!"
character.  Perl itself, escapes the characters correctly (as indicated
through the print $RADCommand code), but the command once executed through
the shell, but from there it goes pear shaped once the system executes the
command.. 

A quick example:
use Data::Dumper;
use strict;
use warnings;
my $AuthName = "user\@domain.com";
my $AuthPass = "!\@#bsay0nd";
my $ClientIP = "10.0.0.3";
my $RADCommand = "/bin/echo -e ";
$RADCommand .= "Called-Station-Id = x.x.x.42, ";
$RADCommand .= "Calling-Station-Id = " . $ClientIP . ", ";
$RADCommand .= "Login-Service = Telnet, ";
$RADCommand .= "Login-TCP-Port = 119, ";
$RADCommand .= "NAS-IP-Address = 10.255.255.245, ";
$RADCommand .= "NAS-Port-Type = Virtual, ";
$RADCommand .= "Service-Type = Authenticate-Only, ";
$RADCommand .= "User-Name = " . $AuthName . ", ";
$RADCommand .= "User-Password = " . $AuthPass . " ";
$RADCommand .= "| /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
quaap5hooZae4ahNguehusieg0Oiph1u";
my @RADResult = qx($RADCommand);
print $RADCommand . "\n";
print Dumper(@RADResult);

The output of the above code is correct:
/bin/echo -e Called-Station-Id = 85.12.8.42, Calling-Station-Id =
198.19.255.3, Login-Service = Telnet, Login-TCP-Port = 119, NAS-IP-Address =
10.255.255.245, NAS-Port-Type = Virtual, Service-Type = Authenticate-Only,
User-Name = gar...@beyondonline.co.za, User-Password = !@#Bey0nd |
/usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
quaap5hooZae4ahNguehusieg0Oiph1u
$VAR1 = 'Received response ID 198, code 3, length = 55
';
$VAR2 = '   Reply-Message = "NOK:Authentication failed"
';

However, once executing the command, the RADIUS server receives the
incorrect string for the password:
Thu May 15 09:57:46 2014
Packet-Type = Access-Request
Called-Station-Id = "x.x.x.42"
Calling-Station-Id = "10.0.0.3"
Login-Service = Telnet
Login-TCP-Port = 119
NAS-IP-Address = 10.255.255.245
NAS-Port-Type = Virtual
Service-Type = Authenticate-Only
User-Name = " u...@domain.com"
User-Password = "!@"
Realm = "DEFAULT"

The problem is a shell problem rather than a perl problem, I do know that
much.  Nevermind what I do or where I put quotes / escape strings, I cannot
get bash to execute the echo statement.

Can anyone shed some light on this subject perhaps?  I know it's more than
likely a little bit off topic, but I would appreciate the assistance.

--
Chris.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Net::Server and SSLEAY issues

2014-02-22 Thread Chris Knipe
Hi all,

I'm attempting to do a very simple Net::Server listening on two different
ports, one being TCP and one being SSLEAY.  So far this is working, but as
soon as I make an normal unencrypted connection (telnet) to the SSLEAY port
and *disconnect*, the Net::Server goes into an infinite loop, passing
process_request() over and over.  This only happens when the non-encrypted
client (telnet), disconnects from the encrypted socket - testing with
openssl s_client, it does work as expected and disconnects / closes the
fork.

STDERR returns Received [] until the Net::Server is forcefully killed.  It's
as if Net::Server doesn't detect that the client has disconnected (which is
more than likely precisely what it is).

Relavent code bits:

sub process_request {
  my $self = shift;
  eval {
local $SIG{ALRM} = sub { die "Timed Out!\n"; };
my $timeout = 30;
my $previous_alarm = alarm($timeout);
while () {
  s/\r?\n$//;
  print STDERR "Received [$_]\n";
  print "$_\n";
  last if /quit/i;
  alarm($timeout);
}
alarm($previous_alarm);
  };

  if ($@=~/timed out/i) {
print STDERR "Timed out.\n";
return;
  }
}

Server->run(port  => ["2020/tcp", "2021/ssleay"],   # The
TCP port that we are listening on
setsid=> "0",   #
Run the application in the background
SSL_key_file  => "/home/cknipe/src/server.key",  #
SSL Private Key
SSL_cert_file => "/home/cknipe/src/server.crt",  #
SSL Public Certificate
);

Would appreciate it if anyone can perhaps shed some light for me.

Thanks,
Chris.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




issue with threaded IO::Socket::INET

2013-05-19 Thread Chris Knipe
Hi All,

I have an issue with a small piece of code.  I am using IO::Socket::INET to
accept client connections from an socket, and then hand the connection off
to an newly created thread.  As soon as an client disconnects (or interrupts
the tcp session), the script will exit completely.  No errors, and the
application doesn't exist the while loop either (the print after the loop
isn't executed).  It almost seems that the main thread is killed?

my $Queue :shared;  # Shared reference to our Queued
work
my $num_of_threads = 2; # Maximum number of threads to start
my @Threads;# An array holding an reference to
our threads
my $SocketAddress = "198.19.255.11";
my $SocketPort = 2000;

# This is the main threads serving the socket connections
sub ProcessClient {
  my ($Client,$Queue) = @_;
  while ($Client) {
my $MessageID = <$Client>;
if ($MessageID && length($MessageID) > 8) {
  $MessageID =~ s/\r?\n$//;
  my $Result = $Queue->enqueue_and_wait($MessageID);
  my ($Content) = @$Result;
  print $Client $Content;
} else {
  print $Client "Invalid Message-ID\n.\n";
}
  }
}

# This is the main threads fetching
sub ThreadWorking {
  my ($Queue) = @_;
  print "Starting Fetcher Thread: " . $$ . "." . threads->tid . "\n";
  ... code ommited ...
}

### Main Processing Section
# Flush buffers after ever write, and setup some other parameters
$| = 1;
select(STDOUT);
setpriority (0,0,20);

# Start the main queue and threads
$Queue = Thread::Queue::Duplex->new(ListenerRequired => 0,
MaxPending   => 1024);
for my $Count (1 .. $num_of_threads) {
  my $QueueWorker = threads->create(\&ThreadWorking, $Queue);
  $QueueWorker->detach();
  push (@Threads, $QueueWorker);
}

print "Waiting for Queue Listeners to become ready...\n";
$Queue->wait_for_listener();
sleep(5);

# Start our main listening socket
my $Socket = IO::Socket::INET->new(LocalAddress => $SocketAddress,
   LocalPort=> $SocketPort,
   Proto=> "tcp",
   Type => SOCK_STREAM,
   Listen   => SOMAXCONN,
   ReuseAddr=> 1) or die "Can't create
listen socket: $!";
$Socket->autoflush(1);
while (1) {
  my $Client;
  do {
$Client = $Socket->accept();
$Client->autoflush(1);
  } until (defined($Client));
  my $ClientThread = threads->create(\&ProcessClient, $Client,
$Queue)->detach;
  push (@Threads, $ClientThread);
  print "Connection received from " . $Client->peerhost() . ":" .
$Client->peerport() . "\n";
}
print "exited while loop\n";


Output:
root@netty:/opt/bin# ./threads 
Starting Fetcher Thread: 17963.1
Waiting for Queue Listeners to become ready...
Starting Fetcher Thread: 17963.2
OK:  Tread: 17963.001, Time: 1.212, Ready to work
OK:  Tread: 17963.002, Time: 1.210, Ready to work
Connection received from 198.19.255.3:37991
root@NNTPWEB01:/srv/nntp/bin#

I've tried various ways to do the while loop, but pretty much everything is
showing the same results, which is why I'm thinking more towards that
there's an threading issue... 

I would appreciate any assistance.

--
Chris.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Battling with threaded TCP server

2013-05-18 Thread Chris Knipe
Hi,

I am looking for assistance in programing an TCP Socket server. Effectively,
I am looking for a skeleton to do the following:

- Server starts up, and starts x amounts of threads (working)
- All threads connects to an remote server via TCP and idles, keeping
the connections alive (working)
- Server starts an listening socket using IO::Socket::INET (working)
- Server forks (non-blocking) when an client connects (working)
- Client must now give an command, and that command must be passed to
the thread queues, to be executed by the thread pool as threads becomes
available *whilst the client waits on the socket*.
- The thread will respond with content to the client via the socket
- Client quits

The threads implementation is based on Jerry Hedden's example of thread
pooling (
http://cpansearch.perl.org/src/JDHEDDEN/threads-1.86/examples/pool_reuse.pl
).  The code via term does -exactly- what I require, and I've had no issues
what so ever to amend and change this to work as I require it to do over
term.  However, I am having significant issues combining this with a socket.
I am absolutely sure however that this is something that I am doing wrong,
more than likely, the entire application needs to be threaded and therefore
re-written from scratch.

The basic theory is that there will be x amount of sleeping threads, and the
socket will receive more connections than what there is threads.  The entire
application thus pools connections to retrieve content from remote servers.

My IO::Socket::INET has successfully started and is listening, and I fork
using
  print "Server waiting for connections\n";
  my $Client;
  while ($Client = $Socket->accept()) {
my $pid;
while (not defined ($pid = fork())) {
  sleep 0.5;
}
if ($pid) {
  close($Client);
} else {
  $Client->autoflush(1);
  close $Socket;
  &DoClientSocket();

And following Jerry's example code, the threads work by (this is what the
client socket would need to execute as far as I can see):
# Work loop
do {
# Indicate that were are ready to do work
printf("Idle -> %2d\n", $tid);
$IDLE_QUEUE->enqueue($tid);

# Wait for work from the queue
my $work = $work_q->dequeue();

# If no more work, exit
last if ($work < 0);

# Do some work while monitoring $TERM
printf("%2d <- Working\n", $tid);
while (($work > 0) && ! $TERM) {
$work -= sleep($work);
}

# Loop back to idle state if not told to terminate
} while (! $TERM);

But I am really at a loss as to how to integrate the two.  The sub used by
IO::Socket::INET (even if passing the variables and hash refs as parameters,
i.e. &ClientSocket(\%work_queues, $tid)) does not successfully pass any work
to the thread pool, and the thread pool also seems to be 'idling' rather
than checking and processing work given to it. I believe this is because
IO::Socket::INET waits for client connections, and does not give the thread
pool time to look for and do it's queued work as well.

Can anyone please assist a semi newbie?  I need this to work relatively
urgently and I would prefer to rather take this off list and spend half an
hour or an hour with an individual able to assist (just don't want to sit
here spamming the lists).  At this stage, I'm even willing to pay if that's
what it needs to come down to...

Many thanks,
Chris.




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




IO::Socket::SSL replacement for IO::Socket::INET

2013-04-08 Thread Chris Knipe
Hi All,

I've successfully written quite an big perl server using IO::Socket::INET -
it seems to be working pretty darn good and so far I'm happy.

I'm attempting now to do the same but by using SSL.  I've read up on
IO::Socket::SSL, and I know that there are minor changes required in terms
of how the socket is created.  I've made those changes, my socket is
successfully created, but when I connect, the server is unable to fork...
The error is blank as well - which is of course helping me allot to
determine what is going wrong...

Can someone possibly shed some light for me on this?

Here's the socket and forking code:
# Open socket and listen for new connections
my $Port563 = IO::Socket::SSL->new(LocalAddr   => "198.19.255.11",
   LocalPort   => "563", 
   Proto   => "TCP", 
   Reuse   => 1,
   Listen  => 128,
   SSL_cert_file   =>
"/srv/nntp/etc/cert.pem",
   SSL_key_file=>
"/srv/nntp/etc/key.pem",
   SSL_verify_mode => 0x01);
if (!$Port563) {
  SysLog('err', 'Server failed to start: ' . $@);
  die "Failed to create listening socket: " . $@ . "\n";
} else {
  binmode $Port563 => ":encoding(utf8)";
  SysLog('info', 'Server started: ' . $Port563->sockhost() . ':' .
$Port563->sockport());
}

# Drop privileges to normal user
drop_privileges('news');

# Wait for client connection and spawn new child
while (my $ClientSocket = $Port563->accept()) {
  my $Child;
  SysLog('err', 'Server failed to fork: ' . $!);
  die "Can't fork: $!" unless defined ($Child = fork());# Script errors
here.  $! contains empty string
  if ($Child == 0) {
$Port563->close;
&ClientConnection($ClientSocket);
undef $Childs{$Child};
exit 0;
  } else {
$Childs{$Child} = 1;
$ClientSocket->close();
  }
}


--
Chris.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: am I missing something?

2013-03-03 Thread Chris Knipe
Hi,

Was an issue somewhere else in my code.  Been using an $counter to keep
track of the records and I executed next without incrementing the counter.

Sorry guys :)



On Sun, Mar 3, 2013 at 11:43 AM,  wrote:

>
>
> -Original Message----- From: Chris Knipe
>
>> my @array = (1..10);
>> foreach my $number (@array) {
>>   next if $number == 5;
>>   print $number;
>> }
>>
>
> I can't reproduce the problem.
> Works as expected for me, and outputs:
> 1234678910
>
> Cheers,
> Rob
>



-- 

Regards,
Chris Knipe


am I missing something?

2013-03-03 Thread Chris Knipe
Hi All,

my @array = (1..10);
foreach my $number (@array) {
  next if $number == 5;
  print $number;
}

When $number == 5, perl exits the foreach loop completely, instead of
skipping the record and going to the next record in the array.

I am obviously missing something here, but it seems to me that 'next' is
behaving like 'last' in this example.   What would be the correct way to do
this?

--
Chris.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Net::NNTP inconsistent article retrieval

2012-08-12 Thread Chris Knipe
So just a quick test using the exact same command issues to the server, and
reading the exact same response...

Perl with Net::NNTP (Net::Cmd) reads 262,144 Bytes  (incomplete article with
corruption on encoded parts)
C# .NET via an Socket reads 393,216 Bytes (complete article without any
corruption)

I've submitted an bug for Net::Cmd.  The difference is quite substantial,
and even between all the encoded content, you can visibly see where
characters are removed by Perl that should not be...

--
Chris.


-Original Message-
From: Chris Knipe [mailto:sav...@savage.za.org] 
Sent: 12 August 2012 10:26
To: 'Paul Anderson'
Cc: beginners@perl.org
Subject: RE: Net::NNTP inconsistent article retrieval

Hi Paul,

I think I've narrowed the issue to Net::Cmd itself (read_untill_dot() used
by Net::SNMP).  Even if we completely forget about writing the file to disk:
print "220 0 " . $Command['1'] . "\r\n";
print @{$Article};
print ".\r\n";

@{$Article} still only prints \n and not \r\n.

When I look at Net::Cmd  getline() around line 301

  my @buf = split(/\015?\012/, $buf, -1);## break into lines
  $partial = pop @buf;
  push(@{${*$cmd}{'net_cmd_lines'}}, map {"$_\n"} @buf);  

Isn't this exactly where my issue is coming from?  The map should (in my
case) be using \r\n?  I changed  this quickly just as a test, and my lines
are now terminated correctly with \r\n as I desire, but obviously this has
now broken ALLOT of other things that uses Net::Cmd...  Short of using my
own sockets (which I really don't want to do), would there be a way to
change this behaviour of Net::Cmd without having to change the module's
code?  I don't see any options o such for it.

--
Chris.




-Original Message-
From: Paul Anderson [mailto:wackyvor...@me.com] 
Sent: 12 August 2012 08:04
To: Chris Knipe
Cc: beginners@perl.org
Subject: Re: Net::NNTP inconsistent article retrieval

>From here:

http://perldoc.perl.org/utf8.html

I wonder if utf8::upgrade() might do the trick. With write_file() in
File::Slurp, passing it a hash with binmode set to :utf8 will get it to
write UTF8 output to disk. Perl has in general very good internal UTF
support. 

An aside: You know that leafnode basically does everything you're trying to
write, right?


Paul Anderson -- VE3HOP

On 2012-08-11, at 5:21 PM, Chris Knipe  wrote:

> Hi Paul,
> 
> I will be inclined to disagree - it depends on whether or not the content
> was encoded to begin with (perhaps I should not use the term 'binary' as
> such, but rather refer to it as unreadable characters).  File::Slurp did
> make my life allot easier now yes, but my problem is still not solved.
> Looking at the packet capture, it is as clear as daylight to me that
either
> Net::NNTP or File::Slurp is replacing all \r\n line breaks with \n.  The
> NNTP RFCs require all lines to be terminated by \r\n.  I can't simply use
a
> regex to replace all instances of \n to \r\n as it will affect the
> attachments (binary or not, encoded or not).  I've attached an screen
> capture out of Wireshark for a single packet (available at
> http://www.savage.za.org/capture.png as well) which is showing my problem
as
> clearly as daylight.
> 
> Line 1: 220 0 \r\nThis is sent by my application, and it
is
> properly terminated as required.
> Line 2 through to 15 original headers as received by my upstream news
> server.  The lines WAS previously terminated with \r\n but either
Net::NNTP
> or File::Slurp, changed all the \r\n values to \n
> Line 18 through to next packet is definitely not text anymore, and neither
> is it terminated by \r\n anymore as it was previously... 
> 
> I am not trying to process, alter, or extract articles in any way, I
simply
> want to download them, store them, and forward them... 
> 
> --
> Chris.
> 
> 
> 
> -Original Message-
> From: Paul Anderson [mailto:wackyvor...@me.com] 
> Sent: 11 August 2012 18:17
> To: Chris Knipe
> Cc: beginners@perl.org
> Subject: Re: Net::NNTP inconsistent article retrieval
> 
> Umm... Are you aware that binary attachments on usenet aren't actually
*in*
> binary? They're encoded in ASCII using one of a number of different
methods.
> They're just text, until decoded on the receiving end. 
> 
> I recommend looking into File::Slurp and CHI. CHI basically implements the
> entire caching back-end for you. 
> 
> Sent from my iPhone
> 
> On 2012-08-11, at 5:21 AM, Chris Knipe  wrote:
> 
>> Hi All,
>> 
>> I'm using Net::NNTP to transfer articles from servers.  My aim is to
write
>> an NNTP proxy.
>> 
>> I obtain the article from my parent news server, write the file to disk,
> 

RE: Net::NNTP inconsistent article retrieval

2012-08-12 Thread Chris Knipe
Hi Paul,

I think I've narrowed the issue to Net::Cmd itself (read_untill_dot() used
by Net::SNMP).  Even if we completely forget about writing the file to disk:
print "220 0 " . $Command['1'] . "\r\n";
print @{$Article};
print ".\r\n";

@{$Article} still only prints \n and not \r\n.

When I look at Net::Cmd  getline() around line 301

  my @buf = split(/\015?\012/, $buf, -1);## break into lines
  $partial = pop @buf;
  push(@{${*$cmd}{'net_cmd_lines'}}, map {"$_\n"} @buf);  

Isn't this exactly where my issue is coming from?  The map should (in my
case) be using \r\n?  I changed  this quickly just as a test, and my lines
are now terminated correctly with \r\n as I desire, but obviously this has
now broken ALLOT of other things that uses Net::Cmd...  Short of using my
own sockets (which I really don't want to do), would there be a way to
change this behaviour of Net::Cmd without having to change the module's
code?  I don't see any options o such for it.

--
Chris.




-Original Message-
From: Paul Anderson [mailto:wackyvor...@me.com] 
Sent: 12 August 2012 08:04
To: Chris Knipe
Cc: beginners@perl.org
Subject: Re: Net::NNTP inconsistent article retrieval

>From here:

http://perldoc.perl.org/utf8.html

I wonder if utf8::upgrade() might do the trick. With write_file() in
File::Slurp, passing it a hash with binmode set to :utf8 will get it to
write UTF8 output to disk. Perl has in general very good internal UTF
support. 

An aside: You know that leafnode basically does everything you're trying to
write, right?


Paul Anderson -- VE3HOP

On 2012-08-11, at 5:21 PM, Chris Knipe  wrote:

> Hi Paul,
> 
> I will be inclined to disagree - it depends on whether or not the content
> was encoded to begin with (perhaps I should not use the term 'binary' as
> such, but rather refer to it as unreadable characters).  File::Slurp did
> make my life allot easier now yes, but my problem is still not solved.
> Looking at the packet capture, it is as clear as daylight to me that
either
> Net::NNTP or File::Slurp is replacing all \r\n line breaks with \n.  The
> NNTP RFCs require all lines to be terminated by \r\n.  I can't simply use
a
> regex to replace all instances of \n to \r\n as it will affect the
> attachments (binary or not, encoded or not).  I've attached an screen
> capture out of Wireshark for a single packet (available at
> http://www.savage.za.org/capture.png as well) which is showing my problem
as
> clearly as daylight.
> 
> Line 1: 220 0 \r\nThis is sent by my application, and it
is
> properly terminated as required.
> Line 2 through to 15 original headers as received by my upstream news
> server.  The lines WAS previously terminated with \r\n but either
Net::NNTP
> or File::Slurp, changed all the \r\n values to \n
> Line 18 through to next packet is definitely not text anymore, and neither
> is it terminated by \r\n anymore as it was previously... 
> 
> I am not trying to process, alter, or extract articles in any way, I
simply
> want to download them, store them, and forward them... 
> 
> --
> Chris.
> 
> 
> 
> -Original Message-
> From: Paul Anderson [mailto:wackyvor...@me.com] 
> Sent: 11 August 2012 18:17
> To: Chris Knipe
> Cc: beginners@perl.org
> Subject: Re: Net::NNTP inconsistent article retrieval
> 
> Umm... Are you aware that binary attachments on usenet aren't actually
*in*
> binary? They're encoded in ASCII using one of a number of different
methods.
> They're just text, until decoded on the receiving end. 
> 
> I recommend looking into File::Slurp and CHI. CHI basically implements the
> entire caching back-end for you. 
> 
> Sent from my iPhone
> 
> On 2012-08-11, at 5:21 AM, Chris Knipe  wrote:
> 
>> Hi All,
>> 
>> I'm using Net::NNTP to transfer articles from servers.  My aim is to
write
>> an NNTP proxy.
>> 
>> I obtain the article from my parent news server, write the file to disk,
> and
>> serve the current, as well as future requests for that article from the
>> local file on the disk.  My results are very inconsistent, and I suspect
>> that it is related to the \r\n line breaks conflicting with the binary
> data
>> retrieved from the article (a line may include \r\n when it's not
actually
>> meant to indicate the END of a line).  I am currently using:
>> 
>> local $/ = "\r\n";
>> my $Article = $nntp->article($Command['1']);
>> if ($Article) {
>>   # The parent has the article!  Let's take it.
>>   open FILE, ">:raw", $File or die $!;
>> 

Net::NNTP inconsistent article retrieval

2012-08-11 Thread Chris Knipe
Hi All,

I'm using Net::NNTP to transfer articles from servers.  My aim is to write
an NNTP proxy.

I obtain the article from my parent news server, write the file to disk, and
serve the current, as well as future requests for that article from the
local file on the disk.  My results are very inconsistent, and I suspect
that it is related to the \r\n line breaks conflicting with the binary data
retrieved from the article (a line may include \r\n when it's not actually
meant to indicate the END of a line).  I am currently using:

  local $/ = "\r\n";
  my $Article = $nntp->article($Command['1']);
  if ($Article) {
# The parent has the article!  Let's take it.
open FILE, ">:raw", $File or die $!;
binmode(FILE);
foreach my $line (@$Article) {
  print FILE $line;
}
close(FILE);
$ReturnStr = "220 0 " . $Command['1'] . "\r\n";
open FILE, "<:raw", $File;
binmode(FILE);
foreach my $line () {
  $ReturnStr .= $line;
}
close(FILE);
$ReturnStr .= ".\r\n";
binmode(STDOUT);
print $ReturnStr;

For some articles, the above code is absolutely fine and no problems are
returned.  For others, the binary attachments to the article (regardless of
type of file), is corrupt, and cannot be opened.   The results are also very
inconsistent, and being binary I'm not exactly sure how to provide samples
of what works and what doesn't.  I've analysed packet captures excessively,
and I am definitely getting all the data correctly, and consistently from my
parent news server - the problem is related to me writing the file to the
local disk, and serving the content of that file from the local disk.

Hopefully someone can assist and point me towards the right direction -
after spending close to a week on this, I'm ready to pull out my hair! :-(
--
Chris.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




trying to match non ascii chars

2011-06-17 Thread Chris Knipe
Hi,

 

I have  bit of  problem with  transparent squid service.  When people tries
to send binary data through squid, the log files naturally doesn't like it
very much.  A sample of such an log file entry:

 

1308293915.456  0 client.host.name NONE/400 3660
[<92>i<8F>>^]^D^N<9F>?[y<81>'4/^<92>kI${
b<8B>o^S %87)d%B8%5B%F6W%A2$%5C - NONE/- text/html

 

I am trying to write  perl regex to skip lines containing these characters,
but I'm not having too much success:

 

while (<>) {

  chomp($_);

  if ($_ =~ s/[\t\n\r\f\a\e\cK]//g) {

next;

  } else {

print $_ . "\n";

  }

}

 

Does anyone perhaps have some insight for me? 

 

Regards,

Chris.

 



Re: PERL MYSQL query "IF EXISTS then UPDATE else INSERT"

2010-10-20 Thread Chris Knipe
Just use SQL?

INSERT INTO tbl, VALUES ('11','22','33') ON DUPLICATE KEY 

http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html



On Wed, Oct 20, 2010 at 9:23 AM, Uri Guttman  wrote:

> >>>>> "SPS" == S Pratap Singh  writes:
>
>
>  SPS> Insert query works fine but I am not able to figure out how to
>  SPS> achieve this "IF EXISTS then UPDATE else INSERT" using a one
>  SPS> liner MYSQL statement . If someone can give me an example to
>  SPS> write such query and execute it from perl then it would be really
>  SPS> appreciated.
>
> that is an sql question that has nothing to do with perl. please ask it
> in an sql forum. the answer that i know is that you can't do it in basic
> sql.
>
> uri
>
> --
> Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com--
> -  Perl Code Review , Architecture, Development, Training, Support
> --
> -  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com-
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 

Regards,
Chris Knipe


quick question

2010-03-19 Thread Chris Knipe
Hi,

I was just wondering, when we talk about integers specifically, what's the
difference between:
my $foo = 1;
my $bar = 1;

and

my ($foo, $bar) = 1

I am getting more and more occurances where when I use the later as above,
$bar would not have a defined value...  I'm not quite sure I understand why.

-- 

Regards,
Chris Knipe


Radius Client modules

2009-04-01 Thread Chris Knipe

Hi,

I've been looking at a few Radius modules to use in some applications.  I
need my perl scripts to send either a COA or Disconnect message to my NAS
devices.

Every radius client for perl I've looked at though, does not seem to support
COA or Disconnects.

Is there anything that anyone can recommend perhaps instead of using exec()
to call radclient ?

Many thanks,
Chris.




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: quick regex question

2009-01-09 Thread Chris Knipe
> >
> > # INTERFACE
> > RADIO-NAME   MAC-ADDRESS   AP  SIGNAL-STRENGTH TX-RATE UPTIME
> >  0 interface_name  radio
> > 00:0C:42:1F:2C:8D yes -63...@18mbps   9Mbps   2h2m38s
> >
> > I'm looking for a 
> > foreach my $Line (@Output) {
> >   my ($interface, $radio, $mac, $ap, $signal, $txrate, uptime) =
> > split(/whatidontknow/, $Line, 7);
> > }
> >
> > Can anyone perhaps help out with the what I don't know bit??   FYI - The
> > columns should be fixed lengths, if that helps perhaps... 
> >   
>
> Hi.
> Could maybe a simple split(/\s+/ $Line, 7); work?

Almost, but we're not *quite* there yet... It will do though, I think
(Really just need to get $interface name and $signal)... 

  foreach my $Line (@Output) {
my ($tmp, $number, $interface, $radio, $mac, $ap, $signal, $txrate,
$uptime) = split(/\s+/, $Line, 9);
print "Number:" . $number . "\n";
print "Interface: " . $interface . "\n";
print "Radio: " . $radio . "\n";
print "MAC:   " . $mac . "\n";
print "AP:" . $ap . "\n";
print "Signal:" . $signal . "\n";
print "TX Rate:   " . $txrate . "\n";
print "Uptime:" . $uptime . "\n";

  }

Number:0
Interface: interface_name
Radio: radio
MAC:   00:0C:42:1F:2C:8D
AP:yes
Signal:-63dBm...
TX Rate:   24Mbps
Uptime:

I'm not sure why I am required to have 9 fields in the split to get the
values now... 

--
Chris.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




quick regex question

2009-01-09 Thread Chris Knipe
Hi,

I have two lines (well, 1 line is headers, then there follows a range of
data)... 

# INTERFACE
RADIO-NAME   MAC-ADDRESS   AP  SIGNAL-STRENGTH TX-RATE UPTIME
 0 interface_name  radio
00:0C:42:1F:2C:8D yes -63...@18mbps   9Mbps   2h2m38s

I'm looking for a 
foreach my $Line (@Output) {
  my ($interface, $radio, $mac, $ap, $signal, $txrate, uptime) =
split(/whatidontknow/, $Line, 7);
}

Can anyone perhaps help out with the what I don't know bit??   FYI - The
columns should be fixed lengths, if that helps perhaps... 

Thanks,
Chris.





-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Radius CPAN Modules

2006-02-20 Thread Chris Knipe
Hi,
 
Is there any modules that supports Radius Disconnect type messages
(RFC3576).  Spend some extensive time going through what's available on
CPAN, but I haven't found anything that supports Disconnect Messages 
 
Did I miss anything, or is radclient my only option?? :(
 
Thanks,
Chris
 


Re: Moving up, processes & threads

2006-01-30 Thread Chris Knipe

IPC::Shareable - share Perl variables between processes


IPC! That's what we used :)  Thanks,

--
Chris.



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




Re: Moving up, processes & threads

2006-01-30 Thread Chris Knipe
Last time I checked, perl's threads wasn't very popular to use.  Now 
that's

a discussion on it's own I guess, and not the intensions of this email to
get into.  I'm planning to develop a rather large perl application.  Due 
to

complexity, I plan to run multiple processes, each process being spawned
from a single main process...  Is there any way that I can share data
between them?


Lots of ways. Here's one that's worked for me. The shared data live in
some convenient location, like a directory, a file, or a database,
depending upon your needs. A little glue code in a module handles
access to the data in a consistent way, maybe using something from the
Tie::* hierarchy to provide a simple interface.


Hi,

Thanks for the suggestion.  This has been recommended to me by someone off 
the list as well (or something relatively close to it), and unfortunately is 
not going to be very efficient.  It's going to kill the system as far as 
disk IO is concerned.  I'm talking about 200+ variables here, about half of 
which will change approximately every 10ms (some even less).  Doing 100 odd 
disk writes/reads every 10ms, plus more than likely searching through open 
files for a specific variable, and closing it in time so that it can be 
written again... Don't think it will be feasable.


I'll need to do this in memory I'm afraid... :(

--
Chris




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




Moving up, processes & threads

2006-01-30 Thread Chris Knipe

Hi,

Last time I checked, perl's threads wasn't very popular to use.  Now that's 
a discussion on it's own I guess, and not the intensions of this email to 
get into.  I'm planning to develop a rather large perl application.  Due to 
complexity, I plan to run multiple processes, each process being spawned 
from a single main process...  Is there any way that I can share data 
between them?


Say, uhm...
Main_Proc.pl
 Sub_Proc1.pl - $var = blah
 Sub_Proc2.pl - I want to use $var

The main thing is that they are all running on their own perl interpreter. 
I therefore don't believe that it would be so easy to do.  On the other 
hand, I've seen this being done before on some really large perl 
applications we used - unfortunately, I was not part of the development 
group, so I don't know how / what they did.


In VB for example, I would just use a single class that is shared between 
multiple threads.  Each thread can then for example set or alter any 
variable inside the class, and the change would reflect obviously on the 
other threads utilising that class.  But - that's threads, not processes. 
Can something similar be used in Perl?  Say, multiple processes using the 
same module perhaps?


Is there perhaps somewhere I can read up on things like this with some good 
examples and documentation?


Thanks,
Chris



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




Getopt::Long

2005-11-07 Thread Chris Knipe
Hi all,
 
Just a quick question and a couple of lines of really simple code 
 
use Getopt::Long;
 
...
 
GetOptions ('h'   => \$h,
'b=s' => \$s );

Sub ShowHelp() {
  print "this is help"
}

Sub DoSomethingWithString() {
...
}

If ($s) {
  DoSomethingWithString();
} else {
  ShowHelp();
}
 
Right.  Now, whilst the above is not perhaps 100% correct, it goes about a
generality of Getopt::Long.

If I now run the application,
./blah.pl -h   - I get the help screen
./blah.pl -s   - I get a error, complaining that -s requires a value, and
THEN the help screen.
./blah.pl -s s - Everything is fine.

So, this is more of a block question I think, but how I can get the above
example to show the help screen FIRST, and THEN complain about the missing
value for -s 

Thanks,
 
 
--
Regards,
Chris.
 


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




Cvs.pm

2005-08-26 Thread Chris Knipe

Just a quickie...

I'm trying to get to use Cvs.pm... I'm BATTLING.

For one, the documentation, indicates that errors is reported by 
$Cvs::ERROR.


$Cvs::ERROR, does not even exist in the module

Does anyone have some info on how I could get some DECENT code working with 
this module??  After creating my I can't even detect a incorrect login...



my $cvs = new Cvs ('/tmp', cvsroot="blah", password='blah') or die 
$Cvs::ERROR; ## Which is COMPLETELY wrong, but anyways.


I give it a incorrect login, and well yeah, it does not even pick this 
up


Is this module working at all?  Anything else that can be suggested for CVS 
access / manupilation in perl?


Thanks,
Chris. 




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




Cvs.pm

2005-08-26 Thread Chris Knipe
Just a quickie...

I'm trying to get to use Cvs.pm... I'm BATTLING.

For one, the documentation, indicates that errors is reported by 
$Cvs::ERROR.

$Cvs::ERROR, does not even exist in the module

Does anyone have some info on how I could get some DECENT code working with 
this module??  After creating my I can't even detect a incorrect login...


my $cvs = new Cvs ('/tmp', cvsroot="blah", password='blah') or die 
$Cvs::ERROR; ## Which is COMPLETELY wrong, but anyways.

I give it a incorrect login, and well yeah, it does not even pick this 
up

Is this module working at all?  Anything else that can be suggested for CVS 
access / manupilation in perl?

Thanks,
Chris. 


freebsd / ifconfig

2005-05-23 Thread Chris Knipe

Hi,

Is there any modules available to manipulate devices (similar to ifconfig) 
in perl?  Basically, I need to give it a IP address, it must find out what 
interface the IP belogs to, and what pid opened the interface ???


Just thought I'd ask first, would be really sweet if something exist.

--
Chris.

I love deadlines. I especially love the whooshing sound they make as they 
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy' 



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




Re: Emulate "tail -f" on file

2005-05-19 Thread Chris Knipe
On Thu, May 19, 2005 at 11:54:35AM +0530, Ramprasad A Padmanabhan wrote:
> use File::Tail;
> 
> 
> On Thu, 2005-05-19 at 11:37, Tielman Koekemoer (TNE) wrote:
> > Hi All,
> > 
> > If I wanted to monitor a file in a way that would emulate "tail -f"
> > (in the shell), how would I open the file? 
> > 
> > open(FILE, " filename |"); (?)
> > 
> > TIA


As someone who asked the -EXACT- same question, not even a month ago,
I can really suggest the archives, and I can also really second
File::Tail - it's a BRILLIANT module.

--
Chris.


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




Re: expensive loops

2005-05-02 Thread Chris Knipe
Thanks, seems to be doing the trick :)
Very nice module indeed...
--
Chris.
I love deadlines. I especially love the whooshing sound they make as they 
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'

- Original Message - 
From: "Joshua Colson" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>
Sent: Monday, May 02, 2005 7:27 PM
Subject: Re: expensive loops


On Mon, 2005-05-02 at 19:10 +0200, Chris Knipe wrote:
Hi,
  open (LOG, '<'.LogFile);
  for (;;) {
while () {
# Do stuff here
  }
}
  }
Why don't you use the File::Tail module from CPAN?
http://search.cpan.org/~mgrabnar/File-Tail-0.99.1/Tail.pm
This is unfortunately very expensive on my CPU.  Are there any better 
ways
to go about this???  tail comes to mind, but I'd prefer to do this all in
perl.

--
Chris.
I love deadlines. I especially love the whooshing sound they make as they
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'

--
Joshua Colson <[EMAIL PROTECTED]>
Sr. Systems Administrator
Giant Industries, Inc
P: (480) 585-8714
F: (480) 502-6641


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: expensive loops

2005-05-02 Thread Chris Knipe
Because I need to do it similarly to tail.
using just the while, the loop will exit at the end of the file.  I need it 
to wait at the end of the file untill new data is appended to the end of it.

--
Chris.
I love deadlines. I especially love the whooshing sound they make as they 
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'

- Original Message - 
From: "Joshua Colson" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>
Sent: Monday, May 02, 2005 7:18 PM
Subject: Re: expensive loops


On Mon, 2005-05-02 at 19:10 +0200, Chris Knipe wrote:
Hi,
  open (LOG, '<'.LogFile);
  for (;;) {
while () {
# Do stuff here
  }
}
  }
Why wouldn't you just use:
open(LOG, "<".LogFile);
while () {
# Do stuff here
}
--
Joshua Colson <[EMAIL PROTECTED]>
Sr. Systems Administrator
Giant Industries, Inc
P: (480) 585-8714
F: (480) 502-6641


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



expensive loops

2005-05-02 Thread Chris Knipe
Hi,
 open (LOG, '<'.LogFile);
 for (;;) {
   while () {
# Do stuff here
 }
   }
 }
This is unfortunately very expensive on my CPU.  Are there any better ways 
to go about this???  tail comes to mind, but I'd prefer to do this all in 
perl.

--
Chris.
I love deadlines. I especially love the whooshing sound they make as they 
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy' 

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



slightly OT - co-ordinates

2005-04-12 Thread Chris Knipe
Lo all,

This is slightly off topic, but does anyone know how to convert hours, minutes 
seconds coordinates into decimal?

I.e. S33* 58.08, E18* 36.27'151 to the xx.x -xx.x

Doing this manually / online is out of the question unfortunately.  I have over 
20,000 to convert :(( 

Thanks



--
Chris.

I love deadlines. I especially love the whooshing sound they make as they fly 
by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'


Re: CGI.pm

2005-03-29 Thread Chris Knipe
DOH!
Something Silly(tm)
Thanks ;)
- Original Message - 
From: "Chris Devers" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>
Cc: "Perl Beginners List" 
Sent: Tuesday, March 29, 2005 9:07 PM
Subject: Re: CGI.pm


On Tue, 29 Mar 2005, Chris Knipe wrote:
if (!$Query->request_method() eq "POST") {
 exit;
}
Using a GET / HEAD method, the IF statement never executes.
Nor would it -- the exclamation point isn't in the right place.
This statement is saying "if not-$query->request_method() equals POST", 
but "not-$query..." makes no sense.

But an exclamation point is the wrong approach here. If you want to say 
that $foo should not equal $bar, use the "not equal" condition -- 'ne':

   if $Query->request_method() ne "POST" {
   exit;
   }
That should do what you want.
--
Chris Devers
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: CGI.pm

2005-03-29 Thread Chris Knipe
Ok, sorry.
This now, does not make sense AT ALL
useing == (which is wrong), matches.
useing eq (which is right?) never matches...
Surely, if I match $ENV{REQUEST_METHOD} I am matching a string value 
Why, oh why dear mighty will == match (and give me a warning), and eq never 
matches

--
Chris.
I love deadlines. I especially love the whooshing sound they make as they 
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'

- Original Message - 
From: "Chris Knipe" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, March 29, 2005 9:00 PM
Subject: Re: CGI.pm


Strange indeed.
For further debuging, I did:
print $ENV{REQUEST_METHOD};
This, as expected, returns POST.
print $Query->request-method();
NULL value.
if ($ENV{REQUEST_METHOD} eq "POST")
Does not match
Another one of those ARGH moments, or am I doing something silly?
--
Chris.

--
Chris.
I love deadlines. I especially love the whooshing sound they make as they 
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'

- Original Message - 
From: "Chris Heiland" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, March 29, 2005 8:52 PM
Subject: RE: CGI.pm



-Original Message-
From: Chris Knipe [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 29, 2005 10:45 AM
To: beginners@perl.org
Subject: CGI.pm
Lo all,
Very quickly
#!/usr/bin/perl
use CGI;
use strict;
use warnings;
my $Query = new CGI;
if (!$Query->request_method() eq "POST") {
  exit;
}
Using a GET / HEAD method, the IF statement never executes.
I am trying to verify the user agent, but the above is just
for my test - which is failing.
Anyone got some clues?
--
Chris.
I love deadlines. I especially love the whooshing sound they
make as they fly by..." - Douglas Adams, 'Hitchhiker's Guide
to the Galaxy'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Untested:
if ($query->request_method() =~ m/^post$/i) {
do something;
}
Chris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: CGI.pm

2005-03-29 Thread Chris Knipe
Strange indeed.
For further debuging, I did:
print $ENV{REQUEST_METHOD};
This, as expected, returns POST.
print $Query->request-method();
NULL value.
if ($ENV{REQUEST_METHOD} eq "POST")
Does not match
Another one of those ARGH moments, or am I doing something silly?
--
Chris.

--
Chris.
I love deadlines. I especially love the whooshing sound they make as they 
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'

- Original Message - 
From: "Chris Heiland" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, March 29, 2005 8:52 PM
Subject: RE: CGI.pm



-Original Message-
From: Chris Knipe [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 29, 2005 10:45 AM
To: beginners@perl.org
Subject: CGI.pm
Lo all,
Very quickly
#!/usr/bin/perl
use CGI;
use strict;
use warnings;
my $Query = new CGI;
if (!$Query->request_method() eq "POST") {
  exit;
}
Using a GET / HEAD method, the IF statement never executes.
I am trying to verify the user agent, but the above is just
for my test - which is failing.
Anyone got some clues?
--
Chris.
I love deadlines. I especially love the whooshing sound they
make as they fly by..." - Douglas Adams, 'Hitchhiker's Guide
to the Galaxy'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Untested:
if ($query->request_method() =~ m/^post$/i) {
do something;
}
Chris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



CGI.pm

2005-03-29 Thread Chris Knipe
Lo all,
Very quickly
#!/usr/bin/perl
use CGI;
use strict;
use warnings;
my $Query = new CGI;
if (!$Query->request_method() eq "POST") {
 exit;
}
Using a GET / HEAD method, the IF statement never executes.  I am trying to 
verify the user agent, but the above is just for my test - which is failing.

Anyone got some clues?
--
Chris.
I love deadlines. I especially love the whooshing sound they make as they 
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy' 

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



Re: hash issue

2005-03-22 Thread Chris Knipe
: Allrighty   The module is called from FreeRadius itself, so if
: there really is nothing wrong with my code (which I suspect there
: isn't), then I guess this must be moved to the FR list.  But let's
: rather make sure it's not the code first.
   To set up a test case we can assume that the while loop has started
and we are in the 'else' block which affects $RAD_REPLY{'Recv-Limit'}
and $RAD_REPLY{'Xmit-Limit'}.
   When I tested this, I found this part okay. Since %RAD_REPLY is
not accessed in this script, I don't know how you determined there
was failure.
That's correct yes.  FreeRadius has a built in perl module that process the 
hash received from the script (that I am trying to write).  I'm pretty 
confident this is a possible bug in the rlm_perl module of freeradius. 
While FR (FreeRadius) runs in debug mode, it outputs the values that is 
inside the hash.  All the values are printed back to me from FR, with the 
exception of Recv-Limit and Xmit-Limit *IF* they are not assigned from the 
variable substraction.

I'll go and moan there rather ;)   It's definately a problem in the module 
somewhere... As you said (and I concur), there really isn't anything in my 
perl code that will make this not work.

   BTW, we don't normally quote numbers in perl The
following line, for example, could be written better.
if (!$SQL->numrows == "1") {
if ( $SQL->numrows != 1 ) {

Thanks :)  I must be getting sleepy!!! I don't normally do it either.
Cheers,
Chris.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: hash issue

2005-03-22 Thread Chris Knipe
M_MODULE_UPDATED;
 }
   }
 } elsif ($GlobalDB && $RAD_REQUEST{'NAS-Port-Type'} eq "Ethernet" && 
$RAD_REQUEST{'Framed-Protocol'} eq "PPP") {
   # PPPoE
 } elsif ($GlobalDB) {
   return RLM_MODULE_NOOP;
 } else {
   return RLM_MODULE_FAIL;
 }
}

# Accounting Request
sub accounting {
 return RLM_MODULE_OK;
}
sub detach {
 &radiusd::radlog(0,"rlm_perl::Detaching. Reloading. Done.");
}
# This is xlate function wich loads some external perl and evaluate it.
sub xlat {
 my ($filename,$a,$b,$c,$d) = @_;
 &radiusd::radlog(1, "From xlat $filename ");
 &radiusd::radlog(1,"From xlat $a $b $c $d ");
 local *FH;
 open FH, $filename or die "open '$filename' $!";
 local($/) = undef;
 my $sub = ;
 close FH;
 my $eval = qq{ sub handler{ $sub;} };
 eval $eval;
 eval {main->handler;};
}

TYIA,
Chris.
- Original Message - 
From: "Charles K. Clarkson" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, March 23, 2005 3:12 AM
Subject: RE: hash issue


Chris Knipe <mailto:[EMAIL PROTECTED]> wrote:
:
: i.e.
: $RAD_REPLY{'Recv-Limit'} = "20971520";
: $RAD_REPLY{'Xmit-Limit'} = "20971520";
: works.
: $RAD_REPLY{'Recv-Limit'} = $BytesAvail - $BytesUsed;
: $RAD_REPLY{'Xmit-Limit'} = $BytesAvail - $BytesUsed;
: doesn't work.
   Works for me:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper 'Dumper';
my( $BytesAvail, $BytesUsed ) = (20971521, 1);
{
   my %RAD_REPLY;
   $RAD_REPLY{'Recv-Limit'} = "20971520";
   $RAD_REPLY{'Xmit-Limit'} = "20971520";
   print Dumper \%RAD_REPLY;
}

{
   my %RAD_REPLY;
   $RAD_REPLY{'Recv-Limit'} = $BytesAvail - $BytesUsed;
   $RAD_REPLY{'Xmit-Limit'} = $BytesAvail - $BytesUsed;
   print Dumper \%RAD_REPLY;
}
__END__

: So, what am I doing wrong?
   Probably something you are not showing us.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



hash issue

2005-03-22 Thread Chris Knipe
Lo all,
Snipette from the perl code...
   $RAD_REPLY{'Recv-Limit'} = $BytesAvail - $BytesUsed;
   $RAD_REPLY{'Xmit-Limit'} = $BytesAvail - $BytesUsed;
   $RAD_REPLY{'Reply-Message'} = "You have " . 
$za->format_bytes($BytesAvail - $BytesUsed) . " available.";

Righty.
$za->format_bytes return 20M (20MB), and is inside hash, returned to FR. 
Recv-Limit and Xmit-Limit never makes it to the hash.  If I assign actual 
NUMBERS (not via a variable) to the attributes, then they make it without 
any problems...

i.e.
   $RAD_REPLY{'Recv-Limit'} = "20971520";
   $RAD_REPLY{'Xmit-Limit'} = "20971520";
works.
   $RAD_REPLY{'Recv-Limit'} = $BytesAvail - $BytesUsed;
   $RAD_REPLY{'Xmit-Limit'} = $BytesAvail - $BytesUsed;
doesn't work.
So, what am I doing wrong?  It must be something really silly, but for the 
love of (you know who), I just can't seem to get it to work.

--
Chris. 

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



Re: script "freeze"

2005-03-18 Thread Chris Knipe
The script never gets to the PRINT statements.  I run it, it works.  I 
run it again, it just sits there with a blank.  Sometimes, one or more of 
the print statements will execute, sometimes all of them, sometimes none 
of them.  This code is as simple as can be... Am I doing anything wrong??

You might put the calls to crypt password into a select loop as many 
progress meters are written. I suspect that it is still working, did you 
see the caveats, specifically the "Bugs" in the docs:

"Bugs
The function to generate a password can sometimes take an extremely long 
time."

It could just be trying to derive enough entropy, or similar, especially 
since you make multiple calls from within the same script. At least try 
putting a print call between each of the calls to Crypt::RandPasswd::word. 
How long have you let it run and is it on a local workstation or on a 
server that would have no X head?

http://danconia.org
Hmm... I left it running for a minute or two at most.  The delay was coming 
from Crypt::RandPasswd::word.  Changed it to use letters instead 
(Crypt::RandPasswd::letters) and it is very fast now, almost 
instantaneously.  What you say does make sense though, it will obviously 
take longer to get "words" out of the entropy than letters.

Thanks for the help.
--
Chris.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: script "freeze"

2005-03-18 Thread Chris Knipe
Strange...
comment out use strict, and everything works
Is this a coding error??? I can't see anything in the code that should break 
things, but I do realise it's perhaps not the best of code...

--
Chris.
- Original Message - 
From: "Chris Knipe" <[EMAIL PROTECTED]>
To: 
Sent: Friday, March 18, 2005 4:09 PM
Subject: script "freeze"


Lo all,
I suspect this is Crypt::RandPassword's doing, but if anyone can please 
help, I'd appreciate it (as always)


#!/usr/bin/perl
use Crypt::RandPasswd;
use Mysql;
use Net::SMTP;
use Number::Format;
use POSIX;
use strict;
use Sys::Syslog;
use warnings;
 # Stage 1: Rotate Test Passwords.
 $Date_Start = POSIX::strftime("%Y-%m-%d", 0, 0, 0, ($MDay - 1), $Mon, 
$Year, $WDay, $YDay, $Isdst);
 my $Pass064 = Crypt::RandPasswd::word('8','10');
 my $Pass128 = Crypt::RandPasswd::word('8','10');
 my $Pass192 = Crypt::RandPasswd::word('8','10');
 my $Pass256 = Crypt::RandPasswd::word('8','10');

print "UPDATE RadiusCheck SET Value='" . $Pass064 . "' WHERE 
UserName='TEST064' AND CustID='0'\n";
print "UPDATE RadiusCheck SET Value='" . $Pass128 . "' WHERE 
UserName='TEST128' AND CustID='0'\n";
print "UPDATE RadiusCheck SET Value='" . $Pass192 . "' WHERE 
UserName='TEST192' AND CustID='0'\n";
print "UPDATE RadiusCheck SET Value='" . $Pass256 . "' WHERE 
UserName='TEST256' AND CustID='0'\n";

die;

The script never gets to the PRINT statements.  I run it, it works.  I run 
it again, it just sits there with a blank.  Sometimes, one or more of the 
print statements will execute, sometimes all of them, sometimes none of 
them.  This code is as simple as can be... Am I doing anything wrong??

--
Chris.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



script "freeze"

2005-03-18 Thread Chris Knipe
Lo all,
I suspect this is Crypt::RandPassword's doing, but if anyone can please 
help, I'd appreciate it (as always)


#!/usr/bin/perl
use Crypt::RandPasswd;
use Mysql;
use Net::SMTP;
use Number::Format;
use POSIX;
use strict;
use Sys::Syslog;
use warnings;
 # Stage 1: Rotate Test Passwords.
 $Date_Start = POSIX::strftime("%Y-%m-%d", 0, 0, 0, ($MDay - 1), $Mon, 
$Year, $WDay, $YDay, $Isdst);
 my $Pass064 = Crypt::RandPasswd::word('8','10');
 my $Pass128 = Crypt::RandPasswd::word('8','10');
 my $Pass192 = Crypt::RandPasswd::word('8','10');
 my $Pass256 = Crypt::RandPasswd::word('8','10');

print "UPDATE RadiusCheck SET Value='" . $Pass064 . "' WHERE 
UserName='TEST064' AND CustID='0'\n";
print "UPDATE RadiusCheck SET Value='" . $Pass128 . "' WHERE 
UserName='TEST128' AND CustID='0'\n";
print "UPDATE RadiusCheck SET Value='" . $Pass192 . "' WHERE 
UserName='TEST192' AND CustID='0'\n";
print "UPDATE RadiusCheck SET Value='" . $Pass256 . "' WHERE 
UserName='TEST256' AND CustID='0'\n";

die;

The script never gets to the PRINT statements.  I run it, it works.  I run 
it again, it just sits there with a blank.  Sometimes, one or more of the 
print statements will execute, sometimes all of them, sometimes none of 
them.  This code is as simple as can be... Am I doing anything wrong??

--
Chris. 

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



I think I need another regex...

2005-03-17 Thread Chris Knipe
Lo all,
I tried to do this with split(), but it's not working good at all
The string:
interface=something very long with spaces and all 
mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
packets=12623,18377 bytes=10829240,2009327 frames=12623,18377
(the above is one line, wrapped for email).

I need to grab the values for all the options
--
Chris.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: regex needed

2005-01-18 Thread Chris Knipe
Hi Randy,
Ok thank you very much.  This works :)  The problem now, is that I have 
never before in my life worked with hashes...

I have now looped the route list, and it is saved in the hash.  Do I loop 
the hash again now (dumping all data) and then put in comparisions?  I'm not 
100% on how to work with this further now to check which route is on the 
interface that I actually want to delete...

I want to achieve something like
if (($data{interface} eq "National Gateway") && ($data{gateway} =~ 
m/165\.(165|146)\.0\.[0-8]/)) {
 #work with $data{rule};
}

--
Chris.



- Original Message - 
From: "Randy W. Sims" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, January 18, 2005 4:04 PM
Subject: Re: regex needed


Chris Knipe wrote:
Lo everyone,
Can someone please give me a regex to parse the following... Flags: X - 
disabled, I - invalid, D - dynamic, J - rejected,
C - connect, S - static, r - rip, o - ospf, b - bgp
 #DST-ADDRESSG GATEWAY DISTANCE INTERFACE
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
[EMAIL PROTECTED] >

I want the regex to return the rule number for all route entries that is 
static (S Flag) on Interface "National Gateway".  For added security, I'd 
like it if the regex will also only return true if the gateway address is 
part of 165.165.0.0/8 or 165.146.0.0/8

Basically, I need to use the rule number in another command to delete the 
route entry... So I presume I'll need to extract it via the regex
If it's a fixed width data format, its better (easier for you, faster for 
perl) to break up the string with C:

#!/usr/bin/perl
use strict;
use warnings;
while (defined( my $line =  )) {
chomp( $line );
my %data;
$data{rule}  = substr( $line,  0,  2 );
$data{flags} = substr( $line,  3,  2 );
$data{dest_ip}   = substr( $line,  6, 18 );
$data{g} = substr( $line, 25,  1 );
$data{gateway}   = substr( $line, 27, 16 );
$data{distance}  = substr( $line, 43,  8 );
$data{interface} = substr( $line, 52 );
# cleanup, stripping spaces
$data{$_} =~ s/^\s+|\s+$//g
for keys %data;
# reformat or reinterpret data
$data{flags} = [ split( //, $data{flags} ) ];
use Data::Dumper;
print Dumper( \%data );
}

__END__
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



regex needed

2005-01-18 Thread Chris Knipe
Lo everyone,

Can someone please give me a regex to parse the following... 



Flags: X - disabled, I - invalid, D - dynamic, J - rejected,
C - connect, S - static, r - rip, o - ospf, b - bgp
 #DST-ADDRESSG GATEWAY DISTANCE INTERFACE
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
[EMAIL PROTECTED] >


I want the regex to return the rule number for all route entries that is static 
(S Flag) on Interface "National Gateway".  For added security, I'd like it if 
the regex will also only return true if the gateway address is part of 
165.165.0.0/8 or 165.146.0.0/8

Basically, I need to use the rule number in another command to delete the route 
entry... So I presume I'll need to extract it via the regex

Hope someone can help me here..

--
Chris.



Re: err, this is stupid, I know...

2004-03-14 Thread Chris Knipe
> First, the first argument to split is *always* a regex. A lot of people 
> are in the habit of passing a quoted string, but according to the 
> perl5-porters (in a thread about a year or so ago) the first argument 
> should always be a regex. So, use the // or m// syntax.
> 
> Doing that should make it obvious what the problem is:
> 
> my @IPs = split(/./, $ARGV[4]);
>   ^
> dot is a meta character in a regex, so it needs to be quoted:

You learn something new everyday.  Thank you - works perfectly... :)

--
me



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




err, this is stupid, I know...

2004-03-14 Thread Chris Knipe
use warnings;

$ARGV[4] = "100.200.30.40"; # for the sake of clarification.

my @IPs = split('.', $ARGV[4]);
if ($IPs[1] < 100) {
  print "TRUE";
} else {
  print "FALSE";
}

running it...
Use of uninitialized value in numeric lt (<) at ./ppp.rotate line 6.

And the condition is *always* true.

Now, as far as I know, this is happening because $IPs[1] isn't a integer,
but a string  What I don't know, is how to fix this :/

I know this is just one line or one function I'm missing... Please assist :)

--
me




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




document creation.

2003-08-14 Thread Chris Knipe
Lo all,

I want to create large number of documents (mainly invoices) using perl.  In
a couple of months, I should be creating a few hundred documents per month
with a few million records in total for the documents (Telecoms
implementation).

Now, preferably, I wanted to create MS Word documents for this, but alas, a
stick was shoved into that idea.  Win32::OLE doesn't work from *Nix, and
RTF::Document has like zero documentation (very help full thanks)...

What's my alternatives???

Please keep in mind where possible, I'd like to automatically print the
invoices prior to archiving the hard documents.  The documents is also quite
complex layout wise, with allot of graphs (Images) and about 95% table
based... Is HTML really the only alternative here??  I'm not sure whether
printing HTML will be a very good idea...

--
me


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



Re: document creation.

2003-08-14 Thread Chris Knipe

> > Please keep in mind where possible, I'd like to automatically print the
> > invoices prior to archiving the hard documents.  The documents is also
quite
> > complex layout wise, with allot of graphs (Images) and about 95% table
> > based... Is HTML really the only alternative here??  I'm not sure
whether
> > printing HTML will be a very good idea...
> >
>
> HTML is one option but not the only one. XML would be the naturally most
> portable and upgradeable probably. Why store them as files in the first
> place, why not just store them to a database? You can store them in any
> number of possible ways, txt, csv, pdf, html, xml, or not at all, just
> store their values and a template and generate them on the fly...

Yes, obviously.  It's pretty much standard telecoms stuff (notable the
majority being detailed call logs).  These are all stored via a database as
they occur and yes, there are already web based interfaces to "lookup" usage
and cost (bill) information.  But that is only one side of the story, and
the side of the story that does work.

Obviously, I cannot simply put bills online (or email for that matter) and
ensure that all clients actually receive a bill (Frankly, I may stand
corrected but I think there is a law in my country which actually ensures
that I must make all attempts possible to get invoices to clients on time).
Some also prefer to have a hard copy for numerious reasons which falls out
of the scope of this topic (Record keeping, TAX, etc)...  The obvious
solution, is to provide invoices both online and off.  Now, online bills
aren't a problem I made a nifty little PHP based app to pull the data and
let it look pretty much in line to what I want my invoices to look like.
This however is not a solution for a "printed" invoice that should be
mailed.

So basically, I need to create a second set of professional looking
documents that can be printed and posted to my clients.  It's as simple as
that.  And no, manually looking up 2000+ invoices a month on IE / Netscape
and manually printing them is not a option (just in case it was questioned).
Page breaks to my knowledge won't work on HTML-based documents in any case,
instead if I go and do silly things like count lines which I feel really
should NOT be neccessary.

> Either way we won't be able to provide you the help without you first
> setting explicitly what your goals are, and making an attempt yourself.

Yes, print "whatever" does work and it does create output that can be sent
to lpr so that it is printed and that I can post it.  However, print
"whatever" does not create a professional looking invoice that I or my
company for that matter will feel comfortable sending to customers. Neither
does it handle tables very well, nor images.  Not to mention bolds, italics,
underlines, or font sizes (I'm sure there's a whole list that I did not
mention, but once again, it falls outside the scope of this topic IMHO)...

Now a module that comes without documentations (notable, RTF::Document), you
can hardly expect me to read non existent documentation.  Apart from
Win32::OLE and RTF::Document, what else is there that I can actually use
(note my original question), to create decently looking documents to send to
lpr.  Once I know what I can possibly use to achieve this, I'd be more than
happy to go and RTFM, provided that there actually is a FM to R.

--
me


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



Re: document creation.

2003-08-11 Thread Chris Knipe
> > Now, preferably, I wanted to create MS Word documents for this, but
> > alas, a stick was shoved into that idea.  Win32::OLE doesn't work from
> > *Nix, and RTF::Document has like zero documentation (very help full
> > thanks)...
> >
> > What's my alternatives???
>
> http://Jenda.Krynicky.cz/#Template::RTF
>


Brilliant :)

Thank you Jenda and those others who made constructive suggestions (on and
off) the list.   From first impressions, Template::RTF would seem to be
simple enough, yet complicated enough to accomplish what I want without to
much troubles.

I'll give it a go and see where I end up.

--
me


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



Re: Stupid regex.. I'm going to kick myself...

2003-02-23 Thread Chris Knipe
> 
> try: ($URL) = /href="(.*?)"/;
> 

Not sure what I did the first time... But it works the second time... 

while (<>) {
   if (($_ =~ /^/i)) {
($URL) = /href="(.*?)"/;
print "$URL\n";
  }
}

Thanks Stefan... Much appreciated.

--
me


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



Re: Stupid regex.. I'm going to kick myself...

2003-02-23 Thread Chris Knipe
- Original Message -
From: "Stefan Lidman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, February 23, 2003 3:17 PM
Subject: Re: Stupid regex.. I'm going to kick myself...


> > while (<>) {
> > if ($_ =~ /LinkArea="MoreHeadlines">/) {
> >   ($URL) = $_ =~ /href="($.)"/;
> >   print "$URL\n";
> > }
> > }
> >
> > I have a URL...
> >
> >  > LinkArea="MoreHeadlines">test
> >
> > Everything is randomly generated. Hence, I want to extract anything
> > specified in the href="" field... So, after doing extensive reading, I
found
> > that I am indeed looking for /href="($.)"/  However, I cannot seem to
> > extract this into a separated variable...
>
> try: ($URL) = /href="(.*?)"/;
>
> /Stefan

Hmmm... Now it only prints a 1

I did check and confirm if my regex is right and all... if ($_ =~ /href="/)
returns true... So it does find it.. It just doesn't want to extract it for
some reason.

Various perl docs / faqs online (google is my friend), suggested something
like this...

/href="($.)"/;  #<-- Shoot me if I know where the regex is supposed to get
the data from to parse...
$URL = $1;
print $URL;

But even that screws up.  $1 is a empty value

 --
me


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



Stupid regex.. I'm going to kick myself...

2003-02-23 Thread Chris Knipe
Lo all,

I'm doing something *really* stupid... Please kick me...

while (<>) {
if ($_ =~ /LinkArea="MoreHeadlines">/) {
  ($URL) = $_ =~ /href="($.)"/;
  print "$URL\n";
}
}

I have a URL...

test

Everything is randomly generated. Hence, I want to extract anything
specified in the href="" field... So, after doing extensive reading, I found
that I am indeed looking for /href="($.)"/  However, I cannot seem to
extract this into a separated variable...

What am I doing wrong??

--
me


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



Re: CSV inports...

2003-02-20 Thread Chris Knipe
Ty everyone;

I stumbled abon a CSV module that did the trick... Wasn't in CPAN though (or
rather, CPAN search didn't find it)... Simply called CSV, worked wonders...
(http://rath.ca/Misc/Perl_CSV/CSV-2.0.tar.gz)

use CSV;
my ($CK, $NAME, $ADDRESS, $TYPE) = CSVsplit($_);

:P

--
me


- Original Message -
From: "Timothy Johnson" <[EMAIL PROTECTED]>
To: "'Chris Knipe'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, February 20, 2003 10:55 PM
Subject: RE: CSV inports...


>
> I would use DBD::CSV or (I think) Text::CSV.  I have a routine that I
tried
> to use in the past, but it gets more complicated than the split solution:
>
> open(INFILE,"myfile.csv");
> while(){
>my @fields;
>while($_ =~ /(\".*\")?,?([^\"]*)/g){
>   push @fields,$1;
>   push @fields,split(/,/,$2);
>}
>print OUTFILE join(',',@fields);
> }
>
>
>
> -Original Message-
> From: Chris Knipe [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 20, 2003 12:34 PM
> To: [EMAIL PROTECTED]
> Subject: CSV inports...
>
>
> Lo all,
>
> I got a little problem with a CSV import... It should be rather straight
> forward to people who do this often.. so I'm hoping for some help...
>
> I have a MS Excel exported CSV text file, with , separated values.  The
> problem now, is that some of the values also contains a , character, and
MS
> Excel thus put the values in a quote such as:
> "blah, blah", blah, "blah, blah, blah"
>
> I have:
> open(FILE, " while () {
>   my ($CK, $NAME, $ADDRESS, $TYPE) = split(',', $_);
> }
> close(FILE);
>
> But this obviously does not work, seeing that it ignores values included
in
> the quotes "...
>
> How would I go about fixing this little issue?
>
> --
> me
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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




CSV inports...

2003-02-20 Thread Chris Knipe
Lo all,

I got a little problem with a CSV import... It should be rather straight
forward to people who do this often.. so I'm hoping for some help...

I have a MS Excel exported CSV text file, with , separated values.  The
problem now, is that some of the values also contains a , character, and MS
Excel thus put the values in a quote such as:
"blah, blah", blah, "blah, blah, blah"

I have:
open(FILE, ") {
  my ($CK, $NAME, $ADDRESS, $TYPE) = split(',', $_);
}
close(FILE);

But this obviously does not work, seeing that it ignores values included in
the quotes "...

How would I go about fixing this little issue?

--
me


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




env

2002-11-05 Thread Chris Knipe
Lo everyone,

How do I read environment variables with perl?

--
me

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




Re: executing binaries

2002-07-17 Thread Chris Knipe

Ok thanks,

Got it working As silly of me as this was, I accidentally had the code
inside a if statement that was returning false :-)

My bad...

--
me


- Original Message -
From: "Chris Knipe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 17, 2002 10:38 PM
Subject: Re: executing binaries


> I got it working on the shell now:
>
> savage@netsonic:~/src# perl -MIPC::Open2 -e'open2(*rd, *wr,
"/bin/ls -al");
> while () { print; }  exit;'
> total 32
> drwxr-x---  8 root  wheel512 Jul 17 03:29 .
> drwxr-xr-x  8 root  wheel512 Jul 16 05:38 ..
> -rwxr-x---  1 root  wheel  21955 Jul 17 22:36 ApacheReconfig
> drwxr-xr-x  5 640   15  1024 Jul 12 00:27 amavisd-snapshot-20020300
> drwxr-x---  2 root  wheel512 Jul  8 01:49 ftpmail
> drwxr-x---  4 root  wheel512 Jul  9 07:33 mrtg-2.9.21
> drwxr-x---  9 root  wheel   1024 Jul 13 21:44 nagios-1.0b4
> drwxr-x---  6 root  wheel   1024 Jul 11 08:07 netsaint-plugins-1.2.9-4
> drwxr-x---  7 root  wheel   2560 Jul 11 05:41 tpop3d-1.4.2
>
> However, when I call it from my perl script:
>
> use strict;
> use IPC::Open2;
>
> open2(*rd, *wr, "/bin/ls -al");
> while () {
>   print $_;
> }
>
> Sure, there's allot of other stuff in the perl script, mainly allot of
> database queries, and to open() / close() file handles, but needless to
say,
> when I use open2() like this from the command line, it works.  Inside my
> script it fails
>
>
>
> - Original Message -
> From: "Tanton Gibbs" <[EMAIL PROTECTED]>
> To: "Chris Knipe" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Wednesday, July 17, 2002 10:27 PM
> Subject: Re: executing binaries
>
>
> > Chris Knipe wrote:
> > > savage@netsonic:~/src# perl -MIPC::Open2 -e'open2($rd, $wr, "ls -al");
> > while
> > > (<$rd>) { print; } exit;'
> > > open2: wtr should not be null at -e line 1
> >
> > It may have to do with the fact that you can't write to ls...the
following
> > worked for me
> >
> > use IPC::Open2;
> > use strict;
> >
> > my ($rd, $wr);
> > open2($rd, $wr, "bc");
> > print $wr "5 + 7\n";
> > my $x = <$rd>;
> > print $x;
> > close( $rd );
> > close( $wr );
> >
> > Tanton
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


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




Re: executing binaries

2002-07-17 Thread Chris Knipe

I got it working on the shell now:

savage@netsonic:~/src# perl -MIPC::Open2 -e'open2(*rd, *wr, "/bin/ls -al");
while () { print; }  exit;'
total 32
drwxr-x---  8 root  wheel512 Jul 17 03:29 .
drwxr-xr-x  8 root  wheel512 Jul 16 05:38 ..
-rwxr-x---  1 root  wheel  21955 Jul 17 22:36 ApacheReconfig
drwxr-xr-x  5 640   15  1024 Jul 12 00:27 amavisd-snapshot-20020300
drwxr-x---  2 root  wheel512 Jul  8 01:49 ftpmail
drwxr-x---  4 root  wheel512 Jul  9 07:33 mrtg-2.9.21
drwxr-x---  9 root  wheel   1024 Jul 13 21:44 nagios-1.0b4
drwxr-x---  6 root  wheel   1024 Jul 11 08:07 netsaint-plugins-1.2.9-4
drwxr-x---  7 root  wheel   2560 Jul 11 05:41 tpop3d-1.4.2

However, when I call it from my perl script:

use strict;
use IPC::Open2;

open2(*rd, *wr, "/bin/ls -al");
while () {
  print $_;
}

Sure, there's allot of other stuff in the perl script, mainly allot of
database queries, and to open() / close() file handles, but needless to say,
when I use open2() like this from the command line, it works.  Inside my
script it fails



- Original Message -
From: "Tanton Gibbs" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, July 17, 2002 10:27 PM
Subject: Re: executing binaries


> Chris Knipe wrote:
> > savage@netsonic:~/src# perl -MIPC::Open2 -e'open2($rd, $wr, "ls -al");
> while
> > (<$rd>) { print; } exit;'
> > open2: wtr should not be null at -e line 1
>
> It may have to do with the fact that you can't write to ls...the following
> worked for me
>
> use IPC::Open2;
> use strict;
>
> my ($rd, $wr);
> open2($rd, $wr, "bc");
> print $wr "5 + 7\n";
> my $x = <$rd>;
> print $x;
> close( $rd );
> close( $wr );
>
> Tanton
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


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




Re: executing binaries

2002-07-17 Thread Chris Knipe

I had a look

The documentation is *very* lacking.

savage@netsonic:~/src# perl -MIPC::Open2 -e'open2($rd, $wr, "ls -al"); while
(<$rd>) { print; } exit;'
open2: wtr should not be null at -e line 1

Needless to say, I am *totally* clueless :(((


- Original Message -
From: "Tanton Gibbs" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, July 17, 2002 9:25 PM
Subject: Re: executing binaries


> The Perl Cookbook recipie 16.8 says
> use the standard IPC::Open2 module:
>
> use IPC::Open2;
>
> open2(*README, *WRITEME, $program);
> print WRITEME "Here's your input\n";
> $output = ;
> close(WRITEME);
> close(README);
>
> However, it warns that there could be problems if the other program
buffers
> input or output.  You should probably perldoc IPC::Open2 for all of the
> details.
> - Original Message -
> From: "Chris Knipe" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, July 17, 2002 3:09 PM
> Subject: executing binaries
>
>
> > Lo all,
> >
> > What's the best way to execute a binary command from within perl, and
read
> > text returned by the binary, as well as write data to certain prompts
that
> > the program may have?
> >
> > Say, I have...
> >
> > #>./myprogram
> > This is my program, I will ask you a question now
> > Please give me your name:  WHATEVER
> > Thank you.
> >
> > In this instance, I want to read the output from the program, wait for
> > "name:", and send it WHATEVER.  Then, based on the exit code of the
> > application, I want to execute various code (say, when the program exits
> > successfully, of when there is a error)
> >
> > Does anyone have some pointers on this for me?  How can I accomplish
> this..
> > To my understanding, both system() and exec() are out of bounds here...
Or
> > am I wrong?
> >
> > --
> > me
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


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




Re: executing binaries

2002-07-17 Thread Chris Knipe

Thanks a million...

I'll give the module a read or two or ten :p)

Regards,
Chris Knipe
Cell: (072) 434-7582
MegaLAN Corporate Networking Services


- Original Message -
From: "Tanton Gibbs" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, July 17, 2002 9:25 PM
Subject: Re: executing binaries


> The Perl Cookbook recipie 16.8 says
> use the standard IPC::Open2 module:
>
> use IPC::Open2;
>
> open2(*README, *WRITEME, $program);
> print WRITEME "Here's your input\n";
> $output = ;
> close(WRITEME);
> close(README);
>
> However, it warns that there could be problems if the other program
buffers
> input or output.  You should probably perldoc IPC::Open2 for all of the
> details.
> - Original Message -
> From: "Chris Knipe" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, July 17, 2002 3:09 PM
> Subject: executing binaries
>
>
> > Lo all,
> >
> > What's the best way to execute a binary command from within perl, and
read
> > text returned by the binary, as well as write data to certain prompts
that
> > the program may have?
> >
> > Say, I have...
> >
> > #>./myprogram
> > This is my program, I will ask you a question now
> > Please give me your name:  WHATEVER
> > Thank you.
> >
> > In this instance, I want to read the output from the program, wait for
> > "name:", and send it WHATEVER.  Then, based on the exit code of the
> > application, I want to execute various code (say, when the program exits
> > successfully, of when there is a error)
> >
> > Does anyone have some pointers on this for me?  How can I accomplish
> this..
> > To my understanding, both system() and exec() are out of bounds here...
Or
> > am I wrong?
> >
> > --
> > me
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


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




executing binaries

2002-07-17 Thread Chris Knipe

Lo all,

What's the best way to execute a binary command from within perl, and read
text returned by the binary, as well as write data to certain prompts that
the program may have?

Say, I have...

#>./myprogram
This is my program, I will ask you a question now
Please give me your name:  WHATEVER
Thank you.

In this instance, I want to read the output from the program, wait for
"name:", and send it WHATEVER.  Then, based on the exit code of the
application, I want to execute various code (say, when the program exits
successfully, of when there is a error)

Does anyone have some pointers on this for me?  How can I accomplish this..
To my understanding, both system() and exec() are out of bounds here... Or
am I wrong?

--
me



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




Re: Quick ways?

2002-07-14 Thread Chris Knipe

> On Sun, Jul 14, 2002 at 06:24:30PM +0200, Chris Knipe wrote:
>
> > Lo all,
> >
> > I was just wondering if there are any quick ways to make a directory
hiracy?
>
> [snip]
>
> > Anyone with some code to share? ;-)
>
> It's your lucky day :-)
>
> You'll be wanting the mkpath function in the standard File::Path module.


mkpath($tmpDir, 0, oct("2750"));

MAN! I love it when things are so easy ;-)

Now, we just have to figure out file / directory ownership Hmmm, agh,
let me go have a look at File.pm and see what other goodies it has ;-)

Thanks a mil.

--
me



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




Quick ways?

2002-07-14 Thread Chris Knipe

Lo all,

I was just wondering if there are any quick ways to make a directory hiracy?

Say, I have the following example:

if (!(-X
"/usr/local/www/v-webs/$ClientCode/$WebList[1]/$WebList[2]/htdocs")) {
  // Directory doesn't exist.
}

What will be the most effective way to make this directory?  I think I'll
need to -X every directory individually to see if it exist, and make it if
they don't exist.. Such as:

if (!(-X "/usr/local/www/v-webs/$ClientCode)) {
  mkdir("/usr/local/www/v-webs/$ClientCode", 0777);
}
 Next dir

But this is going to be a hell of allot of code to do manually surely...
Especially when directory structures becomes even longer...  Is there a
quick way of doing it?  I'm thinking of perhaps splitting the directory into
a array and walking through the elements of the array, but I'm not to
certain on how to do this...

Anyone with some code to share? ;-)

--
me



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




Re: Am I being stupid here... or?

2002-07-10 Thread Chris Knipe

On Wed, Jul 10, 2002 at 04:11:42PM -0400, Bob Showalter wrote:

> > if ($SiteType == "notsomething") {
> 
> Use eq for string comparison. == is for numeric comparison.

Told you I was being stupid :p  

I guess after a well deserved 3 week holiday, I am allowed to be a bit
rusty...  Work's wonderfully now, thanks!

--
me


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




Am I being stupid here... or?

2002-07-10 Thread Chris Knipe

Lo all,

Very stupid it must be, but I can't see what I'm doing wrong here... 

The following if statement, always returns true (prints "a"), regardless
of what the value of $SiteType is... 

#!/usr/bin/perl

$SiteType = "something";

if ($SiteType == "notsomething") {
  print "a";
}

Am I doing something really arbly stupid here, did I miss anything?

What I'd like to accomplish, is something in the lines of:

if ($SiteType == "PHP3") {
  do some stuff
} elsif ($SiteType == "PHP4") {
  do different stuff
} elsif ($SiteType == "ASP") {
  do different stuff

} else {
  do default stuff
}

--
me


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




Re: Formating date string

2002-06-18 Thread Chris Knipe

- Original Message -
From: "drieux" <[EMAIL PROTECTED]>
To: "begin begin" <[EMAIL PROTECTED]>
Sent: Wednesday, June 19, 2002 5:11 AM
Subject: Re: Formating date string


>
> On Tuesday, June 18, 2002, at 07:29 , Chris Knipe wrote:
>
> > How can I convert a date such as '18 Jun, 2002 at 11:00:00 (SAT)' into a
> > DD/MM/ HH:MM string?
>
> are you safely convinced that you will always be seeing your
> input in that format - then the following would help you:
>
> http://www.wetware.com/drieux/pbl/perlTrick/dateStringConvert.txt

Thanks, I'll have a look now :-)

I came up with my own little sub that's basically just two split calls to
split the date & time fields into their own variables... Not to sure how
"correct" that is, but it's working :-)

And yes, the date format already has been in that format for more than three
years... Silly South Africans -eg-

Ok looking at the code.. We basically did the same thing, mine's just allot
uglier and longer... So I'm gonna use your func :-)  Thanks!


--
me




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




Formating date string

2002-06-18 Thread Chris Knipe

Lo all,

How can I convert a date such as '18 Jun, 2002 at 11:00:00 (SAT)' into a
DD/MM/ HH:MM string?

I've been on google for quite some time now, and looked at quite a few CPAN
stuff, but I can't seem to find anything converting that specific format?

--
me



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




Re: cutting of last char of a variable

2002-06-16 Thread Chris Knipe

Thanks,

Geo::Metar was all I needed.  After hunting around a little longer, I found
there was already a module that could do all I needed.

Application's finished, and working wonderfully.


- Original Message -
From: "Daniel Gardner" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Sunday, June 16, 2002 10:50 AM
Subject: Re: cutting of last char of a variable


> Check perldoc -f chop
>
> http://www.perldoc.com/perl5.6.1/pod/func/chop.html
>
>
> Sunday, June 16, 2002, 9:29:00 AM, Chris Knipe wrote:
>
> > Hi,
>
> > How can I cut off the last char. of a string?
>
> > $string = "160700Z";
>
> > I want to remove the Z ?
>
> > This is to import METAR weather data if anyone's interested, and if
someone
> > has a script which process and imports the Metar data already, I'd
> > appreciate it allot :P
>
> > --
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


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




cutting of last char of a variable

2002-06-16 Thread Chris Knipe

Hi,

How can I cut off the last char. of a string?

$string = "160700Z";

I want to remove the Z ?

This is to import METAR weather data if anyone's interested, and if someone
has a script which process and imports the Metar data already, I'd
appreciate it allot :P

--
me



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