-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge_pc.js
More file actions
101 lines (68 loc) · 2.46 KB
/
bridge_pc.js
File metadata and controls
101 lines (68 loc) · 2.46 KB
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
//NODEJS SERVER RUNNING ON BRIDGE PC
var express = require('express');
var http = require('http');
var app = express();
fs = require('fs');
var exec = require('child_process').exec;
app.get('/:lat/:long/:prs', function (req, response) {
var lat = (req.params.lat);
var long = (req.params.long);
var prs = (req.params.prs);
console.log(req.url);
response.contentType('text/html');
exec( 'ssh -i nico.pem ubuntu@52.25.21.145 curl -H \"Accept: application/xml\" -H \"Content-Type: application/xml\" -X GET http://0.0.0.0:3000/'+lat+'/'+long+'/'+prs, function (error, stdout, stderr) {
// output is in stdout
console.log(stdout);console.log(error);console.log(stderr);
response.send(stdout);
if(stdout == '{"in_fence":true}' )
{
var nodemailer = require('nodemailer');
// Create a SMTP transporter object
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'nikotesta@gmail.com',
pass: '*******'// here the password associated to the account is needed
},
ssl: true
});
console.log('SMTP Configured');
// Message object
var message = {
// sender info
from: 'Nico Testolin <nikotesta@gmail.com>',
// Comma separated list of recipients
to: '<danpozza21@hotmail.it>',
// Subject of the message
subject: '!!! ATTENZIONE VIOLAZIONE AREA PROTETTA !!!',
// plaintext body
text: 'Attenzione è stata violata la zona protetta da '+prs+' persona/e, a latitudine : ' + lat+ ' e longitudine : '+long
};
console.log('Sending Mail');
transporter.sendMail(message, function(error, info) {
if (error) {
console.log('Errore durante invio mail. Disattivare antivirus !! ');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
console.log('Server responded with "%s"', info.response);
});
}
});
});
app.get('/checkfences', function (req, response) {
// var uuid = (req.params.uuid);
console.log(req.url);
response.contentType('text/html');
exec("curl http://127.0.0.1:4242/fences", function (error, stdout, stderr) {
// output is in stdout
console.log(stdout);console.log(error);console.log(stderr);
response.send(stdout);
});
});
var server = app.listen(process.env.PORT||3000, function () {
var localhost ="0.0.0.0"; //server.address().address;
port = server.address().port;
console.log('bridge server listening at http://%s:%s', localhost, port);
});