Mercurial > hg > egg-tcls
annotate urllog.tcl @ 456:102dc89488af
urllog: Improve how http headers are formed.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 16 Oct 2017 11:28:56 +0300 |
parents | e5810c52d376 |
children | a7029d65796b |
rev | line source |
---|---|
0 | 1 ########################################################################## |
2 # | |
425
e5810c52d376
Bump some copyright years and versions.
Matti Hamalainen <ccr@tnsp.org>
parents:
424
diff
changeset
|
3 # URLLog v2.4.3 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
e5810c52d376
Bump some copyright years and versions.
Matti Hamalainen <ccr@tnsp.org>
parents:
424
diff
changeset
|
4 # (C) Copyright 2000-2017 Tecnic Software productions (TNSP) |
0 | 5 # |
113
077c7383f36f
urllog: Add line about the script's license.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
6 # This script is freely distributable under GNU GPL (version 2) license. |
077c7383f36f
urllog: Add line about the script's license.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
7 # |
0 | 8 ########################################################################## |
9 # | |
50
f69363fc1f61
Update some comments and add a bit of documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
10 # URL-logger script for EggDrop IRC robot, utilizing SQLite3 database |
81
17e542b7985a
urllog, quotedb: Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
11 # This script requires SQLite TCL extension. Under Debian, you need: |
17e542b7985a
urllog, quotedb: Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
12 # tcl8.5 libsqlite3-tcl (and eggdrop eggdrop-data, of course) |
50
f69363fc1f61
Update some comments and add a bit of documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
13 # |
81
17e542b7985a
urllog, quotedb: Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
14 # NOTICE! If you are upgrading to URLLog v2.0+ from any 1.x version, you |
50
f69363fc1f61
Update some comments and add a bit of documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
15 # may want to run a conversion script against your URL-database file, |
f69363fc1f61
Update some comments and add a bit of documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
16 # if you wish to preserve the old data. |
0 | 17 # |
50
f69363fc1f61
Update some comments and add a bit of documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
18 # See convert_urllog_db.tcl for more information. |
f69363fc1f61
Update some comments and add a bit of documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
19 # |
81
17e542b7985a
urllog, quotedb: Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
20 # If you are doing a fresh install, you will need to create the |
50
f69363fc1f61
Update some comments and add a bit of documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
21 # initial SQLite3 database with the required table schemas. You |
f69363fc1f61
Update some comments and add a bit of documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
22 # can do that by running: create_urllog_db.tcl |
0 | 23 # |
24 ########################################################################## | |
13
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
25 |
263
f01d60175c44
urllog: Move configuration to external file.
Matti Hamalainen <ccr@tnsp.org>
parents:
260
diff
changeset
|
26 ### The configuration should be in config.urllog in same directory |
f01d60175c44
urllog: Move configuration to external file.
Matti Hamalainen <ccr@tnsp.org>
parents:
260
diff
changeset
|
27 ### as this script. Or change the line below to point where ever |
f01d60175c44
urllog: Move configuration to external file.
Matti Hamalainen <ccr@tnsp.org>
parents:
260
diff
changeset
|
28 ### you wish. See "config.urllog.example" for an example config file. |
f01d60175c44
urllog: Move configuration to external file.
Matti Hamalainen <ccr@tnsp.org>
parents:
260
diff
changeset
|
29 source [file dirname [info script]]/config.urllog |
0 | 30 |
291
54d34d086b47
urllog: Use the utility lib for entity conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
31 ### Required utillib.tcl |
54d34d086b47
urllog: Use the utility lib for entity conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
32 source [file dirname [info script]]/utillib.tcl |
54d34d086b47
urllog: Use the utility lib for entity conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
33 |
0 | 34 |
35 ########################################################################## | |
36 # No need to look below this line | |
37 ########################################################################## | |
38 set urllog_name "URLLog" | |
425
e5810c52d376
Bump some copyright years and versions.
Matti Hamalainen <ccr@tnsp.org>
parents:
424
diff
changeset
|
39 set urllog_version "2.4.3" |
0 | 40 |
300
2a9ee3f68225
urllog: Make TLD check configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
41 set urllog_tld_list [split $urllog_tld_list ","] |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
42 set urllog_httprep [split "\@|%40|{|%7B|}|%7D|\[|%5B|\]|%5D" "|"] |
0 | 43 |
102
5425dc418505
urllog: Entity data is now in UTF-8, but TCL source files are interpreted with current system locale, which may not be UTF-8. We must therefore "convert" the entity mapping string to UTF-8 to be certain of TCL's interpretation of its encoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
44 |
13
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
45 ### Require packages |
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
46 package require sqlite3 |
0 | 47 package require http |
7
50b52294e93e
urllog: Strip ‏ entities from titles; Some work on SSL/https support.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
48 |
0 | 49 ### Binding initializations |
219
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
50 bind pub - !urlfind urllog_pub_urlfind |
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
51 bind msg - !urlfind urllog_msg_urlfind |
249 | 52 bind pubm - *.* urllog_check_line |
53 bind topc - *.* urllog_check_line | |
0 | 54 |
55 | |
56 ### Initialization messages | |
425
e5810c52d376
Bump some copyright years and versions.
Matti Hamalainen <ccr@tnsp.org>
parents:
424
diff
changeset
|
57 set urllog_message "$urllog_name v$urllog_version (C) 2000-2017 ccr/TNSP" |
0 | 58 putlog "$urllog_message" |
59 | |
289
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
60 ### Miscellaneous init messages |
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
61 if {$urllog_extra_checks != 0} { |
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
62 putlog " (Additional URL validity checks enabled)" |
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
63 } |
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
64 |
300
2a9ee3f68225
urllog: Make TLD check configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
65 if {$urllog_check_tld != 0} { |
2a9ee3f68225
urllog: Make TLD check configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
66 putlog " (Check TLD)" |
2a9ee3f68225
urllog: Make TLD check configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
67 } |
2a9ee3f68225
urllog: Make TLD check configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
68 |
289
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
69 if {$urllog_verbose != 0} { |
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
70 putlog " (Verbose mode enabled)" |
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
71 } |
5067843cee3d
urllog: Move some initialization messages around.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
72 |
13
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
73 ### HTTP module initialization |
269
d62280f2a9c7
urllog: Make user agent string configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
74 if {[info exists http_user_agent] && $http_user_agent != ""} { |
d62280f2a9c7
urllog: Make user agent string configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
75 ::http::config -useragent $http_user_agent |
d62280f2a9c7
urllog: Make user agent string configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
76 } else { |
d62280f2a9c7
urllog: Make user agent string configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
77 ::http::config -useragent "$urllog_name/$urllog_version" |
d62280f2a9c7
urllog: Make user agent string configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
78 } |
d62280f2a9c7
urllog: Make user agent string configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
79 |
267
da239a953e24
urllog: Change some setting names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
80 if {[info exists http_use_proxy] && $http_use_proxy != 0} { |
28 | 81 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port |
267
da239a953e24
urllog: Change some setting names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
82 putlog " (Using proxy $http_proxy_host:$http_proxy_port)" |
13
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
83 } |
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
84 |
267
da239a953e24
urllog: Change some setting names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
85 if {[info exists http_tls_support] && $http_tls_support != 0} { |
28 | 86 package require tls |
235
059660980388
urllog: Enable TLS, fixes annoying issues where https fails.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
87 ::http::register https 443 [list ::tls::socket -request 1 -require 1 -tls1 1 -cadir $http_tls_cadir] |
267
da239a953e24
urllog: Change some setting names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
88 putlog " (TLS/SSL support enabled)" |
13
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
89 } |
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
90 |
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
91 ### SQLite database initialization |
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
92 if {[catch {sqlite3 urldb $urllog_db_file} uerrmsg]} { |
28 | 93 putlog " Could not open SQLite3 database '$urllog_db_file': $uerrmsg" |
94 exit 2 | |
13
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
95 } |
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
96 |
0 | 97 |
98 #------------------------------------------------------------------------- | |
99 ### Utility functions | |
100 proc urllog_log {arg} { | |
267
da239a953e24
urllog: Change some setting names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
101 global urllog_log_enable urllog_name |
0 | 102 |
267
da239a953e24
urllog: Change some setting names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
103 if {$urllog_log_enable != 0} { |
28 | 104 putlog "$urllog_name: $arg" |
105 } | |
0 | 106 } |
107 | |
108 | |
109 proc urllog_isnumber {uarg} { | |
28 | 110 foreach i [split $uarg {}] { |
65
31c8c4f50aa6
urllog: Improve urllog_isnumber function.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
111 if {![string match \[0-9\] $i]} { return 0 } |
28 | 112 } |
65
31c8c4f50aa6
urllog: Improve urllog_isnumber function.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
113 return 1 |
0 | 114 } |
115 | |
116 | |
117 proc urllog_msg {apublic anick achan amsg} { | |
28 | 118 global urllog_preferredmsg |
0 | 119 |
28 | 120 if {$apublic == 1} { |
121 putserv "$urllog_preferredmsg $achan :$amsg" | |
122 } else { | |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
123 putserv "$urllog_preferredmsg $anick :$amsg" |
28 | 124 } |
0 | 125 } |
126 | |
127 | |
128 proc urllog_verb_msg {anick achan amsg} { | |
28 | 129 global urllog_verbose |
0 | 130 |
28 | 131 if {$urllog_verbose != 0} { |
132 urllog_msg 1 $anick $achan $amsg | |
133 } | |
0 | 134 } |
135 | |
136 | |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
137 proc urllog_sanitize_encoding {uencoding} { |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
138 regsub -- "^\[a-z\]\[a-z\]_\[A-Z\]\[A-Z\]\." $uencoding "" uencoding |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
139 set uencoding [string tolower $uencoding] |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
140 regsub -- "^iso-" $uencoding "iso" uencoding |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
141 return $uencoding |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
142 } |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
143 |
294 | 144 |
0 | 145 #------------------------------------------------------------------------- |
150
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
146 set urllog_shorturl_str "ABCDEFGHIJKLNMOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" |
13
e06d41fb69d5
Begin work on converting urllog.tcl to use an SQLite3 database instead of flat file.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
147 |
150
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
148 proc urllog_get_short {utime} { |
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
149 global urllog_shorturl_prefix urllog_shorturl_str |
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
150 |
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
151 set ulen [string length $urllog_shorturl_str] |
0 | 152 |
28 | 153 set u1 [expr $utime / ($ulen * $ulen)] |
154 set utmp [expr $utime % ($ulen * $ulen)] | |
155 set u2 [expr $utmp / $ulen] | |
156 set u3 [expr $utmp % $ulen] | |
0 | 157 |
150
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
158 return "\[ $urllog_shorturl_prefix[string index $urllog_shorturl_str $u1][string index $urllog_shorturl_str $u2][string index $urllog_shorturl_str $u3] \]" |
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
159 } |
0 | 160 |
161 | |
162 #------------------------------------------------------------------------- | |
163 proc urllog_chop_url {url} { | |
28 | 164 global urllog_shorturl_orig |
68 | 165 |
28 | 166 if {[string length $url] > $urllog_shorturl_orig} { |
167 return "[string range $url 0 $urllog_shorturl_orig]..." | |
168 } else { | |
169 return $url | |
170 } | |
0 | 171 } |
172 | |
241 | 173 |
0 | 174 #------------------------------------------------------------------------- |
83
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
175 proc urllog_exists {urlStr urlNick urlHost urlChan} { |
28 | 176 global urldb urlmsg_alreadyknown urllog_shorturl |
315
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
177 global urllog_msg_channels |
0 | 178 |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
179 set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost, chan AS uchan, title AS utitle FROM urls WHERE url='[utl_escape $urlStr]'" |
297 | 180 urldb eval $usql { |
28 | 181 urllog_log "URL said by $urlNick ($urlStr) already known" |
182 if {$urllog_shorturl != 0} { | |
83
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
183 set qstr "[urllog_get_short $uid] " |
28 | 184 } else { |
185 set qstr "" | |
186 } | |
422
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
372
diff
changeset
|
187 append qstr "($uuser/$uchan@[utl_ctime $utime])" |
83
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
188 if {[string length $utitle] > 0} { |
311 | 189 set qstr "$urlmsg_alreadyknown - '$utitle' $qstr" |
28 | 190 } else { |
191 set qstr "$urlmsg_alreadyknown $qstr" | |
192 } | |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
193 |
315
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
194 if {[utl_match_delim_list $urllog_msg_channels $uchan]} { |
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
195 urllog_verb_msg $urlNick $urlChan $qstr |
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
196 } |
28 | 197 return 0 |
198 } | |
83
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
199 return 1 |
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
200 } |
0 | 201 |
18
1e2232135354
More changes for SQLite support.
Matti Hamalainen <ccr@tnsp.org>
parents:
13
diff
changeset
|
202 |
83
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
203 #------------------------------------------------------------------------- |
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
204 proc urllog_addurl {urlStr urlNick urlHost urlChan urlTitle} { |
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
205 global urldb urllog_shorturl |
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
206 |
93
4e02c0219afe
urllog: Insert NULL into title column when we didn't get a title.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
207 if {$urlTitle == ""} { |
4e02c0219afe
urllog: Insert NULL into title column when we didn't get a title.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
208 set uins "NULL" |
4e02c0219afe
urllog: Insert NULL into title column when we didn't get a title.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
209 } else { |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
210 set uins "'[utl_escape $urlTitle]'" |
93
4e02c0219afe
urllog: Insert NULL into title column when we didn't get a title.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
211 } |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
212 set usql "INSERT INTO urls (utime,url,user,host,chan,title) VALUES ([unixtime], '[utl_escape $urlStr]', '[utl_escape $urlNick]', '[utl_escape $urlHost]', '[utl_escape $urlChan]', $uins)" |
83
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
213 if {[catch {urldb eval $usql} uerrmsg]} { |
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
214 urllog_log "$uerrmsg on SQL:\n$usql" |
28 | 215 return 0 |
216 } | |
82
1bbc79f41a1c
urllog: Rename few variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
217 set uid [urldb last_insert_rowid] |
28 | 218 urllog_log "Added URL ($urlNick@$urlChan): $urlStr" |
0 | 219 |
220 | |
28 | 221 ### Let's say something, to confirm that everything went well. |
222 if {$urllog_shorturl != 0} { | |
82
1bbc79f41a1c
urllog: Rename few variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
223 set qstr "[urllog_get_short $uid] " |
28 | 224 } else { |
225 set qstr "" | |
226 } | |
227 if {[string length $urlTitle] > 0} { | |
311 | 228 urllog_verb_msg $urlNick $urlChan "'$urlTitle' ([urllog_chop_url $urlStr]) $qstr" |
28 | 229 } else { |
230 urllog_verb_msg $urlNick $urlChan "[urllog_chop_url $urlStr] $qstr" | |
231 } | |
0 | 232 |
28 | 233 return 1 |
0 | 234 } |
235 | |
236 | |
237 #------------------------------------------------------------------------- | |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
238 proc urllog_dorequest { urlNick urlChan urlStr urlStatus urlSCode urlCode urlData urlMeta } { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
239 global urlmsg_ioerror urlmsg_timeout urlmsg_errorgettingdoc |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
240 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
241 upvar 1 $urlStatus ustatus |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
242 upvar 1 $urlSCode uscode |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
243 upvar 1 $urlCode ucode |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
244 upvar 1 $urlData udata |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
245 upvar 1 $urlMeta umeta |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
246 |
456
102dc89488af
urllog: Improve how http headers are formed.
Matti Hamalainen <ccr@tnsp.org>
parents:
425
diff
changeset
|
247 set urlHeaders {} |
102dc89488af
urllog: Improve how http headers are formed.
Matti Hamalainen <ccr@tnsp.org>
parents:
425
diff
changeset
|
248 lappend urlHeaders "Accept-Encoding" "identity" |
102dc89488af
urllog: Improve how http headers are formed.
Matti Hamalainen <ccr@tnsp.org>
parents:
425
diff
changeset
|
249 lappend urlHeaders "Connection" "keep-alive" |
102dc89488af
urllog: Improve how http headers are formed.
Matti Hamalainen <ccr@tnsp.org>
parents:
425
diff
changeset
|
250 |
102dc89488af
urllog: Improve how http headers are formed.
Matti Hamalainen <ccr@tnsp.org>
parents:
425
diff
changeset
|
251 if {[catch {set utoken [::http::geturl $urlStr -timeout 6000 -binary 1 -headers $urlHeaders]} uerrmsg]} { |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
252 urllog_verb_msg $urlNick $urlChan "$urlmsg_ioerror ($uerrmsg)" |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
253 urllog_log "HTTP request failed: $uerrmsg" |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
254 return 0 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
255 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
256 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
257 set ustatus [::http::status $utoken] |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
258 if {$ustatus == "timeout"} { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
259 urllog_verb_msg $urlNick $urlChan "$urlmsg_timeout" |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
260 urllog_log "HTTP request timed out ($urlStr)" |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
261 return 0 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
262 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
263 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
264 if {$ustatus != "ok"} { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
265 urllog_verb_msg $urlNick $urlChan "$urlmsg_errorgettingdoc ([::http::error $utoken])" |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
266 urllog_log "Error in HTTP transaction: [::http::error $utoken] ($urlStr)" |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
267 return 0 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
268 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
269 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
270 set ustatus [::http::status $utoken] |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
271 set uscode [::http::code $utoken] |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
272 set ucode [::http::ncode $utoken] |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
273 set udata [::http::data $utoken] |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
274 array set umeta [::http::meta $utoken] |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
275 ::http::cleanup $utoken |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
276 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
277 return 1 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
278 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
279 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
280 #------------------------------------------------------------------------- |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
281 proc urllog_validate_url { urlNick urlChan urlMStr urlMProto urlMHostName } { |
302
f487cc166714
urllog: Add message for unknown TLDs.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
282 global urllog_tld_list urlmsg_nosuchhost urllog_httprep urlmsg_unknown_tld |
300
2a9ee3f68225
urllog: Make TLD check configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
283 global urllog_shorturl_prefix urllog_shorturl urllog_check_tld |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
284 upvar 1 $urlMStr urlStr |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
285 upvar 1 $urlMProto urlProto |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
286 upvar 1 $urlMHostName urlHostName |
3
8003090caa35
Lots of code cleanups, add "fixer" for RasiaTube links (which suck) to point directly to Youtube.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
287 |
96
e5a6c27be365
urllog: Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
95
diff
changeset
|
288 ### Try to guess the URL protocol component (if it is missing) |
28 | 289 set u_checktld 1 |
372
9dd4d2e3a4ac
urllog: Fix missing http(s)/ftp:// protocol prefix guessing.
Matti Hamalainen <ccr@tnsp.org>
parents:
329
diff
changeset
|
290 if {![string match "http://*" $urlStr] && ![string match "https://*" $urlStr] && ![string match "ftp://*" $urlStr]} { |
9dd4d2e3a4ac
urllog: Fix missing http(s)/ftp:// protocol prefix guessing.
Matti Hamalainen <ccr@tnsp.org>
parents:
329
diff
changeset
|
291 if {[string match "*www.*" $urlStr]} { |
9dd4d2e3a4ac
urllog: Fix missing http(s)/ftp:// protocol prefix guessing.
Matti Hamalainen <ccr@tnsp.org>
parents:
329
diff
changeset
|
292 set urlStr "http://$urlStr" |
9dd4d2e3a4ac
urllog: Fix missing http(s)/ftp:// protocol prefix guessing.
Matti Hamalainen <ccr@tnsp.org>
parents:
329
diff
changeset
|
293 } elseif {[string match "*ftp.*" $urlStr]} { |
9dd4d2e3a4ac
urllog: Fix missing http(s)/ftp:// protocol prefix guessing.
Matti Hamalainen <ccr@tnsp.org>
parents:
329
diff
changeset
|
294 set urlStr "ftp://$urlStr" |
9dd4d2e3a4ac
urllog: Fix missing http(s)/ftp:// protocol prefix guessing.
Matti Hamalainen <ccr@tnsp.org>
parents:
329
diff
changeset
|
295 } |
28 | 296 } |
0 | 297 |
95
687bdd74dfac
urllog: Check if TLS support is enabled when checking if we can fetch title information via HTTP or SSL/HTTP.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
298 ### Handle URLs that have an IPv4-address |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
299 if {[regexp "(\[a-z\]+)://(\[0-9\]{1,3})\\.(\[0-9\]{1,3})\\.(\[0-9\]{1,3})\\.(\[0-9\]{1,3})" $urlStr urlMatch urlProto ni1 ni2 ni3 ni4]} { |
28 | 300 # Check if the IP is on local network |
92
f6f4595856ff
urllog: Cosmetics. Remove useless parenthesis.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
301 if {$ni1 == 127 || $ni1 == 10 || ($ni1 == 192 && $ni2 == 168) || $ni1 == 0} { |
28 | 302 urllog_log "URL pointing to local or invalid network, ignored ($urlStr)." |
303 return 0 | |
304 } | |
305 # Skip TLD check for URLs with IP address | |
306 set u_checktld 0 | |
307 } | |
0 | 308 |
96
e5a6c27be365
urllog: Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
95
diff
changeset
|
309 ### Check now if we have an ShortURL here ... |
150
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
310 if {[string match "$urllog_shorturl_prefix*" $urlStr]} { |
98
fbbe7ee40e2f
urllog: Improve one informational / error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
97
diff
changeset
|
311 urllog_log "Ignoring ShortURL from $urlNick: $urlStr" |
252
eb2fce89b8ab
urllog: Comment out some currently unused code.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
312 # set uud "" |
eb2fce89b8ab
urllog: Comment out some currently unused code.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
313 # set usql "SELECT id AS uid, url AS uurl, user AS uuser, host AS uhost, chan AS uchan, title AS utitle FROM urls WHERE utime=$uud" |
eb2fce89b8ab
urllog: Comment out some currently unused code.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
314 # urldb eval $usql { |
eb2fce89b8ab
urllog: Comment out some currently unused code.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
315 # urllog_verb_msg $urlNick $urlChan "'$utitle' - $uurl" |
eb2fce89b8ab
urllog: Comment out some currently unused code.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
316 # return 1 |
eb2fce89b8ab
urllog: Comment out some currently unused code.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
317 # } |
28 | 318 return 0 |
319 } | |
0 | 320 |
95
687bdd74dfac
urllog: Check if TLS support is enabled when checking if we can fetch title information via HTTP or SSL/HTTP.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
321 ### Get URL protocol component |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
322 set urlProto "" |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
323 regexp "(\[a-z\]+)://" $urlStr urlMatch urlProto |
95
687bdd74dfac
urllog: Check if TLS support is enabled when checking if we can fetch title information via HTTP or SSL/HTTP.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
324 |
28 | 325 ### Check the PORT (if the ":" is there) |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
326 set urlRecord [split $urlStr "/"] |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
327 set urlHostName [lindex $urlRecord 2] |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
328 set urlPort [lindex [split $urlHostName ":"] end] |
0 | 329 |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
330 if {![urllog_isnumber $urlPort] && $urlPort != "" && $urlPort != $urlHostName} { |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
331 urllog_log "Broken URL from $urlNick: ($urlStr) illegal port $urlPort" |
28 | 332 return 0 |
333 } | |
0 | 334 |
298 | 335 ### Is it a http or ftp url? |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
336 if {$urlProto != "http" && $urlProto != "https" && $urlProto != "ftp"} { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
337 urllog_log "Broken URL from $urlNick: ($urlStr) UNSUPPORTED protocol class ($urlProto)." |
28 | 338 return 0 |
339 } | |
0 | 340 |
28 | 341 ### Check the Top Level Domain (TLD) validity |
300
2a9ee3f68225
urllog: Make TLD check configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
342 if {$urllog_check_tld != 0 && $u_checktld != 0} { |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
343 set u_sane [lindex [split $urlHostName "."] end] |
28 | 344 set u_tld [lindex [split $u_sane ":"] 0] |
345 set u_found 0 | |
0 | 346 |
28 | 347 if {[string length $u_tld] == 2} { |
348 # Assume all 2-letter domains to be valid :) | |
349 set u_found 1 | |
350 } else { | |
351 # Check our list of known TLDs | |
300
2a9ee3f68225
urllog: Make TLD check configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
352 foreach itld $urllog_tld_list { |
28 | 353 if {[string match $itld $u_tld]} { |
354 set u_found 1 | |
355 } | |
356 } | |
357 } | |
0 | 358 |
28 | 359 if {$u_found == 0} { |
302
f487cc166714
urllog: Add message for unknown TLDs.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
360 urllog_log "Broken URL from $urlNick: ($urlStr) unknown TLD: ${u_tld}." |
f487cc166714
urllog: Add message for unknown TLDs.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
361 urllog_verb_msg $urlNick $urlChan $urlmsg_unknown_tld |
28 | 362 return 0 |
363 } | |
364 } | |
0 | 365 |
28 | 366 set urlStr [string map $urllog_httprep $urlStr] |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
367 return 1 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
368 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
369 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
370 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
371 #------------------------------------------------------------------------- |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
372 proc urllog_check_url {urlStr urlNick urlHost urlChan} { |
299
1ff281e821a3
urllog: Make rasiatube hack configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
298
diff
changeset
|
373 global urllog_encoding http_tls_support urlmsg_errorgettingdoc |
304
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
374 global urllog_extra_checks urllog_extra_strict urllog_rasiatube_hack |
3
8003090caa35
Lots of code cleanups, add "fixer" for RasiaTube links (which suck) to point directly to Youtube.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
375 |
91
6f4bfd8e9447
urllog: Reorder code and make it simpler by removing duplicate checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
376 ### Does the URL already exist? |
6f4bfd8e9447
urllog: Reorder code and make it simpler by removing duplicate checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
377 if {![urllog_exists $urlStr $urlNick $urlHost $urlChan]} { |
6f4bfd8e9447
urllog: Reorder code and make it simpler by removing duplicate checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
378 return 1 |
6f4bfd8e9447
urllog: Reorder code and make it simpler by removing duplicate checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
379 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
380 |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
381 ### Validate URL compoments, etc. |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
382 set urlProto "" |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
383 set urlHostName "" |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
384 if {![urllog_validate_url $urlNick $urlChan urlStr urlProto urlHostName]} { |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
385 return 1 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
386 } |
0 | 387 |
267
da239a953e24
urllog: Change some setting names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
388 ### Do we perform additional checks? |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
389 if {$urllog_extra_checks == 0 || !(($http_tls_support != 0 && $urlProto == "https") || $urlProto == "http")} { |
230 | 390 # No optional checks, or it's not http/https. |
306 | 391 if {$urllog_extra_strict == 0} { |
304
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
392 # Strict checking disabled, so add the URL, if it does not exist already. |
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
393 urllog_addurl $urlStr $urlNick $urlHost $urlChan "" |
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
394 return 1 |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
395 } elseif {$http_tls_support == 0 && $urlProto == "https"} { |
304
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
396 # Strict ENABLED: If TLS support is disabled and we have https, do nothing |
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
397 return 1 |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
398 } elseif {$urlProto != "http" && $urlProto != "https"} { |
304
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
399 # Strict ENABLED: It's not http, or https |
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
400 return 1 |
f1589fe20732
urllog: Added urllog_extra_strict option.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
401 } |
28 | 402 } |
7
50b52294e93e
urllog: Strip ‏ entities from titles; Some work on SSL/https support.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
403 |
28 | 404 ### Does the document pointed by the URL exist? |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
405 if {![urllog_dorequest $urlNick $urlChan $urlStr ustatus uscode ucode udata umeta]} { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
406 return 1 |
28 | 407 } |
0 | 408 |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
409 ### Handle redirects |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
410 if {$ucode >= 301 && $ucode <= 302} { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
411 set nurlStr $umeta(Location) |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
412 if {![regexp "\[a-z\]+://" $nurlStr]} { |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
413 if {[string range $nurlStr 0 0] != "/"} { |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
414 append nurlStr "/" |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
415 } |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
416 set nurlStr "${urlProto}://${urlHostName}${nurlStr}" |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
417 } |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
418 urllog_log "Redirection: $urlStr -> $nurlStr" |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
419 set urlStr $nurlStr |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
420 |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
421 if {![urllog_validate_url $urlNick $urlChan urlStr urlProto urlHostName]} { |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
422 return 1 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
423 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
424 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
425 if {![urllog_dorequest $urlNick $urlChan $urlStr ustatus uscode ucode udata umeta]} { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
426 return 1 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
427 } |
28 | 428 } |
3
8003090caa35
Lots of code cleanups, add "fixer" for RasiaTube links (which suck) to point directly to Youtube.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
429 |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
430 ### Handle 2nd level redirects |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
431 if {$ucode >= 301 && $ucode <= 302} { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
432 set nurlStr $umeta(Location) |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
433 if {![regexp "\[a-z\]+://" $nurlStr]} { |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
434 if {[string range $nurlStr 0 0] != "/"} { |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
435 append nurlStr "/" |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
436 } |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
437 set nurlStr "${urlProto}://${urlHostName}${nurlStr}" |
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
438 } |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
439 urllog_log "Redirection #2: $urlStr -> $nurlStr" |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
440 set urlStr $nurlStr |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
441 |
327
a5282cdc56e6
urllog: Fix redirection handling for HTTP 1.1.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
442 if {![urllog_validate_url $urlNick $urlChan urlStr urlProto urlHostName]} { |
251
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
443 return 1 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
444 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
445 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
446 if {![urllog_dorequest $urlNick $urlChan $urlStr ustatus uscode ucode udata umeta]} { |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
447 return 1 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
448 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
449 } |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
450 |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
451 # Final document |
e59f0c3ea0f4
urllog: Handle first and second level redirects.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
452 if {$ucode >= 200 && $ucode <= 205} { |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
453 set uenc_doc "" |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
454 set uenc_http "" |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
455 set uencoding "" |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
456 |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
457 # Get information about specified character encodings |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
458 if {[info exists umeta(Content-Type)] && [regexp -nocase {charset\s*=\s*([a-z0-9._-]+)} $umeta(Content-Type) umatches uenc_http]} { |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
459 # Found character set encoding information in HTTP headers |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
460 } |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
461 |
150
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
462 if {[regexp -nocase -- "<meta.\*\?content=\"text/html.\*\?charset=(\[^\"\]*)\".\*\?/\?>" $udata umatches uenc_doc]} { |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
463 # Found old style HTML meta tag with character set information |
150
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
464 } elseif {[regexp -nocase -- "<meta.\*\?charset=\"(\[^\"\]*)\".\*\?/\?>" $udata umatches uenc_doc]} { |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
465 # Found HTML5 style meta tag with character set information |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
466 } |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
467 |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
468 # Make sanitized versions of the encoding strings |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
469 set uenc_http2 [urllog_sanitize_encoding $uenc_http] |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
470 set uenc_doc2 [urllog_sanitize_encoding $uenc_doc] |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
471 |
311 | 472 # Check if the document has specified encoding |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
473 # KLUDGE! |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
474 set uencoding $uenc_http2 |
318
5d886e2137d5
urllog: Fix character set conversion a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
475 if {$uencoding == "" && $uenc_doc2 != ""} { |
5d886e2137d5
urllog: Fix character set conversion a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
476 set uencoding $uenc_doc2 |
5d886e2137d5
urllog: Fix character set conversion a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
477 } elseif {$uencoding == ""} { |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
478 # If _NO_ known encoding of any kind, assume the default of iso8859-1 |
86
4c2b6482c08c
urllog: Different strategy for charset encoding conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
84
diff
changeset
|
479 set uencoding "iso8859-1" |
4c2b6482c08c
urllog: Different strategy for charset encoding conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
84
diff
changeset
|
480 } |
0 | 481 |
311 | 482 urllog_log "Charsets: http='$uenc_http', doc='$uenc_doc' / sanitized http='$uenc_http2', doc='$uenc_doc2' -> '$uencoding'" |
483 | |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
484 # Get the document title, if any |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
485 set urlTitle "" |
313
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
486 set tmpRes [regexp -nocase -- "<title.\*\?>(.\*\?)</title>" $udata umatches urlTitle] |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
487 |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
488 # If facebook, get meta info |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
489 if {[regexp -nocase -- "(http|https):\/\/www.facebook.com" $urlStr]} { |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
490 if {[regexp -nocase -- "<meta name=\"description\" content=\"(.\*\?)\"" $udata umatches urlTmp]} { |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
491 if {$urlTitle != ""} { append urlTitle " :: " } |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
492 append urlTitle $urlTmp |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
493 } |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
494 } |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
495 |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
496 # If character set conversion is required, do it now |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
497 if {$urlTitle != "" && $uencoding != ""} { |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
498 if {[catch {set urlTitle [encoding convertfrom $uencoding $urlTitle]} cerrmsg]} { |
8175ef52889b
urllog: Improve URL title functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
499 urllog_log "Error in charset conversion: $cerrmsg" |
28 | 500 } |
150
52350ed97775
urllog: Cleanups, rename/move some global variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
501 |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
502 # Convert some HTML entities to plaintext and do some cleanup |
291
54d34d086b47
urllog: Use the utility lib for entity conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
503 set utmp [utl_convert_html_ent $urlTitle] |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
504 regsub -all "\r|\n|\t" $utmp " " utmp |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
505 regsub -all " *" $utmp " " utmp |
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
506 set urlTitle [string trim $utmp] |
28 | 507 } |
3
8003090caa35
Lots of code cleanups, add "fixer" for RasiaTube links (which suck) to point directly to Youtube.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
508 |
28 | 509 # Rasiatube hack |
299
1ff281e821a3
urllog: Make rasiatube hack configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
298
diff
changeset
|
510 if {$urllog_rasiatube_hack != 0 && [string match "*/rasiatube/view*" $urlStr]} { |
28 | 511 set rasia 0 |
118
e5f2961a6145
urllog: Improve rasiatube URL de-mangling.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
512 if {[regexp -nocase -- "<link rel=\"video_src\"\.\*\?file=(http://\[^&\]+)&" $udata umatches utmp]} { |
e5f2961a6145
urllog: Improve rasiatube URL de-mangling.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
513 regsub -all "\/v\/" $utmp "\/watch\?v=" urlStr |
28 | 514 set rasia 1 |
515 } else { | |
118
e5f2961a6145
urllog: Improve rasiatube URL de-mangling.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
516 if {[regexp -nocase -- "SWFObject.\"(\[^\"\]+)\", *\"flashvideo" $udata umatches utmp]} { |
e5f2961a6145
urllog: Improve rasiatube URL de-mangling.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
517 regsub "http:\/\/www.dailymotion.com\/swf\/" $utmp "http:\/\/www.dailymotion.com\/video\/" urlStr |
28 | 518 set rasia 1 |
519 } | |
520 } | |
521 if {$rasia != 0} { | |
522 urllog_log "RasiaTube mangler: $urlStr" | |
523 urllog_verb_msg $urlNick $urlChan "Korjataan haiseva rasiatube-linkki: $urlStr" | |
524 } | |
525 } | |
3
8003090caa35
Lots of code cleanups, add "fixer" for RasiaTube links (which suck) to point directly to Youtube.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
526 |
83
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
527 # Check if the URL already exists, just in case we had some redirects |
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
528 if {[urllog_exists $urlStr $urlNick $urlHost $urlChan]} { |
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
529 urllog_addurl $urlStr $urlNick $urlHost $urlChan $urlTitle |
f171a9fb7b7b
urllog: Split urllog_add function to urllog_exists for checking whether given URL already exists in the database. Use urllog_exists where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
530 } |
28 | 531 return 1 |
532 } else { | |
116
4f3edcf72987
urllog: Improvements in document / HTTP encoding handling and conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
533 urllog_verb_msg $urlNick $urlChan "$urlmsg_errorgettingdoc ($ucode)" |
224
aaf433ab696a
urllog: Improve error messages a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
534 urllog_log "Error fetching document: status=$ustatus, code=$ucode, scode=$uscode, url=$urlStr" |
28 | 535 } |
0 | 536 } |
537 | |
538 | |
539 #------------------------------------------------------------------------- | |
219
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
540 |
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
541 |
249 | 542 proc urllog_check_line {unick uhost uhand uchan utext} { |
219
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
543 global urllog_log_channels |
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
544 |
28 | 545 ### Check the nick |
87 | 546 if {$unick == "*"} { |
249 | 547 urllog_log "urllog_check_line: Nick was wc, this should not happen." |
28 | 548 return 0 |
549 } | |
0 | 550 |
219
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
551 ### Check the channel |
315
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
552 if {[utl_match_delim_list $urllog_log_channels $uchan]} { |
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
553 ### Do the URL checking |
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
554 foreach str [split $utext " "] { |
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
555 if {[regexp "((ftp|http|https)://\[^\[:space:\]\]+|^(www|ftp)\.\[^\[:space:\]\]+)" $str ulink]} { |
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
556 urllog_check_url $str $unick $uhost $uchan |
219
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
557 } |
28 | 558 } |
559 } | |
0 | 560 |
28 | 561 return 0 |
0 | 562 } |
563 | |
564 | |
565 #------------------------------------------------------------------------- | |
566 ### Parse arguments, find and show the results | |
567 proc urllog_find {unick uhand uchan utext upublic} { | |
62
6428b1bcb34b
urllog: Remove some global variable references where they are not used.
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
568 global urllog_shorturl urldb |
28 | 569 global urllog_showmax_pub urllog_showmax_priv urlmsg_nomatch |
0 | 570 |
28 | 571 if {$upublic == 0} { |
572 set ulimit 5 | |
573 } else { | |
574 set ulimit 3 | |
575 } | |
19
9cf22053e5da
Repair !urlfind functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
18
diff
changeset
|
576 |
28 | 577 ### Parse the given command |
578 urllog_log "$unick/$uhand searched URL: $utext" | |
0 | 579 |
28 | 580 set ftokens [split $utext " "] |
581 set fpatlist "" | |
582 foreach ftoken $ftokens { | |
583 set fprefix [string range $ftoken 0 0] | |
584 set fpattern [string range $ftoken 1 end] | |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
585 set qpattern "'%[utl_escape $fpattern]%'" |
0 | 586 |
28 | 587 if {$fprefix == "-"} { |
128
0d21b9d1d2b9
urllog: Improve search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
588 lappend fpatlist "(url NOT LIKE $qpattern OR title NOT LIKE $qpattern)" |
28 | 589 } elseif {$fprefix == "%"} { |
128
0d21b9d1d2b9
urllog: Improve search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
590 lappend fpatlist "user LIKE $qpattern" |
28 | 591 } elseif {$fprefix == "@"} { |
592 # foo | |
112
fae3dd7a8b20
urllog: Oops, a typo in variable name. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
593 } elseif {$fprefix == "+"} { |
128
0d21b9d1d2b9
urllog: Improve search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
594 lappend fpatlist "(url LIKE $qpattern OR title LIKE $qpattern)" |
28 | 595 } else { |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
596 set qpattern "'%[utl_escape $ftoken]%'" |
128
0d21b9d1d2b9
urllog: Improve search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
597 lappend fpatlist "(url LIKE $qpattern OR title LIKE $qpattern)" |
28 | 598 } |
599 } | |
19
9cf22053e5da
Repair !urlfind functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
18
diff
changeset
|
600 |
27
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
601 if {[llength $fpatlist] > 0} { |
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
602 set fquery "WHERE [join $fpatlist " AND "]" |
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
603 } else { |
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
604 set fquery "" |
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
605 } |
68 | 606 |
28 | 607 set iresults 0 |
82
1bbc79f41a1c
urllog: Rename few variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
608 set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost FROM urls $fquery ORDER BY utime DESC LIMIT $ulimit" |
68 | 609 urldb eval $usql { |
28 | 610 incr iresults |
611 set shortURL $uurl | |
82
1bbc79f41a1c
urllog: Rename few variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
612 if {$urllog_shorturl != 0 && $uid != ""} { |
1bbc79f41a1c
urllog: Rename few variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
613 set shortURL "$shortURL [urllog_get_short $uid]" |
28 | 614 } |
422
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
372
diff
changeset
|
615 urllog_msg $upublic $unick $uchan "#$iresults: $shortURL ($uuser@[utl_ctime $utime])" |
28 | 616 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
617 |
28 | 618 if {$iresults == 0} { |
619 # If no URLs were found | |
620 urllog_msg $upublic $unick $uchan $urlmsg_nomatch | |
621 } | |
0 | 622 |
28 | 623 return 0 |
0 | 624 } |
625 | |
626 | |
627 #------------------------------------------------------------------------- | |
628 ### Finding binded functions | |
629 proc urllog_pub_urlfind {unick uhost uhand uchan utext} { | |
219
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
630 global urllog_search_channels |
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
631 |
315
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
632 if {[utl_match_delim_list $urllog_search_channels $uchan]} { |
7a987b22a817
urllog: Add new configuration option urllog_msg_channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
633 return [urllog_find $unick $uhand $uchan $utext 1] |
219
4e09bcc48851
urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
634 } |
28 | 635 return 0 |
0 | 636 } |
637 | |
638 | |
639 proc urllog_msg_urlfind {unick uhost uhand utext} { | |
28 | 640 urllog_find $unick $uhand "" $utext 0 |
641 return 0 | |
3
8003090caa35
Lots of code cleanups, add "fixer" for RasiaTube links (which suck) to point directly to Youtube.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
642 } |
0 | 643 |
644 # end of script |