Search in sources :

Example 1 with NetworkInterfaceModel

use of com.infiniteautomation.mango.rest.latest.model.server.NetworkInterfaceModel in project ma-modules-public by infiniteautomation.

the class ServerRestController method getNetworkInterfaces.

@ApiOperation(value = "List network interfaces", notes = "Requires global data source permission")
@RequestMapping(method = { RequestMethod.GET }, value = "/network-interfaces")
@PreAuthorize("isGrantedPermission('permissionDatasource')")
public List<NetworkInterfaceModel> getNetworkInterfaces(@RequestParam(value = "includeLoopback", required = false, defaultValue = "false") boolean includeLoopback, @RequestParam(value = "includeDefault", required = false, defaultValue = "false") boolean includeDefault, @AuthenticationPrincipal PermissionHolder user) {
    List<NetworkInterfaceModel> models = new ArrayList<>();
    if (includeDefault) {
        NetworkInterfaceModel model = new NetworkInterfaceModel();
        model.setHostAddress("0.0.0.0");
        model.setInterfaceName("");
        models.add(model);
    }
    try {
        for (NICInfo ni : HostUtils.getLocalInet4Addresses(includeLoopback)) {
            NetworkInterfaceModel model = new NetworkInterfaceModel();
            model.setHostAddress(ni.getInetAddress().getHostAddress());
            model.setInterfaceName(ni.getInterfaceName());
            models.add(model);
        }
    } catch (SocketException e) {
        throw new ServerErrorException(new TranslatableMessage("common.default", e.getMessage()), e);
    }
    return models;
}
Also used : SocketException(java.net.SocketException) NetworkInterfaceModel(com.infiniteautomation.mango.rest.latest.model.server.NetworkInterfaceModel) ArrayList(java.util.ArrayList) ServerErrorException(com.infiniteautomation.mango.rest.latest.exception.ServerErrorException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) NICInfo(com.serotonin.m2m2.util.HostUtils.NICInfo) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ServerErrorException (com.infiniteautomation.mango.rest.latest.exception.ServerErrorException)1 NetworkInterfaceModel (com.infiniteautomation.mango.rest.latest.model.server.NetworkInterfaceModel)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 NICInfo (com.serotonin.m2m2.util.HostUtils.NICInfo)1 ApiOperation (io.swagger.annotations.ApiOperation)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1