Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

09 October, 2008

Virtual Machine on Fedora

Fedora comes with a virtual machine manager( similar to vmware products) which enables you to create a virtual machine and run various other operating system. I tried installing Windows XP on a virtual machine created using virt-manager in my Fedora. Key steps to begin ..

- Make sure libvirtd demon is running
- Allocate the space as per your needs viz hard disk, RAM etc
- This one is the key step, do not forget to add a cdrom (/dev/hdc) pointning to iso image of Windows XP Disc, as after the first boot, XP installation searches for the Windows XP disk and it cannot read the host's CDROM.

Everything goes on smooth with all these parameters.

25 September, 2008

SELinux, Apache and Postgres SQL Connectivity

Recently, I decided to migrate the work from Apache windows to the Apache running on my Vmware fedora machine. Everything was supposed to work like a charm. Unfortunately, it did not. The perl in the cgi-bin directory was throwing internal server error 500. The apache error log indicated 'permission denied to create a socket', 'premature end of the script headers'. The stuff was supposed to be retrieved from postgres sql database by the perl thingy. It appeared to me that database server is not allowing my IP address to establish a connection, as recomended by pgadmin as well. After a successful entry of my IP in the conf file of postgres database server, problem still persisted. I tried almost everything, changing the file owner to apache, suexec in apache and hell lots of other possibilities. Then in the trial process I noticed a small pop up in the corner of the window, SELinux denial. SELinux is an enhanced feature in Linux, that can put restrictions on your applications in apache making database connection, nmap, access to network filesystem and lots and lots more. After giving apache persmission to make database connections, the error was resolved and application ran smoothly.

21 September, 2008

SQUID Proxy Server Authenticated Mode

We run a squid proxy server at our two system network at home :) in unauthenticated mode. I was just going through the squid logs at /var/logs/squid/access.log, and I saw few miscreant IPs eating up my network bandwith by using our proxy server. Then, I decided to tune up the authentication mode for squid proxy server. Squid doesn't have its authentication module and we need to us LDAP,PAM or NCSA. I came accross NCSA based authentication at http://www.cyberciti.biz/tips/linux-unix-squid-proxy-server-authentication.html. Given below. It worked very well in our case. 

Configure an NCSA-style username and password authentication

I am going to assume that squid is installed and working fine.

Tip: Before going further, test basic Squid functionality. Make sure squid is functioning without requiring authorization :)
Step # 1: Create a username/password

First create a NCSA password file using htpasswd command. htpasswd is used to create and update the flat-files used to store usernames and password for basic authentication of squid users.
# htpasswd /etc/squid/passwd user1
Output:

New password:
Re-type new password:
Adding password for user user1

Make sure squid can read passwd file:
# chmod o+r /etc/squid/passwd
Step # 2: Locate nsca_auth authentication helper

Usually nsca_auth is located at /usr/lib/squid/ncsa_auth. You can find out location using rpm (Redhat,CentOS,Fedora) or dpkg (Debian and Ubuntu) command:
# dpkg -L squid | grep ncsa_auth
Output:

/usr/lib/squid/ncsa_auth

If you are using RHEL/CentOS/Fedora Core or RPM based distro try:
# rpm -ql squid | grep ncsa_auth
Output:

/usr/lib/squid/ncsa_auth

Step # 3: Configure nsca_auth for squid proxy authentication

Now open /etc/squid/squid.conf file
# vi /etc/squid/squid.conf
Append (or modify) following configration directive:
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off

Also find out your ACL section and append/modify
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users
Make sure that you do not have any other http_access statement.  
Save and close the file.

Where,

* auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd : Specify squid password file and helper program location
* auth_param basic children 5 : The number of authenticator processes to spawn.
* auth_param basic realm Squid proxy-caching web server : Part of the text the user will see when prompted their username and password
* auth_param basic credentialsttl 2 hours : Specifies how long squid assumes an externally validated username:password pair is valid for - in other words how often the helper program is called for that user with password prompt. It is set to 2 hours.
* auth_param basic casesensitive off : Specifies if usernames are case sensitive. It can be on or off only
* acl ncsa_users proxy_auth REQUIRED : The REQURIED term means that any authenticated user will match the ACL named ncsa_users
* http_access allow ncsa_users : Allow proxy access only if user is successfully authenticated.

Restart squid:
# /etc/init.d/squid restart

16 September, 2008

Vaccum kills us, space kills javascript

I was exporting certain attributes viz roadname, ids, ways etc which were of alphanumeric type by appending them with a '+' charachter from my server side perl program to the javascript program at the client. The firebug popped up, unterminated string literal, lets see whats that .... Googling did not turned out to be of much help. I tried making the string short, taking into an array etc. Sometimes it worked, sometimes it did not. Amazed, I came to a stupid conclusion on the size of the arguments that need to be passed. Perhaps, that was not the cause.On of my appended field was having a space, and string thereafter was considered as a different argument by javascript. Due to mismatch in the number of arguments for that js function, it was breaking. Such a silly mistake !!! :).
Hence, Vaccum kills us, space kills javascript or rather any function in any damn
language.

05 July, 2008

Error while loading shared libraries: libx264.so.56: cannot open shared object file: No such file or directory

I recently ran an upgrade on my Fedora core box. All the library files got upgraded . Unfortunately, VLC player which used to run normal stopped working .

The error thrown was
'vlc:error while loading shared libraries: libx264.so.56: cannot open shared object file: No such file or directory'.

What I discovered is that the file libx264.so.56 had updated to libx264.so.60. Hence, I created a soft link
ln -s libx264.so.60 libx264.so.56 . This solved the issue. And VLC runs file now.

21 June, 2008

Draw a Circle in Java, the fundamental "pixels" way !

The following code draws a circle of particular diameter by setting the PIXELS falling inside the circle to a different RGB value. It involves simple co-ordinate geometry fundas. There are some approximations being taken.











_______________________________________________________________________________________________

import java.awt.image.*;
import javax.swing.*;
import javax.swing.JComponent.*;

public class circles extends JFrame {
public static void main(String args[]) {
double d=Double.parseDouble(args[0]);
int diameter= (int)d;

circles ca= new circles();
ca.drawCircle(diameter);
}
public void drawCircle(int diameter) {
int x=0,y=0,radius;
JFrame frame=new JFrame();
JLabel lab;
BufferedImage bi=new BufferedImage (diameter,diameter,BufferedImage.TYPE_BYTE_GRAY );
WritableRaster raster=bi.getRaster();
double [] iPix=new double [diameter*diameter];
if(diameter%2 == 1) {
diameter-=1;
}
radius=diameter/2;
for(int i=0;i
<(radius)) { x-=radius; } if(y>(radius)){
y=y%(radius);
}
else
{
y-=radius;
y=-y;
}
if((x*x+y*y)<=((radius)*(radius))) { iPix[i]=255; } else { iPix[i]=0; } }
raster.setPixels(0,0,diameter,diameter,iPix); lab=new JLabel(new ImageIcon(bi)); frame.add(lab);

frame.setVisible(true); frame.setSize(600,600);
}
}
_______________________________________________________________________________________________ _______________________________________________________________________________________________

compile the program as javac circles.java

run as java circles diameter_value

e.g. java circles 500

11 June, 2008

Swap two numbers without a '=' operator

Came across an interesting problem of swapping two numbers without using '=' operator. I thought of this approach. It's little lengthy and can be modified I guess.
____________________________________________________________________________
____________________________________________________________________________

#include
static int counter;
int main()
{
int a,b;
printf("Enter two numbers");
scanf("%d%d",&a,&b);

if(a>b)
{
switch ((a-b)%2)
{
case 0 :while((a-b))
{
counter++;
a--;
b++;
}
while (counter >0)
{
counter--;
a--;
b++;
}
printf("\nThe swapped set : %d\t%d",a,b);
break;
case 1 :while((a-b-1))
{
counter++;
a--;
b++;
}
counter++;
while (counter >0)
{
counter--;
a--;
b++;
}
printf("\nThe swapped set : %d\t%d",a,b);
break;
}
}

else
{
switch ((b-a)%2)
{
case 0 :while((b-a))
{
counter++;
a++;
b--;
}
while (counter >0)
{
counter--;
a++;
b--;
}
printf("\nThe swapped set : %d\t%d",a,b);
break;
case 1 :while((b-a-1))
{
counter++;
a++;
b--;
}
counter++;
while (counter >0)
{
counter--;
a++;
b--;
}
printf("\nThe swapped set : %d\t%d",a,b);
break;
}
}
return 0;
}

____________________________________________________________________________
____________________________________________________________________________

22 April, 2008

Determining IP address for eth0 failed

I had a tough time configuring wired internet connection on UBUNTU (7.10 Gusty Gibbon) and FEDORA Core 8 boxes. However after few amendments, I was able to fix and start internet in both. The Network Adapter (eth0) was not able to take IP address from the DHCP servers of my ISP ( Reliance, the case here) because the Linux distros support the future i.e. IPv6. Hence, the task at hand was to disable IPv6 and enable IPv4.

Let us discuss both of them in detail.

Ubuntu

There is process avahi-demon running which is responsible for IPv6 assignment. It can be disabled by removing from the following location
/etc/init.d/avahi-demon. Please not that all these should be done as sudo.
This should be able to fix the problem. You can restart the network and network interfaces by

/etc/init.d/networking restart
ifdown eth0
ifup eth0

Also, the interfaces file specifies starting of Network adapter and assigning address.
cd /etc/Network/interface

It should have following entry to take IP from dhcp server for eth0.

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp


Forcibly , IP address can be assigned by dhclient eth0.

Fedora Core

Disabling IPv6 in Fedora core 8 can also be done in similar fashion.

Now here is how you can do this with FC8 to disable IPv6:

  1. Append the following line to /etc/modprobe.conf:
    install ipv6 /bin/true
    alias net-pf-10 off
    alias ipv6 off

  2. Append the following line to /etc/sysconfig/network:
    NETWORKING_IPV6=no

  3. Ensure your network adapter is configured not to use IPv6. This is an easy edit in the system-config-network gui, or do it manually in /etc/sysconfig/network-scripts/ifcfg-eth0 (ammend for name of your adapter) by appending IPV6INIT=no

To restart the Network Adapter and assign address using DHCP.
ifconfig eth0 down
ifconfig eth0 up
dhclient eth0

After all these changes are made the network adapter takes an IPv4 IP address and works fine.