-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
127 lines (114 loc) · 6.69 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kick UUIDs</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/protobuf.min.js"></script>
<style>
.container {
text-align: center;
}
.center-div {
width: 800px;
margin: 0 auto;
background-color: lightblue;
}
.other-div {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="other-div" />
<div class="center-div">
<h1>UUID as a Service</h1>
<p>This interface enables the registration of UUIDs with your NRGkick cable. <br />No warranty, nothing. Use at your own risk. Good luck! :-)</p>
<input type="text" id="ipInput" placeholder="Enter IP">
<input type="text" id="pinInput" placeholder="last 7 numbers of serial">
<input type="text" id="uuidInput" size="36" placeholder="set desired UUID here">
<br />
<button id="connectButton">Kick!</button>
<button id="generateUUIDButton">Generate UUID</button>
<p>The serial number, or 'access code,' is the 7 digits preceding the letter 'S' in your NRGkick's serial number, found on the device's back. Use the 'Generate UUID' button for easy creation of a UUID. Be sure to note down this UUID, as it must be specified with all commands sent to the cable.</p>
<p id="result"></p>
<script>
protobuf.load("https://raw.githubusercontent.com/dupondje/nrgkick-proto/main/nrgcp.proto", function(err, root) {
if (err) {
throw err;
}
window.Nrgcp = root.lookupType("nrgkick.Nrgcp");
window.Nrgcp_Header = root.lookupType("nrgkick.Nrgcp.Header");
window.Nrgcp_Metadata = root.lookupType("nrgkick.Nrgcp.Metadata");
window.Nrgcp_Payload = root.lookupType("nrgkick.Nrgcp.Payload");
window.Nrgcp_Payload_DeviceControl_Info_Update = root.lookupType("nrgkick.NrgcpDevicecontrolInfoUpdatePayload");
window.Nrgcp_Payload_DeviceControl_Info_Update_DevicePin = root.lookupType("nrgkick.NrgcpDevicecontrolInfoUpdatePayload.DevicePin");
window.Nrgcp_Types = root.lookupType("nrgkick.NrgcpTypes");
});
function blobToUint8Array(blob, callback) {
const reader = new FileReader();
reader.onload = function() {
const arrayBuffer = reader.result;
const uint8Array = new Uint8Array(arrayBuffer);
callback(uint8Array);
};
reader.onerror = function(error) {
console.error("Error reading blob as array buffer:", error);
};
reader.readAsArrayBuffer(blob);
}
document.getElementById('generateUUIDButton').addEventListener('click', function() {
document.getElementById('uuidInput').value = crypto.randomUUID();
});
document.getElementById('connectButton').addEventListener('click', function() {
var ip = document.getElementById('ipInput').value;
if(ip) {
var websocket = new WebSocket('ws://' + ip + ':8765');
var request = window.Nrgcp.create();
request.header = window.Nrgcp_Header.create()
request.metadata = window.Nrgcp_Metadata.create()
request.payload = window.Nrgcp_Payload.create()
request.payload.DEVICECONTROL_INFO_UPDATE = window.Nrgcp_Payload_DeviceControl_Info_Update.create()
request.payload.DEVICECONTROL_INFO_UPDATE.devicePin = window.Nrgcp_Payload_DeviceControl_Info_Update_DevicePin.create();
request.header.type = window.Nrgcp_Header.Type.UPDATE;
request.header.service = window.Nrgcp_Header.Service.DEVICE_CONTROL;
request.header.property = window.Nrgcp_Header.Property.INFO;
request.metadata.requestId = crypto.randomUUID().slice(0, 8);
request.payload.DEVICECONTROL_INFO_UPDATE.devicePin.accessControlState = window.Nrgcp_Types.AccessControlState.AUTHORIZE_CLIENT;
request.payload.DEVICECONTROL_INFO_UPDATE.devicePin.pin = document.getElementById('pinInput').value.toString();
request.payload.DEVICECONTROL_INFO_UPDATE.devicePin.uuid = document.getElementById('uuidInput').value.toString();
var buffer = Nrgcp.encode(request).finish();
websocket.addEventListener('open', (event) => {
console.log("Connection opened:", event);
websocket.send(buffer);
});
websocket.addEventListener('message', (event) => {
console.log("Message received.", event);
blobToUint8Array(event.data, function(uint8Array) {
var response = window.Nrgcp.decode(uint8Array);
console.log("Decoded response: ", response);
if (response.header.status == window.Nrgcp_Header.Status.ACCEPTED
&& response.header.service == window.Nrgcp_Header.Service.DEVICE_CONTROL
&& response.header.type == window.Nrgcp_Header.Type.UPDATE
&& response.header.property == window.Nrgcp_Header.Property.INFO) {
document.getElementById('result').innerHTML = "<h2>Kicked.</h2>";
} else {
document.getElementById('result').innerHTML = "<h2>Failed to kick. Please check your values.</h2>";
}
});
});
websocket.addEventListener('close', (event) => {
console.log("Connection closed.", event);
});
} else {
alert("Please enter a valid IP.");
}
});
</script>
<div>
<div class="other-div" />
</div>
</body>
</html>