Files
libhalo/cli/assets/views/ws_client.html
Robby Klein 3ebe41ee84 Bridge/Gateway: Modify CSS styles of the in-app webpages (#244)
Co-authored-by: Michal Leszczynski <ml@icedev.pl>
2023-08-19 13:12:42 +02:00

140 lines
5.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>HaLo Bridge Server</title>
<link rel="stylesheet" href="/assets/static/style.css" />
</head>
<body>
<div class="container">
<div class="box">
<h1>HaLo Bridge Server</h1>
<p>
This is the example web application of HaLo Bridge Server. Please
connect your PC/SC reader and tap the compatible HaLo tag.
</p>
<pre
class="log-box"
id="log"
style="word-break: break-all; white-space: pre-wrap"
>
Connecting to the server...</pre
>
</div>
<svg
xmlns="http://www.w3.org/2000/svg"
width="58"
height="20"
fill="none"
viewBox="0 0 58 20"
>
<path
fill="currentColor"
d="M34.263 5.253h-6.616v14.238h-4.75V6.694A6.189 6.189 0 0 1 29.09.507h5.174v4.746ZM20.014.51v18.98h-4.75v-.982A9.964 9.964 0 0 1 10.007 20C4.481 19.998 0 15.523 0 9.999 0 4.475 4.481 0 10.007 0c1.93 0 3.73.548 5.257 1.492V.51h4.75ZM15.264 10a5.255 5.255 0 0 0-5.257-5.253 5.255 5.255 0 0 0-5.257 5.253 5.255 5.255 0 0 0 5.257 5.253 5.255 5.255 0 0 0 5.257-5.253Zm36.114 0 1.857-2.784L57.709.51H52l-4.014 6.017-.027.04-.054.08a6.182 6.182 0 0 0-.918 2.42h-.142a6.123 6.123 0 0 0-.919-2.418l-.052-.082-.027-.04L41.833.51h-5.708l2.46 3.683L42.457 10l-1.857 2.784-4.474 6.708h5.709l4.014-6.018.027-.04.054-.08c.465-.719.783-1.54.918-2.42h.142c.133.88.454 1.701.919 2.418l.052.081.027.041 4.014 6.018h5.708l-2.459-3.684L51.378 10Z"
></path>
</svg>
</div>
<script src="/assets/static/libhalo.js"></script>
<script>
let wsp = null;
const wsPort = {{ wsPort }};
const wssPort = {{ wssPort }};
function log(data) {
console.log(data);
document.getElementById('log').innerText += '\n' + data;
}
async function execHaloCommand(command) {
log('Executing command: ' + JSON.stringify(command));
let res = await wsp.sendRequest(command);
if (res.event === "exec_success") {
log('Command executed successfully: ' + JSON.stringify(res));
} else if (res.event === "exec_exception") {
log('[!] Failed to execute command: ' + JSON.stringify(res));
} else {
log('Unknown response: ' + JSON.stringify(res));
}
}
async function processTag(handle) {
await execHaloCommand({
"type": "exec_halo",
"handle": handle,
"command": {
"name": "get_pkeys"
}
});
await execHaloCommand({
"type": "exec_halo",
"handle": handle,
"command": {
"name": "sign",
"message": "010203",
"keyNo": 1
}
});
}
async function run() {
let wsAddress = await haloFindBridge({
wsPort: wsPort,
wssPort: wssPort
});
wsp = haloCreateWs(wsAddress);
wsp.onUnpackedMessage.addListener(async ev => {
if (ev.event !== "exec_success" && ev.event !== "exec_exception") {
switch (ev.event) {
case 'ws_connected':
log('Connected to the server.');
break;
case 'reader_added':
log('Reader connected: ' + ev.data.reader_name);
break;
case 'reader_removed':
log('Reader disconnected: ' + ev.data.reader_name);
break;
case 'handle_added':
log('Detected tag: ' + ev.data.reader_name + ' (handle: ' + ev.data.handle + ')');
break;
case 'handle_removed':
log('Removed tag: ' + ev.data.reader_name + ' (handle: ' + ev.data.handle + ')');
break;
case 'handle_not_compatible':
log('Detected incompatible tag: ' + ev.data.reader_name + ' (message: ' + ev.data.message + ')');
break;
}
}
if (ev.event === "handle_added") {
await processTag(ev.data.handle);
}
});
wsp.onClose.addListener(event => {
if (event.code === 1006) {
log('IMPORTANT: You might be missing a local certificate, which is required for halo-bridge on Safari. ' +
'If the halo-bridge doesn\'t work at all, please try to reinstall the entire toolset using the ' +
'release PKG file. When the installer will ask you about certificate generation, ' +
'please choose "Generate certificate" option.');
}
if (event.code === 4001) {
log('Connection closed, new client has connected.');
} else {
log('Connection closed: ' + event.code);
}
});
wsp.open();
}
run();
</script>
</body>
</html>