DDNS Cloudflare API


Because i move my dns service from Namecheap to Cloudflare, i need to update my dynamic isp ip one of my subdomain in cloudflare with ddns cloudflare api and here some script that i use :

THE SCRIPT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
[ ! -f /var/tmp/current_ip.txt ] && touch /var/tmp/currentip.txt

zone_name="root_domain"
EMAIL="cloudflare_email"
AUTHKEY="cloudflare_api"

DNS1="first_domain"
DNS2="second_domain"

NEWIP=$(curl -s http://ipv4.icanhazip.com)
DOMAINIP1=$(dig "$DNS1" +short | awk '{ print ; exit }')
DOMAINIP2=$(dig "$DNS2" +short | awk '{ print ; exit }')
zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" -H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $AUTHKEY" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 )

dns1_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?name=$DNS1" -H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $AUTHKEY" -H "Content-Type: application/json" | | grep -Po '(?<="id":")[^"]*' | head -1)
dns2_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?name=$DNS2" -H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $AUTHKEY" -H "Content-Type: application/json" | | grep -Po '(?<="id":")[^"]*' | head -1) if [ "$NEWIP" = "$DOMAINIP1" ] then echo "IP address unchanged" else curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$dns1_identifier" \ -H "X-Auth-Email: $EMAIL" \ -H "X-Auth-Key: $AUTHKEY" \ -H "Content-Type: application/json" \ --data "{"id":"$zone_identifier","type":"A","name":"$DNS1","content":"$NEWIP","proxied":true}" echo "$DNS1 IP address changed to $NEWIP from $DOMAINIP1" > /var/tmp/currentip.txt
fi

if [ "$NEWIP" = "$DOMAINIP2" ]
then
echo "IP address unchanged"
else
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$dns2_identifier" \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $AUTHKEY" \
-H "Content-Type: application/json" \
--data "{"id":"$zone_identifier","type":"A","name":"$DNS2","content":"$NEWIP","proxied":true}"
echo "$DNS2 IP address changed to $NEWIP from $DOMAINIP2" >> /var/tmp/currentip.txt
fi

DON’T FORGET

don’t forget to set chmod +x to the file
add it to crontab

OpenWRT + Dnscrypt On TP-Link WDR3600

Because my ISP using a dns transparent, some website are blocked, to fix this problem im using a dnscrypt in my computer, but it is annoying, because i have to start dnscrypt and it use more resource on my computer, so i have to find a way to make dnscrypt to run on my router, after searching on google, theres a way to run dnscrypt on my tplink router with opwnrt firmware, and today i’m trying to flash my TP-Link WDR-3600 wireless router to OpenWRT and setup dncsrypt to run on it

Here’s the step i take

  1. Download the openwrt firmware for wdr 3600 ini here and find openwrt-15.05-ar71xx-generic-tl-wdr3600-v1-squashfs-factory.bin
  2. Rename it so the filename is not too long
  3. Login to router and do factory reset
  4. Go to upgrade firmware, select the file that already downloaded, and then upgrade
  5. It will take a while, after finish, refresh your network and then login to router using this address http://192.168.1.1
  6. Dont forget to change the password, in default theres no password
  7. Done flashing to openwrt
  8. Let’s install dnscrypt
  9. Go to System>Software
  10. Find dnscrypt, if theres no dnscrypt package, update the page first
  11. After dnscrypt installed Login to the router using ssh
  12. Edit
    1
    /etc/config/dnscrypt-proxy using vi or other editor
  13. 1
    2
    3
    4
    5
    6
    config dnscrypt-proxy
    option address '127.0.0.1'
    option port '5353'
    # option resolver 'cisco'
    # option resolvers_list '/usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv'
    # option ephemeral_keys '1'
  14. edit the config as necesary
  15. Go to System>Startup
  16. put this code before exit 0
  17. 1
    2
    3
    /etc/init.d/dnscrypt-proxy enable
    sleep 10
    /etc/init.d/dnscrypt-proxy start
  18. Using ssh again and edit
    1
    /etc/config/dhcp
  19. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    config dnsmasq
    option domainneeded 1
    option boguspriv 1
    option filterwin2k 0
    option localise_queries 1
    option rebind_protection 1
    option rebind_localhost 1
    option local '/lan/'
    option domain 'lan'
    option expandhosts 1
    option nonegcache 0
    option authoritative 1
    option readethers 1
    option leasefile '/tmp/dhcp.leases'
    # option resolvfile '/tmp/resolv.conf.auto'
    option noresolv 1
    list server '127.0.0.1#5353'
    list server '/pool.ntp.org/208.67.222.222'
  20. Restart your router or restart the dnsmasq using /etc/init.d/dnsmasq restart
  21. Done and Good Luck!

Install And Change Apache2 And MySQL Default Directory In Ubuntu 12.04

get the Apache2, PHP5 and MySQL

1
2
3
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install mysql-server

to move your default directory for your site in apache2 make directory where your new site will be stored, for this example i’ll use /home/www/

1
mdkir /home/www/

then set the permission

1
chown -R www-data:www-data /home/www

edit default file in /etc/apache2/sites-available/ to be like this, change the DocumentRoot and Directory to the new directory that you want, in this case im using /home/www

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /home/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

restart the apache2

1
sudo service apache2 restart

done!

to change MySQL default data directory to new one, here’s the step

first stop the MySQL Service

1
sudo service mysql stop

make new directory to store your new data, in this example i’ll use /home/mysql

1
sudo mkdir /home/mysql

copy your mysql data from the old one to the new one

1
sudo cp -R /var/lib/mysql/* /home/mysql/

set the permission

1
sudo chown -R mysql:mysql /home/mysql

edit my.cnf file in /etc/mysql , just edit the data location from

1
datadir = /var/lib/mysql

to

1
datadir = /home/mysql

then edit /etc/apparmor.d/usr.sbin.mysqld

1
sudo gedit /etc/apparmor.d/usr.sbin.mysqld

change

1
2
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,

to

1
2
/home/mysql/ r,
/home/mysql/** rwk,

Reload apparmor

1
sudo /etc/init.d/apparmor reload

Then start mysql

1
sudo service mysql start

Good Luck!!