1#!/usr/bin/ruby
2# iExploder - Generates bad HTML files to perform QA for web browsers.
3#
4# Copyright 2010 Thomas Stromberg - All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#      http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18require 'cgi';
19require 'iexploder';
20
21$CONFIG_PATH = 'config.yaml'
22
23ie = IExploder.new($CONFIG_PATH)
24cgi = CGI.new("html4");
25ie.cgi_url=ENV['SCRIPT_NAME'] || '?'
26ie.browser=ENV['HTTP_USER_AGENT'] || 'unknown'
27ie.test_num = cgi.params['t'][0].to_i
28ie.subtest_data = cgi.params['s'][0] || nil
29ie.random_mode = cgi.params['r'][0]
30ie.lookup_mode = cgi.params['l'][0]
31ie.stop_num = cgi.params['x'][0] || nil
32ie.setRandomSeed()
33
34mime_type = cgi.params['m'][0] || nil
35if mime_type:
36  header_options = ie.buildHeaders(mime_type)
37  # The CGI library wants the Content-Type header to be named 'type'. It
38  # will post two Content-Type headers otherwise.
39  header_options['type'] = header_options['Content-Type'].dup
40  header_options.delete('Content-Type')
41  cgi.out(header_options) do
42    ie.buildMediaFile(mime_type)
43  end
44else
45  cgi.out('type' => 'text/html') do
46    ie.buildPage()
47  end
48end
49