| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
use Jcode; |
|---|
| 36 |
require 'conf.cgi'; |
|---|
| 37 |
|
|---|
| 38 |
&get_query_string(); |
|---|
| 39 |
if ($conf{'use_cookie'}) { |
|---|
| 40 |
&get_cookie(); |
|---|
| 41 |
} |
|---|
| 42 |
$conf{'maxlog'}--; |
|---|
| 43 |
$admin_style = <<"EOM"; |
|---|
| 44 |
h1,h2 { |
|---|
| 45 |
font-size:100%; |
|---|
| 46 |
font-weight:bold; |
|---|
| 47 |
margin:0; |
|---|
| 48 |
} |
|---|
| 49 |
body { |
|---|
| 50 |
font-size:82%; |
|---|
| 51 |
padding:1%; |
|---|
| 52 |
} |
|---|
| 53 |
thead { |
|---|
| 54 |
font-weight:bold; |
|---|
| 55 |
} |
|---|
| 56 |
tbody { |
|---|
| 57 |
font-weight:normal; |
|---|
| 58 |
} |
|---|
| 59 |
td { |
|---|
| 60 |
border-width:0 0 1px 0; |
|---|
| 61 |
border-style:dotted; |
|---|
| 62 |
border-color: |
|---|
| 63 |
margin:0; |
|---|
| 64 |
word-break:break-all; |
|---|
| 65 |
} |
|---|
| 66 |
EOM |
|---|
| 67 |
$MODE = $FORM{'mode'}; |
|---|
| 68 |
$ACTION = $FORM{'action'}; |
|---|
| 69 |
$LOG_FILENAME = './log.cgi'; |
|---|
| 70 |
@LOG_FORMAT = ('status', 'number' ,'name' ,'text' ,'time' , 'host', 'referer'); |
|---|
| 71 |
$LOG_CUTSTR = '<>'; |
|---|
| 72 |
if ($MODE eq '') { |
|---|
| 73 |
$conf{'charset'} = 'sjis'; |
|---|
| 74 |
&put(&login()); |
|---|
| 75 |
exit; |
|---|
| 76 |
} |
|---|
| 77 |
&loadlog(); |
|---|
| 78 |
if ($MODE eq 'write') { |
|---|
| 79 |
&write(); |
|---|
| 80 |
if ($conf{'use_cookie'}) { |
|---|
| 81 |
print &write_finish(); |
|---|
| 82 |
} else { |
|---|
| 83 |
print "location: $conf{return_url}\n\n"; |
|---|
| 84 |
} |
|---|
| 85 |
exit; |
|---|
| 86 |
} |
|---|
| 87 |
if ($MODE eq 'logview') { |
|---|
| 88 |
$conf{'charset'} = 'sjis'; |
|---|
| 89 |
$conf{'viewline'} = $conf{'viewline_logview'}; |
|---|
| 90 |
$conf{'vieworder'} = $conf{'vieworder_logview'}; |
|---|
| 91 |
&put(&latest()); |
|---|
| 92 |
exit; |
|---|
| 93 |
} |
|---|
| 94 |
if ($MODE eq 'latest') { |
|---|
| 95 |
&put(&latest()); |
|---|
| 96 |
exit; |
|---|
| 97 |
} |
|---|
| 98 |
if ($MODE eq 'admin') { |
|---|
| 99 |
$conf{'charset'} = 'sjis'; |
|---|
| 100 |
if ($FORM{'password'} eq $conf{'password'}) { |
|---|
| 101 |
&put(&admin()); |
|---|
| 102 |
} else { |
|---|
| 103 |
&put(&login('<p style="color:#a00">�p�X���[�h���Ⴂ�܂��B</p>')); |
|---|
| 104 |
} |
|---|
| 105 |
exit; |
|---|
| 106 |
} |
|---|
| 107 |
exit; |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
sub loadlog |
|---|
| 112 |
{ |
|---|
| 113 |
my ($num, $row, $log_src, $array, $key, $value, $num_active); |
|---|
| 114 |
@LOG = (); |
|---|
| 115 |
@LOG_ALL = (); |
|---|
| 116 |
@log_src = file($LOG_FILENAME); |
|---|
| 117 |
if ($ |
|---|
| 118 |
open(OUT, "+< $LOG_FILENAME"); |
|---|
| 119 |
eval { flock(OUT, 2); }; |
|---|
| 120 |
eval { truncate(OUT, 0); }; |
|---|
| 121 |
eval { seek(OUT, 0, 0); }; |
|---|
| 122 |
for($num = 1; $num <= $ |
|---|
| 123 |
print(OUT $log_src[$num]); |
|---|
| 124 |
} |
|---|
| 125 |
close(OUT); |
|---|
| 126 |
@log_src = file($LOG_FILENAME); |
|---|
| 127 |
} |
|---|
| 128 |
@log_src = reverse(@log_src); |
|---|
| 129 |
$num_active = 0; |
|---|
| 130 |
for ($num = 0; $num <= $ |
|---|
| 131 |
my $data; |
|---|
| 132 |
$row = $log_src[$num]; |
|---|
| 133 |
@array = split(/$LOG_CUTSTR/, $row); |
|---|
| 134 |
@data = &format_hash(*LOG_FORMAT, *array); |
|---|
| 135 |
($data{'sec'} |
|---|
| 136 |
,$data{'min'} |
|---|
| 137 |
,$data{'hour'} |
|---|
| 138 |
,$data{'mday'} |
|---|
| 139 |
,$data{'mon'} |
|---|
| 140 |
,$data{'YEAR'} |
|---|
| 141 |
,$data{'wday'} |
|---|
| 142 |
,$data{'yday'} |
|---|
| 143 |
,$data{'isdst'}) = localtime($data{'time'}); |
|---|
| 144 |
$data{'YEAR'} += ($data{'YEAR'} < 1900) ? 1900 : 0; |
|---|
| 145 |
$data{'year'} = substr($data{'YEAR'}, 2); |
|---|
| 146 |
$data{'mon'} = &enforce_figure($data{'mon'} + 1, 2); |
|---|
| 147 |
$data{'mday'} = &enforce_figure($data{'mday'}, 2); |
|---|
| 148 |
$data{'hour'} = &enforce_figure($data{'hour'}, 2); |
|---|
| 149 |
$data{'min'} = &enforce_figure($data{'min'}, 2); |
|---|
| 150 |
$data{'sec'} = &enforce_figure($data{'sec'}, 2); |
|---|
| 151 |
while ( ($key, $value) = each %data) { |
|---|
| 152 |
$LOG_ALL[$num]{$key} = $value; |
|---|
| 153 |
} |
|---|
| 154 |
if ($data{'status'} == 0) { |
|---|
| 155 |
while ( ($key, $value) = each %data) { |
|---|
| 156 |
$LOG[$num_active]{$key} = $value; |
|---|
| 157 |
} |
|---|
| 158 |
$num_active++; |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
sub put |
|---|
| 164 |
{ |
|---|
| 165 |
my ($html) = @_; |
|---|
| 166 |
if ($conf{'charset'} ne "" && $conf{'charset'} ne "sjis") { |
|---|
| 167 |
Jcode::convert(\$html, $conf{'charset'}); |
|---|
| 168 |
} |
|---|
| 169 |
print $html; |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
sub latest |
|---|
| 173 |
{ |
|---|
| 174 |
my ($num, $hash_grob, $html, $contents, $option, $start, $body, $cookie); |
|---|
| 175 |
$hash_grob = ''; |
|---|
| 176 |
$contents{'navi'} = ''; |
|---|
| 177 |
$contents{'message_list'} = ''; |
|---|
| 178 |
$html = &content_type('text/html'); |
|---|
| 179 |
my $view_count = 0; |
|---|
| 180 |
$start = ( $FORM{'start'} > 0 ) ? $FORM{'start'} : 0; |
|---|
| 181 |
for ($num = $start; $num <= $ |
|---|
| 182 |
if ($conf{'autolink'}) { |
|---|
| 183 |
$LOG[$num]{'text'} = &auto_link($LOG[$num]{'text'}, $conf{'urlreplace'}, $conf{'target'}); |
|---|
| 184 |
} |
|---|
| 185 |
$hash_grob = $LOG[$num]; |
|---|
| 186 |
if ($conf{'vieworder'}) { |
|---|
| 187 |
$contents{'message_list'} = &replace_hash($hash_grob, $conf{'html_message'}) . $contents{'message_list'}; |
|---|
| 188 |
} else { |
|---|
| 189 |
$contents{'message_list'} .= &replace_hash($hash_grob, $conf{'html_message'}); |
|---|
| 190 |
} |
|---|
| 191 |
$view_count++; |
|---|
| 192 |
if ($view_count == $conf{'viewline'}) { |
|---|
| 193 |
if ($num < $ |
|---|
| 194 |
$option{'start'} = $FORM{'start'} + $conf{'viewline_logview'}; |
|---|
| 195 |
$contents{'navi'} = $conf{'html_navi'}; |
|---|
| 196 |
$contents{'navi'} = &replace_hash(*conf, $contents{'navi'}); |
|---|
| 197 |
$contents{'navi'} = &replace_hash(*option, $contents{'navi'}); |
|---|
| 198 |
} |
|---|
| 199 |
$num = $ |
|---|
| 200 |
} |
|---|
| 201 |
} |
|---|
| 202 |
$cookie{'cname'} = $COOKIE{'cc1linebbsv2_name'}; |
|---|
| 203 |
if ($MODE eq 'logview') { |
|---|
| 204 |
$body{'body'} = $conf{'html_body'}; |
|---|
| 205 |
$body{'body'} = &replace_hash(*conf , $body{'body'}); |
|---|
| 206 |
$body{'body'} = &replace_hash(*cookie , $body{'body'}); |
|---|
| 207 |
$body{'body'} = &replace_hash(*contents, $body{'body'}); |
|---|
| 208 |
$html .= $conf{'html_logview'}; |
|---|
| 209 |
$html = &replace_hash(*body, $html); |
|---|
| 210 |
$html = &replace_hash(*conf, $html); |
|---|
| 211 |
} else { |
|---|
| 212 |
$html .= $conf{'html_body'}; |
|---|
| 213 |
$html = &replace_hash(*conf, $html); |
|---|
| 214 |
$html = &replace_hash(*cookie , $html); |
|---|
| 215 |
$html = &replace_hash(*contents, $html); |
|---|
| 216 |
} |
|---|
| 217 |
return($html); |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
sub write |
|---|
| 221 |
{ |
|---|
| 222 |
my (@data, $wdata, $first, $row); |
|---|
| 223 |
$wdata = ''; |
|---|
| 224 |
$first = 1; |
|---|
| 225 |
$data{'number'} = &select_max(*LOG_ALL, 'number') + 1; |
|---|
| 226 |
$data{'name'} = &real_html($FORM{'name'}); |
|---|
| 227 |
$data{'text'} = &real_html($FORM{'text'}); |
|---|
| 228 |
$data{'time'} = &gettime($conf{'timediff'}); |
|---|
| 229 |
$data{'status'} = 0; |
|---|
| 230 |
$data{'host'} = ($ENV{'REMOTE_HOST'} ne '') ? $ENV{'REMOTE_HOST'} : $ENV{'REMOTE_ADDR'}; |
|---|
| 231 |
$data{'referer'} = $ENV{'HTTP_REFERER'}; |
|---|
| 232 |
if ($data{'name'} eq "") { |
|---|
| 233 |
&error('���O��������܂���); |
|---|
| 234 |
exit; |
|---|
| 235 |
} |
|---|
| 236 |
if ($data{'text'} eq "") { |
|---|
| 237 |
&error('���b�Z�[�W��������܂���); |
|---|
| 238 |
exit; |
|---|
| 239 |
} |
|---|
| 240 |
if (length($data{'name'} . $data{'text'}) > $conf{'maxlength'}) { |
|---|
| 241 |
&error('��\�ȍő������́A���O�ƃ��b�Z�[�W�� . $conf{'maxlength'} . '�o�C�g�܂łł��B'); |
|---|
| 242 |
exit; |
|---|
| 243 |
} |
|---|
| 244 |
if ((time() - (stat($LOG_FILENAME))[9]) <= $conf{'stoptime'}) { |
|---|
| 245 |
&error($conf{'stoptime'} . '�b�ȓ��A���������݂͋֎~�������܂��B'); |
|---|
| 246 |
exit; |
|---|
| 247 |
} |
|---|
| 248 |
foreach $row (@LOG_FORMAT) { |
|---|
| 249 |
$wdata .= ($first != 1) ? $LOG_CUTSTR : ''; |
|---|
| 250 |
$wdata .= $data{$row}; |
|---|
| 251 |
$first = 0; |
|---|
| 252 |
} |
|---|
| 253 |
open(OUT, ">> $LOG_FILENAME"); |
|---|
| 254 |
eval { flock(OUT, 2); }; |
|---|
| 255 |
print(OUT "$wdata\n"); |
|---|
| 256 |
close(OUT); |
|---|
| 257 |
if ($conf{'use_cookie'}) { |
|---|
| 258 |
&set_cookie(key => 'cc1linebbsv2_name', value => $data{name}, expires => 'Thu, 28 Jan 2079 23:59:59 +0900', domain => '', path => '/'); |
|---|
| 259 |
} |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
sub write_finish |
|---|
| 263 |
{ |
|---|
| 264 |
my $html; |
|---|
| 265 |
$html = &content_type('text/html'); |
|---|
| 266 |
$html .= $conf{'html_write_finish'}; |
|---|
| 267 |
$html = &replace_hash(*conf, $html); |
|---|
| 268 |
return $html; |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
sub login |
|---|
| 272 |
{ |
|---|
| 273 |
my ($message) = @_; |
|---|
| 274 |
my ($html); |
|---|
| 275 |
if ($conf{'password'} eq '') { |
|---|
| 276 |
$message .= '<p><strong style="color:#a00">�y�x���z</strong>�p�X���[�h���ݒ肳�����܂���onf.cgi��W���ăp�X���[�h��肵�Ă��������B�i���̂܂܃{�^��������O�C���͏o���܂��j</p>'; |
|---|
| 277 |
} |
|---|
| 278 |
$html = &content_type('text/html'); |
|---|
| 279 |
$html .= &html_header($conf{'title'}.' �Ǘ����O�C��',$admin_style); |
|---|
| 280 |
$html .= <<"EOM"; |
|---|
| 281 |
<h1>$conf{'title'} �Ǘ����O�C��</h1> |
|---|
| 282 |
<hr> |
|---|
| 283 |
<form action="$conf{'cgi'}" method="post" name="login"> |
|---|
| 284 |
$message |
|---|
| 285 |
<p>Password:<input type="password" size="9" name="password"><input type="hidden" name="mode" value="admin"> <input type="submit" name="submit" value="���O�C��"></p> |
|---|
| 286 |
</form> |
|---|
| 287 |
<hr> |
|---|
| 288 |
<p style="text-align:right"><a href="$conf{'cgi'}?mode=logview">logview</a> / Script made by <a href="http://www.akiyan.com/">�~�ϑ���l</a></p> |
|---|
| 289 |
</body> |
|---|
| 290 |
</html> |
|---|
| 291 |
EOM |
|---|
| 292 |
return($html); |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
sub admin |
|---|
| 296 |
{ |
|---|
| 297 |
my ($html, $contents, $num, $hash_grob, $wdata, $start, $nextstart); |
|---|
| 298 |
if (($ACTION eq 'delete' || $ACTION eq 'revival') && $FORM{'number'} ne '') { |
|---|
| 299 |
open(OUT, "+< $LOG_FILENAME"); |
|---|
| 300 |
eval { flock(OUT, 2); }; |
|---|
| 301 |
eval { truncate(OUT, 0); }; |
|---|
| 302 |
eval { seek(OUT, 0, 0); }; |
|---|
| 303 |
for ($num = $#LOG_ALL ;$num >= 0; $num--) { |
|---|
| 304 |
if($LOG_ALL[$num]{'number'} eq $FORM{'number'}) { |
|---|
| 305 |
if ($ACTION eq 'delete') { |
|---|
| 306 |
$LOG_ALL[$num]{'status'} = 1; |
|---|
| 307 |
} else { |
|---|
| 308 |
$LOG_ALL[$num]{'status'} = 0; |
|---|
| 309 |
} |
|---|
| 310 |
} |
|---|
| 311 |
$first = 1; |
|---|
| 312 |
$wdata = ''; |
|---|
| 313 |
foreach $row (@LOG_FORMAT) { |
|---|
| 314 |
$wdata .= ($first != 1) ? $LOG_CUTSTR : ''; |
|---|
| 315 |
$wdata .= $LOG_ALL[$num]{$row}; |
|---|
| 316 |
$first = 0; |
|---|
| 317 |
} |
|---|
| 318 |
print(OUT "$wdata"); |
|---|
| 319 |
} |
|---|
| 320 |
close(OUT); |
|---|
| 321 |
&loadlog(); |
|---|
| 322 |
} |
|---|
| 323 |
$html = &content_type('text/html'); |
|---|
| 324 |
$html .= &html_header($conf{'title'}.' �Ǘ�', $admin_style); |
|---|
| 325 |
$contents{'message_list'} = ''; |
|---|
| 326 |
my $view_count = 0; |
|---|
| 327 |
$start = ( $FORM{'start'} > 0 ) ? $FORM{'start'} : 0; |
|---|
| 328 |
for ($num = $start; $num <= $#LOG; $num++) { |
|---|
| 329 |
$hash_grob = $LOG[$num]; |
|---|
| 330 |
$contents{'message_list'} .= &replace_hash($hash_grob, "<tr><td>{number}</td><td>{name}</td><td>{text}</td><td>{YEAR}/{mon}/{mday} {hour}:{min}</td><td>{host}�@</td></tr>"); |
|---|
| 331 |
$view_count++; |
|---|
| 332 |
if ($view_count == $conf{'viewline_logview'}) { |
|---|
| 333 |
if ($num < $#LOG) { |
|---|
| 334 |
$nextstart = $start + $conf{'viewline_logview'}; |
|---|
| 335 |
$contents{'navi'} = <<"EOM"; |
|---|
| 336 |
<form action="$conf{'cgi'}" name="next" method="post"> |
|---|
| 337 |
<p><input type="hidden" name="mode" value="admin"><input type="hidden" name="start" value="$nextstart"><input type="hidden" name="password" value="$conf{'password'}"><input type="submit" name="submit" value="next"></p> |
|---|
| 338 |
</form> |
|---|
| 339 |
EOM |
|---|
| 340 |
} |
|---|
| 341 |
$num = $#LOG; |
|---|
| 342 |
} |
|---|
| 343 |
} |
|---|
| 344 |
$html .= <<"EOM"; |
|---|
| 345 |
<h1>$conf{'title'} �Ǘ�</h1> |
|---|
| 346 |
<hr> |
|---|
| 347 |
<table border="0" style="width:100%"> |
|---|
| 348 |
<thead> |
|---|
| 349 |
<tr><td style="width:4ex">No.</td><td style="width:16ex">Name</td><td>Message</td><td style="width:18ex">Timestamp</td><td style="width:20ex">Host</td></tr> |
|---|
| 350 |
</thead> |
|---|
| 351 |
<tbody> |
|---|
| 352 |
$contents{'message_list'} |
|---|
| 353 |
<tbody> |
|---|
| 354 |
</table> |
|---|
| 355 |
$contents{'navi'} |
|---|
| 356 |
<div style="text-align:right;margin-top:1em"> |
|---|
| 357 |
<form action="$conf{'cgi'}" method="post" name="ob" style="display:inline"> |
|---|
| 358 |
Name:<input type="text" name="name" size="8"> |
|---|
| 359 |
Message:<input type="text" name="text" size="40"><input type="submit" value="write"> |
|---|
| 360 |
<input type="hidden" name="mode" value="write"> |
|---|
| 361 |
</form> |
|---|
| 362 |
<form action="$conf{'cgi'}" name="delete" method="post" style="display:inline;margin-left:1em"> |
|---|
| 363 |
<input type="hidden" name="mode" value="admin"><input type="hidden" name="action" value="delete"><input type="hidden" name="password" value="$conf{'password'}">Delete No.<input type="text" name="number" size="4"><input type="submit" name="submit" value="delete"> |
|---|
| 364 |
</form> |
|---|
| 365 |
<form action="$conf{'cgi'}" name="revival" method="post" style="display:inline;margin-left:1em"> |
|---|
| 366 |
<input type="hidden" name="mode" value="admin"><input type="hidden" name="action" value="revival"><input type="hidden" name="password" value="$conf{'password'}">Revival No.<input type="text" name="number" size="4"><input type="submit" name="submit" value="Revival"> |
|---|
| 367 |
</form> |
|---|
| 368 |
</div> |
|---|
| 369 |
<hr> |
|---|
| 370 |
<p style="text-align:right"><a href="$conf{'cgi'}?mode=logview">logview</a> / Script made by <a href="http://www.akiyan.com/">�~�ϑ���l</a></p> |
|---|
| 371 |
</body> |
|---|
| 372 |
</html> |
|---|
| 373 |
EOM |
|---|
| 374 |
return($html); |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
sub error |
|---|
| 378 |
{ |
|---|
| 379 |
my ($message) = @_; |
|---|
| 380 |
my $html; |
|---|
| 381 |
$html = &content_type('text/html'); |
|---|
| 382 |
$html .= &html_header($conf{'title'} . ' �G���[', $admin_style); |
|---|
| 383 |
$html .= <<"EOM"; |
|---|
| 384 |
<h1>$conf{'title'} �G���[</h1> |
|---|
| 385 |
<hr> |
|---|
| 386 |
<p style="color:#a00">$message</p> |
|---|
| 387 |
<p><a href="$conf{'return_url'}">Return</a></p> |
|---|
| 388 |
<hr> |
|---|
| 389 |
EOM |
|---|
| 390 |
$html .= &html_futter(); |
|---|
| 391 |
&put($html); |
|---|
| 392 |
exit; |
|---|
| 393 |
} |
|---|
| 394 |
|
|---|
| 395 |
#____�T�u���[�`���Q |
|---|
| 396 |
|
|---|
| 397 |
### |
|---|
| 398 |
# �N�G���[������ǂݍ��� |
|---|
| 399 |
# |
|---|
| 400 |
# @return void |
|---|
| 401 |
# |
|---|
| 402 |
sub get_query_string |
|---|
| 403 |
{ |
|---|
| 404 |
my ($conv) = @_; |
|---|
| 405 |
my ($a, $name, $value, $query_string); |
|---|
| 406 |
if ($ENV{'REQUEST_METHOD'} eq "POST") { |
|---|
| 407 |
read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); |
|---|
| 408 |
} else { |
|---|
| 409 |
$query_string = $ENV{'QUERY_STRING'}; |
|---|
| 410 |
} |
|---|
| 411 |
@a = split(/\&/, $query_string); |
|---|
| 412 |
foreach $a (@a) { |
|---|
| 413 |
($name, $value) = split(/=/, $a); |
|---|
| 414 |
$value =~ tr/+/ /; |
|---|
| 415 |
$value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg; |
|---|
| 416 |
if ( $conv ne "" ) { |
|---|
| 417 |
Jcode::convert(\$value,$conv); |
|---|
| 418 |
} |
|---|
| 419 |
$FORM{$name} = $value; |
|---|
| 420 |
} |
|---|
| 421 |
} |
|---|
| 422 |
|
|---|
| 423 |
### |
|---|
| 424 |
# �N�b�L�[��ݍ��� |
|---|
| 425 |
# |
|---|
| 426 |
# @return void |
|---|
| 427 |
# |
|---|
| 428 |
sub get_cookie { |
|---|
| 429 |
my ($row, $name, $value); |
|---|
| 430 |
foreach $row (split(/; */, $ENV{'HTTP_COOKIE'})) { |
|---|
| 431 |
($name, $value) = split(/=/, $row); |
|---|
| 432 |
$value =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg; |
|---|
| 433 |
$COOKIE{$name} = $value; |
|---|
| 434 |
} |
|---|
| 435 |
} |
|---|
| 436 |
|
|---|
| 437 |
### |
|---|
| 438 |
# �N�b�L�[��b�g����# @param hash string key => �L�[�� |
|---|
| 439 |
# string value => �l |
|---|
| 440 |
# string expires => �L��(RFC2822) |
|---|
| 441 |
# string path => �p�X |
|---|
| 442 |
# |
|---|
| 443 |
sub set_cookie |
|---|
| 444 |
{ |
|---|
| 445 |
my %arg = @_; |
|---|
| 446 |
$arg{'value'} = &urlencode($arg{'value'}); |
|---|
| 447 |
print "Set-cookie: $arg{key}=$arg{value}; expires=$arg{expires}; path=$arg{path}\n"; |
|---|
| 448 |
} |
|---|
| 449 |
|
|---|
| 450 |
### |
|---|
| 451 |
# content-type�w�b�_ |
|---|
| 452 |
# @param string |
|---|
| 453 |
# |
|---|
| 454 |
# @return string |
|---|
| 455 |
# |
|---|
| 456 |
sub content_type |
|---|
| 457 |
{ |
|---|
| 458 |
if ($_content_type_printed) { |
|---|
| 459 |
return(""); |
|---|
| 460 |
} |
|---|
| 461 |
$_content_type_printed = 1; |
|---|
| 462 |
return("Content-type: $_[0]\n\n"); |
|---|
| 463 |
} |
|---|
| 464 |
|
|---|
| 465 |
### |
|---|
| 466 |
# HTML�w�b�_ |
|---|
| 467 |
# |
|---|
| 468 |
# @return string |
|---|
| 469 |
# |
|---|
| 470 |
sub html_header |
|---|
| 471 |
{ |
|---|
| 472 |
my ($title,$style) = @_; |
|---|
| 473 |
return <<"EOM"; |
|---|
| 474 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|---|
| 475 |
<html lang="ja"> |
|---|
| 476 |
<head> |
|---|
| 477 |
<meta http-equiv="content-type" content="text/html; charset=shift_jis"> |
|---|
| 478 |
<meta http-equiv="content-style-type" content="text/css"> |
|---|
| 479 |
<style type="text/css"> |
|---|
| 480 |
$style |
|---|
| 481 |
</style> |
|---|
| 482 |
<title>$title</title> |
|---|
| 483 |
</head> |
|---|
| 484 |
<body> |
|---|
| 485 |
EOM |
|---|
| 486 |
} |
|---|
| 487 |
|
|---|
| 488 |
### |
|---|
| 489 |
# HTML�t�b�^ |
|---|
| 490 |
# |
|---|
| 491 |
# @return string |
|---|
| 492 |
# |
|---|
| 493 |
sub html_futter |
|---|
| 494 |
{ |
|---|
| 495 |
return <<"EOM"; |
|---|
| 496 |
</body> |
|---|
| 497 |
</html> |
|---|
| 498 |
EOM |
|---|
| 499 |
} |
|---|
| 500 |
|
|---|
| 501 |
### |
|---|
| 502 |
# {}�Ɉ͂܂ꂽ�L�[��b�V���Œu�� |
|---|
| 503 |
# |
|---|
| 504 |
# @param *hash �u�������[�ƒl |
|---|
| 505 |
# @param string �u���Ώ� |
|---|
| 506 |
# |
|---|
| 507 |
# @return string �u���ς̑Ώ� |
|---|
| 508 |
# |
|---|
| 509 |
sub replace_hash |
|---|
| 510 |
{ |
|---|
| 511 |
my ($hash, $body, $key, $value); |
|---|
| 512 |
(*hash, $body) = @_; |
|---|
| 513 |
while ( ($key, $value) = each %hash) { |
|---|
| 514 |
$body =~ s/\{$key\}/$value/g; |
|---|
| 515 |
} |
|---|
| 516 |
return($body); |
|---|
| 517 |
} |
|---|
| 518 |
|
|---|
| 519 |
### |
|---|
| 520 |
# �t�@�C����ݍ���z��i�[ |
|---|
| 521 |
# @param string �t�@�C���� |
|---|
| 522 |
# |
|---|
| 523 |
# @return array �t�@�C���� |
|---|
| 524 |
# |
|---|
| 525 |
sub file |
|---|
| 526 |
{ |
|---|
| 527 |
my ($filename) = @_; |
|---|
| 528 |
my ($row, @data); |
|---|
| 529 |
if(!open(IN, "< $filename")) { |
|---|
| 530 |
print &content_type('text/html'); |
|---|
| 531 |
print "file does not open '$filename'"; |
|---|
| 532 |
exit; |
|---|
| 533 |
} |
|---|
| 534 |
eval { flock(IN, 1); }; |
|---|
| 535 |
@data = <IN>; |
|---|
| 536 |
eval { flock(IN, 8); }; |
|---|
| 537 |
close(IN); |
|---|
| 538 |
return(@data); |
|---|
| 539 |
} |
|---|
| 540 |
|
|---|
| 541 |
### |
|---|
| 542 |
# ����[�Ƃ��A����Ƃ��ăn�b�V����� |
|---|
| 543 |
# @param *array ���O |
|---|
| 544 |
# @param *array �l |
|---|
| 545 |
# |
|---|
| 546 |
# @return hash |
|---|
| 547 |
# |
|---|
| 548 |
sub format_hash |
|---|
| 549 |
{ |
|---|
| 550 |
my ($key, $value, $num, @data); |
|---|
| 551 |
(*key, *value) = @_; |
|---|
| 552 |
for ($num = 0; $num <= $#key; $num++) { |
|---|
| 553 |
$data{$key[$num]} = $value[$num]; |
|---|
| 554 |
} |
|---|
| 555 |
return(@data); |
|---|
| 556 |
} |
|---|
| 557 |
|
|---|
| 558 |
sub enforce_figure |
|---|
| 559 |
{ |
|---|
| 560 |
my ($string, $figure) = @_; |
|---|
| 561 |
return(substr('0000000000000000' . $string, 16 + length($string) - $figure, $figure)); |
|---|
| 562 |
} |
|---|
| 563 |
|
|---|
| 564 |
### |
|---|
| 565 |
# �n�b�V���̔z�����t�B�[���h��������# @param *hash_array �n�b�V���̔z�� @param string �I����B�[���h�� |
|---|
| 566 |
# |
|---|
| 567 |
# @return int �ő� |
|---|
| 568 |
# |
|---|
| 569 |
sub select_max |
|---|
| 570 |
{ |
|---|
| 571 |
my ($data, $name, $max_num); |
|---|
| 572 |
(*data, $name) = @_; |
|---|
| 573 |
($num, $max_num) = (0, 0); |
|---|
| 574 |
for ($num = 0; $num <= $#data; $num++) { |
|---|
| 575 |
$max_num = ($data[$num]{$name} > $max_num) ? $data[$num]{$name} : $max_num; |
|---|
| 576 |
} |
|---|
| 577 |
return $max_num; |
|---|
| 578 |
} |
|---|
| 579 |
|
|---|
| 580 |
### |
|---|
| 581 |
# ���݂̎������ |
|---|
| 582 |
# @param int ���� |
|---|
| 583 |
# |
|---|
| 584 |
# @return int |
|---|
| 585 |
# |
|---|
| 586 |
sub gettime |
|---|
| 587 |
{ |
|---|
| 588 |
my ($timediff) = @_; |
|---|
| 589 |
return(time() + $timediff); |
|---|
| 590 |
} |
|---|
| 591 |
|
|---|
| 592 |
### |
|---|
| 593 |
# ��ԎQ�Ƃɒu�� |
|---|
| 594 |
# @param string |
|---|
| 595 |
# |
|---|
| 596 |
# @return string |
|---|
| 597 |
# |
|---|
| 598 |
sub real_html |
|---|
| 599 |
{ |
|---|
| 600 |
my ($html) = @_; |
|---|
| 601 |
$html =~ s/&/&\;/g; |
|---|
| 602 |
$html =~ s/"/"\;/g; |
|---|
| 603 |
$html =~ s/\</<\;/g; |
|---|
| 604 |
$html =~ s/\>/>\;/g; |
|---|
| 605 |
return($html); |
|---|
| 606 |
} |
|---|
| 607 |
|
|---|
| 608 |
### |
|---|
| 609 |
# URL�G���R�[�h |
|---|
| 610 |
# @param string |
|---|
| 611 |
# |
|---|
| 612 |
# @return string |
|---|
| 613 |
# |
|---|
| 614 |
sub urlencode |
|---|
| 615 |
{ |
|---|
| 616 |
my ($str) = @_; |
|---|
| 617 |
$str =~ s/([^0-9A-Za-z_ ])/'%'.unpack('H2',$1)/ge; |
|---|
| 618 |
$str =~ s/\s/+/g; |
|---|
| 619 |
return $str; |
|---|
| 620 |
} |
|---|
| 621 |
|
|---|
| 622 |
### |
|---|
| 623 |
# �ϐ���t/html�ŏo�͂���# @param mixed |
|---|
| 624 |
# |
|---|
| 625 |
# @return void |
|---|
| 626 |
# |
|---|
| 627 |
sub var_dump |
|---|
| 628 |
{ |
|---|
| 629 |
my ($var) = @_; |
|---|
| 630 |
print &content_type('text/html'); |
|---|
| 631 |
print $var . "\n"; |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
### |
|---|
| 635 |
# URL�̎��������N |
|---|
| 636 |
# @param string ���������N���镶���� @param string �u���������� |
|---|
| 637 |
# @return string a href���t����ꂽ������ |
|---|
| 638 |
sub auto_link { |
|---|
| 639 |
my ($html, $replace_word, $target) = @_; |
|---|
| 640 |
if ($target ne '') { |
|---|
| 641 |
$target = " target=\"$target\""; |
|---|
| 642 |
} |
|---|
| 643 |
if ($replace_word ne "") { |
|---|
| 644 |
$html =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" title=\"$2\"$target>$replace_word<\/a>/g; |
|---|
| 645 |
} else { |
|---|
| 646 |
$html =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\"$target>$2<\/a>/g; |
|---|
| 647 |
} |
|---|
| 648 |
return($html); |
|---|
| 649 |
} |
|---|
| 650 |
|
|---|