Completed
Push — stable8 ( f0fddd...5d5dda )
by
unknown
27:14
created

testremote.php ➔ testUrl()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
eloc 7
nc 6
nop 1
dl 0
loc 10
rs 9.2
1
<?php
2
/**
3
 * Copyright (c) 2014 Robin Appelman <[email protected]>
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
OCP\JSON::callCheck();
10
OCP\JSON::checkAppEnabled('files_sharing');
11
12
$remote = $_GET['remote'];
13
14
function testUrl($url) {
15
	try {
16
		$result = file_get_contents($url);
17
		$data = json_decode($result);
18
		// public link mount is only supported in ownCloud 7+
19
		return is_object($data) and !empty($data->version) and version_compare($data->version, '7.0.0', '>=');
20
	} catch (Exception $e) {
21
		return false;
22
	}
23
}
24
25
if (testUrl('https://' . $remote . '/status.php')) {
26
	echo 'https';
27
} elseif (testUrl('http://' . $remote . '/status.php')) {
28
	echo 'http';
29
} else {
30
	echo 'false';
31
}
32