Skip to content

Commit c6f3bdc

Browse files
committed
+feat: expire date to certs.h
+fix: statistics bar title
1 parent e3aa058 commit c6f3bdc

3 files changed

Lines changed: 65 additions & 10 deletions

File tree

fetch_certs.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# Fetch root CA certs for SmartSwitch TLS validation.
3+
# Run this to renew certs.h when root CAs change.
4+
# Usage: ./fetch_certs.sh (from workspace root)
5+
6+
set -e
7+
8+
OUT="smartswitch.espxx/include/certs.h"
9+
10+
get_root_ca() {
11+
local host=$1
12+
local port=${2:-443}
13+
openssl s_client -connect "$host:$port" -showcerts </dev/null 2>/dev/null \
14+
| awk '/-----BEGIN CERTIFICATE-----/{cert=""} {cert=cert $0 "\n"} /-----END CERTIFICATE-----/{last=cert} END{printf "%s", last}'
15+
}
16+
17+
echo "Fetching root CA for api.github.com ..."
18+
GITHUB_CA=$(get_root_ca api.github.com)
19+
20+
echo "Fetching root CA for api.forecast.solar ..."
21+
FORECAST_CA=$(get_root_ca api.forecast.solar)
22+
23+
GITHUB_CN=$(echo "$GITHUB_CA" | openssl x509 -noout -subject 2>/dev/null | sed 's/.*CN\s*=\s*//' | sed 's/,.*//')
24+
GITHUB_EXP=$(echo "$GITHUB_CA" | openssl x509 -noout -enddate 2>/dev/null | sed 's/notAfter=//')
25+
26+
FORECAST_CN=$(echo "$FORECAST_CA" | openssl x509 -noout -subject 2>/dev/null | sed 's/.*CN\s*=\s*//' | sed 's/,.*//')
27+
FORECAST_EXP=$(echo "$FORECAST_CA" | openssl x509 -noout -enddate 2>/dev/null | sed 's/notAfter=//')
28+
29+
{
30+
cat << 'HEADER'
31+
#pragma once
32+
// Auto-generated by fetch_certs.sh — do not edit manually.
33+
// Re-run fetch_certs.sh to renew when root CAs expire.
34+
#ifdef ESP32
35+
static const char ROOT_CA_BUNDLE[] PROGMEM =
36+
HEADER
37+
38+
printf ' // %s — expires %s\n' "$GITHUB_CN" "$GITHUB_EXP"
39+
echo "$GITHUB_CA" | sed 's/\(.*\)/ "\1\\n"/'
40+
41+
printf ' // %s — expires %s\n' "$FORECAST_CN" "$FORECAST_EXP"
42+
echo "$FORECAST_CA" | sed 's/\(.*\)/ "\1\\n"/'
43+
44+
cat << 'FOOTER'
45+
;
46+
#endif // ESP32
47+
FOOTER
48+
} > "$OUT"
49+
50+
echo ""
51+
echo "${OUT} updated."
52+
echo " api.github.com: CN=${GITHUB_CN}, expires ${GITHUB_EXP}"
53+
echo " api.forecast.solar: CN=${FORECAST_CN}, expires ${FORECAST_EXP}"

nginx/app.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function renderLog(el, ls, nm) {
112112
});
113113
}
114114

115-
function batteryInfo(){
115+
function batteryInfo() {
116116
const overlay = document.getElementById("batInfoOverlay");
117117
overlay.classList.add("active");
118118
}
@@ -145,8 +145,8 @@ function renderConsStats(dayIdx) {
145145
const yAxis = document.getElementById("statsYAxis");
146146
if (yAxis) {
147147
yAxis.innerHTML = "";
148-
[maxVal + " Wh", Math.round(maxVal / 2) + " Wh", "0 Wh"].forEach(v => {
149-
const s = document.createElement("span"); s.textContent = v; yAxis.appendChild(s);
148+
[maxVal, Math.round(maxVal / 2), 0].forEach(v => {
149+
const s = document.createElement("span"); s.textContent = (v + " Wh"); yAxis.appendChild(s);
150150
});
151151
}
152152
const bars = document.getElementById("statsBars");
@@ -157,7 +157,7 @@ function renderConsStats(dayIdx) {
157157
const bar = document.createElement("div");
158158
bar.className = "bar" + (h === new Date().getHours() && dayIdx === new Date().getDay() ? " bar-now" : "");
159159
bar.style.height = Math.round(v / maxVal * 100) + "%";
160-
bar.title = h + ":00 — " + v + " W";
160+
bar.title = h + ":00 — " + v + " Wh";
161161
col.appendChild(bar);
162162
bars.appendChild(col);
163163
});
@@ -172,7 +172,7 @@ function renderConsStats(dayIdx) {
172172
}
173173
}
174174

175-
function sendUpdate(payload){
175+
function sendUpdate(payload) {
176176
fetch("/api/update", {
177177
method: "POST",
178178
headers: {
@@ -182,18 +182,18 @@ function sendUpdate(payload){
182182
});
183183
}
184184

185-
function toggleLoadPowerFields(isLoading){
185+
function toggleLoadPowerFields(isLoading) {
186186
document.getElementById("sn_loadpower").disabled = isLoading;
187187
const btn = document.getElementById("calibrateBtn");
188188
btn.disabled = isLoading;
189-
if(isLoading){
189+
if (isLoading) {
190190
btn.classList.add("loading");
191-
}else{
191+
} else {
192192
btn.classList.remove("loading");
193193
}
194194
}
195195

196-
function triggerCalibrate(){
196+
function triggerCalibrate() {
197197
toggleLoadPowerFields(true);
198198
sendUpdate("calibrate");
199199
}

smartswitch.espxx/include/certs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
22
// Auto-generated by fetch_certs.sh — do not edit manually.
3-
// Re-run fetch_certs.sh to renew when root CAs change.
3+
// Re-run fetch_certs.sh to renew when root CAs expire.
44
#ifdef ESP32
55
static const char ROOT_CA_BUNDLE[] PROGMEM =
6+
// Sectigo Public Server Authentication Root E46 — expires Jan 18 23:59:59 2038 GMT
67
"-----BEGIN CERTIFICATE-----\n"
78
"MIIDRjCCAsugAwIBAgIQGp6v7G3o4ZtcGTFBto2Q3TAKBggqhkjOPQQDAzCBiDEL\n"
89
"MAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNl\n"
@@ -23,6 +24,7 @@ static const char ROOT_CA_BUNDLE[] PROGMEM =
2324
"PKpqGGuZ61JZryjFsp+DFpEclCVy4noCMQCwvZDXD/m2Ko1HA5Bkmz7YQOFAiNDD\n"
2425
"49IWa2wdT7R3DtODaSXH/BiXv8fwB9su4tU=\n"
2526
"-----END CERTIFICATE-----\n"
27+
// R12 — expires Mar 12 23:59:59 2027 GMT
2628
"-----BEGIN CERTIFICATE-----\n"
2729
"MIIFBjCCAu6gAwIBAgIRAMISMktwqbSRcdxA9+KFJjwwDQYJKoZIhvcNAQELBQAw\n"
2830
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n"

0 commit comments

Comments
 (0)