BIPEDU

my ideas in action

Category Archives: Internet

update PiHole (inside VM on Freenas)

The PiHole need some updates , from time to time, so is best to setup a cron job to do them automatically. The Pihole updates cannot, at this time , be made form Web interface. In my case Pihole runs inside a VM (ubuntu server) , inside Freenas.

So you need to enter the VM shell , inside your Freenas machine. Open Freenas web interface, then go to VMs –> Pihole –> VNC via web .

Then at the new terminal , after login, you need to sudo a crontab:

sudo crontab -e

Then in crontab editor write this :

5 1 * * * pihole -g -up

15 1 * * * pihole -up

This means that at 1:05am every day the pihole list of ad-serving domains is updated. Then at 1:15am the pihole is updated.

If you want to see the pihole status in real time then use

pihole -c

Screenshot from 2018-12-12 09-21-35

 

 

 

 

Advertisements

recover and boot a VM inside Freenas 11

I made recently a VM inside Freenas with Ubuntu and Pi-Hole to get out some advertisements from my network.

All was configured as described here :

 

The main problem that remains is that after a restart of the VM  ( ubuntu) the system does not reboot correctly. I did not entered in details about the boot process of the VM inside Freenas but apparently is an issue with the EFI file location. The longer explanation is given here :

https://forums.freenas.org/index.php?threads/ubuntu-vm-reboots-to-limited-shell.62558/

https://forums.freenas.org/index.php?threads/howto-how-to-boot-linux-vms-using-uefi.54039/

So … how to fix it ?

first you need to open the VNC to the VM machine ( ubuntu in this case). Then you type “exit”  to get from shell to the EFI menu system and navigate to “Boot Maintenance Manager” and then select “Boot from file” to locate and select your grubx64.efi file.

After booting, execute this command as root (use sudo !!):

grub-install –efi-directory=/boot/efi –boot-directory=/boot –removable

then after reboot of the VM you get back the VNC terminal.

If your VM restarted correctly then it is fine.

If not, then you have to copy some files to be sure that the reboot will happen next time also.

More specifically you have to copy the grubx64.efi from /boot/efi/EFI/ubuntu to /boot/efi/EFI/BOOT.

Do this as root (use sudo !!!) :

cp /boot/efi/EFI/ubuntu/grubx4.efi  /boot/efi/EFI/BOOT/grubx64.efi

cp /boot/efi/EFI/ubuntu/grubx4.efi  /boot/efi/EFI/BOOT/BOOTX64.EFI

 

NB: If grubx64.efi gets updated you will need to re-create bootx64.efi.

So if the VM ubuntu make an automatic update of the grub utility then you may get the VM(ubuntu+PiHole) not restarting correctly. If you do not reboot ever the Frenas and VM then you are fine, but if you get regular restarts ( updates or maintenance) then please remember to do all this steps again.

Unfortunately I do not have yet a permanent fix.

 

For making updates to the VM machine ( ubuntu , in my case) it is better to apply only the security patches and for that is better to use

sudo unattended-upgrade

and not the classical apt-get

sudo apt-get update

sudo apt-get upgrade

 

 

 

 

 

use PAC file for automatic proxy selection

I will explain how to use automatic proxy selection for a local network.

For example let’s say that you have a proxy server but that proxy is not available all time. In this case the you need to find each time if the proxy is alive (available) and if yes to use it. If not then browser will select direct connection.

The easiest way to use it is to create a PAC file and to add it in the Firefox as automatic proxy selection.

Go to Preferences–>Advanced –> Network –>Settings and choose “Automatic proxy configuration URL”

Then type there the path to a local PAC file. Normally there should be a web page address but if the file is locals works also ( no web server needed)

FFsettings

To create the PAC file use any text editor and create a file called “autoproxy.pac” and put this content:

function FindProxyForURL(url, host)
{
return “PROXY 192.168.1.29:3128; DIRECT”;
}

The Proxy in this case is on local network at 192.168.1.29 (Squid Proxy on port 3128) and Firefox try to use it first . In case it is not responding it will use direct connection.

You can set there multiple proxy servers. The order is important.

In the example below you can have two proxies. If the first one (192.168.1.29) is not responding then the second one (192.168.1.42) will be selected, and if the second one also do not respond the direct network connection will be used.

function FindProxyForURL(url, host)
{
return “PROXY 192.168.1.29:3128; PROXY 192.168.1.42:3128; DIRECT”;
}

The name of the PAC file is not important ( “autoproxy.pac” is name used by me), any name will do.

More details regarding the PAC file , examples, more advanced functions can be found here : http://findproxyforurl.com/

 

 

 

FTP backup with BASH script ( FTP scripting)

FTP protocol is used to transfer data between computers. The user has also a possibility to combine bash scripts with FTP to automate the backups of the files. This concept can be used for example to backup some files from a local machine to a remote server.
The way to do this is by making an executable script that is run from time to time by a cron job task. In this way the backup is made automatically in the background and do not require user intervention. But there is a problem. if you use FTP in command line then you have to type user name and password in clear text. So how to do it ?
The solution I suggest is like in the example below:

First step is to determine if the backup is needed . We check if the file was changed since last backup. For this we use a compare between the size of the file in this moment with the size of the file at the previous backup time. The previous size was saved in a file. To check this we use the “if compare” structure from BASH:

### check if the file was changed, and if YES then make FTP transfer, if not exit
 if [ `cat ~/.size_myfile.txt` -ne `du -s /path/to/file | cut -f1` ] ; then
 echo 'File changed !'
 fi
 ###########################

Then we define some parameters for FTP command. This definition can be made in a different ( hidden) file. For not critical situations ( home users) I recommend keeping the user details in the same file ( in the script) but to remove all the permissions for the other users ( use chmod command ). So the backup script should look like this:

-rwx------ myuser mygroup 32 june 12 14:52 backupFTP.script

Notice that only the “myuser” user has the right to read/write/execute the file

So for FTP command you need:

##############################
 HOST='ftp.myserver.com'
 USER='myusername'
 PASSWD='mypassword'
 FILE='/path/to/filesource filedestination'
ftp -n $HOST <<END_SCRIPT
 quote USER $USER
 quote PASS $PASSWD
 cd /path/to/destination
 put $FILE
 quit
 END_SCRIPT
 #############################

Since the source path and the destination path may be different you can use “cd /path/to/destination” for the file. The copied file can be also renamed as shown above ( see “filedestination“)

Notice that the commands between “END_SCRIPT” tags are executed inside FTP terminal. This are FTP commands and not BASH/Linux commands. You can put here whatever FTP commands you want based on your needs. For a full list of the FTP commands type “help” in the FTP terminal.

The 3rd step is to recalculate and save the new size of the file so that next time when backup script is run the size file is updated. For this we do:

################################
 ## recalculate the new size of the file, for next backup
 du -s /path/to/file | cut -f1 > ~/.size_myfile.txt
 env DISPLAY=:0 notify-send 'FTP backup done !' 'File : /path/to/file'
 ###############################

Optionally you can show a desktop notification that the backup was made. If you do not have a GUI then do not use it.

Next I show the full script in only one file:

#!/bin/bash
 ### check if the file was changed, and if YES then make FTP transfer, if not exit
 if [ `cat ~/.size_myfile.txt` -ne `du -s /path/to/file | cut -f1` ] ; then
#    echo 'File changed !'
 sleep 1
 #
 HOST='ftp.myserver.com'
 USER='myusername'
 PASSWD='mypassword'
 FILE='/path/to/filesource filedestination'
 ftp -n $HOST <<END_SCRIPT
 quote USER $USER
 quote PASS $PASSWD
 cd /path/to/destination
 put $FILE
 quit
 END_SCRIPT
 sleep 1
 ## recalculate the new size of the file, for next backup
 du -s /path/to/file | cut -f1 > ~/.size_myfile.txt
 env DISPLAY=:0 notify-send 'FTP backup done !' 'File : /path/to/file'
fi
 ###############

Best parodies for Les Miserables

I think that this are the best parodies for “Les Miserables” movie.

make your searches anonymous

You can increase your privacy by using a search engine that do not give your IP address to bad guys, and offer also HPTTS.
But , wait ! Google is the best for search !
So why not combine the privacy with best google service ?

So use https://startpage.com

So first of all this search engine is owned by a European company ( no US jurisdiction) and offer HTTPS connection.
See settings in top right corner.

Also a Firefox plugin is available (HTTP and HTTPS ) so you can search directly from Firefox.