1 |
c8c15bf5
|
Steve Beaver
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
* copyget.inc
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
8f2f85c3
|
Luiz Otavio O Souza
|
* Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
|
9 |
c8c15bf5
|
Steve Beaver
|
* 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 |
ef7e8885
|
Steve Beaver
|
$copyrightfile = "{$g['cf_conf_path']}/copyright";
|
31 |
|
|
$tmpfile = "{$g['cf_conf_path']}/copyright.tmp";
|
32 |
c8c15bf5
|
Steve Beaver
|
$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 |
8b424bca
|
Viktor G
|
global $g, $copyrightfile, $tmpfile, $idfile, $FQDN;
|
40 |
c8c15bf5
|
Steve Beaver
|
|
41 |
|
|
if (file_exists($idfile)) {
|
42 |
|
|
if (function_exists('curl_version')) {
|
43 |
d7769375
|
Steve Beaver
|
$post = ['uid' => file_get_contents($idfile), 'language' => '0', 'edition' => 'community', 'version' => '2'];
|
44 |
c8c15bf5
|
Steve Beaver
|
$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 |
573ec19d
|
Renato Botelho do Couto
|
curl_setopt($ch, CURLOPT_USERAGENT, $g['product_label'] . '/' . $g['product_version']);
|
51 |
c8c15bf5
|
Steve Beaver
|
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 |
8b424bca
|
Viktor G
|
set_curlproxy($ch);
|
56 |
2cb3c56d
|
Steve Beaver
|
|
57 |
c8c15bf5
|
Steve Beaver
|
$response = curl_exec($ch);
|
58 |
|
|
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
59 |
|
|
curl_close($ch);
|
60 |
|
|
|
61 |
|
|
if ($status == 200) {
|
62 |
|
|
// Save to a temporary file
|
63 |
|
|
file_put_contents($tmpfile, $response);
|
64 |
b0945941
|
Luiz Souza
|
// If the file contents are not the same as the existing file, create the trigger to display the new copyright
|
65 |
47944568
|
Steve Beaver
|
if (!file_exists($copyrightfile) || !compare_copytext(file_get_contents($copyrightfile), $response)) {
|
66 |
c8c15bf5
|
Steve Beaver
|
touch("{$g['cf_conf_path']}/copynotice_display");
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
rename($tmpfile, $copyrightfile);
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
}
|
74 |
|
|
|
75 |
3c07f498
|
Tom Embt
|
// Retrieve the copyright data from Netgate.com if
|
76 |
|
|
// the support data file does not exist, or
|
77 |
|
|
// if it is more than a day old and the URL seems resolvable
|
78 |
8cb0120e
|
Viktor G
|
if ((!file_exists($copyrightfile) || (filesize($copyrightfile) == 0) ||
|
79 |
|
|
((time()-filemtime($copyrightfile) > $refreshinterval))) && is_url_hostname_resolvable($FQDN)) {
|
80 |
c8c15bf5
|
Steve Beaver
|
updateCopyright();
|
81 |
|
|
}
|
82 |
47944568
|
Steve Beaver
|
|
83 |
|
|
// Compare the copyright text contained in the first HTML <DIV>
|
84 |
|
|
function compare_copytext ($new, $old) {
|
85 |
|
|
if ((strlen($new) > 0) && (strlen($old) > 0)) {
|
86 |
|
|
$new_divend = strpos($new, "</div>");
|
87 |
|
|
$old_divend = strpos($old, "</div>");
|
88 |
|
|
|
89 |
|
|
if ($new_divend && $old_divend) {
|
90 |
|
|
return(md5(substr($new, 0, $new_divend)) === md5(substr($old, 0, $old_divend)));
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
return false;
|
95 |
|
|
}
|