Пример #1
0
static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
{
	char *resp = trans->p_rsp_body;

	DO(http_status_valid(trans->status));

	if (strstr(resp, "KO") || strstr(resp, "OK") || strstr(resp, "good"))
		return RC_OK;

	return RC_DYNDNS_RSP_NOTOK;
}
Пример #2
0
/* Freedns afraid.org.specific response validator.
   ok blabla and n.n.n.n
    fail blabla and n.n.n.n
    are the good answers. We search our own IP address in response and that's enough.
*/
static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *alias)
{
	char *resp = trans->p_rsp_body;

	DO(http_status_valid(trans->status));

	if (strstr(resp, alias->address))
		return 0;

	return RC_DYNDNS_RSP_NOTOK;
}
Пример #3
0
static int response(http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias)
{
	char *resp = trans->rsp_body;

	DO(http_status_valid(trans->status));

	if (strstr(resp, "OK"))
		return RC_OK;

	return RC_DDNS_RSP_NOTOK;
}
Пример #4
0
/*
 * Hurricate Electric IPv6 tunnelbroker specific response validator
 * Own IP address and 'already in use' are the good answers.
 */
static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *alias)
{
	char *resp = trans->p_rsp_body;

	DO(http_status_valid(trans->status));

	if (strstr(resp, alias->address) ||
	    strstr(resp, "already"))
//	    strstr(resp, "-ERROR: This tunnel is already associated with this IP address."))
		return RC_OK;

	return RC_DYNDNS_RSP_NOTOK;
}
Пример #5
0
/*
 * NOERROR is the OK code here
 */
static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
{
	char *resp = trans->p_rsp_body;

	DO(http_status_valid(trans->status));

	if (strstr(resp, "NOERROR"))
		return RC_OK;

	if (strstr(resp, "TOOSOON"))
		return RC_DYNDNS_RSP_RETRY_LATER;

	return RC_DYNDNS_RSP_NOTOK;
}
Пример #6
0
/*
 * DynDNS response validator -- common to many other DDNS providers as well
 *  'good' or 'nochg' are the good answers,
 */
int common_response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
{
	char *body = trans->p_rsp_body;

	DO(http_status_valid(trans->status));

	if (strstr(body, "good") || strstr(body, "nochg"))
		return 0;

	if (strstr(body, "dnserr") || strstr(body, "911"))
		return RC_DYNDNS_RSP_RETRY_LATER;

	return RC_DYNDNS_RSP_NOTOK;
}
Пример #7
0
/*
 * ZoneEdit OK codes are:
 *  CODE=200, 201
 *  CODE=707, for duplicated updates
 */
static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
{
	int code = -1;

	DO(http_status_valid(trans->status));

	sscanf(trans->rsp_body, "%*s CODE=\"%4d\" ", &code);
	switch (code) {
	case 200:
	case 201:
	case 707:
		/* XXX: is 707 really OK? */
		return 0;
	default:
		break;
	}

	return RC_DYNDNS_RSP_NOTOK;
}
Пример #8
0
static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
{
	int   code = -1;
	char *tmp;

	DO(http_status_valid(trans->status));

	tmp = strstr(trans->p_rsp_body, "\n");
	if (tmp)
		sscanf(++tmp, "%4d=", &code);

	switch (code) {
	case 0:
	case 1:
		return 0;
	case 4:
	case 11:
		return RC_DYNDNS_RSP_RETRY_LATER;
	default:
		break;
	}

	return RC_DYNDNS_RSP_NOTOK;
}
Пример #9
0
static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
{
	int           i, rc = 0;
	http_t        client;
	http_trans_t  trans;
	char         *buf, *tmp, *line, *hash = NULL;
	char          host[256], updateurl[256];
	char          buffer[256];
	char          digeststr[SHA1_DIGEST_BYTES * 2 + 1];
	unsigned char digestbuf[SHA1_DIGEST_BYTES];

	do {
		TRY(http_construct(&client));

		http_set_port(&client, info->server_name.port);
		http_set_remote_name(&client, info->server_name.name);
		http_set_bind_iface(&client, ctx->bind_interface);

		client.ssl_enabled = info->ssl_enabled;
		if (client.ssl_enabled)	/* XXX: Fix this better, possibly in http_init() */
			client.tcp.ip.port = 443;

		TRY(http_init(&client, "Sending update URL query"));

		snprintf(buffer, sizeof(buffer), "%s|%s",
			 info->creds.username, info->creds.password);
		sha1((unsigned char *)buffer, strlen(buffer), digestbuf);
		for (i = 0; i < SHA1_DIGEST_BYTES; i++)
			sprintf(&digeststr[i * 2], "%02x", digestbuf[i]);

		snprintf(buffer, sizeof(buffer), "/api/?action=getdyndns&sha=%s", digeststr);
		trans.req_len     = snprintf(ctx->request_buf, ctx->request_buflen,
					     GENERIC_HTTP_REQUEST, buffer, info->server_name.name);
		trans.p_req       = ctx->request_buf;
		trans.p_rsp       = ctx->work_buf;
		trans.max_rsp_len = ctx->work_buflen - 1;	/* Save place for a \0 at the end */

		rc  = http_transaction(&client, &trans);
		rc |= http_exit(&client);

		http_destruct(&client, 1);

		if (rc)
			break;

		TRY(http_status_valid(trans.status));

		tmp = buf = strdup(trans.p_rsp_body);
		for (line = strsep(&tmp, "\n"); line; line = strsep(&tmp, "\n")) {
			int num;

			num = sscanf(line, "%255[^|\r\n]|%*[^|\r\n]|%255[^|\r\n]", host, updateurl);
			if (*line && num == 2 && !strcmp(host, alias->name)) {
				hash = strstr(updateurl, "?");
				break;
			}
		}
		free(buf);

		if (!hash)
			rc = RC_DYNDNS_RSP_NOTOK;
		else
			hash++;
	}
	while (0);

	if (rc) {
		logit(LOG_INFO, "Update URL query failed");
		return 0;
	}

	return snprintf(ctx->request_buf, ctx->request_buflen,
		       FREEDNS_UPDATE_IP_REQUEST,
		       info->server_url,
		       hash, alias->address,
		       info->server_name.name);
}