This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
/
server2.js
64 lines (55 loc) · 2 KB
/
server2.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
var http = require('http');
var querystring = require('querystring');
var env = process.env;
var cas_host = 'auth.ctmlabs.net'
var casservice = 'https://'+cas_host+'/'
var casurl = casservice + 'cas/login'
var testhost = env.SERVER_HOST // required
var testport = env.SERVER_PORT || 8080
var express = require('express')
var RedisStore = require('connect-redis')(express);
var cas_validate = require('cas_validate')
var app,server;
function create_server(done){
var app = express()
.use(express.favicon())
.use(express.logger({buffer:5000}))
.use(express.cookieParser('barley Waterloo Napoleon'))
.use(express.session({ store: new RedisStore }))
.use('/',cas_validate.ssoff())
.use('/',cas_validate.ticket({'cas_host':cas_host}))
//,'service':'http://'+testhost+':'+testport}))
.use('/',cas_validate.check_or_redirect({'cas_host':cas_host
,'service':'http://'+testhost+':'+testport}))
.use('/',function(req, res, next){
res.end('hello world')
return null
});
server =app.listen(testport,testhost,done)
}
create_server( function(e){
if(e){
// problems
console.log('cannot start server')
throw new Error(e)
}
console.log("Express server listening to "+ testhost +" on port " + testport);
console.log('Current gid: ' + process.getgid());
try {
process.setgid(65533);
console.log('New gid: ' + process.getgid());
}
catch (err) {
console.log('Failed to set gid: ' + err);
if(process.getgid() === 0) throw(err);
}
console.log('Current uid: ' + process.getuid());
try {
process.setuid(65534);
console.log('New uid: ' + process.getuid());
}
catch (err) {
console.log('Failed to set uid: ' + err);
if(process.getuid() === 0) throw(err);
}
})