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.

Running tcl commands via pm

Help for those learning Tcl or writing their own scripts.
Post Reply
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Running tcl commands via pm

Post by Luminous »

My bot no longer dcc chats with me, so I am looking to convert all the dcc commands to privmsg. The two biggest ones are .tcl and .set, but this post is about .tcl in particular. Is it possible to run .tcl via pm? I was thinking it could be done with tclsh but I am not sure since it prompts for each command. Trying to take $text as a command only resulted in "no such command" errors and I don't think "exec" will work either. A pointer in the right direction would be great, if this is possible. :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You can use the eval command to evaluate any string as a tcl-script. That said, I would recommend against letting any untrusted data be parsed as a script, you need to put some serious thoughts into your security-model if you intend to pursuit this path..
NML_375
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

I can see an issue if someone were to try to run "zebra cakes" or something as a command, but I plan to run it through a catch for errors. Also ,i will likely be the only one using it... or am I overlooking something else there?

Edit: So, something like this? It fails though, no errors:

Code: Select all

bind msg n ~tcl tcl
proc tcl {nick host hand text} {
    if {[catch {eval $text} err]} {
 putnotc $nick $err
    } else {
 set cmd [eval $text]
    puthelp "PRIVMSG $nick :$cmd"
    }
}
If I can just get a single hiccup from it, I can make it nicer, like manage multiple lines of output, etc.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Luminous wrote:I can see an issue if someone were to try to run "zebra cakes" or something as a command, but I plan to run it through a catch for errors. Also ,i will likely be the only one using it... or am I overlooking something else there?

Edit: So, something like this? It fails though, no errors:

Code: Select all

bind msg n ~tcl tcl
proc tcl {nick host hand text} {
    if {[catch {eval $text} err]} {
 putnotc $nick $err
    } else {
 set cmd [eval $text]
    puthelp "PRIVMSG $nick :$cmd"
    }
}
If I can just get a single hiccup from it, I can make it nicer, like manage multiple lines of output, etc.
Nefarious guy in pm to your bot:
~tcl return "[adduser theirnick theirnick!*@*][chattr theirnick +fghjlmnoptx]"
They simply wait for the return of "1 fghjlmnoptx" and they've taken over your bot. I think this is more along the lines of what nml375 meant, not errors.

Note: Your host can be spoofed. That "n" is working off your host record, it's weak part.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Indeed, as speechles suspected, those where my concerns...
That said, first of all, you evaluate the given code twice. That's usualy not such a good idea. If I were to correct that part of the code, it'd look something like this:

Code: Select all

proc msg:tcl {nick host handle text} {
  if {[catch [list eval $text] result]} {
    putnotc $nick "error: $result"
  } {
    putmsg $nick "success: $result"
  }
}
Keep in mind, that this fix does not add any security whatsoever.

Personally, I'd recommend that you live with the telnet/dcc interface (It's not that hard to write a script that causes your eggdrop to send a dcc-chat request that connects you to the lan-IP rather than the public one).
NML_375
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Ah, I see... yeah, that could be a problem but given the channel this bot is running in, shouldn't be a problem. Its invite-only and basically a smaller channel of friends and our bots, haha. Must be a simple way around that though.

I would love to stick with dcc, but it doesn't work. I run two bots from the same host, connect to them from the same(but different) host and one day after my screen session died, one of them no longer responded. This happened to many others too and no one's been able to figure it out yet. And I despise the telnet interface heartily. I can't even scroll so any command like .chaninfo that outputs a lot isn't doing me much good via telnet. Plus, I make a lot of typos and rather enjoy being able to not have to retype /everything/ all the time, lol.

So, about that dcc script....
Personally, I'd recommend that you live with the telnet/dcc interface (It's not that hard to write a script that causes your eggdrop to send a dcc-chat request that connects you to the lan-IP rather than the public one).
What you mean "lan-IP rather than the public one"? Afaik, I can only use one IP and one port.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off... PM's are not restricted to a channel... you do not need to be in the same channel as the bot to send a PM.

On the topic of dcc/telnet; I roughly recalled in an earlier post that you ran your bot behind a NAT (masquerading) firewall along with your irc client? Hence the lan-ip. Nevertheless, if you have an IP address and port number you can telnet to, then this script should do the trick:

Code: Select all

bind msg - chat send_chat
proc ip2long {address} {
  set j 0
  foreach i [split $address .] {
    if {![string is integer $i]} {
      break
    }
    set j [expr ($j*256+$i)]
  }
  return [format "%u" $j]
}

proc send_chat {nick host handle text} {
  puthelp "PRIVMSG $nick :\001DCC CHAT chat [ip2long "192.168.1.1"] 1234\001"
}
Just remember to replace 192.168.1.1 and 1234 with the appropriate values.
NML_375
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Hm.. does seem to send a request to me, but still nothing overall. I am positive the problem is my irc client, irssi. :S Thanks for the help though. I'll have to research dcc ports in irssi more.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Just wanted to post some updates on this script I have made, in case anyone else wants something similar. I did two things, first is I made it able to output multiple lines and do so optionally, and I made it check to make sure that $nick is on that channel before the command is processed, which makes it more secure. Not sure how to make it more so yet, am open to suggestions. Not many people know of this command, so I'm not too concerned:

Code: Select all

bind msg n ~tcl tcl
proc tcl {nick host hand text} {
 set chan "#chan"
   if {$nick eq "$::owner" && [validchan $chan] && [onchan $nick $chan]} {
    if {[string equal "-newline" [lindex [split $text] 0]]} {
 set opt 1
 set cmd [lrange [split $text] 1 end]
    } else {
 set cmd $text
    }
    if {[catch [list eval $cmd] result]} {
         putmsg $chan "$result "
    } {
    if {[info exists opt]} {
      foreach line $result {
          puthelp "PRIVMSG $chan :$line "
      }
    } else {
         putmsg $chan "$result "
    }
    }
   }
 return
}
Post Reply