2024-10-04 23:04:43 +00:00
|
|
|
import { Client } from 'ssh2';
|
2024-10-04 22:41:01 +00:00
|
|
|
export const handler = async (event) => {
|
|
|
|
let result = "did not send";
|
|
|
|
if (event.subject == "You have deliveries" || event.subject == "You have a delivery"){
|
|
|
|
// Trigger home notification
|
2024-10-04 23:04:08 +00:00
|
|
|
console.info("Matched Subject");
|
2024-10-04 22:41:01 +00:00
|
|
|
const command = `ssh ${process.env.INTERNAL_HOST} "/usr/bin/tmux neww -d \"/usr/bin/mplayer '${process.env.INTERNAL_FILE}'\""`;
|
2024-10-04 23:04:08 +00:00
|
|
|
console.info("Import ssh2");
|
2024-10-04 22:41:01 +00:00
|
|
|
const connection = new Client();
|
2024-10-04 23:04:08 +00:00
|
|
|
console.info("Set Conn Info");
|
2024-10-04 22:41:01 +00:00
|
|
|
connection.on('ready', () => {
|
2024-10-04 23:04:08 +00:00
|
|
|
console.info("Connection READY")
|
2024-10-04 22:41:01 +00:00
|
|
|
connection.exec(command, (error, stream) => {
|
|
|
|
if (error) {
|
|
|
|
console.warn(error);
|
|
|
|
result = JSON.stringify(error);
|
|
|
|
}
|
|
|
|
stream.on('close', (code, signal) => {
|
|
|
|
// COMPLETE
|
|
|
|
console.info("Trigger completed", code, signal)
|
|
|
|
}).stderr.on('data', (data) => {
|
|
|
|
// STDERR
|
|
|
|
console.warn(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).connect({
|
|
|
|
host: process.env.TRIGGER_HOST,
|
|
|
|
port: 22,
|
|
|
|
username: process.env.TRIGGER_USERNAME,
|
|
|
|
privateKey: process.env.TRIGGER_PRIVATEKEY
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const response = {
|
|
|
|
statusCode: 200,
|
|
|
|
body: {
|
|
|
|
result
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return response;
|
|
|
|
};
|
|
|
|
|