debugserv.tcl (6837B)
1 blocktnd debugserv 2 3 set debugservunbindalive [llbind - evnt - alive debugserv.connect] 4 set debugservunbindrehash [llbind - evnt - confloaded debugserv.reload] 5 set debugservunbindlogall [llbind - logall - - debug.logall] 6 7 proc debug.logall {netzwerk charakter canal args} { 8 puts stdout [format "%s loglevel %s on %s@%s: %s" "DEBUGSERV" $charakter $canal $netzwerk [join $args]] 9 } 10 11 proc debugserv.reload {arg} { 12 set blocks [tnda get "openconf/[ndcenc debugserv]/blocks"] 13 putlog "debugserv:blocks $blocks" 14 for {set i 1} {$i < ($blocks + 1)} {incr i} { 15 set netname [string tolower [lindex [tnda get [format "openconf/%s/hdr%s" [ndcenc debugserv] $i]] 0]] 16 if {[catch {set ::sock($netname)} result] == 0} { 17 if {![eof $::sock($netname)]} { 18 # connect bind will be called when we reconnect 19 after 1000 [list debugserv.oneintro [tnda get [format "openconf/%s/hdr%s" [ndcenc debugserv] $i]] [tnda get [format "openconf/%s/n%s" [ndcenc debugserv] $i]]] 20 } 21 } 22 } 23 } 24 25 proc debugserv.connect {arg} { 26 set blocks [tnda get "openconf/[ndcenc debugserv]/blocks"] 27 for {set i 1} {$i < ($blocks + 1)} {incr i} { 28 if {[string tolower [lindex [tnda get [format "openconf/%s/hdr%s" [ndcenc debugserv] $i]] 0]] != [string tolower $arg]} {continue} 29 after 1000 [list debugserv.oneintro [tnda get [format "openconf/%s/hdr%s" [ndcenc debugserv] $i]] [tnda get [format "openconf/%s/n%s" [ndcenc debugserv] $i]]] 30 } 31 } 32 33 proc debugserv.find6sid {n s {hunting 0}} { 34 # we're trying to get the sid of the server named $s 35 # if hunting, we're looking for the first splat match 36 set servs [tnda get "servers/$n"] 37 foreach {.k dv} $servs { 38 set k [string toupper [ndadec ${.k}]] 39 # name description uplink sid - we only need two 40 dictassign $dv name sname 41 if {$hunting} { 42 if {[string match [string tolower $s] [string tolower $sname]] == 1} {return $k} 43 } { 44 if {[string tolower $s] == [string tolower $sname]} {return $k} 45 } 46 } 47 return "" 48 } 49 50 proc debugservenabled {chan} { 51 if {[string tolower $chan] != [string tolower [tnda get "debugserv/[curctx net]/logchan"]]} {return 0} 52 return 1 53 } 54 55 proc debugserv.armdns {headline block} { 56 57 } 58 59 proc debugserv.oneintro {headline block} { 60 set net [lindex $headline 0] 61 set nsock $::sock($net) 62 lassign [list debugserv DebugServ DebugServ services.invalid +oi "Default Realname - UNCONFIGURED!" "oper:admin" "oper:tcl"] dbname nick ident host modes realname rehashprivs tclprivs 63 dictassign $block logchan logchan nick nick ident ident host host modes modes realname realname rehashprivs rehashprivs idcommand nspass nickserv nickserv nsserv nsserv \ 64 dnsconf dnsconf dbname dbname 65 tnda set "debugserv/$net/rehashprivs" $rehashprivs 66 tnda set "debugserv/$net/tclprivs" $tclprivs 67 tnda set "debugserv/$net/logchan" $logchan 68 #tnda set "debugserv/$net/nspass" $nspass 69 setctx $net 70 if {[% intclient2uid [tnda get "debugserv/$net/ourid"]] == ""} {% sendUid $nick $ident $host $host [set ourid [% getfreeuid]] [expr {($realname == "") ? "* Debug Service *" : $realname}] $modes} { 71 set quitting 0 72 foreach {confitem} [list nick ident host realname modes] { 73 if {[catch {dict get [tnda get "debugserv/$net/block"] $confitem}] == 0} { 74 if {[dict get [tnda get "debugserv/$net/block"] $confitem] != [set $confitem]} { 75 set quitting 1 76 } 77 } 78 } 79 if {$quitting} { 80 % quit $ourid "REHASHED; RESTARTING TO APPLY NEW CONFIG" 81 % sendUid $nick $ident $host $host [set ourid [% getfreeuid]] [expr {($realname == "") ? "* Debug Service *" : $realname}] $modes 82 } 83 } 84 tnda set "debugserv/$net/block" $block 85 set ouroid [tnda get "debugserv/$net/ourid"] 86 if {[info exists ourid]} {tnda set "debugserv/$net/ourid" $ourid} {set ourid [tnda get "debugserv/$net/ourid"]} 87 unllbindall $nsock pub - ".rehash" 88 unllbindall $nsock pub - ".metadata" 89 unllbindall $nsock msg $ourid "rehash" 90 unllbindall $nsock msg $ourid "metadata" 91 if {$ouroid != $ourid} { 92 unllbindall $nsock msg $ouroid "rehash" 93 unllbindall $nsock msg $ouroid "metadata" 94 } 95 setuctx $nick 96 llbind $nsock pub - ".metadata" [list debugserv.pmetadata $net] 97 if {[string length $nspass] != 0 && [string length $nickserv] != 0} { 98 # only works if nettype is ts6! 99 if {[string first [debugserv.find6sid $net $nsserv] [% nick2uid $nickserv]] == 0} { 100 % privmsg $ourid $nickserv $nspass 101 } { 102 % privmsg $ourid $logchan [gettext debugserv.impostornickserv $nickserv [% nick2uid $nickserv] $nsserv [debugserv.find6sid $net $nsserv]] 103 } 104 } 105 after 650 % putjoin $ourid $logchan 106 after 700 [list % putmode $ourid $logchan "+ao" [format "%s %s" [% intclient2uid $ourid] [% intclient2uid $ourid]]] 107 108 llbind $nsock msg [tnda get "debugserv/$net/ourid"] "metadata" [list debugserv.metadata $net] 109 llbind $nsock msg [tnda get "debugserv/$net/ourid"] "rehash" [list debugserv.rehash $net] 110 # llbind $nsock pub - "gettext" [list debugserv.gettext $net] 111 llbind $nsock pub - ".rehash" [list debugserv.crehash $net] 112 llbind $nsock pub - "!usage" [list debugserv.pusage $net] 113 debugserv.armdns $headline $dnsconf 114 puts stdout "llbind $nsock msg [tnda get "debugserv/$net/ourid"] metadata [list debugserv.metdata $net]" 115 puts stdout [format "Connected for %s: %s %s %s" $net $nick $ident $host] 116 } 117 118 proc debugserv.pusage {n i c m} { 119 set uptime [exec uptime] 120 % [expr {$c != $i ? "privmsg" : "notice"}] [tnda get "debugserv/$n/ourid"] $c $uptime 121 } 122 123 proc debugserv.rehash {n i m} {debugserv.crehash $n $i $i $m} 124 125 proc debugserv.crehash {n i c m} { 126 putloglev o * "debugserv.crehash $n $c $i $m" 127 if {![operHasPrivilege $n $i [tnda get "debugserv/$n/rehashprivs"]]} { 128 putloglev d * "no privilege reached" 129 % [expr {$c != $i ? "privmsg" : "notice"}] [tnda get "debugserv/$n/ourid"] $c [gettext debugserv.youvenoprivs2 $i [join [split [tnda get "debugserv/$n/rehashprivs"] ", "] ", or "]] 130 } { 131 % [expr {$c != $i ? "privmsg" : "notice"}] [tnda get "debugserv/$n/ourid"] $c [gettext debugserv.rehashed [% uid2nick $i]] 132 putloglev d * "svc.rehash reached" 133 after 500 [list uplevel #0 [list svc.rehash]] 134 } 135 } 136 137 proc debugserv.pmetadata {n i c m} { 138 # net chan id msg 139 setctx $n 140 if {($c != $i) && ![debugservenabled $c]} {return} 141 set metadatalist [tnda get "metadata/$n/$i"] 142 if {[llength $metadatalist] < 2} { 143 % [expr {$c != $i ? "privmsg" : "notice"}] [tnda get "debugserv/$n/ourid"] $c [gettext debugserv.nometadata [% uid2nick $i]] 144 } 145 foreach {.datum value} $metadatalist { 146 set datum [ndcdec ${.datum}] 147 % [expr {$c != $i ? "privmsg" : "notice"}] [tnda get "debugserv/$n/ourid"] $c [set totmsg [gettext debugserv.metadata $datum [% uid2nick $i] $value]] 148 } 149 % [expr {$c != $i ? "privmsg" : "notice"}] [tnda get "debugserv/$n/ourid"] $c [gettext [expr {[tnda get "oper/$n/$i"] == 1 ? "debugserv.isoper" : "debugserv.isntoper"}] [% uid2nick $i] $i] 150 } 151 152 proc debugserv.metadata {n i m} { 153 debugserv.pmetadata $n $i $i $m 154 } 155