+- Communauté Eggdrop (https://forum.eggdrop.fr)
+-- Forum : Eggdrop et scripts (https://forum.eggdrop.fr/forumdisplay.php?fid=8)
+--- Forum : Scripts (https://forum.eggdrop.fr/forumdisplay.php?fid=4)
+--- Sujet : Amélioration d'un script pour le rendre plus performant (/showthread.php?tid=1803)
Amélioration d'un script pour le rendre plus performant - Amand - 26/09/2024
Hello à tous,
j'ai besoin d'optimiser un script pour le rendre plus performant :
tcl
# Regexp connection user set ::checkpays::regexpclientco{:\ (.*)\ \((.*?)@(.*?)\) \[(.*?)\] \[vhost: (.*?)\](.*)\ \[country: (.*?)\] \[asn: (.*?)\] \[asname: (.*?)\] \[reputation: (.*?)\](.+)}
# Realname age sexeset ::checkpays::regexpagesex{^\d{1,2}[HFM]( .+)?}
# regexp pour match les ados de 12 à 17ansset ::checkpays::regexpado{(1[2-7])(H|F|M)}
############################################# PROC TRAITEMENT CONNECTING #############################################proc ::checkpays::who:co {from keyword text}{if{![string match -nocase "*Client connecting*"$text]}{return;}set sslco 0set webirc 0set websocket 0set unknow 0set account 0regexp$::checkpays::regexpclientco$text - nick username ip ipdns vhost csa codepays asn asname reputation other
# IP Exceptif{$ip eq "127.0.0.1" || [isbotnick $nick]}{return}set SESSION [md5 "${username}@${vhost}"]if{[string match -nocase "*tls-users*"$other]}{set sslco 1}if{[string match -nocase "*webirc-users*"$other]}{set webirc 1}if{[string match -nocase "*websocket-users*"$other]}{set websocket 1}if{[string match -nocase "*unknown-users*"$other]}{set unknow 1}if{[string match -nocase "*account:*"$csa]}{set account 1}
# On met en mémoire les valeurs qu'on ne récupère pas dans le whoset ::checkpays::DB($SESSION,IP)$ipset ::checkpays::DB($SESSION,IPDNS)$ipdnsset ::checkpays::DB($SESSION,CODEPAYS)$codepaysset ::checkpays::DB($SESSION,ASN)$asnset ::checkpays::DB($SESSION,ASNAME)$asnameset ::checkpays::DB($SESSION,REPUTATION)$reputationset ::checkpays::DB($SESSION,SSLCO)$sslcoset ::checkpays::DB($SESSION,WEBIRC)$webircset ::checkpays::DB($SESSION,WEBSOCKET)$websocketset ::checkpays::DB($SESSION,UNKNOW)$unknowset ::checkpays::DB($SESSION,ACCOUNT)$account
putnow "WHO $nick %unhr"}proc ::checkpays::who:gestion {from key text}{set text [split[string trim $text]]
lassign $text{} username vhost nick
set SESSION [md5 "${username}@${vhost}"]set realname [join[lrange[split$text{:}]1 end]]
## On recupere les variables en mémoireset ip $::checkpays::DB($SESSION,IP)set ipdns $::checkpays::DB($SESSION,IPDNS)set sslco $::checkpays::DB($SESSION,SSLCO)set webirc $::checkpays::DB($SESSION,WEBIRC)set websocket $::checkpays::DB($SESSION,WEBSOCKET)set reputation $::checkpays::DB($SESSION,REPUTATION)set codepays $::checkpays::DB($SESSION,CODEPAYS)set asn $::checkpays::DB($SESSION,ASN)set asname $::checkpays::DB($SESSION,ASNAME)set unknow $::checkpays::DB($SESSION,UNKNOW)set account $::checkpays::DB($SESSION,ACCOUNT)
# Nick/Ip/Ident EXCEPTIONif{[::toolsAmand::verify:b $::checkpays::fichier(ident)$username]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - IDENT\003\002 \002\[\002$codepays\002\]\002 - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocketreturn}elseif{[::toolsAmand::verify:b $::checkpays::fichier(pseudo)$nick]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - PSEUDO\003\002 \002\[\002$codepays\002\]\002 - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocketreturn}elseif{[::toolsAmand::verify:b $::checkpays::fichier(ip)$ip]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - IP\003\002 \002\[\002$codepays\002\]\002 - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocketreturn}else{}
# On envoie à la proc de traitement
::checkpays::traitement$nick$username$ip$ipdns$vhost$codepays$asn$asname$reputation$sslco$webirc$websocket$unknow$realname$account
# Changement du realname en ASV / Redirection adosif{[regexp$::checkpays::regexpagesex$realname]!= 1}{
putnow "CHGNAME $nick [expr 18 + int(rand()*72)] M"
putnow "PRIVMSG $::checkpays::backpaysredirect :\002\00300,02REALNAME\003\002 - \002$nick\002 \[$codepays\] ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Account: $account) (Asn: $asn) (Asname: $asname) vient d'être changé. Realname: $realname"}elseif{[regexp$::checkpays::regexpado$realname] == 1}{
putnow "PRIVMSG OperServ :SVSJOIN $nick $::checkpays::salonado"
putnow "SAUMODE $nick +R" #putnow "PRIVMSG $::checkpays::backpaysredirect :\002\0030,6ADO\002\003 - \002$nick\002 ($username@$ip) a été redirigé sur \002$::checkpays::salonado\002 - \002Realname:\002 $realname"}else{}}proc ::checkpays::traitement{nick username ip ipdns vhost codepays asn asname reputation sslco webirc websocket unknow realname account}{set SESSION [md5 "${username}@${vhost}"]set ALLEXCEPTIONS [list{*}$::checkpays::PAYSINTERDIT{*}$::checkpays::PAYSINTERDITNWSI{*}$::checkpays::PAYSINTERDITNW{*}$::checkpays::PAYSIPAPI{*}$::checkpays::PAYSEXCEPTION]set sanction 0
# IP-API
# Bloquer IPAPI Proxy/Hosting - IPABUSEIPDBif{[lsearch$::checkpays::PAYSIPAPI$codepays]!=-1}{
::checkpays::infoAPI$nick$username$ip$ipdns$unknow$reputation$realname$webirc$websocket$account}
# Traitementif{[lsearch$::checkpays::PAYSINTERDIT$codepays]!= -1}{set sanction 1
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,4PAYS BLOQUÉ\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"}elseif{([lsearch$::checkpays::PAYSINTERDITNWSI$codepays]!= -1)&&($webirc == 0)&&($websocket == 0)&&($reputation<200)}{set sanction 1
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,12PAYS BLOQUÉ - HORS WEB|RÉPUTATION\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"}elseif{([lsearch$::checkpays::PAYSINTERDITNW$codepays]!= -1)&&($webirc == 0)&&($websocket == 0)}{set sanction 1
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,6PAYS BLOQUÉ - HORS WEB\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"}elseif{($codepays eq "US") || ([string match "*.irccloud.com"$ip])}{set sanction 1
putnow "GLINE $username@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,10IRCCloud|US\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"}else{
# Si on entre pas dans une condition blacklisté on envoie à la proc du monitoring
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket}
# Vérification si le codepays est hors liste interdit/protégéif{[lsearch$ALLEXCEPTIONS$codepays]==-1}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,14USER SUSPECT\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::infoAPI$nick$username$ip$ipdns$unknow$reputation$realname$webirc$websocket$account
::checkpays::infoABUSEIPDB$nick$username$ipdns}
# Suppression des valeurs en mémoire. # https://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl/unset.n.html
unset ::checkpays::DB($SESSION,IP)
unset ::checkpays::DB($SESSION,IPDNS)
unset ::checkpays::DB($SESSION,REPUTATION)
unset ::checkpays::DB($SESSION,SSLCO)
unset ::checkpays::DB($SESSION,WEBIRC)
unset ::checkpays::DB($SESSION,CODEPAYS)
unset ::checkpays::DB($SESSION,WEBSOCKET)
unset ::checkpays::DB($SESSION,ASN)
unset ::checkpays::DB($SESSION,ASNAME)
unset ::checkpays::DB($SESSION,UNKNOW)
unset ::checkpays::DB($SESSION,ACCOUNT)if{$sanction == 1}{return}}
Il manque des variables/fonctions, j'ai mis les lignes essentiels pour faire un focus sur la problématique et de la partie qui doit être optimiser.
Il est fonctionnel, mais je pense qu'on peut faire largement mieux pour le rendre plus fluide , si vous avez des idées, welcome.
RE: Amélioration d'un script pour le rendre plus performant - Amand - 27/09/2024
Grâce à CrazyCat sur le channel irc #eggdrop , j'ai pu apporter pas mal d'améliorations :
tcl
proc ::checkpays::who:co {from keyword text}{if{![string match -nocase "*Client connecting*"$text]}{return;}set sslco 0set webirc 0set websocket 0set unknow 0set account 0regexp$::checkpays::regexpclientco$text - nick username ip ipdns vhost csa codepays asn asname reputation other
# IP Exceptif{$ip eq "127.0.0.1" || [isbotnick $nick]}{return}set SESSION [md5 "${username}@${vhost}"]if{[string match -nocase "*tls-users*"$other]}{set sslco 1}if{[string match -nocase "*webirc-users*"$other]}{set webirc 1}if{[string match -nocase "*websocket-users*"$other]}{set websocket 1}if{[string match -nocase "*unknown-users*"$other]}{set unknow 1}if{[string match -nocase "*account:*"$csa]}{set account 1}
# On met en mémoire les valeurs qu'on ne récupère pas dans le whoset ::checkpays::DB($SESSION)[list$ip$ipdns$codepays$asn$asname$reputation$sslco$webirc$websocket$unknow$account]
putlog "who => $::checkpays::DB($SESSION)"
putnow "WHO $nick %unhr"}proc ::checkpays::who:gestion {from key text}{set text [split[string trim $text]]
lassign $text{} username vhost nick
set SESSION [md5 "${username}@${vhost}"]set realname [join[lrange[split$text{:}]1 end]]
## On recupere les variables en mémoire
lassign $::checkpays::DB($SESSION) ip ipdns codepays asn asname reputation sslco webirc websocket unknow account
putlog "gestion => $::checkpays::DB($SESSION)"
# Nick/Ip/Ident EXCEPTIONif{[::toolsAmand::verify:b $::checkpays::fichier(ident)$username]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - IDENT\003\002 \002\[\002$codepays\002\]\002 - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}elseif{[::toolsAmand::verify:b $::checkpays::fichier(pseudo)$nick]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - PSEUDO\003\002 \002\[\002$codepays\002\]\002 - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}elseif{[::toolsAmand::verify:b $::checkpays::fichier(ip)$ip]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - IP\003\002 \002\[\002$codepays\002\]\002 - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}
# On envoie à la proc de traitement
::checkpays::traitement$nick$username$ip$ipdns$vhost$codepays$asn$asname$reputation$sslco$webirc$websocket$unknow$realname$account
# Changement du realname en ASVif{[regexp$::checkpays::regexpagesex$realname]!= 1}{
putnow "CHGNAME $nick [expr 18 + int(rand()*72)] M"
putnow "PRIVMSG $::checkpays::backpaysredirect :\002\00300,02REALNAME\003\002 - \002$nick\002 \[$codepays\] ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Account: $account) (Asn: $asn) (Asname: $asname) vient d'être changé. Realname: $realname"}elseif{[regexp$::checkpays::regexpado$realname] == 1}{
putnow "PRIVMSG OperServ :SVSJOIN $nick $::checkpays::salonado"}}proc ::checkpays::traitement{nick username ip ipdns vhost codepays asn asname reputation sslco webirc websocket unknow realname account}{set SESSION [md5 "${username}@${vhost}"]set ALLEXCEPTIONS [list{*}$::checkpays::PAYSINTERDIT{*}$::checkpays::PAYSINTERDITNWSI{*}$::checkpays::PAYSINTERDITNW{*}$::checkpays::PAYSIPAPI{*}$::checkpays::PAYSEXCEPTION]
# Traitementif{[lsearch$::checkpays::PAYSINTERDIT$codepays]!= -1}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,4PAYS BLOQUÉ\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{([lsearch$::checkpays::PAYSINTERDITNWSI$codepays]!= -1)&&($webirc == 0)&&($websocket == 0)&&($reputation<200)}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,12PAYS BLOQUÉ - HORS WEB|RÉPUTATION\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{([lsearch$::checkpays::PAYSINTERDITNW$codepays]!= -1)&&($webirc == 0)&&($websocket == 0)}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,6PAYS BLOQUÉ - HORS WEB\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{($codepays eq "US") || ([string match "*.irccloud.com"$ip])}{
putnow "GLINE $username@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,10IRCCloud|US\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}else{
# Si on entre pas dans une condition blacklisté on envoie à la proc du monitoring #::checkpays::monitoring $nick $username $ip $vhost $codepays $reputation $sslco $webirc $websocket $realname $asn $asname #::checkpays::CountIRC $ip $username $codepays $webirc $websocket}
# Vérification si le codepays est hors liste interdit/protégéif{[lsearch$ALLEXCEPTIONS$codepays]==-1}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,14USER SUSPECT\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::infoAPI$nick$username$vhost$ip$ipdns$unknow$reputation$realname$webirc$websocket$account
::checkpays::infoABUSEIPDB$nick$username$vhost$ipdns}
# IP-API
# Bloquer IPAPI Proxy/Hosting - IPABUSEIPDBif{[lsearch$::checkpays::PAYSIPAPI$codepays]!=-1}{
::checkpays::infoAPI$nick$username$vhost$ip$ipdns$unknow$reputation$realname$webirc$websocket$account}
# Suppression des valeurs en mémoire. # https://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl/unset.n.html
unset ::checkpays::DB($SESSION)}proc ::checkpays::infoAPI{nick username vhost ip ipdns unknow reputation realname webirc websocket account}{set SESSION [md5 "${username}@${vhost}"]
# Encoding pour corriger un problème de charset. Ex: Ãle-de-Franceset data [encoding convertfrom utf-8[::toolsAmand::getipdatas$ipdns]]if{$data == 0}{
unset ::checkpays::DB($SESSION)return}set country [dict get $data country]set regionName [dict get $data regionName]set region [dict get $data region]set city [dict get $data city]set codepays [dict get $data countryCode]set codepostal [dict get $data zip]set isp [dict get $data isp]set mobile [dict get $data mobile]set proxy [dict get $data proxy]set hosting [dict get $data hosting]set org [dict get $data org]set as [dict get $data as]set asname [dict get $data asname]set district [dict get $data district]
# Bloquer IPAPI Proxy/Hostingif{([lsearch$::checkpays::PAYSIPAPI$codepays]!=-1)&&($proxy eq "true" || $hosting eq "true")}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl \[IP-API\]"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,13IP-API PROXY|HOSTING\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Webirc: $webirc) (Websocket: $websocket) (Région: $regionName) (Ville: $city $codepostal) (Fournisseur: $isp) (Org: $org) (As: $as) (Asname: $asname) (Proxy: $proxy) (Mobile: $mobile) (Hébergeur: $hosting) (Unknow: $unknow) (Réputation: $reputation) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}}proc ::checkpays::infoABUSEIPDB{nick username vhost ipdns}{set SESSION [md5 "${username}@${vhost}"]set data [::toolsAmand::abuseipdb$ipdns]if{$data == 0}{
unset ::checkpays::DB($SESSION)return}set abuseConfidenceScore [dict get $data data abuseConfidenceScore]set codepays [dict get $data data countryCode]set isTor [dict get $data data isTor]set totalReports [dict get $data data totalReports]
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,12ABUSEIPDB\003\002 \[$nick!$username@\002$ipdns\002\]\[\002$codepays\002\] - Score: $abuseConfidenceScore \002|\002 isTor: $isTor \002|\002 totalReports: $totalReports"}
J'ai mis des unset de la variable $SESSION dans les conditions ou il y a un return , opter pour une liste sur le stockage des variables en session pour éviter de set chaque variable.
RE: Amélioration d'un script pour le rendre plus performant - CrazyCat - 27/09/2024
Autre petite optimisation proposée:
tcl
# On envoie à la proc de traitement
::checkpays::traitement$SESSION
...
proc ::checkpays::traitement{SESSION}{
lassign $::checkpays::DB($SESSION) ip ipdns codepays asn asname reputation sslco webirc websocket unknow account
set ALLEXCEPTIONS [list{*}$::checkpays::PAYSINTERDIT{*}$::checkpays::PAYSINTERDITNWSI{*}$::checkpays::PAYSINTERDITNW{*}$::checkpays::PAYSIPAPI{*}$::checkpays::PAYSEXCEPTION]
Et idem pour ::checkpays::infoAPI
RE: Amélioration d'un script pour le rendre plus performant - Amand - 27/09/2024
je pense que tu voulais plutôt dire $::checkpays::DB($SESSION) au lieu de $SESSION
Il faut aussi que je trouve une solution pour l'appel de mes deux procs dans la proc traitement:
tcl
}else{
# Si on entre pas dans une condition blacklisté on envoie à la proc du monitoring
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket}
qui fait des requêtes sql , ça ralenti le script, je sais pas si il y a moyen de gérer ça de manière indépendant.
RE: Amélioration d'un script pour le rendre plus performant - CrazyCat - 28/09/2024
(27/09/2024, 21:59)Amand a écrit : je pense que tu voulais plutôt dire $::checkpays::DB($SESSION) au lieu de $SESSION
Non.
Ta variable est dans le namespace, pourquoi la transmettre alors que tu peux juste transmettre la valeur de $SESSION pour ne pas avoir à recalculer le md5 et accéder simplement à l'item de ta variable ?
RE: Amélioration d'un script pour le rendre plus performant - Amand - 28/09/2024
quand je fais un putlog de $SESSION avant
tcl
# On envoie à la proc de traitement
::checkpays::traitement$nick$username$ip$ipdns$vhost$codepays$asn$asname$reputation$sslco$webirc$websocket$unknow$realname$account
voici le résultat :
SESSION => b70fc77168673cc0c4b938e246d3ecf1
il me retourne le md5 de $username + $vhost
RE: Amélioration d'un script pour le rendre plus performant - CrazyCat - 28/09/2024
Je ne comprends pas ta question (s'il y en a une) ou ton interrogation.
Je te dis de modifier ::checkpays::traitement pour qu'elle ne reçoive qu'un seul argument, à savoir SESSION (qui est bien le md5 de $username + $vhost).
Et dans ta procédure, il devient donc inutile de recalculer ce md5 (vu que tu l'as reçu en argument) et qu'avec un lassign $::checkpays::DB($SESSION) ip ipdns codepays asn asname reputation sslco webirc websocket unknow account tu récupères toutes les variables qui étaient précédemment passées en argument.
RE: Amélioration d'un script pour le rendre plus performant - Amand - 29/09/2024
Ok j'ai compris.
tcl
proc ::checkpays::who:co {from keyword text}{if{![string match -nocase "*Client connecting:*"$text]}{return;}set sslco 0set webirc 0set websocket 0set unknow 0set account 0regexp$::checkpays::regexpclientco$text - nick username ip ipdns vhost csa codepays asn asname reputation other
# IP Exceptif{$ip eq "127.0.0.1" || [isbotnick $nick]}{return}set SESSION [md5 "${nick}@${vhost}"]if{[string match -nocase "*tls-users*"$other]}{set sslco 1}if{[string match -nocase "*webirc-users*"$other]}{set webirc 1}if{[string match -nocase "*websocket-users*"$other]}{set websocket 1}if{[string match -nocase "*unknown-users*"$other]}{set unknow 1}if{[string match -nocase "*account:*"$csa]}{set account 1}
# On met en mémoire les valeurs qu'on ne récupère pas dans le whoset ::checkpays::DB($SESSION)[list$ip$ipdns$codepays$asn$asname$reputation$sslco$webirc$websocket$unknow$account]
putnow "WHO $nick %unhr"}proc ::checkpays::who:gestion {from key text}{set text [split[string trim $text]]
lassign $text{} username vhost nick
set SESSION [md5 "${nick}@${vhost}"]set realname [join[lrange[split$text{:}]1 end]]
## On recupere les variables en mémoire
lassign $::checkpays::DB($SESSION) ip ipdns codepays asn asname reputation sslco webirc websocket unknow account
set ::checkpays::DB($SESSION)[list$nick$username$ip$ipdns$vhost$codepays$asn$asname$reputation$sslco$webirc$websocket$unknow$realname$account]
# Nick/Ip/Ident EXCEPTIONif{[::toolsAmand::verify:b $::checkpays::fichier(ident)$username]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - IDENT\003\002 \[\002$codepays\002\] - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}elseif{[::toolsAmand::verify:b $::checkpays::fichier(pseudo)$nick]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - PSEUDO\003\002 \[\002$codepays\002\] - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}elseif{[::toolsAmand::verify:b $::checkpays::fichier(ip)$ip]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - IP\003\002 \[\002$codepays\002\] - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}
# On envoie à la proc de traitement
::checkpays::traitement$SESSION
# Changement du realname en ASV / Redirection adosif{[regexp$::checkpays::regexpagesex$realname]!= 1}{
putnow "CHGNAME $nick [expr 18 + int(rand()*72)] M"
putnow "PRIVMSG $::checkpays::backpaysredirect :\002\00300,02REALNAME\003\002 - \002$nick\002 \[\002$codepays\002\] ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Account: $account) (Asn: $asn) (Asname: $asname) vient d'être changé. Realname: $realname"}elseif{[regexp$::checkpays::regexpado$realname] == 1}{
putnow "PRIVMSG OperServ :SVSJOIN $nick $::checkpays::salonado"}}proc ::checkpays::traitement{SESSION}{
lassign $::checkpays::DB($SESSION) nick username ip ipdns vhost codepays asn asname reputation sslco webirc websocket unknow realname account
set ALLEXCEPTIONS [list{*}$::checkpays::PAYSINTERDIT{*}$::checkpays::PAYSINTERDITNWSI{*}$::checkpays::PAYSINTERDITNW{*}$::checkpays::PAYSIPAPI{*}$::checkpays::PAYSEXCEPTION]
# Traitementif{[lsearch$::checkpays::PAYSINTERDIT$codepays]!= -1}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,4PAYS BLOQUÉ\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{([lsearch$::checkpays::PAYSINTERDITNWSI$codepays]!= -1)&&($webirc == 0)&&($websocket == 0)&&($reputation<200)}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,12PAYS BLOQUÉ - HORS WEB|RÉPUTATION\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{([lsearch$::checkpays::PAYSINTERDITNW$codepays]!= -1)&&($webirc == 0)&&($websocket == 0)}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,6PAYS BLOQUÉ - HORS WEB\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{($codepays eq "US") || ([string match "*.irccloud.com"$ip])}{
putnow "GLINE $username@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,10IRCCloud|US\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}else{
# Si on entre pas dans une condition blacklisté on envoie à la proc du monitoring
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket}
# Vérification si le codepays est hors liste interdit/protégéif{[lsearch$ALLEXCEPTIONS$codepays]==-1}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,14USER SUSPECT\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::infoAPI$SESSION
::checkpays::infoABUSEIPDB$nick$username$vhost$ipdns}
# IP-API
# Bloquer IPAPI Proxy/Hosting - IPABUSEIPDBif{[lsearch$::checkpays::PAYSIPAPI$codepays]!=-1}{
::checkpays::infoAPI$SESSION}
# Suppression des valeurs en mémoire.# https://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl/unset.n.html
unset ::checkpays::DB($SESSION)}proc ::checkpays::infoAPI{SESSION}{
lassign $::checkpays::DB($SESSION) nick username ip ipdns vhost codepays asn asname reputation sslco webirc websocket unknow realname account
# Encoding pour corriger un problème de charset. Ex: Ãle-de-Franceset data [encoding convertfrom utf-8[::toolsAmand::getipdatas$ipdns]]if{$data == 0}{return}set country [dict get $data country]set regionName [dict get $data regionName]set region [dict get $data region]set city [dict get $data city]set codepays [dict get $data countryCode]set codepostal [dict get $data zip]set isp [dict get $data isp]set mobile [dict get $data mobile]set proxy [dict get $data proxy]set hosting [dict get $data hosting]set org [dict get $data org]set as [dict get $data as]set asname [dict get $data asname]set district [dict get $data district]
# Bloquer IPAPI Proxy/Hostingif{([lsearch$::checkpays::PAYSIPAPI$codepays]!=-1)&&($proxy eq "true" || $hosting eq "true")}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl \[IP-API\]"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,13IP-API PROXY|HOSTING\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Webirc: $webirc) (Websocket: $websocket) (Région: $regionName) (Ville: $city $codepostal) (Fournisseur: $isp) (Org: $org) (As: $as) (Asname: $asname) (Proxy: $proxy) (Mobile: $mobile) (Hébergeur: $hosting) (Unknow: $unknow) (Réputation: $reputation) - Realname: $realname"return}}
Le script est plus optimisé maintenant, merci.
Il me reste le problème des deux procs qui appele du sql , et ce sera bon je pense ..
Merci
RE: Amélioration d'un script pour le rendre plus performant - CrazyCat - 29/09/2024
C'est ça.
Par contre, dans who:gestion tu fais:
tcl
lassign $::checkpays::DB($SESSION) ip ipdns codepays asn asname reputation sslco webirc websocket unknow account
set ::checkpays::DB($SESSION)[list$nick$username$ip$ipdns$vhost$codepays$asn$asname$reputation$sslco$webirc$websocket$unknow$realname$account]
Quel intérêt de re-remplir la variable ?
Et toujours dans cette procédure, tu devrais vérifier l'existence de ::checkpays::DB($SESSION) avant de faire le lassign, ne serait-ce que parce que tu peux avoir d'autres scripts qui envoient un /who sans forcément que ce soit suite à une connexion
RE: Amélioration d'un script pour le rendre plus performant - Amand - 29/09/2024
Je rempli de nouveau la variable en session pour intégrer $nick $username $vhost $realname que je recupère lors de la réponse du WHO pour l'envoyer sur la proc traitement avec $SESSION .
Tu penses qu'il serait plus judicieux de l'envoyer directement depuis la proc et ne pas l'ajouter dans la variable en session ? Ex:
16:49:07] Tcl error [::checkpays::who:gestion]: can't read "ip": no such variable
EDIT:
J'ai voulu tester en mettant la condition comme ça :
tcl
if{![info exists $::checkpays::DB($SESSION)]}{putlog "on entre dans la condition";return}
## On recupere les variables en mémoire
lassign $::checkpays::DB($SESSION) ip ipdns codepays asn asname reputation sslco webirc websocket unknow account
Mais il entre tjrs dans la condition.
RE: Amélioration d'un script pour le rendre plus performant - CrazyCat - 30/09/2024
Citation :info exists varName Renvoie 1 si le nom de variable varName existe dans le contexte courant (soit comme variable globale ou locale) et a été définie en lui donnant une valeur, retourne 0 autrement
Ton test doit être avec le nom de la variable et non pas sa valeur:
tcl
if{![info exists ::checkpays::DB($SESSION)]}
RE: Amélioration d'un script pour le rendre plus performant - Amand - 30/09/2024
Niveau optimisation, je pense qu'on est pas mal :
tcl
proc ::checkpays::who:co {from keyword text}{if{![string match -nocase "*Client connecting:*"$text]}{return;}set sslco 0set webirc 0set websocket 0set unknow 0set account 0regexp$::checkpays::regexpclientco$text - nick username ip ipdns vhost csa codepays asn asname reputation other
# IP Exceptif{$ip eq "127.0.0.1" || [isbotnick $nick]}{return}set SESSION [md5 "${nick}@${vhost}"]if{[string match -nocase "*tls-users*"$other]}{set sslco 1}if{[string match -nocase "*webirc-users*"$other]}{set webirc 1}if{[string match -nocase "*websocket-users*"$other]}{set websocket 1}if{[string match -nocase "*unknown-users*"$other]}{set unknow 1}if{[string match -nocase "*account:*"$csa]}{set account 1}
# On met en mémoire les valeurs qu'on ne récupère pas dans le whoset ::checkpays::DB($SESSION)[list$nick$username$ip$ipdns$vhost$codepays$asn$asname$reputation$sslco$webirc$websocket$unknow$account]
putnow "WHO $nick %unhr"}proc ::checkpays::who:gestion {from key text}{set text [split[string trim $text]]
lassign $text{} username vhost nick
set SESSION [md5 "${nick}@${vhost}"]set realname [join[lrange[split$text{:}]1 end]]if{![info exists ::checkpays::DB($SESSION)]}{return}
## On recupere les variables en mémoire
lassign $::checkpays::DB($SESSION) nick username ip ipdns vhost codepays asn asname reputation sslco webirc websocket unknow account
lappend ::checkpays::DB($SESSION)$realname
# Nick/Ip/Ident EXCEPTIONif{[::toolsAmand::verify:b $::checkpays::fichier(ident)$username]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - IDENT\003\002 \[\002$codepays\002\] - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}elseif{[::toolsAmand::verify:b $::checkpays::fichier(pseudo)$nick]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - PSEUDO\003\002 \[\002$codepays\002\] - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}elseif{[::toolsAmand::verify:b $::checkpays::fichier(ip)$ip]}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,3EXCEPTION - IP\003\002 \[\002$codepays\002\] - $nick ($username@$ip) (Réputation: $reputation) (Sslco: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
unset ::checkpays::DB($SESSION)return}
# On envoie à la proc de traitement
::checkpays::traitement$SESSION
# Changement du realname en ASV / Redirection adosif{[regexp$::checkpays::regexpagesex$realname]!= 1}{
putnow "CHGNAME $nick [expr 18 + int(rand()*72)] M"
putnow "PRIVMSG $::checkpays::backpaysredirect :\002\00300,02REALNAME\003\002 - \002$nick\002 \[\002$codepays\002\] ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Account: $account) (Asn: $asn) (Asname: $asname) vient d'être changé. Realname: $realname"}elseif{[regexp$::checkpays::regexpado$realname] == 1}{
putnow "PRIVMSG OperServ :SVSJOIN $nick $::checkpays::salonado"}}proc ::checkpays::traitement{SESSION}{
lassign $::checkpays::DB($SESSION) nick username ip ipdns vhost codepays asn asname reputation sslco webirc websocket unknow account realname
set ALLEXCEPTIONS [list{*}$::checkpays::PAYSINTERDIT{*}$::checkpays::PAYSINTERDITNWSI{*}$::checkpays::PAYSINTERDITNW{*}$::checkpays::PAYSIPAPI{*}$::checkpays::PAYSEXCEPTION]
# Traitementif{[lsearch$::checkpays::PAYSINTERDIT$codepays]!= -1}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,4PAYS BLOQUÉ\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{([lsearch$::checkpays::PAYSINTERDITNWSI$codepays]!= -1)&&($webirc == 0)&&($websocket == 0)&&($reputation<200)}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,12PAYS BLOQUÉ - HORS WEB|RÉPUTATION\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{([lsearch$::checkpays::PAYSINTERDITNW$codepays]!= -1)&&($webirc == 0)&&($websocket == 0)}{
putnow "GLINE *@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,6PAYS BLOQUÉ - HORS WEB\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}elseif{($codepays eq "US") || ([string match "*.irccloud.com"$ip])}{
putnow "GLINE $username@$ip $::checkpays::timeBans $::checkpays::motifpaysbl"
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,10IRCCloud|US\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
unset ::checkpays::DB($SESSION)return}else{
# Si on entre pas dans une condition blacklisté on envoie à la proc du monitoring
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket}
# Vérification si le codepays est hors liste interdit/protégéif{[lsearch$ALLEXCEPTIONS$codepays]==-1}{
putnow "PRIVMSG $::checkpays::backpaysbl :\002\0030,14USER SUSPECT\003\002 \[\002$codepays\002\] - \002$nick\002 ($username@$ip) (Réputation: $reputation) (Ssl: $sslco) (Webirc: $webirc) (Websocket: $websocket) (Asn: $asn) (Asname: $asname) - Realname: $realname"
::checkpays::infoAPI$SESSION
::checkpays::infoABUSEIPDB$nick$username$vhost$ipdns}
# IP-API
# Bloquer IPAPI Proxy/Hosting - IPABUSEIPDBif{[lsearch$::checkpays::PAYSIPAPI$codepays]!=-1}{
::checkpays::infoAPI$SESSION}
# Suppression des valeurs en mémoire. # https://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl/unset.n.html
unset ::checkpays::DB($SESSION)}
Il manque juste la condition pour l'insertion en base de donnée :
tcl
}else{
# Si on entre pas dans une condition blacklisté on envoie à la proc du monitoring
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket}
J'espère qu'il y a une solution pour ne pas qu'il envoie plusieurs requête en même temps, dispatcher l'envoie des requêtes ou une autre solution.
Merci encore CC
RE: Amélioration d'un script pour le rendre plus performant - CrazyCat - 30/09/2024
Déjà, tu as 2 procédures qui agissent sur la base de données, chacune faisant une ouverture et une fermeture de connexion.
=> tu devrais en faire une seule
De plus, tu as une de ces procédures qui fait un select avant de faire l'insertion ou l'update.
=> en mettant les bons index sur ta table, tu pourrais faire un INSERT ... ON DUPLICATE KEY UPDATE ... et n'avoir qu'une seule requête (petit lien d'aide: https://mariadb.com/kb/en/insert-on-duplicate-key-update/)
RE: Amélioration d'un script pour le rendre plus performant - Amand - 30/09/2024
tcl
proc ::checkpays::monitoring{nick username ip vhost codepays reputation sslco webirc websocket realname asn asname}{
::checkpays::service:connect
set query "CALL `NEW_CONNECTION`('$nick', '$username', '[mysqlescape [encoding convertto utf-8 $realname]]', '$codepays', '$ip', '$vhost', '$webirc', '$websocket', '$sslco');"set res [::mysql::exec$::mysqlink$query]
::checkpays::service:deconnect
}proc ::checkpays::CountIRC{ip username codepays webirc websocket}{set now [strftime "%Y-%m-%d"]set queryverif "SELECT ip,seen FROM compteur WHERE ip='$ip' AND seen='$now'"
::checkpays::service:connect
set res [::mysql::sel$::mysqlink$queryverif]if{[lindex$res0] == 1}{set query "UPDATE compteur SET itr=itr+1 WHERE ip='$ip' AND seen='$now'"}else{set query "INSERT INTO compteur (ip, username, codepays, webirc, websocket, seen, itr) VALUES ('$ip', '$username', '$codepays', '$webirc', '$websocket', NOW(), 1)"}set res [::mysql::sel$::mysqlink$query]
::checkpays::service:deconnect
}
Pour faire une seule fermeture connexion, tu me conseilles de les retirer des deux procédures et de les mettre dans le else .
Exemple:
tcl
}else{
# Si on entre pas dans une condition blacklisté on envoie à la proc du monitoring
::checkpays::service:connect
::checkpays::monitoring$nick$username$ip$vhost$codepays$reputation$sslco$webirc$websocket$realname$asn$asname
::checkpays::CountIRC$ip$username$codepays$webirc$websocket
::checkpays::service:deconnect
}
ou de réunir les deux proc en une seule ? Les réunir ça sera problématique si je veux les appeler séparement.
Et voici la structure de ma table compteur , qui est appeler dans la proc CountIRC : https://imgur.com/YjcEqOW
RE: Amélioration d'un script pour le rendre plus performant - CrazyCat - 01/10/2024
Il n'y a aucun exemple dans ton script qui indique que tu appelles les procédures séparément, donc mon conseil était valide.
Je te déconseille très fortement d'avoir ton :connect et ton deconect hors de la où tu fais tes requêtes, c'est source d'ennuis. Donc soit tu crées une procédure supplémentaire qui gères quand tu as besoin d'appeler les 2 queries en même temps soit... ben il faut réfléchir à une solution différente, passant par un fichier tampon.