Browse Source

update: extract assets

dev
Dnomd343 2 years ago
parent
commit
128bd1bb2f
  1. 2
      include/utils/assets.h
  2. 3
      src/applet/adguard.c
  3. 26
      src/cleardns.c
  4. 11
      src/loader/loader.c
  5. 12
      src/utils/assets.c

2
include/utils/assets.h

@ -1,6 +1,6 @@
#ifndef ASSETS_H_ #ifndef ASSETS_H_
#define ASSETS_H_ #define ASSETS_H_
void load_assets(); void extract_assets();
#endif #endif

3
src/applet/adguard.c

@ -87,6 +87,9 @@ process* adguard_load(adguard *info, const char *dir) { // load adguard options
create_folder(dir); // ensure adguard work dir exist create_folder(dir); // ensure adguard work dir exist
char *adguard_config_ret; char *adguard_config_ret;
char *adguard_config_file = string_join(dir, "AdGuardHome.yaml"); char *adguard_config_file = string_join(dir, "AdGuardHome.yaml");
// TODO: skip to-json if AdGuardHome configure not exist
char *adguard_config_raw = to_json(adguard_config_file); char *adguard_config_raw = to_json(adguard_config_file);
if (adguard_config_raw == NULL) { // configure not exist if (adguard_config_raw == NULL) { // configure not exist
log_info("Create AdGuardHome configure"); log_info("Create AdGuardHome configure");

26
src/cleardns.c

@ -11,6 +11,7 @@
#include "system.h" #include "system.h"
#include "sundry.h" #include "sundry.h"
#include "structure.h" #include "structure.h"
#include "assets.h"
char* init(int argc, char *argv[]) { // return config file char* init(int argc, char *argv[]) { // return config file
char *config = string_init(CONFIG_FILE); char *config = string_init(CONFIG_FILE);
@ -61,18 +62,29 @@ int main(int argc, char *argv[]) { // ClearDNS service
create_folder(WORK_DIR); create_folder(WORK_DIR);
// TODO: load assets first // TODO: load assets first
extract_assets();
load_config(config_file); load_config(config_file);
free(config_file); free(config_file);
// process_list_init(); if (LOG_LEVEL == LOG_DEBUG) { // debug mode enabled
// process_list_append(dnsproxy_load("Domestic", loader.domestic, "domestic.json")); loader.filter->debug = TRUE;
// process_list_append(dnsproxy_load("Foreign", loader.foreign, "foreign.json")); loader.diverter->debug = TRUE;
// process_list_append(overture_load(loader.diverter, "overture.json")); loader.domestic->debug = TRUE;
// if (loader.filter != NULL) { loader.foreign->debug = TRUE;
// process_list_append(adguard_load(loader.filter, ADGUARD_DIR)); }
// }
process_list_init();
// TODO: crontab of assets
process_list_append(dnsproxy_load("Domestic", loader.domestic, "domestic.json"));
process_list_append(dnsproxy_load("Foreign", loader.foreign, "foreign.json"));
process_list_append(overture_load(loader.diverter, "overture.json"));
if (loader.filter != NULL) {
process_list_append(adguard_load(loader.filter, ADGUARD_DIR));
}
// TODO: running custom script // TODO: running custom script
for (char **script = loader.script; *script != NULL; ++script) {
log_info("Run custom script -> `%s`", *script);
}
// process_list_run(); // process_list_run();

11
src/loader/loader.c

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "config.h" #include "config.h"
#include "loader.h" #include "loader.h"
#include "logger.h"
#include "parser.h" #include "parser.h"
#include "sundry.h" #include "sundry.h"
#include "system.h" #include "system.h"
@ -9,7 +10,6 @@
#include "dnsproxy.h" #include "dnsproxy.h"
#include "constant.h" #include "constant.h"
#include "structure.h" #include "structure.h"
#include "logger.h"
struct cleardns loader; struct cleardns loader;
@ -114,8 +114,13 @@ adguard* load_filter(cleardns_config *config) {
} }
assets_config* load_assets(cleardns_config *config) { assets_config* load_assets(cleardns_config *config) {
// TODO: load assets assets_config *assets = (assets_config *)malloc(sizeof(assets_config));
return NULL; assets->update_url = string_list_init();
assets->update_file = string_list_init();
assets->cron = string_init(config->assets.cron);
string_list_update(&assets->update_url, config->assets.update_url);
string_list_update(&assets->update_file, config->assets.update_file);
return assets;
} }
void load_config(const char *config_file) { // parser and load cleardns configure void load_config(const char *config_file) { // parser and load cleardns configure

12
src/utils/assets.c

@ -6,20 +6,20 @@
#include "system.h" #include "system.h"
#include "constant.h" #include "constant.h"
void load_asset(const char *file); void extract_asset(const char *file);
// TODO: assets update -> crontab task // TODO: assets update -> crontab task
void load_assets() { void extract_assets() {
log_info("Start loading assets"); log_info("Start loading assets");
create_folder(ASSETS_DIR); create_folder(ASSETS_DIR);
load_asset(ASSET_GFW_LIST); extract_asset(ASSET_GFW_LIST);
load_asset(ASSET_CHINA_IP); extract_asset(ASSET_CHINA_IP);
load_asset(ASSET_CHINA_LIST); extract_asset(ASSET_CHINA_LIST);
log_info("Assets loaded complete"); log_info("Assets loaded complete");
} }
void load_asset(const char *file) { void extract_asset(const char *file) {
log_debug("Start extract `%s`", file); log_debug("Start extract `%s`", file);
char *output_file = string_join(ASSETS_DIR, file); char *output_file = string_join(ASSETS_DIR, file);
if (is_file_exist(output_file)) { if (is_file_exist(output_file)) {

Loading…
Cancel
Save