You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
975 B
C

#include "tor.h"
#include "model/server.h"
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int start_tor()
{
if( g_server->disable_tor ) {
return 1;
}
mkdir( "data/tor", 0755 );
chdir( "data/tor" );
char wd[512];
getcwd( wd, sizeof(wd) );
FILE* f = fopen( "torrc", "w" );
fprintf( f, "SOCKSPort %d\n", g_server->tor_socks_port );
fprintf( f, "SOCKSPolicy accept 127.0.0.1/8\n" );
fprintf( f, "SOCKSPolicy reject *\n" );
fprintf( f, "Log notice stdout\n" );
fprintf( f, "DataDirectory %s\n", wd );
fprintf( f, "HiddenServiceDir %s/hidden_service\n", wd );
fprintf( f, "HiddenServicePort 80 127.0.0.1:%d\n", g_server->http_settings.bind_port );
fclose(f);
printf( "Starting tor...\n" );
fflush(stdout);
static char *argv[] = {
"/usr/bin/tor",
"-f",
"torrc"
};
execve( "/usr/bin/tor", argv, NULL );
printf( "Failed to start tor: %s\n", strerror(errno) );
return 0;
}