Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10361051
index.mjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
index.mjs
View Options
import
{
WebSocketServer
}
from
"ws"
;
import
child_process
from
"child_process"
;
import
fs
from
"fs"
;
import
{
send_notification
}
from
"./notifications.mjs"
;
async
function
spawnPromise
(
program
,
args
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
output
=
""
;
const
process
=
child_process
.
spawn
(
program
,
args
);
process
.
stdout
.
on
(
"data"
,
(
data
)
=>
{
output
+=
data
;
});
process
.
stderr
.
on
(
"data"
,
(
data
)
=>
{
output
+=
data
;
});
process
.
on
(
"close"
,
(
code
)
=>
{
resolve
({
output
,
code
});
});
});
}
const
wss
=
new
WebSocketServer
({
port
:
3000
});
//maybe check output of child processes and send errors in some way
wss
.
on
(
"connection"
,
(
ws
)
=>
{
ws
.
on
(
"message"
,
async
(
dataBuf
)
=>
{
let
data
=
dataBuf
.
toString
();
if
(
data
===
"screenshot"
)
{
await
spawnPromise
(
"bash"
,
[
"/conf/screenshot.sh"
]);
ws
.
send
(
fs
.
readFileSync
(
"/screenshot.png"
));
}
else
if
(
data
.
includes
(
"touch"
))
{
const
dataSplit
=
data
.
split
(
" "
);
await
spawnPromise
(
"bash"
,
[
"/conf/touch.sh"
,
dataSplit
[
1
],
dataSplit
[
2
],
]);
}
else
if
(
data
===
"back"
)
{
await
spawnPromise
(
"bash"
,
[
"/conf/back.sh"
]);
}
else
if
(
data
===
"home"
)
{
await
spawnPromise
(
"bash"
,
[
"/conf/home.sh"
]);
}
else
if
(
data
===
"install"
)
{
const
res
=
await
spawnPromise
(
"bash"
,
[
"/conf/install.sh"
]);
send_notification
(
res
.
code
===
0
,
"Installing the application"
,
res
.
output
);
}
else
if
(
data
.
includes
(
"drag"
))
{
const
dataSplit
=
data
.
split
(
" "
);
await
spawnPromise
(
"bash"
,
[
"/conf/drag.sh"
,
dataSplit
[
1
],
dataSplit
[
2
],
dataSplit
[
3
],
dataSplit
[
4
],
]);
}
});
ws
.
on
(
"close"
,
(
_
)
=>
{
ws
.
close
();
});
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Nov 8, 10:41 (22 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034480
Default Alt Text
index.mjs (1 KB)
Attached To
Mode
R134 rentgen-android
Attached
Detach File
Event Timeline
Log In to Comment