Gentoo Archives: gentoo-commits

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/bouncer:master commit in: php/, php/inc/, php/rss/, php/cfg/, php/admin/
Date: Mon, 10 Dec 2018 05:09:16
Message-Id: 1544418539.2a8844ce2c1ebe0f206ea366120eea3734a9cbd3.robbat2@gentoo
1 commit: 2a8844ce2c1ebe0f206ea366120eea3734a9cbd3
2 Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
3 AuthorDate: Mon Dec 10 05:08:59 2018 +0000
4 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
5 CommitDate: Mon Dec 10 05:08:59 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/bouncer.git/commit/?id=2a8844ce
7
8 Avoid HTTP downgrades
9
10 Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
11
12 php/admin/index.php | 4 ++--
13 php/admin/locations.php | 4 ++--
14 php/admin/login.php | 2 +-
15 php/admin/logout.php | 2 +-
16 php/admin/os.php | 4 ++--
17 php/admin/products.php | 4 ++--
18 php/admin/regions.php | 4 ++--
19 php/admin/users.php | 4 ++--
20 php/cfg/admin_init.php | 2 +-
21 php/cfg/init.php | 2 ++
22 php/inc/header.php | 6 +++---
23 php/index.php | 2 +-
24 php/rss/download-counts.php | 10 +++++-----
25 13 files changed, 26 insertions(+), 24 deletions(-)
26
27 diff --git a/php/admin/index.php b/php/admin/index.php
28 index 1e08189..e058900 100644
29 --- a/php/admin/index.php
30 +++ b/php/admin/index.php
31 @@ -11,7 +11,7 @@ require_once('../cfg/init.php');
32 if (!empty($_POST['add-submit'])) {
33 if (Mirror::insert_mirror($_POST['mirror_name'],$_POST['region_id'],$_POST['mirror_baseurl'],$_POST['mirror_rating'])) {
34 set_msg('Mirror added successfully.');
35 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
36 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
37 exit;
38 } else {
39 set_error('Mirror could not be added because of an unknown error.');
40 @@ -26,7 +26,7 @@ if (!empty($_POST['submit'])) {
41 if (!empty($_POST['doit'])) {
42 if (Mirror::update_mirror($_POST['mirror_id'],$_POST['mirror_name'],$_POST['region_id'],$_POST['mirror_baseurl'],$_POST['mirror_rating'])) {
43 set_msg('Mirror updated successfully.');
44 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
45 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
46 exit;
47 } else {
48 set_error('Mirror update failed.');
49
50 diff --git a/php/admin/locations.php b/php/admin/locations.php
51 index 029594e..4069452 100644
52 --- a/php/admin/locations.php
53 +++ b/php/admin/locations.php
54 @@ -11,7 +11,7 @@ require_once('../cfg/init.php');
55 if (!empty($_POST['add-submit'])&&!empty($_POST['location_path'])) {
56 if (Mirror::insert_location($_POST['product_id'],$_POST['os_id'],$_POST['location_path'])) {
57 set_msg('Location added successfully.');
58 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/locations.php');
59 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/locations.php');
60 exit;
61 } else {
62 set_error('Location could not be added because of an unknown error.');
63 @@ -26,7 +26,7 @@ if (!empty($_POST['submit'])) {
64 if (!empty($_POST['doit'])) {
65 if (Mirror::update_location($_POST['location_id'],$_POST['product_id'],$_POST['os_id'],$_POST['location_path'])) {
66 set_msg('Location updated successfully.');
67 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/locations.php');
68 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/locations.php');
69 exit;
70 } else {
71 set_error('Location update failed.');
72
73 diff --git a/php/admin/login.php b/php/admin/login.php
74 index 455c556..51c7ee4 100644
75 --- a/php/admin/login.php
76 +++ b/php/admin/login.php
77 @@ -11,7 +11,7 @@ require_once(LIB.'/auth.php');
78 if (!empty($_POST['submit'])) {
79 if ($auth = Auth::query($_POST['username'],$_POST['password'])) {
80 Auth::create_session($auth);
81 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
82 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
83 exit;
84 } else {
85 $msg = 'Authentication failed. Please check username and password and try again.';
86
87 diff --git a/php/admin/logout.php b/php/admin/logout.php
88 index f876efe..0219191 100644
89 --- a/php/admin/logout.php
90 +++ b/php/admin/logout.php
91 @@ -7,4 +7,4 @@
92 require_once('../cfg/init.php');
93 require_once(LIB.'/auth.php');
94 Auth::logout();
95 -header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/login.php');
96 +header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/login.php');
97
98 diff --git a/php/admin/os.php b/php/admin/os.php
99 index 8be6c0e..f554094 100644
100 --- a/php/admin/os.php
101 +++ b/php/admin/os.php
102 @@ -11,7 +11,7 @@ require_once('../cfg/init.php');
103 if (!empty($_POST['add-submit'])&&!empty($_POST['os_name'])) {
104 if (Mirror::insert_os($_POST['os_name'],$_POST['os_priority'])) {
105 set_msg('OS added successfully.');
106 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/os.php');
107 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/os.php');
108 exit;
109 } else {
110 set_error('OS could not be added because of an unknown error.');
111 @@ -26,7 +26,7 @@ if (!empty($_POST['submit'])) {
112 if (!empty($_POST['doit'])) {
113 if (Mirror::update_os($_POST['os_id'],$_POST['os_name'],$_POST['os_priority'])) {
114 set_msg('OS updated successfully.');
115 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/os.php');
116 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/os.php');
117 exit;
118 } else {
119 set_error('OS update failed.');
120
121 diff --git a/php/admin/products.php b/php/admin/products.php
122 index fbf5e87..d97efdc 100644
123 --- a/php/admin/products.php
124 +++ b/php/admin/products.php
125 @@ -11,7 +11,7 @@ require_once('../cfg/init.php');
126 if (!empty($_POST['add-submit'])&&!empty($_POST['product_name'])) {
127 if (Mirror::insert_product($_POST['product_name'],$_POST['product_priority'])) {
128 set_msg('Product added successfully.');
129 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/products.php');
130 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/products.php');
131 exit;
132 } else {
133 set_error('Product could not be added because of an unknown error.');
134 @@ -26,7 +26,7 @@ if (!empty($_POST['submit'])) {
135 if (!empty($_POST['doit'])) {
136 if (Mirror::update_product($_POST['product_id'],$_POST['product_name'],$_POST['product_priority'])) {
137 set_msg('Product updated successfully.');
138 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/products.php');
139 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/products.php');
140 exit;
141 } else {
142 set_error('Product update failed.');
143
144 diff --git a/php/admin/regions.php b/php/admin/regions.php
145 index 370f953..5028a03 100644
146 --- a/php/admin/regions.php
147 +++ b/php/admin/regions.php
148 @@ -11,7 +11,7 @@ require_once('../cfg/init.php');
149 if (!empty($_POST['add-submit'])&&!empty($_POST['region_name'])) {
150 if (Mirror::insert_region($_POST['region_name'],$_POST['region_priority'])) {
151 set_msg('Region added successfully.');
152 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/regions.php');
153 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/regions.php');
154 exit;
155 } else {
156 set_error('Region could not be added because of an unknown error.');
157 @@ -26,7 +26,7 @@ if (!empty($_POST['submit'])) {
158 if (!empty($_POST['doit'])) {
159 if (Mirror::update_region($_POST['region_id'],$_POST['region_name'],$_POST['region_priority'])) {
160 set_msg('Region updated successfully.');
161 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/regions.php');
162 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/regions.php');
163 exit;
164 } else {
165 set_error('Region update failed.');
166
167 diff --git a/php/admin/users.php b/php/admin/users.php
168 index c200a70..b3a0d20 100644
169 --- a/php/admin/users.php
170 +++ b/php/admin/users.php
171 @@ -11,7 +11,7 @@ require_once('../cfg/init.php');
172 if (!empty($_POST['add-submit'])&&!empty($_POST['username'])&&!empty($_POST['password'])&&!empty($_POST['rpassword'])) {
173 if (Mirror::insert_user($_POST['username'],$_POST['password'],$_POST['rpassword'],$_POST['user_firstname'],$_POST['user_lastname'],$_POST['user_email'])) {
174 set_msg('User added successfully.');
175 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/users.php');
176 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/users.php');
177 exit;
178 } else {
179 set_error('User could not be added because of an unknown error.');
180 @@ -26,7 +26,7 @@ if (!empty($_POST['submit'])) {
181 if (!empty($_POST['doit'])) {
182 if (Mirror::update_user($_POST['user_id'],$_POST['username'],$_POST['password'],$_POST['rpassword'],$_POST['user_firstname'],$_POST['user_lastname'],$_POST['user_email'])) {
183 set_msg('User updated successfully.');
184 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/users.php');
185 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/users.php');
186 exit;
187 } else {
188 set_error('User update failed.');
189
190 diff --git a/php/cfg/admin_init.php b/php/cfg/admin_init.php
191 index 68f3063..0819201 100644
192 --- a/php/cfg/admin_init.php
193 +++ b/php/cfg/admin_init.php
194 @@ -8,7 +8,7 @@ require_once(LIB.'/auth.php'); // auth functions
195 require_once(LIB.'/forms.php'); // form library
196
197 if (!Auth::is_valid_session()) {
198 - header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/login.php');
199 + header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/login.php');
200 exit;
201 }
202
203
204 diff --git a/php/cfg/init.php b/php/cfg/init.php
205 index 80f545f..20c671e 100644
206 --- a/php/cfg/init.php
207 +++ b/php/cfg/init.php
208 @@ -5,6 +5,8 @@
209 * @subpackage cfg
210 */
211 require_once('config.php'); // config file that defines constants
212 +// Make it easier for variables
213 +$_SERVER['HTTP_PROTO'] = $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
214 require_once(LIB.'/util.php'); // util file for random functions (no SQL here)
215 require_once(LIB.'/csv.php'); // util file for random functions (no SQL here)
216 $start = microtime_float(); // start timer
217
218 diff --git a/php/inc/header.php b/php/inc/header.php
219 index dbe97b2..3f5afdf 100644
220 --- a/php/inc/header.php
221 +++ b/php/inc/header.php
222 @@ -10,11 +10,11 @@ ob_start();
223 <html>
224 <head>
225 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
226 -<link rel="home" title="Home" href="http://www.gentoo.org/">
227 -<link rel="stylesheet" type="text/css" href="http://www.gentoo.org/css/main.css" media="all">
228 +<link rel="home" title="Home" href="https://www.gentoo.org/">
229 +<link rel="stylesheet" type="text/css" href="https://www.gentoo.org/css/main.css" media="all">
230 <link rel="stylesheet" type="text/css" href="<?php echo WEBPATH; ?>/css/screen.css" media="screen">
231
232 -<link rel="icon" href="http://www.gentoo.org/favicon.ico" type="image/png">
233 +<link rel="icon" href="https://www.gentoo.org/favicon.ico" type="image/png">
234 <title><?php echo $title; ?></title>
235 <meta name="robots" content="all">
236 <meta name="keywords" content="gentoo linux distribution source compile">
237
238 diff --git a/php/index.php b/php/index.php
239 index b925502..d1d4733 100644
240 --- a/php/index.php
241 +++ b/php/index.php
242 @@ -77,4 +77,4 @@ catch (Exception $ex) {
243
244
245 // if we get here, the request was invalid; redirect to Gentoo home
246 -header('Location: http://www.gentoo.org/');
247 +header('Location: https://www.gentoo.org/');
248
249 diff --git a/php/rss/download-counts.php b/php/rss/download-counts.php
250 index 94d96dc..68f4b93 100644
251 --- a/php/rss/download-counts.php
252 +++ b/php/rss/download-counts.php
253 @@ -26,16 +26,16 @@ echo ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
254 echo ' xmlns="http://purl.org/rss/1.0/">'."\n\n";
255
256 // channel details
257 -echo '<channel rdf:about="http://bouncer.gentoo.org/rss/download-counts.php">'."\n";
258 +echo '<channel rdf:about="https://bouncer.gentoo.org/rss/download-counts.php">'."\n";
259 echo ' <title>Gentoo Download Counts</title>'."\n";
260 -echo ' <link>http://www.gentoo.org/</link>'."\n";
261 +echo ' <link>https://www.gentoo.org/</link>'."\n";
262 echo ' <description>Gentoo product download counts pulled from Bouncer database.</description> '."\n";
263
264 // item listing
265 echo ' <items>'."\n";
266 echo ' <rdf:Seq>'."\n";
267 foreach ($data as $product) {
268 - echo ' <rdf:li rdf:resource="http://bouncer.gentoo.org/?product='.$product['product_name'].'&amp;lastmod='.$now.'"/>'."\n";
269 + echo ' <rdf:li rdf:resource="https://bouncer.gentoo.org/?product='.$product['product_name'].'&amp;lastmod='.$now.'"/>'."\n";
270 }
271 echo ' </rdf:Seq>'."\n";
272 echo ' </items>'."\n";
273 @@ -43,10 +43,10 @@ echo '</channel>'."\n\n";
274
275 // item details
276 foreach ($data as $product) {
277 - echo '<item rdf:about="http://bouncer.gentoo.org/?product='.$product['product_name'].'&amp;lastmod='.$now.'">'."\n";
278 + echo '<item rdf:about="https://bouncer.gentoo.org/?product='.$product['product_name'].'&amp;lastmod='.$now.'">'."\n";
279 echo ' <title>'.$product['product_name'].'</title>'."\n";
280 echo ' <description>'.$product['product_count'].'</description>'."\n";
281 - echo ' <link>http://bouncer.gentoo.org/?product='.$product['product_name'].'&amp;lastmod='.$now.'</link>'."\n";
282 + echo ' <link>https://bouncer.gentoo.org/?product='.$product['product_name'].'&amp;lastmod='.$now.'</link>'."\n";
283 echo '</item>'."\n";
284 }