Installing Webmin on Ubuntu Server

Webmin is a cool web based interface to manage servers. You can install this on a server using the following commands

You need the following packages first –

$ sudo apt-get install \
perl libnet-ssleay-perl openssl libauthen-pam-perl \
libpam-runtime libio-pty-perl libmd5-perl \
apt-show-versions libapt-pkg-perl

Now download webmin – look for the latest version and replace the URL

$ sudo wget http://prdownloads.sourceforge.net/webadmin/webmin_1.510-2_all.deb

Install webmin now

$ sudo dpkg -i webmin_1.510-2_all.deb

Update Ubuntu server

Ubuntu server doesn’t have GUI, unless you installed it. So here’s how you update the server using the command line

$ sudo apt-get update

This refreshes the update list and the following actually pulls to cache and installs it. It certainly is a long process – so choose a weekend time to be doing this.

$ sudo apt-get dist-upgrade

Just to be on the safer side, do a restart once everything gets alright.

Copy Ubuntu updates to other machines

All of the files that are updated by the update manager gets cached at the following location.

/var/cache/apt/archives

Simply make a tarball archive and use a USB stick to take it to another machine. You need to sudo

cd /var/cache/apt/archives
sudo tar -pczf updates.tar.gz *

Extract the contents in the target machines cache directory

sudo tar -zxvf updates.tar.gz

Now, run the update manager and you see that most of the stuff that you need are already marked downloaded. Simply download the rest depending on what you need and proceed with the installation. You may have to be around to approve certain dialog pop-ups.

That’s it, you have the most secure ubuntu installation on all your machines.

Downloading and Installing WordPress on cPanel servers

Most times, the hosting folks don’t provide SSH access and here’s how you can download and install WordPress or for that matter anything that’s downloadable. You need the x3 theme with the new file manager though.

First you need to make the public_html to a writable directory and create and upload the file with following code…

<?php
 
/**
 * Download Wordpress directly to the server...
 *
 */
 
function get_by_curl($url){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $c = curl_exec($ch);
  curl_close($ch);
  return $c;
}
 
 
$content = get_by_curl( 'http://wordpress.org/latest.tar.gz' );
 
file_put_contents( 'latest.tar.gz', $content );

You can now make the public_html non-writable. You’ll be able to extract the latest.tar.gz using the Extract icon on the file manager and you can install it as you would normally. The extracted folder is called wordpress and you can rename it to whatever you want or take it to the main folder. Make sure you do this before you installed it.

FTP ES – FTP over explicit TLS/SSL

Well, recently one of the web hosting service that we use switched their FTP from normal plain text file transfer protocol to FTP ES. For some reason we could not get Cute FTP client to work with it but what certainly worked was FileZilla. There are two specific learnings that we’d like to pen down here.

1. If you’re managing more than one site from the same host – like most resellers do, please enter the IP address for the host name in place of ftp.yourdomain.com. This allows a single encryption handshake to work for every site that connects.

FTPES screen FileZilla FTP Client

2. If you’re behind ISA 2006, you’re in for another set of painful setting up. We haven’t succeeded so far but here are some links that might lead to some help.

Enabling Secure FTP Access Through ISA 2006 Firewalls (Part 1)

Enabling Secure FTP Access Through ISA 2006 Firewalls (Part 2)

We’re still looking into the details on this aspect and will update the post once we have something. Any help is more than appreciated.

Using .htaccess to force https

Many occasions you need to push for an https URL (SSL) – here’s how we can do it using .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}/$1

Please note this also ensures www on the domain at the same time!

Convert PDF to plain text

Here’s some code that converts PDF to plain text

<?php
 
// new pdf extract
 
print pdf2txt("test.pdf");
 
// Function    : pdf2txt()
// Arguments   : $filename - Filename of the PDF you want to extract
// Description : Reads a pdf file, extracts data streams, and manages
//               their translation to plain text - returning the plain
//               text at the end
// Author      : Jonathan Beckett, 2005-05-02
function pdf2txt($filename){
 
  $data = getFileData($filename);
 
  // grab objects and then grab their contents (chunks)
  $a_obj = getDataArray($data,"obj","endobj");
  foreach($a_obj as $obj){
 
    $a_filter = getDataArray($obj,"<<",">>");
    if (is_array($a_filter)){
      $j++;
      $a_chunks[$j]["filter"] = $a_filter[0];
 
      $a_data = getDataArray($obj,"stream\r\n","endstream");
      if (is_array($a_data)){
        $a_chunks[$j]["data"] = substr($a_data[0],strlen("stream\r\n"),strlen($a_data[0])-strlen("stream\r\n")-strlen("endstream"));
      }
    }
  }
 
  // decode the chunks
  foreach($a_chunks as $chunk){
 
    // look at each chunk and decide how to decode it - by looking at the contents of the filter
    $a_filter = split("/",$chunk["filter"]);
 
    if ($chunk["data"]!=""){
      // look at the filter to find out which encoding has been used      
      if (substr($chunk["filter"],"FlateDecode")!==false){
        $data =@ gzuncompress($chunk["data"]);
        if (trim($data)!=""){
          $result_data .= ps2txt($data);
        } else {
 
          //$result_data .= "x";
        }
      }
    }
  }
 
  return $result_data;
 
}
 
 
// Function    : ps2txt()
// Arguments   : $ps_data - postscript data you want to convert to plain text
// Description : Does a very basic parse of postscript data to
//               return the plain text
// Author      : Jonathan Beckett, 2005-05-02
function ps2txt($ps_data){
  $result = "";
  $a_data = getDataArray($ps_data,"[","]");
  if (is_array($a_data)){
    foreach ($a_data as $ps_text){
      $a_text = getDataArray($ps_text,"(",")");
      if (is_array($a_text)){
        foreach ($a_text as $text){
          $result .= substr($text,1,strlen($text)-2);
        }
      }
    }
  } else {
    // the data may just be in raw format (outside of [] tags)
    $a_text = getDataArray($ps_data,"(",")");
    if (is_array($a_text)){
      foreach ($a_text as $text){
        $result .= substr($text,1,strlen($text)-2);
      }
    }
  }
  return $result;
}
 
 
// Function    : getFileData()
// Arguments   : $filename - filename you want to load
// Description : Reads data from a file into a variable
//               and passes that data back
// Author      : Jonathan Beckett, 2005-05-02
function getFileData($filename){
  $handle = fopen($filename,"rb");
  $data = fread($handle, filesize($filename));
  fclose($handle);
  return $data;
}
 
 
// Function    : getDataArray()
// Arguments   : $data       - data you want to chop up
//               $start_word - delimiting characters at start of each chunk
//               $end_word   - delimiting characters at end of each chunk
// Description : Loop through an array of data and put all chunks
//               between start_word and end_word in an array
// Author      : Jonathan Beckett, 2005-05-02
function getDataArray($data,$start_word,$end_word){
 
  $start = 0;
  $end = 0;
  unset($a_result);
 
  while ($start!==false && $end!==false){
    $start = strpos($data,$start_word,$end);
    if ($start!==false){
      $end = strpos($data,$end_word,$start);
      if ($end!==false){
        // data is between start and end
        $a_result[] = substr($data,$start,$end-$start+strlen($end_word));
      }
    }
  }
  return $a_result;
}
 
?>