1
|
|
|
// jshint esversion: 8, -W069 |
2
|
|
|
|
3
|
|
|
const whois = require('../common/whoisWrapper'), |
4
|
|
|
parseRawData = require('../common/parseRawData'); |
|
|
|
|
5
|
|
|
|
6
|
|
|
const { |
7
|
|
|
getDate |
8
|
|
|
} = require('../common/conversions'), { |
9
|
|
|
ipcRenderer |
10
|
|
|
} = require('electron'); |
11
|
|
|
|
12
|
|
|
const { |
13
|
|
|
isDomainAvailable, |
14
|
|
|
getDomainParameters, |
15
|
|
|
preStringStrip, |
16
|
|
|
toJSON |
17
|
|
|
} = whois; |
18
|
|
|
|
19
|
|
|
window.$ = window.jQuery = require('jquery'); |
20
|
|
|
|
21
|
|
|
var singleWhois = { |
22
|
|
|
'input': { |
23
|
|
|
'domain': null |
24
|
|
|
}, |
25
|
|
|
'results': null |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
/* |
29
|
|
|
ipcRenderer.on('sw:results', function(...) {...}); |
30
|
|
|
On event: Single whois results, whois reply processing |
31
|
|
|
parameters |
32
|
|
|
event (object) - Event object |
33
|
|
|
domainResults (object) - Domain results object |
34
|
|
|
*/ |
35
|
|
|
ipcRenderer.on('sw:results', function(event, domainResults) { |
36
|
|
|
var domainName, |
37
|
|
|
domainStatus, |
38
|
|
|
domainResultsJSON, |
39
|
|
|
resultFilter, |
40
|
|
|
errorReason; |
41
|
|
|
//ipcRenderer.send('app:debug', "Whois domain reply:\n {0}".format(domainResults)); |
42
|
|
|
|
43
|
|
|
domainResults = preStringStrip(domainResults); |
44
|
|
|
domainResultsJSON = toJSON(domainResults); |
45
|
|
|
|
46
|
|
|
// Check domain status |
47
|
|
|
domainName = domainResultsJSON.domainName || domainResultsJSON.domain; |
48
|
|
|
|
49
|
|
|
domainStatus = isDomainAvailable(domainResults); |
50
|
|
|
resultFilter = getDomainParameters(domainName, domainStatus, domainResults, domainResultsJSON); |
51
|
|
|
|
52
|
|
|
var { |
53
|
|
|
domain, |
54
|
|
|
updateDate, |
55
|
|
|
registrar, |
56
|
|
|
creationDate, |
57
|
|
|
company, |
58
|
|
|
expiryDate |
59
|
|
|
} = resultFilter; |
60
|
|
|
|
61
|
|
|
switch (domainStatus) { |
62
|
|
|
case 'unavailable': |
63
|
|
|
$('#swMessageUnavailable').removeClass('is-hidden'); |
64
|
|
|
$('#swMessageWhoisResults').text(domainResults); |
65
|
|
|
|
66
|
|
|
$('#swTdDomain').attr('url', "http://" + domain); |
67
|
|
|
$('#swTdDomain').text(domain); |
68
|
|
|
|
69
|
|
|
//console.log(domainResultsJSON['registrarRegistrationExpirationDate'] || domainResultsJSON['expires'] || domainResultsJSON['registryExpiryDate']); |
70
|
|
|
$('#swTdUpdate').text(updateDate); |
71
|
|
|
$('#swTdRegistrar').text(registrar); |
72
|
|
|
$('#swTdCreation').text(creationDate); |
73
|
|
|
$('#swTdCompany').text(company); |
74
|
|
|
$('#swTdExpiry').text(expiryDate); |
75
|
|
|
$('#swTableWhoisinfo.is-hidden').removeClass('is-hidden'); |
76
|
|
|
break; |
77
|
|
|
|
78
|
|
|
case 'available': |
79
|
|
|
$('#swMessageWhoisResults').text(domainResults); |
80
|
|
|
$('#swMessageAvailable').removeClass('is-hidden'); |
81
|
|
|
break; |
82
|
|
|
|
83
|
|
|
default: |
84
|
|
|
if (domainStatus.includes('error')) { |
85
|
|
|
errorReason = domainStatus.split(':')[1]; // Get Error reason |
86
|
|
|
$('#swMessageWhoisResults').text("Whois error due to {0}:\n{1}".format(errorReason, domainResults)); |
87
|
|
|
$('#swMessageError').removeClass('is-hidden'); |
88
|
|
|
} else { |
89
|
|
|
$('#swMessageWhoisResults').text("Whois default error\n{0}".format(domainResults)); |
90
|
|
|
$('#swMessageError').removeClass('is-hidden'); |
91
|
|
|
} |
92
|
|
|
break; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$('#swSearchButtonSearch').removeClass('is-loading'); |
96
|
|
|
$('#swSearchInputDomain').removeAttr('readonly'); |
97
|
|
|
|
98
|
|
|
}); |
99
|
|
|
|
100
|
|
|
/* |
101
|
|
|
ipcRenderer.on('sw:copied', function() {...}); |
102
|
|
|
On event: Domain copied |
103
|
|
|
*/ |
104
|
|
|
ipcRenderer.on('sw:copied', function() { |
105
|
|
|
$('#swDomainCopied').addClass('is-active'); |
106
|
|
|
}); |
107
|
|
|
|
108
|
|
|
/* |
109
|
|
|
$('#swSearchInputDomain').keyup(function(...) {...}); |
110
|
|
|
On keyup: Trigger search event with [ENTER] key |
111
|
|
|
*/ |
112
|
|
|
$('#swSearchInputDomain').keyup(function(event) { |
113
|
|
|
// Cancel the default action, if needed |
114
|
|
|
event.preventDefault(); |
115
|
|
|
// Number 13 is the "Enter" key on the keyboard |
116
|
|
|
if (event.keyCode === 13) $('#swSearchButtonSearch').click(); |
117
|
|
|
}); |
118
|
|
|
|
119
|
|
|
/* |
120
|
|
|
$('#swTdDomain').click(function() {...}); |
121
|
|
|
On click: Open website for domain lookup URL in a new window |
122
|
|
|
*/ |
123
|
|
|
$('#swTdDomain').click(function() { |
124
|
|
|
var domain = $('#swTdDomain').attr('url'); |
125
|
|
|
ipcRenderer.send('sw:openlink', domain); |
126
|
|
|
}); |
127
|
|
|
|
128
|
|
|
/* |
129
|
|
|
$('#swSearchButtonSearch').click(function() {...}); |
130
|
|
|
On click: Single whois lookup/search button |
131
|
|
|
*/ |
132
|
|
|
$('#swSearchButtonSearch').click(function() { |
133
|
|
|
var { |
134
|
|
|
input |
135
|
|
|
} = singleWhois; |
136
|
|
|
var { |
137
|
|
|
domain |
138
|
|
|
} = input; |
139
|
|
|
|
140
|
|
|
if ($(this).hasClass('is-loading')) return true; |
141
|
|
|
ipcRenderer.send('app:debug', "#swSearchButtonSearch was clicked"); |
142
|
|
|
|
143
|
|
|
domain = $('#swSearchInputDomain').val(); |
144
|
|
|
|
145
|
|
|
ipcRenderer.send('app:debug', "Looking up for {0}".format(domain)); |
146
|
|
|
|
147
|
|
|
$('#swSearchButtonSearch').addClass('is-loading'); |
148
|
|
|
$('#swSearchInputDomain').attr('readonly', ''); |
149
|
|
|
$('.notification:not(.is-hidden)').addClass('is-hidden'); |
150
|
|
|
$('#swTableWhoisinfo:not(.is-hidden)').addClass('is-hidden'); |
151
|
|
|
tableReset(); |
152
|
|
|
ipcRenderer.send("sw:lookup", domain); |
153
|
|
|
return undefined; |
154
|
|
|
}); |
155
|
|
|
|
156
|
|
|
/* |
157
|
|
|
$('.swMessageWhoisOpen').click(function() {...}); |
158
|
|
|
On click: Single whois lookup modal open click |
159
|
|
|
*/ |
160
|
|
|
$('.swMessageWhoisOpen').click(function() { |
161
|
|
|
ipcRenderer.send('app:debug', "Opening whois reply"); |
162
|
|
|
$('#swMessageWhois').addClass('is-active'); |
163
|
|
|
}); |
164
|
|
|
|
165
|
|
|
/* |
166
|
|
|
$('#swMessageWhoisClose').click(function() {...}); |
167
|
|
|
On click: Single whois lookup modal close click |
168
|
|
|
*/ |
169
|
|
|
$('#swMessageWhoisClose').click(function() { |
170
|
|
|
ipcRenderer.send('app:debug', "Closing whois reply"); |
171
|
|
|
$('#swMessageWhois').removeClass('is-active'); |
172
|
|
|
}); |
173
|
|
|
|
174
|
|
|
/* |
175
|
|
|
$('#swDomainCopiedClose').click(function() {...}); |
176
|
|
|
On click: Domain copied close click |
177
|
|
|
*/ |
178
|
|
|
$('#swDomainCopiedClose').click(function() { |
179
|
|
|
ipcRenderer.send('app:debug', "Closing domain copied"); |
180
|
|
|
$('#swDomainCopied').removeClass('is-active'); |
181
|
|
|
}); |
182
|
|
|
|
183
|
|
|
/* |
184
|
|
|
tableReset |
185
|
|
|
Resets registry table contents |
186
|
|
|
*/ |
187
|
|
|
function tableReset() { |
188
|
|
|
ipcRenderer.send('app:debug', "Resetting whois result table"); |
189
|
|
|
$('#swTdDomain').attr('href', "#"); |
190
|
|
|
$('#swTdDomain').text('n/a'); |
191
|
|
|
$('#swTdUpdate').text('n/a'); |
192
|
|
|
$('#swTdRegistrar').text('n/a'); |
193
|
|
|
$('#swTdCreation').text('n/a'); |
194
|
|
|
$('#swTdCompany').text('n/a'); |
195
|
|
|
$('#swTdExpiry').text('n/a'); |
196
|
|
|
} |
197
|
|
|
|