Remote IP Power Switches
-
Upload
chris-barber -
Category
Technology
-
view
616 -
download
0
Transcript of Remote IP Power Switches
REMOTE IP
POWER
SWITCHES
CHRIS BARBER
PENGUINS UNBOUND – 9/19/15
REMOTE POWER
WHAT?
DATAPROBE IBOOT
PHP SCRIPT
#!/usr/bin/env php<?php
$ip = '192.168.1.211';$port = 80;$password = 'PASS';
$argv = $_SERVER['argv'];
$actions = array("query" => "q","on" => "n","off" => "f","cycle" => "c"
);
$responses = array("N" => "on","F" => "off","Y" => "cycle","U" => "busy"
);
if (count($argv) < 2) {echo "Usage: iboot [query|on|off|cycle]\n";exit(1);
}
$action = $argv[1];if (!isset($actions[$action])) {
echo "Invalid argument \"$action\"\n\nUsage: iboot [query|on|off|cycle]\n";exit(1);
}
if ($fp = fsockopen($ip, $port, $errno, $errstr, 30)) {fwrite($fp, "\x1b" . $password . "\x1b" . $actions[$action] . "\r");stream_set_timeout($fp, 2);$resp = fread($fp, 5);$info = stream_get_meta_data($fp);fclose($fp);echo ($responses[substr($resp, 1, 1)] ?: "ERROR: " . $resp) . "\n";
} else {echo "ERROR: Unable to open connection to $ip:$port\n";exit(1);
}
DATAPROBE IBOOT
NODE.JS SCRIPT
# install$ npm install –g iboot
$ iboot [query|on|off|cycle] --host <ip or hostname> --port <port> --password <pass> [--timeout <ms>]
$ HOST=<ip or address> PORT=<port> PASSWORD=<pass> iboot [query|on|off|cycle]
https://www.npmjs.com/package/iboot
var iBoot = require('iboot');
var conn = new iBoot({
host: '192.168.1.123',
port: 80,
password: 'secret'
});
conn.query(function (err, status) {
console.info('iBoot currently ' + status);
console.info('Powering on...');
conn.on(function (err, status) {
console.info('iBoot currently ' + status);
console.info('Powering off in 2 seconds...');
setTimeout(function () {
conn.off(function (err, status) {
console.info('iBoot currently ' + status);
});
}, 2000);
});
});
CLI
API
3GSTORE REMOTE
POWER SWITCH
$69.99
http://3gstore.com/product/4186_single_outlet_remote_power_switch.html
3GSTORE REMOTE
POWER SWITCH
curl http://HOST/socket.cgi
curl http://HOST/invert.cgi
CURL
iPhone App
3GSTORE REMOTE
POWER SWITCH
2 outlet version
$99.99
http://3gstore.com/product/6081_2_outlet_ip_switch.html
BACKUP-TO-EXTERNAL
BACKUP-TO-EXTERNAL
• Read config
• Init log file
• Turn on external drive, wait
• Mount drive, wait
• rsync, pipe output to log file
• Unmount drive
• Turn off external drive
• Send e-mail w/ log file
https://github.com/cb1kenobi/backup-to-external
BACKUP-TO-EXTERNAL
SAMPLE E-MAIL
https://github.com/cb1kenobi/backup-to-external
Starting backup!
Touching /tmp/backing-up
ezoutlet is off, turning on
Mounting /dev/sdd1 to /venus...
Backing up /files to /venus/files...
sending incremental file list
Backups/raiden/data/archive/mysql-backups/
Backups/raiden/var/log/
Backups/raiden/var/log/syslog
sent 774,718,341 bytes received 252,238 bytes 1,606,156.64 bytes/sec
total size is 7,728,741,607,375 speedup is 9,972.95
rsync completed
Unmounting /venus...
Removing /tmp/backing-up
Touching /var/run/last-backup
Run time: 8 minutes and 48 seconds
Turning off ezoutlet
QUESTIONS?