add /identify command

This commit is contained in:
isundil 2019-09-03 13:24:56 +02:00
commit 6d9c9d8fcd
6 changed files with 64 additions and 4 deletions

View file

@ -9,4 +9,5 @@ char *realname;
char *own_host; /* address to use when connecting this server */
char *autosendcmd; /* command to send after connecting to this ircnet */
char *identifycmd; /* command to use for identifying to this ircnet */
IPADDR *own_ip4, *own_ip6; /* resolved own_address if not NULL */

View file

@ -45,6 +45,7 @@ static void chatnet_config_save(CHATNET_REC *chatnet)
iconfig_node_set_str(node, "realname", chatnet->realname);
iconfig_node_set_str(node, "host", chatnet->own_host);
iconfig_node_set_str(node, "autosendcmd", chatnet->autosendcmd);
iconfig_node_set_str(node, "identifycmd", chatnet->identifycmd);
signal_emit("chatnet saved", 2, chatnet, node);
}
@ -91,6 +92,7 @@ void chatnet_destroy(CHATNET_REC *chatnet)
g_free_not_null(chatnet->realname);
g_free_not_null(chatnet->own_host);
g_free_not_null(chatnet->autosendcmd);
g_free_not_null(chatnet->identifycmd);
g_free(chatnet->name);
g_free(chatnet);
}
@ -154,6 +156,7 @@ static void chatnet_read(CONFIG_NODE *node)
rec->realname = g_strdup(config_node_get_str(node, "realname", NULL));
rec->own_host = g_strdup(config_node_get_str(node, "host", NULL));
rec->autosendcmd = g_strdup(config_node_get_str(node, "autosendcmd", NULL));
rec->identifycmd = g_strdup(config_node_get_str(node, "identifycmd", NULL));
chatnets = g_slist_append(chatnets, rec);
signal_emit("chatnet read", 2, rec, node);

View file

@ -27,6 +27,7 @@
#include <irssi/src/core/levels.h>
#include <irssi/src/core/servers.h>
#include <irssi/src/core/chatnets.h>
#include <irssi/src/irc/core/mode-lists.h>
#include <irssi/src/core/nicklist.h>
#include <irssi/src/irc/core/irc-commands.h>
@ -393,6 +394,53 @@ static void cmd_oper(const char *data, IRC_SERVER_REC *server)
cmd_params_free(free_arg);
}
static void identify_with_pass(const char *password, SERVER_REC *server_rec)
{
if (*password != '\0' && IS_IRC_SERVER(server_rec)) {
char *identify_cmd = "PRIVMSG NickServ IDENTIFY %s";
CHATNET_REC *chatnet_rec = NULL;
if (server_rec->connrec->chatnet)
chatnet_rec = chatnet_find(server_rec->connrec->chatnet);
if (chatnet_rec && chatnet_rec->identifycmd)
identify_cmd = chatnet_rec->identifycmd;
irc_send_cmdv((IRC_SERVER_REC *) server_rec, identify_cmd, password);
}
}
static void cmd_identify_got_pass(const char *password, char *server_tag)
{
identify_with_pass(password, server_find_tag(server_tag));
g_free(server_tag);
}
/* SYNTAX: IDENTIFY <password> */
static void cmd_identify(const char *data, IRC_SERVER_REC *server)
{
char *password, *format;
void *free_arg;
g_return_if_fail(data != NULL);
if (!IS_IRC_SERVER(server) || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
if (!cmd_get_params(data, &free_arg, 1, &password))
return;
if (*password == '\0') {
format = format_get_text(MODULE_NAME, NULL, server, NULL,
IRCTXT_ASK_USER_PASS);
keyboard_entry_redirect((SIGNAL_FUNC) cmd_identify_got_pass,
format,
ENTRY_REDIRECT_FLAG_HIDDEN, g_strdup(server->tag));
g_free(format);
signal_stop();
} else {
identify_with_pass(password, (SERVER_REC*) server);
}
cmd_params_free(free_arg);
}
/* SYNTAX: SETHOST <host> <password> (non-ircops)
SETHOST <ident> <host> (ircops) */
static void cmd_sethost(const char *data, IRC_SERVER_REC *server)
@ -428,6 +476,7 @@ void fe_irc_commands_init(void)
command_bind_irc("topic", NULL, (SIGNAL_FUNC) cmd_topic);
command_bind_irc("ts", NULL, (SIGNAL_FUNC) cmd_ts);
command_bind_irc("oper", NULL, (SIGNAL_FUNC) cmd_oper);
command_bind_irc("identify", NULL, (SIGNAL_FUNC) cmd_identify);
command_bind_irc("sethost", NULL, (SIGNAL_FUNC) cmd_sethost);
}

View file

@ -58,6 +58,8 @@ static void cmd_network_list(void)
g_string_append_printf(str, "host: %s, ", rec->own_host);
if (rec->autosendcmd != NULL)
g_string_append_printf(str, "autosendcmd: %s, ", rec->autosendcmd);
if (rec->identifycmd != NULL)
g_string_append_printf(str, "identifycmd: %s, ", rec->identifycmd);
if (rec->usermode != NULL)
g_string_append_printf(str, "usermode: %s, ", rec->usermode);
if (rec->sasl_mechanism != NULL)
@ -125,6 +127,7 @@ static void cmd_network_add_modify(const char *data, gboolean add)
}
if (g_hash_table_lookup(optlist, "usermode")) g_free_and_null(rec->usermode);
if (g_hash_table_lookup(optlist, "autosendcmd")) g_free_and_null(rec->autosendcmd);
if (g_hash_table_lookup(optlist, "identifycmd")) g_free_and_null(rec->identifycmd);
if (g_hash_table_lookup(optlist, "sasl_mechanism")) g_free_and_null(rec->sasl_mechanism);
if (g_hash_table_lookup(optlist, "sasl_username")) g_free_and_null(rec->sasl_username);
if (g_hash_table_lookup(optlist, "sasl_password")) g_free_and_null(rec->sasl_password);
@ -165,6 +168,8 @@ static void cmd_network_add_modify(const char *data, gboolean add)
if (value != NULL && *value != '\0') rec->usermode = g_strdup(value);
value = g_hash_table_lookup(optlist, "autosendcmd");
if (value != NULL && *value != '\0') rec->autosendcmd = g_strdup(value);
value = g_hash_table_lookup(optlist, "identifycmd");
if (value != NULL && *value != '\0') rec->identifycmd = g_strdup(value);
/* the validity of the parameters is checked in sig_server_setup_fill_chatnet */
value = g_hash_table_lookup(optlist, "sasl_mechanism");
@ -186,7 +191,7 @@ static void cmd_network_add_modify(const char *data, gboolean add)
[-kicks <count>] [-modes <count>] [-cmdspeed <ms>]
[-cmdmax <count>] [-sasl_mechanism <mechanism>]
[-sasl_username <username>] [-sasl_password <password>]
<name> */
[-identifycmd <cmd>] <name> */
static void cmd_network_add(const char *data)
{
cmd_network_add_modify(data, TRUE);
@ -233,9 +238,9 @@ void fe_ircnet_init(void)
command_bind("network remove", NULL, (SIGNAL_FUNC) cmd_network_remove);
command_set_options("network add", "-kicks -msgs -modes -whois -cmdspeed "
"-cmdmax -nick -alternate_nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
"-cmdmax -nick -alternate_nick -user -realname -host -autosendcmd -identifycmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
command_set_options("network modify", "-kicks -msgs -modes -whois -cmdspeed "
"-cmdmax -nick -alternate_nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
"-cmdmax -nick -alternate_nick -user -realname -host -autosendcmd -identifycmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
}
void fe_ircnet_deinit(void)

View file

@ -170,6 +170,7 @@ FORMAT_REC fecommon_irc_formats[] = {
{ "silenced", "Silenced {nick $0}", 1, { 0 } },
{ "unsilenced", "Unsilenced {nick $0}", 1, { 0 } },
{ "silence_line", "{nick $0}: silence {ban $1}", 2, { 0, 0 } },
{ "ask_user_pass", "password:", 0 },
{ "ask_oper_pass", "Operator password:", 0 },
{ "accept_list", "Accepted users: {hilight $0}", 1, { 0 } },

View file

@ -140,7 +140,8 @@ enum {
IRCTXT_SILENCED,
IRCTXT_UNSILENCED,
IRCTXT_SILENCE_LINE,
IRCTXT_ASK_OPER_PASS,
IRCTXT_ASK_USER_PASS,
IRCTXT_ASK_OPER_PASS,
IRCTXT_ACCEPT_LIST
};