source: trunk/www/MuraProxy.cfc @ 4806

Revision 4806, 13.9 KB checked in by mattlevine, 3 months ago (diff)

Merge branch 'master' of github.com:blueriver/MuraCMS

Line 
1<!--- This file is part of Mura CMS.
2
3Mura CMS is free software: you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation, Version 2 of the License.
6
7Mura CMS is distributed in the hope that it will be useful,
8but WITHOUT ANY WARRANTY; without even the implied warranty of
9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10GNU General Public License for more details.
11
12You should have received a copy of the GNU General Public License
13along with Mura CMS. If not, see <http://www.gnu.org/licenses/>.
14
15Linking Mura CMS statically or dynamically with other modules constitutes the preparation of a derivative work based on
16Mura CMS. Thus, the terms and conditions of the GNU General Public License version 2 ("GPL") cover the entire combined work.
17
18However, as a special exception, the copyright holders of Mura CMS grant you permission to combine Mura CMS with programs
19or libraries that are released under the GNU Lesser General Public License version 2.1.
20
21In addition, as a special exception, the copyright holders of Mura CMS grant you permission to combine Mura CMS with
22independent software modules (plugins, themes and bundles), and to distribute these plugins, themes and bundles without
23Mura CMS under the license of your choice, provided that you follow these specific guidelines:
24
25Your custom code
26
27• Must not alter any default objects in the Mura CMS database and
28• May not alter the default display of the Mura CMS logo within Mura CMS and
29• Must not alter any files in the following directories.
30
31 /admin/
32 /tasks/
33 /config/
34 /requirements/mura/
35 /Application.cfc
36 /index.cfm
37 /MuraProxy.cfc
38
39You may copy and distribute Mura CMS with a plug-in, theme or bundle that meets the above guidelines as a combined work
40under the terms of GPL for Mura CMS, provided that you include the source code of that other code when and as the GNU GPL
41requires distribution of source code.
42
43For clarity, if you create a modified version of Mura CMS, you are not obligated to grant this special exception for your
44modified version; it is your choice whether to do so, or to make such modified version available under the GNU General Public License
45version 2 without this exception.  You may, if you choose, apply this exception to your own modified versions of Mura CMS.
46--->
47<cfcomponent output="false" extends="mura.cfobject">
48
49<cfif isDefined("url.args") OR isDefined("form.args")>
50        <cfset injectMethod("callWithStructArgs",call)>
51        <cfset injectMethod("call",callWithStringArgs)>
52</cfif>
53
54<cffunction name="purgeSiteCache" returntype="any" access="remote" output="false">
55        <cfargument name="siteid" required="true" default="">
56        <cfargument name="name" required="true" default="" hint="data, output or both">
57        <cfargument name="appreloadkey" required="true" default="">
58        <cfargument name="instanceID" required="true" default="">
59        <cfif arguments.instanceID neq application.instanceID
60                and arguments.appreloadkey eq application.appreloadkey>
61                <cfif len(arguments.siteid)>
62                        <cfset application.settingsManager.getSite(arguments.siteID).purgeCache(name=arguments.name,broadcast=false)>   
63                <cfelse>
64                        <cfset application.settingsManager.purgeAllCache(broadcast=false)>
65                </cfif>
66        </cfif>
67</cffunction>
68
69<cffunction name="purgeUserCache" returntype="any" access="remote" output="false">
70        <cfargument name="userID" required="true" default="">
71        <cfargument name="appreloadkey" required="true" default="">
72        <cfargument name="instanceID" required="true" default="">
73        <cfif arguments.instanceID neq application.instanceID
74                and arguments.appreloadkey eq application.appreloadkey>
75                <cfset application.userManager.purgeUserCache(userid=arguments.userID,broadcast=false)>
76        </cfif>
77</cffunction>
78
79<cffunction name="purgeCategoryCache" returntype="any" access="remote" output="false">
80        <cfargument name="categoryID" required="true" default="">
81        <cfargument name="appreloadkey" required="true" default="">
82        <cfargument name="instanceID" required="true" default="">
83        <cfif arguments.instanceID neq application.instanceID
84                and arguments.appreloadkey eq application.appreloadkey>
85                <cfset application.categoryManager.purgeCategoryCache(categoryID=arguments.categoryID,broadcast=false)>
86        </cfif>
87</cffunction>
88
89<cffunction name="purgeCategoryDescendentsCache" returntype="any" access="remote" output="false">
90        <cfargument name="categoryID" required="true" default="">
91        <cfargument name="appreloadkey" required="true" default="">
92        <cfargument name="instanceID" required="true" default="">
93        <cfif arguments.instanceID neq application.instanceID
94                and arguments.appreloadkey eq application.appreloadkey>
95                <cfset application.categoryManager.purgeCategoryDescendentsCache(categoryID=arguments.categoryID,broadcast=false)>
96        </cfif>
97</cffunction>
98
99<cffunction name="purgeContentCache" returntype="any" access="remote" output="false">
100        <cfargument name="contentID" required="true" default="">
101        <cfargument name="siteID" required="true" default="">
102        <cfargument name="appreloadkey" required="true" default="">
103        <cfargument name="instanceID" required="true" default="">
104        <cfif arguments.instanceID neq application.instanceID
105                and arguments.appreloadkey eq application.appreloadkey>
106                <cfset application.contentManager.purgeContentCache(contentID=arguments.contentID,siteID=arguments.siteID,broadcast=false)>
107        </cfif>
108</cffunction>
109
110<cffunction name="purgeContentDescendentsCache" returntype="any" access="remote" output="false">
111        <cfargument name="contentID" required="true" default="">
112        <cfargument name="siteID" required="true" default="">
113        <cfargument name="appreloadkey" required="true" default="">
114        <cfargument name="instanceID" required="true" default="">
115        <cfif arguments.instanceID neq application.instanceID
116                and arguments.appreloadkey eq application.appreloadkey>
117                <cfset application.contentManager.purgeContentDescendentsCache(contentID=arguments.contentID,siteID=arguments.siteID,broadcast=false)>
118        </cfif>
119</cffunction>
120
121<cffunction name="reload" returntype="any" access="remote" output="false">
122        <cfargument name="appreloadkey" required="true" default="">
123        <cfargument name="instanceID" required="true" default="">
124        <cfif arguments.instanceID neq application.instanceID
125                and arguments.appreloadkey eq application.appreloadkey>
126                <cfset application.appInitialized=false/>
127                <cfset application.broadcastInit=false />
128        </cfif>
129</cffunction>
130
131<cffunction name="login" returntype="any" output="false" access="remote">
132        <cfargument name="username">
133        <cfargument name="password">
134        <cfargument name="siteID">
135        <cfset var authToken=hash(createUUID())>
136        <cfset var rsSession="">
137        <cfset var sessionData="">
138       
139        <cfset application.loginManager.remoteLogin(arguments)>
140       
141        <cfif session.mura.isLoggedIn>
142                <cfwddx action="cfml2wddx" output="sessionData" input="#session.mura#">
143
144                <cfquery name="rsSession" datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
145                        select * from tuserremotesessions
146                        where userID=<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.mura.userID#">
147                </cfquery>
148               
149                <cfif rsSession.recordcount>
150                       
151                        <cfif rsSession.lastAccessed gte dateAdd("h",-3,now()) and application.configBean.getSharableRemoteSessions()>
152                                <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
153                                        update tuserremotesessions set
154                                        data=<cfqueryparam cfsqltype="cf_sql_varchar" value="#sessionData#">,
155                                        lastAccessed=<cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
156                                        where userID=<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.mura.userID#">
157                                </cfquery>
158                               
159                                <cfset authToken=rsSession.AuthToken>
160                               
161                        <cfelse>
162                                <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
163                                        update tuserremotesessions set
164                                        authToken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#authToken#">,
165                                        data=<cfqueryparam cfsqltype="cf_sql_varchar" value="#sessionData#">,
166                                        created=<cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">,
167                                        lastAccessed=<cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
168                                        where userID=<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.mura.userID#">
169                                </cfquery>
170                               
171                        </cfif>
172                <cfelse>
173                        <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
174                                INSERT Into tuserremotesessions (userID,authToken,data,created,lastAccessed)
175                                values(
176                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#session.mura.userID#">,
177                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#authToken#">,
178                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#sessionData#">,
179                                <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">,
180                                <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
181                                )
182                        </cfquery>
183       
184                </cfif>
185               
186               
187                <cfreturn authToken>
188        <cfelse>
189                <cfif isDate(session.blockLoginUntil) and session.blockLoginUntil gt now()>
190                        <cfset application.loginManager.logout()>
191                        <cfreturn "blocked">
192                <cfelse>
193                        <cfset application.loginManager.logout()>
194                        <cfreturn "false">
195                </cfif>
196        </cfif>
197</cffunction>
198
199<cffunction name="logout" returntype="any" output="false" access="remote">
200        <cfargument name="authToken">
201       
202        <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
203                update tuserremotesessions set
204                lastAccessed=#createODBCDateTime(dateAdd("h",-3,now()))#
205                where authToken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.authToken#">
206        </cfquery>
207       
208        <cfset application.loginManager.logout()>
209
210</cffunction>
211
212<cffunction name="getService" returntype="any" output="false">
213<cfargument name="serviceName">
214       
215        <cfif not structKeyExists(application,"proxyServices")>
216                <cfset application.proxyServices=structNew()>
217        </cfif>
218       
219        <cfif not structKeyExists(application.proxyServices, arguments.serviceName)>
220                <cfset application.proxyServices[arguments.serviceName]=createObject("component","mura.proxy.#arguments.serviceName#").init()>
221        </cfif>
222       
223        <cfreturn application.proxyServices[arguments.serviceName]>
224</cffunction>
225
226<cffunction name="isValidSession" returntype="any" output="false" access="remote">
227<cfargument name="authToken">
228        <cfset var rsSession="">
229       
230        <cfif not len(arguments.authToken)>
231                <cfreturn false>
232        <cfelse>
233                <cfquery name="rsSession" datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
234                        select authToken from tuserremotesessions
235                        where authtoken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.authToken#">
236                        and lastAccessed > #createODBCDateTime(dateAdd("h",-3,now()))#
237                </cfquery>
238               
239                <cfreturn rsSession.recordcount>
240        </cfif>
241</cffunction>
242
243<cffunction name="getSession" returntype="any" output="false">
244<cfargument name="authToken">
245        <cfset var rsSession="">
246        <cfset var sessionData=structNew()>
247       
248        <cfquery name="rsSession" datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
249                select * from tuserremotesessions
250                where authtoken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.authToken#">
251        </cfquery>
252       
253        <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
254                update tuserremotesessions
255                set lastAccessed=<cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
256                where authToken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.authToken#">
257        </cfquery>
258       
259        <cfwddx action="wddx2cfml" input="#rsSession.data#" output="sessionData">
260       
261        <cfreturn sessionData>
262</cffunction>
263
264<cffunction name="call" returntype="any" access="remote">
265<cfargument name="serviceName" type="string">
266<cfargument name="methodName" type="string">
267<cfargument name="authToken" type="string" default="">
268<cfargument name="args" default="#structNew()#" type="struct">
269
270<cfset var event="">
271<cfset var service=""> 
272
273<cfif (isDefined("session.mura.isLoggedIn") and session.mura.isLoggedIn)
274                or (len(arguments.authToken) and isValidSession(arguments.authToken))>
275       
276        <cfif len(arguments.authToken)>
277                <cfset session.mura=getSession(arguments.authToken)>
278                <cfset session.siteID=session.mura.siteID>
279                <cfset application.rbFactory.resetSessionLocale()>
280        </cfif>
281       
282        <cfif not isObject(arguments.args)>
283                <cfset event=createObject("component","mura.event")>
284                <cfset event.init(args)>
285                <cfset event.setValue("proxy",this)>
286        <cfelse>
287                <cfset event=args>
288        </cfif>
289
290        <cfset event.setValue("isProxyCall",true)>
291        <cfset event.setValue("serviceName",arguments.serviceName)>
292        <cfset event.setValue("methodName",arguments.methodName)>
293        <cfset service=getService(event.getValue('serviceName'))>
294       
295        <cfinvoke component="#service#" method="call">
296                <cfinvokeargument name="event" value="#event#" />
297        </cfinvoke>
298       
299        <cfif len(arguments.authToken)>
300                <cfset application.loginManager.logout()>
301        </cfif>
302       
303        <cfreturn event.getValue("__response__")>
304
305<cfelse>
306        <cfreturn "invalid session">
307</cfif>
308</cffunction>
309
310<cffunction name="callWithStringArgs" returntype="any" access="remote">
311        <cfargument name="serviceName" type="string">
312        <cfargument name="methodName" type="string">
313        <cfargument name="authToken" type="string" default="">
314        <cfargument name="args" default="" type="string">
315
316        <cfif isJSON(arguments.args)>
317                <cfset arguments.args=deserializeJSON(arguments.args)>
318        <cfelseif isWddx(arguments.args)>
319                <cfwddx action="wddx2cfml" input="#arguments.args#" output="arguments.args">
320        <cfelseif not isStruct(arguments.args)>
321                <cfset arguments.args=structNew()>
322        </cfif>
323        <cfreturn callWithStructArgs(argumentCollection=arguments)>
324</cffunction>
325
326</cfcomponent>
Note: See TracBrowser for help on using the repository browser.