Skip to content

Commit d752272

Browse files
committed
add
1 parent 431a775 commit d752272

File tree

6 files changed

+234
-81
lines changed

6 files changed

+234
-81
lines changed

assets/js/dark-mode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ document.addEventListener('DOMContentLoaded', function () {
2222
? '/assets/images/avatar_dark.png'
2323
: '/assets/images/avatar.jpg';
2424
} else {
25-
console.error('Avatar image element not found!');
25+
console.log('Avatar image element not found!');
2626
}
2727
}
2828

assets/js/online.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
document.addEventListener('DOMContentLoaded', function () {
2+
fetch('https://www.lzwjava.xyz/bandwidth')
3+
.then(response => response.json())
4+
.then(data => {
5+
var bandwidthData = JSON.parse(data);
6+
var status = bandwidthData.interfaces[0].traffic.total.rx + bandwidthData.interfaces[0].traffic.total.tx > 0 ? 'Online' : 'Offline';
7+
document.getElementById('status').textContent = 'Status: ' + status;
8+
9+
// Create a table
10+
var table = document.createElement('table');
11+
table.border = '1';
12+
table.style.borderCollapse = 'collapse';
13+
table.style.width = '100%';
14+
15+
// Create table header
16+
var thead = document.createElement('thead');
17+
var tr = document.createElement('tr');
18+
var headers = ['UTC Time', 'Local Time', 'Traffic (KB/s)'];
19+
headers.forEach(headerText => {
20+
var th = document.createElement('th');
21+
th.textContent = headerText;
22+
tr.appendChild(th);
23+
});
24+
thead.appendChild(tr);
25+
table.appendChild(thead);
26+
27+
// Create table body
28+
var tbody = document.createElement('tbody');
29+
var fiveMinuteData = bandwidthData.interfaces[0].traffic.fiveminute.reverse();
30+
fiveMinuteData.forEach(interval => {
31+
var tr = document.createElement('tr');
32+
33+
var utcTime = new Date(Date.UTC(interval.date.year, interval.date.month - 1, interval.date.day, interval.time.hour, interval.time.minute));
34+
var localTime = new Date(utcTime.getTime());
35+
36+
var tdUtcTime = document.createElement('td');
37+
tdUtcTime.textContent = `${utcTime.getUTCFullYear().toString().slice(-2)}-${String(utcTime.getUTCMonth() + 1).padStart(2, '0')}-${String(utcTime.getUTCDate()).padStart(2, '0')} ${String(utcTime.getUTCHours()).padStart(2, '0')}:${String(utcTime.getUTCMinutes()).padStart(2, '0')}`;
38+
tr.appendChild(tdUtcTime);
39+
40+
var tdLocalTime = document.createElement('td');
41+
tdLocalTime.textContent = `${localTime.getFullYear().toString().slice(-2)}-${String(localTime.getMonth() + 1).padStart(2, '0')}-${String(localTime.getDate()).padStart(2, '0')} ${String(localTime.getHours()).padStart(2, '0')}:${String(localTime.getMinutes()).padStart(2, '0')}`;
42+
tr.appendChild(tdLocalTime);
43+
44+
var tdRXKBs = document.createElement('td');
45+
tdRXKBs.textContent = ((interval.rx + interval.tx) / (2 * 5 * 60 * 1024)).toFixed(2); // Convert to KB/s
46+
tr.appendChild(tdRXKBs);
47+
48+
tbody.appendChild(tr);
49+
});
50+
table.appendChild(tbody);
51+
52+
// Append the table to the status div
53+
document.getElementById('status').appendChild(table);
54+
})
55+
.catch(error => {
56+
console.error('Error fetching bandwidth data:', error);
57+
});
58+
});

assets/js/vnet.json

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{
2+
"vnstatversion": "2.9",
3+
"jsonversion": "2",
4+
"interfaces": [
5+
{
6+
"name": "docker0",
7+
"alias": "",
8+
"created": {
9+
"date": {
10+
"year": 2025,
11+
"month": 1,
12+
"day": 3
13+
}
14+
},
15+
"updated": {
16+
"date": {
17+
"year": 2025,
18+
"month": 1,
19+
"day": 3
20+
},
21+
"time": {
22+
"hour": 23,
23+
"minute": 45
24+
}
25+
},
26+
"traffic": {
27+
"total": {
28+
"rx": 4231,
29+
"tx": 14169
30+
},
31+
"day": [
32+
{
33+
"id": 4,
34+
"date": {
35+
"year": 2025,
36+
"month": 1,
37+
"day": 3
38+
},
39+
"rx": 4231,
40+
"tx": 14169
41+
}
42+
]
43+
}
44+
},
45+
{
46+
"name": "eth0",
47+
"alias": "",
48+
"created": {
49+
"date": {
50+
"year": 2025,
51+
"month": 1,
52+
"day": 3
53+
}
54+
},
55+
"updated": {
56+
"date": {
57+
"year": 2025,
58+
"month": 1,
59+
"day": 3
60+
},
61+
"time": {
62+
"hour": 23,
63+
"minute": 45
64+
}
65+
},
66+
"traffic": {
67+
"total": {
68+
"rx": 364113830,
69+
"tx": 285641619
70+
},
71+
"day": [
72+
{
73+
"id": 3,
74+
"date": {
75+
"year": 2025,
76+
"month": 1,
77+
"day": 3
78+
},
79+
"rx": 364113830,
80+
"tx": 285641619
81+
}
82+
]
83+
}
84+
},
85+
{
86+
"name": "eth1",
87+
"alias": "",
88+
"created": {
89+
"date": {
90+
"year": 2025,
91+
"month": 1,
92+
"day": 3
93+
}
94+
},
95+
"updated": {
96+
"date": {
97+
"year": 2025,
98+
"month": 1,
99+
"day": 3
100+
},
101+
"time": {
102+
"hour": 23,
103+
"minute": 45
104+
}
105+
},
106+
"traffic": {
107+
"total": {
108+
"rx": 420,
109+
"tx": 41006
110+
},
111+
"day": [
112+
{
113+
"id": 2,
114+
"date": {
115+
"year": 2025,
116+
"month": 1,
117+
"day": 3
118+
},
119+
"rx": 420,
120+
"tx": 41006
121+
}
122+
]
123+
}
124+
},
125+
{
126+
"name": "veth1ba2a46",
127+
"alias": "",
128+
"created": {
129+
"date": {
130+
"year": 2025,
131+
"month": 1,
132+
"day": 3
133+
}
134+
},
135+
"updated": {
136+
"date": {
137+
"year": 2025,
138+
"month": 1,
139+
"day": 3
140+
},
141+
"time": {
142+
"hour": 22,
143+
"minute": 40
144+
}
145+
},
146+
"traffic": {
147+
"total": {
148+
"rx": 4819,
149+
"tx": 13949
150+
},
151+
"day": [
152+
{
153+
"id": 1,
154+
"date": {
155+
"year": 2025,
156+
"month": 1,
157+
"day": 3
158+
},
159+
"rx": 4819,
160+
"tx": 13949
161+
}
162+
]
163+
}
164+
}
165+
]
166+
}

scripts/bandwidth_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
@app.route('/bandwidth', methods=['GET'])
99
def get_bandwidth():
10-
result = subprocess.run(['vnstat', '--json', 'd'], capture_output=True, text=True)
10+
# Run the vnstat command to get the 5-minute interval traffic statistics for eth0
11+
result = subprocess.run(['vnstat', '-i', 'eth0', '-5', '--json'], capture_output=True, text=True)
1112
data = result.stdout
13+
14+
# Return the captured data as a JSON response
1215
return jsonify(data)
1316

1417
if __name__ == '__main__':

scripts/nginx.conf

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,22 @@
1-
# Define a map to handle the allowed origins
2-
map $http_origin $cors_origin {
3-
default "https://lzwjava.xyz";
4-
"http://localhost:3000" "http://localhost:3000";
5-
"https://lzwjava.xyz" "https://lzwjava.xyz";
6-
"https://www.lzwjava.xyz" "https://www.lzwjava.xyz";
7-
}
8-
91
# Redirect HTTP to HTTPS
102
server {
113
listen 80;
12-
server_name lzwjava.xyz api.lzwjava.xyz;
4+
server_name www.lzwjava.xyz;
135

146
return 301 https://$host$request_uri;
157
}
168

17-
# Main site configuration for lzwjava.xyz
18-
server {
19-
listen 443 ssl;
20-
listen [::]:443 ssl ipv6only=on; # managed by Certbot
21-
server_name lzwjava.xyz;
22-
23-
ssl_certificate /etc/letsencrypt/live/lzwjava.xyz/fullchain.pem; # managed by Certbot
24-
ssl_certificate_key /etc/letsencrypt/live/lzwjava.xyz/privkey.pem; # managed by Certbot
25-
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
26-
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
27-
28-
ssl_protocols TLSv1.2 TLSv1.3;
29-
ssl_prefer_server_ciphers on;
30-
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
31-
32-
root /home/project/web;
33-
index index.html index.htm index.php default.html default.htm default.php;
34-
35-
location / {
36-
try_files $uri $uri/ =404;
37-
}
38-
39-
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
40-
expires 30d;
41-
}
42-
43-
location ~ .*\.(js|css)?$ {
44-
expires 12h;
45-
}
46-
47-
error_page 404 /index.html;
48-
}
49-
509
# API configuration for api.lzwjava.xyz
5110
server {
5211
listen 443 ssl;
53-
listen [::]:443 ssl ipv6only=on; # managed by Certbot
54-
server_name api.lzwjava.xyz;
12+
server_name www.lzwjava.xyz;
5513

56-
ssl_certificate /etc/letsencrypt/live/lzwjava.xyz/fullchain.pem; # managed by Certbot
57-
ssl_certificate_key /etc/letsencrypt/live/lzwjava.xyz/privkey.pem; # managed by Certbot
14+
ssl_certificate /etc/letsencrypt/live/www.lzwjava.xyz/fullchain.pem; # managed by Certbot
15+
ssl_certificate_key /etc/letsencrypt/live/www.lzwjava.xyz/privkey.pem; # managed by Certbot
5816
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
5917
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
6018

61-
ssl_protocols TLSv1.2 TLSv1.3;
62-
ssl_prefer_server_ciphers on;
63-
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
64-
6519
location / {
66-
# Clear any pre-existing Access-Control headers
67-
more_clear_headers 'Access-Control-Allow-Origin';
68-
69-
# Handle CORS preflight requests
70-
if ($request_method = 'OPTIONS') {
71-
add_header 'Access-Control-Allow-Origin' $cors_origin;
72-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
73-
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization, X-Client-Info, X-Trace-Id, X-Requested-With, X-HTTP-Method-Override, DNT, Keep-Alive, User-Agent, If-Modified-Since, Cache-Control, Content-Range, Range';
74-
add_header 'Access-Control-Max-Age' 3600;
75-
return 204;
76-
}
77-
78-
add_header 'Access-Control-Allow-Origin' $cors_origin always;
79-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
80-
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization, X-Client-Info, X-Trace-Id, X-Requested-With, X-HTTP-Method-Override, DNT, Keep-Alive, User-Agent, If-Modified-Since, Cache-Control, Content-Range, Range' always;
8120

8221
proxy_pass http://127.0.0.1:5000/;
8322
proxy_set_header Host $host;

status.html

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,4 @@
55

66
<div id="status"></div>
77

8-
<script>
9-
document.addEventListener('DOMContentLoaded', function () {
10-
fetch('http://143.198.202.187:5000/bandwidth')
11-
.then(response => response.json())
12-
.then(data => {
13-
var bandwidthData = JSON.parse(data);
14-
var status = bandwidthData.interfaces[0].traffic.total.rx + bandwidthData.interfaces[0].traffic.total.tx > 0 ? 'Online' : 'Offline';
15-
document.getElementById('status').textContent = 'Status: ' + status;
16-
})
17-
.catch(error => {
18-
console.error('Error fetching bandwidth data:', error);
19-
});
20-
});
21-
</script>
8+
<script src="/assets/js/online.js"></script>

0 commit comments

Comments
 (0)