This repository has been archived by the owner on Aug 11, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pirateship wifi <ESSID> [password] added
- Loading branch information
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var sys = require('sys') | ||
var exec = require('child_process').exec; | ||
var program = require('commander'); | ||
var fs = require('fs') | ||
function puts(error, stdout, stderr) { sys.puts(stdout) } | ||
|
||
function ifdownup(error, stdout, stderr) { | ||
exec('ifdown wlan0', function(error, stdout, stderr) { | ||
if (error !== null) { | ||
console.log('exec error: ' + error); | ||
} | ||
exec('ifup wlan0', function(error, stdout, stderr) { | ||
if (error !== null) { | ||
console.log('exec error: ' + error); | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
|
||
// Set settings.hostname in /etc/hosts and etc/hostname | ||
module.exports = function(ESSID, password) { | ||
if (password === null) { | ||
var fileName = __dirname + '/interfaces.none.template' | ||
fs.readFile(fileName, 'utf8', function (err,data) { | ||
if (err) return console.log(err) | ||
var result = data.replace("WIRELESSSSID", wirelessSSID) | ||
var fileName = '/etc/network/interfaces' | ||
fs.writeFile(fileName, result, 'utf8', function (err) { | ||
if (err) return console.log(err) | ||
ifdownup() | ||
return console.log('success') | ||
}) | ||
}) | ||
} else { | ||
console.log('RECONFIGURING WPA') | ||
var fileName = __dirname + '/interfaces.wpa.template' | ||
fs.readFile(fileName, 'utf8', function (err,data) { | ||
if (err) return console.log(err) | ||
var fileName = '/etc/network/interfaces' | ||
fs.writeFile(fileName, data, 'utf8', function (err) { | ||
if (err) return console.log(err) | ||
fs.readFile(__dirname + '/wpa_supplicant.conf.template', function(err, data) { | ||
if (err) return console.log(err) | ||
$wpa_supplicant_conf = data | ||
var cmd = 'wpa_passphrase "' + wirelessSSID + '" "' + password + '"' | ||
exec(cmd, function(err, stdout, stderr) { | ||
if (err) return console.log(err) | ||
$wpa_supplicant_conf = $wpa_supplicant_conf + stdout | ||
fs.writeFile('/etc/wpa_supplicant/wpa_supplicant.conf', $wpa_supplicant_conf, function(err) { | ||
if (err) return console.log(err) | ||
ifdownup() | ||
return console.log() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
} |
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