Documentation Source Text

Check-in [752d433361]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:In the checklist application, add a /self method and make the magic database name "top" refer to the lexically largest database file.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 752d433361879f3e229dc41886280ff3254dd05369563b685f21f5799e6c0be1
User & Date: drh 2019-07-27 15:28:01
Context
2019-07-27
15:39
Add the CGI-Environment and Source-code submenu links to the checklist application. check-in: a5c38ef1bf user: drh tags: trunk
15:28
In the checklist application, add a /self method and make the magic database name "top" refer to the lexically largest database file. check-in: 752d433361 user: drh tags: trunk
15:13
Fixes to the checklist CGI so that it works better as a Fossil CGI extension. check-in: 41933da084 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to misc/checklist.tcl.

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70



















71
72
73
74
75
76
77
...
645
646
647
648
649
650
651





652
653
654
655
656
657
658
...
663
664
665
666
667
668
669

670

671
672
673
674
675
# Show the CGI environment for testing purposes.
#
proc wapp-page-env {} {
  sqlite3 db :memory:
  set v [db one {SELECT sqlite_source_id()}]
  checklist-verify-login
  wapp-trim {
     <div class='fossil-doc' data-title='Wapp Environment'>
     <pre>%html([wapp-debug-env])}
  global env
  foreach e [array names env] {
    if {![string match FOSSIL* $e]} continue
    set txt "$e = [list $env($e)]\n"
    wapp-subst {%html($txt)}
  }
  wapp-subst {SQLite = %html($v)</pre>\n</div>\n}
}




















# Check user permissions by looking at the login/password in the
# checklist-login cookie.  Set the following environment variables:
#
#     CKLIST_USER      Name of the user.  Empty string if not logged in
#     CKLIST_WRITE     True if the user is allowed to make updates
#     CKLIST_ADMIN     True if the user is an administrator.
................................................................................
#
# If the first element of PATH_INFO is not a valid checklist database name,
# then change PATH_HEAD to be the database listing method.
#
proc wapp-before-dispatch-hook {} {
  global DATADIR
  set dbname [wapp-param PATH_HEAD]





  wapp-set-param ROOT_URL [wapp-param BASE_URL]
  if {[file readable $DATADIR/$dbname.db]} {
    # an appropriate database has been found
    wapp-set-param OBJECT $DATADIR/$dbname.db
    if {[regexp {^([^/]+)(.*)$} [wapp-param PATH_TAIL] all head tail]} {
      wapp-set-param PATH_HEAD $head
      wapp-set-param PATH_TAIL [string trimleft $tail /]
................................................................................
    }
    wapp-set-param BASE [wapp-param BASE_URL]/$dbname
  } else {
    # Not a valid database.  Change the method to list all available
    # databases.
    wapp-set-param OBJECT {}
    wapp-set-param BASE [wapp-param SCRIPT_NAME]

    if {$dbname!="env"} {wapp-set-param PATH_HEAD listing}

  }
}

# Start up the web-server
wapp-start $::argv







|









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>







 







>
|
>





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
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
...
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
# Show the CGI environment for testing purposes.
#
proc wapp-page-env {} {
  sqlite3 db :memory:
  set v [db one {SELECT sqlite_source_id()}]
  checklist-verify-login
  wapp-trim {
     <div class='fossil-doc' data-title='Checklist Environment'>
     <pre>%html([wapp-debug-env])}
  global env
  foreach e [array names env] {
    if {![string match FOSSIL* $e]} continue
    set txt "$e = [list $env($e)]\n"
    wapp-subst {%html($txt)}
  }
  wapp-subst {SQLite = %html($v)</pre>\n</div>\n}
}

# Show the complete text of this script.
#
proc wapp-page-self {} {
  wapp-cache-control max-age=3600
  wapp-subst {<div class='fossil-doc' data-title='Checklist Program Listing'>\n}
  set fd [open [wapp-param SCRIPT_FILENAME] rb]
  set script [read $fd]
  close $fd
  wapp-trim {
    <p>The following is the complete text of the 
    <a href='https://wapp.tcl.tk/'>Wapp script</a> that implements this
    <a href='https://fossil-scm.org/home/doc/trunk/www/serverext.wiki'>Fossil
    CGI extension</a>:</p>
    <pre>%html($script)</pre>
  }
  wapp-subst {</div>\n}
}


# Check user permissions by looking at the login/password in the
# checklist-login cookie.  Set the following environment variables:
#
#     CKLIST_USER      Name of the user.  Empty string if not logged in
#     CKLIST_WRITE     True if the user is allowed to make updates
#     CKLIST_ADMIN     True if the user is an administrator.
................................................................................
#
# If the first element of PATH_INFO is not a valid checklist database name,
# then change PATH_HEAD to be the database listing method.
#
proc wapp-before-dispatch-hook {} {
  global DATADIR
  set dbname [wapp-param PATH_HEAD]
  if {$dbname=="top"} {
    set filelist [glob -tails -directory $DATADIR 3*.db]
    set dbname [lindex [lsort -decr $filelist] 0]
    regsub {.db$} $dbname {} dbname
  }
  wapp-set-param ROOT_URL [wapp-param BASE_URL]
  if {[file readable $DATADIR/$dbname.db]} {
    # an appropriate database has been found
    wapp-set-param OBJECT $DATADIR/$dbname.db
    if {[regexp {^([^/]+)(.*)$} [wapp-param PATH_TAIL] all head tail]} {
      wapp-set-param PATH_HEAD $head
      wapp-set-param PATH_TAIL [string trimleft $tail /]
................................................................................
    }
    wapp-set-param BASE [wapp-param BASE_URL]/$dbname
  } else {
    # Not a valid database.  Change the method to list all available
    # databases.
    wapp-set-param OBJECT {}
    wapp-set-param BASE [wapp-param SCRIPT_NAME]
    if {$dbname!="env" && $dbname!="self"} {
      wapp-set-param PATH_HEAD listing
    }
  }
}

# Start up the web-server
wapp-start $::argv