Project

General

Profile

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

    
22
/*
23
	Provides the functionality required to fetch updated copyright information from Netgate
24
*/
25

    
26
require_once("guiconfig.inc");
27

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

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

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

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

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

    
65
				rename($tmpfile, $copyrightfile);
66
			}
67
		}
68
	}
69
}
70

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