updated the printf to the echo/log function

This commit is contained in:
2021-12-04 10:38:13 -05:00
parent 20f166f9cd
commit 2a10d1f83d

View File

@@ -85,19 +85,8 @@ $randomString = getRandString(5);
echo_write_log($randomString, "Start of Script " . $argv[0]); echo_write_log($randomString, "Start of Script " . $argv[0]);
echo_write_log($randomString, "WAN Interface: " . $wanInterface); echo_write_log($randomString, "WAN Interface: " . $wanInterface);
echo_write_log($randomString, "Name of static WAN Gateway: " . $gatewayName); echo_write_log($randomString, "Name of static WAN Gateway: " . $gatewayName);
echo_write_log($randomString, "Static WAN IP: " . $wanStaticIP);
echo_write_log($randomString, "Static WAN Subnit Bits: " . $wanStaticIPSubnet);
printf("Trying to ping sync host, %s. \n", $syncIP);
exec("ping -c 4 " . $syncIP, $output, $result);
if ($result == 0) {
printf("Ping is successful. No need to update. \n");
if ($force) {
printf("Force was passed in, so continuing with script. \n");
} else {
return;
}
}
printf("WAN Interface Name: %s \n", $wanInterface); printf("WAN Interface Name: %s \n", $wanInterface);
printf("Gateway Name: %s \n", $gatewayName); printf("Gateway Name: %s \n", $gatewayName);
@@ -105,7 +94,7 @@ printf("WAN Static IP: %s \n", $wanStaticIP);
printf("WAN Subnet: %s \n", $wanStaticIPSubnet); printf("WAN Subnet: %s \n", $wanStaticIPSubnet);
printf("Sync IP: %s \n", $syncIP); printf("Sync IP: %s \n", $syncIP);
do { do {
printf("Setting WAN to DHCP. \n"); echo_write_log($randomString, "Setting WAN to DHCP");
# Config for WAN DHCP and disable static gateway # Config for WAN DHCP and disable static gateway
$config['interfaces'][$wanInterface]['ipaddr'] = 'dhcp'; $config['interfaces'][$wanInterface]['ipaddr'] = 'dhcp';
@@ -120,10 +109,10 @@ do {
# set the config and reload everything to get a working DHCP # set the config and reload everything to get a working DHCP
write_config_and_restart_services($wanInterface); write_config_and_restart_services($wanInterface);
printf("Done setting WAN to DHCP. \n"); echo_write_log($randomString, "Done setting WAN to DHCP");
# DHCP ip address and gateway address loop # DHCP ip address and gateway address loop
printf("Getting DHCP and Gateway IP Addresses. \n"); echo_write_log($randomString, "Getting DHCP and Gateway IP Addresses");
# get DHCP wan address and subnet # get DHCP wan address and subnet
@@ -151,20 +140,20 @@ do {
$wanIP = $ifcfg['details']['ipv4'][0]['ipaddr']; $wanIP = $ifcfg['details']['ipv4'][0]['ipaddr'];
$wanSubnet = $ifcfg['details']['ipv4'][0]['subnetbits']; $wanSubnet = $ifcfg['details']['ipv4'][0]['subnetbits'];
printf("WAN DHCP IP: %s \n", $wanIP); echo_write_log($randomString, "WAN DHCP IP: " . $wanIP);
printf("WAN DHCP Sbunet Bits: %s \n", $wanSubnet); echo_write_log($randomString, "WAN DHCP Sbunet Bits: " . $wanSubnet);
$gatewayIP = trim(shell_exec('netstat -rn | grep default | awk \'{print $2;}\'')); $gatewayIP = trim(shell_exec('netstat -rn | grep default | awk \'{print $2;}\''));
printf("Gateway IP: %s \n", $gatewayIP); echo_write_log($randomString, "Gateway IP: " . $gatewayIP);
printf("Done getting DHCP and Gateway IP Addresses. \n"); echo_write_log($randomString, "Done getting DHCP and Gateway IP Addresses");
if (filter_var($wanIP, FILTER_VALIDATE_IP) and is_int($wanSubnet) and filter_var($gatewayIP, FILTER_VALIDATE_IP)) { if (filter_var($wanIP, FILTER_VALIDATE_IP) and is_int($wanSubnet) and filter_var($gatewayIP, FILTER_VALIDATE_IP)) {
printf("WAN IP, Subnet Bits, and Gateway IP are okay. \n"); echo_write_log($randomString, "WAN IP, Subnet Bits, and Gateway IP are okay");
break; break;
} else { } else {
printf("Warning: Missing WAN IP, Subnet Bits, or Gateway IP. Trying again. \n"); echo_write_log($randomString, "Warning: Missing WAN IP, Subnet Bits, or Gateway IP. Trying again...");
} }
} while (true); } while (true);
printf("Setting WAN to Static based on the DHCP information. \n"); echo_write_log($randomString, "Setting WAN to Static based on the DHCP information");
# Config for WAN Static # Config for WAN Static
$config['interfaces'][$wanInterface]['ipaddr'] = $wanStaticIP; $config['interfaces'][$wanInterface]['ipaddr'] = $wanStaticIP;
@@ -200,28 +189,28 @@ foreach ($config['virtualip']['vip'] as $i => $vip) {
# set the config and reload everything to get a working DHCP # set the config and reload everything to get a working DHCP
write_config_and_restart_services($wanInterface); write_config_and_restart_services($wanInterface);
printf("Done Setting WAN to Static based on the DHCP information. \n"); echo_write_log($randomString, "Done Setting WAN to Static based on the DHCP information");
printf("Sleeping for 30 seconds. \n"); echo_write_log($randomString, "Sleeping for 30 seconds");
sleep(30); sleep(30);
# try to sync carp settings to backup node/router # try to sync carp settings to backup node/router
printf("Starting the CARP Sync. \n"); echo_write_log($randomString, "Starting the CARP Sync");
printf("Trying to ping sync host, %s. \n", $syncIP); echo_write_log($randomString, "Trying to ping sync host, " . $syncIP);
do { do {
exec("ping -c 4 " . $syncIP, $output, $result); exec("ping -c 4 " . $syncIP, $output, $result);
if ($result == 0) { if ($result == 0) {
printf("Ping is successful. \n"); echo_write_log($randomString, "Ping is successful");
break; break;
} else { } else {
printf("Ping unsuccessful. \n"); echo_write_log($randomString, "Ping unsuccessful");
} }
} while (true) } while (true)
printf("Sleeping for 30 seconds. \n"); echo_write_log($randomString, "Sleeping for 30 seconds");
sleep(30); sleep(30);
$syncStatus = shell_exec('configctl system ha_reconfigure_backup'); $syncStatus = shell_exec('configctl system ha_reconfigure_backup');
printf("CARP Sync Status: %s. \n", $syncStatus); echo_write_log($randomString, "CARP Sync Status: " . $syncStatus);
printf("finished the CARP Sync. \n"); echo_write_log($randomString, "finished the CARP Sync");