︙ | | | ︙ | |
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
}
proc common-footer {} {
wapp-trim {
</div>
}
}
# Open the shortener database. Initialize it if necessary.
#
proc open-database {} {
global DATABASE
sqlite3 db $DATABASE
db eval {
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
}
proc common-footer {} {
wapp-trim {
</div>
}
}
# Generate a submenu of hyperlinks.
#
proc sub-menu {args} {
wapp-trim {
<p><table border="1" cellpadding="10" cellspacing="0"><tr>
}
foreach {name url} $args {
wapp-trim {
<td><a href="%url($url)">%html($name)</a></td>
}
}
wapp-trim {
</tr></table></p>
}
}
# Open the shortener database. Initialize it if necessary.
#
proc open-database {} {
global DATABASE
sqlite3 db $DATABASE
db eval {
|
︙ | | | ︙ | |
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
}
}
# Debugging: show the environment
proc wapp-page-env {} {
wapp-allow-xorigin-params
common-header
wapp-trim {
<h1>Wapp Environment</h1>
<pre>%html([wapp-debug-env])</pre>
}
common-footer
}
|
>
>
>
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
}
}
# Debugging: show the environment
proc wapp-page-env {} {
wapp-allow-xorigin-params
common-header
set base [wapp-param BASE_URL]
sub-menu {Create New URL} $base/ee {Search} $base/sx \
{Recent Changes} $base/lr
wapp-trim {
<h1>Wapp Environment</h1>
<pre>%html([wapp-debug-env])</pre>
}
common-footer
}
|
︙ | | | ︙ | |
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# Search for an existing entry
#
proc wapp-page-sx {} {
if {[check-credentials]} return
common-header
set base [wapp-param BASE_URL]
wapp-trim {
<p>
<a href="%url($base)/ee">Create-New-URL</a>
<a href="%url($base)/lr">List-Recents</a>
<a href="%url($base)/env">CGI-Environment</a>
<p>
<form>
Search: <input type="text" size="60" name="s">
<input type="submit" name="s1" value="Go">
</form>
}
if {[wapp-param-exists s]} {
set s [wapp-param s]
|
>
>
<
<
<
<
<
|
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# Search for an existing entry
#
proc wapp-page-sx {} {
if {[check-credentials]} return
common-header
set base [wapp-param BASE_URL]
sub-menu {Create New URL} $base/ee {Recents Changes} $base/lr \
{CGI Environment} $base/env
wapp-trim {
<form>
Search: <input type="text" size="60" name="s">
<input type="submit" name="s1" value="Go">
</form>
}
if {[wapp-param-exists s]} {
set s [wapp-param s]
|
︙ | | | ︙ | |
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# Show recent modified URL shorteners pages
#
proc wapp-page-lr {} {
if {[check-credentials]} return
common-header
set base [wapp-param BASE_URL]
wapp-trim {
<p>
<a href="%url($base)/ee">Create-New-URL</a>
<a href="%url($base)/sx">Search</a>
<a href="%url($base)/env">CGI-Environment</a>
}
wapp-trim {
<ol>
}
open-database
set cnt 0
db eval {
SELECT name, redir, user, mtime FROM url
|
<
<
<
|
|
<
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# Show recent modified URL shorteners pages
#
proc wapp-page-lr {} {
if {[check-credentials]} return
common-header
set base [wapp-param BASE_URL]
sub-menu {Create New URL} $base/ee {Search} $base/sx \
{CGI Environment} $base/env
wapp-trim {
<ol>
}
open-database
set cnt 0
db eval {
SELECT name, redir, user, mtime FROM url
|
︙ | | | ︙ | |
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
|
# Create or edit a new URL shortener entry.
#
# Name of the entry to be editted is in PATH_TAIL. Or if PATH_TAIL is
# blank, create a new entry.
#
proc wapp-page-ee {} {
global BASEURL
if {[check-credentials]} return
common-header
if {[wapp-param-exists cancel]} {
wapp-redirect [wapp-param BASE_URL]/sx
return
}
open-database
set hardname [wapp-param PATH_TAIL {}]
set name [wapp-param name $hardname]
set redir [wapp-param redir {}]
set notes [wapp-param notes {}]
wapp-trim {
<head></head>
<body>
}
set errmsg {}
if {[wapp-param-exists s1]} {
if {$hardname==""} {
set e [db one {SELECT count(*) FROM url WHERE name=$name}]
if {$e==1} {
set errmsg "Shortened URL name \"$name\" already exists.\
Pick a different name."
} elseif {[string length $name]<4} {
set errmsg "Shortened URL name \"$name\" too short.\
Must be at least 4 characters."
} elseif {[regexp {[^a-z0-9]} $name]} {
set errmsg "Shortened URL name \"$name\" contains invalid characters. \
The name must be lower-case ASCII letters and digits only."
} elseif {[lsearch [info procs] wapp-page-$name]>=0} {
set errmsg "Shortened URL name \"$name\" already exists.\
Pick a different name."
} else {
set user $::env(FOSSIL_USER)
db eval {
INSERT INTO url(name,redir,user,notes,ctime,mtime)
|
>
>
>
>
<
<
<
<
|
|
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
240
241
242
243
244
245
246
247
|
# Create or edit a new URL shortener entry.
#
# Name of the entry to be editted is in PATH_TAIL. Or if PATH_TAIL is
# blank, create a new entry.
#
proc wapp-page-ee {} {
global BASEURL
wapp-content-security-policy {
default-src 'self' data:;
style-src 'self' 'unsafe-inline';
}
if {[check-credentials]} return
common-header
if {[wapp-param-exists cancel]} {
wapp-redirect [wapp-param BASE_URL]/sx
return
}
open-database
set hardname [wapp-param PATH_TAIL {}]
set name [wapp-param name $hardname]
set redir [wapp-param redir {}]
set notes [wapp-param notes {}]
set errmsg {}
if {[wapp-param-exists s1]} {
if {$hardname==""} {
set e [db one {SELECT count(*) FROM url WHERE name=$name}]
if {$e==1} {
set errmsg "Shortened URL name \"$name\" already exists.\
Pick a different name."
} elseif {[string length $name]<4} {
set errmsg "Shortened URL name \"$name\" too short.\
Must be at least 4 characters."
} elseif {[regexp {[^a-z0-9]} $name]} {
set errmsg "Shortened URL name \"$name\" contains invalid characters. \
The name may contain only lower-case ASCII letters and digits."
} elseif {[lsearch [info procs] wapp-page-$name]>=0} {
set errmsg "Shortened URL name \"$name\" already exists.\
Pick a different name."
} else {
set user $::env(FOSSIL_USER)
db eval {
INSERT INTO url(name,redir,user,notes,ctime,mtime)
|
︙ | | | ︙ | |
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
set mtime {}
if {$hardname==""} {
wapp-trim {
<h1>Create A New Shortened URL</h1>
}
if {$errmsg!=""} {
wapp-trim {
<p style='color:red;'>%html($errmsg)</p>
}
}
wapp-trim {
<form method="POST">
<table border="0" cellpadding="0" cellspacing="10">
<tr>
<td align="right">Shortened-URL:</td>
|
|
|
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
set mtime {}
if {$hardname==""} {
wapp-trim {
<h1>Create A New Shortened URL</h1>
}
if {$errmsg!=""} {
wapp-trim {
<p style='color:red;' >%html($errmsg)</p>
}
}
wapp-trim {
<form method="POST">
<table border="0" cellpadding="0" cellspacing="10">
<tr>
<td align="right">Shortened-URL:</td>
|
︙ | | | ︙ | |
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
wapp-trim {
<tr><td align="right">Created:</td>
<td>%html($ctime) by %html($user)</td></tr>
}
}
if {$mtime!="" && $mtime!=$ctime} {
wapp-trim {
<tr><td align="right">Modified:</td><td>%html($ctime)</td></tr>
}
}
wapp-trim {
<tr>
<td align="right">Notes:</td>
<td><input type="text" name="notes" value="%html($notes)" size="70"></td>
</tr>
|
|
|
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
wapp-trim {
<tr><td align="right">Created:</td>
<td>%html($ctime) by %html($user)</td></tr>
}
}
if {$mtime!="" && $mtime!=$ctime} {
wapp-trim {
<tr><td align="right">Modified:</td><td>%html($mtime)</td></tr>
}
}
wapp-trim {
<tr>
<td align="right">Notes:</td>
<td><input type="text" name="notes" value="%html($notes)" size="70"></td>
</tr>
|
︙ | | | ︙ | |