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.

Diggtitles.tcl + httpS

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
t
tusinamuna
Voice
Posts: 4
Joined: Fri Dec 07, 2012 1:04 pm

Diggtitles.tcl + httpS

Post by tusinamuna »

Hello guys

Here's the deal. I grabbed diggtitles from egghelp, set it up to work channels where needed but then I noticed it doesn't handle httpS urls. I don't know how to script, the link and irc server found in script doesn't exist anymore so I can't go there and ask for help.

So I popped here. The scripts purpose is to announce given url's title to the chan.

Here's the script:

Code: Select all

#############################################################################
#                                                                           #
# diggtitles.tcl                                                            #
#                                                                           #
# Coded by: dragon (dragon@uberdragon.net)                                  #
# Version: 1.0                                                              #
# Released: April 4th, 2009                                                 #
#                                                                           #
# Description: Used to automatically retrieve digg.com's new short url      #
#              as well as the title of URLs pasted into channels.           #
#                                                                           #
# Available Commands:                                                       #
# - DCC: .chanset <chan> +diggtitles :enables auto digg/titles in a channel #
#                                                                           #
# History:                                                                  #
#         - 1.0: First public release - Digg starts service April 2 2009    #
#         - based on urltitles.tcl by perplexa                              #
#                                                                           #
# Report bugs/suggestion to dragon@uberdragon.net                           #
# or visit /server irc.uberdragon.net and join #uberdragon                  #
#                                                                           #
# This program is free software; you can redistribute it and/or modify      #
# it under the terms of the GNU General Public License as published by      #
# the Free Software Foundation; either version 2 of the License, or         #
# (at your option) any later version.                                       #
#                                                                           #
# This program is distributed in the hope that it will be useful,           #
# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
# GNU General Public License for more details.                              #
#                                                                           #
# You should have received a copy of the GNU General Public License         #
# along with this program; if not, write to the Free Software               #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA #
#                                                                           #
#############################################################################
############################################################################


package require http 2.3

namespace eval url {
  variable version "1.0";
  variable agent "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1) Gecko/2006101023 Firefox/2.0";
  # Bot will read data in chunks of this size, 8KB is just fine.
  variable readbuf 8192;
  # Read max. 32KB before the connection gets killed.
  # (to prevent the bot from downloading large files when someone pastes [censored]..)
  variable readlimit 32768;
  variable fds;
  if {![info exists fds]} {
    set fds 0;
  }
  setudef flag diggtitles;
  bind pubm -|- "*" [namespace current]::check;
}

proc url::check {nick host hand chan text} {
  global turl
  if {[channel get $chan diggtitles]} {
    set text [stripcodes uacgbr $text];
    foreach item [split $text] {
      if {[string match -nocase "*http://?*" $item] || [string match -nocase "*https://?*" $item] || [string match -nocase "*www.?*" $item]} {
        regsub -nocase -- "http://" [string map [list "\\" "/"] $item] "" url;
        set url [split $url "/"];
        set get [join [lrange $url 1 end] "/"];
        set url [split [lindex $url 0] ":"];
	set turl [diggurl "http://$url/$get"]
	set host [lindex $url 0]; set port [lindex $url 1];
        if {$port == ""} {set port "80";}
        uconnect $host $port $get $nick $chan;
      }
    }
  }
}

proc url::uconnect {host port get nick chan} {
  variable agent;
  variable fds;
  variable readbuf;
  set token [namespace current]::[incr fds];
  variable $token;
  upvar 0 $token static;
  array set static {
    data ""
    body 0
    code 0
    sock -1
  }
  if {[catch {
    set static(sock) [socket -async $host $port];
    fconfigure $static(sock) -translation {auto crlf} -buffersize $readbuf;
    puts $static(sock) "GET /$get HTTP/1.0";
    puts $static(sock) "Accept: */*";
    if {$port == "80"} {
      puts $static(sock) "Host: $host";
    } else {
      puts $static(sock) "Host: $host:$port";
    }
    puts $static(sock) "User-agent: $agent";
    puts $static(sock) "";
    flush $static(sock);
    fileevent $static(sock) readable [list [namespace current]::handledata $token $nick $chan];
    catch {fconfigure $static(sock) -blocking 0;}
    } error]} {
    destroy $token;
    return $error;
  }
  after [expr 20*1000] [list [namespace current]::destroy $token];
  return $token;
}

proc url::handledata {token nick chan} {
  global turl
  variable readbuf; variable readlimit;
  variable $token;
  upvar 0 $token static;
  if {[eof $static(sock)] || [string length $static(data)]>=$readlimit} {
    destroy $token;
    return;
  }
  set buf [read $static(sock) $readbuf];
  append static(data) $buf;
  regsub -all -- {<!--.*?-->} $static(data) "" static(data);
  foreach line [split $buf "\n"] {
    if {[string match HTTP* $line] && !$static(body)} {
      if {![regexp -- {\d{3}} $line static(code)]} {
        destroy $token;
        return;
      } elseif {$static(code)!=200 && $static(code)!=301 && $static(code)!=302} {
        destroy $token;
        return;
      }
    } elseif {[regexp -nocase -- "^Location:(.+)$" $line -> url]
              && !($static(code)!=301 && $static(code)!=302)} {
      check $nick *!*@* * $chan $url;
      destroy $token;
      return;
    } elseif {[regexp -nocase -- "^Content-type:(.+)$" $line -> type]} {
      if {![string match -nocase text* [string trim $type]]} {
        destroy $token;
        return;
      }
    } elseif {[regexp -nocase -- "^Content-encoding:(.+)$" $line -> encoding]} {
      if {[string match -nocase *gzip* $encoding]
          || [string match -nocase *compress* $encoding]} {
        destroy $token;
        return;
      }
    } elseif {($line == "") && !$static(body)} {
      set static(body) 1;
    } elseif {[regexp -nocase -- {<title>([^<]+?)</title>} $static(data) -> title]
              && $static(code)==200} {
      regsub -all -- {(\n|\r|\s|\t)+} $title " " title;
      set s [expr {[string index $nick end]!="s"?"s":""}];
      set turl 
      putquick "PRIVMSG $chan :\"[decode [string trim $title]]\"";
      destroy $token;
      return;
    }
  }
}

proc url::destroy {token} {
  variable $token
  upvar 0 $token static;
  if {[info exists static]} {
    catch {fileevent $static(sock) readable "";}
    catch {close $static(sock);}
    unset static;
  }
}

proc url::decode {content} {
  if {![string match *&* $content]} {
    return $content;
  }
  set escapes {
      \x20 " \x22 & \x26 &apos; \x27 – \x2D
    < \x3C > \x3E ˜ \x7E € \x80 ¡ \xA1
    ¢ \xA2 £ \xA3 ¤ \xA4 ¥ \xA5 ¦ \xA6
    § \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB
    ¬ \xAC ­ \xAD ® \xAE &hibar; \xAF ° \xB0
    ± \xB1 ² \xB2 ³ \xB3 ´ \xB4 µ \xB5
    ¶ \xB6 · \xB7 ¸ \xB8 ¹ \xB9 º \xBA
    » \xBB ¼ \xBC ½ \xBD ¾ \xBE ¿ \xBF
    À \xC0 Á \xC1 Â \xC2 Ã \xC3 Ä \xC4
    Å \xC5 Æ \xC6 Ç \xC7 È \xC8 É \xC9
    Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE
    Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3
    Ô \xD4 Õ \xD5 Ö \xD6 × \xD7 Ø \xD8
    Ù \xD9 Ú \xDA Û \xDB Ü \xDC Ý \xDD
    Þ \xDE ß \xDF à \xE0 á \xE1 â \xE2
    ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7
    è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC
    í \xED î \xEE ï \xEF ð \xF0 ñ \xF1
    ò \xF2 ó \xF3 ô \xF4 õ \xF5 ö \xF6
    ÷ \xF7 ø \xF8 ù \xF9 ú \xFA û \xFB
    ü \xFC ý \xFD þ \xFE ÿ \xFF
  };
  set content [string map $escapes $content];
  set content [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $content];
  regsub -all -- {&#([[:digit:]]{1,5});} $content {[format %c [string trimleft "\1" "0"]]} content;
  regsub -all -- {&#x([[:xdigit:]]{1,4});} $content {[format %c [scan "\1" %x]]} content;
  regsub -all -- {&#?[[:alnum:]]{2,7};} $content "?" content;
  return [subst $content];
}

proc url::diggurl {url} {
  set agent "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1) Gecko/2006101023 Firefox/2.0";
  http::config -useragent $agent;
  if {[catch {http::geturl "http://services.digg.com/url/short/create?url=$url" -query [http::formatQuery "url" $url] -timeout 20000} token]} {
    return $url;
  }
  set data [http::data $token];
  http::cleanup $token;
  set diggurl "";
  regexp -nocase -- {short_url="(.*?)"} $data -> diggurl;
  return [expr {($diggurl=="")?$url:$diggurl}];
}


putlog "Script loaded: digg url and title fetcher v$url::version by dragon on irc.uberdragon.net";
So little I know about tcl, I tried to fix it by myself by adding that
[string match -nocase "*https://?*" $item]
part to row 63. I have no clue if that is even close how it should be fixed, but it doesn't work nonetheless.

Could some kind soul give me a hint or try to fix that script to work with https?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

There doesn't seem to be a https on services.digg.com, or at least not working at me. Anyway, if you wish to get https working with geturl then you need to do the following changes:
after:

Code: Select all

package require http 2.3
add:

Code: Select all

package require tls
then use this changed code:

Code: Select all

proc url::diggurl {url} {
  set agent "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1) Gecko/2006101023 Firefox/2.0";
  http::config -useragent $agent;
  http::register https 443 ::tls::socket
  if {[catch {http::geturl "http://services.digg.com/url/short/create?url=$url" -query [http::formatQuery "url" $url] -timeout 20000} token]} {
    return $url;
  }
  set data [http::data $token];
  http::cleanup $token;
  http::unregister https
  set diggurl "";
  regexp -nocase -- {short_url="(.*?)"} $data -> diggurl;
  return [expr {($diggurl=="")?$url:$diggurl}];
} 
Apart the package requirement, notice the http::register and http::unregister lines. This two do the trick.
Once the game is over, the king and the pawn go back in the same box.
t
tusinamuna
Voice
Posts: 4
Joined: Fri Dec 07, 2012 1:04 pm

Post by tusinamuna »

Thank you for your answer.

However It gives me this error:

http://i.imgur.com/6HSClok.png

What I've tried so far:

Downloaded tls from http://sourceforge.net/projects/tls/?source=dlp (windows version, I'm running windrop!) (Found a thread about windrop + tls in egghelp and it said to dl that)

didn't knew where to put those for sure, but I put tls.tcl in /scripts/ and to load it first, also put tls16.dll to /modules/ and added line loadmodule tls16 in eggdrop.conf, still not working, only gives the same error as above.

If I delete that

Code: Select all

Package require tls
eggdrop starts without errors, but don't show httpS titles
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Place the tls.tcl in your scripts folder, tls16.dll in modules and then in egdrop.conf file write the next two lines before any other line starting with "source scripts"

Code: Select all

source scripts/tls.tcl
tls::initlib modules tls16.dll
and should work like a charm :)
Once the game is over, the king and the pawn go back in the same box.
t
tusinamuna
Voice
Posts: 4
Joined: Fri Dec 07, 2012 1:04 pm

Post by tusinamuna »

Thanks again, but still not working :/

Here's my .conf if you can see if there's something wrong
source scripts/tls.tcl
tls::initlib modules tls16.dll
source scripts/diggtitles.tcl
I deleted all those personal infos (server, bot name etc ;) ) so nvm about those.

Anyway, dunno why it isn't working :/
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Windrop eh? Then it's freakishly simple to get tls working. It's just that, that IS NOT how you add it... haw.. quite comical.. it isn't a module.. :lol:


Here is how you actually get tls to work on a windrop:
  • 2) Extract this to your c:\windrop\lib\tclX folder. If you are on tcl8.5 this would be c:\windrop\lib\tcl8.5\tls1.6 that would be created when you extracted it.
  • 3) Restart your windrop.
Normally the module must be compiled to an object before you could include it as a package in lib/tcl but windows already has this compiled as a .dll so no compile is necessary here.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

There's no need to copy/paste the entire configuration file as the only info needed was the fact you inserted the stuff I mentioned above.

What exactly isn't working? Is it bitching about that missing package? If it dose,, then have you placed the tls.tcl in your scripts folder, tls16.dll in modules? If it doesn't then the TLS package has been successfully loaded, or at least should.

The script doesn't go on https cos I warned you a few posts above that that site doesn't seem to have https, or at least not working at me.

You can try changing from http to https in the:

Code: Select all

if {[catch {http::geturl "http://services.digg.com/url/short/create?url=$url" -query [http::formatQuery "url" $url] -timeout 20000} token]} { 
but don't know if it's going to work or not.
Once the game is over, the king and the pawn go back in the same box.
x
xmesox
Voice
Posts: 3
Joined: Tue Apr 16, 2013 4:49 pm

Post by xmesox »

I've been having similar problems...

I'm running Windrop and trying to get https feeds going on RSS-Synd, but have been unable to get the TLS to work.

I have followed both sets of instructions in this thread.

I first started by installing the way speechles suggested, but the package doesn't load at all that way. It still gives me the error of being unable to load the feeds because of missing TLS.

And then I tried the other way, placing a copy of the tls16.dll in the modules folder, the tls.tcl in the scripts folder and then changing the config file to include:

source scripts/tls.tcl
tls::initlib modules tls16.dll

But now I get this error:

[22:53:03] Tcl error in file 'eggdrop.conf':
[22:53:03] couldn't load file "/Windrop/modules/tls16.dll": Exec format error
while executing
"tls::initlib modules tls16.dll "
(file "eggdrop.conf" line 1427)


Would really appreciate some help in getting this working.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Dumb question: the tls16.dll is in modules folder?
Once the game is over, the king and the pawn go back in the same box.
x
xmesox
Voice
Posts: 3
Joined: Tue Apr 16, 2013 4:49 pm

Post by xmesox »

Correct, the tls16.dll file is in the modules folder.
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

tls not an eggdrop module...so .. it has to be in Windrop/lib/8.5/* ..and there's no need to "source" it into eggdrop.conf

i also have a windrop ..and here is the ".status" reply :

Code: Select all

status
I am bottz, running eggdrop v1.8.0+modtclresult: 3 users (mem: 494k).
Online for 00:00 (background) - CPU: 00:05.88 - Cache hit: 25.0%
Configured with:  '--enable-strip'
Admin: Heartbroken
Config file: eggdrop.conf
OS: CYGWIN_NT-6.1-WOW64 1.7.16(0.262/5/3)
Process ID: 892 (parent 1)
Tcl library: ./lib/tcl8.5
Tcl version: 8.5.11 (header version 8.5.11)
TLS support is enabled.
TLS library: OpenSSL 1.0.1c 10 May 2012
IPv6 support is enabled.
Socket table: 20/100
Loaded 
Life iS Just a dReaM oN tHE wAy to DeaTh
x
xmesox
Voice
Posts: 3
Joined: Tue Apr 16, 2013 4:49 pm

Post by xmesox »

Hrmmm, interesting...

So you're re-itterating what Speechles suggested?

Because I have tried that too. I placed the tls file in the windrop/lib/8.5 folder (tried both inside a tls folder and just in the main 8.5 folder.

And when I started windrop up, it didn't notice the tsl at all, and just went back to saying that it couldn't load my rss-synd because of missing TLS.

Here is my .status report, with tls.dll in the lib/tcl8.5/ folder
I am Kel, running eggdrop v1.6.21: 1 user (mem: 89k).
Online for 00:00 (background) - CPU: 00:01 - Cache hit: 13.6%
Configured with: '--enable-strip'
Admin: Meso <email: x****x@gmail.com>
Config file: eggdrop.conf
OS: CYGWIN_NT-6.1-WOW64 1.7.15(0.260/5/3)
Tcl library: ./lib/tcl8.5
Tcl version: 8.5.11 (header version 8.5.11)
Socket table: 20/100
Loaded module information:

EDITED:

Just an update on this, I think I've managed to solve it. I replaced the current dll with an older version and it seems to be working now. I am using the method of calling upon the files in the config though, for what it's worth.
Post Reply