diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3f6a10d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,34 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+.DS_Store
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+/logs/
+/config/nacos
+!/config/nacos/config/fixed-127.0.0.1_8848-tsg_nacos
+!/config/nacos/config/fixed-127.0.0.1_8848-cn_nacos
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### Jrebel ###
+rebel*.xml
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..79c3c9b
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,39 @@
+
+stages:
+ - build
+ - clean
+ - deploy
+
+build:
+ stage: build
+ script:
+ - echo 'exec mvn clean package'
+ - echo 'tag:' $CI_COMMIT_TAG
+ - mvn clean package -Dmaven.test.skip=true
+ only:
+ - tags
+ tags:
+ - galaxy
+
+clean:
+ stage: clean
+ script:
+ - echo 'build job fail, exec mvn clean'
+ - echo 'tag:' $CI_COMMIT_TAG
+ - mvn clean
+ when: on_failure
+ only:
+ - tags
+ tags:
+ - galaxy
+deploy:
+ stage: deploy
+ script:
+ - echo 'exec mvn package & docker build'
+ - echo 'tag:' $CI_COMMIT_TAG
+ - mvn clean package -Dmaven.test.skip=true docker:build -DdockerImageTags=$CI_COMMIT_TAG
+ when: on_success
+ only:
+ - tags
+ tags:
+ - galaxy
\ No newline at end of file
diff --git a/README.md b/README.md
index 89430a1..e69de29 100644
--- a/README.md
+++ b/README.md
@@ -1,92 +0,0 @@
-# cn-object-scheduler
-
-
-
-## Getting started
-
-To make it easy for you to get started with GitLab, here's a list of recommended next steps.
-
-Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
-
-## Add your files
-
-- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
-- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
-
-```
-cd existing_repo
-git remote add origin https://git.mesalab.cn/wangwei/cn-object-scheduler.git
-git branch -M main
-git push -uf origin main
-```
-
-## Integrate with your tools
-
-- [ ] [Set up project integrations](https://git.mesalab.cn/wangwei/cn-object-scheduler/-/settings/integrations)
-
-## Collaborate with your team
-
-- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
-- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
-- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
-- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
-- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
-
-## Test and Deploy
-
-Use the built-in continuous integration in GitLab.
-
-- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
-- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
-- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
-- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
-- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
-
-***
-
-# Editing this README
-
-When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
-
-## Suggestions for a good README
-Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
-
-## Name
-Choose a self-explaining name for your project.
-
-## Description
-Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
-
-## Badges
-On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
-
-## Visuals
-Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
-
-## Installation
-Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
-
-## Usage
-Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
-
-## Support
-Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
-
-## Roadmap
-If you have ideas for releases in the future, it is a good idea to list them in the README.
-
-## Contributing
-State if you are open to contributions and what your requirements are for accepting them.
-
-For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
-
-You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
-
-## Authors and acknowledgment
-Show your appreciation to those who have contributed to the project.
-
-## License
-For open source projects, say how it is licensed.
-
-## Project status
-If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
diff --git a/config/application.yml b/config/application.yml
new file mode 100644
index 0000000..b0522da
--- /dev/null
+++ b/config/application.yml
@@ -0,0 +1,44 @@
+server:
+ port: 9999
+spring:
+ application:
+ name: cn-object-scheduler
+ datasource:
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ url: jdbc:mysql://192.168.44.53:3306/cn_api?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=UTC&failOverReadOnly=false&connectTimeout=10000&socketTimeout=30000
+ username: root
+ password: 111111
+tsg:
+ system:
+ url: http://192.168.44.3:80
+ username: wangwei
+ password: ImlUl8/Hdt0MaS1LEnyuCg==
+ token: aa2bdec5518ad131f71944b13ce5c298&1&
+ httpTimeout: 3600000
+ object:
+ ip:
+ #指定排除的IP. 1.如果没有可不写值,2.若有多个用英文逗号,分隔如: 127.0.0.1,127.0.0.2,3.可适用IP段匹配,如:127.*
+ excludeValue: 0.0.0.0,255.255.255.255,127.*,8.8.8.8,1.1.1.1
+ cyberghostvpn_serverip:
+ id: 1309738
+ name: cn_vpn_ip_learning
+ update:
+ cron: 0 0/1 * * * ?
+ enable: true
+ sql: SELECT addr_format AS addrFormat, ip1 AS ip1, ip2 AS ip2 FROM cn_vpn_learning_ip WHERE knowledge_id = 10
+ delete:
+ cron: 0 0/1 * * * ?
+ enable: true
+ offsetSecond: -600
+ fqdn:
+ cyberghostvpn_servername:
+ id: 1309740
+ name: cn_vpn_ip_learning
+ update:
+ cron: 35 0/1 * * * ?
+ enable: true
+ sql: SELECT domain AS domain FROM cn_vpn_learning_domain WHERE knowledge_id = 10
+ delete:
+ cron: 0 0/1 * * * ?
+ enable: true
+ offsetSecond: -600
\ No newline at end of file
diff --git a/config/logback-spring.xml b/config/logback-spring.xml
new file mode 100644
index 0000000..2de7f6d
--- /dev/null
+++ b/config/logback-spring.xml
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+ ${log.colorPattern}
+
+
+
+
+
+
+ ${log.path}/info/info.%d{yyyy-MM-dd}.log
+ ${log.maxHistory}
+
+
+ ${log.pattern}
+
+
+ INFO
+ ACCEPT
+ DENY
+
+
+
+
+ ${log.path}/warn/warn.%d{yyyy-MM-dd}.log
+
+
+ ${log.pattern}
+
+
+ WARN
+ ACCEPT
+ DENY
+
+
+
+
+ ${log.path}/error/error.%d{yyyy-MM-dd}.log
+
+
+ ${log.pattern}
+
+
+ ERROR
+ ACCEPT
+ DENY
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docker/Dockerfile b/docker/Dockerfile
new file mode 100644
index 0000000..e862842
--- /dev/null
+++ b/docker/Dockerfile
@@ -0,0 +1,12 @@
+ARG JDK_IMAGE
+FROM ${JDK_IMAGE}
+MAINTAINER Galaxy
+VOLUME /tmp
+WORKDIR /home/tsg/galaxy/cn-object-scheduler
+COPY config config
+ARG JAR_FILE
+COPY ${JAR_FILE} cn-object-scheduler.xjar
+#dockercompose set JAVA_OPTS
+ENV JAVA_OPTS=" -Xms1024m -Xmx2048m "
+ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8
+ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar cn-object-scheduler.jar" ]
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..06f23c8
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,180 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.3.12.RELEASE
+
+
+ com.geedge
+ cn-object-scheduler
+ 24.01
+ cn-object-scheduler
+ cn-object-scheduler
+
+
+ nexus
+ Team Nexus Repository
+ http://192.168.40.153:8099/content/groups/public
+
+
+
+
+ nexus
+ Team Nexus Repository
+ http://192.168.40.153:8099/content/groups/public
+
+
+
+ 11
+ 23.0
+ 5.7.7
+ 4.9.01
+ 8.0.18
+ 1.1.22
+ 192.168.40.153
+ 2375
+ 192.168.40.153
+ 9080
+ tsg/galaxy
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+
+ mysql
+ mysql-connector-java
+ ${mysql-connector-java.version}
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ ${starter.druid.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ cn.hutool
+ hutool-all
+ ${hutool.version}
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ com.jfinal
+ activerecord
+ ${active.record.version}
+
+
+ javax.activation
+ javax.activation-api
+ 1.2.0
+ compile
+
+
+
+
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ com.spotify
+ docker-maven-plugin
+ 1.0.0
+
+ 153-docker-repo
+ ${docker.registry}:${docker.registry.port}
+ true
+ true
+ ${docker.registry}:${docker.registry.port}/${docker.image.prefix}/${project.artifactId}
+
+ http://${docker.build}:${docker.build.port}
+ docker
+
+ ${docker.registry}:${docker.registry.port}/common/amazon-corretto:11.0.21.9.1
+
+ ${project.build.finalName}.jar
+
+
+ v24.01
+
+
+
+ /
+ ${project.build.directory}
+ ${project.build.finalName}.jar
+
+
+ /config
+ config
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-toolchains-plugin
+ 1.1
+
+
+
+ toolchain
+
+
+
+
+
+
+ 11
+ amazon
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 3.2.0
+
+ utf-8
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.19.1
+
+ true
+
+
+
+
+
+
diff --git a/src/main/java/com/geedge/CnPolicySchedulerApplication.java b/src/main/java/com/geedge/CnPolicySchedulerApplication.java
new file mode 100644
index 0000000..42bbcc0
--- /dev/null
+++ b/src/main/java/com/geedge/CnPolicySchedulerApplication.java
@@ -0,0 +1,18 @@
+package com.geedge;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+/**
+ * @author wangwei
+ */
+@SpringBootApplication
+@EnableScheduling
+public class CnPolicySchedulerApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(CnPolicySchedulerApplication.class, args);
+ }
+
+}
diff --git a/src/main/java/com/geedge/common/config/ScheduledPoolConfig.java b/src/main/java/com/geedge/common/config/ScheduledPoolConfig.java
new file mode 100644
index 0000000..d538ca7
--- /dev/null
+++ b/src/main/java/com/geedge/common/config/ScheduledPoolConfig.java
@@ -0,0 +1,26 @@
+package com.geedge.common.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+
+
+/**
+ * TODO
+ *
+ * @Classname ScheduledPoolConfig
+ * @Date 2024/1/3 14:00
+ * @Author wWei
+ */
+@Configuration
+public class ScheduledPoolConfig implements SchedulingConfigurer {
+
+ @Override
+ public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
+ ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
+ scheduler.setPoolSize(16);
+ scheduler.initialize();
+ taskRegistrar.setScheduler(scheduler);
+ }
+}
diff --git a/src/main/java/com/geedge/common/constant/TsgObject.java b/src/main/java/com/geedge/common/constant/TsgObject.java
new file mode 100644
index 0000000..b587da8
--- /dev/null
+++ b/src/main/java/com/geedge/common/constant/TsgObject.java
@@ -0,0 +1,42 @@
+package com.geedge.common.constant;
+
+/**
+ * TODO
+ *
+ * @Classname TSG
+ * @Date 2024/1/4 16:11
+ * @Author wWei
+ */
+public class TsgObject {
+ public static final String KEY_VSYS_ID = "vsys_id";
+ public static final String KEY_OBJECT = "object";
+ public static final String KEY_CREATED_BEFORE = "created_before";
+ public static final String KEY_OBJECT_NAME = "name";
+ public static final String KEY_OBJECT_TYPE = "type";
+ public static final String KEY_OBJECT_MEMBER = "member";
+ public static final String KEY_OBJECT_MEMBER_TYPE = "type";
+ public static final String KEY_OBJECT_MEMBER_ITEMS = "items";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_OP = "op";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_IP = "ip";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_STRING = "string";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_STRING_PATTERNS = "patterns";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_IP_IP_ADDRESS = "ip_address";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_IP_PORT_RANGE = "port_range";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_STRING_PATTERNS_KEYWORDS = "keywords";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_IP_ADDR_TYPE = "addr_type";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_IP_IP_RANGE = "ip_range";
+ public static final String KEY_OBJECT_MEMBER_ITEMS_IP_IP_CIDR = "ip_cidr";
+
+ public static final String VALUE_OBJECT_TYPE_IP = "ip";
+ public static final String VALUE_OBJECT_TYPE_FQDN = "fqdn";
+ public static final String VALUE_OBJECT_MEMBER_ITEMS_IP_PORT_RANGE = "0-65535";
+ public static final String VALUE_OBJECT_MEMBER_ITEMS_OP_ADD = "add";
+ public static final Integer VALUE_OBJECT_MEMBER_TYPE_1 = 1;
+
+ public static final Integer VALUE_VSYS_ID_1 = 1;
+
+
+
+
+}
+
diff --git a/src/main/java/com/geedge/common/enums/AddressFormat.java b/src/main/java/com/geedge/common/enums/AddressFormat.java
new file mode 100644
index 0000000..bdce811
--- /dev/null
+++ b/src/main/java/com/geedge/common/enums/AddressFormat.java
@@ -0,0 +1,24 @@
+package com.geedge.common.enums;
+
+/**
+ * TODO
+ *
+ * @Classname addrFormat
+ * @Date 2024/1/3 16:26
+ * @Author wWei
+ */
+
+import lombok.Getter;
+
+@Getter
+public enum AddressFormat {
+ SINGLE("Single"),
+ RANGE("Range"),
+ CIDR("CIDR"),
+ ;
+ private final String value;
+
+ AddressFormat(String value) {
+ this.value = value;
+ }
+}
diff --git a/src/main/java/com/geedge/common/plugin/ActiveRecordInit.java b/src/main/java/com/geedge/common/plugin/ActiveRecordInit.java
new file mode 100644
index 0000000..320cf0c
--- /dev/null
+++ b/src/main/java/com/geedge/common/plugin/ActiveRecordInit.java
@@ -0,0 +1,40 @@
+package com.geedge.common.plugin;
+
+import com.jfinal.plugin.druid.DruidPlugin;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * Desc: TODO
+ *
+ * @return {@link null}
+ * @created by wWei
+ * @date 2024/1/3 18:44
+ */
+@Slf4j
+@Component
+public class ActiveRecordInit {
+
+ @Value("${spring.datasource.url}")
+ private String url;
+
+ @Value("${spring.datasource.username}")
+ private String userName;
+
+ @Value("${spring.datasource.password}")
+ private String password;
+
+ @PostConstruct
+ public void initDialect() {
+ DruidPlugin dp = new DruidPlugin(url, userName, password);
+ dp.setTestWhileIdle(true);
+ dp.setValidationQuery("SELECT 1");
+ ArpStartPlugin arp = new ArpStartPlugin(dp);
+ dp.start();
+ arp.start();
+ log.info("Initializing ActiveRecordPlugin Complete");
+ }
+}
diff --git a/src/main/java/com/geedge/common/plugin/ArpStartPlugin.java b/src/main/java/com/geedge/common/plugin/ArpStartPlugin.java
new file mode 100644
index 0000000..35adc18
--- /dev/null
+++ b/src/main/java/com/geedge/common/plugin/ArpStartPlugin.java
@@ -0,0 +1,32 @@
+package com.geedge.common.plugin;
+
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
+import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
+import com.jfinal.plugin.activerecord.IDataSourceProvider;
+
+/**
+ * Desc: TODO
+ *
+ * @return {@link null}
+ * @created by wWei
+ * @date 2024/1/3 18:44
+ */
+public class ArpStartPlugin extends ActiveRecordPlugin {
+
+ private static final Log log = LogFactory.get();
+
+ public ArpStartPlugin(IDataSourceProvider dataSourceProvider) {
+ super(dataSourceProvider);
+ }
+
+ @Override
+ public boolean start() {
+ try {
+ super.start();
+ } catch (RuntimeException e) {
+ log.error("ArpStartPlugin init error:{}", e.getMessage());
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/com/geedge/common/util/TsgUtil.java b/src/main/java/com/geedge/common/util/TsgUtil.java
new file mode 100644
index 0000000..35663d6
--- /dev/null
+++ b/src/main/java/com/geedge/common/util/TsgUtil.java
@@ -0,0 +1,128 @@
+package com.geedge.common.util;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.Header;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.google.common.base.Stopwatch;
+import com.google.common.collect.Maps;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * TODO
+ *
+ * @Classname LoginTsgUtil
+ * @Date 2024/1/3 09:34
+ * @Author wWei
+ */
+@Slf4j
+@Component
+public class TsgUtil {
+
+ public static String TSG_URL;
+ private static String TSG_USERNAME;
+ private static String TSG_PASSWORD;
+ private static Integer httpTimeOut;
+ private static String TSG_TOKEN;
+
+ @Value("${tsg.system.httpTimeout}")
+ public void setTsgUrl(Integer timeOut) {
+ httpTimeOut = timeOut;
+ }
+
+ @Value("${tsg.system.url}")
+ public void setTsgUrl(String url) {
+ TSG_URL = url;
+ }
+
+ @Value("${tsg.system.username}")
+ private void setTsgUsername(String username) {
+ TSG_USERNAME = username;
+ }
+
+ @Value("${tsg.system.password}")
+ private void setTsgPassword(String password) {
+ TSG_PASSWORD = password;
+ }
+
+ @Value("${tsg.system.token}")
+ private void setTsgToken(String token) {
+ TSG_TOKEN = token;
+ }
+
+ public static String getToken() {
+ if (StrUtil.isNotEmpty(TSG_TOKEN)) {
+ return TSG_TOKEN;
+ }
+ String token = "";
+ Map map = Maps.newHashMap();
+ map.put("username", TSG_USERNAME);
+ map.put("password", TSG_PASSWORD);
+ try {
+ Stopwatch watch = Stopwatch.createStarted();
+ String response = HttpRequest.post(TSG_URL + "/v1/user/login")
+ .body(JSONUtil.toJsonStr(map))
+ .timeout(httpTimeOut)
+ .execute().body();
+ log.info("get tsg-api token, cost {} seconds", watch.elapsed(TimeUnit.SECONDS));
+ if (StrUtil.isBlank(response)) {
+ log.error("failed to get TSG system token. response: {}", response);
+ throw new RuntimeException("ailed to get TSG system token. response: " + response);
+ }
+ JSONObject jsonObject = JSONUtil.parseObj(response);
+ if (!"200".equals(jsonObject.get("code").toString())) {
+ log.error("failed to get TSG system token. response: {}", response);
+ throw new RuntimeException("ailed to get TSG system token. response: " + response);
+ }
+ token = JSONUtil.parseObj(jsonObject.get("data")).get("token").toString();
+ } catch (Exception e) {
+ log.error("failed to get TSG system token. message: {}", e.getMessage());
+ throw e;
+ }
+ return token;
+ }
+
+ public static void updateObjectById(Integer id, Map body) {
+ Stopwatch watch = Stopwatch.createStarted();
+ String response = HttpRequest.put(TSG_URL + "/v1/policy/object/" + id)
+ .header(Header.AUTHORIZATION, getToken())
+ .body(JSONUtil.toJsonStr(body))
+ .timeout(httpTimeOut)
+ .execute().body();
+ log.info("update tsg-api, cost {} seconds", watch.elapsed(TimeUnit.SECONDS));
+ if (StrUtil.isBlank(response)) {
+ log.error("update {} Object error, response: {}", id, response);
+ throw new RuntimeException("update " + id + " Object error, response: " + response);
+ }
+ JSONObject jsonObject = JSONUtil.parseObj(response);
+ if (!"200".equals(jsonObject.get("code").toString())) {
+ log.error("update {} Object error, response: {}", id, response);
+ throw new RuntimeException("update " + id + " Object error, response: " + response);
+ }
+ }
+
+ public static void deleteItemOfObjectById(Integer id, Map form) {
+ Stopwatch watch = Stopwatch.createStarted();
+ String response = HttpRequest.delete(TSG_URL + "/v1/policy/object/" + id + "/item")
+ .header(Header.AUTHORIZATION, getToken())
+ .form(form)
+ .timeout(httpTimeOut)
+ .execute().body();
+ log.info("delete tsg-api, cost {} seconds", watch.elapsed(TimeUnit.SECONDS));
+ if (StrUtil.isBlank(response)) {
+ log.error("update {} Object error, response: {}", id, response);
+ throw new RuntimeException("update " + id + " Object error, response: " + response);
+ }
+ JSONObject jsonObject = JSONUtil.parseObj(response);
+ if (!"200".equals(jsonObject.get("code").toString())) {
+ log.error("update {} Object error, response: {}", id, response);
+ throw new RuntimeException("update " + id + " Object error, response: " + response);
+ }
+ }
+}
diff --git a/src/main/java/com/geedge/scheduler/FqdnScheduler.java b/src/main/java/com/geedge/scheduler/FqdnScheduler.java
new file mode 100644
index 0000000..a492162
--- /dev/null
+++ b/src/main/java/com/geedge/scheduler/FqdnScheduler.java
@@ -0,0 +1,128 @@
+package com.geedge.scheduler;
+
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.net.Ipv4Util;
+import cn.hutool.core.net.MaskBit;
+import cn.hutool.core.util.BooleanUtil;
+import com.geedge.common.constant.TsgObject;
+import com.geedge.common.enums.AddressFormat;
+import com.geedge.common.util.TsgUtil;
+import com.google.common.base.Stopwatch;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * TODO
+ *
+ * @Classname Scheduler
+ * @Date 2024/1/2 11:31
+ * @Author wWei
+ */
+@Slf4j
+@Component
+public class FqdnScheduler {
+
+ @Value("${tsg.object.fqdn.cyberghostvpn_servername.id}")
+ private Integer cyberghostvpnServernameId;
+ @Value("${tsg.object.fqdn.cyberghostvpn_servername.name}")
+ private String cyberghostvpnServernameName;
+ @Value("${tsg.object.fqdn.cyberghostvpn_servername.update.enable}")
+ private Boolean cyberghostvpnServernameUpdateEnable;
+ @Value("${tsg.object.fqdn.cyberghostvpn_servername.update.sql}")
+ private String cyberghostvpnServernameSql;
+ @Value("${tsg.object.fqdn.cyberghostvpn_servername.delete.enable}")
+ private Boolean cyberghostvpnServernameDeleteEnable;
+ @Value("${tsg.object.fqdn.cyberghostvpn_servername.delete.offsetSecond}")
+ private Integer cyberghostvpnServernameOffsetSecond;
+
+
+ @Scheduled(cron = "${tsg.object.fqdn.cyberghostvpn_servername.update.cron}")
+ public void scheduledExecutorUpdate() {
+ executeUpdate(cyberghostvpnServernameId, cyberghostvpnServernameName, cyberghostvpnServernameUpdateEnable, cyberghostvpnServernameSql);
+ }
+
+ @Scheduled(cron = "${tsg.object.fqdn.cyberghostvpn_servername.delete.cron}")
+ public void scheduledExecutorDelete() {
+ executeDelete(cyberghostvpnServernameId, cyberghostvpnServernameDeleteEnable, cyberghostvpnServernameOffsetSecond);
+ }
+
+ private static void executeUpdate(Integer id, String name, Boolean enable, String sql) {
+ log.info("{}: started update task.", id);
+ if (BooleanUtil.isFalse(enable)) {
+ log.warn("{}: interrupted update task. enable: {}", id, enable);
+ return;
+ }
+ try {
+ Stopwatch watch = Stopwatch.createStarted();
+ List data = Db.find(sql);
+ log.info("{}: query knowledge base content, cost {} seconds", id, watch.elapsed(TimeUnit.SECONDS));
+ watch.reset().start();
+ List