Friday, August 23, 2013

XPDF Segmentation fault (core dumped) SOLVED

I have a friend with a Linux Mint based on Ubuntu 13.04 that has to use a Java program (jnlp); this program has some print features that doesn't open a print dialog but fires XPDF directly. That's very annoying, because there is no possibility afaik to change the default pdf program inside the application. I suppose that the command is hard coded in the application itself.
The problem is that XPDF opens and shuts down immediately and no pdf is shown. Launching XPDF from a terminal window the following errors are thrown:

$ xpdf main.pdf
***** MediaBox = ll:0,0 ur:595.276,841.89
***** CropBox = ll:0,0 ur:595.276,841.89
***** Rotate = 0
Segmentation fault (core dumped)

After a lot of trials without any success I found the solution to fix that:

sudo apt-get install libfreetype6-dev libmotif-dev
wget ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.03.tar.gz
tar xzpf xpdf-3.03.tar.gz
cd xpdf-3.03
./configure --with-freetype2-library=/usr/lib/i386-linux-gnu /
--with-freetype2-includes=/usr/include/freetype2 /
--with-Xm-library=/usr/lib /
--with-Xm-includes=/usr/include/Xm
make
sudo make install

I hope this can help somebody. Enjoy it.

Friday, May 3, 2013

Killing orphans and zombies

First please do not misunderstand me about "killing orphans and zombies". I'm for sure not going to hurt people without parents or people that are already dead :-(
I'm talking about running processes that can be harmful for your system and shuld be better get killed.

First of all a Zombie process is not an orphan process. As the word says, an orphan process is a procees without legitim parent, a zombie process is not alive but still have an entry in parent table.
A process can be orphaned either intentionally or unintentionally. Sometime a parent process exits/terminates or crashes leaving the child process still running, and then they become orphans.
In Linux/Unix like operating systems, as soon as parents of any process are dead, re-parenting occurs, automatically. Re-parenting processes whose parents are dead, means Orphaned processes, are immediately adopted by special process "init".

Take a look to a htop situation where winexe causes a lot of orphan processes:



An orphan process is a user process, which is having init (process id - 1) as parent. You can use this command in linux to find orphan processes.

       
ps -elf | head -1; ps -elf | awk '{if ($5 == 1 && $3 != "root") {print $0}}' | head


I've added an extra condition to awk cause i want to find orphan processes caused by winexe ( I added thus  && match($15,'winexe-1.00') )

       
ps -elf | head -1; ps -elf | awk '{if ($5 == 1 && $3 != "root" && match($15,'winexe-1.00')) {print $0}}' | head


I get now only the PID of the orphan process ( see in the commad {print $4} instead of {print $0}; we also leave the | head away )

       
ps -elf | ps -elf | awk '{if ($5 == 1 && $3 != "root" && match($15,'winexe-1.00')) {print $4}}'


Then I kill the processes (root permissions required, see sudo before xargs kill -9)

       
ps -elf | ps -elf | awk '{if ($5 == 1 && $3 != "root" && match($15,'winexe-1.00')) {print $4}}' | sudo xargs kill -9


You can put the last command line in a root cron job (without sudo before xargs kill -9) and let it run for instance once per hour.

Thursday, April 11, 2013

Is your Linux log in pswd protected? yes! or...not.

I log in in my linux box with a username and password. I get the feeling that my stuff is more secured and not everyone have the access to it. Nothing is less true! It is easy peasy to change the password and let you in. I'm talking about a standard situation with no encryption or extra protection.

How?

Get ready...

1. reboot the system and select the Recovery Mode:


2. Now select “root – Drop to root shell prompt” and press “Ok”





3. If you forgot your username enter this command to see all the users:

type ls /home

you will see the folder of the user (i.g. nooby)

4. Now use the following command to reset your password:

passwd nooby



Now enter your new password and confirm it.

5. Reboot typing:

exit


That’s it, you can now login with your new password.

Do you feel now less safe?  If you are worried about this you should probably set various layer of protection such as Password protected bios and grub and encrypted disk information (at least /home).

Saturday, March 30, 2013

Are good solutions always expensive?

Almost every day I'm confronted with dilemma's and problems that need an adequate solution. Many people inside my company ask me advice about how solving problems or finding the best solutions for. Sometimes finding solutions means make investments or spend money to buy goods or services for the company. Expensive solutions seems almost always to be the best but… is that true? Before I take a decision on a matter I keep always a story in my mind about the NASA and the Russians; I don't know if this story is true, but I think it's a great example how sometimes things work. Read… "When NASA first started sending up astronauts in the cold space, they quickly discovered that ballpoint pens would not work in zero gravity. To solve this the problem, NASA scientists spent a decade and $12 millions to develop a pen that writes in zero gravity, upside down, underwater, on almost any surface including glass and at temperatures ranging from below freezing to 300 C. The Russians used just a normal pencil." What can we learn from this story? I guess… if you are looking for a solution, clear your mind and think simple, but most of all… THINK!

Saturday, March 23, 2013

Mysql backup shell script

This is a shell script that allows you to backup your MySql databases and mail a compressed file to you. Of course if the backup becomes huge, you can better set the mail option off.
In the script you can give the database(s) you want to back up in an array. The script iterates the array and select the tables to back up.

In the given folder there are 4 sub folders for back up rotation. Every day is the new back up dumped in folder 01. 

Here below the script:


       

  #!/bin/bash

  # modify the destination directory to suit your environment
  export DB_BACKUP="/var/www/backup"

  # rotation ######################
  # remove day 4
  rm -rf $DB_BACKUP/04
  # moves day 3 to day 4
  mv $DB_BACKUP/03 $DB_BACKUP/04
  # moves day 2 to day 3
  mv $DB_BACKUP/02 $DB_BACKUP/03
  # moves day 1 to day 2
  mv $DB_BACKUP/01 $DB_BACKUP/02
  # makes dir 01 for day 1
  mkdir $DB_BACKUP/01
  # end rotation commands #########

  # define array of the database to bak up
  array=( db1 db2 )

  # loop through the array (each database to bak up)
  for db in "${array[@]}"
  do

    # loop through the tables of the database
   for i in `echo "show tables" | mysql -u UserNameHere -pYourPasswordHere $db | grep -v Tables_in_`;
   do
     # dumps the sql of the table to a compressed file with a database name prefix to hold the tables together
      mysqldump --add-drop-table --allow-keywords -q -a -c -u UserNameHere -pYourPasswordHere $db $i | gzip -9 > $DB_BACKUP/01/${db}_$i.sql.gz
   done

  done

  # makes a single compressed file of the backups
  tar -cvzf $DB_BACKUP/db_backup.tar.gz $DB_BACKUP

  # sends the file to your emailbox (you have to have sharutils and mailutils installed)
  uuencode  $DB_BACKUP/db_backup.tar.gz db_backup.tar.gz | mailx you@yourdomain.com

       
 

Wednesday, March 13, 2013

How to get a Mustek 600 CP scanner working in Ubuntu

I have an old scanner Lifetek that I bought years ago at the Aldi market. It is an old scanner I know, but I do not need some spectacular job, just sometimes a simple scanning job. The scanner does not work over USB, as I said it's a 'grand fa'. I faced the problem to get it working in Ubuntu under 'sane'. After some research I came to know that Lifetek is a sub brand that Mustek made for Aldi.

With the following i was able to shake it alive:


       
1. Edit /etc/sane.d/mustek_pp.conf, by uncommenting the right line:
#
# Uncomment/customize to your needs ... mine was the first one
#
# scanner Mustek-600CP 0�378 cis600
#scanner Mustek-1200CP 0�378 cis1200
# scanner Mustek-1200CP+ 0�378 cis1200+
# scanner Mustek-600-IIIEP 0�378 ccd300
#

2. Edit /etc/sane.d/dll.conf by uncommenting mustek_pp:
mustek
#mustek_pp --- THIS LINE FOR NO USB SCANNER
mustek_usb

3. Save the following script as /etc/init.d/mustek:
#!/bin/bash
chmod 777 /dev/lp0 # Does it hurt?
chmod 777 /dev/parport0
exit

4. Execute the following commands:
sudo chmod a+x /etc/init.d/mustek
sudo update-rc.d mustek defaults

       
 

Sunday, March 10, 2013

Broadcom wireless on Unbuntu

I got a lot of headache when I had to reconfigure the wireless of my wife's laptop after installing xubuntu. My wife's laptop is a Dell Vostro 1000 with a Broadcom card (BCM4311). This is a issue because it is not supported out of the box. After a lot of trial and error (a lot of) I found the way of getting it work. Here below the commands:

open a shell box and digit:

sudo apt-get update
sudo apt-get remove --purge bcmwl-kernel-source
sudo apt-get install linux-firmware-nonfree
sudo modprobe b43
sudo reboot
 
After these commands the pc should reboot and you should have your wireless up and running. Do not forget to check that the laptop hardware wireless is ON.

If it doesn't work... please do not shoot on the pianist!

Secure GET

This class can generate and validate URLs to prevent tampering.

It takes an associative array of parameters to pass in a link.

The class assembles the link parameter keys and values and adds an extra parameter which is the SHA1 value of all parameters adding a secret prefix and a suffix salt values.

The class can also verify if the parameter values are correct in a page of the previously generated URL checking against the passed SHA1 value.

Download the package at www.phpclasses.org:

http://www.phpclasses.org/package/7336-PHP-Generate-and-validate-URLs-to-prevent-tampering.html

The class:


       

class secure_get {
    
    var $arr_get;
    var $salt1;
    var $salt2;
    var $sha1;
    var $link;
    
    function __construct(){
       $this->salt1 = 'e5dg6hyt7u8fgigg802s';
       $this->salt2 = '4nfgs5asdd320dkjh7kd';
   }
    
    public function secure_make($arr=array()){
            
        $this->sha1 = $this->salt1;
        $this->link = '?';
        
        foreach($arr as $key => $val){
            
            $this->sha1 .= $key.$val;
            $this->link .= "&".$key."=".urlencode($val);
            
        }
        
        $this->sha1 .= $this->salt2;
        $this->sha1 = sha1($this->sha1);
        $this->link .= "&sha1=".$this->sha1;
        
        return($this->link);
        
    }
    
    public function secure_check($arr=array()){
        
        $this->sha1 = $this->salt1;
        
        foreach($arr as $key => $val){
            
            if($key != 'sha1') $this->sha1 .= urldecode($key.$val);
            
        }
        
        $this->sha1 .= $this->salt2;
        $this->sha1 = sha1($this->sha1);
        
        if($this->sha1 == $arr['sha1']) return(TRUE);
        
    }
    
} 

       
 


and how to use it:

       
require_once('secure_get.class.php');

$arrValues = array('city'=>'Amsterdam', 'name'=>'J. Rambo', 'age'=>'45');

$sg = new secure_get;

$link = $sg->secure_make($arrValues); 

/*
 * checks if the data is sent properly
 */
if(isset($_GET['sha1'])):
    
   echo($sg->secure_check($_GET)) ? 'SENT PROPERLY' : 'SENT WITH MANUPULATION';
    
endif; 

       
 

About "Real scripting"

Hi everyone; I'm a rich internet applications developer and I will publish in this blog everything I think is useful to avoid you some headache. Useful scripts in php, shell, vbs and JavaScript. I will publish other info too that maybe will help you in your search journey on the web. If you need professional developing you can reach me also on my website www.zanfi.nl

Today I was implementing the Gapi Google analytics php interface and I struggled in a issue in the account settings.

This is the url of the class:

http://code.google.com/p/gapi-google-analytics-php-interface/

In order to get you data from Google you have to fill your account data (see below):

define('ga_email','youremail@email.com');
define('ga_password','your password');
define('ga_profile_id','your profile id');


Right, everything OK till the ga_profile_id; this id seems to me almost impossible to find in your dashboard. I tried the id's of the tracking code that you have to insert in the tracked page, but without success.

After almost an hour of research I was able to find my code. The code is the number that you find in the URL of your Google analytics page after the p character

Here an example:

https://www.google.com/analytics/web/?hl=nl&pli=1#home/axxxxxxxxwxxxxxxxxpxxxxxxxx/

Use that code as ga_profile_id and you will be able to authenticate and get your data.