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
<cfsetting enablecfoutputonly="Yes">
<!---
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This file include generic functions used by the ColdFusion Connector (MX 6.0 and above).
--->
 
<cffunction name="RemoveFromStart" output="false" returntype="String">
    <cfargument name="sourceString" type="String">
    <cfargument name="charToRemove" type="String">
 
    <cfif left(ARGUMENTS.sourceString, 1) eq ARGUMENTS.charToRemove>
        <cfreturn mid( ARGUMENTS.sourceString, 2, len(ARGUMENTS.sourceString) -1 )>
    </cfif>
 
    <cfreturn ARGUMENTS.sourceString>
</cffunction>
 
<cffunction name="RemoveFromEnd" output="false" returntype="String">
    <cfargument name="sourceString" type="String">
    <cfargument name="charToRemove" type="String">
 
    <cfif right(ARGUMENTS.sourceString, 1) eq ARGUMENTS.charToRemove>
        <cfreturn mid( ARGUMENTS.sourceString, 1, len(ARGUMENTS.sourceString) -1 )>
    </cfif>
 
    <cfreturn ARGUMENTS.sourceString>
</cffunction>
 
<!---
Check file content.
Currently this function validates only image files.
Returns false if file is invalid.
detectionLevel:
    0 = none
    1 = check image size for images,
    2 = use DetectHtml for images
---->
<cffunction name="IsImageValid" returntype="boolean" output="true">
    <cfargument name="filePath" required="true" type="String">
    <cfargument name="extension" required="true" type="String">
 
    <cfset var imageCFC = "">
    <cfset var imageInfo = "">
 
    <cfif not ListFindNoCase("gif,jpeg,jpg,png,swf,psd,bmp,iff,tiff,tif,swc,jpc,jp2,jpx,jb2,xmb,wbmp", ARGUMENTS.extension)>
        <cfreturn true>
    </cfif>
 
    <cftry>
        <cfif REQUEST.CFVersion gte 8>
            <cfset objImage = ImageRead(ARGUMENTS.filePath) >
            <cfset imageInfo = ImageInfo(objImage)>
            <!--- <cfimage action="info" source="#ARGUMENTS.filePath#" structName="imageInfo" /> --->
        <cfelse>
            <cfset imageCFC = createObject("component", "image")>
            <cfset imageInfo = imageCFC.getImageInfo("", ARGUMENTS.filePath)>
        </cfif>
 
        <cfif imageInfo.height lte 0 or imageInfo.width lte 0>
            <cfreturn false>
        </cfif>
    <cfcatch type="any">
        <cfreturn false>
    </cfcatch>
    </cftry>
 
    <cfreturn true>
</cffunction>
 
<!---
 Detect HTML in the first KB to prevent against potential security issue with
 IE/Safari/Opera file type auto detection bug.
 Returns true if file contain insecure HTML code at the beginning.
--->
<cffunction name="DetectHtml" output="false" returntype="boolean">
    <cfargument name="filePath" required="true" type="String">
 
    <cfset var tags = "<body,<head,<html,<img,<pre,<script,<table,<title">
    <cfset var chunk = lcase( Trim( BinaryFileRead( ARGUMENTS.filePath, 1024 ) ) )>
 
    <cfif not Len(chunk)>
        <cfreturn false>
    </cfif>
 
    <cfif refind('<!doctype\W*x?html', chunk)>
        <cfreturn true>
    </cfif>
 
    <cfloop index = "tag" list = "#tags#">
         <cfif find( tag, chunk )>
            <cfreturn true>
        </cfif>
    </cfloop>
 
    <!--- type = javascript --->
    <cfif refind('type\s*=\s*[''"]?\s*(?:\w*/)?(?:ecma|java)', chunk)>
        <cfreturn true>
    </cfif> >
 
    <!--- href = javascript --->
    <!--- src = javascript --->
    <!--- data = javascript --->
    <cfif refind('(?:href|src|data)\s*=\s*[\''"]?\s*(?:ecma|java)script:', chunk)>
        <cfreturn true>
    </cfif>
 
    <!--- url(javascript --->
    <cfif refind('url\s*\(\s*[\''"]?\s*(?:ecma|java)script:', chunk)>
        <cfreturn true>
    </cfif>
 
    <cfreturn false>
</cffunction>