├── .dockerignore ├── .talismanignore ├── screencast.gif ├── public ├── favicon.ico └── logo.svg ├── .gitignore ├── config ├── badges │ ├── password-master.yaml │ └── always-up-to-date.yaml ├── skills │ ├── yellow │ │ ├── software_updates.yml │ │ ├── no_credentials_in_the_code.yml │ │ ├── strong_passwords.yml │ │ ├── password_manager.yml │ │ └── input_validation.yml │ ├── brown │ │ └── automate_everything.yml │ ├── blue │ │ └── tls_everywhere.yml │ ├── black │ │ └── check_from_knuth.yml │ ├── orange │ │ └── dependency_checks.yml │ └── green │ │ └── evil_user_stories.yml └── teams.json ├── .travis.yml ├── app ├── styles │ ├── icon-sizes.scss │ ├── buttons.scss │ ├── badges.scss │ ├── belts.scss │ ├── toolbar.scss │ ├── card-grid.scss │ ├── leaderboard.scss │ ├── skills.scss │ └── style.scss └── js │ ├── client.js │ ├── skillFilter.js │ └── skillToggle.js ├── .github ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE.md ├── test ├── bad-skills │ ├── blue │ │ └── tls_everywhere.yml │ └── yellow │ │ └── strong_passwords.yml ├── good-skills │ ├── blue │ │ └── tls_everywhere.yml │ └── yellow │ │ └── strong_passwords.yml ├── composer-test.js ├── skills-test.js └── state-test.js ├── server ├── routes │ ├── index.js │ ├── skill.js │ ├── leaderboard.js │ ├── badges.js │ ├── teams.js │ └── api.js ├── views │ ├── error.pug │ ├── teams.pug │ ├── skill-item.pug │ ├── leaderboard.pug │ ├── badges.pug │ ├── layout.pug │ ├── index.pug │ └── team.pug ├── badge.js ├── config.js ├── middleware.js ├── db.js ├── app.js ├── skills.js ├── composer.js └── state.js ├── .editorconfig ├── Dockerfile ├── docker-compose.yml ├── bin └── security-belt-server ├── .eslintrc.json ├── scripts ├── migrations │ ├── 01-convert-timestamps-to-date-objects.js │ └── 00-add-skill-timestamps.js └── migration-runner.js ├── webpack.config.js ├── package.json ├── README.md └── LICENSE /.dockerignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | .git/ 3 | node_modules/ 4 | data/ 5 | screencast.gif 6 | -------------------------------------------------------------------------------- /.talismanignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | config/skills/ 3 | test/bad-skills/ 4 | test/good-skills/ -------------------------------------------------------------------------------- /screencast.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philippnormann/security-belt/HEAD/screencast.gif -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philippnormann/security-belt/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | node_modules 3 | *.log 4 | .idea 5 | data 6 | public/* 7 | !public/favicon.ico 8 | !public/logo.svg 9 | !public/logo.png 10 | build-stats.json 11 | -------------------------------------------------------------------------------- /config/badges/password-master.yaml: -------------------------------------------------------------------------------- 1 | title: Password master 2 | description: You have completed all password-related skills 3 | requiredSkills: 4 | - password_manager 5 | - strong_passwords 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 12 4 | before_script: 5 | - npm run build 6 | script: 7 | - npm test 8 | deploy: 9 | provider: heroku 10 | api_key: $HEROKU_AUTH_TOKEN 11 | -------------------------------------------------------------------------------- /config/badges/always-up-to-date.yaml: -------------------------------------------------------------------------------- 1 | title: Always up to date 2 | description: Your dependencies and software is always up to date. 3 | requiredSkills: 4 | - dependency_checks 5 | - software_updates 6 | -------------------------------------------------------------------------------- /app/styles/icon-sizes.scss: -------------------------------------------------------------------------------- 1 | .material-icons.md-18 { font-size: 18px; } 2 | .material-icons.md-24 { font-size: 24px; } 3 | .material-icons.md-36 { font-size: 36px; } 4 | .material-icons.md-48 { font-size: 48px; } -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # 2 | 3 | ## Proposed Changes 4 | 5 | - 6 | - 7 | - 8 | 9 | ## Additional Information (optional) 10 | 11 | *e.g. reasons behind your changes, description of algorithms, tools etc* -------------------------------------------------------------------------------- /config/skills/yellow/software_updates.yml: -------------------------------------------------------------------------------- 1 | title: Software updates 2 | why: Patch software regularly to prevent bugs and known vulnerabilities 3 | how: Have processes in place that notify you of new versions 4 | validation: Processes exist 5 | -------------------------------------------------------------------------------- /config/skills/brown/automate_everything.yml: -------------------------------------------------------------------------------- 1 | title: Automate everything 2 | why: Avoid human errors, ensure you can react fast 3 | how: Use Continuous deployment and continuous delivery 4 | validation: You can go on vacation without any risk 5 | -------------------------------------------------------------------------------- /app/styles/buttons.scss: -------------------------------------------------------------------------------- 1 | // Buttons 2 | .mdc-button.secondary-filled-button { 3 | @include mdc-button-filled-accessible($mdc-theme-secondary); 4 | } 5 | 6 | .mdc-button.primary-filled-button { 7 | @include mdc-button-filled-accessible($mdc-theme-primary); 8 | } 9 | -------------------------------------------------------------------------------- /config/skills/yellow/no_credentials_in_the_code.yml: -------------------------------------------------------------------------------- 1 | title: No credentials in the code 2 | why: Code can get into the wrong hands 3 | how: Use a credentials provider 4 | validation: Automated tests 5 | links: 6 | - Talisman: https://github.com/thoughtworks/talisman 7 | -------------------------------------------------------------------------------- /config/skills/blue/tls_everywhere.yml: -------------------------------------------------------------------------------- 1 | title: SSL everywhere 2 | why: Don't send data over unencrypted channels 3 | how: Use SSL for all services you offer and validate SSL certificates for all services you consume 4 | validation: Use nmap to ensure only port 443 is open 5 | -------------------------------------------------------------------------------- /test/bad-skills/blue/tls_everywhere.yml: -------------------------------------------------------------------------------- 1 | title: SSL everywhere 2 | why: Don't send data: over unencrypted channels 3 | how: Use SSL for all services you offer and validate SSL certificates for all services you consume 4 | validation: Use nmap to ensure only port 443 is open 5 | -------------------------------------------------------------------------------- /test/good-skills/blue/tls_everywhere.yml: -------------------------------------------------------------------------------- 1 | title: SSL everywhere 2 | why: Don't send data over unencrypted channels 3 | how: Use SSL for all services you offer and validate SSL certificates for all services you consume 4 | validation: Use nmap to ensure only port 443 is open 5 | -------------------------------------------------------------------------------- /server/routes/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const express = require('express'); 3 | const router = express.Router(); 4 | 5 | router.get('/', function (req, res) { 6 | res.render('index', { 7 | title: 'Security Belt' 8 | }); 9 | }); 10 | 11 | exports.router = router; -------------------------------------------------------------------------------- /config/skills/black/check_from_knuth.yml: -------------------------------------------------------------------------------- 1 | title: Get a check from Donald Knuth 2 | why: Prove that you have every bug in the world 3 | how: Fix a bug in tex 4 | validation: Post a photo of your check 5 | links: 6 | - Knuth reward: https://en.wikipedia.org/wiki/Knuth_reward_check 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | end_of_line = lf 10 | # editorconfig-tools is unable to ignore longs strings or urls 11 | max_line_length = null 12 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:12 2 | 3 | ENV SEC_BELT_HOME /home/node/security-belt 4 | ENV NODE_ENV production 5 | 6 | WORKDIR $SEC_BELT_HOME 7 | 8 | COPY . $SEC_BELT_HOME 9 | 10 | RUN chown -R node $SEC_BELT_HOME 11 | RUN npm install 12 | 13 | USER node 14 | 15 | ENTRYPOINT ["npm"] 16 | CMD ["start"] 17 | -------------------------------------------------------------------------------- /config/skills/orange/dependency_checks.yml: -------------------------------------------------------------------------------- 1 | title: Dependency checks 2 | why: Insecure libraries can affect the security of your application 3 | how: Regulary check your used dependancies for known vulnerabilities 4 | validation: Automated dependency checks in your build pipeline 5 | links: 6 | - OWASP Dependency Check: https://www.owasp.org/index.php/OWASP_Dependency_Check 7 | -------------------------------------------------------------------------------- /config/skills/yellow/strong_passwords.yml: -------------------------------------------------------------------------------- 1 | title: Strong passwords 2 | why: Prevent bruteforce attacks against your accounts 3 | how: Everyone in the team uses a password manage 4 | validation: All passwords are generated randomly 5 | links: 6 | - XKCD: https://www.explainxkcd.com/wiki/index.php/936:_Password_Strength 7 | - Password strength meter: https://howsecureismypassword.net/ 8 | -------------------------------------------------------------------------------- /test/bad-skills/yellow/strong_passwords.yml: -------------------------------------------------------------------------------- 1 | title: Strong passwords 2 | why: Prevent bruteforce attacks against your accounts 3 | how: Everyone in the team uses a password manage 4 | validation: All passwords are generated randomly 5 | links: 6 | - XKCD: https://www.explainxkcd.com/wiki/index.php/936:_Password_Strength 7 | - Password strength meter: https://howsecureismypassword.net/ 8 | -------------------------------------------------------------------------------- /test/good-skills/yellow/strong_passwords.yml: -------------------------------------------------------------------------------- 1 | title: Strong passwords 2 | why: Prevent bruteforce attacks against your accounts 3 | how: Everyone in the team uses a password manage 4 | validation: All passwords are generated randomly 5 | links: 6 | - XKCD: https://www.explainxkcd.com/wiki/index.php/936:_Password_Strength 7 | - Password strength meter: https://howsecureismypassword.net/ 8 | -------------------------------------------------------------------------------- /server/views/error.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | section(class='mdc-layout-grid') 5 | div(class='mdc-layout-grid__inner') 6 | div(class='center mdc-layout-grid__cell--span-12') 7 | h1(class='mdc-typography--display3 mdc-theme--accent')= message 8 | h2(class='mdc-typography--display2 mdc-theme--primary')= error.status 9 | pre #{error.stack} 10 | -------------------------------------------------------------------------------- /server/badge.js: -------------------------------------------------------------------------------- 1 | function teamHasBadge(team, badge) { 2 | let hasBadge = true; 3 | badge.requiredSkills.forEach((rs) => { 4 | if(hasBadge === false) { 5 | return; 6 | } 7 | const skill = team.skills.find(s => { return (s.id === rs) || (s.name === rs); }); 8 | if(!skill) { 9 | hasBadge = false; 10 | } 11 | }); 12 | 13 | return hasBadge; 14 | } 15 | 16 | exports.teamHasBadge = teamHasBadge; 17 | -------------------------------------------------------------------------------- /app/styles/badges.scss: -------------------------------------------------------------------------------- 1 | .mdc-card.badge { 2 | background: $mdc-theme-primary; 3 | } 4 | 5 | .mdc-card.badge .mdc-list { 6 | background: $mdc-theme-primary-dark; 7 | } 8 | 9 | .mdc-card.badge { 10 | margin-bottom: 1em; 11 | } 12 | 13 | .mdc-card.badge .mdc-list:last-child { 14 | margin-top: 1em; 15 | } 16 | 17 | .badge--achieved { 18 | color: #43A047; 19 | } 20 | 21 | .badge--unachieved { 22 | color: #E53935; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /config/skills/yellow/password_manager.yml: -------------------------------------------------------------------------------- 1 | title: Personal password manager 2 | why: Only strong passwords are good passwords. You should not be able to memorize them 3 | how: Everyone in the team uses a password manager 4 | validation: Ask all your team members 5 | links: 6 | - Pass (CLI): https://www.passwordstore.org/ 7 | - KeePass: http://keepass.info/ 8 | - 1Password: https://1password.com/ 9 | - Enpass: https://www.enpass.io/ 10 | -------------------------------------------------------------------------------- /app/styles/belts.scss: -------------------------------------------------------------------------------- 1 | $belt-colors: ( 2 | white-belt: #FAFAFA, 3 | yellow-belt: #F9A825, 4 | orange-belt: #EF6C00, 5 | green-belt: #2E7D32, 6 | blue-belt: #1565C0, 7 | brown-belt: #4E342E, 8 | black-belt: #212121 9 | ); 10 | 11 | @each $belt, $color in $belt-colors { 12 | .#{$belt} { 13 | background: $color !important; 14 | } 15 | .#{$belt}-text { 16 | color: $color !important; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | ## Scope 3 | 4 | **I'm submitting a ... ** 5 | 6 | - [ ] bug report 7 | - [ ] feature request 8 | 9 | ## Expected Behavior 10 | 11 | 12 | ## Actual Behavior 13 | 14 | 15 | ## Steps to Reproduce the Problem 16 | 17 | 1. 18 | 2. 19 | 3. 20 | 21 | ## Specifications 22 | 23 | - Version: 24 | - Platform: 25 | - Subsystem: 26 | 27 | ## Additional Information 28 | 29 | *e.g. helpful links, suggestions on how to fix the issue etc* -------------------------------------------------------------------------------- /app/styles/toolbar.scss: -------------------------------------------------------------------------------- 1 | .mdc-toolbar__section a { 2 | text-decoration: none; 3 | } 4 | 5 | .mdc-toolbar__title { 6 | padding: 8px; 7 | } 8 | 9 | .toolbar-nav .mdc-toolbar__section--align-end { 10 | position: absolute; 11 | right: 0; 12 | bottom: -8px; 13 | } 14 | 15 | .mdc-tab-bar__indicator{ 16 | background: $text-color; 17 | } 18 | 19 | .mdc-ripple-upgraded::before, .mdc-ripple-upgraded::after { 20 | background-color: hsla(0,0%,100%,.33) !important; 21 | } 22 | -------------------------------------------------------------------------------- /config/skills/yellow/input_validation.yml: -------------------------------------------------------------------------------- 1 | title: Input Validation 2 | why: Prevent malformed data from entering the system. This can also prevent XSS attacks 3 | how: Validate all the data that is entering your system syntactically and semantically 4 | validation: Automated tests 5 | links: 6 | - Input Validation Cheat Sheet: https://www.owasp.org/index.php/Input_Validation_Cheat_Sheet 7 | - Testing for Input Validation: https://www.owasp.org/index.php/Testing_for_Input_Validation 8 | 9 | -------------------------------------------------------------------------------- /app/styles/card-grid.scss: -------------------------------------------------------------------------------- 1 | .card-grid { 2 | column-count: 1; 3 | column-gap: 1em; 4 | } 5 | 6 | @media only screen and (min-width: 600px) { 7 | .card-grid { 8 | column-count: 2; 9 | } 10 | } 11 | 12 | @media only screen and (min-width: 1200px) { 13 | .card-grid { 14 | column-count: 3; 15 | } 16 | } 17 | 18 | .mdc-card { 19 | margin: 0.25rem; 20 | display: inline-block; 21 | width: 100%; 22 | } 23 | 24 | .mdc-card__info { 25 | background-color: #424242; 26 | } 27 | -------------------------------------------------------------------------------- /config/skills/green/evil_user_stories.yml: -------------------------------------------------------------------------------- 1 | title: Evil user stories 2 | why: The earlier you find a security flaw, the cheaper it is to fix it. Security is built in, not added on 3 | how: Write evil user stories out of the perspective of a potential attacker and perform security-focused code reviews 4 | validation: Evil user stories are part of every sprint backlog 5 | links: 6 | - Don't Forget EVIL User Stories: https://www.owasp.org/index.php/Agile_Software_Development:_Don%27t_Forget_EVIL_User_Stories 7 | -------------------------------------------------------------------------------- /config/teams.json: -------------------------------------------------------------------------------- 1 | { 2 | "teams": [ 3 | { 4 | "name": "Team 1", 5 | "champion": { 6 | "name": "Chuck Norris", 7 | "email": "chuck.norris@example.com" 8 | } 9 | }, 10 | { 11 | "name": "Team 2", 12 | "champion": { 13 | "name": "Bruce Schneier", 14 | "email": "bruce.schneier@example.com" 15 | } 16 | }, 17 | { 18 | "name": "Operations", 19 | "champion": { 20 | "name": "Ernie", 21 | "email": "ernie@example.com" 22 | } 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | 3 | services: 4 | belt-server: 5 | build: ./ 6 | container_name: belt-server 7 | environment: 8 | - DB_HOST=belt-mongo 9 | - NODE_ENV=development 10 | ports: 11 | - "3000:3000" 12 | mem_limit: 250mb 13 | memswap_limit: 250mb 14 | depends_on: 15 | - belt-mongo 16 | belt-mongo: 17 | image: mongo 18 | container_name: belt-mongo 19 | volumes: 20 | - ./data/db:/data/db 21 | ports: 22 | - "27017:27017" 23 | mem_limit: 250mb 24 | memswap_limit: 250mb 25 | -------------------------------------------------------------------------------- /bin/security-belt-server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const yargs = require('yargs'); 4 | const securityBelt = require('../server/app'); 5 | 6 | function startServer(yargs) { 7 | const { port } = yargs 8 | .option('port', { 9 | describe: 'HTTP port. Takes precedence before configuration', 10 | default: (process.env.PORT || 3000) 11 | }).argv; 12 | // Start up the server 13 | securityBelt.startServer(port); 14 | } 15 | 16 | yargs.usage('$0 command') 17 | .command('start', 'Start security belt server', startServer) 18 | .demand(1, 'must provide a valid command') 19 | .help('help') 20 | .argv; 21 | -------------------------------------------------------------------------------- /server/views/teams.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | 5 | div(class='mdc-layout-grid') 6 | div(class='mdc-layout-grid__inner') 7 | 8 | div(class='center mdc-layout-grid__cell--span-12') 9 | div(class='card-grid') 10 | 11 | each team in teams 12 | a(href=`/teams/${encodeURI(team.name)}`) 13 | div(data-mdc-auto-init='MDCRipple' class=`mdc-card ${team.belt}-belt`) 14 | section(class='mdc-card__primary center') 15 | h1(class=`mdc-card__title mdc-typography--headline ${team.belt == 'white' ? 'black-belt-text' : 'white-belt-text'}`)= team.name 16 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true, 4 | "es6": true 5 | }, 6 | "extends": "eslint:recommended", 7 | "parserOptions": { 8 | "ecmaVersion": 8, 9 | "ecmaFeatures": { 10 | "experimentalObjectRestSpread": true 11 | }, 12 | "sourceType": "module" 13 | }, 14 | "rules": { 15 | "indent": [ 16 | "error", 17 | 2 18 | ], 19 | "linebreak-style": [ 20 | "error", 21 | "unix" 22 | ], 23 | "quotes": [ 24 | "warn", 25 | "single" 26 | ], 27 | "semi": [ 28 | "error", 29 | "always" 30 | ], 31 | "no-console": ["warn", { 32 | "allow": ["log","warn", "error"] 33 | }] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/js/client.js: -------------------------------------------------------------------------------- 1 | /* eslint-env browser */ 2 | 'use strict'; 3 | 4 | import '../styles/style.scss'; 5 | 6 | import mdcAutoInit from '@material/auto-init'; 7 | import {MDCRipple} from '@material/ripple'; 8 | import {MDCTabBar, MDCTabBarScroller} from '@material/tabs'; 9 | import {initSkillActions} from "./skillToggle"; 10 | import {initTabbing} from './skillFilter'; 11 | 12 | mdcAutoInit.register('MDCTabBarScroller', MDCTabBarScroller); 13 | mdcAutoInit.register('MDCTabBar', MDCTabBar); 14 | mdcAutoInit.register('MDCRipple', MDCRipple); 15 | mdcAutoInit(); 16 | 17 | initTabbing(); // This needs to happen after UI is initialized since we remove one of the tab-indicators here. 18 | initSkillActions(); 19 | -------------------------------------------------------------------------------- /server/config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | const config = { 4 | server: { 5 | httpPort: process.env.PORT || 3000, 6 | publicPath: path.resolve(__dirname, '../public'), 7 | views: path.resolve(__dirname, 'views') 8 | }, 9 | database: { 10 | host: process.env.DB_HOST || '127.0.0.1:27017', 11 | database: process.env.DB_NAME || 'security-belt', 12 | collection: process.env.DB_COLLECTION || 'belt', 13 | user: process.env.DB_USER, 14 | password: process.env.DB_PASS, 15 | uri: process.env.DB_URI 16 | }, 17 | data: { 18 | skills: path.resolve(__dirname, '../config/skills'), 19 | badges: path.resolve(__dirname, '../config/badges'), 20 | teams: path.resolve(__dirname, '../config/teams.json') 21 | } 22 | }; 23 | 24 | module.exports = config; 25 | -------------------------------------------------------------------------------- /server/routes/skill.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const express = require('express'); 3 | const router = express.Router(); 4 | const state = require('../state'); 5 | const skills = require('../skills'); 6 | 7 | skills.getFileNames().then((fileNames) => { 8 | router.post('/toggle', async function (req, res) { 9 | state.toggleSkill(req.body.team, req.body.skill).then(() => { 10 | return state.teamSkills(req.body.team); 11 | }).then((teamSkills) => { 12 | const belt = state.belt(teamSkills, fileNames); 13 | res.status(200).send({ 14 | belt: belt 15 | }); 16 | }).catch((error) => { 17 | res.status(404).send({ 18 | error: error.message 19 | }); 20 | }); 21 | }); 22 | }).catch((err) => { 23 | console.error(err); 24 | }); 25 | 26 | exports.router = router; 27 | -------------------------------------------------------------------------------- /server/views/skill-item.pug: -------------------------------------------------------------------------------- 1 | div(class=`mdc-card skill-item skill-item__${skill.state}` data-team-name=team.name data-skill-id=skill.id data-skill-state=skill.state data-skill-rank=skill.rank) 2 | section(class='mdc-card__primary') 3 | h1(class='mdc-card__title mdc-typography--headline')= skill.title 4 | section(class='mdc-card__supporting-text') 5 | span(class='skill-section') Description 6 | p= skill.why 7 | span(class='skill-section') Implementation 8 | p= skill.how 9 | span(class='skill-section') Validation 10 | p= skill.validation 11 | if skill.links.length 12 | section(class='mdc-card__actions') 13 | each link in skill.links 14 | a(class='mdc-card__action' href=link.url) 15 | button(data-mdc-auto-init='MDCRipple' class='mdc-button mdc-button--raised primary-filled-button')= link.title 16 | -------------------------------------------------------------------------------- /app/styles/leaderboard.scss: -------------------------------------------------------------------------------- 1 | .mdc-list { 2 | @include mdc-elevation(2); 3 | } 4 | 5 | .mdc-list-item { 6 | border-bottom: 1px solid rgba(0, 0, 0, 0.1); 7 | border-bottom: 1px solid rgba(0, 0, 0, 0.1); 8 | } 9 | 10 | .mdc-list--avatar-list .mdc-list-item__graphic { 11 | @include mdc-elevation(1); 12 | line-height: 40px; 13 | } 14 | 15 | .mdc-list--avatar-list .mdc-list-item__graphic:before { 16 | content: '\00a0'; 17 | } 18 | .mdc-list--avatar-list .mdc-list-item__graphic:after { 19 | content: '.'; 20 | } 21 | 22 | .mdc-list--avatar-list .mdc-list-item__meta { 23 | @include mdc-elevation(1); 24 | padding: 4px 12px; 25 | width: auto; 26 | height: auto; 27 | background: $mdc-theme-accent; 28 | color: $text-color; 29 | border-radius: 3px; 30 | } 31 | 32 | .mdc-list--avatar-list .mdc-list-item__meta:after { 33 | content: ' Skills'; 34 | } 35 | -------------------------------------------------------------------------------- /app/styles/skills.scss: -------------------------------------------------------------------------------- 1 | .team-info h1, 2 | .team-info h2, 3 | .team-info h3 { 4 | margin: 10px; 5 | } 6 | 7 | .mdc-card { 8 | cursor: pointer; 9 | transition: background-color 300ms ease-in-out; 10 | } 11 | 12 | .skill-section { 13 | font-weight: 700; 14 | } 15 | 16 | .mdc-card__title { 17 | margin: 0; 18 | } 19 | 20 | .mdc-card__primary, .mdc-card__supporting-text { 21 | padding: 16px; 22 | } 23 | 24 | .mdc-card__supporting-text { 25 | padding-top: 0; 26 | } 27 | 28 | .mdc-card__supporting-text p:last-child { 29 | margin-bottom: 0; 30 | } 31 | 32 | .mdc-card__actions { 33 | flex-wrap: wrap; 34 | } 35 | 36 | .mdc-card__actions .mdc-card__action { 37 | margin-bottom: 8px; 38 | margin-right: 8px; 39 | } 40 | 41 | .skill-item { 42 | transition: background-color 300ms ease-in-out; 43 | margin: 5px; 44 | 45 | &__closed { 46 | background-color: #43A047; 47 | } 48 | 49 | &__open { 50 | background-color: #E53935; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /server/routes/leaderboard.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const express = require('express'); 4 | const state = require('../state'); 5 | const badge = require('../badge'); 6 | 7 | const router = express.Router(); 8 | 9 | router.get('/', function (req, res) { 10 | state.getTeams().then(async (teams) => { 11 | teams.sort((a, b) => { 12 | return b.skillCount - a.skillCount; 13 | }); 14 | const allBadges = await state.getBadges(); 15 | const teamsWithBadges = teams.map(t => { 16 | const withBadges = Object.assign({}, t); 17 | withBadges.badges = { 18 | completed: allBadges.filter(b => badge.teamHasBadge(t, b)).length, 19 | total: allBadges.length 20 | }; 21 | return withBadges; 22 | }); 23 | res.render('leaderboard', { 24 | title: 'Leaderboard', 25 | teams: teamsWithBadges 26 | }); 27 | }).catch((err) => { 28 | console.error(err); 29 | res.status(500).send('Error getting teams!'); 30 | }); 31 | }); 32 | 33 | exports.router = router; 34 | -------------------------------------------------------------------------------- /server/views/leaderboard.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | div(class='mdc-layout-grid') 5 | div(class='mdc-layout-grid__inner') 6 | 7 | ul(class='mdc-list mdc-list--avatar-list mdc-layout-grid__cell--span-12') 8 | - rank = 1 9 | - lastSkillCount = 0 10 | each team in teams 11 | if team.belt == 'white' 12 | - rankTextColor = 'black' 13 | else 14 | - rankTextColor = 'white' 15 | a(href=`/teams/${encodeURI(team.name)}` class='mdc-list-item' data-mdc-auto-init='MDCRipple') 16 | span(class=`mdc-list-item__graphic center ${team.belt}-belt ${rankTextColor}-belt-text`)= rank 17 | = team.name 18 | div(class='mdc-list-item__meta') 19 | span= `${team.badges.completed} / ${team.badges.total} Badges` 20 | span(class='divider__vertical') 21 | span= team.skillCount 22 | 23 | if lastSkillCount != team.skillCount 24 | - rank++ 25 | - lastSkillCount = team.skillCount 26 | -------------------------------------------------------------------------------- /server/middleware.js: -------------------------------------------------------------------------------- 1 | exports.httpsRedirect = function (req, res, next) { 2 | if (process.env.NODE_ENV !== 'production' || req.headers['x-forwarded-proto'] === 'https') { 3 | return next(); 4 | } 5 | res.redirect('https://' + req.headers.host + req.url); 6 | }; 7 | 8 | exports.notFound = function(req, res) { 9 | res.locals.message = 'Sorry! Nothing here...'; 10 | res.locals.error = { status: 404 }; 11 | res.status(404).render('error'); 12 | }; 13 | 14 | exports.error = function(err, req, res) { 15 | // set locals, only providing error in development 16 | res.locals.message = err.message; 17 | res.locals.error = req.app.get('env') === 'development' ? err : {}; 18 | 19 | // render the error page 20 | res.status(err.status || 500); 21 | res.render('error'); 22 | }; 23 | 24 | exports.cors = function(req, res, next) { 25 | res.header('Access-Control-Allow-Origin', '*'); 26 | res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); 27 | res.header('Access-Control-Allow-Methods', 'GET, HEAD'); 28 | next(); 29 | }; 30 | -------------------------------------------------------------------------------- /server/db.js: -------------------------------------------------------------------------------- 1 | const { MongoClient } = require('mongodb'); 2 | const config = require('./config'); 3 | 4 | function getMongoUri({ host, database, user, password, uri }) { 5 | if (uri) { 6 | return uri 7 | } else if (user && password) { 8 | return `mongodb://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}/${database}?authMechanism=DEFAULT`; 9 | } 10 | return `mongodb://${host}/${database}`; 11 | } 12 | 13 | /** 14 | * Singleton for storing the connection 15 | */ 16 | function Mongo() { 17 | let conn = null; 18 | let db = null; 19 | let collection = null; 20 | 21 | async function getConnection() { 22 | if (db && collection) { 23 | return collection; 24 | } 25 | 26 | conn = await MongoClient.connect(getMongoUri(config.database), { useNewUrlParser: true }); 27 | db = conn.db(config.database.database); 28 | collection = db.collection(config.database.collection); 29 | return collection; 30 | } 31 | 32 | async function closeConnection() { 33 | if (conn) 34 | await conn.close(); 35 | } 36 | 37 | return { 38 | getConnection, 39 | closeConnection 40 | }; 41 | } 42 | 43 | module.exports = Mongo(); 44 | -------------------------------------------------------------------------------- /scripts/migrations/01-convert-timestamps-to-date-objects.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | function isMigrated(team) { 3 | return team.skills.every(skill => { 4 | return (skill.since instanceof Date); 5 | }); 6 | } 7 | 8 | function checkDB(collection) { 9 | return new Promise((resolve, reject) => { 10 | collection.find().toArray().then((teams) => { 11 | if (teams.every(isMigrated)) 12 | reject(Error('all teams are already migrated')); 13 | else 14 | resolve(); 15 | }); 16 | }); 17 | } 18 | 19 | function migrateTeam(team) { 20 | team.skills = team.skills.map((skill) => { 21 | return { 22 | name: skill.name, 23 | since: new Date(skill.since) 24 | }; 25 | }); 26 | return team; 27 | } 28 | 29 | function migrateDB(collection) { 30 | return collection.find({ skills : { $ne: [] }}) 31 | .toArray().then((teams) => { 32 | const migratedTeams = teams.map(migrateTeam); 33 | const promises = migratedTeams.map((team) => { 34 | return collection.replaceOne({ _id: team._id }, team); 35 | }); 36 | return Promise.all(promises); 37 | }); 38 | } 39 | 40 | exports.checkDB = checkDB; 41 | exports.migrateDB = migrateDB; 42 | -------------------------------------------------------------------------------- /scripts/migrations/00-add-skill-timestamps.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | function isMigrated(team) { 3 | return team.skills.every(skill => { 4 | return (skill.name != undefined && skill.since != undefined); 5 | }); 6 | } 7 | 8 | function checkDB(collection) { 9 | return new Promise((resolve, reject) => { 10 | collection.find().toArray().then((teams) => { 11 | if (teams.every(isMigrated)) 12 | reject(Error('all teams are already migrated')); 13 | else 14 | resolve(); 15 | }); 16 | }); 17 | } 18 | 19 | function migrateTeam(team) { 20 | team.skills = team.skills.map((skill) => { 21 | return { 22 | name: skill, 23 | since: new Date().toISOString() 24 | }; 25 | }); 26 | return team; 27 | } 28 | 29 | function migrateDB(collection) { 30 | return collection.find({ skills : { $ne: [] }}) 31 | .toArray().then((teams) => { 32 | const migratedTeams = teams.map(migrateTeam); 33 | const promises = migratedTeams.map((team) => { 34 | return collection.replaceOne({ _id: team._id }, team); 35 | }); 36 | return Promise.all(promises); 37 | }); 38 | } 39 | 40 | exports.checkDB = checkDB; 41 | exports.migrateDB = migrateDB; 42 | -------------------------------------------------------------------------------- /server/routes/badges.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const Router = express.Router(); 3 | const state = require('../state'); 4 | const skills = require('../skills'); 5 | const { teamHasBadge } = require('../badge'); 6 | 7 | Router.get('/', async (req, res) => { 8 | const badges = await state.getBadges(); 9 | const teams = await state.getTeams(); 10 | const allSkillsByBelt = await skills.get(); 11 | const allSkillsFlat = []; 12 | Object.keys(allSkillsByBelt).forEach((color) => { 13 | allSkillsFlat.push(...allSkillsByBelt[color]); 14 | }); 15 | const badgesWithSkillInfos = []; 16 | badges.forEach((badge) => { 17 | const requiredSkills = badge.requiredSkills.map((id) => { 18 | return allSkillsFlat.find(s => s.fileName === id); 19 | }); 20 | const badgeWithInfos = Object.assign({}, badge, { requiredSkills: requiredSkills }); 21 | badgeWithInfos.teams = teams.map((t) => { 22 | const hasAchievedBadge = teamHasBadge(t, badge); 23 | return { 24 | teamName: t.name, 25 | hasBadge: hasAchievedBadge 26 | }; 27 | }); 28 | badgesWithSkillInfos.push(badgeWithInfos); 29 | }); 30 | res.render('badges', { 31 | title: 'Badges', 32 | badges: badgesWithSkillInfos 33 | }); 34 | }); 35 | 36 | exports.router = Router; 37 | -------------------------------------------------------------------------------- /server/routes/teams.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const express = require('express'); 3 | const skills = require('../skills'); 4 | const state = require('../state'); 5 | const composer = require('../composer'); 6 | 7 | const router = express.Router(); 8 | 9 | /* eslint-disable no-unused-vars */ 10 | skills.get().then((_) => { 11 | router.get('/:teamName', async (req, res) => { 12 | const teamName = decodeURI(req.params.teamName); 13 | if (state.getTeamNames().includes(teamName)) { 14 | try { 15 | const repr = await composer.getTeamRepresentation(teamName); 16 | res.render('team', { 17 | title: repr.name, 18 | team: repr 19 | }); 20 | } catch(err) { 21 | console.error(err); 22 | res.status(500).send('Error getting team status!'); 23 | } 24 | } else { 25 | res.status(404).send('Team not found!'); 26 | } 27 | }); 28 | }).catch((err) => { 29 | console.error(err); 30 | }); 31 | 32 | 33 | router.get('/', (req, res) => { 34 | state.getTeams().then((teams) => { 35 | res.render('teams', { 36 | 'title': 'Teams', 37 | 'teams': teams 38 | }); 39 | }).catch((err) => { 40 | console.error(err); 41 | res.status(500).send('Error getting teams!'); 42 | }); 43 | }); 44 | 45 | exports.router = router; 46 | -------------------------------------------------------------------------------- /server/views/badges.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | 5 | div(class='mdc-layout-grid') 6 | div(class='mdc-layout-grid__inner') 7 | div(class='center mdc-layout-grid__cell--span-12') 8 | div 9 | each badge in badges 10 | div(class='mdc-card badge') 11 | section(class='mdc-card__primary') 12 | h1(class='mdc-card__title mdc-typography--headline')= badge.title 13 | section(class='mdc-card__supporting-text') 14 | span(class='skill-section') Description 15 | p= badge.description 16 | ul(class='mdc-list') 17 | each skill in badge.requiredSkills 18 | li(class='mdc-list-item' data-mdc-auto-init='MDCRipple')= skill.title 19 | section(class='mdc-card__supporting-text') 20 | span(class='skill-section') Team List 21 | ul(class='mdc-list') 22 | each team in badge.teams 23 | a(href=`/teams/${team.teamName}` class=`mdc-list-item` data-mdc-auto-init='MDCRipple') 24 | if team.hasBadge 25 | i(class='mdc-list-item__graphic material-icons') done 26 | else 27 | i(class='mdc-list-item__graphic material-icons') error 28 | =team.teamName 29 | -------------------------------------------------------------------------------- /server/views/layout.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html(class='mdc-typography') 3 | head 4 | title= title 5 | meta(http-equiv='Content-Type' content='text/html; charset=UTF-8') 6 | meta(name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1.0') 7 | link(rel='stylesheet' type='text/css' href='/style.css') 8 | link(rel='stylesheet' href='https://fonts.googleapis.com/icon?family=Material+Icons') 9 | 10 | body(class='mdc-theme--background') 11 | header(class='mdc-toolbar mdc-toolbar--fixed') 12 | div(class='mdc-toolbar__row toolbar-nav') 13 | 14 | section(class='mdc-toolbar__section mdc-toolbar__section--shrink-to-fit mdc-toolbar__section--align-start') 15 | a(href='/') 16 | h1(class='mdc-toolbar__title') Security Belt 17 | section(class='mdc-toolbar__section mdc-toolbar__section--shrink-to-fit mdc-toolbar__section--align-end') 18 | nav(class='mdc-tab-bar' data-mdc-auto-init='MDCTabBar') 19 | - var items = { teams : 'Teams', leaderboard: 'Leaderboard', badges: 'Badges'} 20 | for item, path in items 21 | if (item === title) 22 | a(class='mdc-tab mdc-tab--active' href='/' + path)= item 23 | else 24 | a(class='mdc-tab' href='/' + path)= item 25 | span(class='mdc-tab-bar__indicator') 26 | 27 | 28 | div(class='page__content') 29 | block content 30 | 31 | script(src='/app.bundle.js') 32 | -------------------------------------------------------------------------------- /server/routes/api.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const express = require('express'); 4 | const state = require('../state'); 5 | const router = express.Router(); 6 | 7 | router.get('/stats', async (req, res) => { 8 | const days = req.query.days || 14; 9 | const progress = await state.getGraph(days); 10 | res.json({progress}); 11 | }); 12 | 13 | router.get('/stats/:teamName', async (req, res) => { 14 | const teamName = decodeURI(req.params.teamName); 15 | if (state.getTeamNames().includes(teamName)) { 16 | const days = req.query.days || 14; 17 | const progress = await state.getTeamGraph(teamName, days); 18 | res.json({progress}); 19 | } else { 20 | res.status(404).json({error: `Team ${teamName} not found!`}); 21 | } 22 | }); 23 | 24 | router.get('/teams', async (req, res) => { 25 | try { 26 | const teams = await state.getTeams(); 27 | res.json({teams}); 28 | } catch (err) { 29 | console.error(err); 30 | res.status(500).json({error: 'Error getting teams'}); 31 | } 32 | }); 33 | 34 | router.get('/teams/:teamName', async (req, res) => { 35 | const teamName = decodeURI(req.params.teamName); 36 | if (state.getTeamNames().includes(teamName)) { 37 | try { 38 | const team = await state.getTeam(teamName); 39 | res.json(team); 40 | } catch (err) { 41 | console.error(err); 42 | res.status(500).json({error: `Error getting team ${teamName}`}); 43 | } 44 | } else { 45 | res.status(404).json({error: `Team ${teamName} not found!`}); 46 | } 47 | }); 48 | 49 | exports.router = router; 50 | -------------------------------------------------------------------------------- /scripts/migration-runner.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | const walk = require('walk'); 5 | const Mongo = require('../server/db'); 6 | 7 | let migrationNames = []; 8 | 9 | function readMigrations() { 10 | return new Promise((resolve, reject) => { 11 | const walker = walk.walk(__dirname + '/migrations'); 12 | walker.on('file', (root, fileStats, next) => { 13 | if (fileStats.name.endsWith('.js')) 14 | migrationNames.push(fileStats.name); 15 | next(); 16 | }); 17 | walker.on('errors', (root, nodeStatsArray, next) => 18 | next() 19 | ); 20 | walker.on('end', () => { 21 | migrationNames.sort(); 22 | migrationNames.length > 0 ? resolve() : reject(); 23 | }); 24 | }); 25 | } 26 | 27 | async function runMigrations() { 28 | const collection = await Mongo.getConnection(); 29 | let migrationPromises = migrationNames.map((migration) => { 30 | const script = require('./migrations/' + migration); 31 | if (script.checkDB && script.migrateDB) 32 | return script.checkDB(collection) 33 | .then(() => { 34 | console.log(`Applied ${migration}`); 35 | return script.migrateDB(collection); 36 | }).catch(() => { 37 | console.log(`Skipped ${migration}`); 38 | return Promise.resolve(); 39 | }); 40 | else 41 | return Promise.reject(); 42 | }); 43 | return Promise.all(migrationPromises); 44 | } 45 | 46 | readMigrations() 47 | .then(() => runMigrations()) 48 | .then(() => Mongo.closeConnection()) 49 | .catch((err) => { 50 | console.error(err); 51 | Mongo.closeConnection(); 52 | }); 53 | -------------------------------------------------------------------------------- /test/composer-test.js: -------------------------------------------------------------------------------- 1 | const sinon = require('sinon'); 2 | const assert = require('assert'); 3 | const composer = require('../server/composer'); 4 | const state = require('../server/state'); 5 | const skills = require('../server/skills'); 6 | 7 | describe('Composer', () => { 8 | describe('getTeamRepresentation()', () => { 9 | it('should return the right team', async () => { 10 | sinon.stub(state, 'getTeam').returns({ 11 | name: 'Team 1', 12 | belt: 'white', 13 | skillCount: 1, 14 | skills: [ 15 | { name: 'my-skill' } 16 | ] 17 | }); 18 | sinon.stub(skills, 'get').resolves({ 19 | yellow: [ 20 | { name: 'my-skill', fileName: 'my-skill', title: 'My skill' } 21 | ] 22 | }); 23 | sinon.stub(state, 'getBadges').returns([ 24 | { id: 'my-badge', title: 'My badge', requiredSkills: ['my-skill'] } 25 | ]); 26 | const teamname = 'Team 1'; 27 | const result = await composer.getTeamRepresentation(teamname); 28 | assert.equal(result.id, 'team-1'); 29 | assert.equal(result.name, teamname); 30 | assert.equal(result.belt, 'white'); 31 | assert.equal(result.skillCount, 1); 32 | assert.deepEqual(result.skills, [ 33 | { title: 'My skill', id: 'my-skill', name: 'my-skill', rank: 'yellow', state: 'closed', links: [], badges: ['my-badge'] } 34 | ]); 35 | assert.deepEqual(result.badges, [ 36 | { 37 | id: 'my-badge', 38 | isComplete: true, 39 | title: 'My badge', 40 | requiredSkills: [ 41 | { id: 'my-skill' } 42 | ] 43 | } 44 | ]); 45 | }); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /app/styles/style.scss: -------------------------------------------------------------------------------- 1 | $mdc-theme-primary: #3F51B5; 2 | $mdc-theme-accent: #FF5722; 3 | $mdc-theme-background: #263238; 4 | 5 | @import '~normalize.css/normalize'; 6 | 7 | @import '~@material/theme/mdc-theme'; 8 | @import '~@material/typography/mdc-typography'; 9 | @import '~@material/toolbar/mdc-toolbar'; 10 | @import '~@material/layout-grid/mdc-layout-grid'; 11 | @import '~@material/tabs/mdc-tabs'; 12 | @import '~@material/button/mdc-button'; 13 | @import "~@material/card/mdc-card"; 14 | @import "~@material/list/mdc-list"; 15 | @import "~@material/elevation/mdc-elevation"; 16 | @import "~@material/ripple/mdc-ripple"; 17 | @import '~roboto-fontface/css/roboto/roboto-fontface'; 18 | 19 | $text-color: #FAFAFA; 20 | 21 | @import 'icon-sizes'; 22 | @import 'belts'; 23 | @import 'buttons'; 24 | @import 'badges'; 25 | @import 'toolbar'; 26 | @import 'card-grid'; 27 | @import 'leaderboard'; 28 | @import 'skills'; 29 | 30 | body, a, p, h1, h2, h3, h4, .mdc-card__title, .skill-section { 31 | color: $text-color; 32 | } 33 | 34 | // Helper 35 | .center { 36 | justify-content: center; 37 | text-align: center; 38 | } 39 | 40 | // Layout 41 | .mdc-toolbar__row, .page__content { 42 | max-width: 1312px; 43 | padding: 0 16px; 44 | margin: 0 auto; 45 | } 46 | 47 | .page__content { 48 | margin-top: 83px; 49 | } 50 | 51 | .logo { 52 | vertical-align: top; 53 | height: 3.5rem; 54 | margin-right: 10px; 55 | } 56 | 57 | a, u { 58 | text-decoration: none !important; 59 | } 60 | 61 | .divider__vertical { 62 | border-left: 1px solid white; 63 | border-right: 1px solid white; 64 | position: relative; 65 | width: 1px; 66 | min-height: 80%; 67 | margin-right: 10px; 68 | margin-left: 10px; 69 | opacity: 0.7; 70 | } 71 | -------------------------------------------------------------------------------- /server/views/index.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | 5 | section(class='mdc-layout-grid') 6 | div(class='mdc-layout-grid__inner') 7 | 8 | div(class='center mdc-layout-grid__cell--span-12') 9 | h1(class='mdc-typography--display3 mdc-theme--accent') 10 | img(class='logo' src='/logo.svg' alt='logo') 11 | span= title 12 | h5(class='mdc-typography--headline') A framework for improving the IT-Security of your teams 13 | a(href='/teams') 14 | button(class='mdc-button mdc-button--raised secondary-filled-button' data-mdc-auto-init='MDCRipple') view teams 15 | 16 | section(class='mdc-layout-grid') 17 | div(class='mdc-layout-grid__inner') 18 | 19 | div(class='center mdc-layout-grid__cell') 20 | i(class='material-icons md-48 mdc-theme--primary') help 21 | h5(class='mdc-typography--title') Why? 22 | p It helps to achieve a higher level of transparency about the security status of the teams. 23 | p Additionally teams can compare eachother und can see which teams have fulfilled which skills in order to get help. 24 | 25 | div(class='center mdc-layout-grid__cell') 26 | i(class='material-icons md-48 mdc-theme--primary') library_add 27 | h5(class='mdc-typography--title') How? 28 | p Skills can be marked as fulfilled by clicking on them. (Please only do this for your own team) 29 | p The belt color changes automatically according to the fulfilled skills. 30 | 31 | div(class='center mdc-layout-grid__cell') 32 | i(class='material-icons md-48 mdc-theme--primary') call_merge 33 | h5(class='mdc-typography--title') Contribute 34 | p The whole content is available on #[a(href='https://github.com/otto-de/security-belt') GitHub] and we are happy about PRs! 35 | p Especially the content of the skills can be complemented with your experience. 36 | -------------------------------------------------------------------------------- /app/js/skillFilter.js: -------------------------------------------------------------------------------- 1 | /* eslint-env browser */ 2 | 'use strict'; 3 | 4 | const selectors = { 5 | badgeSelect: '.badge-select', 6 | skillCard: '.skill-list__item', 7 | rankTabs: '.rank-select', 8 | rankTab: '.rank-select__tab', 9 | teamInfo: '.team-info' 10 | }; 11 | 12 | function displayCards(predicate) { 13 | document.querySelectorAll(selectors.skillCard).forEach(function(card) { 14 | if(predicate(card.dataset)) { 15 | card.style.display = 'block'; 16 | } else { 17 | card.style.display = 'none'; 18 | } 19 | }); 20 | } 21 | 22 | export function initTabbing() { 23 | if(document.querySelector(selectors.teamInfo)) { 24 | document.querySelectorAll(selectors.rankTab).forEach(function(tab) { 25 | tab.addEventListener('click', function(e) { 26 | displayCards(cardData => cardData.skillRank === e.target.dataset.rank); 27 | const oldActive = document.querySelector('.rank-select__tab.mdc-tab--active'); 28 | if(oldActive) { 29 | oldActive.classList.toggle('mdc-tab--active'); 30 | } 31 | tab.classList.toggle('mdc-tab--active'); 32 | 33 | document.querySelector('.rank-select .tab-bar-indicator-marker').classList.add('mdc-tab-bar__indicator'); 34 | document.querySelector('.badge-select .tab-bar-indicator-marker').classList.remove('mdc-tab-bar__indicator'); 35 | }); 36 | }); 37 | 38 | document.querySelectorAll(selectors.badgeSelect).forEach(function(tab) { 39 | tab.addEventListener('click', function(e) { 40 | let elem = e.target; 41 | while (elem && !elem.dataset.badge) { 42 | elem = elem.parentNode; 43 | } 44 | displayCards(cardData => cardData.skillBadges.split(',').includes(elem.dataset.badge)); 45 | document.querySelector('.rank-select .tab-bar-indicator-marker').classList.remove('mdc-tab-bar__indicator'); 46 | document.querySelector('.badge-select .tab-bar-indicator-marker').classList.add('mdc-tab-bar__indicator'); 47 | }); 48 | }); 49 | 50 | const activeRank = document.querySelector(selectors.rankTabs).dataset.activeRank; 51 | displayCards(cardData => cardData.skillRank === activeRank); 52 | window.location.hash = activeRank; 53 | 54 | document.querySelector('.badge-select .tab-bar-indicator-marker').classList.remove('mdc-tab-bar__indicator'); 55 | } 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /app/js/skillToggle.js: -------------------------------------------------------------------------------- 1 | /* eslint-env browser */ 2 | const selectors = { 3 | skillItem: '.skill-item', 4 | beltText: '.team-info__belt' 5 | }; 6 | 7 | function capitalize(s){ 8 | return s.toLowerCase() 9 | .replace( /\b./g, function(a){ 10 | return a.toUpperCase(); 11 | }); 12 | } 13 | 14 | function toggleSkill(team, skill) { 15 | return fetch('/skill/toggle', { 16 | method: 'post', 17 | headers: { 18 | 'Accept': 'application/json', 19 | 'Content-Type': 'application/json' 20 | }, 21 | body: JSON.stringify({team, skill}) 22 | }); 23 | } 24 | 25 | function toggleSkillState(id) { 26 | const skill = document.querySelector(`${selectors.skillItem}[data-skill-id="${id}"]`); 27 | if(skill) { 28 | if(skill.classList.contains('skill-item__open')) { 29 | skill.classList.remove('skill-item__open'); 30 | skill.classList.add('skill-item__closed'); 31 | } else { 32 | skill.classList.remove('skill-item__closed'); 33 | skill.classList.add('skill-item__open'); 34 | } 35 | } 36 | } 37 | 38 | export function initSkillActions() { 39 | const skills = document.querySelectorAll(selectors.skillItem); 40 | skills.forEach(function(skill) { 41 | skill.addEventListener('click', function(e) { 42 | const card = e.target.closest(selectors.skillItem); 43 | const { skillId, teamName } = card.dataset; 44 | const skillTitle = skillId; 45 | 46 | toggleSkill(teamName, skillTitle) 47 | .then(async function(res) { 48 | const body = await res.json(); 49 | if(res.status === 404) { 50 | return; 51 | } 52 | 53 | const beltText = document.querySelector(selectors.beltText); 54 | beltText.innerHTML = `${capitalize(body.belt)}`; 55 | 56 | const oldBeltColor = document.querySelector(selectors.beltText).className.split(' ') 57 | .find(function(c) { 58 | return /.*-belt-text/.test(c); 59 | }); 60 | beltText.classList.remove(oldBeltColor); 61 | beltText.classList.add(`${body.belt}-belt-text`); 62 | 63 | card.dataset.skillState = card.dataset.skillState === 'open' ? 'closed' : 'open'; 64 | toggleSkillState(skillTitle); 65 | }) 66 | .catch(function(err) { 67 | console.error(`Failed to toggle skill ${skillTitle}:`, err); 68 | }); 69 | }); 70 | }); 71 | } 72 | -------------------------------------------------------------------------------- /test/skills-test.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | 'use strict'; 3 | const skills = require('../server/skills'); 4 | const assert = require('assert'); 5 | 6 | describe('Skills', () => { 7 | 8 | describe('extractFileNames()', () => { 9 | 10 | it('should return a map of belts to card filenames', () => { 11 | const testBelts = { 12 | yellow: [{ 13 | foo: 'bar', 14 | fileName: 'all_devices_encrypted' 15 | }] 16 | }; 17 | const expected = { 18 | yellow: ['all_devices_encrypted'] 19 | }; 20 | assert.deepEqual(skills.extractFileNames(testBelts), expected); 21 | }); 22 | 23 | }); 24 | 25 | describe('read()', () => { 26 | 27 | it('should resolve and return object representing the contents of the correctly formatted .yml files', async() => { 28 | const testPath = __dirname + '/good-skills'; 29 | const expected = { 30 | yellow: [{ 31 | title: 'Strong passwords', 32 | why: 'Prevent bruteforce attacks against your accounts', 33 | how: 'Everyone in the team uses a password manage', 34 | validation: 'All passwords are generated randomly', 35 | links: [{ 36 | 'XKCD': 'https://www.explainxkcd.com/wiki/index.php/936:_Password_Strength' 37 | }, { 38 | 'Password strength meter': 'https://howsecureismypassword.net/' 39 | }], 40 | fileName: 'strong_passwords' 41 | }], 42 | orange: [], 43 | green: [], 44 | blue: [{ 45 | title: 'SSL everywhere', 46 | why: 'Don\'t send data over unencrypted channels', 47 | how: 'Use SSL for all services you offer and validate SSL certificates for all services you consume', 48 | validation: 'Use nmap to ensure only port 443 is open', 49 | fileName: 'tls_everywhere' 50 | }], 51 | brown: [], 52 | black: [] 53 | }; 54 | const res = await skills.read(testPath); 55 | assert.deepEqual(res, expected); 56 | }); 57 | 58 | it('should reject with an error if .yml files contain syntax errors', () => { 59 | const testPath = __dirname + '/bad-skills'; 60 | return new Promise((resolve, reject) => { 61 | skills.read(testPath).then(() => { 62 | reject(Error('should not resolve with incorrectly formatted .yml files')); 63 | }).catch(() => { 64 | resolve(); 65 | }); 66 | }); 67 | }); 68 | 69 | }); 70 | 71 | }); 72 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const webpack = require('webpack'); 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 4 | 5 | const packageJson = require('./package'); 6 | const isProduction = process.env.NODE_ENV === 'production'; 7 | 8 | const webpackConfig = { 9 | cache: true, 10 | devtool: isProduction ? 'eval-source-map' : 'source-map', 11 | entry: { 12 | app: [ 13 | path.resolve(__dirname, 'app', 'js', 'client.js') 14 | ] 15 | }, 16 | output: { 17 | path: path.resolve(__dirname, 'public'), 18 | filename: '[name].bundle.js', 19 | sourceMapFilename: '[file].map', 20 | pathinfo: true, 21 | publicPath: '/', 22 | }, 23 | resolve: { 24 | extensions: [ 25 | '.js', 26 | '.css', 27 | '.scss' 28 | ] 29 | }, 30 | module: { 31 | rules: [ 32 | { 33 | test: /\.js$/, 34 | use: [ 35 | { 36 | loader: 'babel-loader', 37 | options: { 38 | presets: packageJson.babel.presets, 39 | cacheDirectory: true 40 | } 41 | } 42 | ], 43 | include: [ 44 | path.resolve(__dirname, 'node_modules'), 45 | path.resolve(__dirname, 'assets') 46 | ] 47 | }, 48 | { 49 | test: /\.(eot|woff|woff2|svg|ttf)$/, 50 | use: [ 51 | { 52 | loader: 'file-loader', 53 | options: { 54 | limit: 100000, 55 | } 56 | } 57 | ] 58 | }, 59 | { 60 | test: /\.scss$/, 61 | use: [ 62 | { 63 | loader: MiniCssExtractPlugin.loader 64 | } 65 | , 66 | { 67 | loader: 'css-loader', 68 | }, 69 | { 70 | loader: 'resolve-url-loader' 71 | }, 72 | { 73 | loader: 'sass-loader', 74 | options: { 75 | sourceMap: true, 76 | includePaths: [ 77 | path.resolve(__dirname, 'node_modules/') 78 | ] 79 | } 80 | } 81 | ], 82 | include: [ 83 | path.resolve(__dirname, 'node_modules'), 84 | path.resolve(__dirname, 'app') 85 | ] 86 | } 87 | ] 88 | }, 89 | plugins: [ 90 | new MiniCssExtractPlugin({ 91 | filename: 'style.css', 92 | }), 93 | new webpack.NoEmitOnErrorsPlugin() 94 | ] 95 | }; 96 | 97 | module.exports = webpackConfig; 98 | -------------------------------------------------------------------------------- /server/app.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const express = require('express'); 3 | const path = require('path'); 4 | const favicon = require('serve-favicon'); 5 | const bunyan = require('bunyan'); 6 | const bodyParser = require('body-parser'); 7 | 8 | const index = require('./routes/index'); 9 | const teams = require('./routes/teams'); 10 | const leaderboard = require('./routes/leaderboard'); 11 | const skill = require('./routes/skill'); 12 | const api = require('./routes/api'); 13 | const badges = require('./routes/badges'); 14 | const Mongo = require('./db'); 15 | const config = require('./config'); 16 | const middleware = require('./middleware'); 17 | const app = express(); 18 | const rootLogger = bunyan.createLogger({ 19 | name: 'securitybelt', 20 | level: process.env.SB_LOG_LEVEL || 'info', 21 | streams: [ 22 | { stream: process.stdout, level: 'info' } 23 | ], 24 | serializers: bunyan.stdSerializers 25 | }); 26 | 27 | if(process.env.SB_LOG_FILE) { 28 | rootLogger.addStream({ path: path.resolve(process.env.SB_LOG_FILE) }); 29 | } 30 | 31 | function requestLoggerMiddleware(req, res, next) { 32 | if(!req.logger) { 33 | req.logger = rootLogger.child({ label: 'http' }); 34 | } 35 | req.logger.info({ req }); 36 | next(); 37 | } 38 | 39 | function bindStatic(app, config) { 40 | app.set('views', config.server.views); 41 | app.set('view engine', 'pug'); 42 | app.use(favicon(path.join(config.server.publicPath, 'favicon.ico'))); 43 | app.use(express.static(config.server.publicPath)); 44 | } 45 | 46 | function bindBase(app) { 47 | app.use(requestLoggerMiddleware); 48 | app.use(bodyParser.json()); 49 | app.use(bodyParser.urlencoded({ 50 | extended: false 51 | })); 52 | } 53 | 54 | bindBase(app); 55 | bindStatic(app, config); 56 | 57 | app.use(middleware.httpsRedirect); 58 | app.use('/', index.router); 59 | app.use('/teams', teams.router); 60 | app.use('/skill', skill.router); 61 | app.use('/leaderboard', leaderboard.router); 62 | app.use('/api', middleware.cors); 63 | app.use('/api', api.router); 64 | app.use('/badges', badges.router); 65 | app.use(middleware.notFound); 66 | app.use(middleware.error); 67 | 68 | function startServer(httpPort) { 69 | app.set('port', httpPort); 70 | 71 | app.listen(app.get('port'), async () => { 72 | try { 73 | await Mongo.getConnection(); 74 | rootLogger.info('Connected to mongoDB'); 75 | } catch(ex) { 76 | rootLogger.error({ err, msg: `failed to connect to database` }); 77 | } 78 | rootLogger.info(`Server listening on http://localhost:${httpPort}`); 79 | }); 80 | } 81 | 82 | exports.startServer = startServer; 83 | exports.app = app; 84 | -------------------------------------------------------------------------------- /server/skills.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const yaml = require('js-yaml'); 4 | const fs = require('fs'); 5 | const walk = require('walk'); 6 | const config = require('./config'); 7 | 8 | let skills; 9 | let fileNames; 10 | 11 | function read(skillsFolder) { 12 | return new Promise((resolve, reject) => { 13 | const walker = walk.walk(skillsFolder); 14 | let skills = { 15 | yellow: [], 16 | orange: [], 17 | green: [], 18 | blue: [], 19 | brown: [], 20 | black: [] 21 | }; 22 | walker.on('file', (root, fileStats, next) => { 23 | fs.readFile(root + '/' + fileStats.name, (err, data) => { 24 | if (err) reject(err); 25 | let rootSplit = root.split(path.sep); 26 | let beltName = rootSplit[rootSplit.length - 1]; 27 | try { 28 | let skill = yaml.safeLoad(data); 29 | skill.fileName = fileStats.name.replace('.yml', ''); 30 | skills[beltName].push(skill); 31 | next(); 32 | } catch (err) { 33 | reject('Error while reading skill files: ' + err); 34 | } 35 | }); 36 | }); 37 | walker.on('errors', (root, nodeStatsArray, next) => 38 | next() 39 | ); 40 | walker.on('end', () => 41 | resolve(skills) 42 | ); 43 | }); 44 | } 45 | 46 | function get() { 47 | return new Promise((resolve, reject) => { 48 | if (skills === undefined) 49 | read(config.data.skills).then((res) => 50 | resolve(res) 51 | ).catch((err) => 52 | reject(err) 53 | ); 54 | else 55 | resolve(skills); 56 | }); 57 | } 58 | 59 | function extractFileNames(skills) { 60 | let res = {}; 61 | Object.keys(skills).map((beltName) => { 62 | res[beltName] = skills[beltName].map((skill) => { 63 | return skill.fileName; 64 | }); 65 | }); 66 | return res; 67 | } 68 | 69 | function getFileNames() { 70 | return new Promise((resolve, reject) => { 71 | if (fileNames === undefined) 72 | get().then((res) => { 73 | fileNames = extractFileNames(res); 74 | resolve(fileNames); 75 | }).catch((err) => reject(err)); 76 | else 77 | resolve(fileNames); 78 | }); 79 | } 80 | 81 | function getFlatFileNames() { 82 | return getFileNames().then((fileNames) => { 83 | let reducedFileNames = []; 84 | Object.keys(fileNames).map((belt) => { 85 | reducedFileNames = reducedFileNames.concat(fileNames[belt]); 86 | }); 87 | return Promise.resolve(reducedFileNames); 88 | }); 89 | } 90 | 91 | exports.get = get; 92 | exports.read = read; 93 | exports.extractFileNames = extractFileNames; 94 | exports.getFileNames = getFileNames; 95 | exports.getFlatFileNames = getFlatFileNames; 96 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "security-belt", 3 | "version": "1.0.1", 4 | "license": "Apache 2.0", 5 | "description": "A framework for improving the IT-Security of your teams through gamification.", 6 | "keywords": [ 7 | "security", 8 | "self-assessment", 9 | "gamification", 10 | "webapp" 11 | ], 12 | "repository": "github:otto-de/security-belt", 13 | "engines": { 14 | "node": "12" 15 | }, 16 | "private": true, 17 | "bin": { 18 | "security-belt-server": "./bin/security-belt-server", 19 | "security-belt-migrator": "./scripts/migration-runner.js" 20 | }, 21 | "scripts": { 22 | "build": "npm run build:production", 23 | "build:production": "NODE_ENV=production webpack --progress", 24 | "build:dev": "NODE_ENV=development webpack --progress --watch", 25 | "lint:js": "eslint *.js src/", 26 | "lint:yaml": "yamllint config/skills/*/*.yml", 27 | "lint": "npm run lint:js && npm run lint:yaml", 28 | "test:nolint": "mocha --reporter spec", 29 | "test": "npm run lint && npm run test:nolint", 30 | "migrate": "./scripts/migration-runner.js", 31 | "prestart": "npm run build && npm run migrate", 32 | "start": "./bin/security-belt-server start", 33 | "clean": "cd public && ls | grep -Ev 'favicon.ico|logo.svg|logo.png' | xargs rm", 34 | "prepush": "npm run test", 35 | "precommit": "npm run lint" 36 | }, 37 | "dependencies": { 38 | "@material/auto-init": "^0.32.0", 39 | "@material/button": "^0.32.0", 40 | "@material/card": "^0.32.0", 41 | "@material/elevation": "^0.28.0", 42 | "@material/layout-grid": "^0.24.0", 43 | "@material/list": "^0.32.0", 44 | "@material/ripple": "^0.32.0", 45 | "@material/tabs": "^0.32.0", 46 | "@material/theme": "^0.30.0", 47 | "@material/toolbar": "^0.32.0", 48 | "@material/typography": "^0.28.0", 49 | "ajv": "^6.12.6", 50 | "babel-core": "^6.26.3", 51 | "babel-loader": "^7.1.5", 52 | "babel-preset-es2015": "^6.24.1", 53 | "body-parser": "^1.19.0", 54 | "bunyan": "^1.8.15", 55 | "css-loader": "^5.2.0", 56 | "express": "^4.17.1", 57 | "file-loader": "^1.1.11", 58 | "js-yaml": "^3.14.1", 59 | "mini-css-extract-plugin": "^1.4.0", 60 | "mongodb": "^3.6.5", 61 | "node-sass": "^4.14.1", 62 | "normalize.css": "^8.0.1", 63 | "pug": "^3.0.2", 64 | "request": "^2.88.2", 65 | "resolve-url-loader": "^3.1.2", 66 | "roboto-fontface": "^0.9.0", 67 | "sass-loader": "^6.0.7", 68 | "serve-favicon": "^2.5.0", 69 | "style-loader": "^0.20.3", 70 | "walk": "^2.3.14", 71 | "webpack": "^5.30.0", 72 | "webpack-cli": "^4.6.0", 73 | "yargs": "^16.2.0" 74 | }, 75 | "devDependencies": { 76 | "eslint": "^4.19.1", 77 | "husky": "^6.0.0", 78 | "mocha": "^8.3.2", 79 | "sinon": "^4.5.0", 80 | "yaml-lint": "^1.2.4" 81 | }, 82 | "babel": { 83 | "presets": [ 84 | "es2015" 85 | ] 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /server/composer.js: -------------------------------------------------------------------------------- 1 | const state = require('./state'); 2 | const badge = require('./badge'); 3 | const skills = require('./skills'); 4 | 5 | function slug(s) { 6 | let slg = s; 7 | slg = slg.toLowerCase(); 8 | slg = slg.replace(/\s+/, '-'); 9 | return slg; 10 | } 11 | 12 | /** 13 | * Ungroup the legacy representation of skills. It looks like this: 14 | * { yellow: [...skills], green: [...skills] } 15 | * which is turned into this: 16 | * [ { , rank: yellow }, { , rank: green} ] 17 | * @param {*Object} skills The grouped skills object 18 | */ 19 | function ungroupSkills(skills) { 20 | let ungrouped = []; 21 | Object.keys(skills).forEach(color => { 22 | const byColor = skills[color].map(s => { 23 | return Object.assign({}, s, { rank: color }); 24 | }); 25 | ungrouped = ungrouped.concat(byColor); 26 | }); 27 | return ungrouped; 28 | } 29 | 30 | /** 31 | * Assemble a team representation from different 32 | * sources. Prevents the need to have to do this 33 | * every time and gives a centralized representation. 34 | * 35 | * @param {*string} name The team name 36 | */ 37 | async function getTeamRepresentation(name) { 38 | const teamInfo = await state.getTeam(name); 39 | const allBadges = await state.getBadges(); 40 | const teamBadges = allBadges.map(b => { 41 | return Object.assign({}, b, { 42 | isComplete: badge.teamHasBadge(teamInfo, b), 43 | id: slug(b.title), 44 | requiredSkills: b.requiredSkills.map(rs => { 45 | return { id: rs }; 46 | }) 47 | }); 48 | }); 49 | 50 | const allSkills = await skills.get(); 51 | const flatSkills = ungroupSkills(allSkills); 52 | 53 | const allSkillsWithState = flatSkills.map(skill => { 54 | const withState = Object.assign({}, skill); 55 | withState.id = slug(withState.fileName); 56 | withState.state = teamInfo.skills.find(s => { 57 | const has = s.name === skill.fileName; 58 | return has; 59 | }) ? 'closed' : 'open'; 60 | let links = []; 61 | if(withState.links) { 62 | withState.links.forEach(kvPairs => { 63 | const flattened = []; 64 | Object.keys(kvPairs).forEach(k => { 65 | flattened.push({ 66 | title: k, 67 | url: kvPairs[k] 68 | }); 69 | }); 70 | links = links.concat(flattened); 71 | }); 72 | } 73 | withState.links = links; 74 | delete withState['fileName']; 75 | return withState; 76 | }); 77 | 78 | const allSkillsWithStateAndBadges = allSkillsWithState.map(skill => { 79 | const withBadges = Object.assign({}, skill); 80 | withBadges.badges = allBadges 81 | .filter(badge => badge.requiredSkills.includes(skill.id)) 82 | .map(badge => badge.id); 83 | return withBadges; 84 | }); 85 | 86 | const composed = { 87 | id: slug(teamInfo.name), 88 | name: teamInfo.name, 89 | securityChampion: teamInfo.champion, 90 | belt: teamInfo.belt, 91 | skills: allSkillsWithStateAndBadges, 92 | skillCount: teamInfo.skillCount, 93 | badges: teamBadges 94 | }; 95 | return composed; 96 | } 97 | 98 | exports.getTeamRepresentation = getTeamRepresentation; 99 | -------------------------------------------------------------------------------- /server/views/team.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | 5 | - beltNames = {white: 'White', yellow: 'Yellow', orange: 'Orange', green: 'Green', blue: 'Blue', brown: 'Brown', black:'Black'} 6 | - beltKeys = Object.keys(beltNames) 7 | if beltKeys.indexOf(team.belt) === beltKeys.length-1 8 | - nextBelt = 'yellow' 9 | else 10 | - nextBelt = beltKeys[beltKeys.indexOf(team.belt) + 1]; 11 | 12 | div(class='mdc-layout-grid team-info') 13 | div(class='mdc-layout-grid__inner') 14 | 15 | section(class='center mdc-layout-grid__cell--span-12 team-info') 16 | h1(class='mdc-typography--display2')= 'Team ' + team.name 17 | h2(class='mdc-typography--display1') 18 | strong='Belt: ' 19 | strong(class=`team-info__belt ${team.belt}-belt-text`)= beltNames[team.belt] 20 | h3(class='mdc-typography--headline')= 'Security Champion: ' 21 | a(href='mailto:' + team.securityChampion.email) 22 | strong= team.securityChampion.name 23 | 24 | div(data-mdc-auto-init='MDCTabBarScroller' class='mdc-tab-bar-scroller mdc-layout-grid__cell--span-12 belt-toolbar mdc-theme--dark') 25 | div(class='mdc-tab-bar-scroller__indicator mdc-tab-bar-scroller__indicator--back') 26 | a(class='mdc-tab-bar-scroller__indicator__inner material-icons' href='#' aria-label='scroll back button') navigate_before 27 | div(class='mdc-tab-bar-scroller__scroll-frame') 28 | nav(class='mdc-tab-bar mdc-tab-bar-scroller__scroll-frame__tabs badge-select') 29 | each badge in team.badges 30 | a(class="mdc-tab mdc-tab--with-icon-and-text mdc-tab--active " href=`#badge-${badge.id}` data-badge=badge.id) 31 | if badge.isComplete 32 | i(class='material-icons badge--achieved') done 33 | else 34 | i(class='material-icons badge--unachieved') error 35 | span(class="mdc-tab__icon-text")= badge.title 36 | span(class='mdc-tab-bar__indicator tab-bar-indicator-marker') 37 | div(class='mdc-tab-bar-scroller__indicator mdc-tab-bar-scroller__indicator--forward') 38 | a(class='mdc-tab-bar-scroller__indicator__inner material-icons' href='#' aria-label='scroll forward button') navigate_next 39 | 40 | 41 | div(data-mdc-auto-init='MDCTabBarScroller' class='mdc-tab-bar-scroller mdc-layout-grid__cell--span-12 belt-toolbar mdc-theme--dark') 42 | div(class='mdc-tab-bar-scroller__indicator mdc-tab-bar-scroller__indicator--back') 43 | a(class='mdc-tab-bar-scroller__indicator__inner material-icons' href='#' aria-label='scroll back button') navigate_before 44 | div(class='mdc-tab-bar-scroller__scroll-frame') 45 | nav(class='mdc-tab-bar mdc-tab-bar-scroller__scroll-frame__tabs rank-select' data-active-rank=`${nextBelt}`) 46 | each beltColor in beltKeys 47 | if beltColor !== 'white' 48 | a(data-rank=beltColor class=`${beltColor}-belt ${nextBelt === beltColor ? 'mdc-tab--active' : ''} mdc-tab rank-select__tab` href=`#${beltColor}`)= beltNames[beltColor] 49 | span(class='mdc-tab-bar__indicator tab-bar-indicator-marker') 50 | div(class='mdc-tab-bar-scroller__indicator mdc-tab-bar-scroller__indicator--forward') 51 | a(class='mdc-tab-bar-scroller__indicator__inner material-icons' href='#' aria-label='scroll forward button') navigate_next 52 | 53 | section(class='card-grid mdc-layout-grid') 54 | div(class='mdc-layout-grid__inner skill-list') 55 | each skill in team.skills 56 | div(class='mdc-layout-grid__cell skill-list__item' data-skill-badges=skill.badges.join(",") data-skill-rank=skill.rank data-skill-id=skill.id) 57 | include skill-item.pug 58 | -------------------------------------------------------------------------------- /test/state-test.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | 'use strict'; 3 | const sinon = require('sinon'); 4 | const assert = require('assert'); 5 | const MongoClient = require('mongodb').MongoClient; 6 | const state = require('../server/state'); 7 | const db = require('../server/db'); 8 | let collectionStub; 9 | 10 | before(async () => { 11 | collectionStub = { 12 | findOne: sinon.stub().resolves({skills: []}), 13 | updateOne: sinon.stub().resolves(), 14 | insertOne: sinon.stub().resolves() 15 | }; 16 | const dbStub = { 17 | collection: sinon.stub().returns(collectionStub) 18 | }; 19 | const connStub = { 20 | db: sinon.stub().returns(dbStub) 21 | }; 22 | sinon.stub(MongoClient, 'connect').resolves(connStub); 23 | await db.getConnection(); 24 | }); 25 | 26 | describe('State', () => { 27 | 28 | describe('teamSkills()', () => { 29 | 30 | it('should return an empty array if team has no skills', () => { 31 | collectionStub.findOne.resolves({ 32 | skills: [] 33 | }); 34 | return state.teamSkills('Team Awesome').then((skills) => { 35 | if (skills.length === 0) 36 | return Promise.resolve(); 37 | else 38 | return Promise.reject(); 39 | }); 40 | }); 41 | 42 | it('should return an array of team skills', async () => { 43 | const clock = sinon.useFakeTimers(); 44 | const expectedSkills = [{name: 'secure_sauce', since: new Date()}]; 45 | collectionStub.findOne.resolves({skills: [{name: 'secure_sauce', since: new Date()}]}); 46 | const teamSkills = await state.teamSkills('Team Awesome'); 47 | clock.restore(); 48 | assert.deepEqual(teamSkills, expectedSkills); 49 | }); 50 | }); 51 | 52 | }); 53 | 54 | describe('addToSkillSet()', () => { 55 | 56 | it('should add skill with a current timestamp', () => { 57 | const clock = sinon.useFakeTimers(); 58 | const expectedArgs = [{_id : 'Team Awesome'}, 59 | {$push : {skills: {name: 'secure_sauce', since: new Date()}}}]; 60 | collectionStub.findOne.resolves(undefined); 61 | return state.addToSkillSet('Team Awesome', 'secure_sauce').then(() => { 62 | clock.restore(); 63 | if (collectionStub.updateOne.withArgs(expectedArgs[0],expectedArgs[1]).calledOnce) 64 | return Promise.resolve(); 65 | else { 66 | const err = Error(); 67 | err.expected = expectedArgs; 68 | err.actual = collectionStub.updateOne.getCall(collectionStub.updateOne.callCount - 1).args; 69 | return Promise.reject(err); 70 | } 71 | }); 72 | }); 73 | 74 | it('should reject if skill already added', () => { 75 | return new Promise((resolve,reject) => { 76 | collectionStub.findOne.resolves({skills: [{name: 'secure_sauce', since: new Date()}]}); 77 | state.addToSkillSet('Team Awesome', 'secure_sauce').then(() => { 78 | reject(Error('expected reject but was resolved')); 79 | }).catch(() => { 80 | resolve(); 81 | }); 82 | }); 83 | }); 84 | 85 | }); 86 | 87 | describe('removeFromSkillSet()', () => { 88 | 89 | it('should remove skill from set', () => { 90 | const expectedArgs = [{_id: 'Team Awesome'}, 91 | {$pull: {skills: {name: 'secure_sauce'}}}]; 92 | return state.removeFromSkillSet('Team Awesome', 'secure_sauce').then(() => { 93 | if (collectionStub.updateOne.withArgs(expectedArgs[0],expectedArgs[1]).calledOnce) 94 | return Promise.resolve(); 95 | else { 96 | const err = Error(); 97 | err.expected = expectedArgs; 98 | err.actual = collectionStub.updateOne.getCall(collectionStub.updateOne.callCount - 1).args; 99 | return Promise.reject(err); 100 | } 101 | }); 102 | }); 103 | 104 | }); 105 | 106 | describe('belt()', () => { 107 | 108 | it('should return yellow if all yellow cards are completed', () => { 109 | const fileNames = { 110 | yellow: ['Test1','Test2'], 111 | orange: ['Test3'], 112 | black: ['Test4'] 113 | }; 114 | const skills = [{name: 'Test1'},{name: 'Test2'}]; 115 | assert.equal(state.belt(skills,fileNames), 'yellow'); 116 | }); 117 | 118 | it('should not return black if orange cards are missing', () => { 119 | const fileNames = { 120 | yellow: ['Test1'], 121 | orange: ['Test2'], 122 | black: ['Test3','Test4'] 123 | }; 124 | const skills = [{name: 'Test1'},{name: 'Test3'},{name: 'Test4'}]; 125 | assert.equal(state.belt(skills,fileNames), 'yellow'); 126 | }); 127 | 128 | }); 129 | 130 | 131 | -------------------------------------------------------------------------------- /server/state.js: -------------------------------------------------------------------------------- 1 | const skills = require('./skills'); 2 | const config = require('./config'); 3 | const teams = require(config.data.teams).teams; 4 | const Mongo = require('./db'); 5 | 6 | async function getTeamGraph(teamName, days) { 7 | const collection = await Mongo.getConnection(); 8 | const res = []; 9 | for (let i = days-1; i >= 0; i--) { 10 | const d = new Date(); 11 | d.setDate(d.getDate() - i); 12 | const cursor = await collection.aggregate([ 13 | { 14 | $match: { 15 | _id: teamName 16 | } 17 | }, 18 | { 19 | $project: { 20 | skills: { 21 | $filter: { 22 | input: '$skills', 23 | as: 'skill', 24 | cond: { $lte: ['$$skill.since', d]} 25 | } 26 | } 27 | } 28 | }, 29 | { 30 | $project: { 31 | skillCount: { $size: '$skills' } 32 | } 33 | } 34 | ]); 35 | if (await cursor.hasNext()) { 36 | const doc = await cursor.next(); 37 | const timeStamp = Math.floor(d.getTime() / 1000); 38 | res.push({ x: timeStamp, y: doc.skillCount || 0 }); 39 | } 40 | } 41 | return res; 42 | } 43 | 44 | function getGraph(days){ 45 | const summedGraph = []; 46 | const teamGraphs = []; 47 | teams.forEach((team) => { 48 | const teamGraph = getTeamGraph(team.name, days); 49 | teamGraphs.push(teamGraph); 50 | }); 51 | return Promise.all(teamGraphs).then((resolvedGraphs) => { 52 | resolvedGraphs.forEach((team) => { 53 | team.forEach((day, i) => { 54 | if (summedGraph[i]) 55 | summedGraph[i].y += day.y; 56 | else 57 | summedGraph.push(day); 58 | }); 59 | }); 60 | return Promise.resolve(summedGraph); 61 | }).then((res) => Promise.resolve(res)); 62 | } 63 | 64 | function getTeams() { 65 | let allTeams = []; 66 | teams.map((team) => { 67 | allTeams.push(getTeam(team.name)); 68 | }); 69 | return Promise.all(allTeams); 70 | } 71 | 72 | async function getTeam(teamName) { 73 | const currentSkills = await teamSkills(teamName); 74 | const fileNames = await skills.getFileNames(); 75 | const teamObj = teams.find((team) => team.name == teamName); 76 | const team = { 77 | name: teamObj.name, 78 | champion: teamObj.champion, 79 | belt: belt(currentSkills, fileNames), 80 | skills: currentSkills, 81 | skillCount: currentSkills.length 82 | }; 83 | return team; 84 | } 85 | 86 | function getTeamNames() { 87 | return teams.map((team) => team.name); 88 | } 89 | 90 | async function createTeam(teamName) { 91 | const collection = await Mongo.getConnection(); 92 | if (getTeamNames().includes(teamName)) { 93 | const team = {_id: teamName, skills: []}; 94 | return collection.insertOne(team); 95 | } else { 96 | return Promise.reject(Error('Team not found!')); 97 | } 98 | } 99 | 100 | async function teamSkills(teamName) { 101 | const collection = await Mongo.getConnection(); 102 | const doc = await collection.findOne({ _id: teamName }); 103 | if (doc) { 104 | return Promise.resolve(doc.skills); 105 | } else { 106 | await createTeam(teamName); 107 | return teamSkills(teamName); 108 | } 109 | } 110 | 111 | async function addToSkillSet(teamName, cardName) { 112 | const collection = await Mongo.getConnection(); 113 | const doc = await collection.findOne({_id: teamName, skills: {$elemMatch: {name: cardName}}}); 114 | if (doc) { 115 | return Promise.reject(Error('skill is already enabled')); 116 | } 117 | return collection.updateOne({_id: teamName}, {$push: {skills: {name: cardName, since: new Date()}}}); 118 | } 119 | 120 | async function removeFromSkillSet(teamName, cardName) { 121 | const collection = await Mongo.getConnection(); 122 | return collection.updateOne({_id: teamName}, {$pull: {skills: {name: cardName}}}); 123 | } 124 | 125 | function toggleSkill(teamName, cardName) { 126 | return skills.getFlatFileNames().then((res) => { 127 | if (res.includes(cardName)) 128 | return Promise.resolve(teamName); 129 | else 130 | return Promise.reject(Error(cardName + ' Skill not valid!')); 131 | }).then(teamSkills).then((res) => { 132 | if (res.find((skill) => skill.name == cardName)) 133 | return removeFromSkillSet(teamName, cardName); 134 | else 135 | return addToSkillSet(teamName, cardName); 136 | }); 137 | } 138 | 139 | function belt(teamSkills, fileNames) { 140 | let currBelt = 'white'; 141 | for (let beltName in fileNames) { 142 | let len = fileNames[beltName].length; 143 | for (let i in fileNames[beltName]) { 144 | if (teamSkills.find((skill) => skill.name == fileNames[beltName][i])){ 145 | if (i == len - 1) 146 | currBelt = beltName; 147 | } else { 148 | return currBelt; 149 | } 150 | } 151 | } 152 | return currBelt; 153 | } 154 | 155 | function getBadges() { 156 | const fs = require('fs'); 157 | const yaml = require('js-yaml'); 158 | const glob = require('glob'); 159 | const badgePath = config.data.badges; 160 | return new Promise((resolve, reject) => { 161 | glob(`${badgePath}/**/*.yaml`, (err, files) => { 162 | if(err) { 163 | return reject(err); 164 | } 165 | const badges = files.map(f => { 166 | const b = yaml.safeLoad(fs.readFileSync(f, 'utf-8')); 167 | b.id = b.title.toLowerCase().replace(/\s+/, '-'); 168 | return b; 169 | }); 170 | 171 | return resolve(badges); 172 | }); 173 | }); 174 | } 175 | 176 | exports.getTeamGraph = getTeamGraph; 177 | exports.getGraph = getGraph; 178 | exports.getTeams = getTeams; 179 | exports.getTeam = getTeam; 180 | exports.getTeamNames = getTeamNames; 181 | exports.teamSkills = teamSkills; 182 | exports.addToSkillSet = addToSkillSet; 183 | exports.removeFromSkillSet = removeFromSkillSet; 184 | exports.toggleSkill = toggleSkill; 185 | exports.belt = belt; 186 | exports.getBadges = getBadges; 187 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![logo](https://rawgit.com/philippnormann/security-belt/master/public/logo.svg) Security Belt 2 | 3 | [![Build Status](https://travis-ci.org/philippnormann/security-belt.svg?branch=master)](https://travis-ci.org/philippnormann/security-belt) 4 | [![Dependencies Status](https://david-dm.org/philippnormann/security-belt/status.svg)](https://david-dm.org/philippnormann/security-belt) 5 | [![DevDependencies Status](https://david-dm.org/philippnormann/security-belt/dev-status.svg)](https://david-dm.org/philippnormann/security-belt?type=dev) 6 | [![Heroku](http://heroku-badge.herokuapp.com/?app=angularjs-crypto&style=flat&svg=1)](https://security-belt.herokuapp.com/) 7 | 8 | A framework for improving the IT-Security of your teams through gamification. 9 | It allows teams to self-asses their security level and rewards them with security belts (from yellow through black) and topic specific badges. It also ranks the teams by the amount of aquired skills. 10 | 11 | ![screencast](screencast.gif) 12 | ### [**View demo!**](https://security-belt.herokuapp.com/) 13 | 14 | ## Usage 15 | 16 | ### Cloning 17 | ```bash 18 | git clone https://github.com/philippnormann/security-belt.git 19 | cd security-belt 20 | ``` 21 | ### Prerequisites 22 | A mongoDB for storing the progress of the teams is required. The database is automatically seeded once the app is running. 23 | 24 | ### Docker-Compose 25 | The included docker-compose file can be used to launch a mongoDB and a node container running the belt application. It also mounts the `./data/db` folder as a volume for the database. 26 | ``` 27 | docker-compose build 28 | docker-compose up 29 | ``` 30 | ### Development Setup 31 | For development purposes a mongoDB container can be started without a volume: 32 | ```bash 33 | docker run -d --name belt-mongo -p 27017:27017 mongo 34 | ``` 35 | This is better suited for development since the app container doesn't have to be rebuilt after every change. 36 | 37 | Afterwards you can launch the application: 38 | ```bash 39 | npm install 40 | npm start 41 | ``` 42 | Optionally a webpack watcher can be launched in a seperate shell to dynamically recompile the client assets: 43 | ```bash 44 | npm build:dev 45 | ``` 46 | 47 | ### Testing 48 | All the tests for the application can be executed using the test target: 49 | ```bash 50 | npm test 51 | ``` 52 | 53 | 54 | ## Environment Variables 55 | 56 | ### Logging 57 | 58 | - `SB_LOG_LEVEL` one of `debug`, `info` (default), `warn`, `error` 59 | - `SB_LOG_FILE` if set, will log to the given file (disabled by default) 60 | 61 | ### Application port: 62 | - `PORT`, defaults to 3000 63 | 64 | ### Databse connection: 65 | - `DB_USER` 66 | - `DB_PASS` 67 | - `DB_NAME` 68 | - `DB_COLLECTION` 69 | - `DB_HOST` 70 | 71 | ### HTTPS redirect: 72 | - `NODE_ENV` = `production`, to enable HTTPS redirect. 73 | 74 | ## Teams 75 | A team needs to have a security champion. A person from the team who is interested in security and wants to track the current security status of the team regularly. This person also coordinates the tasks that need to be done, in order to advance. 76 | 77 | The team names and security champions are stored in a config file (`config/teams.json`) 78 | 79 | You need to edit this file accordingly. 80 | 81 | A valid team file should look like this: 82 | 83 | ```json 84 | { 85 | "teams": [ 86 | { 87 | "name": "Team 1", 88 | "champion": { 89 | "name": "Chuck Norris", 90 | "email": "chuck.norris@example.com" 91 | } 92 | } 93 | ] 94 | } 95 | ``` 96 | 97 | 98 | ## Skills 99 | All the skills are sorted by colors and written in `.yml` files. (`config/skills`) 100 | 101 | It helps to organize a workshop with the security chapions, in order to define a set of skills that make sense in your enviroment. 102 | 103 | Please complement the skills and send pull requests. 104 | 105 | A valid skill file should look like this: 106 | 107 | ```yaml 108 | title: A nice title shown in the card 109 | why: Why is this skill useful? 110 | how: How can we reach this goal? 111 | validation: How can we tell we reached the goal? 112 | links: 113 | - Example: https://example.com 114 | - Some link in Confluence: https://confluence/?id=234 115 | ``` 116 | 117 | ### Badges 118 | 119 | You can enable badges by adding `.yaml` files in the folder `config/badges`. 120 | 121 | The badges serve as a further motivation and relate to different skills that have been achieved. 122 | 123 | ```yaml 124 | title: Always up to date 125 | description: Your dependencies and software is always up to date. 126 | requiredSkills: 127 | - dependency_checks 128 | - software_updates 129 | ``` 130 | 131 | ### Lint the skills 132 | 133 | To check if all skills are valid YAML syntax, you can use the included lint target: 134 | ```bash 135 | npm run lint:yaml 136 | ``` 137 | 138 | ## REST API 139 | 140 | ### GET `/api/stats?days=[n]` 141 | Get skill progress for all teams over the last n days 142 | 143 | Response: 144 | 145 | - `x`: Unix epoch timestamp in seconds 146 | - `y`: Total number of completed skills at date `x` 147 | 148 | ```json 149 | { 150 | "progress": [ 151 | { 152 | "x": 1497435199, 153 | "y": 172 154 | }, 155 | { 156 | "x": 1497521599, 157 | "y": 175 158 | }, 159 | { 160 | "x": 1497607999, 161 | "y": 194 162 | } 163 | ] 164 | } 165 | ``` 166 | 167 | ### GET `/api/stats/[teamName]?days=[n]` 168 | Get skill progress for a specific team over the last n days 169 | 170 | Response: 171 | 172 | - `x`: Unix epoch timestamp in seconds 173 | - `y`: Total number of completed skills at date `x` 174 | 175 | ```json 176 | { 177 | "progress": [ 178 | { 179 | "x": 1497435199, 180 | "y": 30 181 | }, 182 | { 183 | "x": 1497521599, 184 | "y": 34 185 | }, 186 | { 187 | "x": 1497607999, 188 | "y": 38 189 | } 190 | ] 191 | } 192 | ``` 193 | 194 | ### GET `/api/teams` 195 | Get all teams including their belt and skills 196 | 197 | Response: 198 | 199 | ```json 200 | { 201 | "teams": [ 202 | { 203 | "name": "Team Awesome", 204 | "belt": "white", 205 | "skills": [ 206 | { 207 | "name": "secure_sauce", 208 | "since": 1498747187 209 | } 210 | ], 211 | "skillCount": 1 212 | } 213 | ] 214 | } 215 | ``` 216 | 217 | ## Contribution 218 | 219 | Contributions are always welcome! 220 | 221 | Especially the content of the skills should be complemented with your experience. 222 | -------------------------------------------------------------------------------- /public/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 26 | 33 | 35 | 36 | 37 | 60 | 62 | 63 | 65 | image/svg+xml 66 | 68 | 69 | 70 | 71 | 72 | 77 | 80 | 83 | 88 | 93 | 94 | 95 | 96 | 101 | 105 | 108 | 115 | 121 | 127 | 133 | 139 | 145 | 151 | 157 | 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------