PHP Function to get Abyss's Server info.

 
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions
View previous topic :: View next topic  
Author Message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Thu Nov 30, 2006 11:33 pm    Post subject: PHP Function to get Abyss's Server info. Reply with quote

Hello everyone,

I decided to release the same function I use with my Powered By Abyss
project. The function is called "get_abyss_info", and it grabs the server's
information and puts it into an associated array.

This function supports Abyss websites inside a frame tag. Basicly, a site
that's cloaked by services like, dot.tk.

Note: Requires PHP5 because of the get_headers() function.

Code:
<pre>
<?php
/**
 * The get_abyss_info() Function
 * Created by: Josh (TRUSTAbyss)
 */
 
function get_abyss_info($input) {
   
    $output = array();
   
    if ($response = @get_headers($input, 1)) {
       
        if (gettype($response['Server']) == "array") {
       
            foreach ($response['Server'] as $server) {
           
                if (@preg_match("/^Abyss\//", $server)) {
                 
                    $response['Server'] = $server;
                    break;
                }
            }
        }
       
        if (!@preg_match("/^Abyss\//", $response['Server'])) {
       
            $fp = fopen($input, "r");

            while ($string = fgets($fp, 1024)) {

                if (@preg_match("/<frame.* src=[`'\"]([^`'\"]+)[`'\"].*>/i", $string, $matches)) {

                    $input = $matches[1];
                   
                    if ($response_02 = @get_headers($input, 1)) {
                   
                        if (gettype($response_02['Server']) == "array") {
       
                            foreach ($response_02['Server'] as $server) {
           
                                if (@preg_match("/^Abyss\//", $server)) {
                 
                                    $response_02['Server'] = $server;
                                    $response['Server'] = $response_02['Server'];
                               
                                    break 2;
                                }
                            }
                        }
                        else {
                   
                            $response['Server'] = $response_02['Server'];
                            break;
                        }
                    }
                    else {
               
                        return FALSE;
                        break;
                    }
                }
            }

            fclose($fp);
        }
       
        if (@preg_match("/^Abyss\//", $response['Server'])) {
       
            if (@preg_match("/^Abyss\/([^1].+)-(.+)-(.+) AbyssLib\/(.+)$/", $response['Server'], $matches)) {
           
                $output['version'] = $matches[1];
                $output['type']    = $matches[2];
               
                if ($matches[3] == "Win32") {
               
                    $output['os'] = "Windows";
                }
                else {
               
                    $output['os'] = $matches[3];
                }
               
                $output['libver'] = $matches[4];
                   
            }
            else {
           
                @preg_match("/^Abyss\/([^2].+)( |-)(.+) AbyssLib\/(.+)$/", $response['Server'], $matches);
               
                $output['version'] = $matches[1];
                $output['type']    = "X1";
               
                $matches[3] = @preg_replace("/\(|\)/", "", $matches[3]);
               
                if ($matches[3] == "Win32") {
               
                    $output['os'] = "Windows";
                }
                else {
               
                    $output['os'] = $matches[3];
                }
             
                $output['libver']  = $matches[4];
            }
       
            $output['is_abyss'] = TRUE;
        }
        else {
       
            $output['is_abyss'] = FALSE;
        }
   
        return $output;
    }
    else {
   
        return FALSE;
    }
}

// Start the use of the function. We will output a structured associated
// array using the print_r() function as our example.

// Syntax: get_abyss_info(URL)

$url = "http://www.aprelium.com";

if ($abyss = get_abyss_info($url)) {
   
    if ($abyss['is_abyss']) {

        print "This server is running Abyss Web Server\n\n";
        print_r($abyss);
    }
    else {
   
        print "This server is not running Abyss Web Server";
    }
}
else {

    print "This server appears to be offline";
}
?>
</pre>


Example Output:

Code:
This server is running Abyss Web Server.

Array
(
    [version] => 2.3.2
    [type] => X2
    [os] => Linux
    [libver] => 2.3.2
    [is_abyss] => 1
)


Hopefully this function is useful to some people.


Last edited by TRUSTAbyss on Sun Dec 10, 2006 9:51 pm; edited 3 times in total
Back to top View user's profile Send private message Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Fri Dec 01, 2006 12:22 pm    Post subject: get_headers for php4 Reply with quote

If you are using php4 you can use this function which gives the same output as get_headers for php5

Code:
if(! function_exists("get_headers") ){
 /* Gets the headers
  * Modified from "rsyring+phppost at gmail dot com" code
  * at http://uk2.php.net/manual/en/function.get-headers.php
  */
 function get_headers($url){
 
  $urlInfo = parse_url($url);
 
  if( isset($urlInfo["scheme"]) && $urlInfo["scheme"] == "https" ){
   $port = ( isset($urlInfo["port"]) ) ? $urlInfo["port"] : 443;
   $fp = fsockopen("ssl://" .$url_info["host"], $port, $errno, $errstr, $sktTimeout);
  }else{
   $port = ( isset($urlInfo["port"]) ) ? $urlInfo["port"] : 80;
   $fp = fsockopen($urlInfo["host"], $port, $errno, $errstr, $sktTimeout);
  }
 
  if( $fp ){
   $path = ( $urlInfo["path"] == "" ? "/" : $urlInfo["path"] ) . ( isset($urlInfo["query"]) ? "?". $urlInfo["query"] : "" );
   $head = "HEAD ". $path;
   $head .= " HTTP/1.0\r\nHost: ". $urlInfo["host"] ."\r\n";
   $head .= "Connection: close\r\n\r\n";
   fputs($fp, $head);
   
   while(! feof($fp) ){
    if( $header = trim(fgets($fp, 1024)) ){
     $sc_pos = strpos($header, ":");
     if( $sc_pos === false ){
      $headers[] = $header; //Keep it compatiable with PHP5
     }else{
      $label = substr($header, 0, $sc_pos);
      $value = substr($header, $sc_pos+1);
      $headers[$label] = trim($value);
     }
    }
   }
   
   return $headers;
  }else{
   return false;
  }
 }
}


You will have to copy&paste the above code at the top of the file you have the get_abyss_info() function, or save it as a separate file, and then include it.
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Fri Dec 01, 2006 6:11 pm    Post subject: Reply with quote

Important Update,

I've just fixed a bug that failed to check for an offline status within the frame
tags. The bug is now fixed and ready to be used. I've also improved the loops
a little (By improved, I mean exiting the loops when needed).

Use the PHP source code above for the new update.

Sincerely, Josh (TRUSTAbyss)
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group