mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Check and create v6 migration directory before trying to move/write files there. This involves config migrations but also Teleporter importing
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
#include <libgen.h>
|
||||
// restart_ftl()
|
||||
#include "signals.h"
|
||||
// create_migration_target_v6()
|
||||
#include "config/config.h"
|
||||
|
||||
#define MAXFILESIZE (50u*1024*1024)
|
||||
|
||||
@@ -264,6 +266,9 @@ static int api_teleporter_POST(struct ftl_conn *api)
|
||||
NULL);
|
||||
}
|
||||
|
||||
// Ensure v6 migration directory exists
|
||||
create_migration_target_v6();
|
||||
|
||||
// Check if we received something that claims to be a ZIP archive
|
||||
// - filename should end in ".zip"
|
||||
// - the data itself
|
||||
|
||||
+36
-1
@@ -1624,13 +1624,19 @@ bool readFTLconf(struct config *conf, const bool rewrite)
|
||||
if(!rewrite)
|
||||
return false;
|
||||
|
||||
// Check if MIGRATION_TARGET_V6 exists and is a directory
|
||||
// Ideally, this directory should be created by the installer but users
|
||||
// may have deleted it manually and it is necessary for restoring
|
||||
// Teleporter files
|
||||
create_migration_target_v6();
|
||||
|
||||
// If no previous config file could be read, we are likely either running
|
||||
// for the first time or we are upgrading from a version prior to v6.0
|
||||
// In this case, we try to read the legacy config files
|
||||
const char *path = "";
|
||||
if((path = readFTLlegacy(conf)) != NULL)
|
||||
{
|
||||
const char *target = "/etc/pihole/migration_backup_v6/pihole-FTL.conf";
|
||||
const char *target = MIGRATION_TARGET_V6"/pihole-FTL.conf";
|
||||
log_info("Moving %s to %s", path, target);
|
||||
if(rename(path, target) != 0)
|
||||
log_warn("Unable to move %s to %s: %s", path, target, strerror(errno));
|
||||
@@ -1903,3 +1909,32 @@ static bool port_in_use(const in_port_t port)
|
||||
close(sock);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a migration target directory for version 6.
|
||||
*
|
||||
* This function creates a directory for migration target version 6. If the directory
|
||||
* already exists, it does nothing. The function also changes the ownership of the
|
||||
* directory to the user running the FTL program.
|
||||
*
|
||||
* @return true if the directory creation and ownership change were successful, false otherwise.
|
||||
*/
|
||||
bool create_migration_target_v6(void)
|
||||
{
|
||||
if(mkdir(MIGRATION_TARGET_V6, 0755) != 0 && errno != EEXIST)
|
||||
{
|
||||
log_err("Unable to create directory %s: %s", MIGRATION_TARGET_V6, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Change ownership of the directory to the user running FTL
|
||||
if(chown(MIGRATION_TARGET_V6, getuid(), getgid()) != 0)
|
||||
{
|
||||
log_err("Unable to change ownership of %s: %s", MIGRATION_TARGET_V6, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
// Location of the legacy (pre-v6.0) config file
|
||||
#define GLOBALCONFFILE_LEGACY "/etc/pihole/pihole-FTL.conf"
|
||||
|
||||
// Migration target for the legacy (pre-v6.0) config file
|
||||
#define MIGRATION_TARGET_V6 "/etc/pihole/migration_backup_v6"
|
||||
|
||||
union conf_value {
|
||||
bool b; // boolean value
|
||||
int i; // integer value
|
||||
@@ -363,6 +366,7 @@ bool check_paths_equal(char **paths1, char **paths2, unsigned int max_level) __a
|
||||
const char *get_conf_type_str(const enum conf_type type) __attribute__ ((const));
|
||||
void replace_config(struct config *newconf);
|
||||
void reread_config(void);
|
||||
bool create_migration_target_v6(void);
|
||||
|
||||
// Defined in toml_reader.c
|
||||
bool readDebugSettings(void);
|
||||
|
||||
@@ -24,12 +24,12 @@ bool write_custom_list(void);
|
||||
|
||||
#define DNSMASQ_PH_CONFIG "/etc/pihole/dnsmasq.conf"
|
||||
#define DNSMASQ_TEMP_CONF "/etc/pihole/dnsmasq.conf.temp"
|
||||
#define DNSMASQ_STATIC_LEASES "/etc/pihole/migration_backup_v6/04-pihole-static-dhcp.conf"
|
||||
#define DNSMASQ_CNAMES "/etc/pihole/migration_backup_v6/05-pihole-custom-cname.conf"
|
||||
#define DNSMASQ_STATIC_LEASES MIGRATION_TARGET_V6"/04-pihole-static-dhcp.conf"
|
||||
#define DNSMASQ_CNAMES MIGRATION_TARGET_V6"/05-pihole-custom-cname.conf"
|
||||
#define DNSMASQ_HOSTSDIR "/etc/pihole/hosts"
|
||||
#define DNSMASQ_CUSTOM_LIST DNSMASQ_HOSTSDIR"/custom.list"
|
||||
#define DNSMASQ_CUSTOM_LIST_LEGACY "/etc/pihole/custom.list"
|
||||
#define DNSMASQ_CUSTOM_LIST_LEGACY_TARGET "/etc/pihole/migration_backup_v6/custom.list"
|
||||
#define DNSMASQ_CUSTOM_LIST_LEGACY_TARGET MIGRATION_TARGET_V6"/custom.list"
|
||||
#define DHCPLEASESFILE "/etc/pihole/dhcp.leases"
|
||||
|
||||
#endif //DNSMASQ_CONFIG_H
|
||||
|
||||
@@ -589,7 +589,7 @@ void importsetupVarsConf(void)
|
||||
get_conf_string_from_setupVars("WEB_PORTS", &config.webserver.port);
|
||||
|
||||
// Move the setupVars.conf file to the migration directory
|
||||
const char *setupVars_target = "/etc/pihole/migration_backup_v6/setupVars.conf";
|
||||
const char *setupVars_target = MIGRATION_TARGET_V6"/setupVars.conf";
|
||||
if(rename(config.files.setupVars.v.s, setupVars_target) != 0)
|
||||
log_warn("Could not move %s to %s", config.files.setupVars.v.s, setupVars_target);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user