get rid of multiple get_from_api definitions, put it in application_controller and...
[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/12.1-Milestone2"
108       @isos["lang-32"] = "Addon-Lang-Build0072-i586"
109       @isos["lang-64"] = "Addon-Lang-Build0072-x86_64"
110       @isos["nonoss"] = "Addon-NonOss-BiArch-Build0072-i586-x86_64"
111       @isos["kde-64"] = "KDE-LiveCD-Build0072-x86_64"
112       @isos["kde-32"] = "KDE-LiveCD-Build0072-i686"
113       @isos["gnome-64"] = "GNOME-LiveCD-Build0072-x86_64"
114       @isos["gnome-32"] = "GNOME-LiveCD-Build0072-i686"
115       @isos["dvd-64"] = "DVD-Build0072-x86_64"
116       @isos["dvd-32"] = "DVD-Build0072-i586"
117       @isos["net-32"] = "NET-Build0072-i586"
118       @isos["net-64"] = "NET-Build0072-x86_64"
119
120       @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/12.1/RELEASE-NOTES.en.html"
121       @releasename = "openSUSE 12.1 Milestone 2"
122       @repourl = "http://download.opensuse.org/distribution/12.1"
123       @medium = "dvd"
124     end
125     @release = release
126   end
127
128   def redirectit(release)
129     if request.user_agent && request.user_agent.index('Mozilla/5.0 (compatible; Konqueror/3')
130       notice = _("Konqueror of KDE 3 is unfortunately unmaintained and its javascript implementation contains bugs that " +
131           "make it impossible to use with this page. Please make sure you have javascript disabled before you " +
132           "<a href='%s'>continue</a>.") % url
133       render :template => "main/redirect_with_notice", :locals => { :notice => notice } and return
134     end
135     redirect_to :action => 'release', :release => release, :lang => @lang
136   end
137
138
139   def developer
140     redirectit("developer") and return
141     flash.now[:warn] = _("We currently don't have a Factory Snapshot that is more recent than our last openSUSE release. <br/>" +
142       "Please check <a href='http://en.opensuse.org/Portal:Factory'>http://en.opensuse.org/Portal:Factory</a> for more information.")
143     @exclude_debug = true
144     @include_home = 'false'
145     set_release("114")
146     render :template => "main/release"
147   end
148
149
150   def index
151     redirectit("114")
152   end
153
154   def release
155     @exclude_debug = true
156     @include_home = 'false'
157     set_release(params[:release])
158     render :template => "main/release"
159   end
160
161   def change_install
162     set_release(params[:release])
163     @medium = params[:medium]
164     render :template => "main/release"
165   end
166
167   def download_js
168     set_release(params[:release])
169     render :template => "main/download", :content_type => 'text/javascript', :layout => false
170   end
171
172   def show_request
173     render :template => "main/testrequest", :layout => false
174   end
175
176   def download
177     set_release(params[:release])
178     medium = params[:medium]
179
180     if params[:arch] == "i686"
181       medium += "-32"
182     else
183       medium += "-64"
184     end
185
186     suffix = ".iso"
187     
188     case
189     when params[:protocol] == "torrent"
190       if params[:medium] != "net"
191         suffix = ".iso.torrent"
192       end
193     when params[:protocol] == "mirror"
194       suffix = ".iso?mirrorlist"
195     when params[:protocol] == "metalink"
196       suffix = ".iso.meta4"
197     end
198     redirect_to @directory + "/iso/openSUSE-" + @isos[medium] + suffix
199
200   end
201
202   def top_downloads
203     respond_to do |format|
204       format.xml  { render(:layout => false, :content_type => 'text/xml' ) }
205     end
206   end
207
208 end