-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
219 lines (195 loc) · 8.26 KB
/
index.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//var openssl = require('./lib/openssl.js')
var express_ssl = require('./lib/express_ssl.js')
var config = require('./config.js');
var html = require('./html.js');
var express = require('express')
//var multer = require('multer');
var bodyParser = require('body-parser')
//var https = require('https');
var mustacheExpress = require('mustache-express');
var app = express();
var httpapp = express();
var certtemplates = require('./templates.js');
var opensslcap = require('./lib/openssl_capabilities.js');
const fs = require('fs');
if (fs.existsSync('./ca/global')) {
console.log('exists');
} else {
fs.mkdirSync('./ca/global');
}
console.log('CAIPDIR is set to "' + config.caIPDir + '"');
console.log('HOSTED is set to "' + config.hosted + '"');
console.log('HTTPPORT is set to "' + config.httpport + '"');
console.log('HTTPSPORT is set to "' + config.httpsport + '"');
console.log('PUBLICHTTP is set to "' + config.publichttp + '"');
express_ssl.getSSL(function(sslOptions) {
var server = require('https').createServer(sslOptions, app).listen(config.httpsport);
});
var httpserver = require('http').createServer(httpapp).listen(config.httpport);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies.
// Register '.mustache' extension with The Mustache Express
app.engine('html', mustacheExpress());
app.set('view engine', 'html');
app.use('/js/bootstrap', express.static(__dirname + '/node_modules/bootstrap/dist/js'));
app.use('/js/moment', express.static('./node_modules/moment/min'));
app.use('/js/jquery', express.static('./node_modules/jquery/dist'));
app.use('/js/jquery-ui', express.static('./node_modules/jquery-ui/dist'));
app.use('/js/tempusdominus-bootstrap-3', express.static('./node_modules/tempusdominus-bootstrap-3/build/js'));
app.use('/js/tempusdominus-core', express.static('./node_modules/tempusdominus-core/build/js'));
app.use('/js/popper.js', express.static('./node_modules/popper.js/dist/umd'));
//app.use('/js/fontawesome-free', express.static('./node_modules/@fortawesome/fontawesome-free/js'));
app.use('/css/tempusdominus-bootstrap-3', express.static('./node_modules/tempusdominus-bootstrap-3/build/css'));
app.use('/css/bootstrap', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
app.use('/css/fonts', express.static(__dirname + '/node_modules/bootstrap/dist/fonts'));
app.use('/css/jquery-ui', express.static(__dirname + '/node_modules/jquery-ui/dist'));
app.use('/css/fontawesome-free', express.static('./node_modules/@fortawesome/fontawesome-free/css'));
app.use('/css/webfonts', express.static('./node_modules/@fortawesome/fontawesome-free/webfonts'));
app.use('/images', express.static(__dirname + '/images'));
app.use('/static', express.static(__dirname + '/static'));
//app.use(express.static('files'))app.use('/api/auth', require('./api/auth'));
opensslcap.getCapabilities(function(err, capabilities) {
function getTemplate() {
return template = {
title: "CertificateTools.com X509 Certificate Generator",
certtemplates: certtemplates,
javascripttemplates: JSON.stringify(certtemplates, null, 4),
capabilities: capabilities,
hosted: config.hosted,
header: html.header.join('\r\n')
}
}
//console.log(template);
app.get('/', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip);
let template = getTemplate();
res.render('index.html', template);
});
app.get('/about', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip);
let template = getTemplate();
res.render('about.html', template);
});
app.get('/test', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip);
let template = getTemplate();
res.render('test.html', template);
});
app.get('/ocsp_checker', function(req, res) {
//let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
//console.log('HTTPS connection from ' + ip);
//res.render('ocsp_checker.html', template);
res.redirect(301, '/ocsp-checker')
});
app.get('/ocsp-checker', function(req, res) {
//console.log(req.query);
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip);
/*let url = req.url;
let ocsporrev = url.substring(1).split('-')[0];
ocsporrev = ocsporrev.toUpperCase()
console.log(ocsporrev);*/
let template = getTemplate();
template.title = 'OCSP Checker';
if(req.query.hasOwnProperty('hostname')) {
template.hostname = req.query.hostname;
}/* else {
template.hostname = '';
}*/
res.render('ocsp_checker.html', template);
});
app.get('/test-post-quantum-cryptography', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip);
/*let url = req.url;
let ocsporrev = url.substring(1).split('-')[0];
ocsporrev = ocsporrev.toUpperCase()
console.log(ocsporrev);*/
let template = getTemplate();
template.title = 'Test Post-Quantum Readiness';
if(req.query.hasOwnProperty('hostname')) {
template.hostname = req.query.hostname;
}
res.render('test_post_quantum_cryptography.html', template);
});
app.get('/revocation-checker', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log(req.url);
console.log('HTTPS connection from ' + ip);
/*let url = req.url;
let ocsporrev = url.substring(1).split('-')[0];
ocsporrev = ocsporrev.charAt(0).toUpperCase() + ocsporrev.slice(1);
console.log(ocsporrev);*/
let template = getTemplate();
template.title = 'Revocation Checker';
res.render('ocsp_checker.html', template);
});
app.get('/download-certificates', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log(req.url);
console.log('HTTPS connection from ' + ip);
/*let url = req.url;
let ocsporrev = url.substring(1).split('-')[0];
ocsporrev = ocsporrev.charAt(0).toUpperCase() + ocsporrev.slice(1);
console.log(ocsporrev);*/
let template = getTemplate();
template.title = 'Download Certificates';
res.render('download_certificates.html', template);
});
app.get('/csr-generator', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip);
let template = getTemplate();
res.render('csr_generator.html', template);
});
app.get('/scep-request', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip);
let template = getTemplate();
template.scep = {};
if(req.query.hasOwnProperty('domains')) {
template.scep.domains = req.query.domains;
} else {
template.scep.domains = '';
}
if(req.query.hasOwnProperty('url')) {
template.scep.url = req.query.url;
} else {
template.scep.url = '';
}
if(req.query.hasOwnProperty('challenge')) {
template.scep.challenge = req.query.challenge;
} else {
template.scep.challenge = '';
}
res.render('scep_request.html', template);
});
app.get('/manage-certs', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip);
let template = getTemplate();
res.render('manage_certs.html', template);
});
app.use('/', express.static(__dirname + '/views'));
});
app.get('/newui', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip + ', redirecting to root');
res.redirect('/');
});
app.get('/ca', function(req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('HTTPS connection from ' + ip + ', tshirt CA download');
res.redirect('/ca.crt');
});
app.use(function(req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
//res.header('Content-Type', 'application/json');
//res.header('Strict-Transport-Security', 'max-age=63072000; includeSubDomains');
next();
});
app.use('/api/openssl', require('./api/openssl'));
httpapp.use('/public/', require('./api/public'));