Skip to content

Commit c785ab4

Browse files
authored
github.com/douxxu to github.com/douxxtech
0 parents  commit c785ab4

File tree

6 files changed

+958
-0
lines changed

6 files changed

+958
-0
lines changed

LICENSE

+674
Large diffs are not rendered by default.

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# isitdown
2+
3+
**isitdown** is a simple tool to check whether a website or IP address is up or down. It allows users to enter a URL or IP address, then performs a ping check to determine if the site is online. If the website is up, it shows the response time and additional headers. If it's down, it informs the user accordingly.
4+
5+
You can use this service at [isitdown.douxx.tech](http://isitdown.douxx.tech).
6+
7+
## Features
8+
- Check if a website or IP address is online or down.
9+
- Shows response time and additional information if the site is up.
10+
- Displays a message if the site is down or if the request exceeds the 5-second timeout.
11+
- Simple and intuitive interface with a dark theme.
12+
13+
## Usage
14+
15+
1. Open the site at [isitdown.douxx.tech](http://isitdown.douxx.tech).
16+
2. Enter a URL or IP address in the input field.
17+
3. Click the "Check" button to see if the site is up or down.
18+
4. The result will display the response time and additional information if the site is up, or an error message if the site is down or the request exceeds the timeout.
19+
20+
## License
21+
22+
This project is licensed under the **GPL-3.0 License** - see the [LICENSE](LICENSE) file for details.

api/check.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
function isSiteUp($url) {
3+
$parsedUrl = parse_url($url, PHP_URL_HOST) ?? $url;
4+
$domain = filter_var($parsedUrl, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
5+
6+
if ($domain === false) {
7+
return [
8+
'status' => 'error',
9+
'message' => htmlspecialchars('Invalid URL provided.')
10+
];
11+
}
12+
13+
$output = null;
14+
$statusCode = null;
15+
16+
exec("ping -c 1 -W 5 " . escapeshellarg($domain), $output, $statusCode);
17+
18+
if ($statusCode === 0) {
19+
preg_match('/time=(\d+\.?\d*) ms/', implode("\n", $output), $matches);
20+
$pingTime = $matches[1];
21+
22+
if ($pingTime > 5000) {
23+
return [
24+
'status' => 'down',
25+
'message' => htmlspecialchars('The response time is too long.')
26+
];
27+
}
28+
29+
$headers = @get_headers("http://$domain", 1);
30+
31+
if ($headers) {
32+
foreach ($headers as $key => $value) {
33+
$headers[$key] = htmlspecialchars(
34+
is_array($value) ? implode(', ', array_map('htmlspecialchars', $value)) : $value
35+
);
36+
}
37+
} else {
38+
$headers = htmlspecialchars('Unable to retrieve headers');
39+
}
40+
41+
return [
42+
'status' => 'up',
43+
'ping' => htmlspecialchars($pingTime),
44+
'headers' => $headers
45+
];
46+
} else {
47+
return [
48+
'status' => 'down',
49+
'message' => htmlspecialchars('The site is down.')
50+
];
51+
}
52+
}
53+
54+
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['url'])) {
55+
$url = htmlspecialchars($_POST['url']);
56+
echo json_encode(isSiteUp($url));
57+
}
58+
?>

index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="fr">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Is it down?</title>
7+
<link rel="stylesheet" href="styles/style.css">
8+
<link rel="icon" href="https://douxx.tech/public/icons/icon.png">
9+
</head>
10+
<body>
11+
<div class="container">
12+
<h1>Is it down?</h1>
13+
<form method="POST">
14+
<input type="text" name="url" placeholder="Enter an ip or url" required>
15+
<button type="submit">Check</button>
16+
</form>
17+
18+
<div class="result"></div>
19+
<div class="checking" style="display: none;">
20+
Checking...
21+
</div>
22+
</div>
23+
<script src="scripts/script.js"></script>
24+
</body>
25+
</html>

scripts/script.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
document.querySelector('form').addEventListener('submit', function(e) {
2+
e.preventDefault();
3+
const url = document.querySelector('input[name="url"]').value;
4+
const resultDiv = document.querySelector('.result');
5+
const checkingDiv = document.querySelector('.checking');
6+
7+
checkingDiv.style.display = 'inline-block';
8+
resultDiv.innerHTML = '';
9+
10+
const timeout = 5000;
11+
let timeoutReached = false;
12+
13+
const timeoutId = setTimeout(() => {
14+
timeoutReached = true;
15+
checkingDiv.style.display = 'none';
16+
resultDiv.classList.add('down');
17+
resultDiv.classList.remove('up');
18+
resultDiv.innerHTML = `<p><strong>The site is <span class="down">down</span>.</strong></p>
19+
<h6>Response time exceeded the 5-second limit.</h6>`;
20+
}, timeout);
21+
22+
fetch('api/check.php', {
23+
method: 'POST',
24+
headers: {
25+
'Content-Type': 'application/x-www-form-urlencoded',
26+
},
27+
body: new URLSearchParams({ url: url })
28+
})
29+
.then(response => response.json())
30+
.then(data => {
31+
if (timeoutReached) return;
32+
33+
clearTimeout(timeoutId);
34+
checkingDiv.style.display = 'none';
35+
36+
if (data.status === 'up') {
37+
resultDiv.classList.add('up');
38+
resultDiv.classList.remove('down');
39+
resultDiv.innerHTML = `<p>The site is <strong>online</strong>!</p>
40+
<p>Response time: <strong>${data.ping} ms</strong></p>
41+
<p><strong>Additional information:</strong></p>
42+
<ul>`;
43+
for (let key in data.headers) {
44+
resultDiv.innerHTML += `<li><strong>${key}:</strong> ${Array.isArray(data.headers[key]) ? data.headers[key].join(', ') : data.headers[key]}</li>`;
45+
}
46+
resultDiv.innerHTML += `</ul>`;
47+
} else {
48+
resultDiv.classList.add('down');
49+
resultDiv.classList.remove('up');
50+
resultDiv.innerHTML = `<p><strong>The site is <span class="down">down</span>.</strong></p>`;
51+
52+
if (data.message) {
53+
resultDiv.innerHTML += `<h6>${data.message}</h6>`;
54+
}
55+
}
56+
})
57+
.catch(error => {
58+
checkingDiv.style.display = 'none';
59+
console.log(error);
60+
});
61+
});

styles/style.css

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
body {
2+
background-color: #121212;
3+
color: #fff;
4+
font-family: Arial, sans-serif;
5+
display: flex;
6+
justify-content: center;
7+
align-items: center;
8+
height: 100vh;
9+
margin: 0;
10+
padding: 0;
11+
}
12+
13+
.container {
14+
text-align: center;
15+
max-width: 600px;
16+
padding: 20px;
17+
border-radius: 10px;
18+
background-color: #1f1f1f;
19+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
20+
}
21+
22+
h1 {
23+
color: #00bfae;
24+
font-size: 2em;
25+
}
26+
27+
form {
28+
margin: 20px 0;
29+
}
30+
31+
input[type="text"] {
32+
padding: 10px;
33+
width: 80%;
34+
max-width: 400px;
35+
border: 1px solid #444;
36+
border-radius: 5px;
37+
background-color: #333;
38+
color: #fff;
39+
font-size: 1em;
40+
}
41+
42+
button {
43+
padding: 10px 20px;
44+
margin-top: 10px;
45+
background-color: #00bfae;
46+
border: none;
47+
border-radius: 5px;
48+
color: #fff;
49+
font-size: 1em;
50+
cursor: pointer;
51+
}
52+
53+
button:hover {
54+
background-color: #009f96;
55+
}
56+
57+
.result {
58+
margin-top: 20px;
59+
padding: 15px;
60+
border-radius: 5px;
61+
}
62+
63+
.result.up {
64+
background-color: #2c6f2e;
65+
border: 1px solid #246b26;
66+
}
67+
68+
.result.down {
69+
background-color: #e74c3c;
70+
border: 1px solid #c0392b;
71+
color: #fff;
72+
}
73+
74+
.down {
75+
color: #fff;
76+
}
77+
78+
ul {
79+
text-align: left;
80+
margin-top: 10px;
81+
list-style-type: none;
82+
padding: 0;
83+
}
84+
85+
li {
86+
padding: 5px 0;
87+
}
88+
89+
h6 {
90+
color: #fff;
91+
margin-top: 10px;
92+
}
93+
94+
.checking {
95+
display: inline-block;
96+
padding: 15px;
97+
background-color: #f39c12;
98+
color: #fff;
99+
border-radius: 5px;
100+
font-size: 1.1em;
101+
font-weight: bold;
102+
margin-top: 20px;
103+
}
104+
105+
@keyframes spin {
106+
0% { transform: rotate(0deg); }
107+
100% { transform: rotate(360deg); }
108+
}
109+
110+
.loading {
111+
display: inline-block;
112+
width: 30px;
113+
height: 30px;
114+
border: 4px solid #fff;
115+
border-top: 4px solid #00bfae;
116+
border-radius: 50%;
117+
animation: spin 1s linear infinite;
118+
}

0 commit comments

Comments
 (0)