106 lines
2.5 KiB
Ruby
Executable File
106 lines
2.5 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
$PAGE_BASE = "http://tilde.town/~dzwdz/golf"
|
|
$LOCAL_BASE = "/home/dzwdz/public_html/golf"
|
|
|
|
$HTML_HEAD, $HTML_FOOT = File.read('template.html').split('/snip/')
|
|
|
|
def all_files(event)
|
|
`ls -d /home/*/golf/#{event}/*`
|
|
.lines
|
|
.map(&:strip)
|
|
end
|
|
|
|
def submissions(event)
|
|
all_files(event)
|
|
.filter {|l| not l.end_with? '.hint'}
|
|
end
|
|
|
|
## mirrors files into public_html/golf/[event name]/mirror/
|
|
def mirror(event)
|
|
all_files(event)
|
|
.each do |path|
|
|
split = path.split('/')
|
|
user = split[2]
|
|
name = split[5]
|
|
`mkdir -p #{$LOCAL_BASE}/#{event}/mirror/#{user}`
|
|
begin
|
|
File.symlink(path, "#{$LOCAL_BASE}/#{event}/mirror/#{user}/#{name}")
|
|
rescue Errno::EEXIST
|
|
end
|
|
end
|
|
end
|
|
|
|
def challenge_page(event)
|
|
# maps participants to their submissions
|
|
p_map = Hash.new []
|
|
|
|
submissions(event)
|
|
.each do |path|
|
|
user = path.split('/')[2]
|
|
p_map[user] += [path]
|
|
end
|
|
|
|
# temporary
|
|
p_map["dzwdz1"] = p_map["dzwdz"]
|
|
p_map["dzwdz2"] = p_map["dzwdz"]
|
|
p_map["dzwdz3"] = p_map["dzwdz"]
|
|
|
|
file = File.new("#{$LOCAL_BASE}/#{event}/index.html", 'w')
|
|
file.write $HTML_HEAD
|
|
|
|
# challenge info
|
|
file.write "<div id=\"challenge_header\">"
|
|
file.write "<h1>#{event}</h1>"
|
|
file.write File.read("challenges/#{event}/desc.html")
|
|
file.write "<a href=\"#{$PAGE_BASE}/how.html\">how can i join?</a>"
|
|
file.write "</div>"
|
|
|
|
# solutions
|
|
file.write "<div id=\"solutions\">"
|
|
p_map.each do
|
|
|user, submissions|
|
|
file.print "<div class=\"card\"><h2>~#{user}</h2><ul>"
|
|
submissions.each do
|
|
|path|
|
|
name = path.split('/')[5]
|
|
file.print "<li>"
|
|
# todo this has a million vulns
|
|
# also it's a mess
|
|
file.print "<a href=\"#{$PAGE_BASE}/#{event}/mirror/#{user}/#{name}\">"
|
|
file.print "#{name}"
|
|
file.print "</a> (#{File.size path}b)"
|
|
hint = path + '.hint'
|
|
# speaking of messes
|
|
if File.exists? hint
|
|
file.print "<a class=\"hint\" href=\"#{$PAGE_BASE}/#{event}/mirror/#{user}/#{name}.hint\">hint</a>"
|
|
end
|
|
file.print "</li>"
|
|
end
|
|
file.print "</ul></div>\n"
|
|
end
|
|
file.write "</div>"
|
|
|
|
file.write $HTML_FOOT
|
|
file.close
|
|
end
|
|
|
|
def static_page(path)
|
|
File.open "#{$LOCAL_BASE}/#{path}", "w" do
|
|
|f|
|
|
f.write $HTML_HEAD
|
|
f.write File.read path
|
|
f.write $HTML_FOOT
|
|
end
|
|
end
|
|
|
|
Dir['challenges/*'].each do |path|
|
|
name = path.split('/', 2)[-1]
|
|
mirror name
|
|
challenge_page name
|
|
end
|
|
|
|
static_page 'index.html'
|
|
static_page 'how.html'
|
|
`cp style.css #{$LOCAL_BASE}/`
|