Home directory for Malawi's wwwroot
Duncan Ewan
2021-02-19 3e758c29e0fde36fc088efcfc88f9a3014432b64
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
120
121
122
123
124
125
126
127
128
129
130
131
<!--- Import L10N Taglib (System Generated) --->
<cfimport prefix="admin" taglib="../administrator/cftags/">
 
<!--- Establish page locale, default is english (en). --->
<cfparam name="request.locale" default="en">
<cfscript>
    if(IsDefined("FORM.locale")) { request.locale = LCase(Trim(FORM.locale)); }
    request.localeFile = "resources/general_#request.locale#.xml";
</cfscript>
 
<cfset cookiest = {httponly='true', timeout=createTimeSpan(0, 0, 30, 0), secure='#CGI.SERVER_PORT_SECURE#'}>
<cfset cookieast = {timeout=createTimeSpan(0, 0, 20, 0)}>
<cftry>
<cfapplication name="componentutils" sessionmanagement="Yes" sessiontimeout="#createTimeSpan(0,0,30,0)#" 
                       scriptprotect="form,url" sessioncookie=#cookiest# authcookie=#cookieast#>
<cfcatch type="Any">
    <!--- ///if session management has been disabled. Use this version of the tag. So the app still 
    works. Archives won't tho.    /// --->
    <cfapplication name="componentutils" scriptprotect="form,url" sessioncookie=#cookiest# authcookie=#cookieast#>
</cfcatch>
</cftry>
    
<cfsetting showdebugoutput="no">
<cfset factory = createObject( "java", "coldfusion.server.ServiceFactory" )>
<cfset request.security = factory.securityService>
<cfset request.esapiutils = createObject("java", "coldfusion.security.ESAPIUtils")>
 
<!--- Check if RDS service is enabled. If not, then show error and return.--->
<cfif not request.security.isRdsEnabled()>
    <admin:l10n id="componentutilnotavailable" var="componentutilnotavailable">
            Unsupported Operation. Check application log for more details.
    </admin:l10n>
    <admin:l10n id="component_rdsenable" var="component_rdsenable">
            To use Component Browser, enable RDS Service using Administrator. Note: RDS is intended for development use only.
    </admin:l10n>
    <cfoutput>
        <br> <br>
        #componentutilnotavailable#
        <br> <br>
    </cfoutput>
    <cflog text="#component_rdsenable#"  type="warning">
    <cfabort>
</cfif>
 
<cfset authorized = true>
 
<cftry>
<cfif request.security.RDSSecurityEnabled>
    <cflogin>
        <cfscript>
            authHeader = 'Authorization-MX' ;
        
            authorized = false ;
            
            httpReq = GetHTTPRequestData() ;
            // check the DW authorization header
            if ( StructKeyExists( httpReq.headers, authHeader ) ) {
            
                authString = ListGetAt( httpReq.headers[authHeader], 2, ' ' ) ;
                authString = ToBinary( authString ) ;        
                
                credentials = createObject( "java", "java.lang.String" ) ;
                credentials.init( authString ) ;
                
                // listLast() bug forces us to do it in this way
                pos = Find( ':', credentials.toString() ) ;
                if ( pos neq 0 )
                {
                    // Incase of multiuser RDS, the username will also be sent in the header. Hence, retrieve the user.
                    user = RemoveChars(credentials.toString(), pos, credentials.toString().length());
                    password = RemoveChars( credentials.toString(), 1, pos ) ;
                }
            }
            // check the form password field
            else if ( IsDefined('form.j_password') )
            {
                password = form.j_password ;
                // Bug 73997: username field should be named j_username so that <cflogin> tag identifies the form credentials 
                if (IsDefined('form.j_username'))
                {
                    user = form.j_username;
                }
                else
                {
                    //if singleRDSpassword enabled, set the password value to user.
                    if(request.security.getUseSingleRdsPassword())
                    {
                        user = request.security.getRootAdminUserId();
                    } 
                }
            }
 
            if ( IsDefined('password') )
            {
                if (request.security.getUseSingleRdsPassword())
                {
                    authorized = request.security.checkRDSPassword( password ) ;
                } 
                else
                {
                    if (IsDefined('user') AND len(trim(user)))
                    {
                        authorized = request.security.checkRDSUserIdPassword(user, password) AND request.security.canAccessRDS(user);
                    } else {
                        NullUserIdEntered = true;
                    }
                }
                
                if (not authorized)
                {
                    InvalidUserIdOrPasswordEntered = true;
                }
                    
            }
        </cfscript>
        
        <cfif authorized>
            <cfloginuser roles="RDSUser" name="#user#" password="#password#">        
        </cfif>
 
    </cflogin>
</cfif>
<cfcatch type="any">
    <cfset authorized = false>
</cfcatch>
</cftry>
 
<cfif not authorized>
    <cfinclude template="login.cfm">
    <cfabort>
</cfif>