mIRC Home    About    Download    Register    News    Help

Print Thread
Socket Script Help #246382 07/06/14 04:50 PM
Joined: Jun 2014
Posts: 8
D
Demon1LT Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2014
Posts: 8
Hello. I am trying to create script, for when someone or myself types ".ttr-site" in the channel, it will check if www.toontownrewritten.com is online using www.downforeveryoneorjustme.com website.

The code displaying the websites results is no problem. Problem is, downforeverone...etc wont check www.toontownrewrriten.com itself to see if it actually displays errors even though its still online.

I'm trying to make it so once the results of downforevery..etc website say that the websites up, I then process a second socket to go to the actual website, being www.toontownrewritten.com

I am able to get there through my socket, but not what I am looking for:

Code:
HTTP/1.1 400 Bad Request
Server: cloudflare-nginx
Date: Sat, 07 Jun 2014 16:17:57 GMT
Content-Type: text/html
Content-Length: 177
Connection: close
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare-nginx</center>
</body>
</html>


As you can see, it goes to the site, but since it is a HTTPS:// or SSL website, it keeps giving be a "400 Bad Request" error, instead of what it should display which is the coding of this error page:



I have OpenSSL installed on mIRC, and enabled, and accepted teh site, so I'm not sure what the issue is

I basically just need to connect properly with the doublecheck socket since its HTTPS

Below is my complete coding:

Code:
;if someone types ".trr-site" in #toontownwritten channel, and the script isn't already active, set the nick who said the command,
;and execute the website check

on *:TEXT:*:*:{ 
  if ($chan == #toontownrewritten) { 
    if ($1 == .ttr-site || $2 == .ttr-site) { 
      if (!%active) { 
        set %active $nick
        check 
      } 
    } 
  } 
}

;if I type ".trr-site" in #toontownwritten channel, and the script isn't already active, set me as the nick, and execute the website ;check

on *:INPUT:#toontownrewritten:{ 
  if ($1 == .ttr-site) { 
    if (!%active) {
      set %active $me
      check
    } 
  } 
}

;Starts the website check process for www.downforeveryoneorjustme.com, a website that checks if the website is online or offline
;with a simple input.  I am marking www.toontownrewritten.com as the website to check

alias check {
  doublecheck
  if ($sock(sitecheck)) { sockclose sitecheck }
  sockopen sitecheck www.downforeveryoneorjustme.com 80
  sockmark sitecheck toontownrewritten.com
}

;Opens the website check process and inputs www.toontownrewritten.com it into www.downforeveryoneorjustme.com to check if its online or offline.

on *:sockopen:sitecheck: {
  sockwrite -n $sockname GET $+(/,$sock(sitecheck).mark) HTTP/1.1
  sockwrite -n $sockname Host: www.downforeveryoneorjustme.com
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname $crlf
}

;Once www.downforeveryoneorjustme.com is open, grab the HTML coding, read it, and just display the results of the website,
;stripping ;the HTML from the results as well.

on *:sockread:sitecheck: {
  ;Read the Socket
  var %x | sockread %x

  ;Strip the Sockets HTML and just display the website online/offline results 

  if ($regex(%x,(.+)<a href="(.+)"\sclass="domain">.+<\/a>(.+))) {

    ;If the www.downforeveryoneorjustme.com says the website is up,

    if (up isin %x) { 

      ;then lets initiate our doublecheck, but searching the toontownrewritten.com itself for any error messages from their server

      doublecheck {

        ;if the website displays error messages on it,

        if (%doublecheck == down) {

          ;In 2 seconds, we will start unsetting the doublecheck process and the nick, so I wont get spam commands and so the process can restart

          .timer 1 2 unset %active
          .timer 1 2 unset %doublecheck

          ;Message #toontownrewritten channel, displaying the nick who said the command, and saying the status of the website,
          ;stripping the http:// part, and simply showing the website and the status.  Since doublecheck == down, this will say the websites down.

          msg #toontownrewritten  $+ %active $+ : $gettok($replace($regsubex($+($regml(1), $regml(2), $regml(3)), /(<[^>]*>)/g,), http:&#x2F;&#x2F;, ), 2, 46)) $+ .com looks down from here.
        }

        ;If the website is truely up, then display the actual status from www.downforeveryoneorjustme and unset the variables in 2 seocnds
        ;to prevent spam, and restart the process.

        else {
          .timer 1 2 unset %active
          .timer 1 2 unset %doublecheck
          msg #toontownrewritten  $+ %active $+ : $deltok($replace($regsubex($+($regml(1), $regml(2), $regml(3)), /(<[^>]*>)/g,), http:&#x2F;&#x2F;, ), 1 ,46)) $+ .
        }
      }
    }
  }
}

;Intiate the doublecheck process for toontownrewritten.com.  If this socket is still open, lets close it.
;This is a "HTTPS://" ;website vice "HTTP://" so we have to go into SSL mode with the "-e" on sockopen and the websites port of 443.

alias doublecheck {
  if ($sock(doublecheck)) { sockclose doublecheck }
  sockopen -e doublecheck toontownrewritten.com 443
  sockmark doublecheck toontownrewritten.com
}

;Opening of toontownwritten.com - Can't figure out the website coding they use, I've tried index.php, index.html, index.htm,
;index.asp, index.aspx, with no luck so I just directed the website to /news/ folder, which is the default folder anyway.

on *:sockopen:doublecheck: {
  sockwrite -n $sockname GET /news/ HTTPS/1.0
  sockwrite -n $sockname Host: www.toontownrewritten.com
  sockwrite -n $sockname Connection: closed
  sockwrite -n $sockname $crlf
}

;Once the website is actually open, read the socket.  Don't need to strip it, but just search if the words *application error*
;are displayed on the page, since this is what shows up when the website is online, but with errors.  If it does display,
;set doublecheck as down, and continue with the sitecheck socket from www.downforeveryoneorjustme.com website.

on *:sockread:doublecheck: { 
  var %y 
  sockread %y
  if (*application error* iswm %y) {
    set %doublecheck down
  }
}

Re: Socket Script Help [Re: Demon1LT] #246405 09/06/14 03:29 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Code:
on *:sockopen:doublecheck: {
  sockwrite -n $sockname GET /news/ HTTPS/1.0
  sockwrite -n $sockname Host: www.toontownrewritten.com
  sockwrite -n $sockname Connection: closed
  sockwrite -n $sockname $crlf
}

HTTPS/1.0 should be HTTP/1.1
GET /news/ should be GET /news (without "/" at the end. Sometimes "/" is really matter)
Connection: closed should be Connection: close

Re: Socket Script Help [Re: blessing] #246407 09/06/14 03:56 AM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
Why do you say it should be 1.1 instead of 1.0?

Re: Socket Script Help [Re: Loki12583] #246408 09/06/14 04:22 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Actually i didnt highlight 1.0 or 1.1. I highlight HTTPS one should be HTTP. About 1.1, i see the reply header is HTTP/1.1 from the first post.
Quote:
HTTP/1.1 400 Bad Request

I guess HTTP/1.0 will also do.


Re: Socket Script Help [Re: Demon1LT] #246415 09/06/14 09:37 PM
Joined: Jun 2014
Posts: 8
D
Demon1LT Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2014
Posts: 8
Put the fixes in. It opens the socket, but it skips the reading and automatically closes it. Not sure why. Any ideas?

Re: Socket Script Help [Re: Demon1LT] #246416 09/06/14 09:50 PM
Joined: Mar 2014
Posts: 11
T
Tehpolecat Offline
Pikka bird
Offline
Pikka bird
T
Joined: Mar 2014
Posts: 11
Do you have openSSL installed?

Last edited by Tehpolecat; 09/06/14 09:50 PM.
Re: Socket Script Help [Re: Demon1LT] #246421 10/06/14 03:46 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
How can you tell it skips the reading?
Did you echo it?
Code:
on *:sockread:doublecheck: { 
  var %y 
  sockread %y

  if %y { echo -a %y }

  if (*application error* iswm %y) {
    set %doublecheck down
  }
}

try do /doublecheck in your editbox to see if it works. dont trigger it via command .ttr-site because your whole script is not well written.

Re: Socket Script Help [Re: blessing] #246423 10/06/14 05:36 AM
Joined: Jun 2014
Posts: 8
D
Demon1LT Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2014
Posts: 8
Nope. No luck. I set echos for each stage, sockopen sockread and sockclose and it goes straight from sockopen to sockclose. I redid my script to start of small until I am able to read it. And yes I have OpenSSL installed and enabled which is weird why it wouldnt work.

Code:
alias test {
  if ($sock(test)) { sockclose test }
  sockopen -e test toontownrewritten.com 443
  sockmark test toontownrewritten.com
}

on *:sockopen:test: {
  if ($sockerr > 0) {
    echo -a Error.  Socket could not open.
  }
  elseif (!$sockerr) {
    sockwrite -n $sockname GET /news HTTP/1.0
    sockwrite -n $sockname Host: www.toontownrewritten.com
    sockwrite -n $sockname User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
    sockwrite -n $sockname Connection: close
    sockwrite -n $sockname $crlf
    echo -a Socket Opened.
  }
}

on *:sockread:test: {
  var %y
  sockread %y
  if (%y != $null) {
    set %gtg on
  }
  elseif (!%y || %y == $null) {
    set %gtg off
  }
  if (%gtg == on) {
    echo -a %y
    set %testread on
  }
  elseif (%gtg == off) {
    set %testread off
    return
  }
}

on *:sockclose:test: { unset %gtg | $iif(%testread == on, echo -a Socket Read., echo -a Error.  Socket could not be read.) | echo -a Socket Closed. | unset %testread }

Re: Socket Script Help [Re: Demon1LT] #246427 10/06/14 02:15 PM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
Does $sslready evaluate to $true? Going straight to sockclose is indicative that it's an ssl problem.

Re: Socket Script Help [Re: Loki12583] #246429 10/06/14 03:37 PM
Joined: Jun 2014
Posts: 8
D
Demon1LT Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2014
Posts: 8
FIXED! I reinstalled mIRC enabling portable version, put the latest OpenSSL 1.0.1h and its now reading like a champ. For any that had the issue of not being able to open/read to a HTTPS site with your socket: Things to ask yourself:

1) Do you have OpenSSL Installed? If not, install the latest one into your mIRC folder, and Go to Tools > Options > IRC > Options > and make sure your SSL isnt disabled. To test afterwards, type //echo $sslready - It should come back true, if not, look into it.

2) Do you have -e open your SockOpen command and is the site port, 443?

2) Does your SockOpen script have the GET line as HTTPS/1.1 or HTTPS/1.0? If so, get rid of that "s".

3) Is the folder your opening on the GET line, ending with a "/"? If so, get rid of it (unless your going to the default homepage).

4) Does the Host: line of your SockOpen script have a www. on it? If not, add that unless you're sure the site doesn't connect with www.

5) Is "sockwrite -n $sockname $crlf" in your SockOpen Script? If not, put that in there. It wont work without it.

6) On your SockRead script, do you have your sockread set as a temporary variable? if not, put:

var %x
sockread %x

As the first two commands.

7) If all the above has failed, delete your old mIRC or install a new one in a new directory, latest version, and make sure you enable the "Portal Application" setting. Also, reinstall OpenSSL latest version.

If that doesn't do it, do trial and error testing with echos like I did, or ask someone who knows, like the guys here who helped me ;-)



Last edited by Demon1LT; 10/06/14 03:38 PM.