From d27c54486f3e5656445b43affd37f17d1338a6ce Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Tue, 24 Jun 2014 23:01:06 -0700 Subject: [PATCH 1/9] Change around connection signals in proxy module Change "proxy client connected" to "proxy client connecting" to avoid being confused by clients that have connected but not necessarily authenticated. Emit "proxy client connected" once authenticated, keeping the name for backwards compatibility. --- src/irc/proxy/listen.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index 33392285..8f8ebe99 100644 --- a/src/irc/proxy/listen.c +++ b/src/irc/proxy/listen.c @@ -126,6 +126,9 @@ static void handle_client_connect_cmd(CLIENT_REC *client, /* client didn't send us PASS, kill it */ remove_client(client); } else { + signal_emit("proxy client connected", 1, client); + printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Client finished connecting from %s", client->host); client->connected = TRUE; proxy_dump_data(client); } @@ -361,9 +364,9 @@ static void sig_listen(LISTEN_REC *listen) proxy_clients = g_slist_prepend(proxy_clients, rec); rec->listen->clients = g_slist_prepend(rec->listen->clients, rec); - signal_emit("proxy client connected", 1, rec); + signal_emit("proxy client connecting", 1, rec); printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - "Proxy: Client connected from %s", rec->host); + "Proxy: Client connecting from %s", rec->host); } static void sig_incoming(IRC_SERVER_REC *server, const char *line) From aaa0f73eac88316978c65fb0f0c8b5d23d1dc100 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Tue, 24 Jun 2014 23:45:35 -0700 Subject: [PATCH 2/9] Make proxy messages include more detail and add status command --- src/irc/proxy/listen.c | 15 +++++++++------ src/irc/proxy/proxy.c | 34 ++++++++++++++++++++++++++++++++++ src/irc/proxy/proxy.h | 1 + 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index 8f8ebe99..df0d7479 100644 --- a/src/irc/proxy/listen.c +++ b/src/irc/proxy/listen.c @@ -45,8 +45,8 @@ static void remove_client(CLIENT_REC *rec) rec->listen->clients = g_slist_remove(rec->listen->clients, rec); signal_emit("proxy client disconnected", 1, rec); - printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - "Proxy: Client disconnected from %s", rec->host); + printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Client %s:%d disconnected", rec->host, rec->port); g_free(rec->proxy_address); net_sendbuffer_destroy(rec->handle, TRUE); @@ -127,8 +127,9 @@ static void handle_client_connect_cmd(CLIENT_REC *client, remove_client(client); } else { signal_emit("proxy client connected", 1, client); - printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - "Proxy: Client finished connecting from %s", client->host); + printtext(client->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Client %s:%d connected", + client->host, client->port); client->connected = TRUE; proxy_dump_data(client); } @@ -350,6 +351,7 @@ static void sig_listen(LISTEN_REC *listen) rec->listen = listen; rec->handle = sendbuf; rec->host = g_strdup(host); + rec->port = port; if (strcmp(listen->ircnet, "*") == 0) { rec->proxy_address = g_strdup("irc.proxy"); rec->server = servers == NULL ? NULL : IRC_SERVER(servers->data); @@ -365,8 +367,9 @@ static void sig_listen(LISTEN_REC *listen) rec->listen->clients = g_slist_prepend(rec->listen->clients, rec); signal_emit("proxy client connecting", 1, rec); - printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - "Proxy: Client connecting from %s", rec->host); + printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: New client %s:%d on port %d (%s)", + rec->host, rec->port, listen->port, listen->ircnet); } static void sig_incoming(IRC_SERVER_REC *server, const char *line) diff --git a/src/irc/proxy/proxy.c b/src/irc/proxy/proxy.c index c8f47bdf..75da112c 100644 --- a/src/irc/proxy/proxy.c +++ b/src/irc/proxy/proxy.c @@ -23,6 +23,37 @@ #include "settings.h" #include "levels.h" +#include "fe-common/core/printtext.h" + +static void cmd_proxy_status(const char *data, IRC_SERVER_REC *server) +{ + GSList *tmp; + + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Currently connected clients: %d", + g_slist_length(proxy_clients)); + + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + " %s:%d connect%s to %d (%s)", + rec->host, rec->port, + rec->connected ? "ed" : "ing", + rec->listen->port, rec->listen->ircnet); + } +} + +static void cmd_proxy(const char *data, IRC_SERVER_REC *server, void *item) +{ + if (*data == '\0') { + cmd_proxy_status(data, server); + return; + } + + command_runsub("proxy", data, server, item); +} + void irc_proxy_init(void) { settings_add_str("irssiproxy", "irssiproxy_ports", ""); @@ -43,6 +74,9 @@ void irc_proxy_init(void) "... to set them."); } + command_bind("proxy", NULL, (SIGNAL_FUNC) cmd_proxy); + command_bind("proxy status", NULL, (SIGNAL_FUNC) cmd_proxy_status); + proxy_listen_init(); settings_check(); module_register("proxy", "irc"); diff --git a/src/irc/proxy/proxy.h b/src/irc/proxy/proxy.h index 4ddc9da9..158b0675 100644 --- a/src/irc/proxy/proxy.h +++ b/src/irc/proxy/proxy.h @@ -19,6 +19,7 @@ typedef struct { typedef struct { char *nick, *host; + int port; NET_SENDBUF_REC *handle; int recv_tag; char *proxy_address; From 6a28bad81440290e799c4d4985f31bea6493f58b Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Wed, 25 Jun 2014 22:29:05 -0700 Subject: [PATCH 3/9] Add boolean toggle for irssiproxy being enabled --- src/irc/proxy/listen.c | 12 ++++++++++++ src/irc/proxy/proxy.c | 22 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index df0d7479..a5772301 100644 --- a/src/irc/proxy/listen.c +++ b/src/irc/proxy/listen.c @@ -37,6 +37,8 @@ GSList *proxy_clients; static GString *next_line; static int ignore_next; +static int enabled = FALSE; + static void remove_client(CLIENT_REC *rec) { g_return_if_fail(rec != NULL); @@ -682,6 +684,11 @@ static void sig_dump(CLIENT_REC *client, const char *data) void proxy_listen_init(void) { + if (enabled) { + return; + } + enabled = TRUE; + next_line = g_string_new(NULL); proxy_clients = NULL; @@ -703,6 +710,11 @@ void proxy_listen_init(void) void proxy_listen_deinit(void) { + if (!enabled) { + return; + } + enabled = FALSE; + while (proxy_listens != NULL) remove_listen(proxy_listens->data); g_string_free(next_line, TRUE); diff --git a/src/irc/proxy/proxy.c b/src/irc/proxy/proxy.c index 75da112c..1cc8aebe 100644 --- a/src/irc/proxy/proxy.c +++ b/src/irc/proxy/proxy.c @@ -27,6 +27,12 @@ static void cmd_proxy_status(const char *data, IRC_SERVER_REC *server) { + if (!settings_get_bool("irssiproxy")) { + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy is currently disabled"); + return; + } + GSList *tmp; printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, @@ -54,11 +60,21 @@ static void cmd_proxy(const char *data, IRC_SERVER_REC *server, void *item) command_runsub("proxy", data, server, item); } +static void irc_proxy_setup_changed(void) +{ + if (settings_get_bool("irssiproxy")) { + proxy_listen_init(); + } else { + proxy_listen_deinit(); + } +} + void irc_proxy_init(void) { settings_add_str("irssiproxy", "irssiproxy_ports", ""); settings_add_str("irssiproxy", "irssiproxy_password", ""); settings_add_str("irssiproxy", "irssiproxy_bind", ""); + settings_add_bool("irssiproxy", "irssiproxy", TRUE); if (*settings_get_str("irssiproxy_password") == '\0') { /* no password - bad idea! */ @@ -77,7 +93,11 @@ void irc_proxy_init(void) command_bind("proxy", NULL, (SIGNAL_FUNC) cmd_proxy); command_bind("proxy status", NULL, (SIGNAL_FUNC) cmd_proxy_status); - proxy_listen_init(); + signal_add_first("setup changed", (SIGNAL_FUNC) irc_proxy_setup_changed); + + if (settings_get_bool("irssiproxy")) { + proxy_listen_init(); + } settings_check(); module_register("proxy", "irc"); } From ee3f059e6d895cda94bee0a2df7136108012b910 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Wed, 25 Jun 2014 22:38:03 -0700 Subject: [PATCH 4/9] Update proxy documentation with changes --- docs/proxy.txt | 22 ++++++++++++++++++++++ docs/signals.txt | 1 + 2 files changed, 23 insertions(+) diff --git a/docs/proxy.txt b/docs/proxy.txt index 41875aab..759ef1dc 100644 --- a/docs/proxy.txt +++ b/docs/proxy.txt @@ -12,6 +12,11 @@ In irssi, say: /LOAD proxy +If you want the proxy to be loaded automatically at startup, add the +load command to ~/.irssi/startup: + + echo "load proxy" >> ~/.irssi/startup + You really should set some password for the proxy with: /SET irssiproxy_password secret @@ -24,3 +29,20 @@ something like: There we have 3 different irc networks answering in 3 ports. Note that you'll have to make the correct /IRCNET ADD and /SERVER ADD commands to make it work properly. + +By default, the proxy binds to all available interfaces. To make it +only listen on (for example) the loopback address: + + /SET irssiproxy_bind 127.0.0.1 + +Note that bind address changes won't take effect until the proxy is +disabled and then reenabled. + +Once everything is set up, you can enable / disable the proxy: + + /TOGGLE irssiproxy + +When the proxy is configured and running, the following command will +show all the currently connected clients: + + /PROXY status diff --git a/docs/signals.txt b/docs/signals.txt index f0860d3e..bd5849f1 100644 --- a/docs/signals.txt +++ b/docs/signals.txt @@ -220,6 +220,7 @@ notifylist.c: proxy/listen.c: + "proxy client connecting", CLIENT_REC "proxy client connected", CLIENT_REC "proxy client disconnected", CLIENT_REC "proxy client command", CLIENT_REC, char *args, char *data From 178d595c96dafe36a7041864a00e1e45375dab76 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Tue, 1 Jul 2014 21:21:03 -0700 Subject: [PATCH 5/9] Add port to proxy client struct for Perl scripts --- src/perl/irc/Irc.xs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/perl/irc/Irc.xs b/src/perl/irc/Irc.xs index 18665cb7..a245206c 100644 --- a/src/perl/irc/Irc.xs +++ b/src/perl/irc/Irc.xs @@ -149,6 +149,7 @@ static void perl_client_fill_hash(HV *hv, CLIENT_REC *client) { (void) hv_store(hv, "nick", 4, new_pv(client->nick), 0); (void) hv_store(hv, "host", 4, new_pv(client->host), 0); + (void) hv_store(hv, "port", 4, newSViv(client->port), 0); (void) hv_store(hv, "proxy_address", 13, new_pv(client->proxy_address), 0); (void) hv_store(hv, "server", 6, iobject_bless(client->server), 0); (void) hv_store(hv, "pass_sent", 9, newSViv(client->pass_sent), 0); From bbf404b6112aac5cde9732d893e440d9bf363565 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Mon, 15 Dec 2014 18:41:45 -0800 Subject: [PATCH 6/9] Fix whitespace --- src/irc/proxy/listen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index a5772301..a1cda250 100644 --- a/src/irc/proxy/listen.c +++ b/src/irc/proxy/listen.c @@ -368,7 +368,7 @@ static void sig_listen(LISTEN_REC *listen) proxy_clients = g_slist_prepend(proxy_clients, rec); rec->listen->clients = g_slist_prepend(rec->listen->clients, rec); - signal_emit("proxy client connecting", 1, rec); + signal_emit("proxy client connecting", 1, rec); printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE, "Proxy: New client %s:%d on port %d (%s)", rec->host, rec->port, listen->port, listen->ircnet); From 7beffbdcc5d9ca7433f6617a652ed0b2feca3677 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Tue, 24 Feb 2015 19:46:59 -0800 Subject: [PATCH 7/9] Add help files for proxy module --- docs/help/in/proxy.in | 14 ++++++++++++++ src/irc/proxy/proxy.c | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 docs/help/in/proxy.in diff --git a/docs/help/in/proxy.in b/docs/help/in/proxy.in new file mode 100644 index 00000000..2dc61f43 --- /dev/null +++ b/docs/help/in/proxy.in @@ -0,0 +1,14 @@ + +@SYNTAX:proxy@ + +%9Description:%9 + + Displays the list of clients connected to the proxy. + +%9Examples:%9 + + /PROXY + /PROXY STATUS + +%9See also:%9 LOAD PROXY, SET irssiproxy + diff --git a/src/irc/proxy/proxy.c b/src/irc/proxy/proxy.c index 1cc8aebe..65c778d1 100644 --- a/src/irc/proxy/proxy.c +++ b/src/irc/proxy/proxy.c @@ -25,6 +25,7 @@ #include "fe-common/core/printtext.h" +/* SYNTAX: PROXY STATUS */ static void cmd_proxy_status(const char *data, IRC_SERVER_REC *server) { if (!settings_get_bool("irssiproxy")) { @@ -50,6 +51,7 @@ static void cmd_proxy_status(const char *data, IRC_SERVER_REC *server) } } +/* SYNTAX: PROXY */ static void cmd_proxy(const char *data, IRC_SERVER_REC *server, void *item) { if (*data == '\0') { From a47f45b5b7438209177d76f3efde559e61e5bdb7 Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 14 Jun 2015 11:57:11 -0300 Subject: [PATCH 8/9] Rename /proxy command to /irssiproxy for clarity --- docs/help/in/irssiproxy.in | 14 ++++++++++++++ docs/help/in/proxy.in | 14 -------------- docs/proxy.txt | 2 +- src/irc/proxy/proxy.c | 16 ++++++++-------- 4 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 docs/help/in/irssiproxy.in delete mode 100644 docs/help/in/proxy.in diff --git a/docs/help/in/irssiproxy.in b/docs/help/in/irssiproxy.in new file mode 100644 index 00000000..79d75b91 --- /dev/null +++ b/docs/help/in/irssiproxy.in @@ -0,0 +1,14 @@ + +@SYNTAX:irssiproxy@ + +%9Description:%9 + + Displays the list of clients connected to irssiproxy. + +%9Examples:%9 + + /IRSSIPROXY + /IRSSIPROXY STATUS + +%9See also:%9 LOAD PROXY, SET irssiproxy + diff --git a/docs/help/in/proxy.in b/docs/help/in/proxy.in deleted file mode 100644 index 2dc61f43..00000000 --- a/docs/help/in/proxy.in +++ /dev/null @@ -1,14 +0,0 @@ - -@SYNTAX:proxy@ - -%9Description:%9 - - Displays the list of clients connected to the proxy. - -%9Examples:%9 - - /PROXY - /PROXY STATUS - -%9See also:%9 LOAD PROXY, SET irssiproxy - diff --git a/docs/proxy.txt b/docs/proxy.txt index 759ef1dc..e6360a82 100644 --- a/docs/proxy.txt +++ b/docs/proxy.txt @@ -45,4 +45,4 @@ Once everything is set up, you can enable / disable the proxy: When the proxy is configured and running, the following command will show all the currently connected clients: - /PROXY status + /IRSSIPROXY status diff --git a/src/irc/proxy/proxy.c b/src/irc/proxy/proxy.c index 65c778d1..ce79e2b7 100644 --- a/src/irc/proxy/proxy.c +++ b/src/irc/proxy/proxy.c @@ -25,8 +25,8 @@ #include "fe-common/core/printtext.h" -/* SYNTAX: PROXY STATUS */ -static void cmd_proxy_status(const char *data, IRC_SERVER_REC *server) +/* SYNTAX: IRSSIPROXY STATUS */ +static void cmd_irssiproxy_status(const char *data, IRC_SERVER_REC *server) { if (!settings_get_bool("irssiproxy")) { printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, @@ -51,15 +51,15 @@ static void cmd_proxy_status(const char *data, IRC_SERVER_REC *server) } } -/* SYNTAX: PROXY */ -static void cmd_proxy(const char *data, IRC_SERVER_REC *server, void *item) +/* SYNTAX: IRSSIPROXY */ +static void cmd_irssiproxy(const char *data, IRC_SERVER_REC *server, void *item) { if (*data == '\0') { - cmd_proxy_status(data, server); + cmd_irssiproxy_status(data, server); return; } - command_runsub("proxy", data, server, item); + command_runsub("irssiproxy", data, server, item); } static void irc_proxy_setup_changed(void) @@ -92,8 +92,8 @@ void irc_proxy_init(void) "... to set them."); } - command_bind("proxy", NULL, (SIGNAL_FUNC) cmd_proxy); - command_bind("proxy status", NULL, (SIGNAL_FUNC) cmd_proxy_status); + command_bind("irssiproxy", NULL, (SIGNAL_FUNC) cmd_irssiproxy); + command_bind("irssiproxy status", NULL, (SIGNAL_FUNC) cmd_irssiproxy_status); signal_add_first("setup changed", (SIGNAL_FUNC) irc_proxy_setup_changed); From 51496cd09f5d2f2da0a4ae678663c66e2ceae17c Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 14 Jun 2015 16:41:52 -0300 Subject: [PATCH 9/9] Fix 'address already in use' when changing irssiproxy_ports When changing the value of irssiproxy_ports to use a different network name in a port that was already bound (so like changing from asd=6667 to sdf=6667) it would throw "address already in use". This fixes it by delaying the add_listen() calls after all the remove_listen() were called. --- src/irc/proxy/listen.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index a560801d..dc354c30 100644 --- a/src/irc/proxy/listen.c +++ b/src/irc/proxy/listen.c @@ -642,7 +642,8 @@ static void remove_listen(LISTEN_REC *rec) static void read_settings(void) { LISTEN_REC *rec; - GSList *remove_listens; + GSList *remove_listens = NULL; + GSList *add_listens = NULL; char **ports, **tmp, *ircnet, *port; int portnum; @@ -661,17 +662,30 @@ static void read_settings(void) continue; rec = find_listen(ircnet, portnum); - if (rec == NULL) - add_listen(ircnet, portnum); - else + if (rec == NULL) { + rec = g_new0(LISTEN_REC, 1); + rec->ircnet = ircnet; /* borrow */ + rec->port = portnum; + add_listens = g_slist_prepend(add_listens, rec); + } else { + /* remove from the list of listens to remove == keep it */ remove_listens = g_slist_remove(remove_listens, rec); + } } - g_strfreev(ports); while (remove_listens != NULL) { - remove_listen(remove_listens->data); + remove_listen(remove_listens->data); remove_listens = g_slist_remove(remove_listens, remove_listens->data); } + + while (add_listens != NULL) { + rec = add_listens->data; + add_listen(rec->ircnet, rec->port); + g_free(rec); + add_listens = g_slist_remove(add_listens, add_listens->data); + } + + g_strfreev(ports); } static void sig_dump(CLIENT_REC *client, const char *data)