Commit a87a46a6 authored by Freddy's avatar Freddy

first commit

parents
# ipp
https://tools.wmflabs.org/freddy2001/ipp/
<?php
include "DBPassword.php";
class DBCore extends DBPassword {
protected $DBusername;
protected $DBDBpassword;
protected $database;
protected $DB;
public function __construct ($Accountdata, $Database) {
$a=0;
$Found = false;
$this->init();
$LoginName = unserialize($this->getLoginName ());
$LoginAccount = unserialize($this->getLoginAccount());
$LoginDBpassword = unserialize($this->getLoginDBpassword());
while (isset ($LoginName [$a]) === true) {
if ($LoginName [$a] === $Accountdata) {
$this->DBusername = $LoginAccount [$a];
$this->DBpassword = $LoginDBpassword [$a];
$Found = true;
}
$a++;
}
if (!$Found) {
throw new Exception('Keine passenden DB-Anmeldeinformationen vorhanden.');
die(1); // exit with error
}
$this->DB = new mysqli('tools-db', $this->DBusername, $this->DBpassword, $Database);
if ($this->DB->connect_errno) {
echo "Error: Failed to make a MySQL connection, here is why: \n";
echo "Errno: " . $mysqli->connect_errno . "\n";
echo "Error: " . $mysqli->connect_error . "\n";
die (1);
}
}
public function query ($sql, $sensitive = false) {
if(!$result = $this->DB->query($sql)) {
if ($sensitive === false)
die('There was an error running the query [' . $this->DB->error . ']');
else
echo ('\nThere was an error running the query [' . $this->DB->error . ']');
} else if ($result->num_rows === 0) {
return 0;
} else {
return $result;
}
}
public function modify ($sql, $sensitive = false) {
if(!$result = $this->DB->query($sql)) {
if ($sensitive === false)
die('There was an error running the command [' . $this->DB->error . ']');
else
echo ('\nThere was an error running the command [' . $this->DB->error . ']');
}
else
return $result;
}
function __destruct() {
$this->DB->close();
}
}
?>
<?php
class DBpassword
{
/** Dies ist eine Example-Datei
* Damit das Programm funktioniert, muessen die Daten angepasst werden!
*/
private $LoginName;
private $LoginHost;
private $LoginAccount;
private $LoginPassword;
public function __constuct()
{}
protected function init()
{
$toolaccount = "freddy2001";
$ts_mycnf = parse_ini_file("/mnt/nfs/labstore-secondary-tools-project/" . $toolaccount . "/replica.my.cnf");
$this->LoginName = array( // Empfohlen: Username@wiki
'db@localhost',
);
# Bitte beachten, Accounts müssen in der selben Reihenfolge genannt werden, wie bei LoginName! #
$this->LoginHost = array( // Internetdomain
'tools-db',
);
$this->LoginAccount = array( // Name das Accounts
$ts_mycnf['user'],
);
$this->LoginPassword = array( // Passwort des Accounts
$ts_mycnf['password'],
);
}
protected function getLoginName ()
{
return serialize ($this->LoginName);
}
protected function getLoginHost ()
{
return serialize ($this->LoginHost);
}
protected function getLoginAccount ()
{
return serialize ($this->LoginAccount);
}
protected function getLoginDBpassword ()
{
return serialize ($this->LoginPassword);
}
}
?>
#!/usr/bin/php
<?php
include "DBCore.php";
$DB = new DBCore ('db@localhost', 's53094__ippdata');
$f = fopen("php://stdin", 'r' );
while( $line = fgets( $f ) )
{
if(substr("$line", 0, 5) == "data:") {
$l = json_decode(substr($line, 5), true);
} else {
$l = "";
}
if($l != "") {
if($l['wiki'] == "dewiki") {
if($l['bot'] != 1) {
if($l['type'] == "edit") {
$revision = $l['revision']['new'];
$oldid = $l['revision']['old'];
$new = json_decode(curlRequest("de.wikipedia.org/w/api.php?action=query&prop=revisions&revids=" . $revision . "&rvprop=timestamp|user|comment|content|userid&formatversion=2&format=json"), true);
$userid = $new['query']['pages'][0]['revisions'][0]['userid'];
$old = json_decode(curlRequest("de.wikipedia.org/w/api.php?action=query&prop=revisions&revids=" . $oldid . "&rvprop=timestamp|user|comment|content|userid&formatversion=2&format=json"), true);
$user = urlencode($new['query']['pages'][0]['revisions'][0]['user']);
$comment = urlencode($new['query']['pages'][0]['revisions'][0]['comment']);
$title = urlencode($new['query']['pages'][0]['title']);
$newcontent = $new['query']['pages'][0]['revisions'][0]['content'];
$oldcontent = $old['query']['pages'][0]['revisions'][0]['content'];
if($userid == 0) {
$anon = true;
} else {
$anon = false;
}
if($revision == 0) {
$new = true;
} else {
$new = false;
}
if($l['minor'] == 1) {
$minor = true;
} else {
$minor = false;
}
$changelenth = strlen($newcontent) - strlen($oldcontent);
$score = 0;
$scorewords = array("haha", "fuuuu", "!!!!!!", "??????", "lesb", "faggot", "hihi", "hahaha", "pimmel", "kack", "cool", "rape", "raping", "bla", "sex", "tits", "porn", "yeah", "yea", "yee", "balls", "weed", "arse", "stupid", "hello", "homosexual", "hallo", "idiot", "doof","crackhead", "bieber", "porn", "bold text", "italic text", "crap", "p3n1s", "omg", "lmao", "rofl", "blabla", "hure", "pr0n", "p0rn", "sh1t", "bullshit", "scheiße", "scheisse", "scheis", "piss", "pisse", "arsch", "arschkrampe", "fag", "shit", "gay", "bitch", "penis", "awesome", "gays", "faggots", "suck", "sucks", "boobs", "pussy", "cunt", "poop", "poo", "whore", "schwuchtel", "ficken", "hitler", "stinkt", "kaka", ":)", ":-)", ":P", ":D", "pen1s", "b1tch", "p1ss", "fuck", "asshole", "retard", "=)", "(:", "asshat", "fucknugget", "motherfucker", "fucktard", "arsehole", "swag", "butt", "-.-", "dipshit", "dipstick", "asswipe", "cunt", "twat", "yolo", "fuckoff", "fuck you", "wanker", "sucks dick", "lol", "boobs", "masturbate", "fucking", "nigger", "niga", "nigga", "derp", "derpy", "butthole", "tit", "bum", "arschloch", "titten", "hurensohn", "hurensöhne", "peenis", "peeenis", "peeeenis", "peeeeenis");
for($i = 0; count($scorewords) > $i; $i++) {
$oldscore = substr_count($oldcontent, $scorewords[$i]);
$newscore = substr_count($oldcontent, $scorewords[$i]);
$scoresum = $newscore - $oldscore;
if($scoresum != 0) {
$score = $score + $scoresum;
}
}
$score = $score * 30;
if($anon == true) {
$sql = "INSERT INTO `ipp_changes` (`id`, `title`, `oldid`, `newid`, `changesize`, `user`, `minor`, `new`, `comment`, `time`, `spam`) VALUES ('$revision', '$title ', '$oldid', '$revision', '$changelenth', '$user', '$minor', '$new', '$comment', CURRENT_TIMESTAMP, '$score');";
$DB->modify($sql);
}
}
}
}
}
}
/** curlRequest
* Sendet einen Curl-Request an eine beliebige Webseite
* @author: Freddy2001 <freddy2001@wikipedia.de>
* @param $url - URL der Seite
* @param $https - true:benutze https, false: benutze http
*/
function curlRequest($url, $https = true) {
if($https == true) {
$protocol = 'https';
} else {
$protocol = 'http';
}
$baseURL = $protocol . '://' .
$url;
$Job = $baseURL;
$curl = curl_init();
if (!$baseURL)
throw new Exception('no arguments for http request found.');
// set curl options
curl_setopt($curl, CURLOPT_USERAGENT, "Cygnus");
curl_setopt($curl, CURLOPT_URL, $baseURL);
curl_setopt($curl, CURLOPT_ENCODING, "UTF-8");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, realpath('Cookies' . $Job . '.tmp'));
curl_setopt($curl, CURLOPT_COOKIEJAR, realpath('Cookies' . $Job . '.tmp'));
curl_setopt($curl, CURLOPT_POST, 0);
curl_setopt($curl, CURLOPT_POSTFIELDS, '');
// perform request
$rqResult = curl_exec($curl);
if ($rqResult === false)
throw new Exception('curl request failed: ' . curl_error($curl));
return $rqResult;
}
fclose( $f );
?>
#!/bin/bash
while true; do
curl -s https://stream.wikimedia.org/v2/stream/recentchange | php -f rcbot.php > rcbot.log
sleep 300
done
// global xmlhttprequest object
var xmlHttp = false;
/** AJAX functions **/
// constants
var REQUEST_GET = 0;
var REQEST_POST = 2;
var REQUEST_HEAD = 1;
var REQUEST_XML = 3;
/**
* instantiates a new xmlhttprequest object
*
* @return xmlhttprequest object or false
*/
function getXMLRequester( )
{
var xmlHttp = false;
// try to create a new instance of the xmlhttprequest object
try
{
// Internet Explorer
if( window.ActiveXObject )
{
for( var i = 5; i; i-- )
{
try
{
// loading of a newer version of msxml dll (msxml3 - msxml5) failed
// use fallback solution
// old style msxml version independent, deprecated
if( i == 2 )
{
xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
}
// try to use the latest msxml dll
else
{
xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
}
break;
}
catch( excNotLoadable )
{
xmlHttp = false;
}
}
}
// Mozilla, Opera und Safari
else if( window.XMLHttpRequest )
{
xmlHttp = new XMLHttpRequest();
}
}
// loading of xmlhttp object failed
catch( excNotLoadable )
{
xmlHttp = false;
}
return xmlHttp ;
}
/**
* sends a http request to server
*
* @param strSource, String, datasource on server, e.g. data.php
*
* @param strData, String, data to send to server, optionally
*
* @param intType, Integer,request type, possible values: REQUEST_GET, REQUEST_POST, REQUEST_XML, REQUEST_HEAD default REQUEST_GET
*
* @param strData, Integer, ID of this request, will be given to registered event handler onreadystatechange', optionally
*
* @return String, request data or data source
*/
function sendRequest( strSource, strData, intType, intID )
{
if( !strData )
strData = '';
// default type (0 = GET, 1 = xml, 2 = POST )
if( isNaN( intType ) )
intType = 0; // GET
// previous request not finished yet, abort it before sending a new request
if( xmlHttp && xmlHttp.readyState )
{
xmlHttp.abort( );
xmlHttp = false;
}
// create a new instance of xmlhttprequest object
// if it fails, return
if( !xmlHttp )
{
xmlHttp = getXMLRequester( );
if( !xmlHttp )
return;
}
// parse query string
if( intType != 1 && ( strData && strData.substr( 0, 1 ) == '&' || strData.substr( 0, 1 ) == '?' ) )
strData = strData.substring( 1, strData.length );
// data to send using POST
var dataReturn = strData ? strData : strSource;
switch( intType )
{
case 1: // xml
strData = "xml=" + strData;
case 2: // POST
// open the connection
xmlHttp.open( "POST", strSource, true );
xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
xmlHttp.setRequestHeader( 'Content-length', strData.length );
break;
case 3: // HEAD
// open the connection
xmlHttp.open( "HEAD", strSource, true );
strData = null;
break;
default: // GET
// open the connection
var strDataFile = strSource + (strData ? '?' + strData : '' );
xmlHttp.open( "GET", strDataFile, true );
strData = null;
}
// set onload data event-handler
xmlHttp.onreadystatechange = new Function( "", "processResponse(" + intID + ")" ); ;
// send request to server
xmlHttp.send( strData ); // param = POST data
return dataReturn;
}
/**
* process the response data from server
*
* @param intID, Integer, ID of this response
*/
function processResponse( intID )
{
// status 0 UNINITIALIZED open() has not been called yet.
// status 1 LOADING send() has not been called yet.
// status 2 LOADED send() has been called, headers and status are available.
// status 3 INTERACTIVE Downloading, responseText holds the partial data.
// status 4 COMPLETED Finished with all operations.
switch( xmlHttp.readyState )
{
// uninitialized
case 0:
// loading
case 1:
// loaded
case 2:
// interactive
case 3:
break;
// complete
case 4:
// check http status
if( xmlHttp.status == 200 ) // success
{
processData( xmlHttp, intID );
}
// loading not successfull, e.g. page not available
else
{
if( window.handleAJAXError )
handleAJAXError( xmlHttp, intID );
else
alert( "ERROR\n HTTP status = " + xmlHttp.status + "\n" + xmlHttp.statusText ) ;
}
}
}
/** End AJAX functions **/
<?php
date_default_timezone_set("UTC");
function design_top($titel)
{
// META-Keywords und Description
global $description, $keywords, $user_javascript, $user_css, $user_onload;
if ($description != "") { $description = "<meta name=\"description\" content=\"" . utf8_encode($description) . "\" />\n"; }
if ($keywords != "") { $keywords = "<meta name=\"keywords\" content=\"" . utf8_encode($keywords) . "\" />\n"; }
print '<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
' . $description . $keywords . '
<link rel="stylesheet" type="text/css" href="wikipedia.css" title="main" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="druck.css" title="main" media="print" />
<title>' . $titel . '</title>
' . $user_javascript . '
' . $user_css . '
</head>
<body'. $user_onload . '>
<div id="info_balken">
<div id="info_text">' . $titel . '</div>
</div>
<div id="url">' . $titel . '</div>
<div id="inhalt">
';
}
function design_unten($seealso)
{
// setlocale(LC_TIME, "de_DE");
$datum = strftime("%B %e, %Y %H:%M");
print '
</div>
<div id="navi_balken">
<p><b>See also:</b> ' . $seealso . '</p>
</div>
<div id="copyright">
' . $datum . ' UTC<br />
Freddy2001<br /><small>rewritten based on the <a href="https://tools.wmflabs.org/ipp/">ipp project</a> by Christian Thiele.</small>
</div>
</body>
</html>
';
}
?>
/* druck.css */
img
{
border-width:0;
}
body
{
font-family:Verdana, sans-serif;
font-size:10pt;
color:#000000;
background-image:none;
}
#info_balken
{
font-size:28pt;
font-weight:bold;
width:100%;
border-bottom:3px solid black;
letter-spacing:-3px;
}
#url
{
float:left;
font-size:8pt;
}
#toolserver_text
{
display:none;
}
#navigation
{
margin-top:4px;
float:right;
}
/* Inhalt */
#inhalt
{
margin-top:80px;
}
#inhalt h1
{
border-bottom:1px solid #000000;
font-size:20pt;
}
/* Unterer weisser Balken fuer Impressum... */
#navi_balken
{
display:none;
}
/* Besucheranzahl / Copyrighthinweis */
#copyright
{
margin-top:30px;
width:100%;
text-align:center;
}
#xhtml
{
display:none;
}
This diff is collapsed.
<?php
global $user_css, $user_javascript, $user_onload;
$user_css = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" title=\"main\" media=\"screen, projection\" />";
$remove = "true";
if (isset($_GET['noremove'])) $remove = "false";
$user_javascript = "
<script type='text/javascript' src='ajax.js'></script>
<script type='text/javascript'>
<!--
// settings
set_newentries = 'top'; // 'top' or 'bottom';
set_maxentries = 40;
set_remove = " . $remove . ";
// removes an ip patrol entry
function entry_remove(id)
{
if (id.substring(0, 6) != 'entry_') { id = 'entry_' + id; }
var e = document.getElementById(id);
if (set_remove)
{
if (e != null) e.parentNode.removeChild(e);
}
else
{
e.style.color = '#777777';
var aTags = e.getElementsByTagName('a');
for (i = 0; i < aTags.length; i++)
aTags[i].style.color = '#777777';
}
}
// end entry_remove()
// adds an ip patrol entry
function entry_add(id, timestamp, title, desc, change, user, isnew, spam)
{
var newentry = document.createElement('tr');
newentry.setAttribute('id', 'entry_' + id);
newentry.className = 'et_entry';
if (parseInt(change) < -200) { newentry.className = 'et_vandale'; }
// add columns
var cd = new Date(parseInt(timestamp) * 1000);
var zeit = ((cd.getHours() < 10) ? '0' : '') + cd.getHours() + ':';
zeit += ((cd.getMinutes() < 10) ? '0' : '') + cd.getMinutes();
var datum = ((cd.getDate() < 10) ? '0' : '') + cd.getDate() + '.';
datum += (((cd.getMonth()+1) < 10) ? '0' : '') + (cd.getMonth()+1) + '.';
datum += cd.getFullYear();
var col1 = document.createElement('td');
col1.innerHTML = '<b>' + zeit + '</b><br /><span class=\"date\">' + datum + '</span>';
col1.className = 'textcenter';
// make /* */ grey...
desc = desc.replace(/\/\*(.*)\*\//, \"<span style=\'color:#AAAAAA;\'>$1</span>\");
if (desc == '') desc = '&nbsp;';
// new entry
output_new = '';
if (isnew > 0) { output_new = ' &bull; <span class=\"wp_neu\">NEU</span>'; }
var col2 = document.createElement('td');
col2.innerHTML = '<a href=\"mark.php?id=' + id + '\" onclick=\"entry_remove(\'' + id + '\');\" target=\"_blank\" style=\"display:block; width:100%; text-decoration:none;\"><b style=\"text-decoration:underline;\">' + title + '</b>' + output_new + '<br /><i>' + desc + '</i></a>';
var col3 = document.createElement('td');
col3.innerHTML = change;
if (change > 0) { col3.innerHTML = '+' + col3.innerHTML; }
col3.className = 'textcenter';
var col4 = document.createElement('td');
col4.innerHTML = spam + '%';
col4.className = 'textcenter';
var col5 = document.createElement('td');
col5.innerHTML = '<a href=\"http://de.wikipedia.org/w/wiki.phtml?title=Spezial:Contributions&amp;target=' + user + '\" id=\"entry_' + id + '_user\" target=\"_blank\">' + user + '</a><br />';
col5.innerHTML += '<a href=\"javascript:clickVandale(\'' + id + '\');\" id=\"entry_' + id + '_vandallink\">IP markieren</a>';
newentry.appendChild(col1);
newentry.appendChild(col2);
newentry.appendChild(col3);
newentry.appendChild(col4);
newentry.appendChild(col5);
var d = document.getElementById('edittable');
d = d.getElementsByTagName(\"TBODY\")[0]; // this is needed for IE
// new entry at the top or at the bottom?
if (set_newentries == 'bottom')
d.appendChild(newentry);
else
d.insertBefore(newentry, document.getElementById('et_heading').nextSibling);
// remove all entries, which are too much ;)
if (d.getElementsByTagName('TR').length > set_maxentries + 1)
{
var e = d.getElementsByTagName('TR');
// remove one element at the top
if (set_newentries == 'bottom')
entry_remove(e[1].id);
// remove one element at the bottom
else
entry_remove(e[e.length-1].id);
}
}
// end entry_add()
function markVandale(id)
{
if (id.substring(0, 6) != 'entry_') { id = 'entry_' + id; }
document.getElementById(id).className = 'et_vandale';
document.getElementById(id + '_vandallink').innerHTML = 'IP demarkieren';
}
function unmarkVandale(id)
{
if (id.substring(0, 6) != 'entry_') { id = 'entry_' + id; }
document.getElementById(id).className = 'et_entry';
document.getElementById(id + '_vandallink').innerHTML = 'IP markieren';
}
function toggleVandale(id)
{
if (id.substring(0, 6) != 'entry_') { id = 'entry_' + id; }
if (document.getElementById(id).className == 'et_entry')
markVandale(id);
else
unmarkVandale(id);
}
function clickVandale(id)
{
// what ip?
var user = getInnerText(document.getElementById('entry_' + id + '_user'));
// send to server
if (document.getElementById('entry_' + id).className == 'et_entry')
{
sendRequest('vandale.php','?ip=' + user,REQUEST_GET,2);
vandal_new(user);
}
else
{
sendRequest('vandale2.php','?ip=' + user,REQUEST_GET,2);
vandal_old(user);
}
}
function getInnerText(xmlelement)
{
if (xmlelement.firstChild == null)
return '';
else
return xmlelement.firstChild.data;
}
function entries_new(entriesXML)
{