From b96b6d3ba3e89155449bb3efc807ae14ccc36684 Mon Sep 17 00:00:00 2001 From: Steve Beaver Date: Thu, 20 Jul 2017 13:34:59 -0400 Subject: Add customer support widget --- .../local/www/widgets/widgets/support.widget.php | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/usr/local/www/widgets/widgets/support.widget.php (limited to 'src') diff --git a/src/usr/local/www/widgets/widgets/support.widget.php b/src/usr/local/www/widgets/widgets/support.widget.php new file mode 100644 index 0000000..9955f65 --- /dev/null +++ b/src/usr/local/www/widgets/widgets/support.widget.php @@ -0,0 +1,109 @@ +", "\",\"htmltext\":\"\"}")); +} + +// Poll the Netgate server to obtain the JSON/HTML formatted support information +// and write it to the file /var/db/support.json +function updateSupport() { + global $g, $supportfile, $idfile, $FQDN; + + $success = false; + + if (file_exists($idfile)) { + if (function_exists('curl_version')) { + $post = ['uid' => file_get_contents($idfile), 'language' => '0']; + $url = $FQDN; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_VERBOSE, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . $g['product_version']); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); + $response = curl_exec($ch); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($status == 200) { + file_put_contents($supportfile, $response); + $success = true; + } + } + } + + if (!$success) { + nosupportdata(); + } +} + +// If the widget is called with act=refresh, delete the support.json file and reload hte page, thereby forcing the +// widget to get a fresh copy of hte support information +if ($_REQUEST['act'] == "refresh") { + unlink($supportfile); + header("Location: /"); + exit; +} + +// Retrieve the support data from Netgate.com if the supprt data file does not exist, +// or if it is more than a day old +if (!file_exists($supportfile) || ( time()-filemtime($supportfile) > (24 * 3600))) { + updateSupport(); +} + +$str = file_get_contents($supportfile); +$json = json_decode($str, true); + +print("
"); +print($json['summary']); + +if (strlen($json['htmltext']) > 0) { + print('
'); + print('
'); + print($json['htmltext']); + print('
'); +} + +// Print a low-key refresh link +print('
Refresh
'); + +print("
"); + +?> -- cgit v1.1