forked from postmodern/wsoc
/
app.rb
152 lines (113 loc) · 3.79 KB
/
app.rb
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
#
# WSOC - The Web Spider Obstacle Course
#
# Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
require 'wsoc/course'
require 'wsoc/course_specs'
require 'wsoc/helpers'
require 'wsoc/version'
require 'rubygems'
require 'sinatra'
require 'nokogiri'
module WSOC
class App < Sinatra::Base
include Course
get '/' do
show :welcome
end
get '/specs' do
@specs = specs[:specs]
show :specs
end
get Config::SPECS_PATHS[:json] do
json specs
end
get Config::SPECS_PATHS[:yaml] do
yaml specs
end
course_template '/course/start.html'
get '/course/fail' do
status 404
show :course_fail
end
course_template '/course/relative/start.html'
course_pass '/course/relative/same_directory.html'
course_pass '/course/relative/current_directory.html'
course_pass '/course/relative/normal.html'
course_template '/course/absolute/start.html'
course_pass '/course/absolute/next.html'
course_template '/course/empty/start.html'
course_template '/course/frames/start.html'
course_template '/course/frames/frame.html'
course_template '/course/frames/iframe.html'
course_pass '/course/frames/frame_contents.html'
course_pass '/course/frames/iframe_contents.html'
course_template '/course/javascript/start.html'
course_template '/course/loop/start.html'
course_template '/course/loop/next.html'
course_template '/course/remote/start.html'
course_pass '/course/remote/next.html'
course_template '/course/redirects/start.html'
get '/course/redirects/300.html' do
redirect remote_url('/course/redirects/300/pass.html')
end
course_pass '/course/redirects/300/pass.html'
get '/course/redirects/301.html' do
redirect remote_url('/course/redirects/301/pass.html')
end
course_pass '/course/redirects/301/pass.html'
get '/course/redirects/302.html' do
redirect remote_url('/course/redirects/302/pass.html')
end
course_pass '/course/redirects/302/pass.html'
get '/course/redirects/303.html' do
redirect remote_url('/course/redirects/303/pass.html')
end
course_pass '/course/redirects/303/pass.html'
get '/course/redirects/307.html' do
redirect remote_url('/course/redirects/307/pass.html')
end
course_pass '/course/redirects/307/pass.html'
get '/course/redirects/meta.html' do
course_page :course_redirects_meta
end
course_pass '/course/redirects/meta/pass.html'
get '/course/cookies/start.html' do
response.set_cookie 'auth_level', '1'
course_page :course_cookies_start
end
get '/course/cookies/get.html' do
@authed = (request.cookies['auth_level'] == '1')
course_page :course_cookies_get
end
course_pass '/course/cookies/protected.html'
get '/course/auth/start.html' do
protected! do
course_page :course_auth_start
end
end
get '/course/auth/protected.html' do
protected! do
course_page :course_pass
end
end
get '/*' do
redirect remote_url('/course/fail')
end
end
end