Showing
9 changed files
with
137 additions
and
7 deletions
... | @@ -24,7 +24,7 @@ var LocalStrategy = require('passport-local').Strategy | ... | @@ -24,7 +24,7 @@ var LocalStrategy = require('passport-local').Strategy |
24 | var session = require('express-session') | 24 | var session = require('express-session') |
25 | var flash = require('connect-flash') | 25 | var flash = require('connect-flash') |
26 | var path = require('path') | 26 | var path = require('path') |
27 | -const PORT = 5560 | 27 | +const PORT = 3000 |
28 | 28 | ||
29 | var jsdom = require('jsdom'); | 29 | var jsdom = require('jsdom'); |
30 | const { JSDOM } = jsdom; | 30 | const { JSDOM } = jsdom; |
... | @@ -42,6 +42,7 @@ app.use("/css", express.static(__dirname + "/css")); | ... | @@ -42,6 +42,7 @@ app.use("/css", express.static(__dirname + "/css")); |
42 | app.use("/assets", express.static(__dirname + "/assets")); | 42 | app.use("/assets", express.static(__dirname + "/assets")); |
43 | app.use("/js", express.static(__dirname + "/js")); | 43 | app.use("/js", express.static(__dirname + "/js")); |
44 | app.use("/chat", express.static(__dirname+ "/chat")); | 44 | app.use("/chat", express.static(__dirname+ "/chat")); |
45 | +app.use("/command", express.static(__dirname+ "/command")); | ||
45 | app.use("/node_modules", express.static(path.join(__dirname+ "/node_modules"))); | 46 | app.use("/node_modules", express.static(path.join(__dirname+ "/node_modules"))); |
46 | app.set('view engine', 'ejs') | 47 | app.set('view engine', 'ejs') |
47 | 48 | ||
... | @@ -83,6 +84,10 @@ app.use(flash()) | ... | @@ -83,6 +84,10 @@ app.use(flash()) |
83 | app.use(router) // router 정의 | 84 | app.use(router) // router 정의 |
84 | 85 | ||
85 | // Socket.io | 86 | // Socket.io |
87 | + | ||
88 | + | ||
89 | +var chatnamespace = io.of('/chatnamespace') | ||
90 | + | ||
86 | io.sockets.on('connection', function(socket) { | 91 | io.sockets.on('connection', function(socket) { |
87 | var ip = socket.handshake.address; | 92 | var ip = socket.handshake.address; |
88 | 93 | ... | ... |
js/command.js
0 → 100644
1 | +var mysql_odbc = require('../../db/db_board')(); | ||
2 | +var myinfo = mysql_odbc.init(); | ||
3 | + | ||
4 | +function inpu() { | ||
5 | + // 입력되어있는 데이터 가져오기 | ||
6 | + var command = document.getElementById('command').value | ||
7 | + console.log(command) | ||
8 | + | ||
9 | + // 공백이 아닐때 | ||
10 | + if(!(command.replace(/\s| /gi, "").length == 0)){ | ||
11 | + // 가져왔으니 데이터 빈칸으로 변경 | ||
12 | + document.getElementById('command').value = 'dd' | ||
13 | + | ||
14 | + // 내가 전송할 메시지 클라이언트에게 표시 | ||
15 | + var chat = document.getElementById('console') | ||
16 | + var msg = document.createElement('div') | ||
17 | + var node = document.createTextNode(command) | ||
18 | + msg.classList.add('commandline') | ||
19 | + msg.appendChild(node) | ||
20 | + chat.appendChild(msg) | ||
21 | + | ||
22 | + var command_list = command.split(" ") | ||
23 | + | ||
24 | + if(command_list[0] = "/type"){ | ||
25 | + var target = command_list[1] | ||
26 | + var willbe = command_list[2] | ||
27 | + | ||
28 | + var datas = [willbe, target] | ||
29 | + | ||
30 | + var sql = "update userdb set type=? where nickname =?" | ||
31 | + myinfo.query(sql,datas,function(err,result){ | ||
32 | + if(err) console.error(err); | ||
33 | + console.log('유저의 type을 수정했습니다.') | ||
34 | + }) | ||
35 | + } | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + function a(){ | ||
40 | + var element = document.getElementById('command'); | ||
41 | + element.scrollTop = element.scrollHeight - element.clientHeight; | ||
42 | + } | ||
43 | + a(); | ||
44 | + | ||
45 | +} | ||
46 | + | ||
47 | +function enterkey() { | ||
48 | + if (window.event.keyCode == 13) { | ||
49 | + // 엔터키가 눌렸을 때 실행할 내용 | ||
50 | + inpu(); | ||
51 | + } | ||
52 | + } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
router/command/command.js
0 → 100644
1 | +var express = require('express') | ||
2 | +var app = express() | ||
3 | +var router = express.Router(); | ||
4 | +var path = require('path') // 상대경로 | ||
5 | +var mysql_odbc = require('../../db/db_board')(); | ||
6 | +var myinfo = mysql_odbc.init(); | ||
7 | +var requestIp = require('request-ip'); | ||
8 | + | ||
9 | +// 로그용 | ||
10 | +var logString; | ||
11 | +function getTime(){ | ||
12 | + var today = new Date(); | ||
13 | + var year = today.getFullYear(); | ||
14 | + var month = ('0' + (today.getMonth()+1)).slice(-2); | ||
15 | + var day = ('0' + today.getDate()).slice(-2); | ||
16 | + var hour = ('0' + today.getHours()).slice(-2); | ||
17 | + var minute = ('0' + today.getMinutes()).slice(-2); | ||
18 | + var second = ('0' + today.getSeconds()).slice(-2); | ||
19 | + logString = '['+year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second+'] '; | ||
20 | +} | ||
21 | +// 시간 갱신용 | ||
22 | +function init(){ | ||
23 | + getTime(); | ||
24 | + setInterval(getTime, 1000) | ||
25 | +} | ||
26 | +init() | ||
27 | + | ||
28 | +router.get('/', function(req, res){ | ||
29 | + var ip = requestIp.getClientIp(req); | ||
30 | + var id = req.user; | ||
31 | + var type = req.user.type; | ||
32 | + console.log(id) | ||
33 | + if(type != '운영자'){ | ||
34 | + console.log(logString+'익명 유저의 커맨드 접근을 거부했습니다.('+ip+')') | ||
35 | + res.sendFile(path.join(__dirname, "../../public/main.html")) | ||
36 | + }else{ | ||
37 | + var nickname = req.user.nickname | ||
38 | + console.log(logString+req.user.ID+'('+nickname+') 관리자가 커맨드콘솔에 접근했습니다.('+ip+')') | ||
39 | + res.render('command.ejs', {'id': id, 'nickname':nickname, 'type': type}) | ||
40 | + } | ||
41 | +}); | ||
42 | + | ||
43 | +module.exports = router; |
... | @@ -12,6 +12,7 @@ var board = require('./board/index') | ... | @@ -12,6 +12,7 @@ var board = require('./board/index') |
12 | var profile = require('./profile/index') | 12 | var profile = require('./profile/index') |
13 | var about = require('./about/index') | 13 | var about = require('./about/index') |
14 | var chat = require('./chat/chat') | 14 | var chat = require('./chat/chat') |
15 | +var command = require('./command/command') | ||
15 | 16 | ||
16 | // 로그용 | 17 | // 로그용 |
17 | var logString; | 18 | var logString; |
... | @@ -62,5 +63,6 @@ router.use('/board', board) | ... | @@ -62,5 +63,6 @@ router.use('/board', board) |
62 | router.use('/profile', profile) | 63 | router.use('/profile', profile) |
63 | router.use('/about', about) | 64 | router.use('/about', about) |
64 | router.use('/chat', chat) | 65 | router.use('/chat', chat) |
66 | +router.use('/command', command) | ||
65 | 67 | ||
66 | module.exports = router; | 68 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -49,11 +49,13 @@ passport.serializeUser(function(user, done){ | ... | @@ -49,11 +49,13 @@ passport.serializeUser(function(user, done){ |
49 | console.log(logString+'passport session save: '+ user.ID + '(' + user.nickname + ')') | 49 | console.log(logString+'passport session save: '+ user.ID + '(' + user.nickname + ')') |
50 | done(null, user) | 50 | done(null, user) |
51 | }); | 51 | }); |
52 | + | ||
52 | passport.deserializeUser(function(user, done){ | 53 | passport.deserializeUser(function(user, done){ |
53 | var ID = user.ID; | 54 | var ID = user.ID; |
54 | var nickname = user.nickname; | 55 | var nickname = user.nickname; |
56 | + var type = user.type; | ||
55 | // console.log('passport session get ID: '+ ID + '(' + nickname + ')') | 57 | // console.log('passport session get ID: '+ ID + '(' + nickname + ')') |
56 | - done(null, {'ID': ID, 'nickname':nickname}); // 세션에서 값을 뽑아서 페이지에 전달하는 역할 | 58 | + done(null, {'ID': ID, 'nickname':nickname, 'type': type}); // 세션에서 값을 뽑아서 페이지에 전달하는 역할 |
57 | }) | 59 | }) |
58 | 60 | ||
59 | passport.use('local-login', new LocalStrategy({ | 61 | passport.use('local-login', new LocalStrategy({ |
... | @@ -68,7 +70,7 @@ passport.use('local-login', new LocalStrategy({ | ... | @@ -68,7 +70,7 @@ passport.use('local-login', new LocalStrategy({ |
68 | if(rows.length){ // database에 입력한 ID값이 있는가? | 70 | if(rows.length){ // database에 입력한 ID값이 있는가? |
69 | if(password == rows[0].password){ // 비밀번호와 확인이 같은가? | 71 | if(password == rows[0].password){ // 비밀번호와 확인이 같은가? |
70 | console.log(logString+"로그인 알림: "+ ID +"(" + rows[0].nickname +" // "+ip+')') | 72 | console.log(logString+"로그인 알림: "+ ID +"(" + rows[0].nickname +" // "+ip+')') |
71 | - return done(null, {'ID' : ID, 'nickname' : rows[0].nickname}); | 73 | + return done(null, {'ID' : ID, 'nickname' : rows[0].nickname, 'type': rows[0].type}); |
72 | } | 74 | } |
73 | else{ | 75 | else{ |
74 | console.log(logString+"로그인 알림: 잘못된 비밀번호입니다.(시도된 아이디: "+ID+" // "+ip+')') | 76 | console.log(logString+"로그인 알림: 잘못된 비밀번호입니다.(시도된 아이디: "+ID+" // "+ip+')') | ... | ... |
... | @@ -48,7 +48,7 @@ passport.deserializeUser(function(user, done){ | ... | @@ -48,7 +48,7 @@ passport.deserializeUser(function(user, done){ |
48 | var ID = user.ID; | 48 | var ID = user.ID; |
49 | var nickname = user.nickname; | 49 | var nickname = user.nickname; |
50 | // console.log('passport session get ID: '+ ID + '(' + nickname + ')') | 50 | // console.log('passport session get ID: '+ ID + '(' + nickname + ')') |
51 | - done(null, {'ID': ID, 'nickname':nickname}); // 세션에서 값을 뽑아서 페이지에 전달하는 역할 | 51 | + done(null, {'ID': ID, 'nickname':nickname, 'type': type}); // 세션에서 값을 뽑아서 페이지에 전달하는 역할 |
52 | }) | 52 | }) |
53 | 53 | ||
54 | var searNick; | 54 | var searNick; | ... | ... |
... | @@ -52,8 +52,9 @@ passport.serializeUser(function(user, done){ | ... | @@ -52,8 +52,9 @@ passport.serializeUser(function(user, done){ |
52 | passport.deserializeUser(function(user, done){ | 52 | passport.deserializeUser(function(user, done){ |
53 | var ID = user.ID; | 53 | var ID = user.ID; |
54 | var nickname = user.nickname; | 54 | var nickname = user.nickname; |
55 | + var type = user.type; | ||
55 | // console.log('passport session get ID: '+ ID + '(' + nickname + ')') | 56 | // console.log('passport session get ID: '+ ID + '(' + nickname + ')') |
56 | - done(null, {'ID': ID, 'nickname':nickname}); // 세션에서 값을 뽑아서 페이지에 전달하는 역할 | 57 | + done(null, {'ID': ID, 'nickname':nickname, 'type':type}); // 세션에서 값을 뽑아서 페이지에 전달하는 역할 |
57 | }) | 58 | }) |
58 | 59 | ||
59 | passport.use('local-join', new LocalStrategy({ | 60 | passport.use('local-join', new LocalStrategy({ |
... | @@ -89,7 +90,7 @@ passport.use('local-join', new LocalStrategy({ | ... | @@ -89,7 +90,7 @@ passport.use('local-join', new LocalStrategy({ |
89 | var query = connection.query('insert into userDB set ?', sql, function(err, rows){ | 90 | var query = connection.query('insert into userDB set ?', sql, function(err, rows){ |
90 | if(err) throw err | 91 | if(err) throw err |
91 | console.log(logString+"회원가입 알림: 사용자가 추가되었습니다.({" + ID +"(" + req.body.nickname + ")} // "+ip+')') | 92 | console.log(logString+"회원가입 알림: 사용자가 추가되었습니다.({" + ID +"(" + req.body.nickname + ")} // "+ip+')') |
92 | - return done(null, {'ID' : ID, 'nickname' : req.body.nickname}); | 93 | + return done(null, {'ID' : ID, 'nickname' : req.body.nickname, 'type': req.body.type}); |
93 | }) | 94 | }) |
94 | } | 95 | } |
95 | }) | 96 | }) | ... | ... |
views/command.ejs
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <head> | ||
4 | + <meta charset="utf-8"> | ||
5 | + <title>묵호 - 채팅</title> | ||
6 | + <link rel="stylesheet" href="/css/chat.css"> | ||
7 | + <script src="/socket.io/socket.io.js"></script> | ||
8 | + <script src="/js/command.js"></script> | ||
9 | + <link href="../css/styles.css" rel="stylesheet" /> | ||
10 | + </head> | ||
11 | + <body> | ||
12 | + <div id="main"> | ||
13 | + <div id="console"> | ||
14 | + <!-- 채팅 메시지 영역 --> | ||
15 | + </div> | ||
16 | + <div id = "input"> | ||
17 | + | ||
18 | + <input onkeyup="enterkey()" class = "form-control" type="text" id="command" placeholder="" required/> | ||
19 | + | ||
20 | + | ||
21 | + </div> | ||
22 | + </div> | ||
23 | + </body> | ||
24 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment