- # We're interested by unknown users quitting with Excess Flood message.
- if {![isfloodquitmessage $reason] || $handle != "*"} {
- return
- }
-
- # Botnet nicks have 3 to 5 characters
- set len [strlen $nick]
- if {$len < 3 || $len > 5} {
- return
- }
-
- # And belong to specific ISPs
- set host [gethost $uhost]
- if [isbotnetsuspecthost $host] {
- add_botnet_ban $host
- }
+ # We're interested by unknown users quitting with Excess Flood message.
+ if {![isfloodquitmessage $reason] || $handle != "*"} {
+ return
+ }
+
+ # Botnet nicks have 3 to 5 characters
+ set len [strlen $nick]
+ if {$len < 3 || $len > 5} {
+ return
+ }
+
+ # And belong to specific ISPs
+ set host [gethost $uhost]
+ if [isbotnetsuspecthost $host] {
+ add_botnet_ban $host
+ }
}
proc dcc:botnet {handle idx arg} {
- if {$arg == ""} {
- putdcc $idx "Usage: .botnet <nick>"
- return
- }
-
- set nick $arg
- set uhost [getchanhost $nick]
-
- if {$uhost == ""} {
- putdcc $idx "User unknown: $nick"
- return
- }
-
- set host [gethost $uhost]
- if [isbotnetsuspecthost $host] {
- add_botnet_ban $host
- return 1
- } {
- putdcc $idx "Not a botnet suspect."
- return
- }
+ if {$arg == ""} {
+ putdcc $idx "Usage: .botnet <nick>"
+ return
+ }
+
+ set nick $arg
+ set uhost [getchanhost $nick]
+
+ if {$uhost == ""} {
+ putdcc $idx "User unknown: $nick"
+ return
+ }
+
+ set host [gethost $uhost]
+ if [isbotnetsuspecthost $host] {
+ add_botnet_ban $host
+ return 1
+ } {
+ putdcc $idx "Not a botnet suspect."
+ return
+ }
}
proc add_botnet_ban {host} {
- global botname
+ global botname
- newchanban [registry get protection.botnet.channel] *!*@$host $botname [registry get protection.botnet.banreason] [registry get protection.botnet.banduration] sticky
- sql "INSERT INTO log_flood (host, `count`) VALUES ('[sqlescape $host]', 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;"
+ newchanban [registry get protection.botnet.channel] *!*@$host $botname [registry get protection.botnet.banreason] [registry get protection.botnet.banduration] sticky
+ sql "INSERT INTO log_flood (host, `count`) VALUES ('[sqlescape $host]', 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;"
# Determines if the Wikidata channel is Wikidata specific
# Wikidata channels allow commands for everyone, not only for D users.
proc isWikidataChannel {chan} {
- expr [lsearch [registry get wikidata.channels] $chan] != -1
+ expr [lsearch [registry get wikidata.channels] $chan] != -1
}
# Determines if the specified handle on the specified channel
# is allowed to run a Wikidata comamnd.
proc areWikidataCommandsAllowed {chan handle} {
- if {[matchattr $handle D]} {
- return 1
- }
+ if {[matchattr $handle D]} {
+ return 1
+ }
- isWikidataChannel $chan
+ isWikidataChannel $chan
}
# Handles .+surname command
proc pub:surname {nick uhost handle chan arg} {
- if {![areWikidataCommandsAllowed $chan $handle]} {
- return 0
- }
-
- if {[isAcceptableItemTitle $arg]} {
- create_surname $arg "serv $chan"
- return 1
- } {
- putserv "PRIVMSG $chan :$nick : ne sont gérés comme que les caractères alphanumériques, le tiret, l'apostrophe droite, de même que tout ce qui n'est pas ASCII standard."
- }
- return 0
+ if {![areWikidataCommandsAllowed $chan $handle]} {
+ return 0
+ }
+
+ if {[isAcceptableItemTitle $arg]} {
+ create_surname $arg "serv $chan"
+ return 1
+ } {
+ putserv "PRIVMSG $chan :$nick : ne sont gérés comme que les caractères alphanumériques, le tiret, l'apostrophe droite, de même que tout ce qui n'est pas ASCII standard."
+ }
+ return 0
}
# Handles .+surname command
proc dcc:surname {handle idx arg} {
- if {[isAcceptableItemTitle $arg]} {
- create_surname $arg "dcc $idx"
- return 1
- } {
- putdcc $idx "crée cet item manuellement, je ne suis pas conçu pour gérer ces caractères dans le titre."
- }
- return 0
+ if {[isAcceptableItemTitle $arg]} {
+ create_surname $arg "dcc $idx"
+ return 1
+ } {
+ putdcc $idx "crée cet item manuellement, je ne suis pas conçu pour gérer ces caractères dans le titre."
+ }
+ return 0
}
# Creates a surname
# @param $title the item title
# @param $state the state to pass to the create command callback (here with a mode and a target to print result)
#Checks if $username begins by a letter and contains only letters, digits, -, _ or .
proc tc2:username_isvalid {username} {
- regexp {^[A-Za-z][A-Za-z0-9_\-\.]*$} $username
+ regexp {^[A-Za-z][A-Za-z0-9_\-\.]*$} $username
}
#Determines if $username exists on the system
@@ -69,157 +69,157 @@
proc tc2:username_exists {username} {
#TODO: Windows and other OSes (this line has been tested under FreeBSD)
if {[exec -- logins -oxl $username] == ""} {
- return 0
+ return 0
} {
- return 1
+ return 1
}
}
#Gets server hostname
proc tc2:hostname {} {
- exec hostname -s
+ exec hostname -s
}
#Determines if $username is root
proc tc2:isroot {username} {
- #Validates input data
- set username [string tolower $username]
- if ![tc2:username_isvalid $username] {
- return 0
- }
-
- #Check 1 - User has local accreditation
- if ![sql "SELECT count(*) FROM tc2_roots WHERE account_username = '$username' AND server_name = '[sqlescape [tc2:hostname]]'"] {
- return 0
- }
-
- #Check 2 - User is in the group wheel on the server
- if {[lsearch [exec -- id -Gn $username] wheel] == "-1"} {
- return 0
- } {
- return 1
- }
+ #Validates input data
+ set username [string tolower $username]
+ if ![tc2:username_isvalid $username] {
+ return 0
+ }
+
+ #Check 1 - User has local accreditation
+ if ![sql "SELECT count(*) FROM tc2_roots WHERE account_username = '$username' AND server_name = '[sqlescape [tc2:hostname]]'"] {
+ return 0
+ }
+
+ #Check 2 - User is in the group wheel on the server
+ if {[lsearch [exec -- id -Gn $username] wheel] == "-1"} {
+ return 0
+ } {
+ return 1
+ }
}
#Determines if $requester is *EXPLICITELY* allowed to allowed to manage the account $user
#When you invoke this proc, you should also check if the user is root.
# e.g. if {[tc2:isroot $requester] || [tc2:userallow $requester $user]} { ... }
proc tc2:userallow {requester user} {
- set sql "SELECT count(*) FROM tc2_users_permissions WHERE server_name = '[sqlescape [tc2:hostname]]' AND account_username = '[sqlescape $user]' AND user_id = [getuserid $user]"
- putdebug $sql
- sql $sql
+ set sql "SELECT count(*) FROM tc2_users_permissions WHERE server_name = '[sqlescape [tc2:hostname]]' AND account_username = '[sqlescape $user]' AND user_id = [getuserid $user]"
+ putdebug $sql
+ sql $sql
}
#tc2:getpermissions on $username: Gets permissions on the $username account
#tc2:getpermissions from $username: Gets permissions $username have on server accounts
proc tc2:getpermissions {keyword username} {
- switch $keyword {
- "from" {
- set sql "SELECT account_username FROM tc2_users_permissions WHERE server_name = '[sqlescape [tc2:hostname]]' AND user_id = '[getuserid $username]'"
- }
- "on" {
- set sql "SELECT u.username FROM tc2_users_permissions p, users u WHERE p.server_name = '[sqlescape [tc2:hostname]]' AND p.account_username = '$username' AND u.user_id = p.user_id"
- }
- default {
- error "from or on expected"
- }
- }
- set accounts ""
- foreach row [sql $sql] {
- lappend accounts [lindex $row 0]
- }
+ switch $keyword {
+ "from" {
+ set sql "SELECT account_username FROM tc2_users_permissions WHERE server_name = '[sqlescape [tc2:hostname]]' AND user_id = '[getuserid $username]'"
+ }
+ "on" {
+ set sql "SELECT u.username FROM tc2_users_permissions p, users u WHERE p.server_name = '[sqlescape [tc2:hostname]]' AND p.account_username = '$username' AND u.user_id = p.user_id"
+ }
+ default {
+ error "from or on expected"
+ }
+ }
+ set accounts ""
+ foreach row [sql $sql] {
+ lappend accounts [lindex $row 0]
+ }
}
#Creates an account $username from the $specified group
proc tc2:createaccount {username group} {
- if {$group == "web"} {
- set key "tc2.[tc2:hostname].wwwroot"
- if {[set wwwroot [registry get $key]] == ""} {
- error "You must define the registry key $key"
- }
- set homedir $wwwroot/$username
- if [catch {
- set reply [exec -- pw user add $username -g $group -b $wwwroot -w random]
- exec -- mkdir -p -m 0711 $homedir
- exec -- chown -R $username:web $homedir
- } err] {
- append reply " / "
- append reply $err
- }
- return $reply
- } {
- exec -- pw user add $username -g $group -m -w random
- }
+ if {$group == "web"} {
+ set key "tc2.[tc2:hostname].wwwroot"
+ if {[set wwwroot [registry get $key]] == ""} {
+ error "You must define the registry key $key"
+ }
+ set homedir $wwwroot/$username
+ if [catch {
+ set reply [exec -- pw user add $username -g $group -b $wwwroot -w random]
+ exec -- mkdir -p -m 0711 $homedir
+ exec -- chown -R $username:web $homedir
+ } err] {
+ append reply " / "
+ append reply $err
+ }
+ return $reply
+ } {
+ exec -- pw user add $username -g $group -m -w random
+ }
}
#Checks if $username begins by a letter and contains only letters, digits, -, _ or .
- return "1 {$mandataire has now access to $username account.}"
- }
-
- "del" {
- #e.g. .account permission espacewin del dereckson
- # will remove access to the espacewin account to dereckson
- if {![tc2:isroot $requester] && ![tc2:userallow $requester $username]} {
- return "0 {you don't have the authority to manage the $username account.}"
- }
-
- #Asserts mandataire is a valid bot account
- set mandataire [lindex $arg 3]
- if {[set mandataire_user_id [getuserid $mandataire]] == ""} {
- return "0 {$mandataire doesn't have a bot account, and so, no such permission.}"
- }
-
- #Checks if the permission exists
- if ![tc2:userallow $requester $mandataire] {
- return "0 {$mandataire haven't had an access to $username account.}"
- }
-
- #Removess the permission
- sql "DELETE FROM tc2_users_permissions WHERE server_name = '[sqlescape [tc2:hostname]]' AND account_username = '$username' AND user_id = '$mandataire_user_id'"
-
- return "1 {$mandataire doesn't have access to $username account anymore.}"
- }
-
- "+root" {
- #Checks right and need
- if ![tc2:isroot $requester] {
- return "0 {you don't have root authority yourself.}"
- }
- if [tc2:isroot $username] {
- return "0 {$username have already root authority.}"
+ return "1 {$mandataire has now access to $username account.}"
+ }
+
+ "del" {
+ #e.g. .account permission espacewin del dereckson
+ # will remove access to the espacewin account to dereckson
+ if {![tc2:isroot $requester] && ![tc2:userallow $requester $username]} {
+ return "0 {you don't have the authority to manage the $username account.}"
+ }
+
+ #Asserts mandataire is a valid bot account
+ set mandataire [lindex $arg 3]
+ if {[set mandataire_user_id [getuserid $mandataire]] == ""} {
+ return "0 {$mandataire doesn't have a bot account, and so, no such permission.}"
+ }
+
+ #Checks if the permission exists
+ if ![tc2:userallow $requester $mandataire] {
+ return "0 {$mandataire haven't had an access to $username account.}"
+ }
+
+ #Removess the permission
+ sql "DELETE FROM tc2_users_permissions WHERE server_name = '[sqlescape [tc2:hostname]]' AND account_username = '$username' AND user_id = '$mandataire_user_id'"
+
+ return "1 {$mandataire doesn't have access to $username account anymore.}"
+ }
+
+ "+root" {
+ #Checks right and need
+ if ![tc2:isroot $requester] {
+ return "0 {you don't have root authority yourself.}"
+ }
+ if [tc2:isroot $username] {
+ return "0 {$username have already root authority.}"