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.

just some quick help please? for the gentoo community :)

Old posts that have not been replied to for several years.
Locked
d
dilema

just some quick help please? for the gentoo community :)

Post by dilema »

Ok, I am writing a script that will search Gentoo portage. But i don't quite understand TCL all that great. heres what i have so far.


bind pub - !emerge msg_who

proc msg_who {nick uhost hand channel args} {


putlog "WHO request from $nick has been receved!"
if { [catch {set msg [exec -- emerge -s |egrep "*|available|Size" ]} ]} {
putserv "PRIVMSG $channel :Nothing Matched Your Search"
} else {
putserv "PRIVMSG $channel :Search results are as follows."
set msg [split $msg "\n"]
foreach line $msg { putserv "PRIVMSG $channel :$line" }
putserv "PRIVMSG $channel :Search Finished."
}
return 0
}


Now thats all fine and dandy (it doesn't work i know) but i want it to be able use "!emerge xmms" for eample and PM the user who did the command, and show him all the results. or add something to where i can change it to either send it to the channel or the person. this way i have the option. the problem is i don't uderstand how to use arguements. cause if you do "!emerge xmms" and then someone does "!emerge mozilla" hows it know what to search for? thats where the arguemtn comes in to play. Anyway any help with this would be great thanks in advance. my email is dilema@phreaker.net or you can find me on irc.freenode.net in the channel #w00t tryin to get this script to come to life...thanks again :D
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

if { [catch {set msg [exec -- emerge -s |egrep "*|available|Size" ]} ]}
this line is messed up I think, I'm not sure :-? .
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

According to the exec command the "--" should be removed. Consult the online manual.
Once the game is over, the king and the pawn go back in the same box.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: just some quick help please? for the gentoo community :)

Post by user »

dilema wrote:bind pub - !emerge msg_who
...
set msg [exec -- emerge -s |egrep "*|available|Size"]
Since it is a pub bind, the last argument passed to the proc is a string containing the arguments (if any). Using the variable name "args" (like you do), which has a special meaning in tcl, just leads to extra work in this case, so change that to something else.

I don't know the syntax of "emerge", but I bet the search string goes after the -s :P

The only problem left now is escaping the user input to avoid security issues. Right now I see 3 options:

a) Since you're probably not going to search for things containing any of the "dangerous" chars anyway, I suggest a polite message in return to users trying a search containing any of the banned chars.

b) Escaping the chars. (Can lead to unexpected results, so you better test it real good before you make the command publicly avaliable if you go for this option.)

c) Filtering them out and then doing the search. (makes no sense, but I know some people that would like it to be that way (before realizing it's a bad idea when they see it in action :P))
d
dilema

thanks guys!

Post by dilema »

set msg [exec -- emerge -s |egrep "*|available|Size" ]

well yeah it needed a space and not too mention you can remove the "--" but it doesn't really matter. andwho. the problem is getting it to use the !emerge "blah" how does it know what to search for. i mean where "blah" is gonna be placed behind the -s in the syntax "emerge -s blah"
so thats the real problem. secirity isn't my concern at his point as you prolly guessed. thats the real issue. is getting it to read the !emerge "blah" . I just need some advie on how to get it to read after the !emerge and search for whatever string that the user puts in there. getting it to work is the forst process.. thanks for th replays and sorry i didn't reply fast enough i was away. :)
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

change this:

Code: Select all

proc msg_who {nick uhost hand channel args} {
to this

Code: Select all

proc msg_who {nick uhost hand channel arg} {
then everything typed after !emerge will be in $arg

Code: Select all

#uncomment the next line if you want only the first in $arg word to be in the search
#set arg [lindex [split $arg] 0]
set msg [exec -- emerge -s $arg |egrep "*|available|Size" ]
Elen sila lúmenn' omentielvo
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Not a very wise idea at all when using the exec command.

This will allow complete control of the shell, via your new command.

You would at least need to perform some syntax checking on the $arg variable before passing it to the exec command, even then, be very vary.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

I know, just wanted to push him in the right direction :)
dilema wrote:secirity isn't my concern at his point as you prolly guessed
I think that meant security ;)
Elen sila lúmenn' omentielvo
d
dilema

Post by dilema »

bind pub - !emerge msg_who

proc msg_who {nick uhost hand channel arg} {


putlog "EMERGE request from $nick has been receved!"
#uncomment the next line if you want only the first in $arg word to be in the search
set arg [lindex [split $arg] 0]
if { [catch {set msg [exec /usr/bin/emerge -s $arg |grep "*" ]} ]} {
putserv "PRIVMSG $channel :Nothing Matched Your Search."
} else {
putserv "PRIVMSG $channel :Results Are As Follows."
set msg [split $msg "\n"]
foreach line $msg { putserv "PRIVMSG $channel :$line" }
putserv "PRIVMSG $channel :End Of Search."
}
return 0
}






ok...thats the exact code i am using. But it still doesn't work. It just spins my drive. and i have to "kill -9" the process it's trying to use. Are you allowed to put other commands after "$arg"? like exec /usr/bin/emerge -s $arg |grep "*" . or doea $arg have to end it? cause it doesn't seem to work. when i do the same search from the command line using "emerge -s karamba |grep "*" i get .

dilema@pimpzter dilema $ emerge -s karamba |grep "*"
* x11-misc/karamba
* x11-misc/superkaramba
* x11-plugins/karamba-agenda
* x11-plugins/karamba-albums
blah blah blah.

where of course $arg would be the string "karamba". i don't know whats going on here and why it spins my drive so much but yet when i do it manually it works fine. is it a problem with the "$arg"? and i know it's not perm issues btw it never come sup with any searchs when the bot does it. it just spins and spins. weird ain't it or a simple mistake.
Locked