mIRC Home    About    Download    Register    News    Help

Print Thread
Posting to a forum from mIRC #124848 12/07/05 01:52 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
I am considering a script to handle something in our channel that would post data to a locked forum for the ops. I'm wondering if anyone has socketed anything like that before?

Obviously, I'd use sockets and probably a post command. And I'd have to work with cookies. I'm just wondering if anyone has tried that before and if I can get any tips on what to do/not to do?

Note: I'm planning on doing it with a phpBB forum, if I do it.


Invision Support
#Invision on irc.irchighway.net
Re: Posting to a forum from mIRC #124849 13/07/05 02:50 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
No one has done anything like this? Hm...


Invision Support
#Invision on irc.irchighway.net
Re: Posting to a forum from mIRC #124850 13/07/05 01:55 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Which forum is it? I mean the link...

I don't think it should be overly hard to do, but the problem is I have nothing to test on...atleast not without pissing off owners of a forum if my socketed posts would turn out somewhere else :P

Btw are you always going to want to reply in a certain restricted thread, or is it more like in a restricted forum which can have multiple threads, and you want to be able to make a thread?


Gone.
Re: Posting to a forum from mIRC #124851 13/07/05 03:16 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
You can try here... it's not where I'll end up doing this, but it's the same format. I don't have the other board up yet until I figure out if it's possible to post from a socket.

http://www.KakkoiiTranslations.net/phpBB2/index.php

If you want to test, just register with the nick you have here and try testing in the general forum. Afterwards, I'll just remove the posts.

Here's the general idea.

If an op or a user wants to ask about something, they can use a command in mIRC. The request gets posted on a forum that can only be posted to by an admin (I can set that up and set the socket to login to an admin account, so that's not a problem). Then, users and ops can view what was asked about, but no one can just start posting whatever they want directly on the forum. I'm basically just trying to make requests from users easier for the ops to deal with and this seems to be a very useful way for what I need.

So, what I need is the ability to:

a) login to the forum
b) post a message to the correct forum as a new topic (not a reply)

Example:

I socket the site and load the login page. I post the login information so that I am then logged in (I'd have to handle cookies probably at this point). Then, I move over into the forum that I want. This is simply a matter of GETTING the forum's URL. Then, I post a new topic. Might not be a bad idea to log out... I'm not sure. If you think the script needs to log out, then that should be added. If you think it's no big deal, then we don't need it. I'm the only one going to use it anyhow.

Any other questions, just let me know. Thanks for looking into this. I think I can handle the cookies and moving around the forum and such. My main concern is dealing with the posting of the topic and logging in.


Invision Support
#Invision on irc.irchighway.net
Re: Posting to a forum from mIRC #124852 14/07/05 12:03 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Welp, it works, but what a monster of a code... :tongue:

The problem I encountered is first of all, that I need a crucial temp cookie before being able to login, so I cannot even start of with immediately using POST to login, since I need part of this temp cookie in the POST address.

Apart from that I suppose it goes well.

Here's how it works.

  1. You issue /bb.getid, which is the code to retrieve the temporary cookie, which contains the sid, which we need.
  2. Once we have saved this sid in a global variable, along with another temporary cookie (data), we can login using POST.

    The temp cookie is %bb.tmpcookie, and contains the following:

    a mysql_sid part, which we will keep using throughout the code
    a mysql_data part, which will be replaced with another value once we've logged in.
  3. Use /bb.login, which will prompt you for a username and password, to login. The POST will do it's job, making you login, and creating the permanent cookie with the correct data. This cookie is stored in %bb.cookie. We'll use this cookie to make a new thread in the general discussion forum.
  4. Since the cookie is done, we can now post a thread, with /bb.post. I've added some prefab subject and body to be messaged, you will see it in the code. The text needs to be encoded, I've added a $bb.encode identifier that takes care of that.
  5. Welp, that's it, once you've posted, you will find it on the specified forum.

  • Some things to mention:
  • Basically ever forum on that link you gave me, has an index number. Fex the first forum there, General Discussion, the one I tested in has ID 10, which you can see by hovering over the link, it will say: http://www.kakkoiitranslations.net/phpBB2/viewforum.php?f=10

    So the f=10 is what we want to know.
  • However, we want to post in this forum, a new thread. I follow the link to view the forum, and now navigate over the New Topic button, which gives: http://www.kakkoiitranslations.net/phpBB2/posting.php?mode=newtopic&f=10

    That's the Referer that I use when using POST to send the message. The important part here is the last part: mode=newtopic&f=10
    which will be part of the message sent as you will see in the code.

Now the code (mamma mia):

Code:
alias bb.encode {
  var %a = 1, %b = $replace($1-,$chr(32),+), %c, %d
  while $mid(%b,%a,1) {
    %c = $v1
    %d = %d $+ $iif($regex(%c,/[a-z+]/i),%c,% $+ $base($asc(%c),10,16,2))
    inc %a
  }
  return %d
}
 [color:red]  [/color] 
alias bb.getid {
  sockopen bb.getid kakkoiitranslations.net 80
}
 [color:red]  [/color] 
on *:sockopen:bb.getid:{
  if $sockerr { echo -a error: $v1 | return }
  var %s = sockwrite -n $sockname
  %s GET /phpBB2/login.php HTTP/1.1
  %s Host: www.kakkoiitranslations.net $str($crlf,2)
}
 [color:red]  [/color] 
on *:sockread:bb.getid:{
  if $sockerr { echo -a error: $v1 | return }
  var %a
  sockread %a
  tokenize 32 %a
  if $1 == Set-Cookie: { %bb.tmpcookie = %bb.tmpcookie $2 }
  elseif $1 == $null {
    sockclose bb.getid
    if $numtok(%bb.tmpcookie,32) == 2 {
      echo 04 -a Successfully retrieved temp cookie, you may now login. (/bb.login)
    }
    else echo 04 -a Error retrieving temp cookie
  }
}
 [color:red]  [/color] 
alias bb.login {
  var %userpass = $input(Enter user name,eo) $input(Enter password,eop)
  if $numtok(%userpass,32) != 2 {
    echo -a /bb.login: you must specify both username and password to login
    return
  }
  sockopen bb.login kakkoiitranslations.net 80
  sockmark $sock(bb.login) %userpass
}
 [color:red]  [/color] 
on *:sockopen:bb.login:{
  if $sockerr { echo -a error: $v1 | return }
  tokenize 32 $sock(bb.login).mark
  var %s = sockwrite -n $sockname
  var %data = $+(username=,$1,&password=,$2,&redirect=&login=Log+in)
  ; Here's the first reason why we needed that temp cookie, that is the sid value is part of the login.
  %s POST /phpBB2/login.php?sid= $+ $gettok($gettok(%bb.tmpcookie,2,32),2,61) HTTP/1.1
  %s Referer: http://www.kakkoiitranslations.net/phpBB2/login.php
  %s Content-Type: application/x-www-form-urlencoded
  %s Host: www.kakkoiitranslations.net
  %s Content-Length: $len(%data)
  %s Connection: Keep-Alive
  ; Here's the second reason we needed that temp cookie: to get the final cookie.
  ; I tried, it does not work without sending a temp cookie first.
  %s Cookie: %bb.tmpcookie
  %s
  %s %data
}
 [color:red]  [/color] 
on *:sockread:bb.login:{
  if $sockerr { echo -a error: $v1 | return }
  var %a
  sockread %a
  tokenize 32 %a
  if $1 == Set-Cookie: { %bb.cookie = $2 $gettok(%bb.tmpcookie,2,32) }
  elseif $1 == $null {
    sockclose bb.login
    if $numtok(%bb.cookie,32) != 2 {
      echo 04 -a Could not login with the specified user/pass, please try again
    }
    else echo 04 -a Logged in. You can now create a new post if you like. (/bb.post)
  }
}
 [color:red]  [/color] 
alias bb.post {
  sockopen bb.post kakkoiitranslations.net 80
}
 [color:red]  [/color] 
on *:sockopen:bb.post:{
  if $sockerr { echo -a error: $v1 | return }
  var %s = sockwrite -n $sockname
  var %subject = $bb.encode(some more tests)
  var %subject = subject= $+ %subject
  var %message = $&
    This is a small test to see if I can post a new topic with the user of $&
    sockets in mIRC. $str($crlf,2) $&
    I'll post the quote that I use in my mIRC signature, being: $str($crlf,2) $&
    "In theory, there is no difference between theory and practice, $&
    but in practice there is." $str($crlf,3) $&
    Well that's it for now, I think it works pretty well, although the $&
    retrieving of the cookie is kinda annoying. $str($crlf,2) $&
    Greets, $crlf FiberOPtics
  var %message = &message= $+ $bb.encode(%message)
  var %append = &mode=newtopic&f=10&post=Submit
  var %data = $+(%subject,%message,%append)
  %s POST /phpBB2/posting.php HTTP/1.1
  %s Referer: http://www.kakkoiitranslations.net/phpBB2/posting.php?mode=newtopic&f=10
  %s Content-Type: application/x-www-form-urlencoded
  %s Host: www.kakkoiitranslations.net
  %s Content-Length: $len(%data)
  %s Connection: close
  %s Cookie: %bb.cookie
  %s
  %s %data
  echo 04 -a Posting new thread on forums...
}


I think that should suffice to help you well on your way. Some suggestions:

Since you can sockwrite binvars, you could create the message in a text file, run /filter over it with -k flag (or any other means), to encode each line with the $bb.encode identifier. Then when you are going to post the message, bread it in a binvar, and make sure you put the subject first, and the append thing last, as showed in the code. You'll figure it out.

Another thing, I don't know what the limit is, but I'm sure there's a limit for the length of the subject, so that might give a problem if you take one that is too long. That means you should parse the reply that you get after POSTing. That'd be a sockread event for socket bb.post.

I have put all code seperate, that is instead of using one sockread event bb.* I've kept it seperate so that you don't get lost in all the code. NOrmally I'd probably make it quite smaller by incorporating all code together.

Another issue: I don't know how long the cookie lasts, in my tests I could keep posting new threads with the same cookie information, so that all you need after going through all steps, is /bb.post. At one point, I can imagine the cookie to expire, so you should check for that too by parsing the html received after trying to make a thread.

Btw don't go through the steps of /bb.getid and /bb.login before unsetting the previous cookies lol, or it definitely won't work.

There could be more things to add, but well, I'll leave it over to you, after all, it's your script, not mine smile

Man, I feel like I could make all of this a lot prettier, and have some optimizations here and there, but to be honest, I feel very lazy :tongue:


Gone.
Re: Posting to a forum from mIRC #124853 14/07/05 02:48 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Wow! Thanks! I hadn't expected a complete script. I appreciate it! I'll look it over and try it out tomorrow and see what I come up with. Thanks again!


Invision Support
#Invision on irc.irchighway.net
Re: Posting to a forum from mIRC #124854 18/07/05 10:15 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Finally got a chance to try it. It works great!!! Thanks so much! laugh


Invision Support
#Invision on irc.irchighway.net
Re: Posting to a forum from mIRC #124855 18/07/05 10:20 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Glad to hear that smile

Could use some expanding and more error checking etc. etc. but atleast you have a framework to work with.


Gone.
Re: Posting to a forum from mIRC #124856 31/08/06 08:39 AM
Joined: Mar 2006
Posts: 9
T
TKS Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
T
Joined: Mar 2006
Posts: 9
What hitting 'search' can solve...This script was on my 'wish-list' for a while, but the cookiething was too complicated for me to handle. I just tried the script (offcourse I edited the correct forum info) but it don't seem to work.

I must admit that I understand most of the code, got some sockets in my regular scripts too. However, the part I don't understand is the part where the error occurs (at least I think it does).

When using the 'bb.getid' alias, I get the echo: error: 4. Watching the on sockopen code, the problem is here:
Code:
on *:sockopen:bb.getid:{
  if $sockerr { echo -a error: $v1 | return }

So, it might point to the 'bb.encode' alias, which I don't understand crazy

Are there an thoughts on what I should edit? I know it's a long time ago since this threat ended, but I hope some guys are still in it smile

Thanks in advance wink