whos-online.tcl
Displays who's currently online
- Location:
- /packages/acs-subsite/www/admin/system/whos-online.tcl
- Authors:
- Peter Marklund
- Gustaf Neumann <adapted for interaction with controlling thread>
- CVS ID:
$id: whos-online.tcl,v 1.1.1.1 2004/03/16 16:11:51 nsadmin exp $
Related Files
- packages/acs-subsite/www/admin/system/whos-online.tcl
- packages/acs-subsite/www/admin/system/whos-online.adp
[ hide source ] | [ make this the default ]
File Contents
ad_page_contract { Displays who's currently online @author Peter Marklund @author Gustaf Neumann (adapted for interaction with controlling thread) @cvs-id $id: whos-online.tcl,v 1.1.1.1 2004/03/16 16:11:51 nsadmin exp $ } -query { {orderby:optional} } -properties { title:onevalue context:onevalue } set title "Who's online?" set context [list "Who's online"] set whos_online_interval 10 # get value from package parameters set peer_groups [parameter::get -parameter peer-groups \ -default {*wlan* *dsl* *.com *.net *.org}] set admin [acs_user::site_wide_admin_p] #set admin 0 set template_elements { name { label "User Name" link_url_col url orderby name } online_time { label "Last Activity" html { align right } orderby online_time } } if {$admin} { append template_elements { activity { label "Activity" html { align right } orderby activity } hits { label "Hits" link_url_col detail_url orderby hits } switches { label "Switches" html { align center } orderby switches } peer_address { label "Peer" orderby peer_address } } foreach cat $peer_groups {set peer_cat_count($cat) 0} set peer_cat_count(others) 0 } template::list::create \ -name online_users \ -no_data "no registered users online" \ -elements $template_elements set users [list] proc ::my_hostname pa { if {[catch {set peer [ns_hostbyaddr $pa]}]} { return $pa } return "$peer ($pa)" #return "$peer" } foreach element [throttleThread do Users totalInfo] { lassign $element user_id pa timestamp hits smooth switches if {[string first . $user_id] > 0} { # it was an IP address continue } acs_user::get -user_id $user_id -array user set timestamp [lindex $smooth 2] set last_request_minutes [expr {[clock seconds]/60 - $timestamp}] set peer $pa if {$admin} { #catch {set peer [util_memoize [string tolower [list ::my_hostname $pa]]]} set match 0 foreach cat $peer_groups { if {[string match $cat $peer]} { incr peer_cat_count($cat) set match 1 break } } if {!$match} { incr peer_cat_count(others) append peer " ???" } } set loadparam "1m=[lindex $smooth 3], 10m=$hits" set detail_url "last-requests?request_key=$user_id" lappend users [list "$user(last_name), $user(first_names)" \ [acs_community_member_url -user_id $user_id] \ $last_request_minutes "$last_request_minutes minutes ago" \ [format %.2f [lindex $smooth 0]] \ $hits $loadparam $detail_url \ $switches \ $peer] } set orderby [ns_queryget orderby "name,asc"] switch -glob $orderby { *,desc {set order -decreasing} *,asc {set order -increasing} } switch -glob $orderby { name,* {set index 0; set type -dictionary} online_time,* {set index 2; set type -integer} activity,* {set index 4; set type -real} hits,* {set index 5; set type -dictionary} switches,* {set index 8; set type -integer} peer_address,* {set index 9; set type -dictionary} } if {$admin} { multirow create online_users name url online_time \ activity hits detail_url switches peer_address set total $peer_cat_count(others) foreach cat $peer_groups {incr total $peer_cat_count($cat)} set summarize_categories "$total users logged in from: " foreach cat $peer_groups { append summarize_categories "$cat [format %.2f [expr {$peer_cat_count($cat)*100.0/$total}]]%, " } append summarize_categories "others [format %.2f [expr {$peer_cat_count(others)*100.0/$total}]]%. " } else { set summarize_categories "" multirow create online_users name url online_time } foreach e [lsort $type $order -index $index $users] { multirow append online_users \ [lindex $e 0] \ [lindex $e 1] \ [lindex $e 3] \ [lindex $e 4] \ [lindex $e 6] \ [lindex $e 7] \ [lindex $e 8] \ [lindex $e 9] \ }