Initial commit
[2ch-be.git] / dev-test / rewrite / trip.php
bloba42713291feff4f313b36a735f76b0fd3ab22ebf
1 <?php
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');
11 exit;
13 function mktripcode($pw)
15 /*$pw=mb_convert_encoding($pw,'SJIS','UTF-8');
16 $pw=str_replace('&','&amp;',$pw);
17 $pw=str_replace('"','&quot;',$pw);
18 $pw=str_replace("'",'&#39;',$pw);
19 $pw=str_replace('<','&lt;',$pw);
20 $pw=str_replace('>','&gt;',$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);
30 return $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") {
38 $ret = "";
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");
43 $pos += 5;
46 else {
47 $ret .= substr($para, $pos, 1);
51 return $ret;
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) {
61 $handle = $str;
62 $tripcode = "";
65 // ƒgƒŠƒbƒvƒL[‚ð•ÏŠ·
66 else {
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");
80 // š‚ð™‚É’uŠ·
81 $handle = str_replace("š", "™", $handle);
82 // Ÿ‚ðž‚É’uŠ·
83 $handle = str_replace("Ÿ", "ž", $handle);
85 // ƒnƒ“ƒhƒ‹{ƒgƒŠƒbƒv‚ð•Ô‚·
86 $str = $handle;
87 if(!empty($tripcode))
88 $str .= " Ÿ".$tripcode;
90 return $str;
94 ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
95 Generate a tripcode from string
97 function key2trip($key) {
98 // 12ƒoƒCƒg–¢–ž‚ðˆ—
99 if(strlen($key) < 12) {
100 // ƒL[‚ª‹ó‚È‚ç0x80‚ð‘ã“ü
101 if($key == "")
102 $key = "\x80";
104 // salt‚𐶐¬
105 $salt = substr($key."H.", 1, 2);
106 $salt = preg_replace("/[^\.-z]/", ".", $salt);
107 $salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef");
109 // 10Œ…ƒgƒŠƒbƒv¶¬
110 $trip = key2trip10($key, $salt);
113 // 12ƒoƒCƒgˆÈã‚Í•ªŠò
114 else {
115 // æ“ª‚𒊏o
116 $mark = substr($key, 0, 1);
118 // "#"‚©‚çŽn‚Ü‚é‚à‚Ì‚ðˆ—
119 if($mark == "#") {
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));
125 // ‚»‚êˆÈŠO‚Í–¢ŽÀ‘•
126 else
127 $trip = "???";
130 // "$"‚©‚çŽn‚Ü‚é‚à‚Ì‚Í15Œ…ƒgƒŠƒbƒv¶¬
131 else if($mark == "$")
132 $trip = "???";
133 //$trip = key2trip15($key);
135 // ‚»‚êˆÈŠO‚Í12Œ…ƒgƒŠƒbƒv¶¬
136 else
137 $trip = key2trip12($key);
140 return $trip;
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);
152 // ƒgƒŠƒbƒv•ÏŠ·
153 $trip = crypt($key, $salt);
154 $trip = substr($trip, -10);
156 return $trip;
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);
169 return $trip;
173 15Œ…ƒgƒŠƒbƒv¶¬ƒ‹[ƒ`ƒ“
174 Generate a 15-characters tripcode
175 It is used in 2ch.sc
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);
192 return $trip;
196 if(isset($_POST['s'])){
197 $pw = $_POST['s'];
198 // $pw = filter_var(urldecode($_POST['s']), FILTER_SANITIZE_STRING);
199 //if(empty($pw)) exit;
200 if(strlen($pw) == 0) {
201 $pw = "\n";
202 } else {
203 $pw = mktripcode($pw);
205 print($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");
215 }else{
216 $fdir = substr($email, 0, 1);
217 $sdir = substr($email, 1, 1);
218 $data = @file(DB_PATH."$fdir/$sdir/$email");
219 if(count($data)>3) {
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)) {
226 } else {
227 $echo = "failed!";