File: test.op

package info (click to toggle)
lua-orbit 2.2.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,956 kB
  • sloc: javascript: 2,216; sql: 78; sh: 32; makefile: 31; xml: 20
file content (239 lines) | stat: -rwxr-xr-x 5,636 bytes parent folder | download | duplicates (6)
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env op.cgi

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Orbit Pages Test</title>
    <link rel="stylesheet" href="css/doc.css" type="text/css"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    $lua{[[
    if web.input.user then
        web:set_cookie("cookie_kepler", web.input.user)
    end
    ]]}
</head>

<body>

<div id="container">

<div id="product">
	<div id="product_logo"><a href="http://www.keplerproject.org">
		<img src="img/keplerproject.gif" alt="Kepler Project logo" /></a>
    </div>
	<div id="product_name"><big><strong></strong></big></div>
	<div id="product_description">Orbit Pages simple tests</div>
</div> <!-- id="product" -->

<div id="main">

<div id="navigation">
$lua{[[ 
mods = {}
for file in lfs.dir(web.doc_root .. "/doc") do
    local attr = lfs.attributes (web.doc_root .. "/doc/"..file)
    if attr.mode == "directory" and file ~= "." and file ~= ".." then
        table.insert(mods, file)
    end
end
if #mods == 0 then mods[1] = "(None)" end
table.sort(mods)
]]}

<h1>Kepler</h1>
	<ul>
        <li><a href="index.op">Documentation</a>
            <ul>
                $mods[[
                <li><strong><a href="doc/$it/index.html">$it</a></strong></li>
		]]
            </ul>
        </li>
        <li><strong>Tests</strong></li>
	</ul>
</div> <!-- id="navigation" -->

<div id="content">


<h2>Form Handling</h2>

<p>
Entering values on this form should display them as values in the first submission,
and as a cookie in the next submission
</p>

<form method="post" action="test.op">
    <label>User name: </label><input name="user" maxlength="20" size="20">
    <label>Password: </label><input name="pass" type="password" maxlength="20" size="20">
    <input type="submit" value="Post it">
    <input type="reset" value="Reset">
</form>

<p>
The values should show the previous POST
</p>

<p>
Values: Username = $if{$web|input|user}[[$it]],[[(not set)]], Password = $if{$web|input|pass}[[$it]],[[(not set)]]
</p>

<h2>Cookies test</h2>

<p>
Here you should see the values posted before the ones shown above
</p>

<p>
cookie_kepler = $if{$web|cookies|cookie_kepler}[[$it]],[[(not set)]]
</p>

<h2>File Upload</h2>

<p>Choose a file to upload, press "Upload" and a link to the file should
appear below with the corresponding "Remove" button.</a>
<form method="POST" enctype="multipart/form-data" action="test.op">
    <input type="file" name="file">
    <input type="submit" value="Upload">
</form>

$lua{[[ 
    local f = web.input.file
    upload = {}
    if f then
        local name = f.name
        local bytes = f.contents
        local dest = io.open(web.real_path .. "/" .. name, "wb")
        if dest then
            dest:write(bytes)
            dest:close()
	    upload[1] = name
        end
    end
]]}
$upload[[
<a href="$it">$it</a>
<form method="POST" enctype="multipart/form-data" action="test.op">
<input type="hidden" name="filename" value="$it">
<input type="submit" name="remove" value="Remove">
</form>
]]
$lua{[[
    if web.input.remove then
        os.remove(web.input.filename)
    end
]]}

$lua{[=[
function showtable(arg)
    local t = arg[1]
    local out = {}
    local put = function (s) table.insert(out, s) end
    put "{"
    for i,v in pairs (t) do
        put("\n")
        if type(v) == "table" then
            local vv = "{\n"
            for a,b in pairs(v) do
                vv = string.format ("%s  %s = [[%s]],\n", vv, a, tostring(b))
            end
            v = vv.." },"
            put (string.format (" %s = %s", i, tostring(v)))
        else
            put (string.format (" %s = [[%s]],", i, tostring(v)))
        end
    end
    if next(t) then
        put "\n"
    end
    put "}\n"
    return table.concat(out)
end
]=]}

<h2>web.GET</h2>

<pre class="example">
$showtable{ $web|GET }
</pre>

<h2>web.POST</h2>

<pre class="example">
$showtable{ $web|POST }
</pre>

<h2>Web Variables</h2>

<table border="1">
$lua{[[
vars = {
    "real_path", "path_info", "doc_root", "script_name", "path_translated", "prefix", "method"
}
webvar = function (arg) return web[arg[1] ] end
]]}
$vars[[
  <tr><td>web.$it</td><td>$webvar{ $it }</td></tr>
]]
</table>


<h2>Server Variables</h2>

<table border="1">
$lua{[[
vars = {
    "SERVER_SOFTWARE", "SERVER_NAME", "SERVER_PROTOCOL", "SERVER_PORT",
    "GATEWAY_INTERFACE", "REQUEST_METHOD",
    "SCRIPT_NAME", "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING",
    "CONTENT_TYPE", "CONTENT_LENGTH", 
    "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_USER", "REMOTE_IDENT",
    "AUTH_TYPE",
}
servervar = function (arg) return web.vars[arg[1] ] end
]]}
$vars[[
  <tr><td>$it</td><td>$servervar{ $it }</td></tr>
]]
</table>

<h2>Date</h2>

<p>Today is: $os|date</p>

<h2>Image test</h2>

<p>Here should be a small image: <img src="img/test.jpg" alt="a small photograph" /></p>

<h2>FileSystem test</h2>

<p>
$lua{[[
  dirname = web.doc_root or ""
  dir = {}
  for file in lfs.dir(dirname) do dir[#dir + 1] = "&nbsp;&nbsp;&nbsp;"..file.."<br />" end
]]}
Iterating over $dirname $dir[[$it]]
</p>

<h2>Containment test</h2>

<p>
$lua{[[ if not x then x = 1 else x = x + 1 end ]]}
Expected value: 1, actual value: $x.
</p>


</div> <!-- id="content" -->

</div> <!-- id="main" -->

<div id="about">
	<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0</a></p>
	<p><small>$Id: test.op,v 1.1 2008/06/30 14:29:59 carregal Exp $</small></p>
</div> <!-- id="about" -->

</div> <!-- id="container" -->
</body>
</html>