1
|
|
|
// jshint esversion: 8, -W069 |
2
|
|
|
/** global: appSettings */ |
3
|
|
|
|
4
|
|
|
const whois = require('../../common/whoisWrapper'), |
|
|
|
|
5
|
|
|
conversions = require('../../common/conversions'), |
6
|
|
|
fs = require('fs'); |
7
|
|
|
|
8
|
|
|
const { |
9
|
|
|
ipcRenderer |
10
|
|
|
} = require('electron'), { |
11
|
|
|
tableReset |
12
|
|
|
} = require('./auxiliary'); |
13
|
|
|
|
14
|
|
|
require('../../common/stringFormat'); |
15
|
|
|
|
16
|
|
|
var bwFileContents; |
17
|
|
|
|
18
|
|
|
/* |
19
|
|
|
ipcRenderer.on('bw:fileinput.confirmation', function(...) {...}); |
20
|
|
|
// File input, path and information confirmation container |
21
|
|
|
parameters |
22
|
|
|
event |
23
|
|
|
filePath |
24
|
|
|
isDragDrop |
25
|
|
|
*/ |
26
|
|
|
ipcRenderer.on('bw:fileinput.confirmation', function(event, filePath = null, isDragDrop = false) { |
27
|
|
|
var bwFileStats; // File stats, size, last changed, etc |
28
|
|
|
const { |
29
|
|
|
misc, |
30
|
|
|
lookup |
31
|
|
|
} = settings; |
|
|
|
|
32
|
|
|
|
33
|
|
|
//console.log(filePath); |
34
|
|
|
if (filePath === undefined || filePath == '' || filePath === null) { |
35
|
|
|
//console.log(filePath); |
36
|
|
|
$('#bwFileinputloading').addClass('is-hidden'); |
37
|
|
|
$('#bwEntry').removeClass('is-hidden'); |
38
|
|
|
} else { |
39
|
|
|
$('#bwLoadingInfo').text('Loading file stats...'); |
40
|
|
|
if (isDragDrop === true) { |
41
|
|
|
$('#bwEntry').addClass('is-hidden'); |
42
|
|
|
$('#bwFileinputloading').removeClass('is-hidden'); |
43
|
|
|
bwFileStats = fs.statSync(filePath); |
44
|
|
|
bwFileStats['filename'] = filePath.replace(/^.*[\\\/]/, ''); |
45
|
|
|
bwFileStats['humansize'] = conversions.byteToHumanFileSize(bwFileStats['size'], misc.usestandardsize); |
46
|
|
|
$('#bwFileSpanInfo').text('Loading file contents...'); |
47
|
|
|
bwFileContents = fs.readFileSync(filePath); |
48
|
|
|
} else { |
49
|
|
|
bwFileStats = fs.statSync(filePath[0]); |
50
|
|
|
bwFileStats['filename'] = filePath[0].replace(/^.*[\\\/]/, ''); |
51
|
|
|
bwFileStats['humansize'] = conversions.byteToHumanFileSize(bwFileStats['size'], misc.usestandardsize); |
52
|
|
|
$('#bwFileSpanInfo').text('Loading file contents...'); |
53
|
|
|
bwFileContents = fs.readFileSync(filePath[0]); |
54
|
|
|
} |
55
|
|
|
$('#bwFileSpanInfo').text('Getting line count...'); |
56
|
|
|
bwFileStats['linecount'] = bwFileContents.toString().split('\n').length; |
57
|
|
|
|
58
|
|
|
if (lookup.randomize.timebetween === true) { |
59
|
|
|
bwFileStats['minestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.randomize.timebetweenmin); |
60
|
|
|
bwFileStats['maxestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.randomize.timebetweenmax); |
61
|
|
|
|
62
|
|
|
$('#bwFileSpanTimebetweenmin').text('{0}ms '.format(lookup.randomize.timebetweenmin)); |
63
|
|
|
$('#bwFileSpanTimebetweenmax').text('/ {0}ms'.format(lookup.randomize.timebetweenmax)); |
64
|
|
|
$('#bwFileTdEstimate').text('{0} to {1}'.format(bwFileStats['minestimate'], bwFileStats['maxestimate'])); |
65
|
|
|
} else { |
66
|
|
|
bwFileStats['minestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.timebetween); |
67
|
|
|
$('#bwFileSpanTimebetweenminmax').addClass('is-hidden'); |
68
|
|
|
$('#bwFileSpanTimebetweenmin').text(lookup.timebetween + 'ms'); |
69
|
|
|
$('#bwFileTdEstimate').text('> {0}'.format(bwFileStats['minestimate'])); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
|
74
|
|
|
bwFileStats['filepreview'] = bwFileContents.toString().substring(0, 50); |
75
|
|
|
//console.log(readLines(filePath[0])); |
76
|
|
|
//console.log(bwFileStats['filepreview']); |
77
|
|
|
|
78
|
|
|
//console.log(lineCount(bwFileContents)); |
79
|
|
|
$('#bwFileinputloading').addClass('is-hidden'); |
80
|
|
|
$('#bwFileinputconfirm').removeClass('is-hidden'); |
81
|
|
|
|
82
|
|
|
// stats |
83
|
|
|
$('#bwFileTdName').text(bwFileStats['filename']); |
84
|
|
|
$('#bwFileTdLastmodified').text(conversions.getDate(bwFileStats['mtime'])); |
85
|
|
|
$('#bwFileTdLastaccess').text(conversions.getDate(bwFileStats['atime'])); |
86
|
|
|
$('#bwFileTdFilesize').text(bwFileStats['humansize'] + ' ({0} line(s))'.format(bwFileStats['linecount'])); |
87
|
|
|
$('#bwFileTdFilepreview').text(bwFileStats['filepreview'] + '...'); |
88
|
|
|
//$('#bwTableMaxEstimate').text(bwFileStats['maxestimate']); |
89
|
|
|
//console.log('cont:'+ bwFileContents); |
90
|
|
|
|
91
|
|
|
//console.log(bwFileStats['linecount']); |
92
|
|
|
} |
93
|
|
|
}); |
94
|
|
|
|
95
|
|
|
/* |
96
|
|
|
$('#bwEntryButtonFile').click(function() {...}); |
97
|
|
|
File Input, Entry container button |
98
|
|
|
*/ |
99
|
|
|
$('#bwEntryButtonFile').click(function() { |
100
|
|
|
$('#bwEntry').addClass('is-hidden'); |
101
|
|
|
$.when($('#bwFileinputloading').removeClass('is-hidden').delay(10)).done(function() { |
102
|
|
|
ipcRenderer.send("bw:input.file"); |
103
|
|
|
}); |
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
/* |
107
|
|
|
$('#bwFileButtonCancel').click(function() {...}); |
108
|
|
|
File Input, cancel file confirmation |
109
|
|
|
*/ |
110
|
|
|
$('#bwFileButtonCancel').click(function() { |
111
|
|
|
$('#bwFileinputconfirm').addClass('is-hidden'); |
112
|
|
|
$('#bwEntry').removeClass('is-hidden'); |
113
|
|
|
}); |
114
|
|
|
|
115
|
|
|
/* |
116
|
|
|
$('#bwFileButtonConfirm').click(function() {...}); |
117
|
|
|
File Input, proceed to bulk whois |
118
|
|
|
*/ |
119
|
|
|
$('#bwFileButtonConfirm').click(function() { |
120
|
|
|
var bwDomainArray = bwFileContents.toString().split('\n').map(Function.prototype.call, String.prototype.trim); |
121
|
|
|
var bwTldsArray = $('#bwFileInputTlds').val().toString().split(','); |
122
|
|
|
|
123
|
|
|
tableReset(bwDomainArray.length, bwTldsArray.length); |
124
|
|
|
$('#bwFileinputconfirm').addClass('is-hidden'); |
125
|
|
|
$('#bwProcessing').removeClass('is-hidden'); |
126
|
|
|
|
127
|
|
|
/* |
128
|
|
|
console.log(bwDomainArray); |
129
|
|
|
console.log(bwTldsArray); |
130
|
|
|
*/ |
131
|
|
|
|
132
|
|
|
ipcRenderer.send("bw:lookup", bwDomainArray, bwTldsArray); |
133
|
|
|
}); |
134
|
|
|
|
135
|
|
|
/* |
136
|
|
|
dragDropInitialization (self-executing) |
137
|
|
|
Bulk whois file input by drag and drop |
138
|
|
|
*/ |
139
|
|
|
(function dragDropInitialization() { |
140
|
|
|
var holder = $('#bwMainContainer'); |
141
|
|
|
holder.ondragover = function() { |
142
|
|
|
return false; |
143
|
|
|
}; |
144
|
|
|
|
145
|
|
|
holder.ondragleave = function() { |
146
|
|
|
return false; |
147
|
|
|
}; |
148
|
|
|
|
149
|
|
|
holder.ondragend = function() { |
150
|
|
|
return false; |
151
|
|
|
}; |
152
|
|
|
|
153
|
|
|
holder.ondrop = function(event) { |
154
|
|
|
event.preventDefault(); |
155
|
|
|
for (let f of event.dataTransfer.files) { |
156
|
|
|
ipcRenderer.send('File(s) you dragged here: {0}'.format(f.path)); |
157
|
|
|
ipcRenderer.send('ondragstart', f.path); |
158
|
|
|
} |
159
|
|
|
return false; |
160
|
|
|
}; |
161
|
|
|
})(); |
162
|
|
|
|
163
|
|
|
/* |
164
|
|
|
$("html").on("dragover", function(event) { |
165
|
|
|
event.preventDefault(); |
166
|
|
|
event.stopPropagation(); |
167
|
|
|
console.log('dragging'); |
168
|
|
|
}); |
169
|
|
|
|
170
|
|
|
$("html").on("dragleave", function(event) { |
171
|
|
|
event.preventDefault(); |
172
|
|
|
event.stopPropagation(); |
173
|
|
|
console.log('dragging'); |
174
|
|
|
}); |
175
|
|
|
|
176
|
|
|
$("html").on("drop", function(event) { |
177
|
|
|
event.preventDefault(); |
178
|
|
|
event.stopPropagation(); |
179
|
|
|
alert("Dropped!"); |
180
|
|
|
});*/ |
181
|
|
|
|
182
|
|
|
/* |
183
|
|
|
$('#bwMainContainer').on('drop', function(...) {...}); |
184
|
|
|
On Drop ipsum |
185
|
|
|
*/ |
186
|
|
|
$('#bwMainContainer').on('drop', function(event) { |
187
|
|
|
event.preventDefault(); |
188
|
|
|
for (let f of event.originalEvent.dataTransfer.files) { |
189
|
|
|
ipcRenderer.send('File(s) you dragged here: {0}'.format(f.path)); |
190
|
|
|
ipcRenderer.send('ondragstart', f.path); |
191
|
|
|
} |
192
|
|
|
return false; |
193
|
|
|
}); |
194
|
|
|
|
195
|
|
|
/* |
196
|
|
|
$('#bwFileInputTlds').keyup(function(...) {...}); |
197
|
|
|
ipsum |
198
|
|
|
*/ |
199
|
|
|
$('#bwFileInputTlds').keyup(function(event) { |
200
|
|
|
// Cancel the default action, if needed |
201
|
|
|
event.preventDefault(); |
202
|
|
|
// Number 13 is the "Enter" key on the keyboard |
203
|
|
|
if (event.keyCode === 13) { |
204
|
|
|
// Trigger the button element with a click |
205
|
|
|
$('#bwFileButtonConfirm').click(); |
206
|
|
|
} |
207
|
|
|
}); |
208
|
|
|
|