Created
June 13, 2012 19:52
-
-
Save guyht/2926069 to your computer and use it in GitHub Desktop.
VPN SMS control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'), | |
smsified = require('smsified'), | |
http = require('http'), | |
spawn = require('child_process').spawn; | |
var sms = new SMSified('USERNAME', 'PASSWORD'); | |
var server = http.createServer(function(req, res) { | |
req.addListener('data', function(data){ | |
var json = JSON.parse(data); | |
var inbound = new InboundMessage(json); | |
sys.puts('Inbound message: ' + inbound.message); | |
if(inbound.message == 'Start') { | |
exec('/home/ubuntu/bin/vpn-start'); | |
} else if(inbound.message == 'Stop') { | |
exec('/home/ubuntu/bin/vpn-stop'); | |
} else if(inbound.message == 'Status') { | |
exec('/home/ubuntu/bin/vpn-status'); | |
} | |
}); | |
res.writeHead(200); | |
res.end(); | |
}).listen(8811); | |
function exec(cmd) { | |
var vpn_start = spawn(cmd.replace(/^\s\s*/, '')), | |
d = []; | |
vpn_start.stdout.on('data', function(data) { | |
d.push(data); | |
}); | |
vpn_start.stderr.on('data', function(data) { | |
d.push(data); | |
}); | |
vpn_start.on('exit', function(code) { | |
d.push('exited with code: ' + code); | |
d = d.join('\n'); | |
console.log(d); | |
send(d); | |
}); | |
} | |
function send(msg) { | |
var options = {senderAddress : 'FROM_NUMBER', address : 'MY_PHONE_NUMBER', message : msg}; | |
sms.sendMessage(options, function(result) { | |
sys.puts(sys.inspect(result)); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ec2-start-instances -U https://ec2.eu-west-1.amazonaws.com INSTANCE-ID | |
IP=`ec2-allocate-address -U https://ec2.eu-west-1.amazonaws.com | awk '{print $2}'` | |
ec2-associate-address -U https://ec2.eu-west-1.amazonaws.com -i INSTANCE-ID $IP | |
echo $IP > .ip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ec2-stop-instances -U https://ec2.eu-west-1.amazonaws.com INSTANCE_ID | |
IP=`cat .ip` | |
ec2-disassociate-address -U https://ec2.eu-west-1.amazonaws.com $IP | |
ec2-release-address -U https://ec2.eu-west-1.amazonaws.com $IP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment