forked from verhas/ScriptBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgi.bas
More file actions
155 lines (137 loc) · 5.31 KB
/
cgi.bas
File metadata and controls
155 lines (137 loc) · 5.31 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
' """
FILE: cgi.bas
This is the BASIC import file for the module cgi.
This file was generated by headerer.pl from the file interface.c
Do not edit this file, rather edit the file interface.c and use
headerer.pl to regenerate this file.
"""
module cgi
' When requestiong SaveFile for a field name that does not exist
const ErrorNoFile = &H00080000
const ErrorBufferOverflow = &H00080001
const ErrorContentTooLarge = &H00080002
const ErrorMethodIsInvalid = &H00080003
const ErrorNoDebugFile = &H00080004
const ErrorNotImplemented = &H00080005
const ErrorEndOfFile = &H00080006
const ErrorIllFormedUpload = &H00080007
const ErrorFileTooLarge = &H00080008
const ErrorMethodNotAllowed = &H0008000A
' constants for setting option cgi$Method
const None = &H00000000
const Get = &H00000001
const Post = &H00000002
const Upload = &H00000006
const Put = &H00000008
const Del = &H00000010
const Copy = &H00000020
const Move = &H00000040
const Head = &H00000080
Function Param(ParameterName)
local ParameterValue
ParameterValue = GetParam(ParameterName)
If NOT IsDefined(ParameterValue) Then
ParameterValue = PostParam(ParameterName)
End If
Param = ParameterValue
End Function
'
' cgi::ResolveHtml(Text)
' Resolve an HTML text given as argument
'
sub ResolveHtml(HtmlText)
ResolveHtml = GetHtmlTemplate(HtmlText,1)
end sub
'
' cgi::EmitHtmlTemplate(FileName)
' emit the content of the HTML template to the web client
'
sub EmitHtmlTemplate(FileName)
print GetHtmlTemplate(FileName)
end sub
sub Header(State,ContentType)
if isDefined(HeaderWasPrinted) then exit sub
HeaderWasPrinted = TRUE
if ServerSoftware() like "Microsoft-IIS*" then
print "HTTP/1.0 ",State,"\nContent-Type: ",ContentType,"\n"
else
print "Status: ",State,"\nContent-Type: ",ContentType,"\n"
end if
end sub
sub RequestBasicAuthentication(Realm)
if not IsDefined(Realm) then Realm = "Basic Authentication Realm"
Header 401,"text/html"
print "WWW-Authenticate: Basic realm=\"",Realm,"\"\n"
end sub
sub SetCookie(CookieName,CookieValue,CookieDomain,CookiePath,CookieExpires,CookieIsSecure)
print "Set-cookie: ",CookieName,"=",CookieValue,";"
if IsDefined( CookieDomain ) then
print " domain=",CookieDomain,";"
end if
if IsDefined( CookiePath ) then
print " path=",CookiePath,";"
end if
if IsDefined(CookieExpires) then
print FormatDate("expires=WDN, DD-MON-YY HH:mm:ss GMT;",CookieExpires)
end if
'Wdy, DD-Mon-YY HH:MM:SS GMT
if CookieIsSecure then
print " secure"
end if
print "\n"
end sub
sub FinishHeader
if isDefined(HeaderWasFinished) then exit sub
HeaderWasFinished = TRUE
print "\n"
end sub
function Cookie(CookieName)
local RawCookieText,CookieList,i,LikeString,CookieValue
RawCookieText = RawCookie()
splita RawCookieText by ";" to CookieList
LikeString = CookieName & "=*"
i = 0
while IsDefined(CookieList[i])
CookieList[i] = trim(CookieList[i])
if CookieList[i] LIKE LikeString then
split CookieList[i] by "=" to CookieName,CookieValue
Cookie = CookieValue
exit function
end if
i = i + 1
wend
' by default function return value is undef when cookie is not found
end function
' FUNCTION DECLARATIONS
declare sub ::GetParam alias "getget" lib "cgi"
declare sub ::PostParam alias "getpost" lib "cgi"
declare sub ::GetParamEx alias "getgetex" lib "cgi"
declare sub ::PostParamEx alias "getpostex" lib "cgi"
declare sub ::SaveFile alias "savefile" lib "cgi"
declare sub ::FileName alias "filename" lib "cgi"
declare sub ::FileLength alias "filelen" lib "cgi"
declare sub ::ServerSoftware alias "ServerSoftware" lib "cgi"
declare sub ::ServerName alias "ServerName" lib "cgi"
declare sub ::GatewayInterface alias "GatewayInterface" lib "cgi"
declare sub ::ServerProtocol alias "ServerProtocol" lib "cgi"
declare sub ::ServerPort alias "ServerPort" lib "cgi"
declare sub ::RequestMethod alias "RequestMethod" lib "cgi"
declare sub ::PathInfo alias "PathInfo" lib "cgi"
declare sub ::PathTranslated alias "PathTranslated" lib "cgi"
declare sub ::ScriptName alias "ScriptName" lib "cgi"
declare sub ::QueryString alias "QueryString" lib "cgi"
declare sub ::RemoteHost alias "RemoteHost" lib "cgi"
declare sub ::RemoteAddress alias "RemoteAddress" lib "cgi"
declare sub ::AuthType alias "AuthType" lib "cgi"
declare sub ::RemoteUser alias "RemoteUser" lib "cgi"
declare sub ::RemoteIdent alias "RemoteIdent" lib "cgi"
declare sub ::ContentType alias "ContentType" lib "cgi"
declare sub ::ContentLength alias "ContentLength" lib "cgi"
declare sub ::UserAgent alias "UserAgent" lib "cgi"
declare sub ::RawCookie alias "Cookie" lib "cgi"
declare sub ::Referer alias "Referer" lib "cgi"
declare sub ::SymbolName alias "defsname" lib "cgi"
declare sub ::ResetSymbols alias "resetsymt" lib "cgi"
declare sub ::SymbolFile alias "defsfile" lib "cgi"
declare sub ::GetHtmlTemplate alias "getfile" lib "cgi"
end module