John F. Lewis has uploaded a new change for review. https://gerrit.wikimedia.org/r/195111
Change subject: restructure the repo ...................................................................... restructure the repo Restructure all the files following a new design pattern. Will help make deployments easier as well as this is the same pattern as used on tools. Change-Id: Icb17486317b19916e310c641d91f218830ebf5b8 --- R bots/include/common-functions.php R bots/include/config/irc_conf.sample.php R bots/include/messages/blocks.txt R bots/include/messages/delete.txt R bots/masters/bot-operator.php R bots/masters/rcreader.php R bots/slaves/bot-wmt-attacks.php R bots/slaves/bot-wmt-blocks.php R bots/slaves/bot-wmt-delete.php R bots/slaves/bot-wmt-es.php R bots/slaves/bot-wmt-fr-copyvio.php R bots/slaves/bot-wmt-fr.php R bots/slaves/bot-wmt-ko.php R bots/slaves/bot-wmt-newpages.php R bots/slaves/bot-wmt-ru.php R bots/slaves/bot-wmt-spambots.php R bots/slaves/irc-wmt-blocks-systemmessages-purge.php R bots/slaves/irc-wmt-delete-systemmessages-purge.php D slaves/bot-tmp.php 19 files changed, 176 insertions(+), 653 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/labs/tools/WMT refs/changes/11/195111/1 diff --git a/include/irc-cvn-blocks-functions.fct.php b/bots/include/common-functions.php similarity index 96% rename from include/irc-cvn-blocks-functions.fct.php rename to bots/include/common-functions.php index 137484b..413f218 100644 --- a/include/irc-cvn-blocks-functions.fct.php +++ b/bots/include/common-functions.php @@ -1,16 +1,10 @@ <?php /* --------------------------------------------- - -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2011-10-30 -Last modified : 2011-12-21 - -functions common to the #cvn-blocks bots +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) +Functions which are common to the bots --------------------------------------------- */ @@ -43,15 +37,15 @@ function translate_expiry ($arr_systemmessages, $expiry, $project) { $translations = array(); - + $ipbopt = $arr_systemmessages[$project]['Ipboptions']; $a = explode (',',$ipbopt); - + foreach ($a as $key => $val) { $b = explode (':',$val); $translations[$b[0]] = $b[1]; } - + if (!empty($translations[$expiry])) return $translations[$expiry]; else @@ -61,42 +55,42 @@ function format_changes ($set, $unset) { $changesfoo = ''; - + // explode the two arrays $setarr = ($set!='(none)') ? explode(', ',$set) : array(); $unsetarr = ($unset!='(none)') ? explode(', ',$unset) : array(); - + // some changes on these arrays foreach ($unsetarr as $k=>$v) $unsetarr[$k] = 'un'.$unsetarr[$k]; - + // generation the changesfoo $arrchg = array_merge($setarr,$unsetarr); foreach ($arrchg as $k=>$v) { - $changesfoo .= "\00311".$v."\003"; // couleurs - + $changesfoo .= "\00311".$v."\003"; // colours + if (($k+2)<count($arrchg)) $changesfoo .= ', '; elseif (($k+2)==count($arrchg)) $changesfoo .= ' and '; } - + return $changesfoo; } function get_data_from_file ($file_name) { $file = fopen ($file_name, 'r'); - + $line = fgets($file); // there should be only one line there $arr = unserialize($line); - + fclose ($file); return $arr; } -/* Exemple of file data returned +/* Example of file data returned $ignore_admin = array('HarrivBOT','ProcseeBot','ProxyBlockBot','Blockbot'); $ignore_blocked = array(); $ignore_wiki = array(); @@ -110,11 +104,8 @@ function save_data_to_file ($file_name, $arr) { $file = fopen ($file_name, 'w'); - fputs ($file, serialize($arr)); - fclose ($file); - return 1; } @@ -130,31 +121,22 @@ if (file_exists(DIALOGFILE)) { $file = fopen (DIALOGFILE, 'r'); - $arr = array(); - while ($line = fgets($file)) { $arr[] = substr($line,0,-1) ; // on retire le \n } - fclose ($file); - unlink(DIALOGFILE); - return $arr; } - else return 0; } function send_to_firstbot ($what) { $file = fopen (DIALOGFILE, 'a+'); - fputs ($file, $what."\n"); - fclose ($file); - return 1; } @@ -162,7 +144,7 @@ { global $irc, $configdata; global $bot_channel, $user_admin, $user_privileged; // read-only - + // Group restrictions if (empty($grouprestricted)) { $advancedright = TRUE; @@ -178,7 +160,6 @@ } else exit('Unexpected result in function manage_group()'."\n"); - switch ($action) { case 'add' : @@ -197,7 +178,6 @@ } else $irc->send($bot_channel, $advancedright_warning); break; - case 'del' : if ($advancedright) { @@ -215,7 +195,7 @@ } else $irc->send($bot_channel, $advancedright_warning); break; - + case 'list' : if (count($configdata[$list])>0) { @@ -228,7 +208,7 @@ else $irc->send($bot_channel, "The $describelist list is empty."); break; } - + return 1; } @@ -236,16 +216,16 @@ { global $irc, $configdata; global $bot_channel, $user_privileged; // read-only - + // List name may be changed here $list = 'badwords'; // Group restrictions - can be easily changed $advancedright = ($user_privileged) ? TRUE : FALSE; $advancedright_warning = 'You are not on the privileged users list and cannot perform this operation.'; - + $tab = explode(' ', $data); $action = $tab[4]; - + switch ($action) { case 'add' : @@ -254,7 +234,7 @@ if (preg_match('#^add (.+)$#', substr($data, (strlen($tab[0].$tab[1].$tab[2].$tab[3])+4)), $m)) { $regex = $m[1]; - + // checking if the badword does not already exist $alreadyexists = FALSE; // uncomment the following lines if you want to have one badword per regex /* foreach ($configdata[$list] as $value) { @@ -263,7 +243,6 @@ break; } } */ - if (!$alreadyexists) { $configdata[$list][] = array('regex'=>$regex); @@ -275,18 +254,17 @@ } else $irc->send($bot_channel, $advancedright_warning); break; - case 'del' : if ($advancedright) { if (preg_match('#^del ([0-9]+)$#', substr($data, (strlen($tab[0].$tab[1].$tab[2].$tab[3])+4)), $m)) { $regexid = $m[1]; - + if (!empty($configdata[$list][($regexid-1)]['regex'])) { $regex = $configdata[$list][($regexid-1)]['regex']; - + unset($configdata[$list][($regexid-1)]); update_savefile ($configdata); $irc->send($bot_channel, "The badword '$regex' (#$regexid) has just been removed."); @@ -296,35 +274,33 @@ } else $irc->send($bot_channel, $advancedright_warning); break; - case 'describe' : if (preg_match('#^describe ([0-9]+)$#', substr($data, (strlen($tab[0].$tab[1].$tab[2].$tab[3])+4)), $m)) { $idr = $m[1]; - + if (!empty($configdata[$list][($idr-1)]['regex'])) { // Copy paste of the "list" case just below $regex = $configdata[$list][($idr-1)]; - + $foo = "[#".$idr."] '".$regex['regex']."' "; $foo .= ($regex['enabled']) ? '(enabled)' : '(disabled)'; $foo .= (!empty($regex['summary'])) ? ' -> '.$regex['summary'] : ''; - + $foo2 = ''; foreach ($regex as $k=>$v) { if ($k!='regex'&&$k!='summary'&&$k!='enabled') $foo2 .= $k.'='.$v.', '; } if (!empty($foo2)) $foo .= ' ('.substr($foo2,0,-2).')'; - + $irc->send($bot_channel, $foo); } else $irc->send($bot_channel, "There is no badword #$regexid on the badword list."); } break; - case 'list' : if (count($configdata[$list])>0) { @@ -334,20 +310,20 @@ $foo = "[#".($idr+1)."] '".$regex['regex']."' "; $foo .= ($regex['enabled']) ? '(enabled)' : '(disabled)'; $foo .= (!empty($regex['summary'])) ? ' -> '.$regex['summary'] : ''; - + $foo2 = ''; foreach ($regex as $k=>$v) { if ($k!='regex'&&$k!='summary'&&$k!='enabled') $foo2 .= $k.'='.$v.', '; } if (!empty($foo2)) $foo .= ' ('.substr($foo2,0,-2).')'; - + $irc->send($bot_channel, $foo); } } else $irc->send($bot_channel, "The badword list is empty."); break; - + case 'set' : if ($advancedright) { @@ -355,17 +331,17 @@ $regxactions = ''; foreach ($array_action2 as $v) $regxactions .= '|'.$v; - + if (preg_match('#^set ([0-9]+) (enabled|regex|summary'.$regxactions.') (.+)$#', substr($data, (strlen($tab[0].$tab[1].$tab[2].$tab[3])+4)), $m)) { $regexid = $m[1]; $action2 = $m[2]; $value = $m[3]; - + if (!empty($configdata[$list][($regexid-1)]['regex'])) { $regex = $configdata[$list][($regexid-1)]['regex']; - + switch ($action2) { case 'enabled': @@ -390,7 +366,7 @@ else $irc->send($bot_channel, "The badword '$regex' (#$regexid) was already disabled"); } break; - + case 'regex': if ($value != $regex) { @@ -400,7 +376,7 @@ } else $irc->send($bot_channel, "No changes were made on badword '$regex' (#$regexid)"); break; - + case 'summary': if ($value == 'none') { @@ -417,7 +393,7 @@ else $irc->send($bot_channel, "No changes were made on badword '$regex' (#$regexid)"); break; } - + // Autres actions if (in_array($action2,$array_action2)) { @@ -434,7 +410,7 @@ elseif ((intval($value)) && ($action2!='check-typeaccount' && $action2!='check-blockedwiki')) { $value = intval($value); - + if ($configdata[$list][($regexid-1)][$action2] != $value) { $configdata[$list][($regexid-1)][$action2] = $value; @@ -478,7 +454,7 @@ else $irc->send($bot_channel, $advancedright_warning); break; } - + return 1; } @@ -489,33 +465,33 @@ { private $last_time; private $nb_aborted; - + private $http; private $SUL; - + public function __construct () { $this->last_time = time(); $this->nb_aborted = 0; - + $this->http = new http; $this->SUL = array(); } - + public function update_lasttime () { $this->last_time = time(); - + if ($this->nb_aborted != 0) { global $irc, $bot_channel; // better than nothing :) $irc->send($bot_channel, "Warning - ".$this->nb_aborted." request(s) have been aborted !"); $this->nb_aborted = 0; } } - + private function reset_class () { $this->last_time = time(); $this->nb_aborted = 0; } - + private function should_abort () { // returns true if the request should be aborted, false else if ((time() - $this->last_time) > 30) { @@ -524,10 +500,10 @@ } else return 0; } - + ## ------------------------------------------------------- # Here come the requests functions - + public function isIP ($blocked) { if (preg_match('#^([0-9]+\.){3}[0-9]+$#',$blocked,$m)) @@ -535,7 +511,7 @@ else return 0; } - + public function isUser ($blocked) { if (!preg_match('#^([0-9]+\.){3}[0-9]+(/[0-9]+)?$#',$blocked,$m)) @@ -543,7 +519,7 @@ else return 0; } - + public function isRange ($blocked) { if (preg_match('#^([0-9]+\.){3}[0-9]+(/[0-9]+)$#',$blocked,$m)) @@ -551,18 +527,18 @@ else return 0; } - + // The following functions need the SUL data to be loaded private function get_SUL_infos ($user) { if ($this->SUL['name'] == $user) return 1; // if data is cached - + // this could be time consuming elseif (!$this->should_abort()) { $url = 'http://meta.wikimedia.org/wiki/Special:CentralAuth/'.urlencode(str_replace(' ','_',$user)); $html = $this->http->get($url); unset($this->SUL); - + if (!preg_match('#<div class="error">There is no global account for.+</div>#', $html)) { $this->SUL = array( 'name' => $user, @@ -574,25 +550,24 @@ 'nbblocks' => 0, 'nbcontribs' => 0 ); - + // If the user is already locked, returns 0 : the other conditions are not evaluated // and there is no bot warning output if (preg_match('#<strong>Locked:</strong> yes</p>#', $html)){ $this->SUL['locked'] = 1; return 0; } - + // Else, getting some infos about this account $this->SUL['locked'] = 0; - + // Registration date preg_match('#<p><strong>Registered:</strong> ([0-9]{1,2}):([0-9]{2}), ([0-9]{1,2}) ([A-Z][a-z]+) ([0-9]{4}) \([0-9]+ [a-z]+ ago\)</p>#', $html, $m); $this->SUL['datecreated'] = mktime($m[1],$m[2],0,NumberMonth($m[4]),$m[3],$m[5]); - - + // List of the local accounts, if they are blocked and the number of contributions preg_match('#<legend>List of local accounts</legend><form.+</form></fieldset>#s', $html, $matches); - + preg_match_all('#<tr><td><a href="//([a-z\.]+)\.org/wiki/User:'.real_quote_meta(urlencode($user)).'" title="User '.real_quote_meta($user).' on \1\.org">\1\.org</a></td><td><span style="display: none">[0-9]{14}</span>[0-9]{1,2}:[0-9]{2}, [0-9]{1,2} [A-Z][a-z]+ [0-9]{4}</td><td style="text-align: center"><img src="[^>]+/><span class="[^<]+</span></td><td>(<a href="//\1\.org/wiki/Special:Log/block\?page=User:'.real_quote_meta(urlencode($user)).'" title="block log">(â)</a>|[^<]+)</td><td style="text-align: right"><a href="//\1\.org/wiki/Special:Contributions/'.real_quote_meta(urlencode($user)).'" title="contributions">([0-9,]+)</a></td></tr>#Ui', $matches[0],$allmatches); /* 2011-12-04 : Removing the http: prefix (protocole relative URLs) <tr><td><a href="http://aa.wiktionary.org/wiki/User:Quentinv57" title="User Quentinv57 on aa.wiktionary.org">aa.wiktionary.org</a></td> @@ -605,64 +580,64 @@ $wiki = ($allmatches[1][$k] != 'www.mediawiki') ? $allmatches[1][$k] : 'mediawiki'; $blocked = ($allmatches[3][$k] == 'â') ? 0 : 1; $contribs = str_replace(',','',$allmatches[4][$k]); - + $this->SUL['localaccounts'][$wiki] = array( 'blocked' => $bloqued, 'contribs' => $contribs ); - + $this->SUL['nbaccounts'] ++; $this->SUL['nbblocks'] += ($blocked) ? 1 : 0; $this->SUL['nbcontribs'] += $contribs; } - + return 1; } else // if there is no SUL account return 0; }} - + public function otheraccounts ($user, $nb) { if ($this->get_SUL_infos($user)) { // the > is equivalent to -1 >= if ($this->SUL['nbaccounts'] > $nb) return 1; - + else return 0; } - + else return 0; } - + public function otherblockedaccounts ($user, $nb) { if ($this->get_SUL_infos($user)) { // the > is equivalent to -1 >= if ($this->SUL['nbblocked'] > $nb) return 1; - + else return 0; } - + else return 0; } - + public function otherunblockedaccounts ($user, $nb) { if ($this->get_SUL_infos($user)) { // here it is >= if (($this->SUL['nbaccounts']-$this->SUL['nbblocks']) >= $nb) return 1; - + else return 0; } - + else return 0; } - + public function number_localcontribs ($user, $project, $nb) { global $irc, $bot_channel; // for error reporting only - can be removed when everything will be okay - + if ($this->get_SUL_infos($user)) { if (empty($this->SUL['localaccounts'][$project])) @@ -671,54 +646,54 @@ //var_dump($this->SUL); $irc->send($bot_channel,"Error when getting the number of local contribs for $user on $project\n"); } - + // here it is <= (less than X contribs) if ($this->SUL['localaccounts'][$project]['contribs'] <= $nb) return 1; - + else return 0; } - + else return 0; } - + public function number_globalcontribs ($user, $nb) { if ($this->get_SUL_infos($user)) { // here it is <= (less than X contribs) if ($this->SUL['ncontribs'] <= $nb) return 1; - + else return 0; } - + else return 0; } - + public function date_accountcreated ($user, $nbhours) { if ($this->get_SUL_infos($user)) { // here it is <= (less than X hours) if ((time()-$this->SUL['datecreated']) <= ($nbhours*3600)) return 1; - + else return 0; } - + else return 0; } - + public function otherprojects_contribs ($ip, $project, $delay) { if (!$this->should_abort()) { // returns 0 if the IP has not contributed to others projects within the $delay last hours ; returns 1 else global $arr_databases; - + foreach ($arr_databases as $sql_server => $content) { $toolserver_mycnf = parse_ini_file("/home/".get_current_user()."/.my.cnf"); $mysql = new MySQLi ('sql-s' .$sql_server. '-rr.toolserver.org',$toolserver_mycnf['user'], $toolserver_mycnf['password']); // or echo "<p>SQL error : Can't connect to $sql_server</p>"; unset($toolserver_mycnf); - + foreach ($content as $db => $domain) { if ($mysql->select_db($db)) @@ -726,12 +701,12 @@ if ($res = $mysql->query ("SELECT max(`rc_timestamp`) as last_timestamp FROM `recentchanges` WHERE `rc_user_text`='" .$mysql->real_escape_string($ip). "'")) { $req = $res->fetch_assoc(); - + // si l'IP a contribué dans les $delay dernières heures sur le projet, on s'arrête if ((!empty($req['last_timestamp'])) && ($domain != $project.'.org')) { $delaycontrib = date('YmdHis')-$req['last_timestamp']; - + if ($delaycontrib < $delay*10000) { return 1; } @@ -739,24 +714,24 @@ } } } - + $mysql->close(); } - + return 0; }} - + /* - deprecated public function user_otherprojects ($user, $project) { // returns 0 if the user has no accounts on other projects ; returns 1 else global $arr_databases; - + foreach ($arr_databases as $sql_server => $content) { $toolserver_mycnf = parse_ini_file("/home/".get_current_user()."/.my.cnf"); $mysql = new MySQLi ('sql-s' .$sql_server. '-rr.toolserver.org',$toolserver_mycnf['user'], $toolserver_mycnf['password']); // or echo "<p>SQL error : Can't connect to $sql_server</p>"; unset($toolserver_mycnf); - + foreach ($content as $db => $domain) { if ($mysql->select_db($db)) @@ -769,15 +744,13 @@ } } } - + $mysql->close(); } - - return 0; + + return 0; } */ } - - -?> \ No newline at end of file +?> diff --git a/include/config/irc_conf.sample.php b/bots/include/config/irc_conf.sample.php similarity index 73% rename from include/config/irc_conf.sample.php rename to bots/include/config/irc_conf.sample.php index 015bb09..eb21285 100644 --- a/include/config/irc_conf.sample.php +++ b/bots/include/config/irc_conf.sample.php @@ -1,8 +1,8 @@ <?php -$irc_user = "wmtbot"; // Username of the bot +$irc_user = "wmtbot"; // NickServ account $irc_pwd = "password"; // NickServ password -$irc_port = 6667; // Port to use +$irc_port = 6667; // Port to connect to $irc_freenodeserver = 'irc.freenode.net'; //'irc.freenode.net'; / 174.143.119.91 / 9.16.176.16 $irc_wmserver = 'irc.wikimedia.org'; //'irc.wikimedia.org'; / 208.80.152.178 diff --git a/include/config/irc-cvn-blocks-systemmessages.txt b/bots/include/messages/blocks.txt similarity index 100% rename from include/config/irc-cvn-blocks-systemmessages.txt rename to bots/include/messages/blocks.txt diff --git a/include/config/irc-cvn-delete-systemmessages.txt b/bots/include/messages/delete.txt similarity index 100% rename from include/config/irc-cvn-delete-systemmessages.txt rename to bots/include/messages/delete.txt diff --git a/masters/bot-operator.php b/bots/masters/bot-operator.php similarity index 93% rename from masters/bot-operator.php rename to bots/masters/bot-operator.php index 3fd6294..9efa944 100755 --- a/masters/bot-operator.php +++ b/bots/masters/bot-operator.php @@ -1,18 +1,12 @@ #!/usr/bin/php - <?php +<?php /* --------------------------------------------- - -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2012-05-27 -Last modified : 2012-05-27 +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) Bot Operator (#wmt-op) - --------------------------------------------- */ @@ -70,7 +64,7 @@ $irc->quit() ; $wm->quit() ; # Removed the system instruction - the file will be automatically restarted by daemon - exit(3); + exit(3); } elseif (preg_match ('#^:(wmtbot-.*?)![^ ]* JOIN .wmt-bots$#' , $data , $matches)) { @@ -106,8 +100,6 @@ } // For now, the bot just comes in the channel, even if we can't issue commands yet - - else usleep(500000); // wait 0.5 seconds unset($data); // free memory diff --git a/masters/rcreader.php b/bots/masters/rcreader.php similarity index 99% rename from masters/rcreader.php rename to bots/masters/rcreader.php index 8c93fea..1af24a7 100644 --- a/masters/rcreader.php +++ b/bots/masters/rcreader.php @@ -35,7 +35,7 @@ } else { // Cas g?n?ral $wmchannels["#".$m[1].'.'.$m[2]] = $line['domain']; } - + $arr_databases[$line['slice']][$line['dbname']] = $line['domain']; } unset($m); @@ -64,14 +64,14 @@ while (1) { - + // ------------------------------- // Wikirc Script // ------------------------------- if ($data = $wm-> getdata ()) { $tab = explode (' ', $data); - + if (!empty($data)) { // Init freenode script @@ -80,7 +80,7 @@ $wm-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - + elseif ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -89,12 +89,12 @@ # Removed the system instruction - the file will be automatically restarted by daemon exit(3); } - + elseif (preg_match ('#^:rc-pmtpa!~rc-pm...@special.user PRIVMSG \#([a-z0-9]+\.[a-z0-9]+) (.+)$#' , $data , $matches)) { $wiki = $matches[1]; $feed = $wmchannels['#'.$matches[1]].' '.$matches[2]; - + foreach ($clients as $client_no => $data) { if ($socket->client_exists($client_no)) { @@ -108,15 +108,15 @@ } } } - + else { $data = $socket->read(); - + if (!empty($data)) { $clientno = $data['client']; $msg = $data['msg']; - + if (!array_key_exists($clientno, $clients)) { $clients[$clientno] = $msg; } @@ -125,7 +125,6 @@ usleep(500000); // wait 0.5 seconds } } - unset($data); // free memory } diff --git a/slaves/bot-wmt-attacks.php b/bots/slaves/bot-wmt-attacks.php similarity index 96% rename from slaves/bot-wmt-attacks.php rename to bots/slaves/bot-wmt-attacks.php index a1d4f50..d16fb72 100644 --- a/slaves/bot-wmt-attacks.php +++ b/bots/slaves/bot-wmt-attacks.php @@ -2,20 +2,12 @@ <?php /* --------------------------------------------- +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2012-05-27 -Last modified : 2012-05-27 - -script of the bot that monitors #wmt-attacks - +Channel: #wmt-attacks --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -31,8 +23,6 @@ $irc_user .= '-2'; $arr_sock = array ('wikiset'=>'all'); - - ## Init arrays for #wmt-attacks $newusers = array('Test Account Cowboy'); @@ -70,7 +60,7 @@ ## Inclusion des fonctions, paramètres, etc. $pref2 = '/data/project/irc-wmt/bots'; -include $pref2.'/include/irc-cvn-blocks-functions.fct.php'; +include $pref2.'/include/common-functions.php'; function array_all_optout ($array, $optout) { // returns TRUE if every element of $array is an element of $optout ($array included in $optout) @@ -78,7 +68,7 @@ if (!in_array($v,$optout)) return 0; } - + return 1; } @@ -88,26 +78,24 @@ if (in_array($v,$optout)) return 1; } - + return 0; } function SUL_exists ($user) { global $http; - + $url = 'http://meta.wikimedia.org/wiki/Special:CentralAuth/'.urlencode(str_replace(' ','_',$user)); - + $html = $http->get($url); - + if (preg_match('#<div class="error">There is no global account for.+</div>#', $html)) return 0; - + else return 1; } - - #### #### ###### INITIALISATION DU BOT !!! ###### @@ -147,7 +135,7 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - + if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -158,7 +146,7 @@ } } } - + // ------------------------------- // Wikirc Script // ------------------------------- @@ -169,22 +157,19 @@ { $project = substr($matches[1],0,-4); $user = $matches[2]; - - + // Détection des noms utilisateurs inadmissibles (spécial EvW !!) $scorematch = 0; foreach ($badnames_regex_evw as $regex_evw => $scorereg) { if (preg_match('#'.$regex_evw.'#Ui',$user)) $scorematch += $scorereg; } - if ($scorematch > 30) { // test purposes only #fputs($attacksfollow2, "(".date('Y-m-d H:i:s').") [score=$scorematch] \0034Warning : \002$user\002 created on \00313$project\003 - \00315http://meta.wikimedia.org/wiki/Special:CentralAuth/".urlencode(str_replace(' ','_',$user))."\003\n"); // temp display to file } if ($scorematch >= 100) { // si on a un score supérieur à 100, on affiche un avertissement dans le canal $irc->send($bot_channel, "\0034Warning : \002$user\002 created on \00313$project\003 - \00315http://meta.wikimedia.org/wiki/Special:CentralAuth/".urlencode(str_replace(' ','_',$user))."\003"); } - // Dans tous les cas, on le met dans notre liste de nouveaux utilisateurs (pour qu'il y soit qd même si c'est une erreur) if (!array_key_exists($user, $newusers) AND !array_key_exists($user, $newusers_watchlist)) { @@ -198,7 +183,6 @@ 'false-positive' => 0 ); } - # Updating the $newusers array if ((time()-$newusers_lasttime) > DELAY_REFRESH_ARRAY) { @@ -206,18 +190,15 @@ if ((time()-$value['creation']) > DELAY_REMOVE_FROM_NEWUSERSLIST) unset ($newusers[$key]); } - foreach ($newusers_watchlist as $key => $value) { if ((time()-$value) > DELAY_REMOVE_FROM_WATCHLIST) { unset ($newusers_watchlist[$key]); $irc->send($bot_channel, "\00314Notice : $key has been auto-removed from the watchlist\003"); } } - $newusers_lasttime = time(); } } - // Then, analyse edits elseif (preg_match('#^(([^ ]+) .*5\* 03(.+) 5\*.*)$#',$data, $matches)) { @@ -230,30 +211,25 @@ { $print = $line; $lastpage = NULL; - if (preg_match('#^\#[^ ]+ :14\[\[07([^\]]+)14\]\]4 [MNB!]*10 02([^\*]+) 5\* 03'.real_quote_meta($user).' 5\* \(?[+-][0-9]+?\) 10(.*)$#', $line, $mu)) { $lastpage = $mu[1]; $print = "\002$user\002 edited \00313$project\003 (\00311$lastpage\003)"; if (!empty($mu[3])) $print .= " with the following comment : \00315".$mu[3]."\003"; $print .= " - \00315".$mu[2]."\003"; // adding a link } - ## for the #wmt-attacks channel if (array_key_exists($user, $newusers_watchlist)) $irc->send($bot_channel, $print); - ## for the #wmt-attacks channel if (array_key_exists($user, $newusers)) { $newusers[$user]['edits']++; - // On incrémente les warnings : // 1- si le projet est différent if (!empty($project) && !in_array($project,$newusers[$user]['projects']) && !in_array($project,$trigger_optout_crosswiki)) { $newusers[$user]['projects'][] = $project; $newusers[$user]['warning-crosswiki']++; } - // 2- si une autre page a été modifiée dans un délai de +-50 sec if (!empty($lastpage)) { // adding a warning only if there is a small time before a page *that never got edited by this acc* is edited @@ -264,7 +240,6 @@ } else $newusers[$user]['false-positive']++; } - // Trigger en fonction des warnings : $triggeredfoo = NULL; // -1- crosswiki trigger (edits sur + de 3 wikis) @@ -276,8 +251,6 @@ // -3- Edgar Von Webern trigger (2 wikis including dewiki) <s>+ trigger edit déclenché 1 fois ($newusers[$user]['warning-edit'] >= 1 && )</s> elseif ($newusers[$user]['warning-crosswiki'] >= 2 && array_one_optout($newusers[$user]['projects'],$trigger_edgar_wikis) && !array_one_optout($newusers[$user]['projects'],$trigger_optout_evw) && $newusers[$user]['false-positive']<=$newusers[$user]['warning-edit']) $triggeredfoo = 'Edgar Von Webern ?'; - - if (!empty($triggeredfoo)) { if (SUL_exists($user)) { // si le compte SUL n'existe pas, on ignore l'avertissement (plus simple) @@ -291,14 +264,11 @@ $irc->send($bot_channel, $print); $newusers_watchlist[$user] = time(); } - unset($newusers[$user]); } - else $newusers[$user]['lastedit'] = time(); } } - else { /* disactivated regex --- foreach ($feedchannel['regex'] as $regex) @@ -309,11 +279,8 @@ } } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-blocks.php b/bots/slaves/bot-wmt-blocks.php similarity index 95% rename from slaves/bot-wmt-blocks.php rename to bots/slaves/bot-wmt-blocks.php index 6390b05..569e8a2 100644 --- a/slaves/bot-wmt-blocks.php +++ b/bots/slaves/bot-wmt-blocks.php @@ -2,20 +2,11 @@ <?php /* --------------------------------------------- - -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2012-05-27 -Last modified : 2012-05-27 - -script of the bot that monitors #wmt-blocks - +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) +Channel: #wmt-blocks --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -37,8 +28,7 @@ define('GLOBALCHANGES_WIKI','meta.wikimedia.org'); $pref2 = '/data/project/irc-wmt/bots/include'; define('SAVEFILE', $pref2.'/config/irc-cvn-blocks-saved'); -define('MESSAGESFILE', $pref2.'/config/irc-cvn-blocks-systemmessages.txt'); - +define('MESSAGESFILE', $pref2.'/messages/blocks.txt'); #### #### ###### FUNCTIONS ###### @@ -60,12 +50,12 @@ Time block formats : "\+[0-9]+ (second|minute|hour|day|week|month|year)s?" "[0-9]{,2} (January|February|March|April|May|June|July|August|September|October|November|December) [0-9]{4}" - + http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html */ ## Inclusion des fonctions, paramètres, etc. -include $pref2.'/irc-cvn-blocks-functions.fct.php'; +include $pref2.'/common-functions.php'; function array_all_optout ($array, $optout) { // returns TRUE if every element of $array is an element of $optout ($array included in $optout) @@ -73,7 +63,6 @@ if (!in_array($v,$optout)) return 0; } - return 1; } @@ -83,26 +72,19 @@ if (in_array($v,$optout)) return 1; } - return 0; } function SUL_exists ($user) { global $http; - $url = 'http://meta.wikimedia.org/wiki/Special:CentralAuth/'.urlencode(str_replace(' ','_',$user)); - $html = $http->get($url); - if (preg_match('#<div class="error">There is no global account for.+</div>#', $html)) return 0; - else return 1; } - - #### #### ###### INITIALISATION DU BOT !!! ###### @@ -131,7 +113,6 @@ while ($line = fgets($file)) { $far = explode ('||',$line); $pou = explode (';;',$far[1]); - unset($pou[(count($pou)-1)]); foreach ($pou as $key => $value) { @@ -159,7 +140,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -170,7 +150,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -184,11 +163,9 @@ $anononly = (!empty($matches[3])) ? 1 : 0; $expiry = $matches[4]; $reason = $matches[6]; - $reasonfoo = (!empty($reason)) ? " with the following reason : \00310$reason\003" : ""; $delayfoo = "until \00314$expiry\003"; $optionsfoo = ($anononly) ? " (IP only)" : ""; - $irc->send ($bot_channel , "\0034(IP)\003 \002$blocked\002 was globally \00311blocked\003 by $steward $delayfoo$optionsfoo $reasonfoo") ; } // Global blocks (modify) @@ -199,11 +176,9 @@ $anononly = (!empty($matches[3])) ? 1 : 0; $expiry = $matches[4]; $reason = $matches[6]; - $reasonfoo = (!empty($reason)) ? " with the following reason : \00310$reason\003" : ""; $delayfoo = "until \00314$expiry\003"; $optionsfoo = ($anononly) ? " (IP only)" : ""; - $irc->send ($bot_channel , "\0034(IP)\003 \002$blocked\002 was globally \00311re-blocked\003 by $steward $delayfoo$optionsfoo $reasonfoo") ; } // Global blocks (del) @@ -212,12 +187,9 @@ $steward = $matches[1]; $blocked = $matches[2]; $reason = $matches[4]; - $reasonfoo = (!empty($reason)) ? " with the following reason : \00310$reason\003" : ""; - $irc->send ($bot_channel , "\0034(IP)\003 \002$blocked\002 was globally \00311unblocked\003 by $steward$reasonfoo") ; } - // Global locks / unlocks / ... elseif (preg_match ('#^'.GLOBALCHANGES_WIKI.' :14\[\[07Special:Log/globalauth14\]\]4 setstatus10 02 5\* 03(.+) 5\* 10changed status for global account "User:(.+)@global": Set (.+); Unset ([^:]+)(: (.+))?$#m' , $data , $matches)) { echo $data."\n"; @@ -226,64 +198,51 @@ $set = $matches[3]; $unset = $matches[4]; $reason = $matches[6]; - $reasonfoo = (!empty($reason)) ? " with the following reason : \00310$reason\003" : ""; - // On note les changements d'une façon plus esthétique $changes = format_changes($set,$unset); - // All steward actions are reported. If we want to ignore some, we have to set an ignore_steward list $irc->send ($bot_channel , "\0034(user)\003 \002$blocked\002 was globally $changes by $steward$reasonfoo") ; } - /* gblock messages :rc-pmtpa!~rc-pm...@special.user PRIVMSG #test.wikipedia :14[[07Special:Log/gblblock14]]4 gblock210 02 5* 03Quentinv57 5* 10globally blocked [[02User:240.122.212.12410]] (expires 17:47, 27 October 2011): test :rc-pmtpa!~rc-pm...@special.user PRIVMSG #test.wikipedia :14[[07Special:Log/gblblock14]]4 modify10 02 5* 03Quentinv57 5* 10modified the global block on [[02User:240.122.212.12410]] (anonymous only, expires 17:47, 27 October 2011): test :rc-pmtpa!~rc-pm...@special.user PRIVMSG #test.wikipedia :14[[07Special:Log/gblblock14]]4 gunblock10 02 5* 03Quentinv57 5* 10removed global block on [[02User:240.122.212.12410]]: test - glock : :rc-pmtpa!~rc-pm...@special.user PRIVMSG #test.wikipedia :14[[07Special:Log/globalauth14]]4 setstatus10 02 5* 03Quentinv57 5* 10changed status for global account "User:CU Test Account@global": Set locked; Unset (none): test :rc-pmtpa!~rc-pm...@special.user PRIVMSG #test.wikipedia :14[[07Special:Log/globalauth14]]4 setstatus10 02 5* 03Quentinv57 5* 10changed status for global account "User:CU Test Account@global": Set hidden; Unset (none): test :rc-pmtpa!~rc-pm...@special.user PRIVMSG #test.wikipedia :14[[07Special:Log/globalauth14]]4 setstatus10 02 5* 03Quentinv57 5* 10changed status for global account "User:CU Test Account@global": Set (none); Unset locked, hidden: test */ - // local blocks elseif (preg_match ('#^([^ ]+) .+4 block10 (.+)$#' , $data , $matches)) { // 1 - si on matche un blocage // $1 contiendra le nom du wiki // $2 contiendra la suite - $wikiurl = $matches[1]; $wiki = substr($wikiurl,0,-4); $foo = $matches[2]; - $blocklogentry = $api_systemmessages[$wiki]['blocklogentry']; $parens = $api_systemmessages[$wiki]['parentheses']; $parens = str_replace('#','\#',quotemeta($parens)); $parens = str_replace('\$1', '([^:]*)', $parens); - // Remove the {{GENDER}} into system message // {{GENDER:$1|usuari|usuària}} $blocklogentry = preg_replace ('#\{\{GENDER:[^\|]+\|([^\|]+)\|([^\}]+)\}\}#i', '$1', $blocklogentry); - $regexbl = str_replace('#','\#',quotemeta($blocklogentry)); $regexbl = str_replace('\$1', '[^:]+:(.+)', $regexbl); // utilisateur - $1, $2 et $3 ont aussi été échappés... -- "User:" est différent selon les langues (donc remplacé par "[^:]+") $regexbl = str_replace('\$2', '(([^\(^:]|:[0-9]{2})+)', $regexbl); // délai - remplacement de ([^\(^:]+) par (([^\(^:]|:[0-9]{2})+), pour tenir compte des choses comme 2011-12-27T13:08:09Z $regexbl = str_replace('\$3', $parens, $regexbl); // options - les options sont tjs entre parenthèses, même quand il n'y en a pas -> () $regexbl = str_replace('\[\[', '\[\[02', $regexbl); // les [[ et ]] seront échappés car on a appelé quotemeta() ci-dessus $regexbl = str_replace('\]\]', '10\]\]', $regexbl); - $regex = "#^02 5\* 03(.+) 5\* 10" .$regexbl. "[^:ï¼]*([:ï¼] (.+))?$#m"; // dunno why, but itwiki, fiwiki,... works only with the "m" flag... // test : adding [^:]* before the optional comment (some wikis as frwiki have sth broken after the block options) - // On cherche ensuite à matcher le reste, ce qui dépend du blocklogentry récupéré if (preg_match ($regex , $foo , $matches)) { $user = $matches[1]; $reason = $matches[7]; // 7 depuis que $2 a 2 parenthèses - // 2-3-4 dépend de la place de $1,$2 et $3 dans la regex (à voir en fct de $blocklogentry) if (preg_match('#\$([1-3]).*\$([1-3]).*\$([1-3])#', $blocklogentry, $m)) { @@ -291,32 +250,23 @@ foreach ($m as $key=>$value) // on incrémente les valeurs qui sont au-dessues de $m[2] car le $2 possède désormais deux parenthèses if ($m[$key]>$m[2]) $m[$key]++; // fin incrémentation - $blocked = $matches[(1+$m[1])]; $expiry = $matches[(1+$m[2])]; $options = $matches[(1+$m[3])]; - $urllocal = 'http://'.$wikiurl.'/w/index.php?title=Special:Log&type=block&page=User:'.urlencode(str_replace(' ','_',$blocked)) ; $reasonfoo = (!empty($reason)) ? "with the following reason : \00310$reason\003 " : ""; - $expiry = translate_expiry ($api_systemmessages, $expiry, $wiki); $delayfoo = ($expiry=="infinite"|$expiry=="indefinite") ? "till \00314infinity\003" : "for \00314$expiry\003"; - preg_match('#^([0-9]+\.){3}[0-9]+(/[0-9]+)?$#',$blocked,$m); // +$ if (empty($m[0])) $blockedtype = 'user'; elseif (empty($m[2])) $blockedtype = 'IP'; else $blockedtype = 'range'; - - // Exceptions - this one is just to look better if ($wiki=="mediawiki.wikipedia") $wiki = "mediawiki"; - if (!in_array($wiki,$configdata['ignore_wiki']) && !in_array($user,$configdata['ignore_admin']) && !in_array($blocked,$configdata['ignore_blocked'])) { // if it's not on any ignore list # Generate other links - an other bot will do that soon (this has been moved to the second bot) - - $irc->send ($bot_channel , "\0034($blockedtype)\003 \002$blocked\002 was blocked on \00313$wiki\003 by $user $delayfoo $reasonfoo- \0032$urllocal\003") ; if (!empty($append)) $irc->send ($bot_channel , "\002$blocked\002 $append"); } @@ -331,17 +281,13 @@ $irc->send ($bot_channel, "ERROR when trying to match the block entry on $wiki"); } } - elseif (preg_match('#4 block10#',$data)) { echo $data."\n(ERREUR)\n"; $irc->send("ERREUR - ".$bot_channel, $data); } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-delete.php b/bots/slaves/bot-wmt-delete.php similarity index 92% rename from slaves/bot-wmt-delete.php rename to bots/slaves/bot-wmt-delete.php index 34ad1b9..0b18f6e 100644 --- a/slaves/bot-wmt-delete.php +++ b/bots/slaves/bot-wmt-delete.php @@ -2,20 +2,11 @@ <?php /* --------------------------------------------- - -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2012-05-27 -Last modified : 2012-05-27 - -script of the bot that monitors #wmt-delete - +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) +Channel: #wmt-delete --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -35,7 +26,7 @@ $pref2 = '/data/project/irc-wmt/bots/include'; define('SAVEFILE', $pref2.'/config/irc-cvn-delete-saved'); -define('MESSAGESFILE', $pref2.'/config/irc-cvn-delete-systemmessages.txt'); +define('MESSAGESFILE', $pref2.'/messages/delete.txt'); #### #### ###### FUNCTIONS ###### @@ -43,7 +34,7 @@ ## Inclusion des fonctions, paramètres, etc. -include $pref2.'/irc-cvn-blocks-functions.fct.php'; +include $pref2.'/common-functions.php'; function array_all_optout ($array, $optout) { // returns TRUE if every element of $array is an element of $optout ($array included in $optout) @@ -51,7 +42,6 @@ if (!in_array($v,$optout)) return 0; } - return 1; } @@ -61,7 +51,6 @@ if (in_array($v,$optout)) return 1; } - return 0; } @@ -95,7 +84,6 @@ while ($line = fgets($file)) { $far = explode ('||',$line); $pou = explode (';;',$far[1]); - unset($pou[(count($pou)-1)]); foreach ($pou as $key => $value) { @@ -123,7 +111,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -134,7 +121,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -157,16 +143,12 @@ $reason = $matches2[4]; $urllocal = 'https://'.$wikiurl.'/w/index.php?title=Special:Log&type=delete&page='.urlencode(str_replace(' ','_',$page)) ; $reasonfoo = (!empty($reason)) ? "with the following reason : \00310$reason\003 " : ""; - // Exceptions - this one is just to look better if ($wiki=="mediawiki.wikipedia") $wiki = "mediawiki"; - if (1 == 1) { // if it's not on any ignore list # Generate other links - an other bot will do that soon (this has been moved to the second bot) - - $irc->send ($bot_channel , "\002$page\002 was $action on \00313$wiki\003 by $user $reasonfoo- \0032$urllocal\003") ; if (!empty($append)) $irc->send ($bot_channel , "\002$page\002 $append"); } @@ -176,11 +158,8 @@ $irc->send($bot_channel, "err-".str_replace('','^C',$data)); } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-es.php b/bots/slaves/bot-wmt-es.php similarity index 92% rename from slaves/bot-wmt-es.php rename to bots/slaves/bot-wmt-es.php index 737dba2..1232f50 100644 --- a/slaves/bot-wmt-es.php +++ b/bots/slaves/bot-wmt-es.php @@ -2,20 +2,11 @@ <?php /* --------------------------------------------- - -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2011-12-31 -Last modified : 2012-05-19 - -script of the bot that monitors #wmt-es - +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) +Channel: #wmt-es --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -35,10 +26,6 @@ #### #### ###### FUNCTIONS ###### #### #### - - - - #### #### ###### INITIALISATION DU BOT !!! ###### @@ -83,7 +70,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -94,7 +80,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -105,7 +90,6 @@ { $project = $matches[1]; $user = $matches[2]; - $irc->send($bot_channel,"\0036New user account : $user\003 \00315http://$project.org/wiki/Special:Contributions/".urlencode(str_replace(' ','_',$user))."\003"); } // + modifications non patrouillées @@ -117,15 +101,11 @@ $user = $matches[4]; $comment = $matches[6]; $commentfoo = (!empty($comment)) ? " - \00315$comment\003" : ""; - $irc->send($bot_channel, "\00313$project\003 : \002$user\002 edited \00310$page\003$commentfoo - \0032$patrollink\003"); } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-fr-copyvio.php b/bots/slaves/bot-wmt-fr-copyvio.php similarity index 98% rename from slaves/bot-wmt-fr-copyvio.php rename to bots/slaves/bot-wmt-fr-copyvio.php index 9811e46..53479d7 100644 --- a/slaves/bot-wmt-fr-copyvio.php +++ b/bots/slaves/bot-wmt-fr-copyvio.php @@ -2,20 +2,11 @@ <?php /* --------------------------------------------- - -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2012-05-27 -Last modified : 2012-05-27 - -script of the bot that monitors #wmt-fr-copyvio - +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) +Channel: #wmt-fr-copyvio --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -46,12 +37,10 @@ // if the page has been created, the diff is the current content if (empty($old)) return $new; - $file1 = tempnam('/tmp','diff_'); $file2 = tempnam('/tmp','diff_'); file_put_contents($file1,$old); file_put_contents($file2,$new); - $out = array(); $temp = array('added'=>array(),'removed'=>array()); $result = array(); @@ -59,7 +48,6 @@ $id = -1; @exec('diff -d --suppress-common-lines '.escapeshellarg($file1).' '.escapeshellarg($file2),$out); - foreach ($out as $line) { if (preg_match('#^([0-9]+),?([0-9]*)([ac])([0-9]+),?([0-9]*)$#', $line, $m)) { // no need to use the 'd' - #^([0-9,]+)([acd])([0-9,]+)$# @@ -69,25 +57,21 @@ $removed_nbline = $m[1]; $added_nbline = $m[4]; } - if ($type == 'a' && preg_match('/^\> .*$/', $line)) { $temp['added'][$added_nbline] = substr($line,2); $added_nbline++; } - elseif ($type == 'c') { if (preg_match('/^\> ?.*$/',$line)) { // 0 is the code for empty lines $temp['added'][$added_nbline] = (strlen($line)>2) ? substr($line,2) : NULL; $added_nbline++; } - elseif (preg_match('/^\< ?.*$/',$line)) { $temp['removed'][$removed_nbline] = (strlen($line)>2) ? substr($line,2) : NULL; $removed_nbline++; } } } - // il y a un problème, le bot plante certaines fois, ça peut venir d'ici foreach ($temp['added'] as $id => $val) @@ -97,7 +81,6 @@ if (empty($temp['removed']) OR !array_key_exists($id,$temp['removed'])) { $result[] = $val; } - // if a line has been change, we try to check if it's really a change, or a copy that has some similarities // if more than 50% of the words in the first version are in the second one, we'll consider it as a simply change and not as an added line to check else @@ -105,21 +88,17 @@ // changed line $words_added = explode(' ', $val); $words_removed = explode(' ', $temp['removed'][$id]); - $count = 0; foreach ($words_added as $w) if (in_array($w,$words_removed)) $count++; - if ($count / count($words_added) <= 0.50) $result[] = $val; } } } - unset($out); unlink($file1); unlink($file2); - return $result; } //end diff function @@ -127,40 +106,28 @@ function google_results ($article, $str) { global $http; - $url = 'http://www.google.com/search?hl=fr&q='.urlencode('"'.str_replace('"','',$str).'"'); $wplink = 'http://fr.wikipedia.org/wiki/'.urlencode(urlencode(str_replace(' ','_',$article))); - $html = $http->get($url); $html = mb_convert_encoding ($html, 'UTF-8', 'US-ASCII'); - if (preg_match('#Aucun résultat trouvé pour <b>#', $html)) return NULL; - else { $results = array(); - preg_match_all ('#<li class="g">(.*)</li>#U', $html, $matches); - foreach ($matches[1] as $v) { # preg_match ('#<div class="s">(.*)</div>#U', $v, $m); - if (preg_match ('#<a href="/url\?q=(.+)&#U', $v, $m)) $results[] = $m[1]; } - var_dump($wplink, $results); echo "\n"; - // si l'article de Wikipédia est dans les liens Google, on ne détecte rien if (in_array($wplink, $results)) return -1; - if (!empty($results)) return $url; - else return NULL; } - /* </script></ol></div></div><div id="botabar" style="display:none"><div></div></div></div></div><div class="mw" id="ucs"></div><div class="mw"><div id="arcntc"></div><div id="rcnt" style="clear:both;position:relative;zoom:1"><div id="leftnavc"><div id="leftnav" role="navigation" onclick="google.psy&&google.psy.qs(event)" style="position:absolute;top:1px;width:132px"><div id=ms><ul><li class="mitem msel"><div class="kls">Tout</div></li><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=isch&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=2&ved=0CA8Q_AUoAQ">Images</a></li><li class="mitem"><a class="kl" href="http://maps.google.com/maps?q=Quentinv57&um=1&ie=UTF-8&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=3&ved=0CBAQ_AUoAg">Maps</a></li><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=vid&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=4&ved=0CBEQ_AUoAw">Vidéos</a></li><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=nws&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=5&ved=0CBIQ_AUoBA">Actualités</a></li><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=shop&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=6&ved=0CBMQ_AUoBQ">Shopping</a></li></ul><ul class=nojsb id="hidden_modes"><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=bks&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=1&ved=0CBQQ_AUoAA">Livres</a></li><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=plcs&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=2&ved=0CBUQ_AUoAQ">Adresses</a></li><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=blg&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=3&ved=0CBYQ_AUoAg">Blogs</a></li><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=dsc&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=4&ved=0CBcQ_AUoAw">Discussions</a></li><li class="mitem"><a class="kl" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnms&tbm=app&ei=We-iT9SKH8fJhAeK_t34Dg&sa=X&oi=mode_link&ct=mode&cd=5&ved=0CBgQ_AUoBA">Applications</a></li></ul><a href="#" id=showmodes class="jsb nj kl" onclick="google.x(this.id,function(){google.srp.toggleModes()});google.log('', '&ved=0CA0Q_gU' +'&ei=' + google.kEI);return false"><span class="msm">Plus</span><span class="msl">Moins</span></a></div><div id="bms"><div class="lnsep"></div><div style="clear:both;overflow:hidden"><h2 class=hd>Options de recherche</h2><ul id=tbd class="med"><li><ul class="tbt"><li class="tbos" id=lr_ onclick="return google.Toolbelt.tbosClk(event)">Recherche sur le Web<li class="tbou" id=lr_lang_1fr><a class="q qs" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnt&tbs=lr:lang_1fr&lr=lang_fr&sa=X&ei=We-iT9SKH8fJhAeK_t34Dg&ved=0CAkQpwUoAQ">Rechercher les pages en Français</a><li class="tbou" id=clir_1><a class="q qs" href="/search?q=Quentinv57&hl=fr&prmd=imvns&source=lnt&tbs=clir:1&sa=X&ei=We-iT9SKH8fJhAeK_t34Dg&ved=0CAoQpwUoAg">Pages en langue étrangère traduites</a></ul><li class=jsb style='display:none'><ul class="tbt"></ul><li class=jsb style='display:none'><ul class="tbt"></ul></ul><a href="/search?q=Quentinv57&hl=fr&prmd=imvns&tbo=1" class="nj q pi pt" id=tbpi onclick="return google.x(this,function(){return google.Toolbelt.togglePromotedTools('0CAsQwxE')});" style="clear:both;display:block;"><span class=tbpo>Moins d'outils</span><span class=tbpc>Plus d'outils</span></a></div></div></div></div><div id="center_col"><div id="bst" style="display:none"></div><span id="taw" style="margin-right:0"><div></div><div style="padding:0 8px"></div></span><div class="med" id="res" role="main"><div id="topstuff"></div> <div id="search"><!--a--><h2 class="hd">Résultats de recherche</h2><div id="ires"><ol eid="We-iT9SKH8fJhAeK_t34Dg" id="rso"> @@ -177,14 +144,11 @@ function is_wikitext ($str) { - } function remove_wikitext ($str) { $str = str_replace ('', '', $str); - - return $str; } @@ -229,7 +193,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -240,7 +203,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -257,13 +219,11 @@ $user = $matches[5]; $bytechange = intval($matches[6]); $comment = $matches[7]; - // on ignore les pages de discussion - if (substr($article,0,10)!='Discussion') // on restreint à l'espace principal if (!preg_match('#:#',$article)) { $revisions = $wpapi->revisions ($article, 2, 'older', true, $diff); $added_lines = diff($revisions[1]['*'],$revisions[0]['*']); - if (!empty($added_lines)) { // we can now analyse the contribution we're dealing with and compare with Google to check whether it's a copyright violation or not @@ -274,38 +234,30 @@ foreach ($added_lines as $line) { $words = explode(' ',$line); $nbwords = count($words); - if (($nbwords < 50) AND ($nbwords > 10)) // on retirera ensuite tout le wikitexte, etc. $skipped++; - // if there's more than 20 words, we check it 10 words per 10 words and submit to Google if ($nbwords > 50) { // on scan tous les 50 mots par paragraphe ? for ($i=0; $i<(($nbwords / 50)-1); $i++) { $test = implode (' ', array_slice ($words, $i*50+10, 10)); - #var_dump($test); $google = google_results($article, $test); - if (!empty($google)) $reqtrue[] = $google; $req++; if ($req >= 10 OR $google==-1) break 2; // max. 10 request to Google by page } } - // we also check 1 of 3 lines with less than 20 words elseif (($skipped % 3 == 0) AND ($nbwords > 10)) { $test = implode (' ', array_slice ($words, 0, 10)); - #var_dump($test); $google = google_results($article, $test); - if (!empty($google)) $reqtrue[] = $google; $req++; if ($req >= 10 OR $google==-1) break; // max. 10 request to Google by page } } - if ($req>0) { $irc->send ($bot_channel, "$user edited $article - http://fr.wikipedia.org/w/index.php?oldid=$oldid&diff=$diff") ; if ($google==-1) { @@ -321,11 +273,8 @@ } } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-fr.php b/bots/slaves/bot-wmt-fr.php similarity index 92% rename from slaves/bot-wmt-fr.php rename to bots/slaves/bot-wmt-fr.php index fbd0546..31992c6 100644 --- a/slaves/bot-wmt-fr.php +++ b/bots/slaves/bot-wmt-fr.php @@ -2,20 +2,12 @@ <?php /* --------------------------------------------- +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2011-12-31 -Last modified : 2012-05-19 - -script of the bot that monitors #wmt-fr - +Channel: #wmt-fr --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -35,9 +27,6 @@ #### #### ###### FUNCTIONS ###### #### #### - - - #### #### @@ -83,7 +72,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -94,7 +82,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -105,7 +92,6 @@ { $project = $matches[1]; $user = $matches[2]; - $irc->send($bot_channel,"\0036New user account : $user\003 \00315http://$project.org/wiki/Special:Contributions/".urlencode(str_replace(' ','_',$user))."\003"); } // + modifications non patrouillées @@ -117,15 +103,11 @@ $user = $matches[4]; $comment = $matches[6]; $commentfoo = (!empty($comment)) ? " - \00315$comment\003" : ""; - $irc->send($bot_channel, "\00313$project\003 : \002$user\002 edited \00310$page\003$commentfoo - \0032$patrollink\003"); } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-ko.php b/bots/slaves/bot-wmt-ko.php similarity index 93% rename from slaves/bot-wmt-ko.php rename to bots/slaves/bot-wmt-ko.php index 414b0f3..2086090 100755 --- a/slaves/bot-wmt-ko.php +++ b/bots/slaves/bot-wmt-ko.php @@ -2,20 +2,12 @@ <?php /* --------------------------------------------- +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2011-12-31 -Last modified : 2012-05-19 - -script of the bot that monitors #wmt-ko - +Channel: #wmt-ko --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -35,9 +27,6 @@ #### #### ###### FUNCTIONS ###### #### #### - - - #### #### @@ -83,7 +72,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -94,7 +82,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -105,7 +92,6 @@ { $project = $matches[1]; $user = $matches[2]; - $irc->send($bot_channel,"\0036ì ê³ì ì´ ìì±ëììµëë¤: $user\003 \00315http://$project/wiki/Special:Contribs/".urlencode(str_replace(' ','_',$user))."\003"); } // + modifications non patrouill饳 @@ -137,15 +123,11 @@ $bytediff = "$diffcolor($sizediff)$diffend"; $comment = $matches[6]; $commentfoo = (!empty($comment)) ? " - \00315$comment\003" : ""; - $irc->send($bot_channel, "\00313$project\003 : \002$user\002 í¸ì§ \00310$page\003 $bytediff $commentfoo - \0032$patrollink\003"); } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-newpages.php b/bots/slaves/bot-wmt-newpages.php similarity index 92% rename from slaves/bot-wmt-newpages.php rename to bots/slaves/bot-wmt-newpages.php index 1b216fb..68fab2e 100644 --- a/slaves/bot-wmt-newpages.php +++ b/bots/slaves/bot-wmt-newpages.php @@ -2,20 +2,12 @@ <?php /* --------------------------------------------- +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2011-12-31 -Last modified : 2012-05-19 - -script of the bot that monitors #wmt-newpages - +Channel: #wmt-newpages --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -35,9 +27,6 @@ #### #### ###### FUNCTIONS ###### #### #### - - - #### #### @@ -83,7 +72,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -94,7 +82,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -120,15 +107,11 @@ } $comment = $matches[6]; $commentfoo = (!empty($comment)) ? " - \00314$comment\003" : ""; - $irc->send($bot_channel, "\00313$project\003 : \002$user\002 created$type \00310$page\00314$commentfoo\x0F $color(+$sizediff)\x0F - \0032$patrollink\003"); } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-ru.php b/bots/slaves/bot-wmt-ru.php similarity index 92% rename from slaves/bot-wmt-ru.php rename to bots/slaves/bot-wmt-ru.php index 003a386..72caaca 100644 --- a/slaves/bot-wmt-ru.php +++ b/bots/slaves/bot-wmt-ru.php @@ -2,20 +2,12 @@ <?php /* --------------------------------------------- +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2011-12-31 -Last modified : 2012-05-19 - -script of the bot that monitors #wmt-es - +Channel: #wmt-es --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -35,9 +27,6 @@ #### #### ###### FUNCTIONS ###### #### #### - - - #### #### @@ -83,7 +72,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -94,7 +82,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -105,7 +92,6 @@ { $project = $matches[1]; $user = $matches[2]; - $irc->send($bot_channel,"\0036New user account : $user\003 \00315http://$project.org/wiki/Special:Contributions/".urlencode(str_replace(' ','_',$user))."\003"); } // + modifications non patrouillées @@ -117,15 +103,11 @@ $user = $matches[4]; $comment = $matches[6]; $commentfoo = (!empty($comment)) ? " - \00315$comment\003" : ""; - $irc->send($bot_channel, "\00313$project\003 : \002$user\002 edited \00310$page\003$commentfoo - \0032$patrollink\003"); } } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } -?> +?> diff --git a/slaves/bot-wmt-spambots.php b/bots/slaves/bot-wmt-spambots.php similarity index 96% rename from slaves/bot-wmt-spambots.php rename to bots/slaves/bot-wmt-spambots.php index 1a6a94b..54bb865 100644 --- a/slaves/bot-wmt-spambots.php +++ b/bots/slaves/bot-wmt-spambots.php @@ -2,20 +2,12 @@ <?php /* --------------------------------------------- +Author: Quentinv57 +Licence: GNU General Public License v3 + (see http://www.gnu.org/licenses/) -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2012-05-10 -Last modified : 2012-05-19 - -script of the bot that monitors #wmt-spambots - +Channel: #wmt-spambots --------------------------------------------- */ - - #### #### ###### INCLUDES ET CONSTANTES ###### @@ -70,7 +62,6 @@ function get_name_type ($name) { $patterns = array ( '/[A-Z]/', '/[a-z]/', '/[0-9]/' ); $replacements = array ( 'A', 'a', '0' ); - return preg_replace ($patterns, $replacements, $name); } @@ -79,7 +70,6 @@ // on privilégie la rapidité à l'exhaustivité $len1 = strlen($name1); $len2 = strlen($name2); - // diff1 is sense --> $diff1 = 0; $k = 0; @@ -94,7 +84,6 @@ if ($k>$len2-1) break; } - // diff2 is sense <-- $diff2 = 0; $k = $len2-1; @@ -114,39 +103,32 @@ function get_common_letters ($name1, $name2) { $count = 0; - for ($i=0;$i<min(strlen($name1),strlen($name2));$i++) { if ($name1[$i]==$name2[$i]) $count++; } - return $count; } function get_prefix_length ($name1, $name2) { $count = 0; - for ($i=0;$i<min(strlen($name1),strlen($name2));$i++) { if ($name1[$i]==$name2[$i]) $count++; - else break; } - return $count; } function contain_numbers ($type) { $res = FALSE; - for ($i=0;$i<$type;$i++) { if ($type[$i]=='0') { $res = TRUE; break; } } - return $res; } @@ -158,7 +140,6 @@ function is_alphanumeric ($name) { if (preg_match('#^[A-Za-z0-9]+$#',$name)) return TRUE; - else return FALSE; } @@ -167,17 +148,13 @@ // nb de fois qu'on passe d'une lettre à un chiffre, ou vice versa { $res = 0; - for ($i=1; $i<strlen($type); $i++) { if (strtolower($type[$i])!=strtolower($type[($i-1)])) $res++; } - return $res; } - - #### #### ###### INITIALISATION DU BOT !!! ###### @@ -223,7 +200,6 @@ $irc-> AutreCommande ( "PONG $tab[1]" ) ; echo "PING PONG OK\n" ; } - if ( $tab[0] == "ERROR" ) { // Restarts the current process @@ -234,7 +210,6 @@ } } } - // ------------------------------- // Wikirc Script // ------------------------------- @@ -244,13 +219,11 @@ { $project = $matches[1]; $user = $matches[2]; - // We will only analyse usernames which are alphanumeric if (is_alphanumeric($user)) { echo $user."\n"; $type = get_name_type($user); $continue = TRUE; - // We check if the user matches the regexes if ($continue) { foreach ($array_regexes as $rgx) { @@ -261,7 +234,6 @@ } } } - // We check if it could be the spambot with numbers if ($continue) { if (nb_type_change($type) >= NB_TYPE_CHANGES_MIN) { @@ -269,7 +241,6 @@ $continue = FALSE; } } - // Then we check the differences between user types and names if ($continue) { foreach ($lastusers_array_names as $k => $n) { @@ -278,7 +249,6 @@ $cl = get_common_letters ($user,$n); $prefix = max(get_prefix_length ($user,$n),get_prefix_length (strrev($user),strrev($n))); $diff_needed = max(strlen($user),strlen($n)); - if ($user!=$n AND (abs(strlen($user)-strlen($n)) <= COMPARISON_LENGTH_DIFFMAX)) { if ( ($type==$t AND $prefix >= 2 AND contain_numbers($t)) @@ -296,19 +266,15 @@ } } } - - // The user is finally stocked in the lastusers array : $lastusers_array_names[$lastusers_nb] = $user; $lastusers_array_types[$lastusers_nb] = $type; $lastusers_nb = ($lastusers_nb<(NB_NAMES_TO_KEEP-1)) ? $lastusers_nb+1 : 0; - // Report to the channel : #if ($continue) # $irc->send($bot_channel,"(test mode) \0036New user account : $user\003 \00315http://meta.wikimedia.org/wiki/Special:CentralAuth/".urlencode(str_replace(' ','_',$user))."\003"); } } - /* Display created user pages (disactivated) elseif (preg_match('#^([^ ]+) :14\[\[07([^:]+):([^\]]+)14\]\]4 !N10 02.+ 5\* 03([^\]]+) 5\* \(\+([0-9]+)\) 10#',$data, $matches) AND $matches[3]==$matches[4]) { @@ -316,15 +282,11 @@ $user = $matches[3]; $prefix = (preg_match('/ /',$matches[2])) ? 'User_talk' : 'User'; $bytes_added = $matches[5]; - if (!in_array($project,$array_skip_userpages)) $irc->send($bot_channel,"Warning :\0036 $user\003 created his user page (+$bytes_added) \00315http://$project/wiki/$prefix:".urlencode(str_replace(' ','_',$user))." http://meta.wikimedia.org/wiki/Special:CentralAuth/".urlencode(str_replace(' ','_',$user))."\003"); } */ } - - else usleep(500000); // wait 0.5 seconds - unset($data); // free memory } diff --git a/slaves/irc-wmt-blocks-systemmessages-purge.php b/bots/slaves/irc-wmt-blocks-systemmessages-purge.php similarity index 100% rename from slaves/irc-wmt-blocks-systemmessages-purge.php rename to bots/slaves/irc-wmt-blocks-systemmessages-purge.php diff --git a/slaves/irc-wmt-delete-systemmessages-purge.php b/bots/slaves/irc-wmt-delete-systemmessages-purge.php similarity index 100% rename from slaves/irc-wmt-delete-systemmessages-purge.php rename to bots/slaves/irc-wmt-delete-systemmessages-purge.php diff --git a/slaves/bot-tmp.php b/slaves/bot-tmp.php deleted file mode 100644 index c66e63b..0000000 --- a/slaves/bot-tmp.php +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/php -<?php - -/* --------------------------------------------- - -Author : Quentinv57 - -Licence : GNU General Public License v3 - (see http://www.gnu.org/licenses/) - -Date of creation : 2011-12-31 -Last modified : 2012-05-19 - -script of the bot that monitors #wmt-fr - ---------------------------------------------- */ - - - -#### #### -###### INCLUDES ET CONSTANTES ###### -#### #### -$prefix = '/data/project/quentinv57-common/data/'; -include $prefix.'class/socket.class.php'; -include $prefix.'class/Irc.class.php'; -include '/data/project/irc-wmt/bots/include/config/irc_conf.php'; - -$bot_channel_bots = "#wmt-bots"; -$bot_channel = "#wmt-fr"; -$irc_user .= '-8'; - -#$arr_sock = array ('wikiset'=>'fr'); - - -#### #### -###### FUNCTIONS ###### -#### #### - - - - - -#### #### -###### INITIALISATION DU BOT !!! ###### -#### #### - -// Connexion au serveur rcfeed -#$sock_dir = "/data/project/irc-wmt/bots/tmp/sockets/"; -#$sock = new Socket_client ($sock_dir.'wmt-fr.sock', $sock_dir.'server.sock', $arr_sock); - - -// Configs - settings [le bot récupère les configs dans le fichier] -#$configdata = get_data_from_file(SAVEFILE); - -// Connexion au serveur IRC Freenode -$irc = new Irc ( $irc_freenodeserver , $irc_port , $irc_user , $irc_pwd ) ; -$irc-> identify ( $irc_pwd ) ; sleep(5); -$irc-> join ( $bot_channel_bots ); -$irc-> join ( $bot_channel); - -sleep(2); -$irc->send($bot_channel_bots, "I just restarted and joined $bot_channel with success."); -$irc->send("NickServ", "UNGROUP"); -sleep(10); -$irc->nick("wmtbot-9"); -$irc->send("NickServ", "UNGROUP"); -sleep(2); -$irc->send("NickServ", "identify wmtbot2 <password>"); -sleep(10); -$irc->nick("wmtbot-6"); -$irc->send("NickServ", "GROUP"); -sleep(10); -$irc->nick("wmtbot-7"); -$irc->send("NickServ", "GROUP"); -sleep(10); -$irc->nick("wmtbot-8"); -$irc->send("NickServ", "GROUP"); -sleep(10); -$irc->nick("wmtbot-9"); -$irc->send("NickServ", "GROUP"); -sleep(10); -$irc->nick("wmtbot-10"); -$irc->send("NickServ", "GROUP"); -sleep(10); -exit(); -// variables : -$lastusers_array_names = array(); -$lastusers_array_types = array(); -$lastusers_nb = 0; // to keep only max X entries in the array - -while (1) -{ - // ------------------------------- - // Freenode Script - // ------------------------------- - if ($data = $irc-> getdata ()) - { - $tab = explode (' ', $data); - - if (!empty($data)) - { - // Init freenode script - if ( $tab[0] == "PING" ) - { - $irc-> AutreCommande ( "PONG $tab[1]" ) ; - echo "PING PONG OK\n" ; - } - - if ( $tab[0] == "ERROR" ) - { - // Restarts the current process - $irc->quit() ; - $wm->quit() ; - # Removed the system instruction - the file will be automatically restarted by daemon - exit(3); - } - } - } - - // ------------------------------- - // Wikirc Script - // ------------------------------- - elseif ($data = $sock->read()) - { - // channel : #wmt-fr - if (preg_match('#^([^ ]+) .*4 create10 02 5\* 03(.+) 5\*#',$data, $matches)) - { - $project = $matches[1]; - $user = $matches[2]; - - $irc->send($bot_channel,"\0036New user account : $user\003 \00315http://$project.org/wiki/Special:Contributions/".urlencode(str_replace(' ','_',$user))."\003"); - } - // + modifications non patrouillées - elseif (preg_match('#^([^ ]+) :14\[\[07([^\]]+)14\]\]4 [MNB]*![MNB]*10 02([^\*]+) 5\* 03(.+) 5\* \([\+-]([0-9]+)\) 10(.*)$#', $data, $matches)) - { - $project = $matches[1]; - $page = $matches[2]; - $patrollink = $matches[3]; - $user = $matches[4]; - $comment = $matches[6]; - $commentfoo = (!empty($comment)) ? " - \00315$comment\003" : ""; - - $irc->send($bot_channel, "\00313$project\003 : \002$user\002 edited \00310$page\003$commentfoo - \0032$patrollink\003"); - } - } - - - else usleep(500000); // wait 0.5 seconds - - unset($data); // free memory -} - -?> -- To view, visit https://gerrit.wikimedia.org/r/195111 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icb17486317b19916e310c641d91f218830ebf5b8 Gerrit-PatchSet: 1 Gerrit-Project: labs/tools/WMT Gerrit-Branch: master Gerrit-Owner: John F. Lewis <johnflewi...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits