Archive for the ‘Mẹo vặt của hiếu râu’ Category

2
Mar

linux performance monitor

   Posted by: admin

#vmstat 2

#top

#glances

#sar -r

#to be continued …

5
Feb

freeRadius + PAM

   Posted by: admin

# yum install freeradius

#yum install freeradius-utils

#cd /etc/raddb/sites-enabled
#rm inner-tunnel
#vi default
uncomment pam (Pluggable Authentication Modules)
#vi ../users
uncomment lameuser
add : DEFAULT AUTH-Type := PAM
#vi /etc/pam.d/radiusd
#%PAM-1.0
auth       required     pam_linotp.so nosslhostnameverify nosslcertverify url=https://localhost/OTP/pam.php
account    required     pam_permit.so
#auth       include     password-auth
#account    required    pam_nologin.so
#account    include     password-auth
#password   include     password-auth
#session    include     password-auth
#radtest my_username my_password localhost 18230 testing123
Sending Access-Request of id 228 to 127.0.0.1 port 1812
User-Name = “my_username”
User-Password = “my_password”
NAS-IP-Address = 127.0.0.1
NAS-Port = 18230
Message-Authenticator = 0×00000000000000000000000000000000
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=228, length=20
http://freeradius.org/pam_radius_auth/
22
Nov

php pthreads

   Posted by: admin

error_reporting(E_ALL);
class AsyncWebRequest extends Thread {
    public $url;
    public $data;

    public function __construct($url) {
        $this->url = $url;
    }

    public function run() {
        if (($url = $this->url)) {
            /*
             * If a large amount of data is being requested, you might want to
             * fsockopen and read using usleep in between reads
             */
            $this->data = file_get_contents($url);
        } else
            printf("Thread #%lu was not provided a URL\n", $this->getThreadId());
    }
}

$t = microtime(true);
$g = new AsyncWebRequest(sprintf("http://www.google.com/?q=%s", rand() * 10));
/* starting synchronized */
if ($g->start()) {
    printf("Request took %f seconds to start ", microtime(true) - $t);
    while ( $g->isRunning() ) {
        echo ".";
        usleep(100);
    }
    if ($g->join()) {
        printf(" and %f seconds to finish receiving %d bytes\n", microtime(true) - $t, strlen($g->data));
    } else
        printf(" and %f seconds to finish, request failed\n", microtime(true) - $t);
}
17
Nov

mysql multi instance

   Posted by: admin

mkdir -p /var/lib/mysql2
chown mysql:mysql mysql2

cp -p /etc/my.cnf /etc/my2.cnf
vi my2.cnf

[mysqld]
datadir=/var/lib/mysql2
socket=/var/lib/mysql/mysql2.sock
port=3337

[mysqld_safe]
log-error=/var/log/mysqld2.log
pid-file=/var/run/mysqld/mysqld2.pid


mysql_install_db --user=mysql --datadir=/var/lib/mysql2

mysqld_safe --defaults-file=/etc/my2.cnf &
netstat -antp | grep 3337

mysqladmin -S /var/lib/mysql/mysql2.sock shutdown -p
mysql -S /var/lib/mysql/mysql2.sock -u root -p

13
Nov

procmail - sendmail subject filter

   Posted by: admin

[root@ns6 abc.cadena-it.com]# cat .procmailrc

VERBOSE=off

MAILDIR=$HOME/mail # elm users might use $HOME/Mail instead

DEFAULT=/var/spool/mail/abc.macatung.com

LOGFILE=$HOME/log

CLAMDSCAN=/usr/bin/clamdscan

:0

* ^Subject.*( naked | XXX | sex| Van Tai | Hang Khong | Visa )

/dev/null

:0

* ^From.*(MAILER-DAEMON)

/dev/null

:0

{

RESULT=`$CLAMDSCAN –stdout –no-summary -`

:0 Di

* RESULT ?? FOUND

/dev/null

}

[root@ns6 abc.cadena-it.com]#

general.rc



:0
* ^Cc.*joe@somewhere.org
* ^Cc.*me
{
	:0 c
	$DEFAULT

	:0
	SOME_FOLDER
}

:0
* ^Subject.*something-or-other
! another@address.com

lists.rc


:0
* ^From.*redhat.*list.*list.*@
redhat-lists

:0
* ^From.*owner@independence
independence-list


spam.rc


	  
:0
* ^From.*my-buddy
* ^Subject.*(Fwd|Forward|joke)
/dev/null

:0
* !(To|Cc).*my_address		# this is my account here
* !(To|Cc).*my_address_2	# I get mail forwarded from here
* !From.*my\.domain\.edu	# I trust the locals not to spam
* !From.*list.*@			# don't trash anything from mail lists
* !From.*good-buddy		# sometimes Bcc's me person mail to his sig-other
spam

:0
* ^From.*big-jerk
/dev/null


guestbook.rc


Subject:.*Form Posted
| cat&>$HOME/guestmail && \
$HOME/bin/guestscript $HOME/guestmail

Appendix: egrep regular expressions

Back to top

^ matches the beginning of the line
$ matches the end of the line
. Matches any single character
(character)* match arbitrarily many occurences of (character)
(character)? Match 0 or 1 instance of (character)
[abcdef] Match any character enclosed in [] (in this instance, a b c d e or f) ranges of characters such as [a-z] are permitted. The behaviour of this deserves more description. See the page ongrep for more details about the syntax of lists.
[^abcdef] Match any character NOT enclosed in [ ] (in this instance, any character other than a b c d e or f)
(expression) Group operator. Contents of parentheses treated as one character with respect to * , + , ? and | concatenation operators
\n Backreference - matches the contents of the nth set of parentheses
expression1|expression2 Matches expression1 or expression 2.
9
Oct

apache MPM worker

   Posted by: admin



rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
cd /tmp/
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

vim /etc/httpd/conf.d/fastcgi.conf

FastCgiWrapper Off

<IfModule mod_fastcgi.c>
    AddHandler php5-fcgi .php
    Action php5-fcgi /php5-fcgi
    Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
    DirectoryIndex index.php
    FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
</IfModule>

mkdir -p /usr/lib/cgi-bin

vim /etc/php-fpm.d/www.conf 

listen = /var/run/php5-fpm.sock
beware of sock permission ( nobody 666 )
vi /etc/sysconfig/httpd
HTTPD=/usr/sbin/httpd.worker

28
Sep

sendmail - special port per Mailer

   Posted by: admin

Msmtp,          P=[IPC], F=mDFMuX, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,

T=DNS/RFC822/SMTP,

A=TCP $h

Mesmtp,         P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,

T=DNS/RFC822/SMTP,

A=TCP $h 587

Msmtp8,         P=[IPC], F=mDFMuX8, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,

T=DNS/RFC822/SMTP,

A=TCP $h

Mdsmtp,         P=[IPC], F=mDFMuXa%, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,

T=DNS/RFC822/SMTP,

A=TCP $h

Mrelay,         P=[IPC], F=mDFMuXa8, S=EnvFromSMTP/HdrFromSMTP, R=MasqSMTP, E=\r\n, L=2040,

T=DNS/RFC822/SMTP,

A=TCP $h 3535

24
Sep

Sogo webmail

   Posted by: admin

http://www.iredmail.org/docs/sogo-centos-6-mysql.html

16
Sep

mysql store procedure/function

   Posted by: admin


http://www.mysqltutorial.org/mysql-stored-function/


CREATE DEFINER=`hieunt`@`localhost` FUNCTION `get_range_counter`(`p_idRule` INT, `p_rType` VARCHAR(50))
RETURNS int(11)
LANGUAGE SQL
NOT DETERMINISTIC
READS SQL DATA
SQL SECURITY DEFINER
COMMENT ''
BEGIN

DECLARE ret INT;

select sum(b.rE-b.rB+1) as DIP INTO ret
from tbl_rule_detail b
where b.rType=p_rType and b.idRule= p_idRule;

if p_rType='SP' or p_rType='DP' then
if ret>=65536 then set ret=0; end if;
else
if ret>=2147483647 then set ret=0; end if;
end if;

return (ret);

END

//—————–

select a.id,b.code_ticket ,a.SourceVlan,a.SourceIP,a.SourcePort,a.DesVLan,a.DesIP,a.DesPort,a.Protocol,
get_range_counter(a.id,'SIP') as SIP,
get_range_counter(a.id,'SP') as SP,
get_range_counter(a.id,'DIP') as DIP,
get_range_counter(a.id,'DP') as DP
from tbl_rule_request a, tbl_tickets b
where TO_DAYS(a.LastSeen)>TO_DAYS(NOW())-2 and a.idTicket=b.id
having (SIP>20)or (DIP>20) or SP>10 or DP>10
order by (DP+SP+DIP+SIP) DESC
19
Jun

SSL telnet

   Posted by: admin

openssl s_client -connect example.com:443 -ssl3