-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinjector.html
More file actions
477 lines (442 loc) · 18.5 KB
/
injector.html
File metadata and controls
477 lines (442 loc) · 18.5 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Injector CLI</title>
<style>
body {
margin: 0;
background: #000;
color: #00FF00;
font-family: 'Courier New', monospace;
display: flex;
flex-direction: column;
height: 100vh;
overflow: hidden;
}
#console {
flex-grow: 1;
padding: 1rem;
overflow-y: auto;
font-size: clamp(12px, 3vw, 14px);
}
#input-area {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
padding: 1rem;
background: #111;
}
#command-input {
flex-grow: 1;
background: #000;
color: #00FF00;
border: 1px solid #00FF00;
padding: 0.5rem;
font-family: inherit;
font-size: clamp(12px, 3vw, 14px);
min-width: 200px;
}
.button {
background: #000;
color: #00FF00;
border: 1px solid #00FF00;
padding: 0.5rem 1rem;
margin: 0 0.3rem;
cursor: pointer;
font-family: inherit;
font-size: clamp(12px, 3vw, 14px);
white-space: nowrap;
}
.button:hover {
background: #00FF00;
color: #000;
}
#py-popup {
display: none;
position: fixed;
top: 10%;
left: 5%;
width: 90%;
max-width: 800px;
height: 80%;
background: #111;
border: 1px solid #00FF00;
padding: 1rem;
box-sizing: border-box;
}
#py-input {
width: 100%;
height: 80%;
background: #000;
color: #00FF00;
border: 1px solid #00FF00;
font-family: inherit;
font-size: clamp(12px, 3vw, 14px);
resize: none;
box-sizing: border-box;
}
#turtle-canvas {
display: none;
position: fixed;
top: 20%;
left: 20%;
background: #fff;
border: 1px solid #00FF00;
}
footer {
text-align: center;
padding: 0.5rem;
font-size: clamp(10px, 2.5vw, 12px);
}
.error-details {
color: #FF5555;
white-space: pre-wrap;
}
.security-alert {
color: #FFAA00;
font-weight: bold;
}
@media (min-width: 768px) {
#console {
padding: 10px;
font-size: 14px;
}
#input-area {
flex-wrap: nowrap;
padding: 10px;
}
#command-input {
font-size: 14px;
}
.button {
padding: 5px 10px;
margin: 0 5px;
font-size: 14px;
}
#py-popup {
top: 20%;
left: 20%;
width: 60%;
height: 60%;
padding: 10px;
}
#py-input {
font-size: 14px;
}
#turtle-canvas {
top: 20%;
left: 20%;
}
footer {
font-size: 12px;
}
}
</style>
</head>
<body>
<div id="console"></div>
<div id="input-area">
<input id="command-input" type="text" placeholder="CLI:" onkeypress="if(event.key === 'Enter') executeCommand()">
<button class="button" onclick="executeCommand()">Execute</button>
<button class="button" onclick="showPyPopup()">Inject</button>
<button class="button" onclick="ejectPyConsole()">Eject</button>
<button class="button" onclick="troubleshoot()">Troubleshoot</button>
</div>
<div id="py-popup">
<textarea id="py-input" placeholder="Enter Python script"></textarea>
<button class="button" onclick="injectPyScript()">Inject Script</button>
<button class="button" onclick="closePyPopup()">Close</button>
</div>
<canvas id="turtle-canvas" width="400" height="400"></canvas>
<footer>WebXOS 2025</footer>
<script src="https://cdn.jsdelivr.net/npm/skulpt@1.2.0/dist/skulpt.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/skulpt@1.2.0/dist/skulpt-stdlib.js"></script>
<script src="https://cdn.jsdelivr.net/npm/skulpt@1.2.0/dist/turtle.js"></script>
<script>
const consoleDiv = document.getElementById('console');
let errorLog = [];
let threatLog = [];
if (!consoleDiv) {
console.error('Console div not found. Cannot initialize Injector AI.');
document.body.innerHTML = '<p style="color: red;">Error: Console div not found.</p>';
}
function logToConsole(message, type = 'info') {
if (!consoleDiv) {
console.error('Console div is null. Cannot log:', message);
return;
}
const p = document.createElement('p');
p.style.color = type === 'error' ? '#FF5555' : type === 'input' ? '#FFFF00' : type === 'security' ? '#FFAA00' : '#00FF00';
p.textContent = `[${type.toUpperCase()}] ${message}`;
if (type === 'error' || type === 'security') {
(type === 'error' ? errorLog : threatLog).push(`[${new Date().toISOString()}] ${message}`);
}
try {
consoleDiv.appendChild(p);
consoleDiv.scrollTop = consoleDiv.scrollHeight;
} catch (e) {
console.error('Failed to append to console:', e.message);
}
}
let isWaitingForInput = false;
let inputResolver = null;
Sk.configure({
output: (msg) => logToConsole(msg, 'info'),
read: (filename) => {
if (Sk.builtinFiles === undefined || Sk.builtinFiles.files[filename] === undefined) {
throw new Error(`File not found: ${filename}`);
}
return Sk.builtinFiles.files[filename];
},
inputfun: (prompt) => {
isWaitingForInput = true;
logToConsole(prompt, 'input');
return new Promise((resolve) => {
inputResolver = resolve;
});
},
__future__: Sk.python3
});
Sk.TurtleGraphics = Sk.TurtleGraphics || {};
Sk.TurtleGraphics.target = 'turtle-canvas';
Sk.TurtleGraphics.width = 400;
Sk.TurtleGraphics.height = 400;
function troubleshoot() {
logToConsole('Running Diagnostics...', 'info');
try {
const pyCode = document.getElementById('py-input').value || document.getElementById('command-input').value;
if (!pyCode) {
logToConsole('No Python code to analyze. Enter a script in the Inject popup or console.', 'error');
return;
}
const lines = pyCode.split('\n');
let issues = [];
let indentLevel = 0;
let openBrackets = 0;
let inString = false;
let stringChar = null;
lines.forEach((line, i) => {
const lineNum = i + 1;
const trimmedLine = line.trim();
if (!trimmedLine || trimmedLine.startsWith('#')) return;
const indentMatch = line.match(/^\s*/);
const currentIndent = indentMatch[0].length / 4;
if (currentIndent % 1 !== 0) {
issues.push(`Line ${lineNum}: Invalid indentation. Use multiples of 4 spaces. Found ${indentMatch[0].length} spaces.`);
} else if (currentIndent > indentLevel + 1) {
issues.push(`Line ${lineNum}: Unexpected indentation level. Expected ${indentLevel * 4} spaces, found ${indentMatch[0].length}.`);
}
indentLevel = trimmedLine.match(/^(def|class|if|elif|else|for|while|try|except|finally)\b/) ? currentIndent + 1 : currentIndent;
for (let char of line) {
if (inString) {
if (char === stringChar) inString = false;
continue;
}
if (char === '"' || char === "'") {
inString = true;
stringChar = char;
} else if (char === '(' || char === '[' || char === '{') {
openBrackets++;
} else if (char === ')' || char === ']' || char === '}') {
openBrackets--;
if (openBrackets < 0) {
issues.push(`Line ${lineNum}: Unmatched closing bracket.`);
openBrackets = 0;
}
}
}
if (trimmedLine.includes('input(') && !isWaitingForInput) {
issues.push(`Line ${lineNum}: input() detected. Ensure interactive input is provided via console.`);
}
if (trimmedLine.match(/import\s+([^\s]+)/)) {
const module = RegExp.$1.split(',')[0].trim();
if (!['random', 're', 'time', 'datetime', 'math', 'turtle'].includes(module)) {
issues.push(`Line ${lineNum}: Module '${module}' is not supported by Skulpt 1.2.0. Use supported modules only.`);
}
}
if (trimmedLine.match(/def\s+([^\s(]+)/)) {
const funcName = RegExp.$1;
if (['help', 'print', 'input', 'len', 'str', 'int', 'float'].includes(funcName)) {
issues.push(`Line ${lineNum}: Function '${funcName}' conflicts with Python built-in. Choose a different name.`);
}
}
if (trimmedLine.match(/([^\s=]+)\s*=/) && !trimmedLine.match(/^\s*(def|class)\s/)) {
const varName = RegExp.$1;
if (!lines.slice(0, i).some(l => l.match(new RegExp(`\\b${varName}\\b`))) &&
!['True', 'False', 'None'].includes(varName) && !varName.match(/^[0-9]/)) {
issues.push(`Line ${lineNum}: Variable '${varName}' may be undefined before assignment.`);
}
}
if (trimmedLine.match(/^(if|elif|else|for|while|def|class|try|except|finally)\b/) && !trimmedLine.endsWith(':')) {
issues.push(`Line ${lineNum}: Missing colon at end of statement.`);
}
if (trimmedLine.match(/re\.match|re\.search|re\.findall/) && trimmedLine.match(/r?['"][^'"]*\\b\+[^'"]*['"]/)) {
issues.push(`Line ${lineNum}: Potential invalid regex pattern (e.g., \\b+). Skulpt 1.2.0 does not support complex regex like lookaheads or quantified boundaries.`);
logToConsole(`Security Alert: Suspicious regex pattern on line ${lineNum}.`, 'security');
}
if (trimmedLine.match(/eval\(|exec\(/)) {
issues.push(`Line ${lineNum}: Use of eval() or exec() detected. Avoid for security reasons.`);
logToConsole(`Security Alert: Unsafe function detected on line ${lineNum}.`, 'security');
}
});
if (openBrackets > 0) {
issues.push(`Script: Unclosed brackets detected. Check for matching (), [], or {}.`);
}
if (issues.length > 0) {
issues.forEach(issue => logToConsole(issue, 'error'));
} else {
logToConsole('No syntax or semantic issues detected.', 'info');
}
Sk.misceval.asyncToPromise(() => Sk.importMainWithBody('<stdin>', false, pyCode, true))
.catch((err) => {
const errMsg = err.toString();
let suggestion = 'Check syntax or use Troubleshoot for detailed analysis.';
let context = '';
if (errMsg.includes('NameError')) {
suggestion = 'Undefined variable or function. Verify all names are defined.';
context = errMsg.match(/name '([^']+)'/) ? `Variable/function '${RegExp.$1}' not found.` : '';
} else if (errMsg.includes('SyntaxError')) {
suggestion = 'Syntax error. Check for missing colons, incorrect indentation, or invalid syntax.';
context = errMsg.match(/line (\d+)/) ? `Error on line ${RegExp.$1}.` : '';
} else if (errMsg.includes('TypeError')) {
suggestion = 'Type mismatch. Ensure correct data types for operations.';
context = errMsg.match(/'([^']+)'/) ? `Operation on '${RegExp.$1}' caused error.` : '';
} else if (errMsg.includes('NotImplementedError')) {
suggestion = 'Feature not supported by Skulpt. Avoid unsupported functions.';
} else if (errMsg.includes('ImportError')) {
suggestion = 'Module import failed. Only supported modules are available.';
context = errMsg.match(/No module named '([^']+)'/) ? `Module '${RegExp.$1}' not found.` : '';
} else if (errMsg.includes('Invalid regular expression')) {
suggestion = 'Invalid regex pattern. Skulpt 1.2.0 supports only basic regex; avoid lookaheads or complex quantifiers.';
context = errMsg.match(/: ([^:]+)/) ? `Pattern: ${RegExp.$1}` : '';
}
logToConsole(`Python error: ${errMsg}\nContext: ${context}\nSuggestion: ${suggestion}`, 'error');
});
logToConsole('Validating JavaScript runtime...', 'info');
const testJs = () => { throw new Error('Test JS error'); };
try {
testJs();
} catch (e) {
logToConsole('JavaScript runtime stable. No issues detected.', 'info');
}
logToConsole('Validating CSS integrity...', 'info');
const css = document.querySelector('style').textContent;
if (!css.includes('body')) {
logToConsole('CSS error: Missing body styling. Add body rules.', 'error');
} else {
logToConsole('CSS validated successfully.', 'info');
}
} catch (e) {
logToConsole(`Injector AI Error: ${e.message}\nSuggestion: Verify script format`, 'error');
}
}
function executeCommand() {
const input = document.getElementById('command-input').value.trim();
if (isWaitingForInput && inputResolver) {
inputResolver(input);
isWaitingForInput = false;
inputResolver = null;
document.getElementById('command-input').value = '';
document.getElementById('command-input').focus();
return;
}
try {
if (input === 'clear') {
consoleDiv.innerHTML = '';
logToConsole('Console cleared.', 'info');
} else {
Sk.misceval.asyncToPromise(() => Sk.importMainWithBody('<stdin>', false, input, true))
.then(() => logToConsole('Python script executed successfully.', 'info'))
.catch((err) => {
const errMsg = err.toString();
let suggestion = 'Check syntax or use Troubleshoot for detailed analysis.';
let context = '';
if (errMsg.includes('NameError')) {
suggestion = 'Undefined variable or function. Verify all names are defined.';
context = errMsg.match(/name '([^']+)'/) ? `Variable/function '${RegExp.$1}' not found.` : '';
} else if (errMsg.includes('SyntaxError')) {
suggestion = 'Syntax error. Check for missing colons, incorrect indentation, or invalid syntax.';
context = errMsg.match(/line (\d+)/) ? `Error on line ${RegExp.$1}.` : '';
} else if (errMsg.includes('TypeError')) {
suggestion = 'Type mismatch. Ensure correct data types for operations.';
context = errMsg.match(/'([^']+)'/) ? `Operation on '${RegExp.$1}' caused error.` : '';
} else if (errMsg.includes('NotImplementedError')) {
suggestion = 'Feature not supported by Skulpt. Avoid unsupported functions.';
} else if (errMsg.includes('ImportError')) {
suggestion = 'Module import failed. Only supported modules are available.';
context = errMsg.match(/No module named '([^']+)'/) ? `Module '${RegExp.$1}' not found.` : '';
} else if (errMsg.includes('Invalid regular expression')) {
suggestion = 'Invalid regex pattern. Skulpt 1.2.0 supports only basic regex; avoid lookaheads or complex quantifiers.';
context = errMsg.match(/: ([^:]+)/) ? `Pattern: ${RegExp.$1}` : '';
}
logToConsole(`Python error: ${errMsg}\nContext: ${context}\nSuggestion: ${suggestion}`, 'error');
});
}
} catch (e) {
logToConsole(`Command error: ${e.message}\nSuggestion: Use 'clear'`, 'error');
}
document.getElementById('command-input').value = '';
document.getElementById('command-input').focus();
}
function showPyPopup() {
document.getElementById('py-popup').style.display = 'block';
}
function closePyPopup() {
document.getElementById('py-popup').style.display = 'none';
}
function injectPyScript() {
const pyCode = document.getElementById('py-input').value;
isWaitingForInput = false;
inputResolver = null;
try {
const wrappedCode = `
def run_injected():
${pyCode.replace(/^/gm, ' ')}
run_injected()
`;
Sk.misceval.asyncToPromise(() => Sk.importMainWithBody('<stdin>', false, wrappedCode, true))
.then(() => logToConsole('Python script executed successfully.', 'info'))
.catch((err) => {
const errMsg = err.toString();
let suggestion = 'Check syntax or use Troubleshoot for detailed analysis.';
let context = '';
if (errMsg.includes('NameError')) {
suggestion = 'Undefined variable or function. Verify all names are defined.';
context = errMsg.match(/name '([^']+)'/) ? `Variable/function '${RegExp.$1}' not found.` : '';
} else if (errMsg.includes('SyntaxError')) {
suggestion = 'Syntax error. Check for missing colons, incorrect indentation, or invalid syntax.';
context = errMsg.match(/line (\d+)/) ? `Error on line ${RegExp.$1}.` : '';
} else if (errMsg.includes('TypeError')) {
suggestion = 'Type mismatch. Ensure correct data types for operations.';
context = errMsg.match(/'([^']+)'/) ? `Operation on '${RegExp.$1}' caused error.` : '';
} else if (errMsg.includes('NotImplementedError')) {
suggestion = 'Feature not supported by Skulpt. Avoid unsupported functions.';
} else if (errMsg.includes('ImportError')) {
suggestion = 'Module import failed. Only supported modules are available.';
context = errMsg.match(/No module named '([^']+)'/) ? `Module '${RegExp.$1}' not found.` : '';
} else if (errMsg.includes('Invalid regular expression')) {
suggestion = 'Invalid regex pattern. Skulpt 1.2.0 supports only basic regex; avoid lookaheads or complex quantifiers.';
context = errMsg.match(/: ([^:]+)/) ? `Pattern: ${RegExp.$1}` : '';
}
logToConsole(`Python error: ${errMsg}\nContext: ${context}\nSuggestion: ${suggestion}`, 'error');
});
} catch (e) {
logToConsole(`Injector AI Error: ${e.message}\nSuggestion: Verify Python script format or use Troubleshoot.`, 'error');
}
closePyPopup();
}
function ejectPyConsole() {
document.getElementById('py-input').value = '';
consoleDiv.innerHTML = '';
isWaitingForInput = false;
inputResolver = null;
errorLog = [];
threatLog = [];
logToConsole('Python console ejected. Ready for new commands.', 'info');
}
logToConsole('Injector CLI Terminal by WebXOS 2025 Initialized. Click Inject to inject a .py script...', 'info');
</script>
</body>
</html>