Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions www/include/checkOnline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

$ALLOWED_PROTOCOLS = CURLPROTO_HTTP | CURLPROTO_HTTPS;
$TIMEOUT = 10;

if (!empty($_POST['url'])) {
$url = $_POST['url'];

$request = curl_init($url);

curl_setopt($request, CURLOPT_PROTOCOLS, $ALLOWED_PROTOCOLS);
curl_setopt($request, CURLOPT_CONNECTTIMEOUT, $TIMEOUT);
curl_setopt($request, CURLOPT_FOLLOWLOCATION, true);

$response = curl_exec($request);

if ($response)
$status_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
else
$status_code = 502;

curl_close($request);

http_response_code($status_code);
}
?>
14 changes: 7 additions & 7 deletions www/include/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ function createSections() {
async function checkOnline(thisUrl, thisId) {
//reads all tiles from settings and sets their respective indicators to green
const options = {
method: 'GET',
mode: 'no-cors',
connection: 'close'
method: 'POST',
body: new URLSearchParams({
url: thisUrl
})
};


const response = await fetch(thisUrl,options);
if (response.status = 200) {
const response = await fetch('include/checkOnline.php', options);
if (response.ok) {
thisId.className = thisId.className.replace(/dot(?!\S)/g, 'dot dot-green');

//this theming needs to be done here because js can't change style of future elements of a class
Expand Down Expand Up @@ -242,4 +242,4 @@ function refreshWidgetGlances(nW) {
$.getJSON({url: gSettings.widgets[nW].settings.url + 'api/3/sensors'}).done(function (result, status, xhr) {
document.getElementById('cpuTemp' + nW).innerText = (result.length > 0? result[0].value + 'C' : '-')
});
}
}