Mercurial > hg > egg-tcls
comparison urllog.tcl @ 560:17183d85ab62
urllog: Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 09 Jul 2020 12:49:48 +0300 |
parents | 7d5d97dfc6ad |
children | bdccc83a1c22 |
comparison
equal
deleted
inserted
replaced
559:06d984a92a28 | 560:17183d85ab62 |
---|---|
31 | 31 |
32 | 32 |
33 ########################################################################## | 33 ########################################################################## |
34 # No need to look below this line | 34 # No need to look below this line |
35 ########################################################################## | 35 ########################################################################## |
36 package require sqlite3 | |
37 package require http | |
38 | |
36 set urllog_name "URLLog" | 39 set urllog_name "URLLog" |
37 set urllog_version "2.4.3" | 40 set urllog_version "2.4.3" |
41 set urllog_message "$urllog_name v$urllog_version (C) 2000-2020 ccr/TNSP" | |
42 | |
38 | 43 |
39 set urllog_tld_list [split $urllog_tld_list ","] | 44 set urllog_tld_list [split $urllog_tld_list ","] |
40 set urllog_httprep [split "\@|%40|{|%7B|}|%7D|\[|%5B|\]|%5D" "|"] | 45 set urllog_httprep [split "\@|%40|{|%7B|}|%7D|\[|%5B|\]|%5D" "|"] |
41 | 46 |
42 | |
43 ### Require packages | |
44 package require sqlite3 | |
45 package require http | |
46 | 47 |
47 ### Binding initializations | 48 ### Binding initializations |
48 bind pub - !urlfind urllog_pub_cmd_urlfind | 49 bind pub - !urlfind urllog_pub_cmd_urlfind |
49 bind msg - !urlfind urllog_msg_cmd_urlfind | 50 bind msg - !urlfind urllog_msg_cmd_urlfind |
50 bind pubm - *.* urllog_check_line | 51 bind pubm - *.* urllog_check_line |
51 bind topc - *.* urllog_check_line | 52 bind topc - *.* urllog_check_line |
52 | 53 |
53 | 54 |
54 ### Initialization messages | |
55 set urllog_message "$urllog_name v$urllog_version (C) 2000-2020 ccr/TNSP" | |
56 putlog "$urllog_message" | |
57 | |
58 ### Miscellaneous init messages | |
59 if {$urllog_extra_checks != 0} { | |
60 putlog " - Additional URL validity checks enabled." | |
61 } | |
62 | |
63 if {$urllog_check_tld != 0} { | |
64 putlog " - Check TLD enabled." | |
65 } | |
66 | |
67 if {$urllog_verbose != 0} { | |
68 putlog " - Verbose mode enabled." | |
69 } | |
70 | |
71 ### HTTP module initialization | |
72 if {[info exists http_user_agent] && $http_user_agent != ""} { | |
73 ::http::config -useragent $http_user_agent | |
74 } else { | |
75 ::http::config -useragent "$urllog_name/$urllog_version" | |
76 } | |
77 | |
78 if {[info exists http_use_proxy] && $http_use_proxy != 0} { | |
79 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port | |
80 putlog " - Using proxy $http_proxy_host:$http_proxy_port" | |
81 } | |
82 | |
83 if {[info exists http_tls_support] && $http_tls_support != 0} { | |
84 package require tls | |
85 ::http::register https 443 [list ::tls::socket -request true -require true -ssl2 false -ssl3 false -tls1 true -tls1.1 true -tls1.2 true -cadir $http_tls_cadir -autoservername true] | |
86 putlog " - TLS/SSL support enabled." | |
87 } | |
88 | |
89 ### SQLite database initialization | |
90 if {[catch {sqlite3 urldb $urllog_db_file} uerrmsg]} { | |
91 putlog "Could not open SQLite3 database '$urllog_db_file': $uerrmsg" | |
92 exit 2 | |
93 } | |
94 | |
95 | 55 |
96 #------------------------------------------------------------------------- | 56 #------------------------------------------------------------------------- |
97 ### Utility functions | 57 ### Utility functions |
98 proc urllog_log {arg} { | 58 proc urllog_log {umsg} { |
99 global urllog_log_enable urllog_name | 59 global urllog_log_enable urllog_name |
100 | 60 |
101 if {$urllog_log_enable != 0} { | 61 if {$urllog_log_enable != 0} { |
102 putlog "$urllog_name: $arg" | 62 putlog "$urllog_name: $umsg" |
103 } | 63 } |
104 } | 64 } |
105 | 65 |
106 | 66 |
107 proc urllog_isnumber {uarg} { | 67 proc urllog_isnumber {uarg} { |
627 proc urllog_msg_cmd_urlfind {unick uhost uhand utext} { | 587 proc urllog_msg_cmd_urlfind {unick uhost uhand utext} { |
628 urllog_find $unick $uhand "" $utext 0 | 588 urllog_find $unick $uhand "" $utext 0 |
629 return 0 | 589 return 0 |
630 } | 590 } |
631 | 591 |
592 | |
593 #------------------------------------------------------------------------- | |
594 # Script initialization | |
595 #------------------------------------------------------------------------- | |
596 putlog "$urllog_message" | |
597 | |
598 if {$urllog_extra_checks != 0} { | |
599 putlog " - Additional URL validity checks enabled." | |
600 } | |
601 | |
602 if {$urllog_check_tld != 0} { | |
603 putlog " - Check TLD enabled." | |
604 } | |
605 | |
606 if {$urllog_verbose != 0} { | |
607 putlog " - Verbose mode enabled." | |
608 } | |
609 | |
610 ### HTTP module initialization | |
611 if {[info exists http_user_agent] && $http_user_agent != ""} { | |
612 ::http::config -useragent $http_user_agent | |
613 } else { | |
614 ::http::config -useragent "$urllog_name/$urllog_version" | |
615 } | |
616 | |
617 if {[info exists http_use_proxy] && $http_use_proxy != 0} { | |
618 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port | |
619 putlog " - Using proxy $http_proxy_host:$http_proxy_port" | |
620 } | |
621 | |
622 if {[info exists http_tls_support] && $http_tls_support != 0} { | |
623 package require tls | |
624 ::http::register https 443 [list ::tls::socket -request true -require true -ssl2 false -ssl3 false -tls1 true -tls1.1 true -tls1.2 true -cadir $http_tls_cadir -autoservername true] | |
625 putlog " - TLS/SSL support enabled." | |
626 } | |
627 | |
628 | |
629 ### SQLite database initialization | |
630 if {[catch {sqlite3 urldb $urllog_db_file} uerrmsg]} { | |
631 putlog "Could not open SQLite3 database '$urllog_db_file': $uerrmsg" | |
632 exit 2 | |
633 } | |
634 | |
635 | |
632 # end of script | 636 # end of script |