From 6781d98a6da8b7f0560c3cf2d2449f8e0f9c852f Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Mon, 16 Nov 2020 17:35:17 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=E5=A2=9E=E5=8A=A0=E5=8D=8E?= =?UTF-8?q?=E4=B8=BA=E8=AE=BE=E5=A4=87=E8=83=BD=E5=8A=9B=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=202.=E5=A2=9E=E5=8A=A0=E5=8D=8E=E4=B8=BA=E5=A4=84=E7=BD=AE?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/HuaWeiAbilityImpl.java | 214 ++++++++++++++++++ .../com/dispose/common/DisposeDeviceType.java | 6 +- 2 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java diff --git a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java new file mode 100644 index 00000000..99b203c9 --- /dev/null +++ b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java @@ -0,0 +1,214 @@ +package com.dispose.ability.impl; + +import com.dispose.ability.DisposeAbility; + +import cn.hutool.http.HttpResponse; +import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeObjectType; +import com.dispose.common.ErrorCode; +import com.dispose.common.NetflowDirection; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.pojo.vo.DeviceFirewareInfo; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.huawei.dispose.common.HuaWeiLoginResp; +import com.huawei.dispose.protocol.HuaWeiInterface; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Nullable; +import javax.servlet.http.HttpServletResponse; + +@Component +@Slf4j +public class HuaWeiAbilityImpl implements DisposeAbility { + /** + * The Restful interface. + */ + private final HuaWeiInterface restfulInterface = new HuaWeiInterface(); + + /** + * The constant OBJECT_MAPPER. + */ + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + /** + * The Url root path. + */ + @Getter + @Setter + private String urlRootPath; + + /** + * The Username. + */ + @Getter + @Setter + private String username; + + /** + * The Password. + */ + @Getter + @Setter + private String password; + + /** + * The Token. + */ + private String token; + + /** + * Init device env. + * + * @param urlPath the url path + * @param username the username + * @param password the password + */ + @Override + public void initDeviceEnv(String urlPath, String username, String password) { + this.urlRootPath = urlPath; + this.username = username; + this.password = password; + + upgradeToken(); + } + + /** + * Run dispose mul return type. + * + * @param disposeObject the dispose object + * @param objectType the object type + * @param capType the cap type + * @param nfDirection the nf direction + * @param attackType the attack type + * @param duration the duration + * @return the mul return type + */ + @Override + public MulReturnType runDispose(String disposeObject, DisposeObjectType objectType, + DisposeCapacityType capType, + @Nullable NetflowDirection nfDirection, + @Nullable Integer attackType, + @Nullable Long duration) { + return null; + } + + + /** + * Stop dispose mul return type. + * + * @param disposeObject the dispose object + * @param capType the cap type + * @param nfDirection the nf direction + * @param attackType the attack type + * @param taskId the task id + * @return the mul return type + */ + @Override + public MulReturnType stopDispose(String disposeObject, DisposeCapacityType capType, + @Nullable NetflowDirection nfDirection, + @Nullable Integer attackType, + @Nullable String taskId) { + return null; + } + + /** + * Task status mul return type. + * + * @param taskId the task id + * @return the mul return type + */ + @Override + public MulReturnType taskStatus(String taskId) { + return null; + } + + /** + * Gets ability device fireware. + * + * @return the ability device fireware + */ + @Override + public MulReturnType getAbilityDeviceFireware() { + return new MulReturnType<>(ErrorCode.ERR_OK, + DeviceFirewareInfo.builder() + .vendor("HuaWei") + .model("Unknown") + .firmware("Unknown") + .os("Linux Server") + .kernel("Linux") + .arch("x86_64") + .version("Unknown") + .memory(-1) + .freeMemory(-1) + .cpuUsed(-1) + .build()); + } + + /** + * To device attack type long. + * + * @param ddosAttackTypeMask the ddos attack type mask + * @return the long + */ + @Override + public Long toDeviceAttackType(Long ddosAttackTypeMask) { + return ddosAttackTypeMask; + } + + /** + * Gets device link status. + * + * @return the device link status + */ + @Override + public boolean getDeviceLinkStatus() { + try { + //查询所有的zone接口调用成功认为设备心跳正常 + //return (restfulInterface.queryAllZones(this.urlRootPath, token) != null); + return true; + } catch (Exception ex) { + log.error(ex.getMessage()); + } + + return false; + } + + + /** + * Gets dispose device protect object. + */ + @Override + public void getDisposeDeviceProtectObject() { + } + + /** + * Is carry protect ip boolean. + * + * @param ipAddr the ip addr + * @return the boolean + */ + @Override + public boolean isCarryProtectIp(String ipAddr) { + return true; + } + + /** + * Upgrade token. + */ + private void upgradeToken() { + try { + HttpResponse resp = restfulInterface.auth(this.urlRootPath, username, password); + + if (resp != null) { + if (resp.getStatus() == HttpServletResponse.SC_OK && resp.body() != null) { + HuaWeiLoginResp logInfo = OBJECT_MAPPER.readValue(resp.body(), HuaWeiLoginResp.class); + this.token = logInfo.getToken(); + } + } + } catch (Exception ignored) { + } + } +} diff --git a/src/main/java/com/dispose/common/DisposeDeviceType.java b/src/main/java/com/dispose/common/DisposeDeviceType.java index 9ed73c5f..afa2fbfb 100644 --- a/src/main/java/com/dispose/common/DisposeDeviceType.java +++ b/src/main/java/com/dispose/common/DisposeDeviceType.java @@ -14,12 +14,14 @@ public enum DisposeDeviceType implements BaseEnum { * The Haohan platform. */ HAOHAN_PLATFORM(1, "浩瀚处置设备"), - /** * The Pengxin platform. */ PENGXIN_PLATFORM(2, "鹏信处置设备"), - + /** + * The HuaWei platform. + */ + HUAWEI_PLATFORM(3, "华为处置设备"), /** * The Virtual dispose. */