2018-02-20 01:36:01 +00:00
|
|
|
var app = require('express')(),
|
|
|
|
session = require('express-session'),
|
|
|
|
http = require('http').Server(app),
|
|
|
|
request = require('request'),
|
|
|
|
exphbs = require('express-handlebars')
|
2018-02-19 22:59:28 +00:00
|
|
|
|
2018-02-19 23:44:10 +00:00
|
|
|
app.engine('.hbs', exphbs({defaultLayout: 'single', extname: '.hbs'}))
|
|
|
|
app.set('view engine', '.hbs')
|
2018-02-19 22:59:28 +00:00
|
|
|
|
2018-02-20 01:36:01 +00:00
|
|
|
// function checkAuth (req, res, next) {
|
|
|
|
// console.log(req.session);
|
|
|
|
|
|
|
|
// console.log('checkAuth ' + req.url);
|
|
|
|
|
|
|
|
// // don't serve /secure to those not logged in
|
|
|
|
// // you should add to this list, for each and every secure url
|
|
|
|
// // if (req.url === '/' && (!req.session || !req.session.authenticated)) {
|
|
|
|
// // res.render('unauthorised', { status: 403 });
|
|
|
|
// // return;
|
|
|
|
// // }
|
|
|
|
// next()
|
|
|
|
// }
|
|
|
|
|
|
|
|
app.use(session({ secret: 'example' }))
|
|
|
|
// app.use(checkAuth)
|
|
|
|
|
|
|
|
|
2018-02-19 23:44:10 +00:00
|
|
|
var url = 'http://192.168.178.109:1024/'
|
2018-02-19 22:59:28 +00:00
|
|
|
|
|
|
|
// Host the HTML File
|
|
|
|
app.get('/', function(req, res){
|
2018-02-20 01:36:01 +00:00
|
|
|
if(!req.session.name){
|
|
|
|
res.render('login')
|
|
|
|
return
|
|
|
|
}
|
2018-02-19 22:59:28 +00:00
|
|
|
request({
|
|
|
|
url: url,
|
|
|
|
json: true,
|
|
|
|
auth: {
|
|
|
|
user: 'Simon',
|
|
|
|
pass: 'password'
|
|
|
|
}
|
|
|
|
}, function(error, response, body){
|
2018-02-19 23:44:10 +00:00
|
|
|
var data = []
|
2018-02-19 22:59:28 +00:00
|
|
|
if (!error && response.statusCode === 200) {
|
|
|
|
body.response.bot.accounts.forEach(el => {
|
2018-02-20 00:33:22 +00:00
|
|
|
var tmp = el[Object.keys(el)]
|
|
|
|
tmp.logs = ""
|
|
|
|
tmp.settings = ""
|
2018-02-20 00:46:19 +00:00
|
|
|
tmp.exp_percentage = tmp.experience/tmp.experienceForNextLevel
|
2018-02-20 00:33:22 +00:00
|
|
|
data.push(tmp)
|
2018-02-19 22:59:28 +00:00
|
|
|
});
|
|
|
|
|
2018-02-20 00:07:10 +00:00
|
|
|
res.render('index', {
|
2018-02-20 00:33:22 +00:00
|
|
|
instances: data
|
2018-02-20 00:07:10 +00:00
|
|
|
})
|
2018-02-19 23:44:10 +00:00
|
|
|
} else console.error('HTTP ERROR ' + response.statusCode + '')
|
2018-02-19 22:59:28 +00:00
|
|
|
});
|
|
|
|
})
|
2018-02-19 23:44:10 +00:00
|
|
|
|
|
|
|
app.get('/assets/*', function(req, res){
|
|
|
|
res.sendFile(__dirname + req.originalUrl)
|
|
|
|
})
|
|
|
|
|
2018-02-20 01:36:01 +00:00
|
|
|
app.post('/',function(req,res){
|
|
|
|
console.log(req);
|
|
|
|
|
|
|
|
if(req.body.name === 'Admin' && req.body.pass === '1234'){
|
|
|
|
req.session.name = req.body.name
|
|
|
|
res.end('success')
|
|
|
|
} else {
|
|
|
|
res.end('denied')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-02-19 23:49:09 +00:00
|
|
|
app.listen(8080)
|