Documentation Source Text

Check-in [685371e833]
Login

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

Overview
Comment:Add the search.d/admin script.
Timelines: family | ancestors | descendants | both | search-refactor
Files: files | file ages | folders
SHA3-256: 685371e833bc9f5c27c9f0f435cb7fb09bb4d70ab069b54ab0cefeba2f20a39a
User & Date: drh 2018-02-04 23:30:52
Context
2018-02-05
00:47
On the /search.d/admin page, show the Wapp environment if the env=1 query parameter is present. check-in: ebe9a614eb user: drh tags: search-refactor
2018-02-04
23:30
Add the search.d/admin script. check-in: 685371e833 user: drh tags: search-refactor
21:41
Use Wapp to implement the search function. Search can now be run from the command-line using "./tclsh.docsrc doc/search". check-in: 33c56bee81 user: drh tags: search-refactor
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to main.mk.

157
158
159
160
161
162
163
164
165




166
167
168
169
170
171
172
$(TCLSH): $(SSRC)
	$(CC) -O2 -o $@ -I. $(SFLAGS) $(SSRC) $(TCLFLAGS)

doc/search:	$(TCLSH) $(DOC)/search/mkscript.tcl $(DOC)/search/search.tcl.in $(DOC)/search/wapp.tcl $(DOC)/document_header.tcl
	./$(TCLSH) $(DOC)/search/mkscript.tcl $(DOC)/search/search.tcl.in >doc/search
	chmod +x doc/search

searchdb: $(TCLSH) doc/search
	mkdir -p doc/search.d/




	./$(TCLSH) $(DOC)/search/buildsearchdb.tcl

#	cp $(DOC)/search/search.tcl doc/search.d/admin
#	chmod +x doc/search.d/admin

fts5ext.so:	$(DOC)/search/fts5ext.c
	gcc -shared -fPIC -I. -DSQLITE_EXT \







|

>
>
>
>







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
$(TCLSH): $(SSRC)
	$(CC) -O2 -o $@ -I. $(SFLAGS) $(SSRC) $(TCLFLAGS)

doc/search:	$(TCLSH) $(DOC)/search/mkscript.tcl $(DOC)/search/search.tcl.in $(DOC)/search/wapp.tcl $(DOC)/document_header.tcl
	./$(TCLSH) $(DOC)/search/mkscript.tcl $(DOC)/search/search.tcl.in >doc/search
	chmod +x doc/search

doc/search.d/admin:	$(TCLSH) $(DOC)/search/mkscript.tcl $(DOC)/search/admin.tcl.in $(DOC)/search/wapp.tcl $(DOC)/document_header.tcl
	mkdir -p doc/search.d/
	./$(TCLSH) $(DOC)/search/mkscript.tcl $(DOC)/search/admin.tcl.in >doc/search.d/admin
	chmod +x doc/search.d/admin

searchdb: $(TCLSH) doc/search doc/search.d/admin
	./$(TCLSH) $(DOC)/search/buildsearchdb.tcl

#	cp $(DOC)/search/search.tcl doc/search.d/admin
#	chmod +x doc/search.d/admin

fts5ext.so:	$(DOC)/search/fts5ext.c
	gcc -shared -fPIC -I. -DSQLITE_EXT \

Added search/admin.tcl.in.









































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#!/usr/bin/tclsh.docsrc
#### Import of wapp.tcl
INCLUDE wapp.tcl
#### End of wapp.tcl

# Generate all header content for the output document
#
proc search_header {} {
  wapp-trim {
DOCHEAD {Search SQLite Stats} {../}
  }
}

proc wapp-default {} {
  # When running using the built-in webserver in Wapp (in other words,
  # when not running as CGI) any filename that contains a "." loads
  # directly from the filesystem.
  if {[string match *//127.0.0.1:* [wapp-param BASE_URL]]
   && [string match *.* [wapp-param PATH_INFO]]
  } {
    set altfile [file dir [wapp-param SCRIPT_FILENAME]]/../[wapp-param PATH_INFO]
    set fd [open $altfile rb]
    fconfigure $fd -translation binary
    wapp-unsafe [read $fd]
    close $fd
    switch -glob -- $altfile {
      *.html {
        wapp-mimetype text/html
      }
      *.css {
        wapp-mimetype text/css
      }
      *.gif {
        wapp-mimetype image/gif
      }
    }
    return
  }
  wapp-page-admin
}
proc wapp-page-admin {} {
  wapp-allow-xorigin-params
  wapp-content-security-policy off
  sqlite3 db2 [file dir [wapp-param SCRIPT_FILENAME]]/searchlog.db
  set where ""
  set res ""

  set ipfilter ""
  set ipaddr [wapp-param ip]
  if {$ipaddr!=""} {
    set where {WHERE ip = $ipaddr}
    set ipfilter $ipaddr
  }

  set checked ""
  set isUnique [expr {[wapp-param unique 0]+0}]
  if {$isUnique} {
    set checked "checked"
  }

  set limit [wapp-param limit 10]
  set s10 ""
  set s100 ""
  set s1000 ""
  if {$limit==10} {set s10 selected}
  if {$limit==100} {set s100 selected}
  if {$limit==1000} {set s1000 selected}

  search_header
  set self [wapp-param PATH_HEAD]
  wapp-trim {
    <div style="margin:2em">
    <center>
    <form action='%url($self)' method='GET'>
      Results: <select name=limit onChange="this.form.submit()">
        <option %html($s10) value="10">10</option>
        <option %html($s100) value="100">100</option>
        <option %html($s1000) value="1000">1000</option>
      </select>
      IP: <input type=input name=ip value="%html($ipfilter)">
      Unique: <input 
        type=checkbox name=unique value=1 
        $checked
        onChange="this.form.submit()">
      <input type=submit>
    </form>
    </center>
    </div>
    <table border=1 cellpadding=10 align=center>
    <tr><td><th>IP <th>Query <th> Results <th> Timestamp
  }

  set i 0
  db2 eval "
    SELECT rowid, ip, query, nres, timestamp FROM log $where
    ORDER BY rowid DESC
  " {

    if {$isUnique} {
      if {[info exists seen($query)]} continue
      set seen($query) 1
    }

    wapp-trim {
      <tr><td>%html($rowid)
          <td><a href='%url($self)?ip=%qp($ip)'>%html($ip)</a>
          <td><a href='../search?q=%qp($query)&donotlog=1'>%html($query)</a>
          <td>%html($nres)<td>%html($timestamp)
    }
    incr i
    if {$i >= $limit} break
  }
  wapp-subst {</table\n}
  db2 close
}
wapp-start $argv

Changes to search/search.tcl.in.

268
269
270
271
272
273
274

275
276
277
278
279
280
281
      *.css {
        wapp-mimetype text/css
      }
      *.gif {
        wapp-mimetype image/gif
      }
    }

  }

  search_header
  sqlite3 db [file dir [wapp-param SCRIPT_FILENAME]]/search.d/search.db
  set searchType [wapp-param s d]
  if {$searchType=="c"} {
    set cmd searchchanges







>







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
      *.css {
        wapp-mimetype text/css
      }
      *.gif {
        wapp-mimetype image/gif
      }
    }
    return
  }

  search_header
  sqlite3 db [file dir [wapp-param SCRIPT_FILENAME]]/search.d/search.db
  set searchType [wapp-param s d]
  if {$searchType=="c"} {
    set cmd searchchanges