[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tcldrop/CVS] tcldrop/modules core.tcl
From: |
Philip Moore |
Subject: |
[Tcldrop/CVS] tcldrop/modules core.tcl |
Date: |
Fri, 21 Nov 2003 21:52:38 -0500 |
CVSROOT: /cvsroot/tcldrop
Module name: tcldrop
Branch:
Changes by: Philip Moore <address@hidden> 03/11/21 21:52:37
Modified files:
modules : core.tcl
Log message:
Added the [traffic] command, which is able to both increase traffic
counts and return them.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/tcldrop/tcldrop/modules/core.tcl.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
Patches:
Index: tcldrop/modules/core.tcl
diff -u tcldrop/modules/core.tcl:1.19 tcldrop/modules/core.tcl:1.20
--- tcldrop/modules/core.tcl:1.19 Fri Nov 21 17:26:34 2003
+++ tcldrop/modules/core.tcl Fri Nov 21 21:52:36 2003
@@ -1,6 +1,6 @@
# core.tcl --
#
-# $Id: core.tcl,v 1.19 2003/11/21 22:26:34 fireegl Exp $
+# $Id: core.tcl,v 1.20 2003/11/22 02:52:36 fireegl Exp $
#
# Copyright (C) 2003 FireEgl (Philip Moore) <address@hidden>
#
@@ -47,13 +47,15 @@
# Provide the users module:
variable version {0.3}
package provide tcldrop::core $version
- variable rcsid {$Id: core.tcl,v 1.19 2003/11/21 22:26:34 fireegl Exp $}
+ variable rcsid {$Id: core.tcl,v 1.20 2003/11/22 02:52:36 fireegl Exp $}
# Initialize variables:
variable Binds
variable Timers
variable TimerIDCount 1
+ variable Traffic
+ array set Traffic {}
# Export all the commands that should be available to 3rd-party
scripters:
- namespace export bind unbind binds timer utimer killtimer killutimer
timers utimers maskhost isbotnetnick logfile
+ namespace export bind unbind binds timer utimer killtimer killutimer
timers utimers maskhost isbotnetnick logfile traffic
}
# Add our modules directory to the package require search path:
@@ -477,6 +479,45 @@
}
proc ::tcldrop::isbotnetnick {nick} { string equal -nocase $nick
${::botnet-nick} }
+
+proc ::tcldrop::traffic {{type {*}} {direction {}} {bytes {0}}} {
+ variable Traffic
+ if {$type != {*}} {
+ if {[info exists Traffic($type)]} {
+ # Set the info array to the current counts.
+ array set info $Traffic($type)
+ } else {
+ # Initialize the counts.
+ array set info [list total-in 0 total-out 0 daily-in 0
daily-out 0 restart [unixtime]]
+ }
+ # Increase the counters:
+ if {($bytes) && ($direction == {in} || $direction == {out})} {
+ array set info [list total-$direction [incr
info(total-$direction) $bytes] daily-$direction [incr info(daily-$direction)
$bytes]]
+ }
+ # See if 24 hours have elapsed, and if it has then clear the
daily counts.
+ if {[expr { [unixtime] - $info(restart) > 86400 }]} {
+ array set info [list daily-in 0 daily-out 0 restart
[unixtime]]
+ }
+ # Write the new counts back to the Traffic variable:
+ set Traffic($type) [array get info]
+ if {$direction == {in} || $direction == {out}} {
+ # Return either in or out for $type:
+ list $info(daily-$direction) $info(total-$direction)
+ } else {
+ # Return both directions for $type:
+ list $info(daily-in) $info(total-in) $info(daily-out)
$info(total-out)
+ }
+ } else {
+ # Show them all the traffic stats.
+ set out [list]
+ foreach t [array names Traffic] {
+ array set info $Traffic($t)
+ lappend out [list $t $info(daily-in) $info(total-in)
$info(daily-out) $info(total-out)]
+ }
+ return $out
+ }
+}
+
# Import the core tcldrop commands to the global namespace:
#namespace import -force {::tcldrop::*}