parent
80a0e5c0db
commit
6781d98a6d
|
@ -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<ErrorCode, String> 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<ErrorCode, Long> 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<ErrorCode, Long> taskStatus(String taskId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ability device fireware.
|
||||
*
|
||||
* @return the ability device fireware
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, DeviceFirewareInfo> 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) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue