Search in sources :

Example 1 with NtpClient

use of lucee.runtime.net.ntp.NtpClient in project Lucee by lucee.

the class XMLConfigAdmin method updateTimeServer.

/**
 * update the timeServer
 * @param timeServer
 * @param useTimeServer
 * @throws PageException
 */
public void updateTimeServer(String timeServer, Boolean useTimeServer) throws PageException {
    checkWriteAccess();
    if (useTimeServer != null && useTimeServer.booleanValue() && !StringUtil.isEmpty(timeServer, true)) {
        try {
            new NtpClient(timeServer).getOffset();
        } catch (IOException e) {
            try {
                new NtpClient(timeServer).getOffset();
            } catch (IOException ee) {
                throw Caster.toPageException(ee);
            }
        }
    }
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING);
    if (!hasAccess)
        throw new SecurityException("no access to update regional setting");
    Element scope = _getRootElement("regional");
    scope.setAttribute("timeserver", timeServer.trim());
    if (useTimeServer != null)
        scope.setAttribute("use-timeserver", Caster.toString(useTimeServer));
    else
        scope.removeAttribute("use-timeserver");
}
Also used : NtpClient(lucee.runtime.net.ntp.NtpClient) Element(org.w3c.dom.Element) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException)

Example 2 with NtpClient

use of lucee.runtime.net.ntp.NtpClient in project Lucee by lucee.

the class ConfigImpl method reloadTimeServerOffset.

@Override
public void reloadTimeServerOffset() {
    timeOffset = 0;
    if (useTimeServer && !StringUtil.isEmpty(timeServer, true)) {
        NtpClient ntp = new NtpClient(timeServer);
        timeOffset = ntp.getOffset(0);
    }
}
Also used : NtpClient(lucee.runtime.net.ntp.NtpClient)

Aggregations

NtpClient (lucee.runtime.net.ntp.NtpClient)2 IOException (java.io.IOException)1 SecurityException (lucee.runtime.exp.SecurityException)1 Element (org.w3c.dom.Element)1