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.

Probably simple.. But. I cant do it..

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
r
rpope904
Voice
Posts: 16
Joined: Sat Feb 02, 2008 7:41 pm

Probably simple.. But. I cant do it..

Post by rpope904 »

I am new to tcl, but need to write a simple script.. Basically, I am running a irc server for a webhost company.. We do our support there, and have a bot setup to handle some things. I need a script that when someone messages it in private, or notice a command like GETINFO <NICKNAME> it will go to a web site, i.e. http://www.mysite.com/getuserinfo.php?login=NICKNAME and get the output, (i've already got this part covered) the page returns information in the form of:
hostingtype,serverid,username,domain,hostpackage,suspended

Basically, I need it to either return that to the requesting user in a message or notice and either parse it like
Hosting type: hostingtype
Server ID: serverid
Username: username
Account Domain: domain
Hosting Package: hostingpackage
Account Suspended: accountsuspended

Or, if thats too complicated, just return the whole string to the user and i'll tell them how to read it. I've tried several things, but can't get it.
M
Maiki
Voice
Posts: 28
Joined: Sun May 20, 2007 4:58 pm

Post by Maiki »

If you would give me the website.. Or the page of the soucrce, i will make it for you.
r
rpope904
Voice
Posts: 16
Joined: Sat Feb 02, 2008 7:41 pm

Post by rpope904 »

Sorry i've taken so long.. they are going to change it up alittle, we haven't got the site done yet, but now it's going to be like the bot goes to http://www.somesite.com/somepage.php?login=LOGIN where the person messages or notices the bot with GETINFO <nick>, i'd like to restrict this to ops on a channel, but thats not really required. basically, the site is going to output like this now: (no html tags)
cPanel Login: <login>
Domain Name: <domain>
Hosting type <type>
Account type: <type>
Suspended: Yes/No
Server ID: <id>


Could you possibly get a simple script that just reads the lines of the page, and sends them back to the person who requested it in either privmsg or notice?


Thanks for your help.
M
Maiki
Voice
Posts: 28
Joined: Sun May 20, 2007 4:58 pm

Post by Maiki »

Code: Select all

if {[catch {package require http} error]} { putlog "Failed loading error= $error" }

bind pub - getinfo info

proc info {nick uhost hand chan arg} {
	if {![isop $nick $chan]} { putmsg $chan "No acces to use this script"; return }
	if {$arg == ""} { putmsg $chan "Wrong syntax. \"GETINFO nick\""; return }
	set url "http://www.somesite.com/somepage.php?login=$arg"
	set tok [http::geturl $url]
	set data [http::data $tok]
	http::cleanup $tok
	regexp -- {cPanel Login:(.+?)} $data -> login
	regexp -- {Domain Name:(.+?)} $data -> domain
	regexp -- {Hosting type:(.+?)} $data -> type
	regexp -- {Account type:(.+?)} $data -> account
	regexp -- {Suspended:(.+?)} $data -> suspended
	regexp -- {Server ID:(.+?)} $data -> id
	if {![info exists ::login]} { putmsg $chan "No info available"; return }
	putmsg $nick "$login,$domain,$type,$account,$suspended,$id"
	
}
Last edited by Maiki on Wed Feb 06, 2008 6:29 am, edited 1 time in total.
r
rpope904
Voice
Posts: 16
Joined: Sat Feb 02, 2008 7:41 pm

Post by rpope904 »

Very nice, thank you alot!
r
rpope904
Voice
Posts: 16
Joined: Sat Feb 02, 2008 7:41 pm

Post by rpope904 »

caused an error:

[18:57] <x10Helper> [18:58] Tcl error [info]: bad option "rpope904": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars

any ideas? thanks again.
r
rpope904
Voice
Posts: 16
Joined: Sat Feb 02, 2008 7:41 pm

Post by rpope904 »

i've done a sample output here:

http://rpope904.x10hosting.com/irc/test.php
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

bind pub - getinfo info 
...snipped irrelevant parts...
proc getinfo {nick uhost hand chan arg} {
see the problem? change the part below and it will properly bind getinfo to the proc getinfo

Code: Select all

bind pub - getinfo getinfo 
M
Maiki
Voice
Posts: 28
Joined: Sun May 20, 2007 4:58 pm

Post by Maiki »

speechles wrote:

Code: Select all

bind pub - getinfo info 
...snipped irrelevant parts...
proc getinfo {nick uhost hand chan arg} {
see the problem? change the part below and it will properly bind getinfo to the proc getinfo

Code: Select all

bind pub - getinfo getinfo 
Oopsie, i noticed it to late i guess :p
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

rpope904 wrote:i've done a sample output here:

http://rpope904.x10hosting.com/irc/test.php

Code: Select all

if {[catch {package require http} error]} { putlog "HTTP package required '$error'" }

bind pub - getinfo getinfo

# GET Info
# Grabs your server data, etc, etc
#
proc getinfo {nick uhost hand chan text} {
  if {[isop $nick $chan]} {
    if {$text == ""} {
      putserv "privmsg $nick :Wrong syntax. "GETINFO <nick>""
    } else {
      set tok [http::geturl "http://www.somesite.com/somepage.php?login=[urlencode $text]"]
      set html [http::data $tok]
      http::cleanup $tok
      regexp -nocase -- {cPanel Login:(.+?) Domain Name:(.+?) Hosting type:(.+?) Account type:(.+?) Suspended:(.+?) Server ID:(.+?)} $data -> login domain type account suspended id 
      if {![info exists $login]} {
        putserv "privmsg $nick :No info available for $text."
      ) else {
        putserv "privmsg $nick :[join [list $login $domain $type $account $suspended $id] ", "]"
      }  
    }
  } 
}

# URL Encode
# Encodes anything not a-zA-Z0-9 into %00 strings...Pimp-Style
#
proc urlencode {text} {
  set url ""
  foreach byte [split [encoding convertto utf-8 $text] ""] {
    scan $byte %c i
    if {$i < 65 || $i > 122} {
      append url [format %%%02X $i]
    } else {
      append url $byte
    }
  }
  return [string map {%3A : %2D - %2E . %30 0 %31 1 %32 2 %33 3 %34 4 %35 5 %36 6 %37 7 %38 8 %39 9 \[ %5B \\ %5C \] %5D \^ %5E \_ %5F \` %60} $url]
}
##defeat-word-wrap####################################################################################################################################################################
Try this, since all your stuff is on one line Maiki's regexp's will be very greedy and not do what you want. I've also used putserv for messaging, eliminated all those returns, and stopped it from giving a "you have no access" response if a non-op tries to trigger the script, no response is better. Also included is a pimp-style url encoder.. keke :wink:

@metroid, how does it look now?

edit: corrected missing " which lead to the tcl interpreter giving the missing closing brace error, is now corrected.
Last edited by speechles on Wed Feb 06, 2008 5:26 pm, edited 11 times in total.
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

You should modify info because it'll overwrite the default TCL proc like that.
r
rpope904
Voice
Posts: 16
Joined: Sat Feb 02, 2008 7:41 pm

Post by rpope904 »

Yeah, the second one did cause an error..

[14:25] <x10Helper> [14:26] Tcl error in file './eggdrop.conf':
[14:25] <x10Helper> [14:26] missing close-brace
[14:25] <x10Helper> while executing
[14:25] <x10Helper> "proc getinfo2 {nick uhost hand chan text} {
[14:25] <x10Helper> if {[isop $nick $chan]} {
[14:25] <x10Helper> if {$text == ""} {
[14:25] <x10Helper> putserv "privmsg $nick :Wrong syntax. \"GETINFO <..."
[14:25] <x10Helper> (file "scripts/uinfo2.tcl" line 9)
[14:25] <x10Helper> invoked from within
[14:25] <x10Helper> "source scripts/uinfo2.tcl"
[14:25] <x10Helper> (file "./eggdrop.conf" line 1342)
[14:25] <x10Helper> [14:26] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
DCC session closed

On the first one, I changed the output on the site to one line because I had it printing a <pre> tag first, \n wont work with php echo, and I wasn't sure how the bot would handle a <br> tag on each line..
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Try the edited version above and it'll work, promise.
r
rpope904
Voice
Posts: 16
Joined: Sat Feb 02, 2008 7:41 pm

Post by rpope904 »

thats the one I tried, gonna give it another shot.
r
rpope904
Voice
Posts: 16
Joined: Sat Feb 02, 2008 7:41 pm

Post by rpope904 »

copied and pasted again, exactly as you had it, did a .rehash:

[16:42] <x10Helper> [16:43] Tcl error in file './eggdrop.conf':
[16:42] <x10Helper> [16:43] missing close-brace
[16:42] <x10Helper> while executing
[16:42] <x10Helper> "proc getinfo {nick uhost hand chan text} {
[16:42] <x10Helper> if {[isop $nick $chan]} {
[16:42] <x10Helper> if {$text == ""} {
[16:42] <x10Helper> putserv "privmsg $nick :Wrong syntax. \"GETINFO <n..."
[16:42] <x10Helper> (file "scripts/uinfo2.tcl" line 8)
[16:42] <x10Helper> invoked from within
[16:42] <x10Helper> "source scripts/uinfo2.tcl"
[16:42] <x10Helper> (file "./eggdrop.conf" line 1342)
[16:42] <x10Helper> [16:43] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
DCC session closed
Post Reply