aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2023-04-18 14:43:01 +0200
committerGitHub <noreply@github.com>2023-04-18 14:43:01 +0200
commit4933d4e4f3d1cc8ee308c1bb6bfc4c13ec64ac57 (patch)
tree1fed6ab534a857572c0732fe5c9dad73af4617dd /src/command
parentf51dc019bc08e41fa4564d465136522648a7a663 (diff)
parentbed5c02c0dde0fe3cd8eb6018322a78b4441e22a (diff)
downloadprofani-tty-4933d4e4f3d1cc8ee308c1bb6bfc4c13ec64ac57.tar.gz
Merge pull request #1827 from H3rnand3zzz/feature/sessions-alarm
New Feature: Session Alarm
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_ac.c2
-rw-r--r--src/command/cmd_defs.c8
-rw-r--r--src/command/cmd_funcs.c27
3 files changed, 35 insertions, 2 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 5678dbff..b29acec5 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -485,6 +485,7 @@ cmd_ac_init(void)
autocomplete_add(account_set_ac, "tls");
autocomplete_add(account_set_ac, "auth");
autocomplete_add(account_set_ac, "theme");
+ autocomplete_add(account_set_ac, "session_alarm");
account_clear_ac = autocomplete_new();
autocomplete_add(account_clear_ac, "password");
@@ -498,6 +499,7 @@ cmd_ac_init(void)
autocomplete_add(account_clear_ac, "theme");
autocomplete_add(account_clear_ac, "muc");
autocomplete_add(account_clear_ac, "resource");
+ autocomplete_add(account_clear_ac, "session_alarm");
account_default_ac = autocomplete_new();
autocomplete_add(account_default_ac, "set");
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index fe993e39..0dd7f10a 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2070,6 +2070,7 @@ static const struct cmd_t command_defs[] = {
"/account set <account> tls force|allow|trust|legacy|disable",
"/account set <account> auth default|legacy",
"/account set <account> theme <theme>",
+ "/account set <account> session_alarm <max_sessions>",
"/account clear <account> password",
"/account clear <account> eval_password",
"/account clear <account> server",
@@ -2079,7 +2080,8 @@ static const struct cmd_t command_defs[] = {
"/account clear <account> startscript",
"/account clear <account> clientid",
"/account clear <account> muc",
- "/account clear <account> resource")
+ "/account clear <account> resource",
+ "/account clear <account> session_alarm")
CMD_DESC(
"Commands for creating and managing accounts. "
"Calling with no arguments will display information for the current account.")
@@ -2116,6 +2118,7 @@ static const struct cmd_t command_defs[] = {
{ "set <account> auth default", "Use default authentication process." },
{ "set <account> auth legacy", "Allow legacy authentication." },
{ "set <account> theme <theme>", "Set the UI theme for the account." },
+ { "set <account> session_alarm <max_sessions>", "Alarm about suspicious activity if sessions count exceeds max_sessions." },
{ "clear <account> server", "Remove the server setting for this account." },
{ "clear <account> port", "Remove the port setting for this account." },
{ "clear <account> password", "Remove the password setting for this account." },
@@ -2126,7 +2129,8 @@ static const struct cmd_t command_defs[] = {
{ "clear <account> clientid", "Reset client's name to default." },
{ "clear <account> theme", "Clear the theme setting for the account, the global theme will be used." },
{ "clear <account> resource", "Remove the resource setting for this account." },
- { "clear <account> muc", "Remove the default MUC service setting." })
+ { "clear <account> muc", "Remove the default MUC service setting." },
+ { "clear <account> session_alarm", "Disable the session alarm." })
CMD_EXAMPLES(
"/account add me",
"/account set me jid ulfhednar@valhalla.edda",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 7c533a45..4a5c7fa1 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -905,6 +905,28 @@ _account_set_auth(char* account_name, char* policy)
}
gboolean
+_account_set_max_sessions(char* account_name, char* max_sessions_raw)
+{
+ int max_sessions;
+ char* err_msg = NULL;
+ gboolean res = strtoi_range(max_sessions_raw, &max_sessions, 0, INT_MAX, &err_msg);
+ if (!res) {
+ cons_show(err_msg);
+ cons_show("");
+ free(err_msg);
+ return TRUE;
+ }
+ accounts_set_max_sessions(account_name, max_sessions);
+ if (max_sessions < 1) {
+ cons_show("Max sessions alarm for account %s has been disabled.", account_name);
+ } else {
+ cons_show("Max sessions alarm for account %s has been set to %d", account_name, max_sessions);
+ }
+ cons_show("");
+ return TRUE;
+}
+
+gboolean
_account_set_presence_priority(char* account_name, char* presence, char* priority)
{
int intval;
@@ -997,6 +1019,8 @@ cmd_account_set(ProfWin* window, const char* const command, gchar** args)
return _account_set_tls(account_name, value);
if (strcmp(property, "auth") == 0)
return _account_set_auth(account_name, value);
+ if (strcmp(property, "session_alarm") == 0)
+ return _account_set_max_sessions(account_name, value);
if (valid_resource_presence_string(property)) {
return _account_set_presence_priority(account_name, property, value);
@@ -1057,6 +1081,9 @@ cmd_account_clear(ProfWin* window, const char* const command, gchar** args)
} else if (strcmp(property, "resource") == 0) {
accounts_clear_resource(account_name);
cons_show("Removed resource for account %s", account_name);
+ } else if (strcmp(property, "session_alarm") == 0) {
+ accounts_clear_max_sessions(account_name);
+ cons_show("Disabled session alarm for account %s", account_name);
} else {
cons_show("Invalid property: %s", property);
}