Support for executing multiple commands via /cmd

This commit is contained in:
UAb5eSMn
2026-05-15 13:27:09 +02:00
parent a2b2dbcfbf
commit 2316ffd493
5 changed files with 54 additions and 18 deletions
+34
View File
@@ -1639,3 +1639,37 @@ config_done:
clear_command_history();
save_cmd = 1;
}
// Execute multiple commands
// If a command is too long or can't be tokenized, remaining commands are not executed
// Returns the status via `err_status`-variable.
void execute_commands(__xdata uint8_t *p) __banked {
err_status = ERR_OK;
uint8_t cmd_idx = 0;
while (1) {
if (*p == 0 || *p == '\n' || *p == '\r') {
if (cmd_idx) {
cmd_buffer[cmd_idx] = '\0';
cmd_tokenize();
if (err_status != ERR_OK)
return;
cmd_parser();
}
if (*p == 0)
return;
cmd_idx = 0;
} else {
if (cmd_idx < (CMD_BUF_SIZE - 1)) {
cmd_buffer[cmd_idx++] = *p;
} else {
cmd_buffer[CMD_BUF_SIZE - 1] = '\0';
print_string("ERROR: Command too long: ");
print_string_x(cmd_buffer);
write_char('\n');
err_status = ERR_CMD_TOO_LONG;
return;
}
}
p++;
};
}
+3
View File
@@ -7,10 +7,13 @@
extern __xdata uint8_t cmd_buffer[CMD_BUF_SIZE];
extern __xdata uint8_t cmd_available;
extern __xdata uint8_t err_status;
void cmd_tokenize(void) __banked;
void cmd_parser(void) __banked;
void execute_config(void) __banked;
void execute_commands(__xdata uint8_t *p) __banked;
void print_sw_version(void) __banked;
void clear_command_history(void) __banked;
#endif
+12 -11
View File
@@ -12,18 +12,19 @@ async function ipSub() {
if (!checkIp(document.getElementById(ips[i]).value))
return;
}
var cmd = '';
for (let i=0; i<3;i++){
var cmd = ips[i]+' '+document.getElementById(ips[i]).value;
try {
const response = await fetch('/cmd', {
method: 'POST',
body: cmd
});
console.log('Completed!', response);
fetchIP();
} catch(err) {
console.error(`Error: ${err}`);
}
cmd += ips[i]+' '+document.getElementById(ips[i]).value+'\n';
}
try {
const response = await fetch('/cmd', {
method: 'POST',
body: cmd
});
console.log('Completed!', response);
fetchIP();
} catch(err) {
console.error(`Error: ${err}`);
}
}
+5 -6
View File
@@ -400,17 +400,16 @@ void handle_post(void)
}
if (is_word(request_path, "cmd")) {
register uint8_t i = 0;
p += 4;
if (!authenticated) {
send_unauthorized();
return;
}
while (*p && *p != '\n' && *p != '\r')
cmd_buffer[i++] = *p++;
cmd_buffer[i] = '\0';
if (i)
cmd_available = 1;
execute_commands(p);
if (err_status != ERR_OK) {
send_bad_request();
return;
}
} else if (is_word(request_path, "login")) {
dbg_string("POST login\n");
p += 8; // Read also over "pwd="
-1
View File
@@ -28,7 +28,6 @@
extern __code const struct machine machine;
extern __xdata uint32_t flash_size;
extern __xdata uint8_t err_status;
extern __xdata uint16_t crc_value;
__xdata struct machine_runtime machine_detected;