redirect to 11.3 by default
[opensuse:software-o-o.git] / app / controllers / main_controller.rb
1 require 'net/http'
2 require 'gettext_rails'
3
4 class MainController < ApplicationController
5
6   verify :only => :ymp, :params => [:project, :repository, :arch, :binary],
7     :redirect_to => :index
8
9   # these pages are completely static:
10   caches_page :release, :download_js
11
12   def ymp_with_arch_and_version
13     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:arch]}/#{params[:binary]}?view=ymp"
14     DownloadHistory.create :query => params[:query], :base => params[:base],
15                            :ymp => path
16     res = get_from_api(path)
17     render :text => res.body, :content_type => res.content_type
18   end
19
20   def ymp_without_arch_and_version
21     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:package]}?view=ymp"
22     DownloadHistory.create :query => params[:query], :base => params[:base],
23                            :ymp => path
24     res = get_from_api(path)
25     render :text => res.body, :content_type => res.content_type
26   end
27
28   def set_release(release)
29     if release == "111"
30        @isos = {}
31        @directory = "http://download.opensuse.org/distribution/11.1"
32        @isos["lang-32"] = "11.1-Addon-Lang-i586"
33        @isos["lang-64"] = "11.1-Addon-Lang-x86_64"
34        @isos["nonoss"] = "11.1-Addon-NonOss-BiArch-i586-x86_64"
35        @isos["kde-64"] = "11.1-KDE4-LiveCD-x86_64"
36        @isos["kde-32"] = "11.1-KDE4-LiveCD-i686"
37        @isos["gnome-64"] = "11.1-GNOME-LiveCD-x86_64"
38        @isos["gnome-32"] = "11.1-GNOME-LiveCD-i686"
39        @isos["dvd-64"] = "11.1-DVD-x86_64"
40        @isos["dvd-32"] = "11.1-DVD-i586"
41        @isos["net-32"] = "11.1-NET-i586"
42        @isos["net-64"] = "11.1-NET-x86_64"
43
44        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.1/RELEASE-NOTES.en.html"
45        @releasename = "openSUSE 11.1"
46        @repourl = "http://download.opensuse.org/distribution/11.1"
47        @medium = "dvd"
48     elsif release == "112"
49        @isos = {}
50        @directory = "http://download.opensuse.org/distribution/11.2"
51        @isos["lang-32"] = "11.2-Addon-Lang-i586"
52        @isos["lang-64"] = "11.2-Addon-Lang-x86_64"
53        @isos["nonoss"] = "11.2-Addon-NonOss-BiArch-i586-x86_64"
54        @isos["kde-64"] = "11.2-KDE4-LiveCD-x86_64"
55        @isos["kde-32"] = "11.2-KDE4-LiveCD-i686"
56        @isos["gnome-64"] = "11.2-GNOME-LiveCD-x86_64"
57        @isos["gnome-32"] = "11.2-GNOME-LiveCD-i686"
58        @isos["dvd-64"] = "11.2-DVD-x86_64"
59        @isos["dvd-32"] = "11.2-DVD-i586"
60        @isos["net-32"] = "11.2-NET-i586"
61        @isos["net-64"] = "11.2-NET-x86_64"
62
63        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.2/RELEASE-NOTES.en.html"
64        @releasename = "openSUSE 11.2"
65        @repourl = "http://download.opensuse.org/distribution/11.2"
66        @medium = "dvd"
67     elsif release == "113"
68        @isos = {}
69        @directory = "http://download.opensuse.org/distribution/11.3"
70        @isos["lang-32"] = "11.3-Addon-Lang-i586"
71        @isos["lang-64"] = "11.3-Addon-Lang-x86_64"
72        @isos["nonoss"] = "11.3-Addon-NonOss-BiArch-i586-x86_64"
73        @isos["kde-64"] = "11.3-KDE4-LiveCD-x86_64"
74        @isos["kde-32"] = "11.3-KDE4-LiveCD-i686"
75        @isos["gnome-64"] = "11.3-GNOME-LiveCD-x86_64"
76        @isos["gnome-32"] = "11.3-GNOME-LiveCD-i686"
77        @isos["dvd-64"] = "11.3-DVD-x86_64"
78        @isos["dvd-32"] = "11.3-DVD-i586"
79        @isos["net-32"] = "11.3-NET-i586"
80        @isos["net-64"] = "11.3-NET-x86_64"
81
82        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.3/RELEASE-NOTES.en.html"
83        @releasename = "openSUSE 11.3"
84        @repourl = "http://download.opensuse.org/distribution/11.3"
85        @medium = "dvd"
86     elsif release == "developer"
87        @isos = {}
88        @directory = "http://download.opensuse.org/distribution/11.3-RC2"
89        @isos["lang-32"] = "Addon-Lang-Build0694-i586"
90        @isos["lang-64"] = "Addon-Lang-Build0694-x86_64"
91        @isos["nonoss"] = "Addon-NonOss-BiArch-Build0694-i586-x86_64"
92        @isos["kde-64"] = "KDE-LiveCD-Build0694-x86_64"
93        @isos["kde-32"] = "KDE-LiveCD-Build0694-i686"
94        @isos["gnome-64"] = "GNOME-LiveCD-Build0694-x86_64"
95        @isos["gnome-32"] = "GNOME-LiveCD-Build0694-i686"
96        @isos["dvd-64"] = "DVD-Build0694-x86_64"
97        @isos["dvd-32"] = "DVD-Build0694-i586"
98        @isos["net-32"] = "NET-Build0694-i586"
99        @isos["net-64"] = "NET-Build0694-x86_64"
100
101        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.3/RELEASE-NOTES.en.html"
102        @releasename = "openSUSE 11.3 RC2"
103        @repourl = "http://download.opensuse.org/distribution/11.3"
104        @medium = "dvd"
105     end
106     @release = release
107   end
108
109   def redirectit(release)
110     if params[:lang].nil?
111       lang = request.compatible_language_from(LANGUAGES) || "en"
112     else
113       lang = params[:lang][0]
114     end
115     notice = nil
116     url = "%s/%s/%s" % [ActionController::Base.relative_url_root, release, lang]
117     if request.user_agent && request.user_agent.index('Mozilla/5.0 (compatible; Konqueror/3')
118       notice = _("Konqueror of KDE 3 is unfortunately unmaintained and its javascript implementation contains bugs that make it impossible to use with this page. Please make sure you have javascript disabled before you <a href='%s'>continue</a>.") % url
119     end
120     if notice
121       render :template => "main/redirect_with_notice", :locals => { :notice => notice }
122     else
123       redirect_to url
124     end
125   end
126
127   def developer
128     #redirectit("developer")
129     redirect_to "http://en.opensuse.org/Portal:Factory"
130   end
131    
132   def index
133     redirectit("113")
134   end
135
136   def release
137     @exclude_debug = true
138     @exclude_filter = 'home:'
139     set_release(params[:release])
140     render :template => "main/release"
141   end
142
143   def change_install
144     set_release(params[:release])
145     @medium = params[:medium]
146     render :template => "main/release"
147   end
148
149   def download_js
150     set_release(params[:release])
151     render :template => "main/download", :content_type => 'text/javascript', :layout => false
152   end
153
154   def show_request
155     render :template => "main/testrequest", :layout => false
156   end
157
158   def download
159     set_release(params[:release])
160     medium = params[:medium]
161
162     if params[:arch] == "i686"
163       medium += "-32"
164     else
165       medium += "-64"
166     end
167
168     suffix = ".iso"
169     
170     case
171     when params[:protocol] == "torrent"
172       if params[:medium] != "net"
173           suffix = ".iso.torrent"
174       end
175     when params[:protocol] == "mirror"
176       suffix = ".iso?mirrorlist"
177     when params[:protocol] == "metalink"
178       suffix = ".iso.metalink"
179     end
180     redirect_to @directory + "/iso/openSUSE-" + @isos[medium] + suffix
181
182   end
183
184   private
185   
186   def get_from_api(path)
187     req = Net::HTTP::Get.new(path)
188     req['x-username'] = "obs_read_only"
189
190     host, port = API_HOST.split(/:/)
191     port ||= 80
192     res = Net::HTTP.new(host, port).start do |http|
193       http.request(req)
194     end
195   end
196 end