forked from robtweed/EWD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_zewdAPI2.m
More file actions
211 lines (211 loc) · 5.74 KB
/
_zewdAPI2.m
File metadata and controls
211 lines (211 loc) · 5.74 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
%zewdAPI2 ; Enterprise Web Developer run-time functions and user APIs
;
; Product: Enterprise Web Developer (Build 931)
; Build Date: Fri, 27 Jul 2012 12:05:04
;
; ----------------------------------------------------------------------------
; | Enterprise Web Developer for GT.M and m_apache |
; | Copyright (c) 2004-12 M/Gateway Developments Ltd, |
; | Reigate, Surrey UK. |
; | All rights reserved. |
; | |
; | http://www.mgateway.com |
; | Email: rtweed@mgateway.com |
; | |
; | This program is free software: you can redistribute it and/or modify |
; | it under the terms of the GNU Affero General Public License as |
; | published by the Free Software Foundation, either version 3 of the |
; | License, or (at your option) any later version. |
; | |
; | This program is distributed in the hope that it will be useful, |
; | but WITHOUT ANY WARRANTY; without even the implied warranty of |
; | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
; | GNU Affero General Public License for more details. |
; | |
; | You should have received a copy of the GNU Affero General Public License |
; | along with this program. If not, see <http://www.gnu.org/licenses/>. |
; ----------------------------------------------------------------------------
;
;QUIT
;
;
getTmpSessionValue(name,sessid)
;
; Note: this is WebLink-specific, called from <?= #tmp.xxx ?>
;
n %zt,return,value
;
s name=$$stripSpaces^%zewdAPI(name)
i $g(name)="" QUIT ""
i $g(sessid)="" QUIT ""
i name["." d QUIT value
. n np,obj,prop
. i name["_" s name=$p(name,"_",1)_"."_$p(name,"_",2,200)
. s np=$l(name,".")
. s obj=$p(name,".",1,np-1)
. s prop=$p(name,".",np)
. s value=$$getTmpSessionObject(obj,prop,sessid)
s value=$g(sessionArray(name))
QUIT value
;
getTmpSessionObject(objectName,propertyName,sessid)
;
; Note: this is WebLink-specific, called from <?= #tmp.xxx ?>
;
n comma,i,np,p,value,x
;
i $g(sessid)="" QUIT ""
s value=""
s np=$l(objectName,".")
i objectName["." s objectName=$p(objectName,".",1)_"_"_$p(objectName,".",2,2000)
i np=1 QUIT $g(sessionArray((objectName_"_"_propertyName)))
;
f i=1:1:np-1 s p(i)=$p(objectName,".",i)
s x="s value=$g(sessionArray(",comma=""
f i=1:1:np-1 s x=x_comma_""""_p(i)_"""",comma=","
s x=x_","""_propertyName_"""))"
x x
QUIT value
;
;
; Output encoding functions to prevent XSS attacks
;
jsOutputEncode(string,max)
;
n stop,str
;
s max=$g(max)
i max="" s max=10
s stop=0
f i=1:1:max d q:stop
. s str=$$jsDecode(string)
. i str=string s stop=1
. s string=str
;
QUIT $$jsEncode(string)
;
jsEncode(string)
;
; Output encode untrusted value for use within Javascript
;
n a,buff,c,encode,i
s buff=""
f i=1:1:$l(string) d
. s c=$e(string,i)
. s a=$a(c)
. s encode=1
. i a=32 s encode=0 ; space
. i a>47,a<58 s encode=0 ; number
. i a>63,a<91 s encode=0 ; upper case
. i a>96,a<123 s encode=0 ; lower case
. i 'encode s buff=buff_c q
. ;
. s buff=buff_"\x"_$$hexEncode(a)
s buff=$$replaceAll^%zewdAPI(buff,"\x5Cn","\n")
s buff=$$replaceAll^%zewdAPI(buff,"\x5Cr","\r")
QUIT buff
;
hexEncode(number)
n hex,no,str
s hex=""
s str="123456789ABCDEF"
f d q:number=0
. s no=number#16
. s number=number\16
. i no s no=$e(str,no)
. s hex=no_hex
QUIT hex
;
hexDecode(hex)
QUIT $$hexToDecimal^%zewdGTMRuntime(hex)
;
jsDecode(string)
;
n a,c,c1,c12,c2,np,pos
;
s pos=$f(string,"\x")
f q:pos=0 d
. s pos=$f(string,"\x")
. q:pos=0
. s np=$l(string,"\x")+2
. s c12=$e(string,pos,pos+1)
. i $tr(c12,"0123456789ABCDEFabcdef","")'="" d
. . ; \x wasn't followed by 2 hex chars: temporarily escape out \x
. . s string=$p(string,"\x",1)_$c(1)_$p(string,"\x",2,np)
. e d
. . s c1=$e(c12,1)
. . s c2=$e(c12,2)
. . s a=($$hexDecode(c1)*16)+$$hexDecode(c2)
. . s c=$c(a)
. . s string=$p(string,"\x",1)_c_$e(string,pos+2,$l(string))
s string=$$REPLALL^%wlduta(string,$c(1),"\x")
QUIT string
;
htmlOutputEncode(string,max)
;
n stop,str
;
s max=$g(max)
i max="" s max=10
s stop=0
f i=1:1:max d q:stop
. s str=$$zcvt^%zewdAPI(string,"I","HTML")
. i str=string s stop=1
. s string=str
;
QUIT $$zcvt^%zewdAPI(string,"O","HTML")
;
urlOutputEncode(string,max)
;
n stop,str
;
s max=$g(max)
i max="" s max=10
s stop=0
f i=1:1:max d q:stop
. s str=$$urlEscape^%zewdGTMRuntime(str)
. i str=string s stop=1
. s string=str
;
QUIT $$urlUnescape^%zewdGTMRuntime(string)
;
test()
n ver
s ver=$$version^%zewdAPI()
s ver="<script>alert('"_ver_"')</script>"
QUIT ver
;
getNextSessionName(name,sessid)
;
QUIT $o(^%zewdSession("session",sessid,name))
;
getSessionNames(arrayOfNames,sessid)
;
n name
;
k arrayOfNames
s name=""
f s name=$$getNextSessionName(name,sessid) q:name="" d
. s arrayOfNames(name)=""
QUIT
;
recoverSymbolTable(sessid,web)
n (sessid,web)
n %zzv
s %zzv=""
f s %zzv=$o(^%zewdError(sessid,%zzv)) QUIT:%zzv="" d
. m @%zzv=^%zewdError(sessid,%zzv)
d writeSymbolTable(web)
QUIT
;
writeSymbolTable(web)
i $g(web)="node" d QUIT
. k web
. ;d writeLine("<pre>","node")
. d buffer^%zewdNode("zwrite")
. ;d writeLine("<pre>","node")
i $g(web) w "<pre>"
zwrite
i $g(web) w "</pre>"
QUIT
;