]> git.basschouten.com Git - openhab-addons.git/blob
6be5801e8951f5d6e22005d208c67fa00406b1ba
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.freeboxos.internal.api.rest;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
17 import org.openhab.binding.freeboxos.internal.api.Response;
18
19 /**
20  * The {@link FtpManager} is the Java class used to handle api requests related to ftp
21  *
22  * https://dev.freebox.fr/sdk/os/system/#
23  *
24  * @author GaĆ«l L'hopital - Initial contribution
25  */
26 @NonNullByDefault
27 public class FtpManager extends ConfigurableRest<FtpManager.Config, FtpManager.ConfigResponse> {
28     private static final String PATH = "ftp";
29
30     protected static class ConfigResponse extends Response<Config> {
31     }
32
33     protected static record Config(boolean enabled, boolean allowAnonymous, boolean allowAnonymousWrite,
34             boolean allowRemoteAccess, boolean weakPassword, int portCtrl, int portData, String remoteDomain) {
35     }
36
37     public FtpManager(FreeboxOsSession session) throws FreeboxException {
38         super(session, LoginManager.Permission.NONE, ConfigResponse.class, session.getUriBuilder().path(PATH),
39                 CONFIG_PATH);
40     }
41
42     public boolean getStatus() throws FreeboxException {
43         return getConfig().enabled();
44     }
45
46     public boolean setStatus(boolean enabled) throws FreeboxException {
47         Config oldConfig = getConfig();
48         Config newConfig = new Config(enabled, oldConfig.allowAnonymous, oldConfig.allowAnonymousWrite,
49                 oldConfig.allowRemoteAccess, oldConfig.weakPassword, oldConfig.portCtrl, oldConfig.portData,
50                 oldConfig.remoteDomain);
51         return setConfig(newConfig).enabled();
52     }
53 }