'sanitize_search_string']);
$page = basename(str_replace('.html', '.md', grv('page')));
$fgc_contextoption = [
'ssl' => [
'verify_peer' => true,
'verify_peer_name' => true,
'allow_self_signed' => false,
'timeout' => 2,
'ignore_errors' => true
],
'http' => [
'follow_location' => 0
]
];
if (read_config_option('local_documentation') != 'on') {
$fgc_context = stream_context_create($fgc_contextoption);
$contents = @file_get_contents('https://docs.cacti.net/' . $page, false, $fgc_context);
$response_code = http_response_code();
} else {
$contents = '';
$response_code = 200;
}
if ($response_code != 200) {
print json_encode(
[
'status' => 'Not Reachable',
'message' => __('The Document page \'%s\' count not be reached. The Cacti Documentation site is not reachable. The http error was \'%s\'. Consider downloading an official release to obtain the latest documentation and hosting the documentation locally.', $page, $response_code)
]
);
} elseif ($contents != '' && !preg_match('/does not appear to exist/i', $contents)) {
print json_encode(
[
'status' => 'Success',
'location' => 'https://docs.cacti.net/' . $page
]
);
} elseif ($contents != '' && preg_match('/does not appear to exist/i', $contents)) {
print json_encode(
[
'status' => 'Not Found',
'location' => __esc('The Help File %s was not located on the Cacti Documentation Website.', $page) . '
' . __esc('Open a ticket at ') . '' . __esc('Cacti GitHub Site') . '.'
]
);
} elseif (file_exists(CACTI_PATH_DOCS . '/' . $page)) {
print json_encode(
[
'status' => 'Success',
'location' => CACTI_PATH_URL . 'docs/' . $page
]
);
} else {
print json_encode(
[
'status' => 'Not Reachable',
'message' => __('The Document page \'%s\' count not be reached locally.', $page, $response_code)
]
);
}
}