Archiv des Autors: pat

Read Windows licence serial from UEFI Bios

For hardware with preinstalled (OEM) Windows 8.x and Windows 10, buyers don’t get a valid key printed on the device’s back or under the battery (for notebooks). The windows installer doesn’t even ask for a key anymore or the answer is skippable. If you still want to know your key to validate your fresh installation (on another pc) you can read it using the acpidump command under linux. For ubuntu install the package with:

sudo aptitude install acpidump

and read your serial with:

sudo acpidump -n MSDM

Root login on debian mariadb

Debian switched to mariadb by default. On a new installation you can login to your mysql database as root just by executing the mysql command without a password.

root@host:~# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 56339
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type ‚help;‘ or ‚\h‘ for help. Type ‚\c‘ to clear the current input statement.

MariaDB [(none)]>

This is or can be a nice security feature. Connecting as root is only allowed by the root system user through the mysql unix socket. On the other hand you may have some software which needs the root user to access the database server. In this case you need to tweak some user settings.

First, set a password.

MariaDB [(none)]> update mysql.user set password=password(‚geheim‘) where user=’root‘;
MariaDB [(none)]> flush privileges;

Next, change the connection type.

MariaDB [(none)]> update mysql.user set plugin=“ where user=’root‘;
MariaDB [(none)]> flush privileges;

Downside seems to be the init process and autostart procedure. If you set a password for the root account, you need to add it to your /etc/mysql/debian.cnf in cleartext. Maybe you might want to consider this. Better choice would be to create a second privileged user.

Reverse ssh tunnel

My ISP started to roll out broken IPv6 for home users, so my services aren’t available from outside anymore. I don’t need a full vpn solution, but sometimes I just want to ssh home to check a file etc. The simplest solution was to create a reverse ssh tunnel. The raspberry pi inside my home network connects to my public server via ssh. Logged in on the server I can connect to a local port and get forwarded to the raspberry. That works for me really well.

Since wifi is a little bit flaky, I need to make sure, that the ssh connection is reopened when there is a connection loss. You can write a very simple script like this and use a cronjob to execute it.

#!/bin/bash

COUNT=$(ps ax | grep 'ssh -Nf -R' | wc -l)

if [ $COUNT -eq 1 ]
then
    echo "No tunnel yet. Creating..."
    ssh -Nf -R LOCALPORT:localhost:PORT user@remote
else
    echo "Tunnel already exists. Aborting."
fi

But I just found out about autossh. Which does the monitoring for you. I tried to get it working with systemd, but without any success. Ideas are welcome.

$ cat /etc/systemd/system/autossh-tunnel.service
[Unit]
Description=reverse ssh tunnel
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=localuser
ExecStart=/usr/bin/autossh -f -M 0 remote -l remoteuser -N -o "ServerliveInterval 60" -o "ServerAliveCountMax 3" -R LOCALPORT:localhost:PORT
ExecStop=/usr/bin/pkill autossh
Restart=always

$ sudo systemctl enable autossh-tunnel.service
$ systemctl start autossh-tunnel.service

Looking at journalctl, I can see the exit but no reason. Executing the command manually works fine.

systemd[1]: Starting reverse ssh tunnel...
systemd[1]: Started reverse ssh tunnel.
autossh[2468]: port set to 0, monitoring disabled
autossh[2474]: starting ssh (count 1)
ssh child pid is 2476
received signal to exit (15)

In the end I modified the bash script to use autossh.

#!/bin/bash

COUNT=$(ps ax | grep 'autossh' | wc -l)

if [ $COUNT -eq 1 ]
then
  echo "No tunnel yet. Creating..."
  /usr/bin/autossh -f -M 0 remote -l remoteuser -N -o "ServerliveInterval 60" -o "ServerAliveCountMax 3" -R LOCALPORT:localhost:PORT
else
  echo "Tunnel already exists. Aborting."
fi

If you have a better solution, let me know.

Building a cross-platform app with Apache Cordova, Ionic 3, AngularFire 2, Angular 4 and Google Firebase

After reading about 50234 different tutorials, I decided to write down the steps for a development environment on Ubuntu 16.

Install node.js. Minimum version 6. Here for Ubuntu.

The first two commands to reset/cleanup your global installation. Also make sure, there is no old binary in /usr/local/bin/.

$ sudo aptitude purge nodejs
$ sudo rm -r /usr/lib/node_modules
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo aptitude install nodejs

Also install the SDKs for your target platforms. Android or iOS.

Install the needed packages (-g for global installation).
$ sudo npm install -g ionic@latest cordova typescript typings

Your system should look anything like this:

$ ionic info
Your system information:
Cordova CLI: 7.0.0
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v6.10.3
Xcode version: Not installed

Create a new Ionic project. This will also create the project folder.
$ ionic start hybridapp blank --v2

where hybridapp is the name of the app and blank is a starter template layout (See $ ionic start –list for more examples). –v2 is needed to build the newest ionic version. Change into the project folder. This is your home now.

Install the needed npm packages (inside your project folder).

$ npm install firebase angularfire2 –save

Following this guide, I edited the package.json file. Not needed when using the correct ionic cli version.

Go to https://firebase.google.com/ and create an account. Create a new project and select „Add Firebase to your web app“. Edit the file src/app/app.module.ts and add your details.


import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';

import { AngularFireModule } from 'angularfire2';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

export const firebaseConfig = {
apiKey: "your api key",
authDomain: "your domain",
databaseURL: "your url",
storageBucket: "your id",
messagingSenderId: "your id"
};

@NgModule({
declarations: [
MyApp,
HomePage,
ListPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(firebaseConfig)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
ListPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}

Try starting the setup with

$ npm run ionic:serve

If everything works, backup your files, commit to your git so you have a working base installation.

You can now start developing. Have fun.

Turn-by-turn navigation with a single click

I was always looking to start a navigation using Google Maps on Android with a just a single click. Of course you can set some presets or even a location, and since a few generations of Google now, there is even a navigation shortcut for your work or home address. But one thing, all these methods were missing: A real one click solution. Every shortcut only gets you to the calculated route, you always have to start the real navigation with another click.
Using tasker, I found a way to finally realize what i needed.
Tasker has support for intents and using the Google Maps-Intent works like a charm.

Create a new task.
Add System -> Send Intent
Action: android.intent.action.VIEW
Type: None
Data: google.navigation:q=location+you+look+for&mode=w

modes:

  • d for car (drive)
  • w for walk
  • b for bike

Take a look the the manual page for all options.

Trakt.Watch 1.2 update – Loading screen, watchlist

I updated the pebble watchapp to version 1.2 and added two new features:

  • Loading screen
  • Watchlist

Since most entries require a web request to get the relevant data, there is always some loading time. Depending on your bluetooth connection to your phone and your phone’s network connection, this can take a few seconds. To make it visible, that the app is working and processing your request, I added a loading screen when making a web request.

I added a new menu entry: watchlist. At the moment the menu only shows the episodes on your watchlist. I’m planing to add shows and to mark them as watched.

I would love to hear some user feedback and your feature requests.

 

Trakt.Watch v1.1 for pebble released

I got my Pebble 2 a few weeks ago and decided to tinker a little bit with the SDK. Since I’m using trakt.tv to track my tv shows and wanted to try a few things, I build a watchapp for my pebble and released it today.

At the moment the app is able to:

  • authenticate against the trakt.tv api using the API (using the watchapp configuration dialog)
  • show your „on deck“ episodes
  • add the episode to you watch history (with current timestamp)
  • show your history of watched shows
  • „unwatch“ an episode
  • show basic user information
  • show auth information

Maybe I will add some more features in the future.

You can find more info about the app here: https://qstracker.com/traktwatch/. You’re welcome to try the watchapp and leave some comment.

The process of build the app and all other things needed to operate this (oauth handler etc) was quite fun and I’m thinking about porting this for some other APIs.

Fastes way to create a good looking webpage with node.js

If you need a responsive website to showcase something, here is a really fast way to do so.

Download a design you like from html5up.net.

$ mkdir node-html5
$ cd node-html5
$ npm init (just accept default settings)
$ npm install express --save

Extract the content of the design pack into the directory. Create index.js in the directory with the following content:

var express = require('express')
var path = require('path')
var PORT = 60000
var app = express()

app.use('/assets', express.static('assets'))
app.use('/images', express.static('images'))

app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/index.html'))
})

app.listen(PORT, function () {
console.log('Listening on port: ' + PORT)
})

The directory should look like this:

../node-html5/
├── assets
├── images
├── index.html
├── index.js
├── node_modules
├── package.json

Now edit the html, css and images like you want to.
Start the webserver with

$ node index.js

and point your browser to http://localhost:60000.

To deploy this setup e.g. to uberspace, see this post.

WordPress: HTTP Error 500 after plugin activation

After activating a wordpress plugin, the whole website went offline and the webserver showed an http error 500. You have to deactivate the plugin to access the site and the wp-admin interface again. You can do this either by editing the mysql database table or much simpler: By temporarily moving the plugins folder!
Just move the folder plugins in wp-contents to plugins.old, create an empty folder plugins, refresh the dashboard and click on Plugins. Remove the folder and move your plugins.old back to plugins. You have to activate all plugins again after this.

Source: https://codex.wordpress.org/FAQ_Troubleshooting#How_to_deactivate_all_plugins_when_not_able_to_access_the_administrative_menus.3F

node.js webserver auf einem uberspace einrichten

Ich wollte mich schon länger mal mit node.js beschäftigen und einen einfachen Webdienst damit bauen. Es gibt im uberspace wiki einen kurzen Artikel zu nodejs und auch alle weiteren benötigten Informationen findet man dort irgendwo. Aber man muss sich doch alles zusammen suchen. Deswegen hiermal alle Punkte zusammengefasst, die man beachten muss, um einen einfachen Prototyp bei den ubernauten zu betreiben.

node.js Version

Mit dem Befehl

$ node -v
v0.10.41

kann man sich die aktuell verwendete nodejs Version anzeigen lassen. Diese ist im Normalfall sehr alt. Um beim Aufruf von node eine aktuelle Version zu verwenden, ändern wir den Pfad. Alle verfügbaren installierten Versionen kann man sich anzeigen lassen:

$ ls -ld /package/host/localhost/nodejs-*

In der ~/.bash_profile fügt man in der letzten Zeile die gewünschte Version ein. z.B. 6

$ export PATH=/package/host/localhost/nodejs-6/bin:$PATH

Umgebungsvariable mit source ~/.bash_profile neuladen. Anschließend sollte die korrekte Version benutzt werden.

$ node -v
v6.9.1

Einfacher node.js webserver

Da wir nicht die einzigen auf dem uberspace host sind und die gängigen Ports 80 und 443 bereits vom Apachen verwendet werden, müssen wir unseren node.js server auf einem anderen Port starten und leiten dann die Anfragen an Port 80 an diesen um. Der Port sollte zwischen 61000 und 65535 liegen. Wir suchen uns einen aus (hier 61003) und überprüfen, ob dieser schon belegt ist:

$ /usr/sbin/ss -ln | fgrep 61003

Bekommen wir keinen Eintrag angezeigt, können wir diesen Port verwenden. Die Weiterleitung richten wir mit einer .htaccess Datei in ~/html/ ein:

RewriteEngine On
RewriteRule ^(.*) http://localhost:61003/$1 [P]

Jetzt können wir loslegen. Wir wechseln in unseren DocumentRoot und installieren das node express.js modul für einen Webserver.

$ cd ~/html
$ npm install express

Als nächstes erstellen wir die Datei index.js mit folgenden Inhalt (den Port entsprechend anpassen):

var express = require('express');

var app = express();
app.set('port', (process.env.PORT || 61003));

app.get('/', function (req, res) {
  res.send('Hello World!')
})

var server = app.listen(app.get('port'), function () {
 console.log('Started on port %s', app.get('port'));
});

Der Webserver kann nun testweise mit

node index.js

gestartet werden und ein Aufruf der eigenen uberspace url im Browser sollte ein „Hello World!“ anzeigen. Schon fertig!

Naja, fast. Wir möchten ja, dass der Dienst zukünftig auch läuft, wenn wir nicht angemeldet sind. Also müssen wir unseren Server nun als Dienst einrichten.

Als Dienst einrichten

Dem uberspace wiki folgend erstellen wir als nächstes einen Dienst. Dafür zuerst den supervisor aktivieren und anschließend den Dienst hinzufügen. Hier heißt dieser einfach nodetest. 

$ test -d ~/service || uberspace-setup-svscan 
$ uberspace-setup-service nodetest node ~/html/index.js

Dem tool uberspace-setup-service übergibt man als 1. Parameter den Name des neuen Dienstes (nodetest) und als 2. Parameter das Kommando (node ~/html/index.js). Das Ergebnis schauen wir uns gleich an. Solltet ihr das ganze testen wollen oder geht irgendetwas schief, könnt ihr so den Dienst wieder löschen:

$ cd ~/service/nodetest
$ rm ~/service/nodetest
$ svc -dx . log
$ rm -rf ~/etc/run-nodetest

Für jeden Dienst wird in ~/service ein eigener Unterordner erzeugt. Hier liegt die run Datei, welche den eigentlich Aufruf beinhaltet und die Logdateien. Seit ihr dem Artikel genau gefolgt, sollte die letzte Zeile mit dem Aufruf der ~/service/nodetest/run so aussehen:

exec /package/host/localhost/nodejs-6/bin/node /home/user/html/index.js 2>&1

Das node als 2. Parameter wurde durch den gesammten Pfad ersetzt. Möchte man das nicht und will lieber immer die eingestellte Version verwenden, den Pfad entfernen und nur node verwenden.

Gesteuert wird der Dienst mit dem tool svc. Die wichtigsten Parameter:

-u up, also Dienst starten
-d down, also Dienst beenden
-h hup, ein HUP-Signal senden (Reload)

Ein Neustart des Dienstes sähe z.B. so aus:

$ svc -du ~/service/nodetest

Logging

Das entsprechende Log des Dienstes können wir recht einfach lesen. Mit dieser kleinen Funktion in der ~/.bashrc wird es aber noch einfacher:

readlog()
{
        if [ -n "$1" ]; then
                zcat -f ~/service/$1/log/main/* | tai64nlocal | less;
        else
                echo "Usage: readlog <daemonname>";
        fi;
}

Der Aufruf geschieht dann mit:

$ readlog nodetest