Skip to content

Commit 640cf63

Browse files
committed
update
1 parent 5b3e5d3 commit 640cf63

File tree

2 files changed

+81
-19
lines changed

2 files changed

+81
-19
lines changed

src/title/LineEntryMenu.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,27 @@ protected Map doInBackground() throws Exception {
862862
removeItem.setToolTipText("Just Delete Entry In Title Panel");
863863

864864

865+
/**
866+
* 删除明显无效的记录,以便再次请求,可能发现新的有效资产
867+
*/
868+
JMenuItem removeInvalidItems = new JMenuItem(new AbstractAction("Delete Invalid Entries") {//need to show dialog to confirm
869+
@Override
870+
public void actionPerformed(ActionEvent actionEvent) {
871+
new SwingWorker<Map,Map>(){
872+
873+
@Override
874+
protected Map doInBackground() throws Exception {
875+
int result = JOptionPane.showConfirmDialog(null,"Are you sure to DELETE invalid items(eg. stauts=-1,status=503) ?");
876+
if (result == JOptionPane.YES_OPTION) {
877+
lineTable.getLineTableModel().removeInvalidRows();
878+
titlepanel.digStatus();
879+
}
880+
return null;
881+
}
882+
}.execute();
883+
}
884+
});
885+
865886
/**
866887
* 删除明显非目标的记录
867888
*/
@@ -1096,6 +1117,7 @@ public void actionPerformed(ActionEvent actionEvent) {
10961117
this.add(addToblackListAndDeleteItem);//加入黑名单并删除
10971118
this.add(removeItem);//单纯删除记录
10981119
this.add(removeItemsNotInTargets);
1120+
this.add(removeInvalidItems);
10991121
//this.add(removeSubDomainItem);
11001122
//this.add(removeCustomAssetItem);
11011123
this.add(DeleteHostFromTargetItem);

src/title/LineTableModel.java

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,45 @@ public void removeRowsNotInTargets() {
836836
});
837837

838838
}
839+
840+
public void removeInvalidRows() {
841+
842+
SwingUtilities.invokeLater(() -> {
843+
for (int i = lineEntries.size() - 1; i >= 0; i--) {// 降序删除才能正确删除每个元素
844+
try {
845+
LineEntry entry = lineEntries.get(i);
846+
if (entry == null) {
847+
continue;
848+
}
849+
int status = entry.getStatuscode();
850+
/**
851+
* -1 No DNS Record,or just DNS Record
852+
* 0 No Response
853+
* 400 Bad Request
854+
* 502 Bad Gateway
855+
* 503 Service Unavailable
856+
* 504 Gateway Time-out
857+
* 521 Web Server Is Down
858+
* 522 Connection Timed Out
859+
*
860+
*/
861+
if (status == -1 || status == 0 || status == 400 || status >= 502) {
862+
String url = entry.getUrl();
863+
lineEntries.remove(i);
864+
titleDao.deleteTitleByUrl(url);// 写入数据库
865+
stdout.println("!!! " + url + " deleted, due to status : " + status);
866+
int index = i;
867+
868+
fireTableRowsDeleted(index, index);
869+
}
870+
871+
} catch (Exception e) {
872+
e.printStackTrace(stderr);
873+
}
874+
}
875+
});
876+
877+
}
839878

840879
/**
841880
* 暂时只是标记重复项目,然后用户可以手动标记,不直接执行删除操作
@@ -1063,39 +1102,40 @@ public void addNewLineEntryWithTime(LineEntry lineEntry) {
10631102
String key = lineEntry.getUrl() + "#" + System.nanoTime();
10641103
lineEntry.setUrl(key);
10651104
lineEntries.put(key, lineEntry);
1066-
1105+
10671106
// compute index from size - 1: this avoids reliance on indexOfKey correctness
1068-
int index;
1069-
try {
1070-
index = lineEntries.size() - 1;
1071-
if (index < 0) {
1072-
index = 0;
1073-
}
1074-
} catch (Exception e) {
1075-
index = lineEntries.indexOfKey(key); // fallback
1076-
}
1077-
1107+
int index;
1108+
try {
1109+
index = lineEntries.size() - 1;
1110+
if (index < 0) {
1111+
index = 0;
1112+
}
1113+
} catch (Exception e) {
1114+
index = lineEntries.indexOfKey(key); // fallback
1115+
}
1116+
10781117
// System.out.println("rowCount=" + getRowCount() + ", lineEntries.size=" + lineEntries.size());
10791118
// System.out.println("index=" + index + ", size=" + lineEntries.size());
1080-
1119+
10811120
/**
1082-
* java.lang.ArrayIndexOutOfBoundsException: Index 1847 out of bounds for length 1847
1083-
* at java.desktop/javax.swing.DefaultRowSorter.setModelToViewFromViewToModel(DefaultRowSorter.java:745)
1121+
* java.lang.ArrayIndexOutOfBoundsException: Index 1847 out of bounds for length
1122+
* 1847 at
1123+
* java.desktop/javax.swing.DefaultRowSorter.setModelToViewFromViewToModel(DefaultRowSorter.java:745)
10841124
*/
1085-
//方案1:
1125+
// 方案1:
10861126
// LineTable table = guiMain.getTitlePanel().getTitleTable();
10871127
// RowSorter<? extends TableModel> sorter = table.getRowSorter();
10881128
// table.setRowSorter(null); // temporarily disable sorter
10891129
//
10901130
// fireTableRowsInserted(index, index);// 有毫秒级时间戳,只会是新增
10911131
//
10921132
// table.setRowSorter(sorter); // enable again
1093-
1094-
//方案2:
1133+
1134+
// 方案2:
10951135
fireTableDataChanged();
1096-
1136+
10971137
new Thread(() -> titleDao.addOrUpdateTitle(lineEntry)).start();// 写入数据库
1098-
System.out.println(key+" added");
1138+
System.out.println(key + " added");
10991139
});
11001140

11011141
}

0 commit comments

Comments
 (0)