diff options
author | Andreas Unterkircher <unki@netshadow.at> | 2008-12-03 20:37:13 +0100 |
---|---|---|
committer | Andreas Unterkircher <unki@netshadow.at> | 2008-12-12 18:36:55 +0100 |
commit | 0a6e4fae2c79d5f9da1033e0a51abfc69e10b8b2 (patch) | |
tree | 041b13746bede1eeceec181a8a00405e26d9db36 /exilog_util.pm | |
parent | 226ad0a3c764c0606048acf7371b02765eee60d2 (diff) | |
download | exilog-0a6e4fae2c79d5f9da1033e0a51abfc69e10b8b2.zip exilog-0a6e4fae2c79d5f9da1033e0a51abfc69e10b8b2.tar.gz exilog-0a6e4fae2c79d5f9da1033e0a51abfc69e10b8b2.tar.bz2 |
sort files into their directories. move agent- and cleanup-script into 'agents', all static www-content (icons, stylesheet, javascript, ...) into 'htdocs'. cgi-stuff into 'cgi' and all reused code into 'lib'.
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
Diffstat (limited to 'exilog_util.pm')
-rw-r--r-- | exilog_util.pm | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/exilog_util.pm b/exilog_util.pm deleted file mode 100644 index c50e679..0000000 --- a/exilog_util.pm +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/perl -w -# -# This file is part of the exilog suite. -# -# http://duncanthrax.net/exilog/ -# -# (c) Tom Kistner 2004 -# -# See LICENSE for licensing information. -# - -package exilog_util; -use Time::Local; -use POSIX qw( strftime ); -use strict; -use exilog_config; - -BEGIN { - use Exporter; - use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); - - # set the version for version checking - $VERSION = 0.1; - @ISA = qw(Exporter); - @EXPORT = qw( - &edt - &edv - &ina - &date_to_stamp - &stamp_to_date - &human_size - ); - - %EXPORT_TAGS = (); - - # your exported package globals go here, - # as well as any optionally exported functions - @EXPORT_OK = qw(); -} - - -# checks if scalar is in array -sub ina { - my $aref = shift || []; - my $str = shift || ""; - - unless (ref($aref) eq 'ARRAY') { - $aref = [ $aref ]; - }; - - foreach (@{ $aref }) { - return 1 if ($_ eq $str); - }; - return 0; -}; - - -# exists, defined and true (in perl sense) -sub edt { - my $h = shift; - my $hkey = shift; - return 0 unless (ref($h) eq 'HASH'); - return 1 if ( exists($h->{$hkey}) && - defined($h->{$hkey}) && - $h->{$hkey} ); - return 0; -}; - - -# exists, defined and valid (that is, not empty) -sub edv { - my $h = shift; - my $hkey = shift; - return 0 unless (ref($h) eq 'HASH'); - return 1 if ( exists($h->{$hkey}) && - defined($h->{$hkey}) && - $h->{$hkey} ne '' ); - return 0; -}; - - -sub date_to_stamp { - my $date = shift || ""; - my $tod = shift || "00:00:00"; - my ($year,$month,$mday) = split /\-/, $date; - my ($hour,$minute,$second,$junk) = split /[: ]/, $tod; - $year-=1900; - $month--; - - # This is for parsing timestamps that include GMT offsets - if (edv($junk)) { - my $hoff = ($junk =~ /[-+](\d\d)\d\d/); - my $moff = ($junk =~ /[-+]\d\d(\d\d)/); - if ($junk =~ /\+/) { - $hour = $hour - $hoff; - $minute = $minute - $moff; - } - else { - $hour = $hour + $hoff; - $minute = $minute + $moff; - } - }; - - if ($config->{web}->{timestamps} eq 'local') { - return timelocal($second,$minute,$hour,$mday,$month,$year); - } - else { - return timegm($second,$minute,$hour,$mday,$month,$year); - }; -}; - - -sub stamp_to_date { - my $stamp = shift; - my $no_seconds = shift || 0; - # convert to date/time string - if ($config->{web}->{timestamps} eq 'local') { - return ($no_seconds ? strftime("%Y-%m-%d %H:%M",localtime($stamp)) : strftime("%Y-%m-%d %H:%M:%S",localtime($stamp))); - } - else { - return ($no_seconds ? strftime("%Y-%m-%d %H:%M",gmtime($stamp)) : strftime("%Y-%m-%d %H:%M:%S",gmtime($stamp))); - }; -}; - -sub human_size { - my $size = shift; - my @units = ( '', 'k', 'M', 'G' ); - while ( ($size > 9999) && ((scalar @units) > 1) ) { - shift @units; - $size = int($size/1024); - }; - return $size.$units[0]; -}; - - -1; |