Project

General

Profile

Download (2.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * copyget.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23

    
24
/*
25
	Provides the functionality required to fetch updated copyright information from Netgate
26
*/
27

    
28
require_once("guiconfig.inc");
29

    
30
$copyrightfile = "{$g['cf_conf_path']}/copyright";
31
$tmpfile = "{$g['cf_conf_path']}/copyright.tmp";
32
$idfile = "/var/db/uniqueid";
33
$FQDN = "https://ews.netgate.com/copyright";
34
$refreshinterval = (24 * 3600);	// 24 hours
35

    
36
// Poll the Netgate server to obtain the JSON/HTML formatted support information
37
// and write it to the JSON file
38
function updatecopyright() {
39
	global $g, $copyrightfile, $tmpfile, $idfile, $FQDN;
40

    
41
	if (file_exists($idfile)) {
42
		if (function_exists('curl_version')) {
43
			$post = ['uid' => file_get_contents($idfile), 'language' => '0', 'edition' => 'community', 'version' => '1'];
44
			$url = $FQDN;
45

    
46
			$ch = curl_init();
47
			curl_setopt($ch, CURLOPT_HEADER, 0);
48
			curl_setopt($ch, CURLOPT_VERBOSE, 0);
49
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
50
			curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . $g['product_version']);
51
			curl_setopt($ch, CURLOPT_URL, $url);
52
			curl_setopt($ch, CURLOPT_POST, true);
53
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
54
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,4);
55
			$response = curl_exec($ch);
56
			$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
57
			curl_close($ch);
58

    
59
			if ($status == 200) {
60
				// Save to a temporary file
61
				file_put_contents($tmpfile, $response);
62
				// If the file contents are not the same as the existing file, create the trigger to display the new copyright
63
				if (!file_exists($copyrightfile) || (md5_file($copyrightfile) != md5_file($tmpfile))) {
64
					touch("{$g['cf_conf_path']}/copynotice_display");
65
				}
66

    
67
				rename($tmpfile, $copyrightfile);
68
			}
69
		}
70
	}
71
}
72

    
73
// Retrieve the copyright data from Netgate.com if the support data file does not exist,
74
// or if it is more than a day old
75
if (!file_exists($copyrightfile) || ( time()-filemtime($copyrightfile) > $refreshinterval)) {
76
	updateCopyright();
77
}
(12-12/60)