This commit is contained in:
2019-06-07 23:04:57 +08:00
commit 36b92f19e0
67 changed files with 18266 additions and 0 deletions

30
src/websocket/index.js Normal file
View File

@ -0,0 +1,30 @@
import container from './container'
import git from './git'
import log from './log'
import JsSHA from 'jssha'
import {
SYSTEM
} from '../config'
export default (io, docker) => {
console.log('Websocket Runing...')
io.on('connection', function (socket) {
console.log('One user connected - ' + socket.id)
socket.emit('requireAuth', 'distribution')
socket.emit('opend', new Date())
socket.on('auth', function (token) {
const shaObj = new JsSHA('SHA-512', 'TEXT')
shaObj.update(SYSTEM.TOKEN)
const hash = shaObj.getHash('HEX')
if (token === hash) {
container(io, socket, docker)
git(io, socket, docker)
log(io, socket, docker)
socket.emit('auth', 'success')
} else {
socket.emit('auth', 'fail')
}
})
})
}