fix kde link
[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 == "114"
87        @isos = {}
88        @directory = "http://download.opensuse.org/distribution/11.4"
89        @isos["lang-32"] = "11.4-Addon-Lang-i586"
90        @isos["lang-64"] = "11.4-Addon-Lang-x86_64"
91        @isos["nonoss"] = "11.4-Addon-NonOss-BiArch-i586-x86_64"
92        @isos["kde-64"] = "11.4-KDE-LiveCD-x86_64"
93        @isos["kde-32"] = "11.4-KDE-LiveCD-i686"
94        @isos["gnome-64"] = "11.4-GNOME-LiveCD-x86_64"
95        @isos["gnome-32"] = "11.4-GNOME-LiveCD-i686"
96        @isos["dvd-64"] = "11.4-DVD-x86_64"
97        @isos["dvd-32"] = "11.4-DVD-i586"
98        @isos["net-32"] = "11.4-NET-i586"
99        @isos["net-64"] = "11.4-NET-x86_64"
100
101        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.4/RELEASE-NOTES.en.html"
102        @releasename = "openSUSE 11.4"
103        @repourl = "http://download.opensuse.org/distribution/11.4"
104        @medium = "dvd"
105     elsif release == "developer"
106        @isos = {}
107        @directory = "http://download.opensuse.org/distribution/11.4-RC2"
108        @isos["lang-32"] = "Addon-Lang-Build0012-i586"
109        @isos["lang-64"] = "Addon-Lang-Build0012-x86_64"
110        @isos["nonoss"] = "Addon-NonOss-BiArch-Build0012-i586-x86_64"
111        @isos["kde-64"] = "KDE-LiveCD-Build0012-x86_64"
112        @isos["kde-32"] = "KDE-LiveCD-Build0012-i686"
113        @isos["gnome-64"] = "GNOME-LiveCD-Build0012-x86_64"
114        @isos["gnome-32"] = "GNOME-LiveCD-Build0012-i686"
115        @isos["dvd-64"] = "DVD-Build0012-x86_64"
116        @isos["dvd-32"] = "DVD-Build0012-i586"
117        @isos["net-32"] = "NET-Build0012-i586"
118        @isos["net-64"] = "NET-Build0012-x86_64"
119
120        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.4/RELEASE-NOTES.en.html"
121        @releasename = "openSUSE 11.4 RC 2"
122        @repourl = "http://download.opensuse.org/distribution/11.4"
123        @medium = "dvd"
124     end
125     @release = release
126   end
127
128   def redirectit(release)
129     notice = nil
130     url = "%s/%s/%s" % [ActionController::Base.relative_url_root, release, @lang]
131     if request.user_agent && request.user_agent.index('Mozilla/5.0 (compatible; Konqueror/3')
132       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
133     end
134     if notice
135       render :template => "main/redirect_with_notice", :locals => { :notice => notice }
136     else
137       redirect_to url
138     end
139   end
140
141   def developer
142     #redirectit("developer")
143     redirect_to "http://en.opensuse.org/Portal:Factory"
144   end
145
146   def index
147     redirectit("114")
148   end
149
150   def release
151     @exclude_debug = true
152     @include_home = 'false'
153     set_release(params[:release])
154     render :template => "main/release"
155   end
156
157   def change_install
158     set_release(params[:release])
159     @medium = params[:medium]
160     render :template => "main/release"
161   end
162
163   def download_js
164     set_release(params[:release])
165     render :template => "main/download", :content_type => 'text/javascript', :layout => false
166   end
167
168   def show_request
169     render :template => "main/testrequest", :layout => false
170   end
171
172   def download
173     set_release(params[:release])
174     medium = params[:medium]
175
176     if params[:arch] == "i686"
177       medium += "-32"
178     else
179       medium += "-64"
180     end
181
182     suffix = ".iso"
183     
184     case
185     when params[:protocol] == "torrent"
186       if params[:medium] != "net"
187           suffix = ".iso.torrent"
188       end
189     when params[:protocol] == "mirror"
190       suffix = ".iso?mirrorlist"
191     when params[:protocol] == "metalink"
192       suffix = ".iso.meta4"
193     end
194     redirect_to @directory + "/iso/openSUSE-" + @isos[medium] + suffix
195
196   end
197
198   def top_downloads
199     respond_to do |format|
200       format.xml  { render(:layout => false, :content_type => 'text/xml' ) }
201     end
202   end
203
204   private
205   
206   def get_from_api(path)
207     req = Net::HTTP::Get.new(path)
208     req['x-username'] = "obs_read_only"
209
210     host, port = API_HOST.split(/:/)
211     port ||= 80
212     res = Net::HTTP.new(host, port).start do |http|
213       http.request(req)
214     end
215   end
216 end