Skip to content

Commit

Permalink
Initial commit of the v1.0.0 code base.
Browse files Browse the repository at this point in the history
  • Loading branch information
onefrankguy committed Jan 29, 2016
1 parent 545f4c1 commit 0a4275b
Show file tree
Hide file tree
Showing 12 changed files with 674 additions and 0 deletions.
133 changes: 133 additions & 0 deletions app-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
var Menu = require('menu')
var Application = require('app')

var template = [{
label: 'Edit',
submenu: [{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
role: 'undo'
},{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
role: 'redo'
},{
type: 'separator'
},{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
role: 'cut'
},{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
role: 'copy'
},{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
role: 'paste'
},{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
role: 'selectall'
}]
},{
label: 'View',
submenu: [{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click: function (item, focusedWindow) {
if (focusedWindow) {
focusedWindow.reload()
}
}
},{
label: 'Toggle Full Screen',
accelerator: (function () {
if (process.platform == 'darwin') {
return 'Ctrl+Command+F'
} else {
return 'F11'
}
})(),
click: function (item, focusedWindow) {
if (focusedWindow) {
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
}
}
},{
label: 'Toggle Developer Tools',
accelerator: (function () {
if (process.platform == 'darwin') {
return 'Alt+Command+I'
} else {
return 'Ctrl+Shift+I'
}
})(),
click: function (item, focusedWindow) {
if (focusedWindow) {
focusedWindow.toggleDevTools()
}
}
}]
},{
label: 'Window',
role: 'window',
submenu: [{
label: 'Minimize',
accelerator: 'CmdOrCtrl+M',
role: 'minimize'
},{
label: 'Close',
accelerator: 'CmdOrCtrl+W',
role: 'close'
}]
}]

if (process.platform == 'darwin') {
var name = 'Awsaml'
template.unshift({
label: name,
submenu: [{
label: 'About '+name,
role: 'about'
},{
type: 'separator'
},{
label: 'Services',
role: 'services',
submenu: []
},{
type: 'separator'
},{
label: 'Hide '+name,
accelerator: 'Command+H',
role: 'hide'
},{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
role: 'hideothers'
},{
label: 'Show All',
role: 'unhide'
},{
type: 'separator'
},{
label: 'Quit',
accelerator: 'Command+Q',
click: function () {
Application.quit()
}
}]
})

// Window menu.
template[3].submenu.push({
type: 'separator'
},{
label: 'Bring All to Front',
role: 'front'
})
}

var menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
66 changes: 66 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var Application = require('app')
var BrowserWindow = require('browser-window')
var Storage = require('./lib/storage')
var Server = require('./lib/server')
var config = require('./config')

var mainWindow = null

Application.commandLine.appendSwitch('disable-http-cache')

Application.on('window-all-closed', function() {
Application.quit()
})

Application.on('ready', function() {
require('./app-menu')

var host = Server.get('host')
var port = Server.get('port')
Server.listen(port, host, function () {
console.log('Server listening on http://%s:%s', host, port)
})

var lastWindowState = Storage.get('lastWindowState')
if (lastWindowState === null) {
lastWindowState = {
width: 800,
height: 700
}
}

mainWindow = new BrowserWindow({
title: 'Rapid7 - Awsaml',
x: lastWindowState.x,
y: lastWindowState.y,
width: lastWindowState.width,
height: lastWindowState.height,
show: false,
'web-preferences': {
'node-integration': false
}
})

mainWindow.on('close', function () {
var bounds = mainWindow.getBounds()
Storage.set('lastWindowState', {
x: bounds.x,
y: bounds.y,
width: bounds.width,
height: bounds.height,
version: 1
})
})

mainWindow.on('closed', function() {
mainWindow = null
})

mainWindow.loadUrl(Server.get('configureUrl'))
mainWindow.show()

setInterval(function () {
console.log('Reloading...')
mainWindow.loadUrl(Server.get('entryPointUrl'))
}, (config.aws.duration - 10) * 1000)
})
12 changes: 12 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"server": {
"host": "localhost",
"port": 2600
},
"auth": {
"path": "/sso/saml"
},
"aws": {
"duration": 3600
}
}
43 changes: 43 additions & 0 deletions lib/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var SamlStrategy = require('passport-saml').Strategy

function Auth (options) {
var self = this
this.users = Object.create(null)
this.passport = require('passport')

this.passport.serializeUser(function (user, done) {
self.users[user.nameID] = user
return done(null, user.nameID)
})

this.passport.deserializeUser(function (id, done) {
return done(null, self.users[id])
})

this.guard = function (req, res, next) {
if (req.isAuthenticated()) {
return next()
}
res.redirect(options.entryPoint)
}
}

Auth.prototype.initialize = function () {
return this.passport.initialize()
}

Auth.prototype.session = function () {
return this.passport.session()
}

Auth.prototype.authenticate = function (type, options) {
return this.passport.authenticate(type, options)
}

Auth.prototype.configure = function (options) {
this.passport.use(new SamlStrategy(options, function (profile, done) {
return done(null, profile)
}))
}

module.exports = Auth
66 changes: 66 additions & 0 deletions lib/aws-credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var ini = require('ini')
var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')

function AwsCredentials () {
}

AwsCredentials.prototype.save = function (credentials, profile, done) {
this.saveAsIniFile(credentials, profile, done)
}

AwsCredentials.prototype.saveAsIniFile = function (credentials, profile, done) {
if (!credentials) {
return done(new Error('Invalid AWS credentials'))
}

if (!profile) {
return done(new Error('Cannot save AWS credentials, profile not set'))
}

var home = this.resolveHomePath()
if (!home) {
return done(new Error('Cannot save AWS credentials, HOME path not set'))
}

var self = this
var configFile = path.join(home, '.aws', 'credentials')
// mkdirp is a no-op if the directory already exists
mkdirp(path.join(home, '.aws'), '0700', function (err) {
if (err) {
return done(err)
}

fs.readFile(configFile, 'utf8', function (err, data) {
if (err && err.code !== 'ENOENT') {
return done(err)
}

var config = Object.create(null)
if (data && data !== '') {
config = ini.parse(data)
}

config[profile] = {}
config[profile].aws_access_key_id = credentials.AccessKeyId
config[profile].aws_secret_access_key = credentials.SecretAccessKey
config[profile].aws_session_token = credentials.SessionToken
// Some libraries e.g. boto v2.38.0, expect an "aws_security_token" entry.
config[profile].aws_security_token = credentials.SessionToken
config = ini.encode(config, { whitespace: true })

fs.writeFile(configFile, config, 'utf8', done)
})
})
}

AwsCredentials.prototype.resolveHomePath = function () {
var env = process.env
, home = env.HOME ||
env.USERPROFILE ||
(env.HOMEPATH ? ((env.HOMEDRIVE || 'C:/') + env.HOMEPATH) : null)
return home
}

module.exports = AwsCredentials
Loading

0 comments on commit 0a4275b

Please sign in to comment.