[bash] Export wordpress posts as pdf without plugin

Install wkhtmltopdf:

apt-get install wkhtmltopdf

From phpmyadmin, export permalinks as CSV, use this SQL query:

SELECT `post_name` FROM `wp_posts` WHERE `post_type` = 'post' AND `post_status` = 'publish';

Copy the script, change filename, wp base url and output directory:

#!/bin/bash

# Input file
filename='wp_posts.csv'

# Wordpress base url
wp='http://blog.chemel.fr/'

# Ouput dir
directory='./dump/'

mkdir -p $directory

while IFS=$'\n\r' read -r permalink
do
    if [ ! -f $directory$permalink.pdf ]; then

        echo $wp$permalink

        wkhtmltopdf $wp$permalink $directory$permalink.pdf
    fi
done < "$filename"

Set permission and execute:

chmod +x wordpress2pdf.sh

./wordpress2pdf.sh

Done.

If you don’t have access to the mysql database you can crawl the sitemap.xml. See this script: https://github.com/chemel/blog2pdf

[debian] Howto install mini DLNA server

minidlna is a lightware DLNA server allow to stream media files (musics, pictures, and videos) on your Smart TV or Smartphone on a network.

Let’s start:

Install the server with apt:

apt-get install minidlna

Edit config file:

nano /etc/minidlna.conf
# set your media dir
media_dir=A,/home/alexis/musics
media_dir=P,/home/alexis/pictures
media_dir=V,/home/alexis/videos

# uncomment log_dir if you want
log_dir=/var/log

# uncomment max_connections
max_connections=50

Open UDP port 1900 and TCP port 8200 in your firewall, for iptables add the following rules:

iptables -A INPUT -i eth0 -p udp --dport 1900 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 8200 -j ACCEPT

Restart the server:

service minidlna restart

Job done!

Note: to regenerate minidlna’s database type:

minidlnad -R

Note2: to view MiniDLNA status open http://127.0.0.1:8200/ in your browser

Note3: Working great on Samsung Smart TV

[debian] Installation d’un DNS menteur avec bind9 rpz

Install the server with apt:

apt-get install bind9

Edit config file:

nano /etc/bind/named.conf.options

Add response-policy directive with your zone:

response-policy { zone "loppsi.gouv.fr"; };

Edit config file:

nano /etc/bind/named.conf.local

Create your zone:

zone "loppsi.gouv.fr" {
      type master;
      file "/etc/bind/db.loppsi.gouv.fr";
      allow-query {none;};
};

Create config file:

nano /etc/bind/db.loppsi.gouv.fr

Add your rules:

; Beginning of the zone, some mandatory values
$TTL 1H

@   SOA gueant.interieur.gouv.fr. root.elysee.fr (2011031800 2h 30m 30d 1h)
    NS gueant.interieur.gouv.fr.

; Filtering rules
; NXDOMAIN will be sent back
google-analytics.com         CNAME   .
*.google-analytics.com         CNAME   .

; NOERROR, ANSWER=0 will be sent back
enlarge-your-penis.biz           CNAME   *.
*.enlarge-your-penis.biz         CNAME   *.

; Replace the address by ours
; Since we provide only a AAAA, A queries will get NOERROR,ANSWER=0
ads.example.net             AAAA 2001:db8::1

Restart the server:

service bind9 restart

Testing with dig:

# Simple with default dns
dig google-analytics.com

# Choose DNS server
dig @192.168.1.1 google-analytics.com

# Choose DNS server and port
dig @127.0.0.1 -p 9053 google-analytics.com

Source : http://www.bortzmeyer.org/rpz-faire-mentir-resolveur-dns.html

[debian] How to install and configure ISC DHCP Server

Install the server with apt

apt-get install isc-dhcp-server

Edit config file

nano /etc/default/isc-dhcp-server

Add your network interface, default eth0

INTERFACES="eth0"

Edit dhcpd config file

nano /etc/dhcp/dhcpd.conf

Uncomment

authoritative;

And add at the end of file

subnet 192.168.1.0 netmask 255.255.255.0 { # IP and Netmask
  option routers 192.168.1.1; # Gateway
  option domain-name-servers 8.8.8.8; # DNS
  pool {
    range 192.168.1.2 192.168.1.245; # IP Range
  }
}

Restart the server

service isc-dhcp-server restart

Static address reservation

subnet 192.168.1.0 netmask 255.255.255.0 { # IP and Netmask
  option routers 192.168.1.1; # Gateway
  option domain-name-servers 8.8.8.8; # DNS
  pool {
    range 192.168.1.3 192.168.1.245; # IP Range
  }
  host printer {
    hardware ethernet CA-FC-EB-91-D6-31;
    fixed-address 192.168.1.2;
  }
}

Logging: redirect syslog to dhcpd.log

Edit dhcpd.conf

nano /etc/dhcp/dhcpd.conf

Verify

log-facility local7;

Edit rsyslog default.conf

nano /etc/rsyslog.d/50-default.conf

Change “*.*;auth,authpriv.none -/var/log/syslog” to

*.*;auth,authpriv.none,local7.none  -/var/log/syslog

Add following line

local7.*    /var/log/dhcpd.log

Touch dhcpd.log and change owner

touch /var/log/dhcpd.log
chown syslog:adm /var/log/dhcpd.log

Restart syslog and isc-dhcp-server

service syslog restart
service isc-dhcp-server restart

[linux] Create virtual machine from physical disk

Convert directly:

VBoxManage convertfromraw /dev/sda sda.vdi --format vdi

Or Create raw image backup and convert it:

dd if=/dev/sda of=/storage/sda.raw

VBoxManage convertfromraw sda.raw sda.vdi --format vdi

To list all devices, run:

lsblk