Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nrn/Smallest-Federated-Wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
nrn committed Jan 13, 2012
2 parents c2c8cd6 + dfb8d2a commit c9ac0cf
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 33 deletions.
4 changes: 1 addition & 3 deletions server/Wikiduino/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ along with an FDDI USB to serial converter for device programming and software d
from a custom made for purpose development environment. The Wikiduino configuration
adds to this an Ethernet adapter daughter card (called a shield) and a variety of sensors.

The source code for Wikiduino exists in a single file which can be copied and pasted into the Arduino IDE. We host two files that vary depending on which version of IDE and libraries one is
using. These are:
The source code for Wikiduino exists in a single file which can be copied and pasted into the Arduino IDE or cloned directly from GitHub:

* Wikiduino.pde for use with Arduino beta version 22
* Wikiduino.ino for use with release 1.0 or later

System Operation
Expand Down
9 changes: 2 additions & 7 deletions server/express/bin/server
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ argv = optimist
)
.options('u',
alias : 'url'
default : 'http://localhost:3000'
default : ''
describe : 'Url to be used for the realm in openID'
)
.options('p',
Expand All @@ -45,12 +45,7 @@ argv = optimist
if argv.h
optimist.showHelp()
process.exit()
if not argv.d
argv.d = path.relative("#{__dirname}", "#{argv.r}/data")
if not argv.c
argv.c = path.relative("#{__dirname}", "#{argv.r}/client")
argv.db = path.resolve(path.join(argv.d, 'pages'))
argv.status = path.resolve(path.join(argv.d, 'status'))
argv = require('../lib/defaultargs')(argv)

# Create an instance of server using command line arguments and defaults.
server(argv)
13 changes: 13 additions & 0 deletions server/express/lib/defaultargs.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# defaultargs.coffee
path = require 'path'

module.exports = (argv) ->
argv.o or= ''
argv.p or= 3000
argv.r or= path.join("#{__dirname}", '..', '..', '..')
argv.d or= path.relative("#{__dirname}", "#{argv.r}/data")
argv.c or= path.relative("#{__dirname}", "#{argv.r}/client")
argv.db or= path.resolve(path.join(argv.d, 'pages'))
argv.status = path.resolve(path.join(argv.d, 'status'))
argv.u or= 'http://localhost' + (':' + argv.p) unless argv.p is 80
argv
14 changes: 10 additions & 4 deletions server/express/lib/page.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ blank_page = (loc, cb) ->

# Exported functions

itself.get = (loc, cb) ->
path.exists(loc, (exists) ->
itself.setup = (opts) ->
@argv = opts


itself.get = (file, cb) ->
loc = path.join(@argv.db, file)
path.exists(loc, (exists) =>
if exists
load_parse(loc, cb)
else
defloc = path.join(path.dirname(loc), '..', '..', '..', 'default-data', 'pages', path.basename(loc))
defloc = path.join(@argv.r, 'default-data', 'pages', file)
path.exists(defloc, (exists) ->
if exists
load_parse_copy(defloc, loc, cb)
Expand All @@ -54,7 +59,8 @@ itself.get = (loc, cb) ->
)


itself.put = (loc, page, cb) ->
itself.put = (file, page, cb) ->
loc = path.join(@argv.db, file)
page = JSON.stringify(page)
path.exists(path.dirname(loc), (exists) ->
if exists
Expand Down
47 changes: 28 additions & 19 deletions server/express/lib/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ fs = require('fs')
path = require('path')
http = require('http')
hbs = require('hbs')
_ = require('../../../client/js/underscore-min.js')
pagehandler = require('./page.coffee')
_ = require('../../../client/js/underscore-min.js')
favicon = require('./favicon.coffee')
passport = require('passport')
OpenIDstrat = require('passport-openid').Strategy
Expand All @@ -20,6 +20,9 @@ module.exports = (argv) ->
###

# Helper functions
argv = require('./defaultargs')(argv)
pagehandler.setup(argv)

owner = ''

setOwner = (id) ->
Expand All @@ -40,8 +43,8 @@ module.exports = (argv) ->
setOwner()

authenticated = (req, res, next) ->
console.log owner
console.log req.user?.id
console.log(owner) if argv.debug
console.log(req.user?.id) if argv.debug
if req.isAuthenticated() and req.user.id is owner
next()
else res.send('Access forbidden', 403)
Expand All @@ -63,13 +66,15 @@ module.exports = (argv) ->
identifierField: 'identifier'
},
((id, done) ->
console.log id, done
console.log(id, done) if argv.debug
process.nextTick( ->
unless owner
setOwner(id)
else if id isnt owner
done(null, false)
if owner
if id is owner
done(null, {id})
else
done(null, false)
else
setOwner(id)
done(null, {id})
)
)))
Expand Down Expand Up @@ -111,10 +116,14 @@ module.exports = (argv) ->
)

app.redirect('remotefav', (req, res) ->
console.log req.params
"http://#{req.params[0]}"
)

app.redirect('notyourwiki', (req, res) ->
'/notyourwiki'
)


# Get routes


Expand All @@ -124,22 +133,20 @@ module.exports = (argv) ->
port: 80
path: "/#{req.params[1]}.json"
}
console.log getopts
http.get(getopts, (resp) ->
responsedata = ''
resp.on('data', (chunk) ->
responsedata += chunk
)
resp.on('end', ->
console.log responsedata
res.json(JSON.parse(responsedata))
)
)
)

app.get('*.json', (req, res) ->
file = req.params[0]
pagehandler.get(path.join(argv.db, file), (page) =>
pagehandler.get(file, (page) =>
res.json(page)
)
)
Expand All @@ -152,7 +159,6 @@ module.exports = (argv) ->
#res.sendfile("#{argv.r}/server/sinatra/views/static.html")
urlPages = (i for i in req.params[0].split('/') by 2)[1..]
urlLocs = (j for j in req.params[0].split('/')[1..] by 2)
console.log owner
info = {
pages: []
authenticated: req.isAuthenticated()
Expand Down Expand Up @@ -207,7 +213,7 @@ module.exports = (argv) ->
when 'move'
page.story = _(action.order).map((i) ->
_(page.story).find( (story) ->
console.log i, story
console.log(i, story) if argv.debug
i is story.id
)
)
Expand Down Expand Up @@ -236,7 +242,7 @@ module.exports = (argv) ->
if not page.journal
page.journal = []
page.journal.push(action)
pagehandler.put(path.join(argv.db, req.params[0]), page, (err) =>
pagehandler.put(req.params[0], page, (err) =>
if err then throw err
res.send('ok')
console.log 'saved' if argv.debug
Expand All @@ -255,18 +261,17 @@ module.exports = (argv) ->
responsedata += chunk
)
resp.on('end', ->
console.log responsedata
actionCB(JSON.parse(responsedata))
)
)
else
pagehandler.get(path.join(argv.db, req.params[0]), actionCB)
pagehandler.get(req.params[0], actionCB)
)

# Routes used for openID authentication

app.post('/login',
passport.authenticate('openid', { failureRedirect: 'index'}),
passport.authenticate('openid', { failureRedirect: 'notyourwiki'}),
(req, res) ->
res.redirect('index')
)
Expand All @@ -282,11 +287,15 @@ module.exports = (argv) ->
)

app.get('/login/openid/complete',
passport.authenticate('openid', { failureRedirect: 'index'}),
passport.authenticate('openid', { failureRedirect: 'notyourwiki'}),
(req, res) ->
res.redirect('index')
)

app.get('/notyourwiki', (req, res) ->
res.send('This is not your wiki!', 403)
)

app.get('/', (req, res) ->
res.redirect('index')
)
Expand Down

0 comments on commit c9ac0cf

Please sign in to comment.