-
Notifications
You must be signed in to change notification settings - Fork 12
/
Application.cfc
119 lines (98 loc) · 3.33 KB
/
Application.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
*
* This file is part of MuraPlugin
*
* Copyright 2013-2016 Stephen J. Withington, Jr.
* Licensed under the Apache License, Version v2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
component accessors=true output=false {
property name='$';
include 'plugin/settings.cfm';
include '../../config/applicationSettings.cfm';
include '../../config/mappings.cfm';
include '../mappings.cfm';
public any function onApplicationStart() {
include '../../config/appcfc/onApplicationStart_include.cfm';
return true;
}
public any function onRequestStart(required string targetPage) {
include '../../config/appcfc/onRequestStart_include.cfm';
if (
(
StructKeyExists(variables.settings, 'reloadApplicationOnEveryRequest')
&& variables.settings.reloadApplicationOnEveryRequest
)
|| !StructKeyExists(application, 'appInitializedTime')
) {
onApplicationStart();
}
if ( isSessionExpired() ) {
lock scope='session' type='exclusive' timeout=10 {
setupSession();
}
}
// You may want to change the methods being used to secure the request
secureRequest();
return true;
}
public void function onRequest(required string targetPage) {
var $ = get$();
var pluginConfig = $.getPlugin(variables.settings.pluginName);
include arguments.targetPage;
}
public void function onSessionStart() {
include '../../config/appcfc/onSessionStart_include.cfm';
setupSession();
}
public void function onSessionEnd() {
include '../../config/appcfc/onSessionEnd_include.cfm';
}
// ----------------------------------------------------------------------
// HELPERS
private struct function get$() {
if ( !StructKeyExists(arguments, '$') ) {
var siteid = StructKeyExists(session, 'siteid') ? session.siteid : 'default';
arguments.$ = StructKeyExists(request, 'murascope')
? request.murascope
: StructKeyExists(application, 'serviceFactory')
? application.serviceFactory.getBean('$').init(siteid)
: {};
}
return arguments.$;
}
public any function secureRequest() {
var $ = get$();
return !inPluginDirectory() || $.currentUser().isSuperUser()
? true
: ( inPluginDirectory() && !StructKeyExists(session, 'siteid') )
|| ( inPluginDirectory() && !$.getBean('permUtility').getModulePerm($.getPlugin(variables.settings.pluginName).getModuleID(),session.siteid) )
? goToLogin()
: true;
}
public boolean function inPluginDirectory() {
var uri = getPageContext().getRequest().getRequestURI();
return ListFindNoCase(uri, 'plugins', '/') && ListFindNoCase(uri, variables.settings.package,'/');
}
private void function goToLogin() {
var $ = get$();
location(url='#$.globalConfig('context')#/admin/index.cfm?muraAction=clogin.main&returnURL=#$.globalConfig('context')#/plugins/#$.getPlugin(variables.settings.pluginName).getPackage()#/', addtoken=false);
}
private boolean function isSessionExpired() {
var p = variables.settings.package;
return !StructKeyExists(session, p)
|| DateCompare(now(), session[p].expires, 's') == 1
|| DateCompare(application.appInitializedTime, session[p].created, 's') == 1;
}
private void function setupSession() {
var p = variables.settings.package;
StructDelete(session, p);
// Expires - s:seconds, n:minutes, h:hours, d:days
session[p] = {
created = Now()
, expires = DateAdd('d', 1, Now())
, sessionid = Hash(CreateUUID())
};
}
}