diff --git a/README b/README index 240a4cb..e3916bb 100644 --- a/README +++ b/README @@ -127,6 +127,23 @@ On success, tiipost.tcl will output a message that starts with "Success", in case of an error the line will start with "Error". The server-side description will follow this success or error status. +HTTP client configuration +------------------------- +For both fetching and posting, you can configure several values in the config +file (config.txt in the script directory, the example is included in the repo) +that will allow you to set HTTP proxy and override the user agent. As of now, +the file is a Tcl dictionary (`key "value"`) and has the following fields: + +* useragent: the user agent string to set for all HTTP requests +* proxyhost: the HTTP proxy hostname to use (if empty or omitted, the scripts + will connect directly) +* proxyport: the HTTP port to use on the proxy (only effective if proxyhost is + set to a non-empty string) + +Any of the fields can be omitted, as well as the file itself. +You can also use torsocks with any script invocation in order to fully cloak +your originating IP address. + Message database format ----------------------- The tiidb format is based upon the official ii/IDEC developer recommendations diff --git a/config.txt b/config.txt new file mode 100644 index 0000000..ebbf317 --- /dev/null +++ b/config.txt @@ -0,0 +1,3 @@ +useragent "curl/7.54.1" +proxyhost "" +proxyport 0 diff --git a/tiifetch.tcl b/tiifetch.tcl index aec0672..afd0e5b 100755 --- a/tiifetch.tcl +++ b/tiifetch.tcl @@ -294,8 +294,23 @@ set appdir [file dirname $scriptpath] if [string match *app-tiifetch $appdir] { set appdir [file normalize [file join $appdir ".." ".." ".." ]] } - set localdbdir [file join $appdir "tiidb"] + +# populate general HTTP configuration +set cfgfile [file join $appdir "config.txt"] +if {[file exists $cfgfile]} { + set cfg [readfile $cfgfile] + if {[dict exists $cfg useragent]} { + ::http::config -useragent [dict get $cfg useragent] + } + if {[dict exists $cfg proxyhost]} { + ::http::config -proxyhost [dict get $cfg proxyhost] + } + if {[dict exists $cfg proxyport]} { + ::http::config -proxyport [dict get $cfg proxyport] + } +} + if {$argc > 0} { if {$argc > 2} { set localdbdir [lindex $argv 2] diff --git a/tiipost.tcl b/tiipost.tcl index 91808b3..6665f8f 100755 --- a/tiipost.tcl +++ b/tiipost.tcl @@ -57,19 +57,27 @@ set appdir [file dirname $scriptpath] if [string match *app-tiipost $appdir] { set appdir [file normalize [file join $appdir ".." ".." ".." ]] } -# auth string mapping + +# populate general HTTP configuration +set cfgfile [file join $appdir "config.txt"] +if {[file exists $cfgfile]} { + set cfg [readfile $cfgfile] + if {[dict exists $cfg useragent]} { + ::http::config -useragent [dict get $cfg useragent] + } + if {[dict exists $cfg proxyhost]} { + ::http::config -proxyhost [dict get $cfg proxyhost] + } + if {[dict exists $cfg proxyport]} { + ::http::config -proxyport [dict get $cfg proxyport] + } +} + +# get auth string mapping set authmap "" set authfile [file join $appdir "auth.txt"] if {[file exists $authfile]} { - set authdata [readfile $authfile] - set authlist [split $authdata "\n"] - foreach authline $authlist { - set authline [string trim $authline] - if {$authline ne ""} { - set parts [split $authline " \t"] - dict set authmap [string trim [lindex $parts 0]] [string trim [lindex $parts 1]] - } - } + set authmap [readfile $authfile] } if {$argc > 3} {