Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
NON-WORKING: Added custom page requests
Browse files Browse the repository at this point in the history
Fixed single recheck initialization
  • Loading branch information
TETYYS committed Sep 18, 2015
1 parent da60d45 commit 846e449
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "IPv6Map.h"
#include <stddef.h>

#define VERSION "0.8.0"
#define VERSION "0.8.1"
#define CALLBACK
#define OUT
#define MEM_OUT
Expand Down
1 change: 1 addition & 0 deletions Harvester.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void HarvestLoop()

size_t AddProxyHarvesterFormat(char *In, PROXY_TYPE *CurrentType)
{
// TODO: Add in proxy sources
if (strncmp(In, "setType", 7) == 0)
*CurrentType = atoll(In + 8);

Expand Down
144 changes: 107 additions & 37 deletions Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

void InterfaceInit()
{
InterfacePagesSize = 11;
InterfacePagesSize = 7;
InterfacePages = malloc(InterfacePagesSize * sizeof(INTERFACE_PAGE));
InterfacePages[0].name = "Home";
InterfacePages[0].page = INTERFACE_PAGE_HOME;
Expand All @@ -31,16 +31,8 @@ void InterfaceInit()
InterfacePages[4].page = INTERFACE_PAGE_STATS;
InterfacePages[5].name = "Proxy recheck";
InterfacePages[5].page = INTERFACE_PAGE_RECHECK;
InterfacePages[6].name = "Raw Spamhaus ZEN output";
InterfacePages[6].page = INTERFACE_PAGE_SPAMHAUS;
InterfacePages[7].name = "Raw Reverse DNS output";
InterfacePages[7].page = INTERFACE_PAGE_RDNS;
InterfacePages[8].name = "Raw proxy check output";
InterfacePages[8].page = INTERFACE_PAGE_CHECK;
InterfacePages[9].name = "Raw proxy add";
InterfacePages[9].page = INTERFACE_PAGE_ADD;
InterfacePages[10].name = "Tools";
InterfacePages[10].page = INTERFACE_PAGE_TOOLS;
InterfacePages[6].name = "Tools";
InterfacePages[6].page = INTERFACE_PAGE_TOOLS;
}

// Please lock AuthWebLock
Expand Down Expand Up @@ -608,17 +600,20 @@ static PROXY *GetProxyFromUidBuff(char *Buff)
{
PROXY *proxy = NULL;

char *pathStart = strstr(Buff, "?uid=");
if (pathStart == NULL)
char *uidStart = strstr(Buff, "?uid=");
if (uidStart == NULL)
return NULL;

char *pathEnd = strchr(pathStart, ' ');
if (pathEnd == NULL)
return NULL;
char *uidEnd = strchr(uidStart, '&');
if (uidEnd == NULL) {
uidEnd = strchr(uidStart, ' ');
if (uidEnd == NULL)
return NULL;
}

*pathEnd = 0x00;
*uidEnd = 0x00;

return GetProxyFromUid(pathStart + (5 * sizeof(char)));
return GetProxyFromUid(uidStart + (5 * sizeof(char)));
}

void InterfaceProxyRecheck(struct bufferevent *BuffEvent, char *Buff)
Expand All @@ -636,6 +631,8 @@ void InterfaceProxyRecheck(struct bufferevent *BuffEvent, char *Buff)
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
if (HtmlTemplateUseStock)
bufferevent_free(BuffEvent);
return;
}

Expand Down Expand Up @@ -669,7 +666,6 @@ void InterfaceProxyRecheck(struct bufferevent *BuffEvent, char *Buff)
bufferevent_free(BuffEvent);
evbuffer_free(headers);
} else {

if (proxy == NULL) {
bufferevent_write(BuffEvent, "HTTP/1.1 404 Not found\r\nContent-Length: 15\r\n\r\nProxy not found", 61 * sizeof(char));
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);
Expand Down Expand Up @@ -718,6 +714,7 @@ void InterfaceRawSpamhausZen(struct bufferevent *BuffEvent, char *Buff)
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}

Expand All @@ -728,6 +725,7 @@ void InterfaceRawSpamhausZen(struct bufferevent *BuffEvent, char *Buff)
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}

Expand All @@ -750,6 +748,7 @@ void InterfaceRawHttpBL(struct bufferevent *BuffEvent, char *Buff)
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}

Expand All @@ -775,11 +774,6 @@ void InterfaceRawReverseDNS(struct bufferevent *BuffEvent, char *Buff)
struct evbuffer *body = evbuffer_new();
INTERFACE_INFO info;

for (size_t x = 0;x < InterfacePagesSize;x++) {
if (InterfacePages[x].page == INTERFACE_PAGE_RECHECK)
info.currentPage = &(InterfacePages[x]);
}

if (!AuthVerify(Buff, headers, bufferevent_getfd(BuffEvent), &info, false)) {
bufferevent_write_buffer(BuffEvent, headers);
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);
Expand Down Expand Up @@ -874,16 +868,12 @@ void InterfaceRawRecheck(struct bufferevent *BuffEvent, char *Buff)
struct evbuffer *headers = evbuffer_new();
INTERFACE_INFO info;

for (size_t x = 0;x < InterfacePagesSize;x++) {
if (InterfacePages[x].page == INTERFACE_PAGE_RECHECK)
info.currentPage = &(InterfacePages[x]);
}

if (!AuthVerify(Buff, headers, bufferevent_getfd(BuffEvent), &info, false)) {
bufferevent_write_buffer(BuffEvent, headers);
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}

Expand All @@ -894,13 +884,15 @@ void InterfaceRawRecheck(struct bufferevent *BuffEvent, char *Buff)
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}
if (proxy->rechecking) {
bufferevent_write(BuffEvent, "HTTP/1.1 403 Forbidden\r\nContent-Length: 18\r\n\r\nAlready rechecking", 64 * sizeof(char));
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}

Expand All @@ -912,9 +904,6 @@ void InterfaceRawRecheck(struct bufferevent *BuffEvent, char *Buff)

void InterfaceRawUProxyAdd(struct bufferevent *BuffEvent, char *Buff)
{
if (Buff == NULL) {

}
struct evbuffer *headers = evbuffer_new();
struct evbuffer *body = evbuffer_new();
INTERFACE_INFO info;
Expand All @@ -923,16 +912,12 @@ void InterfaceRawUProxyAdd(struct bufferevent *BuffEvent, char *Buff)
PROXY_TYPE type;
char *offset = &(Buff[8]);

/*for (size_t x = 0;x < InterfacePagesSize;x++) {
if (InterfacePages[x].page == INTERFACE_PAGE_ADD)
info.currentPage = &(InterfacePages[x]);
}*/

if (!AuthVerify(Buff, headers, bufferevent_getfd(BuffEvent), &info, false)) {
bufferevent_write_buffer(BuffEvent, headers);
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}

Expand Down Expand Up @@ -1147,4 +1132,89 @@ void InterfaceTools(struct bufferevent *BuffEvent, char *Buff)

evbuffer_free(headers);
evbuffer_free(body);
}

static void InterfaceRawGetCustomPageStage2(UNCHECKED_PROXY *UProxy)
{
struct bufferevent *buffEvent = (struct bufferevent*)UProxy->singleCheckCallbackExtraData;

if (!UProxy->checkSuccess) {
bufferevent_write(buffEvent, "HTTP/1.1 504 Gateway Timeout\r\nContent-Length: 23\r\nContent-Type: text/html\r\n\r\nProxy connection failure", 101);
bufferevent_flush(buffEvent, EV_WRITE, BEV_FINISHED);
Log(LOG_LEVEL_DEBUG, "BuffEvent free %p", buffEvent);
bufferevent_free(buffEvent);
return;
}

bufferevent_write_buffer(buffEvent, bufferevent_get_input(UProxy->assocBufferEvent));

pthread_mutex_unlock(&(UProxy->processing));

bufferevent_flush(buffEvent, EV_WRITE, BEV_FINISHED);
Log(LOG_LEVEL_DEBUG, "BuffEvent free %p", buffEvent);
bufferevent_free(buffEvent);
return;
}

void InterfaceRawGetCustomPage(struct bufferevent *BuffEvent, char *Buff)
{
struct evbuffer *headers = evbuffer_new();
struct evbuffer *body = evbuffer_new();
INTERFACE_INFO info;

if (!AuthVerify(Buff, headers, bufferevent_getfd(BuffEvent), &info, false)) {
bufferevent_write_buffer(BuffEvent, headers);
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(body);
evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}

char *newLine = strchr(Buff, '\n');

PROXY *proxy = GetProxyFromUidBuff(Buff);

if (proxy == NULL) {
bufferevent_write(BuffEvent, "HTTP/1.1 404 Not found\r\nContent-Length: 15\r\n\r\nProxy not found", 61 * sizeof(char));
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(body);
evbuffer_free(headers);
bufferevent_free(BuffEvent);
return;
}

char *pageStart = strstr((strlen(Buff) + 1) * sizeof(char), "&page="); // That's because GetProxyFromUidBuff puts 0x00 at & or \x20 in path (& in this situation, if page= exists). Search page= at one character from 0x00
if (pageStart == NULL || pageStart >= newLine) {
evbuffer_add(body, "Missing page parameter", 22 * sizeof(char));
goto fail;
}

char *pageEnd = strchr(pageStart, ' ');
if (pageEnd == NULL) {
evbuffer_add(body, "Malformed request", 17 * sizeof(char));
goto fail;
}

*pageEnd = 0x00;

PageRequest(proxy, InterfaceRawGetCustomPageStage2, pageStart, NULL);

evbuffer_free(headers);
evbuffer_free(body);

return;
fail:
evbuffer_add_printf(headers, "%d", evbuffer_get_length(body)); // To Content-Length
evbuffer_add(headers, "\r\nContent-Type: text/html\r\n\r\n", 29 * sizeof(char));

bufferevent_write_buffer(BuffEvent, headers);
bufferevent_write_buffer(BuffEvent, body);
bufferevent_flush(BuffEvent, EV_WRITE, BEV_FINISHED);

evbuffer_free(headers);
evbuffer_free(body);
bufferevent_free(BuffEvent);
}
3 changes: 2 additions & 1 deletion Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ void InterfaceRawRecheck (struct bufferevent *BuffEvent, char *Buff);
void InterfaceRawHttpBL (struct bufferevent *BuffEvent, char *Buff);
void InterfaceRawUProxyAdd (struct bufferevent *BuffEvent, char *Buff);
void InterfaceTools (struct bufferevent *BuffEvent, char *Buff);
void InterfaceRawUProxyAddProcessPost (struct bufferevent *BuffEvent, char *Buff);
void InterfaceRawUProxyAddProcessPost (struct bufferevent *BuffEvent, char *Buff);
void InterfaceRawGetCustomPage (struct bufferevent *BuffEvent, char *Buff);
2 changes: 1 addition & 1 deletion LiveProxies.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ int main(int argc, char** argv)
} /* End GlobalIP */

CONFIG_STRING(cfgRoot, "RequestHeaders", RequestString,
"GET /prxchk HTTP/1.1\r\n"
"GET {PAGE_PATH} HTTP/1.1\r\n"
"Host: {HOST}\r\n"
"Connection: Close\r\n"
"Cache-Control: max-age=0\r\n"
Expand Down
6 changes: 6 additions & 0 deletions ProxyLists.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ void UProxyFree(UNCHECKED_PROXY *In)
event_free(In->timeout);
}
pthread_mutex_destroy(&(In->processing));
if (In->pageTarget != NULL)
free(In->pageTarget);
if (In->targetIPv4 != NULL)
free(In->targetIPv4);
if (In->targetIPv6 != NULL)
free(In->targetIPv6);
free(In->ip);
free(In);
}
Expand Down
Loading

0 comments on commit 846e449

Please sign in to comment.