1
|
|
|
// jshint esversion: 8, -W069 |
2
|
|
|
|
3
|
|
|
/** global: settings */ |
4
|
|
|
const whois = require('../../common/whoisWrapper'), |
|
|
|
|
5
|
|
|
conversions = require('../../common/conversions'), |
6
|
|
|
fs = require('fs'), |
7
|
|
|
Papa = require('papaparse'), |
8
|
|
|
dt = require('datatables')(); |
|
|
|
|
9
|
|
|
|
10
|
|
|
const { |
11
|
|
|
ipcRenderer |
12
|
|
|
} = require('electron'); |
13
|
|
|
|
14
|
|
|
require('../../common/stringFormat'); |
15
|
|
|
|
16
|
|
|
var bwaFileContents; |
17
|
|
|
|
18
|
|
|
/* |
19
|
|
|
ipcRenderer.on('bwa:fileinput.confirmation', function(...) {...}); |
20
|
|
|
File input, path and information confirmation container |
21
|
|
|
*/ |
22
|
|
|
ipcRenderer.on('bwa:fileinput.confirmation', function(event, filePath = null, isDragDrop = false) { |
23
|
|
|
var bwaFileStats; // File stats, size, last changed, etc |
24
|
|
|
|
25
|
|
|
$('#bwaFileSpanInfo').text('Waiting for file...'); |
26
|
|
|
|
27
|
|
|
//console.log(filePath); |
28
|
|
|
if (filePath === undefined || filePath == '' || filePath === null) { |
29
|
|
|
//console.log(filePath); |
30
|
|
|
$('#bwaFileinputloading').addClass('is-hidden'); |
31
|
|
|
$('#bwaEntry').removeClass('is-hidden'); |
32
|
|
|
} else { |
33
|
|
|
$('#bwaFileSpanInfo').text('Loading file stats...'); |
34
|
|
|
if (isDragDrop === true) { |
35
|
|
|
$('#bwaEntry').addClass('is-hidden'); |
36
|
|
|
$('#bwaFileinputloading').removeClass('is-hidden'); |
37
|
|
|
bwaFileStats = fs.statSync(filePath); |
38
|
|
|
bwaFileStats['filename'] = filePath.replace(/^.*[\\\/]/, ''); |
39
|
|
|
bwaFileStats['humansize'] = conversions.byteToHumanFileSize(bwaFileStats['size'], settings['lookup.misc'].useStandardSize); |
40
|
|
|
$('#bwaFileSpanInfo').text('Loading file contents...'); |
41
|
|
|
bwaFileContents = Papa.parse(fs.readFileSync(filePath).toString(), { |
42
|
|
|
header: true |
43
|
|
|
}); |
44
|
|
|
} else { |
45
|
|
|
bwaFileStats = fs.statSync(filePath[0]); |
46
|
|
|
bwaFileStats['filename'] = filePath[0].replace(/^.*[\\\/]/, ''); |
47
|
|
|
bwaFileStats['humansize'] = conversions.byteToHumanFileSize(bwaFileStats['size'], settings['lookup.misc'].useStandardSize); |
48
|
|
|
$('#bwaFileSpanInfo').text('Loading file contents...'); |
49
|
|
|
bwaFileContents = Papa.parse(fs.readFileSync(filePath[0]).toString(), { |
50
|
|
|
header: true |
51
|
|
|
}); |
52
|
|
|
} |
53
|
|
|
//console.log(bwaFileContents.data[0]); |
54
|
|
|
$('#bwaFileSpanInfo').text('Getting line count...'); |
55
|
|
|
bwaFileStats['linecount'] = bwaFileContents.data.length; |
56
|
|
|
try { |
57
|
|
|
bwaFileStats['filepreview'] = JSON.stringify(bwaFileContents.data[0], null, "\t").substring(0, 50); |
58
|
|
|
} catch (e) { |
59
|
|
|
bwaFileStats['filepreview'] = ''; |
60
|
|
|
} |
61
|
|
|
bwaFileStats['errors'] = JSON.stringify(bwaFileContents.errors).slice(1, -1); |
62
|
|
|
//console.log(bwaFileContents.data); |
63
|
|
|
|
64
|
|
|
//console.log(readLines(filePath[0])); |
65
|
|
|
//console.log(bwFileStats['filepreview']); |
66
|
|
|
|
67
|
|
|
//console.log(lineCount(bwFileContents)); |
68
|
|
|
$('#bwaFileinputloading').addClass('is-hidden'); |
69
|
|
|
$('#bwaFileinputconfirm').removeClass('is-hidden'); |
70
|
|
|
|
71
|
|
|
// stats |
72
|
|
|
$('#bwaFileTdFilename').text(bwaFileStats['filename']); |
73
|
|
|
$('#bwaFileTdLastmodified').text(conversions.getDate(bwaFileStats['mtime'])); |
74
|
|
|
$('#bwaFileTdLastaccessed').text(conversions.getDate(bwaFileStats['atime'])); |
75
|
|
|
$('#bwaFileTdFilesize').text(bwaFileStats['humansize'] + ' ({0} record(s))'.format(bwaFileStats['linecount'])); |
76
|
|
|
$('#bwaFileTdFilepreview').text(bwaFileStats['filepreview'] + '...'); |
77
|
|
|
$('#bwaFileTextareaErrors').text(bwaFileStats['errors'] || "No errors"); |
78
|
|
|
//$('#bwTableMaxEstimate').text(bwFileStats['maxestimate']); |
79
|
|
|
//console.log('cont:'+ bwFileContents); |
80
|
|
|
|
81
|
|
|
//console.log(bwFileStats['linecount']); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return; |
85
|
|
|
}); |
86
|
|
|
|
87
|
|
|
/* |
88
|
|
|
$('#bwaEntryButtonOpen').click(function() {...}); |
89
|
|
|
Bulk whois, file input, entry container button |
90
|
|
|
*/ |
91
|
|
|
$('#bwaEntryButtonOpen').click(function() { |
92
|
|
|
$('#bwaEntry').addClass('is-hidden'); |
93
|
|
|
$.when($('#bwaFileinputloading').removeClass('is-hidden').delay(10)).done(function() { |
94
|
|
|
ipcRenderer.send("bwa:input.file"); |
95
|
|
|
}); |
96
|
|
|
|
97
|
|
|
return; |
|
|
|
|
98
|
|
|
}); |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/* |
102
|
|
|
$('#bwaFileinputconfirmButtonCancel').click(function() {...}); |
103
|
|
|
Bulk whois, file input, cancel button, file confirmation |
104
|
|
|
*/ |
105
|
|
|
$('#bwaFileinputconfirmButtonCancel').click(function() { |
106
|
|
|
$('#bwaFileinputconfirm').addClass('is-hidden'); |
107
|
|
|
$('#bwaEntry').removeClass('is-hidden'); |
108
|
|
|
|
109
|
|
|
return; |
|
|
|
|
110
|
|
|
}); |
111
|
|
|
|
112
|
|
|
/* |
113
|
|
|
$('#bwaFileinputconfirmButtonStart').click(function() {...}); |
114
|
|
|
Bulk whois, file input, start button, file confirmation |
115
|
|
|
*/ |
116
|
|
|
$('#bwaFileinputconfirmButtonStart').click(function() { |
117
|
|
|
ipcRenderer.send("bwa:analyser.start", bwaFileContents); |
118
|
|
|
/* |
119
|
|
|
$('#bwaFileinputconfirm').addClass('is-hidden'); |
120
|
|
|
$.when($('#bwaProcess').removeClass('is-hidden').delay(10)).done(function() { |
121
|
|
|
showTable(); |
122
|
|
|
});*/ |
123
|
|
|
|
124
|
|
|
return; |
|
|
|
|
125
|
|
|
}); |
126
|
|
|
|
127
|
|
|
/* |
128
|
|
|
// File Input, proceed to bulk whois |
129
|
|
|
$('#bwafButtonConfirm').click(function() { |
130
|
|
|
var bwDomainArray = bwFileContents.toString().split('\n').map(Function.prototype.call, String.prototype.trim); |
131
|
|
|
var bwTldsArray = $('#bwfSearchTlds').val().toString().split(','); |
132
|
|
|
|
133
|
|
|
$('#bwFileInputConfirm').addClass('is-hidden'); |
134
|
|
|
$('#bwProcessing').removeClass('is-hidden'); |
135
|
|
|
|
136
|
|
|
ipcRenderer.send("bulkwhois:lookup", bwDomainArray, bwTldsArray); |
137
|
|
|
}); |
138
|
|
|
|
139
|
|
|
// Bulk whois file input by drag and drop |
140
|
|
|
(function() { |
141
|
|
|
var holder = document.getElementById('bwaMainContainer'); |
142
|
|
|
holder.ondragover = function() { |
143
|
|
|
return false; |
144
|
|
|
}; |
145
|
|
|
|
146
|
|
|
holder.ondragleave = function() { |
147
|
|
|
return false; |
148
|
|
|
}; |
149
|
|
|
|
150
|
|
|
holder.ondragend = function() { |
151
|
|
|
return false; |
152
|
|
|
}; |
153
|
|
|
|
154
|
|
|
holder.ondrop = function(event) { |
155
|
|
|
event.preventDefault(); |
156
|
|
|
for (let f of event.dataTransfer.files) { |
157
|
|
|
ipcRenderer.send('File(s) you dragged here: {0}'.format(f.path)); |
158
|
|
|
ipcRenderer.send('ondragstart', f.path); |
159
|
|
|
} |
160
|
|
|
return false; |
161
|
|
|
}; |
162
|
|
|
})(); |
163
|
|
|
|
164
|
|
|
// Enter when confirming file input bulk whois |
165
|
|
|
document.getElementById('bwfSearchTlds').addEventListener("keyup", function(event) { |
166
|
|
|
// Cancel the default action, if needed |
167
|
|
|
event.preventDefault(); |
168
|
|
|
// Number 13 is the "Enter" key on the keyboard |
169
|
|
|
if (event.keyCode === 13) { |
170
|
|
|
// Trigger the button element with a click |
171
|
|
|
$('#bwfButtonConfirm').click(); |
172
|
|
|
} |
173
|
|
|
}); |
174
|
|
|
*/ |
175
|
|
|
|