-
Notifications
You must be signed in to change notification settings - Fork 12
/
Application.cfc
83 lines (66 loc) · 2.67 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
/**
*
* This file is part of MuraLocations
*
* Copyright 2010-2015 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='$';
this.pluginPath = GetDirectoryFromPath(GetCurrentTemplatePath());
this.muraroot = Left(this.pluginPath, Find('plugins', this.pluginPath) - 1);
this.depth = ListLen(RemoveChars(this.pluginPath,1, Len(this.muraroot)), '\/');
this.includeroot = RepeatString('../', this.depth);
include 'plugin/settings.cfm';
this.muraAppConfigPath = this.includeroot & 'core/';
include this.muraAppConfigPath & 'appcfc/applicationSettings.cfm';
try {
include this.includeroot & 'config/mappings.cfm';
include this.includeroot & 'plugins/mappings.cfm';
} catch(any e) {}
public any function onApplicationStart() {
include this.muraAppConfigPath & '/appcfc/onApplicationStart_include.cfm';
var $ = get$();
return true;
}
public any function onRequestStart(required string targetPage) {
var $ = get$();
include this.muraAppConfigPath & '/appcfc/onRequestStart_include.cfm';
if ( StructKeyExists(url, $.globalConfig('appreloadkey')) ) {
onApplicationStart();
}
// 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;
}
// ----------------------------------------------------------------------
// HELPERS
public struct function get$() {
return IsDefined('session') && StructKeyExists(session, 'siteid')
? application.serviceFactory.getBean('$').init(session.siteid)
: application.serviceFactory.getBean('$').init('default');
}
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() {
return ListFindNoCase(getPageContext().getRequest().getRequestURI(), 'plugins', '/');
}
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);
}
}