2013-10-20 22:04:58 +00:00
|
|
|
|
|
|
|
exports.index = function (req, res) {
|
2014-07-23 00:45:57 +00:00
|
|
|
res.render('index', { title: 'Home' })
|
2013-10-20 22:04:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.db = function (req, res) {
|
2014-07-23 00:45:57 +00:00
|
|
|
res.render('database', { title: 'Manage MAC' })
|
2013-10-20 22:04:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.form = function (req, res) {
|
|
|
|
var snmpMac = req.app.get('snmpMac'); //TODO: wie kann man das schoener machen?
|
|
|
|
var mac = req.body.mac,
|
|
|
|
label = req.body.label,
|
|
|
|
action = req.body.action;
|
|
|
|
var status = "";
|
|
|
|
mac = mac.toLowerCase();
|
|
|
|
|
|
|
|
if (/^([0-9a-f]{2}[:-]){5}([0-9a-f]{2})$/.exec(mac)) {
|
|
|
|
if (action == "add") {
|
|
|
|
if (/^[0-9a-zA-Z]+$/.exec(label)) {
|
|
|
|
snmpMac.add(mac, label, function (err) {
|
|
|
|
console.log("add mac result: " + err);
|
|
|
|
req.flash('status', err == null ? "" : "database error: " + err);
|
|
|
|
res.redirect("/db");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
req.flash('status', 'label is invalid ("^[0-9a-zA-Z]+$")');
|
|
|
|
res.redirect("/db");
|
|
|
|
}
|
|
|
|
} else if (action == "remove") {
|
|
|
|
snmpMac.delete(mac, function (err) {
|
|
|
|
console.log("delete mac result: " + err);
|
|
|
|
req.flash('status', err == null ? "" : "database error: " + err);
|
|
|
|
res.redirect("/db");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.redirect("/db");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
req.flash('status', 'mac address is invalid');
|
|
|
|
res.redirect("/db");
|
|
|
|
}
|
|
|
|
};
|