123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- # CIMS: Community IRC Messaging Service
- # CIMS formerly known as MNET (Message Network)
- # Administration Script
- # Copyright (C) 2004 Paul-Dieter Klumpp
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # of the License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- # vim: expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
- namespace eval ::cims::admin {
- variable admin_channels {"#messagenet" "#quad.dev" "#qwnet"}
- variable mnet_admin_version "cims!A!1.14namespaced+savesettings"
- # include my/our little eggdrop utilities and helper library. ;-) Putils!
- if {[file isfile "scripts/cims/putils.tcl"] == 1} {
- source "scripts/cims/putils.tcl"
- }
- }
- # allowcheck for admin commands..
- proc ::cims::admin::allowed_channel {nick mask hand chan admin_channels} {
- global botnick botnet-nick lastbind
- putlog "mnet! = an admin command triggered triggered by $nick ($mask) in $chan"
- # the command must be from a channel of "ownchannels"
-
- putlog "mnet! = trying if $chan is an admin-channel"
- set found 0
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- foreach _try_chan $admin_channels {
- if {[string compare -nocase ${chan} ${_try_chan}] == 0} {
- putlog "mnet! = channel: ${chan} is allowed to administrate cims on this bot"
- set found 1
- } else {
- # putlog "mnet: = not in list: $chan"
- }
- }
- if {$found == 0} {
- putlog "mnet! = administration on ${chan} on this bot is not allowed"
- return 0
- }
-
- if {![isop ${nick} ${chan}]} {
- putlog "mnet! = allowed in ${chan}, but $nick is no op"
- ::putils::put_nick ${nick} "Sorry $nick, you are not an administrator here."
- return 0
- }
- if {${nick} == ${botnick}} {
- # no recursion :)
- return 0
- }
-
-
- # got through all checks .. so it's an OK channel
- return 1
- }
- proc ::cims::admin::check_addchannel {nick channel} {
- if {[botonchan ${channel}] == 1} {
- ::putils::put_nick ${nick} "Mnet! I added myself to the channel ${channel}"
- putlog "Mnet! I added myself to the channel ${channel}"
- } else {
- ::putils::put_nick ${nick} "Mnet! I tried to add myself to the channel ${value} - but failed! Pls check."
- putlog "Mnet! I tried to add myself to the channel ${value} - but failed! Pls check."
- }
- }
- proc ::cims::admin::rehashme {nick mask hand chan text} {
- variable admin_channels
- global botnet-nick
-
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
-
- set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
- if {$allowed == 0} {
- return 0
- }
- putlog "test"
- # rehash the bot... be sure the scripts are coded correctly!! or the bot will DIE!
- rehash
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" has rehashed and thus reloaded the mnet.tcl"
- }
- proc ::cims::admin::version {nick mask hand chan text} {
- variable admin_channels
- variable mnet_admin_version
-
- global botnet-nick
-
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
-
- set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
- if {$allowed == 0} {
- return 0
- }
-
- # tells version
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" Admin: $mnet_admin_version and Mnet is: $::cims::mnet(version)"
- }
- proc ::cims::admin::channelinfo {nick mask hand chan text} {
- variable admin_channels
- global botnet-nick
-
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
- if {$allowed == 0} {
- return 0
- }
-
- # tell channel infos
- set chan_list [channels]
- set chan_count [llength $chan_list]
- set output ""
- foreach _try_chan ${chan_list} {
- set q_missing_s ""
- set q_missing_e ""
- set userlist [chanlist "${_try_chan}"]
- set usercount [llength ${userlist}]
- #::putils::put_nick ${nick} "${_try_chan}: ${userlist} is -${usercount}- in length"
-
- if {[lsearch -exact ${userlist} Q] < 0} {
- #Q missing
- set q_missing_s ",5\002"
- set q_missing_e "\002"
- }
- if {${usercount} == 0} {
- # no users! someone banned us!
- set output "${output}\00313${_try_chan} ${usercount}\003, "
- } elseif {${usercount} <= 3} {
- # toooo few users .. channel dead?
- set output "${output}\00304${q_missing_s}${_try_chan} ${usercount}\003${q_missing_e}, "
- } elseif {${usercount} <=5} {
- # puh .. a bit more..
- set output "${output}\00308${q_missing_s}${_try_chan} ${usercount}\003${q_missing_e}, "
- } else {
- # a healthy channel .. > 5 users
- set output "${output}\00303${q_missing_s}${_try_chan} ${usercount}\003${q_missing_e}, "
- }
- }
-
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" has \002${chan_count}\002 channels: ${output}"
- }
- proc ::cims::admin::has_channelrecord {chan} {
-
- set channel_records [channels]
- foreach _try_chan $channel_records {
- if {${chan} == ${_try_chan}} {
- # found the channel in the records, go for it and return 1
- return 1
- } else {
- # putlog "mnet: = not in list: $chan"
- }
- }
-
- # not found till now? then return 0
- return 0
-
- }
- proc ::cims::admin::trylink_admin {} {
- global botnet-nick
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- set botslist [userlist b]
- foreach _try_bot $botslist {
- if {[islinked ${_try_bot}] == 0} {
- link ${_try_bot}
- }
- }
- return 0
- }
- proc ::cims::admin::trylink {nick mask hand chan text} {
- variable admin_channels
- global botnet-nick
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- set botslist [userlist b]
- set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
- if {$allowed == 0} {
- return 0
- }
- foreach _try_bot $botslist {
- if {[islinked ${_try_bot}] == 0} {
- set _try [link ${_try_bot}]
- if {$_try == 1} {
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" tries to link to \"${_try_bot}\""
- utimer 5 "::cims::admin::trylink_test ${_try_bot} ${nick}"
- }
- } else {
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" \00303already linked\003 to \"${_try_bot}\" - good."
- }
- }
- return 0
- }
- proc ::cims::admin::trylink_test {_try_bot nick} {
- variable admin_channels
- global botnet-nick
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- if {[islinked ${_try_bot}] == 1} {
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" \00309succeeded\003 to link to \"${_try_bot}\"! :)"
- } else {
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" \00304FAILED\003 to link to \"${_try_bot}\"! :("
- }
- }
- proc ::cims::admin::savesettings_admin {} {
- global botnet-nick botnick
- namespace eval ::cims {
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- ::putils::write_f_array "scripts/cims/save/${proper_botnick}_freqs" [array get mnet_freqs_onoff]
- ::putils::write_f_array "scripts/cims/save/${proper_botnick}_colors" [array get mnet_colors_onoff]
- }
- }
- proc ::cims::admin::savesettings {nick mask hand chan text} {
- variable admin_channels
- global botnet-nick botnick
-
- set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
- if {$allowed == 0} {
- return 0
- }
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
-
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" saves settings."
- namespace eval ::cims {
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- ::putils::write_f_array "scripts/cims/save/${proper_botnick}_freqs" [array get mnet_freqs_onoff]
- ::putils::write_f_array "scripts/cims/save/${proper_botnick}_colors" [array get mnet_colors_onoff]
- }
- }
- proc ::cims::admin::loadsettings_admin {} {
- global botnet-nick botnick
- namespace eval ::cims {
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- array set mnet_freqs_onoff [::putils::read_f_array "scripts/cims/save/${proper_botnick}_freqs"]
- array set mnet_colors_onoff [::putils::read_f_array "scripts/cims/save/${proper_botnick}_colors"]
- }
- }
- proc ::cims::admin::loadsettings {nick mask hand chan text} {
- variable admin_channels
- global botnet-nick botnick
-
- set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
- if {$allowed == 0} {
- return 0
- }
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
-
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" restores settings."
-
- namespace eval ::cims {
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- array set mnet_freqs_onoff [::putils::read_f_array "scripts/cims/save/${proper_botnick}_freqs"]
- array set mnet_colors_onoff [::putils::read_f_array "scripts/cims/save/${proper_botnick}_colors"]
- }
- }
- proc ::cims::admin::reload {nick mask hand chan text} {
- variable admin_channels
- global botnet-nick
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
- if {$allowed == 0} {
- return 0
- }
- set cmd "dummy"
- # reload config... be sure this script works or the bot will DIE!
- putlog "mnet! = reloading configs by admin"
- ::cims::dcc_configload ${cmd} ${cmd} ${cmd}
- ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" Configs reload triggered."
- }
- proc ::cims::admin::main {nick mask hand chan text} {
- variable admin_channels
- global botnet-nick
-
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
- if {$allowed == 0} {
- return 0
- }
-
- set tmp_cmd [lindex ${text} 0]
- set tmp_value [lindex ${text} 1]
-
-
- set cmd [string tolower [::putils::kill_spaces ${tmp_cmd}]]
- set value [string tolower [::putils::kill_spaces ${tmp_value}]]
-
- if {${cmd} == "add"} {
-
- # check $value ... if there
- if {${value} != ""} {
- # get channelrecord: ${value} if we don't have the record already:
- if {[::cims::admin::has_channelrecord ${value}] == 0} {
- channel add ${value}
- # save it
- savechannels
-
- # did it work?
- utimer 10 "::cims::admin::check_addchannel ${nick} ${value}"
- } else {
- ::putils::put_nick ${nick} "Mnet! Can't add again - I already have the channel ${value}"
- putlog "Mnet! Can't add again - I already have the channel ${value}"
- }
- } else {
- ::putils::put_nick ${nick} "Mnet! Can't add: no channel given"
- }
-
- return 0
- }
-
- if {${cmd} == "remove"} {
- # check $value ... if there
- if {${value} != ""} {
- # remove ${value} from bot, if we have a record for it.
- if {[::cims::admin::has_channelrecord ${value}] == 1} {
- channel remove ${value}
- savechannels
-
- ::putils::put_nick ${nick} "Mnet! I removed the channelrecord: ${value}"
- putlog "Mnet! I removed the channelrecord: ${value}"
- } else {
- ::putils::put_nick ${nick} "Mnet! Can't remove - I don't have that channelrecord: ${value}"
- putlog "Mnet! Can't remove - I don't have that channelrecord: ${value}"
- }
- } else {
- ::putils::put_nick ${nick} "Mnet! Can't remove: no channel given"
- }
-
- return 0
- }
- if {${cmd} == "reload"} {
- # reload network configs, pointing to procedure
- ::cims::admin::reload $nick $mask $hand $chan $text
- return 0
- }
- if {${cmd} == "channels"} {
- # tell channel infos, pointing to procedure
- ::cims::admin::channelinfo $nick $mask $hand $chan $text
- return 0
- }
- if {${cmd} == "rehash"} {
- # rehash
- ::cims::admin::rehashme $nick $mask $hand $chan $text
- return 0
- }
-
- if {${cmd} == "savesettings"} {
- # savesettings
- ::cims::admin::savesettings $nick $mask $hand $chan $text
- return 0
- }
- if {${cmd} == "loadsettings"} {
- # loadsettings
- ::cims::admin::loadsettings $nick $mask $hand $chan $text
- return 0
- }
- if {${cmd} == "version"} {
- # tells version
- ::cims::admin::version $nick $mask $hand $chan $text
- return 0
- }
-
- # none of the above worked .. so we are here:
- ::putils::put_nick ${nick} "mnet! possible commands are: add remove reload channels rehash version savesettings loadsettings"
- ::putils::put_nick ${nick} "mnet! use either \002!mnet_botnetnickname <command>\002 to admin a single bot or just \002!mnet_<command>\002 to admin ALL bots that listen to your words here."
- ::putils::put_nick ${nick} "add #channelname || bot joins a channel"
- ::putils::put_nick ${nick} "remove #channelname || bot parts a channel"
- ::putils::put_nick ${nick} "reload || reloads the mnet_configs"
- ::putils::put_nick ${nick} "channels || tells some channel-infos"
- ::putils::put_nick ${nick} "rehash || rehashes the bot, reloads all botscripts"
- ::putils::put_nick ${nick} "version || tells version"
- ::putils::put_nick ${nick} "savesettings || saves channel output settings to file"
- ::putils::put_nick ${nick} "loadsettings || restores channel output settings from file"
- }
- proc ::cims::admin::startup {} {
- variable mnet_admin_version
- global botnet-nick
- set proper_botnick [::putils::proper_botnick ${botnet-nick}]
- bind pub - !mnet_${proper_botnick} ::cims::admin::main
- bind pub - !mnet_reload ::cims::admin::reload
- bind pub - !mnet_channels ::cims::admin::channelinfo
- bind pub - !mnet_rehash ::cims::admin::rehashme
- bind pub - !mnet_version ::cims::admin::version
- bind pub - !mnet_trylink ::cims::admin::trylink
- bind pub - !mnet_savesettings ::cims::admin::savesettings
- bind pub - !mnet_loadsettings ::cims::admin::loadsettings
-
- ::cims::admin::loadsettings_admin
- utimer 10 "::cims::admin::trylink_admin"
- timer 1405 "::cims::admin::trylink_admin" 0
- timer 1205 "::cims::admin::savesettings_admin" 0
- putlog "mnet! = mnet adminscript loaded: $mnet_admin_version"
- }
- namespace eval ::cims::admin {
- # timer weil $botnet-nick nicht sofort von eggdrop gesetzt wird
- utimer 3 "::cims::admin::startup"
- }
|