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.

Help with my script, sendftp, etc

Old posts that have not been replied to for several years.
Locked
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Help with my script, sendftp, etc

Post by Stylez »

I've been working on this script for a while, in a n00b-like manner, and this is what I have:

Code: Select all

#set the file you want to write to
set kchtmlfile "/home/stylez/eggdrop/kc-chan.html"

#Channel to show stats for
set kcchan "#kc"

#How often (in minutes) does the html file get updated.
set kchtmlrefresh 10

#  The font to use on the html page.
set kchtmlfont "verdana,helvetica,arial"

#this generates an html file with all the people on the chan 
#and the current topic.
proc kchtml {} {
 global kcchan botnick kchtmlfile kchtmlrefresh server
 global kctimer 
 global kchtmlfont
 #set the topic that is in the channel
 set topic [topic $kcchan]
 set _file [open $kchtmlfile~new w]
 puts $_file "<h5><font color=#3399ff>$kcchan Topic:<br>$topic</font></h5>"
 puts $_file "<table border=0 cellpadding=0 cellspacing=0 width=150><tr><td width=100><h5><font color=#3399ff>Name</font></h5></td><td width=50><h5><font color=#3399ff>Idle</font></h5></td></tr>"
 foreach nick [lsort [chanlist $kcchan]] {
 puts $_file "   <tr>"
 puts $_file "    <td><h6><font color=#3399ff>[expr [isop $nick $kcchan]?"@":""][expr [isvoice $nick $kcchan]?"+":""]$nick[expr [string match $nick $botnick]?" (Bot)":""]</font></h6></td>"
 puts $_file "   <td><h6><font color=#3399ff>[expr [getchanidle $nick $kcchan]>10?"[getchanidle $nick $kcchan]m":"-"]</font></h6></td>"
 		}
 puts $_file "</table>"
 #puts $_file ""
 #puts $_file ""
 #puts $_file ""
 close $_file
 file rename -force $kchtmlfile~new $kchtmlfile
 putlog "$kcchan Stats Updated"
sendftp /home/stylez/eggdrop/kc-chan.html ftp.kronicconcerz.com login pass /httpdocs/kc-chan.html
timer $kchtmlrefresh kchtml
}
utimer $kchtmlrefresh kchtml
It generated the html file fine, but in no way will it upload it.
This is the sendftp.tcl script for anyone unfamiliar with it:

Code: Select all

#
# Sendftp v1.01 (12/6/97) by Ernst <ernst@studbox.uni-stuttgart.de>
# Ernst's eggdrop page:  http://www.sodre.net/ernst/eggdrop/
# =============================================================================

# This is a proc to send a file via FTP to another server. Useful in many
# situations, for example to upload a HTML file generated by eggdrop to your
# www server if it is not the same as your eggdrops machine.

# Change this to something to use to check if a host is alife.
# set pingcheck "" to disable this checking.
# "/bin/ping -c 1" works on Linux. Try just "/bin/ping" on other machines
# Set to "" to disable this checking
set pingcheck "/bin/ping -c 1"

# Include it with 'source scripts/sendftp.tcl'.  Call it with all parameters:
#
#   sendftp <localfile> <server> <user> <password> <remotefile>
#
# 'localfile' and 'remotefile' *must* both be given as FULL paths to the
# filenames, the first on the local, the second	on the remote server.
#
# For example:
#
# sendftp /home/bill/stats.htm www.ms.com bill secret /bgates/WWW/stats.htm
#             (local-file       server    user  pass       remote-file)

proc sendftp { localfile server user pass remotefile } {
	global pingcheck
	if {![file exist $localfile]} {
		return "sendftp: File $localfile does not exist."
	}
	if {$pingcheck != ""} {
		if {[catch {exec [lindex $pingcheck 0] [lrange $pingcheck 1 end] $server > /dev/null 2> /dev/null}]} {
			return "sendftp: Machine $server seems to be dead."
		}
	}
	set noftp [catch {set ftpprog [exec which ftd]}] 
	if {$noftp} {
		if {[file executable /usr/bin/ftp]} {
			set ftpprog /usr/bin/ftp
			set noftp 0
		}
		if {[file executable /bin/ftp]} {
			set ftpprog /bin/ftp
			set noftp 0
		}
	}
	if {$noftp} { return "sendftp: You don't seem to have the 'ftp' tool" }
	set pipe [open "|$ftpprog -n $server" w]
	puts $pipe "user $user $pass"
	puts $pipe "bin"
	puts $pipe "put $localfile $remotefile"
	puts $pipe "quit"
	close $pipe
	return 1
}
Now just to make sure the sendftp script was working I made a little script to verify it, but I don't know if THIS script works, hehe.. here it is:

Code: Select all

timer 2 html
proc html {} {
sendftp /home/stylez/eggdrop/kc-chan.html ftp.kronicconcerz.com login pass /httpdocs/kc-chan.html
}
I have actually loaded the sendftp script in the conf file with source scripts/sendftp.tcl, so that's not the problem.
Any insight?
P
Photon
Op
Posts: 170
Joined: Wed Aug 28, 2002 8:00 am
Location: Liverpool, England

Post by Photon »

are you sure that that is creating the right file - wont that create the file "/home/stylez/eggdrop/kc-chan.html~new" ??

Thus it wont send, because it cant find the file?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Yes, this will create the file with ~new on the end. However, there is also a "file rename" just after the file is closed.

Have you tried using the ftp package that comes with tcllib?

Second, try chaning the script, to read the reply from the sendftp program.

Somthing like

Code: Select all

if {[set er [sendftp params go here you know]] != "1"} {
  putlog "Error in sendftp: $er"
}
This will return any error information, if sendftp supplied it. It it triggers as complete (ie without error), there may be an issue with your ftp program.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

It may also be wise to fix this line

Code: Select all

set noftp [catch {set ftpprog [exec which ftd]}] 
The word ftp is spelt incorrectly.
User avatar
Souperman
Halfop
Posts: 69
Joined: Sat Feb 02, 2002 8:00 pm
Location: Cape Town, South Africa
Contact:

Re: Help with my script, sendftp, etc

Post by Souperman »

Stylez wrote:I've been working on this script for a while, in a n00b-like manner, and this is what I have:
It would be nice if you gave me credit for what you've been "working on" ... seems to be pretty much ripped from my trivia script if I'm not mistaken.
Quick! Somebody get me a new ink cartridge
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Sorry Souperman, I have actually given you credit in my other topic when I first started this script:
The code is quite messy, and some of the variables are not even needed. I also have to change some of the variable names because they are conflicting with the script I used to make this, which is Souperman's trivia script.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

UGH.. this is the error I got with your new code ppslim
Error in sendftp: sendftp: You don't seem to have the 'ftp' tool
Now I guess I need to get the 'ftp' tool somewhere. Although I don't see why I don't have it.
I know I un-installed an ftp package that was kerberos, because I got an error when it tried to load saying something about authentication, then the bot would die. I get this error with the ftp (with kerberos support)
Tcl error in script for 'timer13':
KERBEROS_V4 rejected as an authentication type
The version my ftp supports is supposedly v5.
However I can login myself with the shell:
[stylez@kronic stylez]$ ftp kronicconcerz.com
Connected to kronicconcerz.com.
220 ProFTPD 1.2.5 Server (ProFTPD) [1t3.com]
500 AUTH not understood.
500 AUTH not understood.
KERBEROS_V4 rejected as an authentication type
Name (kronicconcerz.com:stylez): XXXX
331 Password required for XXXX.
Password:
230 User XXXX logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> quit
221 Goodbye.
How can I get around this? I've been looking for a substitute for 'ftp' that doesn't haver kerberos but I can't find one.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Wow, it works finally. Found another console ftp without kerberos I guess. Thank you rpmfind! http://rpmfind.net//linux/RPM/redhat/8. ... .i386.html
Thanks guys for all the help, now I just have to maybe implement the colour code stripper. But that's for later.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

As noted, no-spam has a colour stripper which you may freely use, so long as you give me and (i think) stdragn, as he tidied it up.

As for the reason behind that message, I can only guess that because that KERBEROS message is placed on STDERR, rather than the rest of the text, which is piped to STDOUT, Tcl interprets this as a error, and makes the "catch" command returns as such.

You could change the script around for this support, but it's far simpler to use without this support.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Okay the script is done now, I think, I'm not sure how cleanly the timers are working, I don't know if it is only spawning one timer only, or one timer on every rehash. I also changed the way it updates. As it was, it updated every 10 minutes and spammed the ftp server, even when there was no channel activity. ie: very early morning. So, I changed it to use binds, so that it updates only when someone joins, or when someone leaves. The bind to part didn't quite work right, because the script would output the html file before you actually completely left, so you would still be in the html file although you're not in the channel. So I added a timer that makes the script wait 5 seconds before making the html. Well, here it is :D:

Code: Select all

#=====Chanstats by Stylez=====
#
# Credits - code from other scripts used to make this script:
#	1)Trivia.tcl by Souperman for most of the base to output the
#	list of nicks on the channel to html, and for the layout for timers.
#	http://eggdrop.za.net/
#
# This script requires sendftp.tcl by Ernst, get it at:
# http://www.baschny.de/eggdrop/
#
# This script would not have been possible without the help of the
# community at http://www.egghelp.org/
#



#--Set the variables--

#set the file you want to write to
set kchtmlfile "/home/stylez/eggdrop/kc-chan.html"

#Channel to show stats for
set kcchan "#kc"

#  The font to use on the html page.
set kchtmlfont "verdana,helvetica,arial"

#make the page update when someone joins or leaves
bind join - * kctimed
bind part - * kctimed

#a b c d and msg are just dummy placeholders for arguments passed from the join/part binds
proc kctimed {a b c d {msg ""}} {
set kctimer [utimer 5 kchtml]
if {[utimerexists kctimer]!=""} {killutimer $kctimer}
if {$kctimer>0} {
set kctimer [utimer 5 kchtml]
	}
}

#this generates an html file with all the people on the chan
#and the current topic.
proc kchtml {} {
 global kcchan botnick kchtmlfile kchtmlfont
 #set the topic that is in the channel
 set topic [topic $kcchan]
 set _file [open $kchtmlfile~new w]
 puts $_file "<h5><font color=#3399ff>$kcchan Topic:<br>$topic</font></h5>"
 puts $_file "<table border=0 cellpadding=0 cellspacing=0 width=150><tr><td width=100><h5><font color=#3399ff>Name</font></h5></td><td width=50><h5><font color=#3399ff>Idle</font></h5></td></tr>"
 foreach nick [lsort [chanlist $kcchan]] {
 puts $_file "   <tr>"
 puts $_file "    <td><h6><font color=#3399ff>[expr [isop $nick $kcchan]?"@":""][expr [isvoice $nick $kcchan]?"+":""]$nick[expr [string match $nick $botnick]?" (Bot)":""]</font></h6></td>"
 puts $_file "   <td><h6><font color=#3399ff>[expr [getchanidle $nick $kcchan]>10?"[getchanidle $nick $kcchan]m":"-"]</font></h6></td>"
 		}
 puts $_file "</table>"
 close $_file
 file rename -force $kchtmlfile~new $kchtmlfile
if {[set er [sendftp localfile server login pass remotefile]] != "1"} {
  putlog "Error in sendftp: $er"
}
}

putlog "Chanstats v1.0 beta by Stylez loaded."
I didn't bother implementing the colour stripper, as the code was like :o and I didn't understand it.
This script won't work on Windrops, as you can't execute external programs(some kind of bug) to ftp the html file.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Two things.

The code stripper isn't that bad.

It's a few simpel lines of code, that you can introduce at the top of your script.

Depeding ont eh name of the proc (can't be bothered looking at this time of the mroning), you would call it like so

Code: Select all

#call code, so that the topic is contained int he variable $topic
set topic [stripcolours $topic]
This will feed the value of $topic into the stripper, than spit otu a new stripped value, and place it into topic again.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Okay this is the code from your script that actually strips the colours from the string right?

Code: Select all

proc ctrl:filter {str} {
  regsub -all -- {([\003]{1}[0-9]{0,2}[\,]{0,1}[0-9]{0,2})} $str "" str; #color
  regsub -all -- "\017" $str "" str; #plain
  regsub -all -- "\037" $str "" str; #underline
  regsub -all -- "\002" $str "" str; #bold
  regsub -all -- "\026" $str "" str; #reverse
  return $str
}
So to get it to strip the topic I would just write it like this? :

Code: Select all


set topic [ctrl:filter $topic]

proc ctrl:filter {str} {
  regsub -all -- {([\003]{1}[0-9]{0,2}[\,]{0,1}[0-9]{0,2})} $str "" str; #color
  regsub -all -- "\017" $str "" str; #plain
  regsub -all -- "\037" $str "" str; #underline
  regsub -all -- "\002" $str "" str; #bold
  regsub -all -- "\026" $str "" str; #reverse
  return $str
}
#and this will output a variable $topic without the codes in it?
#meanwhile all this has to be above the "kchtml" proc?

proc kchtml {} {
bla bla make the html file etc then ftp it
}
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I can't say yes, I can't say no.

How you use it, is the same as any other Tcl command, that returns somthing, that you want to obtain.

EG: "lindex $arg 0" used in a Tcl script (when arguments are named correctly) returns a string of text.

You pass unfiltered text, to the proc as a arguement, just like you pass text, and the index to the lindex command, and it returns it unfiltered, as it's output, just like lindex does.

so (without looking at your code), when you obtain the topic, store it for example in a variable called $topic, for easy referance.

Pass the ctrl:filter proc the unfiltered topic, to the set command (As shown in my example), so it can set $topic to a new value.

This should be done within your script, as it is it working. After it obtains the tpoic, but before it outputs to the html file.

The version of no-spam you have obtained thsi from is old (likely from the tcl archive, which I won't be updating till the next version of no-spam). The new version only uses one regsub line, which is faster.

The one you are using is fast as it is (about 1/10th slower than the newer version), but if speed is crucial to you, you may want to update.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Okay got the filter to work, first try amazingly. lol
I put the command? inside the proc that makes the html file, I placed it right after it does 'set topic [topic $kchtml]'.. well like this:

Code: Select all

 #set the topic that is in the channel
 set topic [topic $kcchan]
 set topic [ctrl:filter $topic]
and I put the filter proc above the html generator proc.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

That is correct.

Just for clarity, you can simplify this.

Code: Select all

set topic [ctrl:filter [topic $kcchan]]
You should see how it works.
Locked