prepare for 11.2 launch
[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     res = get_from_api(path)
15     render :text => res.body, :content_type => res.content_type
16   end
17
18   def ymp_without_arch_and_version
19     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:package]}?view=ymp"
20     res = get_from_api(path)
21     render :text => res.body, :content_type => res.content_type
22   end
23
24   def set_release(release)
25     if release == "111"
26        @isos = {}
27        @directory = "http://download.opensuse.org/distribution/11.1"
28        @isos["lang-32"] = "11.1-Addon-Lang-i586"
29        @isos["lang-64"] = "11.1-Addon-Lang-x86_64"
30        @isos["nonoss"] = "11.1-Addon-NonOss-BiArch-i586-x86_64"
31        @isos["kde-64"] = "11.1-KDE4-LiveCD-x86_64"
32        @isos["kde-32"] = "11.1-KDE4-LiveCD-i686"
33        @isos["gnome-64"] = "11.1-GNOME-LiveCD-x86_64"
34        @isos["gnome-32"] = "11.1-GNOME-LiveCD-i686"
35        @isos["dvd-64"] = "11.1-DVD-x86_64"
36        @isos["dvd-32"] = "11.1-DVD-i586"
37        @isos["net-32"] = "11.1-NET-i586"
38        @isos["net-64"] = "11.1-NET-x86_64"
39
40        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.1/RELEASE-NOTES.en.html"
41        @releasename = "openSUSE 11.1"
42        @repourl = "http://download.opensuse.org/distribution/11.1"
43        @medium = "dvd"
44     elsif release == "112"
45        @isos = {}
46        @directory = "http://download.opensuse.org/distribution/11.2"
47        @isos["lang-32"] = "11.2-Addon-Lang-i586"
48        @isos["lang-64"] = "11.2-Addon-Lang-x86_64"
49        @isos["nonoss"] = "11.2-Addon-NonOss-BiArch-i586-x86_64"
50        @isos["kde-64"] = "11.2-KDE4-LiveCD-x86_64"
51        @isos["kde-32"] = "11.2-KDE4-LiveCD-i686"
52        @isos["gnome-64"] = "11.2-GNOME-LiveCD-x86_64"
53        @isos["gnome-32"] = "11.2-GNOME-LiveCD-i686"
54        @isos["dvd-64"] = "11.2-DVD-x86_64"
55        @isos["dvd-32"] = "11.2-DVD-i586"
56        @isos["net-32"] = "11.2-NET-i586"
57        @isos["net-64"] = "11.2-NET-x86_64"
58
59        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.2/RELEASE-NOTES.en.html"
60        @releasename = "openSUSE 11.2"
61        @repourl = "http://download.opensuse.org/distribution/11.2"
62        @medium = "dvd"
63     elsif release == "developer"
64        @isos = {}
65        @directory = "http://download.opensuse.org/distribution/11.2-RC2"
66        @isos["lang-32"] = "Addon-Lang-Build0339-i586"
67        @isos["lang-64"] = "Addon-Lang-Build0339-x86_64"
68        @isos["nonoss"] = "Addon-NonOss-BiArch-Build0339-i586-x86_64"
69        @isos["kde-64"] = "KDE4-LiveCD-Build0339-x86_64"
70        @isos["kde-32"] = "KDE4-LiveCD-Build0339-i686"
71        @isos["gnome-64"] = "GNOME-LiveCD-Build0339-x86_64"
72        @isos["gnome-32"] = "GNOME-LiveCD-Build0339-i686"
73        @isos["dvd-64"] = "DVD-Build0339-x86_64"
74        @isos["dvd-32"] = "DVD-Build0339-i586"
75        @isos["net-32"] = "NET-Build0339-i586"
76        @isos["net-64"] = "NET-Build0339-x86_64"
77
78        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.2/RELEASE-NOTES.en.html"
79        @releasename = "openSUSE 11.2-RC2"
80        @repourl = "http://download.opensuse.org/distribution/11.2"
81        @medium = "dvd"
82     end
83     @release = release
84   end
85
86   def redirectit(release)
87     if params[:lang].nil?
88       lang = request.compatible_language_from(LANGUAGES) || "en"
89     else
90       lang = params[:lang][0]
91     end
92     notice = nil
93     url = "/%s/%s" % [release, lang]
94     if request.user_agent.index('Mozilla/5.0 (compatible; Konqueror/3')
95         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
96     end
97     if notice
98        render :template => "main/redirect_with_notice", :locals => { :notice => notice }
99     else
100        redirect_to url
101     end
102   end
103
104   def developer
105     # redirectit("developer")
106     redirect_to "http://en.opensuse.org/Factory"
107   end
108    
109   def index
110     redirectit("112")
111   end
112
113   def release
114     @lang = params[:lang][0].gsub(/\-/, '_')
115     GetText.locale = @lang
116
117     set_release(params[:release])
118     render :template => "main/release"
119   end
120
121   def change_install
122     set_release(params[:release])
123     @medium = params[:medium]
124     @lang = params[:lang]
125     render :template => "main/release"
126   end
127
128   def download_js
129     set_release(params[:release])
130     render :template => "main/download", :content_type => 'text/javascript', :layout => false
131   end
132
133   def show_request
134     render :template => "main/testrequest", :layout => false
135   end
136
137   def download
138     set_release(params[:release])
139     medium = params[:medium]
140
141     if params[:arch] == "i686"
142       medium += "-32"
143     else
144       medium += "-64"
145     end
146
147     suffix = ".iso"
148     
149     case
150     when params[:protocol] == "torrent"
151       if params[:medium] != "net"
152           suffix = ".iso.torrent"
153       end
154     when params[:protocol] == "mirror"
155       suffix = ".iso?mirrorlist"
156     when params[:protocol] == "metalink"
157       suffix = ".iso.metalink"
158     end
159     redirect_to @directory + "/iso/openSUSE-" + @isos[medium] + suffix
160
161   end
162
163   private
164   
165   def get_from_api(path)
166     req = Net::HTTP::Get.new(path)
167     req['x-username'] = "obs_read_only"
168
169     host, port = API_HOST.split(/:/)
170     port ||= 80
171     res = Net::HTTP.new(host, port).start do |http|
172       http.request(req)
173     end
174   end
175 end