Wednesday, August 29, 2012

Solution for New XAMPP security concept in ubuntu

When you are using phpmyadmin in XAMPP 1.8.0, you will be faceed this problem. To avoid this you will need to do some changes in httpd-xampp.conf file.



Open file as super user

sudo gedit /opt/lampp/etc/extra/httpd-xampp.conf

It will looks like this

1:  <IfDefine PHP4>  
2:  LoadModule php4_module    modules/libphp4.so  
3:  </IfDefine>  
4:  <IfDefine PHP5>  
5:  LoadModule php5_module    modules/libphp5.so  
6:  </IfDefine>  
7:  # Disabled in XAMPP 1.8.0-beta2 because of current incompatibilities with Apache 2.4  
8:  # LoadModule perl_module    modules/mod_perl.so  
9:  Alias /phpmyadmin "/opt/lampp/phpmyadmin"  
10:  Alias /phpsqliteadmin "/opt/lampp/phpsqliteadmin"  
11:  # since XAMPP 1.4.3  
12:  <Directory "/opt/lampp/phpmyadmin">  
13:    AllowOverride AuthConfig Limit  
14:    Order allow,deny  
15:    Allow from all  
16:  </Directory>  
17:  <Directory "/opt/lampp/phpsqliteadmin">  
18:    AllowOverride AuthConfig Limit  
19:    Order allow,deny  
20:    Allow from all  
21:  </Directory>  
22:  # since LAMPP 1.0RC1  
23:  AddType application/x-httpd-php .php .php3 .php4  
24:  XBitHack on  
25:  # since 0.9.8 we've mod_perl  
26:  <IfModule mod_perl.c>  
27:      AddHandler perl-script .pl  
28:            PerlHandler ModPerl::PerlRunPrefork  
29:            PerlOptions +ParseHeaders  
30:      PerlSendHeader On  
31:  </IfModule>  
32:  # demo for mod_perl responsehandler  
33:  #PerlModule Apache::CurrentTime  
34:  #<Location /time>  
35:  #   SetHandler modperl  
36:  #   PerlResponseHandler Apache::CurrentTime  
37:  #</Location>  
38:  # AcceptMutex sysvsem is default but on some systems we need this  
39:  # thanks to jeff ort for this hint  
40:  #AcceptMutex flock  
41:  #LockFile /opt/lampp/logs/accept.lock  
42:  # this makes mod_dbd happy - oswald, 02aug06  
43:  # mod_dbd doesn't work in Apache 2.2.3: getting always heaps of "glibc detected *** corrupted double-linked list" on shutdown - oswald, 10sep06  
44:  #DBDriver sqlite3  
45:  #  
46:  # New XAMPP security concept  
47:  #  
48:  <LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">  
49:       Order deny,allow  
50:       Deny from all  
51:       Allow from ::1 127.0.0.0/8 \  
52:  fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \  
53:  81.196.40.94/32  
54:       ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var  
55:  </LocationMatch>  


2. Change according to red colored changes
1:  <IfDefine PHP4>  
2:  LoadModule php4_module    modules/libphp4.so  
3:  </IfDefine>  
4:  <IfDefine PHP5>  
5:  LoadModule php5_module    modules/libphp5.so  
6:  </IfDefine>  
7:  # Disabled in XAMPP 1.8.0-beta2 because of current incompatibilities with Apache 2.4  
8:  # LoadModule perl_module    modules/mod_perl.so  
9:  Alias /phpmyadmin "/opt/lampp/phpmyadmin"  
10:  Alias /phpsqliteadmin "/opt/lampp/phpsqliteadmin"  
11:  # since XAMPP 1.4.3  
12:  <Directory "/opt/lampp/phpmyadmin">  
13:    AllowOverride AuthConfig Limit  
14:    Require all granted  
15:    Order allow,deny  
16:    Allow from all  
17:  </Directory>  
18:  <Directory "/opt/lampp/phpsqliteadmin">  
19:    AllowOverride AuthConfig Limit  
20:    Require all granted  
21:    Order allow,deny  
22:    Allow from all  
23:  </Directory>  
24:  # since LAMPP 1.0RC1  
25:  AddType application/x-httpd-php .php .php3 .php4  
26:  XBitHack on  
27:  # since 0.9.8 we've mod_perl  
28:  <IfModule mod_perl.c>  
29:      AddHandler perl-script .pl  
30:            PerlHandler ModPerl::PerlRunPrefork  
31:            PerlOptions +ParseHeaders  
32:      PerlSendHeader On  
33:  </IfModule>  
34:  # demo for mod_perl responsehandler  
35:  #PerlModule Apache::CurrentTime  
36:  #<Location /time>  
37:  #   SetHandler modperl  
38:  #   PerlResponseHandler Apache::CurrentTime  
39:  #</Location>  
40:  # AcceptMutex sysvsem is default but on some systems we need this  
41:  # thanks to jeff ort for this hint  
42:  #AcceptMutex flock  
43:  #LockFile /opt/lampp/logs/accept.lock  
44:  # this makes mod_dbd happy - oswald, 02aug06  
45:  # mod_dbd doesn't work in Apache 2.2.3: getting always heaps of "glibc detected *** corrupted double-linked list" on shutdown - oswald, 10sep06  
46:  #DBDriver sqlite3  
47:  #  
48:  # New XAMPP security concept  
49:  #  
50:  <LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">  
51:       Order deny,allow  
52:       Allow from all  
53:       ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var  
54:  </LocationMatch>  

Then restart the XAMPP again.

If you consider about security, do not use this method

Wednesday, June 13, 2012

Enable hibernate in ubuntu 12.04

Hibernate is disable by default in ubuntu 12.04 because of a bug. Follow below instructions to enable hibernate back.

Get the terminal and copy & paste this code
$gedit /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

then it will prompt a new file in gedit and do changes like below

[Re-enable hibernate]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

Restart computer and hibernate will be back.

Thursday, June 7, 2012

Most trusted universities for online activity

The top ten most trusted universities according to iovation, with most trusted being number one, are:


 1. University of California, San Francisco
 2. Columbia University
 3. Cornell University
 4. University of Texas
 5. University of Chicago
 6. University of California, Los Angeles
 7. Northwestern University
 8. Texas A&M University
 9. University of Utah
10. University of Virginia.


Source

Tuesday, June 5, 2012

Canny and Sobel Edge Detection in C#

Sobel and Canny are major edge detection algorithms in Image Processing. Here I have implemented those algorithms using c#.

Download the source code from here.

Canny Edge Detection (click to zoom)

Sobel Edge Detection (click to zoom)




You can improve the program by using optimization methods such as threading and loop optimization.

Monday, June 4, 2012

Array addition using OpenMP

OpenMP is an application programming interface (API) that supports multi-platform shared memory multiprocessing programming.

To compile this in linux environment
$gcc -fopenmp omp_add.c -o omp_add

Then you need to define number of threads:
$export OMP_NUM_THREADS=10

To run program:
$./omp_add

Here is omp_add.c
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (int argc, char *argv[]) {
  
    int i, tid, nthreads, n = 10, N = 100000000;
    double *A, *B, tResult, fResult;
    
    time_t start, stop;
    clock_t ticks; long count;

      A = (double *) malloc(N*sizeof(double));
      B = (double *) malloc(N*sizeof(double));

      for (i=0; i<N; i++) {
          A[i] = (double)(i+1);
        B[i] = (double)(i+1);
      }

    time(&start);

    /*
    //this block use single process
    for (i=0; i<N; i++)
    {
            fResult = fResult + A[i] + B[i];
    }
    
    */
    
    //begin of parallel section
    
    #pragma omp parallel private(tid, i,tResult) shared(n,A,B,fResult)
    {
        tid = omp_get_thread_num();
        if (tid == 0) 
        {
            nthreads = omp_get_num_threads();
            printf("Number of threads = %d\n", nthreads);
        }

    #pragma omp for schedule (static, n)
        for (i=0; i < N; i++) {
            tResult = tResult + A[i] + B[i];
        }

    #pragma omp for nowait
        for (i=0; i < n; i++) 
        {
            printf("Thread %d does iteration %d\n", tid, i);
        }
        
    #pragma omp critical 
        fResult = fResult + tResult; 
    }
    //end of parallel section
    
    time(&stop);

      printf("%f\n",fResult);
      
       printf("Finished in about %.0f seconds. \n", difftime(stop, start));
  
     exit(0);
}

Special thanks for Dr. M.C. Jayawardena - BSc (Col), PhD(Uppsala), MIEEE, AMCS(SL) (Lecturer)

For more examples

Sunday, June 3, 2012

Matrix Multiplication using MPI with C

Here I'll give you a code for matrix multiplication using Message passing interface (MPI). If you are dealing with parallel computing MPI will take major role. Before run the MPI codes you will need to have MPI environment. In my case I am using university cluster.

Here is code

 /**********************************************************************  
  * MPI-based matrix multiplication AxB=C   
  *********************************************************************/  
 #include <stdio.h>  
 #include "mpi.h"  
 #define N 500    /* number of rows and columns in matrix */  
 MPI_Status status;  
 double a[N][N],b[N][N],c[N][N];       
 main(int argc, char **argv)   
 {  
  int numtasks,taskid,numworkers,source,dest,rows,offset,i,j,k,remainPart,originalRows;  
  struct timeval start, stop;  
  MPI_Init(&argc, &argv);  
  MPI_Comm_rank(MPI_COMM_WORLD, &taskid);  
  MPI_Comm_size(MPI_COMM_WORLD, &numtasks);  
  numworkers = numtasks-1;  
  /*---------------------------- master ----------------------------*/  
  if (taskid == 0) {  
   for (i=0; i<N; i++) {  
    for (j=0; j<N; j++) {    
     a[i][j]= 1.0;  
     b[i][j]= 2.0;  
    }  
   }  
   gettimeofday(&start, 0);  
   /* send matrix data to the worker tasks */  
   rows = N/numworkers;  
   offset = 0;  
   remainPart = N%numworkers;  
   for (dest=1; dest<=numworkers; dest++)   
   {          
    if (remainPart > 0)  
    {      
      originalRows = rows;  
      ++rows;  
      remainPart--;  
      MPI_Send(&offset, 1, MPI_INT, dest, 1, MPI_COMM_WORLD);  
      MPI_Send(&rows, 1, MPI_INT, dest, 1, MPI_COMM_WORLD);  
      MPI_Send(&a[offset][0], rows*N, MPI_DOUBLE,dest,1, MPI_COMM_WORLD);  
      MPI_Send(&b, N*N, MPI_DOUBLE, dest, 1, MPI_COMM_WORLD);  
      offset = offset + rows;   
      rows = originalRows;  
    }  
    else  
    {      
        MPI_Send(&offset, 1, MPI_INT, dest, 1, MPI_COMM_WORLD);  
        MPI_Send(&rows, 1, MPI_INT, dest, 1, MPI_COMM_WORLD);  
        MPI_Send(&a[offset][0], rows*N, MPI_DOUBLE,dest,1, MPI_COMM_WORLD);  
        MPI_Send(&b, N*N, MPI_DOUBLE, dest, 1, MPI_COMM_WORLD);  
        offset = offset + rows;  
    }  
   }  
   /* wait for results from all worker tasks */  
   for (i=1; i<=numworkers; i++)      
   {              
    source = i;  
    MPI_Recv(&offset, 1, MPI_INT, source, 2, MPI_COMM_WORLD, &status);  
    MPI_Recv(&rows, 1, MPI_INT, source, 2, MPI_COMM_WORLD, &status);  
    MPI_Recv(&c[offset][0], rows*N, MPI_DOUBLE, source, 2, MPI_COMM_WORLD, &status);  
   }  
   gettimeofday(&stop, 0);  
   /* printf("Here is the result matrix:\n");  
   for (i=0; i<N; i++) {   
    for (j=0; j<N; j++)   
     printf("%6.2f  ", c[i][j]);  
    printf ("\n");  
   }  
  */  
   fprintf(stdout,"Time = %.6f\n\n",  
      (stop.tv_sec+stop.tv_usec*1e-6)-(start.tv_sec+start.tv_usec*1e-6));  
  }   
  /*---------------------------- worker----------------------------*/  
  if (taskid > 0) {  
   source = 0;  
   MPI_Recv(&offset, 1, MPI_INT, source, 1, MPI_COMM_WORLD, &status);  
   MPI_Recv(&rows, 1, MPI_INT, source, 1, MPI_COMM_WORLD, &status);  
   MPI_Recv(&a, rows*N, MPI_DOUBLE, source, 1, MPI_COMM_WORLD, &status);  
   MPI_Recv(&b, N*N, MPI_DOUBLE, source, 1, MPI_COMM_WORLD, &status);  
   /* Matrix multiplication */  
   for (k=0; k<N; k++)  
    for (i=0; i<rows; i++) {  
     c[i][k] = 0.0;  
     for (j=0; j<N; j++)  
      c[i][k] = c[i][k] + a[i][j] * b[j][k];  
    }  
   MPI_Send(&offset, 1, MPI_INT, 0, 2, MPI_COMM_WORLD);  
   MPI_Send(&rows, 1, MPI_INT, 0, 2, MPI_COMM_WORLD);  
   MPI_Send(&c, rows*N, MPI_DOUBLE, 0, 2, MPI_COMM_WORLD);  
  }   
  MPI_Finalize();  
 }   

How to compile



How to run



Special Thanks for Mr. K.P.M.K. Silva - BSc (Col), MSc(York) (Lecturer)