Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
38765d2
Added cookieParser and cookieSession to express config. Added this co…
Apr 3, 2013
256e48a
Added hasSerial and userAuth functions to middleware. Added both to '…
Apr 3, 2013
943fa62
Added use of logger to route logging.
Apr 3, 2013
c2385ca
Removed unnecessary closure
Apr 3, 2013
362f64e
Added use of logger to route logging.
Apr 3, 2013
8494f5d
package.json: Bumped version. Updated dependencies. Removed unused sc…
Apr 3, 2013
0d2bc92
Added auth route, renders unauthorized screen.
Apr 3, 2013
26ce746
Added serial route, renders undetected serial screen.
Apr 3, 2013
14df655
Added auth view.
Apr 3, 2013
ecaef50
Added serial view.
Apr 3, 2013
68731d1
Added logger library.
Apr 3, 2013
da42bcc
Added modified credentials library.
Apr 3, 2013
d47dcad
index.js: Added logger and credentials. Removed closure. Added this c…
Apr 3, 2013
9765e72
Rename package to 'block-wifi' to match repo name.
timoxley Jun 20, 2013
ca54a65
Make index.js executable, add exec entries to package.json.
timoxley Jun 20, 2013
9ccf6b4
Fix typo
timoxley Jun 19, 2013
e71ee72
Make background transparent for embedding.
timoxley Jun 20, 2013
a649413
Kill monitor process if parent dies.
timoxley Jun 24, 2013
540d109
Fix borked package.json
timoxley Jun 24, 2013
e391343
Simplify random session key.
timoxley Jun 26, 2013
57932f4
Add error template.
timoxley Jun 26, 2013
d55a19d
Prefer explicit args over context via bind/call
timoxley Jun 26, 2013
38b6c6d
Boot monitor if platform OK
timoxley Jun 26, 2013
7826317
Upgrade express
timoxley Jun 26, 2013
f142876
Remove auth for now.
timoxley Jun 26, 2013
ec39f90
Add custom styles to serial page.
timoxley Jun 26, 2013
8756fa7
Queue messages until monitor is up.
timoxley Jul 3, 2013
1d7237f
Reorder stylesheets.
timoxley Jul 2, 2013
0f797c7
Only call config once.
timoxley Jul 3, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,60 @@ var
, express = require('express')
, route = require('./routes')
, events = require('events')
, crypto = require('crypto')
, util = require('util')
, path = require('path')
;

module.exports = function(app) {

var mids = middleware(app);


events.EventEmitter.call(app);
util.inherits(events.EventEmitter, app);

app.set('view engine', 'ejs');
app.set('views', path.resolve(__dirname, '..', 'views'));
app.use(express.static(path.resolve(__dirname, '..', 'public')));
app.use(express.static(path.resolve(__dirname, '..', 'public')));
app.use(express.methodOverride());

app.use(express.bodyParser());
app.use(express.favicon());
app.use(express.cookieParser(crypto.randomBytes(7).toString('base64')));
app.use(express.cookieSession());

app.use(function(req, res, next) {
var os = require('os')
if (os.platform() !== 'linux') {
var err = new Error('Wifi Setup is not implemented on this platform.')
return next(err)
}
app.emit('platformOK', true);
next()
})


/**
* We can log everything here
*/
app.all('*', function(req, res, next) {

// console.log(req.route);
// ^ too verbose, we'll log in each route.
next();

});

return route(app, mids);
};



route(app, middleware(this, app));
app.use(function(err, req, res, next) {
if (!err) return next();
console.error(err, err.stack)
res.status(500);
res.render('error', {
title: 'Sorry',
message: err.message
})
})

return app
};
40 changes: 37 additions & 3 deletions app/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var
, state
;

module.exports = function(app) {
module.exports = function(wifi, app) {

/**
* When device comes up, try to bring the
Expand Down Expand Up @@ -124,21 +124,55 @@ module.exports = function(app) {
}
next();
}
, hasSerial : function(req, res, next) {

if(!wifi.serial) {

return res.redirect('/serial');
}
next();
}
, userAuth : function(req, res, next) {

if((req.session) && req.session.block) { // session already checked

if(req.session.block == wifi.serial) {

wifi.log.debug("User has proper credentials in session");
return next();
}
wifi.log.info("User has invalid credential in session");
}
if((req.query) && req.query.block) { // check new session

if(req.query.block == wifi.serial) {

req.session.block = req.query.block;
wifi.log.info("User provided proper credentials");
return next();
}
wifi.log.info("User provided invalid credentials");
}
wifi.log.debug("Redirecting unauthed user to auth screen");
res.redirect('/auth');
}
};

/**
* Convenience wrappers
*/
mids.ready = [

mids.hasDevice
mids.hasSerial
, mids.hasDevice
, mids.hasIface
, mids.notCycling
];

mids.online = [

mids.hasDevice
mids.hasSerial
, mids.hasDevice
, mids.hasIface
, mids.isConnected
];
Expand Down
9 changes: 9 additions & 0 deletions app/routes/get-auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function(app) {

app.get('/auth', function(req, res, next) {

app.log.info("Rendering auth screen.");
res.render('auth');

});
};
2 changes: 1 addition & 1 deletion app/routes/get-connected.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

app.get('/connected', function(req, res, next) {

console.log("Rendering connected screen.");
app.log.info("Rendering connected screen.");
res.render('connected');
setTimeout(reset, 5000);
});
Expand Down
2 changes: 1 addition & 1 deletion app/routes/get-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

app.get('/', mids.ready, function(req, res, next) {

console.log("Rendering index screen.");
app.log.info("Rendering index screen.");
res.render("index");

});
Expand Down
2 changes: 1 addition & 1 deletion app/routes/get-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

app.get('/plugin', function(req, res, next) {

console.log("Rendering plugin screen.");
app.log.info("Rendering plugin screen.");
res.render("plugin");
});
};
Expand Down
9 changes: 9 additions & 0 deletions app/routes/get-serial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function(app) {

app.get('/serial', function(req, res, next) {

app.log.info("Rendering serial screen.");
res.render('serial');

});
};
43 changes: 20 additions & 23 deletions app/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
;(function() {

var
routes = {

connected : require('./get-connected')
, networks : require('./xhr-networks')
, connect : require('./post-connect')
, device : require('./xhr-device')
, status : require('./get-status')
, plugin : require('./get-plugin')
, index : require('./get-index')
}
, router = function(app, mids) {
var
routes = {

Object.keys(routes).forEach(function(route) {

module.exports[route] = routes[route](app, mids);
});
connected : require('./get-connected')
, networks : require('./xhr-networks')
, connect : require('./post-connect')
, device : require('./xhr-device')
, status : require('./get-status')
, plugin : require('./get-plugin')
, serial : require('./get-serial')
, index : require('./get-index')
}
, router = function(app, mids) {

return app;
}
;
Object.keys(routes).forEach(function(route) {

module.exports[route] = routes[route](app, mids);
});

module.exports = router;
return app;
}
;

})();
module.exports = router;
15 changes: 6 additions & 9 deletions app/routes/post-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

if(params.ssid && params.ssid.length > 0) { // non-broadcast

console.log("Client submitting non-broadcast network...");
app.log.info("Client submitting non-broadcast network...");
if(!params.security) {

return error(res, "Invalid parameters");
Expand All @@ -60,7 +60,7 @@

var record = cells[params.network] || undefined;

console.log("Client submitting pre-scanned network...");
app.log.info("Client submitting pre-scanned network...");
if(!record) { return error(res, "Network not found"); }

if(params.password && record.encryption) {
Expand All @@ -79,14 +79,11 @@

delete params.network;

console.log(
app.log.info(

util.format(

"Requesting wpa_supplicant config for %s (%s)."
, params.ssid || "Unknown Network"
, params.encType || "OPEN"
)
"Requesting wpa_supplicant config for %s (%s)."
, params.ssid || "Unknown Network"
, params.encType || "OPEN"
);
app.send("writeConfig", params);
res.json({ 'connected' : true });
Expand Down
2 changes: 1 addition & 1 deletion app/routes/xhr-networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
app.get('/networks', function(req, res, next) {

app.send('wifiScan', true);
console.log("Client requested network list...");
app.log.info("Client requested network list...");
console.log(cells);
setTimeout(function() {

Expand Down
Loading