From 5573c3b86a8817c3cdf7ff123d0704844d5d86a3 Mon Sep 17 00:00:00 2001 From: Wizzard Date: Fri, 8 Mar 2024 07:28:39 -0500 Subject: [PATCH] Change vpn data location to /tmp/vpndb --- src/main.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 31067f8..5397404 100644 --- a/src/main.c +++ b/src/main.c @@ -8,10 +8,23 @@ #include #include -#define VPN_LIST_PATH "/tmp/ipv4.txt" +#define VPN_DB_DIR "/tmp/vpndb" +#define VPN_LIST_PATH VPN_DB_DIR "/ipv4.txt" #define VPN_LIST_URL "https://raw.githubusercontent.com/X4BNet/lists_vpn/main/ipv4.txt" +int ensure_directory_exists(const char *dirPath) { + struct stat st = {0}; + + if (stat(dirPath, &st) == -1) { + if (mkdir(dirPath, 0755) == -1) { + fprintf(stderr, "Failed to create directory %s\n", dirPath); + return -1; + } + } + return 0; +} + unsigned long ip_to_ulong(const char *ip) { struct in_addr inVal; if (inet_aton(ip, &inVal)) { @@ -58,6 +71,7 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { } int download_vpn_list(const char *url, const char *output_path) { + printf("Downloading VPN lists...\n"); struct stat fileInfo; time_t now; @@ -117,6 +131,11 @@ int main(int argc, char *argv[]) { return 1; } + if (ensure_directory_exists(VPN_DB_DIR) != 0) { + fprintf(stderr, "Failed to create VPN database directory.\n"); + return 1; + } + if (download_vpn_list(VPN_LIST_URL, VPN_LIST_PATH) != 0) { fprintf(stderr, "Failed to download VPN list.\n"); return 1;