Initial commit
[2ch-be.git] / dev-test / old / bak / trip.php
blobe298d870e7ee634f0ad0f5de9d8df898053f4c83
1 <?php
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');
8 exit;
10 function mktripcode($pw)
12 /*$pw=mb_convert_encoding($pw,'SJIS','UTF-8');
13 $pw=str_replace('&','&amp;',$pw);
14 $pw=str_replace('"','&quot;',$pw);
15 $pw=str_replace("'",'&#39;',$pw);
16 $pw=str_replace('<','&lt;',$pw);
17 $pw=str_replace('>','&gt;',$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);
27 return $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") {
35 $ret = "";
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");
40 $pos += 5;
43 else {
44 $ret .= substr($para, $pos, 1);
48 return $ret;
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) {
58 $handle = $str;
59 $tripcode = "";
62 // ƒgƒŠƒbƒvƒL[‚ð•ÏŠ·
63 else {
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");
77 // š‚ð™‚É’uŠ·
78 $handle = str_replace("š", "™", $handle);
79 // Ÿ‚ðž‚É’uŠ·
80 $handle = str_replace("Ÿ", "ž", $handle);
82 // ƒnƒ“ƒhƒ‹{ƒgƒŠƒbƒv‚ð•Ô‚·
83 $str = $handle;
84 if(!empty($tripcode))
85 $str .= " Ÿ".$tripcode;
87 return $str;
91 ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
92 Generate a tripcode from string
94 function key2trip($key) {
95 // 12ƒoƒCƒg–¢–ž‚ðˆ—
96 if(strlen($key) < 12) {
97 // ƒL[‚ª‹ó‚È‚ç0x80‚ð‘ã“ü
98 if($key == "")
99 $key = "\x80";
101 // salt‚𐶐¬
102 $salt = substr($key."H.", 1, 2);
103 $salt = preg_replace("/[^\.-z]/", ".", $salt);
104 $salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef");
106 // 10Œ…ƒgƒŠƒbƒv¶¬
107 $trip = key2trip10($key, $salt);
110 // 12ƒoƒCƒgˆÈã‚Í•ªŠò
111 else {
112 // æ“ª‚𒊏o
113 $mark = substr($key, 0, 1);
115 // "#"‚©‚çŽn‚Ü‚é‚à‚Ì‚ðˆ—
116 if($mark == "#") {
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));
122 // ‚»‚êˆÈŠO‚Í–¢ŽÀ‘•
123 else
124 $trip = "???";
127 // "$"‚©‚çŽn‚Ü‚é‚à‚Ì‚Í15Œ…ƒgƒŠƒbƒv¶¬
128 else if($mark == "$")
129 //$trip = "???";
130 $trip = key2trip15($key);
132 // ‚»‚êˆÈŠO‚Í12Œ…ƒgƒŠƒbƒv¶¬
133 else
134 $trip = key2trip12($key);
137 return $trip;
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);
149 // ƒgƒŠƒbƒv•ÏŠ·
150 $trip = crypt($key, $salt);
151 $trip = substr($trip, -10);
153 return $trip;
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);
166 return $trip;
170 15Œ…ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
171 Generate a 15-characters tripcode
172 It is used in 2ch.sc
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);
189 return $trip;
193 if(isset($_POST['s'])){
194 $pw = filter_var(urldecode($_POST['s']), FILTER_SANITIZE_STRING);
195 if(empty($pw)) exit;
196 $pw = mktripcode($pw);
197 print($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");
207 }else{
208 $fdir = substr($email, 0, 1);
209 $sdir = substr($email, 1, 1);
210 $data = @file(DB_PATH."$fdir/$sdir/$email");
211 if(count($data)>3) {
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)) {
218 } else {
219 $echo = "failed!";