Blogs

Flushing iptables rules

If you need to flush your firewall iptables rules, do not do a direct `iptables --flush` from a remote machine if the default policy is set to DROP packets, you will lock yourself out.

Run the below script instead:

#!/bin/bash
# flushIptables.sh
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -F

or set the default policy to ACCEPT before flushing.

To find the default policy:

# iptables -L -n | grep policy

Setup Maxemum TV-Guide in Ubuntu

Maxemum TV-Guide is a KDE TV-guide. It is developed in C++, based on QT/KDE and uses XMLTV as it’s back end to grab listings. At present there are backends grabbing TV listings for Australia, Belgium and Luxemburg, Brazil, Britain and Ireland, Denmark, Estonia, Finland, France, Germany, Hungary and Romania, Iceland, Italy, Japan, Netherlands, North America, Norway, Portugal, Reunion Island (France), South Africa, Spain, Sweden and Switzerland.

Full Story

tar with Extended Attributes/xattrs support in RedHat 5

If using earlier versions, use "star" to backup and restore files with extended attributes. SELinux and ACLs use these Extended Attributes to store the security contexts and access control lists respectively.

Tar has now been rebuilt in RedHat 5 and added support for Extended Attributes.

--selinux Archive the SELinux attributes of the files and directories
--acls Archive the ACL attributes of files and directories
--xattrs Archive all Extended Attributes of files and directories.
This includes both SELinux and ACL attributes, as well as any other xattr.

Finding setuid and setgid files

setuid files when executed inherit the permissions of the owner of the file. So having files with setuid of root is a bad idea.

Here's how to find it and unset it.

Note:
There are some system files like at and crontab that have these bits set and is required for it to run.

# find / -perm +6000 -type f -exec ls -ld {}\; > setuid.txt &

To unset it:

# chmod a-s <file>

Build PHP with Freetype on DirectAdmin

Easy way to add freetype support on PHP, on a DirectAdmin hosting environment with Fedora as the OS, is to use the rpm versions of freetype and freetype-devel.

  1. If not installed already:
    # yum install freetype freetype-devel

  2. Edit "/usr/local/directadmin/customapache/configure.php" to include the below lines.
            --with-freetype \
            --with-freetype-dir=/usr/lib \
            --enable-gd-native-ttf \

    Note: /usr/lib is the path to the libttf.so .
    # rpm -ql freetype-devel | grep libttf.so

  3. Then run the build:
    # ./build clean
    # ./build php n

  4. If you need to build and update existing packages:
    # ./build clean
    # ./build update
    # ./build all

  5. Check with phpinfo to confirm.

bash code snippets

This is going to be a collection of bash code snippets:

  1. Check if the user running the script is root:
    # make sure we're running as root
    if [ `id -u` != 0 ]; then { echo "Sorry, must be root.  Exiting..."; exit; } fi
  2. Check the successful execution of previous command:
    if (( $? )); then
            {
                    echo "could not executed successfully";
                    exit;
            }
    fi;
  3. Check number of arguments:
    # Check for proper number of command line args.

    EXPECTED_ARGS=1
    E_BADARGS=65

    if [ $# -ne $EXPECTED_ARGS ]
    then
      echo "Usage: `basename $0` {arg}"
      exit $E_BADARGS
    fi
  4. Array loops:
    VALUES=("value1" "value2" "value3" "..." "valueN")

    for ((i=0; i<${#VALUES[@]}; i++))
    do
      echo ${VALUES[$i]}
    done

How to install Vmware server From Canonical commercial repository in Ubuntu Feisty

VMware Server is a free virtualization product for Windows and Linux servers with enterprise-class support and VirtualCenter management. VMware Server is a robust yet easy to use server virtualization product and is based on proven virtualization technology, which has been used by thousands of customers for more than six years

Full Story

Create and Extract .gz,.bz2 Files in Debian

bzip2 and bunzip2 are file compression and decompression utilities. The bzip2 and bunzip2 utilities are newer than gzip and gunzip and are not as common yet, but they are rapidly gaining popularity. The bzip2 utility is capable of greater compression ratios than gzip. Therefore, a bzip2 file can be 10-20% smaller than a gzip version of the same file. Usually, files that have been compressed by bzip2 will have a .bz2 extension.

Full Story

`yum update kernel` without removing old kernels

Edit "/etc/yum/pluginconf.d/installonlyn.conf" and change the enabled to "0" or increase the "tokeep" value to the number of versions you want to keep.

[main]
enabled=1
# this sets the number of package versions which are kept
tokeep=2

Simple serach friendly url rewrite rules

Scenario:

Example:
http://somesite.com/mydir/a
http://somesite.com/mydir/b
http://somesite.com/mydir/c
etc...

To be rewritten as:
http://somesite.com/mydir/view.php?p=a
http://somesite.com/mydir/view.php?p=b
http://somesite.com/mydir/view.php?p=c
etc...

Except:
http://somesite.com/mydir rewrite--> /mydir/home.html
http://somesite.com/mydir/home rewrite-> /mydir/home.html
http://somesite.com/mydir/about rewrite-> /mydir/about.html

Solution:

These rules should go in an .htaccess file in the "mydir" directory:

DirectoryIndex home.html
Options +FollowSymLinks
RewriteEngine on
RewriteBase /mydir/
RewriteCond %{REQUEST_URI} ^/mydir/(home|about)$
RewriteRule ^.*$ %1.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ view.php?p=$1 [L]

Syndicate content
Comment