294 lines
9.2 KiB
Plaintext
294 lines
9.2 KiB
Plaintext
<cfcomponent
|
||
displayname="Application"
|
||
output="true"
|
||
hint="Handle the application.">
|
||
|
||
|
||
<!--- Set up the application. --->
|
||
<cfset this.Name = "Contracts and Specifications" />
|
||
<cfset this.applicationTimeout = createTimeSpan( 0, 0, 1, 0 ) />
|
||
<cfset this.sessionmanagement="Yes"/>
|
||
<cfset this.clientmanagement="No"/>
|
||
<cfset this.sessiontimeout=CreateTimeSpan(0, 0, 120, 0)/>
|
||
<cfset this.setclientcookies="No"/>
|
||
<cfset this.mappings = structNew() />
|
||
<cfset this.mappings["/mod"] = getDirectoryFromPath(getCurrentTemplatePath()) & "mod/" />
|
||
<cfset this.customTagPaths = expandPath(getDirectoryFromPath(getCurrentTemplatePath())&'mod')/>
|
||
|
||
<cfset this.datasource = "spec"/>
|
||
<cfset this.defaultdatasource = this.datasource/>
|
||
<cfset request.DS = "#this.datasource#">
|
||
<cfset this.datasources["#this.datasource#"]=getDS("#this.datasource#","datasource_#this.datasource#")/>
|
||
|
||
<cfset COOKIEENCKEY = "PREVED!Y2"/>
|
||
<!--- Define the page request properties. --->
|
||
<cfsetting
|
||
requesttimeout="20"
|
||
showdebugoutput="false"
|
||
enablecfoutputonly="false"
|
||
/>
|
||
|
||
<cffunction
|
||
name="OnApplicationStart"
|
||
access="public"
|
||
returntype="boolean"
|
||
output="false"
|
||
hint="Fires when the application is first created.">
|
||
|
||
<cfreturn true />
|
||
</cffunction>
|
||
|
||
<cffunction
|
||
name="OnRequest"
|
||
access="public"
|
||
returntype="void"
|
||
output="true"
|
||
hint="Fires after pre page processing is complete.">
|
||
|
||
<cfargument name="template" type="string" required="true"/>
|
||
|
||
<cfset request.startTickCount=getTickCount()/>
|
||
|
||
<cfset setEncoding("FORM", "UTF-8")>
|
||
<cfset setEncoding("URL", "UTF-8")>
|
||
|
||
<cfset request.PERMISSION_NONE=0/>
|
||
<cfset request.PERMISSION_READ=1/>
|
||
<cfset request.PERMISSION_WRITE=2/>
|
||
|
||
<cfset request.UNDEFINED_USR_ID=-1/>
|
||
<!--- request.ROOT_USR_ID=1 not used --->
|
||
<cfset request.ANONYMOUS_USR_ID=2/>
|
||
<cfset request.GUEST_USR_ID=3/>
|
||
|
||
|
||
<cfset DAYSCALE_START = '2024-01-01'/>
|
||
<cfset DAYSCALE_FINISH = '2026-12-31'/>
|
||
|
||
<!--- global settings --->
|
||
|
||
<!--- <cfset this.datasource = "spec"/>
|
||
*** здесь не работает!<cfset this.defaultdatasource = this.datasource/>
|
||
<cfset request.DS = "#this.datasource#"> --->
|
||
<!--- <cfset this.datasources["#this.datasource#"]=getDS("#this.datasource#","datasource_#this.datasource#")/> --->
|
||
|
||
<cfset request.RECORDS_PER_PAGE=500/>
|
||
<cfset request.APP_VERSION="0.00.022"/>
|
||
|
||
<cflock scope="application" type="readonly" timeout=3>
|
||
<cfset request.APP_NAME=this.Name/>
|
||
</cflock>
|
||
|
||
|
||
|
||
<cfset local = {} /> <!--- между прочим, эта переменная будет видна во включенных included страницах --->
|
||
|
||
<cfset local.basePath = getDirectoryFromPath(
|
||
getCurrentTemplatePath()
|
||
) />
|
||
|
||
<cfset local.targetPath = getDirectoryFromPath(
|
||
expandPath( arguments.template )
|
||
) />
|
||
|
||
<cfset local.requestDepth = (
|
||
listLen( local.targetPath, "\/" ) -
|
||
listLen( local.basePath, "\/" )
|
||
) />
|
||
|
||
<cfset request.webRoot = repeatString(
|
||
"../",
|
||
local.requestDepth
|
||
) />
|
||
|
||
<!---
|
||
While we wouldn't normally do this for every page
|
||
request (it would normally be cached in the
|
||
application initialization), I'm going to calculate
|
||
the site URL based on the web root.
|
||
--->
|
||
<cfset request.siteUrl = (
|
||
IIF(
|
||
(CGI.server_port_secure <!--- CGI.https EQ "On" does not work with apache+tomcat and nginx+tomcat --->),
|
||
DE( "https://" ),
|
||
DE( "http://" )
|
||
) &
|
||
cgi.http_host &
|
||
reReplace(
|
||
getDirectoryFromPath( arguments.template ),
|
||
"([^\\/]+[\\/]){#local.requestDepth#}$",
|
||
"",
|
||
"one"
|
||
)
|
||
) />
|
||
|
||
<cfset request.thisPage=Replace(ReplaceNoCase(expandPath(ARGUMENTS.template), local.basePath, ""), "\", "/")/>
|
||
|
||
<cfinclude template="inc/functions.cfm"/>
|
||
|
||
<cfcookie name="CFID" value="#session.CFID#">
|
||
<cfcookie name="CFTOKEN" value="#session.CFTOKEN#">
|
||
|
||
<!--- check saved login --->
|
||
<!---
|
||
если в сессии есть usr_id, ничего делать не нужно
|
||
если его нет (то есть сессия новая или свежесброшенная),
|
||
- проверить куки.
|
||
Дополнительное условие: если происходит процесс установки-сброса кук,
|
||
(в процессе установки-сброса определена переменная session.save_login) - не вмешиваемся
|
||
--->
|
||
|
||
<cflock scope="session" type="exclusive" timeout="3">
|
||
|
||
<!---<cfset session.usr_id = 10> *** --->
|
||
|
||
<cfif NOT structKeyExists(session,"usr_id") OR (structKeyExists(session,"usr_id") AND NOT isNumeric(session.usr_id))>
|
||
<cfset session.usr_id=#request.UNDEFINED_USR_ID#>
|
||
</cfif>
|
||
|
||
<cfif session.usr_id EQ request.UNDEFINED_USR_ID>
|
||
<cfif NOT structKeyExists(session, "save_login")>
|
||
<cfif structKeyExists(cookie, "portalUser")>
|
||
<cftry>
|
||
<cfset login = Decrypt(cookie.portalUser,COOKIEENCKEY)>
|
||
<cfoutput>#login#</cfoutput>
|
||
|
||
<cfquery name="qGetCredentials" datasource="#request.DS#">
|
||
select usr_id from usr where login='#login#'
|
||
</cfquery>
|
||
|
||
<cfset session.usr_id = qGetCredentials.usr_id>
|
||
<m:settings action="create"/>
|
||
|
||
<cfcatch type="Any">
|
||
<cfoutput>#cfcatch.message#</cfoutput>
|
||
<cfset session.usr_id = request.UNDEFINED_USR_ID>
|
||
</cfcatch>
|
||
</cftry>
|
||
</cfif>
|
||
</cfif>
|
||
</cfif>
|
||
|
||
<cfif session.usr_id EQ request.UNDEFINED_USR_ID>
|
||
<cfset session.usr_id = request.ANONYMOUS_USR_ID>
|
||
</cfif>
|
||
|
||
<cfset request.usr_id=session.usr_id/>
|
||
|
||
<cfif structKeyExists(session, "username")>
|
||
<cfset request.username=#session.username#/>
|
||
<cfelse>
|
||
<cfset request.username=""/>
|
||
</cfif>
|
||
|
||
<cfparam name="language" default=""/>
|
||
<cfif language EQ "ru" OR language EQ "en">
|
||
<cfset session.language=language/>
|
||
<cfelse>
|
||
<cfparam name="session.language" default="ru"/>
|
||
</cfif>
|
||
<cfset request.language=session.language/>
|
||
|
||
</cflock><!--- session exclusive --->
|
||
|
||
<cfset request.usr_is_admin=0/>
|
||
|
||
|
||
<cfif request.usr_id GT 0 AND request.usr_id NEQ request.ANONYMOUS_USR_ID> <!--- в данном случае закрыли анонимный доступ --->
|
||
<cfinclude template="#ARGUMENTS.template#"/>
|
||
<cfelse>
|
||
<cfset currentDir = (
|
||
lCase(
|
||
replace(
|
||
getDirectoryFromPath(
|
||
replaceNoCase(
|
||
expandPath(
|
||
ARGUMENTS.template
|
||
),
|
||
getDirectoryFromPath(
|
||
getCurrentTemplatePath()
|
||
),
|
||
""
|
||
)
|
||
), "\", "/", "ALL"
|
||
)
|
||
)
|
||
)/>
|
||
<cfif currentDir EQ "saml/"><!--- note traling slash --->
|
||
<cfinclude template="#ARGUMENTS.template#"/>
|
||
<cfelse>
|
||
<cfinclude template="login.cfm" />
|
||
</cfif>
|
||
</cfif>
|
||
|
||
<cfreturn />
|
||
</cffunction>
|
||
|
||
|
||
<cffunction
|
||
name="OnRequestEnd"
|
||
access="public"
|
||
returntype="void"
|
||
output="true"
|
||
hint="Fires after the page processing is complete.">
|
||
<!--- Attention! Before CF9, OnrequestEnd is not executed in case of redirect. That is why we use session.save_login --->
|
||
|
||
<cfif structKeyExists(session, "save_login")>
|
||
<cfif session.save_login EQ "">
|
||
<!--- unset (expire) cookie --->
|
||
<cfcookie expires="-1" name="portalUser" value="">
|
||
<cfelse>
|
||
<!--- set persistent cookie with no expiration --->
|
||
<cfcookie expires="NEVER" name="portalUser" value="#encrypt(session.save_login,COOKIEENCKEY)#">
|
||
</cfif>
|
||
<cfset structDelete(session, "save_login")>
|
||
</cfif>
|
||
|
||
<cfreturn />
|
||
</cffunction>
|
||
|
||
|
||
<cffunction
|
||
name="getDS"
|
||
access="private"
|
||
returntype="struct"
|
||
output="true"
|
||
hint="Configure data source from environment variables. Convention: data source name is an environment varialble prefix">
|
||
|
||
<cfargument name="dsname" type="string" required="true"/>
|
||
<cfargument name="prefix" type="string" default=#dsname#/>
|
||
|
||
<cfset system = createObject("java", "java.lang.System")/>
|
||
<cfset var ds={}/>
|
||
|
||
<cfloop list="class,connectionString,database,driver,dbdriver,host,port,type,url,username,password,bundleName,bundleVersion,connectionLimit,liveTimeout,validate" item="field"><!--- driver vs dbdriver --->
|
||
<cfset var value=system.getEnv("#arguments.prefix#_#field#")/>
|
||
<cfif isDefined("value") AND len(value)>
|
||
<cfset structInsert(ds,field,value)/>
|
||
</cfif>
|
||
</cfloop>
|
||
<cfif structIsEmpty(ds)>
|
||
<cfthrow type="application" message="Datasource not configured" detail="Datasource not defined in the environment. Expected prefix is #arguments.prefix#"/>
|
||
</cfif>
|
||
|
||
<!--- test datasource (just to get exception if invalid) --->
|
||
<cftry>
|
||
<cfquery name="qTestDs" datasource=#ds#>
|
||
select 1;
|
||
</cfquery>
|
||
|
||
<cfcatch type="any">
|
||
<!---
|
||
<cfdump var=#ds#/>
|
||
<cfdump var=#system.getEnv()#/>
|
||
<cfabort/>
|
||
--->
|
||
<cfrethrow/>
|
||
</cfcatch>
|
||
</cftry>
|
||
|
||
<cfreturn ds/>
|
||
</cffunction>
|
||
|
||
|
||
</cfcomponent> |