Skip to content

Commit 0a4275b

Browse files
committed
Initial commit of the v1.0.0 code base.
1 parent 545f4c1 commit 0a4275b

File tree

12 files changed

+674
-0
lines changed

12 files changed

+674
-0
lines changed

app-menu.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
var Menu = require('menu')
2+
var Application = require('app')
3+
4+
var template = [{
5+
label: 'Edit',
6+
submenu: [{
7+
label: 'Undo',
8+
accelerator: 'CmdOrCtrl+Z',
9+
role: 'undo'
10+
},{
11+
label: 'Redo',
12+
accelerator: 'Shift+CmdOrCtrl+Z',
13+
role: 'redo'
14+
},{
15+
type: 'separator'
16+
},{
17+
label: 'Cut',
18+
accelerator: 'CmdOrCtrl+X',
19+
role: 'cut'
20+
},{
21+
label: 'Copy',
22+
accelerator: 'CmdOrCtrl+C',
23+
role: 'copy'
24+
},{
25+
label: 'Paste',
26+
accelerator: 'CmdOrCtrl+V',
27+
role: 'paste'
28+
},{
29+
label: 'Select All',
30+
accelerator: 'CmdOrCtrl+A',
31+
role: 'selectall'
32+
}]
33+
},{
34+
label: 'View',
35+
submenu: [{
36+
label: 'Reload',
37+
accelerator: 'CmdOrCtrl+R',
38+
click: function (item, focusedWindow) {
39+
if (focusedWindow) {
40+
focusedWindow.reload()
41+
}
42+
}
43+
},{
44+
label: 'Toggle Full Screen',
45+
accelerator: (function () {
46+
if (process.platform == 'darwin') {
47+
return 'Ctrl+Command+F'
48+
} else {
49+
return 'F11'
50+
}
51+
})(),
52+
click: function (item, focusedWindow) {
53+
if (focusedWindow) {
54+
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
55+
}
56+
}
57+
},{
58+
label: 'Toggle Developer Tools',
59+
accelerator: (function () {
60+
if (process.platform == 'darwin') {
61+
return 'Alt+Command+I'
62+
} else {
63+
return 'Ctrl+Shift+I'
64+
}
65+
})(),
66+
click: function (item, focusedWindow) {
67+
if (focusedWindow) {
68+
focusedWindow.toggleDevTools()
69+
}
70+
}
71+
}]
72+
},{
73+
label: 'Window',
74+
role: 'window',
75+
submenu: [{
76+
label: 'Minimize',
77+
accelerator: 'CmdOrCtrl+M',
78+
role: 'minimize'
79+
},{
80+
label: 'Close',
81+
accelerator: 'CmdOrCtrl+W',
82+
role: 'close'
83+
}]
84+
}]
85+
86+
if (process.platform == 'darwin') {
87+
var name = 'Awsaml'
88+
template.unshift({
89+
label: name,
90+
submenu: [{
91+
label: 'About '+name,
92+
role: 'about'
93+
},{
94+
type: 'separator'
95+
},{
96+
label: 'Services',
97+
role: 'services',
98+
submenu: []
99+
},{
100+
type: 'separator'
101+
},{
102+
label: 'Hide '+name,
103+
accelerator: 'Command+H',
104+
role: 'hide'
105+
},{
106+
label: 'Hide Others',
107+
accelerator: 'Command+Shift+H',
108+
role: 'hideothers'
109+
},{
110+
label: 'Show All',
111+
role: 'unhide'
112+
},{
113+
type: 'separator'
114+
},{
115+
label: 'Quit',
116+
accelerator: 'Command+Q',
117+
click: function () {
118+
Application.quit()
119+
}
120+
}]
121+
})
122+
123+
// Window menu.
124+
template[3].submenu.push({
125+
type: 'separator'
126+
},{
127+
label: 'Bring All to Front',
128+
role: 'front'
129+
})
130+
}
131+
132+
var menu = Menu.buildFromTemplate(template)
133+
Menu.setApplicationMenu(menu)

app.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var Application = require('app')
2+
var BrowserWindow = require('browser-window')
3+
var Storage = require('./lib/storage')
4+
var Server = require('./lib/server')
5+
var config = require('./config')
6+
7+
var mainWindow = null
8+
9+
Application.commandLine.appendSwitch('disable-http-cache')
10+
11+
Application.on('window-all-closed', function() {
12+
Application.quit()
13+
})
14+
15+
Application.on('ready', function() {
16+
require('./app-menu')
17+
18+
var host = Server.get('host')
19+
var port = Server.get('port')
20+
Server.listen(port, host, function () {
21+
console.log('Server listening on http://%s:%s', host, port)
22+
})
23+
24+
var lastWindowState = Storage.get('lastWindowState')
25+
if (lastWindowState === null) {
26+
lastWindowState = {
27+
width: 800,
28+
height: 700
29+
}
30+
}
31+
32+
mainWindow = new BrowserWindow({
33+
title: 'Rapid7 - Awsaml',
34+
x: lastWindowState.x,
35+
y: lastWindowState.y,
36+
width: lastWindowState.width,
37+
height: lastWindowState.height,
38+
show: false,
39+
'web-preferences': {
40+
'node-integration': false
41+
}
42+
})
43+
44+
mainWindow.on('close', function () {
45+
var bounds = mainWindow.getBounds()
46+
Storage.set('lastWindowState', {
47+
x: bounds.x,
48+
y: bounds.y,
49+
width: bounds.width,
50+
height: bounds.height,
51+
version: 1
52+
})
53+
})
54+
55+
mainWindow.on('closed', function() {
56+
mainWindow = null
57+
})
58+
59+
mainWindow.loadUrl(Server.get('configureUrl'))
60+
mainWindow.show()
61+
62+
setInterval(function () {
63+
console.log('Reloading...')
64+
mainWindow.loadUrl(Server.get('entryPointUrl'))
65+
}, (config.aws.duration - 10) * 1000)
66+
})

config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"server": {
3+
"host": "localhost",
4+
"port": 2600
5+
},
6+
"auth": {
7+
"path": "/sso/saml"
8+
},
9+
"aws": {
10+
"duration": 3600
11+
}
12+
}

lib/auth.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var SamlStrategy = require('passport-saml').Strategy
2+
3+
function Auth (options) {
4+
var self = this
5+
this.users = Object.create(null)
6+
this.passport = require('passport')
7+
8+
this.passport.serializeUser(function (user, done) {
9+
self.users[user.nameID] = user
10+
return done(null, user.nameID)
11+
})
12+
13+
this.passport.deserializeUser(function (id, done) {
14+
return done(null, self.users[id])
15+
})
16+
17+
this.guard = function (req, res, next) {
18+
if (req.isAuthenticated()) {
19+
return next()
20+
}
21+
res.redirect(options.entryPoint)
22+
}
23+
}
24+
25+
Auth.prototype.initialize = function () {
26+
return this.passport.initialize()
27+
}
28+
29+
Auth.prototype.session = function () {
30+
return this.passport.session()
31+
}
32+
33+
Auth.prototype.authenticate = function (type, options) {
34+
return this.passport.authenticate(type, options)
35+
}
36+
37+
Auth.prototype.configure = function (options) {
38+
this.passport.use(new SamlStrategy(options, function (profile, done) {
39+
return done(null, profile)
40+
}))
41+
}
42+
43+
module.exports = Auth

lib/aws-credentials.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var ini = require('ini')
2+
var fs = require('fs')
3+
var path = require('path')
4+
var mkdirp = require('mkdirp')
5+
6+
function AwsCredentials () {
7+
}
8+
9+
AwsCredentials.prototype.save = function (credentials, profile, done) {
10+
this.saveAsIniFile(credentials, profile, done)
11+
}
12+
13+
AwsCredentials.prototype.saveAsIniFile = function (credentials, profile, done) {
14+
if (!credentials) {
15+
return done(new Error('Invalid AWS credentials'))
16+
}
17+
18+
if (!profile) {
19+
return done(new Error('Cannot save AWS credentials, profile not set'))
20+
}
21+
22+
var home = this.resolveHomePath()
23+
if (!home) {
24+
return done(new Error('Cannot save AWS credentials, HOME path not set'))
25+
}
26+
27+
var self = this
28+
var configFile = path.join(home, '.aws', 'credentials')
29+
// mkdirp is a no-op if the directory already exists
30+
mkdirp(path.join(home, '.aws'), '0700', function (err) {
31+
if (err) {
32+
return done(err)
33+
}
34+
35+
fs.readFile(configFile, 'utf8', function (err, data) {
36+
if (err && err.code !== 'ENOENT') {
37+
return done(err)
38+
}
39+
40+
var config = Object.create(null)
41+
if (data && data !== '') {
42+
config = ini.parse(data)
43+
}
44+
45+
config[profile] = {}
46+
config[profile].aws_access_key_id = credentials.AccessKeyId
47+
config[profile].aws_secret_access_key = credentials.SecretAccessKey
48+
config[profile].aws_session_token = credentials.SessionToken
49+
// Some libraries e.g. boto v2.38.0, expect an "aws_security_token" entry.
50+
config[profile].aws_security_token = credentials.SessionToken
51+
config = ini.encode(config, { whitespace: true })
52+
53+
fs.writeFile(configFile, config, 'utf8', done)
54+
})
55+
})
56+
}
57+
58+
AwsCredentials.prototype.resolveHomePath = function () {
59+
var env = process.env
60+
, home = env.HOME ||
61+
env.USERPROFILE ||
62+
(env.HOMEPATH ? ((env.HOMEDRIVE || 'C:/') + env.HOMEPATH) : null)
63+
return home
64+
}
65+
66+
module.exports = AwsCredentials

0 commit comments

Comments
 (0)