Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: exim: users

Exim Webmin Module.

 

 

exim users RSS feed   Index | Next | Previous | View Threaded


gpeel at thenetnow

Jan 16, 2012, 6:15 AM

Post #1 of 8 (717 views)
Permalink
Exim Webmin Module.

Hi all,

The perl code below has is a file from a Webmin module used to interface with Exim, show stats manage queue etc. The issue is that the date does not decode properly. The code is quite old, and I have been hacking at it for weeks trying to get it to work correctly. I have attempted to contact the original developer, but suspect his email is not been checked.

I am posting to this list thinking perhaps some of you may have some expierence with the base62 encoding, and hopefully perl!

If anyone would like to take a shot at it ....

Example
1RkkUB-000CAI-Ce is being decoded a s: Sat Apr 23 16:10:52 2005
which is not correct.

Here is the code: (Message.pm)

I suspect the issue is with the base62_to_decimal sub near the end.




#!/usr/bin/perl

package Exim::Message;

require 5;

use strict;
use integer;

sub uli # 'uli' stands for Unique Local Identifier
{
my $self = shift;
if (@_) {
my $uli = shift;

return undef if $uli !~ /[0-9a-zA-Z]{6}-[0-9a-zA-Z]{6}-[0-9a-zA-Z]{2}/;
$self->{uli} = $uli
}
return $$self{uli}
}

sub time
{
my $self = shift;
if (@_) {
my $time = shift;
my $units = 'smhdw';

$time =~ /^(\d+)([$units])/ or return undef;

$$self{rtime} = { value => $1, unit => $2 };

my ($value, $unit) = ($1, index($units, $2));
my @coef = (1, 60, 60, 24, 7);

while ($unit > 0) { $value *= $coef[$unit--] }
$$self{time} = $value;
}
return $$self{time}
}

sub rounded_time
{
my $self = shift;
return $$self{rtime}
}

sub size
{
my $self = shift;
if (@_) {
my $size = shift;
$size = defined $size?$size:0;

my $units = '_KMG';

my $bytes;

if ($size =~ /\./) {
$size =~ /^(\d+\.?\d+)([$units])?/ or return undef;
$$self{rsize} = { value => $1, unit => $2.'B' };
$bytes = $1*1024**index($units, $2);
}
else {
$size =~ /^(\d+)([$units]?)/ or return undef;
$$self{rsize} = { value => $1, unit => $2.'B' };
$bytes = $1 << 10*index($units, $2);
}

$$self{size} = $bytes;
}

return $$self{size}
}

sub rounded_size
{
my $self =shift;
return $$self{rsize}
}

sub sender
{
my $self = shift;
if (@_) {
my $sender = shift;

$sender =~ s/^\<(.*)\>$/$1/;
$$self{sender} = $sender;
}
return $$self{sender}
}

sub status
{
my $self = shift;
if (@_) { $$self{status} = shift()?1:0 }
return $$self{status}
}

sub undelivered
{
my $self = shift;
if (@_) { push @{$$self{undelivered}}, @_ }
return @{$$self{undelivered}};
}

sub delivered
{
my $self = shift;
if (@_) { push @{$$self{delivered}}, @_ }
return @{$$self{delivered}};
}

sub _init_
{
my $self = shift;

my @fields = split ' ', shift;
return undef if @fields < 4;

&time ($self, shift @fields) or return undef;
&size ($self, shift @fields) or return undef;
&uli ($self, shift @fields) or return undef;
&sender ($self, shift @fields);
&status ($self, shift @fields);

$$self{delivered} = [];
$$self{undelivered} = [];

local $_;
foreach (@_) {
chomp;
next if /^$/;
s/^\s+//;
s/^D\s+//?&delivered($self, $_):&undelivered($self, $_)
}
return $self
}

sub new
{
my $class = shift;
$class = ref($class) || $class;

my $self = bless {}, $class;

if (@_) {
$self->_init_ (split /\n/, shift ()) or return undef;
}
return $self;
}

sub gmt
{
my $self = shift;

return $$self{gmt} if defined $$self{gmt};

return $$self{gmt} = gmtime base62_to_decimal ($$self{uli})
}

sub is_frozen
{
my $self = shift;
return $$self{status};
}

# Converts base 62 ([0-9a-zA-Z]*) ASCII strings to decimal numbers.
# Example: &base62_to_decimal('15gY5D');
sub base62_to_decimal
{
my @tab62 =
(0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, # 0-9
0,10,11,12,13,14,15,16,17,18,19,20, # A-K
21,22,23,24,25,26,27,28,29,30,31,32, # L-W
33,34,35, 0, 0, 0, 0, 0, # X-Z
0,36,37,38,39,40,41,42,43,44,45,46, # a-k
47,48,49,50,51,52,53,54,55,56,57,58, # l-w
59,60,61); # x-z

my($d) = 0;
my($O) = ord('0');
my(@c) = unpack('C*', shift);
while($#c >= 0) { $d = $d * 62 + $tab62[shift(@c) - $O] }
return $d;
}

-Thanks

-G
--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


nigel at dotdot

Jan 16, 2012, 6:48 AM

Post #2 of 8 (715 views)
Permalink
Re: Exim Webmin Module. [In reply to]

On 16 Jan 2012, at 14:15, Grant Peel wrote:

> Hi all,
>
> The perl code below has is a file from a Webmin module used to interface with Exim, show stats manage queue etc. The issue is that the date does not decode properly. The code is quite old, and I have been hacking at it for weeks trying to get it to work correctly. I have attempted to contact the original developer, but suspect his email is not been checked.
>
> I am posting to this list thinking perhaps some of you may have some expierence with the base62 encoding, and hopefully perl!



I suggest that rather than re-implementing this, you use a CPAN module
https://metacpan.org/module/Data::ID::Exim

Nigel.

--
[ Nigel Metheringham ------------------------------ nigel [at] dotdot ]
[ Ellipsis Intangible Technologies ]



--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


tlyons at ivenue

Jan 16, 2012, 11:28 AM

Post #3 of 8 (705 views)
Permalink
Re: Exim Webmin Module. [In reply to]

On Mon, Jan 16, 2012 at 6:15 AM, Grant Peel <gpeel [at] thenetnow> wrote:
> Hi all,
>
> The perl code below has is a file from a Webmin module used to interface with Exim, show stats manage queue etc. The issue is that the date does not decode properly. The code is quite old, and I have been hacking at it for weeks trying to get it to work correctly. I have attempted to contact the original developer, but suspect his email is not been checked.

The code works fine in my limited testing.

> I am posting to this list thinking perhaps some of you may have some expierence with the base62 encoding, and hopefully perl!
>
> If anyone would like to take a shot at it ....
>
> Example
> 1RkkUB-000CAI-Ce        is being decoded a s:         Sat Apr 23 16:10:52 2005
> which is not correct.

Probably because you're passing the whole message id string to the
function instead of just the portion which is the datetime. Observe,
using your data:

$ perl test.pl 1RkkUB-000CAI-Ce
Starting with 1RkkUB-000CAI-Ce
Reduced to 1RkkUB
Seconds since Jan 1 1970: 1326235687
Tue Jan 10 14:48:07 2012
Tue Jan 10 22:48:07 2012

You have to strip all the extra cruft after and including the first
dash. Only the first 6 characters are significant for time
calculation.


Experiment with this:

#!/usr/bin/perl
use strict;
use warnings;

my $id = shift() || '1Rmrv2-0001v1-T6';
print "Starting with $id\n";
my $tm;
($tm = $id) =~ s/^([0-9a-zA-Z]{6})-[0-9a-zA-Z]{6}-[0-9a-zA-Z]{2}$/$1/ ?
print "Reduced to $tm\n" :
die ("Not proper format of message ID");
print "Extracted time portion: $id\n";

my $seconds = base62_to_decimal($id);
print "Seconds since Jan 1 1970: $seconds\n";
print scalar localtime($seconds),"\n";
print scalar gmtime($seconds),"\n";

...Todd
--
SOPA: Any attempt to [use legal means to] reverse technological
advances is doomed.  --Leo Leporte

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


gpeel at thenetnow

Jan 16, 2012, 4:05 PM

Post #4 of 8 (704 views)
Permalink
Re: Exim Webmin Module. [In reply to]

Hi Todd, thanks for the reply...please see below.

On Mon, 16 Jan 2012 11:28:08 -0800, Todd Lyons wrote
> On Mon, Jan 16, 2012 at 6:15 AM, Grant Peel <gpeel [at] thenetnow> wrote:
> > Hi all,
> >
> > The perl code below has is a file from a Webmin module used to interface
with Exim, show stats manage queue etc. The issue is that the date does not
decode properly. The code is quite old, and I have been hacking at it for
weeks trying to get it to work correctly. I have attempted to contact the
original developer, but suspect his email is not been checked.
>
> The code works fine in my limited testing.

Actually, if you were to look at the result(s) in the webmin module, it does
not work even closely. The Times and date are completely whacked...

>
> > I am posting to this list thinking perhaps some of you may have some
expierence with the base62 encoding, and hopefully perl!
> >
> > If anyone would like to take a shot at it ....
> >
> > Example
> > 1RkkUB-000CAI-Ce        is being decoded a s:         Sat Apr 23
16:10:52 2005
> > which is not correct.
>
> Probably because you're passing the whole message id string to the
> function instead of just the portion which is the datetime. Observe,
> using your data:

Sorry Todd, I am not passing anything, I did not write the code, a fellow
named Alexander did. I tried to understand it but I think it is way above my
head. I suspect I should take a sceen shot of the results, post that along
with the whole module and see if anyone wants to take a shot at it...

>
> $ perl test.pl 1RkkUB-000CAI-Ce
> Starting with 1RkkUB-000CAI-Ce
> Reduced to 1RkkUB
> Seconds since Jan 1 1970: 1326235687
> Tue Jan 10 14:48:07 2012
> Tue Jan 10 22:48:07 2012
>
> You have to strip all the extra cruft after and including the first
> dash. Only the first 6 characters are significant for time
> calculation.
>
> Experiment with this:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $id = shift() || '1Rmrv2-0001v1-T6';
> print "Starting with $id\n";
> my $tm;
>
> ($tm = $id) =~ s/^([0-9a-zA-Z]{6})-[0-9a-zA-Z]{6}-[0-9a-zA-
> Z]{2}$/$1/ ? print "Reduced to $tm\n" : die ("Not proper format
> of message ID"); print "Extracted time portion: $id\n";
>
> my $seconds = base62_to_decimal($id);
> print "Seconds since Jan 1 1970: $seconds\n";
> print scalar localtime($seconds),"\n";
> print scalar gmtime($seconds),"\n";
>
> ...Todd
> --
> SOPA: Any attempt to [use legal means to] reverse technological
> advances is doomed.  --Leo Leporte
>
> --
> ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/


--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


Max.Caines at wlv

Jan 17, 2012, 5:54 AM

Post #5 of 8 (700 views)
Permalink
Re: Exim Webmin Module. [In reply to]

Hi

I put Webmin on our Exim servers recently, and did a fix myself. I enclose the fixed module, which is Message.pm, which on a default install is in /opt/webmin/exim/Exim

Regards

Max Caines
University of Wolverhampton

> -----Original Message-----
> From: exim-users-bounces+max.caines=wlv.ac.uk [at] exim [mailto:exim-
> users-bounces+max.caines=wlv.ac.uk [at] exim] On Behalf Of gpeel
> Sent: 17 January 2012 00:05
> To: Todd Lyons
> Cc: exim-users [at] exim
> Subject: Re: [exim] Exim Webmin Module.
>
> Hi Todd, thanks for the reply...please see below.
>
> On Mon, 16 Jan 2012 11:28:08 -0800, Todd Lyons wrote
> > On Mon, Jan 16, 2012 at 6:15 AM, Grant Peel <gpeel [at] thenetnow>
> wrote:
> > > Hi all,
> > >
> > > The perl code below has is a file from a Webmin module used to
> interface
> with Exim, show stats manage queue etc. The issue is that the date does
> not
> decode properly. The code is quite old, and I have been hacking at it
> for
> weeks trying to get it to work correctly. I have attempted to contact
> the
> original developer, but suspect his email is not been checked.
> >
> > The code works fine in my limited testing.
>
> Actually, if you were to look at the result(s) in the webmin module, it
> does
> not work even closely. The Times and date are completely whacked...
>
> >
> > > I am posting to this list thinking perhaps some of you may have some
> expierence with the base62 encoding, and hopefully perl!
> > >
> > > If anyone would like to take a shot at it ....
> > >
> > > Example
> > > 1RkkUB-000CAI-Ce        is being decoded a s:         Sat Apr 23
> 16:10:52 2005
> > > which is not correct.
> >
> > Probably because you're passing the whole message id string to the
> > function instead of just the portion which is the datetime. Observe,
> > using your data:
>
> Sorry Todd, I am not passing anything, I did not write the code, a
> fellow
> named Alexander did. I tried to understand it but I think it is way
> above my
> head. I suspect I should take a sceen shot of the results, post that
> along
> with the whole module and see if anyone wants to take a shot at it...
>
> >
> > $ perl test.pl 1RkkUB-000CAI-Ce
> > Starting with 1RkkUB-000CAI-Ce
> > Reduced to 1RkkUB
> > Seconds since Jan 1 1970: 1326235687
> > Tue Jan 10 14:48:07 2012
> > Tue Jan 10 22:48:07 2012
> >
> > You have to strip all the extra cruft after and including the first
> > dash. Only the first 6 characters are significant for time
> > calculation.
> >
> > Experiment with this:
> >
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> >
> > my $id = shift() || '1Rmrv2-0001v1-T6';
> > print "Starting with $id\n";
> > my $tm;
> >
> > ($tm = $id) =~ s/^([0-9a-zA-Z]{6})-[0-9a-zA-Z]{6}-[0-9a-zA-
> > Z]{2}$/$1/ ? print "Reduced to $tm\n" : die ("Not proper format
> > of message ID"); print "Extracted time portion: $id\n";
> >
> > my $seconds = base62_to_decimal($id);
> > print "Seconds since Jan 1 1970: $seconds\n";
> > print scalar localtime($seconds),"\n";
> > print scalar gmtime($seconds),"\n";
> >
> > ...Todd
> > --
> > SOPA: Any attempt to [use legal means to] reverse technological
> > advances is doomed.  --Leo Leporte
> >
> > --
> > ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> > ## Exim details at http://www.exim.org/
> > ## Please use the Wiki with this list - http://wiki.exim.org/
>
>
> --
> ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/

--
Scanned by iCritical.
Attachments: Message.pm (3.76 KB)


gpeel at thenetnow

Jan 17, 2012, 6:27 AM

Post #6 of 8 (712 views)
Permalink
Re: Exim Webmin Module. [In reply to]

Nice Job Max, thanks a million!

I will submit to Jamie (hint,hint) and perhaps he will repackage the version
on the webmin site with your new (and improved) Message.pl

Dare I ask what part of the code was broken?

-G

On Tue, 17 Jan 2012 13:54:04 -0000, Caines, Max wrote
> Hi
>
> I put Webmin on our Exim servers recently, and did a fix myself. I
> enclose the fixed module, which is Message.pm, which on a default
> install is in /opt/webmin/exim/Exim
>
> Regards
>
> Max Caines
> University of Wolverhampton
>
> > -----Original Message-----
> > From: exim-users-bounces+max.caines=wlv.ac.uk [at] exim [mailto:exim-
> > users-bounces+max.caines=wlv.ac.uk [at] exim] On Behalf Of gpeel
> > Sent: 17 January 2012 00:05
> > To: Todd Lyons
> > Cc: exim-users [at] exim
> > Subject: Re: [exim] Exim Webmin Module.
> >
> > Hi Todd, thanks for the reply...please see below.
> >
> > On Mon, 16 Jan 2012 11:28:08 -0800, Todd Lyons wrote
> > > On Mon, Jan 16, 2012 at 6:15 AM, Grant Peel <gpeel [at] thenetnow>
> > wrote:
> > > > Hi all,
> > > >
> > > > The perl code below has is a file from a Webmin module used to
> > interface
> > with Exim, show stats manage queue etc. The issue is that the date does
> > not
> > decode properly. The code is quite old, and I have been hacking at it
> > for
> > weeks trying to get it to work correctly. I have attempted to contact
> > the
> > original developer, but suspect his email is not been checked.
> > >
> > > The code works fine in my limited testing.
> >
> > Actually, if you were to look at the result(s) in the webmin module, it
> > does
> > not work even closely. The Times and date are completely whacked...
> >
> > >
> > > > I am posting to this list thinking perhaps some of you may have some
> > expierence with the base62 encoding, and hopefully perl!
> > > >
> > > > If anyone would like to take a shot at it ....
> > > >
> > > > Example
> > > > 1RkkUB-000CAI-Ce        is being decoded a s:         Sat Apr 23
> > 16:10:52 2005
> > > > which is not correct.
> > >
> > > Probably because you're passing the whole message id string to the
> > > function instead of just the portion which is the datetime. Observe,
> > > using your data:
> >
> > Sorry Todd, I am not passing anything, I did not write the code, a
> > fellow
> > named Alexander did. I tried to understand it but I think it is way
> > above my
> > head. I suspect I should take a sceen shot of the results, post that
> > along
> > with the whole module and see if anyone wants to take a shot at it...
> >
> > >
> > > $ perl test.pl 1RkkUB-000CAI-Ce
> > > Starting with 1RkkUB-000CAI-Ce
> > > Reduced to 1RkkUB
> > > Seconds since Jan 1 1970: 1326235687
> > > Tue Jan 10 14:48:07 2012
> > > Tue Jan 10 22:48:07 2012
> > >
> > > You have to strip all the extra cruft after and including the first
> > > dash. Only the first 6 characters are significant for time
> > > calculation.
> > >
> > > Experiment with this:
> > >
> > > #!/usr/bin/perl
> > > use strict;
> > > use warnings;
> > >
> > > my $id = shift() || '1Rmrv2-0001v1-T6';
> > > print "Starting with $id\n";
> > > my $tm;
> > >
> > > ($tm = $id) =~ s/^([0-9a-zA-Z]{6})-[0-9a-zA-Z]{6}-[0-9a-zA-
> > > Z]{2}$/$1/ ? print "Reduced to $tm\n" : die ("Not proper format
> > > of message ID"); print "Extracted time portion: $id\n";
> > >
> > > my $seconds = base62_to_decimal($id);
> > > print "Seconds since Jan 1 1970: $seconds\n";
> > > print scalar localtime($seconds),"\n";
> > > print scalar gmtime($seconds),"\n";
> > >
> > > ...Todd
> > > --
> > > SOPA: Any attempt to [use legal means to] reverse technological
> > > advances is doomed.  --Leo Leporte
> > >
> > > --
> > > ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> > > ## Exim details at http://www.exim.org/
> > > ## Please use the Wiki with this list - http://wiki.exim.org/
> >
> >
> > --
> > ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> > ## Exim details at http://www.exim.org/
> > ## Please use the Wiki with this list - http://wiki.exim.org/
>
> --
> Scanned by iCritical.


--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


tlyons at ivenue

Jan 17, 2012, 6:29 AM

Post #7 of 8 (703 views)
Permalink
Re: Exim Webmin Module. [In reply to]

On Tue, Jan 17, 2012 at 6:27 AM, gpeel <gpeel [at] thenetnow> wrote:
> Nice Job Max, thanks a million!
>
> I will submit to Jamie (hint,hint) and perhaps he will repackage the version
> on the webmin site with your new (and improved) Message.pl
>
> Dare I ask what part of the code was broken?

return $$self{gmt} = gmtime base62_to_decimal ($$self{uli});

became

return $$self{gmt} = gmtime base62_to_decimal (substr($$self{uli}, 0, 6));

which strips everything after the 6th character.

...Todd
--
SOPA: Any attempt to [use legal means to] reverse technological
advances is doomed.  --Leo Leporte

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


tlyons at ivenue

Jan 17, 2012, 6:31 AM

Post #8 of 8 (699 views)
Permalink
Re: Exim Webmin Module. [In reply to]

On Mon, Jan 16, 2012 at 4:05 PM, gpeel <gpeel [at] thenetnow> wrote:
>> The code works fine in my limited testing.
>
> Actually, if you were to look at the result(s) in the webmin module, it does
> not work even closely. The Times and date are completely whacked...

My apologies, you specifically said that you thought the problem was
in the base62_to_decimal sub, so that's what I tested.

>> Probably because you're passing the whole message id string to the
>> function instead of just the portion which is the datetime.  Observe,
>> using your data:
>
> Sorry Todd, I am not passing anything, I did not write the code, a fellow
> named Alexander did. I tried to understand it but I think it is way above my
> head. I suspect I should take a sceen shot of the results, post that along
> with the whole module and see if anyone wants to take a shot at it...

You need to modify the gmt function so that it strips everything after
the first dash, like I did with my test program. Look how it works
below:

>> $ perl test.pl 1RkkUB-000CAI-Ce
>> Starting with 1RkkUB-000CAI-Ce
>> Reduced to 1RkkUB

>> You have to strip all the extra cruft after and including the first
>> dash.  Only the first 6 characters are significant for time
>> calculation.

Getting rid of all that extra stuff is what makes it work.

Regards... Todd
--
SOPA: Any attempt to [use legal means to] reverse technological
advances is doomed.  --Leo Leporte

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/

exim users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.