var _u = require("underscore"); var express = require('express'), app = express(), server = require('http').createServer(app), io = require('socket.io').listen(server); var flash = require('connect-flash'); var SnmpMac = require("./snmp-mac"); var IpPoll = require("./ip-poll"); var routes = require("./routes"); var spaceanswer = { "api": "0.13", "space": "Chaostreff Dortmund", "logo": "http://www.chaostreff-dortmund.de/logo.jpg", "url": "http://www.chaostreff-dortmund.de/", "location": { "address": "Braunschweiger Str 22, 44145 Dortmund, Germany", "lon": 7.4649449, "lat": 51.527611 }, "contact": { "phone": "+49231 8 404 777", "irc": "irc://irc.hackint.eu/#ctdo", "ml": "ccc@chaostreff-dortmund.de", "twitter": "@ctdo", "issue_mail": "server-admin@chaostreff-dortmund.de" }, "issue_report_channels": [ "issue_email" ], "state": { "open": null, "lastchange": 0 } }; var simpleanswer = { "state": "unknown", "count": 0, "names": [], "lastchange": 0 }; var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23"); var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.20-62 195.160.169.70-126"); snmpMac.on('done', function (res) { // console.log(res); simpleanswer.names = res; simpleanswer.lastchange = parseInt((new Date().getTime()) / 1000); }); ippoll.on('doneCount', function (num) { // console.log("there are " + num + " hosts up"); simpleanswer.count = num; simpleanswer.lastchange = parseInt((new Date().getTime()) / 1000); io.sockets.emit('sdata', { "data": simpleanswer }); }); ippoll.on('doneState', function (state) { // console.log("room state is: " + state); simpleanswer.state = state; spaceanswer.state.open = state; spaceanswer.state.lastchange = parseInt((new Date().getTime()) / 1000); simpleanswer.lastchange = spaceanswer.state.lastchange; io.sockets.emit('sdata', { "data": simpleanswer }); }); io.configure(function () { io.set('log level', 0); }); io.sockets.on('connection', function (socket) { // socket.emit('news', { hello: 'world' }); }); function work() { snmpMac.poll(); ippoll.pollCount(); ippoll.pollState(); } setInterval(work, 60000); work(); app.set('snmpMac', snmpMac); //TODO: wie kann man das schoener machen? (Modul in die Routes reintun) app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.disable('x-powered-by'); app.configure('development', function () { app.use(express.errorHandler()); app.locals.pretty = true; }); app.use(express.static(__dirname + '/public')); app.use(express.bodyParser()); app.use(express.cookieParser('chaostreff')); app.use(express.session({ cookie: { maxAge: 60000 }})); app.use(flash()); app.get('/api/spaceapi/v13', function (req, res) { res.send(spaceanswer); }); app.get('/api/simple/v2', function (req, res) { res.send(simpleanswer); }); app.get('/db', routes.db); app.post('/form', routes.form); app.get('/', routes.index); server.listen(3000, 'localhost');