This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
diagnostics.js
150 lines (138 loc) · 5.41 KB
/
diagnostics.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
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
'use strict';
/**
* Pterodactyl - Daemon
* Copyright (c) 2015 - 2018 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const Async = require('async');
const Inquirer = require('inquirer');
const Request = require('request');
const Process = require('child_process');
const Fs = require('fs-extra');
const _ = require('lodash');
const Path = require('path');
const Package = require('../package.json');
function postToHastebin(text) {
return new Promise((resolve, reject) => {
Request.post({
uri: 'https://hastebin.com/documents',
body: text,
}, (error, response, body) => {
if (error || response.statusCode !== 200) {
reject(error);
} else {
resolve(`https://hastebin.com/${JSON.parse(body).key.toString()}`);
}
});
});
}
Inquirer.prompt([
{
name: 'endpoints',
type: 'confirm',
message: 'Do you want to include Endpoints (i.e. the FQDN/IP of your Panel)',
default: true,
}, {
name: 'logs',
type: 'confirm',
message: 'Do you want to include the latest logs?',
default: true,
}, {
name: 'hastebin',
type: 'confirm',
message: 'Do you directly want to upload the diagnostics to hastebin.com?',
default: true,
},
]).then(answers => {
Async.auto({
config: callback => {
Fs.access('./config/core.json', (Fs.constants || Fs).R_OK | (Fs.constants || Fs).W_OK, err => { // eslint-disable-line
if (err) return callback(null, { error: true });
return callback(null, Fs.readJsonSync('./config/core.json'));
});
},
docker_version: callback => {
Process.exec('docker --version', (err, stdout) => {
callback(err, stdout);
});
},
docker_info: callback => {
Process.exec('docker info', (err, stdout) => {
callback(err, stdout);
});
},
docker_containers: callback => {
Process.exec('docker ps --format \'table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Status}}\' -a', (err, stdout) => {
callback(err, stdout);
});
},
bunyan_logs: callback => {
if (answers.logs) {
const MainLog = Fs.existsSync(Path.resolve('logs/wings.log'));
const SecondLog = Fs.existsSync(Path.resolve('logs/wings.log.0'));
let logFile;
if (MainLog) {
logFile = 'logs/wings.log';
} else if (SecondLog) {
logFile = 'logs/wings.log.0';
} else {
return callback(null, '[no logs found]');
}
Process.exec(`tail -n 200 ${logFile} | ./node_modules/bunyan/bin/bunyan -o short`, { maxBuffer: 100 * 1024 }, (err, stdout) => {
callback(err, stdout);
});
} else {
return callback(null, '[not provided]');
}
},
}, (err, results) => {
if (err) return console.error(err); // eslint-disable-line
const remoteHost = (answers.endpoints) ? _.get(results.config, 'remote.base', null) : '[redacted]';
const outputFormat = `
==[ Pterodactyl Daemon: Diagnostics Report ]==
--| Software Versions
- Daemon: ${Package.version}
- Node.js: ${process.version}
- Docker: ${results.docker_version}
--| Daemon Configuration
- SSL Enabled: ${_.get(results.config, 'web.ssl.enabled', null)}
- Port: ${_.get(results.config, 'web.listen', null)}
- Upload Size: ${_.get(results.config, 'uploads.size_limit', null)}
- Remote Host: ${remoteHost}
--| Docker Information
${results.docker_info}
--| Docker Containers
${results.docker_containers}
--| Latest Logs
${results.bunyan_logs}
==[ END DIAGNOSTICS ]==`;
if (answers.hastebin) {
postToHastebin(outputFormat)
.then(url => {
console.log('Your diagnostics report is available at:', url); // eslint-disable-line
})
.catch(error => {
console.error('An error occured while trying to upload to hastebin.com', error); // eslint-disable-line
});
} else {
console.log(outputFormat); // eslint-disable-line
}
});
});