| View previous topic :: View next topic |
| Author |
Message |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Wed Sep 22, 2010 4:23 pm Post subject: Running tcl commands via pm |
|
|
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.  |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Sep 22, 2010 6:05 pm Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Wed Sep 22, 2010 9:47 pm Post subject: |
|
|
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: |
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. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed Sep 22, 2010 10:07 pm Post subject: |
|
|
| 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: |
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: | Quote: | | ~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. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Sep 23, 2010 2:30 am Post subject: |
|
|
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: | 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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Thu Sep 23, 2010 9:36 am Post subject: |
|
|
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.... | Quote: | | 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. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Sep 23, 2010 3:53 pm Post subject: |
|
|
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: | 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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Sat Sep 25, 2010 1:21 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Wed Sep 29, 2010 7:19 pm Post subject: |
|
|
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: |
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
}
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|