Skip to content

Commit

Permalink
Simplify configuration file
Browse files Browse the repository at this point in the history
(URL- and file-based images are handled depending on http-prefix)
  • Loading branch information
bkimminich committed Apr 28, 2017
1 parent 8d0dc4d commit 3f1d956
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 24 deletions.
3 changes: 1 addition & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

var server = require('./server')
const config = require('config')

server.start(config)
server.start()
Binary file added app/public/favicon_ctf.ico
Binary file not shown.
Binary file added app/public/images/JuiceShopCTF_Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions config/bodgeit.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
application:
domain: thebodgeitstore.com
name: "The BodgeIt Store"
logoReplacementUrl: "http://www.userlogos.org/files/logos/inductiveload/Google%20Code.png"
faviconReplacementUrl: "https://www.shareicon.net/download/2016/08/13/808555_media.ico"
logo: "http://www.userlogos.org/files/logos/inductiveload/Google%20Code.png"
favicon: "https://www.shareicon.net/download/2016/08/13/808555_media.ico"
showChallengeSolvedNotifications: true
theme: "paper"
products:
Expand Down
4 changes: 2 additions & 2 deletions config/ctf.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
application:
logoReplacementUrl: "https://raw.githubusercontent.com/bkimminich/juice-shop-ctf/develop/images/JuiceShopCTF_Logo.png"
faviconReplacementUrl: "https://raw.githubusercontent.com/bkimminich/juice-shop-ctf/develop/images/favicon_ctf.ico"
logo: "JuiceShopCTF_Logo.png"
favicon: "favicon_ctf.ico"
showCtfFlagsInNotifications: true

4 changes: 2 additions & 2 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ server:
application:
domain: juice-sh.op
name: "OWASP Juice Shop"
logoReplacementUrl: ~
faviconReplacementUrl: ~
logo: "JuiceShop_Logo.png"
favicon: "favicon_v2.ico"
numberOfRandomFakeUsers: 0
showChallengeSolvedNotifications: true
showCtfFlagsInNotifications: false
Expand Down
2 changes: 1 addition & 1 deletion config/sickshop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
application:
domain: sick-sh.op
name: "Sick-Shop"
logoReplacementUrl: "https://openclipart.org/image/300px/svg_to_png/250927/1465228117.png"
logo: "https://openclipart.org/image/300px/svg_to_png/250927/1465228117.png"
numberOfRandomFakeUsers: 50
showChallengeSolvedNotifications: false
theme: "cosmo"
Expand Down
5 changes: 2 additions & 3 deletions data/datacreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,8 @@ module.exports = function () {
var image = product.image || 'undefined.png'
if (utils.startsWith(image, 'http')) {
var imageUrl = image
image = image.substring(image.lastIndexOf('/') + 1)
var imageFilePath = 'app/public/images/products/' + image
utils.downloadToFile(imageUrl, imageFilePath)
image = decodeURIComponent(image.substring(image.lastIndexOf('/') + 1))
utils.downloadToFile(imageUrl, 'app/public/images/products/' + image)
}
models.Product.create({
name: name,
Expand Down
30 changes: 22 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var server = require('http').Server(app)
var io = require('socket.io')(server)
var replace = require('replace')
var appConfiguration = require('./routes/appConfiguration')
const config = require('config')

global.io = io
errorhandler.title = 'Juice Shop (Express ' + utils.version('express') + ')'
Expand Down Expand Up @@ -78,7 +79,16 @@ app.use(function (req, res, next) {
})

/* Favicon */
app.use(favicon(path.join(__dirname, 'app/public/favicon_v2.ico')))
var icon = 'favicon_v2.ico'
if (config.get('application.favicon')) {
icon = config.get('application.favicon')
if (utils.startsWith(icon, 'http')) {
var iconPath = icon
icon = decodeURIComponent(icon.substring(icon.lastIndexOf('/') + 1))
utils.downloadToFile(iconPath, 'app/public/' + icon)
}
}
app.use(favicon(path.join(__dirname, 'app/public/' + icon)))

/* Checks for solved challenges */
app.use('/public/images/tracking', verify.accessControlChallenges())
Expand Down Expand Up @@ -179,7 +189,7 @@ io.on('connection', function (socket) {
})
})

exports.start = function (config, readyCallback) {
exports.start = function (readyCallback) {
if (!this.server) {
models.sequelize.drop()
models.sequelize.sync().success(function () {
Expand All @@ -191,15 +201,19 @@ exports.start = function (config, readyCallback) {
}
})
})
if (config.get('application.logoReplacementUrl')) {
utils.downloadToFile(config.get('application.logoReplacementUrl'), 'app/public/images/JuiceShop_Logo.png')
}
if (config.get('application.faviconReplacementUrl')) {
utils.downloadToFile(config.get('application.faviconReplacementUrl'), 'app/public/favicon_v2.ico')
if (config.get('application.logo')) {
var logo = config.get('application.logo')
if (utils.startsWith(logo, 'http')) {
var logoPath = logo
logo = decodeURIComponent(logo.substring(logo.lastIndexOf('/') + 1))
utils.downloadToFile(logoPath, 'app/public/images/' + logo)
}
var logoImageTag = '<img class="navbar-brand navbar-logo" src="/public/images/' + logo + '">'
replace({ regex: /<img class="navbar-brand navbar-logo"(.*?)>/, replacement: logoImageTag, paths: ['app/index.html'], recursive: false, silent: true })
}
if (config.get('application.theme')) {
var themeCss = 'bower_components/bootswatch/' + config.get('application.theme') + '/bootstrap.min.css'
replace({ regex: 'bower_components/bootswatch/.*/bootstrap.min.css', replacement: themeCss, paths: ['app/index.html'], recursive: false, silent: true })
replace({ regex: /bower_components\/bootswatch\/.*\/bootstrap\.min\.css/, replacement: themeCss, paths: ['app/index.html'], recursive: false, silent: true })
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/e2eTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
var spawn = require('cross-spawn')
var colors = require('colors/safe')
var server = require('./../server.js')
var config = require('config')

server.start(config, function () {
server.start(function () {
var protractor = spawn('protractor', [ 'protractor.conf.js' ])
function logToConsole (data) {
console.log(String(data))
Expand Down
3 changes: 1 addition & 2 deletions test/serverTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
var spawn = require('cross-spawn')
var colors = require('colors/safe')
var server = require('./../server.js')
var config = require('config')

server.start(config, function () {
server.start(function () {
var jasmineNode = spawn('jasmine-node', [ 'test/server', '--junitreport', '--output', 'build/reports/server_results' ])
function logToConsole (data) {
console.log(String(data))
Expand Down

0 comments on commit 3f1d956

Please sign in to comment.