Beispiel #1
0
static void log_change_nick(struct plugin_handle* plugin, struct plugin_user* user, const char* new_nick)
{
	struct log_data* ldata = (struct log_data*) plugin->ptr;
	const char* addr = ip_convert_to_string(&user->addr);
	char* nick = strdup(sql_escape_string(user->nick));

	int rc = sql_execute(ldata, null_callback, NULL, "INSERT INTO userlog VALUES('', '%s', '%s', '', '', '%s (%s -> %s)', DATETIME('NOW', 'localtime', '%d hours'));", user->cid, addr, "NickChange", nick, new_nick, ldata->srvtdiff);

	if (rc < 0)
		fprintf(stderr, "[SQLITE LOG] Unable to log: NickChange %s/%s %s \"%s\" -> \"%s\"\n", sid_to_string(user->sid), user->cid, addr, user->nick, new_nick);

	hub_free(nick);
}
Beispiel #2
0
static void log_user_logout(struct plugin_handle* plugin, struct plugin_user* user, const char* reason)
{
	struct log_data* ldata = (struct log_data*) plugin->ptr;
	const char* addr = ip_convert_to_string(&user->addr);
	char* nick = strdup(sql_escape_string(user->nick));
	char* uagent = strdup(sql_escape_string(user->user_agent));

	int rc = sql_execute(ldata, null_callback, NULL, "INSERT INTO userlog VALUES('%s', '%s', '%s', '', '%s', '%s (%s)', DATETIME('NOW', 'localtime', '%d hours'));", nick, user->cid, addr, uagent, "Logout", reason, ldata->srvtdiff);

	if (rc < 0)
		fprintf(stderr, "[SQLITE LOG] Unable to log: Logout %s/%s %s \"%s\" (%s) \"%s\"\n", sid_to_string(user->sid), user->cid, addr, user->nick, reason, user->user_agent);

	hub_free(nick);
	hub_free(uagent);
}
Beispiel #3
0
static void probe_net_event(struct net_connection* con, int events, void *arg)
{
	struct hub_probe* probe = (struct hub_probe*) net_con_get_ptr(con);
	if (events == NET_EVENT_TIMEOUT)
	{
		char buf[512];
		ssize_t len = snprintf(buf, sizeof(buf), "This hub runs on ADC protocol only!\n\nThese are the possible reasons why you see this message:\n\n * you used address without protocol specification, e.g. example.com:1234 instead of adc://example.com:1234\n * your client does not support ADC protocol.\n|$ForceMove %s|", probe->hub->config->nmdc_only_redirect_addr);
		net_con_send(con, buf, (size_t) len);
		probe_destroy(probe);
		return;
	}

	if (events & NET_EVENT_READ)
	{
		int bytes = net_con_peek(con, probe_recvbuf, PROBE_RECV_SIZE);
		if (bytes < 0)
		{
			probe_destroy(probe);
			return;
		}

		if (bytes >= 4)
		{
			if (memcmp(probe_recvbuf, "HSUP", 4) == 0)
			{
				LOG_TRACE("Probed ADC");
#ifdef SSL_SUPPORT
				if (probe->hub->config->tls_enable && probe->hub->config->tls_require)
				{
					LOG_TRACE("Not TLS connection - closing connection.");
					if (*probe->hub->config->tls_require_redirect_addr)
					{
						char buf[512];
						ssize_t len = snprintf(buf, sizeof(buf), "ISUP " ADC_PROTO_SUPPORT "\nISID AAAB\nIINF NIRedirecting...\nIQUI AAAB RD%s\n", probe->hub->config->tls_require_redirect_addr);
						net_con_send(con, buf, (size_t) len);
						LOG_TRACE("Not TLS connection - Redirecting to %s.", probe->hub->config->tls_require_redirect_addr);
					}
					else
					{
						LOG_TRACE("Not TLS connection - closing connection.");
					}
				}
				else
#endif
				if (user_create(probe->hub, probe->connection, &probe->addr))
				{
					probe->connection = 0;
				}
				probe_destroy(probe);
				return;
			}
			else if ((memcmp(probe_recvbuf, "GET ", 4) == 0) ||
				 (memcmp(probe_recvbuf, "POST", 4) == 0) ||
				 (memcmp(probe_recvbuf, "HEAD", 4) == 0))
			{
				/* Looks like HTTP - Not supported, but we log it. */
				LOG_TRACE("Probed HTTP connection. Not supported closing connection (%s)", ip_convert_to_string(&probe->addr));
				const char* buf = "501 Not implemented\r\n\r\n";
				net_con_send(con, buf, strlen(buf));
			}
#ifdef SSL_SUPPORT
			else if (bytes >= 11 &&
				probe_recvbuf[0] == 22 &&
				probe_recvbuf[1] == 3 && /* protocol major version */
				probe_recvbuf[5] == 1 && /* message type */
				probe_recvbuf[9] == probe_recvbuf[1])
			{
				if (probe->hub->config->tls_enable)
				{
					LOG_TRACE("Probed TLS %d.%d connection", (int) probe_recvbuf[1], (int) probe_recvbuf[2]);
					if (user_create(probe->hub, probe->connection, &probe->addr))
					{
						probe->connection = 0;
					}
					net_con_ssl_handshake(con, net_con_ssl_mode_server, probe->hub->ctx);
				}
				else
				{
					LOG_TRACE("Probed TLS %d.%d connection. TLS disabled in hub.", (int) probe_recvbuf[9], (int) probe_recvbuf[10]);
				}
			}
			else
			{
				LOG_TRACE("Probed unsupported protocol: %x%x%x%x.", (int) probe_recvbuf[0], (int) probe_recvbuf[1], (int) probe_recvbuf[2], (int) probe_recvbuf[3]);
			}
#endif
			probe_destroy(probe);
			return;
		}
	}
}
Beispiel #4
0
const char* user_get_address(struct hub_user* user)
{
	return ip_convert_to_string(&user->id.addr);
}