Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #http://192.168.1.254:9999/SysStatistics_ADSL.html
- bind pub -|- "!statszyxel" zyxel
- proc zyxel {nick host handle chan text} {
- set validargs [list "" -help -S -s -W -w -L -l -noise -noiset]
- set validargfound 0
- foreach i $validargs {
- if {$i==$text} {set validargfound 1}
- }
- if {$validargfound==0} {
- putquick "privmsg $chan :Invalid argument \002$text\002. Try -help for help."
- return
- }
- if {$text=="-help"} {
- putquick "privmsg $chan :ZyXEL script for eggdrop. Usage:"
- putquick "privmsg $chan : -s Displays System Monitor status only"
- putquick "privmsg $chan : -w Displays WAN Port Statistics status only"
- putquick "privmsg $chan : -n Displays LAN Port Statistics status only"
- putquick "privmsg $chan : <empty> Displays all the 3 items above together"
- putquick "privmsg $chan : -noise Displays DSL Line Status only"
- putquick "privmsg $chan : -noiset Displays DSL Line Status table-like only"
- return 0
- }
- package require http
- putquick "PRIVMSG $chan :Requesting and processing information, please wait..."
- set rzyxel ""
- http::config -useragent Mozilla
- if {![catch {http::geturl "http://192.168.1.254:9999/SysStatistics_ADSL.html" -timeout 10000} web]} {
- http::wait $web
- set rzyxel [http::data $web]
- http::cleanup $web
- }
- if {$rzyxel==""} {
- putquick "privmsg $chan :Acquire failed! Try again later."
- return
- }
- if {[regexp "Password" $rzyxel]==1} {
- putquick "privmsg $chan :Router asked to login. Doing it now..."
- set rzyxel ""
- set rquery [http::formatQuery LoginUsername admin LoginPassword ZyXEL+ZyWALL+Series hiddenPassword 33ea114683e0bdcee30763c9723bfcb2 Prestige_Login Login]
- if {![catch {http::geturl "http://192.168.1.254:9999/Forms/rpAuth_1" -query $rquery -timeout 10000} web]} {
- http::wait $web
- set rzyxel [http::data $web]
- http::cleanup $web
- }
- set rzyxel ""
- if {![catch {http::geturl "http://192.168.1.254:9999/SysStatistics_ADSL.html" -timeout 10000} web]} {
- http::wait $web
- set rzyxel [http::data $web]
- http::cleanup $web
- }
- if {$rzyxel==""} {
- putquick "privmsg $chan :Acquire failed! Try again later."
- return
- }
- if {[regexp "Password" $rzyxel]==1} {
- putquick "privmsg $chan :Login incorrect."
- return
- }
- }
- #set fd [open zyxel.txt w+]
- #puts $fd "$rzyxel"
- #close $fd
- if {($text=="-noise")||($text=="-noiset")} {
- set rzyxel ""
- set rquery [http::formatQuery LineInfoDisplay "" DiagDSLStatus DSL+Line+Status]
- set web [http::geturl "http://192.168.1.254:9999/Forms/DiagADSL_1" -query $rquery -timeout 10000]
- if {![catch {http::geturl "http://192.168.1.254:9999/DiagADSL.html" -timeout 10000} web]} {
- http::wait $web
- set rzyxel [http::data $web]
- http::cleanup $web
- }
- if {$rzyxel==""} {
- putquick "privmsg $chan :Nothing retrieved."
- return 0
- }
- set nmu [regexp -inline -all -- {noise margin upstream: (.*?) 0.1db} $rzyxel]
- set opd [regexp -inline -all -- {output power downstream: (.*?) 0.1db} $rzyxel]
- set aus [regexp -inline -all -- {attenuation upstream: (.*?) 0.1db} $rzyxel]
- set nmd [regexp -inline -all -- {noise margin downstream: (.*?) 0.1db} $rzyxel]
- set opu [regexp -inline -all -- {output power upstream: (.*?) 0.1db} $rzyxel]
- set ads [regexp -inline -all -- {attenuation downstream: (.*?) 0.1db} $rzyxel]
- if {$text=="-noise"} {
- putquick "privmsg $chan :[lindex $nmu 0]"
- putquick "privmsg $chan :[lindex $opd 0]"
- putquick "privmsg $chan :[lindex $aus 0]"
- putquick "privmsg $chan :[lindex $nmd 0]"
- putquick "privmsg $chan :[lindex $opu 0]"
- putquick "privmsg $chan :[lindex $ads 0]"
- }
- if {$text=="-noiset"} {
- putquick "privmsg $chan : Downstream Upstream"
- putquick "privmsg $chan :noise margin [expr {[lindex $nmd 1] *0.1}] [expr {[lindex $nmu 1] *0.1}]"
- putquick "privmsg $chan :attenuation [expr {[lindex $ads 1] *0.1}] [expr {[lindex $aus 1] *0.1}]"
- putquick "privmsg $chan :output power [expr {[lindex $opd 1] *0.1}] [expr {[lindex $opu 1] *0.1}]"
- }
- return 0
- }
- regsub -all -- {\{} $rzyxel {(} rzyxel
- regsub -all -- {\}} $rzyxel {)} rzyxel
- regsub -all -- {\"} $rzyxel {'} rzyxel
- regsub -all -- {\n} $rzyxel "" rzyxel
- set SystemUpTime [string trim [lindex [regexp -inline -- {<td width='30%'> System up Time: </td><td width='70%'> <b>(.*?)</b> </td>} $rzyxel] 1]]
- set CPUUsage [string trim [lindex [regexp -inline -- {<td>CPU Usage:</td><td><b>(.*?)</b></td>} $rzyxel] 1]]
- set MemoryUsage [string trim [lindex [regexp -inline -- {<td>Memory Usage:</td><td><b>(.*?)</b> </td>} $rzyxel] 1]]
- set LinkStatus [string trim [lindex [regexp -inline -- {<td width='30%'> Link Status:</td><td width='71%'><b>(.*?)</b></td></tr><tr>} $rzyxel] 1]]
- set WANIP [string trim [lindex [regexp -inline -- {<td>WAN IP Address:</td><td><b>(.*?)</b></td></tr><tr>} $rzyxel] 1]]
- set UpstremSpeed [string trim [lindex [regexp -inline -- {<td>Upstream Speed:</td><td><b>(.*?)</b></td></tr><tr>} $rzyxel] 1]]
- set DownstreamSpeed [string trim [lindex [regexp -inline -- {<td>Downstream Speed: </td><td><b>(.*?)</b></td></tr><tr>} $rzyxel] 1]]
- regsub -all -- {%} $CPUUsage {} cpuusagen
- regsub -all -- {%} $MemoryUsage {} memoryusagen
- set linkstat [lindex [regexp -inline -- {<td class='tabcolor2' > <div align=center> 1(.*?)</tr>} $rzyxel] 0]
- regsub -all -- { } $linkstat "" linkstat
- regsub -all -- {</tr>} $linkstat "" linkstat
- regsub -all -- {<tdclass='tabcolor2'><divalign=center>} $linkstat "" linkstat
- regsub -all -- {</div></td>} $linkstat " " linkstat
- set lanstat [lindex [regexp -inline -- {<td class='tabcolor2'> <div align=center> Ethernet(.*?)</table>} $rzyxel] 0]
- regsub -all -- { } $lanstat "" lanstat
- regsub -all -- {</tr>} $lanstat "" lanstat
- regsub -all -- {<tdclass='tabcolor2'><divalign=center>} $lanstat "" lanstat
- regsub -all -- {<tr><tdclass='TableItem'><divalign=center>} $lanstat "" lanstat
- regsub -all -- {<td><divalign=center>} $lanstat "" lanstat
- regsub -all -- {</div></td>} $lanstat " " lanstat
- regsub -all -- {</table>} $lanstat "" lanstat
- set systemuptimehms [split $SystemUpTime ":"]
- set systemuptimesecs [expr [regsub {^0*(.+)} [lindex $systemuptimehms 0] {\1}]*3600+[regsub {^0*(.+)} [lindex $systemuptimehms 1] {\1}]*60+[regsub {^0*(.+)} [lindex $systemuptimehms 2] {\1}]]
- set routerweb [http::geturl "http://192.168.1.254:9999/home.html" -timeout 3000]
- http::wait $routerweb
- set routermodeldata [http::data $routerweb]
- http::cleanup $routerweb
- regsub -all {\n} $routermodeldata "" routermodeldata
- set rzmodel ""
- set rzmodel [lindex [regexp -all -inline -- {<td>Model Number: </td><td colspan=\"2\" class=\"ds_text\">(.*?)</td></tr>} $routermodeldata] 1]
- set rdslmode [lindex [regexp -all -inline -- {DSL Mode: \</td\>\<td colspan=\"2\" class=\"ds_text\"\>(.*?)</td>} $routermodeldata] 1]
- if {($text=="") || ([lsearch -nocase $text "-s"]>=0)} {
- putquick "PRIVMSG $chan :\0031,14\002 System Monitor \002\003 \0037\002Model Number:\002\00311 ZyXEL$rzmodel \0037\002System Up Time:\002\00311 $SystemUpTime ([conv_s_wdhms $systemuptimesecs]) \002\0037CPU Usage:\002\003 [usagebar $cpuusagen 20] \002\0037Memory Usage:\002\003 [usagebar $memoryusagen 20]\003"
- }
- if {($text=="") || ([lsearch -nocase $text "-w"]>=0)} {
- putquick "PRIVMSG $chan :\0031,14\002 WAN Port Statistics \002\003 \0037\002Link Status:\002\00311 $LinkStatus \002\0037WAN IP Address:\002\00311 $WANIP \002\0037Upstream Speed:\002\00311 $UpstremSpeed \002\0037Downstream Speed:\002\00311 $DownstreamSpeed \002\0037DSL Modulation:\002\00311$rdslmode\003"
- putquick "PRIVMSG $chan :\002\0037Node-Link:\002\00311 [lindex $linkstat 0] \002\0037Status:\002\00311 [lindex $linkstat 1] \002\0037TxPkts:\002\00311 [lindex $linkstat 2] \002\0037RxPkts:\002\00311 [lindex $linkstat 3] \002\0037Errors:\002\00311 [lindex $linkstat 4] \002\0037Tx B/s:\002\00311 [lindex $linkstat 5] \002\0037Rx B/s:\002\00311 [lindex $linkstat 6] \002\0037Up Time:\002\00311 [lindex $linkstat 7]"
- }
- if {($text=="") || ([lsearch -nocase $text "-l"]>=0)} {
- putquick "PRIVMSG $chan :\0031,14\002 LAN Port Statistics \002\003"
- putquick "PRIVMSG $chan :Interface |Status |TxPkts |RxPkts |Collisions "
- putquick "PRIVMSG $chan :[format "%-11s|%-11s|%11s|%11s|%11s" [lindex $lanstat 0] [lindex $lanstat 1] [lindex $lanstat 2] [lindex $lanstat 3] [lindex $lanstat 4]]"
- putquick "PRIVMSG $chan :[format "%-11s|%-11s|%11s|%11s|%11s" [lindex $lanstat 5] [lindex $lanstat 6] [lindex $lanstat 7] [lindex $lanstat 8] [lindex $lanstat 9]]"
- return
- }
- }
- proc usagebar {percentage barwidth} {
- #set barx "[expr $barwidth * round($percentage) / 100]"
- #if {$barx == "0"} {set barx "1"}
- #set thebar "\00312[string repeat "█" $barx]\003"
- #set thebar "${thebar}\0032,1[string repeat "█" [expr $barwidth - $barx]]\003"
- #return $thebar
- return [pbardraw 20 [expr round($percentage)] 12 2 0 $percentage% ]
- }
- proc conv_s_wdhms {duration} {
- set outputtext ""
- set zw [expr $duration/604800]
- set duration [expr $duration-$zw*604800]
- set zd [expr $duration/86400]
- set duration [expr $duration-$zd*86400]
- set zh [expr $duration/3600]
- set duration [expr $duration-$zh*3600]
- set zm [expr $duration/60]
- set duration [expr $duration-$zm*60]
- set zs $duration
- if {$zw == 1} {append outputtext $zw "wk "}
- if {$zw > 1} {append outputtext $zw "wks "}
- if {$zd == 1} {append outputtext $zd "day "}
- if {$zd > 1} {append outputtext $zd "days "}
- if {$zh == 1} {append outputtext $zh "hr "}
- if {$zh > 1} {append outputtext $zh "hrs "}
- if {$zm == 1} {append outputtext $zm "min "}
- if {$zm > 1} {append outputtext $zm "mins "}
- if {$zs == 1} {append outputtext $zs "sec"}
- if {$zs > 1} {append outputtext $zs "secs"}
- return $outputtext
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement