fredag den 16. oktober 2015

FreeOTP icon fix on Android

This guide is a workaround for:
https://fedorahosted.org/freeotp/ticket/51

How to backup your FreeOTP tokens is described in this ticket.
To backup your tokens run:
adb backup -f freeotp.bak org.fedorahosted.freeotp

Next we need to extract the backup to edit it. (How to extract the backup)

First run this command:
dd if=freeotp.bak bs=24 skip=1 | openssl zlib -d > freeotp.tar
OR
java -jar abe.jar unpack freeotp.bak freeotp.tar <password>

Then extract the tar archive and the list of files in the tar archive:
tar -tf freeotp.tar > freeotp.list
tar -xvf freeotp.tar

Now edit apps/org.fedorahosted.freeotp/sp/tokens.xml
Look for a string like this:
content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F<unique number>/ACTUAL/<SOME NUMBER>

Change it to:
content://media/external/images/media/<unique number>
The number <unique number> should be replaced with the actual number in your string.

Now pack the updated file:
cat freeotp.list | pax -wd > freeotp.tar
java -jar abe.jar pack freeotp.tar freeotp2.bak

Then restore the backup
adb restore freeotp2.bak

torsdag den 13. november 2014

Connect to postgresql 9.2 server in openSUSE 13.2

I tried to connect to my postgresql server after upgrading to openSUSE 13.2 from 13.1 using the guide from opensuse.org
That resulted in this error message:

psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


There was no files in /var/run/postgresql/. So that explained why it could not connect to that Unix domain socket.
So where was the socket? Reading this answer I found that I could run this command to figure out where the socket was:
~> netstat -nlp | grep 5432
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      12827/postgres     
tcp        0      0 :::5432                 :::*                    LISTEN      12827/postgres     
unix  2      [ ACC ]     STREAM     LISTENING     10994605 12827/postgres      /tmp/.s.PGSQL.543


That indicated that the socket was located at /tmp/ instead of /var/run/postgresql/ I was then able to find an explanation here

With that in mind i tried to connect with /tmp/ as host:
~> psql -h /tmp/
psql (9.3.5, server 9.2.7)
Type "help" for help.


That worked and as you can see the server and the client versions does not match. That could explain why the client was compiled with a different default host. Next thing could be to try to update the server from 9.2 to 9.3.

mandag den 6. januar 2014

Get Notes 9.0.1 to run on openSUSE 13.1

I installed openSUSE 13.1 just a week after its release. Unfortunately IBM Notes 9.0.1 crashed so I had to revert back to 12.3 since I wasn't able to fix the issue on my own.

By now the community have done what they do best and come up with a solution that makes it possible to run Notes 9 on openSUSE 13.1.

The issue was reported on the lotus forum.

In the response from Ben Kevan there was a link to a workaround that could get notes to run on openSUSE.

Apparently there is a bug that might be related to KDE. It has been filed on the KDE Bugtracking System as bug 329445.

Btw I am using the 64 bit version of openSUSE.

mandag den 26. august 2013

Cisco UCS XML API Event from java

I've been working professionally on an integration with the Cisco UCS Manager. Their API is non-standard. It isn't SOAP or REST or any other well known protocol. But it seems that there are actually good reasons for this. It is easy to write scripts that uses the XML API.

I did not need to write scripts though. I had to implement a java client. There were limited resources available on the subject so I wanted to post what I came up with for subscribing for events.



    public void subscribe(String host, String port) throws InterruptedException, IOException, HttpException {
String subscribeRequest = "<eventSubscribe cookie=\"\"><inFilter></inFilter></eventSubscribe>";
        HttpClient httpclient = new DefaultHttpClient();

        try {
            HttpPost httpPost = new HttpPost(MessageFormat.format("http://{1}:{2}/nuova", host, port));

            httpPost.setEntity(new StringEntity(subscribeRequest));

            // Execute HTTP request
            HttpResponse response = httpclient.execute(httpPost);

            // Get hold of the response entity
            HttpEntity entity = response.getEntity();

            // If the response does not enclose an entity, there is no need
            // to bother about connection release
            if (entity != null) {
                InputStream instream = new BufferedInputStream(entity.getContent());
                try {
                    generateEventsFromStream(instream, new EventCallBackHandler());
                } catch (RuntimeException ex) {
                    // In case of an unexpected exception you may want to abort
                    // the HTTP request in order to shut down the underlying
                    // connection immediately.
                    httpPost.abort();
                    throw ex;
                } finally {
                    // Closing the input stream will trigger connection release
                    try {
                        instream.close();
                    } catch (Exception ignore) {
                    }
                }
            }

        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }


    public void generateEventsFromStream(InputStream is, EventCallBackHandler callBack) throws IOException {
        if (is != null) {
            // Writer writer = new StringWriter();

            StringBuilder builder = new StringBuilder();
            char[] buffer = new char[1024];
            int inEid = -1;
            try {
                Reader reader = new BufferedReader(new InputStreamReader(is));
                int n;
                while ((n = reader.read(buffer)) != -1 && !stopRequested) {
                    builder.append(new String(buffer, 0, n));
                    int indexOfDelimiter = builder.indexOf(delimiter);
                    if (indexOfDelimiter != -1) {
                        String event = builder.substring(0, indexOfDelimiter + delimiter.length());
                        int indexOfStart = event.indexOf("<methodVessel"); //$NON-NLS-1$
                        event = event.substring(indexOfStart);
                        callBack.eventOccured(event);
                        builder = new StringBuilder(builder.substring(indexOfDelimiter + delimiter.length()));
                    }
                }
            } finally {
                is.close();
            }
        }
    }

When the Android device appears offline while trying to debug

I struggled a bit with my Android device appearing offline while trying to deploy an app I was working on to my phone. I was trying running adb devices to figure out if the system could communicate with the phone.

./adb devices
List of devices attached
<serial_number> offline 

At least since version 4.2.2, there is a security question that appears on the phone requesting RSA verification with the computer. Be sure your tools are updated AND you allow the PC access by verifying the security question on the devices in question. This fixed it for me. And as always, verify you have debugging enabled in the developer options ;)

Using hardware devices for Android development on openSUSE

I started doing android development.

Debugging on my Galaxy Nexus on linux did not work out of the box like it does on OS X.

Google only documented the procedure for Ubuntu based system.

On openSUSE you can put the udev rule here:
/usr/lib/udev/rules.d/51-android.rules

For a Galaxy Nexus you would add the line:
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="users"

For other devices change "04e8" to the relevant USB vendor id

Edit (2nd January 2014): Most devices are now automatically included in the above mentioned file. (Running openSUSE 12.3)

torsdag den 8. november 2012

Distributing Liferay including custom portlets, hook, ext etc

Been working on Liferay (CE 6.1.1) for a couple of months now.
I ended up with a task about creating a script that could automate deployment of Liferay, a database server and all the war archives we created (portlets, ext, hooks, themes etc).

I used PostgreSQL (9.1.6) as the database.

The documentation on this was pretty fragmented so I thought I might as well publish the complete script here:

#!/bin/bash

####################################################
# Install the postgres database                    #
####################################################
tar -zxvf ~/Downloads/postgresql-9.1.6-1-linux-x64-binaries.tar.gz
pgsql/bin/initdb -D pgsql/data
pgsql/bin/pg_ctl start -w -D pgsql/data/ -l postgres.logs
pgsql/bin/createuser --no-createdb --no-createrole --no-superuser schneider
pgsql/bin/createdb lportal -O schneider
####################################################
# Install liferay bundle including tomcat          #
####################################################
unzip ~/Downloads/liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip
####################################################
# Install portlets, hook, ext...                   #
####################################################
mkdir liferay-portal-6.1.1-ce-ga2/deploy
unzip ~/Downloads/all_the_war_archives.zip -d liferay-portal-6.1.1-ce-ga2/deploy/
####################################################
# Manually deploy ext...                           #
####################################################
unzip liferay-portal-6.1.1-ce-ga2/deploy/project-ext.war WEB-INF/ext-web/docroot/WEB-INF/classes/portal-ext.properties
mv WEB-INF/ext-web/docroot/WEB-INF/classes/portal-ext.properties liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes/
unzip liferay-portal-6.1.1-ce-ga2/deploy/project-ext.war WEB-INF/ext-impl/classes/*
mv WEB-INF/ext-impl/classes/ liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes/
rm -rf WEB-INF
####################################################
# Add setup properties file to avoid initial       #
# create user dialog...                            #
#################################################### 
cp portal-setup-wizard.properties liferay-portal-6.1.1-ce-ga2/
####################################################
# Startup liferay                                  #
####################################################
liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/startup.sh

The auto deployment of the ext war archive didin't work as expected. Because of that I manually extract the parts I needed to have deployed on startup.

To make Liferay automatically create the required database tables the portal-ext.properties have to be deployed prior to the first startup. The required settings in the portal-ext.properties are:

    #
    # Set this to to true to populate with the minimal amount of data. Set this
    # to false to populate with a larger amount of sample data.
    #
    schema.run.minimal=true
  
    #
    # Set this to true to automatically create tables and populate with default
    # data if the database is empty.
    #
    schema.run.enabled=true
   
    jdbc.default.driverClassName=org.postgresql.Driver
    jdbc.default.url=jdbc:postgresql://localhost:5432/lportal
    jdbc.default.username=schneider
    jdbc.default.password=schneider