16 de enero de 2021

Pi-Hole Upgrade

 When you see in your Pi-Hole admin web:

is time to update your Pi-Hole software.

Protocol:

# pihole -up

  [i] Checking for updates...
  [i] Pi-hole Core:    update available
  [i] Web Interface:    update available
  [i] FTL:        update available

  [i] Pi-hole core files out of date, updating local repo.
  [✓] Check for existing repository in /etc/.pihole
  [i] Update repo in /etc/.pihole...HEAD is now at cbc3fbdf Merge pull request #3989 from pi-hole/release/v5.2.3
  [✓] Update repo in /etc/.pihole

  [i] If you had made any changes in '/etc/.pihole/', they have been stashed using 'git stash'

  [i] Pi-hole Web Admin files out of date, updating local repo.
  [✓] Check for existing repository in /var/www/html/admin
  [i] Update repo in /var/www/html/admin...HEAD is now at 3ff33a3d Merge pull request #1704 from pi-hole/release/v5.3
  [✓] Update repo in /var/www/html/admin

  [i] If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'

  [i] FTL out of date, it will be updated by the installer.

  [✓] Root user check

        .;;,.
        .ccccc:,.
         :cccclll:.      ..,,
          :ccccclll.   ;ooodc
           'ccll:;ll .oooodc
             .;cll.;;looo:.
                 .. ','.
                .',,,,,,'.
              .',,,,,,,,,,.
            .',,,,,,,,,,,,....
          ....''',,,,,,,'.......
        .........  ....  .........
        ..........      ..........
        ..........      ..........
        .........  ....  .........
          ........,,,,,,,'......
            ....',,,,,,,,,,,,.
               .',,,,,,,,,'.
                .',,,,,,'.
                  ..'''.

  [i] Update local cache of available packages...

...
...
...

  [i] The install log is located at: /etc/pihole/install.log
Update Complete!

  Current Pi-hole version is v5.2.3.
  Current AdminLTE version is v5.3.
  Current FTL version is v5.4.


... only have to wait, Pi-Hole makes everithing fo you.

And finally think about contribute PiHole, a really amaizing tool.


Ref.:

https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249



PiHole databases and SQLite

The PiHole data databases are make and
managed by SQLite.

PiHole databases files are located in /etc/pihole:

$ ls -f /etc/pihole
.
..
list.5.s3.amazonaws.com.domains
black.list
list.2.mirror1.malwaredomains.com.domains
GitHubVersions
local.list
migration_backup
gravity.db
list.1.raw.githubusercontent.com.domains
custom.list
logrotate
dns-servers.conf
list.3.sysctl.org.domains
list.4.zeustracker.abuse.ch.domains
setupVars.conf.update.bak
install.log
gravity.list
macvendor.db
setupVars.conf
pihole-FTL.conf
list.6.s3.amazonaws.com.domains
localbranches
localversions
adlists.list
pihole-FTL.db
dhcp.leases

Databases are available from SQLite3 commands in bash console or SQLliteBrowser.

SQL code to get the know MACs order by recent DNS queries in PiHole from /etc/pihole/pihole-FTL.db:

SELECT hwaddr , strftime('%Y-%m-%d %H:%M:%S', lastQuery, 'unixepoch') AS date FROM `network` ORDER BY lastQuery DESC;

"hwaddr" "date"
"xx:xx:xx:xx:xx:xx"    "2021-01-16 18:26:58"
"xx:xx:xx:xx:xx:xx"    "2021-01-16 18:26:28"
"xx:xx:xx:xx:xx:xx"    "2021-01-16 18:23:35"
"xx:xx:xx:xx:xx:xx"    "2021-01-16 18:26:58"
"xx:xx:xx:xx:xx:xx"    "2021-01-16 18:26:28"
"xx:xx:xx:xx:xx:xx"    "2021-01-16 18:23:35"
 ...

 It is good source of data for monitoring the net.

 

Search queries by domain name:

sqlite> .open pihole-FTL.db

sqlite> select * from queries where domain like "%KeyWord%" limit 50;

 .

 

 


14 de enero de 2021

RPI4: poner un boton de apagado en el GPIO

En los equipos RPi sin teclado, ni pantalla, apargarlos de forma correcta es laborioso ya que hay que acceder vía remota y ejecutar

# shutdown -h now

Una buena solucción es poner un botón en el GPIO y hacer que se ejecute el comando de apagado al pulsarlo.

Este tutorial me ha funcionado:

https://core-electronics.com.au/tutorials/how-to-make-a-safe-shutdown-button-for-raspberry-pi.html

 

 

9 de enero de 2021

YouTube Video downloader command line tool for Linux


Useful and complete commandline tool for download videos of youtube:

https://youtube-dl.org/

Update the latest version to avoid download errors.

 

Use:

$ youtube-dl --help

    To see all youtube options

$ youtube-dl --list-formats [youtube video url]

[info] Available formats for [youtube video url]:
format code  extension  resolution note
249          webm       audio only tiny   59k , opus @ 50k (48000Hz), 43.30MiB
250          webm       audio only tiny   75k , opus @ 70k (48000Hz), 57.18MiB
140          m4a        audio only tiny  137k , m4a_dash container, mp4a.40.2@128k (44100Hz), 111.75MiB
251          webm       audio only tiny  145k , opus @160k (48000Hz), 116.17MiB
278          webm       256x144    144p  132k , webm container, vp9, 25fps, video only, 72.24MiB
160          mp4        256x144    144p  141k , avc1.4d400c, 25fps, video only, 95.43MiB
242          webm       426x240    240p  229k , vp9, 25fps, video only, 163.18MiB
133          mp4        426x240    240p  275k , avc1.4d4015, 25fps, video only, 211.09MiB
243          webm       640x360    360p  443k , vp9, 25fps, video only, 350.08MiB
134          mp4        640x360    360p  563k , avc1.4d401e, 25fps, video only, 465.65MiB
244          webm       854x480    480p  761k , vp9, 25fps, video only, 628.15MiB
135          mp4        854x480    480p  819k , avc1.4d401e, 25fps, video only, 685.90MiB
247          webm       1280x720   720p 1518k , vp9, 25fps, video only, 1.25GiB
136          mp4        1280x720   720p 2206k , avc1.4d401f, 25fps, video only, 1.80GiB
18           mp4        640x360    360p  738k , avc1.42001E, 25fps, mp4a.40.2@ 96k (44100Hz), 637.51MiB
22           mp4        1280x720   720p 2268k , avc1.64001F, 25fps, mp4a.40.2@192k (44100Hz) (best)

... (select the download format and indicate it in -f option):

$ youtube-dl -f 22 [youtube video url]

...


6 de enero de 2021

RPi GPIO imprimible

Para trabajar con el GPIO del RPi hay que saber que es cada pin.

Una buena opción es imprimir una plantilla a tamaño real y ponerla sobre el GPIO del RPi.

Hay muchos modelos en internet, uno es este:

https://mikaelleven.files.wordpress.com/2015/11/rpi_b_gpio_card_mikael-leven.pdf

Conectar y programar una Pantalla LCD 20x4 en RPi4 con Python

Protocolo:

1) Activar I2C en RPi4

    $ sudo raspi-config

        3- Interface Options

        P5 I2C Enable/disable automatic loading of I2C Kernel Module

        Yes

 

2) Conectar el LCD +I2C al Gpio del RPi:

    I2C        Gpio RPi

    VCC    -    3.3V

    GND   -    GND

    SDA    -    #2 SDA

    SCL     -    #3 SCL

 

3) Instalar I2C-Tools y SMBUS:

    # aptitude install i2c-tools python3-smbus

 

4) Detectar el I2C

    $ sudo i2cdetect -y 1

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --   

Vemos que en mi caso el I2C este en la dirección 27, esto lo utilizaremos en el siguiente paso.

 

 5) Descargar Librerías

Descargar las librerías lcd_display.py e i2c_lib.py de la dirección: https://github.com/paulbarber/raspi-gpio

 

    $ wget https://raw.githubusercontent.com/paulbarber/raspi-gpio/master/i2c_lib.py

    $ wget https://raw.githubusercontent.com/paulbarber/raspi-gpio/master/lcd_display.py


6) Modificar la librería lcd_display.py:

Modificación 1:

    $ nano  lcd_display.py

        ...
        # LCD Address
        ADDRESS = 0x27 <--- Modificar esto poniendo la direccion I2C

        ...

Modificación 2:

Para utilizar un display de 20×4 es necesario hacer algunas modificaciones adicionales,

Buscar las líneas (sobre la linea 90):

    """display a string on the given line of the display, 1 or 2, string is truncated to 16 chars and centred"""
    centered_string = string.center(16)
    if line == 1:
      self.write(0x80)
    if line == 2:
      self.write(0xC0)


y cambiarlas por:

    """display a string on the given line of the display, 1 or 2, string is truncated to 16 chars and centred"""
    centered_string = string.center(20)
    if line == 1:
      self.write(0x80)
    if line == 2:
      self.write(0xC0)
    if line == 3:
      self.write(0x94)
    if line == 4:
      self.write(0xD4)

Con esto se ha adaptado para un display con 20 caracteres horizontales y 4 líneas.

 

7) Probar el lcd: Script en python3:

#!/usr/bin/python3
from lcd_display import lcd
from time import sleep

lcd = lcd()

t = 0.4

while True:
    lcd.display_string("Hello World Display",1)
    sleep(t)
    lcd.display_string("Hello World Display",2)
    sleep(t)
    lcd.display_string("Hello World Display",3)
    sleep(t)
    lcd.display_string("Hello World Display",4)
    sleep(t)
    lcd.clear()
    sleep(t)

 

Bibliografía:

https://openhardware.pe/contactando-un-display-lcd-de-20x4-a-rasperrt-pi-mediante-i2c-i2c-iii/


Update:

La librería para programar el LCD es muy limitada. Hay otra mas completa en:

https://pypi.org/project/RPLCD/

https://rplcd.readthedocs.io/en/stable/usage.html#writing-to-display

RPi4 System monitoring with python3 in lcd display 20x4

Python3 script:

#!/usr/bin/python3

#Librerias
from time import sleep
from lcd_display import lcd
from gpiozero import CPUTemperature

import psutil

lcd = lcd()

temp1 = str(CPUTemperature())
temp2 = temp1.split("=")     
temp3 = "CPU.temp: "+temp2[1][:-1] + " C"

cpu1 = "CPU.load: " + str(psutil.cpu_percent()) + " %"
ram1 = "RAM.use: " + str(psutil.virtual_memory().percent) + " %"


while True:
    #print ("temp:",temp3)
    #print ("cpu: ", cpu1)
    #print ("ram: ", ram1)
    #print ("------------------")
    lcd.clear()
    sleep(0.3)
    lcd.display_string("--- RPi4.monitor ---",1)
    lcd.display_string(temp3,2)
    lcd.display_string(cpu1,3)
    lcd.display_string(ram1,4)
    sleep(15)

  

Bibliografía:

https://raspberrypi.stackexchange.com/questions/85415/how-to-directly-get-cpu-temp-in-python

https://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python

2 de diciembre de 2020

Instalar DNIe en Linux Mint 20 Ulyana

Para poder rusar el DNI electrónico en Linux necesitas un lector de tarjetas y el DNIe activado.

1) Descargar software oficial de la web de la policía.

https://www.dnielectronico.es/PortalDNIe/PRF1_Cons02.action?pag=REF_1112

2) Instalar el software en Linux Mint.

3) Conectar el lector de tarjetas a un puerto usb.

4) Comprobar que reconoce el lector:     

    # lsusb

5) Instala paquetes para interpretar el chip del DNIe con el lector) y herramientas para el manejo del lector:

        # aptitude install  pcscd pcsc-tools

6) Poner el DNIe en el lector y comprobar que lo reconoce:

        # pcsc_scan

7) Instalar la libreria de soporte para tarjetas opensc-pkcs11:

        # aptitude install opensc-pkcs11

8) localizar la ruta del archivo: opensc-pkcs11.so en el directorio pkcs11:

        # updatedb

        # locate opensc-pkcs11.so

            /usr/lib/x86_64-linux-gnu/onepin-opensc-pkcs11.so
            /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so
            /usr/lib/x86_64-linux-gnu/pkcs11/onepin-opensc-pkcs11.so
     --->   /usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so

 9) Abrir Firefox:

            Preferencias/Privacidad &Seguridad/Dispositivos de seguridad/Cargar
            Ponle un nombre representativo (DNIe)
            Pega la ruta (/usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so)     
            [ Aceptar ]
 
     Aparecerá el nuevo dispositivo que has creado en la lista de la izquierda.

 10) Descargar el certificado pkcs1-sha256WithRSAEncryption de la pagina oficial del DNIe:

https://www.dnielectronico.es/PortalDNIe/PRF1_Cons02.action?pag=REF_077 

 
11) Guarda el archivo .ZIP y des-comprímelo
 
12) En Firefox:
        Preferencias/Privacidad &Seguridad/Certificados/Importar
 
        Carga el archivo CRT que has descomprimido.
        Tras importar el certificado, acepta las dos casillas.
 
13)Reinicia Firefox con el lector de DNIe conectado
 
14)  Accede a la FNMT para verificar el funcionamiento del certificado:
 

Ref.:

https://lasegundapuerta.com/index.php/informatica/linux-y-software-libre/2422-instalar-dni-e-dni-electronico-en-ubuntu-18-04-y-20-04

 

7 de junio de 2020

Linux Mint 19.3 Tricia y Window10 con UEFI dual boot

Los sistemas de arranque con UEFI en general me han dado problemas de configuración.

Como norma es mejor instalar primero Windows10 y después el sistema linux ya este ultimo suele reconocer los sistemas previos instalados y configura grub2 para multi-boot system.

Pero esto no es siempre así !!!, especialmente con sistemas UEFI de arranque.



Protocolo:

0) Acceder a la BIOS del ordenados y activar el sistema de arranque EFI.


1) Con un USB de rescate Instalar Win10

2) Arrancar equipo con Usb-Live Linux Mint 19.3

3) En el espacio libre dejado por Win10 hacer una partición con gparted


4) Instalar Linux Mint en la partición creada para ello.

7) Queda un espacio al final del disco duro para Datos: crearemos aquí una partición desde Win10 para que sea NTFS y lo reconozcan los dos sistemas.



Así es como han quedado las particiones en mi sistema.


8) Para acceder a la partición de datos NTFS desde linux hay que desactivar el Inicio rápido de Win10.





27 de abril de 2020

Netflix en RPi3 con Raspbian Buster

Al intentar ver Netflix en mi RPI3 con Raspbian Buster esto es lo que NO me ha funcionado:

   - firefox-esr
   - instalar ultima versión de firefox con snap
   - Ad-on de Netflix en Kodi ...

Después de probar varias cosas ... finalmente esta es la que me ha funcionado con el navegador Chromium v78 instalado por defecto en RPI3 con raspbian:

lsb_release -a
No LSB modules are available.
Distributor ID:    Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:    buster



- Instalar widevine: (permite ver contenido DRM)
    - descargar
    - descomprimir
    - instalar
    - copiar al dir de chromiun ...

- Cambiar el user gent por uno de Chrome de la version 78.
   (sin este paso no funcionaba)


Aquí se describe todo el proceso:
https://raspberryparanovatos.com/tutoriales/drm-navegador-raspberry-pi/