![]() | 上のディレクトリへ |
![]() | calendar.cgi |
![]() | multiupload.cgi |
![]() | subdir |
変数名 | スカラー | 配列 | ハッシュ | |
---|---|---|---|---|
history | ● | ● | historyを編集 | |
init | ● | ● | initを編集 | |
file | ● | ● | fileを編集 | |
val | ● | ● | valを編集 | |
wh | ● | ● | whを編集 | |
param | ● | ● | ● | paramを編集 |
cook | ● | ● | cookを編集 |
■以下の書式を変換します |
1458行 | if (-d $tmp) { |
if (is_dir($tmp)) { | |
2044行 | if (!-d $attach_dir) { |
if (!is_dir($attach_dir)) { |
1 | <?php | |
2 | ||
3 | #???????????????????????????????????????????????????????????????????? | |
4 | #?? ?????????????? | |
5 | #?? Copyright (c) hirayama | |
6 | #??http://www2u.biglobe.ne.jp/~k_hiray/sts/fsw/ | |
7 | #??????????????1?????1???(I!"(B2???????????????????????????????????????? | |
8 | #?????????????????(IN8(B?????????????????????? | |
9 | #?????????????????????????????????????????????? | |
10 | #????????????????????????????????????Agenda???????????????????????? | |
11 | #???????????????????????????????????????????????????????????????????? | |
12 | #???????????????????????????????????????????????????????????????????? | |
13 | #?? [???????] | |
14 | #?? 1. ???(IN%(B??????????????????????(IN%(B?????????????? | |
15 | #?? ?????????????(IP$(B?????????????????(I$$(B????? | |
16 | #???????????????????????????????????????????????????????????????????? | |
17 | $history = <<"EOF"; | |
18 | # ver.1.01 2007.12.11 ???(IN%(B?????????????????(IP%(B????? | |
19 | # ver.1.02 2008.10.10 ??????????????????????????(?????????????????????????(IN>(B??) | |
20 | # ver.1.03 2008.10.14 ???????(IN%(B??????????????????????(IN1(B??????????????(IN$(B??? | |
21 | # ver.1.04 2010.02.25 Agenda?(IN%(B??????????????????????(I$,(B????(IN$(B??? | |
22 | # ver.1.05 2010.02.26 ?????????(IN%(B??????????(IN%(B??????????????????????????????????????????????????? | |
23 | # ????????????????????????????????? | |
24 | # ver.1.051 2010.03.08 3??????????????????????????????????????(IN$(B???????????? | |
25 | # ver.1.06 2010.03.10 ?????????????????????????????? | |
26 | # ver.1.061 2010.03.15 ????"(???????????)?????????????????????(IP%(B?????????????? | |
27 | # ver.1.07 2010.03.30 ??????????????(IN$(B?????????????????????????????????(IN>(B???URL??????????????? | |
28 | # ver.1.08 2011.06.16 ???????????????????????????????????(IN$(B??????????init.cgi?(IN%P%(B???????????????????????????? | |
29 | # ver.1.09 2012.03.07 ???????????????(IN%(B??????????????????????(IP%(B?????????????? | |
30 | # ver.1.091 2012.04.17 ??????????????????????????????????(IN%(B????????????????????????????????????? | |
31 | # ???????????????????1?????????????????????????(??????????????\$january_top ??1?????) | |
32 | # ver.1.092 2012.04.25 ?????????????????(??????3???????)?????????????????????????? | |
33 | # ?(IP!(B??????????????????????init_bck.cgi???????????????????????????? | |
34 | # ver.1.093 2012.05.17 ?????1?????????????????????????????????????????????(IP%(B?????????????? | |
35 | # ver.1.094 2013.03.08 ?????????(IN%(B???????????????????????(IP%(B????????????????????????(IN%(B???????????????????? | |
36 | # ver.1.095 2014.02.13 9??????(IN%(B????????????????????????? | |
37 | # ver.1.096 2014.02.19 ?????1??????????1????2?????????????????????(IP%(B?????????????? | |
38 | EOF | |
39 | $ver = $history =~ /ver\.?(\d+\.\d*)/g; | |
40 | foreach $version ($ver) { | |
41 | $ver = $version if $version > $ver; | |
42 | } | |
43 | require './init.cgi'; | |
44 | require './lib/cgi-lib.pl'; | |
45 | require './lib/jcode.pl'; | |
46 | require './lib/holiday.pl'; # kent-web?????????????holiday.pl???????????????????? | |
47 | ||
48 | #=========================== | |
49 | if (! $code) { | |
50 | # ???(I2=(B????????(IN>(B??(IN$(B??????????????????? | |
51 | use File::Find; | |
52 | # MD5????????????????????????????? | |
53 | $md5ok; | |
54 | find(\&mdsearch, $INC); | |
55 | function mdsearch() { | |
56 | if ($_ === 'MD5.pm') { | |
57 | $md5ok = 1; | |
58 | return $md5ok; | |
59 | } | |
60 | } | |
61 | &lock; | |
62 | open(INT,'./init.cgi') || &error("init.cgi???????????"); | |
63 | $init = <INT>; | |
64 | close(INT); | |
65 | ||
66 | $code_str; | |
67 | if ($md5ok) { | |
68 | $code_str = '$code = 2;' . "\n"; | |
69 | } else { | |
70 | $code_str = '$code = 1;' . "\n"; | |
71 | } | |
72 | open(INT,">./init.cgi"); | |
73 | foreach ($init) { | |
74 | if (/^\s*\$code\s*=/) { | |
75 | print INT $code_str; | |
76 | } else { | |
77 | print INT $_; | |
78 | } | |
79 | } | |
80 | close(INT); | |
81 | &unlock; | |
82 | } | |
83 | ||
84 | ||
85 | $title = $cal_title; | |
86 | &decode; | |
87 | ||
88 | # ????????? | |
89 | $_SERVER['TZ'] = "JST-9"; | |
90 | list($tsec, $tmin, $thour, $tmday, $tmon, $tyear)=localtime(time); | |
91 | $tyear+=1900; | |
92 | $tmon++; | |
93 | ||
94 | if ($in['test']) { | |
95 | $tyear = substr($in['test'],0,4); | |
96 | $tmon = substr($in['test'],4,2); | |
97 | } | |
98 | ||
99 | list($cpass,$cstyear,$cendyear,$ccfsize,$cccwidth,$type) = &get_cookie if $pass_cookie; | |
100 | $ctype = $type; | |
101 | $in['type'] = $type if ! $in['type']; | |
102 | if ($in['mode'] ne 'config') { | |
103 | if ($cstyear ne '') { | |
104 | $before_year = $cstyear; | |
105 | } | |
106 | if ($cendyear ne '') { | |
107 | $show_year = $cendyear; | |
108 | } | |
109 | } | |
110 | ||
111 | if ($ccfsize) { | |
112 | $cal_fsize = $ccfsize; | |
113 | } else { | |
114 | $cal_fsize = $calSize; | |
115 | } | |
116 | if ($cccwidth) { | |
117 | $cal_cwidth = $cccwidth; | |
118 | } else { | |
119 | $cal_cwidth = $cellwidth; | |
120 | } | |
121 | ||
122 | # ?????????????????????(IP=(B?????? | |
123 | $config_value; | |
124 | $load_config; | |
125 | if (!$pass) { | |
126 | # init.cgi?(IN%P%(B??????????????? | |
127 | if (file_exists('init_bck.cgi')) { | |
128 | open(BCK,'init_bck.cgi'); | |
129 | $scr = <BCK>; | |
130 | close(BCK); | |
131 | foreach $cfg ('pass',$config) { | |
132 | ($tmp, $com, $name, $value); | |
133 | foreach $line ($scr) { | |
134 | if ($line =~ /^\s*#/) { next; } | |
135 | if ($line =~ /\s*(my)?\s*\$$cfg\s*=\s*/) { | |
136 | $tmp = split(/;/,$line); | |
137 | $com = pop($tmp); | |
138 | chomp $com; | |
139 | $line = join(';',$tmp); | |
140 | list($name, $value) = split(/=/,$line); | |
141 | $name =~ s/^\s*my\s*[^\$]//; | |
142 | $name =~ s/\s*$//; | |
143 | $value =~ s/^\s*['"]?//; | |
144 | $value =~ s/['"]?\s*$//; | |
145 | last; | |
146 | } | |
147 | } | |
148 | push($config_value,"$cfg<>$value"); | |
149 | if ($cfg === 'pass' && $value) { | |
150 | $load_config = 1; | |
151 | } | |
152 | } | |
153 | if ($load_config) { | |
154 | $title .= '?????????????'; | |
155 | &load_config; | |
156 | exit; | |
157 | } else { | |
158 | $title .= '?????????'; | |
159 | &create_pass; | |
160 | exit; | |
161 | } | |
162 | } else { | |
163 | $title .= '?????????'; | |
164 | &create_pass; | |
165 | exit; | |
166 | } | |
167 | } | |
168 | if ($in['year'] === '?????') { | |
169 | $in['show_year'] = ''; | |
170 | $in['before_year'] = ''; | |
171 | &set_cookie($cpass,1,1,$cal_fsize,$cal_cwidth,$in['type']); | |
172 | $url = $script; | |
173 | &redirect($url); | |
174 | } | |
175 | if ($in['end_year']) { | |
176 | if ($january_top || $tmon <= 2) { | |
177 | $in['show_year'] = $in['end_year'] - $tyear; | |
178 | } else { | |
179 | $in['show_year'] = $in['end_year'] - $tyear - 1; | |
180 | } | |
181 | } | |
182 | if ($in['show_year'] ne '') { | |
183 | $show_year = $in['show_year']; | |
184 | } | |
185 | if ($in['start_year']) { | |
186 | $in['before_year'] = $tyear - $in['start_year']; | |
187 | } | |
188 | if ($in['before_year'] ne '') { | |
189 | $before_year = $in['before_year']; | |
190 | } | |
191 | # ???????????????????????????? | |
192 | if ($in['csize_edit']) { | |
193 | $cal_fsize =~ /(\d+)/; | |
194 | $calf = $1; | |
195 | if ($in['cfsize'] === '??') { | |
196 | $calf += 10; | |
197 | } elseif ($in['cfsize'] === '??') { | |
198 | $calf -= 10; | |
199 | } | |
200 | $cal_fsize =~ s/^\d+/$calf/; | |
201 | if ($in['ccsize'] === '??') { | |
202 | $cal_cwidth ++; | |
203 | } elseif ($in['ccsize'] === '??') { | |
204 | $cal_cwidth --; | |
205 | } | |
206 | &set_cookie($cpass,$cstyear,$cendyear,$cal_fsize,$cal_cwidth,$in['type']); | |
207 | } | |
208 | ||
209 | # ?????????????????????????????????????????? | |
210 | if ($in['change_show_year'] && $pass_cookie) { | |
211 | $cstyear = $in['before_year']; | |
212 | $cendyear = $in['show_year']; | |
213 | &set_cookie($cpass,$cstyear,$cendyear,$cal_fsize,$cal_cwidth,$in['type']); | |
214 | } | |
215 | ||
216 | if ($pass_cookie && $ctype ne $in['type']) { | |
217 | &set_cookie($cpass,$cstyear,$cendyear,$cal_fsize,$cal_cwidth,$in['type']); | |
218 | } | |
219 | ||
220 | if ($in['mode'] === 'write') { | |
221 | &write; | |
222 | exit; | |
223 | } elseif ($in['mode'] === 'del_file') { | |
224 | &del_file; | |
225 | exit; | |
226 | ||
227 | # ???????????????????????True?(IN>(B?? | |
228 | } elseif ($in['mode'] === 'search' && $in['keyword'] ne '') { | |
229 | $title .= "???????"; | |
230 | &search; | |
231 | exit; | |
232 | } elseif ($in['mode'] === 'config') { | |
233 | $title .= "???????"; | |
234 | &config; | |
235 | exit; | |
236 | } elseif ($in['mode'] === 'history') { | |
237 | &history; | |
238 | exit; | |
239 | } | |
240 | ||
241 | # Agenda??????????Agenda?(IN;(B????????????????????????? | |
242 | $agd_cont = array(); | |
243 | if ($coop_agenda) { | |
244 | if (!file_exists($agenda_dir)) { | |
245 | &header; | |
246 | print "<div style=\"line-height:1.5em;margin:1em\">"; | |
247 | if ($agenda_dir) { | |
248 | print "<span style=\"font-weight:bold;\">$agenda_dir</span>??????????????????????????????<br>\n"; | |
249 | } else { | |
250 | print "Agenda??Data?????????????????????<br>\n"; | |
251 | } | |
252 | print '$agenda_dir????????????????Windows XP?(IN>(B?????? <strong>"C:\Documents and Settings\(???????)\Application Data\Oceansoft\Agenda\Data"</strong> ?????<br>'; | |
253 | print "???????????????Agenda??????????????<strong>\$coop_agenda = 0;</strong> ?????????????????<a href=\"$script?mode=config\">$title????</a>"; | |
254 | print "</div>"; | |
255 | &footer; | |
256 | exit; | |
257 | } | |
258 | opendir(AGD,$agenda_dir) || &error($agenda_dir . "???????????"); | |
259 | while ($file = readdir(AGD)) { | |
260 | list($dt,$ex) = split(/\./,$file); | |
261 | $agenda_dir =~ s/\\/\//g; | |
262 | $agenda_dir =~ s/\/$//g; | |
263 | $path = join('/',$agenda_dir, $file); | |
264 | if ($file ne '.' && $file ne '..' && $ex === 'dat' && (stat $path)[7] > 0 && $dt =~ /^[0-9]${8}/) { | |
265 | push($agd_cont,$file); | |
266 | } | |
267 | } | |
268 | closedir(AGD) | |
269 | } | |
270 | $data_dir =~ s/\/$//g; | |
271 | if (!file_exists($data_dir)) { mkdir($data_dir); } # $data_dir???????(IP:(B???????? | |
272 | &header; | |
273 | ||
274 | # Agenda??????????Agenda?(IN%(B???????????????????????????sjis ?? euc ?????????????? | |
275 | if ($coop_agenda) { | |
276 | $agd_cont = sort {$b <=> $a} $agd_cont; | |
277 | foreach ($agd_cont) { | |
278 | $date = (split(/\./,$_))[0]; | |
279 | $ag_data = $agenda_dir . '/' . $date . '.dat'; | |
280 | $cal_data = $data_dir . '/' . $date . '.cgi'; | |
281 | if (!file_exists($cal_data || (stat $ag_data))[9] > (stat $cal_data)[9]) { | |
282 | open(DAT,"$ag_data") || &error("$ag_data???????????"); | |
283 | $ag_cont = <DAT>; | |
284 | close(DAT); | |
285 | if (!file_exists($cal_data)) { | |
286 | open(NEW,">$cal_data") || &error("$cal_data??????????????"); | |
287 | close(NEW); | |
288 | } | |
289 | open(OLD,"$cal_data") || &error("$cal_data???????????1"); | |
290 | $first_line = <OLD>; | |
291 | close(OLD); | |
292 | if (index($first_line,'<!-!>') >= 0) { | |
293 | $cat = (split(/<!-!>/,$first_line))[0]; | |
294 | } else { | |
295 | $cat = ''; | |
296 | } | |
297 | open(NEW,">$cal_data") || &error("$cal_data???????????2"); | |
298 | print NEW $cat . "<!-!>"; | |
299 | foreach $line ($ag_cont) { | |
300 | &jcode'convert(*line,'euc'); #' | |
301 | print NEW $line; | |
302 | } | |
303 | close(NEW); | |
304 | print $ag_data . "??????????????????<br>\n"; | |
305 | } | |
306 | } | |
307 | } | |
308 | &calen; | |
309 | &footer; | |
310 | ||
311 | ||
312 | # ???????????? | |
313 | function history() { | |
314 | $title .= ' ????????'; | |
315 | &header; | |
316 | $history = split("\n",$history); | |
317 | $i = 0; | |
318 | foreach ($history) { | |
319 | if (!/\s+ver[\.\s]*\d/) { | |
320 | s/#\s*/<br>/; | |
321 | $history[$i-1] .= $_; | |
322 | $history[$i] = ''; | |
323 | } | |
324 | $i++; | |
325 | } | |
326 | $history = reverse $history; | |
327 | print "<div style=\"margin:1em\"><a href=\"#\" onClick=\"history.back("; return false;">???</a>\n<table cellpadding="2" style="line-height:1.5em">\n); | |
328 | foreach ($history) { | |
329 | next if !$_; | |
330 | s/^#\s*//; | |
331 | s/\t+/<\/td><td valign="top">/g; | |
332 | print "<tr><td valign=\"top\">??</td><td valign=\"top\">"; | |
333 | print $_ . "<br>\n"; | |
334 | print "</td></tr>"; | |
335 | } | |
336 | print "</table>\n</div>\n"; | |
337 | &footer; | |
338 | } | |
339 | ||
340 | function create_pass() { | |
341 | # $in['pass']??True???init.cgi???????????????????? | |
342 | if ($in['pass']) { | |
343 | if (length($in['pass']) < 5) { | |
344 | &error("????????5???????????????????"); | |
345 | } | |
346 | # init.cgi?????? | |
347 | open(INIT,"./init.cgi") || &error("./init.cgi???????????"); | |
348 | $init = <INIT>; | |
349 | close(INIT); | |
350 | $new_init = array(); | |
351 | foreach $line ($init) { | |
352 | $tmp = $line; | |
353 | $tmp =~ s/ //g; | |
354 | if ($tmp =~ /^\$pass='/) { | |
355 | # ??????????????????????crypt????$pass???????????????????? | |
356 | $crypt_pass = &encrypt($in['pass']); | |
357 | $tmp = split(/;/,$line); | |
358 | $com = pop($tmp); | |
359 | $new_pass = '$pass = ' . "'" . $crypt_pass . "';" . $com; | |
360 | push($new_init,$new_pass); | |
361 | } else { | |
362 | push($new_init,$line); | |
363 | } | |
364 | } | |
365 | # init.cgi?????????(IP%(B?????????? | |
366 | open(INIT,">./init_bck.cgi") || &error("./init_bck.cgi???????????"); | |
367 | print INIT $init; | |
368 | close(INIT); | |
369 | unlink 'init.bck' if file_exists('init.bck'); # ?????(IN%P%(B??????????????????? | |
370 | ||
371 | # init.cgi????? | |
372 | open(INIT,">./init.cgi") || &error("./init.cgi???????????"); | |
373 | print INIT $new_init; | |
374 | close(INIT); | |
375 | ||
376 | # ??????????????????? | |
377 | if ($_SERVER[PERLXS] === "PerlIS") { | |
378 | print "HTTP/1.0 302 Temporary Redirection\r\n"; | |
379 | print "Content-type: text/html\n"; | |
380 | } | |
381 | print "Location: $script?mode=config&pass=$in['pass']\n\n"; | |
382 | exit; | |
383 | } | |
384 | &header; | |
385 | print "<div style=\"margin:1em\">"; | |
386 | print "<p>??????????????????????????????</p>\n"; | |
387 | print "<form action=\"$script\" method=\"post\">\n"; | |
388 | print "??????? <input type=\"password\" name=\"pass\" value=\"\" size=\"10\">\n"; | |
389 | print "<input type=\"submit\" value=\"???\">\n"; | |
390 | print "</form>\n"; | |
391 | print "</div>"; | |
392 | &footer; | |
393 | } | |
394 | ||
395 | ||
396 | function config() { | |
397 | if ($in['change_pass'] === '????????????????') { | |
398 | if (length($in['new_pass']) < 5) { | |
399 | &error("????????5???????????????????"); | |
400 | } | |
401 | } | |
402 | if ($pass_cookie) { ($cpass) = &get_cookie; } | |
403 | if ($in['pass'] === "") { | |
404 | &header; | |
405 | print "<center><h4>????????????????????</h4>\n"; | |
406 | print "<form action=\"$script\" method=\"POST\">\n"; | |
407 | print "<input type=hidden name=mode value=\"config\">\n"; | |
408 | print "<p><input type=password name=pass size=8 value=\"$cpass\">\n"; | |
409 | print "<input type=submit value=\" ??? \"></form>\n"; | |
410 | print "</center>\n"; | |
411 | &footer; | |
412 | exit; | |
413 | } elseif (&decrypt($in['pass'], $pass) === 'no') { | |
414 | &error("?????????????"); | |
415 | } | |
416 | if ($pass_cookie) { | |
417 | if (!$in['before_year']) { | |
418 | $in['before_year'] = $before_year; | |
419 | } | |
420 | if (!$in['show_year']) { | |
421 | $in['show_year'] = $show_year; | |
422 | } | |
423 | &set_cookie($in['pass'],$in['before_year'],$in['show_year'],$cal_fsize,$cal_cwidth,$in['type']); | |
424 | } | |
425 | ||
426 | open(INIT,"./init.cgi") || &error("./init.cgi???????????"); | |
427 | $init = <INIT>; | |
428 | close(INIT); | |
429 | $list_nmb = 0; | |
430 | foreach (keys %in) { | |
431 | if (/^cat(\d+)/) { | |
432 | $list_nmb = $1 if $1 > $list_nmb; | |
433 | } | |
434 | } | |
435 | $new_line = array(); | |
436 | $line_count = 0; | |
437 | foreach $init_line ($init) { | |
438 | $line_flag =0; | |
439 | if ($in['config'] === 'category_color') { | |
440 | if ($init_line =~ /^\s*\$category\s*=\s*/) { # ??????????????????????(^^;; | |
441 | $cat; | |
442 | foreach ($count=0; $count<=$list_nmb; $count++) { | |
443 | if ($in["cat$count"] && $in["col$count"]) { | |
444 | push($cat,"'" . $in["cat$count"] . "'"); | |
445 | } | |
446 | } | |
447 | $init_line = '$category = array(' . join(',',$cat) . ");\n"; | |
448 | } elseif ($init_line =~ /^\s*\$category_color\s*=\s*/) { | |
449 | $col; | |
450 | foreach ($count=0; $count<=$list_nmb; $count++) { | |
451 | if ($in["cat$count"] && $in["col$count"]) { | |
452 | $init_line .= "'" . $in["col$count"] . "',"; | |
453 | push($col,"'" . $in["col$count"] . "'"); | |
454 | $base_color = $in["col$count"]; | |
455 | $base_color =~ s/#//; | |
456 | $r = substr($base_color,0,2); | |
457 | $g = substr($base_color,2,2); | |
458 | $b = substr($base_color,4,2); | |
459 | $r_hex = hex($r); | |
460 | $g_hex = hex($g); | |
461 | $b_hex = hex($b); | |
462 | $meido = $r_hex * 0.299 + $g_hex * 0.587 + $b_hex * 0.114; | |
463 | if ($meido < 128) { | |
464 | $add_comment .= "$in[\"cat$count\"]?(IN?(B?" . '??' . "${base_color}???????????????????????????????????????(IP$(B???????????????????????\n"; | |
465 | } | |
466 | } | |
467 | } | |
468 | $init_line = '$category_color = array(' . join(',',$col) . ");\n"; | |
469 | } elseif ($init_line =~ /^\s*\$memo_col\s*=\s*/ && $in['memo_col']) { | |
470 | $init_line = '$memo_col = ' . "'" . $in['memo_col'] . "';\n"; | |
471 | } | |
472 | } | |
473 | foreach $cfg ($config) { | |
474 | $next = 0; | |
475 | foreach ($invalid) { | |
476 | if ($cfg === $_) { | |
477 | $next = 1; | |
478 | } | |
479 | } | |
480 | if ($cfg && $init_line =~ /^\s*\$$cfg\s*=\s*/) { | |
481 | if ($in["$cfg"] =~ /^\d+$/) { | |
482 | $value = $in["$cfg"]; | |
483 | } else { | |
484 | $val = $in["$cfg"]; | |
485 | $val =~ s/</</g; | |
486 | $val =~ s/>/>/g; | |
487 | $val =~ s/"/"/g; #" | |
488 | $val =~ s/\\$//; | |
489 | $value = "'" . $val . "'"; | |
490 | } | |
491 | $tmp = split(/;/,$init_line); | |
492 | $com = pop($tmp); | |
493 | ||
494 | chomp $com; | |
495 | $popup["$cfg"] = $com; | |
496 | if (!$next && $in['config'] ne 'category_color') { | |
497 | $init_line = '$' . $cfg . " = " . $value . ";" . $com . "\n"; | |
498 | } | |
499 | $ex_line = $line_count - 1; | |
500 | while ($init[$ex_line] =~ /^#+/) { | |
501 | $memo = $init[$ex_line]; | |
502 | $popup["$cfg"] = $memo . $popup["$cfg"]; | |
503 | $ex_line--; | |
504 | } | |
505 | last; | |
506 | } | |
507 | } | |
508 | if ($in['change_pass'] === '????????????????' && $init_line =~ /^\$pass\s*=\s*/) { | |
509 | $crypt_pass = &encrypt($in['new_pass']); | |
510 | $tmp = split(/;/,$init_line); | |
511 | $com = pop($tmp); | |
512 | $init_line = '$pass = ' . "'" . $crypt_pass . "';" . $com; | |
513 | $new_pass = $in['new_pass']; | |
514 | } | |
515 | push($new_line, $init_line); | |
516 | $line_count++; | |
517 | } | |
518 | $comment; | |
519 | if ($in['modify'] === 'do') { | |
520 | ||
521 | # init.cgi?????????(IP%(B?????????? | |
522 | use File::Copy; | |
523 | copy './init.cgi', './init_bck.cgi'; | |
524 | unlink 'init.bck' if file_exists('init.bck'); # ?????(IN%P%(B??????????????????? | |
525 | ||
526 | open(NEW,">./init.cgi") || &error("./init.cgi???????????"); | |
527 | print NEW $new_line; | |
528 | close(NEW); | |
529 | ||
530 | # ???????????????????$in['pass']???????????????????????????????????????????????????????? | |
531 | if ($new_pass) { | |
532 | $in['pass'] = $new_pass; | |
533 | # $comment = &url_encode('????????????????????'); | |
534 | $comment = '????????????????????'; | |
535 | $add = "&pass_change=1&comment=$comment"; | |
536 | } elseif ($in['config'] === 'category_color') { | |
537 | $comment = '?????????????????????'; | |
538 | if ($add_comment) { | |
539 | $comment .= "\n" . $add_comment; | |
540 | } | |
541 | # $comment = &url_encode($comment); | |
542 | $add = "&comment=$comment"; | |
543 | } else { | |
544 | $com = "?????????????????"; | |
545 | if (!$in['permission'] && $in['use_tag']) { | |
546 | $com .= "\n??????(IN$(B??????????????????????????????"; | |
547 | } | |
548 | # $comment = &url_encode($com); | |
549 | $comment = $com; | |
550 | $add = "&comment=$comment"; | |
551 | } | |
552 | # if ($_SERVER[PERLXS] === "PerlIS") { | |
553 | # print "HTTP/1.0 302 Temporary Redirection\r\n"; | |
554 | # print "Content-type: text/html\n"; | |
555 | # } | |
556 | # print "Location: $script?mode=config&pass=$in['pass']$add\n\n"; | |
557 | # exit; | |
558 | } | |
559 | &header; | |
560 | print "<div style=\"padding:0.5em 1em 0.5em 1em;\">\n"; | |
561 | print "<div style=\"margin-bottom:0.5em\">[<a href=\"$script\">???</a>]</div>\n"; | |
562 | if (length($in['pass']) > 8 && length($pass) == 13 && ! $in['new_pass']) { | |
563 | print "<div style=\"line-height:1.5em;color:red;margin-bottom:0.5em\">9??????(IN%(B??????????????????????????8????????????????????????<br>9???????????????????????????????????????????????????????????????????????????</div>\n"; | |
564 | ||
565 | } | |
566 | print "<table border=\"$frame_border\" cellpadding=\"$frame_padding\" cellspacing=\"$frame_spacing\" border=0><tr>\n"; | |
567 | $today = sprintf("%04d-%s-%s", $tyear,$tmon,$tmday); | |
568 | $yy = $tyear; | |
569 | $mm = $tmon; | |
570 | for ($m = $mm - 1; $m <= $mm + 1; $m++) { | |
571 | if ($m < 1) { | |
572 | $mmm = $m + 12; | |
573 | $yyy = $yy - 1; | |
574 | } elseif ($m > 12) { | |
575 | $mmm = $m - 12; | |
576 | $yyy = $yy + 1; | |
577 | } else { | |
578 | $mmm = $m; | |
579 | $yyy = $yy; | |
580 | } | |
581 | if ($tyear == $yyy && $tmon == $mmm) { | |
582 | print "<td valign=\"top\" bgcolor=\"$tomon_col\">"; | |
583 | } else { | |
584 | print "<td valign=\"top\">"; | |
585 | } | |
586 | &create_calen($yyy,$mmm); | |
587 | print "</td>\n"; | |
588 | } | |
589 | print "</tr></table>\n"; | |
590 | # print "<div style=\"color:red;padding-top:0.5em\">$in['comment']</div>" if $in['comment']; | |
591 | print "<div style=\"color:red;padding-top:0.5em\">$comment</div>" if $comment; | |
592 | print "<table cellpadding=\"4\"><tr><td valign=\"top\">\n"; | |
593 | print "<form action=\"$script\" method=\"post\">\n"; | |
594 | print "<input type=\"hidden\" name=\"mode\" value=\"config\">\n"; | |
595 | print "<input type=\"hidden\" name=\"modify\" value=\"do\">\n"; | |
596 | print "<input type=\"hidden\" name=\"pass\" value=\"$in['pass']\">\n"; | |
597 | print "<table border=\"1\">\n"; | |
598 | print "<tr><td colspan=\"3\"><input type=\"submit\" value=\"??????????\"> ???????????(IN$(B???????????????????????????????</td></tr>\n"; | |
599 | print "<tr><td colspan=\"3\"><input type=\"submit\" name=\"change_pass\" value=\"????????????????\"> ????????????? <input type=\"text\" name=\"new_pass\">\n"; | |
600 | print "</td></tr>\n"; | |
601 | foreach ($config) { | |
602 | $enc = $$_; | |
603 | if ($in["$_"] ne '') { | |
604 | $enc = $in["$_"]; | |
605 | } | |
606 | $enc =~ s/</</g; | |
607 | $enc =~ s/>/>/g; | |
608 | $enc =~ s/"/"/g; | |
609 | $length = length($enc) + 2; | |
610 | if ($length > 110) { | |
611 | $length = 110; | |
612 | } | |
613 | if ($length > 20) { | |
614 | $size_op = " size=\"$length\""; | |
615 | if ($length > 50) { | |
616 | $size_op = " size=\"50\""; | |
617 | } | |
618 | } else { | |
619 | $size_op = ''; | |
620 | } | |
621 | if ($enc =~ /#[a-fA-F\d]/) { | |
622 | $tx_col = &text_color($enc); | |
623 | $ime_op = " style=\"ime-mode:inactive;background-color:$enc;color:$tx_col\""; | |
624 | ||
625 | } else { | |
626 | $ime_op = " style=\"ime-mode:inactive\""; | |
627 | } | |
628 | $popup["$_"] =~ s/\n/<br>/g; | |
629 | if ($popup["$_"]) { | |
630 | $exp = $popup["$_"]; | |
631 | } else { | |
632 | $exp = " "; | |
633 | } | |
634 | if ($size_op) { | |
635 | print "<tr><td align=\"right\" valign=\"top\">\$$_ = </td><td colspan=\"2\"><input type=\"text\" name=\"$_\" value=\"$enc\"$size_op$ime_op><br>$exp</td></tr>\n"; | |
636 | } else { | |
637 | print "<tr><td align=\"right\">\$$_ = </td><td><input type=\"text\" name=\"$_\" value=\"$enc\"$size_op$ime_op></td><td>$exp</td></tr>\n"; | |
638 | } | |
639 | } | |
640 | print "</table>\n"; | |
641 | print "</form>\n"; | |
642 | print "</td>\n<td valign=\"top\">\n"; | |
643 | #-----------?????????------------ | |
644 | print "<form action=\"$script\" method=\"post\">\n"; | |
645 | print "<input type=\"hidden\" name=\"mode\" value=\"config\">"; | |
646 | print "<input type=\"hidden\" name=\"config\" value=\"category_color\">"; | |
647 | print "<input type=\"hidden\" name=\"modify\" value=\"do\">"; | |
648 | print "<input type=\"hidden\" name=\"pass\" value=\"$in['pass']\">\n"; | |
649 | print "<table>\n"; | |
650 | print "<tr><td colspan=\"2\"><input type=\"submit\" value=\"??????????\"></td></tr>\n"; | |
651 | print "<tr><td>???????</td><td>??</td></tr>\n"; | |
652 | print "<tr style=\"background-color:$memo_col;\"><td>???</td><td><input type=\"text\" name=\"memo_col\" value=\"$memo_col\" size=\"8\" style=\"background-color:$memo_col;\"></td></tr>\n"; | |
653 | $count = 0; | |
654 | foreach ($category) { | |
655 | $txt_col = &text_color($cat_col["$_"]); | |
656 | print "<tr style=\"background-color:$cat_col[\"$_\"];\"><td><input type=\"text\" name=\"cat$count\" value=\"$_\" style=\"background-color:$cat_col[\"$_\"];color:$txt_col\"></td>"; | |
657 | print "<td><input type=\"text\" name=\"col$count\" value=\"$cat_col[\"$_\"]\" size=\"8\" style=\"background-color:$cat_col[\"$_\"];color:$txt_col;ime-mode:disabled;\"></td></tr>\n"; | |
658 | $count++; | |
659 | } | |
660 | print "<tr><td><input type=\"text\" name=\"cat$count\" value=\"\"></td>"; | |
661 | print "<td><input type=\"text\" name=\"col$count\" value=\"\" size=\"8\"></td></tr>\n"; | |
662 | print "<tr><td colspan=\"2\">????????????????????<br>????????????????????</td></tr>\n"; | |
663 | print "</table></form>\n"; | |
664 | #------------------------- | |
665 | print "</td></tr></table>"; | |
666 | print "</div>\n"; | |
667 | &footer; | |
668 | exit; | |
669 | } | |
670 | ||
671 | ||
672 | # ?????????????????????? | |
673 | function load_config() { | |
674 | # $ref_config_value = $_[0]; | |
675 | # $config_value = ${ $ref_config_value }; | |
676 | %val; | |
677 | foreach ($config_value) { | |
678 | list($name,$value) = split(/<>/); | |
679 | chomp $value; | |
680 | if ($name) { | |
681 | $tmp = '$' . $name . '=\'' . $value . '\';'; | |
682 | eval $tmp; | |
683 | $val["$name"] = $value; | |
684 | } | |
685 | } | |
686 | $config_value = array(); | |
687 | if (! open(SCR,"./init.cgi")) { | |
688 | &dbg("./init.cgi????????"); | |
689 | return; | |
690 | } | |
691 | ($chg_com, $config_start, $config_end); | |
692 | $scr = <SCR>; | |
693 | close(SCR); | |
694 | $new_scr = array(); | |
695 | foreach $line ($scr) { | |
696 | # if ($line =~ /^# config_start/) { $config_start = 1; } | |
697 | # if ($line =~ /^# config_end/) { $config_end = 1; } | |
698 | # if ($config_end || ! $config_start) { | |
699 | # push($new_scr, $line); | |
700 | # next; | |
701 | # } | |
702 | foreach $cfg ('pass',$config) { | |
703 | if ($cfg && exists $val["$cfg"] && $line =~ /^\s*\$$cfg\s*=\s*/) { | |
704 | ($value,$val); | |
705 | if ($val["$cfg"] =~ /^\d+$/) { | |
706 | $value = $val["$cfg"]; | |
707 | } else { | |
708 | $val = $val["$cfg"]; | |
709 | $val =~ s/</</g; | |
710 | $val =~ s/>/>/g; | |
711 | $val =~ s/"/"/g; | |
712 | $val =~ s/\\$//; | |
713 | $value = "'" . $val . "'"; | |
714 | } | |
715 | my($frm,$com); | |
716 | $frm = $line; | |
717 | $frm =~ s/;([^;]*$)//; | |
718 | $com = $1; | |
719 | my($var,$oval) = split(/=/,$frm); | |
720 | $oval =~ s/\s//; | |
721 | $oval =~ s/^['"]//; | |
722 | $oval =~ s/['"]$//; | |
723 | if ($oval ne $val["$cfg"]) { | |
724 | $chg_com .= "${frm} ?? " . '$' . $cfg . " = " . $value . "\n"; | |
725 | } | |
726 | chomp $com; | |
727 | $line = '$' . $cfg . " = " . $value . ";" . $com . "\n"; | |
728 | push($config_value,"$cfg<>" . $val["$cfg"] . "\n"); | |
729 | last; | |
730 | } | |
731 | } | |
732 | push($new_scr, $line); | |
733 | } | |
734 | open(NEW,">init.cgi") || &error("init.cgi???????????"); | |
735 | print NEW $new_scr; | |
736 | close(NEW); | |
737 | ||
738 | # open(CFG,">$config_file") || &error("${config_file}???????????"); | |
739 | # print CFG $config_value; | |
740 | # close(CFG); | |
741 | ||
742 | $message = "????????????????"; | |
743 | $jump = "$script?comment=" . &url_encode($message); | |
744 | &redirect($jump); | |
745 | exit; | |
746 | } | |
747 | ||
748 | ||
749 | function del_file() { | |
750 | $file = &url_encode($in['file']); | |
751 | $file =~ s/%2e/\./g; | |
752 | $del_file = $data_dir . $in['date'] . '/' . $file; | |
753 | if ($in['del_file'] === 'do') { | |
754 | if ($permission) { | |
755 | if (&decrypt($in['pass'], $pass) === 'no') { | |
756 | &error("?????????????"); | |
757 | } | |
758 | } | |
759 | if (unlink $del_file) { | |
760 | if ($action) { | |
761 | $jump = "$script"; | |
762 | } else { | |
763 | $comment = "$in['file']???????????"; | |
764 | $comment = &url_encode($comment); | |
765 | $jump = "$script?mode=write&date=$in['date']&comment=$comment"; | |
766 | } | |
767 | &redirect($jump); | |
768 | } else { | |
769 | &error("$del_file??????????????????"); | |
770 | } | |
771 | } | |
772 | $title .= '??????'; | |
773 | &header; | |
774 | print "<div style=\"margin:1em\">\n"; | |
775 | $in['file'] =~ /.*\.(.*)/; | |
776 | $tail = lc $1; | |
777 | if ($tail === 'jpg' || $tail === 'gif' || $tail === 'png') { | |
778 | ||
779 | # ?????????????? | |
780 | if ($tail === "jpg") { ($w, $h) = &j_size($del_file); } | |
781 | elseif ($tail === "gif") { ($w, $h) = &g_size($del_file); } | |
782 | elseif ($tail === "png") { ($w, $h) = &p_size($del_file); } | |
783 | list($w,$h) = &small_size($w,$h); | |
784 | if ($w && $h) { | |
785 | $wh = " width=\"$w\" height=\"$h\""; | |
786 | } else { | |
787 | $wh = ''; | |
788 | } | |
789 | $del_file =~ s/%/%25/g; | |
790 | print "<img src=\"$del_file\"$wh><div style=\"margin:0.5em\">???(IN%(B??????????????????"; | |
791 | } else { | |
792 | print "<img src=\"./clip.gif\">$in['file']?????????????"; | |
793 | } | |
794 | if ($permission) { | |
795 | if ($pass_cookie) { | |
796 | list($cpass) = &get_cookie; | |
797 | } | |
798 | $pass_com = "??????? <input type=\"password\" name=\"pass\" value=\"$cpass\"><br>\n"; | |
799 | } | |
800 | print <<"EOF"; | |
801 | <form action="$script" method="post" style="margin:0"> | |
802 | <input type="hidden" name="mode" value="del_file"> | |
803 | <input type="hidden" name="date" value="$in['date']"> | |
804 | <input type="hidden" name="file" value="$in['file']"> | |
805 | <input type="hidden" name="del_file" value="do"> | |
806 | $pass_com | |
807 | <input type="submit" value="???????"> <input type="submit" value="??????" onclick="history.back(); return false;"> | |
808 | </form> | |
809 | EOF | |
810 | print "</div>\n"; | |
811 | &footer; | |
812 | } | |
813 | ||
814 | ||
815 | ||
816 | # ?????????? | |
817 | function write() { | |
818 | $data_file = $data_dir . '/' . $in['date'] . '.cgi'; | |
819 | ||
820 | # ????????????? | |
821 | if ($in['write'] === 'do') { | |
822 | if ($permission) { | |
823 | if (&decrypt($in['pass'], $pass) === 'no') { | |
824 | &error("?????????????"); | |
825 | } | |
826 | } | |
827 | if ($in['upfile']) { &upload; } | |
828 | $lock_file = $lock_dir . $in['date']; | |
829 | &lock($lock_file); | |
830 | $in['memo'] =~ s/<br>/\n/g; | |
831 | $in['memo'] =~ s/<br>/\n/g; | |
832 | open(FILE, ">$data_file"); | |
833 | print(FILE $in['category'] . "<!-!>" . $in['memo']); # ???????????????????????????????<!-!>?????????? | |
834 | close(FILE); | |
835 | ||
836 | # ?????????????(IN$(B??????????????????(???????????????)??????????? | |
837 | if (!$in['memo'] && file_exists($data_file)) { | |
838 | unlink $data_file; | |
839 | } | |
840 | ||
841 | # Agenda?????????? | |
842 | if ($coop_agenda) { | |
843 | $agen_file = join('/',$agenda_dir, $in['date'] . '.dat'); | |
844 | if ($in['memo']) { | |
845 | $str = $in['memo']; | |
846 | &jcode::convert(\$str, "sjis"); | |
847 | open(NEW,">$agen_file") || &error("$agen_file???????????"); | |
848 | print NEW $str; | |
849 | close(NEW); | |
850 | } | |
851 | if (!$in['memo'] && file_exists($agen_file)) { | |
852 | unlink $agen_file; | |
853 | } | |
854 | } | |
855 | &unlock($lock_file); | |
856 | if ($action) { | |
857 | $jump = "$script"; | |
858 | } else { | |
859 | $comment = "??????????"; | |
860 | $comment = &url_encode($comment); | |
861 | $jump = "$script?mode=write&date=$in['date']&comment=$comment"; | |
862 | } | |
863 | &redirect($jump); | |
864 | } | |
865 | if (file_exists($data_file)) { | |
866 | $modify_time = (stat($data_file))[9]; | |
867 | if (!open(IN,$data_file)) { &error('???????????????','????????????????.'); } | |
868 | $memo = <IN>; | |
869 | close(IN); | |
870 | } else { | |
871 | $memo = ''; | |
872 | } | |
873 | $memo = ''; | |
874 | foreach ($memo) { | |
875 | $memo .= $_; | |
876 | } | |
877 | list($category,$memo) = split(/<!-!>/,$memo,2); | |
878 | if (!$memo) { | |
879 | $memo = $category; | |
880 | $category = ''; | |
881 | } | |
882 | &header; | |
883 | &write_form; | |
884 | &footer; | |
885 | } | |
886 | ||
887 | ||
888 | # ??????????????? | |
889 | function write_form() { | |
890 | $memo =~ s/<br>/\n/g; | |
891 | $yy = substr($in['date'], 0,4); | |
892 | $mm = substr($in['date'], 4,2); | |
893 | $dd = substr($in['date'], 6,2); | |
894 | $week = &holiday::get_week($yy, $mm, $dd); | |
895 | $holiday = &holiday::holiday($yy, $mm, $dd); | |
896 | $holiday = '' if (!$holiday); | |
897 | $holiday = qq|<span style="color:$holCol;">| . $holiday . qq|</span>| if ($holiday); | |
898 | if (!$holiday) { | |
899 | $w_w = $week; | |
900 | } else { | |
901 | $w_w = 7; | |
902 | } | |
903 | $week_com = qq|<span style="color:$col[$w_w];">| . $week_list[$week] . qq|</span>|; | |
904 | print "<div style=\"padding:1em\">\n"; | |
905 | $param = array('type'=>'month','year'=>$yy,'month'=>$mm,'before_year'=>$in['before_year'],'show_year'=>$in['show_year']); | |
906 | print "<a href=\"$script" . &url_param(%param) . "\">$yy?$mm??</a>$dd??($week_com" $holiday ?(IN%(B?? ); | |
907 | $param['type'] = $in['type']; | |
908 | $param['year'] = $in['year']; | |
909 | $param['month'] = $in['month']; | |
910 | print " <a href=\"$script" . &url_param(%param) . "\">?????????</a>"; | |
911 | print "<form action=\"$script\" method=\"post\" enctype=\"multipart/form-data\" style=\"margin:1em 0 0 0;\">\n"; | |
912 | print "<input type=\"hidden\" name=\"mode\" value=\"write\">\n"; | |
913 | print "<input type=\"hidden\" name=\"write\" value=\"do\">\n"; | |
914 | print "<input type=\"hidden\" name=\"date\" value=\"$in['date']\">\n"; | |
915 | print "<input type=\"hidden\" name=\"type\" value=\"$in['type']\">\n"; | |
916 | print "<input type=\"hidden\" name=\"year\" value=\"$in['year']\">\n"; | |
917 | print "<input type=\"hidden\" name=\"month\" value=\"$in['month']\">\n"; | |
918 | print "<table>\n"; | |
919 | print "<tr><td>\n"; | |
920 | print "??????? <select name=\"category\" size=\"1\">\n"; | |
921 | if ($category) { | |
922 | print "<option value=\"\">???</option>"; | |
923 | } else { | |
924 | print "<option value=\"\" selected>???</option>"; | |
925 | } | |
926 | foreach ($category) { | |
927 | if ($category === $_) { | |
928 | print "<option value=\"$_\" selected>$_</option>"; | |
929 | } else { | |
930 | print "<option value=\"$_\">$_</option>"; | |
931 | } | |
932 | } | |
933 | print "</select>\n"; | |
934 | list($sec, $min, $hour, $mday, $month, $year) = localtime($modify_time); | |
935 | $year += 1900; | |
936 | $month++; | |
937 | if ($modify_time) { | |
938 | print "<span style=\"font-size:80%\">$year?$month??$mday??$hour:$min ????</span>\n"; | |
939 | } | |
940 | print "</td></tr>\n"; | |
941 | print "<tr><td>\n"; | |
942 | print "<textarea name=\"memo\" rows=\"20\" cols=\"100\">$memo</textarea>\n"; | |
943 | print "</td></tr>\n"; | |
944 | if ($upload) { | |
945 | print "<tr><td>\n"; | |
946 | print "?????????? <input type=\"file\" name=\"upfile\" size=\"40\"><br>\n"; | |
947 | print "</td></tr>\n"; | |
948 | } | |
949 | if ($permission) { | |
950 | if ($pass_cookie) { | |
951 | list($cpass) = &get_cookie; | |
952 | } | |
953 | print "<tr><td>\n"; | |
954 | print "??????? <input type=\"password\" name=\"pass\" value=\"$cpass\"><br>\n"; | |
955 | print "</td></tr>\n"; | |
956 | } | |
957 | print "<tr><td>\n"; | |
958 | print "<input type=\"submit\" value=\"????????\"><input type=\"reset\" value=\"?????\">\n"; | |
959 | print "</td></tr>\n"; | |
960 | print "</table>\n"; | |
961 | print "</form>\n"; | |
962 | print "</div>\n"; | |
963 | # $memo =~ s/</</g if !$permission; # ????????? | |
964 | $memo =~ s/\n/<br>/g; | |
965 | if ($in['comment']) { | |
966 | print "<div style=\"margin:0 1em 0 1em;color:red\">$in['comment']</div>\n"; | |
967 | } | |
968 | print "<div style=\"background-color:$memo_back_col;padding:0.5em 1em 0.5em 1em;margin-bottom:0.5em;\">"; | |
969 | ||
970 | if ($use_tag && $permission) { | |
971 | # ??????????????????????(IN$(B?????(IN>(B??????????????????? | |
972 | $memo =~ s/</</g; | |
973 | $memo =~ s/>/>/g; | |
974 | $memo =~ s/"/"/g; | |
975 | } else { | |
976 | $memo =~ s/</</g; | |
977 | $memo =~ s/>/>/g; | |
978 | $memo =~ s/<br>/<br>/g; | |
979 | $memo =~ s/"/"/g; | |
980 | } | |
981 | print $memo; | |
982 | $attach_dir = $data_dir . $in['date']; | |
983 | if (file_exists($attach_dir)) { | |
984 | opendir(DIR,"$attach_dir"); | |
985 | while ($file = readdir(DIR)) { | |
986 | next if $file === '.' || $file === '..'; | |
987 | $link = join('/',$attach_dir,$file); | |
988 | $file =~ /.*\.(.*)/; | |
989 | $tail = lc $1; | |
990 | list($d,$d,$d,$d,$d,$d,$d,$fsize,$d,$mtime) = stat($link); | |
991 | $mtime["$link"] = $mtime; | |
992 | $file["$link"] = $file; | |
993 | if ($fsize < 2000) { | |
994 | $fsize["$link"] = $fsize . 'byte'; | |
995 | } elseif ($fsize > 2000) { | |
996 | $fsize["$link"] = sprintf( "%.1f", ($fsize / 1024)) . 'KB'; | |
997 | } | |
998 | if ($tail === 'jpg' || $tail === 'gif' || $tail === 'png') { | |
999 | ||
1000 | # ?????????????? | |
1001 | if ($tail === "jpg") { ($w, $h) = &j_size($link); } | |
1002 | elseif ($tail === "gif") { ($w, $h) = &g_size($link); } | |
1003 | elseif ($tail === "png") { ($w, $h) = &p_size($link); } | |
1004 | list($w,$h) = &small_size($w,$h); | |
1005 | if ($w && $h) { $wh["$link"] = "width=\"$w\" height=\"$h\""; } | |
1006 | else { $wh["$link"] = ""; } | |
1007 | } | |
1008 | } | |
1009 | closedir(DIR); | |
1010 | foreach $key (sort { $mtime[$b] <=> $mtime[$a] } keys %mtime) { | |
1011 | $tmp = $key; | |
1012 | $tmp =~ s/%/%25/g; | |
1013 | $decode_name = &url_decode($file["$key"]); | |
1014 | if ($wh["$key"]) { | |
1015 | print "<div style=\"margin:0.5em\"><a href=\"$tmp\"><img src=\"$tmp\" $wh[\"$key\"] border=\"0\" alt=\"decode_name\" title=\"$decode_name\n$fsize[\"$key\"]\"></a> <a href=\"$script?mode=del_file&date=$in['date']&file=$file[\"$key\"]\">???</a></div>"; | |
1016 | } else { | |
1017 | print "<div style=\"margin:0.5em\"><a href=\"$tmp\" title=\"$decode_name\n$fsize[\"$key\"]\"><img src=\"./clip.gif\" border=\"0\" alt=\"$decode_name\">$decode_name</a> <a href=\"$script?mode=del_file&date=$in['date']&file=$file[\"$key\"]\">???</a></div>"; | |
1018 | } | |
1019 | } | |
1020 | } | |
1021 | print "</div>\n"; | |
1022 | } | |
1023 | ||
1024 | function small_size() { | |
1025 | list($w,$h,$mw,$mh) = $_; | |
1026 | $maxw = $MaxW; | |
1027 | $maxh = $MaxH; | |
1028 | $maxw = $mw if $mw; | |
1029 | $maxh = $mh if $mh; | |
1030 | if ($w > 0 && $w > $maxw) { | |
1031 | $ratio = $maxw / $w; | |
1032 | $w = $maxw; | |
1033 | $h = int($h * $ratio); | |
1034 | } | |
1035 | if ($h > 0 && $h > $maxh) { | |
1036 | $ratio = $maxh / $h; | |
1037 | $h = $maxh; | |
1038 | $w = int($w * $ratio); | |
1039 | } | |
1040 | return($w,$h); | |
1041 | } | |
1042 | ||
1043 | ||
1044 | # ???????? | |
1045 | function search() { | |
1046 | &header; | |
1047 | &search_form; | |
1048 | $cond = $in['cond']; | |
1049 | $key = $in['keyword']; | |
1050 | $key =~ s/??/ /g; | |
1051 | $key =~ s/\t/ /g; | |
1052 | $key_list = split(/ /,$key); | |
1053 | $hit_list = array(); | |
1054 | print "<div style=\"padding:1em\">"; | |
1055 | $param = array('before_year'=>$in['before_year'],'show_year'=>$in['show_year'],'type'=>$in['type'],'year'=>$in['year'],'month'=>$in['month']); | |
1056 | print "<a href=\"$script" . &url_param(%param) . "\">?????????</a>\n"; | |
1057 | $result = "<table>\n"; | |
1058 | opendir(DIR, $data_dir); | |
1059 | $logfile_list = grep { /\.cgi$/i } readdir(DIR); | |
1060 | closedir(DIR); | |
1061 | $logfile_list = sort {$b <=> $a} $logfile_list; | |
1062 | $total_file = scalar($logfile_list); | |
1063 | $hit_count = 0; | |
1064 | $ascii = '[\x00-\x7F]'; | |
1065 | $twoBytes = '[\x8E\xA1-\xFE][\xA1-\xFE]'; | |
1066 | $threeBytes = '\x8F[\xA1-\xFE][\xA1-\xFE]'; | |
1067 | foreach $file ($logfile_list) { | |
1068 | $file_path = join('/',$data_dir, $file); | |
1069 | open(FILE,$file_path) || &error("Can't open $file_path"); | |
1070 | $cont = <FILE>; | |
1071 | close(FILE); | |
1072 | $cont = ''; | |
1073 | foreach ($cont) { $cont .= $_; } | |
1074 | list($category,$cont) = split(/<!-!>/,$cont,2); | |
1075 | if (!$cont) { | |
1076 | $cont = $category; | |
1077 | $category = ''; | |
1078 | } | |
1079 | $flag = 0; | |
1080 | foreach $key ($key_list){ | |
1081 | if ($cont =~ /^(?:$ascii|$twoBytes|$threeBytes)*?(?:$key)/) { | |
1082 | $flag = 1; | |
1083 | if ($cond === 'or') { last; } | |
1084 | } else { | |
1085 | if ($cond === 'and'){ $flag = 0; last; } | |
1086 | } | |
1087 | } | |
1088 | if ($flag == 1) { | |
1089 | $result .= "<tr>"; | |
1090 | $yy = substr($file, 0,4); | |
1091 | $mm = substr($file, 4,2); | |
1092 | $dd = substr($file, 6,2); | |
1093 | $week = &holiday::get_week($yy, $mm, $dd); | |
1094 | $holiday = &holiday::holiday($yy, $mm, $dd); | |
1095 | if ($holiday) { | |
1096 | $wk_c = $col[7]; | |
1097 | } else { | |
1098 | $wk_c = $col[$week]; | |
1099 | } | |
1100 | $result .= qq|<td nowrap valign="top">$yy?$mm??$dd??(<span style="color:$wk_c">$week_list[$week]</span>)</td>\n|; | |
1101 | $hit = 0; | |
1102 | $cont = split(/\n/,$cont); | |
1103 | foreach ($cont) { | |
1104 | foreach $key ($key_list){ | |
1105 | if (/^(?:$ascii|$twoBytes|$threeBytes)*?(?:$key)/) { | |
1106 | $hit_line = $_; | |
1107 | $hit = 1; | |
1108 | last; | |
1109 | } | |
1110 | } | |
1111 | if ($hit) { last; } | |
1112 | } | |
1113 | $catcol = $cat_col["$category"]; | |
1114 | if (!$catcol) { | |
1115 | $catcol = $memo_col; | |
1116 | } | |
1117 | $result .= "<td><a href=\"$script?mode=write&date=$yy$mm$dd\" target=\"_blank\" style=\"color:$catcol;text-decoration:none\">??</a>" . &keyword_coloring($hit_line, $key_list) . "</td>"; | |
1118 | $result .= "</tr>\n"; | |
1119 | $hit_count++; | |
1120 | } | |
1121 | } | |
1122 | if (!$hit_count) { | |
1123 | print "<div>????????????????</div>\n"; | |
1124 | } else { | |
1125 | print "<div style=\"margin:0.3em;color:red;\">" . $hit_count . "?????!</div>\n"; | |
1126 | } | |
1127 | $result .= "</table>\n"; | |
1128 | print $result; | |
1129 | print "</div>\n"; | |
1130 | &footer | |
1131 | } | |
1132 | ||
1133 | # ??????????????? | |
1134 | function search_form() { | |
1135 | print "<div style=\"margin:0.5em 1em 0.5em 1em;\">\n"; | |
1136 | print "<table width=\"100%\"><tr><td>"; | |
1137 | print "<form action=\"$script\" method=\"post\" style=\"margin:0\">\n"; | |
1138 | print "<input type=\"hidden\" name=\"mode\" value=\"search\">\n"; | |
1139 | print "<input type=\"hidden\" name=\"type\" value=\"$in['type']\">\n"; | |
1140 | print "<input type=\"hidden\" name=\"year\" value=\"$in['year']\">\n"; | |
1141 | print "<input type=\"hidden\" name=\"month\" value=\"$in['month']\">\n"; | |
1142 | print "<input type=\"hidden\" name=\"before_year\" value=\"$in['before_year']\">\n"; | |
1143 | print "<input type=\"hidden\" name=\"show_year\" value=\"$in['show_year']\">\n"; | |
1144 | print " ???????? <input type=\"text\" name=\"keyword\" value=\"$in['keyword']\" size=\"20\">\n"; | |
1145 | foreach ('and','or') { | |
1146 | if ($in['cond'] === $_ || (!$in['cond'] && $_ === 'and')) { | |
1147 | print "<input type=\"radio\" name=\"cond\" value=\"$_\" checked>" . uc($_) . " \n"; | |
1148 | } else { | |
1149 | print "<input type=\"radio\" name=\"cond\" value=\"$_\">" . uc($_) . " \n"; | |
1150 | } | |
1151 | } | |
1152 | print "<input type=\"submit\" value=\"????????\"><input type=\"reset\" value=\"?????\">\n"; | |
1153 | print "</form></td>"; | |
1154 | if ($in['comment']) { | |
1155 | print "<td><span style=\"color:red\">$in['comment']</span></td>"; | |
1156 | } | |
1157 | print "<td align=\"right\">\n"; | |
1158 | print "<form action=\"$script\" method=\"post\" style=\"margin:0;padding:0\">\n"; | |
1159 | print "<input type=\"hidden\" name=\"change_show_year\" value=\"1\">\n"; | |
1160 | print "<input type=\"hidden\" name=\"_pass\" value=\"$in['_pass']\">\n"; | |
1161 | print "<input type=\"hidden\" name=\"type\" value=\"$in['type']\">\n"; | |
1162 | ($bef_mon,$after_mon,$start_year,$end_year); | |
1163 | $start_year = $tyear - $before_year; | |
1164 | $end_year = $tyear + $show_year; | |
1165 | if ($january_top) { | |
1166 | $bef_mon = 1; | |
1167 | $after_mon = 12; | |
1168 | } else { | |
1169 | $bef_mon = $tmon - 1; | |
1170 | if ($bef_mon < 1) { | |
1171 | $bef_mon = 12; | |
1172 | $start_year--; | |
1173 | } | |
1174 | $after_mon = $tmon +10; | |
1175 | if ($after_mon > 12) { | |
1176 | $after_mon -= 12; | |
1177 | $end_year++; | |
1178 | } | |
1179 | } | |
1180 | # print "</select>?${bef_mon}????"; | |
1181 | print "<input type=\"text\" name=\"start_year\" value=\"$start_year\" size=\"4\" style=\"ime-mode:disabled;\">?${bef_mon}????"; | |
1182 | # print "<input type=\"text\" name=\"before_year\" value=\"$before_year\" size=\"2\" style=\"ime-mode:disabled\">??????? "; | |
1183 | print "<input type=\"hidden\" name=\"before_year\" value=\"$before_year\">\n"; | |
1184 | # print "<input type=\"text\" name=\"show_year\" value=\"$show_year\" size=\"2\" style=\"ime-mode:disabled\">???????? "; | |
1185 | print "<input type=\"hidden\" name=\"show_year\" value=\"$show_year\">\n"; | |
1186 | print "<input type=\"text\" name=\"end_year\" value=\"$end_year\" size=\"4\" style=\"ime-mode:disabled;\">?${after_mon}????"; | |
1187 | print "<input type=\"submit\" value=\"????????\"><input type=\"submit\" name=\"year\" value=\"?????\">\n"; | |
1188 | print "</form></td>\n"; | |
1189 | print "<td><a href=\"$script?mode=config\">????</a></td>"; | |
1190 | print "</tr></table>"; | |
1191 | print "</div>\n"; | |
1192 | } | |
1193 | ||
1194 | function calen() { | |
1195 | local($next_y,$next_m,$back_y,$back_m,$today, | |
1196 | $last,$week,$md,$f,$i,$mkey,$holi,$flag,$col); | |
1197 | ||
1198 | $year = $tyear; | |
1199 | $mon = $tmon; | |
1200 | $mday = $tmday; | |
1201 | $today = sprintf("%04d-%s-%s", $year,$mon,$mday); | |
1202 | &search_form; | |
1203 | $sc_st = 0; | |
1204 | $sc_count = 0; | |
1205 | $sc_com = array(); | |
1206 | if ($in['type'] === 'month') { | |
1207 | if (!$in['year']) { | |
1208 | $in['year'] = $year; | |
1209 | } | |
1210 | if (!$in['month']) { | |
1211 | $in['month'] = $mon; | |
1212 | } | |
1213 | $y_stt = $y_end = $year = $in['year']; | |
1214 | $mon = $in['month']; | |
1215 | $m_stt = $mon - 1; | |
1216 | $m_end = $mon + 1; | |
1217 | } else { | |
1218 | $y_stt = $year - $before_year; | |
1219 | $y_end = $year+$show_year; | |
1220 | $m_stt = $mon - 1; | |
1221 | $m_end = $mon + 10; | |
1222 | } | |
1223 | if ($january_top && $in['type'] ne 'month') { | |
1224 | $m_stt = 1; | |
1225 | $m_end = 12; | |
1226 | } | |
1227 | print "<div style=\"margin:0 1em 0 1em;\">"; | |
1228 | print "<a href=\"$script?type=year\">??????????</a>" if $in['type'] === 'month'; | |
1229 | # print "<a href=\"$script?before_year=$in['before_year']&show_year=$in['show_year']\">??????????</a>" if $in['type'] === 'month'; | |
1230 | print "<table border=\"$frame_border\" cellpadding=\"$frame_padding\" cellspacing=\"$frame_spacing\" style=\"margin-top:0.5em\">\n"; | |
1231 | for ($y = $y_stt; $y <= $y_end; $y++) { | |
1232 | print "<tr>\n"; | |
1233 | for ($m = $m_stt; $m <= $m_end; $m++) { | |
1234 | if ($in['type'] === 'month') { | |
1235 | if ($m == $mon) { | |
1236 | $sc_st = 1; | |
1237 | } else { | |
1238 | $sc_st = 0; | |
1239 | } | |
1240 | } | |
1241 | if ($m < 1) { | |
1242 | $mm = $m + 12; | |
1243 | $yy = $y - 1; | |
1244 | } elseif ($m > 12) { | |
1245 | $mm = $m - 12; | |
1246 | $yy = $y + 1; | |
1247 | } else { | |
1248 | $mm = $m; | |
1249 | $yy = $y; | |
1250 | } | |
1251 | if ($tyear == $yy && $tmon == $mm) { | |
1252 | print "<td valign=\"top\" style=\"background-color:$tomon_col\">"; | |
1253 | } elseif ($m == $mon && $in['type'] === 'month') { | |
1254 | print "<td valign=\"top\" style=\"background-color:$memo_back_col\">"; | |
1255 | } else { | |
1256 | print "<td valign=\"top\">"; | |
1257 | } | |
1258 | ||
1259 | # ?????????????? | |
1260 | $last = (31,28,31,30,31,30,31,31,30,31,30,31) [$mm-1] | |
1261 | + ($mm == 2 && (($yy % 4 == 0 && $yy % 100 != 0) || | |
1262 | $yy % 400 == 0)); | |
1263 | ||
1264 | # ???????(IN=(B?????? | |
1265 | $week = &getweek(1, $yy, $mm); | |
1266 | $col = array($sunCol,$norCol,$norCol,$norCol,$norCol,$norCol,$satCol,$holCol); | |
1267 | &create_calen($yy,$mm); | |
1268 | print "</td>\n"; | |
1269 | } | |
1270 | print "</tr>\n"; | |
1271 | } | |
1272 | print "</table>\n</div>\n"; | |
1273 | print "<div style=\"margin:1em 1em 0.5em 1em;background-color:$memo_back_col\">"; | |
1274 | if ($in['type'] === 'month') { | |
1275 | if ($view_past) { | |
1276 | $sch_title = "$year?$mon??(IN%(B??"; | |
1277 | } else { | |
1278 | $sch_title = "$year?$mon??????"; | |
1279 | } | |
1280 | } else { | |
1281 | if ($view_past) { | |
1282 | $sch_title = "???(IN%(B??$sc_number??"; | |
1283 | } else { | |
1284 | $sch_title = "??????????$sc_number??"; | |
1285 | } | |
1286 | } | |
1287 | $txt_col = &text_color($title_back_col); | |
1288 | print "<div style=\"color:$txt_col; background:$title_back_col;padding:2px;font-weight:bold;\">$sch_title</div>\n"; | |
1289 | print "<div style=\"margin:0.4em;\">\n?????????<span style=\"font-size:100%;color:$memo_col;\">??</span>???"; | |
1290 | foreach($category) { | |
1291 | print " <span style=\"font-size:100%;color:$cat_col[\"$_\"];\">??</span>$_"; | |
1292 | } | |
1293 | print "</div>\n"; | |
1294 | print "<table cellpadding=\"2\" style=\"line-heigft:1.2em;\">" if $sc_com; | |
1295 | if ($view_past) { | |
1296 | $sc_com = reverse($sc_com); | |
1297 | $sc_com = $sc_com[0 .. ($sc_number-1)]; | |
1298 | } | |
1299 | foreach ($sc_com) { | |
1300 | if ($use_tag && $permission) { | |
1301 | # ??????????????????????(IN$(B?????(IN>(B??????????????????? | |
1302 | s/</</g; | |
1303 | s/>/>/g; | |
1304 | s/"/"/g; | |
1305 | } | |
1306 | print $_; | |
1307 | } | |
1308 | print "</table>\n" if $sc_com; | |
1309 | print "</div>\n"; | |
1310 | print "<div style=\"text-align:right;margin-right:1em\">\n"; | |
1311 | print "<form action=\"$script\" method=\"post\">\n"; | |
1312 | print "<input type=\"hidden\" name=\"csize_edit\" value=\"1\">"; | |
1313 | print "<input type=\"hidden\" name=\"type\" value=\"$in['type']\">"; | |
1314 | print "<input type=\"hidden\" name=\"year\" value=\"$in['year']\">"; | |
1315 | print "<input type=\"hidden\" name=\"month\" value=\"$in['month']\">"; | |
1316 | print "<table style=\"margin-left:auto;margin-right:1em\"><tr><td><span style=\"font-size:80%\">?????????(IN%(B????????</span></td></tr>\n"; | |
1317 | print "<tr><td><span style=\"font-size:80%\">???????????</span> "; | |
1318 | print "<input type=\"submit\" name=\"cfsize\" value=\"??\"> <input type=\"submit\" name=\"cfsize\" value=\"??\"> "; | |
1319 | print "<span style=\"font-size:80%\">??</span> <input type=\"submit\" name=\"ccsize\" value=\"??\"> <input type=\"submit\" name=\"ccsize\" value=\"??\"></td></tr></table>\n</form>\n"; | |
1320 | print "</div>\n"; | |
1321 | } | |
1322 | ||
1323 | ||
1324 | function create_calen() { | |
1325 | list($yy,$mm,) = $_; | |
1326 | ||
1327 | # ?????????????? | |
1328 | $last = (31,28,31,30,31,30,31,31,30,31,30,31) [$mm-1] | |
1329 | + ($mm == 2 && (($yy % 4 == 0 && $yy % 100 != 0) || | |
1330 | $yy % 400 == 0)); | |
1331 | $week = &getweek(1, $yy, $mm); | |
1332 | $txt_col = &text_color($month_back_col); | |
1333 | $param = array('type'=>'month','year'=>$yy,'month'=>$mm,'before_year'=>$in['before_year'],'show_year'=>$in['show_year']); | |
1334 | $url = $script . &url_param(%param); | |
1335 | print <<EOM; | |
1336 | <table border="$cal_border" cellpadding="$cal_padding" cellspacing="$cal_spacing" width="100%"> | |
1337 | <tr> | |
1338 | <th colspan=7 style="background-color:$month_back_col;padding:0.2em 0 0.2em 0;" class="month"><a href="$url" title="$yy?$mm????????" style="color:$txt_col;">$yy?$mm??</a></th> | |
1339 | </tr> | |
1340 | <tr> | |
1341 | EOM | |
1342 | ||
1343 | # ????? | |
1344 | foreach $i (0 .. 6) { | |
1345 | print "<td align=center style=\"color:$col[$i]; font-size:$cal_fsize;\" width=\"$cal_cwidth\">$week_list[$i]</td>\n"; | |
1346 | } | |
1347 | print "</tr>\n<tr>"; | |
1348 | ||
1349 | # ???(IN%(B????? | |
1350 | foreach $i (0 .. 6) { | |
1351 | last if ($i == $week); | |
1352 | print "<td> </td>\n"; | |
1353 | } | |
1354 | ||
1355 | # ??????????????? | |
1356 | $flag=0; | |
1357 | $mkey=0; | |
1358 | foreach $i (1 .. $last) { | |
1359 | ||
1360 | # ??????? | |
1361 | if ($week > 0 && $week % 7 == 0) { | |
1362 | print "</tr>\n<tr>"; | |
1363 | $week=0; | |
1364 | } | |
1365 | ||
1366 | # ??(I2?(B???????? | |
1367 | if ($week == 1) { $mkey++; } | |
1368 | $md = sprintf("%02d%02d", $mm,$i); | |
1369 | $w = &holiday::get_week($yy, $mm, $i); | |
1370 | if ($today === "$yy-$mm-$i") { | |
1371 | $today_border = "border-style:solid;border-color:red; border-width:1px"; | |
1372 | $sc_st = 1; | |
1373 | } else { | |
1374 | $today_border = ''; | |
1375 | } | |
1376 | $holiday = &holiday::holiday($yy, $mm, $i); | |
1377 | $date = sprintf("%04d%02d%02d",$yy, $mm, $i); | |
1378 | ||
1379 | # ??????(IN>(B?? | |
1380 | $data_file = join('/',$data_dir, "${date}.cgi"); | |
1381 | if (file_exists($data_file)) { | |
1382 | if (!open(IN,$data_file)) { &error('???????????????','????????????????.'); } | |
1383 | $memo = <IN>; | |
1384 | close(IN); | |
1385 | $memo = ''; | |
1386 | $count = 0; | |
1387 | foreach ($memo) { | |
1388 | if ($count > $max_line) { | |
1389 | last; | |
1390 | } | |
1391 | $memo .= $_; | |
1392 | $count++; | |
1393 | } | |
1394 | list($category,$memo) = split(/<!-!>/,$memo,2); | |
1395 | $catcol = $cat_col["$category"]; | |
1396 | if (!$memo) { | |
1397 | $memo = $category; | |
1398 | $category = ''; | |
1399 | } | |
1400 | if (!$catcol) { | |
1401 | $catcol = $memo_col; | |
1402 | } | |
1403 | $new_time = (stat $data_file)[10]; | |
1404 | $up_time = (stat $data_file)[9]; | |
1405 | if ($new_time < $up_time && $up_time + $new_memo * 24 * 3600> time) { | |
1406 | $show_new = "<span style=\"color:red;font-size:90%;\">up!</span> "; | |
1407 | } elseif ($new_time + $new_memo * 24 * 3600> time) { | |
1408 | $show_new = "<span style=\"color:red;font-size:90%;\">new!</span> "; | |
1409 | } else { | |
1410 | $show_new = ' '; | |
1411 | } | |
1412 | $memo_flag = 0; | |
1413 | if ($memo && !$view_past) { | |
1414 | if ($in['type'] === 'month') { | |
1415 | if ($in['year'] == $yy && $in['month'] == $mm) { | |
1416 | $memo_flag = 1; | |
1417 | } | |
1418 | } else { | |
1419 | if ($sc_st && $sc_count < $sc_number) { | |
1420 | $memo_flag = 1; | |
1421 | } | |
1422 | } | |
1423 | } | |
1424 | if ($memo && $view_past) { | |
1425 | if ($in['type'] === 'month') { | |
1426 | if ($in['year'] == $yy && $in['month'] == $mm) { | |
1427 | $memo_flag = 1; | |
1428 | } | |
1429 | ||
1430 | } else { | |
1431 | if (!$sc_st || $today_border) { | |
1432 | $memo_flag = 1; | |
1433 | } | |
1434 | } | |
1435 | } | |
1436 | if ($memo_flag) { | |
1437 | if ($holiday) { | |
1438 | $wk_c = $col[7]; | |
1439 | } else { | |
1440 | $wk_c = $col[$w]; | |
1441 | } | |
1442 | $br_memo = $memo; | |
1443 | $br_memo =~ s/</</g if !$permission; | |
1444 | $br_memo =~ s/\n/<br>/g; | |
1445 | $sc_date = sprintf("%02d??%02d??", $mm, $i); | |
1446 | $param = array('mode'=>'write','date'=>$date,'before_year'=>$in['before_year'],'show_year'=>$in['show_year']); | |
1447 | $url = $script . &url_param(%param); | |
1448 | if ($in['type']) { | |
1449 | $param['type'] = $in['type']; | |
1450 | $param['year'] = $in['year']; | |
1451 | $param['month'] = $in['month']; | |
1452 | $url = $script . &url_param(%param); | |
1453 | } | |
1454 | $sc = qq(<tr><td valign="top" align="right" nowrap>$show_new | |
1455 | ) . $sc_date . qq|(<span style="color:$wk_c">| . $week_list[$w] . qq|</span>)</td>\n | |
1456 | <td valign="top"><a href="$url" style="text-decoration:none;"><span style="font-size:120%;color:$catcol;">??</span></a></td><td>|; | |
1457 | $tmp = $data_dir . '/' . $date; | |
1458 | if (-d $tmp) { | |
1459 | opendir(DIR,"$tmp"); | |
1460 | while ($file=readdir(DIR)) { | |
1461 | next if $file === '.' || $file === '..'; | |
1462 | $file !~ /.*\.(.*)/; | |
1463 | $tail = lc $1; | |
1464 | $path = join('/',$tmp,$file); | |
1465 | $path =~ s/%/%25/g; | |
1466 | $decode_name = &url_decode($file); | |
1467 | if ($tail === 'jpg' || $tail === 'gif' || $tail === 'png') { | |
1468 | $sc .= "<a href=\"$path\"><img src=\"./img.gif\" alt=\"$decode_name\" title=\"$decode_name\" border=\"0\"></a> "; | |
1469 | } else { | |
1470 | $sc .= "<a href=\"$path\"><img src=\"./clip.gif\" alt=\"$decode_name\" title=\"$decode_name\" border=\"0\"></a> "; | |
1471 | } | |
1472 | } | |
1473 | closedir(DIR); | |
1474 | } | |
1475 | $sc .= $br_memo . "</td>\n</tr>\n"; | |
1476 | push($sc_com,$sc); | |
1477 | $sc_count++; | |
1478 | } | |
1479 | } else { | |
1480 | $memo = ''; | |
1481 | } | |
1482 | $param = array('mode'=>'write','date'=>$date,'before_year'=>$in['before_year'],'show_year'=>$in['show_year']); | |
1483 | $url = $script . &url_param(%param); | |
1484 | if ($in['type']) { | |
1485 | $param['type'] = $in['type']; | |
1486 | $param['year'] = $in['year']; | |
1487 | $param['month'] = $in['month']; | |
1488 | $url = $script . &url_param(%param); | |
1489 | } | |
1490 | if ($memo) { | |
1491 | $memo =~ s/<br>/\n/g; | |
1492 | $memo =~ s/<.*?>//g; | |
1493 | $memo =~ s/&/&/g; | |
1494 | $memo =~ s/</</g; | |
1495 | $memo =~ s/>/>/g; | |
1496 | $memo =~ s/"/"/g; | |
1497 | $day_col = $col[$w]; | |
1498 | if (!$day_col) {$day_col = '#000000';} | |
1499 | if ($holiday) { | |
1500 | $memo = "--" . $holiday . "--\n" . $memo; | |
1501 | $day_col = $col[7]; | |
1502 | } | |
1503 | if ($cat_col["$category"] ne '') { | |
1504 | $bgc = $cat_col["$category"]; | |
1505 | } else { | |
1506 | $bgc = $memo_col; | |
1507 | } | |
1508 | $txt_col = &text_color($bgc); | |
1509 | print "<td align=right class=\"cal\" style=\"background-color:$bgc;color:$txt_col;$today_border\">\n"; | |
1510 | print "<a href=\"$url\" style=\"color:$day_col;text-decoration:none;\" title=\"$memo\">$i</a>"; | |
1511 | } else { | |
1512 | if (!$holiday) { | |
1513 | if ($col[$w]) { | |
1514 | print "<td align=right class=cal style=\"$today_border\"><a href=\"$url\" style=\"color:$col[$w];text-decoration:none;\">$i</a>"; | |
1515 | } else { | |
1516 | print "<td align=right class=cal style=\"$today_border\"><a href=\"$url\" style=\"color:#000000;text-decoration:none;\">$i</a>"; | |
1517 | } | |
1518 | } else { | |
1519 | print "<td align=right class=cal style=\"$today_border\"><strong><a href=\"$url\" title=\"--$holiday--\" style=\"color:$holCol;text-decoration:none;\">$i</a></strong>"; | |
1520 | } | |
1521 | } | |
1522 | print "</td>\n"; | |
1523 | $week++; | |
1524 | } | |
1525 | ||
1526 | # ?????(IN%(B????? | |
1527 | while ( $week < 7 ) { | |
1528 | print "<td> </td>\n"; | |
1529 | $week++; | |
1530 | } | |
1531 | print "</tr></table>\n"; | |
1532 | } | |
1533 | ||
1534 | ||
1535 | #------------------------------------------------- | |
1536 | # ???????????? | |
1537 | #------------------------------------------------- | |
1538 | function encrypt_old() { | |
1539 | local($inpw) = $_[0]; | |
1540 | local($SALT, $salt, $encrypt); | |
1541 | ||
1542 | $SALT = array('a'..'z', 'A'..'Z', '0'..'9', '.', '/'); | |
1543 | srand; | |
1544 | $salt = $SALT[int(rand($SALT))] . $SALT[int(rand($SALT))]; | |
1545 | $encrypt = crypt($inpw, $salt) || crypt ($inpw, '$1$' . $salt); | |
1546 | $encrypt; | |
1547 | } | |
1548 | ||
1549 | function encrypt() { | |
1550 | my($inpw) = $_[0]; | |
1551 | $encrypt; | |
1552 | if ($code == 2) { | |
1553 | use Digest::MD5 qw/md5_hex/; | |
1554 | $str = array('a' .. 'f', 0 .. 9); | |
1555 | $salt; | |
1556 | for (1 .. 8) { | |
1557 | $salt .= $str[int(rand($str))]; | |
1558 | } | |
1559 | $encrypt = $salt . md5_hex($salt . $inpw); | |
1560 | } else { | |
1561 | my($SALT, $salt); | |
1562 | $SALT = array('a'..'z', 'A'..'Z', '0'..'9'); | |
1563 | srand(int(rand(100000))); | |
1564 | $salt = $SALT[int(rand($SALT))] . $SALT[int(rand($SALT))]; | |
1565 | $encrypt = crypt($inpw, $salt) || crypt ($inpw, '$1$' . $salt); | |
1566 | if (length($inpw) > 8) { | |
1567 | $inpw2 = substr($inpw,8,8); | |
1568 | srand(int(rand(100000))); | |
1569 | $salt2 = $SALT[int(rand($SALT))] . $SALT[int(rand($SALT))]; | |
1570 | $encrypt2 = crypt($inpw2, $salt2) || crypt ($inpw2, '$1$' . $salt2); | |
1571 | $encrypt .= $encrypt2; | |
1572 | } | |
1573 | } | |
1574 | $encrypt; | |
1575 | } | |
1576 | ||
1577 | #------------------------------------------------- | |
1578 | # ???????????? | |
1579 | #------------------------------------------------- | |
1580 | function decrypt_old() { | |
1581 | local($inpw, $logpw) = $_; | |
1582 | local($salt, $check); | |
1583 | ||
1584 | $salt = $logpw =~ /^\$1\$(.*)\$/ && $1 || substr($logpw, 0, 2); | |
1585 | $check = "no"; | |
1586 | if (crypt($inpw, $salt) === $logpw || crypt($inpw, '$1$' . $salt) === $logpw) | |
1587 | { $check = "yes"; } | |
1588 | $check; | |
1589 | } | |
1590 | ||
1591 | ||
1592 | function decrypt() { | |
1593 | my($inpw, $logpw) = $_; | |
1594 | my($salt, $check); | |
1595 | if (length($logpw) == 40) { | |
1596 | # salt???????8?????????(IP$(B? | |
1597 | $salt = substr($logpw, 0, 8); | |
1598 | $check = "no"; | |
1599 | # ??? | |
1600 | if ($logpw === ($salt . md5_hex($salt . $inpw))) { | |
1601 | $check = "yes"; | |
1602 | } | |
1603 | } else { | |
1604 | $logpw1 = substr($logpw,0,13); | |
1605 | $inpw1 = substr($logpw,0,8); | |
1606 | $salt = $logpw1 =~ /^\$1\$(.*)\$/ && $1 || substr($logpw1, 0, 2); | |
1607 | $check = "no"; | |
1608 | if (crypt($inpw, $salt) === $logpw1 || crypt($inpw1, '$1$' . $salt) === $logpw1) { | |
1609 | $check = "yes"; | |
1610 | } | |
1611 | if ($check === "yes" && length($logpw) == 26) { | |
1612 | $logpw2 = substr($logpw,13,13); | |
1613 | $inpw2 = substr($inpw,8,8); | |
1614 | $salt2 = $logpw2 =~ /^\$1\$(.*)\$/ && $1 || substr($logpw2, 0, 2); | |
1615 | if (crypt($inpw2, $salt2) === $logpw2 || crypt($inpw2, '$1$' . $salt2) === $logpw2) { | |
1616 | $check = "yes"; | |
1617 | } else { | |
1618 | $check = "no"; | |
1619 | } | |
1620 | } | |
1621 | } | |
1622 | $check; | |
1623 | } | |
1624 | ||
1625 | ||
1626 | #--------------------------------------- | |
1627 | # ????????????? | |
1628 | #--------------------------------------- | |
1629 | function decode() { | |
1630 | local($key,$val); | |
1631 | undef(%in); | |
1632 | &ReadParse; | |
1633 | while ( ($key,$val) = each(%in) ) { | |
1634 | next if ($key =~ /^upfile/); | |
1635 | ||
1636 | # ?????JIS????????? | |
1637 | &jcode'convert(*val, 'euc'); | |
1638 | ||
1639 | # ?????????? | |
1640 | $val =~ s/<>/<>/g; | |
1641 | $val =~ s/&/&/g; | |
1642 | $val =~ s/"/"/g; | |
1643 | $val =~ s/</</g; | |
1644 | $val =~ s/>/>/g; | |
1645 | $val =~ s/\r\n/<br>/g; | |
1646 | $val =~ s/\r/<br>/g; | |
1647 | $val =~ s/\n/<br>/g; | |
1648 | $val =~ s/\,/,/g; | |
1649 | $in[$key] = $val; | |
1650 | } | |
1651 | } | |
1652 | ||
1653 | ||
1654 | function url_param() { | |
1655 | %param = $_; | |
1656 | $count = 0; | |
1657 | $url; | |
1658 | foreach (sort keys %param) { | |
1659 | if ($param["$_"]) { | |
1660 | if (! $count) { | |
1661 | $url .= "?" . $_ . "=$param[\"$_\"]"; | |
1662 | $count++; | |
1663 | } else { | |
1664 | $url .= "&" . $_ . "=$param[\"$_\"]"; | |
1665 | } | |
1666 | } | |
1667 | } | |
1668 | return $url; | |
1669 | } | |
1670 | ||
1671 | ||
1672 | #------------------------------------------------- | |
1673 | # ?????????? | |
1674 | #------------------------------------------------- | |
1675 | function set_cookie() { | |
1676 | local($cook) = $_; | |
1677 | local($gmt, $cook, $t, $m, $w); | |
1678 | ||
1679 | $cookie_day = 30 if !$cookie_day; | |
1680 | $t = gmtime(time + $cookie_day*24*60*60); | |
1681 | $m = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); | |
1682 | $w = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); | |
1683 | ||
1684 | # ???????????? | |
1685 | $gmt = sprintf("%s, %02d-%s-%04d %02d:%02d:%02d GMT", | |
1686 | $w[$t[6]], $t[3], $m[$t[4]], $t[5]+1900, $t[2], $t[1], $t[0]); | |
1687 | ||
1688 | # ??????????URL??????? | |
1689 | foreach ($cook) { | |
1690 | s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg; | |
1691 | $cook .= "$_<>"; | |
1692 | } | |
1693 | ||
1694 | # ??? | |
1695 | print "Set-Cookie: CALENDAR=$cook; expires=$gmt\n"; | |
1696 | } | |
1697 | ||
1698 | #------------------------------------------------- | |
1699 | # ??????????? | |
1700 | #------------------------------------------------- | |
1701 | function get_cookie() { | |
1702 | local($key, $val, *cook); | |
1703 | ||
1704 | # ???????????? | |
1705 | $cook = $_SERVER['HTTP_COOKIE']; | |
1706 | ||
1707 | # ????ID????(IP$(B? | |
1708 | foreach ( split(/;/, $cook) ) { | |
1709 | list($key, $val) = split(/=/); | |
1710 | $key =~ s/\s//g; | |
1711 | $cook[$key] = $val; | |
1712 | } | |
1713 | ||
1714 | # ???????URL?????????????? | |
1715 | foreach ( split(/<>/, $cook['CALENDAR']) ) { | |
1716 | s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg; | |
1717 | ||
1718 | push($cook,$_); | |
1719 | } | |
1720 | return ($cook); | |
1721 | } | |
1722 | ||
1723 | ||
1724 | function header() { | |
1725 | if ($head_flag) { | |
1726 | return; | |
1727 | } | |
1728 | $head_flag = 1; | |
1729 | $color = array('bgcolor'=>'#ffffff','text'=>'black','link'=>'blue','vlink'=>'purple','alink'=>'#cc0000'); | |
1730 | foreach (array_keys($color) as $key) { | |
1731 | if (!$$key) { $$key = $color[$key]; } | |
1732 | } | |
1733 | print "Content-type: text/html\n\n"; | |
1734 | $calFont =~ s/,/,/g; | |
1735 | $text_color = &text_color($month_back_col); | |
1736 | list($bright,$dark) = &bright_dark($month_back_col); | |
1737 | $mh_back; | |
1738 | if ($text_color === '#ffffff') { | |
1739 | $mh_back = $dark; | |
1740 | } else { | |
1741 | $mh_back = $bright; | |
1742 | } | |
1743 | print <<"EOM"; | |
1744 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
1745 | <html lang="ja"> | |
1746 | <head> | |
1747 | <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=euc-jp"> | |
1748 | <META HTTP-EQUIV="Content-Style-Type" content="text/css"> | |
1749 | <title>$title</title> | |
1750 | <style type="text/css"> | |
1751 | <!-- | |
1752 | body { | |
1753 | margin-left:0px; | |
1754 | margin-right:0px; | |
1755 | margin-top:0px; | |
1756 | margin-bottom:0px; | |
1757 | } | |
1758 | table { | |
1759 | font-size:90%; | |
1760 | } | |
1761 | a:link { color:$link_col } | |
1762 | a:visited { color:$visited_col } | |
1763 | a:hover { | |
1764 | background:$hover_background_col; | |
1765 | color:$hover_col; | |
1766 | } | |
1767 | a:active { color:$active_col } | |
1768 | ||
1769 | .cal { | |
1770 | font-size:$cal_fsize; | |
1771 | font-family:$calFont; | |
1772 | } | |
1773 | ||
1774 | .month a { | |
1775 | font-size:110%; | |
1776 | color:$text_color; | |
1777 | text-decoration:none; | |
1778 | } | |
1779 | ||
1780 | .month a:hover { | |
1781 | background:$mh_back; | |
1782 | font-size:110%; | |
1783 | color:$text_color; | |
1784 | text-decoration:none; | |
1785 | } | |
1786 | ||
1787 | --> | |
1788 | </style> | |
1789 | </head> | |
1790 | <body bgcolor="$bgcolor" text="$text_col" link="$link" vlink="$vlink" alink="$alink"> | |
1791 | EOM | |
1792 | &headline; | |
1793 | } | |
1794 | ||
1795 | ||
1796 | function headline() { | |
1797 | if ($_[0]) { | |
1798 | $title = $_[0]; | |
1799 | } | |
1800 | $txt_col = &text_color($title_back_col); | |
1801 | print <<"EOM"; | |
1802 | <div style="text-align:center;background-color:$title_back_col;color:$txt_col;padding:0.2em 0.2em 0.2em 0.2em;font-size:$title_font_size;font-weight:bold;margin-bottom:0em">$title</div> | |
1803 | EOM | |
1804 | } | |
1805 | ||
1806 | ||
1807 | function footer() { | |
1808 | if ($dbg_mode) { | |
1809 | foreach (keys %in) { | |
1810 | print "\$in[\"$_\"]=$in[\"$_\"]<br>\n" if $in["$_"]; | |
1811 | } | |
1812 | } | |
1813 | print "<div style=\"text-align:right;padding:1em\">$title <a href=\"$script?mode=history\" title=\"????????\">ver.$ver</a> © <a href=\"http://shade-search.com/sts/fsw/\" target=\"_blank\">hirayama</a></div>"; | |
1814 | print "</body></html>\n"; | |
1815 | } | |
1816 | ||
1817 | ||
1818 | ||
1819 | function lock() { | |
1820 | $lockfile = $_[0] if $_[0]; | |
1821 | if (!file_exists($lock_dir)) { mkdir($lock_dir); } | |
1822 | # ???????????????? | |
1823 | if (file_exists($lockfile)) { | |
1824 | local($mtime) = (stat($lockfile))[9]; | |
1825 | if ($mtime < time - 30) { &unlock; } | |
1826 | } | |
1827 | local($retry) = 5; | |
1828 | # symlink?????????? | |
1829 | if ($lockkey == 1) { | |
1830 | while (!symlink(".", $lockfile)) { | |
1831 | if (--$retry <= 0) { &error('LOCK is BUSY'); } | |
1832 | sleep(1); | |
1833 | } | |
1834 | # mkdir?????????? | |
1835 | } elseif ($lockkey == 2) { | |
1836 | while (!mkdir($lockfile, 0755)) { | |
1837 | if (--$retry <= 0) { &error('LOCK is BUSY'); } | |
1838 | sleep(1); | |
1839 | } | |
1840 | } | |
1841 | $lockflag=1; | |
1842 | } | |
1843 | ||
1844 | ||
1845 | function unlock() { | |
1846 | $lockfile = $_[0] if $_[0]; | |
1847 | if ($lockkey == 1) { unlink($lockfile); } | |
1848 | elseif ($lockkey == 2) { rmdir($lockfile); } | |
1849 | ||
1850 | $lockflag=0; | |
1851 | } | |
1852 | ||
1853 | function error() { | |
1854 | if ($lockflag) { &unlock; } | |
1855 | &header; | |
1856 | print "<div style=\"margin:1em\">\n"; | |
1857 | print "<h1>$_[0]</h1>\n"; | |
1858 | print "<h3>$_[1]</h3><p>\n"; | |
1859 | print "???????[???]????????????(IN2(B?????????????????.<p>\n"; | |
1860 | print "</div>\n"; | |
1861 | &footer; | |
1862 | exit; | |
1863 | } | |
1864 | ||
1865 | ||
1866 | ||
1867 | #------------------------------------------------- | |
1868 | # ??????(IN8(B??? | |
1869 | #------------------------------------------------- | |
1870 | function getweek() { | |
1871 | local($day,$year,$month) = $_; | |
1872 | # $year = ?; # 4?? | |
1873 | # $month = ??; # 1-12 ?? 1???1 | |
1874 | ||
1875 | if ($month == 1 || $month == 2) { | |
1876 | $year--; | |
1877 | $month += 12; | |
1878 | } | |
1879 | int ($year + int ($year/4) - int ($year/100) + int ($year/400) + int ((13*$month+8)/5) + $day) % 7; | |
1880 | } | |
1881 | ||
1882 | #--------------------------------------- | |
1883 | # ??????????????(IN?(B???????? | |
1884 | # &keyword_coloring(?????,???????????????) | |
1885 | #--------------------------------------- | |
1886 | function keyword_coloring() { | |
1887 | $key_tex_col = '#dd3000'; | |
1888 | $key_bg_col = '#F0F0D0'; | |
1889 | $ascii = '[\x00-\x7F]'; | |
1890 | $twoBytes = '[\x8E\xA1-\xFE][\xA1-\xFE]'; | |
1891 | $threeBytes = '\x8F[\xA1-\xFE][\xA1-\xFE]'; | |
1892 | list($string, $keys) = $_; | |
1893 | $string .= "\r"; | |
1894 | foreach $key ($keys) { | |
1895 | if (length $key > 1) { | |
1896 | $new_split = "<span style=\"color:$key_tex_col;background-color:$key_bg_col\">" . $key . "</span>"; | |
1897 | $string =~ s/\G((?:$ascii|$twoBytes|$threeBytes)*?)(?:$key)/$1$new_split/g; | |
1898 | } | |
1899 | } | |
1900 | chomp $string; | |
1901 | return $string; | |
1902 | } | |
1903 | ||
1904 | function url_encode() { | |
1905 | $encoded = $_[0]; | |
1906 | $encoded =~ s/([^\w ])/'%' . unpack('H2', $1)/eg; | |
1907 | $encoded =~ tr/ /+/; | |
1908 | return $encoded; | |
1909 | } | |
1910 | ||
1911 | function url_decode() { | |
1912 | $value = $_[0]; | |
1913 | $value =~ tr/+/ /; | |
1914 | $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |
1915 | return $value; | |
1916 | } | |
1917 | ||
1918 | function text_color() { | |
1919 | $base_color = $_[0]; | |
1920 | if ($_[0] !~ /#[a-zA-Z0-9]{6}/) { | |
1921 | return '#000000'; | |
1922 | } | |
1923 | $base_color =~ s/#//; | |
1924 | $r = substr($base_color,0,2); | |
1925 | $g = substr($base_color,2,2); | |
1926 | $b = substr($base_color,4,2); | |
1927 | $r_hex = hex($r); | |
1928 | $g_hex = hex($g); | |
1929 | $b_hex = hex($b); | |
1930 | $meido = $r_hex * 0.299 + $g_hex * 0.587 + $b_hex * 0.114; | |
1931 | if ($meido < 128) { | |
1932 | $txt_color = '#ffffff'; | |
1933 | } else { | |
1934 | $txt_color = '#000000'; | |
1935 | } | |
1936 | return $txt_color; | |
1937 | } | |
1938 | ||
1939 | function bright_dark() { | |
1940 | $base = $_[0]; | |
1941 | if ($base !~ /^#[0-9abcdef]{6}$/i) { | |
1942 | # $base = &color_name($base); | |
1943 | $base = '#aaaaaa' if !$base; | |
1944 | } | |
1945 | $sa = 48; | |
1946 | $base =~ s/#//; | |
1947 | $r = hex(substr($base,0,2)); | |
1948 | $g = hex(substr($base,2,2)); | |
1949 | $b = hex(substr($base,4,2)); | |
1950 | $r_b = $r + $sa; | |
1951 | if ($r_b > 255) { $r_b = 255; } | |
1952 | $g_b = $g + $sa; | |
1953 | if ($g_b > 255) { $g_b = 255; } | |
1954 | $b_b = $b + $sa; | |
1955 | if ($b_b > 255) { $b_b = 255; } | |
1956 | $r_d = $r - $sa; | |
1957 | if ($r_d < 0) { $r_d = 0; } | |
1958 | $g_d = $g - $sa; | |
1959 | if ($g_d < 0) { $g_d = 0; } | |
1960 | $b_d = $b - $sa; | |
1961 | if ($b_d < 0) { $b_d = 0; } | |
1962 | $r_b = sprintf("%02x",$r_b); | |
1963 | $g_b = sprintf("%02x",$g_b); | |
1964 | $b_b = sprintf("%02x",$b_b); | |
1965 | $r_d = sprintf("%02x",$r_d); | |
1966 | $g_d = sprintf("%02x",$g_d); | |
1967 | $b_d = sprintf("%02x",$b_d); | |
1968 | $bb = '#' . $r_b .$g_b . $b_b; | |
1969 | $dd = '#' . $r_d .$g_d . $b_d; | |
1970 | return($bb,$dd); | |
1971 | } | |
1972 | ||
1973 | ||
1974 | #--------------------------------------- | |
1975 | # ?????????????? | |
1976 | #--------------------------------------- | |
1977 | function upload() { | |
1978 | local($macbin,$fname,$flag,$upfile); | |
1979 | ||
1980 | # ???????? | |
1981 | $macbin=0; | |
1982 | foreach ($in) { | |
1983 | if (/(.*)Content-type:(.*)/i) { $tail=$2; } | |
1984 | if (/(.*)filename=\"(.*)\"/i) { $fname=$2; } | |
1985 | if (/application\/x-macbinary/i) { $macbin=1; } #" | |
1986 | } | |
1987 | $tail =~ s/\r//g; | |
1988 | $tail =~ s/\n//g; | |
1989 | ||
1990 | # ??????????????? | |
1991 | $flag=0; | |
1992 | if ($tail =~ /image\/gif/i && $gif) { $tail=".gif"; $flag=1; } | |
1993 | if ($tail =~ /image\/p?jpeg/i && $jpeg) { $tail=".jpg"; $flag=1; } | |
1994 | if ($tail =~ /image\/x-png/i && $png) { $tail=".png"; $flag=1; } | |
1995 | if ($tail =~ /text\/plain/i && $text) { $tail=".txt"; $flag=1; } | |
1996 | if ($tail =~ /lha/i && $lha) { $tail=".lzh"; $flag=1; } | |
1997 | if ($tail =~ /zip/i && $zip) { $tail=".zip"; $flag=1; } | |
1998 | if ($tail =~ /pdf/i && $pdf) { $tail=".pdf"; $flag=1; } | |
1999 | if ($tail =~ /audio\/.*mid/i && $midi) { $tail=".mid"; $flag=1; } | |
2000 | if ($tail =~ /msword/i && $word) { $tail=".doc"; $flag=1; } | |
2001 | if ($tail =~ /ms-excel/i && $excel) { $tail=".xls"; $flag=1; } | |
2002 | if ($tail =~ /ms-powerpoint/i && $ppt) { $tail=".ppt"; $flag=1; } | |
2003 | if ($tail =~ /audio\/.*realaudio/i && $ram) { $tail=".ram"; $flag=1; } | |
2004 | if ($tail =~ /application\/.*realmedia/i && $rm) { $tail=".rm"; $flag=1; } | |
2005 | if ($tail =~ /video\/.*mpeg/i && $mpeg) { $tail=".mpg"; $flag=1; } | |
2006 | if ($tail =~ /audio\/.*mpeg/i && $mp3) { $tail=".mp3"; $flag=1; } | |
2007 | if ($tail =~ /shockwave\-flash/i && $swf) { $tail=".swf"; $flag=1; } | |
2008 | ||
2009 | if (!$flag) { | |
2010 | if ($fname =~ /\.gif$/i && $gif) { $tail=".gif"; $flag=1; } | |
2011 | if ($fname =~ /\.jpe?g$/i && $jpeg) { $tail=".jpg"; $flag=1; } | |
2012 | if ($fname =~ /\.png$/i && $png) { $tail=".png"; $flag=1; } | |
2013 | if ($fname =~ /\.lzh$/i && $lha) { $tail=".lzh"; $flag=1; } | |
2014 | if ($fname =~ /\.txt$/i && $text) { $tail=".txt"; $flag=1; } | |
2015 | if ($fname =~ /\.zip$/i && $zip) { $tail=".zip"; $flag=1; } | |
2016 | if ($fname =~ /\.pdf$/i && $pdf) { $tail=".pdf"; $flag=1; } | |
2017 | if ($fname =~ /\.mid$/i && $midi) { $tail=".mid"; $flag=1; } | |
2018 | if ($fname =~ /\.doc$/i && $word) { $tail=".doc"; $flag=1; } | |
2019 | if ($fname =~ /\.xls$/i && $excel) { $tail=".xls"; $flag=1; } | |
2020 | if ($fname =~ /\.ppt$/i && $ppt) { $tail=".ppt"; $flag=1; } | |
2021 | if ($fname =~ /\.ram$/i && $ram) { $tail=".ram"; $flag=1; } | |
2022 | if ($fname =~ /\.rm$/i && $rm) { $tail=".rm"; $flag=1; } | |
2023 | if ($fname =~ /\.mpe?g$/i && $mpeg) { $tail=".mpg"; $flag=1; } | |
2024 | if ($fname =~ /\.mp3$/i && $mp3) { $tail=".mp3"; $flag=1; } | |
2025 | if ($fname =~ /\.swf$/i && $swf) { $tail=".swf"; $flag=1; } | |
2026 | } | |
2027 | ||
2028 | # ???????????????? | |
2029 | if (!$flag || !$fname) { | |
2030 | if (!$clip_err) { return; } | |
2031 | else { &error("?????????????????"); } | |
2032 | } | |
2033 | $upfile = $in['upfile']; | |
2034 | ||
2035 | # ?????(IP%(B?????(IP:(B? | |
2036 | if ($macbin) { | |
2037 | $length = substr($upfile,83,4); | |
2038 | $length = unpack("%N",$length); | |
2039 | $upfile = substr($upfile,128,$length); | |
2040 | } | |
2041 | ||
2042 | # ????????????? | |
2043 | $attach_dir = $data_dir . $in['date']; | |
2044 | if (!-d $attach_dir) { | |
2045 | mkdir($attach_dir); | |
2046 | } | |
2047 | opendir(ATT,"$attach_dir"); | |
2048 | while ($file = readdir(ATT)) { | |
2049 | next if $file === '.' || $file === '..'; | |
2050 | if ($file =~ /^(\d+)/) { | |
2051 | $no = $1; | |
2052 | $last_no = $no if $no > $last_no; | |
2053 | } | |
2054 | } | |
2055 | $no = $last_no + 1; | |
2056 | closedir(ATT); | |
2057 | if ($attach_name) { | |
2058 | $imgfile = join('/', $attach_dir, "${no}$tail"); | |
2059 | } else { | |
2060 | $tmp = split(/[\/\\]/,$fname); | |
2061 | $name = pop $tmp; | |
2062 | $head = $name; | |
2063 | $head =~ s/\..{1,4}$//; | |
2064 | $name = &url_encode($head) . $tail; # ?????(IN%(B??????????(IP1(B??????????????????????URL?????????? | |
2065 | # ?????????.??URL????????????????(IN$(B??.???????????URL??????????????????????? | |
2066 | $imgfile = join('/', $attach_dir, "$name"); | |
2067 | } | |
2068 | if (!open(OUT,"> $imgfile")) { | |
2069 | if ($clip_err) { &error("?????(IN%(B???????????????????\$imgfile=$imgfile"); } | |
2070 | } | |
2071 | binmode(OUT); | |
2072 | binmode(STDOUT); | |
2073 | print OUT $upfile; | |
2074 | close(OUT); | |
2075 | chmod(0666,$imgfile); | |
2076 | ||
2077 | # ?????????????? | |
2078 | if ($tail === ".jpg") { ($W, $H) = &j_size($imgfile); } | |
2079 | elseif ($tail === ".gif") { ($W, $H) = &g_size($imgfile); } | |
2080 | elseif ($tail === ".png") { ($W, $H) = &p_size($imgfile); } | |
2081 | ||
2082 | # ?????????? | |
2083 | if ($W > $MaxW || $H > $MaxH) { | |
2084 | $W2 = $MaxW / $W; | |
2085 | $H2 = $MaxH / $H; | |
2086 | if ($W2 < $H2) { $key = $W2; } | |
2087 | else { $key = $H2; } | |
2088 | $W = int ($W * $key) || 1; | |
2089 | $H = int ($H * $key) || 1; | |
2090 | } | |
2091 | } | |
2092 | ||
2093 | #--------------------------------------- | |
2094 | # JPEG????????? | |
2095 | #--------------------------------------- | |
2096 | function j_size() { | |
2097 | local($jpeg) = $_; | |
2098 | local($t, $m, $c, $l, $W, $H); | |
2099 | ||
2100 | open(JPEG, "$jpeg") || return (0,0); | |
2101 | binmode JPEG; | |
2102 | read(JPEG, $t, 2); | |
2103 | while (1) { | |
2104 | read(JPEG, $t, 4); | |
2105 | list($m, $c, $l) = unpack("a a n", $t); | |
2106 | ||
2107 | if ($m ne "\xFF") { $W = $H = 0; last; } | |
2108 | elseif ((ord($c) >= 0xC0) && (ord($c) <= 0xC3)) { | |
2109 | read(JPEG, $t, 5); | |
2110 | list($H, $W) = unpack("xnn", $t); | |
2111 | last; | |
2112 | } else { | |
2113 | read(JPEG, $t, ($l - 2)); | |
2114 | } | |
2115 | } | |
2116 | close(JPEG); | |
2117 | return ($W, $H); | |
2118 | } | |
2119 | ||
2120 | #--------------------------------------- | |
2121 | # GIF????????? | |
2122 | #--------------------------------------- | |
2123 | function g_size() { | |
2124 | local($gif) = $_; | |
2125 | local($data); | |
2126 | ||
2127 | open(GIF,"$gif") || return (0,0); | |
2128 | binmode(GIF); | |
2129 | sysread(GIF,$data,10); | |
2130 | close(GIF); | |
2131 | ||
2132 | if ($data =~ /^GIF/) { $data = substr($data,-4); } | |
2133 | ||
2134 | $W = unpack("v",substr($data,0,2)); | |
2135 | $H = unpack("v",substr($data,2,2)); | |
2136 | return ($W, $H); | |
2137 | } | |
2138 | ||
2139 | #--------------------------------------- | |
2140 | # PNG????????? | |
2141 | #--------------------------------------- | |
2142 | function p_size() { | |
2143 | local($png) = $_; | |
2144 | local($data); | |
2145 | ||
2146 | open(PNG, "$png") || return (0,0); | |
2147 | binmode(PNG); | |
2148 | read(PNG, $data, 24); | |
2149 | close(PNG); | |
2150 | ||
2151 | $W = unpack("N", substr($data, 16, 20)); | |
2152 | $H = unpack("N", substr($data, 20, 24)); | |
2153 | return ($W, $H); | |
2154 | } | |
2155 | ||
2156 | #--------------------------------------- | |
2157 | # BMP?????? | |
2158 | #--------------------------------------- | |
2159 | function b_size() { | |
2160 | local($png) = $_; | |
2161 | local($data); | |
2162 | ||
2163 | open(BMP, "$png") || return (0,0); | |
2164 | binmode(BMP); | |
2165 | seek(BMP, 0, 0); | |
2166 | read(BMP, $buf, 6); | |
2167 | seek(BMP, 12, 1); | |
2168 | read(BMP, $buf, 8); | |
2169 | list($W, $H) = unpack("VV", $buf); | |
2170 | ||
2171 | return ($W, $H); | |
2172 | } | |
2173 | ||
2174 | function redirect() { | |
2175 | if ($_SERVER[PERLXS] === "PerlIS") { | |
2176 | print "HTTP/1.0 302 Temporary Redirection\r\n"; | |
2177 | print "Content-type: text/html\n"; | |
2178 | } | |
2179 | print "Location: $_[0]" ."\n\n"; | |
2180 | exit; | |
2181 | } |