From 07cc19ce10dcf1cbbdca4797540d4f2bea74b724 Mon Sep 17 00:00:00 2001 From: John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> Date: Thu, 13 Apr 2023 17:16:24 +0200 Subject: Add sessions_alarm Introduce new feature: sessions_alarm. Added new account setting: max_connections. On exceeding this number, user will get an alert. If number is less than 1, no alert will happen. Tests altered to fit new feature. --- src/command/cmd_ac.c | 2 ++ src/command/cmd_defs.c | 8 ++++++-- src/command/cmd_funcs.c | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) (limited to 'src/command') 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 tls force|allow|trust|legacy|disable", "/account set auth default|legacy", "/account set theme ", + "/account set session_alarm ", "/account clear password", "/account clear eval_password", "/account clear server", @@ -2079,7 +2080,8 @@ static const struct cmd_t command_defs[] = { "/account clear startscript", "/account clear clientid", "/account clear muc", - "/account clear resource") + "/account clear resource", + "/account clear 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 auth default", "Use default authentication process." }, { "set auth legacy", "Allow legacy authentication." }, { "set theme ", "Set the UI theme for the account." }, + { "set session_alarm ", "Alarm about suspicious activity if sessions count exceeds max_sessions." }, { "clear server", "Remove the server setting for this account." }, { "clear port", "Remove the port setting for this account." }, { "clear password", "Remove the password setting for this account." }, @@ -2126,7 +2129,8 @@ static const struct cmd_t command_defs[] = { { "clear clientid", "Reset client's name to default." }, { "clear theme", "Clear the theme setting for the account, the global theme will be used." }, { "clear resource", "Remove the resource setting for this account." }, - { "clear muc", "Remove the default MUC service setting." }) + { "clear muc", "Remove the default MUC service setting." }, + { "clear 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 @@ -904,6 +904,28 @@ _account_set_auth(char* account_name, char* policy) return TRUE; } +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) { @@ -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); } -- cgit 1.4.1-2-gfad0 ref='#n88'>88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353