This repository was archived by the owner on Oct 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
169 lines (158 loc) · 4.2 KB
/
index.js
File metadata and controls
169 lines (158 loc) · 4.2 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
var Hapi = require('hapi');
var fs = require('fs');
var server = new Hapi.Server('mc.spectrumbranch.com', 8123, {});
var lib = require('./lib');
var skins = lib.skins;
skins.init();
var crunch = lib.crunch;
crunch.init();
var isValidAPIKey = function(input, cb) {
fs.readFile(__dirname + '/keys/keys.json', function(err, data) {
if (err) {
cb(err, false);
} else {
var keyjson = JSON.parse(data);
var isValid = false;
for (var i = 0; i < keyjson.keys.length; i++) {
console.log('Comparing ['+keyjson.keys[i].key+'] to ['+input+']');
if (keyjson.keys[i].key === input) {
isValid = true;
break;
}
}
cb(null, isValid);
}
});
};
var getWhitelist = function(cb) {
var showUUID = true;
fs.readFile('/home/minecraft/apoc_minecraft/whitelist.json', function(err, data) {
if (err) {
cb(err, {});
} else {
var whitelistjson = JSON.parse(data);
if (!showUUID) {
for (var i = 0; i < whitelistjson.length; i++) {
delete whitelistjson[i]['uuid'];
}
}
cb(null, whitelistjson);
}
});
};
var getFTBWhitelist = function(cb) {
var showUUID = true;
fs.readFile('/home/minecraft/ftb_minecraft/whitelist.json', function(err, data) {
if (err) {
cb(err, {});
} else {
var whitelistjson = JSON.parse(data);
if (!showUUID) {
for (var i = 0; i < whitelistjson.length; i++) {
delete whitelistjson[i]['uuid'];
}
}
cb(null, whitelistjson);
}
});
};
server.route([
{
method: 'POST',
path: '/ftb_minecraft/whitelist.json',
handler: function (request, reply) {
if (request.payload && request.payload.apikey) {
console.log('Hit whitelist at ' + new Date().toString() + ' by IP: ' + request.info.remoteAddress);
var apikey = request.payload.apikey;
isValidAPIKey(apikey, function(err, isValid) {
if (isValid) {
getFTBWhitelist(function(err, whitelist) {
if (err) {
reply({ success: false, error: err});
} else {
reply({ success: true, whitelist: whitelist });
}
});
} else {
reply({ success: false });
}
});
} else {
reply({ success: false });
}
}
},
{
method: 'POST',
path: '/apoc_minecraft/whitelist.json',
handler: function (request, reply) {
if (request.payload && request.payload.apikey) {
console.log('Hit whitelist at ' + new Date().toString() + ' by IP: ' + request.info.remoteAddress);
var apikey = request.payload.apikey;
isValidAPIKey(apikey, function(err, isValid) {
if (isValid) {
getWhitelist(function(err, whitelist) {
if (err) {
reply({ success: false, error: err});
} else {
reply({ success: true, whitelist: whitelist });
}
});
} else {
reply({ success: false });
}
});
} else {
reply({ success: false });
}
}
},
{
method: 'POST',
path: '/apoc_minecraft/skin.json',
handler: function (request, reply) {
if (request.payload && request.payload.apikey && request.payload.uuid) {
console.log('Hit skins at ' + new Date().toString() + ' by IP: ' + request.info.remoteAddress);
var apikey = request.payload.apikey;
isValidAPIKey(apikey, function(err, isValid) {
if (isValid) {
skins.getSkinForUUID(request.payload.uuid, function(err1, skin) {
if (err1 || skin == null) {
console.log('Unable to retrieve skin');
reply({ success: false, error: err1 || 'Unable to retrieve skin.' });
} else {
reply({ success: true, skin: skin });
}
});
} else {
reply({ success: false });
}
});
} else {
reply({ success: false });
}
}
},
{
method: 'POST',
path: '/apoc_minecraft/parsedLogs.json',
handler: function (request, reply) {
console.log('test');
if (request.payload && request.payload.apikey) {
console.log('Hit parsed logs at ' + new Date().toString() + ' by IP: ' + request.info.remoteAddress);
var apikey = request.payload.apikey;
isValidAPIKey(apikey, function(err, isValid) {
if (isValid) {
reply.file('output/parsedLogs.json');
} else {
reply({ success: false });
}
});
} else {
reply({ success: false });
}
}
}
]);
server.start();
console.log('Server up at ' + server.info.uri + ' !');