Blogs

How to fix _Can't open file: 'sessions.MYI'_ in Drupal

This seems to occur if mysql crashes for some reason and corrupts the sessions table for Drupal.
Here is a quick way to resolve this and I have used it in the past...

mysql> REPAIR TABLE sessions QUICK;

You can also use phpmyadmin to repair the table.

Related Reading: MySQL Database Repair

Eliminate Command Line Histories with chattr (change attribute)...

If you use bash as the default shell, it keeps a history of commands accessed via the `history` command for convenience. This could end up being a security problem if someone were able to compromise a users' home directory. In some cases, this could expose improperly used passwords or special privileges available to the user such as sudo.

Consider disabling this by changing the attribute of the file to lock out the ability to update the file. As root:

# cat /dev/null > ~user/.bash_history
# chattr +i ~user/.bash_history

The user will still have a command line history, but it will only apply to the current session. When the user logs out, the information will not be saved. To have this apply to all future users, make the changes in the "/etc/skel" directory.

Compiling support for XSLT in PHP

XSLT, Extensible Stylesheet Language (XSL) Transformations is a language for transforming XML documents into other XML documents. It is a standard defined by The World Wide Web Consortium (W3C). Information about XSLT and related technologies can be found at http://www.w3.org/TR/xslt.

PHP XSLT extension only supports the Sablotron library from the Ginger Alliance. The extension does not come standard with Redhat Enterprise... and the compilation was a bit tricky. So if you are having difficulty, theses notes may help you some...

Training SpamAssassin

I use SquirrelMail and seperate out my missed spam email to a "Train/SPAM" folder and the wrongly tagged ones to "Train/HAM" folder and automate the process of training SpamAssassin via a daily cron.

Put the "SAtrain.sh" file in "/etc/cron.daily" directory.

  #!/bin/bash
  # SAtrain.sh

  # Trains SpamAssassin with Spam and Ham mbox feeds...
  # Put this file in "/etc/cron.daily" directory.
  # chmod 700 "/etc/cron.daily/SAtrain.sh"

  echo "Training SpamAssassin Begin:"
  echo "Learning from Spam..."
  /usr/bin/sa-learn --spam --configpath=/etc/mail/spamassassin --showdots --mbox /home/user/mail/Train/Spam
  sleep 10
  echo "Learning from Ham..."
  /usr/bin/sa-learn --ham --configpath=/etc/mail/spamassassin --showdots --mbox /home/user/mail/Train/Ham
  sleep 10
  echo "Clearing Spam Feed..."
  cat /dev/null > /home/user/mail/Train/Spam
  echo "Clearning Ham Feed..."
  cat /dev/null > /home/user/mail/Train/Ham
  echo "Training SpamAssassin Completed!"
  

With spamassassin trained daily and my "required_hits set to 1.9" in my "~/.spamassassin/user_prefs" file, I have been able to get an accuracy of emails being tagged as spam for about 99.9% of my emails... Woohooo!!

Related Reading:

Bayes In SpamAssassin
Bayes FAQ

TCL and Eggdrop1.6.17 installation

What is an eggdrop?

Eggdrop is an IRC bot which is the best , popular and most supported IRC bot that people use . Loads of functions can be done through eggdrop ( for eg . Channel management , userfile structures ) and the most popular part of an eggdrop is we can add modules and TCL scripts .

Setting up an eggdrop .

how to setup
You can see the manual on how to setup an eggdrop there .

But to make it quick , let me Write down some few stuffs .

  1. ssh to your shell

AutoReject Rogue Virus / Worm Mail generating infected IP via sendmail access list

MailScanner is good at filtering out the emails with attached worms and viruses. However, it does this at the expense of a high server cpu load when there is a sudden influx of auto-generated email bombardment from an IP that has been infected.

Most recent of which causing havoc is the Nyxem.E (aliases: Email-Worm.Win32.Nyxem.e, Kama Sutra, W32/MyWife.d@MM) worm set to execute on the third of each month (e.g. February 3, 2006).

Here is a quick documentaion of what I have done to autoreject emails from ISPs that are generating rogue emails.

How to create a favicon (icon displayed in the browsers location bar) with Gimp

If you notice your http error logs with a lot of messages such as "File does not exist: ... favicon.ico". You are missing an icon for your website which is displayed in the browsers location bar and also within the browser bookmarks.

Here's an easy way to create one with Gimp:

  1. Open the image you want to create the icon for, with Gimp.
  2. Resize the image to a 16x16 pixel.
  3. When you go to save, "Select File Type (By Extension)".
  4. Save as "Microsoft Windows Icon" -- ico .
  5. Name it "favicon.ico".
  6. Upload the favicon.ico file to the websites home directory.

When you visit your website, you should now have a cool new icon displayed within the browsers location bar!!

Sorting VARCHAR data in mysql

Here's a quick tip at sorting VARCHAR type data in mysql database with values in a column.

With the default sort, it would look something like below:

mysql> SELECT column FROM table_name ORDER BY column; 

column
======
100
1000
10000
200
2000
20000
...

Now with "... ORDER BY column+0", I get it sorted right:

mysql> SELECT column FROM table_name ORDER BY column+0; 

column
======
100
200
1000
2000
10000
20000
...

This is a quick fix instead of sorting to CAST operator.

Pixel Ads at LinuxWeBLOG.com

Support LinuxWeBLOG by purchasing pixels at the pixels homepage. It is being introduced for just 10 cents a pixel for a limited time, so don't miss out the opportunity to advertize your site and begin receiving traffic from us.

The site is already spidered by the bigger search engines like -- google, yahoo, msn, aol etc...

This is a one time deal and your link remains on the site forever. With the growing hits and membership on the site, the cost will not remain the same... Buy Pixels NOW !!

Listing image files in folders and subfolders with PHP

Here's a quick way to create a listing of images uploaded to a folder with php:

<?php
// file name: list_pics.php

global $startDir;

/**
 * List Directories function, which transverses sub-folders
 * listing out the image files that exists within it.
 */
function listDir( $path ) {
  global $startDir;
  $handle = opendir( $path );
  while (false !== ($file = readdir($handle))) {
    if( substr( $file, 0, 1 ) != '.' ) {
      if( is_dir( $path.'/'.$file ) ) {
        listDir( $path.'/'.$file );
      }
      else {
        if( @getimagesize( $path.'/'.$file ) ) {

          /*
          // Uncomment if using with the below "pic.php" script to
          // encode the filename and protect from direct linking. 
          $url = 'http://domain.tld/images/pic.php?pic='
                 .urlencode( str_rot13( substr( $path, strlen( $startDir )+1 ).'/'.$file ) );
          */

          $url='http://domain.tld/images/'. 
          substr( $path, strlen( $startDir )+1 ).'/'.$file;

          // You can customize the output to use img tag instead.
          echo "<a href='".$url."'>".$url."</a><br>";
        }
      }
    }
  }
  closedir( $handle );
} // End listDir function

$startDir = '.';
listDir( $startDir );

?>
Comment