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