4
1
Fork 0
This repository has been archived on 2019-02-05. You can view files and clone it, but cannot push or open issues or pull requests.
Shakes_and_Fidget/index.js
2018-02-20 17:56:28 +01:00

68 lines
1.8 KiB
JavaScript

var app = require('express')(),
session = require('express-session'),
http = require('http').Server(app),
bodyParser = require('body-parser'),
request = require('request'),
exphbs = require('express-handlebars')
app.engine('.hbs', exphbs({defaultLayout: 'single', extname: '.hbs'}))
app.set('view engine', '.hbs')
app.use(session({ resave: true, saveUninitialized: false, secret: '62gzrhufijw' }))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
var url = 'http://192.168.178.109:1024/'
// Host the HTML File
app.get('/', function(req, res){
if(!req.session.name){
res.render('login')
return
}
request({
url: url,
json: true,
auth: {
user: req.session.name,
pass: req.session.pass
}
}, function(error, response, body){
var data = []
if (!error && response.statusCode === 200) {
body.response.bot.accounts.forEach(el => {
var tmp = el[Object.keys(el)]
tmp.logs = ""
tmp.settings = ""
tmp.exp_percentage = tmp.experience/tmp.experienceForNextLevel
data.push(tmp)
});
res.render('index', {
instances: data
})
} else console.error('HTTP ERROR ' + response.statusCode + '')
});
})
app.get('/assets/*', function(req, res){
res.sendFile(__dirname + req.originalUrl)
})
app.post('/',function(req,res){
if(
req.body.name === 'Simon' && req.body.pass === 'password' ||
req.body.name === 'Suxxi' && req.body.pass === 'GSGSpandau'
){
req.session.name = req.body.name
req.session.pass = req.body.pass
res.end('true')
} else {
res.end()
}
})
app.listen(8080)