Repository navigation
Expand file tree
/
Copy pathexport_ip.html
More file actions
107 lines (96 loc) · 3.47 KB
/
Copy pathexport_ip.html
File metadata and controls
107 lines (96 loc) · 3.47 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
99
100
101
102
103
104
105
106
107
<form method="POST" onSubmit="onSubmit(); return false;">
<div class="row-fluid">
<div class="span2">
<label for="ip-format">{{ _( "Export format" ) }}</label>
</div> <!-- .span2 -->
<div class="span10">
<select id="ip-format">
<option value="1" selected>IP|IP|IP (Gogo-Tester/Goagent{{ _( " format" ) }})</option>
<option value="2">{{ _( "New line delimiter" ) }}</option>
</select>
</div> <!-- .span10 -->
</div> <!-- .row-fluid -->
<div class="row-fluid">
<div class="span2">
<label for="ip-list">{{ _( "IP address 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 doExportAction(ipFormat) {
$.ajax({
type: 'POST',
url: '/module/gae_proxy/control/importip?cmd=exportip',
dataType: 'JSON',
success: function(result) {
var ipList = result['res'];
tip('{{ _("Succeeded exporting ") }}' + ipList.split('|').length + '{{ _(" IP addresses.") }}', 'success');
ipList = conversionFormat('1', ipFormat, ipList);
$('#ip-list').val(ipList);
},
error: function() {
tip('{{ _("Failed exporting the IP addresses.") }}', 'error');
}
});
}
</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) { // convert from the interim format to the destination format由中间格式转换为目标格式
case '1': //IP|IP|IP
result = '';
for(var id in ipList) {
result += ipList[id] + '|';
}
result = result.substr(0, result.length - 1);
break;
case '2': //New line delimiter换行分割
result = '';
for(var id in ipList) {
result += ipList[id] + '\n';
}
break;
}
return result;
}
</script>
<script type="text/javascript">
function onSubmit() {
var ipFormat = $('#ip-format').val();
return doExportAction(ipFormat);
}
</script>