Browse Source

fix: custom rules apply at update process

dev
Dnomd343 2 years ago
parent
commit
e655984d2c
  1. 2
      include/loader/loader.h
  2. 4
      include/utils/assets.h
  3. 8
      src/common/system.c
  4. 7
      src/loader/loader.c
  5. 20
      src/utils/assets.c

2
include/loader/loader.h

@ -20,6 +20,8 @@ struct cleardns {
extern struct cleardns loader; extern struct cleardns loader;
void load_diverter_assets();
void load_config(const char *config_file); void load_config(const char *config_file);
#endif #endif

4
include/utils/assets.h

@ -3,6 +3,10 @@
#include <stdint.h> #include <stdint.h>
extern char **custom_gfwlist;
extern char **custom_china_ip;
extern char **custom_chinalist;
typedef struct { typedef struct {
char *file; // string char *file; // string
char **sources; // string list char **sources; // string list

8
src/common/system.c

@ -95,11 +95,3 @@ void save_string_list(const char *file, char **string_list) { // save string lis
fclose(fp); fclose(fp);
log_debug("Save `%s` success", file); log_debug("Save `%s` success", file);
} }
void download_file(const char *file, const char *url) { // download file
log_debug("Download file `%s` -> %s", file, url);
char *download_cmd = string_load("wget -T 8 -O %s %s", file, url);
if (run_command(download_cmd)) {
log_warn("File `%s` download failed", url);
}
}

7
src/loader/loader.c

@ -95,6 +95,13 @@ overture* load_diverter(cleardns_config *config) {
free(china_ip); free(china_ip);
free(gfwlist); free(gfwlist);
custom_gfwlist = config->diverter.gfwlist;
custom_china_ip = config->diverter.china_ip;
custom_chinalist = config->diverter.chinalist;
config->diverter.gfwlist = string_list_init();
config->diverter.china_ip = string_list_init();
config->diverter.chinalist = string_list_init();
uint32_list_update(&diverter->reject_type, config->reject); uint32_list_update(&diverter->reject_type, config->reject);
if (!config->assets.disable) { if (!config->assets.disable) {
assets_extract(); // extract built-in resource assets_extract(); // extract built-in resource

20
src/utils/assets.c

@ -1,15 +1,20 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include "assets.h"
#include "loader.h"
#include "logger.h" #include "logger.h"
#include "sundry.h" #include "sundry.h"
#include "system.h" #include "system.h"
#include "constant.h" #include "constant.h"
#include "structure.h" #include "structure.h"
#include "assets.h"
asset **update_info; asset **update_info;
char **custom_gfwlist;
char **custom_china_ip;
char **custom_chinalist;
void assets_update_entry(); void assets_update_entry();
void extract(const char *file); void extract(const char *file);
@ -83,7 +88,18 @@ void assets_update_entry() { // receive SIGALRM for update all assets
} }
free(content); free(content);
} }
// TODO: refresh `/etc/cleardns/*.txt`
char *gfwlist = string_join(WORK_DIR, ASSET_GFW_LIST);
char *china_ip = string_join(WORK_DIR, ASSET_CHINA_IP);
char *chinalist = string_join(WORK_DIR, ASSET_CHINA_LIST);
save_string_list(gfwlist, custom_gfwlist);
save_string_list(china_ip, custom_china_ip);
save_string_list(chinalist, custom_chinalist);
free(chinalist);
free(china_ip);
free(gfwlist);
load_diverter_assets(); // load assets data into `WORK_DIR`
log_info("Restart overture to apply new assets"); log_info("Restart overture to apply new assets");
run_command("pgrep overture | xargs kill"); // restart overture run_command("pgrep overture | xargs kill"); // restart overture
log_info("Assets update complete"); log_info("Assets update complete");

Loading…
Cancel
Save