Tricks and Tips about Systems/Network

August 26, 2008

How to redirect the page within your php application

Filed under: Apache,Debian,Linux,RedHat EL5,Ubuntu — Liju Mathew @ 10:40 pm

PHP Redirect Script

You can easily redirect using following code:

 
<?php
/* Redirect browser */
header("Location: http://theos.in/");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>

Another sample hack

Sample function – sitefunctions.php (note I’m not the author of the following I found it somewhere else on the Internet):

function movePage($num,$url){
   static $http = array (
       100 => "HTTP/1.1 100 Continue",
       101 => "HTTP/1.1 101 Switching Protocols",
       200 => "HTTP/1.1 200 OK",
       201 => "HTTP/1.1 201 Created",
       202 => "HTTP/1.1 202 Accepted",
       203 => "HTTP/1.1 203 Non-Authoritative Information",
       204 => "HTTP/1.1 204 No Content",
       205 => "HTTP/1.1 205 Reset Content",
       206 => "HTTP/1.1 206 Partial Content",
       300 => "HTTP/1.1 300 Multiple Choices",
       301 => "HTTP/1.1 301 Moved Permanently",
       302 => "HTTP/1.1 302 Found",
       303 => "HTTP/1.1 303 See Other",
       304 => "HTTP/1.1 304 Not Modified",
       305 => "HTTP/1.1 305 Use Proxy",
       307 => "HTTP/1.1 307 Temporary Redirect",
       400 => "HTTP/1.1 400 Bad Request",
       401 => "HTTP/1.1 401 Unauthorized",
       402 => "HTTP/1.1 402 Payment Required",
       403 => "HTTP/1.1 403 Forbidden",
       404 => "HTTP/1.1 404 Not Found",
       405 => "HTTP/1.1 405 Method Not Allowed",
       406 => "HTTP/1.1 406 Not Acceptable",
       407 => "HTTP/1.1 407 Proxy Authentication Required",
       408 => "HTTP/1.1 408 Request Time-out",
       409 => "HTTP/1.1 409 Conflict",
       410 => "HTTP/1.1 410 Gone",
       411 => "HTTP/1.1 411 Length Required",
       412 => "HTTP/1.1 412 Precondition Failed",
       413 => "HTTP/1.1 413 Request Entity Too Large",
       414 => "HTTP/1.1 414 Request-URI Too Large",
       415 => "HTTP/1.1 415 Unsupported Media Type",
       416 => "HTTP/1.1 416 Requested range not satisfiable",
       417 => "HTTP/1.1 417 Expectation Failed",
       500 => "HTTP/1.1 500 Internal Server Error",
       501 => "HTTP/1.1 501 Not Implemented",
       502 => "HTTP/1.1 502 Bad Gateway",
       503 => "HTTP/1.1 503 Service Unavailable",
       504 => "HTTP/1.1 504 Gateway Time-out"
   );
   header($http[$num]);
   header ("Location: $url");
}

Now call it as follows:

<?php
@include("/path/to/sitefunctions.php");
movePage(403,"http://www.cyberciti.biz/");
?>

August 8, 2008

How to install java on Ubuntu

Filed under: Ubuntu — Liju Mathew @ 10:06 am

This small guide shows how to install the original Sun Java 2 Platform Standard Edition 5.0 JRE (Java Runtime Environment) and JDK (Java Developer Kit) on Ubuntu.

The original Sun Java 2 is available in the ‘multiverse’ section of the Ubuntu repositories. To enable this section first add the multiverse repository to the apt sources file – the /etc/apt/sources.list should look like, – important parts are in bold:


deb http://dk.archive.ubuntu.com/ubuntu/ feisty universe multiverse

Now, update apt:

sudo apt-get update

Then install the Java debian packages.

sudo apt-get install sun-java5-bin

Or this for installing the JDK ( the Java SDK )

sudo apt-get install sun-java5-jdk

July 30, 2008

How to run mulitple Tomcat instance on the same server

Filed under: Apache,Debian,Linux,RedHat EL5,Ubuntu — Liju Mathew @ 10:41 pm
Tags:

I am listing the steps to  archive the goal

1, Step 1: Install the Tomcat files

2, Make directories for each instance

3. Editing the server.xml

Tomcat  using  2 major port one for listening http request and another for listening shutdown port

in here i put tomcat installation on /usr/local/tomcat5.5.9 folder

now I am going to edit server.xml inside the conf folder

vi /usr/local/tomcat5.5.9 folder/conf/server.xml

Find the entry

a, <Server port=”8001″ shutdown=”SHUTDOWN”> and changed the server port to any unused port

b, <!– Define a non-SSL HTTP/1.1 Connector on port 8080 –>
<Connector port=”9000″ maxHttpHeaderSize=”8192″  Change the Connector port to any unused port which tomcat listen

Again  restart the tomcat and check the that it is listening in the connector port by

!, telnet localhost   <connector port >  if it is opend a blank window it work

2, exicute $ netstat -nlp| grep  :”<connector port> .If it shows any result it’s working

Now you can start to depoly  the website.

I recommended that always to use tomcat as a backend server for Apache. You can use proxy pass module for  this functionality in apache. It also included in my previous  blog in Apache category.

################ Tomcat start up scripts ###########

# This is the init script for starting up the
#  Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

tomcat=/usr/local/jakarta-tomcat-5.5.9
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
export JAVA_HOME=/usr/java/jdk1.5.0_06

start(){
echo -n $”Starting Tomcat service: “
#daemon -c
$startup
RETVAL=$?
echo
}

stop(){
action $”Stopping Tomcat service: ” $shutdown
RETVAL=$?
echo
}

restart(){
stop
start
}

# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
status)
# This doesn’t work ;)
status tomcat
;;
restart)
restart
;;
*)
echo $”Usage: $0 {start|stop|status|restart}”
exit 1
esac

exit 0
####### end of scripts ########
How to   use this scripts

1, open in any editor and  change the path of java and  Tomcat install location

2, Move the scripts to the /etc/init.d

3, Give execute permission to the scripts, #chmod  755 /etc/init.d/tomcatd  and then execute the scripts for the testing. Eg: # ./etc/init.d/tomcat start

4, Setting runlevel and added it to system service list by # chkconfig –add /etc/init.d/tomcatd

5. Setting the tomcat  should be run at start up by #chkconfig tomcatd   on

That’s it

Liju

July 28, 2008

How to monitor SSH Login activities and FTP logins over the web

Filed under: Debian,Linux,RedHat EL5,Ubuntu — Liju Mathew @ 8:48 pm

Basic Idea behind scripts is,

We can able to monitor the activities of ssh logins,any hacking attempt and ftp logins. The steps are involved in this scripts is

1, first check the log log files for whether there is any entry is present

2, If any lines present in the logs regarding the login activities, write all those lines in our custom web access file.

3, Place the report file in a web accessable location

4, Create a virtual host on Apache for this

5, set a cron to automate the logs creation and removal

########################### Log monitoring scripts ##############

#!/bin/bash
#fingers: Liju mathew ~! lijumathewliju@gmail.com
#created: 27.07.2008
#purpose: to check the status of ssh/logins and notify the system personnel
#      if they are not listening!

today=`date +%d-%m-%y`
day_ftr=`date +%b” “%d`
web_location=/var/www/logs

# In the below example I guess the ssh log files are created in /var/log/secure (on debian /var/lig/auth.log) #and vsftp/proftp logs are created on /var/log/vsftp.log
## SSH Allow script for checking empty data from the file

/bin/cat /var/log/secure| grep “$day_ftr”| grep sshd | grep “Accepted password” &> /dev/null
if [ "$?" -eq "0"  ];then
/bin/cat /var/log/secure | grep sshd | grep “Accepted password” > $web_location/ssh-allow-$today.txt
fi

#SSH -Deny scripts for removing empty file creation
/bin/cat /var/log/secure |grep “$day_ftr” | grep “sshd” | grep “Failed password”$> /dev/null
if [ "$?" -eq "0"  ];then
/bin/cat /var/log/secure |grep “$day_ftr” | grep “sshd” | grep “Failed password” > $web_location/ssh-deny-$today.txt
fi
## FTP Scripts for avioding empty file creation
/bin/cat /var/log/xferlog | grep “$day_ftr” &> /dev/null
if [ "$?" -eq "0"  ];then
/bin/cat /var/log/xferlog | grep “$day_ftr” > $web_location/ftp-log-$today.txt
fi
### ############End of scripts ############

Create a virtual host entry for this

<VirtualHost *:80>

ServerName 182.163.98.2

Alias /logs  “/var/www/html/logs”

<Directory “/var/www/html/logs” >
Options +Indexes
AllowOverride All
Allow from all
Order allow,deny
</Directory>

<Location /logs>
AuthType Basic
AuthName “Admin access details “
AuthUserFile /var//pwd/prod/passwd
Require valid-user
Allow from all
</Location>

</VirtualHost>

3, Set up a cron for o this

copy this scripts to /var/opt/scripts/ssh_monitor.sh

30 12  * * * /bin/sh /var/opt/scripts/ssh-monitor.sh

That’s it

Note : pls make sure that log file is properly formatted with my  grep comand. If not. pls update it with your required strings.

July 24, 2008

Memory inspection

Filed under: Debian,Linux,PostgresSQL,RedHat EL5,Ubuntu — Liju Mathew @ 8:53 pm

A, Cheking  memory size and avialbale ususge

$free -m

B, What is the maximum RAM supported by the system?

$ dmidecode -t 16

C, How many memory slots are available for expansion?
$ dmidecode -t 17 | grep Size

D, Detailed memory information

$ cat /proc/meminfo

March 13, 2008

Check the status of a Crontab entry

Filed under: Debian,Linux,RedHat EL5,Ubuntu — Liju Mathew @ 8:44 pm
Tags:

How to check a cronjob is working properly

1.From the terminal exicute
$ crontab -e
* * * * * date >>/home/cronstatus.txt

then save and open the /home/cronstatus.txt using any editor
check the time intervel between the date printed on the file.

Note: the above cron job will execute every second .So you need to be remove from it ASAP after the testing …
Will update the later part shortly…….
That’s it !

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.