Repository navigation
Expand file tree
/
Copy pathimport_ip.html
More file actions
98 lines (88 loc) · 2.89 KB
/
Copy pathimport_ip.html
File metadata and controls
98 lines (88 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<form method="POST" onSubmit="onSubmit(); return false;">
<div class="row-fluid">
<div class="span2">
<label for="ip-list">{{ _( "IP list" ) }}</label>
</div> <!-- .span2 -->
<div class="span10">
<textarea id="ip-list" rows="10"></textarea>
</div> <!-- .span10 -->
</div> <!-- .row-fluid -->
<div class="row-fluid">
<div class="span12">
<button class="btn btn-primary btn-block" type="submit">{{ _( "Run" ) }}</button>
</div> <!-- .span12 -->
</div> <!-- .row-fluid -->
</form> <!-- #import-export-ip -->
<script type="text/javascript">
function onSubmit() {
var ipList = $('#ip-list').val();
return doImportAction(ipList);
}
</script>
<script type="text/javascript">
function doImportAction(ipList) {
ipList = conversionFormat('3', '1', ipList);
console.log('尝试导入 ', ipList.split('|').length, ' 个IP.');
var postData = {
'ipList': ipList
};
$.ajax({
type: 'POST',
url: '/module/gae_proxy/control/importip?cmd=importip',
data: postData,
dataType: 'JSON',
success: function(result) {
tip('成功导入' + result['res'] + '个IP.', 'success');
},
error: function() {
tip('导入IP失败');
}
});
}
</script>
<script type="text/javascript">
function conversionFormat(originalFormat, targetFormat, sourceData) {
if( originalFormat == targetFormat ) {
return sourceData;
}
var ipList;
switch(originalFormat) { //由源数据转换为中间格式
case '1': //IP|IP|IP
ipList = sourceData.split("|");
break;
case '2': //换行分割
ipList = sourceData.split("\n");
break;
case '3': //智能正则匹配
var tmp = ' ' + sourceData;
var regex = /(?!\d)[^\d](([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])(\.([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])){3}(?!\d))/gm;
var regexResult;
ipList = [];
while(true) {
regexResult = regex.exec(tmp);
if(regexResult === null) {
break;
}
ipList.push(regexResult[1]);
}
break;
}
var result;
switch(targetFormat) { //由中间格式转换为目标格式
case '1': //IP|IP|IP
result = '';
for(var id in ipList) {
result += ipList[id] + '|';
}
result = result.substr(0, result.length - 1);
break;
case '2': //换行分割
result = '';
for(var id in ipList) {
result += ipList[id] + '\n';
}
break;
}
return result;
}
</script>