-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
71 lines (52 loc) · 1.98 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* MAIN_SERVER
* 정보보호 19-4기
* 박재용 <[email protected]>
*/
//모듈을 추출합니다.
var dateFormat = require('dateformat');
var socketio = require('socket.io');
var now = function() { return dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss"); }
var sites = require('./sites');
var http = require('http');
var config = require('./config');
var app = require('./front');
var shodan = require('./terminalNodes/shodan');
var httpget = require('./terminalNodes/httpget');
var server = http.createServer(app);
//var shodan = require('./shodan');
//웹서버를 실행합니다.
server.listen(config.PORT,function(){
console.log("server is running at "+config.PORT )
console.log()
//shodan().then(function(vuln){console.log(now()+" : "+ vuln[0].ip_str)})
httpget().then(function(status){console.log(now()+" : "+ status[0].statusCode)})
});
//http 요청에 대한 응답
server.on('request',function(code){
console.log('HI')
})
var test = function(){
server.close();
console.log("server is closed now")
}
//소켓 서버를 생성 및 실행합니다.
var io = socketio.listen(server);
io.sockets.on('connection',function(socket){
//// 최초 프레임 생성을 위해 sites 의 내용을 클라이언트로 전송합니다.
socket.on('frame',function(data){
console.log("client send data :",data);
socket.emit('kiso',sites);
})
//// http request 신호를 받으면 해당 모듈의 결과값을 클라이언트에 전송합니다.
socket.on('web',function(data){
console.log("client send data :",data);
httpget().then(function(status){socket.emit('webinfo',status);
console.log('server : web info is sent')})
})
//// shodan request 신호를 받으면 해당 모듈의 결과값을 클라이언트에 전송합니다.
socket.on('shodan',function(index){
console.log('shodan info is needed (from client to server): ',index);
shodan(index).then(res=>{socket.emit('shodaninfo',res)});
console.log('server : shodan info is sent')})
})