2 header("Content-type: text/html; charset=Shift_JIS");
3 include('include/config.php');;
5 if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH']!='XMLHttpRequest' )){
6 header('location:index.php');
8 // isset if login or not
9 if (!isset($_COOKIE['DMDM']) && !isset($_COOKIE['MDMD'])) {
10 header('location:index.php');
13 function mktripcode($pw)
15 /*$pw=mb_convert_encoding($pw,'SJIS','UTF-8');
16 $pw=str_replace('&','&',$pw);
17 $pw=str_replace('"','"',$pw);
18 $pw=str_replace("'",''',$pw);
19 $pw=str_replace('<','<',$pw);
20 $pw=str_replace('>','>',$pw);
22 $salt=substr($pw.'H.',1,2);
23 $salt=preg_replace('/[^.\/0-9:;<=>?@A-Z\[\\\]\^_`a-z]/','.',$salt);
24 $salt=strtr($salt,':;<=>?@[\]^_`','ABCDEFGabcdef');
26 $trip=substr(crypt($pw,$salt),-10);*/
27 $trip = str_replace("+", "%2B", $pw);
28 $trip = urldecode(unescape($trip));
29 $trip = key2trip($trip);
33 JavaScript‚Åescape‚³‚ꂽ•¶Žš—ñ‚ðShift_JIS‚É•ÏŠ·
34 Decode %uXXXX to Shift_JIS
35 http://www.webdb.co.jp/aki/jsescapephp.html
37 function unescape($para, $type = "Shift_JIS") {
40 for($pos = 0; $pos < strlen($para); $pos++
) {
41 if(substr($para, $pos,2) == "%u") {
42 $ret .= mb_convert_encoding(chr(hexdec(substr($para, $pos +
2, 2))) . chr(hexdec(substr($para, $pos +
4, 2))),$type, "UTF-16");
47 $ret .= substr($para, $pos, 1);
55 •¶Žš—ñ‚ðƒnƒ“ƒhƒ‹{ƒgƒŠƒbƒvŒ`Ž®‚Åo—Í‚·‚郋[ƒ`ƒ“
56 Generate a name and a tripcode from string
58 function str2name($str) {
59 // "#"‚ªŠÜ‚Ü‚ê‚Ä‚¢‚È‚©‚Á‚½‚ç‘f’Ê‚µ
60 if(strpbrk($str, "#") == false) {
67 list($handle, $key) = explode("#", $str, 2);
68 $tripcode = key2trip($key);
71 // §ŒäƒR[ƒh‚𔼊pƒXƒy[ƒX‚É’uŠ·
72 $handle = preg_replace("/[\x01-\x1f\x7f]/", "", $handle);
74 // •¶Žš—ñ‚Ì擪‚¨‚æ‚Ñ––”ö‚É‚ ‚éƒzƒƒCƒgƒXƒy[ƒX‚ðŽæ‚蜂
75 $handle = trim($handle);
77 // “ÁŽê•¶Žš‚ðHTMLƒGƒ“ƒeƒBƒeƒB‚É•ÏŠ·‚·‚é
78 $handle = htmlspecialchars($handle, ENT_QUOTES | ENT_HTML5
, "Shift_JIS");
81 $handle = str_replace("š", "™", $handle);
83 $handle = str_replace("Ÿ", "ž", $handle);
85 // ƒnƒ“ƒhƒ‹{ƒgƒŠƒbƒv‚ð•Ô‚·
88 $str .= " Ÿ".$tripcode;
95 Generate a tripcode from string
97 function key2trip($key) {
99 if(strlen($key) < 12) {
100 // ƒL[‚ª‹ó‚È‚ç0x80‚ð‘ã“ü
105 $salt = substr($key."H.", 1, 2);
106 $salt = preg_replace("/[^\.-z]/", ".", $salt);
107 $salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef");
110 $trip = key2trip10($key, $salt);
113 // 12ƒoƒCƒgˆÈã‚Í•ªŠò
116 $mark = substr($key, 0, 1);
118 // "#"‚©‚çŽn‚Ü‚é‚à‚Ì‚ðˆ—
120 // ¶ƒL[Œ`Ž®‚Ìê‡10Œ…ƒgƒŠƒbƒv¶¬
121 if(preg_match("|^#([[:xdigit:]]{16})([./0-9A-Za-z]{0,2})$|", $key, $str)) {
122 $trip = key2trip10(hex2bin($str[1]), substr($str[2]."..", 0, 2));
130 // "$"‚©‚çŽn‚Ü‚é‚à‚Ì‚Í15Œ…ƒgƒŠƒbƒv¶¬
131 else if($mark == "$")
133 //$trip = key2trip15($key);
135 // ‚»‚êˆÈŠO‚Í12Œ…ƒgƒŠƒbƒv¶¬
137 $trip = key2trip12($key);
144 10Œ…ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
145 Generate a 10-characters tripcode
147 function key2trip10($key, $salt) {
148 // 0x80‚ðI’[‚Æ‚µ‚Ĉµ‚¤ˆ—
149 // Replace 0x80 by 0x00 to be compatible with Perl
150 $key = preg_replace("/\x80/", "\x00", $key);
153 $trip = crypt($key, $salt);
154 $trip = substr($trip, -10);
160 12Œ…ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
161 Generate a 12-characters tripcode
163 function key2trip12($key) {
164 $trip = sha1($key, true);
165 $trip = base64_encode($trip);
166 $trip = substr($trip, 0, 12);
167 $trip = str_replace("+", ".", $trip);
173 15Œ…ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
174 Generate a 15-characters tripcode
177 function key2trip15($key) {
178 $trip = sha1($key, true);
179 $trip = base64_encode($trip);
180 $trip = substr($trip, 3, 15);
182 $trip = strtr($trip, "+/", ".!");
184 // ƒL[2•¶Žš–Ú‚ª”¼ŠpƒJƒi‚Ìꇂ͔¼ŠpƒJƒiƒgƒŠƒbƒv‚É’uŠ·
185 // Replace ASCII by Halfwidth Katakana
186 if(preg_match("/^[$][\xA1-\xDF]/", $key)) {
187 $ascii = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.";
188 $kana = "¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß";
189 $trip = strtr($trip, $ascii, $kana);
196 if(isset($_POST['s'])){
198 // $pw = filter_var(urldecode($_POST['s']), FILTER_SANITIZE_STRING);
199 //if(empty($pw)) exit;
200 if(strlen($pw) == 0) {
203 $pw = mktripcode($pw);
211 $email = Decrypt($_COOKIE['DMDM'],KEY
);
212 $email = filter_var($email, FILTER_SANITIZE_EMAIL
);
213 if (!filter_var($email, FILTER_VALIDATE_EMAIL
)) {
214 die("Invalid email");
216 $fdir = substr($email, 0, 1);
217 $sdir = substr($email, 1, 1);
218 $data = @file
(DB_PATH
."$fdir/$sdir/$email");
220 for ($i=0; $i < count($data); $i++
) {
221 $data[$i] = trim($data[$i]);
224 $writeData = $data[0]."\n".$data[1]."\n".$data[2]."\n".$data[3]."\n".$data[4]."\n".$data[5]."\n".$data[6]."\n".$pw;
225 if(file_put_contents(DB_PATH
."$fdir/$sdir/$email", $writeData)) {