diff --git a/root/.htaccess b/root/.htaccess new file mode 100644 index 0000000..c0337b5 --- /dev/null +++ b/root/.htaccess @@ -0,0 +1,4 @@ +AddHandler cgi-script .rb +Options +ExecCGI +AddType "text/html; charset=utf-8" .html + diff --git a/root/editor.css b/root/editor.css new file mode 100644 index 0000000..e109d96 --- /dev/null +++ b/root/editor.css @@ -0,0 +1,44 @@ +body{ + height: 100%; + /* background: linear-gradient(#44a9ff, #cee6fa); */ + background-color: #44a9ff; + } + +h1{border-bottom: double 5px #72ff83;} + +textarea {height:300px; width:500px; margin-bottom: 20px;} + +di#result{ + background-color: black; + color: white; + height: 300px; + width: 500px; + overflow: scroll; +} + +#kome{ + color: #423b3b; +} + +a { + background-color: pink; + color: black;} + +#black { + background-color: black; + color: white; + height: 300px; + width: 500px; + overflow: scroll; + } + + +span { +border-bottom: 2px double red; +} + +#code { +background-color: white; +border: 3px solid black; +width: 300px; +} diff --git a/root/editor.rb b/root/editor.rb new file mode 100755 index 0000000..bcfa10c --- /dev/null +++ b/root/editor.rb @@ -0,0 +1,59 @@ +#!/usr/bin/env ruby +# coding: utf-8 + +Encoding.default_external = 'utf-8' +require'kconv' +require'cgi' +require'open3' +require'timeout' + +#ENV['RUBYOPT']="-Ku" + +c = CGI.new(:accept_charset => "ascii-8bit") + +p = " +i = 1 +while i <= 1000 +if i%2 == 0 +puts i +end +i += 1 +end +".toutf8 + +cmd = "ruby -Ku -e '#{p}'" +o,e,s = Open3.capture3(cmd) + +print("Content-type: text/html; charset=utf-8\n\n") + +print < + + + + テキストエディタ読込 + + + + + +
+

名前を入力してください

+ +

1〜1000までの数のうち、偶数のみ表示させるプログラムを作成してください。

+ + + + + +

出力例

+

※print文などで一文づつ書いている場合は減点しまーーーーす

+ +EOF + +printf("\n", o.toutf8) + +puts("
") +puts("\n") diff --git a/root/errormes.txt b/root/errormes.txt new file mode 100644 index 0000000..f87b516 --- /dev/null +++ b/root/errormes.txt @@ -0,0 +1,14 @@ + + + + ERROR!! + + + + +

繰り返し処理に失敗しました!!

+エディタ画面へ戻る + diff --git a/root/escape.txt b/root/escape.txt new file mode 100644 index 0000000..89023f6 --- /dev/null +++ b/root/escape.txt @@ -0,0 +1,15 @@ + + + + worning!! + + + + +

不正な文字列です

+

意図した攻撃性のあるプログラムと判定されました。

+エディタ画面へ戻る + diff --git a/root/ranking.rb b/root/ranking.rb new file mode 100755 index 0000000..6b6f257 --- /dev/null +++ b/root/ranking.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env ruby +# coding: utf-8 + +require'sqlite3' +require'cgi' +c = CGI.new(:accept_charset => "UTF-8") + +print < + + + ランキング + + + + +EOF + +SQLite3::Database.new("../data/ranking.db") do |db| + db.results_as_hash = true + + name = "" + id = "" + i = 1 + a = 1 + o = 1 + + puts("

ランキング

") + puts("

※インデントは考慮していません

") + db.execute("select * from ranking") do |f| + name = f["name"] + pro = f["id"] + printf("

名前:%s

+

●コード

%s
\n", name, pro.gsub(/(\r\n|\r|\n)/,"
")) + i += 1 + if i == 6 + break + end + end +end diff --git a/root/textcode.rb b/root/textcode.rb new file mode 100755 index 0000000..823f950 --- /dev/null +++ b/root/textcode.rb @@ -0,0 +1,89 @@ +#!/usr/bin/env ruby +# coding: utf-8 +Encoding.default_external = 'utf-8' + +require'kconv' +require'cgi' +require'open3' +require'sqlite3' +require'timeout' + +def ptag(name) + puts"

#{name}

" +end + +begin + Timeout.timeout(2){ + +c = CGI.new(:accept_charset => "UTF-8") + +print"Content-type: text/html; charset=utf-8\n\n" + +SQLite3::Database.new("../data/ranking.db") do |db| + db.results_as_hash = true + + coderead = c["example"] + if /system|exec|open/ =~ coderead + file = File.open("escape.txt", "r") + puts file.read + file.close + exit + end + +namae = c["name"] +ans = c["ans"].delete("\r") +newans = ans.strip + +cmd = "ruby -Ku -e '#{coderead}'" +o,$e,s = Open3.capture3(cmd) #o,$e,s = 実行結果、エラー文、プロセス? +newo = o.strip + +print < + + + テキストエディタ読み込み + + + + +EOF + + +puts("

入力したコード

") +printf("\n", coderead) +puts("

実行結果

") +puts("
") + +printf("
%s
\n", CGI.escapeHTML(o)) +puts("
") + + if newans == newo #一致したときにDBにかきこむ + puts("

おめでとう!!成功です!!

") + if namae == "" + ptag("名前が入力されていません!名前を入力して下さい。") + else + db.execute("insert into ranking (id, name) values (?, ?)",coderead , namae) + puts("

ランキングに書き込みました!

") + end + if $e == "" + puts("

エラー文

") + printf("

%s

\n", $e) + end + else + puts("

もう一度やってみよう...!!

") + end +end + +puts("エディタ画面へ戻る") +puts("\n") + + } +rescue Timeout::Error + file = File.open("errormes.txt", "r") + puts file.read + file.close +end