mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
commit
2b13e793c4
14
docs/help/in/irssiproxy.in
Normal file
14
docs/help/in/irssiproxy.in
Normal file
@ -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
|
||||
|
@ -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:
|
||||
|
||||
/IRSSIPROXY status
|
||||
|
@ -225,6 +225,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
|
||||
|
@ -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 (g_strcmp0(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)
|
||||
@ -634,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;
|
||||
|
||||
@ -653,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)
|
||||
@ -676,6 +698,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 +724,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);
|
||||
|
@ -23,11 +23,60 @@
|
||||
#include "settings.h"
|
||||
#include "levels.h"
|
||||
|
||||
#include "fe-common/core/printtext.h"
|
||||
|
||||
/* 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,
|
||||
"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: IRSSIPROXY */
|
||||
static void cmd_irssiproxy(const char *data, IRC_SERVER_REC *server, void *item)
|
||||
{
|
||||
if (*data == '\0') {
|
||||
cmd_irssiproxy_status(data, server);
|
||||
return;
|
||||
}
|
||||
|
||||
command_runsub("irssiproxy", 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("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);
|
||||
|
||||
if (settings_get_bool("irssiproxy")) {
|
||||
proxy_listen_init();
|
||||
}
|
||||
settings_check();
|
||||
module_register("proxy", "irc");
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
char *nick, *host;
|
||||
int port;
|
||||
NET_SENDBUF_REC *handle;
|
||||
int recv_tag;
|
||||
char *proxy_address;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user