Buscar este blog

sábado, 11 de febrero de 2017

CentOS 6 - Install LibreOffice - Offline installation

In the previous post CentOS 6 - Install LibreOffice as a service I installed libre office by using yum repositories. But if your client machine does not have access to the yum repository wich contains these packages, you have a problem.

In my local installation, I used my CentOS-Base.repo yum repo (check appendix I). This is the repo in /etc/yum.repos.d/CentOS-Base.repo file:
(...)
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
(...)

This mirror is resolved as http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock (check appendix II)

So, you can add this repo to the client machine or you can prepare a "bundle" which contains all packages needed to your installation. I tried this second one.

In my local machine I used yum downloadonly plugin in order to download the libreoffice packages and all their dependencies, and save them in a directory.
yum install yum-plugin-downloadonly

yum install --downloadonly --downloaddir=/tmp/libreoffice libreoffice-headless
yum install --downloadonly --downloaddir=/tmp/libreoffice libreoffice-writer

cd /tmp
tar -zcvf libreoffice-4.3.7.gz libreoffice

Once you have all the RPM files, you only need to put them in the client machine and make a local install.
tar -xvf libreoffice-4.3.7.gz
cd libreoffice

yum localinstall *.rpm

Appendix I - How to know which repo a package came from

I you have a package installed and you want to know where it came from, you can use repoquery. This is a utility of yum-utils:
yum install yum-utils

repoquery -i libreoffice-writer

Appendix II - How to resolve yum properties

Yum properties like "releasever", "basearch" and "infra" can be resolved by using a python script:
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["rleaseserver"]'
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["basearch "]'
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["infra"]'

Apendix III - Why I did not install the latest version of libreoffice

My Unix skills are quite meager. I tried to download and install the latest stable libreoffice RPMs by downloading them from the official site: https://es.libreoffice.org/descarga/libreoffice-estable/?type=rpm-x86_64&version=5.2 , but after the installation I got a lot of errors like:
/opt/libreoffice5.1/program/oosplash: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

Each time I installed the missing library, another one missing library appeared. I think this is due to the fact that I was using a CentOS server installation, without Gnome or KDE...

sábado, 4 de febrero de 2017

CentOS 6 - Install LibreOffice as a service

The purpose of this post is to show how to install LibreOffice in CentOS 6, without GUI. My requirements were to use LibreOffice as a PDF converter.

Install LibreOffice by using yum:
yum install libreoffice-headless

yum install libreoffice-writer

libreoffice --version

The install directory will be /usr/lib64/libreoffice

In order to make a test, you can try convert a file:
echo 'hola' > prueba.txt

libreoffice --headless --convert-to pdf prueba.txt

If you want to install it as a service, just create the following file and save it in /etc/init.d (I copied this file from here):
#!/bin/sh
#
# ooffice       openoffice conversion service
#
#
# chkconfig: 345 50 25
# description: Startup script for the Open Office conversion process
# pidfile: /var/run/ooffice.pid

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

proc="/usr/lib64/libreoffice/program/soffice.bin"
options="--headless --accept=\"socket,host=0,port=8100,tcpNoDelay=1;urp\" --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible &"
if [ ! -f $proc ]; then
        proc="/usr/lib64/openoffice.org3/program/soffice.bin"
        options="--headless --accept=\"socket,host=0,port=8100,tcpNoDelay=1;urp\" --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible &"
fi


prog=ooffice
PID_FILE=/var/run/ooffice.pid

LOG=/var/log/ooffice
if [ ! -f $LOG ]; then
        touch $LOG
        chmod 644 $LOG
fi


start() {
        echo -n $"Starting $prog: "
        umask 000
        daemon $prog $options
        RETVAL=$?
        echo
        sleep 1
        pidofproc $proc > $PID_FILE
        echo "`date +\"%Y-%m-%d %T\"`  Starting ooffice." >> $LOG
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc -p $PID_FILE $prog
        RETVAL=$?
        echo
        echo "`date +\"%Y-%m-%d %T\"`  Stopping ooffice." >> $LOG
        return $RETVAL
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                sleep 1
                start
                ;;
        status)
                status -p $PID_FILE $prog
                ;;
        *)
                echo $"Usage: $prog {start | stop | restart | status}"
                exit 1
esac

exit $RETVAL

Finally configure this script as an executable and set the service as autostart:
chmod +x /etc/init.d/soffice
chkconfig --add soffice
chkconfig soffice on
service soffice start

domingo, 8 de enero de 2017

Chrome DevTools persist changes on page reload

Chrome DevTools allow you, amongst much other things, to edit HTML and JS files and save them in a workspace.
When debugging, you can add a local folder as a workspace. Then you can map any JS file served by the server to a local file in this workspace. Any change you made in this file, by using chrome editor, is automatically saved in the workspace.
You can check the full explanation here.

There is a problem though, each time you reload the page, the browser request again de JS file and your changes are "lost". Indeed, the changes still are saved in the workspace, but you see again the file loaded from the server.


There is a solution for this. Just set the workspace as the server resources folder. In this way, you edit the same file the browser is loading.
But what happens when you does not have direct access to the server resources folder?


My solution is to combine chrome DevTools with Fiddler Autoresponder.

Fiddler is a proxy tool that captures all http traffic and allows you to inspect and change it. With the autoresponder option you can return a local response when the browser request some URL, based on a set of rules. In this way you can build your own responses or modify some previous ones, instead to request them to the server.
The problem is that the fiddler response file is not editable by chrome. The fiddler file has two parts: headers and body, being the body the JS file. So, you need two files, the fiddler response and the JS body.


You edit the JS file by using chrome editor, then copy the body to the fiddler response file, and when the page is reloaded fiddler will return the modified response.

Instead editing the fiddler response file manually, I created a python script wich inspects the chrome workspace folder looking for JS files. For each of them, the script creates a fiddler file response by appending a set of headers. These headers are also in other common file.

This script read recursively all files in a root folder, keeping only th JS files. For each one create the corresponding fiddler response file by appending a common response headers.

You can check the script here: https://github.com/evazquezma/python/blob/master/fiddlerResponse/generateResponses.py

lunes, 26 de diciembre de 2016

Windows 7 - Reboot and select proper boot device

My second windows 7 apocalypse in three weeks.

These are the steps and links I followed in order to not format (again) my system:
1) Ensure my main hard drive works properly
I disconnected the others hard drives (I have three) and I searched my main hard drive in BIOS.
The HD was there and was the first option to boot menu.

2) Try windows 7 gui repair tools
I booted from a win7 install DVD and tried to use all repair options. The problem was that my previous win7 installation was not recognized.

3) Try windows 7 command line repair tools
One of the repair win7 options is to open a DOS prompt. There I put the following commands:
bootrec /FixMbr
bootrec /FixBoot
bootrec /RebuildBcd
The first one was successful, but the other two prompted "element not found"

4) Reactivate main partition (https://aitorlozano.com/arreglando-el-arranque-de-windows/)
With these commands I could set the hard drive partition as active.
list disk
select disk = X
list partition
select partition = Y
active
exit X
X is the disk number associated with your main hard drive. You check this number with the list disk command.
Y is the disk partition. Usually has the value 1.

Then, I could execute the previous commands successful (bootrec).

5) Change boot order.
The next time I restarted the PC I got this error: "bootmgr is missing".
The only avaliable option was "Press Ctrl+Alt+Supr" to reboot, and then back to the same message.
In this situation I was not able to boot from win7 install DVD neither. So I went to BIOS again and I changed the devices boot order by selecting DVD as first option. In this way, next time it will try to boot front win7 install DVD again.

6) Replace bootmgr (https://answers.microsoft.com/en-us/windows/forum/all/bootrec-error-element-not-found/cac41df1-0590-4ea3-b7cd-134256e84c8f)
Using win7 disk I put the following commands:
bcdboot C:\windows /l es-ES

One more reboot and success!!!!

domingo, 25 de diciembre de 2016

Password hash 2016 - Argon2

Argon2 was the winner of Password Hashing Competition.

The project is written in C, but there is a java version that uses JNA (Java Native Access):  https://github.com/phxql/argon2-jvm

Maven configuration.
<dependency>
    <groupId>de.mkammerer</groupId>
    <artifactId>argon2-jvm</artifactId>
    <version>2.1</version>
</dependency>

Java example (most of the examples I saw are inaccurate due the fact that the password is actually wiped after the encryption);
import de.mkammerer.argon2.Argon2;
import de.mkammerer.argon2.Argon2Factory;

public class Main {

 public static void main(final String[] args) {
  final String hash = generateHash("secret".toCharArray());

  System.out.println(isValidPass("secret".toCharArray(), hash));
  System.out.println(isValidPass("otherPass".toCharArray(), hash));
 }

 private static String generateHash(final char[] pass) {
  final Argon2 argon2 = Argon2Factory.create(Argon2Factory.Argon2Types.ARGON2i, 64, 64);
     final char[] passwd = "secret".toCharArray();
  try {
   final int t = 2;
   final int m = 65536;
   final int p = 1;
      return argon2.hash(t, m, p, passwd);
  } finally {
      argon2.wipeArray(passwd);
  }
 }

 private static boolean isValidPass(final char[] passwd, final String hash) {
  final Argon2 argon2 = Argon2Factory.create(Argon2Factory.Argon2Types.ARGON2i, 64, 64);
  try {
   return argon2.verify(hash, passwd);
  } finally {
      argon2.wipeArray(passwd);
  }

 }
}