added random string and echo/log functions
This commit is contained in:
@@ -45,6 +45,17 @@ if (count($argv) > 1){
|
||||
}
|
||||
}
|
||||
|
||||
function getRandString($n) {
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$randomString = '';
|
||||
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
$index = rand(0, strlen($characters) - 1);
|
||||
$randomString .= $characters[$index];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
function write_config_and_restart_services ($interface) {
|
||||
write_config();
|
||||
@@ -58,6 +69,24 @@ function write_config_and_restart_services ($interface) {
|
||||
rrd_configure(true);
|
||||
}
|
||||
|
||||
function echo_write_log ($randomString, $message) {
|
||||
$dateTime = date("Y-m-d H:i:s");
|
||||
$folder = '/var/log/opnsense_carp_dhcp';
|
||||
$message = $dateTime . " - " . $randomString . " - " . $message . "\n";
|
||||
if (!is_dir($folder)) {
|
||||
mkdir($folder);
|
||||
}
|
||||
file_put_contents("$folder/log_".date("Ymd").".log", $message, FILE_APPEND);
|
||||
echo $message;
|
||||
}
|
||||
|
||||
$randomString = getRandString(5);
|
||||
|
||||
echo_write_log($randomString, "Start of Script " . $argv[0]);
|
||||
echo_write_log($randomString, "WAN Interface: " . $wanInterface);
|
||||
echo_write_log($randomString, "Name of static WAN Gateway: " . $gatewayName);
|
||||
|
||||
|
||||
printf("Trying to ping sync host, %s. \n", $syncIP);
|
||||
exec("ping -c 4 " . $syncIP, $output, $result);
|
||||
if ($result == 0) {
|
||||
|
||||
Reference in New Issue
Block a user