offer top_searches as xml
[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     notice = nil
111     url = "%s/%s/%s" % [ActionController::Base.relative_url_root, release, @lang]
112     if request.user_agent && request.user_agent.index('Mozilla/5.0 (compatible; Konqueror/3')
113       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
114     end
115     if notice
116       render :template => "main/redirect_with_notice", :locals => { :notice => notice }
117     else
118       redirect_to url
119     end
120   end
121
122   def developer
123     #redirectit("developer")
124     redirect_to "http://en.opensuse.org/Portal:Factory"
125   end
126    
127   def index
128     redirectit("113")
129   end
130
131   def release
132     @exclude_debug = true
133     @exclude_filter = 'home:'
134     set_release(params[:release])
135     render :template => "main/release"
136   end
137
138   def change_install
139     set_release(params[:release])
140     @medium = params[:medium]
141     render :template => "main/release"
142   end
143
144   def download_js
145     set_release(params[:release])
146     render :template => "main/download", :content_type => 'text/javascript', :layout => false
147   end
148
149   def show_request
150     render :template => "main/testrequest", :layout => false
151   end
152
153   def download
154     set_release(params[:release])
155     medium = params[:medium]
156
157     if params[:arch] == "i686"
158       medium += "-32"
159     else
160       medium += "-64"
161     end
162
163     suffix = ".iso"
164     
165     case
166     when params[:protocol] == "torrent"
167       if params[:medium] != "net"
168           suffix = ".iso.torrent"
169       end
170     when params[:protocol] == "mirror"
171       suffix = ".iso?mirrorlist"
172     when params[:protocol] == "metalink"
173       suffix = ".iso.metalink"
174     end
175     redirect_to @directory + "/iso/openSUSE-" + @isos[medium] + suffix
176
177   end
178
179   def top_downloads
180     respond_to do |format|
181       format.xml  { render(:layout => false, :content_type => 'text/xml' ) }
182     end
183   end
184
185   private
186   
187   def get_from_api(path)
188     req = Net::HTTP::Get.new(path)
189     req['x-username'] = "obs_read_only"
190
191     host, port = API_HOST.split(/:/)
192     port ||= 80
193     res = Net::HTTP.new(host, port).start do |http|
194       http.request(req)
195     end
196   end
197 end