Skip to content

Commit 2c109ef

Browse files
committed
feat: add report10
1 parent 2de5be6 commit 2c109ef

File tree

6 files changed

+234
-2
lines changed

6 files changed

+234
-2
lines changed

report10/cal-output

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
azalea11% echo $LANG
2+
ja_JP.UTF-8
3+
azalea11% export REQUEST_METHOD=GET
4+
azalea11% export QUERY_STRING='year=2024&month=8'
5+
azalea11% ./cgi-cal.rb # 正しいパラメタの例 1
6+
Content-Type: text/html
7+
8+
<HTML><HEAD></HEAD><BODY><PRE>
9+
8月 2024
10+
日 月 火 水 木 金 土
11+
1 2 3
12+
4 5 6 7 8 9 10
13+
11 12 13 14 15 16 17
14+
18 19 20 21 22 23 24
15+
25 26 27 28 29 30 31
16+
17+
</PRE></BODY></HTML>
18+
azalea11% export QUERY_STRING='year=2023&month=8'
19+
azalea11% ./cgi-cal.rb # 正しいパラメタの例 2
20+
Content-Type: text/html
21+
22+
<HTML><HEAD></HEAD><BODY><PRE>
23+
8月 2023
24+
日 月 火 水 木 金 土
25+
1 2 3 4 5
26+
6 7 8 9 10 11 12
27+
13 14 15 16 17 18 19
28+
20 21 22 23 24 25 26
29+
27 28 29 30 31
30+
31+
</PRE></BODY></HTML>
32+
azalea11% export QUERY_STRING=''
33+
azalea11% ./cgi-cal.rb # 不適切なパラメタの例 1
34+
Content-Type: text/html
35+
36+
<HTML><HEAD></HEAD><BODY><PRE>
37+
Parameter 'year' is required but empty.
38+
Parameter 'month' is required but empty.
39+
</PRE></BODY></HTML>
40+
azalea11% export QUERY_STRING='year=2023'
41+
azalea11% ./cgi-cal.rb # 不適切なパラメタの例 2
42+
Content-Type: text/html
43+
44+
<HTML><HEAD></HEAD><BODY><PRE>
45+
Parameter 'month' is required but empty.
46+
</PRE></BODY></HTML>
47+
azalea11% export QUERY_STRING='month=8'
48+
azalea11% ./cgi-cal.rb # 不適切なパラメタの例 3
49+
Content-Type: text/html
50+
51+
<HTML><HEAD></HEAD><BODY><PRE>
52+
Parameter 'year' is required but empty.
53+
</PRE></BODY></HTML>
54+
azalea11% export QUERY_STRING='year=2023&month=13'
55+
azalea11% ./cgi-cal.rb # 不適切なパラメタの例 4
56+
Content-Type: text/html
57+
58+
<HTML><HEAD></HEAD><BODY><PRE>
59+
Invalid value.
60+
</PRE></BODY></HTML>
61+
azalea11% export QUERY_STRING='year=2023&month=aaa'
62+
azalea11% ./cgi-cal.rb # 不適切なパラメタの例 5
63+
Content-Type: text/html
64+
65+
<HTML><HEAD></HEAD><BODY><PRE>
66+
Invalid value.
67+
</PRE></BODY></HTML>
68+
azalea11% export QUERY_STRING='year=0&month=8'
69+
azalea11% ./cgi-cal.rb # 不適切なパラメタの例 6
70+
Content-Type: text/html
71+
72+
<HTML><HEAD></HEAD><BODY><PRE>
73+
Invalid value.
74+
</PRE></BODY></HTML>
75+
azalea11% export QUERY_STRING='year=aaaaa&month=8'
76+
azalea11% ./cgi-cal.rb # 不適切なパラメタの例 7
77+
Content-Type: text/html
78+
79+
<HTML><HEAD></HEAD><BODY><PRE>
80+
Invalid value.
81+
</PRE></BODY></HTML>
82+
azalea11% export QUERY_STRING='year=100000000&month=8'
83+
azalea11% ./cgi-cal.rb # 不適切なパラメタの例 8
84+
Content-Type: text/html
85+
86+
<HTML><HEAD></HEAD><BODY><PRE>
87+
Invalid value.
88+
</PRE></BODY></HTML>

report10/cal.html

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title></title>
7+
</head>
8+
<body>
9+
<form action="cgi-cal.rb" method="get">
10+
<label for="form-month">month</label>
11+
<input
12+
id="form-month"
13+
type="number"
14+
name="month"
15+
min="1"
16+
max="12"
17+
required
18+
/>
19+
<label for="form-year">year</label>
20+
<input
21+
id="form-year"
22+
type="number"
23+
name="year"
24+
min="1"
25+
max="9999"
26+
required
27+
/>
28+
<input type="submit" />
29+
<input type="reset" />
30+
</form>
31+
</body>
32+
</html>

report10/cgi-cal.rb

100644100755
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/local3/coins/linux/bin/ruby
2+
# -*- coding: utf-8 -*-
3+
require "cgi"
4+
5+
def main()
6+
@cgi = CGI.new()
7+
print_header()
8+
print_content()
9+
exit(0)
10+
end
11+
12+
def print_header()
13+
printf("Content-Type: text/html\n")
14+
printf("\n")
15+
end
16+
17+
def print_content()
18+
printf("<HTML><HEAD></HEAD><BODY><PRE>\n")
19+
$stdout.flush()
20+
21+
valid = true
22+
23+
year_s = @cgi["year"]
24+
year = 0
25+
case(year_s)
26+
when ""
27+
printf("Parameter 'year' is required but empty.\n");
28+
valid = false
29+
else
30+
year = year_s.to_i()
31+
if year <= 0 || year >= 10000 then
32+
printf("Invalid value.\n");
33+
valid = false
34+
end
35+
end
36+
37+
month_s = @cgi["month"]
38+
month = 0
39+
case(month_s)
40+
when ""
41+
printf("Parameter 'month' is required but empty.\n");
42+
valid = false
43+
else
44+
month = month_s.to_i()
45+
if month <= 0 || month > 12 then
46+
printf("Invalid value.\n");
47+
valid = false
48+
end
49+
end
50+
51+
if valid then
52+
child_pid = fork do
53+
exec("/usr/bin/cal", sprintf("%d", month), sprintf("%d", year))
54+
end
55+
Process.waitpid(child_pid)
56+
end
57+
58+
printf("</PRE></BODY></HTML>\n")
59+
end
60+
61+
main()

report10/cgi-counter.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
require "cgi"
44

55
DATA_FILENAME = "file-counter-value.data"
6-
$comname = $0
76

87
def main()
98
@cgi = CGI.new()
109
print_header()
1110
counter = handle_counter()
1211
print_content(counter)
13-
exit( 0 )
12+
exit(0)
1413
end
1514

1615
def print_header()

report10/log.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2400:4051:c4a0:9600:aefe:3b:f3e4:8d7e - - [04/Aug/2024:23:41:23 +0900] "GET /~s2
2+
311951/syspro-cgi-examples/cal.html HTTP/1.1" 200 682 "-" "Mozilla/5.0 (X11; Lin
3+
ux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0"
4+
2400:4051:c4a0:9600:aefe:3b:f3e4:8d7e - - [04/Aug/2024:23:41:32 +0900] "GET /~s2
5+
311951/syspro-cgi-examples/cgi-cal.rb?month=1&year=2000 HTTP/1.1" 200 220 "http:
6+
//www.coins.tsukuba.ac.jp/~s2311951/syspro-cgi-examples/cal.html" "Mozilla/5.0 (
7+
X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0"

report10/report10.raw.txt

+45
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,48 @@
33
課題番号:10
44
練習問題番号:1013
55
題名:システムプログラム 第10回レポート課題
6+
7+
以下のプログラムを作成した。
8+
9+
__INCLUDE(./cgi-cal.rb)__
10+
11+
本プログラムは以下の仕様を満たしている。
12+
- CGI のプログラムである
13+
- パラメタ year を取る
14+
- パラメタ month を取る
15+
- パラメタが与えられなかった場合、クライアントにエラーメッセージを返す
16+
- パラメタが以下を満たす場合 Invalid value. という旨のエラーメッセージを返す
17+
"month" パラメタが 0 以下、または 12 以上だった場合
18+
"year" パラメタが 0 以下、または 10000 以上だった場合
19+
- 文字列として "100xx" のように数字以外が現れると、それより前の数字だけから
20+
計算した値を用いる
21+
- 文字列に数字が一切現れない時には、0 として解釈し、Invalid value. という旨の
22+
エラーメッセージを返す
23+
24+
実行結果を以下に示す。
25+
なお、azalea 環境で行ったが、LANG 環境変数に ja_JP.UTF-8 が指定されていたために
26+
/usr/bin/cal の出力結果が日本語で出力された。
27+
28+
__INCLUDE(./cal-output)__
29+
30+
また、coins Web サーバに作成した CGI プログラムと
31+
フォーム用の HTML ファイルを置いた。以下にそのフォーム用のファイルを示す。
32+
33+
__INCLUDE(./cal.html)__
34+
35+
なお、Coins の Web サーバに上の URL は以下の通りである。
36+
http://www.coins.tsukuba.ac.jp/~__STUDENT_UTID__/syspro-cgi-examples/cal.html
37+
38+
ブラウザ上でこれを開き、month=1, year=2000 の値をフォームを用いて送信した。
39+
40+
ブラウザ上に 2000 年 1 月のカレンダーが表示された。
41+
なお、www における LANG 環境変数は C.UTF-8 であったため、
42+
azalea 環境とは異なり、英語でカレンダーが表示された。
43+
44+
その後、サーバのアクセスログを確認した。
45+
具体的には、cd /var/log/httpd/ をした後、
46+
cat $(ls access_log_* | tail -1) | grep __STUDENT_UTID__ を実行して抜き出した。
47+
48+
以下にそのアクセスログを示す。なお、適宜改行を挟んでいる。
49+
50+
__INCLUDE(./log.txt)__

0 commit comments

Comments
 (0)