|
@ -1,19 +1,23 @@ |
|
|
package a8k.app.service.setting; |
|
|
package a8k.app.service.setting; |
|
|
|
|
|
|
|
|
import a8k.app.service.data.AppUserMgrService; |
|
|
|
|
|
import a8k.app.type.exception.AppException; |
|
|
|
|
|
import a8k.app.dao.DeviceSettingDao; |
|
|
import a8k.app.dao.DeviceSettingDao; |
|
|
import a8k.app.dao.LISSettingDao; |
|
|
import a8k.app.dao.LISSettingDao; |
|
|
|
|
|
|
|
|
import a8k.app.dao.type.db.DeviceSetting; |
|
|
import a8k.app.dao.type.db.DeviceSetting; |
|
|
import a8k.app.dao.type.db.LISSetting; |
|
|
import a8k.app.dao.type.db.LISSetting; |
|
|
import a8k.app.hardware.type.A8kEcode; |
|
|
import a8k.app.hardware.type.A8kEcode; |
|
|
|
|
|
import a8k.app.service.data.AppUserMgrService; |
|
|
|
|
|
import a8k.app.type.exception.AppException; |
|
|
import a8k.app.utils.IPAddressValidator; |
|
|
import a8k.app.utils.IPAddressValidator; |
|
|
import jakarta.annotation.PostConstruct; |
|
|
import jakarta.annotation.PostConstruct; |
|
|
import jakarta.annotation.Resource; |
|
|
import jakarta.annotation.Resource; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Component |
|
|
@Component |
|
|
public class AppSettingsMgrService { |
|
|
public class AppSettingsMgrService { |
|
|
Logger logger = org.slf4j.LoggerFactory.getLogger(AppSettingsMgrService.class); |
|
|
Logger logger = org.slf4j.LoggerFactory.getLogger(AppSettingsMgrService.class); |
|
@ -32,7 +36,6 @@ public class AppSettingsMgrService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
|
// EXT FUNC |
|
|
// EXT FUNC |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
@ -152,4 +155,57 @@ public class AppSettingsMgrService { |
|
|
deviceSettingDao.update(setting); |
|
|
deviceSettingDao.update(setting); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set the system date and time. |
|
|
|
|
|
* |
|
|
|
|
|
* @param datetime date-time string in the format "yyyy-MM-dd HH:mm:ss" |
|
|
|
|
|
*/ |
|
|
|
|
|
public void setDateAndTime(String datetime) { |
|
|
|
|
|
String os = System.getProperty("os.name").toLowerCase(); |
|
|
|
|
|
if (os.contains("windows")) { |
|
|
|
|
|
log.info("Windows detected, skipping system time update. Received datetime: {}", datetime); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
ProcessBuilder pbNtp = new ProcessBuilder("timedatectl", "set-ntp", "false").redirectErrorStream(true); |
|
|
|
|
|
Process procNtp = pbNtp.start(); |
|
|
|
|
|
StringBuilder ntpOut = new StringBuilder(); |
|
|
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(procNtp.getInputStream()))) { |
|
|
|
|
|
String line; |
|
|
|
|
|
while ((line = reader.readLine()) != null) { |
|
|
|
|
|
ntpOut.append(line).append("\n"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
int ntpExit = procNtp.waitFor(); |
|
|
|
|
|
if (ntpExit != 0) { |
|
|
|
|
|
log.error("Failed to disable NTP (exit={}):\n{}", ntpExit, ntpOut.toString().trim()); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.info("Automatic time synchronization disabled"); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("Error disabling NTP before setting time", e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ProcessBuilder pbTime = new ProcessBuilder("timedatectl", "set-time", datetime).redirectErrorStream(true); |
|
|
|
|
|
try { |
|
|
|
|
|
Process procTime = pbTime.start(); |
|
|
|
|
|
StringBuilder timeOut = new StringBuilder(); |
|
|
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(procTime.getInputStream()))) { |
|
|
|
|
|
String line; |
|
|
|
|
|
while ((line = reader.readLine()) != null) { |
|
|
|
|
|
timeOut.append(line).append("\n"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
int timeExit = procTime.waitFor(); |
|
|
|
|
|
if (timeExit != 0) { |
|
|
|
|
|
log.error("Failed to update system time (exit={}):\n{}", timeExit, timeOut.toString().trim()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
log.info("System time successfully updated to {}", datetime); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("Error executing system time update command", e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |