Fixed the UTF8 and Space error

This commit is contained in:
Tim Windelschmidt 2016-09-27 21:11:28 +02:00
parent 7bed7ba82f
commit d39cbaa25b
2 changed files with 11 additions and 9 deletions

View File

@ -17,19 +17,21 @@ exports.form = function (req, res) {
if (/^([0-9a-f]{2}[:-]){5}([0-9a-f]{2})$/.exec(mac)) {
if (action == "add") {
console.log("add mac request mac: "+mac + " label " + label + " ip: " + ip);
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");
});
if (label) {
if(label.split('').length > 1) {
console.log("add mac request mac: " +mac + " label " + label + " ip: " + ip);
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") {
console.log("remove mac request mac: "+mac + " label " + label + " ip: " + ip);
console.log("remove mac request mac: "+mac + " label " + '"' + label + '"' + " ip: " + ip);
snmpMac.delete(mac, function (err) {
console.log("delete mac result: " + err);
req.flash('status', err == null ? "" : "database error: " + err);

View File

@ -109,7 +109,7 @@ app.use(express.static('public'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ extended: true }));
app.use(cookieSession({secret: 'steam-stalker', cookie: {maxAge: 60000}}));
app.use(cookieSession({secret: 'ctdo', cookie: {maxAge: 60000}}));
app.use(flash());
app.set('/views');