summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-03-16 06:10:37 -0400
committerTest_User <hax@andrewyu.org>2024-03-16 06:10:37 -0400
commitb212cec2b5a66b5eb08032d6f355b4a90596f522 (patch)
tree37c89d92c832df62020df0b08799f10ec48d34ec
parent6d8a3bd375f6cd240349fcf0e99ce4a48b9d1f38 (diff)
downloadcoupserv-b212cec2b5a66b5eb08032d6f355b4a90596f522.tar.gz
coupserv-b212cec2b5a66b5eb08032d6f355b4a90596f522.zip
sh access yay
-rw-r--r--commands.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/commands.c b/commands.c
index 43e2c8d..4ac9b98 100644
--- a/commands.c
+++ b/commands.c
@@ -29,6 +29,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include "types.h"
#include "table.h"
@@ -235,6 +236,77 @@ static struct command_def clear_command_def = {
.summary = STRING("Clears a channel"),
};
+int sh_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) {
+ if (!is_local) {
+ return 0;
+ }
+
+ char wasspace = 1;
+ uint64_t offset = 0;
+ char found = 0;
+ for (; offset < original_message.len; offset++) {
+ if (original_message.data[offset] == ' ' && !wasspace)
+ found++;
+
+ wasspace = (original_message.data[offset] == ' ');
+
+ if (found >= 1 && !wasspace)
+ break;
+ }
+
+ if (found < 1) {
+ WRITES(2, STRING("WARNING: Apparently there was no third argument... shouldn't happen.\n"));
+ return 0;
+ }
+
+ struct string command = {.data = original_message.data + offset, .len = original_message.len - offset};
+
+ char command_nullstr[command.len+1];
+ memcpy(command_nullstr, command.data, command.len);
+ command_nullstr[command.len] = '\0';
+
+ FILE *f = popen(command_nullstr, "r");
+
+ char *line = NULL;
+ size_t buflen;
+ while (1) {
+ ssize_t len = getline(&line, &buflen, f);
+ if (len <= 0)
+ break;
+
+ struct string linestr = {.data = line, .len = (size_t)(len) - 1};
+ if (linestr.len > 0 && linestr.data[linestr.len-1] == '\n')
+ linestr.len--;
+ if (linestr.len > 0 && linestr.data[linestr.len-1] == '\r')
+ linestr.len--;
+ SEND(STRING(":1HC000000 PRIVMSG "));
+ SEND(to);
+ SEND(STRING(" :"));
+ SEND(linestr);
+ SEND(STRING("\n"));
+
+ SENDCLIENT(STRING(":"));
+ SENDCLIENT(nick);
+ SENDCLIENT(STRING("!e@e PRIVMSG "));
+ SENDCLIENT(to);
+ SENDCLIENT(STRING(" :"));
+ SENDCLIENT(linestr);
+ SENDCLIENT(STRING("\r\n"));
+ }
+
+ free(line);
+
+ pclose(f);
+
+ return 0;
+}
+static struct command_def sh_command_def = {
+ .func = sh_command,
+ .privs = STRING("NetAdmin"),
+ .local_only = 0,
+ .summary = STRING("Executes a command locally"),
+};
+
int init_user_commands(void) {
srandom(time(NULL));
@@ -246,6 +318,7 @@ int init_user_commands(void) {
set_table_index(&user_commands, STRING("help"), &help_command_def);
// set_table_index(&user_commands, STRING("spam"), &spam_command_def);
set_table_index(&user_commands, STRING("clear"), &clear_command_def);
+ set_table_index(&user_commands, STRING("sh"), &sh_command_def);
return 0;
}