05-30-2020, 07:42 +0200
Forum: Overviewworkscript announcements
This script download a url link and add it to config file and load (or not, read config)
AuthorPost
HackeMate  04-14-2009, 12:41   | eWebSource.tcl Homepage
Member since 05/2008
6 Posts
Location: Spain
Configure default options reading the header script, it will usefull for you.
You can download and source a file without access shell, any comment, bug, idea or suggestion is welcomed

                                                                                                                              
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# eWebSource --
# This script downloads and saves a url if it is a tcl file to be loaded


global eWS

# Path where the files will be saved
set eWS(scriptdir) "scripts"

# Should I add the downloaded file to config file to be loaded when rehash?
# (1) Enable (0) Disable
set eWS(addsource) 1

# Should I load the file after download? (Does not means rehash)
set eWS(load) 1

# (1) Enable proxy (0) Disable
set eWS(dl.useproxy) 0

# Timeout in milliseconds
set eWS(dl.timeout) "5000"

# Proxy:port to connect trought firewall (will be random select)
set eWS(dl.proxy) {
    216.194.70.3:8118
    200.209.145.179:3128
    83.17.123.186:8080
    212.93.193.83:8082
    203.162.224.137:80
    203.162.224.139:80
    217.17.248.171:80
}
# Default proxy port if not defined. Do not force script to use this, most of
# times will not work.
set eWS(dl.defaultport) "8080"


set eWS(me.name) "eWebSource"
set eWS(me.version) "1.0"
set eWS(me.fileName) [file tail [info script]]
set eWS(me.author) "HackeMate"
set eWS(me.contact) "HackeMate <Sentencia@eggdrop.es>"
package require http

setudef flag websource

bind pub n !websource eWebSource

proc eWebSource {nick uhost hand chan text} {

    if {![channel get $chan websource]} {
        putserv "NOTICE $nick :This channel has this script disabled; enable it using .chanset $chan +websource via party line"
        return
    }
    set url [lindex [split $text] 0]
    set source [lindex [split $text] 1]
    set load [lindex [split $text] 2]

    # You can use this command directly via tcldebug or .tcl command party line
    # if you know already what are the right arguments
    eWSdownload $url $chan $source $load

}
proc eWSIsIp {arg} {
    # modify these if you want to check specifi ranges for
    # each portion - now it look for 0 - 255 in each
    set ipnum1 {\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]}
    set ipnum2 {\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]}
    set ipnum3 {\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]}
    set ipnum4 {\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]}
    set fullExp {^($ipnum1)\.($ipnum2)\.($ipnum3)\.($ipnum4)$}
    set partialExp {^(($ipnum1)(\.(($ipnum2)(\.(($ipnum3)(\.(($ipnum4)?)?)?)?)?)?)?)?$}
    set fullExp [subst -nocommands -nobackslashes $fullExp]
    set partialExp [subst -nocommands -nobackslashes $partialExp]
    if [string equal int focusout] {
        if [regexp -- $fullExp $arg] {
            return 1
        } else {
            return 0
        }
    } else {
        return [regexp -- $partialExp $arg]
    }
}

proc eWSLog {target string} {
    global eWS
    if {![validchan $target]} {
        putlog "$eWS(me.name)\: $string"
    } else {
        putserv "PRIVMSG $target :$eWS(me.name)\: $string"
    }
}

proc eWSdownload {webtarget {chan "log"} {addSource ""} {rehash ""}} {
    global eWS config
    regsub -all -- {17|02|37|26|03(\d{1,2})?(,\d{1,2})?} $webtarget "" target
    set isName [lindex [split $target "|"] 0]
    if {[file extension $isName] eq ".tcl"} {
        set fileName $isName
        set target [join [lrange [split $target "|"] 1 end] "|"]
    } else {
        set fileName [file tail $target]
    }
    if {![regexp -nocase {^(http://)?([^/:]+)(:([0-9]+))?(/.*)?$} $target]} {
        if {$webtarget eq ""} {
            set target "Put some url link. Usage: !websource 'url link0' 'add to config file (yes or no)' 'load when download (yes or no)'"
        }
        eWSLog $chan "Unsupported URL: $target"
        return
    }
    if {([file extension $target] ne ".tcl") && ([file extension $fileName] ne ".tcl")} {
        eWSLog $chan "That url does not seems a valid tcl file, if you are sure that really it is, Especific the name using: !websource name.tcl\|$target (I will stop now)"
        return
    }
    if {$addSource eq ""} {
        set addSource $eWS(addsource)
    }
    if {$rehash eq ""} {
        set rehash $eWS(load)
    }
    if {$addSource eq "yes"} {
        set addSource 1
    }
    if {$addSource eq "no"} {
        set addSource 0
    }
    if {($addSource != 1) && ($addSource != 0)} {
        eWSLog $chan "Should I add file to source or not? Use !websource $webtarget 'yes (1) or no (0)' $rehash"
        return
    }
    if {$rehash eq "yes"} {
        set rehash 1
    }
    if {$rehash eq "no"} {
        set rehash 0
    }
    if {($rehash != 1) && ($rehash != 0)} {
        eWSLog $chan "Should I add load the file after download or not? Use !websource $webtarget $addSource 'yes (1) or no (0)'"
        return
    }
    if {$eWS(dl.useproxy)} {
        set randProxy [lindex $eWS(dl.proxy) [rand [llength $eWS(dl.proxy)]]]
        set port [lindex [split $randProxy ":"] 1]
        set proxy [lindex [split $randProxy ":"] 0]
        if {![eWSIsIp $proxy]} {
            eWSLog $chan "$proxy Is Not a valid ip proxy. I will go ahead anyway (sorry)"
            set proxy {}
            set port {}
        }
        if {![string is digit -strict $port]} {
            if {![string is digit -strict $eWS(dl.defaultport)]} {
                set eWS(dl.defaultport) "8080"
                eWSLog $chan "$port and the default $eWS(dl.defaultport) Are Not valid port numbers. I will use the most common proxy port number: 8080 (recheck your config, probably I will break)"
                set port "8080"
            } else {
                eWSLog $chan "$port Is Not a valid port number. I will use the default one: $eWS(dl.defaultport) - It may not work (verify your config)"
            }
        }
        if {$proxy ne ""} {
            eWSLog $chan "Proxy: $proxy\:$port"
        }
    } else {
        set proxy {}
        set port {}
    }
    set fileTcl [file join $eWS(scriptdir) $fileName]
    if {[file exists $fileTcl]} {
        eWSLog $chan "$fileName already exists. Last modified [duration [expr [clock seconds]-[file mtime $fileTcl]]] ago"
        # Use 02!websource $target yes02 to overwrite. ?
        return
    }
    http::config -useragent "$eWS(me.name) - $eWS(me.version)" -proxyhost $proxy -proxyport $port
    if {![string is digit -strict $eWS(dl.timeout)]} {
        set eWS(dl.timeout) "5000"
    }
    set token [http::geturl $target -binary 1 -timeout $eWS(dl.timeout)]
    upvar #0 $token state
    regexp {[0-9]{3}} $state(http) ncode
    if {$ncode eq ""} {
        set ncode $state(http)
    }
    switch -- $ncode {
        "200" {
            eWSLog $chan "File reached $state(currentsize) bytes. MD5sum: [md5 $state(body)]"
            if {$addSource} {
                set fs [open $fileTcl w]
                puts -nonewline $fs $state(body)
                close $fs
                eWSLog $chan "$fileTcl Saved."
                set fs [open $config r]
                set data [split [read $fs] \n]
                close $fs
                lappend data "\# File saved from $target and loaded automaticly by $eWS(me.name) $eWS(me.version)"
                lappend data "source $fileTcl"
                set fs [open $config w]
                puts $fs [join $data \n]
                close $fs
                eWSLog $chan "This file was added to config file."
            }
            if {$rehash} {
                if {[catch {source $fileTcl} msg]} {
                    eWSLog $chan "There is an error loading $fileTcl\:\n $msg"
                } else {
                    eWSLog $chan "File loaded sucessfully."
                }
            }
        }
        "404" {
            eWSLog $chan "No such file or webpage."
            http::cleanup $token
            return
        }
        "default" {
            eWSLog $chan "unforeseen circumstance. Server responded: $state(http)"
        }
    }
    http::cleanup $token
}

eWSLog "log" "$eWS(me.fileName) $eWS(me.version) loaded - by $eWS(me.author)"


I'm the Player2
This post was edited 1 times, last on 04-17-2009, 19:22 by HackeMate
  The user has attached a file: eWebSource.tcl (Save, 7,736 Bytes, downloaded 142 times)
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen | Time: 161.9 msec, CPU time: 58.2 msec, 30 Database queries in 115.5 msec | 7.9 kB (46.8 kB) | Timezone: +0200