-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
146 lines (133 loc) · 3.95 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//win.showDevTools();
var os = require('os');
const exec = require('child_process').exec;
if (os.platform() == 'linux') {
$('button[name="bt-quickill"]').attr('onclick', 'linuxQuickill()');
$('button[name="bt-search"]').attr('onclick', 'linuxSearchProcess()');
$('button[name="bt-killall"]').attr('onclick', 'linuxQuickill()');
$('button[name="bt-kill-selected"]').attr('onclick', 'linuxKillSelected()');
}
$(".txt-search").focus();
function up() {
location = "#first-page";
}
function microsoftQuickill() {
$('.process-list').empty();
var processToFind = $(".txt-search").val();
exec('tasklist | find /I "' + processToFind + '"', (err, sto, ste) => {
if (err) {
flashMessage(`exec error: ${error}`);
return;
}
sto = sto.split("\n");
flashMessage(`sto: ${sto.length}`);
var processToKill = sto[0].match(/[^\\]*\.(\w+)/g);
exec(`taskkill /f /im ${processToKill}`, function(err, sto, ste) {
if (err){
flashMessage(`Error killing process: ${err}`);
return
}
flashMessage(`Process killed, ${sto}`);
});
});
}
function microsoftSearchProcess() {
location = "#second-page";
$('.process-list').empty();
var processToFind = $(".txt-search").val();
exec('tasklist | find /I "' + processToFind + '"', (err, sto, ste) => {
if (err) {
flashMessage(`exec error: ${error}`);
return;
}
sto = sto.split("\n");
sto.pop();
flashMessage(`sto: ${sto.length}`);
var processToKill = sto[0].match(/[^\\]*\.(\w+)/g);
sto.forEach(microsoftLogArrayElements);
});
}
function microsoftLogArrayElements(el, index, array) {
var fileName = el.match(/[^\\]*\.(\w+)/g);
$('.process-list').append(`<input type="checkbox" value="${fileName}">${fileName}<br>`);
}
function microsoftKillSelected() {
var inputChecked = new Array;
var i = 0;
var re = /,/gi; //For string replace
$('input:checked').each(function() {
inputChecked.push($(this).val());
i++;
if (i == $('input:checked').length) {
inputChecked = inputChecked.toString().replace(re, " /im ");
flashMessage(inputChecked);
exec(`taskkill /f /im ${inputChecked}`, (err, sto, ste) => {
if (err){
flashMessage(`Error Killing Selected: ${err}`);
return
}
flashMessage(`Kill Selected: ${sto}`);
});
}
});
}
function linuxQuickill() {
$('.process-list').empty();
var processToFind = $('.txt-search').val();
exec(`pkill -e ${processToFind}`, (err, sto, ste) => {
if (err) {
flashMessage(`Error QuicKilling ${err}`);
return;
}
sto.split("\n");
flashMessage(`You killed: ${sto}`);
});
}
function linuxSearchProcess() {
location = '#second-page';
$('.process-list').empty();
var processToFind = $(".txt-search").val();
exec(`ps -A | grep ${processToFind}`, (err, sto, ste) => {
if (err) {
flashMessage(`Error Searching: ${err}`);
return;
}
sto = sto.split("\n");
sto.pop();
sto.forEach(linuxLogArrayElements);
});
}
function linuxLogArrayElements(el, index, array) {
var uid = el.replace(/\s+/g, "");
uid = uid.match(/^(\d+)/g);
$('.process-list').append(`<input type="checkbox" value="${uid}">${el}<br>`)
}
function linuxKillSelected() {
var inputChecked = new Array;
var i = 0;
$('input:checked').each(function() {
inputChecked.push($(this).val());
i++;
if (i == $('input:checked').length) {
inputChecked = inputChecked.toString().replace(",", " ");
exec(`kill ${inputChecked}`, (err, sto, ste) => {
if(err) {
flashMessage(`Error Killing Selected: ${err}`);
return
}
flashMessage('Killed Selected');
});
}
});
}
// Flash Message
function flashMessage(msg){
if(hideFlashMessage)
clearTimeout(hideFlashMessage);
$('.flashmessage').removeClass('not-visible').addClass('is-visible')
.html('<p>'+msg+'</p>');
var hideFlashMessage = setTimeout(function(){
$('.flashmessage').removeClass('is-visible').addClass('not-visible');
}, 3000);
}
// Flash Message