tii

Tcl-based suite for working with ii/idec protocol
git clone git://git.luxferre.top/tii.git
Log | Files | Refs | README

commit 4453ed575a8a9896dd4fb39897f0708938c72736
parent 20b522d18da9bfeb942098562a2c9821c03e88cf
Author: Luxferre <lux@ferre>
Date:   Tue, 22 Oct 2024 20:11:33 +0300

Implemented proxy spec and useragent spoofing

Diffstat:
MREADME | 17+++++++++++++++++
Aconfig.txt | 3+++
Mtiifetch.tcl | 17++++++++++++++++-
Mtiipost.tcl | 28++++++++++++++++++----------
4 files changed, 54 insertions(+), 11 deletions(-)

diff --git 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 @@ -0,0 +1,3 @@ +useragent "curl/7.54.1" +proxyhost "" +proxyport 0 diff --git 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 @@ -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} {