Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 63
- Log:
Initial import of RCVSweb 0.0.2 sources. RCVSweb is a Ruby On Rails
wrapper around CVSweb, to provide Rails-based HTML template facilities.
- Author:
- adh
- Date:
- Sun Aug 06 17:55:00 +0100 2006
- Size:
- 4320 Bytes
1 | class RcvswebController < ApplicationController |
2 | |
3 | # All routes lead to the 'run' method, which invokes CVSweb based |
4 | # on the request URL and embeds the result in a View. |
5 | |
6 | def run |
7 | |
8 | # Get the request URI in a way that works for FCGI and regular |
9 | # CGI, at least for LightTPD. Strip off the PATH_PREFIX (location |
10 | # of the Rails application) if present. |
11 | |
12 | uri = @request.env['REQUEST_URI'].dup |
13 | uri.slice!(PATH_PREFIX + '/') |
14 | |
15 | # Split off the query string section, if there is one. |
16 | |
17 | (path_info, query) = uri.split('?') |
18 | |
19 | # The CGI script expects certain variables to be set up in a |
20 | # certain way. "Slow" CGI does this but FastCGI does not because |
21 | # the script executes under a different process environment |
22 | # entirely, without the benefit of server-set variables. We must |
23 | # therefore emulate the required environment by setting system |
24 | # variables before executing the CVSweb script. |
25 | |
26 | command = '' |
27 | needed = %w( |
28 | HTTP_USER_AGENT HTTP_ACCEPT_ENCODING |
29 | MOD_PERL PATH_INFO |
30 | SCRIPT_NAME SCRIPT_FILENAME |
31 | QUERY_STRING |
32 | ) |
33 | |
34 | needed.each do |key| |
35 | |
36 | # Override certain items where we know we want a particular |
37 | # result, else use a server-set value if there is one. |
38 | |
39 | case key |
40 | when 'SCRIPT_NAME' |
41 | value = PATH_PREFIX |
42 | when 'SCRIPT_FILENAME' |
43 | value = "#{RAILS_ROOT}/public/dispatch.cgi" |
44 | when 'PATH_INFO' |
45 | value = path_info || '' |
46 | value = '/' + value unless (value[0] == '/') |
47 | when 'QUERY_STRING' |
48 | value = query |
49 | else |
50 | value = @request.env[key] || '' |
51 | end |
52 | |
53 | # Add the variable initialisation statement to the command string. |
54 | |
55 | command += "#{key}=\"#{value}\" " |
56 | |
57 | end # From needed.each |
58 | |
59 | # Add the CVSweb command to the command string and execute it. |
60 | |
61 | command += "#{CVSWEB_LOCATION}" |
62 | @output = `#{command}` |
63 | |
64 | # The command should have included HTTP headers; split the two. |
65 | |
66 | pos = @output.index("\r\n\r\n") |
67 | headstr = @output.slice!(0..pos + 3) if pos |
68 | headers = {} |
69 | |
70 | if (headstr) |
71 | |
72 | # There are indeed some headers. Create a hash from them. |
73 | |
74 | headstr.downcase.split("\r\n").each do |str| |
75 | pos = str.index(':') |
76 | headers[str.slice!(0..pos - 1).strip] = str[1..-1].strip if (pos > 1) |
77 | end |
78 | |
79 | # For a content type of 'text/html', render within a View. Otherwise |
80 | # send the data directly without a surrounding template. |
81 | |
82 | if ([ 'text/html', 'text/x-html' ].include? headers['content-type']) |
83 | |
84 | # Almost there - extract a title if we can, and chop off the header |
85 | # and footer (HTML prologue and epilogue) to attempt to produce |
86 | # valid (X)HTML. The version of CVSweb in use at the time of writing |
87 | # always writes body and title container tags in lower case which |
88 | # helps save a bit of effort. |
89 | |
90 | title_tag = @output.slice(/<title.*\/title>/) |
91 | title_tag.gsub!(/<title.*?>/, '') |
92 | @title = title_tag.gsub(/<\/title>/, '') || 'CVS Repository' |
93 | |
94 | # Chop everything from the front of the output string up to the end |
95 | # of the opening body tag, inclusive. |
96 | |
97 | body_tag = @output.slice(/<body.*?>/) |
98 | body_pos = @output.index('<body') |
99 | |
100 | if (body_pos && body_tag && body_tag.length > 0) |
101 | @output.slice!(0..body_pos + body_tag.length - 1) |
102 | end |
103 | |
104 | # Chop off anything after the closing body tag too. |
105 | |
106 | body_pos = @output.index('</body') |
107 | @output.slice!(body_pos..-1) if body_pos |
108 | |
109 | # Render the default layout to send the template-based output. |
110 | |
111 | render :layout => 'default' |
112 | |
113 | else |
114 | |
115 | # Apparently, not HTML; send the data directly. |
116 | |
117 | type = headers['content-type'] || 'application/octet-stream' |
118 | send_data @output, |
119 | :type => type, |
120 | :disposition => 'inline' |
121 | end |
122 | |
123 | else |
124 | |
125 | # CVSweb output had no HTTP header - this is unexpected. We don't |
126 | # understand its output so just send this to the browser as a |
127 | # stream of binary data. |
128 | |
129 | send_data @output, |
130 | :filename => 'rcvsweb.dat', |
131 | :type => 'application/octet-stream' |
132 | end |
133 | end |
134 | end |