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

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-02-20 01:36:01 +00:00
var app = require('express')(),
session = require('express-session'),
http = require('http').Server(app),
2018-02-20 01:50:03 +00:00
bodyParser = require('body-parser'),
2018-02-20 01:36:01 +00:00
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
2018-02-20 01:50:03 +00:00
app.use(session({ resave: true, saveUninitialized: false, secret: '62gzrhufijw' }))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
2018-02-20 01:36:01 +00:00
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: {
2018-02-20 01:50:03 +00:00
user: req.session.name,
pass: req.session.pass
2018-02-19 22:59:28 +00:00
}
}, 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 16:56:28 +00:00
2018-02-20 01:36:01 +00:00
app.post('/',function(req,res){
2018-02-20 01:50:03 +00:00
if(
req.body.name === 'Simon' && req.body.pass === 'password' ||
2018-03-06 17:46:31 +00:00
req.body.name === 'Alpha' && req.body.pass === 'passwordfisch'
2018-02-20 01:50:03 +00:00
){
2018-02-20 01:36:01 +00:00
req.session.name = req.body.name
2018-02-20 01:50:03 +00:00
req.session.pass = req.body.pass
res.end('true')
2018-02-20 01:36:01 +00:00
} else {
2018-02-20 01:50:03 +00:00
res.end()
2018-02-20 01:36:01 +00:00
}
2018-02-20 01:50:03 +00:00
})
2018-02-20 01:36:01 +00:00
2018-02-19 23:49:09 +00:00
app.listen(8080)