Skip to content

Commit

Permalink
feat: Update for ColdBox 5 and cbstorages 2.0.0
Browse files Browse the repository at this point in the history
New settings introduced: `cookieCheck` which defaults to `true` to check
for a CFID cookie to determine if the request is likely a bot and
`botsJsonFile` to change what file to load.  Additionally, the configured
`botsJsonFile` is loaded and mapped to `Bots@disable-bot-sessions` in the
`ModuleConfig.cfc`.  Also added cfformat support and expanded CI matrix testing.

BREAKING CHANGE:  Support dropped for ACF 11 and Lucee 4.5
  • Loading branch information
elpete committed Apr 13, 2020
1 parent 646868b commit abcb389
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 205 deletions.
63 changes: 63 additions & 0 deletions .cfformat.json
@@ -0,0 +1,63 @@
{
"array.empty_padding": false,
"array.padding": true,
"array.multiline.min_length": 40,
"array.multiline.element_count": 2,
"array.multiline.leading_comma.padding": true,
"array.multiline.leading_comma": false,
"alignment.consecutive.assignments": true,
"alignment.consecutive.properties": true,
"alignment.consecutive.params": true,
"brackets.padding": true,
"comment.asterisks": "align",
"binary_operators.padding": true,
"for_loop_semicolons.padding": true,
"function_call.empty_padding": false,
"function_call.padding": true,
"function_call.multiline.leading_comma.padding": true,
"function_call.casing.builtin": "cfdocs",
"function_call.casing.userdefined": "camel",
"function_call.multiline.element_count": 3,
"function_call.multiline.leading_comma": false,
"function_call.multiline.min_length": 40,
"function_declaration.padding": true,
"function_declaration.empty_padding": false,
"function_declaration.multiline.leading_comma": false,
"function_declaration.multiline.leading_comma.padding": true,
"function_declaration.multiline.element_count": 3,
"function_declaration.multiline.min_length": 40,
"function_declaration.group_to_block_spacing": "spaced",
"function_anonymous.empty_padding": false,
"function_anonymous.group_to_block_spacing": "spaced",
"function_anonymous.multiline.element_count": 3,
"function_anonymous.multiline.leading_comma": false,
"function_anonymous.multiline.leading_comma.padding": true,
"function_anonymous.multiline.min_length": 40,
"function_anonymous.padding": true,
"indent_size": 4,
"keywords.block_to_keyword_spacing": "spaced",
"keywords.group_to_block_spacing": "spaced",
"keywords.padding_inside_group": true,
"keywords.spacing_to_block": "spaced",
"keywords.spacing_to_group": true,
"keywords.empty_group_spacing": false,
"max_columns": 120,
"metadata.multiline.element_count": 3,
"metadata.multiline.min_length": 40,
"newline":"\n",
"property.multiline.element_count": 3,
"property.multiline.min_length": 40,
"parentheses.padding": true,
"strings.quote": "double",
"strings.convertNestedQuotes": false,
"strings.attributes.quote": "double",
"struct.separator": " : ",
"struct.padding": true,
"struct.empty_padding": false,
"struct.multiline.leading_comma": false,
"struct.multiline.leading_comma.padding": true,
"struct.multiline.element_count": 2,
"struct.multiline.min_length": 40,
"struct.quote_keys": true,
"tab_indent": true
}
69 changes: 40 additions & 29 deletions .travis.yml
@@ -1,30 +1,41 @@
language: java
sudo: required
jdk:
- openjdk8
cache:
directories:
- $HOME/.CommandBox
env:
matrix:
- ENGINE=lucee@5
- ENGINE=lucee@4.5
- ENGINE=adobe@2018
- ENGINE=adobe@2016
- ENGINE=adobe@11
before_install:
- sudo apt-key adv --keyserver keys.gnupg.net --recv 6DA70622
- sudo echo "deb http://downloads.ortussolutions.com/debs/noarch /" | sudo tee -a /etc/apt/sources.list.d/commandbox.list
install:
- sudo apt-get update && sudo apt-get --assume-yes install commandbox
- box install
before_script:
- box server start cfengine=$ENGINE port=8500
script:
- box testbox run runner='http://127.0.0.1:8500/tests/runner.cfm'
after_success:
- box install commandbox-semantic-release
- box config set endpoints.forgebox.APIToken=${FORGEBOX_TOKEN}
- box semantic-release
notifications:
email: false
os: linux
jdk:
- openjdk8
cache:
directories:
- "$HOME/.CommandBox/artifacts/"
- "$HOME/.CommandBox/server/"
env:
jobs:
- ENGINE=adobe@2018 COLDBOX_VERSION=stable CBSTORAGES_VERSION=stable
- ENGINE=adobe@2016 COLDBOX_VERSION=stable CBSTORAGES_VERSION=stable
- ENGINE=lucee@5 COLDBOX_VERSION=stable CBSTORAGES_VERSION=stable
- ENGINE=adobe@2018 COLDBOX_VERSION=be CBSTORAGES_VERSION=stable
- ENGINE=adobe@2016 COLDBOX_VERSION=be CBSTORAGES_VERSION=stable
- ENGINE=lucee@5 COLDBOX_VERSION=be CBSTORAGES_VERSION=stable
- ENGINE=adobe@2018 COLDBOX_VERSION=stable CBSTORAGES_VERSION=be
- ENGINE=adobe@2016 COLDBOX_VERSION=stable CBSTORAGES_VERSION=be
- ENGINE=lucee@5 COLDBOX_VERSION=stable CBSTORAGES_VERSION=be
- ENGINE=adobe@2018 COLDBOX_VERSION=be CBSTORAGES_VERSION=be
- ENGINE=adobe@2016 COLDBOX_VERSION=be CBSTORAGES_VERSION=be
- ENGINE=lucee@5 COLDBOX_VERSION=be CBSTORAGES_VERSION=be
before_install:
- curl -fsSl https://downloads.ortussolutions.com/debs/gpg | sudo apt-key add -
- sudo echo "deb http://downloads.ortussolutions.com/debs/noarch /" | sudo tee -a /etc/apt/sources.list.d/commandbox.list
install:
- sudo apt-get update && sudo apt-get --assume-yes install commandbox
- box install commandbox-cfconfig,commandbox-cfformat
- box install
- box install coldbox@${COLDBOX_VERSION},cbstorages@${CBSTORAGES_VERSION} --force
before_script:
- box server start cfengine=$ENGINE port=8500
script:
- box testbox run runner='http://127.0.0.1:8500/tests/runner.cfm'
- box run-script format:check
after_success:
- box install commandbox-semantic-release
- box config set endpoints.forgebox.APIToken=${FORGEBOX_TOKEN}
- box semantic-release
notifications:
email: false
47 changes: 27 additions & 20 deletions ModuleConfig.cfc
@@ -1,27 +1,34 @@
component {

this.name = "disable-bot-sessions";
this.author = "Eric Peterson";
this.webUrl = "https://github.com/elpete/disable-bot-sessions";
this.mapping = "disable-bot-sessions";
this.autoMapModels = false;
this.dependencies = [ "cbstorages" ];
this.name = "disable-bot-sessions";
this.author = "Eric Peterson";
this.webUrl = "https://github.com/elpete/disable-bot-sessions";
this.mapping = "disable-bot-sessions";
this.autoMapModels = false;
this.dependencies = [ "cbstorages" ];

function configure() {
interceptors = [
{ class = "#moduleMapping#.interceptors.DisableBotSessions" }
];
function configure() {
settings = {
"cookieCheck" : true,
"botsJsonFile" : "#moduleMapping#/config/bots.json"
};

binder.map( "CGIScope@disable-bot-sessions" )
.to( "#moduleMapping#.models.CGIScope" );
binder.map( "PlatformHelper@disable-bot-sessions" )
.to( getPlatformHelperPath() );
}
binder.map( "PlatformHelper@disable-bot-sessions" ).to( getPlatformHelperPath() );
binder
.map( "Bots@disable-bot-sessions" )
.toValue( deserializeJSON( fileRead( expandPath( settings.botsJsonFile ) ) ) );

function getPlatformHelperPath() {
return server.keyExists( "lucee" ) ?
"#moduleMapping#.models.helpers.LuceeHelper" :
"#moduleMapping#.models.helpers.ACFHelper";
interceptors = [
{
"class" : "#moduleMapping#.interceptors.DisableBotSessions",
"name" : "DisableBotSessions"
}
];
}


function getPlatformHelperPath() {
return server.keyExists( "lucee" ) ? "#moduleMapping#.models.helpers.LuceeHelper" : "#moduleMapping#.models.helpers.ACFHelper";
}

}
}
73 changes: 38 additions & 35 deletions box.json
@@ -1,35 +1,38 @@
{
"name":"disable-bot-sessions",
"version":"0.0.0",
"author":"Eric Peterson",
"location":"forgeboxStorage",
"homepage":"https://github.com/coldbox-modules/disable-bot-sessions",
"documentation":"https://github.com/coldbox-modules/disable-bot-sessions",
"repository":{
"type":"git",
"URL":"https://github.com/coldbox-modules/disable-bot-sessions"
},
"bugs":"https://github.com/coldbox-modules/disable-bot-sessions/issues",
"slug":"disable-bot-sessions",
"shortDescription":"Automatically disable sessions for likely bots",
"description":"Automatically disable sessions for likely bots",
"type":"modules",
"dependencies":{
"coldbox":"^4.3.0+188",
"cbstorages":"^1.4.0+19"
},
"devDependencies":{
"testbox":"^2.4.0+80"
},
"installPaths":{
"testbox":"testbox",
"coldbox":"tests/resources/app/coldbox",
"cbstorages":"modules/cbstorages"
},
"scripts":{},
"ignore":[
"**/.*",
"test",
"tests"
]
}
{
"name":"disable-bot-sessions",
"version":"0.0.0",
"author":"Eric Peterson",
"location":"forgeboxStorage",
"homepage":"https://github.com/coldbox-modules/disable-bot-sessions",
"documentation":"https://github.com/coldbox-modules/disable-bot-sessions",
"repository":{
"type":"git",
"URL":"https://github.com/coldbox-modules/disable-bot-sessions"
},
"bugs":"https://github.com/coldbox-modules/disable-bot-sessions/issues",
"slug":"disable-bot-sessions",
"shortDescription":"Automatically disable sessions for likely bots",
"description":"Automatically disable sessions for likely bots",
"type":"modules",
"dependencies":{
"cbstorages":"^2.1.0+45"
},
"devDependencies":{
"testbox":"^3.2.0+356",
"coldbox":"^5.6.2+1021"
},
"installPaths":{
"testbox":"testbox/",
"coldbox":"tests/resources/app/coldbox/",
"cbstorages":"modules/cbstorages/"
},
"scripts":{
"format": "cfformat run interceptors/**/*.cfc,models/**/*.cfc,tests/specs/**/*.cfc,ModuleConfig.cfc --overwrite",
"format:check": "cfformat check interceptors/**/*.cfc,models/**/*.cfc,tests/specs/**/*.cfc,ModuleConfig.cfc --verbose"
},
"ignore":[
"**/.*",
"test",
"tests"
]
}
36 changes: 17 additions & 19 deletions interceptors/DisableBotSessions.cfc
@@ -1,27 +1,25 @@
component {

property name="cookieStorage" inject="CookieStorage@cbstorages";
property name="CGIScope" inject="CGIScope@disable-bot-sessions";
property name="helper" inject="PlatformHelper@disable-bot-sessions";
property name="helper" inject="PlatformHelper@disable-bot-sessions";
property name="bots" inject="Bots@disable-bot-sessions";
property name="cookieCheck" inject="coldbox:setting:cookieCheck@disable-bot-sessions";

function configure() {
variables.bots = deserializeJSON(
fileRead( expandPath( "../config/bots.json" ) )
);
}
function preProcess() {
if ( notUsingCookies() || isLikelyBot() ) {
helper.setSessionTimeout( 0, 0, 0, 1 );
}
}

function preProcess() {
if ( notUsingCookies() || isLikelyBot() ) {
helper.setSessionTimeout( 0, 0, 0, 1 );
}
}
private function notUsingCookies() {
if ( !variables.cookieCheck ) {
return false;
}

private function notUsingCookies() {
return ! cookieStorage.exists( "CFID" ) || len( cookieStorage.getVar( "CFID" ) ) == 0;
}
return !structKeyExists( cookie, "CFID" ) || len( cookie[ "CFID" ] ) == 0;
}

private function isLikelyBot() {
return CGIScope.exists( CGI.HTTP_USER_AGENT );
}
private function isLikelyBot() {
return variables.bots.keyExists( CGI.HTTP_USER_AGENT );
}

}
5 changes: 0 additions & 5 deletions models/CGIScope.cfc

This file was deleted.

0 comments on commit abcb389

Please sign in to comment.