2 header("Content-type: text/html; charset=Shift_JIS");
3 include('encrypt.php');
5 // isset if login or not
6 if (!isset($_COOKIE['DMDM']) && !isset($_COOKIE['MDMD'])) {
7 header('location:index.php');
10 function mktripcode($pw)
12 /*$pw=mb_convert_encoding($pw,'SJIS','UTF-8');
13 $pw=str_replace('&','&',$pw);
14 $pw=str_replace('"','"',$pw);
15 $pw=str_replace("'",''',$pw);
16 $pw=str_replace('<','<',$pw);
17 $pw=str_replace('>','>',$pw);
19 $salt=substr($pw.'H.',1,2);
20 $salt=preg_replace('/[^.\/0-9:;<=>?@A-Z\[\\\]\^_`a-z]/','.',$salt);
21 $salt=strtr($salt,':;<=>?@[\]^_`','ABCDEFGabcdef');
23 $trip=substr(crypt($pw,$salt),-10);*/
24 $trip = str_replace("+", "%2B", $pw);
25 $trip = urldecode(unescape($trip));
26 $trip = key2trip($trip);
30 JavaScript‚Åescape‚³‚ꂽ•¶Žš—ñ‚ðShift_JIS‚É•ÏŠ·
31 Decode %uXXXX to Shift_JIS
32 http://www.webdb.co.jp/aki/jsescapephp.html
34 function unescape($para, $type = "Shift_JIS") {
37 for($pos = 0; $pos < strlen($para); $pos++
) {
38 if(substr($para, $pos,2) == "%u") {
39 $ret .= mb_convert_encoding(chr(hexdec(substr($para, $pos +
2, 2))) . chr(hexdec(substr($para, $pos +
4, 2))),$type, "UTF-16");
44 $ret .= substr($para, $pos, 1);
52 •¶Žš—ñ‚ðƒnƒ“ƒhƒ‹{ƒgƒŠƒbƒvŒ`Ž®‚Åo—Í‚·‚郋[ƒ`ƒ“
53 Generate a name and a tripcode from string
55 function str2name($str) {
56 // "#"‚ªŠÜ‚Ü‚ê‚Ä‚¢‚È‚©‚Á‚½‚ç‘f’Ê‚µ
57 if(strpbrk($str, "#") == false) {
64 list($handle, $key) = explode("#", $str, 2);
65 $tripcode = key2trip($key);
68 // §ŒäƒR[ƒh‚𔼊pƒXƒy[ƒX‚É’uŠ·
69 $handle = preg_replace("/[\x01-\x1f\x7f]/", "", $handle);
71 // •¶Žš—ñ‚Ì擪‚¨‚æ‚Ñ––”ö‚É‚ ‚éƒzƒƒCƒgƒXƒy[ƒX‚ðŽæ‚蜂
72 $handle = trim($handle);
74 // “ÁŽê•¶Žš‚ðHTMLƒGƒ“ƒeƒBƒeƒB‚É•ÏŠ·‚·‚é
75 $handle = htmlspecialchars($handle, ENT_QUOTES | ENT_HTML5
, "Shift_JIS");
78 $handle = str_replace("š", "™", $handle);
80 $handle = str_replace("Ÿ", "ž", $handle);
82 // ƒnƒ“ƒhƒ‹{ƒgƒŠƒbƒv‚ð•Ô‚·
85 $str .= " Ÿ".$tripcode;
92 Generate a tripcode from string
94 function key2trip($key) {
96 if(strlen($key) < 12) {
97 // ƒL[‚ª‹ó‚È‚ç0x80‚ð‘ã“ü
102 $salt = substr($key."H.", 1, 2);
103 $salt = preg_replace("/[^\.-z]/", ".", $salt);
104 $salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef");
107 $trip = key2trip10($key, $salt);
110 // 12ƒoƒCƒgˆÈã‚Í•ªŠò
113 $mark = substr($key, 0, 1);
115 // "#"‚©‚çŽn‚Ü‚é‚à‚Ì‚ðˆ—
117 // ¶ƒL[Œ`Ž®‚Ìê‡10Œ…ƒgƒŠƒbƒv¶¬
118 if(preg_match("|^#([[:xdigit:]]{16})([./0-9A-Za-z]{0,2})$|", $key, $str)) {
119 $trip = key2trip10(hex2bin($str[1]), substr($str[2]."..", 0, 2));
127 // "$"‚©‚çŽn‚Ü‚é‚à‚Ì‚Í15Œ…ƒgƒŠƒbƒv¶¬
128 else if($mark == "$")
130 $trip = key2trip15($key);
132 // ‚»‚êˆÈŠO‚Í12Œ…ƒgƒŠƒbƒv¶¬
134 $trip = key2trip12($key);
141 10Œ…ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
142 Generate a 10-characters tripcode
144 function key2trip10($key, $salt) {
145 // 0x80‚ðI’[‚Æ‚µ‚Ĉµ‚¤ˆ—
146 // Replace 0x80 by 0x00 to be compatible with Perl
147 $key = preg_replace("/\x80/", "\x00", $key);
150 $trip = crypt($key, $salt);
151 $trip = substr($trip, -10);
157 12Œ…ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
158 Generate a 12-characters tripcode
160 function key2trip12($key) {
161 $trip = sha1($key, true);
162 $trip = base64_encode($trip);
163 $trip = substr($trip, 0, 12);
164 $trip = str_replace("+", ".", $trip);
170 15Œ…ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
171 Generate a 15-characters tripcode
174 function key2trip15($key) {
175 $trip = sha1($key, true);
176 $trip = base64_encode($trip);
177 $trip = substr($trip, 3, 15);
179 $trip = strtr($trip, "+/", ".!");
181 // ƒL[2•¶Žš–Ú‚ª”¼ŠpƒJƒi‚Ìꇂ͔¼ŠpƒJƒiƒgƒŠƒbƒv‚É’uŠ·
182 // Replace ASCII by Halfwidth Katakana
183 if(preg_match("/^[$][\xA1-\xDF]/", $key)) {
184 $ascii = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.";
185 $kana = "¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß";
186 $trip = strtr($trip, $ascii, $kana);
193 if(isset($_POST['s'])){
194 $pw = filter_var(urldecode($_POST['s']), FILTER_SANITIZE_STRING
);
196 $pw = mktripcode($pw);
203 $email = Decrypt($_COOKIE['DMDM'],KEY
);
204 $email = filter_var($email, FILTER_SANITIZE_EMAIL
);
205 if (!filter_var($email, FILTER_VALIDATE_EMAIL
)) {
206 die("Invalid email");
208 $fdir = substr($email, 0, 1);
209 $sdir = substr($email, 1, 1);
210 $data = @file
(DB_PATH
."$fdir/$sdir/$email");
212 for ($i=0; $i < count($data); $i++
) {
213 $data[$i] = trim($data[$i]);
216 $writeData = $data[0]."\n".$data[1]."\n".$data[2]."\n".$data[3]."\n".$data[4]."\n".$data[5]."\n".$data[6]."\n".$pw;
217 if(file_put_contents(DB_PATH
."$fdir/$sdir/$email", $writeData)) {