This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

tcl and lftp , need help with output

Help for those learning Tcl or writing their own scripts.
Post Reply
h
hazzlah
Voice
Posts: 4
Joined: Fri May 13, 2011 9:54 pm

tcl and lftp , need help with output

Post by hazzlah »

Hi everybody first time apology for my bad english.

I have a problem with lftp / tcl.

The bot relays the commands to the FTP-Server without any problems.
But unfortunately no success Replay into the channel

Here is the code , I hope someone can help me.

Code: Select all

set log "lftp.log"

proc lftp {nick host hand chan arg} {
    global log
    set cmd "[lrange $arg 0 end]"
    exec lftp -c open ip -u user,password -p port -e "site $cmd ; quit"
    set fp [open $log r]
    while {![eof $fp]} {
    gets $fp line
    putquick "PRIVMSG $chan :[join [lrange $line 1 end]]" 
     }
    close $fp
}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First of all,
drop all those random list operations, they won't do you any good like that.

Secondly,
Have you verified that the lftp.log file is actually created by the lftp client? As far as I can tell, lftp sends logging to ~/.lftp/log, and only if the process is run in background mode (which you are currently not doing).

I would assume that you should actually catch the stdout output, and print this instead:

Code: Select all

proc lftp {nick host handle channel text} {
  set result [exec lftp -c open ip -u user,password -p port -e "site $text ; quit"]

  #convert the result into a list - splitting on newlines
  #then iterate through the list and print each item (line)

  foreach line [split $result "\n"] {
    puthelp "PRIVMSG $channel :$line"
  }
}
Be adviced though, that there is a serious security-issue with the code. There is nothing to prevent a malicious user from adding a ; to the command string, and then using the ! command to run arbitrary code on the shell..

Code: Select all

!lftp help ; !rm -rf .
There's quite a few other ways this could be abused, so I would stronlgy advice against letting irc users gain access to code such as this...
You have been warned
NML_375
Post Reply