Thứ Ba, 21 tháng 2, 2017

Calculating start and end dates of a week.

"How do I calculate start (monday) and end (sunday) dates from a given week number for a specified year?" Instead of having to come up with your own algorithm you can simply do the following in PHP 5.1 and higher:

<?php
// Monday
echo date(
    datetime::ISO8601,
    strtotime("2006W37"));

// Sunday
echo date(
    datetime::ISO8601,
    strtotime("2006W377"));
?>

The format is " year 'W' weeknr ( daynr )?" where the default daynr is 1 being the Monday of that week. The daynr can be in the range 0 to 7. The weeknr is the ISO week number . Please note that the " year '-W' weeknr ( '-' daynr )?" format is only supported in PHP 5.2 and higher.

Thứ Sáu, 18 tháng 11, 2016

Roundcube: connection to storage server failed

1) If you've recently updated your version of dovecot, and if you get this error in RoundCube:
connection to storage server failed
it may be that the dovecot index files are for an older version of dovecot, and don't work full with the new version.
To resolve that issue, simply delete all dovecot index files, and dovecot will re-create them when it notices they're missing.

You should test this on one User first, before doing it on all Users.
Also, backup the dovecot* files of the test User first (shouldn't be required, but not a bad thing to do)
cd /home
/etc/init.d/dovecot stop
rm -f */imap/*/*/Maildir/dovecot*
rm -f */imap/*/*/Maildir/.*/dovecot*
rm -f */Maildir/dovecot*
rm -f */Maildir/.*/dovecot*
/etc/init.d/dovecot restart
Dovecot will recreate the dovecot* files once the User logs in.




2) Causing number 2 would be if dovecot has hit the per-IP limit.  If that's the case, you'd see something like this in your /var/log/maillog:
imap-login: Maximum number of connections from user+IP exceeded (mail_max_userip_connections=10)
The solution for that is to add the following to the very bottom of your /etc/dovecot/dovecot.conf file:
mail_max_userip_connections = 15
remote 127.0.0.1 {
       mail_max_userip_connections = 40
}
where the "remote 127.0.0.1" refers to the local limit (connections from roundcube and squirrelmail), and the limit of 15, just above it, is the per-IP limit for external IP addresses.  There are a couple other ways of going about it (can be done in the "protocol imap" section, but the method metioned here also covers pop without any extra code.




3) Another error:
master: Warning: service(imap-login): process_limit (100) reached, client connections are being dropped
The solution for this is to increase the process_limit for imap.  Edit the /etc/dovecot.conf, find the "service imap-login {" section, and set a higher limit, eg:
service imap-login {
       process_limit = 800
       process_min_avail = 16
       user = dovecot
}





4) Beyond that, check your apache logs for possible clues:
cd /var/log/httpd
tail -n 20 error_log
tail -n 20 domains/domain.com.log
tail -n 20 domains/domain.com.error.log
and the dovecot logs:
tail -n 20 /var/log/maillog


5) Check:
/etc/hosts

to ensure you see:
127.0.0.1   localhost
and that localhost does not exist under other IPs.

6) The error can also showed up when the /etc/virtual/domain.compasswd file is not in the correct format.
It should have 7 columns, separated by colons.  If you only see 2 columns, (1 colon), then run the ./build todovecot command.

Thứ Ba, 15 tháng 11, 2016

Cách khắc phục lỗi chữ bị răng cưa trong Photoshop

Nhiều bạn thắc mắc là tại sao chữ trong Photoshop lại bị răng cưa? mà không được mịn ở đường viền xung quanh chữ như hình dưới:



Nếu bạn cũng gặp trường hợp như vậy thì hãy làm theo các bước dưới đây.
B1. Chọn Text (T) để vào chữ viết bình thường.
B2. Chọn Sharp

Lý do bị răng cưa là bạn để chế độ None


Chủ Nhật, 16 tháng 10, 2016

Hướng dẫn mở và khóa port trên Linux

Trong quá trình sử dụng hoặc quản lý server linux, tùy theo mục đích và yêu cầu công việc mà bạn cần thực hiện mở hoặc khóa một cổng (port) trên server để phục vụ cho tính an toàn và bảo mật.
Bài viết sẽ hướng dẫn cách cơ bản để có thể mở hoặc khóa các port.
Một số port phổ biến thường được sử dụng:
TCP port 80 – HTTP Server
TCP port 443 – HTTPS Server
TCP port 25 – Mail Server
TCP port 22 – OpenSSH (remote) secure shell server
TCP port 110 – POP3 (Post Office Protocol v3) server
TCP port 143 – Internet Message Access Protocol (IMAP) - Management of email messages
TCP / UDP port 53 – Domain Name System (DNS)
Bạn có thể sử dụng lênh nano /etc/services (vi /etc/services) để xem danh sách các port

Mở port 80 Firewall trên Centos

Enable Firewall port 80 Centos – Mở port cho phép truy cập web trừ internet
Mặc định Centos/RedHat… chặn port 80 truy cập từ internet vào server của bạn. Vì vậy bạn cần phải mở Firewall port 80 cho truy cập vào web từ bên ngoài

# /sbin/iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT

# service iptables save

1.     Khóa cổng vào (Block Incoming Port)
 
/sbin/iptables -A INPUT -p tcp --destination-port {PORT-NUMBER-HERE} -j DROP
 
### interface section use eth1 ###
/sbin/iptables -A INPUT -i eth1 -p tcp --destination-port {PORT-NUMBER-HERE} -j DROP
 
### only drop port for given IP or Subnet ##
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port {PORT-NUMBER-HERE} -s {IP-ADDRESS-HERE} -j DROP
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port {PORT-NUMBER-HERE} -s {IP/SUBNET-HERE} -j DROP
Ví dụ: Để khóa imcoming port 80 (HTTP server), ta sử dụng lệnh sau:
 
/sbin/iptables -A INPUT -p tcp --destination-port 80 -j DROP
/sbin/service iptables save
Để khóa port 80 với tất cả IP, chỉ cho duy nhất IP có địa chỉ 10.7.3.2 truy cập
 
/sbin/iptables -A INPUT -p tcp -i eth1 -s ! 10.7.3.2 --dport 80 -j DROP

2.     Khóa cổng ra (Block Outgoing Port)
 
/sbin/iptables -A OUTPUT -p tcp --dport {PORT-NUMBER-HERE} -j DROP
 
### interface section use eth1 ###
/sbin/iptables -A OUTPUT -i eth1 -p tcp --dport {PORT-NUMBER-HERE} -j DROP
 
### only drop port for given IP or Subnet ##
/sbin/iptables -A OUTPUT -i eth0 -p tcp --destination-port {PORT-NUMBER-HERE} -s {IP-ADDRESS-HERE} -j DROP
/sbin/iptables -A OUTPUT -i eth0 -p tcp --destination-port {PORT-NUMBER-HERE} -s {IP/SUBNET-HERE} -j DROP
Ví dụ: Để khóa outgoing port 25, ta sử dụng lệnh sau:
 
/sbin/iptables -A OUTPUT -p tcp --dport 25 -j DROP
/sbin/service iptables save
Để khóa outgoing port 279 đối với IP 10.7.3.5, sử dụng lệnh sau:
 
/sbin/iptables -A OUTPUT -p tcp -d 10.7.3.5 --dport 279 -j DROP
/sbin/service iptables save
Chúc các bạn thành công!

Thứ Sáu, 14 tháng 10, 2016

Backup plesk và restore trên linux, restore sang server mới

1. Backup plesk
đăng nhập plesk với quyền admin
chọn: Tools & settings > Backup manager để tạo backup
sau khi backup xong bạn có thể tải file backup về hoặc vào thư mục lưu file backup để xem.
thư mục lưu file backup: /var/lib/psa/dumps

nếu tải file backup về và đưa sang máy khác khi đó file sẽ ở dạng .tar khi đưa sang server khác bạn phải bung file này ra thư mục /var/lib/psa/dumps. ví dụ backup_info_1610111447.xml.tar

Sau khi bung file backup ra thì vào mục Tools & settings > Backup manager sẽ thấy được file backup.

2. Restore plesk
Thư mục để chạy lệnh restore plesk thường là: /usr/local/psa/bin/pleskrestore
Chạy lệnh sau để restore:

[root@localhost ~]# /usr/local/psa/bin/pleskrestore --restore /var/lib/psa/dumps/backup_file_name.tar -level server

ví dụ: [root@localhost ~]# /usr/local/psa/bin/pleskrestore --restore /var/lib/psa/dumps/backup_info_1610111447.xml.tar -level server

To restore entire server:
pleskrestore restore <backup repository root>/<server>.xml -level server

Note: When the whole server backup is restored, license keys are not restored by default. To restore license keys along with other server content, use the -license option in your restore command.

To restore entire server with license keys:
pleskrestore --restore <backup repository root>/<server>.xml -level server -license


To restore all domains belonging to a reseller:
pleskrestore --restore <backup repository root>/resellers/<reseller ID>/<reseller>.xml -level domains

To restore all reseller accounts:

pleskrestore --restore <backup repository root>/<server>.xml -level resellers

To restore two resellers from a server backup:
pleskrestore --restore <backup repository root>/<server>.xml -level resellers -filter list:JohnDoe,JaneDoe
or

pleskrestore --restore <Upload directory>/<server backup name>.tar -level resellers -filter list:JohnDoe,JaneDoe


To restore two domains owned by Plesk admin:
pleskrestore --restore <backup repository root>/<server>.xml -level domains -filter list:example.com,sample.org


To restore client's several domains defined in a file:

pleskrestore --restore <backup repository root>/resellers/SandyLee/clients/JaneDow/<client>.xml -level domains -filter <path to the file>/restore-domains.txt

MẸO: nếu báo lỗi IP ...
làm như sau vào phần quản trị database https://103.211.212.53:8443/domains/databases/phpMyAdmin/

chọn database "psa" tìm table ip_pool chỉnh sửa Exclusive thành shared

Sau đó restore lại là OK

Thứ Ba, 11 tháng 10, 2016

Cài đặt Plesk trên centos

Để cài đặt Plesk trên linux centos cần đăng nhập với quyền root rồi cài với lệnh sau:

sh <(curl https://installer.plesk.com/one-click-installer || wget -O - https://installer.plesk.com/one-click-installer)

để xem lệnh bạn có thể vào http://page.plesk.com/plesk-free-download-wp để xem chci tiết hơn.

Nếu quá trình bài đặt xảy ra lỗi sau:

"Fatal error during packages installation: Test Transaction Errors: file /etc/httpd/conf.d/fcgid.conf from install of psa-mod_fcgid-2.3.9.1-centos7.14080113.x86_64 conflicts with file from package mod_fcgid-2.3.9-4.el7.x86_64
file /usr/lib/tmpfiles.d/mod_fcgid.conf from install of psa-mod_fcgid-2.3.9.1-centos7.14080113.x86_64 conflicts with file from package mod_fcgid-2.3.9-4.el7.x86_64
file /usr/lib64/httpd/modules/mod_fcgid.so from install of psa-mod_fcgid-2.3.9.1-centos7.14080113.x86_64 conflicts with file from package mod_fcgid-2.3.9-4.el7.x86_64

YumTestTransactionError: Test Transaction Errors: file /etc/httpd/conf.d/fcgid.conf from install of psa-mod_fcgid-2.3.9.1-centos7.14080113.x86_64 conflicts with file from package mod_fcgid-2.3.9-4.el7.x86_64
file /usr/lib/tmpfiles.d/mod_fcgid.conf from install of psa-mod_fcgid-2.3.9.1-centos7.14080113.x86_64 conflicts with file from package mod_fcgid-2.3.9-4.el7.x86_64
file /usr/lib64/httpd/modules/mod_fcgid.so from install of psa-mod_fcgid-2.3.9.1-centos7.14080113.x86_64 conflicts with file from package mod_fcgid-2.3.9-4.el7.x86_64


ERROR: The Yum utility failed to install the required packages.
Attention! Your software might be inoperable.
Please, contact product technical support."

Hãy chạy lệnh sau:

# rpm -e --test mod_fcgid

Nếu không được thì hãy chạy lệnh sau:

# rpm -e mod_fcgid

Sau đó hãy chạy lại lệnh cài đặt Plesk ban đầu.

Sau khi cài xong dùng lệnh sau để kiểm tra xem plesk đã chạy chưa:

# /etc/init.d/psa status

sw-cp-serverd (pid 1192) is running...

Nếu thấy Plesk đang tắt thì dùng lệnh sau để start

# service psa start

Muốn kiểm tra password của plesk admin, hãy chạy lệnh sau:


# plesk bin admin --show-password
hay

# /usr/local/psa/bin/admin --show-password

Sau khi cài xong check plesk running bạn vào: https://ip_cuaban:8443 nếu chạy được tức là đã OK
Nếu chưa chạy được thì bạn kiểm tra có thể firewall chặn. Bạn thử tắt firewall đi với lệnh

Disable Firewalld

systemctl disable firewalld

Stop Firewalld

systemctl stop firewalld

Check the Status of Firewalld

systemctl status firewalld

Enable Firewalld

systemctl enable firewalld

Start Firewalld

systemctl start firewalld

Check the Status of Firewalld

systemctl status firewalld

Nếu do Firewalld chặn thì hãy sử dụng lệnh để mở port 8443 lên.

Thứ Năm, 18 tháng 8, 2016

How to Upload Large Files in PHP

Uploading a file from a web form in PHP is easy. The online manual provides a Handling File Uploads section, and there are several articles on sitepoint.com, including How To Handle File Uploads With PHP by Kevin Yank.