Add restricted mode

master
Curtis McEnroe 2019-09-16 16:57:50 -04:00
parent aa3cf0b7d3
commit c5718dd82f
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 39 additions and 24 deletions

View File

@ -1,4 +1,4 @@
.Dd July 2, 2019 .Dd September 16, 2019
.Dt CATGIRL 1 .Dt CATGIRL 1
.Os .Os
. .
@ -8,7 +8,7 @@
. .
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl Nv .Op Fl NRv
.Op Fl W Ar pass .Op Fl W Ar pass
.Op Fl a Ar auth .Op Fl a Ar auth
.Op Fl h Ar host .Op Fl h Ar host
@ -33,6 +33,14 @@ The arguments are as follows:
Send notifications with Send notifications with
.Xr notify-send 1 . .Xr notify-send 1 .
. .
.It Fl R
Restrict the use of the
.Ic /join ,
.Ic /query ,
.Ic /quote ,
.Ic /raw
commands.
.
.It Fl W Ar pass .It Fl W Ar pass
Send Send
.Cm WEBIRC .Cm WEBIRC

3
chat.c
View File

@ -53,9 +53,10 @@ int main(int argc, char *argv[]) {
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
int opt; int opt;
while (0 < (opt = getopt(argc, argv, "NW:a:h:j:k:l:n:p:r:u:vw:"))) { while (0 < (opt = getopt(argc, argv, "NRW:a:h:j:k:l:n:p:r:u:vw:"))) {
switch (opt) { switch (opt) {
break; case 'N': self.notify = true; break; case 'N': self.notify = true;
break; case 'R': self.limit = true;
break; case 'W': self.webp = dupe(optarg); break; case 'W': self.webp = dupe(optarg);
break; case 'a': self.auth = dupe(optarg); break; case 'a': self.auth = dupe(optarg);
break; case 'h': self.host = dupe(optarg); break; case 'h': self.host = dupe(optarg);

1
chat.h
View File

@ -44,6 +44,7 @@ struct {
char *real; char *real;
char *join; char *join;
char *keys; char *keys;
bool limit;
bool raw; bool raw;
bool notify; bool notify;
bool quit; bool quit;

47
input.c
View File

@ -195,28 +195,29 @@ static void inputWindow(struct Tag tag, char *params) {
static const struct { static const struct {
const char *command; const char *command;
Handler *handler; Handler *handler;
bool limit;
} Commands[] = { } Commands[] = {
{ "/close", inputClose }, { "/close", .handler = inputClose },
{ "/help", inputMan }, { "/help", .handler = inputMan },
{ "/join", inputJoin }, { "/join", .handler = inputJoin, .limit = true },
{ "/list", inputList }, { "/list", .handler = inputList },
{ "/man", inputMan }, { "/man", .handler = inputMan },
{ "/me", inputMe }, { "/me", .handler = inputMe },
{ "/move", inputMove }, { "/move", .handler = inputMove },
{ "/names", inputWho }, { "/names", .handler = inputWho },
{ "/nick", inputNick }, { "/nick", .handler = inputNick },
{ "/open", inputOpen }, { "/open", .handler = inputOpen },
{ "/part", inputPart }, { "/part", .handler = inputPart },
{ "/query", inputQuery }, { "/query", .handler = inputQuery, .limit = true },
{ "/quit", inputQuit }, { "/quit", .handler = inputQuit },
{ "/quote", inputQuote }, { "/quote", .handler = inputQuote, .limit = true },
{ "/raw", inputRaw }, { "/raw", .handler = inputRaw, .limit = true },
{ "/topic", inputTopic }, { "/topic", .handler = inputTopic },
{ "/url", inputURL }, { "/url", .handler = inputURL },
{ "/who", inputWho }, { "/who", .handler = inputWho },
{ "/whois", inputWhois }, { "/whois", .handler = inputWhois },
{ "/window", inputWindow }, { "/window", .handler = inputWindow },
{ "/znc", inputZNC }, { "/znc", .handler = inputZNC },
}; };
static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]); static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]);
@ -264,6 +265,10 @@ void input(struct Tag tag, char *input) {
for (size_t i = 0; i < CommandsLen; ++i) { for (size_t i = 0; i < CommandsLen; ++i) {
if (strcasecmp(command, Commands[i].command)) continue; if (strcasecmp(command, Commands[i].command)) continue;
if (self.limit && Commands[i].limit) {
uiFmt(tag, UIHot, "%s isn't available in restricted mode", command);
return;
}
Commands[i].handler(tag, input); Commands[i].handler(tag, input);
return; return;
} }