-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
214 lines (208 loc) · 7.07 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
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
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<title>Pika Cloud Console</title>
<meta property="og:title" content="Cloud's Console" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://lukas-bownik.net/" />
<meta property="og:description" content="ofca's cloud's console" />
<meta property="og:image" content="https://lukas-bownik.net/img/pikacloud.png" />
<meta name="theme-color" content="#607FBA">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="site.webmanifest">
<link rel="stylesheet" href="font/css/ibm-plex.css">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/screen.css">
<link rel="stylesheet" href="css/logo_pane.css">
<link type="text/plain" rel="author" href="humans.txt" />
<link rel="stylesheet" href="https://unpkg.com/terminal.css@0.7.2/dist/terminal.min.css" />
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
</head>
<body id="app" class="base-colour-bg">
<main class="container grid">
<div class="left-pane screen center">
<div class="screen-grid terminal-prompt" ref="screengrid">
{{ message }}
</div>
</div>
<div class="right-pane logo_pane center">
<div class="system_logo" @click="redirectToCore">
</div>
</div>
</main>
</body>
<script>
const { createApp } = Vue
let commandBuffer = "";
let sourceChosen = false;
let source = null;
const commands = [
".SYSSTA",
".USRNFO",
".DIR",
".S.CRT",
"RST",
"?"
];
const sources = [
"S1"
];
const baseUrl = "https://core.lukas-bownik.net/Api/v1/Command";
createApp({
data() {
return {
message: '!INIT ERR'
}
},
mounted() {
const $this = this;
this.askToChooseSource();
document.addEventListener('keydown', function (evt) {
if(evt.key === "Enter"){
$this.executeCommand(commandBuffer);
commandBuffer = "";
$this.$refs.screengrid.innerText += "\n";
}
if($this.validateKeyboardKey(evt.key) || $this.validateKeyboardCode(evt.keyCode)){
$this.$refs.screengrid.innerText += evt.key;
commandBuffer += evt.key;
}
$this.$refs.screengrid.scrollTo(0, $this.$refs.screengrid.scrollTop + $this.$refs.screengrid.offsetHeight);
});
},
methods: {
// TODO: This method will use some major refactor, should move all commands logic to separated file and use some strategy or sth.
executeCommand(command) {
command = command.toUpperCase();
commandSlices = command.split(" ");
commandName = commandSlices[0];
args = commandSlices.slice(1, commandSlices.length);
if(!sourceChosen && sources.includes(commandName)){
this.setSource(command);
return;
}
if(sourceChosen && commands.includes(commandName)){
// If the command starts with . it is a remote command, otherwise local
if(command.startsWith(".")){
if(commandName === ".S.CRT"){
args = [source, args[0], args[1]];
}
this.executeApiCall(commandName, args);
} else {
if(command === "?") {
this.printCommands();
}
if(command === "RST"){
this.reset();
}
}
} else if(sourceChosen) {
this.refreshScreen("!ERROR - NO SUCH EXECUTABLE OR FILE");
} else {
this.askToChooseSource();
}
},
validateKeyboardKey(input) {
return input == '.' || input == "?" || input == " " || input == "_";
},
validateKeyboardCode(code) {
// Small ASCII letters and digits
return code >= 65 && code <= 93 || code >= 48 && code <= 57;
},
handleBackspaceKey() {;
commandBuffer = commandBuffer.substring(0, commandBuffer.length - 1);
this.$refs.screengrid.innerText = commandBuffer;
},
refreshScreen(output, append = true) {
if(!append){
this.$refs.screengrid.innerText = output;
} else {
this.$refs.screengrid.innerText += '\n' + output;
}
},
executeApiCall(command, args) {
const s = `${args}`.replaceAll(",", " ");
fetch(`${baseUrl}/${command.toUpperCase()}?body=${s}`,
{
method: 'POST'
})
.then(r => {
if(r.status === 200){
r.json()
.then(t => {
let jsonPayload = t.output.split("=")[1];
let resultText = "";
try{
resultText = "PROP\tVALUE\n";
const payload = JSON.parse(jsonPayload);
const payloadKeys = Object.keys(payload);
for(const k in payloadKeys){
if(payloadKeys[k] === "output") {
output = payload[payloadKeys[k]];
console.log(output);
resultText = "CONTENTS\n";
resultText += `${output}`;
if(Array.isArray(output)){
resultText = resultText.replaceAll(",", "\n");
}
resultText += "\n";
} else {
resultText += `${payloadKeys[k]}\t${payload[payloadKeys[k]]}\n`;
}
}
}catch(e){
resultText = "!ERROR - THERE WAS AN ERROR READING THE FILE\n";
//resultText += jsonPayload ?? "";
}
this.refreshScreen(resultText);
})
.catch(e => {
this.refreshScreen(`!ERROR - ${source} RETURNED UNEXPECTED RESPONSE FORMAT\n`);
});
} else {
this.refreshScreen(`!ERROR - ${source} RETURNED UNEXPECTED RESPONSE\n`);
}
})
.catch(e => {
this.refreshScreen(`!ERROR - ${source} RETURNED UNEXPECTED RESPONSE\n`);
});
},
setSource(command) {
sourceChosen = true;
source = command;
this.refreshScreen(`MAX SRC# - ${sources.length}, CLOUD CONSOLE # ${source}`, false);
},
askToChooseSource() {
this.refreshScreen("S=", false);
},
printCommands() {
let commandsText = "";
for(let cmd in commands){
commandsText += commands[cmd] + "\n";
}
this.refreshScreen(commandsText);
this.printLogo();
},
reset(){
this.commandBuffer = "";
this.refreshScreen(`MAX SRC# - ${sources.length}, CLOUD CONSOLE # ${source}`, false);
},
printLogo() {
fetch('/logo.txt')
.then(r => r.text())
.then(r => {
this.refreshScreen(r.replace("%S", source), true);
});
},
redirectToCore() {
this.refreshScreen("REDIRECTING TO PIKACORE...");
setInterval(() => {
document.location = "https://core.lukas-bownik.net/";
}, 1000);
}
}
}).mount('#app')
</script>
</html>