source: branches/5.2/www/MuraProxy.cfc @ 2456

Revision 2456, 9.8 KB checked in by mattlevine, 23 months ago (diff)
  1. Adding application.instanceID to determine witch Mura instance in a cluster made a request.
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
16the preparation of a derivative work based on Mura CMS. Thus, the terms and     
17conditions of the GNU General Public License version 2 (ÔÞΩGPLÔÞΩ) cover the entire combined work.
18
19However, as a special exception, the copyright holders of Mura CMS grant you permission
20to combine Mura CMS with programs or libraries that are released under the GNU Lesser General Public License version 2.1.
21
22In addition, as a special exception, ÔÞΩthe copyright holders of Mura CMS grant you permission
23to combine Mura CMS ÔÞΩwith independent software modules that communicate with Mura CMS solely
24through modules packaged as Mura CMS plugins and deployed through the Mura CMS plugin installation API,
25provided that these modules (a) may only modify the ÔÞΩ/trunk/www/plugins/ directory through the Mura CMS
26plugin installation API, (b) must not alter any default objects in the Mura CMS database
27and (c) must not alter any files in the following directories except in cases where the code contains
28a separately distributed license.
29
30/trunk/www/admin/
31/trunk/www/tasks/
32/trunk/www/config/
33/trunk/www/requirements/mura/
34
35You may copy and distribute such a combined work under the terms of GPL for Mura CMS, provided that you include
36the source code of that other code when and as the GNU GPL requires distribution of source code.
37
38For clarity, if you create a modified version of Mura CMS, you are not obligated to grant this special exception
39for your modified version; it is your choice whether to do so, or to make such modified version available under
40the GNU General Public License version 2 ÔÞΩwithout this exception. ÔÞΩYou may, if you choose, apply this exception
41to your own modified versions of Mura CMS.
42--->
43<cfcomponent output="false" extends="mura.cfobject">
44
45<cffunction name="purgeSiteCache" returntype="any" access="remote" output="false">
46        <cfargument name="siteid" required="true" default="">
47        <cfargument name="appreloadkey" required="true" default="">
48        <cfargument name="instanceID" required="true" default="">
49        <cfif arguments.instanceID neq application.instanceID
50                and arguments.appreloadkey eq application.appreloadkey>
51                <cfif len(arguments.siteid)>
52                        <cfset application.settingsManager.getSite(arguments.siteID).getCacheFactory().purgeAll()>     
53                <cfelse>
54                        <cfset application.settingsManager.purgeAllCache()>
55                </cfif>
56        </cfif>
57</cffunction>
58
59<cffunction name="reload" returntype="any" access="remote" output="false">
60        <cfargument name="appreloadkey" required="true" default="">
61        <cfargument name="instanceID" required="true" default="">
62        <cfif arguments.instanceID neq application.instanceID
63                and arguments.appreloadkey eq application.appreloadkey>
64                <cfset application.appInitialized=false/>
65                <cfset application.broadcastInit=false />
66        </cfif>
67</cffunction>
68
69<cffunction name="login" returntype="any" output="false" access="remote">
70        <cfargument name="username">
71        <cfargument name="password">
72        <cfargument name="siteID">
73        <cfset var authToken=hash(createUUID())>
74        <cfset var rsSession="">
75        <cfset var sessionData="">
76       
77        <cfset application.loginManager.remoteLogin(arguments)>
78       
79        <cfif session.mura.isLoggedIn>
80                <cfwddx action="cfml2wddx" output="sessionData" input="#session.mura#">
81
82                <cfquery name="rsSession" datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
83                        select * from tuserremotesessions
84                        where userID=<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.mura.userID#">
85                </cfquery>
86               
87                <cfif rsSession.recordcount>
88                       
89                        <cfif rsSession.lastAccessed gte dateAdd("h",-3,now()) and application.configBean.getSharableRemoteSessions()>
90                                <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
91                                        update tuserremotesessions set
92                                        data=<cfqueryparam cfsqltype="cf_sql_varchar" value="#sessionData#">,
93                                        lastAccessed=#createODBCDateTime(now())#
94                                        where userID=<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.mura.userID#">
95                                </cfquery>
96                               
97                                <cfset authToken=rsSession.AuthToken>
98                               
99                        <cfelse>
100                                <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
101                                        update tuserremotesessions set
102                                        authToken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#authToken#">,
103                                        data=<cfqueryparam cfsqltype="cf_sql_varchar" value="#sessionData#">,
104                                        created=#createODBCDateTime(now())#,
105                                        lastAccessed=#createODBCDateTime(now())#
106                                        where userID=<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.mura.userID#">
107                                </cfquery>
108                               
109                        </cfif>
110                <cfelse>
111                        <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
112                                INSERT Into tuserremotesessions (userID,authToken,data,created,lastAccessed)
113                                values(
114                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#session.mura.userID#">,
115                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#authToken#">,
116                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#sessionData#">,
117                                #createODBCDateTime(now())#,
118                                #createODBCDateTime(now())#
119                                )
120                        </cfquery>
121       
122                </cfif>
123               
124               
125                <cfreturn authToken>
126        <cfelse>
127                <cfif isDate(session.blockLoginUntil) and session.blockLoginUntil gt now()>
128                        <cfset application.loginManager.logout()>
129                        <cfreturn "blocked">
130                <cfelse>
131                        <cfset application.loginManager.logout()>
132                        <cfreturn "false">
133                </cfif>
134        </cfif>
135</cffunction>
136
137<cffunction name="logout" returntype="any" output="false" access="remote">
138        <cfargument name="authToken">
139       
140        <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
141                update tuserremotesessions set
142                lastAccessed=#createODBCDateTime(dateAdd("h",-3,now()))#
143                where authToken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.authToken#">
144        </cfquery>
145       
146        <cfset application.loginManager.logout()>
147
148</cffunction>
149
150<cffunction name="getService" returntype="any" output="false">
151<cfargument name="serviceName">
152       
153        <cfif not structKeyExists(application,"proxyServices")>
154                <cfset application.proxyServices=structNew()>
155        </cfif>
156       
157        <cfif not structKeyExists(application.proxyServices, arguments.serviceName)>
158                <cfset application.proxyServices[arguments.serviceName]=createObject("component","mura.proxy.#arguments.serviceName#").init()>
159        </cfif>
160       
161        <cfreturn application.proxyServices[arguments.serviceName]>
162</cffunction>
163
164<cffunction name="isValidSession" returntype="any" output="false">
165<cfargument name="authToken">
166        <cfset var rsSession="">
167       
168        <cfif not len(arguments.authToken)>
169                <cfreturn false>
170        <cfelse>
171                <cfquery name="rsSession" datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
172                        select authToken from tuserremotesessions
173                        where authtoken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.authToken#">
174                        and lastAccessed > #createODBCDateTime(dateAdd("h",-3,now()))#
175                </cfquery>
176               
177                <cfreturn rsSession.recordcount>
178        </cfif>
179</cffunction>
180
181<cffunction name="getSession" returntype="any" output="false">
182<cfargument name="authToken">
183        <cfset var rsSession="">
184        <cfset var sessionData=structNew()>
185       
186        <cfquery name="rsSession" datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
187                select * from tuserremotesessions
188                where authtoken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.authToken#">
189        </cfquery>
190       
191        <cfquery datasource="#application.configBean.getDatasource()#" username="#application.configBean.getDBUsername()#" password="#application.configBean.getDBPassword()#">
192                update tuserremotesessions
193                set lastAccessed=#createODBCDateTime(now())#
194                where authToken=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.authToken#">
195        </cfquery>
196       
197        <cfwddx action="wddx2cfml" input="#rsSession.data#" output="sessionData">
198       
199        <cfreturn sessionData>
200</cffunction>
201
202<cffunction name="call" returntype="any" access="remote">
203<cfargument name="serviceName">
204<cfargument name="methodName">
205<cfargument name="authToken">
206<cfargument name="args">
207
208<cfset var event="">
209<cfset var service=""> 
210
211<cfif len(arguments.authToken) and isValidSession(arguments.authToken)>
212        <cfset session.mura=getSession(arguments.authToken)>
213       
214        <cfif not isObject(arguments.args)>
215                <cfset event=createObject("component","mura.event")>
216                <cfset event.init(args)>
217                <cfset event.setValue("proxy",this)>
218        <cfelse>
219                <cfset event=args>
220        </cfif>
221
222        <cfset event.setValue("isProxyCall",true)>
223        <cfset event.setValue("serviceName",arguments.serviceName)>
224        <cfset event.setValue("methodName",arguments.methodName)>
225        <cfset service=getService(event.getValue('serviceName'))>
226       
227        <cfinvoke component="#service#" method="call">
228                <cfinvokeargument name="event" value="#event#" />
229        </cfinvoke>
230       
231        <cfset application.loginManager.logout()>
232        <cfreturn event.getValue("__response__")>
233
234<cfelse>
235        <cfreturn "invalid session">
236</cfif>
237</cffunction>
238
239</cfcomponent>
Note: See TracBrowser for help on using the repository browser.