Monday, April 7, 2014

Error: /usr/lib/php5/20090626/idn.so

full error: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/idn.so' - /usr/lib/php5/20090626/idn.so: cannot open shared object file: No such file or directory in Unknown on line 0


fix: sudo bzip2 /etc/php5/conf.d/idn.ini

Reference: ubuntuforums.org

Check log mail

how to check logmail

1. grep “tom@anydomain.tld” /var/log/mail.log
2. tail -f /var/log/mail.log |grep "@gmail.com"
3. tail -n 100 /var/log/mail.log



Sunday, April 6, 2014

how to migrate user account linux

copy from  website howto-move-migrate-user-accounts-old-to-new-server

Q. How do I Move or migrate user accounts to from old Linux server a new Cent OS Linux server including mails? This new system a fresh installation.
A. You can migrate users from old Linux server to new Linux sever with standard commands such as tar, awk, scp and others. This is also useful if you are using old Linux distribution such as Redhat 9 or Debian 2.x.
Following files/dirs are required for traditional Linux user management:
* /etc/passwd - contains various pieces of information for each user account
* /etc/shadow - contains the encrypted password information for user's accounts and optional the password aging information.

* /etc/group - defines the groups to which users belong
* /etc/gshadow - group shadow file (contains the encrypted password for group)
* /var/spool/mail - Generally user emails are stored here.
* /home - All Users data is stored here.
You need to backup all of the above files and directories from old server to new Linux server.

Commands to type on old Linux system

First create a tar ball of old uses (old Linux system). Create a directory:
# mkdir /root/move/
Setup UID filter limit:
# export UGIDLIMIT=500
Now copy /etc/passwd accounts to /root/move/passwd.mig using awk to filter out system account (i.e. only copy user accounts)
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
Copy /etc/group file:
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
Copy /etc/shadow file:
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig
Copy /etc/gshadow (rarely used):
# cp /etc/gshadow /root/move/gshadow.mig
Make a backup of /home and /var/spool/mail dirs:
# tar -zcvpf /root/move/home.tar.gz /home
# tar -zcvpf /root/move/mail.tar.gz /var/spool/mail
Where,
  • Users that are added to the Linux system always start with UID and GID values of as specified by Linux distribution or set by admin. Limits according to different Linux distro:
    • RHEL/CentOS/Fedora Core : Default is 500 and upper limit is 65534 (/etc/libuser.conf).
    • Debian and Ubuntu Linux : Default is 1000 and upper limit is 29999 (/etc/adduser.conf).
  • You should never ever create any new system user accounts on the newly installed Cent OS Linux. So above awk command filter out UID according to Linux distro.
  • export UGIDLIMIT=500 - setup UID start limit for normal user account. Set this value as per your Linux distro.
  • awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig - You need to pass UGIDLIMIT variable to awk using -v option (it assigns value of shell variable UGIDLIMIT to awk program variable LIMIT). Option -F: sets the field separator to : . Finally awk read each line from /etc/passwd, filter out system accounts and generates new file /root/move/passwd.mig. Same logic is applies to rest of awk command.
  • tar -zcvpf /root/move/home.tar.gz /home - Make a backup of users /home dir
  • tar -zcvpf /root/move/mail.tar.gz /var/spool/mail - Make a backup of users mail dir
Use scp or usb pen or tape to copy /root/move to a new Linux system.
# scp -r /root/move/* user@new.linuxserver.com:/path/to/location

Commands to type on new Linux system

First, make a backup of current users and passwords:
# mkdir /root/newsusers.bak
# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak

Now restore passwd and other files in /etc/
# cd /path/to/location
# cat passwd.mig >> /etc/passwd
# cat group.mig >> /etc/group
# cat shadow.mig >> /etc/shadow
# /bin/cp gshadow.mig /etc/gshadow
Please note that you must use >> (append) and not > (create) shell redirection.
Now copy and extract home.tar.gz to new server /home
# cd /
# tar -zxvf /path/to/location/home.tar.gz
Now copy and extract mail.tar.gz (Mails) to new server /var/spool/mail
# cd /
# tar -zxvf /path/to/location/mail.tar.gz
Now reboot system; when the Linux comes back, your user accounts will work as they did before on old system:
# reboot
Please note that if you are new to Linux perform above commands in a sandbox environment. Above technique can be used to UNIX to UNIX OR UNIX to Linux account migration. You need to make couple of changes but overall the concept remains the same.

Further readings

  • Read man pages of awk, passwd(5), shadow(5), group(5), tar command
Updated for accuracy.

Root Alert

Script alert root login on shell.

1. edit file .bashrc
#vim /root/.bashrc
--------------------------------------Start-----------------------------------------------
Type: 1
echo 'ALERT - Root Shell Access (mail.mydomain.co.th) on:' `date` `who` | mail -s "Alert: Root Access to MAIL server mycompany from `who | cut -d"(" -f2 | cut -d")" -f1`" email@domain.co.th

Type: 2

sh /root/checklogin/.shell-login.sh | mail -s "Alert Root Access to Server from: `who | cut -d"(" -f2 | cut -d")" -f1`" email@domain.co.th

Type:3 [send pass SMPT, By sender]
sh /root/checklogin/.shell-login.sh | mail -S smtp:192.168.0.xx:25 -s "Alert Root Access to Server from: `who | cut -d"(" -f2 | cut -d")" -f1`" -r sender@domain.co.th -v receive@domain.co.th

---------------------------------------End-----------------------------------------------

2. create file on /root/.shell-login.sh
-----------------------------/root/.shell-login.sh-------------------------------------------
#!/bin/bash

echo "Login on: $(hostname) (at) $(date)"
echo "Change user to: "$(whoami)
echo
w -i

------------------------------End------------------------------------------------------

Wednesday, April 2, 2014

add change passwd plugin roundcubemail

#aptitude install sudo
#change /etc/sudoes

www-data ALL=NOPASSWD: /usr/sbin/chpasswd



Reading


Monday, March 31, 2014

ERROR: Wrong 'suhosin.session.encrypt' option value and it wasn't possible to set it to required value ()

how to troubleshooting config roundcubemail v.0.9


Edit file php.ini and add this line bottom file

#vim /etc/php5/apache2/php.ini

For Err: date.timezone:  NOT OK(not set)
----------------------Edit-----------------------------
date.timezone = "Asia/Bangkok"


---------------Adding Bottom line--------
suhosin.session.encrypt = 0


For Err: Intl:  NOT AVAILABLE (See http://www.php.net/manual/en/book.intl.php)

Just install intl package
#aptitude install php5-intl
#/etc/init.d/apache2 restart

Wednesday, March 26, 2014

unknown option '$TTL' and unexpected token near end of file

วิธีแก้ไข Err. bind(DNS) ใน Debain
- unknown option '$TTL'
- unexpected token near end of file

คำสั่งตรวจสอบค่าคอนฟิก ที่ Zone file ที่มีปัญหา
1. named-checkconf db.domain.co.th
-----------------------------------
#db.domain.co.th:1: unknown option '$TTL'
#db.domain.co.th:47: unexpected token near end of file
//---------------------------------------

2. named-checkzone domain.co.th /var/named/db.domain.co.th
--------------------------------------
zone domain.co.th/IN: NS 'hostxxx.domain.co.th' has no address records (A or AAAA)
zone domain.co.th/IN: not loaded due to errors.
//--------------------------------------

How to fix BIND does not permit underscores "_" unless you specificy the whole domain name

# named-checkzone abc.com. /var/named/abc.com.hosts 
/var/named/abc.com.hosts:60: express_www1.abc.com: bad owner name (check-names)
/var/named/abc.com.hosts:61: express_www2.abc.com: bad owner name (check-names)
zone abc.com/IN: loaded serial 2020122401
OK

Add this to the option []
------
vim /etc/named.conf
options {
        listen-on port 53 { any; };
        listen-on-v6 port 53 { any; };
.
.
         check-names master ignore;
         check-names slave ignore;
         check-names response ignore;
};

# systemctl restart named
# systemctl status named
# named-checkzone abc.com. /var/named/abc.com.hosts   -> recheck if show bad owner name (check-names) but it is OK!

ref:

คำสั่งปฏิบัติการ
1. rndc flush
2. rndc reload
3. เข้าไปแก้ไข Serail Number ที่ Zone File นั้นก่อน restart service DNS
4. /etc/init.d/bind9 reload  (Restart service DNS)


ตัวอย่าง การแก้ไข

root@sip40:/etc/bind# rndc flush
root@sip40:/etc/bind# rndc reload
server reload successful
root@sip40:/etc/bind# named-checkzone domain.co.th db.domain.co.th
zone domain.co.th/IN: NS 'hqbackup01.domain.co.th' has no address records (A or AAAA)   ** แสดงโดเมนที่ไม่สามารถโหลดได้ เราต้องเข้าไปแก้ไขตรวจสอบดูว่า ยังใช้งานอยู่ไหม
zone domain.co.th/IN: not loaded due to errors.

root@sip40:/etc/bind# vim db.domain.co.th ** เข้าไปแก้ไข และปรับค่า Serial ใหม่
root@sip40:/etc/bind# /etc/init.d/bind9 reload
Reloading domain name service...: bind9.
root@sip40:/etc/bind# named-checkzone domain.co.th db.domain.co.th
zone domain.co.th/IN: loaded serial 2014032701
OK
//--------------------------------------------------------------

แล้วกลับไปตรวจสอบอีกครั้ง

1. named-checkconf db.domain.co.th
-----------------------------------
#db.domain.co.th:1: unknown option '$TTL'
#db.domain.co.th:47: unexpected token near end of file
//---------------------------------------
**** ยังเจอ err. อยู่เหมือนเดิม แต่เมื่อลองไป nslookup จากเครื่องอื่น กลับสามารถ solve domain ได้ ถือว่า ok

2. named-checkzone domain.co.th db.domain.co.th
-----------------------------------
zone domain.co.th/IN: loaded serial 2014032701
OK
 //--------------------------------
*** ใช้งานได้แล้ว

Reference:

rndc flush & rndc reload
Command Check DNS


Monday, March 24, 2014

Upgrade debian 6.x to 7.x

Reading .... how to upgrade debian 6.x to 7.x

Friday, March 21, 2014

Script Convert Ms outlook.psd to Thunderbird

to convert read link below

Convert

http://www.howtoforge.com/convert_outlook_pst_files_to_thunderbird_and_evolution_on_linux

Tuesday, March 18, 2014

zimbra whitelist

Add zimbra whitelist

Reference: wiki.zimbra.com


PLEASE NOTE:
WHITELISTING SPECIFIC IP ADDRESS & HOSTNAME CAN INCREASE SPAM EMAILS IN CASE OF THE CLIENT MACHINE (IP) THAT YOU WHITELIST IS INFECTED BY VIRUS, ALSO IF THE WHITELISTED IP/HOSTNAME IS ALREADY BLACKLISTED, THEN BLACKLIST RULES WILL BE CONSIDERED FIRST.

Workaround1: whitelist specific user/complete domain
Edit the Spamassassin config file "/opt/zimbra/conf/salocal.cf.in" add below lines to the end of the file to whitelist a complete domain or specific user.
whitelist_from *@domain.com 
whitelist_from user@domain.com 
After the above changes restart zmmtactl and zmamaviasdctl services and test the issue.
zmmtactl restart && zmamavisdctl restart
Workaround2: Whitelist IP Addresses/Hostnames while using RBL restrictions
Example:
[zimbra@zcs ~]$ vi /opt/zimbra/conf/postfix_rbl_override
[zimbra@zcs ~]$ cat /opt/zimbra/conf/postfix_rbl_override -> add IP/hostnames you want to   whitelist in this file.
10.137.27.80 OK
10.137.27.88 OK
zcs711.us.zimbralab.com OK
zcs714.us.zimbralab.com OK
[zimbra@zcs ~]$ postmap /opt/zimbra/conf/postfix_rbl_override
[zimbra@zcs ~]$ vi /opt/zimbra/conf/postfix_recipient_restrictions.cf
[zimbra@zcs ~]$ cat /opt/zimbra/conf/postfix_recipient_restrictions.cf
%%contains VAR:zimbraServiceEnabled cbpolicyd, check_policy_service inet:127.0.0.1:10031%%
reject_non_fqdn_recipient
permit_sasl_authenticated
permit_mynetworks
reject_unauth_destination
check_client_access hash:/opt/zimbra/conf/postfix_rbl_override
reject_unlisted_recipient
%%contains VAR:zimbraMtaRestriction reject_invalid_hostname%%
%%contains VAR:zimbraMtaRestriction reject_non_fqdn_hostname%%
%%contains VAR:zimbraMtaRestriction reject_non_fqdn_sender%%
%%contains VAR:zimbraMtaRestriction reject_unknown_client%%
%%contains VAR:zimbraMtaRestriction reject_unknown_hostname%%
%%contains VAR:zimbraMtaRestriction reject_unknown_sender_domain%%
%%explode reject_rbl_client VAR:zimbraMtaRestrictionRBLs%%
%%contains VAR:zimbraMtaRestriction check_policy_service unixrivate/policy%%
permit
[zimbra@zcs ~]$ zmmtactl restart
Rewriting configuration files...done.
postfix/postfix-script: refreshing the Postfix mail system
Stopping saslauthd...done.
Starting saslauthd...done.
[zimbra@zcs ~]$
Workaround3: Whitelist Hostname/IP addresses without restarting any services
[[root@v01 ~]# mkdir /etc/zimbra_custom --> create a directory inside /etc
[root@v01 ~]# chown zimbra:zimbra /etc/zimbra_custom --> change user and group ownership to  zimbra
[root@v01 ~]# ls -ld /etc/zimbra_custom/
drwxr-xr-x 2 zimbra zimbra 4096 Jan 26 18:23 /etc/zimbra_custom/
[root@v01 ~]# su - zimbra --> switch to zimbra 
[zimbra@v01 ~]$ touch /etc/zimbra_custom/test_whitelist --> create a file
[zimbra@v01 ~]$ nano /etc/zimbra_custom/test_whitelist --> ad list of domains or specific user  that you want to whitelist
[zimbra@v01 ~]$ cat /etc/zimbra_custom/test_whitelist
v01.vinay.com OK
10.112.233.180 OK
[zimbra@v01 ~]$ /opt/zimbra/postfix/sbin/postmap /etc/zimbra_custom/test_whitelist --> create a  hash file using zimbra postmap
[zimbra@v01 ~]$ ls -l /etc/zimbra_custom/
total 12
-rw-r----- 1 zimbra zimbra 18 Jan 26 18:24 test_whitelist
-rw-r----- 1 zimbra zimbra 12288 Jan 26 18:24 test_whitelist.db --> .db file will be created
[zimbra@v01 ~]$
[zimbra@v01 ~]$ postconf |grep smtpd_recipient_restrictions --> check the current recipient  restrictions
smtpd_recipient_restrictions = reject_non_fqdn_recipient, permit_sasl_authenticated,   permit_mynetworks, reject_unauth_destination, reject_unlisted_recipient,   reject_invalid_helo_hostname, reject_non_fqdn_sender, permit
[zimbra@v01 ~]$ postconf -e smtpd_recipient_restrictions="reject_non_fqdn_recipient,  permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination,  reject_unlisted_recipient, check_sender_access hash:/etc/zimbra_custom/test_whitelist,  reject_invalid_helo_hostname, reject_non_fqdn_sender, permit" --> add the hash file to current  recipient restrictions
[zimbra@v01 ~]$ postconf |grep smtpd_recipient_restrictionssmtpd_recipient_restrictions =  reject_non_fqdn_recipient, permit_sasl_authenticated, permit_mynetworks,  reject_unauth_destination, reject_unlisted_recipient, check_sender_access  hash:/etc/zimbra_custom/test_whitelist, reject_invalid_helo_hostname, reject_non_fqdn_sender,  permit
[zimbra@v01 ~]$


Note: All 3 workarounds will not survive upgrades, will have to take backup of above changes and redo the same changes after the upgrade.