-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (36 loc) · 1.61 KB
/
index.js
File metadata and controls
39 lines (36 loc) · 1.61 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
const express = require('express');
const app = express();
const shell = require('shelljs');
var payload = require('request-payload');
const crypto = require('crypto');
exports.start = function (secret,port){
var hmac,hash;
app.listen(port, () => {
console.log('Update Port : ' + port);
});
app.post('/deployment/updatetheapp', (req, res) => {
var rhash = req.headers['x-hub-signature'];
if (process.platform == "linux") {
payload(req, function(body) {
hmac = crypto.createHmac('sha1',secret)
hmac.update(body);
hash = hmac.digest('hex');
hash = 'sha1=' + hash;
if(rhash==hash){
console.log("verified");
var cmd = "echo ========================================================;echo ------------------- Updater Script ---------------------;echo ---------------- Connecting to GitHub ------------------;git pull;echo -------------- Updating Node modules -------------------;npm update;npm install;echo ------------------Update completed----------------------;pm2 restart all;exit"
res.send({"message":"Update in progress"})
shell.exec(cmd)
}
else{
console.log("Not Verified");
res.send({"Error":"Invalid Hash !!. Update Not verified !"})
}
});
}
else{
console.log(process.platform + " not supported !!")
res.send({"Error":"NodeJS-ADS does not support " + process.platform});
}
});
}