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/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 diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index 33392285..a1cda250 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); @@ -45,8 +47,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); @@ -126,6 +128,10 @@ 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(client->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Client %s:%d connected", + client->host, client->port); client->connected = TRUE; proxy_dump_data(client); } @@ -347,6 +353,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); @@ -361,9 +368,10 @@ 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); - printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - "Proxy: Client connected from %s", rec->host); + 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); } static void sig_incoming(IRC_SERVER_REC *server, const char *line) @@ -676,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; @@ -697,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 c8f47bdf..65c778d1 100644 --- a/src/irc/proxy/proxy.c +++ b/src/irc/proxy/proxy.c @@ -23,11 +23,60 @@ #include "settings.h" #include "levels.h" +#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")) { + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy is currently disabled"); + return; + } + + 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); + } +} + +/* SYNTAX: PROXY */ +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); +} + +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! */ @@ -43,7 +92,14 @@ void irc_proxy_init(void) "... to set them."); } - proxy_listen_init(); + command_bind("proxy", NULL, (SIGNAL_FUNC) cmd_proxy); + command_bind("proxy status", NULL, (SIGNAL_FUNC) cmd_proxy_status); + + 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"); } 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; 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);