Skip to content
This repository has been archived by the owner on Jun 24, 2023. It is now read-only.

Commit

Permalink
Merge branch 'dev' -> release 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Jun 5, 2016
2 parents 5eaaf2a + 35306a6 commit 788bbb2
Show file tree
Hide file tree
Showing 40 changed files with 1,951 additions and 819 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ compiler:
before_script:
- sudo apt-get update -qq
- sudo apt-get install -qq cmake python python-dev liblua5.2-dev ruby ruby-dev libperl-dev tcl-dev default-jdk
- curl -fsSL https://github.com/ARMmbed/mbedtls/archive/mbedtls-1.3.13.tar.gz | tar xz && cd mbedtls-mbedtls-1.3.13 && cmake . -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_SHARED_LINKER_FLAGS="-pie" && sudo make install
- curl -fSsL https://tls.mbed.org/download/mbedtls-2.2.0-gpl.tgz|tar xz && cd mbedtls-2.2.0 && cmake . -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_SHARED_LINKER_FLAGS="-pie" && make && sudo make install && cd ..

script: cmake . -DDEBUG=on && make && make clean && cmake . -DDEBUG=off && make

Expand Down
44 changes: 28 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ option(DEBUG_SSL "Enable SSL debug" OFF)
option(DEBUG_LEAK "Enable memleak checks" OFF)

if (DEBUG)
message("-- Compiling as debug mode")
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_FLAGS_DEBUG "-ggdb -DDEBUG -O0")
set(CMAKE_VERBOSE_MAKEFILE ON)

if(DEBUG_LEAK)

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
message("-- Compiling with sanitizers")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address")
endif(DEBUG_LEAK)

if (DEBUG_SSL)
message("-- Compiling with SSL debug informations")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG_SSL")
endif(DEBUG_SSL)

Expand Down Expand Up @@ -120,18 +122,19 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(EXTRA_LIBS "-lpthread")


# check for polarssl (*REQUIRED*)
find_package(PolarSSL REQUIRED)
if(POLARSSL_FOUND AND POLARSSL_INCLUDE_DIR AND POLARSSL_LIBRARIES)
add_definitions(-DHAVE_POLARSSL)
include_directories(${POLARSSL_INCLUDE_DIR})
set(EXTRA_LIBS ${EXTRA_LIBS} ${POLARSSL_LIBRARIES})
set(_POLARSSL_VERSION_ ${POLARSSL_VERSION})
message("-- PolarSSL ${POLARSSL_VERSION} found!")
# check for mbedtls (*REQUIRED*)
find_package(MbedTLS REQUIRED)
if(MBEDTLS_FOUND AND MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
add_definitions(-DHAVE_MBEDTLS)
include_directories(${MBEDTLS_INCLUDE_DIR})
set(EXTRA_LIBS ${EXTRA_LIBS} ${MBEDTLS_LIBRARIES})
set(_MBEDTLS_VERSION_ ${MBEDTLS_VERSION})
message("-- mbedTLS ${MBEDTLS_VERSION} found!")
else()
return()
endif()


# prepare compilation
set(ALL_FILES ${CORE_FILES})

Expand Down Expand Up @@ -276,16 +279,25 @@ target_link_libraries(proxenet ${EXTRA_LIBS} ${CMAKE_LINK_HARDEN})

# install
set (MANDIR /usr/share/man/man1)
install (TARGETS proxenet DESTINATION bin)

add_custom_target( setup )
add_custom_command (TARGET setup
POST_BUILD
COMMAND bash cmake/setup.sh ${CMAKE_SOURCE_DIR} ${CMAKE_INSTALL_PREFIX} ${MANDIR})
if(DEBUG)
install (TARGETS proxenet DESTINATION bin CONFIGURATIONS Debug)
else()
install (TARGETS proxenet DESTINATION bin CONFIGURATIONS Release)
endif()
install (DIRECTORY docs
DESTINATION misc
PATTERN "*.md" EXCLUDE
)
install (FILES proxenet-control-cli.py proxenet-control-web.py keys/proxenet-setup-ca.sh
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION misc
)
install (FILES proxenet.1
DESTINATION ${MANDIR})

add_custom_target( uninstall )
add_custom_command (TARGET uninstall
POST_BUILD
COMMAND echo "* Deleting ${PROGNAME} tree"
COMMAND rm -fr "${CMAKE_INSTALL_PREFIX}" "${MANDIR}/${PROGNAME}.1.gz"
)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ browser.
``` bash
$ git clone https://github.com/hugsy/proxenet.git
$ cd proxenet && cmake . && make
$ sudo make install setup
```


Expand Down
4 changes: 2 additions & 2 deletions cmake/FindLua.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_search_module(LUA lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua-5.0 lua5.0 lua50 lua)
endif()
pkg_search_module(LUA lua53 lua-5.3 lua5.3 lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua-5.0 lua5.0 lua50 lua)
endif()
53 changes: 53 additions & 0 deletions cmake/FindMbedTLS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Try to find mbedTLS library
#
# Once done this will define
# MBEDTLS_FOUND
# MBEDTLS_INCLUDE_DIR
# MBEDTLS_LIBRARIES
# MBEDTLS_VERSION_MAJOR
# MBEDTLS_VERSION_MINOR
# MBEDTLS_VERSION_PATCH
# MBEDTLS_VERSION

include(FindPackageHandleStandardArgs)
find_path(MBEDTLS_INCLUDE_DIR NAMES mbedtls/ssl.h)
find_library(MBEDTLS_LIB NAMES mbedtls)
find_package_handle_standard_args(MBEDTLS REQUIRED_VARS MBEDTLS_INCLUDE_DIR MBEDTLS_LIB)

if( ${MBEDTLS_LIBRARIES-NOTFOUND} )
message(FATAL_ERROR "Failed to get info from Mbedtls library, check your Mbedtls installation")
set(MBEDTLS_FOUND False)
return()
endif()

execute_process(
COMMAND bash -c "echo \"#include <mbedtls/version.h>\n#include <stdio.h>\nint main(){printf(MBEDTLS_VERSION_STRING);return 0;}\">a.c;cc a.c -I${MBEDTLS_INCLUDE_DIR} ${MBEDTLS_LIBRARIES} ;./a.out;rm -f a.c a.out"
OUTPUT_VARIABLE MBEDTLS_VERSION
)

string(REPLACE "." ";" MBEDTLS_VERSION_LIST ${MBEDTLS_VERSION})

list(GET ${MBEDTLS_VERSION_LIST} 0 MBEDTLS_VERSION_MAJOR)
list(GET ${MBEDTLS_VERSION_LIST} 1 MBEDTLS_VERSION_MINOR)
list(GET ${MBEDTLS_VERSION_LIST} 2 MBEDTLS_VERSION_PATCH)

if( ${MBEDTLS_VERSION} VERSION_LESS "2.1.0")
message(FATAL_ERROR "Mbedtls 2.1+ is required for compiling ${PROGNAME} (current is ${MBEDTLS_VERSION}).")
set(MBEDTLS_FOUND False)
return()
endif()

find_library(MBEDX509_LIB NAMES mbedx509)
find_library(MBEDCRYPTO_LIB NAMES mbedcrypto)
set(MBEDTLS_LIBRARIES ${MBEDX509_LIB} ${MBEDTLS_LIB} ${MBEDCRYPTO_LIB})

set(MBEDTLS_FOUND True)
mark_as_advanced(
MBEDTLS_FOUND
MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARIES
MBEDTLS_VERSION_MAJOR
MBEDTLS_VERSION_MINOR
MBEDTLS_VERSION_PATCH
MBEDTLS_VERSION
)
2 changes: 1 addition & 1 deletion cmake/FindRuby.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(RUBY_FOUND)
endif()

find_program(RUBY_EXECUTABLE
NAMES ruby2.2 ruby22 ruby2.1 ruby21 ruby2.0 ruby2 ruby1.9.3 ruby193 ruby1.9.2 ruby192 ruby1.9.1 ruby191 ruby1.9 ruby19 ruby1.8 ruby18 ruby
NAMES ruby2.4 ruby24 ruby2.3 ruby23 ruby2.2 ruby22 ruby2.1 ruby21 ruby2.0 ruby2 ruby1.9.3 ruby193 ruby1.9.2 ruby192 ruby1.9.1 ruby191 ruby1.9 ruby19 ruby1.8 ruby18 ruby
PATHS /usr/bin /usr/local/bin /usr/pkg/bin
)
if(RUBY_EXECUTABLE)
Expand Down
34 changes: 0 additions & 34 deletions cmake/setup.sh

This file was deleted.

21 changes: 13 additions & 8 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,30 @@
#include <netinet/in.h>
#endif

#define MAX_THREADS 50 // maximum number of threads
#define CFG_DEFAULT_LOCATION "@CMAKE_INSTALL_PREFIX@"
#define PROXENET_HOME_DIR "~/.proxenet"

#define MAX_THREADS 100 // maximum number of threads
#define CFG_DEFAULT_BIND_ADDR "localhost" // default binding address
#define CFG_DEFAULT_BIND_PORT "8008" // default binding port
#define CFG_DEFAULT_PROXY_PORT "8080" // if relay is enabled, use this port as default
#define CFG_DEFAULT_NB_THREAD 20 // default number of threads
#define CFG_DEFAULT_TRY_EXIT_MAX 3 // default number for attempting to kill the process gently
#define CFG_DEFAULT_PLUGIN_PRIORITY 5 // default priority for plugins
#define CFG_DEFAULT_OUTPUT stdout // default output file stream
#define CFG_DEFAULT_PLUGINS_PATH "./proxenet-plugins" // default location of plugins
#define CFG_DEFAULT_PLUGINS_AUTOLOAD_PATH "/autoload" // default name of autoload dir (*Must* start with a '/')
#define CFG_DEFAULT_SSL_CERTFILE "./keys/proxenet.crt" // default path of SSL private certificate
#define CFG_DEFAULT_SSL_KEYFILE "./keys/proxenet.key" // default path of SSL private key
#define CFG_DEFAULT_PLUGINS_PATH PROXENET_HOME_DIR"/plugins" // default location of plugins
#define CFG_DEFAULT_PLUGINS_AUTOLOAD_PATHNAME "autoload" // default name of autoload dir (*Must* start with a '/')
#define CFG_DEFAULT_SSL_CERTFILE PROXENET_HOME_DIR"/keys/proxenet.crt" // default path of SSL private certificate
#define CFG_DEFAULT_SSL_KEYFILE PROXENET_HOME_DIR"/keys/proxenet.key" // default path of SSL private key
#define CFG_DEFAULT_SSL_KEYFILE_PWD "" // default password for the SSL private key
#define CFG_DEFAULT_SSL_CERTSDIR "./keys/certs" // default path of stored certificates
#define CFG_DEFAULT_SSL_CERTSKEY "./keys/certs/generic.key" // default path of stored certificates private key
#define CFG_DEFAULT_SSL_CERTSDIR PROXENET_HOME_DIR"/keys/certs" // default path of stored certificates
#define CFG_DEFAULT_SSL_CERTSKEY PROXENET_HOME_DIR"/keys/certs/generic.key" // default path of stored certificates private key
#define CFG_DEFAULT_SSL_CERTSPWD "" // default password for stored certificates private key
#define CFG_DEFAULT_IP_VERSION AF_INET // IP version (AF_INET for IPv6 or AF_INET6 for IPv6)
#define CFG_REQUEST_PLUGIN_FUNCTION "proxenet_request_hook" // default name for hooking request function
#define CFG_RESPONSE_PLUGIN_FUNCTION "proxenet_response_hook" // default name for hooking response function
#define CFG_ONLOAD_PLUGIN_FUNCTION "proxenet_on_load" // default name for on-load trigger function
#define CFG_ONLEAVE_PLUGIN_FUNCTION "proxenet_on_leave" // default name for on-leave trigger function
#define CFG_DEFAULT_SSL_CLIENT_DOMAIN "*" // default domain to use the SSL client certificate (* means any)
#define CFG_DEFAULT_INTERCEPT_PATTERN "*" // default pattern to intercept (all)
#define CFG_CONTROL_SOCK_PATH "/tmp/proxenet-control-socket"
Expand Down Expand Up @@ -68,7 +73,7 @@
#define CC "@CMAKE_C_COMPILER_ID@"


#cmakedefine _POLARSSL_VERSION_ "@POLARSSL_VERSION@"
#cmakedefine _MBEDTLS_VERSION_ "@MBEDTLS_VERSION@"

#cmakedefine _C_PLUGIN
#cmakedefine _C_VERSION_ "C"
Expand Down
94 changes: 84 additions & 10 deletions control-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ COMMAND_SIGNATURE(reload);
COMMAND_SIGNATURE(threads);
COMMAND_SIGNATURE(plugin);
COMMAND_SIGNATURE(config);
COMMAND_SIGNATURE(version);

static struct command_t known_commands[] = {
COMMAND(quit, 0, "Make "PROGNAME" leave kindly"),
COMMAND(restart, 0, "Make "PROGNAME" restart"),
COMMAND(help, 0, "Show this menu"),
COMMAND(info, 0, "Display information about environment"),
COMMAND(reload, 0, "Reload the plugins"),
COMMAND(threads, 0, "Show info about threads"),
COMMAND(threads, 1, "Command the threads"),
COMMAND(plugin, 1, "Get/Set info about plugin"),
COMMAND(config, 1, "Edit configuration at runtime"),

COMMAND(version, 0, "Show proxenet version"),
{ NULL, 0, NULL, NULL}
};

Expand Down Expand Up @@ -198,6 +199,51 @@ static void help_cmd(sock_t fd, char *options, unsigned int nb_options)
}


/**
* Show proxenet version
*/
static void version_cmd(sock_t fd, char *options, unsigned int nb_options)
{
char *msg = "{"
"\"name\": \""PROGNAME"\", "
"\"author\": \""AUTHOR"\", "
"\"version\": \""VERSION"\", "
"\"compilation\": \""CC" for "SYSTEM" using MBedTLS "_MBEDTLS_VERSION_"\", "
"\"vms\": [ "
#ifdef _C_PLUGIN
"\""_C_VERSION_"\","
#endif
#ifdef _PYTHON_PLUGIN
"\""_PYTHON_VERSION_"\","
#endif
#ifdef _RUBY_PLUGIN
"\""_RUBY_VERSION_"\","
#endif
#ifdef _LUA_PLUGIN
"\""_LUA_VERSION_"\","
#endif
#ifdef _JAVA_PLUGIN
"\""_JAVA_VERSION_"\","
#endif
#ifdef _TCL_PLUGIN
"\""_TCL_VERSION_"\","
#endif
#ifdef _PERL_PLUGIN
"\""_PERL_VERSION_"\","
#endif
"\"\"],"
"\"license\": \""LICENSE"\" "
"}";

/* happy compiler means karma++ */
(void) options;
(void) nb_options;

proxenet_write(fd, (void*)msg, strlen(msg));
return;
}


/**
* Get information about proxenet state.
*/
Expand Down Expand Up @@ -294,8 +340,11 @@ static void reload_cmd(sock_t fd, char *options, unsigned int nb_options)
static void threads_cmd(sock_t fd, char *options, unsigned int nb_options)
{
char msg[BUFSIZE] = {0, };
char *static_msg;
char *ptr;
int n;
int n, res;
long long tid;


(void) options;
(void) nb_options;
Expand All @@ -308,14 +357,39 @@ static void threads_cmd(sock_t fd, char *options, unsigned int nb_options)
return;
}

if (strcmp(ptr, "inc")==0 && cfg->nb_threads<MAX_THREADS)
n = proxenet_xsnprintf(msg, BUFSIZE, "Nb threads level is now %d\n", ++cfg->nb_threads);
else if (strcmp(ptr, "dec")==0 && cfg->nb_threads>1)
n = proxenet_xsnprintf(msg, BUFSIZE, "Nb threads level is now %d\n", --cfg->nb_threads);
else
n = proxenet_xsnprintf(msg, BUFSIZE, "Invalid action\n Syntax\n threads (inc|dec)\n");
if (strcmp(ptr, "inc")==0 && cfg->nb_threads<MAX_THREADS){
n = proxenet_xsnprintf(msg, BUFSIZE, "Nb threads level is now %d", ++cfg->nb_threads);
proxenet_write(fd, (void*)msg, n);
} else if (strcmp(ptr, "dec")==0 && cfg->nb_threads>1){
n = proxenet_xsnprintf(msg, BUFSIZE, "Nb threads level is now %d", --cfg->nb_threads);
proxenet_write(fd, (void*)msg, n);
} else if (strcmp(ptr, "kill")==0){
ptr = strtok(NULL, " \n");
if (!ptr){
static_msg = "Missing ThreadId";
proxenet_write(fd, (void*)static_msg, strlen(static_msg));
return;
}

proxenet_write(fd, (void*)msg, n);
tid = atoll(ptr);
if(tid<=0){
static_msg = "Invalid ThreadId value";
proxenet_write(fd, (void*)static_msg, strlen(static_msg));
return;
}

res = proxenet_kill_thread((pthread_t)tid);
if(res==0){
n = proxenet_xsnprintf(msg, BUFSIZE, "Thread %lu killed successfully", tid);
} else {
n = proxenet_xsnprintf(msg, BUFSIZE, "Failed to kill thread %lu: retcode=%d", tid, res);
}

proxenet_write(fd, (void*)msg, n);
} else {
static_msg = "Invalid action: must be in (inc|dec)";
proxenet_write(fd, (void*)static_msg, strlen(static_msg));
}

return;
}
Expand Down
Loading

0 comments on commit 788bbb2

Please sign in to comment.