Fossil SCM

Enhance the /cookies webpage to show all cookies and give the user an opportunity to delete them.

drh 2021-02-08 17:29 trunk
Commit 7b00defa9d7dd323c98d82d126b9dd03dcedb15b72ba30c2d8394e7baf4a5396
3 files changed +23 +35 -16 +4 -12
+23
--- src/cgi.c
+++ src/cgi.c
@@ -1489,10 +1489,33 @@
14891489
break;
14901490
}
14911491
}
14921492
}
14931493
}
1494
+
1495
+/*
1496
+** Put information about the N-th parameter into arguments.
1497
+** Return non-zero on success, and return 0 if there is no N-th parameter.
1498
+*/
1499
+int cgi_param_info(
1500
+ int N,
1501
+ const char **pzName,
1502
+ const char **pzValue,
1503
+ int *pbIsQP
1504
+){
1505
+ if( N>=0 && N<nUsedQP ){
1506
+ *pzName = aParamQP[N].zName;
1507
+ *pzValue = aParamQP[N].zValue;
1508
+ *pbIsQP = aParamQP[N].isQP;
1509
+ return 1;
1510
+ }else{
1511
+ *pzName = 0;
1512
+ *pzValue = 0;
1513
+ *pbIsQP = 0;
1514
+ return 0;
1515
+ }
1516
+}
14941517
14951518
/*
14961519
** Export all untagged query parameters (but not cookies or environment
14971520
** variables) as hidden values of a form.
14981521
*/
14991522
--- src/cgi.c
+++ src/cgi.c
@@ -1489,10 +1489,33 @@
1489 break;
1490 }
1491 }
1492 }
1493 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1494
1495 /*
1496 ** Export all untagged query parameters (but not cookies or environment
1497 ** variables) as hidden values of a form.
1498 */
1499
--- src/cgi.c
+++ src/cgi.c
@@ -1489,10 +1489,33 @@
1489 break;
1490 }
1491 }
1492 }
1493 }
1494
1495 /*
1496 ** Put information about the N-th parameter into arguments.
1497 ** Return non-zero on success, and return 0 if there is no N-th parameter.
1498 */
1499 int cgi_param_info(
1500 int N,
1501 const char **pzName,
1502 const char **pzValue,
1503 int *pbIsQP
1504 ){
1505 if( N>=0 && N<nUsedQP ){
1506 *pzName = aParamQP[N].zName;
1507 *pzValue = aParamQP[N].zValue;
1508 *pbIsQP = aParamQP[N].isQP;
1509 return 1;
1510 }else{
1511 *pzName = 0;
1512 *pzValue = 0;
1513 *pbIsQP = 0;
1514 return 0;
1515 }
1516 }
1517
1518 /*
1519 ** Export all untagged query parameters (but not cookies or environment
1520 ** variables) as hidden values of a form.
1521 */
1522
+35 -16
--- src/cookies.c
+++ src/cookies.c
@@ -52,10 +52,11 @@
5252
** char *cookie_value(zPName, zDefault);
5353
**
5454
** Look up the value of a cookie parameter zPName. Return zDefault if
5555
** there is no display preferences cookie or if zPName does not exist.
5656
*/
57
+#include "config.h"
5758
#include "cookies.h"
5859
#include <assert.h>
5960
#include <string.h>
6061
6162
#if INTERFACE
@@ -208,24 +209,42 @@
208209
** Show the current display settings contained in the
209210
** "fossil_display_settings" cookie.
210211
*/
211212
void cookie_page(void){
212213
int i;
213
- if( PB("clear") ){
214
- cgi_set_cookie(DISPLAY_SETTINGS_COOKIE, "", 0, 1);
215
- cgi_replace_parameter(DISPLAY_SETTINGS_COOKIE, "");
216
- }
214
+ int nCookie = 0;
215
+ const char *zName = 0;
216
+ const char *zValue = 0;
217
+ int isQP = 0;
217218
cookie_parse();
218
- style_header("User Preference Cookie Values");
219
- if( cookies.nParam ){
220
- style_submenu_element("Clear", "%R/cookies?clear");
221
- }
222
- @ <p>The following are user preference settings held in the
223
- @ "fossil_display_settings" cookie.
224
- @ <ul>
225
- @ <li>Raw cookie value: "%h(PD("fossil_display_settings",""))"
226
- for(i=0; i<cookies.nParam; i++){
227
- @ <li>%h(cookies.aParam[i].zPName): "%h(cookies.aParam[i].zPValue)"
228
- }
229
- @ </ul>
219
+ style_header("Cookies");
220
+ @ <form method="POST">
221
+ @ <ol>
222
+ for(i=0; cgi_param_info(i, &zName, &zValue, &isQP); i++){
223
+ char *zDel;
224
+ if( isQP ) continue;
225
+ if( fossil_isupper(zName[0]) ) continue;
226
+ zDel = mprintf("del%s",zName);
227
+ if( P(zDel)!=0 ){
228
+ cgi_set_cookie(zName, "", 0, -1);
229
+ cgi_redirect("cookies");
230
+ }
231
+ nCookie++;
232
+ @ <li><p><b>%h(zName)</b>: %h(zValue)
233
+ @ <input type="submit" name="%h(zDel)" value="Delete">
234
+ if( fossil_strcmp(zName, DISPLAY_SETTINGS_COOKIE)==0 && cookies.nParam>0 ){
235
+ int j;
236
+ @ <ul>
237
+ for(j=0; j<cookies.nParam; j++){
238
+ @ <li>%h(cookies.aParam[j].zPName): "%h(cookies.aParam[j].zPValue)"
239
+ }
240
+ @ </ul>
241
+ }
242
+ fossil_free(zDel);
243
+ }
244
+ @ </ol>
245
+ @ </form>
246
+ if( nCookie==0 ){
247
+ @ <p><i>No cookies for this website</i></p>
248
+ }
230249
style_finish_page();
231250
}
232251
--- src/cookies.c
+++ src/cookies.c
@@ -52,10 +52,11 @@
52 ** char *cookie_value(zPName, zDefault);
53 **
54 ** Look up the value of a cookie parameter zPName. Return zDefault if
55 ** there is no display preferences cookie or if zPName does not exist.
56 */
 
57 #include "cookies.h"
58 #include <assert.h>
59 #include <string.h>
60
61 #if INTERFACE
@@ -208,24 +209,42 @@
208 ** Show the current display settings contained in the
209 ** "fossil_display_settings" cookie.
210 */
211 void cookie_page(void){
212 int i;
213 if( PB("clear") ){
214 cgi_set_cookie(DISPLAY_SETTINGS_COOKIE, "", 0, 1);
215 cgi_replace_parameter(DISPLAY_SETTINGS_COOKIE, "");
216 }
217 cookie_parse();
218 style_header("User Preference Cookie Values");
219 if( cookies.nParam ){
220 style_submenu_element("Clear", "%R/cookies?clear");
221 }
222 @ <p>The following are user preference settings held in the
223 @ "fossil_display_settings" cookie.
224 @ <ul>
225 @ <li>Raw cookie value: "%h(PD("fossil_display_settings",""))"
226 for(i=0; i<cookies.nParam; i++){
227 @ <li>%h(cookies.aParam[i].zPName): "%h(cookies.aParam[i].zPValue)"
228 }
229 @ </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230 style_finish_page();
231 }
232
--- src/cookies.c
+++ src/cookies.c
@@ -52,10 +52,11 @@
52 ** char *cookie_value(zPName, zDefault);
53 **
54 ** Look up the value of a cookie parameter zPName. Return zDefault if
55 ** there is no display preferences cookie or if zPName does not exist.
56 */
57 #include "config.h"
58 #include "cookies.h"
59 #include <assert.h>
60 #include <string.h>
61
62 #if INTERFACE
@@ -208,24 +209,42 @@
209 ** Show the current display settings contained in the
210 ** "fossil_display_settings" cookie.
211 */
212 void cookie_page(void){
213 int i;
214 int nCookie = 0;
215 const char *zName = 0;
216 const char *zValue = 0;
217 int isQP = 0;
218 cookie_parse();
219 style_header("Cookies");
220 @ <form method="POST">
221 @ <ol>
222 for(i=0; cgi_param_info(i, &zName, &zValue, &isQP); i++){
223 char *zDel;
224 if( isQP ) continue;
225 if( fossil_isupper(zName[0]) ) continue;
226 zDel = mprintf("del%s",zName);
227 if( P(zDel)!=0 ){
228 cgi_set_cookie(zName, "", 0, -1);
229 cgi_redirect("cookies");
230 }
231 nCookie++;
232 @ <li><p><b>%h(zName)</b>: %h(zValue)
233 @ <input type="submit" name="%h(zDel)" value="Delete">
234 if( fossil_strcmp(zName, DISPLAY_SETTINGS_COOKIE)==0 && cookies.nParam>0 ){
235 int j;
236 @ <ul>
237 for(j=0; j<cookies.nParam; j++){
238 @ <li>%h(cookies.aParam[j].zPName): "%h(cookies.aParam[j].zPValue)"
239 }
240 @ </ul>
241 }
242 fossil_free(zDel);
243 }
244 @ </ol>
245 @ </form>
246 if( nCookie==0 ){
247 @ <p><i>No cookies for this website</i></p>
248 }
249 style_finish_page();
250 }
251
+4 -12
--- src/sitemap.c
+++ src/sitemap.c
@@ -221,38 +221,30 @@
221221
@ </li>
222222
}
223223
224224
if( !g.zLogin ){
225225
@ <li>%z(href("%R/login"))Login</a>
226
+ @ <ul>
226227
if( login_self_register_available(0) ){
227
- @ <ul>
228228
@ <li>%z(href("%R/register"))Create a new account</a></li>
229
- inSublist = 1;
230229
}
231230
}else {
232231
@ <li>%z(href("%R/logout"))Logout</a>
232
+ @ <ul>
233233
if( g.perm.Password ){
234
- @ <ul>
235234
@ <li>%z(href("%R/logout"))Change Password</a></li>
236
- inSublist = 1;
237235
}
238236
}
239237
if( alert_enabled() && g.perm.EmailAlert ){
240
- if( !inSublist ){
241
- inSublist = 1;
242
- @ <ul>
243
- }
244238
if( login_is_individual() ){
245239
@ <li>%z(href("%R/alerts"))Email Alerts</a></li>
246240
}else{
247241
@ <li>%z(href("%R/subscribe"))Subscribe to Email Alerts</a></li>
248242
}
249243
}
250
- if( inSublist ){
251
- @ </ul>
252
- inSublist = 0;
253
- }
244
+ @ <li>%z(href("%R/cookies"))Cookies</a></li>
245
+ @ </ul>
254246
@ </li>
255247
256248
if( g.perm.Read ){
257249
@ <li>%z(href("%R/stat"))Repository Status</a>
258250
@ <ul>
259251
--- src/sitemap.c
+++ src/sitemap.c
@@ -221,38 +221,30 @@
221 @ </li>
222 }
223
224 if( !g.zLogin ){
225 @ <li>%z(href("%R/login"))Login</a>
 
226 if( login_self_register_available(0) ){
227 @ <ul>
228 @ <li>%z(href("%R/register"))Create a new account</a></li>
229 inSublist = 1;
230 }
231 }else {
232 @ <li>%z(href("%R/logout"))Logout</a>
 
233 if( g.perm.Password ){
234 @ <ul>
235 @ <li>%z(href("%R/logout"))Change Password</a></li>
236 inSublist = 1;
237 }
238 }
239 if( alert_enabled() && g.perm.EmailAlert ){
240 if( !inSublist ){
241 inSublist = 1;
242 @ <ul>
243 }
244 if( login_is_individual() ){
245 @ <li>%z(href("%R/alerts"))Email Alerts</a></li>
246 }else{
247 @ <li>%z(href("%R/subscribe"))Subscribe to Email Alerts</a></li>
248 }
249 }
250 if( inSublist ){
251 @ </ul>
252 inSublist = 0;
253 }
254 @ </li>
255
256 if( g.perm.Read ){
257 @ <li>%z(href("%R/stat"))Repository Status</a>
258 @ <ul>
259
--- src/sitemap.c
+++ src/sitemap.c
@@ -221,38 +221,30 @@
221 @ </li>
222 }
223
224 if( !g.zLogin ){
225 @ <li>%z(href("%R/login"))Login</a>
226 @ <ul>
227 if( login_self_register_available(0) ){
 
228 @ <li>%z(href("%R/register"))Create a new account</a></li>
 
229 }
230 }else {
231 @ <li>%z(href("%R/logout"))Logout</a>
232 @ <ul>
233 if( g.perm.Password ){
 
234 @ <li>%z(href("%R/logout"))Change Password</a></li>
 
235 }
236 }
237 if( alert_enabled() && g.perm.EmailAlert ){
 
 
 
 
238 if( login_is_individual() ){
239 @ <li>%z(href("%R/alerts"))Email Alerts</a></li>
240 }else{
241 @ <li>%z(href("%R/subscribe"))Subscribe to Email Alerts</a></li>
242 }
243 }
244 @ <li>%z(href("%R/cookies"))Cookies</a></li>
245 @ </ul>
 
 
246 @ </li>
247
248 if( g.perm.Read ){
249 @ <li>%z(href("%R/stat"))Repository Status</a>
250 @ <ul>
251

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button