<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/19426" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2013-06-20T22:25:59-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/19426</id>

		<entry>
		<author><name><![CDATA[tintin]]></name></author>
		<updated>2013-06-20T22:25:59-04:00</updated>

		<published>2013-06-20T22:25:59-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101704#p101704</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101704#p101704"/>
		<title type="html"><![CDATA[Submit a html form]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101704#p101704"><![CDATA[
I’m Just going to reuse this topic as its still relevant, I’m using the http module to edit a post, to add a picture, I can get the script to log in and post the data, but the problem is that it whips the rest of the post away, the html of this page has an image and description field, the description field is the part that is lost when posting the image. I think this is by design so I figured I could just 'backup' the description field and re-add it as well as the picture. I’m not sure if that is the best way to go about it I’m open for suggestions. The issue is that the data backed up does not preserve 'newlines' so when it’s added back in it all appears on one line, not exactly what I want. <br><br>I’m just using a regexp to grab the description from the edit page (so to keep any bb code intact) again I’m not sure if that is the best way to go about it or if my regexp is wrong. Here is the code section in question. The image and in future the post ID are all handled in a different section<br><div class="codebox"><p>Code: </p><pre><code>proc image:upload {image site} {http::config -useragent "Mozilla/5.0 (Windows NT; U; Windows NT x86; en-ES; rv:1.9.0.3) Firefox 3.0.7" -accept "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"set login [::http::formatQuery username user password password]set tok [::http::geturl http://www.site.net/login.php -query $login]upvar \#0 $tok stateset cookies [list]putlog $cookiesforeach {name value} $state(meta) {     if { $name eq "Set-Cookie" } {         lappend cookies [lindex [split $value {;}] 0]     } } ::http::cleanup $tok set backup [http::geturl http://www.site.net/torrents.php?action=editgroup&amp;groupid=31 -timeout 10000 -headers [list Cookie [join $cookies {;}]]] upvar #0 $backup state    set data $state(body)    regsub -all {\n|\t} $data "" dataregexp -nocase -all -- {&lt;textarea name="body" cols="91" rows="20"&gt;(.*?)&lt;/textarea&gt;} $data descputlog "Desc $desc" set cover [http::formatQuery image $image body $desc auth authcode action takegroupedit groupid 31] putlog $cover set token [http::geturl http://www.site.net/torrents.php -query $cover -timeout 10000 -headers [list Cookie [join $cookies {;}]]]</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12187">tintin</a> — Thu Jun 20, 2013 10:25 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tintin]]></name></author>
		<updated>2013-05-26T07:53:14-04:00</updated>

		<published>2013-05-26T07:53:14-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101576#p101576</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101576#p101576"/>
		<title type="html"><![CDATA[Submit a html form]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101576#p101576"><![CDATA[
Thanks That worked a charm.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12187">tintin</a> — Sun May 26, 2013 7:53 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[speechles]]></name></author>
		<updated>2013-05-18T02:00:03-04:00</updated>

		<published>2013-05-18T02:00:03-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101563#p101563</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101563#p101563"/>
		<title type="html"><![CDATA[Re: Submit a html form]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101563#p101563"><![CDATA[
A wrapper would be required to simplify this entire process. A wrapper with redirect/cookie support and can handle errors gracefully. One entirely recursive, straight forward how it works. Hopefully..<br><br>It would be used like so:<br>s:wget &lt;url-string&gt; &lt;type-string&gt; &lt;referer-string&gt; &lt;cookies-list&gt; &lt;redirects-int&gt; &lt;poison-int&gt;<br>The only required part to issue is &lt;url-string&gt;. The rest if omitted will have defaults assumed. Timeout and UserAgent are assumed to make this simple as well...<br><br>You would interact with the wrapper like so...<div class="codebox"><p>Code: </p><pre><code># login and get cookiejar and html to start withset reply [s:wget "http:://website.com/login?username=user&amp;password=pass&amp;submit=submit%20the%20url" POST]# was there an error?if {$reply != 0} {   # no, seperate html and cookiejar from reply   foreach {html cookiejar_login} $reply { break }   # get next url, using cookiejar_login obtained from above   set reply [s:wget "http:://website.com/search?text=this&amp;somethingelse=that&amp;submit=Go" GET "http://website.com/login" $cookiejar_login]   # was there an error?   if {$reply != 0} {      # no, get html to parse and create a cookiejar for search      # seperate from the one we use for login. we may never      # use the cookiejar_search but if we need to it's there.      foreach {html cookiejar_search} $reply { break }      # rest of script here..      # etc...      # etc...using cookiejar_login      # if cookiejar_login expires, you will need      # to re-login, you can use a timer or bind      # to time to simply reget a new fresh      # cookiejar and keep this in global space      # for the search procedure to use. there      # are many ways to go from here....   } else {      # yes, error type is issued in partyline...   }} else {  # yes, error type is issued in partyline...}  </code></pre></div>Here is the code to said wrapper:<div class="codebox"><p>Code: </p><pre><code># AN EASIER WAY v1.1# by speechles (c) 2013# s:wget - simple http wrapper for tcl scripting to acesss html/cookies# s:debug - simple debug output for s:wget wrapper## v1.1 - introducing an easier way...# v1.0 - the beginning...package require http# remove the two lines below if you don't care about HTTPSpackage require tlshttp::register https 443 [list ::tls::socket -require 0 -request 1]# recursive wget with cookies and refererproc s:wget { url {type GET} {refer ""} {cookies ""} {re 0} {poison 0} } {   http::config -useragent "Mozilla/EggdropWget"   # if we have cookies, let's use em ;)   if {[string equal -nocase GET $type]} {      if {![string length $cookies]} {         catch {set token [http::geturl $url -binary 1 -timeout 10000]} error      } else {         catch {set token [::http::geturl $url -binary 1 -headers [list "Referer" "$refer" "Cookie" "[string trim [join $cookies {;}] {;}]" ] -timeout 10000]} error      }   } else {      foreach {url query} [split $url ?] {break}      if {![string length $cookies]} {         catch {set token [http::geturl $url -query $query -binary 1 -timeout 10000]} error      } else {         catch {set token [::http::geturl $url -query $query -binary 1 -headers [list "Referer" "$refer" "Cookie" "[string trim [join $cookies {;}] {;}]" ] -timeout 10000]} error      }   }   # error condition 1, invalid socket or other general error   if {![string match -nocase "::http::*" $error]} {      s:debug "Error: [string totitle [string map {"\n" " | "} $error]] \( $url \)"      return 0   }   # error condition 2, http error   if {![string equal -nocase [::http::status $token] "ok"]} {      s:debug "Http error: [string totitle [::http::status $token]] \( $url \)"      http::cleanup $token      return 0   }   upvar #0 $token state   # iterate through the meta array to grab cookies   foreach {name value} $state(meta) {      # do we have cookies?                                                                    if {[regexp -nocase ^Set-Cookie$ $name]} {         # yes, add them to cookie list                                                                lappend ourCookies [lindex [split $value {;}] 0]      }   }   # if no cookies this iteration remember cookies from last   if {![info exists ourCookies] &amp;&amp; [string length $cookies]} {      set ourCookies $cookies   }   # recursive redirect support, 300's   # the full gambit of browser support, hopefully ... ;)   if {[string match "*[http::ncode $token]*" "303|302|301" ]} {      foreach {name value} $state(meta) {         if {[regexp -nocase ^location$ $name]} {            if {![string match "http*" $value]} {               # fix our locations if needed               if {![string match "/" [string index $value 0]]} {                  set value "[join [lrange [split $url "/"] 0 2] "/"]/$value"               } else {                  set value "[join [lrange [split $url "/"] 0 2] "/"]$value"               }            }            # catch redirect to self's. There is one rule:            # A url can redirect to itself a few times to attempt to            # gain proper cookies, or referers. This is hard-coded at 2.            # We catch the 3rd time and poison our recursion with it.            # This will stop the madness ;)            if {[string match [string map {" " "%20"} $value] $url]} {               incr poison               if {$poison &gt; 2} {                  s:debug "HTTP Error: Redirect error self to self \(3rd instance poisoned\) \( $url \)"                  http::cleanup $token                  return 0               }            }            # poison any nested recursion over 10 traversals deep. no legitimate            # site needs to do this. EVER!            if {[incr re] &gt; 10} {              s:debug "HTTP Error: Redirect error (&gt;10 too deep) \( $url \)"              http::cleanup $token              return 0            }            http::cleanup $token            # recursive redirect by passing cookies and referer            # this is what makes it now work! :)            if {![info exists ourCookies]} {               return [s:wget [string map {" " "%20"} $value] $url $type "" $re $poison]            } else {               return [s:wget [string map {" " "%20"} $value] $url $type $ourCookies $re $poison]            }         }      }   }   # waaay down here, we finally check the ncode for 400 or 500 codes   if {[string match 4* [http::ncode $token]] || [string match 5* [http::ncode $token]]} {      s:debug "Http resource is not available: [http::ncode $token] \( $url \)"      http::cleanup $token      return 0   }   # --- return reply   set data [http::data $token]   http::cleanup $token   if {[info exists ourCookies]} {      return [list $data $ourCookies]   } else {      return [list $data ""]   }}# debug - errors pass thru hereproc s:debug {text} {  putlog "s:wget: $text"}# eof</code></pre></div><blockquote class="uncited"><div>.tcl set cookie [lindex [s:wget <a href="http://www.google.com/search?q=hi" class="postlink">http://www.google.com/search?q=hi</a> POST] 1]<br>&gt; [01:32] s:wget: Http resource is not available: 405 ( <a href="http://www.google.com/search" class="postlink">http://www.google.com/search</a> )<br>&gt; Tcl:<br>.tcl set cookie [lindex [s:wget <a href="http://www.google.com/search?q=hi" class="postlink">http://www.google.com/search?q=hi</a> GET] 1]<br>&gt; Tcl: PREF=ID=5fce19142b49a09b:FF=0:TM=1368865867:LM=1368865867:S=VkNZO3p8OIULztjJ NID=67=JZcQs5ry96mcOry62REFi1cnEuQmFWCfFSez9hifN9Raz5PWwHTcJY1HBkepwwMQgI3dyMdIfqYzjVq6rPpsvRFi61yiloXZpdtPJhVEbOAByVvHRRVKYPaFN1TEWhZS<br>.tcl llength $cookie<br>&gt; Tcl: 2</div></blockquote>Google doesn't like POST used for GET requests as you can tell, and it also issues "two" cookies to keep track of... Hence the "cookiejar" is always a list. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"><br><br>Hopefully with all the #comments in the code everything is clear what is going on...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8138">speechles</a> — Sat May 18, 2013 2:00 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tintin]]></name></author>
		<updated>2013-05-17T23:46:23-04:00</updated>

		<published>2013-05-17T23:46:23-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101562#p101562</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101562#p101562"/>
		<title type="html"><![CDATA[Submit a html form]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101562#p101562"><![CDATA[
Sorry if this is answered somewhere else feel free to point me in the right direction if you know of something.<br><br>OK So I'm trying to get a script to do a search of some forums, then relay that data to the channel or pm, but these forums are login only so I need to get the bot to log into the site. Once I can do that I will be able to write the rest of the code relatively easily.<br><br>So I need to get the http::geturl to submit the login form then make the search.<br><br>The form has 2 parts plus the submit button.<br>username<br>&amp;<br>password<br><br>These are on the obviously named <a href="http://somesite.tld/login.php" class="postlink">http://somesite.tld/login.php</a><br>and the search is submitted from <a href="http://somesite.tld/forums.php?action=search&amp;search=whatever" class="postlink">http://somesite.tld/forums.php?action=s ... h=whatever</a><br><br>I only need help with the login and keeping it logged in to be able to make the search.<br><br>Thanks for any help<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12187">tintin</a> — Fri May 17, 2013 11:46 pm</p><hr />
]]></content>
	</entry>
	</feed>
