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

Commit

Permalink
Windows port progress
Browse files Browse the repository at this point in the history
  • Loading branch information
TETYYS committed Oct 24, 2015
1 parent c857dd5 commit 18916e6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 36 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required (VERSION 2.6)
project (LiveProxies)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
set (CMAKE_C_FLAGS "-DDEBUG -g ${CMAKE_C_FLAGS}")

if (WIN32)
set (CMAKE_C_FLAGS "--std=gnu99 -Wall ${CMAKE_C_FLAGS}")
Expand Down
34 changes: 16 additions & 18 deletions Harvester.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ void HarvestLoop()
HANDLE d = NULL;

size_t harvestersPathLen = strlen(HarvestersPath);
char *fullPath = malloc((harvestersPathLen + 4) * sizeof(char)); {
char *fullPath = malloc((harvestersPathLen + 3) * sizeof(char)); {
strcpy(fullPath, HarvestersPath);
if (HarvestersPath[harvestersPathLen - 1] == '\\') {
strcat(fullPath, "*.*");
HarvestersPath[harvestersPathLen + 3] = 0x00;
} else
strcat(fullPath, "\\*.*");
HarvestersPath[harvestersPathLen + 4] = 0x00;

if ((d = FindFirstFile(WINDOWS_LOCAL_HTML_PATH"*.*", &fdFile)) == INVALID_HANDLE_VALUE) {
d = false;
strcat(fullPath, "\\*");
fullPath[harvestersPathLen + 2] = 0x00;

if ((d = FindFirstFile(WINDOWS_LOCAL_HTML_PATH"\\*.*", &fdFile)) == INVALID_HANDLE_VALUE) {
Log(LOG_LEVEL_DEBUG, "WIN32: Failed to search files: %d (%s)", GetLastError(), WINDOWS_LOCAL_HTML_PATH"*.*");
if ((d = FindFirstFile(fullPath, &fdFile)) == INVALID_HANDLE_VALUE) {
Log(LOG_LEVEL_ERROR, "WIN32: Failed to search files: %d (%s)", GetLastError(), fullPath);
d = false;
}
}
} free(fullPath);
#endif
Expand Down Expand Up @@ -158,17 +158,13 @@ void HarvestLoop()
sourceType = URL;
if (sourceType == NONE)
continue;

char *path = (char*)malloc(10 + strlen(name) + 1 /* NULL */);
sprintf(path, "%s", name);
path[strlen(path) - (sourceType == SCRIPT ? 3 : 4)] = '\0';

Log(LOG_LEVEL_SUCCESS, "Executing %s... (%s)", path, ProxySourceTypeToString(sourceType));

char *result;
uint32_t added = 0, addedPrev = 0, total = 0;
PROXY_TYPE curType = PROXY_TYPE_HTTP;

if (sourceType == SCRIPT) {
pName = PyString_FromString(path);
pModule = PyImport_Import(pName);
Expand Down Expand Up @@ -214,9 +210,13 @@ void HarvestLoop()
} free(pathFull);
}
if (sourceType == URL) {
char pathFull = malloc((strlen(HarvestersPath) + 1 + fileNameLen) * sizeof(char)); {
char *pathFull = malloc((strlen(HarvestersPath) + 1 + fileNameLen) * sizeof(char) + 1); {
strcpy(pathFull, HarvestersPath);
#ifdef __linux__
strcat(pathFull, "/");
#elif defined _WIN32 || defined _WIN64
strcat(pathFull, "\\");
#endif
strcat(pathFull, name);

FILE *hFile = fopen(pathFull, "r"); {
Expand All @@ -243,15 +243,13 @@ void HarvestLoop()
if (url[strlen(url) - 1] == '\n')
url[strlen(url) - 1] = 0x00;

result = malloc(1);
result = malloc(0);
CURL *hCurl = curl_easy_init(); {
curl_easy_setopt(hCurl, CURLOPT_URL, url);
curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, &result);
curl_easy_setopt(hCurl, CURLOPT_USERAGENT, REQUEST_UA);

CURLcode res = curl_easy_perform(hCurl);

if (res != CURLE_OK) {
Log(LOG_LEVEL_WARNING, "Request to %s failed: %s", url, curl_easy_strerror(res));
} else {
Expand Down
4 changes: 3 additions & 1 deletion Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static bool AuthVerify(char *Buff, struct evbuffer *OutBuff, int Fd, WEB_INTERFA
} pthread_mutex_unlock(&AuthWebLock);
} /* End authorize by cookie */
endCookie:

if (!AllowOnlyCookie) { /* Authorize by login */
char *username, *password;
char *authStr;
Expand Down Expand Up @@ -164,6 +164,8 @@ static bool AuthVerify(char *Buff, struct evbuffer *OutBuff, int Fd, WEB_INTERFA
char *pbkdf2 = PBKDF2_HMAC_SHA_512Ex(password, strlen(password), salt, saltLen, iterations); // TODO: Possible DoS, needs login limit
free(salt);

Log(LOG_LEVEL_DEBUG, "PBKDF2 CMP: %s vs %s", AuthLocalList[x]->password, pbkdf2);

if (strcmp(AuthLocalList[x]->password, pbkdf2) == 0) {
pthread_mutex_unlock(&AuthLocalLock);
free(pbkdf2);
Expand Down
40 changes: 29 additions & 11 deletions LiveProxies.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ int main(int argc, char** argv)
"Accept-Encoding: gzip, deflate, sdch\r\n"
"Accept-Language: en-US,en;q=0.8\r\n"
"{KEY_NAME}: {KEY_VAL}")
// Host and LPKey is injected upon request
StrReplaceOrig(&RequestString, "{VERSION}", VERSION);
// Host and LPKey is injected upon request
StrReplaceOrig(&RequestString, "{VERSION}", VERSION);
StrReplaceOrig(&RequestString, "{UA}", RequestUA);
StrReplaceOrig(&RequestString, "{KEY_NAME}", RequestHeaderKey);
RequestStringLen = strlen(RequestString);
Expand All @@ -459,23 +459,40 @@ int main(int argc, char** argv)
/* Auth init */ {
config_t cfg;
config_init(&cfg);
bool noAuth = false;
bool authExists = true;
AuthLocalList = NULL;
AuthLocalCount = 0;

if (config_read_file(&cfg, "passwd.conf") == CONFIG_FALSE) {
Log(LOG_LEVEL_DEBUG, "Failed to open passwd.conf in working directory, opening in global...: %s (line %d)", config_error_text(&cfg), config_error_line(&cfg));
noAuth = true;
#ifdef __linux__
globalPath = "/etc/liveproxies/passwd.conf";
#elif defined _WIN32 || defined _WIN64
globalPath = malloc((strlen(WinAppData) + 29) * sizeof(char) + 1);
strcpy(globalPath, WinAppData);
strcat(globalPath, "\\liveproxies\\passwd.conf");
#endif
#ifdef __linux__
localPath = "./passwd.conf";
#elif defined _WIN32 || defined _WIN64
localPath = ".\\passwd.conf";
#endif

if (config_read_file(&cfg, localPath) == CONFIG_FALSE) {
Log(LOG_LEVEL_DEBUG, "Failed to open %s in working directory, opening in global...: %s (line %d)", localPath, config_error_text(&cfg), config_error_line(&cfg));
authExists = false;
}

if (noAuth) {
if (config_read_file(&cfg, "/etc/liveproxies/passwd.conf") == CONFIG_FALSE)
Log(LOG_LEVEL_DEBUG, "Failed to open /etc/liveproxies/passwd.conf: %s (line %d)", config_error_text(&cfg), config_error_line(&cfg));
if (!authExists) {
if (config_read_file(&cfg, globalPath) == CONFIG_FALSE)
Log(LOG_LEVEL_DEBUG, "Failed to open %s: %s (line %d)", globalPath, config_error_text(&cfg), config_error_line(&cfg));
else
noAuth = false;
authExists = false;
}

if (!noAuth) {
#if defined _WIN32 || defined _WIN64
free(globalPath);
#endif

if (authExists) {
pthread_mutex_init(&AuthLocalLock, NULL);
config_setting_t *cfgRoot = config_root_setting(&cfg);
size_t x = 0;
Expand All @@ -495,6 +512,7 @@ int main(int argc, char** argv)

AuthLocalList[AuthLocalCount - 1]->username = malloc((strlen(val) * sizeof(char)) + 1);
strcpy((char*)AuthLocalList[AuthLocalCount - 1]->username, val);
Log(LOG_LEVEL_DEBUG, "Added user %s", AuthLocalList[AuthLocalCount - 1]->username);
} else {
AuthLocalList[AuthLocalCount - 1]->password = malloc((strlen(val) * sizeof(char)) + 1);
strcpy((char*)AuthLocalList[AuthLocalCount - 1]->password, val);
Expand Down
4 changes: 1 addition & 3 deletions Logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
#include <stdio.h>
#include <stdlib.h>

#define DEBUG 1

void _Log(char *File, int Line, LOG_LEVEL Level, const char *Format, ...)
{
if (Level == LOG_LEVEL_DEBUG) {
#if !DEBUG
#ifndef DEBUG
return;
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions Server.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "HtmlTemplate.h"
#include "Websocket.h"
#include <stdio.h>
#if DEBUG
#if defined DEBUG && defined __linux__
#include <valgrind/memcheck.h>
#endif
#include <openssl/rand.h>
Expand Down Expand Up @@ -411,7 +411,7 @@ void ServerRead(struct bufferevent *BuffEvent, void *Ctx)
char *buff = malloc(len + 1);
evbuffer_copyout(evBuff, buff, len);

#if DEBUG
#if defined DEBUG && defined __linux__
VALGRIND_MAKE_MEM_DEFINED(buff, len + 1);
#endif

Expand Down
Binary file modified bin/win32_mingw/LiveProxies.exe
Binary file not shown.

0 comments on commit 18916e6

Please sign in to comment.