forked from snaplet/postgres-wasm
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
215 lines (188 loc) · 6.82 KB
/
index.html
File metadata and controls
215 lines (188 loc) · 6.82 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html>
<head>
<title>IvorySQL in browser</title>
<link rel="stylesheet" href="https://unpkg.com/xterm@5.2.1/css/xterm.css" />
<link rel="stylesheet" href="./styles.css" />
<script src="https://unpkg.com/xterm-addon-fit@0.8.0/lib/xterm-addon-fit.js"></script>
<script src="https://unpkg.com/xterm@5.2.1/lib/xterm.js"></script>
<script src="./lib/libv86.js"></script>
<script>
window.onload = () => {
const baseOptions = {
wasm_path: "./lib/v86.wasm",
memory_size: 128 * 1024 * 1024,
vga_memory_size: 2 * 1024 * 1024,
filesystem: {
basefs: "filesystem/filesystem.json",
baseurl: "filesystem/",
},
screen_container: document.getElementById("screen_container"),
serial_container_xtermjs: document.getElementById("terminal"),
// network_relay_url: "wss://relay.widgetry.org/",
autostart: true,
disable_keyboard: true,
disable_mouse: true,
disable_speaker: true,
acpi: true,
};
const params = new URL(document.location).searchParams;
const boot = params.get("boot") === "true";
if (boot) {
document.getElementById("screen_container").style = "display:block";
document.getElementById("terminal").style = "";
}
const bzimageUrl = "./filesystem/e1d7fc24.bin";
const options = {
...baseOptions,
...(boot
? {
bzimage: {
url: bzimageUrl,
},
cmdline: [
"rw",
"root=host9p rootfstype=9p rootflags=version=9p2000.L,trans=virtio,cache=loose quiet acpi=off console=ttyS0 tsc=reliable mitigations=off random.trust_cpu=on nowatchdog page_poison=on",
].join(" "),
bios: {
url: "./bios/seabios.bin",
},
// vga_bios: {
// url: "./bios/vgabios.bin",
// },
}
: { initial_state: { url: "./state/v86state.bin.zst" } }),
};
var emulator = new V86(options);
function initTerm() {
const fitAddon = new FitAddon.FitAddon();
emulator.serial_adapter.term.loadAddon(fitAddon);
fitAddon.fit();
window.addEventListener("resize", () => fitAddon.fit());
}
function sendBackgroundCommands(commands) {
const filename = `${(Math.random() + 1).toString(36).substring(7)}.sh`;
emulator.create_file(
`/inbox/${filename}`,
new TextEncoder("UTF-8").encode(commands.join("\n"))
);
}
if (!boot) {
emulator.add_listener("emulator-ready", function () {
initTerm();
setTimeout(() => {
sendBackgroundCommands(["/etc/init.d/S40network restart"]);
emulator.serial0_send(
`\\! stty rows ${emulator.serial_adapter.term.rows} cols ${emulator.serial_adapter.term.cols} && reset\n`
);
emulator.serial_adapter.term.focus();
}, 0);
});
}
var state;
document.getElementById("save_restore").onclick = async function () {
var button = this;
if (state) {
button.value = "Save state";
await emulator.restore_state(state);
state = undefined;
} else {
const new_state = await emulator.save_state();
console.log("Saved state of " + new_state.byteLength + " bytes");
button.value = "Restore state";
state = new_state;
}
button.blur();
};
document.getElementById("save_file").onclick = async function () {
const new_state = await emulator.save_state();
var a = document.createElement("a");
a.download = "v86state.bin";
a.href = window.URL.createObjectURL(new Blob([new_state]));
a.dataset.downloadurl =
"application/octet-stream:" + a.download + ":" + a.href;
a.click();
this.blur();
};
document.getElementById("restore_file").onchange = function () {
if (this.files.length) {
var filereader = new FileReader();
emulator.stop();
filereader.onload = async function (e) {
await emulator.restore_state(e.target.result);
emulator.run();
};
filereader.readAsArrayBuffer(this.files[0]);
this.value = "";
}
this.blur();
};
document.getElementById("upload_files").onchange = function (e) {
var files = e.target.files;
for (var i = 0; i < files.length; i++) {
var reader = new FileReader();
reader.onload = (function (file) {
return function (e) {
var data = new TextEncoder("UTF-8").encode(e.target.result);
emulator.create_file("/" + file.name, data);
console.log("uploaded " + file.name);
};
})(files[i]);
reader.readAsText(files[i]);
}
};
const uploadBtns = document.getElementsByClassName("upload-btn");
for (let btn of uploadBtns) {
btn.addEventListener("click", (event) => {
const input = btn.getElementsByTagName("input")[0];
input.click(event);
});
}
};
</script>
</head>
<body>
<div id="screen_container" style="display: none">
<div></div>
<canvas></canvas>
</div>
<div id="menu">
<div>
<input id="save_restore" type="button" value="Save state" />
<input id="save_file" type="button" value="Save state to file" />
</div>
<div style="display: flex">
<div class="upload-btn">
<input id="restore_file" type="file" hidden />
<p>Restore from file</p>
</div>
<div class="upload-btn">
<input id="upload_files" type="file" multiple hidden />
<p>Upload files to the emulator</p>
</div>
<input id="home_button" type="button" value="Home" />
<input id="help_button" type="button" value="Help" />
</div>
</div>
<div style="text-align: center; margin: 30px; font-size: 24px; color: #f5f1f1;">
Welcome to IvorySQL v{{version}} online trial
</div>
<div class="container">
<div class="xterminal">
<div id="terminal"></div>
</div>
</div>
<div style="text-align: center; margin: 50px; font-size: 12px; color: #888;">
Any comments please contact <a href="mailto:support@ivorysql.org"style="color: #d8d5d5;">support@ivorysql.org</a>
Copyright © 2025 IvorySQL
</div>
<script>
const version = "5.1";
document.body.innerHTML = document.body.innerHTML.replace("{{version}}", version);
document.getElementById("help_button").onclick = function() {
window.open("https://docs.ivorysql.org/", "_blank");
};
document.getElementById("home_button").onclick = function() {
window.open("https://www.ivorysql.org/", "_blank");
};
</script>
</body>