Posts Tagged ‘password’

Portable PHP HTTP(S) GET Request with HTTP Basic Authentication

I’m not sure where I found this class years ago (probably the php.net comments) but it’s a handy way to make simple HTTP GET requests in PHP without having to rely on the availability of allow_url_fopen or curl extensions. It supports automatic detection of SSL/TLS and non-default port numbers based on the URL you provide.

I’ve made a minor modification to include support for HTTP Basic Authentication.

class HTTPRequest
{
    var $_fp;          // HTTP socket
    var $_url;         // full URL
    var $_host;        // HTTP host
    var $_protocol;    // protocol (HTTP/HTTPS)
    var $_uri;         // request URI
    var $_port;        // port
    var $_user;        // HTTP Basic Auth User
    var $_pass;        // HTTP Basic Auth Password
   
    // scan url
    function _scan_url()
    {
        $req = $this->_url;
       
        $pos = strpos($req, '://');
        $this->_protocol = strtolower(substr($req, 0, $pos));
       
        $req = substr($req, $pos+3);
        $pos = strpos($req, '/');
        if($pos === false)
            $pos = strlen($req);
        $host = substr($req, 0, $pos);
       
        if(strpos($host, ':') !== false)
        {
            list($this->_host, $this->_port) = explode(':', $host);
        }
        else
        {
            $this->_host = $host;
            $this->_port = ($this->_protocol == 'https') ? 443 : 80;
        }
       
        $this->_uri = substr($req, $pos);
        if($this->_uri == '')
            $this->_uri = '/';
    }
   
    // constructor
    function HTTPRequest($url, $user='', $pass='')
    {
        $this->_url = $url;
        $this->_scan_url();
        $this->_user = $user;
        $this->_pass = $pass;
    }
   
    // download URL to string
    function DownloadToString()
    {
        $crlf = "\r\n";
       
        // generate request
        $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
            .    'Host: ' . $this->_host . $crlf;
            if(!empty($this->_user))
                 $req .= "Authorization: Basic " . base64_encode($this->_user . ':' . $this->_pass) . $crlf;
       $req .= $crlf;
       
        // fetch
        $this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
        fwrite($this->_fp, $req);
        while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
            $response .= fread($this->_fp, 1024);
        fclose($this->_fp);
       
        // split header and body
        $pos = strpos($response, $crlf . $crlf);
        if($pos === false)
            return($response);
        $header = substr($response, 0, $pos);
        $body = substr($response, $pos + 2 * strlen($crlf));
       
        // parse headers
        $headers = array();
        $lines = explode($crlf, $header);
        foreach($lines as $line)
            if(($pos = strpos($line, ':')) !== false)
                $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
       
        // redirection?
        if(isset($headers['location']))
        {
            $http = new HTTPRequest($headers['location']);
            return($http->DownloadToString($http));
        }
        else
        {
            return($body);
        }
    }
}

Usage:

$r = new HTTPRequest($url, [username], [password]);
$response = $r->DownloadToString();

The username and password variables are optional.

Dumpster Diving Part Two: Self Indulgence and KSU Resets due to Power Loss

I wasn’t going to write about the Meridian I adopted way back again because I planned on cleaning it up and selling the system. It turns out I have had better things to do. One night recently I decided to reward myself for being productive by dicking around with it for a bit and managed to get it working on a VoIP line by way of an ATA. I was so impressed with the quality of the audio I decided to keep the system for personal use. There is a subtle irony to having a three metre analogue bridge between two perfectly digital systems and all this fire-retardant 1990s-beige/grey plastic is getting to my head.

The POTS interface is generally terminated with a 25-pair BIX (Building Industry Cross-connect) block. These require a punch-down tool. My only punch-down tool at the moment has automatic snippers on one end which is useless as the position of the terminal teeth alternates from top to bottom.

I jammed the pairs in with the attached blade tool which is strongly discouraged as you invariably weaken the teeth and risk cracking the (especially ancient) plastic.

I, however, am a rebel.

The KSU had been unplugged some time and defaulted. Interestingly, the dialing mode defaults to pulse which, intuitively enough, doesn’t work with my ATA. It turns out you have to go in and set each line to tone dialing individually.

m7324: I rode this phone into Germany during WWII and rescued some POWs.

It took me forever to find out how to do this so pay close attention, I’m only going to remember this once:

  • Punch FEATURE **CONFIG
    • **CONFIG is **266344
  • The password should be CONFIG,  if lost will have to be reset.
  • Press the top-rightmost indicated meta key, the display will read:
    • 1. Trk/Line Data
  • Press the top-rightmost indicated meta key again. The display will read:
    • Show line: _
  • This prompt expects three digits. To configure line one, press 001. The display will read:
    • Trunk data
  • Press the top-rightmost indicated meta key once then the bottom-rightmost twice. The display will read:
    • Dial Mode: Pulse
  • The rightmost display key will read
    • CHANGE
  • Press the CHANGE display key and it will toggle between Pulse and Tone.
  • Press Rls to exit the menu

Above you can see the data and software cartridges for the M8x24; one fits into the other which fits into the cabinet. If your KSU loses all of its settings when the power goes out you need to replace the backup capacitors mounted on the data board. They are 1 farad and 5.5 volts each.

These appear to be a very common capacitor configuration for data backup and shouldn’t be hard to find at a reasonable price.

Something neat I learned in my travels is that when these 24V phones are subjected to the ring voltage on a POTS line (90V in NA?) they tend to blow. What they may lack in ruggedness they more than make up for in ease of installation however, as their all-digital signalling makes their ports polarity agnostic.

Remote Ethernet Packet Capture with Wireshark and tshark over SSH

Wireshark is a powerful and popular packet capture and analysis suite that runs on Windows and most flavours of UNIX. Often one finds one’s self in need of its GUI’s abilities on remote, headless servers without X windows (and who wants to install X on a server if they don’t have to?). One has three options: use a text/ncurses based packet capture system like ettercap to analyze the traffic on the server itself, save packet capture files and move them to your Wireshark host or pipe the output from tshark – Wireshark’s text interface – to your client in real-time. The last option suits me best; I don’t want to have to learn two packet capture suites if I can only use one and it is often useful to see the packets fly by as they come.

To compile Wireshark without the GUI, and therefore all of its X windows dependencies, on Gentoo:

# USE=”-gtk” emerge wireshark

Or disable the GTK use flag in your /etc/make.conf.

The next step is to establish passwordless root ssh access to the target machine. This should only be temporary as it is best practice to disallow any form of remote login for the root user. Please read my previous article, Passwordless or Single Password SSH with Key Exchange but be sure to use a blank passphrase for your key and disregard the part about restricting root access. Once this has been completed and you are able to log in to the target server by simply typing ssh hostname you are ready to begin your packet capture.

On the client which runs the GUI version of Wireshark, open up a shell as root and run the following:

wireshark -k -i < ( ssh -l root xxx.xxx.xxx.xxx /usr/bin/tshark -i eth0 -w - )

Be sure to change the path to tshark if this does not reflect your installation. Adjust the interface (-i flag) to match your target.

Return top
foxpa.ws
Online Marketing Toplist
Internet
Technology Blogs - Blog Rankings

Internet Blogs - BlogCatalog Blog Directory

Technology blogs
Bad Karma Networks

Please Donate!


Made in Canada  •  There's a fox in the Gibson!  •  2010-12