Explorar o código

Update system now uses HTTPS connection

- Add some curl checks
- Refactor code
Marien Fressinaud %!s(int64=11) %!d(string=hai) anos
pai
achega
909d8747ba
Modificáronse 2 ficheiros con 33 adicións e 29 borrados
  1. 32 28
      app/Controllers/updateController.php
  2. 1 1
      constants.php

+ 32 - 28
app/Controllers/updateController.php

@@ -44,43 +44,47 @@ class FreshRSS_update_Controller extends Minz_ActionController {
 
 		$c = curl_init(FRESHRSS_UPDATE_WEBSITE);
 		curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
+		curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
+		curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
 		$result = curl_exec($c);
+		$c_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
+		curl_close($c);
 
-		if (curl_getinfo($c, CURLINFO_HTTP_CODE) == 200) {
-			$res_array = explode("\n", $result, 2);
-			$status = $res_array[0];
-
-			if (strpos($status, 'UPDATE') === 0) {
-				$script = $res_array[1];
-				if (file_put_contents(UPDATE_FILENAME, $script) !== false) {
-					$this->view->message = array(
-						'status' => 'good',
-						'title' => _t('ok'),
-						'body' => _t('update_can_apply', _url('update', 'apply'))
-					);
-				} else {
-					$this->view->message = array(
-						'status' => 'bad',
-						'title' => _t('damn'),
-						'body' => _t('update_problem', 'Cannot save the update script')
-					);
-				}
-			} else {
-				$this->view->message = array(
-					'status' => 'bad',
-					'title' => _t('damn'),
-					'body' => _t('no_update')
-				);
-			}
-		} else {
+		if ($c_status !== 200) {
 			$this->view->message = array(
 				'status' => 'bad',
 				'title' => _t('damn'),
 				'body' => _t('update_server_not_found', FRESHRSS_UPDATE_WEBSITE)
 			);
+			return;
 		}
 
-		curl_close($c);
+		$res_array = explode("\n", $result, 2);
+		$status = $res_array[0];
+		if (strpos($status, 'UPDATE') !== 0) {
+			$this->view->message = array(
+				'status' => 'bad',
+				'title' => _t('damn'),
+				'body' => _t('no_update')
+			);
+
+			return;
+		}
+
+		$script = $res_array[1];
+		if (file_put_contents(UPDATE_FILENAME, $script) !== false) {
+			$this->view->message = array(
+				'status' => 'good',
+				'title' => _t('ok'),
+				'body' => _t('update_can_apply', _url('update', 'apply'))
+			);
+		} else {
+			$this->view->message = array(
+				'status' => 'bad',
+				'title' => _t('damn'),
+				'body' => _t('update_problem', 'Cannot save the update script')
+			);
+		}
 	}
 
 	public function applyAction() {

+ 1 - 1
constants.php

@@ -1,7 +1,7 @@
 <?php
 define('FRESHRSS_VERSION', '0.8-dev');
 define('FRESHRSS_WEBSITE', 'http://freshrss.org');
-define('FRESHRSS_UPDATE_WEBSITE', 'http://update.freshrss.org?v=' . FRESHRSS_VERSION);
+define('FRESHRSS_UPDATE_WEBSITE', 'https://update.freshrss.org?v=' . FRESHRSS_VERSION);
 
 // PHP text output compression http://php.net/ob_gzhandler (better to do it at Web server level)
 define('PHP_COMPRESSION', false);