Added Codelines from the Shell

This commit is contained in:
Tim Windelschmidt 2015-10-07 12:23:39 +02:00
parent 8e041efb86
commit 14f0af92e3
2 changed files with 5 additions and 2 deletions

3
node/routes/index.js Normal file → Executable file
View File

@ -14,9 +14,11 @@ exports.form = function (req, res) {
action = req.body.action; action = req.body.action;
var status = ""; var status = "";
mac = mac.toLowerCase(); mac = mac.toLowerCase();
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
if (/^([0-9a-f]{2}[:-]){5}([0-9a-f]{2})$/.exec(mac)) { if (/^([0-9a-f]{2}[:-]){5}([0-9a-f]{2})$/.exec(mac)) {
if (action == "add") { if (action == "add") {
console.log("add mac request mac: "+mac + " label " + label + " ip: " + ip);
if (/^[0-9a-zA-Z]+$/.exec(label)) { if (/^[0-9a-zA-Z]+$/.exec(label)) {
snmpMac.add(mac, label, function (err) { snmpMac.add(mac, label, function (err) {
console.log("add mac result: " + err); console.log("add mac result: " + err);
@ -28,6 +30,7 @@ exports.form = function (req, res) {
res.redirect("/db"); res.redirect("/db");
} }
} else if (action == "remove") { } else if (action == "remove") {
console.log("remove mac request mac: "+mac + " label " + label + " ip: " + ip);
snmpMac.delete(mac, function (err) { snmpMac.delete(mac, function (err) {
console.log("delete mac result: " + err); console.log("delete mac result: " + err);
req.flash('status', err == null ? "" : "database error: " + err); req.flash('status', err == null ? "" : "database error: " + err);

2
node/statusbot.js Normal file → Executable file
View File

@ -115,7 +115,7 @@ app.use(express.bodyParser());
app.use(express.cookieParser('chaostreff')); app.use(express.cookieParser('chaostreff'));
app.use(express.session({cookie: {maxAge: 60000}})); app.use(express.session({cookie: {maxAge: 60000}}));
app.use(flash()); app.use(flash());
app.enable('trust proxy');
app.get('/api/spaceapi/v13', function (req, res) { app.get('/api/spaceapi/v13', function (req, res) {
res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Origin", "*");