1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use warnings; |
4 |
|
|
use CGI::Carp qw/fatalsToBrowser/; |
5 |
|
|
|
6 |
|
|
use lib qw[/home/wakaba/work/manakai2/lib]; |
7 |
|
|
|
8 |
|
|
use Message::CGI::Util qw/htescape/; |
9 |
|
|
|
10 |
|
|
require Message::CGI::HTTP; |
11 |
|
|
my $cgi = Message::CGI::HTTP->new; |
12 |
|
|
$cgi->{decoder}->{'#default'} = sub { |
13 |
|
|
return Encode::decode ('utf-8', $_[1]); |
14 |
|
|
}; |
15 |
|
|
|
16 |
|
|
my $input = my $input_orig = $cgi->get_parameter ('s'); |
17 |
|
|
my $charset = $cgi->get_parameter ('c') || 'utf-8'; |
18 |
|
|
$input = Encode::encode ($charset, $input); |
19 |
wakaba |
1.2 |
$input =~ s/\x0D\x0A/\x0A/g; |
20 |
|
|
$input =~ tr/\x0D/\x0A/; |
21 |
wakaba |
1.1 |
|
22 |
|
|
print "Content-Type: text/html; charset=utf-8\n\n"; |
23 |
|
|
|
24 |
|
|
my $output = ''; |
25 |
|
|
if (length $input) { |
26 |
|
|
require Template; |
27 |
|
|
my $template = Template->new ({ |
28 |
|
|
INCLUDE_PATH => '/tmp/no-such-directory/', |
29 |
|
|
}); |
30 |
|
|
$template->process (\$input, {}, \$output) or $output = $template->error; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
print qq[<!DOCTYPE HTML> |
34 |
|
|
<html lang=en> |
35 |
|
|
<title>TT Viewer</title> |
36 |
|
|
<link rel=stylesheet href="/www/style/html/xhtml"> |
37 |
|
|
<style> |
38 |
|
|
p { |
39 |
|
|
text-indent: 0 !important; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
textarea { |
43 |
|
|
height: 10em; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
textarea#result { |
47 |
|
|
height: 30em; |
48 |
|
|
} |
49 |
|
|
</style> |
50 |
|
|
|
51 |
|
|
<form action=live method=get accept-charset=utf-8> |
52 |
|
|
|
53 |
|
|
<p><textarea name=s>@{[htescape $input_orig]}</textarea> |
54 |
|
|
|
55 |
|
|
<button type=submit>Process</button></p> |
56 |
|
|
</form> |
57 |
|
|
|
58 |
|
|
<h2>Result</h2> |
59 |
|
|
|
60 |
|
|
<textarea id=result> |
61 |
|
|
Input: |
62 |
|
|
[PRE(code)[ |
63 |
|
|
@{[htescape $input]} |
64 |
|
|
]PRE] |
65 |
|
|
|
66 |
|
|
Result: |
67 |
|
|
[PRE(code)[ |
68 |
|
|
@{[htescape $output]} |
69 |
|
|
]PRE] |
70 |
|
|
|
71 |
|
|
</textarea> |
72 |
|
|
<script> |
73 |
|
|
document.getElementById ('result').value += ';; <' + location.href + '>\\n'; |
74 |
|
|
</script> |
75 |
|
|
|
76 |
|
|
]; |
77 |
|
|
|
78 |
|
|
|