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