-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheljssave.cgi
175 lines (139 loc) · 3.85 KB
/
eljssave.cgi
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env perl -w
# 2011-02-21
# 2006-04-05
# 2006-04-02
# --------------------------------------------------------------------
# config
$cfg_me = 'eljssave.cgi'; # this script's name
$cfg_logdir = 'eljssave'; # path to log file
$cfg_logfile = 'log.txt'; # log file name
$cfg_index = 'index.html'; # path to index file
$cfg_eellljs = './eellljs.html'; # path to eellljs file
$cfg_derault_css= 'css/default.css'; # path to defualt stylesheet
$cfg_eljs_css = 'css/eljs.css'; # path to eljs stylesheet
$cfg_charset = "utf-8"; # charset for RESULT OUTPUT (not log!)
# --------------------------------------------------------------------
# utils
sub puts { print(join('', @_) . "\n"); }
sub escapeHTML($) {
my $s = shift;
$s =~ s/&/&/g;
$s =~ s/</</g;
$s =~ s/>/>/g;
$s =~ s/\"/"/g;
$s =~ s/\f/^L/g;
return $s;
}
# --------------------------------------------------------------------
# global vars and constants
$gcgi = '';
$c_link_to_logfile = <<"EOF";
<a href="$cfg_logdir/$cfg_logfile"
type="text/plain" hreflang="ja" charset="utf-8"
>$cfg_logdir/$cfg_logfile</a>
EOF
$c_success0 = "<p>$cfg_me succeeded.</p>";
$c_success1 = "<p>次の内容を $c_link_to_logfile に保存しました。</p>";
$c_failure0 = "<p>$cfg_me failed.</p>";
$c_failure1 =
"<p>次の内容を $c_link_to_logfile に保存しようとしました" .
"<br>…が、<strong>失敗しました</strong>。</p>";
$menu = <<"EOF";
<div class="menu">
[
<a href="$cfg_index">もくじにもどる</a>
|
<a href="$cfg_eellljs">eelll/JS にもどる</a>
]
</div>
EOF
# --------------------------------------------------------------------
# init
umask(0000);
use CGI;
$gcgi = new CGI;
$geljs = $gcgi->param('eljs');
$guser = $gcgi->param('user');
$gdate = $gcgi->param('date');
$glog = $gcgi->param('log');
# --------------------------------------------------------------------
# prototypes
sub mk_html($);
sub mk_data();
# --------------------------------------------------------------------
# main(?)
$gdata = &mk_data();
$gdata =~ s/\r\n/\n/g; # CR/LF => LF
if (open(F, ">>$cfg_logdir/$cfg_logfile")) {
print F $gdata;
close(F);
print &mk_html(1);
} else {
print &mk_html(0);
}
exit 0;
# --------------------------------------------------------------------
sub mk_data() {
return <<"EOF";
eljs: $geljs
user: $guser
date: $gdate
$glog
\f
EOF
}
# --------------------------------------------------------------------
sub mk_html($) { # $ : 1 (success) or 0 (error)
my $success = shift;
my $msg0;
my $msg1;
my $data_escaped = escapeHTML($gdata);
if ($success) {
$msg0 = $c_success0;
$msg1 = $c_success1;
} else {
$msg0 = $c_failure0;
$msg1 = $c_failure1;
}
return <<"EOF";
Content-Type: text/html; charset=$cfg_charset
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=$cfg_charset">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>eljssave</title>
<link rel="stylesheet" href="$cfg_derault_css">
<link rel="stylesheet" href="$cfg_eljs_css">
</head>
<body class="eljs">
<div class="container">
<h1><a name="top">eljssave</a></h1>
$menu
<hr>
$msg0
<hr>
$msg1
<textarea cols="80" rows="20" readonly>$data_escaped</textarea>
<hr>
$menu
<div class="version">
eljssave.cgi version <!-- version -->0.2.3<!-- /version -->
<!-- time-stamp-start -->2011-02-21 yuse<!-- time-stamp-end -->
</div>
</div>
</html>
<!-- ============================================================= -->
<!--
:: Local Variables:
:: time-stamp-line-limit: -20
:: time-stamp-start: "<!-\\- *time-stamp-start *-\\-."
:: time-stamp-end: "<!-\\- *time-stamp-end *-\\-."
:: time-stamp-format: "%:y-%02m-%02d %u"
:: End:
-->
</body>
EOF
}