mirror all submissions + generate a very basic per-challenge listing
This commit is contained in:
		
						commit
						bfe7c56bcf
					
				
							
								
								
									
										65
									
								
								gather.rb
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										65
									
								
								gather.rb
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,65 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env ruby
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$PAGE_BASE = "http://tilde.town/~dzwdz/golf"
 | 
				
			||||||
 | 
					$LOCAL_BASE = "/home/dzwdz/public_html/golf"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  file = File.new("#{$LOCAL_BASE}/#{event}/index.html", 'w')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  p_map.each do
 | 
				
			||||||
 | 
					    |user, submissions|
 | 
				
			||||||
 | 
					    file.print "<div class=\"user\"><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></li>"
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    file.print "</ul></div>\n"
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  file.close
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mirror 'firstone'
 | 
				
			||||||
 | 
					challenge_page 'firstone'
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user