Monthly Archives: October 2021

Using vintage tables in nowadays Internet.

I’m a melancholic of my vintage devices. I still have a Nokia Lumia 620 running Windows Phone 8, a Blackberry Playbook and a Samsung Galaxy SCL a part from the phone I normally use.

These old devices still work and I like giving them use. For example reading stuff from Wikipedia on the Playbook.

Since several years I was experiencing that most of the webs no longer worked on then. Not only that the HTML and CSS didn’t show right because they have evolved and their browsers became obsolete. The webs just didn’t download.

They browser said Network Error, that’s it.

The problem is that webs have updated the HTTPS encryption algorithm and if one tries the HTTP version many will redirect onto the HTTPS ant that prevents those devices which don’t support the new algorithm from open up the webs.

I thought one day that someone else must have dealt with the problem and some solution must exist. Perhaps a proxy which makes internet compatible to vintage devices. So I search the Internet and I found a post in some forum that commented about a project called WebOne.

WebOne is a proxy develop by Alexander Tauenis and it’s a software made in C# that makes the HTTPS request compatible with your own device.

The goal therefore is to have this proxy running on a machine and make your table do the request through it.

I managed to install it in my Raspberry Pi 3 and in this article I’m going to explain the steps to achieve it.

LWhat I normally do is to use docker and start with a clean Ubuntu 18.4 image but it should work on a bare metal operating system.

The steps are the following:

First of all we need to update Apt and install wget and libicu-dev

apt-get update
apt-get install wget libicu-dev

Now we have to unload a .NET runtime. It has to be .NET Core 3.1.
It can be downloaded from this URL https://dotnet.microsoft.com/download/dotnet/3.1

At the time I did it I chose ASP.NET Core Runtime 3.1.19 but I also tested it with SDK 3.1.413.

As I’m installing it in the Raspberry Pi which runs Linux and the microprocessor is ARM I picked aspnetcore-runtime-3.1.19-linux-arm.tar.gz. You has to pick the fittest to the computer we are going to run it.

wget https://download.visualstudio.microsoft.com/download/pr/151dda42-4bbe-4a05-a3bf-ccb5803a2a28/8e0b0ae365850d455efbf2afcd7c6768/aspnetcore-runtime-3.1.19-linux-arm.tar.gz

Now we download WebOne from Alexander Tauenis’s Git.

wget https://github.com/atauenis/webone/releases/download/v0.11.0/webone.0.11.0.linux-armhf.deb

Now we install it. In my example I installed it in the folder root because it’s a Docker container. You can do it in a different folder.

export DOTNET_ROOT=/root/dotnet
export PATH=$PATH:$DOTNET_ROOT
mkdir -p $DOTNET_ROOT 
tar zxf aspnetcore-runtime-3.1.19-linux-arm.tar.gz -C $DOTNET_ROOT
dpkg -x webone.0.11.0.linux-armhf.deb ~/WebOneDeb 

and now to run it use run the command:

dotnet WebOneDeb/usr/share/webone/webone.dll WebOneDeb/etc/webone.conf > /dev/null

Now WebOne is running and it accepts calls on the port 8080.

Now in the device you have to set up the proxy, set the url of the comupter where you are running Web one and the port 8080 and you can now use internet on it.

I hope this tutorial is helpful.

Ncurses and PHP I

Back to the 2005 I did a course on Linux administration and we over saw a bit of Ncurses.

Ncurses is the open implementation of Curses which is a library that provides functionalities to draw the screen, keyboard and mouse management in terminals in text mode regardless of the terminal type.
This is that there are terminals with colours or only 2 colours, different number of columns and rows, character set as well as keyboard and mouse functionalities. Ncurses takes care of all for us.

Formulario de instalación de Linux (wikipedia)

Ncurses is develop in C but there are interfaces to access its functionalities from other languages like Python, Perl, JavaScript, PHP and many others.

I work with PHP which is a language mainly for web development and I thought it was interesting to be able to use it for something else other than the web and I remembered this library so I decided to research about it and see what we can do with PHP and Ncurses.

In the lists of commands I’ll give below I assume that with work with a fresh Ubuntu installation and that we have to install all the dependencies fro scratch as well as we are super user.

Installing Ncurses in PHP5.6

The reason is that the Ncurses extension wasn’t ported to PHP7 but there is a way to install it that I’ll explain later.

The ncurses extension for php isn’t available in APT but in PECL so we need to install it first.

  1. apt-get update
  2. apt-get -y install software-properties-common
  3. add-apt-repository ppa:ondrej/php
  4. apt-get update
  5. apt-get -y install php5.6-dev php5.6-xml libncurses5-dev libncursesw5-dev
  6. pecl install ncurses
  7. echo "extension=ncurses.so" > /etc/php/5.6/cli/conf.d/20-ncurses.ini

Now we can check that it’s installed with the following command:

php -m | grep ncurses

Installing Ncurses in PHP.7

n PHP 7 the process has more steps because because if we tried to install Ncurses with PECL, at step 6 it would give error. Instead we are going to download it and apply a patch by hand.

  1. apt-get update
  2. apt-get -y install wget php-dev libncursesw5-dev libncurses5-dev php-pear
  3. cd /root
  4. pecl download ncurses
  5. mkdir /root/ncurses
  6. cd /root/ncurses
  7. tar -xvzf /root/ncurses-1.0.2.tgz
  8. wget "https://bugs.php.net/patch-display.php?bug_id=71299&patch=ncurses-php7-support-again.patch&revision=1474549490&download=1" -O ncurses.patch
  9. mv ncurses-1.0.2 ncurses-php5
  10. patch --strip=0 --verbose --ignore-whitespace <ncurses.patch
  11. cd ncurses-php5
  12. phpize
  13. ./configure
  14. make
  15. make install
  16. cat <<'EndOfHereDoc' >/etc/php/7.2/mods-available/ncurses.ini
    ; configuration for php ncurses module
    ; priority=20
    extension=ncurses.so
    EndOfHereDoc
  17. ln --symbolic /etc/php/7.2/mods-available/ncurses.ini /etc/php/7.2/cli/conf.d/20-ncurses.ini
  18. php -m | grep ncurses

Sample code:

Here I leave a PHP script that draws a frame in the middle of the screen with the phrase hola mundo.

#!/usr/bin/env php
<?php
/*
 * We force this environment variable to “linux because in some terminals
 * the border that we are going to use to draw the dialogue box doesn’t
 * show well in Putty nor in colour without this value.
 */
putenv('TERM=linux');

//Iniciamos ncurses.
$ncurses_session = ncurses_init();

//We save the settings there were before running the script
ncurses_savetty();

//we check whether the terminal is in colour.
if (ncurses_has_colors()) {
    ncurses_start_color();
	//we create an ink and paper colour combination.
    ncurses_init_pair(
		1,						//index
		NCURSES_COLOR_YELLOW,	//ink colour
		NCURSES_COLOR_BLUE		//papel colour
	);
	//we set this colour by default.
    ncurses_color_set(1);
}
/**
 * we createe "window" with the values 0.
 * This creates a "window" of the size of the screen.
 * The window is a concept that will be explained.
 */
$ventana_principal = ncurses_newwin(
	0, //rows
	0, //columns
	0, //y
	0  //x
);

//We use the window to capture the size in columns and rows by reference.
ncurses_getmaxyx($ventana_principal, $filas, $columnas);

//We create an smaller window to draw inside.
$my_windows = ncurses_newwin(
	5,	//rows
	15,	//columns
	($filas - 5) / 2,		//y
	($columnas - 15) / 2	//x
);

//we set the same colour we created above to draw in the window.
ncurses_wcolor_set($my_windows , 1);

/*
 * the loop is to paint the background of the window
 * we paint 5 rows of spaces of blue colour
 */
for($y = 0; $y < 5; $y++){
	//We set the cursor on the corresponding row.
	ncurses_wmove($my_windows , $y, 0);
	//We paint a 15 space character line.
	ncurses_whline(
		$my_windows ,	//handler of our window.
		ord(' '),		//Chracter we are going to draw. It has to be converter indo ASCII.
		15
	);
}

//now we write the text of our window.
ncurses_mvwaddstr(
	$my_windows ,	//handler of our window.
	2,				//y, relative to the interior of our window.
	3,				//x, relative to the interior of our window.
	'Hola mundo'	//text
);

//now we draw the frame around.
ncurses_wborder(
	$my_windows ,	//handler of our window.
	0, //character to paint line on the left, 0 =│, ord('|') for another
	0, //character to paint line on the right, 0 =│, ord('|') for another
	0, //character to paint line on the top, 0 = ─, ord('-') for another
	0, //character to paint line on the bottom, 0 = ─, ord('-') for another
	0, //character to paint corner top-left 0 = ┌, ord('+') for another
	0, //character to paint corner top-right 0 = ┐, ord('+') for another
	0, //character to paint corner bottom-left 0 = └, ord('+') for another
	0  //character to paint corner bottom.right 0 = ┘, ord('+') for another
); // border it

//now we flush on the screen the window we draw above.
ncurses_wrefresh($my_windows);

//we reset the settings there were before we run the script
ncurses_resetty();
//we close ncurses
ncurses_end();

Copy and paste this script in a file called test.php and run it with the following command:

php test.php

It should look like this:

I hope you find it interesting.

RAID 0 in Raspberry PI with pen drives.

I have a Raspberry PI 3 to do experiments and when I’m not using it it runs Boinc which is a distributed computing software I will talk about another day.

This software makes an intensive use of disk access and I thought of a way to save the SD card for those who use one or as in my case to make less use of the HDD I have plugged by USB, It would be to install that program on a pen drive.

It turns out that I have many pen drives. Some of a few Gigabytes but also, the older ones of some tens of megs and I thought of an experiment to make use of those old pen drives whilst I protect my HDD.

The solution I thought of was to create a RAID 0 with the pen drives.
RAID 0 is a setting for which It’s possible to mount a filesystem in a number of store devices as is they were only one.
There are other configurations as for example to mount two devices in which one is a replica of the other for error prevention.

RAIDs can be hardware in which the operating system only sees a device instead of the bunch of then that compound it, or it can be by software in which the operating system takes care of it and it’s transparent for the user and the applications.

The software I found is called mdadm and it’s very easy to install in the Linux of Raspberry PI:

sudo apt-get install -y mdadm

With the command lsblk we can see the device files of our pen drives.

Now well, let’s suppose that we have two pen drives and their devices are /dev/sdd1 and /dev/sdb1.

We would crate the RAID device with the following command:

sudo mdadm --create /dev/md0 --raid-devices=2 --level=0 /dev/sdd1 /dev/sdb1

Now we need to save the configuration for Linux to remember it next time how to mount the device /dev/md0. We use the command:

sudo mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf

Now we have to “assemble” the new RAID. This internally stores some data about how mdadm has to access the devices. The order and that stuff. Remember it for later.

sudo mdadm -A /dev/md0 -f /dev/sdc1 /dev/sdb1

At this point now we can format the new device /dev/md0 as it was anyother:

sudo mkfs.ext4 /dev/md0

And to mount it. For this example I will use the folder /mnt/raid:

sudo mount /dev/md0 /mnt/raid

And now we can access it as we would with any other device even thought it’s compounded by two.

Now we have a problem. If we restart the computer it won’t mount it anymore. This is because returning to the “assembling” step there is an issue that has to do with mdadm because in previous versions it made that assembly in a way whereas in posterior versions it does it in another way and when Linux tries to reconstruct the RAID it tries in the legacy mode instead on the modern one. So I’m going to explain how to fix this scenario and afterwards I’ll fix it definitely.

First we stop the RAID:

sudo mdadm --stop /dev/md0

Now we put the value 2 inside that file to set the mode.

sudo echo 2 > /sys/module/raid0/parameters/default_layout

and assemble it again RAID

sudo mdadm -A /dev/md0 -f /dev/sdc1 /dev/sdb1

Now we can mount it as before.

As this is unpractical we need the Raspberry Pi to know the mode to re-assemble the RAID.
For this we need to pass some parameters to the kernel on bootstrap.
This is done by editing the file /boot/cmdline.txt and adding in the same line the parameter raid0.default_layout=2. In my case it’s between fsck.repair=yes and rootwait.

With this the Raspberry Pi Linux starts knowing the mode it has to assemble the RAID with.

I hope it’s helpful to you, you’ll tell me in the comments.