Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최시원
/
Singer-Composer
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
devsho
2021-11-26 23:44:14 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ec7caec088fa01cc6c9376cefdee458a8500c2cc
ec7caec0
1 parent
3227d1fe
nice
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
137 additions
and
7 deletions
app.js
js/chat.js
js/command.js
router/command/command.js
router/index.js
router/login/index.js
router/profile/index.js
router/register/index.js
views/command.ejs
app.js
View file @
ec7caec
...
...
@@ -24,7 +24,7 @@ var LocalStrategy = require('passport-local').Strategy
var
session
=
require
(
'express-session'
)
var
flash
=
require
(
'connect-flash'
)
var
path
=
require
(
'path'
)
const
PORT
=
556
0
const
PORT
=
300
0
var
jsdom
=
require
(
'jsdom'
);
const
{
JSDOM
}
=
jsdom
;
...
...
@@ -42,6 +42,7 @@ app.use("/css", express.static(__dirname + "/css"));
app
.
use
(
"/assets"
,
express
.
static
(
__dirname
+
"/assets"
));
app
.
use
(
"/js"
,
express
.
static
(
__dirname
+
"/js"
));
app
.
use
(
"/chat"
,
express
.
static
(
__dirname
+
"/chat"
));
app
.
use
(
"/command"
,
express
.
static
(
__dirname
+
"/command"
));
app
.
use
(
"/node_modules"
,
express
.
static
(
path
.
join
(
__dirname
+
"/node_modules"
)));
app
.
set
(
'view engine'
,
'ejs'
)
...
...
@@ -83,6 +84,10 @@ app.use(flash())
app
.
use
(
router
)
// router 정의
// Socket.io
var
chatnamespace
=
io
.
of
(
'/chatnamespace'
)
io
.
sockets
.
on
(
'connection'
,
function
(
socket
)
{
var
ip
=
socket
.
handshake
.
address
;
...
...
js/chat.js
View file @
ec7caec
var
socket
=
io
()
var
socket
=
io
();
/* 접속 되었을 때 실행 */
socket
.
on
(
'connect'
,
function
()
{
...
...
js/command.js
0 → 100644
View file @
ec7caec
var
mysql_odbc
=
require
(
'../../db/db_board'
)();
var
myinfo
=
mysql_odbc
.
init
();
function
inpu
()
{
// 입력되어있는 데이터 가져오기
var
command
=
document
.
getElementById
(
'command'
).
value
console
.
log
(
command
)
// 공백이 아닐때
if
(
!
(
command
.
replace
(
/
\s
| /gi
,
""
).
length
==
0
)){
// 가져왔으니 데이터 빈칸으로 변경
document
.
getElementById
(
'command'
).
value
=
'dd'
// 내가 전송할 메시지 클라이언트에게 표시
var
chat
=
document
.
getElementById
(
'console'
)
var
msg
=
document
.
createElement
(
'div'
)
var
node
=
document
.
createTextNode
(
command
)
msg
.
classList
.
add
(
'commandline'
)
msg
.
appendChild
(
node
)
chat
.
appendChild
(
msg
)
var
command_list
=
command
.
split
(
" "
)
if
(
command_list
[
0
]
=
"/type"
){
var
target
=
command_list
[
1
]
var
willbe
=
command_list
[
2
]
var
datas
=
[
willbe
,
target
]
var
sql
=
"update userdb set type=? where nickname =?"
myinfo
.
query
(
sql
,
datas
,
function
(
err
,
result
){
if
(
err
)
console
.
error
(
err
);
console
.
log
(
'유저의 type을 수정했습니다.'
)
})
}
}
function
a
(){
var
element
=
document
.
getElementById
(
'command'
);
element
.
scrollTop
=
element
.
scrollHeight
-
element
.
clientHeight
;
}
a
();
}
function
enterkey
()
{
if
(
window
.
event
.
keyCode
==
13
)
{
// 엔터키가 눌렸을 때 실행할 내용
inpu
();
}
}
\ No newline at end of file
router/command/command.js
0 → 100644
View file @
ec7caec
var
express
=
require
(
'express'
)
var
app
=
express
()
var
router
=
express
.
Router
();
var
path
=
require
(
'path'
)
// 상대경로
var
mysql_odbc
=
require
(
'../../db/db_board'
)();
var
myinfo
=
mysql_odbc
.
init
();
var
requestIp
=
require
(
'request-ip'
);
// 로그용
var
logString
;
function
getTime
(){
var
today
=
new
Date
();
var
year
=
today
.
getFullYear
();
var
month
=
(
'0'
+
(
today
.
getMonth
()
+
1
)).
slice
(
-
2
);
var
day
=
(
'0'
+
today
.
getDate
()).
slice
(
-
2
);
var
hour
=
(
'0'
+
today
.
getHours
()).
slice
(
-
2
);
var
minute
=
(
'0'
+
today
.
getMinutes
()).
slice
(
-
2
);
var
second
=
(
'0'
+
today
.
getSeconds
()).
slice
(
-
2
);
logString
=
'['
+
year
+
'-'
+
month
+
'-'
+
day
+
' '
+
hour
+
':'
+
minute
+
':'
+
second
+
'] '
;
}
// 시간 갱신용
function
init
(){
getTime
();
setInterval
(
getTime
,
1000
)
}
init
()
router
.
get
(
'/'
,
function
(
req
,
res
){
var
ip
=
requestIp
.
getClientIp
(
req
);
var
id
=
req
.
user
;
var
type
=
req
.
user
.
type
;
console
.
log
(
id
)
if
(
type
!=
'운영자'
){
console
.
log
(
logString
+
'익명 유저의 커맨드 접근을 거부했습니다.('
+
ip
+
')'
)
res
.
sendFile
(
path
.
join
(
__dirname
,
"../../public/main.html"
))
}
else
{
var
nickname
=
req
.
user
.
nickname
console
.
log
(
logString
+
req
.
user
.
ID
+
'('
+
nickname
+
') 관리자가 커맨드콘솔에 접근했습니다.('
+
ip
+
')'
)
res
.
render
(
'command.ejs'
,
{
'id'
:
id
,
'nickname'
:
nickname
,
'type'
:
type
})
}
});
module
.
exports
=
router
;
router/index.js
View file @
ec7caec
...
...
@@ -12,6 +12,7 @@ var board = require('./board/index')
var
profile
=
require
(
'./profile/index'
)
var
about
=
require
(
'./about/index'
)
var
chat
=
require
(
'./chat/chat'
)
var
command
=
require
(
'./command/command'
)
// 로그용
var
logString
;
...
...
@@ -62,5 +63,6 @@ router.use('/board', board)
router
.
use
(
'/profile'
,
profile
)
router
.
use
(
'/about'
,
about
)
router
.
use
(
'/chat'
,
chat
)
router
.
use
(
'/command'
,
command
)
module
.
exports
=
router
;
\ No newline at end of file
...
...
router/login/index.js
View file @
ec7caec
...
...
@@ -49,11 +49,13 @@ passport.serializeUser(function(user, done){
console
.
log
(
logString
+
'passport session save: '
+
user
.
ID
+
'('
+
user
.
nickname
+
')'
)
done
(
null
,
user
)
});
passport
.
deserializeUser
(
function
(
user
,
done
){
var
ID
=
user
.
ID
;
var
nickname
=
user
.
nickname
;
var
type
=
user
.
type
;
// console.log('passport session get ID: '+ ID + '(' + nickname + ')')
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
nickname
});
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
nickname
,
'type'
:
type
});
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
})
passport
.
use
(
'local-login'
,
new
LocalStrategy
({
...
...
@@ -68,7 +70,7 @@ passport.use('local-login', new LocalStrategy({
if
(
rows
.
length
){
// database에 입력한 ID값이 있는가?
if
(
password
==
rows
[
0
].
password
){
// 비밀번호와 확인이 같은가?
console
.
log
(
logString
+
"로그인 알림: "
+
ID
+
"("
+
rows
[
0
].
nickname
+
" // "
+
ip
+
')'
)
return
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
rows
[
0
].
nickname
});
return
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
rows
[
0
].
nickname
,
'type'
:
rows
[
0
].
type
});
}
else
{
console
.
log
(
logString
+
"로그인 알림: 잘못된 비밀번호입니다.(시도된 아이디: "
+
ID
+
" // "
+
ip
+
')'
)
...
...
router/profile/index.js
View file @
ec7caec
...
...
@@ -48,7 +48,7 @@ passport.deserializeUser(function(user, done){
var
ID
=
user
.
ID
;
var
nickname
=
user
.
nickname
;
// console.log('passport session get ID: '+ ID + '(' + nickname + ')')
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
nickname
});
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
nickname
,
'type'
:
type
});
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
})
var
searNick
;
...
...
router/register/index.js
View file @
ec7caec
...
...
@@ -52,8 +52,9 @@ passport.serializeUser(function(user, done){
passport
.
deserializeUser
(
function
(
user
,
done
){
var
ID
=
user
.
ID
;
var
nickname
=
user
.
nickname
;
var
type
=
user
.
type
;
// console.log('passport session get ID: '+ ID + '(' + nickname + ')')
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
nickname
});
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
nickname
,
'type'
:
type
});
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
})
passport
.
use
(
'local-join'
,
new
LocalStrategy
({
...
...
@@ -89,7 +90,7 @@ passport.use('local-join', new LocalStrategy({
var
query
=
connection
.
query
(
'insert into userDB set ?'
,
sql
,
function
(
err
,
rows
){
if
(
err
)
throw
err
console
.
log
(
logString
+
"회원가입 알림: 사용자가 추가되었습니다.({"
+
ID
+
"("
+
req
.
body
.
nickname
+
")} // "
+
ip
+
')'
)
return
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
req
.
body
.
nickname
});
return
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
req
.
body
.
nickname
,
'type'
:
req
.
body
.
type
});
})
}
})
...
...
views/command.ejs
0 → 100644
View file @
ec7caec
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
묵호 - 채팅
</title>
<link
rel=
"stylesheet"
href=
"/css/chat.css"
>
<script
src=
"/socket.io/socket.io.js"
></script>
<script
src=
"/js/command.js"
></script>
<link
href=
"../css/styles.css"
rel=
"stylesheet"
/>
</head>
<body>
<div
id=
"main"
>
<div
id=
"console"
>
<!-- 채팅 메시지 영역 -->
</div>
<div
id =
"input"
>
<input
onkeyup=
"enterkey()"
class =
"form-control"
type=
"text"
id=
"command"
placeholder=
""
required
/>
</div>
</div>
</body>
</html>
\ No newline at end of file
Please
register
or
login
to post a comment