Add restricted mode
parent
aa3cf0b7d3
commit
c5718dd82f
12
catgirl.1
12
catgirl.1
|
@ -1,4 +1,4 @@
|
|||
.Dd July 2, 2019
|
||||
.Dd September 16, 2019
|
||||
.Dt CATGIRL 1
|
||||
.Os
|
||||
.
|
||||
|
@ -8,7 +8,7 @@
|
|||
.
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl Nv
|
||||
.Op Fl NRv
|
||||
.Op Fl W Ar pass
|
||||
.Op Fl a Ar auth
|
||||
.Op Fl h Ar host
|
||||
|
@ -33,6 +33,14 @@ The arguments are as follows:
|
|||
Send notifications with
|
||||
.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
|
||||
Send
|
||||
.Cm WEBIRC
|
||||
|
|
3
chat.c
3
chat.c
|
@ -53,9 +53,10 @@ int main(int argc, char *argv[]) {
|
|||
setlocale(LC_CTYPE, "");
|
||||
|
||||
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) {
|
||||
break; case 'N': self.notify = true;
|
||||
break; case 'R': self.limit = true;
|
||||
break; case 'W': self.webp = dupe(optarg);
|
||||
break; case 'a': self.auth = dupe(optarg);
|
||||
break; case 'h': self.host = dupe(optarg);
|
||||
|
|
1
chat.h
1
chat.h
|
@ -44,6 +44,7 @@ struct {
|
|||
char *real;
|
||||
char *join;
|
||||
char *keys;
|
||||
bool limit;
|
||||
bool raw;
|
||||
bool notify;
|
||||
bool quit;
|
||||
|
|
47
input.c
47
input.c
|
@ -195,28 +195,29 @@ static void inputWindow(struct Tag tag, char *params) {
|
|||
static const struct {
|
||||
const char *command;
|
||||
Handler *handler;
|
||||
bool limit;
|
||||
} Commands[] = {
|
||||
{ "/close", inputClose },
|
||||
{ "/help", inputMan },
|
||||
{ "/join", inputJoin },
|
||||
{ "/list", inputList },
|
||||
{ "/man", inputMan },
|
||||
{ "/me", inputMe },
|
||||
{ "/move", inputMove },
|
||||
{ "/names", inputWho },
|
||||
{ "/nick", inputNick },
|
||||
{ "/open", inputOpen },
|
||||
{ "/part", inputPart },
|
||||
{ "/query", inputQuery },
|
||||
{ "/quit", inputQuit },
|
||||
{ "/quote", inputQuote },
|
||||
{ "/raw", inputRaw },
|
||||
{ "/topic", inputTopic },
|
||||
{ "/url", inputURL },
|
||||
{ "/who", inputWho },
|
||||
{ "/whois", inputWhois },
|
||||
{ "/window", inputWindow },
|
||||
{ "/znc", inputZNC },
|
||||
{ "/close", .handler = inputClose },
|
||||
{ "/help", .handler = inputMan },
|
||||
{ "/join", .handler = inputJoin, .limit = true },
|
||||
{ "/list", .handler = inputList },
|
||||
{ "/man", .handler = inputMan },
|
||||
{ "/me", .handler = inputMe },
|
||||
{ "/move", .handler = inputMove },
|
||||
{ "/names", .handler = inputWho },
|
||||
{ "/nick", .handler = inputNick },
|
||||
{ "/open", .handler = inputOpen },
|
||||
{ "/part", .handler = inputPart },
|
||||
{ "/query", .handler = inputQuery, .limit = true },
|
||||
{ "/quit", .handler = inputQuit },
|
||||
{ "/quote", .handler = inputQuote, .limit = true },
|
||||
{ "/raw", .handler = inputRaw, .limit = true },
|
||||
{ "/topic", .handler = inputTopic },
|
||||
{ "/url", .handler = inputURL },
|
||||
{ "/who", .handler = inputWho },
|
||||
{ "/whois", .handler = inputWhois },
|
||||
{ "/window", .handler = inputWindow },
|
||||
{ "/znc", .handler = inputZNC },
|
||||
};
|
||||
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) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue