Skip to content

Commit

Permalink
Merge pull request #11 from Yohann0617/dev
Browse files Browse the repository at this point in the history
update web and bug fix
  • Loading branch information
Yohann0617 authored Apr 1, 2024
2 parents 2b732cf + d19eedd commit 7d702b3
Show file tree
Hide file tree
Showing 19 changed files with 448 additions and 213 deletions.
8 changes: 8 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
60 changes: 8 additions & 52 deletions common/src/main/java/com/proxyip/select/common/bean/ProxyIp.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.proxyip.select.common.bean;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
* 代理ip表
*
* @author Yohann
*/
@Data
public class ProxyIp implements Serializable {
private String id;

Expand All @@ -16,57 +21,8 @@ public class ProxyIp implements Serializable {

private Integer pingValue;

private static final long serialVersionUID = 1L;

@Override
public String toString() {
return "ProxyIp{" +
"id='" + id + '\'' +
", country='" + country + '\'' +
", ip='" + ip + '\'' +
", pingValue=" + pingValue +
'}';
}

public ProxyIp() {
}

public ProxyIp(String id, String country, String ip, Integer pingValue) {
this.id = id;
this.country = country;
this.ip = ip;
this.pingValue = pingValue;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private LocalDateTime createTime;

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public Integer getPingValue() {
return pingValue;
}

public void setPingValue(Integer pingValue) {
this.pingValue = pingValue;
}
private static final long serialVersionUID = 1L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public interface IApiService {
* @param apiToken apiToken
*/
void removeCfDnsRecords(List<String> proxyDomainList, String zoneId, String apiToken);

/**
* 清除cf指定代理域名的某个ip地址的dns记录
*
* @param proxyDomain 代理域名
* @param ip ip地址
* @param zoneId zoneId
* @param apiToken apiToken
*/
void removeCfSingleDnsRecords(String proxyDomain, String ip, String zoneId, String apiToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.proxyip.select.common.exception.BusinessException;
import com.proxyip.select.common.service.IApiService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

Expand All @@ -23,6 +24,7 @@
* @since 2024/3/29 13:57
*/
@Service
@Slf4j
public class ApiServiceImpl implements IApiService {

/**
Expand All @@ -44,6 +46,15 @@ public class ApiServiceImpl implements IApiService {
" -H \"Authorization: Bearer %s\" " +
" -H \"Content-Type: application/json\"";

/**
* cf删除指定代理域名的某个ip地址的dns记录api
*/
private static String CF_REMOVE_SINGLE_DNS_RECORDS_API = "curl -X GET \"https://api.cloudflare.com/client/v4/zones/%s/dns_records?type=A&name=%s\" " +
"-H \"Authorization: Bearer %s\" " +
"-H \"Content-Type: application/json\" | jq -c '.result[] | select(.content == \"%s\") | .id' | xargs -n 1 -I {} curl -X DELETE \"https://api.cloudflare.com/client/v4/zones/%s/dns_records/{}\" " +
"-H \"Authorization: Bearer %s\" " +
"-H \"Content-Type: application/json\"";

/**
* 获取ip归属国家api
*/
Expand All @@ -67,7 +78,7 @@ public void uploadFileToNetDisc(String filePath, String apiAddress) {
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("\"code\":1")) {
System.out.println("√√√ 文件:" + filePath + " 已发送至个人网盘 √√√");
log.info("√√√ 文件:{} 已发送至个人网盘 √√√", filePath);
break;
}
}
Expand Down Expand Up @@ -99,7 +110,7 @@ public List<String> resolveDomain(List<String> domainList, String dnsServer) {
// Wait for the process to finish
int exitCode = process.waitFor();
if (exitCode != 0) {
System.out.println("Error executing nslookup command");
log.error("Error executing nslookup command");
// System.exit(1);
}
} catch (Exception e) {
Expand Down Expand Up @@ -175,19 +186,19 @@ public void addCfDnsRecords(String domainPrefix, String ipAddress, String zoneId

// try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
// String line;
// System.out.println("add ------------------" + domainPrefix + "-------------------");
// log.info("add ------------------" + domainPrefix + "-------------------");
// while ((line = reader.readLine()) != null) {
// System.out.println(line);
// log.info(line);
// }
// System.out.println("add ------------------" + domainPrefix + "-------------------");
// log.info("add ------------------" + domainPrefix + "-------------------");
// }

// Wait for the process to finish
int exitCode = process.waitFor();
if (exitCode != 0) {
System.out.println("Error executing addCfDnsRecords task");
log.error("Error executing addCfDnsRecords task");
}
// System.out.println("域名:" + domainPrefix + "." + dnsCfg.getRootDomain() + " 的dns记录添加成功!ip地址:" + ipAddress);
// log.info("域名:" + domainPrefix + "." + dnsCfg.getRootDomain() + " 的dns记录添加成功!ip地址:" + ipAddress);
} catch (Exception e) {
e.printStackTrace();
throw new BusinessException(-1, "添加cf记录失败:" + e.getLocalizedMessage());
Expand All @@ -204,23 +215,41 @@ public void removeCfDnsRecords(List<String> proxyDomainList, String zoneId, Stri
// Wait for the process to finish
int exitCode = process.waitFor();
if (exitCode != 0) {
System.out.println("Error executing addCfDnsRecords task");
log.error("Error executing removeCfDnsRecords task");
}
// try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
// String line;
// System.out.println("rm ------------------" + proxyDomain + "-------------------");
// log.info("rm ------------------" + proxyDomain + "-------------------");
// while ((line = reader.readLine()) != null) {
// System.out.println(line);
// log.info(line);
// }
// System.out.println("rm ------------------" + proxyDomain + "-------------------");
// log.info("rm ------------------" + proxyDomain + "-------------------");
// } catch (Exception e) {
// e.printStackTrace();
// }
} catch (IOException | InterruptedException e) {
e.printStackTrace();
throw new BusinessException(-1, "清除DNS记录失败:" + e.getLocalizedMessage());
}
System.out.println("√√√ 域名:" + proxyDomain + "的dns记录已清除! √√√");
log.info("√√√ 域名:{} 的dns记录已清除! √√√", proxyDomain);
});
}

@Override
public void removeCfSingleDnsRecords(String proxyDomain, String ip, String zoneId, String apiToken) {
String curlCommand = String.format(CF_REMOVE_SINGLE_DNS_RECORDS_API, zoneId, proxyDomain, apiToken, ip, zoneId, apiToken);
ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", curlCommand);
try {
Process process = processBuilder.start();
// Wait for the process to finish
int exitCode = process.waitFor();
if (exitCode != 0) {
log.error("Error executing removeCfSingleDnsRecords task");
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
throw new BusinessException(-1, "清除DNS记录失败:" + e.getLocalizedMessage());
}
log.info("√√√ 域名:{} 的A记录ip:{} 的dns记录已清除! √√√", proxyDomain, ip);
}
}
12 changes: 7 additions & 5 deletions foreign-server/resources/table.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
create table if not exists `proxy_ip`
(
id varchar(256) not null, --'id'
country varchar(64) null, --'国家代码'
ip varchar(64) not null, --'ip地址'
ping_value INT null, --'ping值'
id varchar(256) not null, --'id'
country varchar(64) null, --'国家代码'
ip varchar(64) not null, --'ip地址'
ping_value INT null, --'ping值'
create_time datetime default (datetime('now', 'localtime')) not null,-- '记录创建时间'
primary key ("id")
);--代理ip表

CREATE INDEX idx_country ON proxy_ip (country);
CREATE INDEX idx_ip ON proxy_ip (ip);
CREATE INDEX idx_ping_value ON proxy_ip (ping_value);
CREATE INDEX idx_ping_value ON proxy_ip (ping_value);
CREATE INDEX idx_create_time ON proxy_ip (create_time DESC);
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.proxyip.select.bean.params;

import lombok.Data;

import java.util.List;

/**
Expand All @@ -9,15 +11,8 @@
* @author: Yohann
* @date: 2024/3/30 20:47
*/
@Data
public class AddDnsRecordsBatchParams {

List<String> ids;

public List<String> getIds() {
return ids;
}

public void setIds(List<String> ids) {
this.ids = ids;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.proxyip.select.bean.params;

import lombok.Data;

import java.util.List;

/**
* <p>
* AddProxyIpToDbParams
* </p >
*
* @author yuhui.fan
* @since 2024/4/1 16:51
*/
@Data
public class AddProxyIpToDbParams {

List<String> ipList;
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package com.proxyip.select.bean.params;

import lombok.Data;

/**
* @projectName: scan-proxyip
* @package: com.proxyip.select.bean.params
* @className: AddSingleDnsRecordParams
* @author: Yohann
* @date: 2024/3/30 17:54
*/
@Data
public class AddSingleDnsRecordParams {

private String id;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,18 @@
package com.proxyip.select.bean.params;

import lombok.Data;

/**
* @projectName: scan-proxyip
* @package: com.proxyip.select.bean.params
* @className: ProxyIpPageParams
* @author: Yohann
* @date: 2024/3/30 14:37
*/
@Data
public class ProxyIpPageParams {

private String keyword;
private long currentPage;
private long pageSize;

public ProxyIpPageParams() {
}

public ProxyIpPageParams(String keyword, long currentPage, long pageSize) {
this.keyword = keyword;
this.currentPage = currentPage;
this.pageSize = pageSize;
}

public String getKeyword() {
return keyword;
}

public void setKeyword(String keyword) {
this.keyword = keyword;
}

public long getCurrentPage() {
return currentPage;
}

public void setCurrentPage(long currentPage) {
this.currentPage = currentPage;
}

public long getPageSize() {
return pageSize;
}

public void setPageSize(long pageSize) {
this.pageSize = pageSize;
}

@Override
public String toString() {
return "ProxyIpPageParams{" +
"keyword='" + keyword + '\'' +
", currentPage=" + currentPage +
", pageSize=" + pageSize +
'}';
}
}
Loading

0 comments on commit 7d702b3

Please sign in to comment.