htaccess redirect http:// to www and vice versa

    RewriteEngine On
    RewriteBase /

    # Redirect to www
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    #Redirect to http://
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


    Tags: , , , , ,

    Useful vi commands

    Just in case you’re lost at some point.

    “o” = insert mode
    “A” = edit at the end
    “a” = edit where you are
    “shift r” = replace some text
    “yy” “5yy” = copy the lines
    “p” “shift p” = paste below or above the line
    “dd” “10dd” = deletes the line
    “shift h” = go top
    “shift l” or “shift g” = go bottom
    “cw” = replace only 1 word – different than “shift r”
    “/” = search forward | “n” and “shift n” – go to the next search
    “?” = search backward
    “u” = undo
    “:%s/the/katmai” – replace in all the doc
    “:1s/the/katmai” – replace on a line
    “:e filename” – loads a file
    “:r filename” – loads the contents of another file

    Tags: , , ,

    disable and stop firewall on CentOS7

    For the time being the firewall has to be off. I will replace it with csf anyway.

    [root@500748 ~]# systemctl list-unit-files |grep -i firewall
    dbus-org.fedoraproject.FirewallD1.service enabled
    firewalld.service enabled
    [root@500748 ~]# systemctl disable firewalld
    rm ‘/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service’
    rm ‘/etc/systemd/system/’

    [root@500748 ~]# systemctl stop firewalld
    [root@500748 ~]#


    Tags: , , , , ,

    CentOS7 disable ipv6

    For the time being this has to stay off for clarity sake:

    net.ipv6.conf.all.disable_ipv6 = 1
    to /etc/sysctl.conf
    then type: sysctl -p
    Tags: , , , ,

    CentOS7 change hostname

    I started switching recently (i know i should have probably started earlier but meh, was busy) switching boxes to CentOS7. Changing the hostname is slightly different now:

    [root@500748 ~]# hostnamectl status
    Static hostname:
    Icon name: computer-desktop
    Chassis: desktop
    Machine ID: e289f5250bd548609d5989766573ab49
    Boot ID: 844dbb05561c4c599aad84d9f685d0e8
    Operating System: CentOS Linux 7 (Core)
    CPE OS Name: cpe:/o:centos:centos:7
    Kernel: Linux 3.10.0-229.el7.x86_64
    Architecture: x86_64

    So in order to change the hostname you would do:

    hostnamectl set-hostname


    Tags: , , , ,

    cPanel/WHM mass add spf and domainkeys to all accounts

    I am not really just now adding these, i merely ran some cleanups on the zones, removing obsolete ip’s and stuff like that, but i thought to share the script i used to reset the DKIM and SPF records for all accounts:

    #!/bin/bash -x
    for user in `ls -A /var/cpanel/users`;
    /usr/local/cpanel/bin/dkim_keys_install $user && /usr/local/cpanel/bin/spf_installer $user;


    Tags: ,

    Previous value removed by cPanel transfer auto-merge

    So i have been doing a hardware upgrade, and during the migration of the accounts, the target server named zone files got polluted with stuff like this:

    ; 86400 ;refresh ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
    ; 7200 ;retry ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
    ; 3600000 ;expire ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
    ; 86400 ) ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT

    In order to clean things up, you can do something like this:

    1 –  backup your named folder : cd /var;tar czf named.tgz named

    2 – cd /var/named

    perl -i.bak -ne ‘next if (/^; .+ ; Previous value removed by cPanel transfer auto-merge on/); print;’ /var/named/*.db


    Voila! Things should be clean.

    Tags: , , ,

    nano / pico replace text

    Dunno why i haven’t used this earlier. There have been some instances when i had to search and replace some text in nano or pico (i can’t get accustomed to nano, so i always symlink nano to pico lol). Anyway here it goes:

    Press: Ctrl + \

    After that it’s pretty self explanatory:
    Enter your search term [press return]
    Enter your replacement term [press return]

    You can either press Y to see every instance getting replaced, or take the easy route and press A [to replace all instances].

    Enjoy your new found nano / pico skills.

    Tags: , , , , ,

    PostgreSQL – useful stuff

    (Everything below has been done on FreeBSD 10.1 with PostgreSQL 9.3)

    How to connect to the PostgreSQL database:

    su – psql

    pgsql -U pgsql -d template1

    How to list the PostgreSQL databases

    \l #(that is a lowercase L not an i)

    How to add a user and grant permissions to a certain PostgreSQL database:

    psql -U pgsql -d template1

    CREATE USER username WITH PASSWORD ‘password’;


    GRANT ALL PRIVILEGES ON DATABASE dbname to username;

    Remove database and user:

    DROP DATABASE dbname;

    DROP USER username;

    Backup/Dump | Restore a PostgreSQL database:

    dump -> pg_dump -U username dbname -f dump.sql
    restore -> psql -U username -d dbname -f dump.sql
    Tags: , , , , , , ,

    CentOS wifi howto setup


    So here are the instructions for getting the wifi rolling:
    yum -y install wireless-tools wpa_supplicant dbus
    ifconfig wlan0 up
    iwlist wlan0 scan

    record the channel number
    ifconfig wlan0 down
    create /etc/sysconfig/network-scripts/ifcfg-wlan0 with the contents below and the instructions mentioned below:

    UUID=<an-optional-uuid> #generate one with uuidgen
    ESSID=<your-ssid> # you should either know this or take it from the iwlist wlan0 scan
    CHANNEL=<ssid-channel> #the channel you got from when you ran iwlist wlan0 scan
    chkconfig NetworkManager off
    edit /etc/sysconfig/wpa_supplicant and add the wlan name: INTERFACES=”-iwlan0″
    load the encrypted passphrase in the supplicant
    wpa_passphrase <ssid> <passphrase> >> /etc/wpa_supplicant/wpa_supplicant.conf
    chkconfig messagebus on
    chkconfig wpa_supplicant on
    If the wireless is the only active option, edit /etc/sysconfig/network-scripts – the configs for ifcfg-eth0 and 1 and set onboot to no, so that the route goes over wifi.

    Everything should be good to go.

    Tags: , , , ,