So, der Code enthielt ja einige übertragungsfehler... ich hab das jetzt auch unter 2.0.2 laufen... hier der code nochmal in hofentlich fehlerfrei
Code: Alles auswählen
###############################################################################
##
## MOD: Private Nachrichten verschlüsselt in der DB abspeichern
## VER: 0.1.1 - zweite Veröffentlichung (beta)
## FOR: phpBB2 V2.0.1 & 2.0.2 only
##
## AUTOR: Sven Schumacher (bitboy0) bitboy0@terratalk.de
##
## HINWEISE: Die Privaten Nachrichten des Boards werden normal im Klartext
## In der Datenbank abgelegt. Da kann jeder der Zugriff hat alle
## Texte im Klartext lesen. Ebenso stehen die Texte im SQL-DUMP
## den man als Backup aus PHPMyAdmin erhält. Bei manchen Hostern
## kann man evtl mit ein bischen fachwissen auch den Inhalt der
## DB eines anderen Users sehen.
## Um den User besser zu schützen werden PN's mit diesem MOD
## in der DB nur verschlüsselt abgelegt. Die Inhalte werden mit
## einem 32bit-Schlüssel codiert der für jede Nachricht neu erzeugt
## wird. Danach wird die codierte Nachricht in HEX-Code umgewandelt
## der sich einfacher in der DB speichern lässt.
## PN's die vor dem Einbau geschrieben wurden werden nicht ver-
## ändert und können weiter normal angesehen werden.
## Das Subject einer PN wird nicht verschlüsselt.
##
## ACHTUNG: Es handelt sich bei dieser Codierung NICHT um eine sogenannte
## 'starke' Verschlüsselung. Der 32bit Schlüssel kann sicher auch
## mit 'brute force' geknackt werden. Mit diesem MOD kann aber
## zuverlässig verhindert werden das man einen DUMP durchliest oder
## mal eben so mit PHPMyAdmin einzelne Nachrichten ausliest.
##
###############################################################################
##
## Dateien: privmsg.php -> wird geändert
## includes/functions_post.php -> wird ergänzt
##
## DB: {prefix_}privmsgs/privmsgs_key -> wird erstellt
##
###############################################################################
##
##-----[datenbank erweitern]---------------------------------------------------
##
## darauf achten daß das Prefix zu eurem Board passt!
##
ALTER TABLE `phpbb_privmsgs` ADD `privmsgs_key` INT DEFAULT '0' NOT NULL;
##-----[öffne includes/functions_post.php]-------------------------------------
##-----[suche nach]------------------------------------------------------------
$unhtml_specialchars_match = array('#>#', '#<#', '#"#', '#&#');
$unhtml_specialchars_replace = array('>', '<', '"', '&');
##-----[danach einfügen]-------------------------------------------------------
function hex2bin($text)
{
$result = '';
$decode[ 48]= 0; // 0
$decode[ 49]= 1; // 1
$decode[ 50]= 2; // 2
$decode[ 51]= 3; // 3
$decode[ 52]= 4; // 4
$decode[ 53]= 5; // 5
$decode[ 54]= 6; // 6
$decode[ 55]= 7; // 7
$decode[ 56]= 8; // 8
$decode[ 57]= 9; // 9
$decode[ 65]=10; // A
$decode[ 66]=11; // B
$decode[ 67]=12; // C
$decode[ 68]=13; // D
$decode[ 69]=14; // E
$decode[ 70]=15; // F
$decode[ 97]=10; // a
$decode[ 98]=11; // b
$decode[ 99]=12; // c
$decode[100]=13; // d
$decode[101]=14; // e
$decode[102]=15; // f
for($i=0;$i < bcdiv(strlen($text),2);$i++)
{
$result .= chr(($decode[ord(substr($text,$i*2,1))]*16)+$decode[ord(substr($text,($i*2)+1,1))]);
}
return $result;
}
function make_key_array($keyint)
{
if ($keyint < 0) $keyint = bcpow(2,32) + $keyint;
for($i=31;$i>=0;$i--)
{
$test = bcpow(2,$i);
if ($keyint>=$test)
{
$bit = 1;
$keyint = $keyint - $test;
}
else
{
$bit = 0;
}
$key4[bcdiv($i,8)]=chr(ord($key4[bcdiv($i,8)])+bcpow(2,bcmod($i,8))*$bit);
}
return array($key4[0],$key4[1],$key4[2],$key4[3]);
}
function xor_text($text,$keyint,$dir)
{
if ($dir == 2) $text = hex2bin($text);
$key = make_key_array($keyint);
$result = '';
for($i = 0;$i < strlen($text);$i++)
{
$result .= chr(ord(substr($text,$i))^ord($key[bcmod($i,4)]));
}
if ($dir == 1) return bin2hex($result); else return $result;
}
##-----[speichern und schliessen]----------------------------------------------
##-----[öffne privmsg.php]-----------------------------------------------------
##-----[suche nach]------------------------------------------------------------
//
// Processing of post
//
$post_subject = $privmsg['privmsgs_subject'];
$private_message = $privmsg['privmsgs_text'];
##-----[ersetze mit]-------------------------------------------------------
//
// Processing of post
//
$post_subject = $privmsg['privmsgs_subject'];
$msgkey = $privmsg['privmsgs_key'];
$private_message = ($msgkey == 0)? $privmsg['privmsgs_text'] : xor_text($privmsg['privmsgs_text'],$msgkey,2);
##-----[suche nach]------------------------------------------------------------
//
// This makes a copy of the post and stores it as a SENT message from the sendee. Perhaps
// not the most DB friendly way but a lot easier to manage, besides the admin will be able to
// set limits on numbers of storable posts for users ... hopefully!
//
$sql = "INSERT $sql_priority INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig)
VALUES (" . PRIVMSGS_SENT_MAIL . ", '" . str_replace("\'", "''", addslashes($privmsg['privmsgs_subject'])) . "', " . $privmsg['privmsgs_from_userid'] . ", " . $privmsg['privmsgs_to_userid'] . ", " . $privmsg['privmsgs_date'] . ", '" . $privmsg['privmsgs_ip'] . "', " . $privmsg['privmsgs_enable_html'] . ", " . $privmsg['privmsgs_enable_bbcode'] . ", " . $privmsg['privmsgs_enable_smilies'] . ", " . $privmsg['privmsgs_attach_sig'] . ")";
##-----[ersetze mit]-------------------------------------------------------
//
// This makes a copy of the post and stores it as a SENT message from the sendee. Perhaps
// not the most DB friendly way but a lot easier to manage, besides the admin will be able to
// set limits on numbers of storable posts for users ... hopefully!
//
$sql = "INSERT $sql_priority INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig, privmsgs_key)
VALUES (" . PRIVMSGS_SENT_MAIL . ", '" . str_replace("\'", "''", addslashes($privmsg['privmsgs_subject'])) . "', " . $privmsg['privmsgs_from_userid'] . ", " . $privmsg['privmsgs_to_userid'] . ", " . $privmsg['privmsgs_date'] . ", '" . $privmsg['privmsgs_ip'] . "', " . $privmsg['privmsgs_enable_html'] . ", " . $privmsg['privmsgs_enable_bbcode'] . ", " . $privmsg['privmsgs_enable_smilies'] . ", " . $privmsg['privmsgs_attach_sig'] . ", " . $privmsg['privmsgs_key'] . ")";
##-----[suche nach]------------------------------------------------------------
if ( $submit && !$error )
{
##-----[danach einfügen]-------------------------------------------------------
$msgtemp = stripslashes(str_replace("\'", "''", $privmsg_message));
$msgkey = crc32($msgtemp);
if ($msgkey == 0) $msgkey = 1;
$msgcode = xor_text($msgtemp,$msgkey,1);
##-----[suche nach]------------------------------------------------------------
$sql_info = "INSERT INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig)
VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . str_replace("\'", "''", $privmsg_subject) . "', " . $userdata['user_id'] . ", " . $to_userdata['user_id'] . ", $msg_time, '$user_ip', $html_on, $bbcode_on, $smilies_on, $attach_sig)";
##-----[ersetze mit]-----------------------------------------------------------
$sql_info = "INSERT INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig, privmsgs_key)
VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . str_replace("\'", "''", $privmsg_subject) . "', " . $userdata['user_id'] . ", " . $to_userdata['user_id'] . ", $msg_time, '$user_ip', $html_on, $bbcode_on, $smilies_on, $attach_sig, $msgkey)";
##-----[suche nach]------------------------------------------------------------
$sql_info = "UPDATE " . PRIVMSGS_TABLE . "
SET privmsgs_type = " . PRIVMSGS_NEW_MAIL . ", privmsgs_subject = '" . str_replace("\'", "''", $privmsg_subject) . "', privmsgs_from_userid = " . $userdata['user_id'] . ", privmsgs_to_userid = " . $to_userdata['user_id'] . ", privmsgs_date = $msg_time, privmsgs_ip = '$user_ip', privmsgs_enable_html = $html_on, privmsgs_enable_bbcode = $bbcode_on, privmsgs_enable_smilies = $smilies_on, privmsgs_attach_sig = $attach_sig
WHERE privmsgs_id = $privmsg_id";
##-----[ersetze mit]-----------------------------------------------------------
$sql_info = "UPDATE " . PRIVMSGS_TABLE . "
SET privmsgs_type = " . PRIVMSGS_NEW_MAIL . ", privmsgs_subject = '" . str_replace("\'", "''", $privmsg_subject) . "', privmsgs_from_userid = " . $userdata['user_id'] . ", privmsgs_to_userid = " . $to_userdata['user_id'] . ", privmsgs_date = $msg_time, privmsgs_ip = '$user_ip', privmsgs_enable_html = $html_on, privmsgs_enable_bbcode = $bbcode_on, privmsgs_enable_smilies = $smilies_on, privmsgs_attach_sig = $attach_sig , privmsgs_key = $msgkey
WHERE privmsgs_id = $privmsg_id";
##-----[suche nach]------------------------------------------------------------
$sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . str_replace("\'", "''", $privmsg_message) . "')";
##-----[ersetze mit]-----------------------------------------------------------
$sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . $msgcode . "')";
##-----[suche nach]------------------------------------------------------------
$sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . "
SET privmsgs_text = '" . str_replace("\'", "''", $privmsg_message) . "', privmsgs_bbcode_uid = '$bbcode_uid'
WHERE privmsgs_text_id = $privmsg_id";
##-----[ersetze mit]-----------------------------------------------------------
$sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . "
SET privmsgs_text = '" . $msgcode . "', privmsgs_bbcode_uid = '$bbcode_uid'
WHERE privmsgs_text_id = $privmsg_id";
##-----[suche nach]------------------------------------------------------------
$privmsg_subject = $privmsg['privmsgs_subject'];
$privmsg_message = $privmsg['privmsgs_text'];
##-----[ersetze mit]-----------------------------------------------------------
$privmsg_subject = $privmsg['privmsgs_subject'];
$msgkey = $privmsg['privmsgs_key'];
$privmsg_message = ($msgkey == 0)? $privmsg['privmsgs_text'] : xor_text($privmsg['privmsgs_text'],$msgkey,2);
##-----[suche nach]------------------------------------------------------------
$sql = "SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id
FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u
WHERE pm.privmsgs_id = $privmsg_id
AND pmt.privmsgs_text_id = pm.privmsgs_id
AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
AND u.user_id = pm.privmsgs_from_userid";
##-----[ersetze mit]-----------------------------------------------------------
$sql = "SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id, pm.privmsgs_key
FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u
WHERE pm.privmsgs_id = $privmsg_id
AND pmt.privmsgs_text_id = pm.privmsgs_id
AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
AND u.user_id = pm.privmsgs_from_userid";
##-----[suche nach]------------------------------------------------------------
if ( $mode == 'quote' )
{
$privmsg_message = $privmsg['privmsgs_text'];
##-----[ersetze mit]-----------------------------------------------------------
if ( $mode == 'quote' )
{
$msgkey = $privmsg['privmsgs_key'];
$privmsg_message = ($msgkey == 0)? $privmsg['privmsgs_text'] : xor_text($privmsg['privmsgs_text'],$msgkey,2);
##-----[speichern und schliessen]----------------------------------------------
##-----[ENDE]------------------------------------------------------------------